-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added REST services for Addon entity and changed persistence.xml
- Loading branch information
Showing
5 changed files
with
294 additions
and
161 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,78 +1,88 @@ | ||
<?xml version="1.0" encoding="UTF-8" standalone="no"?> | ||
<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> | ||
<parent> | ||
<artifactId>jboss-parent</artifactId> | ||
<groupId>org.jboss</groupId> | ||
<version>12</version> | ||
</parent> | ||
<groupId>org.jboss.forge</groupId> | ||
<artifactId>website</artifactId> | ||
<version>1.0.0-SNAPSHOT</version> | ||
<packaging>war</packaging> | ||
<dependencyManagement> | ||
<dependencies> | ||
<dependency> | ||
<groupId>org.jboss.spec</groupId> | ||
<artifactId>jboss-javaee-6.0</artifactId> | ||
<version>3.0.2.Final</version> | ||
<type>pom</type> | ||
<scope>import</scope> | ||
</dependency> | ||
</dependencies> | ||
</dependencyManagement> | ||
<dependencies> | ||
<dependency> | ||
<groupId>org.hibernate.javax.persistence</groupId> | ||
<artifactId>hibernate-jpa-2.0-api</artifactId> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.jboss.spec.javax.ejb</groupId> | ||
<artifactId>jboss-ejb-api_3.1_spec</artifactId> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>javax.enterprise</groupId> | ||
<artifactId>cdi-api</artifactId> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.jboss.spec.javax.annotation</groupId> | ||
<artifactId>jboss-annotations-api_1.1_spec</artifactId> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.jboss.spec.javax.servlet</groupId> | ||
<artifactId>jboss-servlet-api_3.0_spec</artifactId> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.jboss.spec.javax.faces</groupId> | ||
<artifactId>jboss-jsf-api_2.1_spec</artifactId> | ||
<scope>provided</scope> | ||
</dependency> | ||
</dependencies> | ||
<profiles> | ||
<profile> | ||
<!-- When built in OpenShift the openshift profile will be used when invoking mvn. --> | ||
<!-- Use this profile for any OpenShift specific customization your app will need. --> | ||
<!-- By default that is to put the resulting archive into the deployments folder. --> | ||
<!-- http://maven.apache.org/guides/mini/guide-building-for-different-environments.html --> | ||
<id>openshift</id> | ||
<build> | ||
<finalName>website</finalName> | ||
<plugins> | ||
<plugin> | ||
<artifactId>maven-war-plugin</artifactId> | ||
<version>2.2</version> | ||
<configuration> | ||
<outputDirectory>deployments</outputDirectory> | ||
<warName>ROOT</warName> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</profile> | ||
</profiles> | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>org.jboss</groupId> | ||
<artifactId>jboss-parent</artifactId> | ||
<version>12</version> | ||
</parent> | ||
<groupId>org.jboss.forge</groupId> | ||
<artifactId>website</artifactId> | ||
<version>1.0.0-SNAPSHOT</version> | ||
<packaging>war</packaging> | ||
<dependencyManagement> | ||
<dependencies> | ||
<dependency> | ||
<groupId>javax.ws.rs</groupId> | ||
<artifactId>javax.ws.rs-api</artifactId> | ||
<version>2.0</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.jboss.spec</groupId> | ||
<artifactId>jboss-javaee-6.0</artifactId> | ||
<version>3.0.2.Final</version> | ||
<type>pom</type> | ||
<scope>import</scope> | ||
</dependency> | ||
</dependencies> | ||
</dependencyManagement> | ||
<dependencies> | ||
<dependency> | ||
<groupId>org.hibernate.javax.persistence</groupId> | ||
<artifactId>hibernate-jpa-2.0-api</artifactId> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.jboss.spec.javax.ejb</groupId> | ||
<artifactId>jboss-ejb-api_3.1_spec</artifactId> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>javax.enterprise</groupId> | ||
<artifactId>cdi-api</artifactId> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.jboss.spec.javax.annotation</groupId> | ||
<artifactId>jboss-annotations-api_1.1_spec</artifactId> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.jboss.spec.javax.servlet</groupId> | ||
<artifactId>jboss-servlet-api_3.0_spec</artifactId> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.jboss.spec.javax.faces</groupId> | ||
<artifactId>jboss-jsf-api_2.1_spec</artifactId> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>javax.ws.rs</groupId> | ||
<artifactId>javax.ws.rs-api</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.jboss.spec.javax.transaction</groupId> | ||
<artifactId>jboss-transaction-api_1.1_spec</artifactId> | ||
</dependency> | ||
</dependencies> | ||
<profiles> | ||
<profile> | ||
<id>openshift</id> | ||
<build> | ||
<finalName>website</finalName> | ||
<plugins> | ||
<plugin> | ||
<artifactId>maven-war-plugin</artifactId> | ||
<version>2.2</version> | ||
<configuration> | ||
<outputDirectory>deployments</outputDirectory> | ||
<warName>ROOT</warName> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</profile> | ||
</profiles> | ||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
package org.jboss.forge.rest; | ||
|
||
import java.util.List; | ||
|
||
import javax.ejb.Stateless; | ||
import javax.persistence.EntityManager; | ||
import javax.persistence.NoResultException; | ||
import javax.persistence.PersistenceContext; | ||
import javax.persistence.TypedQuery; | ||
import javax.ws.rs.*; | ||
import javax.ws.rs.core.Response; | ||
import javax.ws.rs.core.Response.Status; | ||
import javax.ws.rs.core.UriBuilder; | ||
import org.jboss.forge.website.model.Addon; | ||
|
||
/** | ||
* | ||
*/ | ||
@Stateless | ||
@Path("/addons") | ||
public class AddonEndpoint | ||
{ | ||
@PersistenceContext(unitName = "website-persistence-unit") | ||
private EntityManager em; | ||
|
||
@POST | ||
@Consumes("application/xml") | ||
public Response create(Addon entity) | ||
{ | ||
em.persist(entity); | ||
return Response.created(UriBuilder.fromResource(AddonEndpoint.class).path(String.valueOf(entity.getId())).build()).build(); | ||
} | ||
|
||
@DELETE | ||
@Path("/{id:[0-9][0-9]*}") | ||
public Response deleteById(@PathParam("id") Long id) | ||
{ | ||
Addon entity = em.find(Addon.class, id); | ||
if (entity == null) | ||
{ | ||
return Response.status(Status.NOT_FOUND).build(); | ||
} | ||
em.remove(entity); | ||
return Response.noContent().build(); | ||
} | ||
|
||
@GET | ||
@Path("/{id:[0-9][0-9]*}") | ||
@Produces("application/xml") | ||
public Response findById(@PathParam("id") Long id) | ||
{ | ||
TypedQuery<Addon> findByIdQuery = em.createQuery("SELECT DISTINCT a FROM Addon a WHERE a.id = :entityId ORDER BY a.id", Addon.class); | ||
findByIdQuery.setParameter("entityId", id); | ||
Addon entity; | ||
try | ||
{ | ||
entity = findByIdQuery.getSingleResult(); | ||
} | ||
catch (NoResultException nre) | ||
{ | ||
entity = null; | ||
} | ||
if (entity == null) | ||
{ | ||
return Response.status(Status.NOT_FOUND).build(); | ||
} | ||
return Response.ok(entity).build(); | ||
} | ||
|
||
@GET | ||
@Produces("application/xml") | ||
public List<Addon> listAll(@QueryParam("start") Integer startPosition, @QueryParam("max") Integer maxResult) | ||
{ | ||
TypedQuery<Addon> findAllQuery = em.createQuery("SELECT DISTINCT a FROM Addon a ORDER BY a.id", Addon.class); | ||
if (startPosition != null) | ||
{ | ||
findAllQuery.setFirstResult(startPosition); | ||
} | ||
if (maxResult != null) | ||
{ | ||
findAllQuery.setMaxResults(maxResult); | ||
} | ||
final List<Addon> results = findAllQuery.getResultList(); | ||
return results; | ||
} | ||
|
||
@PUT | ||
@Path("/{id:[0-9][0-9]*}") | ||
@Consumes("application/xml") | ||
public Response update(Addon entity) | ||
{ | ||
entity = em.merge(entity); | ||
return Response.noContent().build(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package org.jboss.forge.rest; | ||
|
||
import javax.ws.rs.core.Application; | ||
import javax.ws.rs.ApplicationPath; | ||
|
||
@ApplicationPath("/rest") | ||
public class RestApplication extends Application | ||
{ | ||
} |
Oops, something went wrong.