diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..88a8bcb --- /dev/null +++ b/pom.xml @@ -0,0 +1,32 @@ + + + 4.0.0 + + com.nutcore + orientdb-microservices-archetype + 1.0-SNAPSHOT + maven-archetype + + orientdb-microservices-archetype + + + + + org.apache.maven.archetype + archetype-packaging + 2.4 + + + + + + + maven-archetype-plugin + 2.4 + + + + + + http://maven.apache.org + diff --git a/src/main/resources/META-INF/maven/archetype-metadata.xml b/src/main/resources/META-INF/maven/archetype-metadata.xml new file mode 100644 index 0000000..f9dca77 --- /dev/null +++ b/src/main/resources/META-INF/maven/archetype-metadata.xml @@ -0,0 +1,20 @@ + + + + + src/main/java + + **/*.java + + + + src/main/resources + + **/*.xml + **/*.properties + + + + diff --git a/src/main/resources/archetype-resources/pom.xml b/src/main/resources/archetype-resources/pom.xml new file mode 100644 index 0000000..79b5d8c --- /dev/null +++ b/src/main/resources/archetype-resources/pom.xml @@ -0,0 +1,148 @@ + + + 4.0.0 + ${groupId} + ${artifactId} + jar + ${version} + OrientDB Microservices + http://maven.apache.org + + + 3.0.13.Final + 1.3.5.Final + 2.2.12 + 2.4.0.Final + + + + + org.nutcore + orientdb-javaee + 1.0 + + + org.jboss.resteasy + resteasy-jaxrs + ${resteasy.version} + + + org.jboss.resteasy + async-http-servlet-3.0 + ${resteasy.version} + + + io.undertow + undertow-servlet + ${undertow.version} + + + org.jboss.resteasy + resteasy-undertow + ${resteasy.version} + + + org.jboss.resteasy + resteasy-cdi + ${resteasy.version} + + + org.jboss.resteasy + resteasy-jackson-provider + ${resteasy.version} + + + io.undertow + undertow-core + ${undertow.version} + + + com.orientechnologies + orientdb-core + ${orientdb.version} + + + com.orientechnologies + orientdb-graphdb + ${orientdb.version} + + + com.orientechnologies + orientdb-server + ${orientdb.version} + + + com.orientechnologies + orientdb-tools + ${orientdb.version} + + + com.orientechnologies + orientdb-client + ${orientdb.version} + + + com.orientechnologies + orientdb-object + ${orientdb.version} + + + javassist + org.javassist + + + + + javassist + org.javassist + 3.18.2-GA + + + org.jboss.weld + weld-core + ${weld.version} + + + org.jboss.weld.servlet + weld-servlet-core + ${weld.version} + + + io.swagger + swagger-jaxrs + 1.5.0 + + + + ${artifactId} + + + maven-war-plugin + 3.0.0 + + + org.apache.maven.plugins + maven-compiler-plugin + + 1.8 + 1.8 + + + + org.codehaus.mojo + exec-maven-plugin + 1.2.1 + + + + java + + + + + ${groupId}.Main + + + + + diff --git a/src/main/resources/archetype-resources/src/main/java/CORSFilter.java b/src/main/resources/archetype-resources/src/main/java/CORSFilter.java new file mode 100644 index 0000000..8abe23d --- /dev/null +++ b/src/main/resources/archetype-resources/src/main/java/CORSFilter.java @@ -0,0 +1,27 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +package ${package}; + +import javax.ws.rs.container.ContainerRequestContext; +import javax.ws.rs.container.ContainerResponseContext; +import javax.ws.rs.container.ContainerResponseFilter; +import javax.ws.rs.ext.Provider; +import java.io.IOException; + +@Provider +public class CORSFilter implements ContainerResponseFilter +{ + + @Override + public void filter(final ContainerRequestContext requestContext, + final ContainerResponseContext cres) throws IOException + { + cres.getHeaders().add("Access-Control-Allow-Origin", "*"); + cres.getHeaders().add("Access-Control-Allow-Headers", "origin, content-type, accept, authorization"); + cres.getHeaders().add("Access-Control-Allow-Credentials", "true"); + cres.getHeaders().add("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS, HEAD"); + cres.getHeaders().add("Access-Control-Max-Age", "1209600"); + } + +} \ No newline at end of file diff --git a/src/main/resources/archetype-resources/src/main/java/Main.java b/src/main/resources/archetype-resources/src/main/java/Main.java new file mode 100644 index 0000000..1f1a919 --- /dev/null +++ b/src/main/resources/archetype-resources/src/main/java/Main.java @@ -0,0 +1,62 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +package ${package}; + +import com.nutcore.orientdb.javaee.orientdb.OrientDBFilter; +import com.nutcore.orientdb.javaee.orientdb.OrientDBJacksonProvider; +import com.nutcore.orientdb.javaee.orientdb.OrientDBServletContextListener; +import io.undertow.Undertow; +import io.undertow.servlet.Servlets; +import io.undertow.servlet.api.DeploymentInfo; +import io.undertow.servlet.api.FilterInfo; +import org.jboss.resteasy.plugins.server.undertow.UndertowJaxrsServer; +import org.jboss.resteasy.spi.ResteasyDeployment; + +import javax.servlet.DispatcherType; +import java.util.Arrays; + +public class Main +{ + private static final String ORIENTDB_FILTER = "orientdb"; + + public static void main(String[] args) throws Exception + { + startWebServer(args); + } + + private static void startWebServer(String[] args) + { + String host = "0.0.0.0"; + int port = 8080; + if (args.length > 0) + { + host = args[0]; + } + if (args.length > 1) + { + port = Integer.parseInt(args[1]); + } + + ResteasyDeployment deployment = new ResteasyDeployment(); + deployment.setProviderClasses(Arrays.asList(OrientDBJacksonProvider.class.getName())); + deployment.setInjectorFactoryClass("org.jboss.resteasy.cdi.CdiInjectorFactory"); + deployment.setApplicationClass(MyApplication.class.getName()); + + Undertow.Builder builder = Undertow.builder().addHttpListener(port, host); + + UndertowJaxrsServer server = new UndertowJaxrsServer().start(builder); + DeploymentInfo deploymentInfo = server + .undertowDeployment(deployment) + .setClassLoader(Main.class.getClassLoader()) + .addListener(Servlets.listener(OrientDBServletContextListener.class)) + .addListeners(Servlets.listener(org.jboss.weld.environment.servlet.Listener.class)) + .setContextPath("/api") + .setDeploymentName("${artifactId}") + .addFilter(new FilterInfo(ORIENTDB_FILTER, OrientDBFilter.class)) + .addFilterUrlMapping(ORIENTDB_FILTER, "/*", DispatcherType.REQUEST); + server.deploy(deploymentInfo); + + } + +} diff --git a/src/main/resources/archetype-resources/src/main/java/MyApplication.java b/src/main/resources/archetype-resources/src/main/java/MyApplication.java new file mode 100644 index 0000000..134d39a --- /dev/null +++ b/src/main/resources/archetype-resources/src/main/java/MyApplication.java @@ -0,0 +1,37 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +package ${package}; + +import ${package}.resource.HelloResource; +import io.swagger.jaxrs.config.BeanConfig; + +import javax.ws.rs.core.Application; +import java.util.HashSet; +import java.util.Set; + +public class MyApplication extends Application +{ + + public MyApplication() + { + BeanConfig beanConfig = new BeanConfig(); + beanConfig.setVersion("1.0.0"); + beanConfig.setSchemes(new String[]{"http"}); + beanConfig.setHost("localhost:8080"); + beanConfig.setBasePath("/api"); + beanConfig.setResourcePackage("${package}.resource"); + beanConfig.setScan(true); + } + + @Override + public Set> getClasses() + { + HashSet> classes = new HashSet>(); + classes.add(HelloResource.class); + classes.add(CORSFilter.class); + classes.add(io.swagger.jaxrs.listing.ApiListingResource.class); + classes.add(io.swagger.jaxrs.listing.SwaggerSerializers.class); + return classes; + } +} \ No newline at end of file diff --git a/src/main/resources/archetype-resources/src/main/java/domain/User.java b/src/main/resources/archetype-resources/src/main/java/domain/User.java new file mode 100644 index 0000000..8d9dc91 --- /dev/null +++ b/src/main/resources/archetype-resources/src/main/java/domain/User.java @@ -0,0 +1,34 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +package ${package}.domain; + +import javax.persistence.Id; + +public class User +{ + @Id + private String id; + private String name; + + public String getId() + { + return id; + } + + public void setId(String id) + { + this.id = id; + } + + public String getName() + { + return name; + } + + public void setName(String name) + { + this.name = name; + } + +} diff --git a/src/main/resources/archetype-resources/src/main/java/resource/HelloResource.java b/src/main/resources/archetype-resources/src/main/java/resource/HelloResource.java new file mode 100644 index 0000000..0e47ea1 --- /dev/null +++ b/src/main/resources/archetype-resources/src/main/java/resource/HelloResource.java @@ -0,0 +1,45 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +package ${package}.resource; + +import ${package}.domain.User; +import com.orientechnologies.orient.core.sql.query.OSQLSynchQuery; +import com.orientechnologies.orient.object.db.OObjectDatabaseTx; +import io.swagger.annotations.Api; + +import javax.inject.Inject; +import javax.ws.rs.*; +import javax.ws.rs.core.MediaType; +import java.util.List; +import java.util.UUID; + +@Api("Hello") +@Path("/hello") +@Produces(MediaType.APPLICATION_JSON) +@Consumes(MediaType.APPLICATION_JSON) +public class HelloResource +{ + + @Inject + OObjectDatabaseTx db; + + @GET + @Path("/{user}") + public User get(@PathParam("user") String username) + { + User user = new User(); + user.setName(username); + User result = db.save(user); + db.commit(); + return result; + } + + @GET + public List getAll() + { + return db.command(new OSQLSynchQuery("select * from User")).execute(); + } + + +} diff --git a/src/main/resources/archetype-resources/src/main/resources/META-INF/beans.xml b/src/main/resources/archetype-resources/src/main/resources/META-INF/beans.xml new file mode 100644 index 0000000..c841c08 --- /dev/null +++ b/src/main/resources/archetype-resources/src/main/resources/META-INF/beans.xml @@ -0,0 +1,9 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) + + \ No newline at end of file diff --git a/src/main/resources/archetype-resources/src/main/resources/db.config.xml b/src/main/resources/archetype-resources/src/main/resources/db.config.xml new file mode 100644 index 0000000..36f8a6c --- /dev/null +++ b/src/main/resources/archetype-resources/src/main/resources/db.config.xml @@ -0,0 +1,44 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/resources/archetype-resources/src/main/resources/orientdb.properties b/src/main/resources/archetype-resources/src/main/resources/orientdb.properties new file mode 100644 index 0000000..e1a8355 --- /dev/null +++ b/src/main/resources/archetype-resources/src/main/resources/orientdb.properties @@ -0,0 +1,7 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +orientdb.entitymanager.packagename=${package}.domain +orientdb.database.password=root +orientdb.database.username=root +orientdb.database.url=plocal:databases/${artifactId} \ No newline at end of file diff --git a/src/test/resources/projects/basic/archetype.properties b/src/test/resources/projects/basic/archetype.properties new file mode 100644 index 0000000..4f4aa3c --- /dev/null +++ b/src/test/resources/projects/basic/archetype.properties @@ -0,0 +1,5 @@ +#Sun Nov 06 22:41:14 CET 2016 +package=it.pkg +version=0.1 +groupId=archetype.it +artifactId=basic diff --git a/src/test/resources/projects/basic/goal.txt b/src/test/resources/projects/basic/goal.txt new file mode 100644 index 0000000..e69de29