server/src/main/java/org/iri_research/renkan/rest/ProjectsResource.java
changeset 47 267d67791e05
parent 45 37c9a17c3284
child 51 3247fccfbd3f
--- a/server/src/main/java/org/iri_research/renkan/rest/ProjectsResource.java	Tue Dec 11 00:01:41 2012 +0100
+++ b/server/src/main/java/org/iri_research/renkan/rest/ProjectsResource.java	Tue Dec 25 21:29:11 2012 +0100
@@ -19,6 +19,7 @@
 import javax.ws.rs.core.Response.Status;
 import javax.ws.rs.core.UriInfo;
 
+import org.iri_research.renkan.models.Project;
 import org.iri_research.renkan.repositories.ProjectsRepository;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -54,18 +55,17 @@
 	@GET
 	@Path("{id : [a-zA-Z\\-0-9]+}")
 	@Produces(MediaType.APPLICATION_JSON + ";charset=utf-8")
-	public String getProject(@PathParam("id") String projectId) {
+	public Project getProjectSd(@PathParam("id") String projectId) {
 		
-		this.logger.debug("GetProject : id " + projectId);
+		this.logger.debug("GetProject: " + projectId);
 				
-		DBCollection projectCollection = this.getCollection();
-		DBObject project = projectCollection.findOne(projectId);
+		Project project = this.projectRepository.findOne(projectId);
 		
 		if (null == project) {
 			throw new WebApplicationException(Status.NOT_FOUND);
 		}
 		
-		return project.toString();				
+		return project;				
 	}
 	
 	@DELETE
@@ -74,21 +74,10 @@
 	public Response deleteProject(@PathParam("id") String projectId) {
 		
 		this.logger.debug("DeleteProject : id " + projectId);
-		DBCollection projectCollection = this.getCollection();
-		BasicDBObject filter = new BasicDBObject("_id", projectId);
-		WriteResult res = projectCollection.remove(filter);
 		
-		if(res.getLastError().ok()) {
-			if(res.getN() == 0) {
-				return Response.noContent().build();
-			}
-			else {
-				return Response.ok(this.uriInfo.getAbsolutePathBuilder().segment(projectId).build().toString() + " deleted").build();
-			}
-		}
-		else {
-			throw new WebApplicationException(Response.status(Status.BAD_REQUEST).entity(res.getError()).build());
-		}
+		this.projectRepository.delete(projectId);
+		return Response.ok(this.uriInfo.getAbsolutePathBuilder().segment(projectId).build().toString() + " deleted").build();
+		
 	}
 
 
@@ -113,6 +102,7 @@
 		
 	}
 	
+	//TODO: uses spring data
 	@GET
 	@Produces(MediaType.APPLICATION_JSON + ";charset=utf-8")
 	public String getProjectList() {
@@ -159,6 +149,7 @@
 		return JSON.serialize(res);
 	}
 	
+	//TODO: rewrite for recursive object and use spring data
 	private Response createOrUpdateProject(String projectId, String projectContent) {
 		
 		if(null == projectContent || projectContent.isEmpty()) {