]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
CSPACE-5531: Added code to update refName field of collectionspace_core table when...
authorRichard Millet <remillet@berkeley.edu>
Tue, 18 Sep 2012 20:21:59 +0000 (13:21 -0700)
committerRichard Millet <remillet@berkeley.edu>
Tue, 18 Sep 2012 20:21:59 +0000 (13:21 -0700)
services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/AuthorityResource.java
services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/nuxeo/AuthorityItemDocumentModelHandler.java
services/common/src/main/java/org/collectionspace/services/common/AbstractCollectionSpaceResourceImpl.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/RemoteDocumentModelHandlerImpl.java

index 152e74626a192384f72b1c412b73bdb6807a88e8..5c599db680e8599d73ba48458e53f0b35ab7a767 100644 (file)
@@ -276,8 +276,10 @@ public abstract class AuthorityResource<AuthCommon, AuthItemHandler>
                return tempResult.CSID;
        }
 
-    private CsidAndShortIdentifier lookupParentCSIDAndShortIdentifer(String parentspecifier,
-               String method, String op,
+    private CsidAndShortIdentifier lookupParentCSIDAndShortIdentifer(
+               String parentspecifier,
+               String method,
+               String op,
                UriInfo uriInfo)
             throws Exception {
         CsidAndShortIdentifier result = new CsidAndShortIdentifier();
@@ -526,7 +528,7 @@ public abstract class AuthorityResource<AuthCommon, AuthItemHandler>
     public Response createAuthorityItem(
                @Context ResourceMap resourceMap,
                @Context UriInfo uriInfo, 
-               @PathParam("csid") String specifier,
+               @PathParam("csid") String parentspecifier,
                String xmlPayload) {
        Response result = null;
        
@@ -535,7 +537,7 @@ public abstract class AuthorityResource<AuthCommon, AuthItemHandler>
             ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx = createServiceContext(getItemServiceName(), input, resourceMap, uriInfo);
 
             // Note: must have the parentShortId, to do the create.
-            CsidAndShortIdentifier parent = lookupParentCSIDAndShortIdentifer(specifier, "createAuthorityItem", "CREATE_ITEM", null);
+            CsidAndShortIdentifier parent = lookupParentCSIDAndShortIdentifer(parentspecifier, "createAuthorityItem", "CREATE_ITEM", null);
             DocumentHandler<?, AbstractCommonList, DocumentModel, DocumentModelList> handler = 
                createItemDocumentHandler(ctx, parent.CSID, parent.shortIdentifier);
             String itemcsid = getRepositoryClient(ctx).create(ctx, handler);
@@ -859,7 +861,7 @@ public abstract class AuthorityResource<AuthCommon, AuthItemHandler>
     @Path("{csid}/items/{itemcsid}")
     public byte[] updateAuthorityItem(
                @Context ResourceMap resourceMap, 
-            @Context UriInfo ui,
+            @Context UriInfo uriInfo,
             @PathParam("csid") String parentspecifier,
             @PathParam("itemcsid") String itemspecifier,
             String xmlPayload) {
@@ -867,16 +869,16 @@ public abstract class AuthorityResource<AuthCommon, AuthItemHandler>
         try {
             PoxPayloadIn theUpdate = new PoxPayloadIn(xmlPayload);
             // Note that we have to create the service context for the Items, not the main service
-            //Laramie CSPACE-3175.  passing null for queryParams, because prior to this refactor, the code moved to lookupParentCSID in this instance called the version of getServiceContext() that passes null
-            String parentcsid = lookupParentCSID(parentspecifier, "updateAuthorityItem(parent)", "UPDATE_ITEM", null);
+            // Laramie CSPACE-3175.  passing null for queryParams, because prior to this refactor, the code moved to lookupParentCSID in this instance called the version of getServiceContext() that passes null
+            CsidAndShortIdentifier csidAndShortId = lookupParentCSIDAndShortIdentifer(parentspecifier, "updateAuthorityItem(parent)", "UPDATE_ITEM", null);
+            String parentcsid = csidAndShortId.CSID;
+            String parentShortId = csidAndShortId.shortIdentifier;
 
-            ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx = createServiceContext(getItemServiceName(), theUpdate);
-            ctx.setResourceMap(resourceMap);
+            ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx = createServiceContext(getItemServiceName(), theUpdate, resourceMap, uriInfo);
             String itemcsid = lookupItemCSID(itemspecifier, parentcsid, "updateAuthorityItem(item)", "UPDATE_ITEM", ctx);
 
             // We omit the parentShortId, only needed when doing a create...
-            DocumentHandler<?, AbstractCommonList, DocumentModel, DocumentModelList> handler = createItemDocumentHandler(ctx, parentcsid, null);
-            ctx.setUriInfo(ui);
+            DocumentHandler<?, AbstractCommonList, DocumentModel, DocumentModelList> handler = createItemDocumentHandler(ctx, parentcsid, parentShortId);
             getRepositoryClient(ctx).update(ctx, itemcsid, handler);
             result = ctx.getOutput();
 
index c0060d725c6fc0c4f09b57ad296c765c0d8ab9a4..905a6794ee9746a2740b7255aa6c374872d14eea 100644 (file)
@@ -353,7 +353,7 @@ public abstract class AuthorityItemDocumentModelHandler<AICommon>
         }
         authItem.displayName = newDisplayName;
         String updatedRefName = authItem.toString();
-        docModel.setProperty(authorityItemCommonSchemaName, AuthorityItemJAXBSchema.REF_NAME, updatedRefName);
+        docModel.setProperty(authorityItemCommonSchemaName, AuthorityItemJAXBSchema.REF_NAME, updatedRefName); // Maybe set collectionspace_core schema here?
         return updatedRefName;
     }
     
index 3fbdf24e83395569e6c9a683d7b54d22520a4388..d7d5335856198db6e78614090bbd6ebbb724eb01 100644 (file)
@@ -296,7 +296,7 @@ public abstract class AbstractCollectionSpaceResourceImpl<IT, OT>
                        null /* the class of the input type */);\r
        return ctx;\r
     }\r
-    \r
+        \r
     protected ServiceContext<IT, OT> createServiceContext(\r
                IT input,\r
                ResourceMap resourceMap,\r
index c2570da50f70c66f2e83a6c3ec05bb5e2649d044..98ab558c6eac865480880797208b1e0c479f9b90 100644 (file)
@@ -345,15 +345,6 @@ public abstract class DocumentModelHandler<T, TL>
             //
             documentModel.setProperty(CollectionSpaceClient.COLLECTIONSPACE_CORE_SCHEMA,
                        CollectionSpaceClient.COLLECTIONSPACE_CORE_URI, getUri(documentModel));
-            //
-            // Add the resource's refname
-            //
-            RefNameInterface refname = getRefName(ctx, documentModel); // Sub-classes may override the getRefName() method called here.
-            if (refname != null) {
-               String refnameStr = refname.toString();
-                   documentModel.setProperty(CollectionSpaceClient.COLLECTIONSPACE_CORE_SCHEMA,
-                               CollectionSpaceClient.COLLECTIONSPACE_CORE_REFNAME, refnameStr);
-            }
                //
                // Add the CSID to the DublinCore title so we can see the CSID in the default
                // Nuxeo webapp.
@@ -367,6 +358,9 @@ public abstract class DocumentModelHandler<T, TL>
                                                documentModel.getName());
                        }
                }
