initial commit with apps from course repo
This commit is contained in:
49
todo-api-swarm/.classpath
Normal file
49
todo-api-swarm/.classpath
Normal file
@@ -0,0 +1,49 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" output="target/classes" path="src/main/java">
|
||||
<attributes>
|
||||
<attribute name="optional" value="true"/>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
|
||||
<attributes>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
|
||||
<attributes>
|
||||
<attribute name="optional" value="true"/>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
<attribute name="test" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
|
||||
<attributes>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
|
||||
<attributes>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="src" path="target/generated-sources/annotations">
|
||||
<attributes>
|
||||
<attribute name="optional" value="true"/>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
<attribute name="ignore_optional_problems" value="true"/>
|
||||
<attribute name="m2e-apt" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="src" output="target/test-classes" path="target/generated-test-sources/test-annotations">
|
||||
<attributes>
|
||||
<attribute name="optional" value="true"/>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
<attribute name="ignore_optional_problems" value="true"/>
|
||||
<attribute name="m2e-apt" value="true"/>
|
||||
<attribute name="test" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="output" path="target/classes"/>
|
||||
</classpath>
|
||||
23
todo-api-swarm/.project
Normal file
23
todo-api-swarm/.project
Normal file
@@ -0,0 +1,23 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>todo-api</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.m2e.core.maven2Builder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
<nature>org.eclipse.m2e.core.maven2Nature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
||||
@@ -0,0 +1,4 @@
|
||||
eclipse.preferences.version=1
|
||||
encoding//src/main/java=UTF-8
|
||||
encoding//src/main/resources=UTF-8
|
||||
encoding/<project>=UTF-8
|
||||
2
todo-api-swarm/.settings/org.eclipse.jdt.apt.core.prefs
Normal file
2
todo-api-swarm/.settings/org.eclipse.jdt.apt.core.prefs
Normal file
@@ -0,0 +1,2 @@
|
||||
eclipse.preferences.version=1
|
||||
org.eclipse.jdt.apt.aptEnabled=false
|
||||
9
todo-api-swarm/.settings/org.eclipse.jdt.core.prefs
Normal file
9
todo-api-swarm/.settings/org.eclipse.jdt.core.prefs
Normal file
@@ -0,0 +1,9 @@
|
||||
eclipse.preferences.version=1
|
||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
|
||||
org.eclipse.jdt.core.compiler.compliance=1.8
|
||||
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
|
||||
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
|
||||
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore
|
||||
org.eclipse.jdt.core.compiler.processAnnotations=disabled
|
||||
org.eclipse.jdt.core.compiler.release=disabled
|
||||
org.eclipse.jdt.core.compiler.source=1.8
|
||||
4
todo-api-swarm/.settings/org.eclipse.m2e.core.prefs
Normal file
4
todo-api-swarm/.settings/org.eclipse.m2e.core.prefs
Normal file
@@ -0,0 +1,4 @@
|
||||
activeProfiles=
|
||||
eclipse.preferences.version=1
|
||||
resolveWorkspaceProjects=true
|
||||
version=1
|
||||
111
todo-api-swarm/pom.xml
Executable file
111
todo-api-swarm/pom.xml
Executable file
@@ -0,0 +1,111 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.redhat.training.example</groupId>
|
||||
<artifactId>todo-api</artifactId>
|
||||
<name>WildFly Swarm Example</name>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
<packaging>war</packaging>
|
||||
|
||||
<properties>
|
||||
<version.wildfly.swarm>2017.12.1</version.wildfly.swarm>
|
||||
<version.mysql>6.0.6</version.mysql>
|
||||
<maven.compiler.source>1.8</maven.compiler.source>
|
||||
<maven.compiler.target>1.8</maven.compiler.target>
|
||||
<failOnMissingWebXml>false</failOnMissingWebXml>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<fabric8.maven.plugin.version>3.1.80.redhat-000019</fabric8.maven.plugin.version>
|
||||
<fabric8.version>2.3.6</fabric8.version>
|
||||
</properties>
|
||||
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.wildfly.swarm</groupId>
|
||||
<artifactId>bom-all</artifactId>
|
||||
<version>${version.wildfly.swarm}</version>
|
||||
<scope>import</scope>
|
||||
<type>pom</type>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
<build>
|
||||
<finalName>demo</finalName>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.wildfly.swarm</groupId>
|
||||
<artifactId>wildfly-swarm-plugin</artifactId>
|
||||
<version>${version.wildfly.swarm}</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>package</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>io.fabric8</groupId>
|
||||
<artifactId>fabric8-maven-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>resource</goal>
|
||||
<goal>build</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
<generator>
|
||||
<includes>
|
||||
<include>wildfly-swarm</include>
|
||||
</includes>
|
||||
<excludes>
|
||||
<exclude>webapp</exclude>
|
||||
</excludes>
|
||||
<config>
|
||||
<wildfly-swarm>
|
||||
<fromMode>isTag</fromMode>
|
||||
<from>redhat-openjdk18-openshift</from>
|
||||
</wildfly-swarm>
|
||||
</config>
|
||||
</generator>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<dependencies>
|
||||
<!-- Java EE 7 dependency -->
|
||||
<dependency>
|
||||
<groupId>javax</groupId>
|
||||
<artifactId>javaee-api</artifactId>
|
||||
<version>7.0</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<!-- WildFly Swarm Fractions -->
|
||||
<dependency>
|
||||
<groupId>org.wildfly.swarm</groupId>
|
||||
<artifactId>jaxrs-jsonp</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.wildfly.swarm</groupId>
|
||||
<artifactId>jpa</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.wildfly.swarm</groupId>
|
||||
<artifactId>ejb</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.wildfly.swarm</groupId>
|
||||
<artifactId>datasources</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>mysql</groupId>
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
<version>${version.mysql}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
21
todo-api-swarm/src/main/fabric8/deployment.yml
Normal file
21
todo-api-swarm/src/main/fabric8/deployment.yml
Normal file
@@ -0,0 +1,21 @@
|
||||
spec:
|
||||
template:
|
||||
spec:
|
||||
containers:
|
||||
-
|
||||
resources:
|
||||
requests:
|
||||
cpu: "0.2"
|
||||
# memory: 256Mi
|
||||
limits:
|
||||
cpu: "1.0"
|
||||
# memory: 256Mi
|
||||
env:
|
||||
- name: DATABASE_USER
|
||||
value: '${database.user}'
|
||||
- name: DATABASE_PASSWORD
|
||||
value: '${database.password}'
|
||||
- name: DATABASE_SVC_HOSTNAME
|
||||
value: '${database.svc.hostname}'
|
||||
- name: DATABASE_NAME
|
||||
value: '${database.name}'
|
||||
18
todo-api-swarm/src/main/fabric8/route.yml
Normal file
18
todo-api-swarm/src/main/fabric8/route.yml
Normal file
@@ -0,0 +1,18 @@
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: Route
|
||||
metadata:
|
||||
labels:
|
||||
expose: "true"
|
||||
app: ${project.artifactId}
|
||||
provider: fabric8
|
||||
version: "1.0"
|
||||
group: com.redhat.training
|
||||
name: ${project.artifactId}
|
||||
spec:
|
||||
host: ${hostname}
|
||||
port:
|
||||
targetPort: ${service-port}
|
||||
to:
|
||||
kind: Service
|
||||
name: ${project.artifactId}
|
||||
21
todo-api-swarm/src/main/fabric8/svc.yml
Normal file
21
todo-api-swarm/src/main/fabric8/svc.yml
Normal file
@@ -0,0 +1,21 @@
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
annotations:
|
||||
fabric8.io/iconUrl: img/icons/camel.svg
|
||||
labels:
|
||||
expose: "true"
|
||||
app: ${project.artifactId}
|
||||
provider: fabric8
|
||||
version: "1.0"
|
||||
group: com.redhat.training
|
||||
name: ${project.artifactId}
|
||||
spec:
|
||||
ports:
|
||||
- name: http
|
||||
port: ${service-port}
|
||||
protocol: TCP
|
||||
targetPort: ${service-port}
|
||||
selector:
|
||||
deploymentconfig: ${project.artifactId}
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.redhat.training.example.todoapi.rest;
|
||||
|
||||
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.core.Response;
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.Produces;
|
||||
|
||||
|
||||
@Path("/hello")
|
||||
public class HelloWorldEndpoint {
|
||||
|
||||
@GET
|
||||
@Produces("text/plain")
|
||||
public Response doGet() {
|
||||
return Response.ok("Hello from WildFly Swarm!").build();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package com.redhat.training.example.todoapi.rest;
|
||||
|
||||
import org.wildfly.swarm.Swarm;
|
||||
import org.wildfly.swarm.datasources.DatasourcesFraction;
|
||||
|
||||
public class Main {
|
||||
public static void main(String[] args) throws Exception {
|
||||
String host = System.getenv("HOST");
|
||||
new Swarm()
|
||||
.fraction(new DatasourcesFraction()
|
||||
.jdbcDriver("mysql", (d) -> {
|
||||
d.driverClassName("com.mysql.cj.jdbc.Driver");
|
||||
d.xaDatasourceClass("com.mysql.jdbc.jdbc2.optional.MysqlXADataSource");
|
||||
d.driverModuleName("com.mysql");
|
||||
})
|
||||
.dataSource("MySQLDS", (ds) -> {
|
||||
ds.driverName("mysql");
|
||||
ds.connectionUrl("jdbc:mysql://"+host+":8889/todo");
|
||||
ds.userName("root");
|
||||
ds.password("root");
|
||||
}))
|
||||
.start()
|
||||
.deploy();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.redhat.training.model;
|
||||
|
||||
import java.net.InetAddress;
|
||||
|
||||
public class Host {
|
||||
|
||||
private String ip;
|
||||
private String hostname;
|
||||
|
||||
public Host(String ip, String hostname) {
|
||||
this.ip = ip;
|
||||
this.hostname = hostname;
|
||||
}
|
||||
|
||||
public String getIp() {
|
||||
return ip;
|
||||
}
|
||||
|
||||
public String getHostname() {
|
||||
return hostname;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
package com.redhat.training.model;
|
||||
|
||||
import javax.persistence.*;
|
||||
|
||||
@Entity
|
||||
public class Item {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long id;
|
||||
|
||||
private String description;
|
||||
|
||||
private Boolean done = false;
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public Boolean isDone() {
|
||||
return done;
|
||||
}
|
||||
|
||||
public void setDone(Boolean done) {
|
||||
this.done = done;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) { return true; }
|
||||
if (o == null || getClass() != o.getClass()) { return false; }
|
||||
|
||||
Item item = (Item) o;
|
||||
|
||||
return id.equals(item.id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return id.hashCode();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package com.redhat.training.rest;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import javax.ws.rs.container.ContainerRequestContext;
|
||||
import javax.ws.rs.container.ContainerRequestFilter;
|
||||
import javax.ws.rs.container.PreMatching;
|
||||
import javax.ws.rs.core.Response;
|
||||
import javax.ws.rs.ext.Provider;
|
||||
|
||||
@Provider
|
||||
@PreMatching
|
||||
public class CORSRequestFilter implements ContainerRequestFilter {
|
||||
|
||||
private final static Logger log = Logger.getLogger(CORSRequestFilter.class.getName());
|
||||
|
||||
@Override
|
||||
public void filter(ContainerRequestContext requestCtx) throws IOException {
|
||||
log.fine("Executing REST request filter");
|
||||
|
||||
// When HttpMethod comes as OPTIONS, just acknowledge that it accepts...
|
||||
if (requestCtx.getRequest().getMethod().equals( "OPTIONS" )) {
|
||||
log.fine("HTTP Method (OPTIONS) - Detected!");
|
||||
|
||||
// Just send a OK signal back to the browser
|
||||
requestCtx.abortWith(Response.status(Response.Status.OK).build());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package com.redhat.training.rest;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import javax.ws.rs.container.ContainerRequestContext;
|
||||
import javax.ws.rs.container.ContainerResponseContext;
|
||||
import javax.ws.rs.container.ContainerResponseFilter;
|
||||
import javax.ws.rs.container.PreMatching;
|
||||
import javax.ws.rs.core.MultivaluedMap;
|
||||
import javax.ws.rs.core.Response;
|
||||
import javax.ws.rs.ext.Provider;
|
||||
|
||||
@Provider
|
||||
@PreMatching
|
||||
public class CORSResponseFilter implements ContainerResponseFilter {
|
||||
|
||||
private final static Logger log = Logger.getLogger(CORSResponseFilter.class.getName());
|
||||
|
||||
@Override
|
||||
public void filter(ContainerRequestContext requestCtx, ContainerResponseContext responseCtx) throws IOException {
|
||||
log.fine("Executing REST response filter");
|
||||
|
||||
MultivaluedMap<String, Object> headers = responseCtx.getHeaders();
|
||||
|
||||
headers.add("Access-Control-Allow-Origin", "*");
|
||||
headers.add("Access-Control-Allow-Methods", "GET, POST, DELETE, PUT, OPTIONS");
|
||||
headers.add("Access-Control-Allow-Headers", "X-Requested-With, Content-Type");
|
||||
//responseCtx.getHeaders().add( "Access-Control-Allow-Credentials", "true" );
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package com.redhat.training.rest;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
|
||||
import javax.ejb.Stateless;
|
||||
import javax.ws.rs.Consumes;
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
|
||||
import com.redhat.training.model.Host;
|
||||
|
||||
@Stateless
|
||||
@Path("host")
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
public class HostService {
|
||||
|
||||
@GET
|
||||
public Host getHostInfo() throws UnknownHostException {
|
||||
InetAddress address = InetAddress.getLocalHost();
|
||||
Host host = new Host(address.getHostAddress(), address.getHostName());
|
||||
return host;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,97 @@
|
||||
package com.redhat.training.rest;
|
||||
|
||||
import com.redhat.training.model.Item;
|
||||
import com.redhat.training.ui.PaginatedListWrapper;
|
||||
|
||||
import javax.ejb.Stateless;
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.PersistenceContext;
|
||||
import javax.persistence.Query;
|
||||
import javax.persistence.TypedQuery;
|
||||
import javax.ws.rs.*;
|
||||
import javax.ws.rs.core.Application;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Stateless
|
||||
@Path("items")
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
public class ItemService extends Application {
|
||||
|
||||
@PersistenceContext
|
||||
private EntityManager entityManager;
|
||||
|
||||
private Integer countItems() {
|
||||
Query query = entityManager.createQuery("SELECT COUNT(i.id) FROM Item i");
|
||||
return ((Long) query.getSingleResult()).intValue();
|
||||
}
|
||||
|
||||
private List<Item> findItems(int startPosition, int maxResults, String sortFields, String sortDirections) {
|
||||
TypedQuery<Item> query =
|
||||
entityManager.createQuery("SELECT i FROM Item i ORDER BY i." + sortFields + " " + sortDirections,
|
||||
Item.class);
|
||||
query.setFirstResult(startPosition);
|
||||
query.setMaxResults(maxResults);
|
||||
return query.getResultList();
|
||||
}
|
||||
|
||||
private PaginatedListWrapper findItems(PaginatedListWrapper wrapper) {
|
||||
wrapper.setTotalResults(countItems());
|
||||
int start = (wrapper.getCurrentPage() - 1) * wrapper.getPageSize();
|
||||
wrapper.setList(findItems(start,
|
||||
wrapper.getPageSize(),
|
||||
wrapper.getSortFields(),
|
||||
wrapper.getSortDirections()));
|
||||
return wrapper;
|
||||
}
|
||||
|
||||
@GET
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
public PaginatedListWrapper listItems(@DefaultValue("1")
|
||||
@QueryParam("page")
|
||||
Integer page,
|
||||
@DefaultValue("id")
|
||||
@QueryParam("sortFields")
|
||||
String sortFields,
|
||||
@DefaultValue("asc")
|
||||
@QueryParam("sortDirections")
|
||||
String sortDirections) {
|
||||
PaginatedListWrapper paginatedListWrapper = new PaginatedListWrapper();
|
||||
paginatedListWrapper.setCurrentPage(page);
|
||||
paginatedListWrapper.setSortFields(sortFields);
|
||||
paginatedListWrapper.setSortDirections(sortDirections);
|
||||
paginatedListWrapper.setPageSize(10);
|
||||
return findItems(paginatedListWrapper);
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("{id}")
|
||||
public Item getitem(@PathParam("id") Long id) {
|
||||
return entityManager.find(Item.class, id);
|
||||
}
|
||||
|
||||
@POST
|
||||
public Item saveItem(Item item) {
|
||||
if (item.getId() == null) {
|
||||
Item itemToSave = new Item();
|
||||
itemToSave.setDescription(item.getDescription());
|
||||
itemToSave.setDone(item.isDone());
|
||||
entityManager.persist(item);
|
||||
} else {
|
||||
Item itemToUpdate = getitem(item.getId());
|
||||
itemToUpdate.setDescription(item.getDescription());
|
||||
itemToUpdate.setDone(item.isDone());
|
||||
item = entityManager.merge(itemToUpdate);
|
||||
}
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
@DELETE
|
||||
@Path("{id}")
|
||||
public void deleteItem(@PathParam("id") Long id) {
|
||||
entityManager.remove(getitem(id));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package com.redhat.training.rest;
|
||||
|
||||
import javax.ws.rs.ApplicationPath;
|
||||
import javax.ws.rs.core.Application;
|
||||
|
||||
@ApplicationPath("/todo/api")
|
||||
public class RestApplication extends Application {
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
package com.redhat.training.ui;
|
||||
|
||||
import com.redhat.training.model.Item;
|
||||
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
@XmlRootElement
|
||||
public class PaginatedListWrapper implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private Integer currentPage;
|
||||
private Integer pageSize;
|
||||
private Integer totalResults;
|
||||
|
||||
private String sortFields;
|
||||
private String sortDirections;
|
||||
@XmlElement
|
||||
private List<Item> list;
|
||||
|
||||
public Integer getCurrentPage() {
|
||||
return currentPage;
|
||||
}
|
||||
|
||||
public void setCurrentPage(Integer currentPage) {
|
||||
this.currentPage = currentPage;
|
||||
}
|
||||
|
||||
public Integer getPageSize() {
|
||||
return pageSize;
|
||||
}
|
||||
|
||||
public void setPageSize(Integer pageSize) {
|
||||
this.pageSize = pageSize;
|
||||
}
|
||||
|
||||
public Integer getTotalResults() {
|
||||
return totalResults;
|
||||
}
|
||||
|
||||
public void setTotalResults(Integer totalResults) {
|
||||
this.totalResults = totalResults;
|
||||
}
|
||||
|
||||
public String getSortFields() {
|
||||
return sortFields;
|
||||
}
|
||||
|
||||
public void setSortFields(String sortFields) {
|
||||
this.sortFields = sortFields;
|
||||
}
|
||||
|
||||
public String getSortDirections() {
|
||||
return sortDirections;
|
||||
}
|
||||
|
||||
public void setSortDirections(String sortDirections) {
|
||||
this.sortDirections = sortDirections;
|
||||
}
|
||||
|
||||
public List<Item> getList() {
|
||||
return list;
|
||||
}
|
||||
|
||||
public void setList(List<Item> list) {
|
||||
this.list = list;
|
||||
}
|
||||
}
|
||||
18
todo-api-swarm/src/main/resources/META-INF/persistence.xml
Normal file
18
todo-api-swarm/src/main/resources/META-INF/persistence.xml
Normal file
@@ -0,0 +1,18 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<persistence version="2.1"
|
||||
xmlns="http://xmlns.jcp.org/xml/ns/persistence"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
|
||||
<persistence-unit name="Items" transaction-type="JTA">
|
||||
<jta-data-source>java:jboss/datasources/MySQLDS</jta-data-source>
|
||||
<properties>
|
||||
<property name="javax.persistence.schema-generation.database.action" value="none"/>
|
||||
<property name="javax.persistence.schema-generation.create-source" value="script"/>
|
||||
<property name="javax.persistence.schema-generation.drop-source" value="script"/>
|
||||
<property name="javax.persistence.schema-generation.create-script-source" value="sql/create.sql"/>
|
||||
<property name="javax.persistence.schema-generation.drop-script-source" value="sql/drop.sql"/>
|
||||
<property name="javax.persistence.sql-load-script-source" value="sql/load.sql"/>
|
||||
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5InnoDBDialect" />
|
||||
</properties>
|
||||
</persistence-unit>
|
||||
</persistence>
|
||||
@@ -0,0 +1,16 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
~ Copyright 2015 Red Hat, Inc. and/or its affiliates.
|
||||
~
|
||||
~ Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
|
||||
-->
|
||||
<module xmlns="urn:jboss:module:1.3" name="com.mysql">
|
||||
|
||||
<resources>
|
||||
<artifact name="mysql:mysql-connector-java:6.0.6"/>
|
||||
</resources>
|
||||
<dependencies>
|
||||
<module name="javax.api"/>
|
||||
<module name="javax.transaction.api"/>
|
||||
</dependencies>
|
||||
</module>
|
||||
13
todo-api-swarm/src/main/resources/project-defaults.yml
Normal file
13
todo-api-swarm/src/main/resources/project-defaults.yml
Normal file
@@ -0,0 +1,13 @@
|
||||
swarm:
|
||||
datasources:
|
||||
jdbc-drivers:
|
||||
com.mysql:
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
xa-datasource-class-name: com.mysql.jdbc.jdbc2.optional.MysqlXADataSource
|
||||
driver-module-name: com.mysql
|
||||
data-sources:
|
||||
MySQLDS:
|
||||
driver-name: com.mysql
|
||||
connection-url: jdbc:mysql://${env.DATABASE_SVC_HOSTNAME}:3306/${env.DATABASE_NAME}
|
||||
user-name: ${env.DATABASE_USER}
|
||||
password: ${env.DATABASE_PASSWORD}
|
||||
1
todo-api-swarm/src/main/resources/sql/create.sql
Normal file
1
todo-api-swarm/src/main/resources/sql/create.sql
Normal file
@@ -0,0 +1 @@
|
||||
CREATE TABLE `Item` (`id` BIGINT not null auto_increment primary key, `description` VARCHAR(100), `done` BIT);
|
||||
1
todo-api-swarm/src/main/resources/sql/drop.sql
Normal file
1
todo-api-swarm/src/main/resources/sql/drop.sql
Normal file
@@ -0,0 +1 @@
|
||||
DROP TABLE `Item`;
|
||||
2
todo-api-swarm/src/main/resources/sql/load.sql
Normal file
2
todo-api-swarm/src/main/resources/sql/load.sql
Normal file
@@ -0,0 +1,2 @@
|
||||
INSERT INTO `Item` (`id`,`description`,`done`) VALUES (1,'Pick up newspaper', 0);
|
||||
INSERT INTO `Item` (`id`,`description`,`done`) VALUES (2,'Buy groceries', 1);
|
||||
18
todo-api-swarm/target/classes/META-INF/persistence.xml
Normal file
18
todo-api-swarm/target/classes/META-INF/persistence.xml
Normal file
@@ -0,0 +1,18 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<persistence version="2.1"
|
||||
xmlns="http://xmlns.jcp.org/xml/ns/persistence"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
|
||||
<persistence-unit name="Items" transaction-type="JTA">
|
||||
<jta-data-source>java:jboss/datasources/MySQLDS</jta-data-source>
|
||||
<properties>
|
||||
<property name="javax.persistence.schema-generation.database.action" value="none"/>
|
||||
<property name="javax.persistence.schema-generation.create-source" value="script"/>
|
||||
<property name="javax.persistence.schema-generation.drop-source" value="script"/>
|
||||
<property name="javax.persistence.schema-generation.create-script-source" value="sql/create.sql"/>
|
||||
<property name="javax.persistence.schema-generation.drop-script-source" value="sql/drop.sql"/>
|
||||
<property name="javax.persistence.sql-load-script-source" value="sql/load.sql"/>
|
||||
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5InnoDBDialect" />
|
||||
</properties>
|
||||
</persistence-unit>
|
||||
</persistence>
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,16 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
~ Copyright 2015 Red Hat, Inc. and/or its affiliates.
|
||||
~
|
||||
~ Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
|
||||
-->
|
||||
<module xmlns="urn:jboss:module:1.3" name="com.mysql">
|
||||
|
||||
<resources>
|
||||
<artifact name="mysql:mysql-connector-java:6.0.6"/>
|
||||
</resources>
|
||||
<dependencies>
|
||||
<module name="javax.api"/>
|
||||
<module name="javax.transaction.api"/>
|
||||
</dependencies>
|
||||
</module>
|
||||
13
todo-api-swarm/target/classes/project-defaults.yml
Normal file
13
todo-api-swarm/target/classes/project-defaults.yml
Normal file
@@ -0,0 +1,13 @@
|
||||
swarm:
|
||||
datasources:
|
||||
jdbc-drivers:
|
||||
com.mysql:
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
xa-datasource-class-name: com.mysql.jdbc.jdbc2.optional.MysqlXADataSource
|
||||
driver-module-name: com.mysql
|
||||
data-sources:
|
||||
MySQLDS:
|
||||
driver-name: com.mysql
|
||||
connection-url: jdbc:mysql://${env.DATABASE_SVC_HOSTNAME}:3306/${env.DATABASE_NAME}
|
||||
user-name: ${env.DATABASE_USER}
|
||||
password: ${env.DATABASE_PASSWORD}
|
||||
1
todo-api-swarm/target/classes/sql/create.sql
Normal file
1
todo-api-swarm/target/classes/sql/create.sql
Normal file
@@ -0,0 +1 @@
|
||||
CREATE TABLE `Item` (`id` BIGINT not null auto_increment primary key, `description` VARCHAR(100), `done` BIT);
|
||||
1
todo-api-swarm/target/classes/sql/drop.sql
Normal file
1
todo-api-swarm/target/classes/sql/drop.sql
Normal file
@@ -0,0 +1 @@
|
||||
DROP TABLE `Item`;
|
||||
2
todo-api-swarm/target/classes/sql/load.sql
Normal file
2
todo-api-swarm/target/classes/sql/load.sql
Normal file
@@ -0,0 +1,2 @@
|
||||
INSERT INTO `Item` (`id`,`description`,`done`) VALUES (1,'Pick up newspaper', 0);
|
||||
INSERT INTO `Item` (`id`,`description`,`done`) VALUES (2,'Buy groceries', 1);
|
||||
Reference in New Issue
Block a user