chemistry-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fguilla...@apache.org
Subject svn commit: r893764 - in /incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src: main/java/org/apache/chemistry/atompub/server/jaxrs/AbderaResource.java test/java/org/apache/chemistry/atompub/server/AtomPubServerTestCase.java
Date Thu, 24 Dec 2009 14:22:18 GMT
Author: fguillaume
Date: Thu Dec 24 14:22:18 2009
New Revision: 893764

URL: http://svn.apache.org/viewvc?rev=893764&view=rev
Log:
Added JAX-RS object-by-path bindings

Modified:
    incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/jaxrs/AbderaResource.java
    incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/test/java/org/apache/chemistry/atompub/server/AtomPubServerTestCase.java

Modified: incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/jaxrs/AbderaResource.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/jaxrs/AbderaResource.java?rev=893764&r1=893763&r2=893764&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/jaxrs/AbderaResource.java
(original)
+++ incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/jaxrs/AbderaResource.java
Thu Dec 24 14:22:18 2009
@@ -26,6 +26,7 @@
 import javax.ws.rs.POST;
 import javax.ws.rs.PUT;
 import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
 import javax.ws.rs.Produces;
 import javax.ws.rs.core.Context;
 import javax.ws.rs.core.Response;
@@ -302,6 +303,19 @@
     }
 
     @GET
+    @Produces(AtomPub.MEDIA_TYPE_ATOM_ENTRY)
+    @Path("path/{path:.*}")
+    public Response doGetObjectByPath(@PathParam("path") String path) {
+        int skipSegments = 2;
+        for (int i = 0; i < path.length(); i++) {
+            if (path.charAt(i) == '/') {
+                skipSegments++;
+            }
+        }
+        return getAbderaEntry(skipSegments);
+    }
+
+    @GET
     @Path("file/{objectid}")
     public Response doGetFile() {
         // objectid decoded by Abdera getCollectionAdapter

Modified: incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/test/java/org/apache/chemistry/atompub/server/AtomPubServerTestCase.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/test/java/org/apache/chemistry/atompub/server/AtomPubServerTestCase.java?rev=893764&r1=893763&r2=893764&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/test/java/org/apache/chemistry/atompub/server/AtomPubServerTestCase.java
(original)
+++ incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/test/java/org/apache/chemistry/atompub/server/AtomPubServerTestCase.java
Thu Dec 24 14:22:18 2009
@@ -23,6 +23,7 @@
 import java.util.Arrays;
 
 import javax.ws.rs.core.HttpHeaders;
+import javax.xml.namespace.QName;
 
 import junit.framework.TestCase;
 
@@ -144,27 +145,32 @@
         rootFolderId = root.getId();
 
         Folder folder1 = root.newFolder("fold");
+        folder1.setName("folder1");
         folder1.setValue("title", "The folder 1 description");
         folder1.setValue("description", "folder 1 title");
         folder1.save();
 
         Folder folder2 = folder1.newFolder("fold");
+        folder2.setName("folder2");
         folder2.setValue("title", "The folder 2 description");
         folder2.setValue("description", "folder 2 title");
         folder2.save();
 
         Document doc1 = folder1.newDocument("doc");
+        doc1.setName("doc1");
         doc1.setValue("title", "doc 1 title");
         doc1.setValue("description", "The doc 1 descr");
         doc1.save();
 
         Document doc2 = folder2.newDocument("doc");
+        doc2.setName("doc2");
         doc2.setValue("title", "doc 2 title");
         doc2.setValue("description", "The doc 2 descr");
         doc2.save();
         doc2id = doc2.getId();
 
         Document doc3 = folder2.newDocument("doc");
+        doc3.setName("doc3");
         doc3.setValue("title", "doc 3 title");
         doc3.setValue("description", "The doc 3 descr");
         ContentStream cs = new SimpleContentStream(
@@ -254,6 +260,16 @@
         resp.release();
     }
 
+    public void testGetObjectByPath() {
+        ClientResponse resp = client.get(base + "/path/folder1/folder2/doc3");
+        assertEquals(HttpStatus.SC_OK, resp.getStatus());
+        Element ob = resp.getDocument().getRoot();
+        assertNotNull(ob);
+        Element id = ob.getFirstChild(new QName(AtomPub.ATOM_NS, "id"));
+        assertEquals("urn:uuid:" + doc3id, id.getText());
+        resp.release();
+    }
+
     public void testFile() throws Exception {
         HttpMethod method = new GetMethod(base + "/file/" + doc3id);
         int status = new HttpClient().executeMethod(method);



Mime
View raw message