RM-5012 - fixed custom identifier issue

This commit is contained in:
Ana Bozianu
2017-05-12 18:54:31 +03:00
parent 1d50299bd2
commit f971c80a37
5 changed files with 76 additions and 26 deletions

View File

@@ -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

View File

@@ -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<Void>()
{
// get the record name
String name = (String)nodeService.getProperty(document, ContentModel.PROP_NAME);
@Override
public Void doWork() throws Exception {
Map<QName, Serializable> props = new HashMap<>();
// add the record aspect
Map<QName, Serializable> props = new HashMap<QName, Serializable>(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
{

View File

@@ -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<QName, Serializable> 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<QName, Serializable> qnameProperties = mapToNodeProperties(properties);
if (qnameProperties != null)
{
nodeService.addProperties(newNodeRef, qnameProperties);
}
// Add the provided aspects if any
if (aspects != null)
{

View File

@@ -192,7 +192,7 @@ public class UnfiledContainerChildrenRelation implements RelationshipResourceAct
return createdNodes;
}
};
List<NodeRef> createdNodes = transactionService.getRetryingTransactionHelper().doInTransaction(callback);
List<NodeRef> createdNodes = transactionService.getRetryingTransactionHelper().doInTransaction(callback, false, true);
// Get the nodes info
List<UnfiledContainerChild> result = new LinkedList<>();

View File

@@ -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;
}