]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
CSPACE-4037 Making it easier to get uri for a doc model, without a docmodelhandler...
authorPatrick Schmitz <pschmitz@berkeley.edu>
Mon, 23 May 2011 22:01:14 +0000 (22:01 +0000)
committerPatrick Schmitz <pschmitz@berkeley.edu>
Mon, 23 May 2011 22:01:14 +0000 (22:01 +0000)
3rdparty/nuxeo/nuxeo-platform-collectionspace/src/main/resources/schemas/collectionspace_core.xsd
services/common/src/main/java/org/collectionspace/services/common/repository/RepositoryClient.java
services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/DocumentModelHandler.java
services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RepositoryJavaClientImpl.java

index 7ef65b122a9203047627434a1ac8fca78e33ea69..7e5416d303bec589bffda0eb2386abe4e5bfa339 100644 (file)
@@ -16,6 +16,7 @@
          \r
 \r
     <xs:element name="tenantId" type="xs:string"/>\r
+    <xs:element name="uri" type="xs:string"/>\r
     <!--<xs:element name="createdAt" type="xs:string"/>-->\r
     <xs:element name="createdAt" type="xs:dateTime"/>\r
     <xs:element name="updatedAt" type="xs:dateTime"/>\r
index 46b76bfa46eee22e050a6461cab36e769ef783fe..bc92588a615ae3afeecc97084f8ec453d97fecee 100644 (file)
@@ -31,6 +31,7 @@ import org.collectionspace.services.common.document.DocumentException;
 import org.collectionspace.services.common.document.DocumentNotFoundException;
 import org.collectionspace.services.common.document.DocumentWrapper;
 import org.collectionspace.services.common.storage.StorageClient;
+import org.nuxeo.ecm.core.api.ClientException;
 import org.nuxeo.ecm.core.api.DocumentModel;
 import org.nuxeo.ecm.core.api.DocumentModelList;
 
