chemistry-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fguilla...@apache.org
Subject svn commit: r796385 - in /incubator/chemistry/trunk/chemistry: chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/ chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/ chemistry-tests/src/main/java/org/apa...
Date Tue, 21 Jul 2009 17:08:56 GMT
Author: fguillaume
Date: Tue Jul 21 17:08:56 2009
New Revision: 796385

URL: http://svn.apache.org/viewvc?rev=796385&view=rev
Log:
CMIS-34: Implement AtomPub document creation (fix returned entry)

Modified:
    incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/APPObject.java
    incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/APPObjectEntry.java
    incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISObjectsCollection.java
    incubator/chemistry/trunk/chemistry/chemistry-tests/src/main/java/org/apache/chemistry/test/BasicTestCase.java

Modified: incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/APPObject.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/APPObject.java?rev=796385&r1=796384&r2=796385&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/APPObject.java
(original)
+++ incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/APPObject.java
Tue Jul 21 17:08:56 2009
@@ -33,6 +33,7 @@
 import org.apache.chemistry.RelationshipDirection;
 import org.apache.chemistry.Type;
 import org.apache.chemistry.atompub.CMIS;
+import org.apache.chemistry.atompub.client.connector.Connector;
 import org.apache.chemistry.atompub.client.connector.Request;
 import org.apache.chemistry.atompub.client.connector.Response;
 import org.apache.chemistry.atompub.client.stax.ReadContext;
@@ -43,7 +44,7 @@
  */
 public abstract class APPObject extends BaseObject {
 
-    protected final APPObjectEntry entry;
+    protected APPObjectEntry entry;
 
     private final Type type;
 
@@ -197,6 +198,9 @@
     }
 
     protected void create() throws ContentManagerException {
+        Connector connector = entry.connection.getConnector();
+        ReadContext ctx = new ReadContext(entry.connection);
+
         String href = entry.getLink(CMIS.LINK_PARENTS); // TODO check this
         if (href == null) {
             throw new IllegalArgumentException(
@@ -207,14 +211,31 @@
         href = href.replaceAll("/object/([0-9a-f-]{36}$)", "/children/$1");
         Request req = new Request(href);
         req.setHeader("Content-Type", "application/atom+xml;type=entry");
-        Response resp = entry.connection.getConnector().postObject(req, entry);
-        if (!resp.isOk()) {
+        Response resp = connector.postObject(req, entry);
+        if (resp.getStatusCode() != 201) { // Created
             throw new ContentManagerException(
                     "Remote server returned error code: "
                             + resp.getStatusCode());
         }
-        // TODO get the response to update the content of the posted document
-        // resp.getEntity(get, APPDocument.class);
+        APPObjectEntry newEntry = (APPObjectEntry) resp.getObject(ctx);
+        // newEntry SHOULD be returned (AtomPub 9.2)...
+        String loc = resp.getHeader("Location");
+        if (loc == null) {
+            throw new ContentManagerException(
+                    "Remote server failed to return a Location header");
+        }
+        if (newEntry == null || !loc.equals(resp.getHeader("Content-Location"))) {
+            // (Content-Location defined by AtomPub 9.2)
+            // fetch actual new entry from Location header
+            // TODO could fetch only a subset of the properties, if deemed ok
+            newEntry = (APPObjectEntry) connector.getObject(ctx, loc);
+            if (newEntry == null) {
+                throw new ContentManagerException(
+                        "Remote server failed to return an entry for Location: "
+                                + loc);
+            }
+        }
+        entry = newEntry;
     }
 
     protected void update() throws ContentManagerException {

Modified: incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/APPObjectEntry.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/APPObjectEntry.java?rev=796385&r1=796384&r2=796385&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/APPObjectEntry.java
(original)
+++ incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/APPObjectEntry.java
Tue Jul 21 17:08:56 2009
@@ -182,7 +182,8 @@
 
     @Override
     public String toString() {
-        return getId();
+        return getClass().getSimpleName() + '(' + getTypeId() + ',' + getId()
+        + ')';
     }
 
     public void writeObjectTo(XMLWriter xw) throws IOException {

Modified: incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISObjectsCollection.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISObjectsCollection.java?rev=796385&r1=796384&r2=796385&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISObjectsCollection.java
(original)
+++ incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISObjectsCollection.java
Tue Jul 21 17:08:56 2009
@@ -209,10 +209,14 @@
         ObjectEntry object = spi.getProperties(objectId, null, null, false,
                 false);
 
-        entry.setUpdated(new Date());
-        entry.getIdElement().setValue(getId(object));
+        // prepare the updated entry to return in the response
+        entry = request.getAbdera().getFactory().newEntry();
+        try {
+            addEntryDetails(request, entry, null, object);
+        } catch (ResponseContextException e) {
+            return createErrorResponse(e);
+        }
         String link = getObjectLink(object.getId(), request);
-        entry.addLink(link, "edit");
         return buildCreateEntryResponse(link, entry);
     }
 

Modified: incubator/chemistry/trunk/chemistry/chemistry-tests/src/main/java/org/apache/chemistry/test/BasicTestCase.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-tests/src/main/java/org/apache/chemistry/test/BasicTestCase.java?rev=796385&r1=796384&r2=796385&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-tests/src/main/java/org/apache/chemistry/test/BasicTestCase.java
(original)
+++ incubator/chemistry/trunk/chemistry/chemistry-tests/src/main/java/org/apache/chemistry/test/BasicTestCase.java
Tue Jul 21 17:08:56 2009
@@ -236,7 +236,11 @@
         assertEquals("GregorianCalendar(2009-07-14T12:00:00.000+05:00)",
                 cal.toString());
         doc.setValue("date", cal);
+        assertNull(doc.getId()); // not yet saved
         doc.save();
+        String id = doc.getId();
+        assertNotNull(id);
+
         // new connection
         closeConn();
         openConn();
@@ -244,6 +248,7 @@
         List<CMISObject> children = root.getChildren(BaseType.DOCUMENT);
         assertEquals(1, children.size());
         doc = (Document) children.get(0);
+        assertEquals(id, doc.getId());
         assertEquals("mydoc", doc.getName());
         assertEquals("mytitle", doc.getString("title"));
         Calendar cal2 = doc.getDateTime("date");



Mime
View raw message