You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@marmotta.apache.org by ja...@apache.org on 2014/02/24 11:18:18 UTC

[1/2] git commit: MARMOTTA-440: Improved transaction handling

Repository: marmotta
Updated Branches:
  refs/heads/ldp 16bd00090 -> cfa63186f


MARMOTTA-440: Improved transaction handling


Project: http://git-wip-us.apache.org/repos/asf/marmotta/repo
Commit: http://git-wip-us.apache.org/repos/asf/marmotta/commit/2bd128c9
Tree: http://git-wip-us.apache.org/repos/asf/marmotta/tree/2bd128c9
Diff: http://git-wip-us.apache.org/repos/asf/marmotta/diff/2bd128c9

Branch: refs/heads/ldp
Commit: 2bd128c9f543aceb58c5189e69215048bf85dc4b
Parents: 16bd000
Author: Jakob Frank <ja...@apache.org>
Authored: Mon Feb 24 10:28:25 2014 +0100
Committer: Jakob Frank <ja...@apache.org>
Committed: Mon Feb 24 10:28:25 2014 +0100

----------------------------------------------------------------------
 .../platform/ldp/webservices/LdpWebService.java  | 19 +++++++------------
 1 file changed, 7 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/marmotta/blob/2bd128c9/platform/marmotta-ldp/src/main/java/org/apache/marmotta/platform/ldp/webservices/LdpWebService.java
