mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-31 17:39:05 +00:00
RM-5012 - fixed custom identifier issue
This commit is contained in:
@@ -52,6 +52,7 @@ import java.util.NoSuchElementException;
|
|||||||
import org.alfresco.rest.rm.community.base.BaseRMRestTest;
|
import org.alfresco.rest.rm.community.base.BaseRMRestTest;
|
||||||
import org.alfresco.rest.rm.community.base.TestData;
|
import org.alfresco.rest.rm.community.base.TestData;
|
||||||
import org.alfresco.rest.rm.community.model.fileplan.FilePlan;
|
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.UnfiledContainer;
|
||||||
import org.alfresco.rest.rm.community.model.unfiledcontainer.UnfiledContainerChild;
|
import org.alfresco.rest.rm.community.model.unfiledcontainer.UnfiledContainerChild;
|
||||||
import org.alfresco.rest.rm.community.model.unfiledcontainer.UnfiledContainerChildCollection;
|
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.model.unfiledcontainer.UnfiledRecordFolder;
|
||||||
import org.alfresco.rest.rm.community.requests.gscore.api.UnfiledContainerAPI;
|
import org.alfresco.rest.rm.community.requests.gscore.api.UnfiledContainerAPI;
|
||||||
import org.alfresco.rest.rm.community.utils.FilePlanComponentsUtil;
|
import org.alfresco.rest.rm.community.utils.FilePlanComponentsUtil;
|
||||||
|
import org.springframework.http.HttpStatus;
|
||||||
import org.testng.annotations.AfterClass;
|
import org.testng.annotations.AfterClass;
|
||||||
import org.testng.annotations.AfterMethod;
|
import org.testng.annotations.AfterMethod;
|
||||||
import org.testng.annotations.DataProvider;
|
import org.testng.annotations.DataProvider;
|
||||||
@@ -400,6 +402,29 @@ public class UnfiledContainerTests extends BaseRMRestTest
|
|||||||
// Verify the status code
|
// Verify the status code
|
||||||
assertStatusCode(UNPROCESSABLE_ENTITY);
|
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
|
@AfterMethod
|
||||||
@AfterClass (alwaysRun = true)
|
@AfterClass (alwaysRun = true)
|
||||||
public void tearDown() throws Exception
|
public void tearDown() throws Exception
|
||||||
|
@@ -486,6 +486,8 @@ public class RecordServiceImpl extends BaseBehaviourBean
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// recalculate disposition schedule for the record when linking it
|
||||||
|
dispositionService.recalculateNextDispositionStep(nodeRef);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (RecordLinkRuntimeException e)
|
catch (RecordLinkRuntimeException e)
|
||||||
@@ -1206,29 +1208,43 @@ public class RecordServiceImpl extends BaseBehaviourBean
|
|||||||
disablePropertyEditableCheck();
|
disablePropertyEditableCheck();
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// get the record id
|
authenticationUtil.runAsSystem(new RunAsWork<Void>()
|
||||||
String recordId = identifierService.generateIdentifier(ASPECT_RECORD,
|
{
|
||||||
nodeService.getPrimaryParent(document).getParentRef());
|
|
||||||
|
|
||||||
// get the record name
|
@Override
|
||||||
String name = (String)nodeService.getProperty(document, ContentModel.PROP_NAME);
|
public Void doWork() throws Exception {
|
||||||
|
Map<QName, Serializable> props = new HashMap<>();
|
||||||
|
|
||||||
// add the record aspect
|
if(!nodeService.hasAspect(document, ASPECT_RECORD_COMPONENT_ID))
|
||||||
Map<QName, Serializable> props = new HashMap<QName, Serializable>(2);
|
{
|
||||||
props.put(PROP_IDENTIFIER, recordId);
|
// get the record id
|
||||||
props.put(PROP_ORIGIONAL_NAME, name);
|
String recordId = identifierService.generateIdentifier(ASPECT_RECORD,
|
||||||
nodeService.addAspect(document, RecordsManagementModel.ASPECT_RECORD, props);
|
nodeService.getPrimaryParent(document).getParentRef());
|
||||||
|
|
||||||
// remove versionable aspect(s)
|
// get the record name
|
||||||
nodeService.removeAspect(document, RecordableVersionModel.ASPECT_VERSIONABLE);
|
String name = (String)nodeService.getProperty(document, ContentModel.PROP_NAME);
|
||||||
|
|
||||||
// remove the owner
|
// add the record aspect
|
||||||
ownableService.setOwner(document, OwnableService.NO_OWNER);
|
|
||||||
|
|
||||||
if (TYPE_NON_ELECTRONIC_DOCUMENT.equals(nodeService.getType(document)))
|
props.put(PROP_IDENTIFIER, recordId);
|
||||||
{
|
props.put(PROP_ORIGIONAL_NAME, name);
|
||||||
appendIdentifierToName(nodeService, document);
|
}
|
||||||
}
|
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
|
finally
|
||||||
{
|
{
|
||||||
|
@@ -617,13 +617,6 @@ public class FilePlanComponentsApiUtils
|
|||||||
QName typeQName = nodes.createQName(type);
|
QName typeQName = nodes.createQName(type);
|
||||||
newNodeRef = fileFolderService.create(parentNodeRef, name, typeQName).getNodeRef();
|
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 electronic record create empty content
|
||||||
if (!typeQName.equals(RecordsManagementModel.TYPE_NON_ELECTRONIC_DOCUMENT)
|
if (!typeQName.equals(RecordsManagementModel.TYPE_NON_ELECTRONIC_DOCUMENT)
|
||||||
&& dictionaryService.isSubClass(typeQName, ContentModel.TYPE_CONTENT))
|
&& dictionaryService.isSubClass(typeQName, ContentModel.TYPE_CONTENT))
|
||||||
@@ -631,6 +624,13 @@ public class FilePlanComponentsApiUtils
|
|||||||
writeContent(newNodeRef, name, new ByteArrayInputStream("".getBytes()), false);
|
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
|
// Add the provided aspects if any
|
||||||
if (aspects != null)
|
if (aspects != null)
|
||||||
{
|
{
|
||||||
|
@@ -192,7 +192,7 @@ public class UnfiledContainerChildrenRelation implements RelationshipResourceAct
|
|||||||
return createdNodes;
|
return createdNodes;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
List<NodeRef> createdNodes = transactionService.getRetryingTransactionHelper().doInTransaction(callback);
|
List<NodeRef> createdNodes = transactionService.getRetryingTransactionHelper().doInTransaction(callback, false, true);
|
||||||
|
|
||||||
// Get the nodes info
|
// Get the nodes info
|
||||||
List<UnfiledContainerChild> result = new LinkedList<>();
|
List<UnfiledContainerChild> result = new LinkedList<>();
|
||||||
|
@@ -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.disposition.DispositionService;
|
||||||
import org.alfresco.module.org_alfresco_module_rm.model.RecordsManagementModel;
|
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.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.FilePlanRoleService;
|
||||||
import org.alfresco.module.org_alfresco_module_rm.role.Role;
|
import org.alfresco.module.org_alfresco_module_rm.role.Role;
|
||||||
import org.alfresco.repo.content.MimetypeMap;
|
import org.alfresco.repo.content.MimetypeMap;
|
||||||
@@ -78,6 +79,7 @@ public class CommonRMTestUtils implements RecordsManagementModel
|
|||||||
private ModelSecurityService modelSecurityService;
|
private ModelSecurityService modelSecurityService;
|
||||||
private FilePlanRoleService filePlanRoleService;
|
private FilePlanRoleService filePlanRoleService;
|
||||||
private CapabilityService capabilityService;
|
private CapabilityService capabilityService;
|
||||||
|
private RecordService recordService;
|
||||||
|
|
||||||
/** test values */
|
/** test values */
|
||||||
public static final String DEFAULT_DISPOSITION_AUTHORITY = "disposition authority";
|
public static final String DEFAULT_DISPOSITION_AUTHORITY = "disposition authority";
|
||||||
@@ -104,6 +106,7 @@ public class CommonRMTestUtils implements RecordsManagementModel
|
|||||||
modelSecurityService = (ModelSecurityService)applicationContext.getBean("ModelSecurityService");
|
modelSecurityService = (ModelSecurityService)applicationContext.getBean("ModelSecurityService");
|
||||||
filePlanRoleService = (FilePlanRoleService)applicationContext.getBean("FilePlanRoleService");
|
filePlanRoleService = (FilePlanRoleService)applicationContext.getBean("FilePlanRoleService");
|
||||||
capabilityService = (CapabilityService)applicationContext.getBean("CapabilityService");
|
capabilityService = (CapabilityService)applicationContext.getBean("CapabilityService");
|
||||||
|
recordService = (RecordService)applicationContext.getBean("RecordService");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -250,6 +253,9 @@ public class CommonRMTestUtils implements RecordsManagementModel
|
|||||||
writer.setEncoding("UTF-8");
|
writer.setEncoding("UTF-8");
|
||||||
writer.putContent(content);
|
writer.putContent(content);
|
||||||
|
|
||||||
|
// file the record
|
||||||
|
recordService.file(record);
|
||||||
|
|
||||||
return record;
|
return record;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -273,6 +279,9 @@ public class CommonRMTestUtils implements RecordsManagementModel
|
|||||||
writer.setEncoding("UTF-8");
|
writer.setEncoding("UTF-8");
|
||||||
writer.putContent(content);
|
writer.putContent(content);
|
||||||
|
|
||||||
|
// file the record
|
||||||
|
recordService.file(record);
|
||||||
|
|
||||||
return record;
|
return record;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user