]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
DRYD-768: Sync workflow state on newly created records during SAS sync.
authorRay Lee <ray.lee@lyrasis.org>
Fri, 18 Oct 2019 02:26:54 +0000 (19:26 -0700)
committerRay Lee <ray.lee@lyrasis.org>
Fri, 18 Oct 2019 02:26:54 +0000 (19:26 -0700)
services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/AuthorityServiceUtils.java
services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/nuxeo/AuthorityDocumentModelHandler.java
services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/nuxeo/AuthorityItemDocumentModelHandler.java

index e82bb881a7b6ce9395b78cee90533a2bf741fb1e..311039d5b1169a57aff7be89df6ee10967f84a25 100644 (file)
@@ -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<PoxPayloadIn, PoxPayloadOut> ctx,
+                       AuthorityResource authorityResource,
+                       String sasWorkflowState,
+                       String localParentCsid,
+                       String localItemCsid,
+                       DocumentModel localItemDocModel) throws Exception {
+               String localItemWorkflowState = localItemDocModel.getCurrentLifeCycleState();
+               List<String> 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.
         *
index 6054afdd7f107ff6131b2bb0673e431fbe461b03..3b73cf3a1f3b15af616173e0924de862c6450f55 100644 (file)
@@ -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<AuthCommon> 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
index c3d895e53c07b2467bde3bc6486175efcb0e8b79..30616a1cdc44a1d877d626c88d8d2a964ec53c9f 100644 (file)
@@ -511,36 +511,14 @@ public abstract class AuthorityItemDocumentModelHandler<AICommon>
                                result = true;
                        }
                }
-               //
-               // Check to see if we need to update the local items's workflow state to reflect that of the remote's
-               //
-               List<String> 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;
        }