From 974397cff027a5d5fe0cdfd3a4bb5d476d0ca783 Mon Sep 17 00:00:00 2001 From: Ana Bozianu Date: Fri, 12 May 2017 18:54:31 +0300 Subject: [PATCH] RM-5012 - fixed custom identifier issue --- .../UnfiledContainerTests.java | 25 +++++++++ .../record/RecordServiceImpl.java | 52 ++++++++++++------- .../api/impl/FilePlanComponentsApiUtils.java | 14 ++--- .../UnfiledContainerChildrenRelation.java | 2 +- .../test/util/CommonRMTestUtils.java | 9 ++++ 5 files changed, 76 insertions(+), 26 deletions(-) diff --git a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/unfiledcontainers/UnfiledContainerTests.java b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/unfiledcontainers/UnfiledContainerTests.java index 719d1dddd1..4d5b73daac 100644 --- a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/unfiledcontainers/UnfiledContainerTests.java +++ b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/unfiledcontainers/UnfiledContainerTests.java @@ -52,6 +52,7 @@ import java.util.NoSuchElementException; import org.alfresco.rest.rm.community.base.BaseRMRestTest; import org.alfresco.rest.rm.community.base.TestData; import org.alfresco.rest.rm.community.model.fileplan.FilePlan; +import org.alfresco.rest.rm.community.model.record.RecordProperties; import org.alfresco.rest.rm.community.model.unfiledcontainer.UnfiledContainer; import org.alfresco.rest.rm.community.model.unfiledcontainer.UnfiledContainerChild; import org.alfresco.rest.rm.community.model.unfiledcontainer.UnfiledContainerChildCollection; @@ -59,6 +60,7 @@ import org.alfresco.rest.rm.community.model.unfiledcontainer.UnfiledContainerChi import org.alfresco.rest.rm.community.model.unfiledcontainer.UnfiledRecordFolder; import org.alfresco.rest.rm.community.requests.gscore.api.UnfiledContainerAPI; import org.alfresco.rest.rm.community.utils.FilePlanComponentsUtil; +import org.springframework.http.HttpStatus; import org.testng.annotations.AfterClass; import org.testng.annotations.AfterMethod; import org.testng.annotations.DataProvider; @@ -400,6 +402,29 @@ public class UnfiledContainerTests extends BaseRMRestTest // Verify the status code assertStatusCode(UNPROCESSABLE_ENTITY); } + + @Test(description = "Create a record with custom record identifier in unfiled container") + public void createRecordWithCustomIdentifier() throws Exception + { + String recordName = "customIdRecord-" + getRandomAlphanumeric(); + String customIdentifier = "customId"; + RecordProperties propertiesModel = RecordProperties.builder().identifier(customIdentifier).build(); + + UnfiledContainerChild childModel = UnfiledContainerChild.builder() + .name(recordName) + .nodeType(CONTENT_TYPE) + .properties(UnfiledContainerChildProperties.builder() + .identifier(customIdentifier) + .build()) + .build(); + + UnfiledContainerChild child = getRestAPIFactory().getUnfiledContainersAPI().createUnfiledContainerChild(childModel, UNFILED_RECORDS_CONTAINER_ALIAS); + + assertStatusCode(HttpStatus.CREATED); + assertEquals(child.getProperties().getIdentifier(), customIdentifier); + assertEquals(child.getName(), recordName + " (" + customIdentifier + ")"); + } + @AfterMethod @AfterClass (alwaysRun = true) public void tearDown() throws Exception diff --git a/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/record/RecordServiceImpl.java b/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/record/RecordServiceImpl.java index 364238d0c9..b40485f3a8 100644 --- a/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/record/RecordServiceImpl.java +++ b/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/record/RecordServiceImpl.java @@ -486,6 +486,8 @@ public class RecordServiceImpl extends BaseBehaviourBean } } + // recalculate disposition schedule for the record when linking it + dispositionService.recalculateNextDispositionStep(nodeRef); } } catch (RecordLinkRuntimeException e) @@ -1206,29 +1208,43 @@ public class RecordServiceImpl extends BaseBehaviourBean disablePropertyEditableCheck(); try { - // get the record id - String recordId = identifierService.generateIdentifier(ASPECT_RECORD, - nodeService.getPrimaryParent(document).getParentRef()); + authenticationUtil.runAsSystem(new RunAsWork() + { - // get the record name - String name = (String)nodeService.getProperty(document, ContentModel.PROP_NAME); + @Override + public Void doWork() throws Exception { + Map props = new HashMap<>(); - // add the record aspect - Map props = new HashMap(2); - props.put(PROP_IDENTIFIER, recordId); - props.put(PROP_ORIGIONAL_NAME, name); - nodeService.addAspect(document, RecordsManagementModel.ASPECT_RECORD, props); + if(!nodeService.hasAspect(document, ASPECT_RECORD_COMPONENT_ID)) + { + // get the record id + String recordId = identifierService.generateIdentifier(ASPECT_RECORD, + nodeService.getPrimaryParent(document).getParentRef()); - // remove versionable aspect(s) - nodeService.removeAspect(document, RecordableVersionModel.ASPECT_VERSIONABLE); + // get the record name + String name = (String)nodeService.getProperty(document, ContentModel.PROP_NAME); - // remove the owner - ownableService.setOwner(document, OwnableService.NO_OWNER); + // add the record aspect - if (TYPE_NON_ELECTRONIC_DOCUMENT.equals(nodeService.getType(document))) - { - appendIdentifierToName(nodeService, document); - } + props.put(PROP_IDENTIFIER, recordId); + props.put(PROP_ORIGIONAL_NAME, name); + } + nodeService.addAspect(document, RecordsManagementModel.ASPECT_RECORD, props); + + // remove versionable aspect(s) + nodeService.removeAspect(document, RecordableVersionModel.ASPECT_VERSIONABLE); + + // remove the owner + + ownableService.setOwner(document, OwnableService.NO_OWNER); + + if (TYPE_NON_ELECTRONIC_DOCUMENT.equals(nodeService.getType(document))) + { + appendIdentifierToName(nodeService, document); + } + return null; + } + }); } finally { diff --git a/rm-community/rm-community-repo/source/java/org/alfresco/rm/rest/api/impl/FilePlanComponentsApiUtils.java b/rm-community/rm-community-repo/source/java/org/alfresco/rm/rest/api/impl/FilePlanComponentsApiUtils.java index 7ba7add131..c4552503d6 100644 --- a/rm-community/rm-community-repo/source/java/org/alfresco/rm/rest/api/impl/FilePlanComponentsApiUtils.java +++ b/rm-community/rm-community-repo/source/java/org/alfresco/rm/rest/api/impl/FilePlanComponentsApiUtils.java @@ -617,13 +617,6 @@ public class FilePlanComponentsApiUtils QName typeQName = nodes.createQName(type); newNodeRef = fileFolderService.create(parentNodeRef, name, typeQName).getNodeRef(); - // Set the provided properties if any - Map qnameProperties = mapToNodeProperties(properties); - if (qnameProperties != null) - { - nodeService.addProperties(newNodeRef, qnameProperties); - } - // If electronic record create empty content if (!typeQName.equals(RecordsManagementModel.TYPE_NON_ELECTRONIC_DOCUMENT) && dictionaryService.isSubClass(typeQName, ContentModel.TYPE_CONTENT)) @@ -631,6 +624,13 @@ public class FilePlanComponentsApiUtils writeContent(newNodeRef, name, new ByteArrayInputStream("".getBytes()), false); } + // Set the provided properties if any + Map qnameProperties = mapToNodeProperties(properties); + if (qnameProperties != null) + { + nodeService.addProperties(newNodeRef, qnameProperties); + } + // Add the provided aspects if any if (aspects != null) { diff --git a/rm-community/rm-community-repo/source/java/org/alfresco/rm/rest/api/unfiledcontainers/UnfiledContainerChildrenRelation.java b/rm-community/rm-community-repo/source/java/org/alfresco/rm/rest/api/unfiledcontainers/UnfiledContainerChildrenRelation.java index f163b7a796..7e73f0fcd3 100644 --- a/rm-community/rm-community-repo/source/java/org/alfresco/rm/rest/api/unfiledcontainers/UnfiledContainerChildrenRelation.java +++ b/rm-community/rm-community-repo/source/java/org/alfresco/rm/rest/api/unfiledcontainers/UnfiledContainerChildrenRelation.java @@ -192,7 +192,7 @@ public class UnfiledContainerChildrenRelation implements RelationshipResourceAct return createdNodes; } }; - List createdNodes = transactionService.getRetryingTransactionHelper().doInTransaction(callback); + List createdNodes = transactionService.getRetryingTransactionHelper().doInTransaction(callback, false, true); // Get the nodes info List result = new LinkedList<>(); diff --git a/rm-community/rm-community-repo/test/java/org/alfresco/module/org_alfresco_module_rm/test/util/CommonRMTestUtils.java b/rm-community/rm-community-repo/test/java/org/alfresco/module/org_alfresco_module_rm/test/util/CommonRMTestUtils.java index 20b8947d0a..865be37d74 100644 --- a/rm-community/rm-community-repo/test/java/org/alfresco/module/org_alfresco_module_rm/test/util/CommonRMTestUtils.java +++ b/rm-community/rm-community-repo/test/java/org/alfresco/module/org_alfresco_module_rm/test/util/CommonRMTestUtils.java @@ -50,6 +50,7 @@ import org.alfresco.module.org_alfresco_module_rm.disposition.DispositionSchedul import org.alfresco.module.org_alfresco_module_rm.disposition.DispositionService; import org.alfresco.module.org_alfresco_module_rm.model.RecordsManagementModel; import org.alfresco.module.org_alfresco_module_rm.model.security.ModelSecurityService; +import org.alfresco.module.org_alfresco_module_rm.record.RecordService; import org.alfresco.module.org_alfresco_module_rm.role.FilePlanRoleService; import org.alfresco.module.org_alfresco_module_rm.role.Role; import org.alfresco.repo.content.MimetypeMap; @@ -78,6 +79,7 @@ public class CommonRMTestUtils implements RecordsManagementModel private ModelSecurityService modelSecurityService; private FilePlanRoleService filePlanRoleService; private CapabilityService capabilityService; + private RecordService recordService; /** test values */ public static final String DEFAULT_DISPOSITION_AUTHORITY = "disposition authority"; @@ -104,6 +106,7 @@ public class CommonRMTestUtils implements RecordsManagementModel modelSecurityService = (ModelSecurityService)applicationContext.getBean("ModelSecurityService"); filePlanRoleService = (FilePlanRoleService)applicationContext.getBean("FilePlanRoleService"); capabilityService = (CapabilityService)applicationContext.getBean("CapabilityService"); + recordService = (RecordService)applicationContext.getBean("RecordService"); } /** @@ -250,6 +253,9 @@ public class CommonRMTestUtils implements RecordsManagementModel writer.setEncoding("UTF-8"); writer.putContent(content); + // file the record + recordService.file(record); + return record; } @@ -273,6 +279,9 @@ public class CommonRMTestUtils implements RecordsManagementModel writer.setEncoding("UTF-8"); writer.putContent(content); + // file the record + recordService.file(record); + return record; }