Return-Path: Delivered-To: apmail-incubator-chemistry-commits-archive@minotaur.apache.org Received: (qmail 25255 invoked from network); 21 Jul 2009 17:08:13 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 21 Jul 2009 17:08:13 -0000 Received: (qmail 83937 invoked by uid 500); 21 Jul 2009 17:09:18 -0000 Delivered-To: apmail-incubator-chemistry-commits-archive@incubator.apache.org Received: (qmail 83903 invoked by uid 500); 21 Jul 2009 17:09:18 -0000 Mailing-List: contact chemistry-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: chemistry-dev@incubator.apache.org Delivered-To: mailing list chemistry-commits@incubator.apache.org Received: (qmail 83893 invoked by uid 99); 21 Jul 2009 17:09:18 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 21 Jul 2009 17:09:18 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 21 Jul 2009 17:09:16 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 9C6222388901; Tue, 21 Jul 2009 17:08:56 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit 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 -0000 To: chemistry-commits@incubator.apache.org From: fguillaume@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20090721170856.9C6222388901@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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 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");