]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
CSPACE-6937-A: Added mapping for SAS workflow states to the client workflow states...
authorremillet <remillet@yahoo.com>
Thu, 21 Apr 2016 04:30:11 +0000 (21:30 -0700)
committerremillet <remillet@yahoo.com>
Thu, 21 Apr 2016 04:30:11 +0000 (21:30 -0700)
services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/AuthorityResource.java
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
services/client/src/main/java/org/collectionspace/services/client/workflow/WorkflowClient.java
services/common/src/main/java/org/collectionspace/services/common/document/DocumentHandler.java
services/common/src/main/java/org/collectionspace/services/common/storage/jpa/JpaDocumentHandler.java
services/common/src/main/java/org/collectionspace/services/common/workflow/service/nuxeo/WorkflowDocumentModelHandler.java
services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RemoteDocumentModelHandlerImpl.java
services/relation/service/src/main/java/org/collectionspace/services/relation/nuxeo/RelationDocumentModelHandler.java

index 198519283cef7247b4c42787c65413998dede568..33c71980682aef9b4b994b2a7fd0f3b802a925b7 100644 (file)
@@ -69,6 +69,7 @@ import org.collectionspace.services.common.document.DocumentException;
 import org.collectionspace.services.common.document.DocumentFilter;
 import org.collectionspace.services.common.document.DocumentHandler;
 import org.collectionspace.services.common.document.DocumentNotFoundException;
+import org.collectionspace.services.common.document.DocumentReferenceException;
 import org.collectionspace.services.common.document.DocumentWrapper;
 import org.collectionspace.services.common.document.Hierarchy;
 import org.collectionspace.services.common.query.QueryManager;
@@ -231,7 +232,7 @@ public abstract class AuthorityResource<AuthCommon, AuthItemHandler>
 
 
     private CsidAndShortIdentifier lookupParentCSIDAndShortIdentifer(
-               ServiceContext itemServiceCtx, // Ok to be null
+               ServiceContext existingCtx, // Ok to be null
                String parentIdentifier,
                String method,
                String op,
@@ -253,8 +254,8 @@ public abstract class AuthorityResource<AuthCommon, AuthItemHandler>
             String whereClause = RefNameServiceUtils.buildWhereForAuthByName(authorityCommonSchemaName, parentShortIdentifier);
             ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx = createServiceContext(getServiceName(), uriInfo);
             CoreSessionInterface repoSession = null;
-            if (itemServiceCtx != null) {
-               repoSession = (CoreSessionInterface) itemServiceCtx.getCurrentRepositorySession();  // We want to use the thread's current repo session
+            if (existingCtx != null) {
+               repoSession = (CoreSessionInterface) existingCtx.getCurrentRepositorySession();  // We want to use the thread's current repo session
             }
             parentcsid = getRepositoryClient(ctx).findDocCSID(repoSession, ctx, whereClause); //FIXME: REM - If the parent has been soft-deleted, should we be looking for the item?
         }
@@ -265,15 +266,20 @@ public abstract class AuthorityResource<AuthCommon, AuthItemHandler>
         return result;
     }
 
