From: Richard Millet Date: Tue, 18 Sep 2012 20:21:59 +0000 (-0700) Subject: CSPACE-5531: Added code to update refName field of collectionspace_core table when... X-Git-Url: https://git.aero2k.de/?a=commitdiff_plain;h=730c16877c9a8fc69843a4cef510a55c3d95383c;p=tmp%2Fjakarta-migration.git CSPACE-5531: Added code to update refName field of collectionspace_core table when there has been a refName change --- diff --git a/services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/AuthorityResource.java b/services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/AuthorityResource.java index 152e74626..5c599db68 100644 --- a/services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/AuthorityResource.java +++ b/services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/AuthorityResource.java @@ -276,8 +276,10 @@ public abstract class AuthorityResource 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 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 ServiceContext 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 handler = createItemDocumentHandler(ctx, parent.CSID, parent.shortIdentifier); String itemcsid = getRepositoryClient(ctx).create(ctx, handler); @@ -859,7 +861,7 @@ public abstract class AuthorityResource @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 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 ctx = createServiceContext(getItemServiceName(), theUpdate); - ctx.setResourceMap(resourceMap); + ServiceContext 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 handler = createItemDocumentHandler(ctx, parentcsid, null); - ctx.setUriInfo(ui); + DocumentHandler handler = createItemDocumentHandler(ctx, parentcsid, parentShortId); getRepositoryClient(ctx).update(ctx, itemcsid, handler); result = ctx.getOutput(); diff --git a/services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/nuxeo/AuthorityItemDocumentModelHandler.java b/services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/nuxeo/AuthorityItemDocumentModelHandler.java index c0060d725..905a6794e 100644 --- a/services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/nuxeo/AuthorityItemDocumentModelHandler.java +++ b/services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/nuxeo/AuthorityItemDocumentModelHandler.java @@ -353,7 +353,7 @@ public abstract class AuthorityItemDocumentModelHandler } 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; } diff --git a/services/common/src/main/java/org/collectionspace/services/common/AbstractCollectionSpaceResourceImpl.java b/services/common/src/main/java/org/collectionspace/services/common/AbstractCollectionSpaceResourceImpl.java index 3fbdf24e8..d7d533585 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/AbstractCollectionSpaceResourceImpl.java +++ b/services/common/src/main/java/org/collectionspace/services/common/AbstractCollectionSpaceResourceImpl.java @@ -296,7 +296,7 @@ public abstract class AbstractCollectionSpaceResourceImpl null /* the class of the input type */); return ctx; } - + protected ServiceContext createServiceContext( IT input, ResourceMap resourceMap, diff --git a/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/DocumentModelHandler.java b/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/DocumentModelHandler.java index c2570da50..98ab558c6 100644 --- a/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/DocumentModelHandler.java +++ b/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/DocumentModelHandler.java @@ -345,15 +345,6 @@ public abstract class DocumentModelHandler // 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 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 } 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 diff --git a/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RemoteDocumentModelHandlerImpl.java b/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RemoteDocumentModelHandlerImpl.java index f598d597d..013c9daa2 100644 --- a/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RemoteDocumentModelHandlerImpl.java +++ b/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RemoteDocumentModelHandlerImpl.java @@ -225,8 +225,8 @@ public abstract class RemoteDocumentModelHandlerImpl } 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 * @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 } } + 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. */