// 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);
//
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;
*/
@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);
}
}
@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();
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
* @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);
+ }
/**
*
// 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();
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)
Assert.assertEquals(res.getStatus(), testExpectedStatusCode);
AUTHORITY_ITEM_TYPE syncedAuthorityItem = extractItemCommonPartValue(res);
Assert.assertNotNull(syncedAuthorityItem);
- compareUpdatedItemInstances(sasAuthorityItem, updatedAuthorityItem);
+ compareUpdatedItemInstances(syncedAuthorityItem, updatedSASAuthorityItem);
} finally {
res.close();
}
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;
import org.collectionspace.services.lifecycle.TransitionDef;
import org.collectionspace.services.workflow.WorkflowCommon;
import org.dom4j.DocumentException;
-
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
}
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);
}
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);
}
@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
@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
@Override
protected void compareUpdatedItemInstances(PersonsCommon original,
- PersonsCommon updated) throws Exception {
+ PersonsCommon updated,
+ boolean compareRevNumbers) throws Exception {
PersonTermGroupList originalTermList = original.getPersonTermGroupList();
Assert.assertNotNull(originalTermList);
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