<description>Soft-delete the document from the project state</description>
</transition>
+ <!--
+ Notice the convention used in the transition names below. {transition-verb)_{lifecycle-state} -e.g., delete_locked
+ This convention is critical to the code here: org.collectionspace.services.client.AuthorityClient.AuthorityItemDocumentModelHandler
+ -->
+
<!-- Transitions TO "locked_deleted" state -->
<transition name="delete_locked" destinationState="locked_deleted">
<description>Delete the locked document from the "locked" state</description>
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;
this.inAuthority = inAuthority;
}
- public String getInAuthority() {
+ public String getInAuthorityCsid() {
return this.inAuthority;
}
/**
* 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<DocumentModel> 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.
*/
//
// 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);
}
protected String getInAuthorityValue() {
- String inAuthorityValue = getInAuthority();
+ String inAuthorityValue = getInAuthorityCsid();
if (Tools.notBlank(inAuthorityValue)) {
return inAuthorityValue;
} else {
return result;
}
-
+
private PoxPayloadIn synthEmptyWorkflowInput() {
PoxPayloadIn result = null;
*/
package org.collectionspace.services.common.workflow.service.nuxeo;
+import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
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<DocumentModel> wrapDoc, TransitionDef transitionDef) {
+ String result = null;
+
+ String currentTransitionName = result = transitionDef.getName(); // begin with result set to the current name
+ DocumentModel docModel = wrapDoc.getWrappedObject();
+ Collection<String> allowedTransitionList = docModel.getAllowedStateTransitions();
+ for (String allowedTransitionName:allowedTransitionList) {
+ if (allowedTransitionName.startsWith(currentTransitionName)) {
+ result = allowedTransitionName;
+ break; // we found a mapping
+ }
+ }
+
+ return result;
+ }
+
/*
* Handle Update (PUT)
*/
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 = "
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;
*/
@Override
public Lifecycle getLifecycle(String docTypeName) {
- org.nuxeo.ecm.core.lifecycle.LifeCycle nuxeoLifecyle;
Lifecycle result = null;
try {
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);