@@ -102,7 +103,9 @@ public interface RepositoryClient<IT, OT> extends StorageClient {
     public DocumentWrapper<DocumentModel> getDocFromCsid(ServiceContext<IT, OT> ctx,
                String csid)
             throws Exception;
-    
+
+    public String getDocURI(DocumentWrapper<DocumentModel> wrappedDoc) throws ClientException;
+
     /**
      * Find wrapped documentModel from the Nuxeo repository
      * @param ctx service context under which this method is invoked
index 2fd29648a6175484e1b6191a0f7fc456179422a0..3f518cfbd3c2259045e0d3ea08842043c108713f 100644 (file)
@@ -25,8 +25,11 @@ package org.collectionspace.services.nuxeo.client.java;
 
 import java.util.List;
 
+import org.collectionspace.services.client.PoxPayloadIn;
+import org.collectionspace.services.client.PoxPayloadOut;
 import org.collectionspace.services.common.authorityref.AuthorityRefList;
 import org.collectionspace.services.common.context.ServiceContext;
+import org.collectionspace.services.common.datetime.GregorianCalendarDateTimeUtils;
 import org.collectionspace.services.common.document.AbstractMultipartDocumentHandlerImpl;
 import org.collectionspace.services.common.document.DocumentFilter;
 import org.collectionspace.services.common.document.DocumentWrapper;
@@ -35,6 +38,7 @@ import org.collectionspace.services.nuxeo.client.*;
 import org.collectionspace.services.nuxeo.util.NuxeoUtils;
 import org.collectionspace.services.common.profile.Profiler;
 
+import org.nuxeo.ecm.core.api.ClientException;
 import org.nuxeo.ecm.core.api.DocumentModel;
 import org.nuxeo.ecm.core.api.DocumentModelList;
 import org.nuxeo.ecm.core.api.model.PropertyException;
@@ -58,6 +62,7 @@ public abstract class DocumentModelHandler<T, TL>
 
     public final static String COLLECTIONSPACE_CORE_SCHEMA = "collectionspace_core";
     public final static String COLLECTIONSPACE_CORE_TENANTID = "tenantId";
+    public final static String COLLECTIONSPACE_CORE_URI = "uri";
     public final static String COLLECTIONSPACE_CORE_CREATED_AT = "createdAt";
     public final static String COLLECTIONSPACE_CORE_UPDATED_AT = "updatedAt";
 
@@ -72,6 +77,8 @@ public abstract class DocumentModelHandler<T, TL>
     public String getUri(DocumentModel docModel) {
         return getServiceContextPath()+getCsid(docModel);
     }
+    
+    
     /**
      * getRepositorySession returns Nuxeo Repository Session
      * @return
@@ -93,6 +100,7 @@ public abstract class DocumentModelHandler<T, TL>
        // TODO for sub-docs - check to see if the current service context is a multipart input, 
        // OR a docfragment, and call a variant to fill the DocModel.
         fillAllParts(wrapDoc, Action.CREATE);
+        handleCoreValues(wrapDoc, Action.CREATE);
     }
     
     // TODO for sub-docs - Add completeCreate in which we look for set-aside doc fragments 
@@ -105,6 +113,7 @@ public abstract class DocumentModelHandler<T, TL>
        // TODO for sub-docs - check to see if the current service context is a multipart input, 
        // OR a docfragment, and call a variant to fill the DocModel.
         fillAllParts(wrapDoc, Action.UPDATE);
+        handleCoreValues(wrapDoc, Action.UPDATE);
     }
 
     @Override
@@ -168,4 +177,43 @@ public abstract class DocumentModelHandler<T, TL>
             DocumentWrapper<DocumentModel> docWrapper,
                List<String> authRefFields) throws PropertyException;    
 
+    private void handleCoreValues(DocumentWrapper<DocumentModel> docWrapper, 
+               Action action)  throws ClientException {
+       DocumentModel documentModel = docWrapper.getWrappedObject();
+        String now = GregorianCalendarDateTimeUtils.timestampUTC();
+       if(action==Action.CREATE) {
+               String tenantId = getServiceContext().getTenantId();
+            //
+            // Add the tenant ID value to the new entity
+            //
+            documentModel.setProperty(COLLECTIONSPACE_CORE_SCHEMA,
+                    COLLECTIONSPACE_CORE_TENANTID,
+                    getServiceContext().getTenantId());
+            //
+            // Add the uri value to the new entity
+            //
+            documentModel.setProperty(COLLECTIONSPACE_CORE_SCHEMA,
+                    COLLECTIONSPACE_CORE_URI, getUri(documentModel));
+               //
+               // Add the CSID to the DublinCore title so we can see the CSID in the default
+               // Nuxeo webapp.
+               //
+               try {
+               documentModel.setProperty("dublincore", "title",
+                       documentModel.getName());
+               } catch (Exception x) {
+                       if (logger.isWarnEnabled() == true) {
+                               logger.warn("Could not set the Dublin Core 'title' field on document CSID:" +
+                                               documentModel.getName());
+                       }
+               }
+            documentModel.setProperty(COLLECTIONSPACE_CORE_SCHEMA,
+                    COLLECTIONSPACE_CORE_CREATED_AT, now);
+       }
+       if(action==Action.CREATE || action==Action.UPDATE) {
+            documentModel.setProperty(COLLECTIONSPACE_CORE_SCHEMA,
+                    COLLECTIONSPACE_CORE_UPDATED_AT, now);
+       }
+    }
+
 }
index b4fff66af4bd38180828ef358b1d63a8680f569d..20bcf75e204916b90d194a42468be5756ff1186a 100644 (file)
@@ -108,58 +108,6 @@ public class RepositoryJavaClientImpl implements RepositoryClient<PoxPayloadIn,
        }
     }
     
-    /**
-     * Sets the collection space core values.
-     *
-     * @param ctx the ctx
-     * @param documentModel the document model
-     * @throws ClientException the client exception    //FIXME: REM - This behavior needs to be part of the base DocumentHandler classes, so our JPA services get this behavior as well
-     */
-    private void setCollectionSpaceCoreValues(ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx,
-            DocumentModel documentModel,
-            Action action) throws ClientException {
-       //
-       // Add the CSID to the DublinCore title so we can see the CSID in the default
-       // Nuxeo webapp.
-       //
-       try {
-               documentModel.setProperty("dublincore",
-                       "title",
-                       documentModel.getName());
-       } catch (Exception x) {
-               if (logger.isWarnEnabled() == true) {
-                       logger.warn("Could not set the Dublin Core 'title' field on document CSID:" +
-                                       documentModel.getName());
-               }
-       }
-        //
-        // Add the tenant ID value to the new entity
-        //
-        documentModel.setProperty(DocumentModelHandler.COLLECTIONSPACE_CORE_SCHEMA,
-                DocumentModelHandler.COLLECTIONSPACE_CORE_TENANTID,
-                ctx.getTenantId());
-
-        String now = GregorianCalendarDateTimeUtils.timestampUTC();
-        
-        switch (action) {
-            case CREATE:
-                documentModel.setProperty(DocumentModelHandler.COLLECTIONSPACE_CORE_SCHEMA,
-                                DocumentModelHandler.COLLECTIONSPACE_CORE_CREATED_AT,
-                                now);
-                documentModel.setProperty(DocumentModelHandler.COLLECTIONSPACE_CORE_SCHEMA,
-                                                DocumentModelHandler.COLLECTIONSPACE_CORE_UPDATED_AT,
-                                                now);
-                break;
-            case UPDATE:
-                documentModel.setProperty(DocumentModelHandler.COLLECTIONSPACE_CORE_SCHEMA,
-                                DocumentModelHandler.COLLECTIONSPACE_CORE_UPDATED_AT,
-                                now);
-
-                break;
-            default:
-        }
-    }
-
     /**
      * create document in the Nuxeo repository
      *
@@ -205,7 +153,6 @@ public class RepositoryJavaClientImpl implements RepositoryClient<PoxPayloadIn,
             DocumentWrapper<DocumentModel> wrapDoc = new DocumentWrapperImpl<DocumentModel>(doc);
             handler.handle(Action.CREATE, wrapDoc);
             // create document with documentmodel
-            setCollectionSpaceCoreValues(ctx, doc, Action.CREATE);
             doc = repoSession.createDocument(doc);
             repoSession.save();
 // TODO for sub-docs need to call into the handler to let it deal with subitems. Pass in the id,
@@ -625,6 +572,20 @@ public class RepositoryJavaClientImpl implements RepositoryClient<PoxPayloadIn,
         return result;
     }
 
+    /**
+     * find doc and return CSID from the Nuxeo repository
+     * @param ctx service context under which this method is invoked
+     * @param whereClause where NXQL where clause to get the document
+     * @throws DocumentException
+     */
+    @Override
+    public String getDocURI(DocumentWrapper<DocumentModel> wrappedDoc) throws ClientException {
+       DocumentModel docModel = wrappedDoc.getWrappedObject();
+        String uri = (String)docModel.getProperty(DocumentModelHandler.COLLECTIONSPACE_CORE_SCHEMA,
+                               DocumentModelHandler.COLLECTIONSPACE_CORE_URI);
+        return uri;
+    }
+
 
     /**
      * getFiltered get all documents for an entity service from the Document repository,
@@ -723,7 +684,6 @@ public class RepositoryJavaClientImpl implements RepositoryClient<PoxPayloadIn,
             ((DocumentModelHandler) handler).setRepositorySession(repoSession);
             DocumentWrapper<DocumentModel> wrapDoc = new DocumentWrapperImpl<DocumentModel>(doc);
             handler.handle(Action.UPDATE, wrapDoc);
-            setCollectionSpaceCoreValues(ctx, doc, Action.UPDATE);
             repoSession.saveDocument(doc);
             repoSession.save();
             handler.complete(Action.UPDATE, wrapDoc);