----------------------------------------------------------------------
diff --git a/platform/marmotta-ldp/src/main/java/org/apache/marmotta/platform/ldp/webservices/LdpWebService.java b/platform/marmotta-ldp/src/main/java/org/apache/marmotta/platform/ldp/webservices/LdpWebService.java
index 2e96207..620fe98 100644
--- a/platform/marmotta-ldp/src/main/java/org/apache/marmotta/platform/ldp/webservices/LdpWebService.java
+++ b/platform/marmotta-ldp/src/main/java/org/apache/marmotta/platform/ldp/webservices/LdpWebService.java
@@ -164,10 +164,6 @@ public class LdpWebService {
     @POST
     public Response POST(@Context UriInfo uriInfo, @HeaderParam("Slug") String slug, InputStream postBody, @HeaderParam(HttpHeaders.CONTENT_TYPE) MediaType type)
             throws RepositoryException {
-        /*
-         * TODO: POST implementation
-         * a POST to an existing resource converts this resource into an LDP-C
-         */
 
         final String container = getResourceUri(uriInfo);
         log.debug("POST to LDP-R <{}>", container);
@@ -187,7 +183,7 @@ public class LdpWebService {
             log.trace("Slug-Header urified: {}", localName);
         }
 
-        String newResource = uriInfo.getRequestUriBuilder().path(localName).build().toString();
+        String newResource = UriBuilder.fromUri(java.net.URI.create(container)).path(localName).build().toString();
         final RepositoryConnection con = sesameService.getConnection();
         try {
             final URI c = con.getValueFactory().createURI(container);
@@ -214,7 +210,6 @@ public class LdpWebService {
 
             // Add container triples (Sec. 6.4.3)
             // container and meta triples!
-
             Literal now = con.getValueFactory().createLiteral(new Date());
 
             con.add(c, RDF.TYPE, LDP.BasicContainer, ldpContext);
@@ -226,27 +221,24 @@ public class LdpWebService {
             con.add(s, DCTERMS.created, now, ldpContext);
             con.add(s, DCTERMS.modified, now, ldpContext);
 
-            // LDP-BC for now!
-            con.commit();
-
             // Add the bodyContent
             log.trace("Content ({}) for new resource <{}>", type, newResource);
             final RDFFormat rdfFormat = Rio.getParserFormatForMIMEType(type.toString());
             if (rdfFormat == null) {
                 log.debug("POST creates new LDP-BR with type {}", type);
                 log.warn("LDP-BR not (yet) supported!");
+                con.rollback();
                 return createResponse(Response.Status.NOT_IMPLEMENTED, uriInfo).entity("LDP-BR not (yet) supported").build();
             } else {
                 log.debug("POST creates new LDP-RR, data provided as {}", rdfFormat.getName());
                 try {
-                    con.begin();
-
                     // FIXME: We are (are we?) allowed to filter out server-managed properties here
                     con.add(postBody, newResource, rdfFormat, s);
 
                     con.commit();
                     return createResponse(Response.Status.CREATED, uriInfo).location(java.net.URI.create(newResource)).build();
                 } catch (IOException | RDFParseException e) {
+                    con.rollback();
                     return createResponse(Response.Status.BAD_REQUEST, uriInfo).entity(e.getClass().getSimpleName() + ": "+ e.getMessage()).build();
                 }
             }
@@ -314,7 +306,10 @@ public class LdpWebService {
         final String resource = getResourceUri(uriInfo);
         log.debug("DELETE to <{}>", resource);
 
-        log.warn("NOT CHECKING EXISTENCE OF <{}>", resource);
+        final Response.ResponseBuilder rb404 = check404(resource);
+        if (rb404 != null) {
+            return rb404.build();
+        }
 
         final RepositoryConnection con = sesameService.getConnection();
         try {


[2/2] git commit: MARMOTTA-440: updated some wording from the spec, started patch implementation

Posted by ja...@apache.org.
MARMOTTA-440: updated some wording from the spec, started patch implementation


Project: http://git-wip-us.apache.org/repos/asf/marmotta/repo
Commit: http://git-wip-us.apache.org/repos/asf/marmotta/commit/cfa63186
Tree: http://git-wip-us.apache.org/repos/asf/marmotta/tree/cfa63186
Diff: http://git-wip-us.apache.org/repos/asf/marmotta/diff/cfa63186

Branch: refs/heads/ldp
Commit: cfa63186f8aa3212cb3f3d0dffe3e77758436d0f
Parents: 2bd128c
Author: Jakob Frank <ja...@apache.org>
Authored: Mon Feb 24 11:17:22 2014 +0100
Committer: Jakob Frank <ja...@apache.org>
Committed: Mon Feb 24 11:17:22 2014 +0100

----------------------------------------------------------------------
 .../platform/ldp/webservices/LdpWebService.java | 29 +++++++++++++-------
 1 file changed, 19 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/marmotta/blob/cfa63186/platform/marmotta-ldp/src/main/java/org/apache/marmotta/platform/ldp/webservices/LdpWebService.java
----------------------------------------------------------------------
diff --git a/platform/marmotta-ldp/src/main/java/org/apache/marmotta/platform/ldp/webservices/LdpWebService.java b/platform/marmotta-ldp/src/main/java/org/apache/marmotta/platform/ldp/webservices/LdpWebService.java
index 620fe98..e652ec2 100644
--- a/platform/marmotta-ldp/src/main/java/org/apache/marmotta/platform/ldp/webservices/LdpWebService.java
+++ b/platform/marmotta-ldp/src/main/java/org/apache/marmotta/platform/ldp/webservices/LdpWebService.java
@@ -64,6 +64,7 @@ import java.util.*;
 public class LdpWebService {
 
     public static final String PATH = "ldp";
+    public static final String APPLICATION_RDF_PATCH = "application/rdf-patch";
 
     private Logger log = org.slf4j.LoggerFactory.getLogger(this.getClass());
 
@@ -85,7 +86,7 @@ public class LdpWebService {
     public Response GET(@Context final UriInfo uriInfo, @Context Request r, @HeaderParam(HttpHeaders.ACCEPT) MediaType type)
             throws RepositoryException {
         if (log.isDebugEnabled()) {
-            log.debug("GET to PDP-R <{}>", getResourceUri(uriInfo));
+            log.debug("GET to LDPR <{}>", getResourceUri(uriInfo));
         }
         return doGetHead(uriInfo, r ,type).build();
     }
@@ -94,7 +95,7 @@ public class LdpWebService {
     public Response HEAD(@Context final UriInfo uriInfo, @Context Request r, @HeaderParam(HttpHeaders.ACCEPT) MediaType type)
             throws RepositoryException {
         if (log.isDebugEnabled()) {
-            log.debug("HEAD to PDP-R <{}>", getResourceUri(uriInfo));
+            log.debug("HEAD to LDPR <{}>", getResourceUri(uriInfo));
         }
         return doGetHead(uriInfo, r, type).entity(null).build();
     }
@@ -166,7 +167,7 @@ public class LdpWebService {
             throws RepositoryException {
 
         final String container = getResourceUri(uriInfo);
-        log.debug("POST to LDP-R <{}>", container);
+        log.debug("POST to LDPC <{}>", container);
 
         // TODO: Check if resource (container) exists
         log.warn("NOT CHECKING EXISTENCE OF <{}>", container);
@@ -206,7 +207,7 @@ public class LdpWebService {
                 log.debug("no name clash for <{}>", newResource);
             }
 
-            log.debug("POST to <{}> will create new LDP-R <{}>", container, newResource);
+            log.debug("POST to <{}> will create new LDPR <{}>", container, newResource);
 
             // Add container triples (Sec. 6.4.3)
             // container and meta triples!
@@ -225,12 +226,12 @@ public class LdpWebService {
             log.trace("Content ({}) for new resource <{}>", type, newResource);
             final RDFFormat rdfFormat = Rio.getParserFormatForMIMEType(type.toString());
             if (rdfFormat == null) {
-                log.debug("POST creates new LDP-BR with type {}", type);
+                log.debug("POST creates new LDP-NR with type {}", type);
                 log.warn("LDP-BR not (yet) supported!");
                 con.rollback();
-                return createResponse(Response.Status.NOT_IMPLEMENTED, uriInfo).entity("LDP-BR not (yet) supported").build();
+                return createResponse(Response.Status.NOT_IMPLEMENTED, uriInfo).entity("LDP-BR not (yet) supported\n").build();
             } else {
-                log.debug("POST creates new LDP-RR, data provided as {}", rdfFormat.getName());
+                log.debug("POST creates new LDP-RS, data provided as {}", rdfFormat.getName());
                 try {
                     // FIXME: We are (are we?) allowed to filter out server-managed properties here
                     con.add(postBody, newResource, rdfFormat, s);
@@ -346,7 +347,14 @@ public class LdpWebService {
 
 
     @PATCH
-    public Response PATCH() {
+    public Response PATCH(@Context UriInfo uriInfo,
+                          InputStream postBody, @HeaderParam(HttpHeaders.CONTENT_TYPE) MediaType type) {
+
+        // Check for the supported mime-type
+        if (!type.toString().equals(APPLICATION_RDF_PATCH)) {
+            return createResponse(Response.Status.BAD_REQUEST, uriInfo).entity("Unknown Content-Type: " + type + "\n").build();
+        };
+
         return Response.status(Response.Status.NOT_IMPLEMENTED).build();
     }
 
@@ -366,10 +374,11 @@ public class LdpWebService {
         builder.allow("GET", "HEAD", "POST", "OPTIONS");
 
         // Sec. 6.4.14 / Sec. 8.1
-        builder.header("Accept-Post", "text/turtle, */*");
+        // builder.header("Accept-Post", "text/turtle, */*");
+        builder.header("Accept-Post", "text/turtle");
 
         // TODO: Sec. 5.8.2
-        //builder.header("Accept-Patch", null);
+        builder.header("Accept-Patch", APPLICATION_RDF_PATCH);
 
 
         // TODO: Sec. 6.9.1