-    public String lookupItemCSID(ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx, String itemspecifier, String parentcsid, String method, String op)
-            throws DocumentException {
+    public String lookupItemCSID(ServiceContext<PoxPayloadIn, PoxPayloadOut> existingContext, String itemspecifier, String parentcsid, String method, String op)
+            throws Exception {
         String itemcsid;
         Specifier itemSpec = Specifier.getSpecifier(itemspecifier, method, op);
         if (itemSpec.form == SpecifierForm.CSID) {
             itemcsid = itemSpec.value;
         } else {
             String itemWhereClause = RefNameServiceUtils.buildWhereForAuthItemByName(authorityItemCommonSchemaName, itemSpec.value, parentcsid);
-            itemcsid = getRepositoryClient(ctx).findDocCSID(null, ctx, itemWhereClause); //FIXME: REM - Should we be looking for the 'wf_deleted' query param and filtering on it?
+               MultipartServiceContext ctx = (MultipartServiceContext) createServiceContext(getItemServiceName());
+            CoreSessionInterface repoSession = null;
+            if (existingContext != null) {
+               repoSession = (CoreSessionInterface) existingContext.getCurrentRepositorySession();  // We want to use the thread's current repo session
+            }
+            itemcsid = getRepositoryClient(ctx).findDocCSID(repoSession, ctx, itemWhereClause); //FIXME: REM - Should we be looking for the 'wf_deleted' query param and filtering on it?
         }
         return itemcsid;
     }
@@ -688,16 +694,16 @@ public abstract class AuthorityResource<AuthCommon, AuthItemHandler>
     @PUT
     @Path("{csid}/items/{itemcsid}" + WorkflowClient.SERVICE_PATH + "/{transition}")
     public byte[] updateItemWorkflowWithTransition(
-            @PathParam("csid") String csid,
-            @PathParam("itemcsid") String itemcsid,
+            @PathParam("csid") String parentIdentifier,
+            @PathParam("itemcsid") String itemIdentifier,
             @PathParam("transition") String transition) {
         PoxPayloadOut result = null;
         
         try {            
-            result = updateItemWorkflowWithTransition(NULL_CONTEXT, // Ok to send null
-                       csid, itemcsid, transition, AuthorityServiceUtils.UPDATE_REV);
+            result = updateItemWorkflowWithTransition(NULL_CONTEXT, 
+                       parentIdentifier, itemIdentifier, transition, AuthorityServiceUtils.UPDATE_REV);
         } catch (Exception e) {
-            throw bigReThrow(e, ServiceMessages.UPDATE_FAILED + WorkflowClient.SERVICE_PAYLOAD_NAME, csid);
+            throw bigReThrow(e, ServiceMessages.UPDATE_FAILED + WorkflowClient.SERVICE_PAYLOAD_NAME, parentIdentifier);
         }
         
         return result.getBytes();
@@ -710,16 +716,23 @@ public abstract class AuthorityResource<AuthCommon, AuthItemHandler>
      * @param itemcsid
      * @param transition
      * @return
+     * @throws DocumentReferenceException 
      */
     public PoxPayloadOut updateItemWorkflowWithTransition(ServiceContext existingContext,
-            String parentCsid,
-            String itemCsid,
+            String parentIdentifier,
+            String itemIdentifier,
             String transition,
-            boolean updateRevNumber) {
+            boolean updateRevNumber) throws DocumentReferenceException {
        PoxPayloadOut result = null;
        
         try {
                //
+               // We need CSIDs for both the parent authority and the authority item
+               //
+            CsidAndShortIdentifier csidAndShortId = lookupParentCSIDAndShortIdentifer(existingContext, parentIdentifier, "updateItemWorkflowWithTransition(parent)", "UPDATE_ITEM", null);
+            String itemCsid = lookupItemCSID(existingContext, itemIdentifier, csidAndShortId.CSID, "updateAuthorityItem(item)", "UPDATE_ITEM");
+
+            //
                // Create an empty workflow_commons input part and set it into a new "workflow" sub-resource context
                //
                PoxPayloadIn input = new PoxPayloadIn(WorkflowClient.SERVICE_PAYLOAD_NAME, new WorkflowCommon(), 
@@ -748,8 +761,10 @@ public abstract class AuthorityResource<AuthCommon, AuthItemHandler>
             WorkflowDocumentModelHandler handler = createWorkflowDocumentHandler(ctx);
             getRepositoryClient(ctx).update(ctx, itemCsid, handler);
             result = ctx.getOutput();
+        } catch (DocumentReferenceException de) {
+               throw de;
         } catch (Exception e) {
-            throw bigReThrow(e, ServiceMessages.UPDATE_FAILED + WorkflowClient.SERVICE_PAYLOAD_NAME, itemCsid);
+            throw bigReThrow(e, ServiceMessages.UPDATE_FAILED + WorkflowClient.SERVICE_PAYLOAD_NAME, itemIdentifier);
         }
        
        return result;
@@ -786,7 +801,6 @@ public abstract class AuthorityResource<AuthCommon, AuthItemHandler>
                }
         }
         
-
        return result;
     }
 
@@ -1003,10 +1017,10 @@ public abstract class AuthorityResource<AuthCommon, AuthItemHandler>
             UriTemplateRegistry uriTemplateRegistry,
             UriInfo uriInfo) throws Exception {
        AuthorityRefDocList authRefDocList = null;
-       
-            ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx = createServiceContext(getItemServiceName(), uriInfo);
-            MultivaluedMap<String, String> queryParams = ctx.getQueryParams();
-
+        ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx = createServiceContext(getItemServiceName(), uriInfo);
+        MultivaluedMap<String, String> queryParams = ctx.getQueryParams();
+        //
         // Merge parts of existing context with our new context
         //
         if (existingContext != null && existingContext.getCurrentRepositorySession() != null) {
@@ -1014,16 +1028,14 @@ public abstract class AuthorityResource<AuthCommon, AuthItemHandler>
                ctx.setProperties(existingContext.getProperties());
         }
 
-            String parentcsid = lookupParentCSID(parentspecifier, "getReferencingObjects(parent)", "GET_ITEM_REF_OBJS", uriInfo);
-            String itemcsid = lookupItemCSID(ctx, itemspecifier, parentcsid, "getReferencingObjects(item)", "GET_ITEM_REF_OBJS");
+        String parentcsid = lookupParentCSID(parentspecifier, "getReferencingObjects(parent)", "GET_ITEM_REF_OBJS", uriInfo);
+        String itemcsid = lookupItemCSID(ctx, itemspecifier, parentcsid, "getReferencingObjects(item)", "GET_ITEM_REF_OBJS");
 
-            List<String> serviceTypes = queryParams.remove(ServiceBindingUtils.SERVICE_TYPE_PROP);
-            if(serviceTypes == null || serviceTypes.isEmpty()) {
-               serviceTypes = ServiceBindingUtils.getCommonServiceTypes(true); //CSPACE-5359: Should now include objects, procedures, and authorities
-            }
+        List<String> serviceTypes = queryParams.remove(ServiceBindingUtils.SERVICE_TYPE_PROP);
+        if (serviceTypes == null || serviceTypes.isEmpty()) {
+               serviceTypes = ServiceBindingUtils.getCommonServiceTypes(true); //CSPACE-5359: Should now include objects, procedures, and authorities
+        }
             
-            // Note that we have to create the service context for the Items, not the main service
-            // We omit the parentShortId, only needed when doing a create...
         AuthorityItemDocumentModelHandler handler = (AuthorityItemDocumentModelHandler)createItemDocumentHandler(ctx, parentcsid, null);
         authRefDocList = handler.getReferencingObjects(ctx, uriTemplateRegistry, serviceTypes, getRefPropName(), itemcsid);
 
index 14b346c19a765472f101c61dc76b7ab4fcdeed61..8b694b8cde195f1db5730d9976e188b6230a171f 100644 (file)
@@ -4,11 +4,15 @@ import javax.ws.rs.core.Response;
 
 import org.collectionspace.services.client.AuthorityClient;
 import org.collectionspace.services.client.PoxPayloadIn;
+import org.collectionspace.services.common.api.RefNameUtils.AuthorityTermInfo;
 import org.collectionspace.services.common.context.MultipartServiceContextImpl;
 import org.collectionspace.services.common.context.ServiceContext;
 import org.collectionspace.services.common.vocabulary.RefNameServiceUtils.AuthorityItemSpecifier;
 import org.collectionspace.services.common.vocabulary.RefNameServiceUtils.Specifier;
 import org.collectionspace.services.common.vocabulary.nuxeo.AuthorityIdentifierUtils;
+import org.collectionspace.services.nuxeo.client.java.CoreSessionInterface;
+import org.collectionspace.services.nuxeo.util.NuxeoUtils;
+import org.nuxeo.ecm.core.api.DocumentModel;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -78,4 +82,37 @@ public class AuthorityServiceUtils {
        
        return result;
     }
+    
+    static public boolean setAuthorityItemDeprecated(DocumentModel docModel, String authorityItemCommonSchemaName, Boolean flag) throws Exception {
+       boolean result = false;
+       
+       docModel.setProperty(authorityItemCommonSchemaName, AuthorityItemJAXBSchema.DEPRECATED,
+                       new Boolean(flag));
+       CoreSessionInterface session = (CoreSessionInterface) docModel.getCoreSession();
+       session.saveDocument(docModel);
+       result = true;
+       
+       return result;
+    }
+    
+    /**
+     * Mark the authority item as deprecated.
+     * 
+     * @param ctx
+     * @param itemInfo
+     * @throws Exception
+     */
+    static public boolean markAuthorityItemAsDeprecated(ServiceContext ctx, String authorityItemCommonSchemaName, String itemCsid) throws Exception {
+       boolean result = false;
+       
+       try {
+               DocumentModel docModel = NuxeoUtils.getDocFromCsid(ctx, (CoreSessionInterface)ctx.getCurrentRepositorySession(), itemCsid);
+               result = setAuthorityItemDeprecated(docModel, authorityItemCommonSchemaName, AuthorityServiceUtils.DEPRECATED);
+       } catch (Exception e) {
+               logger.warn(String.format("Could not mark item '%s' as deprecated.", itemCsid), e);
+               throw e;
+       }
+       
+       return result;
+    }
 }
