]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
CSPACE-6949: Add rev number comparison test.
authorRichard Millet <remillet@yahoo.com>
Wed, 11 May 2016 15:38:14 +0000 (08:38 -0700)
committerRichard Millet <remillet@yahoo.com>
Wed, 11 May 2016 15:38:14 +0000 (08:38 -0700)
services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/nuxeo/AuthorityDocumentModelHandler.java
services/citation/client/src/test/java/org/collectionspace/services/client/test/CitationAuthorityServiceTest.java
services/client/src/main/java/org/collectionspace/services/client/test/AbstractAuthorityServiceTest.java
services/common/src/main/java/org/collectionspace/services/common/AbstractMultiPartCollectionSpaceResourceImpl.java
services/concept/client/src/test/java/org/collectionspace/services/client/test/ConceptAuthorityServiceTest.java
services/location/client/src/test/java/org/collectionspace/services/client/test/LocationAuthorityServiceTest.java
services/person/client/src/test/java/org/collectionspace/services/client/test/PersonAuthorityServiceTest.java

index 5cf02866df7392825063ced960be976b9f88c0ef..40a590db53a9e1c591a6af41639c2d8ce58f20ae 100644 (file)
@@ -132,7 +132,6 @@ public abstract class AuthorityDocumentModelHandler<AuthCommon>
         // Get the rev number of the authority so we can compare with rev number of shared authority
         //
         DocumentModel docModel = NuxeoUtils.getDocFromSpecifier(ctx, getRepositorySession(), authorityCommonSchemaName, specifier);
-        String authorityCsid = docModel.getName();
         Long localRev = (Long) NuxeoUtils.getProperyValue(docModel, AuthorityJAXBSchema.REV);
         String shortId = (String) NuxeoUtils.getProperyValue(docModel, AuthorityJAXBSchema.SHORT_IDENTIFIER);
         //
@@ -162,9 +161,13 @@ public abstract class AuthorityDocumentModelHandler<AuthCommon>
                        result = true;
                }
                //
-               // We need to transition the authority into a replicated state now that we've sync'd it.
+               // We may need to transition the authority into a replicated state the first time we sync it.
                //
-               authorityResource.updateWorkflowWithTransition(ctx, authorityCsid, WorkflowClient.WORKFLOWTRANSITION_REPLICATE);
+               String workflowState = docModel.getCurrentLifeCycleState();
+               if (workflowState.contains(WorkflowClient.WORKFLOWSTATE_REPLICATED) == false) {
+                   String authorityCsid = docModel.getName();
+                       authorityResource.updateWorkflowWithTransition(ctx, ctx.getUriInfo(), authorityCsid, WorkflowClient.WORKFLOWTRANSITION_REPLICATE);
+               }
         }
         
         return result;
