Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorporate Elide #3

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 38 additions & 15 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@
<checkstyle.suppressions.location>checkstyle-suppressions.xml</checkstyle.suppressions.location>
<checkstyle.version>8.30</checkstyle.version>
<checkstyle.resourceIncludes>**/*.properties*</checkstyle.resourceIncludes>

<jakarta-websocket.version>2.0.0</jakarta-websocket.version>
</properties>

<dependencyManagement>
Expand Down Expand Up @@ -93,6 +95,42 @@
</dependencyManagement>

<dependencies>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-server</artifactId>
<!-- <scope>test</scope>-->
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-webapp</artifactId>
<!-- <scope>test</scope>-->
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-servlet</artifactId>
<!-- <scope>test</scope>-->
</dependency>
<dependency>
<groupId>jakarta.websocket</groupId>
<artifactId>jakarta.websocket-api</artifactId>
<version>${jakarta-websocket.version}</version>
</dependency>
<dependency>
<groupId>com.yahoo.elide</groupId>
<artifactId>elide-core</artifactId>
<version>7.0.0-pr6</version>
</dependency>
<dependency>
<groupId>com.yahoo.elide</groupId>
<artifactId>elide-model-config</artifactId>
<version>7.0.0-pr6</version>
</dependency>
<dependency>
<groupId>com.yahoo.elide</groupId>
<artifactId>elide-standalone</artifactId>
<version>7.0.0-pr6</version>
</dependency>

<dependency>
<groupId>org.glassfish.jaxb</groupId>
<artifactId>jaxb-runtime</artifactId>
Expand Down Expand Up @@ -230,21 +268,6 @@
</dependency>

<!--Jetty-->
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-server</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-webapp</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-servlet</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
Expand Down
107 changes: 96 additions & 11 deletions src/main/java/com/paiondata/astraios/application/ResourceConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,34 @@
*/
package com.paiondata.astraios.application;

import com.paiondata.astraios.web.filters.CorsFilter;
import com.yahoo.elide.Elide;
import com.yahoo.elide.ElideSettings;
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;
import com.yahoo.elide.modelconfig.DynamicConfiguration;
import com.yahoo.elide.standalone.Util;
import com.yahoo.elide.standalone.config.ElideStandaloneSettings;

import org.glassfish.hk2.utilities.Binder;
import org.glassfish.jersey.media.multipart.MultiPartFeature;
import org.glassfish.hk2.api.ServiceLocator;
import org.glassfish.jersey.internal.inject.AbstractBinder;

import jakarta.inject.Inject;
import jakarta.persistence.Entity;
import jakarta.persistence.EntityManagerFactory;
import jakarta.persistence.Id;
import jakarta.persistence.Table;
import jakarta.servlet.ServletContext;
import jakarta.ws.rs.ApplicationPath;
import jakarta.ws.rs.core.Context;
import net.jcip.annotations.Immutable;
import net.jcip.annotations.ThreadSafe;

import java.io.IOException;
import java.util.Optional;
import java.util.Properties;

/**
* The resource configuration for the web applications.
*/
Expand All @@ -33,18 +51,85 @@
@ApplicationPath("v1")
public class ResourceConfig extends org.glassfish.jersey.server.ResourceConfig {

private static final String ENDPOINT_PACKAGE = "com.paiondata.astraios.web.endpoints";
private final ServiceLocator injector;

@Entity
@Table(name="ArtifactGroup")
@Include(rootLevel = true, name = "group", friendlyName = "group", description = "group desc")
public class ArtifactGroup {
@Id
public String name = "";

public String description = "";
}

public class AstraiosBinder extends AbstractBinder {

@Override
protected void configure() {
ElideStandaloneSettings settings = new ElideStandaloneSettings() {
@Override
public String getModelPackageName() {
return ArtifactGroup.class.getPackage().getName();
}

@Override
public Properties getDatabaseProperties() {
Properties options = new Properties();

options.put("hibernate.dialect", "org.hibernate.dialect.MySQL5Dialect");
options.put("javax.persistence.jdbc.driver", "com.mysql.jdbc.Driver");
options.put("javax.persistence.jdbc.url", "jdbc:mysql://localhost:3306/testDB");
options.put("javax.persistence.jdbc.user", "root");
options.put("javax.persistence.jdbc.password", "root");

return options;
}
};

EntityManagerFactory entityManagerFactory = Util.getEntityManagerFactory(
settings.getClassScanner(),
settings.getModelPackageName(),
false,
settings.getDatabaseProperties()
);
DataStore dataStore = settings.getDataStore(entityManagerFactory);

Optional<DynamicConfiguration> dynamicConfiguration;
try {
dynamicConfiguration = settings.getDynamicConfiguration(settings.getClassScanner());
} catch (IOException exception) {
throw new IllegalStateException(exception);
}
EntityDictionary entityDictionary = settings.getEntityDictionary(
injector,
settings.getClassScanner(),
dynamicConfiguration,
settings.getEntitiesToExclude()
);

ElideSettings elideSettings = settings.getElideSettings(entityDictionary, dataStore, settings.getObjectMapper());
Elide elide = new Elide(
elideSettings,
new TransactionRegistry(),
elideSettings.getDictionary().getScanner(),
false
);

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

/**
* DI Constructor.
*/
@Inject
public ResourceConfig() {
final Binder binder = new BinderFactory().buildBinder();

packages(ENDPOINT_PACKAGE);
register(new CorsFilter());
register(binder);
register(MultiPartFeature.class);
public ResourceConfig(ServiceLocator injector, @Context ServletContext servletContext) {
this.injector = injector;
register(new AstraiosBinder());
}
}
30 changes: 0 additions & 30 deletions src/main/resources/logback.xml

This file was deleted.

Loading