\ No newline at end of file
index da8b055cec31ed4dbd0c188c7f440acb195b6db5..37060f9bc906191b7105b5701856295ebdc4252c 100644 (file)
@@ -243,7 +243,8 @@ public abstract class AuthorityDocumentModelHandler<AuthCommon>
                } catch (DocumentReferenceException de) {
                        logger.info(String.format("Authority item '%s' has existing references and cannot be removed during sync.",
                                        refName), de);
-                       boolean marked = markAuthorityItemAsDeprecated(ctx, itemInfo);
+                       boolean marked = AuthorityServiceUtils.markAuthorityItemAsDeprecated(ctx, authorityItemCommonSchemaName,
+                                       itemInfo.csid);
                        if (marked == true) {
                                result++;
                        }
@@ -263,32 +264,6 @@ public abstract class AuthorityDocumentModelHandler<AuthCommon>
        return result;
     }
     
-    /**
-     * Mark the authority item as deprecated.
-     * 
-     * @param ctx
-     * @param itemInfo
-     * @throws Exception
-     */
-    private boolean markAuthorityItemAsDeprecated(ServiceContext ctx, AuthorityTermInfo itemInfo) throws Exception {
-       boolean result = false;
-       
-       try {
-               String itemCsid = itemInfo.csid;
-               DocumentModel docModel = NuxeoUtils.getDocFromCsid(ctx, (CoreSessionInterface)ctx.getCurrentRepositorySession(), itemCsid);
-               docModel.setProperty(authorityItemCommonSchemaName, AuthorityItemJAXBSchema.DEPRECATED,
-                               new Boolean(AuthorityServiceUtils.DEPRECATED));
-               CoreSessionInterface session = (CoreSessionInterface) ctx.getCurrentRepositorySession();
-               session.saveDocument(docModel);
-               result = true;
-       } catch (Exception e) {
-               logger.warn(String.format("Could not mark item '%s' as deprecated.", itemInfo.name), e);
-               throw e;
-       }
-       
-       return result;
-    }
-    
     /**
      * Gets the list of SAS related items in the local authority.  We exlude items with the "proposed" flags because
      * we want a list with only SAS created items.
@@ -366,7 +341,7 @@ public abstract class AuthorityDocumentModelHandler<AuthCommon>
                                itemIdentifier, parentIdentifier));
        }
        //
-       // Handle the workflow state
+       // Since we're creating an item that was sourced from the SAS, we need to lock it.
        //
        authorityResource.updateItemWorkflowWithTransition(ctx, parentIdentifier, itemIdentifier, 
                        WorkflowClient.WORKFLOWTRANSITION_LOCK, AuthorityServiceUtils.DONT_UPDATE_REV);
@@ -499,7 +474,7 @@ public abstract class AuthorityDocumentModelHandler<AuthCommon>
      * @see org.collectionspace.services.nuxeo.client.java.RemoteDocumentModelHandlerImpl#handleWorkflowTransition(org.collectionspace.services.common.document.DocumentWrapper, org.collectionspace.services.lifecycle.TransitionDef)
      */
     @Override
