Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
QubitPi committed Aug 15, 2023
1 parent 994143d commit d7d2592
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 50 deletions.
5 changes: 5 additions & 0 deletions docs/docs/development.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,10 @@ Lastly, drop the [WAR file](#packaging) into **/path/to/jetty-base/webapps** dir
mv /path/to/war-file /path/to/jetty-base/webapps/ROOT.war
```

### Setting Environment Variables

- **MODEL_PACKAGE_NAME**: Model package in CLASSPATH

### Running Astraios

```bash
Expand All @@ -154,3 +158,4 @@ The webservice will run on port **8080**

[astraios]: https://github.com/paion-data/astraios
[astraios Dockerfile]: https://github.com/paion-data/astraios/blob/master/Dockerfile

21 changes: 0 additions & 21 deletions docs/docs/elide.md

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,6 @@
@Config.Sources({"system:env", "system:properties"})
public interface ApplicationConfig extends Config {

@Key("EXAMPLE_CONFIG_KEY_NAME")
String exampleConfigKey();
@Key("MODEL_PACKAGE_NAME")
String modelPackageName();
}
26 changes: 12 additions & 14 deletions src/main/java/com/paiondata/astraios/application/BinderFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import com.yahoo.elide.Elide;
import com.yahoo.elide.ElideSettings;
import com.yahoo.elide.ElideSettingsBuilder;
import com.yahoo.elide.annotation.Include;
import com.yahoo.elide.core.TransactionRegistry;
import com.yahoo.elide.core.datastore.DataStore;
import com.yahoo.elide.core.dictionary.EntityDictionary;
Expand All @@ -34,18 +33,16 @@

import com.paiondata.astraios.models.Note;

import org.aeonbits.owner.ConfigFactory;
import org.glassfish.hk2.api.ServiceLocator;
import org.glassfish.hk2.utilities.Binder;
import org.glassfish.hk2.utilities.binding.AbstractBinder;
import org.hibernate.Session;
import org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl;
import org.hibernate.jpa.boot.internal.PersistenceUnitInfoDescriptor;

import jakarta.persistence.Entity;
import jakarta.persistence.EntityManager;
import jakarta.persistence.EntityManagerFactory;
import jakarta.persistence.Id;
import jakarta.persistence.Table;
import jakarta.persistence.spi.PersistenceUnitInfo;
import jakarta.validation.constraints.NotNull;
import net.jcip.annotations.Immutable;
Expand Down Expand Up @@ -75,24 +72,26 @@ public class BinderFactory {
* {@link org.glassfish.jersey.server.ResourceConfig#register(Object)}
*/
@NotNull
public Binder buildBinder(ServiceLocator injector) {
public Binder buildBinder(final ServiceLocator injector) {
return new AbstractBinder() {

private static final Consumer<EntityManager> TXCANCEL = em -> em.unwrap(Session.class).cancelQuery();

private static final ApplicationConfig CONFIG = ConfigFactory.create(ApplicationConfig.class);

private final ClassScanner classScanner = new DefaultClassScanner();

@Override
protected void configure() {
ElideSettings elideSettings = buildElideSettings();
final ElideSettings elideSettings = buildElideSettings();

bind(buildElide(elideSettings)).to(Elide.class).named("elide");;
bind(elideSettings).to(ElideSettings.class);
bind(elideSettings.getDictionary()).to(EntityDictionary.class);
bind(elideSettings.getDataStore()).to(DataStore.class).named("elideDataStore");
}

private Elide buildElide(ElideSettings elideSettings) {
private Elide buildElide(final ElideSettings elideSettings) {
return new Elide(
elideSettings,
new TransactionRegistry(),
Expand All @@ -104,22 +103,21 @@ private Elide buildElide(ElideSettings elideSettings) {
private ElideSettings buildElideSettings() {
return new ElideSettingsBuilder(buildDataStore(buildEntityManagerFactory()))
.withEntityDictionary(buildEntityDictionary(injector))
.withJsonApiPath("/api/v1/")
.build();
}

private DataStore buildDataStore(EntityManagerFactory entityManagerFactory) {
private DataStore buildDataStore(final EntityManagerFactory entityManagerFactory) {
return new JpaDataStore(
entityManagerFactory::createEntityManager,
em -> new NonJtaTransaction(em, TXCANCEL),
entityManagerFactory::getMetamodel);
}

private EntityManagerFactory buildEntityManagerFactory() {
String modelPackageName = Note.class.getPackage().getName();
ClassLoader classLoader = null;
final String modelPackageName = CONFIG.modelPackageName();
final ClassLoader classLoader = null;

PersistenceUnitInfo persistenceUnitInfo = new PersistenceUnitInfoImpl(
final PersistenceUnitInfo persistenceUnitInfo = new PersistenceUnitInfoImpl(
"astraios",
combineModelEntities(classScanner, modelPackageName, false),
getDefaultDbConfigs(),
Expand All @@ -134,7 +132,7 @@ private EntityManagerFactory buildEntityManagerFactory() {
}

private static Properties getDefaultDbConfigs() {
Properties dbProperties = new Properties();
final Properties dbProperties = new Properties();

dbProperties.put("hibernate.show_sql", "true");
dbProperties.put("hibernate.hbm2ddl.auto", "create");
Expand Down Expand Up @@ -162,7 +160,7 @@ private static Properties getDefaultDbConfigs() {
return dbProperties;
}

private EntityDictionary buildEntityDictionary(ServiceLocator injector) {
private EntityDictionary buildEntityDictionary(final ServiceLocator injector) {
return new EntityDictionary(
new HashMap<>(),
new HashMap<>(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,9 @@
package com.paiondata.astraios.application;

import com.yahoo.elide.Elide;
import com.yahoo.elide.core.dictionary.EntityDictionary;
import com.yahoo.elide.swagger.resources.ApiDocsEndpoint;

import com.paiondata.astraios.web.filters.CorsFilter;

import org.glassfish.hk2.api.ServiceLocator;
import org.glassfish.hk2.api.TypeLiteral;
import org.glassfish.hk2.utilities.Binder;
import org.glassfish.jersey.media.multipart.MultiPartFeature;

import jakarta.inject.Inject;
import jakarta.servlet.ServletContext;
Expand All @@ -33,33 +27,29 @@
import net.jcip.annotations.Immutable;
import net.jcip.annotations.ThreadSafe;

import java.util.List;

/**
* The resource configuration for the web applications.
*/
@Immutable
@ThreadSafe
@ApplicationPath("/")
@ApplicationPath("/v1/data/")
public class ResourceConfig extends org.glassfish.jersey.server.ResourceConfig {

private static final String ENDPOINT_PACKAGE = "com.yahoo.elide.jsonapi.resources";


/**
* DI Constructor.
*/
@Inject
public ResourceConfig(ServiceLocator injector, @Context ServletContext servletContext) {
public ResourceConfig(final ServiceLocator injector, @Context final ServletContext servletContext) {
final Binder binder = new BinderFactory().buildBinder(injector);

register(binder);

register(new org.glassfish.hk2.utilities.binding.AbstractBinder() {
@Override
protected void configure() {
Elide elide = injector.getService(Elide.class, "elide");

final Elide elide = injector.getService(Elide.class, "elide");
elide.doScans();
}
});
Expand Down

0 comments on commit d7d2592

Please sign in to comment.