You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@clerezza.apache.org by mi...@apache.org on 2009/12/15 17:43:08 UTC

svn commit: r890877 - in /incubator/clerezza/issues/CLEREZZA-26/org.apache.clerezza.platform.content/src/main/java/org/apache/clerezza/platform/content: ContentManager.java ContentPostSupport.java

Author: mir
Date: Tue Dec 15 16:43:08 2009
New Revision: 890877

URL: http://svn.apache.org/viewvc?rev=890877&view=rev
Log:
CLEREZZA-26: applied review comments

Added:
    incubator/clerezza/issues/CLEREZZA-26/org.apache.clerezza.platform.content/src/main/java/org/apache/clerezza/platform/content/ContentPostSupport.java
      - copied, changed from r890855, incubator/clerezza/issues/CLEREZZA-26/org.apache.clerezza.platform.content/src/main/java/org/apache/clerezza/platform/content/ContentManager.java
Removed:
    incubator/clerezza/issues/CLEREZZA-26/org.apache.clerezza.platform.content/src/main/java/org/apache/clerezza/platform/content/ContentManager.java

Copied: incubator/clerezza/issues/CLEREZZA-26/org.apache.clerezza.platform.content/src/main/java/org/apache/clerezza/platform/content/ContentPostSupport.java (from r890855, incubator/clerezza/issues/CLEREZZA-26/org.apache.clerezza.platform.content/src/main/java/org/apache/clerezza/platform/content/ContentManager.java)
URL: http://svn.apache.org/viewvc/incubator/clerezza/issues/CLEREZZA-26/org.apache.clerezza.platform.content/src/main/java/org/apache/clerezza/platform/content/ContentPostSupport.java?p2=incubator/clerezza/issues/CLEREZZA-26/org.apache.clerezza.platform.content/src/main/java/org/apache/clerezza/platform/content/ContentPostSupport.java&p1=incubator/clerezza/issues/CLEREZZA-26/org.apache.clerezza.platform.content/src/main/java/org/apache/clerezza/platform/content/ContentManager.java&r1=890855&r2=890877&rev=890877&view=diff
==============================================================================
--- incubator/clerezza/issues/CLEREZZA-26/org.apache.clerezza.platform.content/src/main/java/org/apache/clerezza/platform/content/ContentManager.java (original)
+++ incubator/clerezza/issues/CLEREZZA-26/org.apache.clerezza.platform.content/src/main/java/org/apache/clerezza/platform/content/ContentPostSupport.java Tue Dec 15 16:43:08 2009
@@ -24,9 +24,11 @@
 import javax.ws.rs.POST;
 import javax.ws.rs.Path;
 
+import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.Response;
 import org.apache.clerezza.jaxrs.utils.form.FormFile;
 import org.apache.clerezza.jaxrs.utils.form.MultiPartBody;
+import org.apache.clerezza.platform.graphprovider.content.ContentGraphProvider;
 import org.apache.clerezza.rdf.core.UriRef;
 import org.apache.felix.scr.annotations.Component;
 import org.apache.felix.scr.annotations.Property;
@@ -43,21 +45,26 @@
 @Service(Object.class)
 @Property(name="javax.ws.rs", boolValue=true)
 @Path("content")
-public class ContentManager {
+public class ContentPostSupport {
 	
 	@Reference
 	private DiscobitsHandler handler;
 
+	@Reference
+	private ContentGraphProvider cgProvider;
+
 	/**
 	 * Uploads a content into the content graph.
 	 * This JAX-RS method is available under the path "content". It requires
-	 * two query parameters: "content", which is the content to be uploaded into
+	 * two form fields: "content", which is the content to be uploaded into
 	 * the content graph and "uri" which is the uri will be the uri of the content
 	 * in the graph.
 	 *
 	 * @param form
-	 * @return Returns a 201 (Created) response, if the info bit was successfully
-	 * uploaded. Returns 400 (Bad Request), if required query parameters are missing.
+	 * @return Returns a Created (201) response, if the info bit was successfully
+	 * uploaded. Returns Bad Request (400) response, if required form fields are
+	 * missing. Returns a Conflict (409) response, if at the specified URI a
+	 * resource already exists.
 	 */
 	@POST
 	@Consumes("multipart/form")
@@ -66,7 +73,13 @@
 		String uri = form.getTextParameterValues("uri")[0];
 		byte[] content = formFile.getContent();
 		if (content == null || uri == null) {
-			return Response.status(400).build();
+			return Response.status(400).entity("Required form field is missing").
+					type(MediaType.TEXT_PLAIN_TYPE).build();
+		}
+		if (cgProvider.getContentGraph().filter(new UriRef(uri), null, null).hasNext()) {
+			return Response.status(Response.Status.CONFLICT).
+					entity("A resource with the specified URI already exists").
+					type(MediaType.TEXT_PLAIN_TYPE).build();
 		}
 		handler.put(new UriRef(uri), formFile.getMediaType(), content);
 		return Response.created(URI.create(uri)).build();