-    public void handleWorkflowTransition(DocumentWrapper<DocumentModel> wrapDoc, TransitionDef transitionDef) throws Exception {
+    public void handleWorkflowTransition(ServiceContext ctx, DocumentWrapper<DocumentModel> wrapDoc, TransitionDef transitionDef) throws Exception {
        // Update the revision number
        updateRevNumbers(wrapDoc);
     }
index 95804a67b7b78da8dbcfe275e5852d6c197d3126..fd6d102f36b10d9a5525f16ad0678ea6ed4c57f0 100644 (file)
@@ -373,15 +373,20 @@ public abstract class AuthorityItemDocumentModelHandler<AICommon>
      * Warning: This method might change the transitionDef's transtionName value
      */
     @Override
-    public void handleWorkflowTransition(DocumentWrapper<DocumentModel> wrapDoc, TransitionDef transitionDef) throws Exception {
+    public void handleWorkflowTransition(ServiceContext ctx, DocumentWrapper<DocumentModel> wrapDoc, TransitionDef transitionDef) throws Exception {
        // 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);
        }
-       
+       //
+       // We can't delete an authority item that has referencing records.
+       //
        DocumentModel docModel = wrapDoc.getWrappedObject();
-       if (this.hasReferencingObjects(this.getServiceContext(), docModel) == true) {
-               
+       if (transitionDef.getName().equalsIgnoreCase(WorkflowClient.WORKFLOWTRANSITION_DELETE)) {
+                       if (hasReferencingObjects(this.getServiceContext(), docModel) == true) {
+                       throw new DocumentReferenceException(String.format("Cannot delete authority item '%s' because it still has records in the system that are referencing it.  See the service layer log file for details.",
+                                       docModel.getName()));
+                       }
        }
     }
         
@@ -447,20 +452,23 @@ public abstract class AuthorityItemDocumentModelHandler<AICommon>
         //
         // If the workflow states are different, we need to update the local's to reflects the remote's
         //
-        if (localItemWorkflowState.equalsIgnoreCase(sasWorkflowState) == false) {
+       List<String> transitionList = 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.
                //
-               List<String> transitionList = getTransitionList(sasWorkflowState, localItemWorkflowState);
                for (String transition:transitionList) {
-                       if (transition.equalsIgnoreCase(WorkflowClient.WORKFLOWTRANSITION_DELETE) == true) {
-                               if (hasReferencingObjects(ctx, itemDocModel)) {
-                                       throw new DocumentReferenceException(String.format("Cannot soft-delete authority item '%s' because it still has records in the system that are referencing it.  See the service layer log file for details.",
-                                                       itemDocModel.getName()));
-                               }
+                       try {
+                               authorityResource.updateItemWorkflowWithTransition(ctx, localParentCsid, localItemCsid, transition, AuthorityServiceUtils.DONT_UPDATE_REV);
+                       } 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.
+                               //
+                               AuthorityServiceUtils.setAuthorityItemDeprecated(itemDocModel, authorityItemCommonSchemaName, AuthorityServiceUtils.DEPRECATED);  // Since we can't sof-delete it, we need to mark it as deprecated since it is soft-deleted on the SAS
+                               logger.warn(String.format("Could not transition item CSID='%s' from workflow state '%s' to '%s'.  Check the services log file for details.",
+                                               localItemCsid, localItemWorkflowState, sasWorkflowState));
                        }
-                       authorityResource.updateItemWorkflowWithTransition(ctx, localParentCsid, localItemCsid, transition, AuthorityServiceUtils.DONT_UPDATE_REV);
                }
                result = true;
         }
@@ -470,26 +478,66 @@ public abstract class AuthorityItemDocumentModelHandler<AICommon>
     
     /**
      * We need to move the local item to the SAS workflow state.  This might involve multiple transitions.
+     * See table at https://wiki.collectionspace.org/pages/viewpage.action?pageId=162496556
+     * @throws DocumentException 
      */
-    private List<String> getTransitionList(String sasWorkflowState, String localItemWorkflowState) {
-       List<String> result = new ArrayList<String>();
-       
+    private List<String> getTransitionList(String sasWorkflowState, String localItemWorkflowState) throws DocumentException {
+       List<String> result = new ArrayList<String>();          
        //
-       // If the SAS authority items is soft-deleted, we need to mark the local item as soft-deleted
+       // The first set of conditions maps a SAS "project" state to a local state of "locked"
        //
-       if (sasWorkflowState.contains(WorkflowClient.WORKFLOWSTATE_DELETED)) {
-               result.add(WorkflowClient.WORKFLOWTRANSITION_DELETE);
-       } else if (sasWorkflowState.equalsIgnoreCase(WorkflowClient.WORKFLOWSTATE_PROJECT)) {
+       if (sasWorkflowState.equals(WorkflowClient.WORKFLOWSTATE_PROJECT) && localItemWorkflowState.equals(WorkflowClient.WORKFLOWSTATE_PROJECT)) {
+               result.add(WorkflowClient.WORKFLOWTRANSITION_LOCK);
+       } else if (sasWorkflowState.equals(WorkflowClient.WORKFLOWSTATE_PROJECT) && localItemWorkflowState.equals(WorkflowClient.WORKFLOWSTATE_DELETED)) {
                result.add(WorkflowClient.WORKFLOWTRANSITION_UNDELETE);
-       }
-       
+               result.add(WorkflowClient.WORKFLOWTRANSITION_LOCK);
+       } else if (sasWorkflowState.equals(WorkflowClient.WORKFLOWSTATE_PROJECT) && localItemWorkflowState.equals(WorkflowClient.WORKFLOWSTATE_LOCKED)) {
+               // Do nothing.  We're good with this state
+       } else if (sasWorkflowState.equals(WorkflowClient.WORKFLOWSTATE_PROJECT) && localItemWorkflowState.equals(WorkflowClient.WORKFLOWSTATE_LOCKED_DELETED)) {
+               result.add(WorkflowClient.WORKFLOWTRANSITION_UNDELETE);
+       //
+       // The second set of conditions maps a SAS "deleted" state to a local state of "deleted"
+       //
+       } else if (sasWorkflowState.equals(WorkflowClient.WORKFLOWSTATE_DELETED) && localItemWorkflowState.equals(WorkflowClient.WORKFLOWSTATE_PROJECT)) {
+               result.add(WorkflowClient.WORKFLOWTRANSITION_LOCK);
+               result.add(WorkflowClient.WORKFLOWTRANSITION_DELETE);
+       } else if (sasWorkflowState.equals(WorkflowClient.WORKFLOWSTATE_DELETED) && localItemWorkflowState.equals(WorkflowClient.WORKFLOWSTATE_DELETED)) {
+               result.add(WorkflowClient.WORKFLOWTRANSITION_LOCK);
+       } else if (sasWorkflowState.equals(WorkflowClient.WORKFLOWSTATE_DELETED) && localItemWorkflowState.equals(WorkflowClient.WORKFLOWSTATE_LOCKED)) {
+               result.add(WorkflowClient.WORKFLOWTRANSITION_DELETE);
+       } else if (sasWorkflowState.equals(WorkflowClient.WORKFLOWSTATE_DELETED) && localItemWorkflowState.equals(WorkflowClient.WORKFLOWSTATE_LOCKED_DELETED)) {
+               // Do nothing.  We're good with this state
        //
-       // Ensure the local item is always in a "locked" state.  Items sync'd with a SAS should always be locked
+       // The third set of conditions maps a SAS "locked" state to a local state of "locked"
+       //
+       } else if (sasWorkflowState.equals(WorkflowClient.WORKFLOWSTATE_LOCKED) && localItemWorkflowState.equals(WorkflowClient.WORKFLOWSTATE_PROJECT)) {
+               result.add(WorkflowClient.WORKFLOWTRANSITION_LOCK);
+       } else if (sasWorkflowState.equals(WorkflowClient.WORKFLOWSTATE_LOCKED) && localItemWorkflowState.equals(WorkflowClient.WORKFLOWSTATE_DELETED)) {
+               result.add(WorkflowClient.WORKFLOWTRANSITION_UNDELETE);
+               result.add(WorkflowClient.WORKFLOWTRANSITION_LOCK);
+       } else if (sasWorkflowState.equals(WorkflowClient.WORKFLOWSTATE_LOCKED) && localItemWorkflowState.equals(WorkflowClient.WORKFLOWSTATE_LOCKED)) {
+               // Do nothing.  We're good with this state
+       } else if (sasWorkflowState.equals(WorkflowClient.WORKFLOWSTATE_LOCKED) && localItemWorkflowState.equals(WorkflowClient.WORKFLOWSTATE_LOCKED_DELETED)) {
+               result.add(WorkflowClient.WORKFLOWTRANSITION_UNDELETE);
+               //
+       // The last set of conditions maps a SAS "locked_deleted" state to a local state of "deleted"
        //
-       if (localItemWorkflowState.contains(WorkflowClient.WORKFLOWSTATE_LOCKED) != true) { // REM - This may be a bad assumption to make.
+       } else if (sasWorkflowState.equals(WorkflowClient.WORKFLOWSTATE_LOCKED_DELETED) && localItemWorkflowState.equals(WorkflowClient.WORKFLOWSTATE_PROJECT)) {
                result.add(WorkflowClient.WORKFLOWTRANSITION_LOCK);
+               result.add(WorkflowClient.WORKFLOWTRANSITION_DELETE);
+       } else if (sasWorkflowState.equals(WorkflowClient.WORKFLOWSTATE_LOCKED_DELETED) && localItemWorkflowState.equals(WorkflowClient.WORKFLOWSTATE_DELETED)) {
+               result.add(WorkflowClient.WORKFLOWTRANSITION_LOCK);
+       } else if (sasWorkflowState.equals(WorkflowClient.WORKFLOWSTATE_LOCKED_DELETED) && localItemWorkflowState.equals(WorkflowClient.WORKFLOWSTATE_LOCKED)) {
+               result.add(WorkflowClient.WORKFLOWTRANSITION_DELETE);
+       } else if (sasWorkflowState.equals(WorkflowClient.WORKFLOWSTATE_LOCKED_DELETED) && localItemWorkflowState.equals(WorkflowClient.WORKFLOWSTATE_LOCKED_DELETED)) {
+               // Do nothing.  We're good with this state              
+       } else {
+               //
+               // If we get here, we've encountered a SAS workflow state that we don't recognize.
+               //
+               throw new DocumentException(String.format("Encountered an invalid workflow state of '%s' on a SAS authority item.", sasWorkflowState));
        }
-
+       
        return result;
     }
     
@@ -543,7 +591,9 @@ public abstract class AuthorityItemDocumentModelHandler<AICommon>
                result = true;
                logger.error(String.format("Cannot delete authority item '%s' because it still has %d records in the system that are referencing it.",
                                itemCsid, refObjs.getTotalItems()));
-               logReferencingObjects(docModel, refObjs);
+               if (logger.isWarnEnabled() == true) {
+                       logReferencingObjects(docModel, refObjs);
+               }
        }
        
        return result;
@@ -552,8 +602,9 @@ public abstract class AuthorityItemDocumentModelHandler<AICommon>
     private void logReferencingObjects(DocumentModel docModel, AuthorityRefDocList refObjs) {
        List<AuthorityRefDocList.AuthorityRefDocItem> items = refObjs.getAuthorityRefDocItem();
        int i = 0;
+       logger.warn(String.format("The authority item '%s' has the following references:", docModel.getName()));
        for (AuthorityRefDocList.AuthorityRefDocItem item : items) {
-            logger.debug(docModel.getName() + ": list-item[" + i + "] "
+            logger.warn(docModel.getName() + " referenced by : list-item[" + i + "] "
                     + item.getDocType() + "("
                     + item.getDocId() + ") Name:["
                     + item.getDocName() + "] Number:["
@@ -763,7 +814,7 @@ public abstract class AuthorityItemDocumentModelHandler<AICommon>
                String propertyName,
             String itemcsid) throws Exception {
         AuthorityRefDocList authRefDocList = null;
-        CoreSessionInterface repoSession = null;
+        CoreSessionInterface repoSession = (CoreSessionInterface) ctx.getCurrentRepositorySession();
        boolean releaseRepoSession = false;
         
        try {
index 634b66c0c36dce2284fda0aaf5531e5a03fcf6d0..7f9d68432679b5ab904eaa2c2289c06ff4c03089 100644 (file)
@@ -50,6 +50,7 @@ public class WorkflowClient extends AbstractCommonListPoxServiceClientImpl<Workf
        
        public static final String WORKFLOWTRANSITION_LOCK = "lock";
        public static final String WORKFLOWSTATE_LOCKED = "locked";
+       public static final String WORKFLOWSTATE_LOCKED_DELETED = "locked_deleted";
         
     public static final String WORKFLOWTRANSITION_TO = "to";
        //
index 386151d824a8f88a838f8a114c88a42bbadc6cd6..90ed731e09183e62c8547f90dc5b74a5670dc384 100644 (file)
@@ -84,7 +84,7 @@ public interface DocumentHandler<T, TL, WT, WTL> {
     /**
      * updateWorkflowTransition - prepare for a workflow transition
      */
-    public void handleWorkflowTransition(DocumentWrapper<DocumentModel> wrapDoc, TransitionDef transitionDef) throws Exception;
+    public void handleWorkflowTransition(ServiceContext ctx, DocumentWrapper<DocumentModel> wrapDoc, TransitionDef transitionDef) throws Exception;
     
     /**
      * prepareCreate processes documents before creating document in repository
index 65f577013c31a32ac1c82e7043f6f974d2dc631e..9ce64108e95735a55373e234732157b52b766a82 100644 (file)
@@ -3,6 +3,7 @@ package org.collectionspace.services.common.storage.jpa;
 import java.util.List;
 
 import org.collectionspace.services.common.api.RefName;
+import org.collectionspace.services.common.context.ServiceContext;
 import org.collectionspace.services.common.document.AbstractDocumentHandlerImpl;
 import org.collectionspace.services.common.document.DocumentFilter;
 import org.collectionspace.services.common.document.DocumentWrapper;
@@ -65,8 +66,7 @@ public abstract class JpaDocumentHandler<T, TL, WT, WLT>
     }
     
        @Override
-       public void handleWorkflowTransition(
-                       DocumentWrapper<DocumentModel> wrapDoc, TransitionDef transitionDef)
+       public void handleWorkflowTransition(ServiceContext ctx, DocumentWrapper<DocumentModel> wrapDoc, TransitionDef transitionDef)
                        throws Exception {
                // Do nothing.  JPA document handlers do not support workflow transitions yet.
        }
index 696bc4641394980e1698b2f006b334399ed5cb6e..0894119849cfb6b605d42298b8a20a6e305f5296 100644 (file)
@@ -69,9 +69,13 @@ public class WorkflowDocumentModelHandler
        //
        ServiceContext ctx = this.getServiceContext();
        DocumentModelHandler targetDocHandler = (DocumentModelHandler)ctx.getProperty(WorkflowClient.TARGET_DOCHANDLER);
+       
+       // We need to make sure the repo session is available to the handler and its service context
        targetDocHandler.setRepositorySession(this.getRepositorySession()); // Make sure the target doc handler has a repository session to work with
+       targetDocHandler.getServiceContext().setCurrentRepositorySession(this.getRepositorySession());
+       
        TransitionDef transitionDef =  (TransitionDef)ctx.getProperty(WorkflowClient.TRANSITION_ID);
-       targetDocHandler.handleWorkflowTransition(wrapDoc, transitionDef);  // Call the target resouce's handler first
+       targetDocHandler.handleWorkflowTransition(ctx, wrapDoc, transitionDef);  // Call the target resouce's handler first
        //
        // If no exception occurred, then call the super's method
        //
@@ -201,6 +205,6 @@ public class WorkflowDocumentModelHandler
                ClientException ce = new ClientException("Unable to follow workflow transition: " + transitionToFollow);
                throw ce;
        }
-    }    
+    }
 }
 
index a70327bea1f88c36d70273c710d5c0d17b22f5f2..0d46995d5414f9ee133d1981ae4f7f24f53454c9 100644 (file)
@@ -79,13 +79,10 @@ import org.collectionspace.services.relation.RelationsCommon;
 import org.collectionspace.services.relation.RelationsCommonList;
 import org.collectionspace.services.relation.RelationsDocListItem;
 import org.collectionspace.services.relation.RelationshipType;
-
 import org.dom4j.Element;
-
 import org.nuxeo.ecm.core.api.DocumentModel;
 import org.nuxeo.ecm.core.api.DocumentModelList;
 import org.nuxeo.ecm.core.api.model.PropertyException;
-
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -193,9 +190,8 @@ public abstract class   RemoteDocumentModelHandlerImpl<T, TL>
        return result;
     }
     
-
        @Override
-       public void handleWorkflowTransition(DocumentWrapper<DocumentModel> wrapDoc, TransitionDef transitionDef)
+       public void handleWorkflowTransition(ServiceContext ctx, DocumentWrapper<DocumentModel> wrapDoc, TransitionDef transitionDef)
                        throws Exception {
                // Do nothing by default, but children can override if they want.  The real workflow transition happens in the WorkflowDocumemtModelHandler class
        }
index 98d94e5c6fa85818307f83391c9e5d62d1735470..8d30d6c873c6d81927b4db7077e41756bb8f4c2d 100644 (file)
@@ -115,7 +115,7 @@ public class RelationDocumentModelHandler
         * 
         * @see org.collectionspace.services.nuxeo.client.java.RemoteDocumentModelHandlerImpl#handleWorkflowTransition(org.collectionspace.services.common.document.DocumentWrapper, org.collectionspace.services.lifecycle.TransitionDef)
         */
-       public void handleWorkflowTransition(DocumentWrapper<DocumentModel> wrapDoc, TransitionDef transitionDef)
+       public void handleWorkflowTransition(ServiceContext ctx, DocumentWrapper<DocumentModel> wrapDoc, TransitionDef transitionDef)
                        throws Exception {              
                if (subjectOrObjectInWorkflowState(wrapDoc, WorkflowClient.WORKFLOWSTATE_LOCKED) == true) {
                throw new ServiceException(HttpURLConnection.HTTP_FORBIDDEN,