From: remillet Date: Fri, 15 Apr 2016 22:16:27 +0000 (-0700) Subject: CSPACE-6937: Added the ability to put a record in both a locked state and a deleted... X-Git-Url: https://git.aero2k.de/?a=commitdiff_plain;h=40ea3730fc9f1fe47b628652833c088dd0de808e;p=tmp%2Fjakarta-migration.git CSPACE-6937: Added the ability to put a record in both a locked state and a deleted state. --- diff --git a/3rdparty/nuxeo/nuxeo-platform-collectionspace/src/main/resources/OSGI-INF/default-life-cycle-contrib.xml b/3rdparty/nuxeo/nuxeo-platform-collectionspace/src/main/resources/OSGI-INF/default-life-cycle-contrib.xml index ecfbcbd3e..5c3f95e90 100644 --- a/3rdparty/nuxeo/nuxeo-platform-collectionspace/src/main/resources/OSGI-INF/default-life-cycle-contrib.xml +++ b/3rdparty/nuxeo/nuxeo-platform-collectionspace/src/main/resources/OSGI-INF/default-life-cycle-contrib.xml @@ -102,6 +102,11 @@ Soft-delete the document from the project state + + Delete the locked document from the "locked" state 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 a6cf7781b..e5762339a 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 @@ -68,6 +68,7 @@ import org.slf4j.LoggerFactory; import javax.ws.rs.core.MultivaluedMap; import java.util.ArrayList; +import java.util.Collection; import java.util.Collections; import java.util.HashMap; import java.util.List; @@ -180,7 +181,7 @@ public abstract class AuthorityItemDocumentModelHandler this.inAuthority = inAuthority; } - public String getInAuthority() { + public String getInAuthorityCsid() { return this.inAuthority; } @@ -350,15 +351,16 @@ public abstract class AuthorityItemDocumentModelHandler /** * We consider workflow state changes as a change that should bump the revision number. + * Warning: This method might change the transitionDef's transtionName value */ @Override public void handleWorkflowTransition(DocumentWrapper wrapDoc, TransitionDef transitionDef) throws Exception { - // Update the revision number + // Decide whether or not to update the revision number if (this.getShouldUpdateRevNumber() == true) { // We don't update the rev number of synchronization requests updateRevNumbers(wrapDoc); } } - + /** * This method synchronizes/updates a single authority item resource. */ @@ -549,8 +551,12 @@ public abstract class AuthorityItemDocumentModelHandler // // Next, update the inAuthority (the parent's) rev number // - String inAuthority = (String)documentModel.getProperty(authorityItemCommonSchemaName, AuthorityItemJAXBSchema.IN_AUTHORITY); - DocumentModel inAuthorityDocModel = NuxeoUtils.getDocFromCsid(getServiceContext(), getRepositorySession(), inAuthority); + String inAuthorityCsid = this.getInAuthorityCsid(); + if (inAuthorityCsid == null) { + // When inAuthorityCsid is null, it usually means we're performing and update or synch with the SAS + inAuthorityCsid = (String)documentModel.getProperty(authorityItemCommonSchemaName, AuthorityItemJAXBSchema.IN_AUTHORITY); + } + DocumentModel inAuthorityDocModel = NuxeoUtils.getDocFromCsid(getServiceContext(), getRepositorySession(), inAuthorityCsid); Long parentRev = (Long)inAuthorityDocModel.getProperty(getParentCommonSchemaName(), AuthorityJAXBSchema.REV); if (parentRev == null) { parentRev = new Long(0); @@ -980,7 +986,7 @@ public abstract class AuthorityItemDocumentModelHandler } protected String getInAuthorityValue() { - String inAuthorityValue = getInAuthority(); + String inAuthorityValue = getInAuthorityCsid(); if (Tools.notBlank(inAuthorityValue)) { return inAuthorityValue; } else { diff --git a/services/common/src/main/java/org/collectionspace/services/common/AbstractMultiPartCollectionSpaceResourceImpl.java b/services/common/src/main/java/org/collectionspace/services/common/AbstractMultiPartCollectionSpaceResourceImpl.java index 02193d1b0..ade28820c 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/AbstractMultiPartCollectionSpaceResourceImpl.java +++ b/services/common/src/main/java/org/collectionspace/services/common/AbstractMultiPartCollectionSpaceResourceImpl.java @@ -215,7 +215,7 @@ public abstract class AbstractMultiPartCollectionSpaceResourceImpl extends Abstr return result; } - + private PoxPayloadIn synthEmptyWorkflowInput() { PoxPayloadIn result = null; diff --git a/services/common/src/main/java/org/collectionspace/services/common/workflow/service/nuxeo/WorkflowDocumentModelHandler.java b/services/common/src/main/java/org/collectionspace/services/common/workflow/service/nuxeo/WorkflowDocumentModelHandler.java index 14b773cec..c65da9b96 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/workflow/service/nuxeo/WorkflowDocumentModelHandler.java +++ b/services/common/src/main/java/org/collectionspace/services/common/workflow/service/nuxeo/WorkflowDocumentModelHandler.java @@ -23,6 +23,7 @@ */ package org.collectionspace.services.common.workflow.service.nuxeo; +import java.util.Collection; import java.util.HashMap; import java.util.Map; @@ -153,6 +154,31 @@ public class WorkflowDocumentModelHandler return result; } + /* + * Maps the transition name to handle existing states like "locked" and "deleted". This allows us to do things like lock "deleted" + * records, delete "locked" records, etc. For example, this code maps the transition name "delete" to "delete_locked" on records in the "locked" state. + * As another example, it would map "undelete" to "undelete_locked" for locked records and just "undelete" for records in any other state. + * + * Essentially, this mapping allows REST API clients to use the "delete", "undelete", "lock", "unlock", etc transitions on records no matter what + * their current state. Without this mapping, REST API clients would need to calculate this on their own and use the longer forms like: + * "delete_locked", "undelete_locked", "lock_deleted", "unlocked_deleted", etc. + */ + String getQualifiedTransitionName(DocumentWrapper wrapDoc, TransitionDef transitionDef) { + String result = null; + + String currentTransitionName = result = transitionDef.getName(); // begin with result set to the current name + DocumentModel docModel = wrapDoc.getWrappedObject(); + Collection allowedTransitionList = docModel.getAllowedStateTransitions(); + for (String allowedTransitionName:allowedTransitionList) { + if (allowedTransitionName.startsWith(currentTransitionName)) { + result = allowedTransitionName; + break; // we found a mapping + } + } + + return result; + } + /* * Handle Update (PUT) */ @@ -166,7 +192,7 @@ public class WorkflowDocumentModelHandler try { TransitionDef transitionDef = (TransitionDef)this.getServiceContext().getProperty(WorkflowClient.TRANSITION_ID); - transitionToFollow = transitionDef.getName(); + transitionToFollow = getQualifiedTransitionName(wrapDoc, transitionDef); docModel.followTransition(transitionToFollow); } catch (Exception e) { String msg = "Unable to follow workflow transition to state = " 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 a1c33595a..cf9bd22de 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 @@ -65,6 +65,7 @@ import org.nuxeo.ecm.core.api.ClientException; import org.nuxeo.ecm.core.api.DocumentModel; import org.nuxeo.ecm.core.api.DocumentModelList; import org.nuxeo.ecm.core.api.model.PropertyException; +import org.nuxeo.ecm.core.lifecycle.LifeCycle; import org.nuxeo.ecm.core.lifecycle.LifeCycleService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -168,7 +169,6 @@ public abstract class DocumentModelHandler */ @Override public Lifecycle getLifecycle(String docTypeName) { - org.nuxeo.ecm.core.lifecycle.LifeCycle nuxeoLifecyle; Lifecycle result = null; try { @@ -179,12 +179,10 @@ public abstract class DocumentModelHandler e.printStackTrace(); } - String lifeCycleName; - lifeCycleName = lifeCycleService.getLifeCycleNameFor(docTypeName); - nuxeoLifecyle = lifeCycleService.getLifeCycleByName(lifeCycleName); + String lifeCycleName = lifeCycleService.getLifeCycleNameFor(docTypeName); + org.nuxeo.ecm.core.lifecycle.LifeCycle nuxeoLifecyle = lifeCycleService.getLifeCycleByName(lifeCycleName); result = createCollectionSpaceLifecycle(nuxeoLifecyle); -// result = (Lifecycle)FileTools.getJaxbObjectFromFile(Lifecycle.class, "default-lifecycle.xml"); } catch (Exception e) { // TODO Auto-generated catch block logger.error("Could not retreive life cycle information for Nuxeo doctype: " + docTypeName, e);