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;
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;
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.
*
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;
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;
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;
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
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;
}