@@ -576,7 +579,13 @@ public abstract class AuthorityDocumentModelHandler<AuthCommon>
      */
     @Override
     public void handleWorkflowTransition(ServiceContext ctx, DocumentWrapper<DocumentModel> wrapDoc, TransitionDef transitionDef) throws Exception {
-       if (this.getShouldUpdateRevNumber() == true) { // We don't update the rev number of synchronization requests
+       boolean updateRevNumber = this.getShouldUpdateRevNumber();
+        Boolean contextProperty = (Boolean) ctx.getProperty(AuthorityServiceUtils.SHOULD_UPDATE_REV_PROPERTY);
+        if (contextProperty != null) {
+               updateRevNumber = contextProperty;
+        }
+
+       if (updateRevNumber == true) { // We don't update the rev number of synchronization requests
                updateRevNumbers(wrapDoc);
        }
     }
index fff2b2d12567d0c9a2e3ed9ef45f3f0b5588e701..522fcbd9d68d5c6fda79bc493ef25b8a419d81e6 100644 (file)
@@ -391,7 +391,8 @@ public class CitationAuthorityServiceTest extends AbstractAuthorityServiceTest<C
 
     @Override
     protected void compareUpdatedItemInstances(CitationsCommon original,
-            CitationsCommon updated) throws Exception {
+            CitationsCommon updated,
+            boolean compareRevNumbers) throws Exception {
         CitationTermGroupList originalTermList = original.getCitationTermGroupList();
         Assert.assertNotNull(originalTermList);
         List<CitationTermGroup> originalTerms = originalTermList.getCitationTermGroup();
@@ -410,6 +411,10 @@ public class CitationAuthorityServiceTest extends AbstractAuthorityServiceTest<C
         Assert.assertEquals(updatedTerms.get(0).getTermStatus(),
                 originalTerms.get(0).getTermDisplayName(),
                 "Value in updated record did not match submitted data.");
+        
+        if (compareRevNumbers == true) {
+               Assert.assertEquals(original.getRev(), updated.getRev(), "Revision numbers should match.");
+        }
     }
 
     @Override
index 14f7142e7d3e57ec5da6f9223778551f72fb931c..7296efde086b494d9160cb3f8944083166c362d8 100644 (file)
@@ -93,7 +93,20 @@ public abstract class AbstractAuthorityServiceTest<AUTHORITY_COMMON_TYPE, AUTHOR
      * @param updated
      * @throws Exception
      */
-    protected abstract void compareUpdatedItemInstances(AUTHORITY_ITEM_TYPE original, AUTHORITY_ITEM_TYPE updated) throws Exception;
+    protected abstract void compareUpdatedItemInstances(AUTHORITY_ITEM_TYPE original,
+               AUTHORITY_ITEM_TYPE updated,
+               boolean compareRevNumbers) throws Exception;
+    
+    /**
+     * 
+     * @param original
+     * @param updated
+     * @throws Exception
+     */
+    protected void compareUpdatedItemInstances(AUTHORITY_ITEM_TYPE original,
+               AUTHORITY_ITEM_TYPE updated) throws Exception {
+       compareUpdatedItemInstances(original, updated, false);
+    }
     
     /**
      * 
@@ -881,7 +894,7 @@ public abstract class AbstractAuthorityServiceTest<AUTHORITY_COMMON_TYPE, AUTHOR
         // Submit the updated authority item and check the response.
         PoxPayloadOut output = this.createItemRequestTypeInstance(theUpdate);
         res = sasClient.updateNamedItemInNamedAuthority(knownSASAuthorityResourceIdentifier, knownSASItemIdentifiersList.get(0), output);
-        AUTHORITY_ITEM_TYPE updatedAuthorityItem = null;
+        AUTHORITY_ITEM_TYPE updatedSASAuthorityItem = null;
         try {
                int statusCode = res.getStatus();
        
@@ -894,16 +907,16 @@ public abstract class AbstractAuthorityServiceTest<AUTHORITY_COMMON_TYPE, AUTHOR
                Assert.assertEquals(statusCode, testExpectedStatusCode);
        
                // Retrieve the updated authority item and verify that its contents exist.
-               updatedAuthorityItem = extractItemCommonPartValue(res);
-               Assert.assertNotNull(updatedAuthorityItem);
+               updatedSASAuthorityItem = extractItemCommonPartValue(res);
+               Assert.assertNotNull(updatedSASAuthorityItem);
 
-               compareUpdatedItemInstances(theUpdate, updatedAuthorityItem);
+               compareUpdatedItemInstances(theUpdate, updatedSASAuthorityItem);
         } finally {
                res.close();
         }
         
-        // Synchronize the item's parent authority and verify the update we just made
-        // to the SAS appears locally
+        // Synchronize the local item's parent authority and verify the update we just made
+        // to the SAS item appears locally after the sync
         setupSync();
         AuthorityClient localClient = (AuthorityClient) this.getClientInstance();
        Response response = localClient.syncByName(knownSASAuthorityResourceIdentifier); // Notice we're using the Short ID (short ID is the same on the local and SAS)
@@ -921,7 +934,7 @@ public abstract class AbstractAuthorityServiceTest<AUTHORITY_COMMON_TYPE, AUTHOR
                Assert.assertEquals(res.getStatus(), testExpectedStatusCode);
                AUTHORITY_ITEM_TYPE syncedAuthorityItem = extractItemCommonPartValue(res);
                Assert.assertNotNull(syncedAuthorityItem);
-               compareUpdatedItemInstances(sasAuthorityItem, updatedAuthorityItem);
+               compareUpdatedItemInstances(syncedAuthorityItem, updatedSASAuthorityItem);
         } finally {
                res.close();
         }
index 28e404971cc31c396db5659695a758f270d90d26..f3020da179f84e8394235116c11c209da77dd7db 100644 (file)
@@ -42,6 +42,7 @@ import org.collectionspace.services.client.PoxPayloadOut;
 import org.collectionspace.services.client.workflow.WorkflowClient;
 import org.collectionspace.services.common.context.MultipartServiceContext;
 import org.collectionspace.services.common.context.MultipartServiceContextFactory;
+import org.collectionspace.services.common.context.MultipartServiceContextImpl;
 import org.collectionspace.services.common.context.ServiceContext;
 import org.collectionspace.services.common.context.ServiceContextFactory;
 import org.collectionspace.services.common.document.DocumentHandler;
@@ -50,7 +51,6 @@ import org.collectionspace.services.lifecycle.Lifecycle;
 import org.collectionspace.services.lifecycle.TransitionDef;
 import org.collectionspace.services.workflow.WorkflowCommon;
 import org.dom4j.DocumentException;
-
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -234,39 +234,53 @@ public abstract class AbstractMultiPartCollectionSpaceResourceImpl extends Abstr
     }
     
     public PoxPayloadOut updateWorkflowWithTransition(ServiceContext existingContext,
+               UriInfo uriInfo,
                String csid,
                String transition) {
 
         PoxPayloadOut result = null;
                 
         try {
-               MultipartServiceContext ctx = (MultipartServiceContext)existingContext;
+               MultipartServiceContextImpl workflowCtx = (MultipartServiceContextImpl)createServiceContext(WorkflowClient.SERVICE_NAME, uriInfo);
+               //
+               // Get properties out of the existing context if one was passed in
+               //
+               if (existingContext != null) {
+                       if (existingContext.getCurrentRepositorySession() != null) {
+                               workflowCtx.setCurrentRepositorySession(existingContext.getCurrentRepositorySession());
+                       }
+                       if (existingContext.getProperties() != null) {
+                               workflowCtx.setProperties(existingContext.getProperties());
+                       }
+               }
+
                //
                // 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(), 
                                WorkflowClient.SERVICE_COMMONPART_NAME);
-            ctx.setInput(input);
+            workflowCtx.setInput(input);
                
-            // Create a service context and document handler for the parent resource.
-            ServiceContext<PoxPayloadIn, PoxPayloadOut> parentCtx = createServiceContext(ctx.getUriInfo());
-            DocumentHandler targetDocHandler = createDocumentHandler(parentCtx);  
-            ctx.setProperty(WorkflowClient.TARGET_DOCHANDLER, targetDocHandler); //added as a context param for the workflow document handler -it will call the parent's dochandler "prepareForWorkflowTranstion" method
+            // Create a service context and document handler for the target resource.
+            ServiceContext<PoxPayloadIn, PoxPayloadOut> targetCtx = createServiceContext(workflowCtx.getUriInfo());
+            DocumentHandler targetDocHandler = createDocumentHandler(targetCtx);  
+            workflowCtx.setProperty(WorkflowClient.TARGET_DOCHANDLER, targetDocHandler); //added as a context param for the workflow document handler -it will call the parent's dochandler "prepareForWorkflowTranstion" method
 
             // When looking for the document, we need to use the parent's workspace name -not the "workflow" workspace name
-            String targetWorkspaceName = parentCtx.getRepositoryWorkspaceName();
-            ctx.setRespositoryWorkspaceName(targetWorkspaceName); //find the document in the parent's workspace
+            String targetWorkspaceName = targetCtx.getRepositoryWorkspaceName();
+            workflowCtx.setRespositoryWorkspaceName(targetWorkspaceName); //find the document in the parent's workspace
             
                // Get the type of transition we're being asked to make and store it as a context parameter -used by the workflow document handler
-            TransitionDef transitionDef = getTransitionDef(parentCtx, transition);
+            TransitionDef transitionDef = getTransitionDef(targetCtx, transition);
             if (transitionDef == null) {
                throw new DocumentException(String.format("The document with ID='%s' does not support the workflow transition '%s'.",
                                csid, transition));
             }
-            ctx.setProperty(WorkflowClient.TRANSITION_ID, transitionDef);
+            workflowCtx.setProperty(WorkflowClient.TRANSITION_ID, transitionDef);
 
-            WorkflowDocumentModelHandler handler = createWorkflowDocumentHandler(ctx);
-            getRepositoryClient(ctx).update(ctx, csid, handler);
-            result = ctx.getOutput();
+            WorkflowDocumentModelHandler workflowHandler = createWorkflowDocumentHandler(workflowCtx);
+            getRepositoryClient(workflowCtx).update(workflowCtx, csid, workflowHandler);
+            result = workflowCtx.getOutput();
         } catch (Exception e) {
             throw bigReThrow(e, ServiceMessages.UPDATE_FAILED + WorkflowClient.SERVICE_PAYLOAD_NAME, csid);
         }
@@ -287,8 +301,7 @@ public abstract class AbstractMultiPartCollectionSpaceResourceImpl extends Abstr
         PoxPayloadOut result = null;
                 
         try {
-               ServiceContext ctx = (ServiceContext) createServiceContext(WorkflowClient.SERVICE_NAME, uriInfo);
-               result = this.updateWorkflowWithTransition(ctx, csid, transition);
+               result = this.updateWorkflowWithTransition(NULL_CONTEXT, uriInfo, csid, transition);
         } catch (Exception e) {
             throw bigReThrow(e, ServiceMessages.UPDATE_FAILED + WorkflowClient.SERVICE_PAYLOAD_NAME, csid);
         }
index 4ff6d67b7c7e9e2c1306f9485956e7108d475b81..7c16b46770fdd53b2c15539d5f38bd1b5ecaf8b7 100644 (file)
@@ -403,25 +403,27 @@ public class ConceptAuthorityServiceTest extends AbstractAuthorityServiceTest<Co
 
        @Override
        protected void compareUpdatedItemInstances(ConceptsCommon original,
-                       ConceptsCommon updated) throws Exception {
-            ConceptTermGroupList originalTermList = original.getConceptTermGroupList();
-            Assert.assertNotNull(originalTermList);
-            List<ConceptTermGroup> originalTerms = originalTermList.getConceptTermGroup();
-            Assert.assertNotNull(originalTerms);
-            Assert.assertTrue(originalTerms.size() > 0);
-            
-            ConceptTermGroupList updatedTermList = updated.getConceptTermGroupList();
-            Assert.assertNotNull(updatedTermList);
-            List<ConceptTermGroup> updatedTerms = updatedTermList.getConceptTermGroup();
-            Assert.assertNotNull(updatedTerms);
-            Assert.assertTrue(updatedTerms.size() > 0);
-            
-            Assert.assertEquals(updatedTerms.get(0).getTermDisplayName(),
-                originalTerms.get(0).getTermDisplayName(),
-                "Value in updated record did not match submitted data.");
-            Assert.assertEquals(updatedTerms.get(0).getTermStatus(),
-                originalTerms.get(0).getTermDisplayName(),
-                "Value in updated record did not match submitted data.");
+                       ConceptsCommon updated,
+                       boolean compareRevNumbers) throws Exception {
+               ConceptTermGroupList originalTermList = original.getConceptTermGroupList();
+               Assert.assertNotNull(originalTermList);
+               List<ConceptTermGroup> originalTerms = originalTermList.getConceptTermGroup();
+               Assert.assertNotNull(originalTerms);
+               Assert.assertTrue(originalTerms.size() > 0);
+
+               ConceptTermGroupList updatedTermList = updated.getConceptTermGroupList();
+               Assert.assertNotNull(updatedTermList);
+               List<ConceptTermGroup> updatedTerms = updatedTermList.getConceptTermGroup();
+               Assert.assertNotNull(updatedTerms);
+               Assert.assertTrue(updatedTerms.size() > 0);
+
+               Assert.assertEquals(updatedTerms.get(0).getTermDisplayName(), originalTerms.get(0).getTermDisplayName(), "Value in updated record did not match submitted data.");
+               Assert.assertEquals(updatedTerms.get(0).getTermStatus(), originalTerms.get(0).getTermDisplayName(),
+                               "Value in updated record did not match submitted data.");
+               
+               if (compareRevNumbers == true) {
+               Assert.assertEquals(original.getRev(), updated.getRev(), "Revision numbers did not match.");
+        }
        }
 
        @Override
index 506ecc0a390e66ed5c30a5b0d7751a4e0c81cbf0..53afd1721535e72b9c64a10d229e7c78be963017 100644 (file)
@@ -407,22 +407,25 @@ public class LocationAuthorityServiceTest extends AbstractAuthorityServiceTest<L
 
        @Override
        protected void compareUpdatedItemInstances(LocationsCommon original,
-                       LocationsCommon updated) throws Exception {
-            LocTermGroupList originalTermList = original.getLocTermGroupList();
-            Assert.assertNotNull(originalTermList);
-            List<LocTermGroup> originalTerms = originalTermList.getLocTermGroup();
-            Assert.assertNotNull(originalTerms);
-            Assert.assertTrue(originalTerms.size() > 0);
-            
-            LocTermGroupList updatedTermList = updated.getLocTermGroupList();
-            Assert.assertNotNull(updatedTermList);
-            List<LocTermGroup> updatedTerms = updatedTermList.getLocTermGroup();
-            Assert.assertNotNull(updatedTerms);
-            Assert.assertTrue(updatedTerms.size() > 0);
-            
-            Assert.assertEquals(updatedTerms.get(0).getTermDisplayName(),
-                originalTerms.get(0).getTermDisplayName(),
-                "Value in updated record did not match submitted data.");
+                       LocationsCommon updated,
+                       boolean compareRevNumbers) throws Exception {
+               LocTermGroupList originalTermList = original.getLocTermGroupList();
+               Assert.assertNotNull(originalTermList);
+               List<LocTermGroup> originalTerms = originalTermList.getLocTermGroup();
+               Assert.assertNotNull(originalTerms);
+               Assert.assertTrue(originalTerms.size() > 0);
+
+               LocTermGroupList updatedTermList = updated.getLocTermGroupList();
+               Assert.assertNotNull(updatedTermList);
+               List<LocTermGroup> updatedTerms = updatedTermList.getLocTermGroup();
+               Assert.assertNotNull(updatedTerms);
+               Assert.assertTrue(updatedTerms.size() > 0);
+
+               Assert.assertEquals(updatedTerms.get(0).getTermDisplayName(), originalTerms.get(0).getTermDisplayName(), "Value in updated record did not match submitted data.");
+               
+               if (compareRevNumbers == true) {
+               Assert.assertEquals(original.getRev(), updated.getRev(), "Revision numbers should match.");
+        }
        }
 
        @Override
index 77e99ec059e3c17f12506178d2067a73ee43870d..bf67f0eb880d38716184a592f95bbc24f7d73558 100644 (file)
@@ -1359,7 +1359,8 @@ public class PersonAuthorityServiceTest extends AbstractAuthorityServiceTest<Per
 
        @Override
        protected void compareUpdatedItemInstances(PersonsCommon original,
-                       PersonsCommon updated) throws Exception {
+                       PersonsCommon updated,
+                       boolean compareRevNumbers) throws Exception {
             
             PersonTermGroupList originalTermList = original.getPersonTermGroupList();
             Assert.assertNotNull(originalTermList);
@@ -1376,6 +1377,10 @@ public class PersonAuthorityServiceTest extends AbstractAuthorityServiceTest<Per
             Assert.assertEquals(updatedTerms.get(0).getTermDisplayName(),
                 originalTerms.get(0).getTermDisplayName(),
                 "Value in updated record did not match submitted data.");
+            
+            if (compareRevNumbers == true) {
+               Assert.assertEquals(original.getRev(), updated.getRev(), "Revision numbers should match.");
+            }
        }
 
        @Override