From 5487310ce9c5358c1d310098e2aec6704efaf9c5 Mon Sep 17 00:00:00 2001 From: remillet Date: Thu, 14 Apr 2016 20:39:48 -0700 Subject: [PATCH] CSPACE-6937: Added new SAS document lifecycle for authority and authority item documents. --- .../OSGI-INF/default-life-cycle-contrib.xml | 77 +++++++++++++++++++ .../common/vocabulary/AuthorityResource.java | 48 +++++++++--- .../nuxeo/AuthorityDocumentModelHandler.java | 15 ++++ .../AuthorityItemDocumentModelHandler.java | 41 ++++++++-- .../client/test/RoleServiceTest.java | 16 +++- .../client/workflow/WorkflowClient.java | 21 ++++- .../collectionspace-client.properties | 4 +- ...tMultiPartCollectionSpaceResourceImpl.java | 8 +- .../nuxeo/WorkflowDocumentModelHandler.java | 5 +- .../java/NuxeoDocumentModelHandler.java | 10 +++ .../client/test/OrgAuthorityServiceTest.java | 7 +- .../client/PersonAuthorityClientUtils.java | 9 ++- .../test/PersonAuthorityServiceTest.java | 4 +- .../client/test/VocabularyServiceTest.java | 2 +- 14 files changed, 227 insertions(+), 40 deletions(-) diff --git a/3rdparty/nuxeo/nuxeo-platform-collectionspace/src/main/resources/OSGI-INF/default-life-cycle-contrib.xml b/3rdparty/nuxeo/nuxeo-platform-collectionspace/src/main/resources/OSGI-INF/default-life-cycle-contrib.xml index 14c955b5f..ecfbcbd3e 100644 --- a/3rdparty/nuxeo/nuxeo-platform-collectionspace/src/main/resources/OSGI-INF/default-life-cycle-contrib.xml +++ b/3rdparty/nuxeo/nuxeo-platform-collectionspace/src/main/resources/OSGI-INF/default-life-cycle-contrib.xml @@ -70,4 +70,81 @@ + + + + + + CollectionSpace "SAS" life cycle definition. + + + + + Unlock the document back to project state. + + + Undelete the document to the project state. + + + + + Lock a document from the project state + + + Soft-delete the document from the project state + + + + + Delete the locked document from the "locked" state + + + Lock the deleted document from the "deleted" state. + + + + + Undelete the locked document from locked_deleted state + + + Unlock the deleted document. + + + + + + + + delete + lock + + + + unlock + delete_locked + + + + undelete + lock_deleted + + + + + unlock_deleted + undelete_locked + + + + + + diff --git a/services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/AuthorityResource.java b/services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/AuthorityResource.java index 558bfecba..f8dcd8215 100644 --- a/services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/AuthorityResource.java +++ b/services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/AuthorityResource.java @@ -719,24 +719,54 @@ public abstract class AuthorityResource @PathParam("transition") String transition) { PoxPayloadOut result = null; + try { + result = updateItemWorkflowWithTransition(null, // Ok to send null + csid, itemcsid, transition, AuthorityServiceUtils.UPDATE_REV); + } catch (Exception e) { + throw bigReThrow(e, ServiceMessages.UPDATE_FAILED + WorkflowClient.SERVICE_PAYLOAD_NAME, csid); + } + + return result.getBytes(); + } + + /** + * Update an authority item's workflow state. + * @param existingContext + * @param csid + * @param itemcsid + * @param transition + * @return + */ + public PoxPayloadOut updateItemWorkflowWithTransition(ServiceContext existingContext, + String csid, + String itemcsid, + String transition, + boolean updateRevNumber) { + PoxPayloadOut result = null; + try { // // 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); MultipartServiceContext ctx = (MultipartServiceContext) createServiceContext(WorkflowClient.SERVICE_NAME, input); + if (existingContext != null && existingContext.getCurrentRepositorySession() != null) { + ctx.setCurrentRepositorySession(existingContext.getCurrentRepositorySession()); // If a repo session is already open, we need to use it and not create a new one + } - // Create a service context and document handler for the parent resource. - ServiceContext parentCtx = createServiceContext(getItemServiceName()); - DocumentHandler parentDocHandler = this.createDocumentHandler(parentCtx); - ctx.setProperty(WorkflowClient.PARENT_DOCHANDLER, parentDocHandler); //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 -not the workflow resource itself. + ServiceContext targetCtx = createServiceContext(getItemServiceName()); + AuthorityItemDocumentModelHandler parentDocHandler = (AuthorityItemDocumentModelHandler) this.createDocumentHandler(targetCtx); + parentDocHandler.setShouldUpdateRevNumber(updateRevNumber); + ctx.setProperty(WorkflowClient.TARGET_DOCHANDLER, parentDocHandler); //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 parentWorkspaceName = parentCtx.getRepositoryWorkspaceName(); + // When looking for the document, we need to use the parent resource's workspace name -not the "workflow" workspace name + String parentWorkspaceName = targetCtx.getRepositoryWorkspaceName(); ctx.setRespositoryWorkspaceName(parentWorkspaceName); //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); ctx.setProperty(WorkflowClient.TRANSITION_ID, transitionDef); WorkflowDocumentModelHandler handler = createWorkflowDocumentHandler(ctx); @@ -745,8 +775,8 @@ public abstract class AuthorityResource } catch (Exception e) { throw bigReThrow(e, ServiceMessages.UPDATE_FAILED + WorkflowClient.SERVICE_PAYLOAD_NAME, csid); } - - return result.getBytes(); + + return result; } private PoxPayloadOut getAuthorityItem( 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 4e919d85c..ee0ead044 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 @@ -55,6 +55,7 @@ import org.collectionspace.services.common.vocabulary.RefNameServiceUtils.Author import org.collectionspace.services.common.vocabulary.RefNameServiceUtils.Specifier; import org.collectionspace.services.common.vocabulary.RefNameServiceUtils.SpecifierForm; import org.collectionspace.services.config.service.ObjectPartType; +import org.collectionspace.services.lifecycle.TransitionDef; import org.collectionspace.services.nuxeo.client.java.NuxeoDocumentModelHandler; import org.collectionspace.services.nuxeo.client.java.CoreSessionInterface; import org.collectionspace.services.nuxeo.client.java.RepositoryClientImpl; @@ -229,6 +230,9 @@ public abstract class AuthorityDocumentModelHandler if (response.getStatus() != Response.Status.CREATED.getStatusCode()) { throw new DocumentException(String.format("Could not create new authority item '%s' during synchronization of the '%s' authority.", itemIdentifier, parentIdentifier)); + // + // Handle the workflow state + // } } @@ -349,6 +353,17 @@ public abstract class AuthorityDocumentModelHandler documentModel.setProperty(authorityCommonSchemaName, AuthorityJAXBSchema.REV, rev); } + /* + * We consider workflow state changes as changes that should bump the revision number + * (non-Javadoc) + * @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 wrapDoc, TransitionDef transitionDef) throws Exception { + // Update the revision number + updateRevNumbers(wrapDoc); + } + @Override public void handleCreate(DocumentWrapper wrapDoc) throws Exception { super.handleCreate(wrapDoc); diff --git a/services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/nuxeo/AuthorityItemDocumentModelHandler.java b/services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/nuxeo/AuthorityItemDocumentModelHandler.java index 470c93d4b..5fdd5dcdc 100644 --- a/services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/nuxeo/AuthorityItemDocumentModelHandler.java +++ b/services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/nuxeo/AuthorityItemDocumentModelHandler.java @@ -24,6 +24,7 @@ package org.collectionspace.services.common.vocabulary.nuxeo; import org.collectionspace.services.client.AuthorityClient; +import org.collectionspace.services.client.CollectionSpaceClient; import org.collectionspace.services.client.IQueryManager; import org.collectionspace.services.client.PoxPayloadIn; import org.collectionspace.services.client.PoxPayloadOut; @@ -51,19 +52,19 @@ import org.collectionspace.services.common.vocabulary.RefNameServiceUtils.Specif import org.collectionspace.services.common.vocabulary.RefNameServiceUtils.SpecifierForm; import org.collectionspace.services.config.service.ListResultField; import org.collectionspace.services.config.service.ObjectPartType; +import org.collectionspace.services.lifecycle.TransitionDef; import org.collectionspace.services.nuxeo.client.java.NuxeoDocumentModelHandler; import org.collectionspace.services.nuxeo.client.java.CoreSessionInterface; import org.collectionspace.services.nuxeo.client.java.RepositoryClientImpl; import org.collectionspace.services.nuxeo.util.NuxeoUtils; import org.collectionspace.services.relation.RelationsCommonList; import org.collectionspace.services.vocabulary.VocabularyItemJAXBSchema; - import org.nuxeo.ecm.core.api.ClientException; import org.nuxeo.ecm.core.api.DocumentModel; import org.nuxeo.ecm.core.api.model.PropertyException; - import org.slf4j.Logger; import org.slf4j.LoggerFactory; + import javax.ws.rs.core.MultivaluedMap; import java.util.ArrayList; @@ -347,6 +348,17 @@ public abstract class AuthorityItemDocumentModelHandler return list; } + /** + * We consider workflow state changes as a change that should bump the revision number. + */ + @Override + public void handleWorkflowTransition(DocumentWrapper wrapDoc, TransitionDef transitionDef) throws Exception { + // 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. */ @@ -354,8 +366,9 @@ public abstract class AuthorityItemDocumentModelHandler public boolean handleSync(DocumentWrapper wrapDoc) throws Exception { boolean result = false; ServiceContext ctx = getServiceContext(); + // - // Get the rev number of the local authority item so we can compare with rev number of shared authority + // Get information about the local authority item so we can compare with corresponding item on the shared authority server // AuthorityItemSpecifier authorityItemSpecifier = (AuthorityItemSpecifier) wrapDoc.getWrappedObject(); DocumentModel itemDocModel = NuxeoUtils.getDocFromSpecifier(ctx, getRepositorySession(), getAuthorityItemCommonSchemaName(), @@ -365,13 +378,17 @@ public abstract class AuthorityItemDocumentModelHandler authorityItemSpecifier.getItemSpecifier().value)); } Long localItemRev = (Long) NuxeoUtils.getProperyValue(itemDocModel, AuthorityItemJAXBSchema.REV); + String localItemCsid = itemDocModel.getName(); + String localItemWorkflowState = (String) NuxeoUtils.getProperyValue(itemDocModel, CollectionSpaceClient.CORE_WORKFLOWSTATE); String itemShortId = (String) NuxeoUtils.getProperyValue(itemDocModel, AuthorityItemJAXBSchema.SHORT_IDENTIFIER); + // - // Now get the Authority (the parent) information + // Now get the item's Authority (the parent) information // DocumentModel authorityDocModel = NuxeoUtils.getDocFromSpecifier(ctx, getRepositorySession(), authorityCommonSchemaName, authorityItemSpecifier.getParentSpecifier()); String authorityShortId = (String) NuxeoUtils.getProperyValue(authorityDocModel, AuthorityJAXBSchema.SHORT_IDENTIFIER); + String localParentCsid = authorityDocModel.getName(); // // Using the short IDs of the local authority and item, create URN specifiers to retrieve the SAS authority item // @@ -382,6 +399,7 @@ public abstract class AuthorityItemDocumentModelHandler PoxPayloadIn sasPayloadIn = AuthorityServiceUtils.requestPayloadIn(sasAuthorityItemSpecifier, getAuthorityServicePath(), getEntityResponseType()); Long sasRev = getRevision(sasPayloadIn); + String sasWorkflowState = getWorkflowState(sasPayloadIn); // // If the shared authority item is newer, update our local copy // @@ -392,15 +410,24 @@ public abstract class AuthorityItemDocumentModelHandler PoxPayloadOut payloadOut = authorityResource.updateAuthorityItem(ctx, resourceMap, ctx.getUriInfo(), - authorityDocModel.getName(), // parent's CSID - itemDocModel.getName(), // item's CSID - sasPayloadIn, // the payload from the SAS + localParentCsid, // parent's CSID + localItemCsid, // item's CSID + sasPayloadIn, // the payload from the remote SAS AuthorityServiceUtils.DONT_UPDATE_REV); // don't update the parent's revision number if (payloadOut != null) { ctx.setOutput(payloadOut); result = true; } } + // + // If the workflow states are different, we need to update the local's to reflects the remote's + // + if (localItemWorkflowState.equalsIgnoreCase(sasWorkflowState) == false) { + ResourceMap resourceMap = ctx.getResourceMap(); + String resourceName = this.getAuthorityServicePath(); + AuthorityResource authorityResource = (AuthorityResource) resourceMap.get(resourceName); + authorityResource.updateItemWorkflowWithTransition(ctx, localParentCsid, localItemCsid, transition, AuthorityServiceUtils.DONT_UPDATE_REV) + } return result; } diff --git a/services/authorization-mgt/client/src/test/java/org/collectionspace/services/authorization/client/test/RoleServiceTest.java b/services/authorization-mgt/client/src/test/java/org/collectionspace/services/authorization/client/test/RoleServiceTest.java index 56c4e5cbc..f538dcfc2 100644 --- a/services/authorization-mgt/client/src/test/java/org/collectionspace/services/authorization/client/test/RoleServiceTest.java +++ b/services/authorization-mgt/client/src/test/java/org/collectionspace/services/authorization/client/test/RoleServiceTest.java @@ -24,6 +24,8 @@ package org.collectionspace.services.authorization.client.test; //import java.util.ArrayList; //import java.util.List; +import java.util.Random; + import javax.ws.rs.core.Response; import org.collectionspace.services.client.CollectionSpaceClient; @@ -32,10 +34,8 @@ import org.collectionspace.services.authorization.Role; import org.collectionspace.services.authorization.RolesList; import org.collectionspace.services.client.RoleFactory; import org.collectionspace.services.client.test.AbstractServiceTestImpl; - import org.testng.Assert; import org.testng.annotations.Test; - import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -51,7 +51,10 @@ public class RoleServiceTest extends AbstractServiceTestImpl statesMappedToTransitions; + static + { + statesMappedToTransitions = new HashMap(); + statesMappedToTransitions.put(WORKFLOWSTATE_DELETED, WORKFLOWTRANSITION_DELETE); + statesMappedToTransitions.put("c", "d"); + } @Override diff --git a/services/client/src/main/resources/collectionspace-client.properties b/services/client/src/main/resources/collectionspace-client.properties index d077dd6be..75cb8b86d 100644 --- a/services/client/src/main/resources/collectionspace-client.properties +++ b/services/client/src/main/resources/collectionspace-client.properties @@ -9,8 +9,8 @@ cspace.url=http://localhost:8180/cspace-services/ cspace.ssl=false cspace.auth=true # default user -#cspace.user=admin@core.collectionspace.org -cspace.user=admin@testsci.collectionspace.org +cspace.user=admin@core.collectionspace.org +#cspace.user=admin@testsci.collectionspace.org cspace.password=Administrator # default tenant cspace.tenant=1 diff --git a/services/common/src/main/java/org/collectionspace/services/common/AbstractMultiPartCollectionSpaceResourceImpl.java b/services/common/src/main/java/org/collectionspace/services/common/AbstractMultiPartCollectionSpaceResourceImpl.java index 1dcc3db35..02193d1b0 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/AbstractMultiPartCollectionSpaceResourceImpl.java +++ b/services/common/src/main/java/org/collectionspace/services/common/AbstractMultiPartCollectionSpaceResourceImpl.java @@ -256,12 +256,12 @@ public abstract class AbstractMultiPartCollectionSpaceResourceImpl extends Abstr // Create a service context and document handler for the parent resource. ServiceContext parentCtx = createServiceContext(uriInfo); - DocumentHandler parentDocHandler = this.createDocumentHandler(parentCtx); - ctx.setProperty(WorkflowClient.PARENT_DOCHANDLER, parentDocHandler); //added as a context param for the workflow document handler -it will call the parent's dochandler "prepareForWorkflowTranstion" method + DocumentHandler targetDocHandler = this.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 // When looking for the document, we need to use the parent's workspace name -not the "workflow" workspace name - String parentWorkspaceName = parentCtx.getRepositoryWorkspaceName(); - ctx.setRespositoryWorkspaceName(parentWorkspaceName); //find the document in the parent's workspace + String targetWorkspaceName = parentCtx.getRepositoryWorkspaceName(); + ctx.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); diff --git a/services/common/src/main/java/org/collectionspace/services/common/workflow/service/nuxeo/WorkflowDocumentModelHandler.java b/services/common/src/main/java/org/collectionspace/services/common/workflow/service/nuxeo/WorkflowDocumentModelHandler.java index 1ce127f7a..14b773cec 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/workflow/service/nuxeo/WorkflowDocumentModelHandler.java +++ b/services/common/src/main/java/org/collectionspace/services/common/workflow/service/nuxeo/WorkflowDocumentModelHandler.java @@ -67,9 +67,10 @@ public class WorkflowDocumentModelHandler // the super/parent handleUpdate() method. // ServiceContext ctx = this.getServiceContext(); - DocumentModelHandler docHandler = (DocumentModelHandler)ctx.getProperty(WorkflowClient.PARENT_DOCHANDLER); + DocumentModelHandler targetDocHandler = (DocumentModelHandler)ctx.getProperty(WorkflowClient.TARGET_DOCHANDLER); + targetDocHandler.setRepositorySession(this.getRepositorySession()); // Make sure the target doc handler has a repository session to work with TransitionDef transitionDef = (TransitionDef)ctx.getProperty(WorkflowClient.TRANSITION_ID); - docHandler.handleWorkflowTransition(wrapDoc, transitionDef); + targetDocHandler.handleWorkflowTransition(wrapDoc, transitionDef); // Call the parent resouce's handler first // // If no exception occurred, then call the super's method // diff --git a/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/NuxeoDocumentModelHandler.java b/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/NuxeoDocumentModelHandler.java index 6ace56a4f..4b2c25439 100644 --- a/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/NuxeoDocumentModelHandler.java +++ b/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/NuxeoDocumentModelHandler.java @@ -38,6 +38,7 @@ import org.collectionspace.services.client.IRelationsManager; import org.collectionspace.services.client.PoxPayload; import org.collectionspace.services.client.PoxPayloadIn; import org.collectionspace.services.client.PoxPayloadOut; +import org.collectionspace.services.client.workflow.WorkflowClient; import org.collectionspace.services.common.ReflectionMapper; import org.collectionspace.services.common.XmlTools; import org.collectionspace.services.common.api.GregorianCalendarDateTimeUtils; @@ -116,6 +117,15 @@ public abstract class NuxeoDocumentModelHandler extends RemoteDocumentModelHa return String.class; } + protected String getWorkflowState(PoxPayload payload) { + String result = null; + + Document document = payload.getDOMDocument(); + result = XmlTools.getElementValue(document, "//" + WorkflowClient.WORKFLOWSTATE_XML_ELEMENT_NAME); + + return result; + } + protected Long getRevision(PoxPayload payload) { Long result = null; diff --git a/services/organization/client/src/test/java/org/collectionspace/services/client/test/OrgAuthorityServiceTest.java b/services/organization/client/src/test/java/org/collectionspace/services/client/test/OrgAuthorityServiceTest.java index add12535f..290e9855f 100644 --- a/services/organization/client/src/test/java/org/collectionspace/services/client/test/OrgAuthorityServiceTest.java +++ b/services/organization/client/src/test/java/org/collectionspace/services/client/test/OrgAuthorityServiceTest.java @@ -26,6 +26,7 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; + import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; @@ -48,9 +49,7 @@ import org.collectionspace.services.organization.OrgauthoritiesCommon; import org.collectionspace.services.organization.OrganizationsCommon; import org.collectionspace.services.organization.OrgTermGroup; import org.collectionspace.services.organization.OrgTermGroupList; - import org.jboss.resteasy.client.ClientResponse; - import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.testng.Assert; @@ -121,7 +120,7 @@ public class OrgAuthorityServiceTest extends AbstractAuthorityServiceTest testOrgMap = new HashMap(); testOrgMap.put(OrganizationJAXBSchema.SHORT_IDENTIFIER, shortId); testOrgMap.put(OrganizationJAXBSchema.FOUNDING_DATE, TEST_ORG_FOUNDING_DATE); @@ -154,7 +153,7 @@ public class OrgAuthorityServiceTest extends AbstractAuthorityServiceTest testOrgMap = new HashMap(); testOrgMap.put(OrganizationJAXBSchema.SHORT_IDENTIFIER, shortId); testOrgMap.put(OrganizationJAXBSchema.FOUNDING_DATE, TEST_ORG_FOUNDING_DATE); diff --git a/services/person/client/src/main/java/org/collectionspace/services/client/PersonAuthorityClientUtils.java b/services/person/client/src/main/java/org/collectionspace/services/client/PersonAuthorityClientUtils.java index 16aca218f..6913506d1 100644 --- a/services/person/client/src/main/java/org/collectionspace/services/client/PersonAuthorityClientUtils.java +++ b/services/person/client/src/main/java/org/collectionspace/services/client/PersonAuthorityClientUtils.java @@ -44,7 +44,6 @@ import org.collectionspace.services.person.PersonsCommon; import org.collectionspace.services.person.PersonauthoritiesCommon; import org.collectionspace.services.person.SchoolOrStyleList; import org.collectionspace.services.person.StructuredDateGroup; - import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -57,6 +56,7 @@ public class PersonAuthorityClientUtils { private static final Logger logger = LoggerFactory.getLogger(PersonAuthorityClientUtils.class); private static final ServiceRequestType READ_REQ = ServiceRequestType.READ; + static private final Random random = new Random(System.currentTimeMillis()); /** * @param csid the id of the PersonAuthority @@ -467,7 +467,12 @@ public class PersonAuthorityClientUtils { } private static String getGeneratedIdentifier() { - return "id" + new Date().getTime(); + return "id" + createIdentifier(); } + + private static String createIdentifier() { + long identifier = System.currentTimeMillis() + random.nextInt(); + return Long.toString(identifier); + } } 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 57dfce266..df6cf9995 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 @@ -186,7 +186,7 @@ public class PersonAuthorityServiceTest extends AbstractAuthorityServiceTest personInfo = new HashMap(); - String shortId = "MarkTwainAuthor"; + String shortId = "MarkTwainAuthor" + identifier; personInfo.put(PersonJAXBSchema.SHORT_IDENTIFIER, shortId); List terms = new ArrayList(); @@ -232,7 +232,7 @@ public class PersonAuthorityServiceTest extends AbstractAuthorityServiceTest vocabItemInfo = new HashMap(); - String shortId = createIdentifier(); + String shortId = identifier; vocabItemInfo.put(AuthorityItemJAXBSchema.SHORT_IDENTIFIER, shortId); vocabItemInfo.put(AuthorityItemJAXBSchema.DISPLAY_NAME, "display-" + shortId); -- 2.47.3