From: Ray Lee Date: Fri, 18 Oct 2019 02:26:54 +0000 (-0700) Subject: DRYD-768: Sync workflow state on newly created records during SAS sync. X-Git-Url: https://git.aero2k.de/?a=commitdiff_plain;h=56349a11f97d466bf2df697024ee17c305f799b6;p=tmp%2Fjakarta-migration.git DRYD-768: Sync workflow state on newly created records during SAS sync. --- diff --git a/services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/AuthorityServiceUtils.java b/services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/AuthorityServiceUtils.java index e82bb881a..311039d5b 100644 --- a/services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/AuthorityServiceUtils.java +++ b/services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/AuthorityServiceUtils.java @@ -11,6 +11,7 @@ import javax.ws.rs.core.Response; import org.collectionspace.services.client.AuthorityClient; import org.collectionspace.services.client.PoxPayloadIn; +import org.collectionspace.services.client.PoxPayloadOut; import org.collectionspace.services.client.workflow.WorkflowClient; import org.collectionspace.services.common.ServiceMain; import org.collectionspace.services.common.api.RefNameUtils; @@ -20,6 +21,7 @@ import org.collectionspace.services.common.context.MultipartServiceContextImpl; import org.collectionspace.services.common.context.ServiceContext; import org.collectionspace.services.common.document.DocumentException; import org.collectionspace.services.common.document.DocumentNotFoundException; +import org.collectionspace.services.common.document.DocumentReferenceException; import org.collectionspace.services.common.vocabulary.RefNameServiceUtils.AuthorityItemSpecifier; import org.collectionspace.services.common.vocabulary.RefNameServiceUtils.Specifier; import org.collectionspace.services.config.service.ServiceBindingType; @@ -334,6 +336,37 @@ public class AuthorityServiceUtils { return (itemCsid != null); } + public static boolean syncWorkflowState( + ServiceContext ctx, + AuthorityResource authorityResource, + String sasWorkflowState, + String localParentCsid, + String localItemCsid, + DocumentModel localItemDocModel) throws Exception { + String localItemWorkflowState = localItemDocModel.getCurrentLifeCycleState(); + List transitionList = AuthorityServiceUtils.getTransitionList(sasWorkflowState, localItemWorkflowState); + + if (!transitionList.isEmpty()) { + try { + // Transition the local item to the new workflow state. This might involve multiple transitions. + + for (String transition : transitionList) { + authorityResource.updateItemWorkflowWithTransition(ctx, localParentCsid, localItemCsid, transition, AuthorityServiceUtils.DONT_UPDATE_REV, AuthorityServiceUtils.DONT_ROLLBACK_ON_EXCEPTION); + } + } catch (DocumentReferenceException de) { + logger.info(String.format("Failed to soft-delete %s (transition from %s to %s): item is referenced, and will be deprecated instead", localItemCsid, localItemWorkflowState, sasWorkflowState)); + + // One or more of the transitions may have succeeded, so refresh the document model to make sure it + // reflects the current workflow state. + localItemDocModel.refresh(); + + AuthorityServiceUtils.setAuthorityItemDeprecated(ctx, authorityResource, localParentCsid, localItemCsid, localItemDocModel); + } + } + + return true; + } + /** * Mark the authority item as deprecated. * diff --git a/services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/nuxeo/AuthorityDocumentModelHandler.java b/services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/nuxeo/AuthorityDocumentModelHandler.java index 6054afdd7..3b73cf3a1 100644 --- a/services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/nuxeo/AuthorityDocumentModelHandler.java +++ b/services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/nuxeo/AuthorityDocumentModelHandler.java @@ -30,7 +30,6 @@ import java.util.List; import java.util.Map; import java.util.Set; -import javax.ws.rs.core.MultivaluedMap; import javax.ws.rs.core.PathSegment; import javax.ws.rs.core.Response; import javax.ws.rs.core.UriInfo; @@ -41,7 +40,6 @@ import org.collectionspace.services.client.AuthorityClient; import org.collectionspace.services.client.PayloadInputPart; import org.collectionspace.services.client.PoxPayloadIn; import org.collectionspace.services.client.PoxPayloadOut; -import org.collectionspace.services.client.RelationClient; import org.collectionspace.services.client.XmlTools; import org.collectionspace.services.client.workflow.WorkflowClient; import org.collectionspace.services.common.ResourceMap; @@ -68,11 +66,10 @@ import org.collectionspace.services.config.service.ObjectPartType; import org.collectionspace.services.jaxb.AbstractCommonList; import org.collectionspace.services.jaxb.AbstractCommonList.ListItem; import org.collectionspace.services.lifecycle.TransitionDef; -import org.collectionspace.services.nuxeo.client.java.NuxeoDocumentModelHandler; import org.collectionspace.services.nuxeo.client.java.CoreSessionInterface; +import org.collectionspace.services.nuxeo.client.java.NuxeoDocumentModelHandler; import org.collectionspace.services.nuxeo.client.java.NuxeoRepositoryClientImpl; import org.collectionspace.services.nuxeo.util.NuxeoUtils; -import org.collectionspace.services.relation.RelationsCommonList; import org.dom4j.Element; import org.nuxeo.ecm.core.api.ClientException; import org.nuxeo.ecm.core.api.DocumentModel; @@ -448,12 +445,22 @@ public abstract class AuthorityDocumentModelHandler extends NuxeoDoc throw new DocumentException(String.format("Could not create new authority item '%s' during synchronization of the '%s' authority.", itemIdentifier, parentIdentifier)); } - // - // Since we're creating an item that was sourced from the replication server, we need to replicate it locally. - // - authorityResource.updateItemWorkflowWithTransition(ctx, parentIdentifier, itemIdentifier, - WorkflowClient.WORKFLOWTRANSITION_REPLICATE, AuthorityServiceUtils.DONT_UPDATE_REV); // don't update the rev number of the new replicated item (use the rev number of the sourced item) - } + + // Sync the workflow state. + + String itemLocation = response.getHeaderString("Location"); + String itemCsid = itemLocation.substring(itemLocation.lastIndexOf("/") + 1); + + DocumentModel itemDocModel = NuxeoUtils.getDocFromCsid(ctx, getRepositorySession(), itemCsid); + + AuthorityServiceUtils.syncWorkflowState( + ctx, + authorityResource, + getWorkflowState(sasPayloadIn), + parentIdentifier, + itemIdentifier, + itemDocModel); + } /** * Synchronize a remote item (using its refName) with a local item. If the local doesn't yet 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 c3d895e53..30616a1cd 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 @@ -511,36 +511,14 @@ public abstract class AuthorityItemDocumentModelHandler result = true; } } - // - // Check to see if we need to update the local items's workflow state to reflect that of the remote's - // - List transitionList = AuthorityServiceUtils.getTransitionList(sasWorkflowState, localItemWorkflowState); - - if (transitionList.isEmpty() == false) { - AuthorityResource authorityResource = (AuthorityResource) ctx.getResource(getAuthorityServicePath()); // Get the authority (parent) client not the item client - // - // We need to move the local item to the SAS workflow state. This might involve multiple transitions. - // - try { - for (String transition:transitionList) { - authorityResource.updateItemWorkflowWithTransition(ctx, localParentCsid, localItemCsid, transition, AuthorityServiceUtils.DONT_UPDATE_REV, AuthorityServiceUtils.DONT_ROLLBACK_ON_EXCEPTION); - } - } catch (DocumentReferenceException de) { - // - // This exception means we tried unsuccessfully to soft-delete (workflow transition 'delete') an item that still has references to it from other records. - // - logger.info(String.format("Failed to soft-delete %s (transition from %s to %s): item is referenced, and will be deprecated instead", localItemCsid, localItemWorkflowState, sasWorkflowState)); - // One or more of the transitions may have succeeded, so refresh the document model to make sure it - // reflects the current workflow state. - itemDocModel.refresh(); - - // Since we can't soft-delete it, we need to mark it as deprecated since it is soft-deleted on the SAS. - AuthorityServiceUtils.setAuthorityItemDeprecated(ctx, authorityResource, localParentCsid, localItemCsid, itemDocModel); - } - - result = true; - } + AuthorityServiceUtils.syncWorkflowState( + ctx, + (AuthorityResource) ctx.getResource(getAuthorityServicePath()), + sasWorkflowState, + localParentCsid, + localItemCsid, + itemDocModel); return result; }