From 0b1f34ddeae08c9cb73fc322404038b427531bd6 Mon Sep 17 00:00:00 2001 From: Richard Millet Date: Wed, 11 May 2016 08:38:14 -0700 Subject: [PATCH] CSPACE-6949: Add rev number comparison test. --- .../nuxeo/AuthorityDocumentModelHandler.java | 17 +++++-- .../test/CitationAuthorityServiceTest.java | 7 ++- .../test/AbstractAuthorityServiceTest.java | 29 ++++++++---- ...tMultiPartCollectionSpaceResourceImpl.java | 45 ++++++++++++------- .../test/ConceptAuthorityServiceTest.java | 40 +++++++++-------- .../test/LocationAuthorityServiceTest.java | 35 ++++++++------- .../test/PersonAuthorityServiceTest.java | 7 ++- 7 files changed, 115 insertions(+), 65 deletions(-) diff --git a/services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/nuxeo/AuthorityDocumentModelHandler.java b/services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/nuxeo/AuthorityDocumentModelHandler.java index 5cf02866d..40a590db5 100644 --- a/services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/nuxeo/AuthorityDocumentModelHandler.java +++ b/services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/nuxeo/AuthorityDocumentModelHandler.java @@ -132,7 +132,6 @@ public abstract class AuthorityDocumentModelHandler // 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 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 */ @Override public void handleWorkflowTransition(ServiceContext ctx, DocumentWrapper 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); } } diff --git a/services/citation/client/src/test/java/org/collectionspace/services/client/test/CitationAuthorityServiceTest.java b/services/citation/client/src/test/java/org/collectionspace/services/client/test/CitationAuthorityServiceTest.java index fff2b2d12..522fcbd9d 100644 --- a/services/citation/client/src/test/java/org/collectionspace/services/client/test/CitationAuthorityServiceTest.java +++ b/services/citation/client/src/test/java/org/collectionspace/services/client/test/CitationAuthorityServiceTest.java @@ -391,7 +391,8 @@ public class CitationAuthorityServiceTest extends AbstractAuthorityServiceTest originalTerms = originalTermList.getCitationTermGroup(); @@ -410,6 +411,10 @@ public class CitationAuthorityServiceTest extends AbstractAuthorityServiceTest 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 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); } diff --git a/services/concept/client/src/test/java/org/collectionspace/services/client/test/ConceptAuthorityServiceTest.java b/services/concept/client/src/test/java/org/collectionspace/services/client/test/ConceptAuthorityServiceTest.java index 4ff6d67b7..7c16b4677 100644 --- a/services/concept/client/src/test/java/org/collectionspace/services/client/test/ConceptAuthorityServiceTest.java +++ b/services/concept/client/src/test/java/org/collectionspace/services/client/test/ConceptAuthorityServiceTest.java @@ -403,25 +403,27 @@ public class ConceptAuthorityServiceTest extends AbstractAuthorityServiceTest originalTerms = originalTermList.getConceptTermGroup(); - Assert.assertNotNull(originalTerms); - Assert.assertTrue(originalTerms.size() > 0); - - ConceptTermGroupList updatedTermList = updated.getConceptTermGroupList(); - Assert.assertNotNull(updatedTermList); - List 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 originalTerms = originalTermList.getConceptTermGroup(); + Assert.assertNotNull(originalTerms); + Assert.assertTrue(originalTerms.size() > 0); + + ConceptTermGroupList updatedTermList = updated.getConceptTermGroupList(); + Assert.assertNotNull(updatedTermList); + List 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 diff --git a/services/location/client/src/test/java/org/collectionspace/services/client/test/LocationAuthorityServiceTest.java b/services/location/client/src/test/java/org/collectionspace/services/client/test/LocationAuthorityServiceTest.java index 506ecc0a3..53afd1721 100644 --- a/services/location/client/src/test/java/org/collectionspace/services/client/test/LocationAuthorityServiceTest.java +++ b/services/location/client/src/test/java/org/collectionspace/services/client/test/LocationAuthorityServiceTest.java @@ -407,22 +407,25 @@ public class LocationAuthorityServiceTest extends AbstractAuthorityServiceTest originalTerms = originalTermList.getLocTermGroup(); - Assert.assertNotNull(originalTerms); - Assert.assertTrue(originalTerms.size() > 0); - - LocTermGroupList updatedTermList = updated.getLocTermGroupList(); - Assert.assertNotNull(updatedTermList); - List 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 originalTerms = originalTermList.getLocTermGroup(); + Assert.assertNotNull(originalTerms); + Assert.assertTrue(originalTerms.size() > 0); + + LocTermGroupList updatedTermList = updated.getLocTermGroupList(); + Assert.assertNotNull(updatedTermList); + List 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 diff --git a/services/person/client/src/test/java/org/collectionspace/services/client/test/PersonAuthorityServiceTest.java b/services/person/client/src/test/java/org/collectionspace/services/client/test/PersonAuthorityServiceTest.java index 77e99ec05..bf67f0eb8 100644 --- a/services/person/client/src/test/java/org/collectionspace/services/client/test/PersonAuthorityServiceTest.java +++ b/services/person/client/src/test/java/org/collectionspace/services/client/test/PersonAuthorityServiceTest.java @@ -1359,7 +1359,8 @@ public class PersonAuthorityServiceTest extends AbstractAuthorityServiceTest