Skip to content

Commit

Permalink
streamline rest endpoints for templates and services
Browse files Browse the repository at this point in the history
  • Loading branch information
sbryzak committed Dec 11, 2014
1 parent f00f666 commit c6ed8a2
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/main/java/org/forgeide/model/ProjectTemplate.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import javax.persistence.GeneratedValue;
import javax.persistence.Id;

import com.fasterxml.jackson.annotation.JsonIgnore;

/**
* Defines an individual project template, based on a specific Maven archetype
*
Expand All @@ -32,6 +34,7 @@ public class ProjectTemplate implements Serializable

private String archetypeVersion;

@JsonIgnore
public Long getId()
{
return id;
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/org/forgeide/model/TemplateService.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.xml.bind.annotation.XmlTransient;

import com.fasterxml.jackson.annotation.JsonIgnore;

/**
* Defines a service that may be activated for a specific project template
Expand Down Expand Up @@ -35,6 +38,7 @@ public class TemplateService implements Serializable

private int steps;

@JsonIgnore
public Long getId()
{
return id;
Expand All @@ -45,6 +49,7 @@ public void setId(Long id)
this.id = id;
}

@JsonIgnore
public ProjectTemplate getTemplate()
{
return template;
Expand Down
30 changes: 30 additions & 0 deletions src/main/java/org/forgeide/service/TemplateServices.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,17 @@ public List<ProjectTemplate> listTemplates()
.getResultList();
}

@GET
@Path("/{code}")
@Produces(MediaType.APPLICATION_JSON)
public ProjectTemplate getTemplate(@PathParam("code") String code)
{
return entityManager.createQuery(
"select t from ProjectTemplate t where t.code = :code", ProjectTemplate.class)
.setParameter("code", code)
.getSingleResult();
}

@GET
@Path("/{code}/services")
@Produces(MediaType.APPLICATION_JSON)
Expand All @@ -50,4 +61,23 @@ public List<TemplateService> listServices(@PathParam("code") String code)
.setParameter("template", t)
.getResultList();
}

@GET
@Path("/{code}/services/{serviceCode}")
@Produces(MediaType.APPLICATION_JSON)
public TemplateService getService(@PathParam("code") String code,
@PathParam("serviceCode") String serviceCode)
{
ProjectTemplate t = entityManager.createQuery(
"select t from ProjectTemplate t where t.code = :code", ProjectTemplate.class)
.setParameter("code", code)
.getSingleResult();

return entityManager.createQuery(
"select s from TemplateService s where s.template = :template and s.code = :code",
TemplateService.class)
.setParameter("template", t)
.setParameter("code", serviceCode)
.getSingleResult();
}
}

0 comments on commit c6ed8a2

Please sign in to comment.