+               //
+               // Add createdAt timestamp and createdBy user
+               //
             documentModel.setProperty(CollectionSpaceClient.COLLECTIONSPACE_CORE_SCHEMA,
                        CollectionSpaceClient.COLLECTIONSPACE_CORE_CREATED_AT, now);
             documentModel.setProperty(CollectionSpaceClient.COLLECTIONSPACE_CORE_SCHEMA,
@@ -374,13 +368,25 @@ public abstract class DocumentModelHandler<T, TL>
        }
        
                if (action == Action.CREATE || action == Action.UPDATE) {
+            //
+            // Add the resource's refname
+            //
+            RefNameInterface refname = getRefName(ctx, documentModel); // Sub-classes may override the getRefName() method called here.
+            if (refname != null) {
+               String refnameStr = refname.toString();
+                   documentModel.setProperty(CollectionSpaceClient.COLLECTIONSPACE_CORE_SCHEMA,
+                               CollectionSpaceClient.COLLECTIONSPACE_CORE_REFNAME, refnameStr);
+            }
+            //
+            // Add updatedAt timestamp and updateBy user
+            //
                        documentModel.setProperty(CollectionSpaceClient.COLLECTIONSPACE_CORE_SCHEMA,
                                        CollectionSpaceClient.COLLECTIONSPACE_CORE_UPDATED_AT, now);
                        documentModel.setProperty(CollectionSpaceClient.COLLECTIONSPACE_CORE_SCHEMA,
                                        CollectionSpaceClient.COLLECTIONSPACE_CORE_UPDATED_BY, userId);
-               }
+               }               
     }
-    
+        
     /*
      * If we see the "rtSbj" query param then we need to perform a CMIS query.  Currently, we have only one
      * CMIS query, but we could add more.  If we do, this method should look at the incoming request and corresponding
index f598d597d4ae64c178453e5f675f4e8f1b93bd75..013c9daa20d717ca787efc59d69ea5d497bafd9a 100644 (file)
@@ -225,8 +225,8 @@ public abstract class   RemoteDocumentModelHandlerImpl<T, TL>
         }
         
         if (supportsHierarchy() == true) {
-            handleRelationsPayload(wrapDoc, true);
-            handleItemRefNameReferenceUpdate();
+            handleRelationsPayload(wrapDoc, true); // refNames in relations payload should refer to pre-updated record refName value
+            handleItemRefNameReferenceUpdate(); // if our record's refName changed, we need to update all the references -including relations.
         }
     }
 
@@ -1391,7 +1391,7 @@ public abstract class   RemoteDocumentModelHandlerImpl<T, TL>
      * @throws Exception 
      */
     protected void handleItemRefNameReferenceUpdate() throws Exception {
-        if (newRefNameOnUpdate != null && oldRefNameOnUpdate != null) {
+        if (hasRefNameUpdate() == true) {
             // We have work to do.
             if (logger.isDebugEnabled()) {
                 String eol = System.getProperty("line.separator");
@@ -1411,6 +1411,24 @@ public abstract class   RemoteDocumentModelHandlerImpl<T, TL>
         }
     }
     
+    protected boolean hasRefNameUpdate() {
+       return (newRefNameOnUpdate != null && oldRefNameOnUpdate != null);
+    }
+
+    protected String getRefNameUpdate() {
+       String result = null;
+       
+       if (hasRefNameUpdate() == true) {
+               result = newRefNameOnUpdate;
+               if (logger.isDebugEnabled() == true) {
+                       logger.debug(String.format("There was a refName update.  New: %s Old: %s" ,
+                                       newRefNameOnUpdate, oldRefNameOnUpdate));
+               }
+       }
+       
+       return result;
+    }
+    
     /*
      * Note: The Vocabulary document handler overrides this method.
      */