mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-31 17:39:05 +00:00
Feature/rm 4639 rest api refactoring 2
This commit is contained in:
@@ -26,16 +26,20 @@
|
||||
*/
|
||||
package org.alfresco.rest.rm.community.base;
|
||||
|
||||
import static org.alfresco.rest.rm.community.base.TestData.CATEGORY_TITLE;
|
||||
import static org.alfresco.rest.rm.community.base.TestData.FOLDER_TITLE;
|
||||
import static lombok.AccessLevel.PROTECTED;
|
||||
|
||||
import static org.alfresco.rest.rm.community.base.TestData.RECORD_CATEGORY_TITLE;
|
||||
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentAlias.FILE_PLAN_ALIAS;
|
||||
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentAlias.UNFILED_RECORDS_CONTAINER_ALIAS;
|
||||
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentAspects.ASPECTS_CLOSED_RECORD;
|
||||
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentAspects.ASPECTS_COMPLETED_RECORD;
|
||||
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.RECORD_CATEGORY_TYPE;
|
||||
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.RECORD_FOLDER_TYPE;
|
||||
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.RECORD_TYPE;
|
||||
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.UNFILED_RECORD_FOLDER_TYPE;
|
||||
import static org.alfresco.rest.rm.community.utils.FilePlanComponentsUtil.createFilePlanComponentModel;
|
||||
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.UNFILED_CONTAINER_TYPE;
|
||||
import static org.alfresco.rest.rm.community.utils.FilePlanComponentsUtil.createRecordCategoryChildModel;
|
||||
import static org.alfresco.rest.rm.community.utils.FilePlanComponentsUtil.createRecordCategoryModel;
|
||||
import static org.alfresco.rest.rm.community.utils.FilePlanComponentsUtil.createUnfiledContainerChildModel;
|
||||
import static org.alfresco.rest.rm.community.utils.RMSiteUtil.createStandardRMSiteModel;
|
||||
import static org.alfresco.utility.data.RandomData.getRandomAlphanumeric;
|
||||
import static org.springframework.http.HttpStatus.CREATED;
|
||||
@@ -47,10 +51,18 @@ import java.util.List;
|
||||
|
||||
import org.alfresco.rest.RestTest;
|
||||
import org.alfresco.rest.core.RestAPIFactory;
|
||||
import org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponent;
|
||||
import org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentProperties;
|
||||
import org.alfresco.rest.rm.community.requests.igCoreAPI.FilePlanComponentAPI;
|
||||
import org.alfresco.rest.rm.community.requests.igCoreAPI.RMSiteAPI;
|
||||
import org.alfresco.rest.rm.community.model.fileplan.FilePlan;
|
||||
import org.alfresco.rest.rm.community.model.record.Record;
|
||||
import org.alfresco.rest.rm.community.model.recordcategory.RecordCategory;
|
||||
import org.alfresco.rest.rm.community.model.recordcategory.RecordCategoryChild;
|
||||
import org.alfresco.rest.rm.community.model.recordfolder.RecordFolder;
|
||||
import org.alfresco.rest.rm.community.model.recordfolder.RecordFolderProperties;
|
||||
import org.alfresco.rest.rm.community.model.transfercontainer.TransferContainer;
|
||||
import org.alfresco.rest.rm.community.model.unfiledcontainer.UnfiledContainer;
|
||||
import org.alfresco.rest.rm.community.model.unfiledcontainer.UnfiledContainerChild;
|
||||
import org.alfresco.rest.rm.community.requests.gscore.api.RMSiteAPI;
|
||||
import org.alfresco.rest.rm.community.requests.gscore.api.RecordCategoryAPI;
|
||||
import org.alfresco.rest.rm.community.requests.gscore.api.RecordsAPI;
|
||||
import org.alfresco.utility.data.DataUser;
|
||||
import org.alfresco.utility.model.UserModel;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -58,8 +70,10 @@ import org.springframework.http.HttpStatus;
|
||||
import org.testng.annotations.BeforeClass;
|
||||
import org.testng.annotations.DataProvider;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* Base class for all IG REST API Tests
|
||||
* Base class for all GS REST API Tests
|
||||
*
|
||||
* @author Kristijan Conkas
|
||||
* @author Tuna Aksoy
|
||||
@@ -68,31 +82,13 @@ import org.testng.annotations.DataProvider;
|
||||
public class BaseRMRestTest extends RestTest
|
||||
{
|
||||
@Autowired
|
||||
@Getter (value = PROTECTED)
|
||||
private RestAPIFactory restAPIFactory;
|
||||
|
||||
@Autowired
|
||||
@Getter (value = PROTECTED)
|
||||
private DataUser dataUser;
|
||||
|
||||
/**
|
||||
* Gets the REST API Factory
|
||||
*
|
||||
* @return the restAPIFactory The REST API Factory
|
||||
*/
|
||||
protected RestAPIFactory getRestAPIFactory()
|
||||
{
|
||||
return this.restAPIFactory;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the data user
|
||||
*
|
||||
* @return the dataUser The data user
|
||||
*/
|
||||
protected DataUser getDataUser()
|
||||
{
|
||||
return this.dataUser;
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts the given status code
|
||||
*
|
||||
@@ -100,7 +96,7 @@ public class BaseRMRestTest extends RestTest
|
||||
*/
|
||||
protected void assertStatusCode(HttpStatus statusCode)
|
||||
{
|
||||
restAPIFactory.getRmRestWrapper().assertStatusCodeIs(statusCode);
|
||||
getRestAPIFactory().getRmRestWrapper().assertStatusCodeIs(statusCode);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -115,16 +111,16 @@ public class BaseRMRestTest extends RestTest
|
||||
|
||||
/** Valid root containers where electronic and non-electronic records can be created */
|
||||
@DataProvider(name = "validRootContainers")
|
||||
public Object[][] getValidRootContainers() throws Exception
|
||||
public String[][] getValidRootContainers() throws Exception
|
||||
{
|
||||
return new Object[][]
|
||||
return new String[][]
|
||||
{
|
||||
// an arbitrary record folder
|
||||
{ createCategoryFolderInFilePlan() },
|
||||
{ createCategoryFolderInFilePlan().getId(), RECORD_FOLDER_TYPE},
|
||||
// unfiled records root
|
||||
{ getFilePlanComponent(UNFILED_RECORDS_CONTAINER_ALIAS) },
|
||||
{ UNFILED_RECORDS_CONTAINER_ALIAS, UNFILED_CONTAINER_TYPE},
|
||||
// an arbitrary unfiled records folder
|
||||
{ createUnfiledRecordsFolder(UNFILED_RECORDS_CONTAINER_ALIAS, "Unfiled Folder " + getRandomAlphanumeric()) }
|
||||
{ createUnfiledContainerChild(UNFILED_RECORDS_CONTAINER_ALIAS, "Unfiled Folder " + getRandomAlphanumeric(), UNFILED_RECORD_FOLDER_TYPE).getId(), UNFILED_RECORD_FOLDER_TYPE }
|
||||
};
|
||||
}
|
||||
|
||||
@@ -145,7 +141,7 @@ public class BaseRMRestTest extends RestTest
|
||||
*/
|
||||
public void createRMSiteIfNotExists() throws Exception
|
||||
{
|
||||
RMSiteAPI rmSiteAPI = restAPIFactory.getRMSiteAPI();
|
||||
RMSiteAPI rmSiteAPI = getRestAPIFactory().getRMSiteAPI();
|
||||
|
||||
// Check RM site doesn't exist
|
||||
if (!rmSiteAPI.existsRMSite())
|
||||
@@ -159,71 +155,162 @@ public class BaseRMRestTest extends RestTest
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method to create child category
|
||||
* Helper method to create root category as the admin user
|
||||
*
|
||||
* @param user The user under whose privileges this structure is going to be created
|
||||
* @param parentCategoryId The id of the parent category
|
||||
* @param categoryName The name of the category
|
||||
* @return The created category
|
||||
* @throws Exception on unsuccessful component creation
|
||||
*/
|
||||
public FilePlanComponent createCategory(UserModel user, String parentCategoryId, String categoryName) throws Exception
|
||||
public RecordCategory createRootCategory(String categoryName) throws Exception
|
||||
{
|
||||
return createComponent(user, parentCategoryId, categoryName, RECORD_CATEGORY_TYPE, CATEGORY_TITLE);
|
||||
return createRootCategory(getAdminUser(), categoryName, RECORD_CATEGORY_TITLE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method to create child category as the admin user
|
||||
* Helper method to create root category
|
||||
*
|
||||
* @param parentCategoryId The id of the parent category
|
||||
* @param userModel The user under whose privileges this structure is going to be created
|
||||
* @param categoryName The name of the category
|
||||
* @return The created category
|
||||
* @throws Exception on unsuccessful component creation
|
||||
*/
|
||||
public FilePlanComponent createCategory(String parentCategoryId, String categoryName) throws Exception
|
||||
public RecordCategory createRootCategory(UserModel userModel, String categoryName) throws Exception
|
||||
{
|
||||
return createCategory(getAdminUser(), parentCategoryId, categoryName);
|
||||
return createRootCategory(userModel, categoryName, RECORD_CATEGORY_TITLE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method to create child folder
|
||||
* Helper method to create root category as the admin user
|
||||
*
|
||||
* @param categoryName The name of the category
|
||||
* @param categoryTitle The title of the category
|
||||
* @return The created category
|
||||
* @throws Exception on unsuccessful component creation
|
||||
*/
|
||||
public RecordCategory createRootCategory(String categoryName, String categoryTitle) throws Exception
|
||||
{
|
||||
return createRootCategory(getAdminUser(), categoryName, categoryTitle);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method to create root category
|
||||
*
|
||||
* @param userModel The user under whose privileges this structure is going to be created
|
||||
* @param categoryName The name of the category
|
||||
* @param categoryTitle The title of the category
|
||||
* @return The created category
|
||||
* @throws Exception on unsuccessful component creation
|
||||
*/
|
||||
public RecordCategory createRootCategory(UserModel userModel, String categoryName, String categoryTitle) throws Exception
|
||||
{
|
||||
RecordCategory recordCategoryModel = createRecordCategoryModel(categoryName, categoryTitle);
|
||||
return getRestAPIFactory().getFilePlansAPI(userModel).createRootRecordCategory(recordCategoryModel, FILE_PLAN_ALIAS);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method to create a record category child
|
||||
*
|
||||
* @param user The user under whose privileges the node is going to be created
|
||||
* @param recordCategoryId The id of the record category
|
||||
* @param name The name of the record category child
|
||||
* @param type The type of the record category child
|
||||
* @param title The title of the record category child
|
||||
* @return The created {@link RecordCategoryChild}
|
||||
* @throws Exception {@link RecordCategoryAPI#createRecordCategoryChild(RecordCategoryChild, String)}
|
||||
*/
|
||||
public RecordCategoryChild createRecordCategoryChild(UserModel user, String recordCategoryId, String name, String type) throws Exception
|
||||
{
|
||||
RecordCategoryChild recordCategoryChildModel = createRecordCategoryChildModel(name, type);
|
||||
return getRestAPIFactory().getRecordCategoryAPI(user).createRecordCategoryChild(recordCategoryChildModel, recordCategoryId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method to create a record category child as the admin user
|
||||
*
|
||||
* @param user The user under whose privileges the node is going to be created
|
||||
* @param recordCategoryId The id of the record category
|
||||
* @param name The name of the record category child
|
||||
* @param type The type of the record category child
|
||||
* @param title The title of the record category child
|
||||
* @return The created {@link RecordCategoryChild}
|
||||
* @throws Exception {@link RecordCategoryAPI#createRecordCategoryChild(RecordCategoryChild, String)}
|
||||
*/
|
||||
public RecordCategoryChild createRecordCategoryChild(String recordCategoryId, String name, String type) throws Exception
|
||||
{
|
||||
return createRecordCategoryChild(getAdminUser(), recordCategoryId, name, type);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method to create a record category as the admin user
|
||||
*
|
||||
* @param recordCategoryId The id of the record category
|
||||
* @param name The name of the record category child
|
||||
* @return The created {@link RecordCategoryChild}
|
||||
* @throws Exception {@link RecordCategoryAPI#createRecordCategoryChild(RecordCategoryChild, String)}
|
||||
*/
|
||||
public RecordCategoryChild createRecordCategory(String recordCategoryId, String name) throws Exception
|
||||
{
|
||||
return createRecordCategoryChild(getAdminUser(), recordCategoryId, name, RECORD_CATEGORY_TYPE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method to create a record folder as the admin user
|
||||
*
|
||||
* @param recordCategoryId The id of the record category
|
||||
* @param name The name of the record category child
|
||||
* @return The created {@link RecordCategoryChild}
|
||||
* @throws Exception {@link RecordCategoryAPI#createRecordCategoryChild(RecordCategoryChild, String)}
|
||||
*/
|
||||
public RecordCategoryChild createRecordFolder(String recordCategoryId, String name) throws Exception
|
||||
{
|
||||
return createRecordCategoryChild(getAdminUser(), recordCategoryId, name, RECORD_FOLDER_TYPE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method to create record folder
|
||||
*
|
||||
* @param user The user under whose privileges this structure is going to be created
|
||||
* @param parentCategoryId The id of the parent category
|
||||
* @param folderName The name of the category
|
||||
* @return The created category
|
||||
* @param recordCategoryId The id of the record category
|
||||
* @param name The name of the folder
|
||||
* @return The created folder
|
||||
* @throws Exception on unsuccessful component creation
|
||||
*/
|
||||
public FilePlanComponent createFolder(UserModel user, String parentCategoryId, String folderName) throws Exception
|
||||
public RecordCategoryChild createFolder(UserModel user, String recordCategoryId, String name) throws Exception
|
||||
{
|
||||
return createComponent(user, parentCategoryId, folderName, RECORD_FOLDER_TYPE, FOLDER_TITLE);
|
||||
RecordCategoryChild recordFolderModel = createRecordCategoryChildModel(name, RECORD_FOLDER_TYPE);
|
||||
return getRestAPIFactory().getRecordCategoryAPI(user).createRecordCategoryChild(recordFolderModel, recordCategoryId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method to create child folder as the admin user
|
||||
* Helper method to create record folder as the admin user
|
||||
*
|
||||
* @param parentCategoryId The id of the parent category
|
||||
* @param folderName The name of the category
|
||||
* @return The created category
|
||||
* @param recordCategoryId The id of the record category
|
||||
* @param name The name of the folder
|
||||
* @return The created folder
|
||||
* @throws Exception on unsuccessful component creation
|
||||
*/
|
||||
public FilePlanComponent createFolder(String parentCategoryId, String folderName) throws Exception
|
||||
public RecordCategoryChild createFolder(String recordCategoryId, String name) throws Exception
|
||||
{
|
||||
return createFolder(getAdminUser(), parentCategoryId, folderName);
|
||||
return createFolder(getAdminUser(), recordCategoryId, name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method to create child unfiled record folder
|
||||
*
|
||||
* @param user The user under whose privileges this structure is going to be created
|
||||
*@param user The user under whose privileges this structure is going to be created
|
||||
* @param parentId The id of the parent folder
|
||||
* @param folderName The name of the folder
|
||||
* @param nodeType The child type
|
||||
* @return The created folder
|
||||
* @throws Exception on unsuccessful component creation
|
||||
*/
|
||||
public FilePlanComponent createUnfiledRecordsFolder(UserModel user, String parentId, String folderName) throws Exception
|
||||
public UnfiledContainerChild createUnfiledRecordsFolderChild(UserModel user, String parentId, String childName, String nodeType) throws Exception
|
||||
{
|
||||
return createComponent(user, parentId, folderName, UNFILED_RECORD_FOLDER_TYPE, FOLDER_TITLE);
|
||||
UnfiledContainerChild childModel = createUnfiledContainerChildModel(childName, nodeType);
|
||||
UnfiledContainerChild child = getRestAPIFactory().getUnfiledRecordFoldersAPI(user).createUnfiledRecordFolderChild(childModel, parentId);
|
||||
assertStatusCode(CREATED);
|
||||
|
||||
return child;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -231,32 +318,46 @@ public class BaseRMRestTest extends RestTest
|
||||
*
|
||||
* @param parentId The id of the parent folder
|
||||
* @param folderName The name of the folder
|
||||
* @param nodeType The child type
|
||||
* @return The created folder
|
||||
* @throws Exception on unsuccessful component creation
|
||||
*/
|
||||
public FilePlanComponent createUnfiledRecordsFolder(String parentId, String folderName) throws Exception
|
||||
public UnfiledContainerChild createUnfiledRecordsFolderChild(String parentId, String childName, String nodeType) throws Exception
|
||||
{
|
||||
return createUnfiledRecordsFolder(getAdminUser(), parentId, folderName);
|
||||
return createUnfiledRecordsFolderChild(getAdminUser(), parentId, childName, nodeType);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method to create generic child component
|
||||
* Helper method to create a child to an unfiled record container
|
||||
*
|
||||
* @param user user under whose privileges this structure is going to be created
|
||||
* @param parentComponentId The id of the parent file plan component
|
||||
* @param componentName The name of the file plan component
|
||||
* @param componentType The type of the file plan component
|
||||
* @param componentTitle The title of the file plan component
|
||||
* @return The created file plan component
|
||||
* @throws Exception
|
||||
* @param user The user under whose privileges this structure is going to be created
|
||||
* @param parentId The id of the parent container
|
||||
* @param childName The name of the child
|
||||
* @oaram nodeType the child type
|
||||
* @return The created chid
|
||||
* @throws Exception on unsuccessful child creation
|
||||
*/
|
||||
private FilePlanComponent createComponent(UserModel user, String parentComponentId, String componentName, String componentType, String componentTitle) throws Exception
|
||||
public UnfiledContainerChild createUnfiledContainerChild(UserModel user, String parentId, String childName, String nodeType) throws Exception
|
||||
{
|
||||
FilePlanComponent filePlanComponentModel = createFilePlanComponentModel(componentName, componentType, componentTitle);
|
||||
FilePlanComponent filePlanComponent = getRestAPIFactory().getFilePlanComponentsAPI(user).createFilePlanComponent(filePlanComponentModel, parentComponentId);
|
||||
UnfiledContainerChild childModel = createUnfiledContainerChildModel(childName, nodeType);
|
||||
UnfiledContainerChild child = getRestAPIFactory().getUnfiledContainersAPI(user).createUnfiledContainerChild(childModel, parentId);
|
||||
assertStatusCode(CREATED);
|
||||
|
||||
return filePlanComponent;
|
||||
return child;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method to create a child to an unfiled record container as the admin user
|
||||
*
|
||||
* @param parentId The id of the parent container
|
||||
* @param childName The name of the child
|
||||
* @oaram nodeType the child type
|
||||
* @return The created chid
|
||||
* @throws Exception on unsuccessful child creation
|
||||
*/
|
||||
public UnfiledContainerChild createUnfiledContainerChild(String parentId, String childName, String nodeType) throws Exception
|
||||
{
|
||||
return createUnfiledContainerChild(getAdminUser(), parentId, childName, nodeType);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -266,56 +367,55 @@ public class BaseRMRestTest extends RestTest
|
||||
* @return The closed folder
|
||||
* @throws Exception
|
||||
*/
|
||||
protected FilePlanComponent closeFolder(String folderId) throws Exception
|
||||
protected RecordFolder closeFolder(String folderId) throws Exception
|
||||
{
|
||||
// build file plan component + properties for update request
|
||||
FilePlanComponentProperties properties = new FilePlanComponentProperties();
|
||||
properties.setIsClosed(true);
|
||||
FilePlanComponent filePlanComponent = new FilePlanComponent();
|
||||
filePlanComponent.setProperties(properties);
|
||||
|
||||
FilePlanComponent updatedComponent = getRestAPIFactory().getFilePlanComponentsAPI().updateFilePlanComponent(filePlanComponent, folderId);
|
||||
RecordFolder recordFolderModel = RecordFolder.builder()
|
||||
.properties(RecordFolderProperties.builder()
|
||||
.isClosed(true)
|
||||
.build())
|
||||
.build();
|
||||
RecordFolder updateRecordFolder = getRestAPIFactory().getRecordFolderAPI().updateRecordFolder(recordFolderModel, folderId);
|
||||
assertStatusCode(OK);
|
||||
return updatedComponent;
|
||||
|
||||
return updateRecordFolder;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method to close record
|
||||
* Helper method to complete record
|
||||
*
|
||||
* @param recordToClose Record to close
|
||||
* @return The closed record
|
||||
* @param recordId The id of the record to complete
|
||||
* @return The completed record
|
||||
* @throws Exception
|
||||
*/
|
||||
public FilePlanComponent closeRecord(FilePlanComponent recordToClose) throws Exception
|
||||
public Record completeRecord(String recordId) throws Exception
|
||||
{
|
||||
FilePlanComponentAPI filePlanComponentsAPI = getRestAPIFactory().getFilePlanComponentsAPI();
|
||||
List<String> aspects = filePlanComponentsAPI.getFilePlanComponent(recordToClose.getId()).getAspectNames();
|
||||
RecordsAPI recordsAPI = getRestAPIFactory().getRecordsAPI();
|
||||
List<String> aspects = recordsAPI.getRecord(recordId).getAspectNames();
|
||||
|
||||
// this operation is only valid for records
|
||||
assertTrue(aspects.contains(RECORD_TYPE));
|
||||
// a record mustn't be closed
|
||||
assertFalse(aspects.contains(ASPECTS_CLOSED_RECORD));
|
||||
// a record mustn't be completed
|
||||
assertFalse(aspects.contains(ASPECTS_COMPLETED_RECORD));
|
||||
// add completed record aspect
|
||||
aspects.add(ASPECTS_COMPLETED_RECORD);
|
||||
|
||||
// add closed record aspect
|
||||
aspects.add(ASPECTS_CLOSED_RECORD);
|
||||
|
||||
FilePlanComponent updatedComponent = filePlanComponentsAPI.updateFilePlanComponent(FilePlanComponent.builder().aspectNames(aspects).build(),
|
||||
recordToClose.getId());
|
||||
Record updateRecord = recordsAPI.updateRecord(Record.builder().aspectNames(aspects).build(), recordId);
|
||||
assertStatusCode(OK);
|
||||
return updatedComponent;
|
||||
|
||||
return updateRecord;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method to create a randomly-named <category>/<folder> structure in file plan
|
||||
*
|
||||
* @param user The user under whose privileges this structure is going to be created
|
||||
* @param parentId parent container id
|
||||
* @return record folder
|
||||
* @return {@link RecordCategoryChild} which represents the record folder
|
||||
* @throws Exception on failed creation
|
||||
*/
|
||||
public FilePlanComponent createCategoryFolderInFilePlan(UserModel user) throws Exception
|
||||
public RecordCategoryChild createCategoryFolderInFilePlan(UserModel user) throws Exception
|
||||
{
|
||||
// create root category
|
||||
FilePlanComponent recordCategory = createCategory(user, FILE_PLAN_ALIAS, "Category " + getRandomAlphanumeric());
|
||||
RecordCategory recordCategory = createRootCategory(user, "Category " + getRandomAlphanumeric());
|
||||
|
||||
// and return a folder underneath
|
||||
return createFolder(user, recordCategory.getId(), "Folder " + getRandomAlphanumeric());
|
||||
@@ -324,38 +424,41 @@ public class BaseRMRestTest extends RestTest
|
||||
/**
|
||||
* Helper method to create a randomly-named <category>/<folder> structure in file plan as the admin user
|
||||
*
|
||||
* @param parentId parent container id
|
||||
* @return record folder
|
||||
* @return {@link RecordCategoryChild} which represents the record folder
|
||||
* @throws Exception on failed creation
|
||||
*/
|
||||
public FilePlanComponent createCategoryFolderInFilePlan() throws Exception
|
||||
public RecordCategoryChild createCategoryFolderInFilePlan() throws Exception
|
||||
{
|
||||
return createCategoryFolderInFilePlan(getAdminUser());
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method to retrieve a file plan component with user's privilege
|
||||
*
|
||||
* @param user user under whose privileges a component is to be read
|
||||
* @param componentId id of the component to read
|
||||
* @return {@link FilePlanComponent} for given componentId
|
||||
* @throws Exception if user doesn't have sufficient privileges
|
||||
*/
|
||||
public FilePlanComponent getFilePlanComponentAsUser(UserModel user, String componentId) throws Exception
|
||||
public UnfiledContainer getUnfiledContainerAsUser(UserModel user, String componentId) throws Exception
|
||||
{
|
||||
return getRestAPIFactory().getFilePlanComponentsAPI(user).getFilePlanComponent(componentId);
|
||||
return getRestAPIFactory().getUnfiledContainersAPI(user).getUnfiledContainer(componentId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method to retrieve a file plan component with user's privilege as the admin user
|
||||
*
|
||||
* @param componentId id of the component to read
|
||||
* @return {@link FilePlanComponent} for given componentId
|
||||
* @throws Exception if user doesn't have sufficient privileges
|
||||
*/
|
||||
public FilePlanComponent getFilePlanComponent(String componentId) throws Exception
|
||||
public UnfiledContainer getUnfiledContainer(String componentId) throws Exception
|
||||
{
|
||||
return getFilePlanComponentAsUser(getAdminUser(), componentId);
|
||||
return getUnfiledContainerAsUser(getAdminUser(), componentId);
|
||||
}
|
||||
|
||||
public TransferContainer getTransferContainerAsUser(UserModel user, String componentId) throws Exception
|
||||
{
|
||||
return getRestAPIFactory().getTransferContainerAPI(user).getTransferContainer(componentId);
|
||||
}
|
||||
|
||||
public TransferContainer getTransferContainer(String componentId) throws Exception
|
||||
{
|
||||
return getTransferContainerAsUser(getAdminUser(), componentId);
|
||||
}
|
||||
|
||||
public FilePlan getFilePlanAsUser(UserModel user, String componentId) throws Exception
|
||||
{
|
||||
return getRestAPIFactory().getFilePlansAPI(user).getFilePlan(componentId);
|
||||
}
|
||||
|
||||
public FilePlan getFilePlan(String componentId) throws Exception
|
||||
{
|
||||
return getFilePlanAsUser(getAdminUser(), componentId);
|
||||
}
|
||||
}
|
||||
|
@@ -27,14 +27,11 @@
|
||||
package org.alfresco.rest.rm.community.base;
|
||||
|
||||
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentAlias.FILE_PLAN_ALIAS;
|
||||
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentAlias.HOLDS_ALIAS;
|
||||
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentAlias.TRANSFERS_ALIAS;
|
||||
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentAlias.UNFILED_RECORDS_CONTAINER_ALIAS;
|
||||
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.CONTENT_TYPE;
|
||||
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.FILE_PLAN_TYPE;
|
||||
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.FOLDER_TYPE;
|
||||
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.HOLD_CONTAINER_TYPE;
|
||||
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.HOLD_TYPE;
|
||||
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.RECORD_CATEGORY_TYPE;
|
||||
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.RECORD_FOLDER_TYPE;
|
||||
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.TRANSFER_CONTAINER_TYPE;
|
||||
@@ -74,12 +71,11 @@ public interface TestData
|
||||
* @return file plan component alias
|
||||
*/
|
||||
@DataProvider
|
||||
public static Object[][] getContainers()
|
||||
public static String[][] getContainers()
|
||||
{
|
||||
return new Object[][] {
|
||||
return new String[][] {
|
||||
{ FILE_PLAN_ALIAS },
|
||||
{ TRANSFERS_ALIAS },
|
||||
{ HOLDS_ALIAS },
|
||||
{ UNFILED_RECORDS_CONTAINER_ALIAS },
|
||||
};
|
||||
}
|
||||
@@ -91,43 +87,42 @@ public interface TestData
|
||||
* @return file plan component alias
|
||||
*/
|
||||
@DataProvider
|
||||
public static Object[][] getContainersAndTypes()
|
||||
public static String[][] getContainersAndTypes()
|
||||
{
|
||||
return new Object[][] {
|
||||
return new String[][] {
|
||||
{ FILE_PLAN_ALIAS, FILE_PLAN_TYPE },
|
||||
{ TRANSFERS_ALIAS, TRANSFER_CONTAINER_TYPE },
|
||||
{ HOLDS_ALIAS, HOLD_CONTAINER_TYPE },
|
||||
{ UNFILED_RECORDS_CONTAINER_ALIAS, UNFILED_CONTAINER_TYPE },
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* The default CATEGORY name used when creating categories
|
||||
* The default record category name used when creating categories
|
||||
*/
|
||||
public static String CATEGORY_NAME = "CATEGORY NAME" + getRandomAlphanumeric();
|
||||
public static String RECORD_CATEGORY_NAME = "CATEGORY NAME" + getRandomAlphanumeric();
|
||||
|
||||
/**
|
||||
* The default CATEGORY title used when creating categories
|
||||
* The default record category title used when creating categories
|
||||
*/
|
||||
public static String CATEGORY_TITLE = "CATEGORY TITLE" + getRandomAlphanumeric();
|
||||
public static String RECORD_CATEGORY_TITLE = "CATEGORY TITLE" + getRandomAlphanumeric();
|
||||
|
||||
/**
|
||||
* The default FOLDER name used when creating folders
|
||||
* The default record folder name used when creating folders
|
||||
*/
|
||||
public static String FOLDER_NAME = "FOLDER NAME" + getRandomAlphanumeric();
|
||||
public static String RECORD_FOLDER_NAME = "FOLDER NAME" + getRandomAlphanumeric();
|
||||
|
||||
/**
|
||||
* The default FOLDER title used when creating folders
|
||||
* The default record folder title used when creating folders
|
||||
*/
|
||||
public static String FOLDER_TITLE = "FOLDER TITLE" + getRandomAlphanumeric();
|
||||
public static String RECORD_FOLDER_TITLE = "FOLDER TITLE" + getRandomAlphanumeric();
|
||||
|
||||
/**
|
||||
* The default electronic record name used when creating electronic records
|
||||
* The default electronic record name used when creating electronic records
|
||||
*/
|
||||
public static String ELECTRONIC_RECORD_NAME = "Record electronic" + getRandomAlphanumeric();
|
||||
|
||||
/**
|
||||
* The default Non electronic record name used when creating non-electronic records
|
||||
* The default non-electronic record name used when creating non-electronic records
|
||||
*/
|
||||
public static String NONELECTRONIC_RECORD_NAME = "Record nonelectronic" + getRandomAlphanumeric();
|
||||
|
||||
@@ -138,22 +133,18 @@ public interface TestData
|
||||
* @return file plan component alias
|
||||
*/
|
||||
@DataProvider
|
||||
public static Object[][] childrenNotAllowedForCategory()
|
||||
public static String[][] childrenNotAllowedForCategory()
|
||||
{
|
||||
return new Object[][] {
|
||||
return new String[][] {
|
||||
{ FILE_PLAN_TYPE },
|
||||
{ TRANSFER_CONTAINER_TYPE },
|
||||
{ HOLD_CONTAINER_TYPE },
|
||||
{ UNFILED_CONTAINER_TYPE },
|
||||
{ UNFILED_RECORD_FOLDER_TYPE },
|
||||
{ HOLD_TYPE },
|
||||
{ TRANSFER_TYPE },
|
||||
{ CONTENT_TYPE }
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Data Provider with:
|
||||
* with the object types for creating a Record Folder
|
||||
@@ -161,9 +152,9 @@ public interface TestData
|
||||
* @return file plan component alias
|
||||
*/
|
||||
@DataProvider
|
||||
public static Object[][] folderTypes()
|
||||
public static String[][] folderTypes()
|
||||
{
|
||||
return new Object[][] {
|
||||
return new String[][] {
|
||||
{ RECORD_FOLDER_TYPE },
|
||||
{ FOLDER_TYPE }
|
||||
};
|
||||
@@ -176,9 +167,9 @@ public interface TestData
|
||||
* @return file plan component alias
|
||||
*/
|
||||
@DataProvider
|
||||
public static Object[][] categoryTypes()
|
||||
public static String[][] categoryTypes()
|
||||
{
|
||||
return new Object[][] {
|
||||
return new String[][] {
|
||||
{ FOLDER_TYPE },
|
||||
{ RECORD_CATEGORY_TYPE }
|
||||
};
|
||||
|
@@ -27,9 +27,19 @@
|
||||
package org.alfresco.rest.rm.community.fileplancomponents;
|
||||
|
||||
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentAlias.UNFILED_RECORDS_CONTAINER_ALIAS;
|
||||
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.NON_ELECTRONIC_RECORD_TYPE;
|
||||
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.RECORD_FOLDER_TYPE;
|
||||
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.UNFILED_CONTAINER_TYPE;
|
||||
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.UNFILED_RECORD_FOLDER_TYPE;
|
||||
import static org.alfresco.rest.rm.community.model.user.UserPermissions.PERMISSION_FILING;
|
||||
import static org.alfresco.rest.rm.community.model.user.UserRoles.ROLE_RM_POWER_USER;
|
||||
import static org.alfresco.rest.rm.community.utils.FilePlanComponentsUtil.IMAGE_FILE;
|
||||
import static org.alfresco.rest.rm.community.utils.FilePlanComponentsUtil.createElectronicRecordModel;
|
||||
import static org.alfresco.rest.rm.community.utils.FilePlanComponentsUtil.createNonElectronicRecordModel;
|
||||
import static org.alfresco.rest.rm.community.utils.FilePlanComponentsUtil.createElectronicUnfiledContainerChildModel;
|
||||
import static org.alfresco.rest.rm.community.utils.FilePlanComponentsUtil.createNonElectronicUnfiledContainerChildModel;
|
||||
import static org.alfresco.rest.rm.community.utils.FilePlanComponentsUtil.getFile;
|
||||
import static org.alfresco.utility.constants.UserRole.SiteCollaborator;
|
||||
import static org.springframework.http.HttpStatus.CREATED;
|
||||
import static org.springframework.http.HttpStatus.FORBIDDEN;
|
||||
import static org.springframework.http.HttpStatus.NOT_FOUND;
|
||||
@@ -37,22 +47,21 @@ import static org.springframework.http.HttpStatus.NO_CONTENT;
|
||||
import static org.springframework.http.HttpStatus.OK;
|
||||
|
||||
import org.alfresco.rest.rm.community.base.BaseRMRestTest;
|
||||
import org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponent;
|
||||
import org.alfresco.rest.rm.community.model.user.UserPermissions;
|
||||
import org.alfresco.rest.rm.community.model.user.UserRoles;
|
||||
import org.alfresco.rest.rm.community.requests.igCoreAPI.FilePlanComponentAPI;
|
||||
import org.alfresco.rest.rm.community.model.record.Record;
|
||||
import org.alfresco.rest.rm.community.model.recordcategory.RecordCategoryChild;
|
||||
import org.alfresco.rest.rm.community.model.unfiledcontainer.UnfiledContainerChild;
|
||||
import org.alfresco.rest.rm.community.requests.gscore.api.RecordCategoryAPI;
|
||||
import org.alfresco.rest.rm.community.requests.gscore.api.RecordFolderAPI;
|
||||
import org.alfresco.rest.rm.community.requests.gscore.api.RecordsAPI;
|
||||
import org.alfresco.test.AlfrescoTest;
|
||||
import org.alfresco.utility.constants.UserRole;
|
||||
import org.alfresco.utility.data.RandomData;
|
||||
import org.alfresco.utility.model.SiteModel;
|
||||
import org.alfresco.utility.model.UserModel;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
/**
|
||||
* Create/File electronic records tests
|
||||
* <br>
|
||||
* These tests only test the creation and filing of electronic records, update at
|
||||
* present isn't implemented in the API under test.
|
||||
* <p>
|
||||
* Delete records tests
|
||||
*
|
||||
* @author Kristijan Conkas
|
||||
* @since 2.6
|
||||
*/
|
||||
@@ -60,15 +69,12 @@ public class DeleteRecordTests extends BaseRMRestTest
|
||||
{
|
||||
/**
|
||||
* <pre>
|
||||
* Given a record
|
||||
* Given an electronic record
|
||||
* And that I have the "Delete Record" capability
|
||||
* And write permissions
|
||||
* When I delete the record
|
||||
* Then it is deleted from the file plan
|
||||
* </pre>
|
||||
*
|
||||
* @param container
|
||||
* @throws Exception
|
||||
*/
|
||||
@Test
|
||||
(
|
||||
@@ -76,26 +82,43 @@ public class DeleteRecordTests extends BaseRMRestTest
|
||||
description = "Admin user can delete an electronic record"
|
||||
)
|
||||
@AlfrescoTest(jira="RM-4363")
|
||||
public void adminCanDeleteElectronicRecord(FilePlanComponent container) throws Exception
|
||||
public void adminCanDeleteElectronicRecord(String folderId, String type) throws Exception
|
||||
{
|
||||
FilePlanComponent newRecord = getRestAPIFactory().getFilePlanComponentsAPI().createElectronicRecord(createElectronicRecordModel(), IMAGE_FILE, container.getId());
|
||||
// Create record
|
||||
String recordId;
|
||||
|
||||
if(RECORD_FOLDER_TYPE.equalsIgnoreCase(type))
|
||||
{
|
||||
recordId = getRestAPIFactory().getRecordFolderAPI().createRecord(createElectronicRecordModel(), folderId, getFile(IMAGE_FILE)).getId();
|
||||
}
|
||||
else if(UNFILED_CONTAINER_TYPE.equalsIgnoreCase(type))
|
||||
{
|
||||
recordId = getRestAPIFactory().getUnfiledContainersAPI().uploadRecord(createElectronicUnfiledContainerChildModel(), folderId, getFile(IMAGE_FILE)).getId();
|
||||
}
|
||||
else if(UNFILED_RECORD_FOLDER_TYPE.equalsIgnoreCase(type))
|
||||
{
|
||||
recordId = getRestAPIFactory().getUnfiledRecordFoldersAPI().uploadRecord(createElectronicUnfiledContainerChildModel(), folderId, getFile(IMAGE_FILE)).getId();
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception("Unsuported type = " + type);
|
||||
}
|
||||
|
||||
// Assert status
|
||||
assertStatusCode(CREATED);
|
||||
|
||||
deleteAndVerify(newRecord);
|
||||
// Delete record and verify successful deletion
|
||||
deleteAndVerify(recordId);
|
||||
}
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* Given a record
|
||||
* Given a non-electronic record
|
||||
* And that I have the "Delete Record" capability
|
||||
* And write permissions
|
||||
* When I delete the record
|
||||
* Then it is deleted from the file plan
|
||||
* </pre>
|
||||
*
|
||||
* @param container
|
||||
* @throws Exception
|
||||
*/
|
||||
@Test
|
||||
(
|
||||
@@ -103,27 +126,43 @@ public class DeleteRecordTests extends BaseRMRestTest
|
||||
description = "Admin user can delete a non-electronic record"
|
||||
)
|
||||
@AlfrescoTest(jira="RM-4363")
|
||||
public void adminCanDeleteNonElectronicRecord(FilePlanComponent container) throws Exception
|
||||
public void adminCanDeleteNonElectronicRecord(String folderId, String type) throws Exception
|
||||
{
|
||||
// create a non-electronic record
|
||||
FilePlanComponent newRecord = getRestAPIFactory().getFilePlanComponentsAPI().createFilePlanComponent(createNonElectronicRecordModel(), container.getId());
|
||||
// Create record
|
||||
String nonElectronicRecordId;
|
||||
|
||||
if(RECORD_FOLDER_TYPE.equalsIgnoreCase(type))
|
||||
{
|
||||
nonElectronicRecordId = getRestAPIFactory().getRecordFolderAPI().createRecord(createNonElectronicRecordModel(), folderId).getId();
|
||||
}
|
||||
else if(UNFILED_CONTAINER_TYPE.equalsIgnoreCase(type))
|
||||
{
|
||||
nonElectronicRecordId = getRestAPIFactory().getUnfiledContainersAPI().createUnfiledContainerChild(createNonElectronicUnfiledContainerChildModel(), folderId).getId();
|
||||
}
|
||||
else if(UNFILED_RECORD_FOLDER_TYPE.equalsIgnoreCase(type))
|
||||
{
|
||||
nonElectronicRecordId = getRestAPIFactory().getUnfiledRecordFoldersAPI().createUnfiledRecordFolderChild(createNonElectronicUnfiledContainerChildModel(), folderId).getId();
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception("Unsuported type = " + type);
|
||||
}
|
||||
|
||||
// Assert status
|
||||
assertStatusCode(CREATED);
|
||||
|
||||
deleteAndVerify(newRecord);
|
||||
// Delete record and verify successful deletion
|
||||
deleteAndVerify(nonElectronicRecordId);
|
||||
}
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* Given a record
|
||||
* Given a non-electronic record
|
||||
* And that I don't have write permissions
|
||||
* When I try to delete the record
|
||||
* Then nothing happens
|
||||
* And error gets reported
|
||||
* </pre>
|
||||
*
|
||||
* @param container
|
||||
* @throws Exception
|
||||
*/
|
||||
@Test
|
||||
(
|
||||
@@ -132,23 +171,27 @@ public class DeleteRecordTests extends BaseRMRestTest
|
||||
@AlfrescoTest(jira="RM-4363")
|
||||
public void userWithoutWritePermissionsCantDeleteRecord() throws Exception
|
||||
{
|
||||
// create a non-electronic record in unfiled records
|
||||
FilePlanComponent newRecord = getRestAPIFactory().getFilePlanComponentsAPI().createFilePlanComponent(createNonElectronicRecordModel(), UNFILED_RECORDS_CONTAINER_ALIAS);
|
||||
// Create a non-electronic record in unfiled records
|
||||
UnfiledContainerChild nonElectronicRecord = UnfiledContainerChild.builder()
|
||||
.name("Record " + RandomData.getRandomAlphanumeric())
|
||||
.nodeType(NON_ELECTRONIC_RECORD_TYPE)
|
||||
.build();
|
||||
UnfiledContainerChild newRecord = getRestAPIFactory().getUnfiledContainersAPI().createUnfiledContainerChild(nonElectronicRecord, UNFILED_RECORDS_CONTAINER_ALIAS);
|
||||
|
||||
assertStatusCode(CREATED);
|
||||
|
||||
// create test user and add it with collab. privileges
|
||||
// Create test user and add it with collaboration privileges
|
||||
UserModel deleteUser = getDataUser().createRandomTestUser("delnoperm");
|
||||
deleteUser.setUserRole(UserRole.SiteCollaborator);
|
||||
logger.info("test user: " + deleteUser.getUsername());
|
||||
getDataUser().addUserToSite(deleteUser, new SiteModel(getRestAPIFactory().getRMSiteAPI().getSite().getId()), UserRole.SiteCollaborator);
|
||||
String username = deleteUser.getUsername();
|
||||
logger.info("Test user: " + username);
|
||||
getDataUser().addUserToSite(deleteUser, new SiteModel(getRestAPIFactory().getRMSiteAPI().getSite().getId()), SiteCollaborator);
|
||||
|
||||
// add RM role to user
|
||||
getRestAPIFactory().getRMUserAPI().assignRoleToUser(deleteUser.getUsername(), UserRoles.ROLE_RM_POWER_USER);
|
||||
// Add RM role to user
|
||||
getRestAPIFactory().getRMUserAPI().assignRoleToUser(username, ROLE_RM_POWER_USER);
|
||||
assertStatusCode(OK);
|
||||
|
||||
// try to delete newRecord
|
||||
getRestAPIFactory().getFilePlanComponentsAPI(deleteUser).deleteFilePlanComponent(newRecord.getId());
|
||||
// Try to delete newRecord
|
||||
getRestAPIFactory().getRecordsAPI(deleteUser).deleteRecord(newRecord.getId());
|
||||
assertStatusCode(FORBIDDEN);
|
||||
}
|
||||
|
||||
@@ -160,9 +203,6 @@ public class DeleteRecordTests extends BaseRMRestTest
|
||||
* Then nothing happens
|
||||
* And error gets reported
|
||||
* </pre>
|
||||
*
|
||||
* @param container
|
||||
* @throws Exception
|
||||
*/
|
||||
@Test
|
||||
(
|
||||
@@ -171,56 +211,55 @@ public class DeleteRecordTests extends BaseRMRestTest
|
||||
@AlfrescoTest(jira="RM-4363")
|
||||
public void userWithoutDeleteRecordsCapabilityCantDeleteRecord() throws Exception
|
||||
{
|
||||
// create test user and add it with collab. privileges
|
||||
// Create test user and add it with collaboration privileges
|
||||
UserModel deleteUser = getDataUser().createRandomTestUser("delnoperm");
|
||||
deleteUser.setUserRole(UserRole.SiteCollaborator);
|
||||
getDataUser().addUserToSite(deleteUser, new SiteModel(getRestAPIFactory().getRMSiteAPI().getSite().getId()), UserRole.SiteCollaborator);
|
||||
logger.info("test user: " + deleteUser.getUsername());
|
||||
getDataUser().addUserToSite(deleteUser, new SiteModel(getRestAPIFactory().getRMSiteAPI().getSite().getId()), SiteCollaborator);
|
||||
String username = deleteUser.getUsername();
|
||||
logger.info("Test user: " + username);
|
||||
|
||||
// add RM role to user, RM Power User doesn't have the Delete Record capabilities
|
||||
getRestAPIFactory().getRMUserAPI().assignRoleToUser(deleteUser.getUsername(), UserRoles.ROLE_RM_POWER_USER);
|
||||
// Add RM role to user, RM Power User doesn't have the "Delete Record" capabilities
|
||||
getRestAPIFactory().getRMUserAPI().assignRoleToUser(username, ROLE_RM_POWER_USER);
|
||||
assertStatusCode(OK);
|
||||
|
||||
// create random folder
|
||||
FilePlanComponent randomFolder = createCategoryFolderInFilePlan();
|
||||
logger.info("random folder:" + randomFolder.getName());
|
||||
// Create random folder
|
||||
RecordCategoryChild recordFolder = createCategoryFolderInFilePlan();
|
||||
logger.info("Random folder:" + recordFolder.getName());
|
||||
|
||||
// grant deleteUser Filing privileges on randomFolder category, this will be
|
||||
// inherited to randomFolder
|
||||
FilePlanComponentAPI filePlanComponentsAPIAsAdmin = getRestAPIFactory().getFilePlanComponentsAPI();
|
||||
getRestAPIFactory().getRMUserAPI().addUserPermission(filePlanComponentsAPIAsAdmin.getFilePlanComponent(randomFolder.getParentId()),
|
||||
deleteUser, UserPermissions.PERMISSION_FILING);
|
||||
// Grant "deleteUser" filing permissions on "randomFolder" parent, this will be inherited to randomFolder
|
||||
RecordCategoryAPI recordCategoryAPI = getRestAPIFactory().getRecordCategoryAPI();
|
||||
getRestAPIFactory().getRMUserAPI().addUserPermission(recordCategoryAPI.getRecordCategory(recordFolder.getParentId()).getId(), deleteUser, PERMISSION_FILING);
|
||||
assertStatusCode(OK);
|
||||
|
||||
// create a non-electronic record in randomFolder
|
||||
FilePlanComponent newRecord = filePlanComponentsAPIAsAdmin.createFilePlanComponent(createNonElectronicRecordModel(), randomFolder.getId());
|
||||
// Create a non-electronic record in "randomFolder"
|
||||
RecordFolderAPI recordFolderAPI = getRestAPIFactory().getRecordFolderAPI();
|
||||
Record newRecord = recordFolderAPI.createRecord(createNonElectronicRecordModel(), recordFolder.getId());
|
||||
assertStatusCode(CREATED);
|
||||
|
||||
// verify the user can see the newRecord
|
||||
FilePlanComponentAPI filePlanComponentsAPIAsUser = getRestAPIFactory().getFilePlanComponentsAPI(deleteUser);
|
||||
filePlanComponentsAPIAsUser.getFilePlanComponent(newRecord.getId());
|
||||
// Verify the user can see "newRecord"
|
||||
RecordsAPI recordsAPI = getRestAPIFactory().getRecordsAPI(deleteUser);
|
||||
recordsAPI.getRecord(newRecord.getId());
|
||||
assertStatusCode(OK);
|
||||
|
||||
// try to delete newRecord
|
||||
filePlanComponentsAPIAsUser.deleteFilePlanComponent(newRecord.getId());
|
||||
// Try to delete "newRecord"
|
||||
recordsAPI.deleteRecord(newRecord.getId());
|
||||
assertStatusCode(FORBIDDEN);
|
||||
}
|
||||
|
||||
/**
|
||||
* Utility method to delete a record and verify successful deletion
|
||||
* @param record
|
||||
* @throws Exception
|
||||
*
|
||||
* @param recordId The id of the record
|
||||
*/
|
||||
private void deleteAndVerify(FilePlanComponent record) throws Exception
|
||||
private void deleteAndVerify(String recordId)
|
||||
{
|
||||
FilePlanComponentAPI filePlanComponentsAPI = getRestAPIFactory().getFilePlanComponentsAPI();
|
||||
RecordsAPI recordsAPI = getRestAPIFactory().getRecordsAPI();
|
||||
|
||||
// delete it and verify status
|
||||
filePlanComponentsAPI.deleteFilePlanComponent(record.getId());
|
||||
// Delete record and verify status
|
||||
recordsAPI.deleteRecord(recordId);
|
||||
assertStatusCode(NO_CONTENT);
|
||||
|
||||
// try to get deleted file plan component
|
||||
filePlanComponentsAPI.getFilePlanComponent(record.getId());
|
||||
// Try to get deleted record
|
||||
recordsAPI.deleteRecord(recordId);
|
||||
assertStatusCode(NOT_FOUND);
|
||||
}
|
||||
}
|
||||
|
@@ -26,18 +26,20 @@
|
||||
*/
|
||||
package org.alfresco.rest.rm.community.fileplancomponents;
|
||||
|
||||
import static org.alfresco.rest.rm.community.base.TestData.CATEGORY_NAME;
|
||||
import static org.alfresco.rest.rm.community.base.TestData.ELECTRONIC_RECORD_NAME;
|
||||
import static org.alfresco.rest.rm.community.base.TestData.FOLDER_NAME;
|
||||
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentAlias.FILE_PLAN_ALIAS;
|
||||
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentAlias.HOLDS_ALIAS;
|
||||
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentAlias.TRANSFERS_ALIAS;
|
||||
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentAlias.UNFILED_RECORDS_CONTAINER_ALIAS;
|
||||
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.CONTENT_TYPE;
|
||||
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.RECORD_FOLDER_TYPE;
|
||||
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.UNFILED_CONTAINER_TYPE;
|
||||
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.UNFILED_RECORD_FOLDER_TYPE;
|
||||
import static org.alfresco.rest.rm.community.util.PojoUtility.toJson;
|
||||
import static org.alfresco.rest.rm.community.utils.FilePlanComponentsUtil.IMAGE_FILE;
|
||||
import static org.alfresco.rest.rm.community.utils.FilePlanComponentsUtil.createElectronicRecordModel;
|
||||
import static org.alfresco.rest.rm.community.utils.FilePlanComponentsUtil.createElectronicUnfiledContainerChildModel;
|
||||
import static org.alfresco.rest.rm.community.utils.FilePlanComponentsUtil.createTempFile;
|
||||
import static org.alfresco.rest.rm.community.utils.FilePlanComponentsUtil.getFile;
|
||||
import static org.alfresco.utility.data.RandomData.getRandomAlphanumeric;
|
||||
import static org.springframework.http.HttpStatus.BAD_REQUEST;
|
||||
import static org.springframework.http.HttpStatus.CREATED;
|
||||
@@ -46,40 +48,40 @@ import static org.testng.Assert.assertFalse;
|
||||
import static org.testng.Assert.assertTrue;
|
||||
|
||||
import org.alfresco.rest.rm.community.base.BaseRMRestTest;
|
||||
import org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponent;
|
||||
import org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentContent;
|
||||
import org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentFields;
|
||||
import org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentProperties;
|
||||
import org.alfresco.rest.rm.community.requests.igCoreAPI.FilePlanComponentAPI;
|
||||
import org.alfresco.rest.rm.community.model.record.Record;
|
||||
import org.alfresco.rest.rm.community.model.record.RecordContent;
|
||||
import org.alfresco.rest.rm.community.model.recordcategory.RecordCategoryChild;
|
||||
import org.alfresco.rest.rm.community.model.unfiledcontainer.UnfiledContainerChild;
|
||||
import org.alfresco.rest.rm.community.requests.gscore.api.RecordFolderAPI;
|
||||
import org.alfresco.rest.rm.community.requests.gscore.api.RecordsAPI;
|
||||
import org.alfresco.rest.rm.community.requests.gscore.api.UnfiledContainerAPI;
|
||||
import org.alfresco.rest.rm.community.requests.gscore.api.UnfiledRecordFolderAPI;
|
||||
import org.alfresco.utility.report.Bug;
|
||||
import org.testng.annotations.DataProvider;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
/**
|
||||
* Create/File electronic records tests
|
||||
* <br>
|
||||
* These tests only test the creation and filing of electronic records, update at
|
||||
* present isn't implemented in the API under test.
|
||||
* <p>
|
||||
*
|
||||
* @author Kristijan Conkas
|
||||
* @since 2.6
|
||||
*/
|
||||
public class ElectronicRecordTests extends BaseRMRestTest
|
||||
{
|
||||
/** Valid root containers where electronic records can be created */
|
||||
private static final String TEXT_PLAIN_VALUE = "text/plain";
|
||||
|
||||
/** Invalid parent containers where electronic records can't be created */
|
||||
@DataProvider(name = "invalidParentContainers")
|
||||
public Object[][] invalidContainers() throws Exception
|
||||
public String[][] invalidParentContainers() throws Exception
|
||||
{
|
||||
return new Object[][]
|
||||
return new String[][]
|
||||
{
|
||||
// record category
|
||||
{ getFilePlanComponent(createCategoryFolderInFilePlan().getParentId()) },
|
||||
{ createCategoryFolderInFilePlan().getParentId() },
|
||||
// file plan root
|
||||
{ getFilePlanComponent(FILE_PLAN_ALIAS) },
|
||||
{ FILE_PLAN_ALIAS },
|
||||
// transfers
|
||||
{ getFilePlanComponent(TRANSFERS_ALIAS) },
|
||||
// holds
|
||||
{ getFilePlanComponent(HOLDS_ALIAS) },
|
||||
{ TRANSFERS_ALIAS }
|
||||
};
|
||||
}
|
||||
|
||||
@@ -90,21 +92,21 @@ public class ElectronicRecordTests extends BaseRMRestTest
|
||||
* Then nothing happens
|
||||
* And an error is reported
|
||||
* </pre>
|
||||
* @param container
|
||||
* @throws Exception
|
||||
* @param container The parent container
|
||||
* @throws Exception if record can't be created
|
||||
*/
|
||||
@Test
|
||||
(
|
||||
dataProvider = "invalidParentContainers",
|
||||
description = "Electronic records can't be created in invalid parent containers"
|
||||
)
|
||||
public void cantCreateElectronicRecordsInInvalidContainers(FilePlanComponent container) throws Exception
|
||||
public void cantCreateElectronicRecordsInInvalidContainers(String container) throws Exception
|
||||
{
|
||||
// Build object the filePlan, this should throw an IllegalArgumentException
|
||||
getRestAPIFactory().getFilePlanComponentsAPI().createElectronicRecord(createElectronicRecordModel(), IMAGE_FILE, container.getId());
|
||||
// Create an electronic record in the given container, this should throw an IllegalArgumentException
|
||||
getRestAPIFactory().getRecordFolderAPI().createRecord(createElectronicRecordModel(), container, getFile(IMAGE_FILE));
|
||||
|
||||
// verify the create request status code
|
||||
assertStatusCode(UNPROCESSABLE_ENTITY);
|
||||
// Verify the create request status code
|
||||
assertStatusCode(BAD_REQUEST);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -115,7 +117,7 @@ public class ElectronicRecordTests extends BaseRMRestTest
|
||||
* Then nothing happens
|
||||
* And an error is reported
|
||||
* </pre>
|
||||
* @throws Exception
|
||||
* @throws Exception if record can't be created
|
||||
*/
|
||||
@Test
|
||||
(
|
||||
@@ -123,18 +125,18 @@ public class ElectronicRecordTests extends BaseRMRestTest
|
||||
)
|
||||
public void cantCreateElectronicRecordInClosedFolder() throws Exception
|
||||
{
|
||||
FilePlanComponent recordFolder = createCategoryFolderInFilePlan();
|
||||
RecordCategoryChild recordFolder = createCategoryFolderInFilePlan();
|
||||
|
||||
// the folder should be open
|
||||
// The folder should be open
|
||||
assertFalse(recordFolder.getProperties().getIsClosed());
|
||||
|
||||
// close the folder
|
||||
// Close the folder
|
||||
closeFolder(recordFolder.getId());
|
||||
|
||||
// try to create it, this should throw IllegalArgumentException
|
||||
getRestAPIFactory().getFilePlanComponentsAPI().createElectronicRecord(createElectronicRecordModel(), IMAGE_FILE, recordFolder.getId());
|
||||
// Try to create an electronic record, this should throw IllegalArgumentException
|
||||
getRestAPIFactory().getRecordFolderAPI().createRecord(createElectronicRecordModel(), recordFolder.getId(), getFile(IMAGE_FILE));
|
||||
|
||||
// verify the status code
|
||||
// Verify the status code
|
||||
assertStatusCode(UNPROCESSABLE_ENTITY);
|
||||
}
|
||||
|
||||
@@ -149,39 +151,57 @@ public class ElectronicRecordTests extends BaseRMRestTest
|
||||
* </pre>
|
||||
* and
|
||||
* <pre>
|
||||
*
|
||||
*
|
||||
* Given a parent container that is an unfiled record folder or the root unfiled record container
|
||||
* When I try to create an electronic record within the parent container
|
||||
* And I do not provide all the required mandatory property values
|
||||
* Then nothing happens
|
||||
* And an error is reported
|
||||
* </pre>
|
||||
* @param container
|
||||
* @throws Exception
|
||||
* @param folderid The folder, which the record will be created in
|
||||
* @param type The type of the record folder, which the record will be created in
|
||||
* @throws Exception if record can't be created
|
||||
*/
|
||||
@Test
|
||||
(
|
||||
dataProvider = "validRootContainers",
|
||||
description = "Electronic record can only be created if all mandatory properties are given"
|
||||
)
|
||||
public void canCreateElectronicRecordOnlyWithMandatoryProperties(FilePlanComponent container) throws Exception
|
||||
public void canCreateElectronicRecordOnlyWithMandatoryProperties(String folderId, String type) throws Exception
|
||||
{
|
||||
logger.info("Root container:\n" + toJson(container));
|
||||
logger.info("Root container:\n" + toJson(folderId));
|
||||
|
||||
if (container.getNodeType().equals(RECORD_FOLDER_TYPE))
|
||||
if (RECORD_FOLDER_TYPE.equalsIgnoreCase(type))
|
||||
{
|
||||
// only record folders can be open or closed
|
||||
assertFalse(container.getProperties().getIsClosed());
|
||||
// Only record folders can be opened or closed
|
||||
RecordFolderAPI recordFolderAPI = getRestAPIFactory().getRecordFolderAPI();
|
||||
assertFalse(recordFolderAPI.getRecordFolder(folderId).getProperties().getIsClosed());
|
||||
|
||||
// Record without name
|
||||
Record recordModel = Record.builder().nodeType(CONTENT_TYPE).build();
|
||||
|
||||
// Try to create it
|
||||
recordFolderAPI.createRecord(recordModel, folderId);
|
||||
}
|
||||
else if(UNFILED_CONTAINER_TYPE.equalsIgnoreCase(type))
|
||||
{
|
||||
UnfiledContainerAPI unfiledContainersAPI = getRestAPIFactory().getUnfiledContainersAPI();
|
||||
UnfiledContainerChild recordModel = UnfiledContainerChild.builder().nodeType(CONTENT_TYPE).build();
|
||||
unfiledContainersAPI.createUnfiledContainerChild(recordModel, folderId);
|
||||
}
|
||||
else if(UNFILED_RECORD_FOLDER_TYPE.equalsIgnoreCase(type))
|
||||
{
|
||||
UnfiledRecordFolderAPI unfiledRecordFoldersAPI = getRestAPIFactory().getUnfiledRecordFoldersAPI();
|
||||
UnfiledContainerChild recordModel = UnfiledContainerChild.builder().nodeType(CONTENT_TYPE).build();
|
||||
unfiledRecordFoldersAPI.createUnfiledRecordFolderChild(recordModel, folderId);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception("Unsuported type = " + type);
|
||||
}
|
||||
|
||||
// component without name
|
||||
FilePlanComponent record = FilePlanComponent.builder()
|
||||
.nodeType(CONTENT_TYPE)
|
||||
.build();
|
||||
|
||||
// try to create it
|
||||
getRestAPIFactory().getFilePlanComponentsAPI().createFilePlanComponent(record, container.getId());
|
||||
|
||||
// verify the status code is BAD_REQUEST
|
||||
// Verify the status code is BAD_REQUEST
|
||||
assertStatusCode(BAD_REQUEST);
|
||||
}
|
||||
|
||||
@@ -195,151 +215,185 @@ public class ElectronicRecordTests extends BaseRMRestTest
|
||||
* </pre>
|
||||
* and
|
||||
* <pre>
|
||||
*
|
||||
* Given a parent container that is an unfiled record folder or the root unfiled record container
|
||||
* When I try to create an electronic record within the parent container
|
||||
* Then the electronic record is created
|
||||
* And the details of the new record are returned
|
||||
* </pre>
|
||||
* @throws Exception
|
||||
* @param folderId The folder, which the record will be created in
|
||||
* @param type The type of the folder, which the record will be created in
|
||||
* @throws Exception if record can't be created
|
||||
*/
|
||||
@Test
|
||||
(
|
||||
dataProvider = "validRootContainers",
|
||||
description = "Electronic records can be created in unfiled record folder or unfiled record root"
|
||||
description = "Electronic records can be created in record folders, unfiled record folders or unfiled record folder root"
|
||||
)
|
||||
public void canCreateElectronicRecordsInValidContainers(FilePlanComponent container) throws Exception
|
||||
public void canCreateElectronicRecordsInValidContainers(String folderId, String type) throws Exception
|
||||
{
|
||||
FilePlanComponent record = createElectronicRecordModel();
|
||||
FilePlanComponentAPI filePlanComponentsAPI = getRestAPIFactory().getFilePlanComponentsAPI();
|
||||
String newRecordId = filePlanComponentsAPI.createElectronicRecord(record, IMAGE_FILE, container.getId()).getId();
|
||||
|
||||
// verify the create request status code
|
||||
String newRecordId;
|
||||
String expectedName;
|
||||
if (RECORD_FOLDER_TYPE.equalsIgnoreCase(type))
|
||||
{
|
||||
RecordFolderAPI recordFolderAPI = getRestAPIFactory().getRecordFolderAPI();
|
||||
Record recordModel = createElectronicRecordModel();
|
||||
newRecordId = recordFolderAPI.createRecord(recordModel, folderId, getFile(IMAGE_FILE)).getId();
|
||||
expectedName = recordModel.getName();
|
||||
}
|
||||
else if(UNFILED_CONTAINER_TYPE.equalsIgnoreCase(type))
|
||||
{
|
||||
UnfiledContainerAPI unfiledContainersAPI = getRestAPIFactory().getUnfiledContainersAPI();
|
||||
UnfiledContainerChild recordModel = createElectronicUnfiledContainerChildModel();
|
||||
newRecordId = unfiledContainersAPI.uploadRecord(recordModel, folderId, getFile(IMAGE_FILE)).getId();
|
||||
expectedName = recordModel.getName();
|
||||
}
|
||||
else if(UNFILED_RECORD_FOLDER_TYPE.equalsIgnoreCase(type))
|
||||
{
|
||||
UnfiledRecordFolderAPI unfiledRecordFoldersAPI = getRestAPIFactory().getUnfiledRecordFoldersAPI();
|
||||
UnfiledContainerChild recordModel = createElectronicUnfiledContainerChildModel();
|
||||
newRecordId = unfiledRecordFoldersAPI.uploadRecord(recordModel, folderId, getFile(IMAGE_FILE)).getId();
|
||||
expectedName = recordModel.getName();
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception("Unsuported type = " + type);
|
||||
}
|
||||
// Verify the create request status code
|
||||
assertStatusCode(CREATED);
|
||||
|
||||
// get newly created electronic record and verify its properties
|
||||
FilePlanComponent electronicRecord = filePlanComponentsAPI.getFilePlanComponent(newRecordId);
|
||||
// created record will have record identifier inserted in its name but will be prefixed with
|
||||
// the name it was created as
|
||||
assertTrue(electronicRecord.getName().startsWith(record.getName()));
|
||||
assertTrue(electronicRecord.getName().contains(electronicRecord.getProperties().getRmIdentifier()));
|
||||
// Get newly created electronic record and verify its properties
|
||||
RecordsAPI recordsAPI = getRestAPIFactory().getRecordsAPI();
|
||||
Record record = recordsAPI.getRecord(newRecordId);
|
||||
String recordName = record.getName();
|
||||
|
||||
// Created record will have record identifier inserted in its name but will be prefixed with the name it was created as
|
||||
assertTrue(recordName.startsWith(expectedName));
|
||||
assertTrue(recordName.contains(record.getProperties().getIdentifier()));
|
||||
}
|
||||
|
||||
/**
|
||||
* This test verified that in the test client implementation if record name isn't specified it
|
||||
* defaults to filed file name.
|
||||
* @param container valid record container
|
||||
* @throws Exception if record creation failed
|
||||
* <pre>
|
||||
* Given that a record name isn't specified
|
||||
* When I create an electronic record
|
||||
* Then the record name defaults to filed file name.
|
||||
* </pre>
|
||||
* @param folderId The folder, which the record will be created in
|
||||
* @param type The type of the folder, which the record will be created in
|
||||
* @throws Exception if record can't be created
|
||||
*/
|
||||
@Test
|
||||
(
|
||||
dataProvider = "validRootContainers",
|
||||
description = "Electronic records can be created in unfiled record folder or unfiled record root"
|
||||
)
|
||||
public void recordNameDerivedFromFileName(FilePlanComponent container) throws Exception
|
||||
public void recordNameDerivedFromFileName(String folderId, String type) throws Exception
|
||||
{
|
||||
// record object without name set
|
||||
FilePlanComponent record = FilePlanComponent.builder()
|
||||
.nodeType(CONTENT_TYPE)
|
||||
.build();
|
||||
String newRecordId;
|
||||
if (RECORD_FOLDER_TYPE.equalsIgnoreCase(type))
|
||||
{
|
||||
// Create a record model without a name
|
||||
Record recordModel = Record.builder().nodeType(CONTENT_TYPE).build();
|
||||
|
||||
FilePlanComponentAPI filePlanComponentsAPI = getRestAPIFactory().getFilePlanComponentsAPI();
|
||||
String newRecordId = filePlanComponentsAPI.createElectronicRecord(record, IMAGE_FILE, container.getId()).getId();
|
||||
|
||||
// verify the create request status code
|
||||
// Create an electronic record
|
||||
RecordFolderAPI recordFolderAPI = getRestAPIFactory().getRecordFolderAPI();
|
||||
newRecordId = recordFolderAPI.createRecord(recordModel, folderId, getFile(IMAGE_FILE)).getId();
|
||||
}
|
||||
else if(UNFILED_CONTAINER_TYPE.equalsIgnoreCase(type))
|
||||
{
|
||||
UnfiledContainerAPI unfiledContainersAPI = getRestAPIFactory().getUnfiledContainersAPI();
|
||||
UnfiledContainerChild recordModel = UnfiledContainerChild.builder().nodeType(CONTENT_TYPE).build();
|
||||
newRecordId = unfiledContainersAPI.uploadRecord(recordModel, folderId, getFile(IMAGE_FILE)).getId();
|
||||
}
|
||||
else if(UNFILED_RECORD_FOLDER_TYPE.equalsIgnoreCase(type))
|
||||
{
|
||||
UnfiledRecordFolderAPI unfiledRecordFoldersAPI = getRestAPIFactory().getUnfiledRecordFoldersAPI();
|
||||
UnfiledContainerChild recordModel = UnfiledContainerChild.builder().nodeType(CONTENT_TYPE).build();
|
||||
newRecordId = unfiledRecordFoldersAPI.uploadRecord(recordModel, folderId, getFile(IMAGE_FILE)).getId();
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception("Unsuported type = " + type);
|
||||
}
|
||||
// Verify the create request status code
|
||||
assertStatusCode(CREATED);
|
||||
|
||||
// get newly created electonic record and verify its properties
|
||||
FilePlanComponent electronicRecord = filePlanComponentsAPI.getFilePlanComponent(newRecordId);
|
||||
// record will have record identifier inserted in its name but will for sure start with file name
|
||||
// and end with its extension
|
||||
// Get newly created electronic record and verify its properties
|
||||
Record electronicRecord = getRestAPIFactory().getRecordsAPI().getRecord(newRecordId);
|
||||
|
||||
// Record will have record identifier inserted in its name but will for sure start with file name and end with its extension
|
||||
assertTrue(electronicRecord.getName().startsWith(IMAGE_FILE.substring(0, IMAGE_FILE.indexOf("."))));
|
||||
assertTrue(electronicRecord.getName().contains(electronicRecord.getProperties().getRmIdentifier()));
|
||||
assertTrue(electronicRecord.getName().contains(electronicRecord.getProperties().getIdentifier()));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Bug (id = "RM-4568")
|
||||
/**
|
||||
* Given I want to create an electronic record
|
||||
* When I use the path relative to the filePlanComponentid
|
||||
* <pre>
|
||||
* Given that I want to create an electronic record in one unfiled record folder
|
||||
* When I use the path relative to the one unfiled record folder
|
||||
* Then the containers in the relativePath that don't exist are created before creating the electronic record
|
||||
* <pre>
|
||||
*/
|
||||
public void createElectronicRecordWithRelativePath() throws Exception
|
||||
{
|
||||
//the containers specified on the RELATIVE_PATH parameter don't exist on server
|
||||
String RELATIVE_PATH = CATEGORY_NAME + "/" + CATEGORY_NAME + "/" + FOLDER_NAME;
|
||||
FilePlanComponent electronicRecord = FilePlanComponent.builder()
|
||||
.name(ELECTRONIC_RECORD_NAME)
|
||||
.nodeType(CONTENT_TYPE.toString())
|
||||
.content(FilePlanComponentContent
|
||||
.builder()
|
||||
.mimeType("text/plain")
|
||||
.build()
|
||||
)
|
||||
.properties(FilePlanComponentProperties
|
||||
.builder()
|
||||
.description(ELECTRONIC_RECORD_NAME)
|
||||
.build()
|
||||
)
|
||||
.relativePath(RELATIVE_PATH)
|
||||
.build();
|
||||
// The containers specified on the relativePath parameter don't exist on server
|
||||
String parentUbnfiledRecordFolderName = "ParentUnfiledRecordFolder" + getRandomAlphanumeric();
|
||||
String unfiledRecordFolderPathEl1 = "UnfiledRecordFolderPathEl1" + getRandomAlphanumeric();
|
||||
String unfiledRecordFolderPathEl2 = "UnfiledRecordFolderPathEl2" + getRandomAlphanumeric();
|
||||
String unfiledRecordFolderPathEl3 = "UnfiledRecordFolderPathEl3" + getRandomAlphanumeric();
|
||||
|
||||
FilePlanComponentAPI filePlanComponentsAPI = getRestAPIFactory().getFilePlanComponentsAPI();
|
||||
FilePlanComponent recordCreated = filePlanComponentsAPI.createElectronicRecord(electronicRecord, createTempFile(ELECTRONIC_RECORD_NAME, ELECTRONIC_RECORD_NAME), FILE_PLAN_ALIAS);
|
||||
String parentUnfiledRecordFolderId = createUnfiledContainerChild(UNFILED_RECORDS_CONTAINER_ALIAS, parentUbnfiledRecordFolderName, UNFILED_RECORD_FOLDER_TYPE).getId();
|
||||
|
||||
String relativePath = unfiledRecordFolderPathEl1 + "/" + unfiledRecordFolderPathEl2 + "/" + unfiledRecordFolderPathEl3;
|
||||
UnfiledContainerChild unfiledContainerChildModel= UnfiledContainerChild.builder()
|
||||
.name(ELECTRONIC_RECORD_NAME)
|
||||
.nodeType(CONTENT_TYPE)
|
||||
.content(RecordContent.builder()
|
||||
.mimeType(TEXT_PLAIN_VALUE)
|
||||
.build())
|
||||
.relativePath(relativePath)
|
||||
.build();
|
||||
|
||||
|
||||
|
||||
UnfiledRecordFolderAPI unfiledRecordFoldersAPI = getRestAPIFactory().getUnfiledRecordFoldersAPI();
|
||||
UnfiledContainerChild recordCreated = unfiledRecordFoldersAPI.uploadRecord(unfiledContainerChildModel, parentUnfiledRecordFolderId, createTempFile(ELECTRONIC_RECORD_NAME, ELECTRONIC_RECORD_NAME));
|
||||
|
||||
// Verify the create request status code
|
||||
assertStatusCode(CREATED);
|
||||
|
||||
// Get newly created electronic record and verify its properties
|
||||
RecordsAPI recordsAPI = getRestAPIFactory().getRecordsAPI();
|
||||
Record record = recordsAPI.getRecord(recordCreated.getId());
|
||||
|
||||
assertTrue(record.getName().startsWith(ELECTRONIC_RECORD_NAME));
|
||||
assertTrue(unfiledRecordFoldersAPI.getUnfiledRecordFolder(record.getParentId()).getName().equals(unfiledRecordFolderPathEl3));
|
||||
|
||||
// The first relative path element exists and the second one does not exist
|
||||
String unfiledRecordFolderPathEl4 = "UnfiledRecordFolderPathEl4" + getRandomAlphanumeric();
|
||||
relativePath = unfiledRecordFolderPathEl1 + "/" + unfiledRecordFolderPathEl4;
|
||||
unfiledContainerChildModel.setRelativePath(relativePath);
|
||||
recordCreated = unfiledRecordFoldersAPI.uploadRecord(unfiledContainerChildModel, parentUnfiledRecordFolderId, createTempFile(ELECTRONIC_RECORD_NAME, ELECTRONIC_RECORD_NAME));
|
||||
// verify the create request status code
|
||||
assertStatusCode(CREATED);
|
||||
|
||||
// get newly created electronic record and verify its properties
|
||||
assertTrue(filePlanComponentsAPI.getFilePlanComponent(recordCreated.getId())
|
||||
.getName().startsWith(ELECTRONIC_RECORD_NAME));
|
||||
assertTrue(filePlanComponentsAPI.getFilePlanComponent(recordCreated.getId())
|
||||
.getProperties().getDescription().equals(ELECTRONIC_RECORD_NAME));
|
||||
assertTrue(filePlanComponentsAPI.getFilePlanComponent(recordCreated.getParentId())
|
||||
.getName().equals(FOLDER_NAME));
|
||||
//get newly created electronic record using the relativePath
|
||||
assertTrue(filePlanComponentsAPI.getFilePlanComponent(FILE_PLAN_ALIAS, FilePlanComponentFields.RELATIVE_PATH + "=" + RELATIVE_PATH + "/" + recordCreated.getName())
|
||||
.getId().equals(recordCreated.getId()));
|
||||
record = recordsAPI.getRecord(recordCreated.getId());
|
||||
|
||||
//the category specified via the RELATIVE_PATH exist, folder doesn't exist
|
||||
RELATIVE_PATH = CATEGORY_NAME + "/" + FOLDER_NAME;
|
||||
electronicRecord.setRelativePath(RELATIVE_PATH);
|
||||
recordCreated = filePlanComponentsAPI.createElectronicRecord(electronicRecord, createTempFile(ELECTRONIC_RECORD_NAME, ELECTRONIC_RECORD_NAME), FILE_PLAN_ALIAS);
|
||||
// verify the create request status code
|
||||
assertStatusCode(CREATED);
|
||||
// get newly created electronic record and verify its properties
|
||||
assertTrue(filePlanComponentsAPI.getFilePlanComponent(recordCreated.getId())
|
||||
.getName().startsWith(ELECTRONIC_RECORD_NAME));
|
||||
assertTrue(filePlanComponentsAPI.getFilePlanComponent(recordCreated.getParentId())
|
||||
.getName().startsWith(FOLDER_NAME));
|
||||
//get newly created electronic record using the relativePath
|
||||
assertTrue(filePlanComponentsAPI.getFilePlanComponent(FILE_PLAN_ALIAS, FilePlanComponentFields.RELATIVE_PATH + "=" + RELATIVE_PATH + "/" + recordCreated.getName())
|
||||
.getId().equals(recordCreated.getId()));
|
||||
assertTrue(record.getName().startsWith(ELECTRONIC_RECORD_NAME));
|
||||
assertTrue(unfiledRecordFoldersAPI.getUnfiledRecordFolder(record.getParentId()).getName().equals(unfiledRecordFolderPathEl4));
|
||||
|
||||
//the containers from the RELATIVE PATH exists
|
||||
electronicRecord.setName(ELECTRONIC_RECORD_NAME + getRandomAlphanumeric());
|
||||
recordCreated = filePlanComponentsAPI.createElectronicRecord(electronicRecord, createTempFile(ELECTRONIC_RECORD_NAME, ELECTRONIC_RECORD_NAME), FILE_PLAN_ALIAS);
|
||||
unfiledContainerChildModel.setName(ELECTRONIC_RECORD_NAME + getRandomAlphanumeric());
|
||||
recordCreated = unfiledRecordFoldersAPI.uploadRecord(unfiledContainerChildModel, parentUnfiledRecordFolderId, createTempFile(ELECTRONIC_RECORD_NAME, ELECTRONIC_RECORD_NAME));
|
||||
// verify the create request status code
|
||||
assertStatusCode(CREATED);
|
||||
// get newly created electronic record and verify its properties
|
||||
assertTrue(filePlanComponentsAPI.getFilePlanComponent(recordCreated.getId())
|
||||
.getName().startsWith(ELECTRONIC_RECORD_NAME));
|
||||
assertTrue(filePlanComponentsAPI.getFilePlanComponent(recordCreated.getParentId())
|
||||
.getName().startsWith(FOLDER_NAME));
|
||||
//get newly created electronic record using the relativePath
|
||||
assertTrue(filePlanComponentsAPI.getFilePlanComponent(FILE_PLAN_ALIAS, FilePlanComponentFields.RELATIVE_PATH + "=" + RELATIVE_PATH + "/" + recordCreated.getName())
|
||||
.getId().equals(recordCreated.getId()));
|
||||
record = recordsAPI.getRecord(recordCreated.getId());
|
||||
|
||||
//create the container structure relative to the categoryId
|
||||
String categoryId = filePlanComponentsAPI.getFilePlanComponent(FILE_PLAN_ALIAS, FilePlanComponentFields.RELATIVE_PATH + "=" + CATEGORY_NAME)
|
||||
.getId();
|
||||
RELATIVE_PATH = CATEGORY_NAME + CATEGORY_NAME + "/" + FOLDER_NAME;
|
||||
electronicRecord.setRelativePath(RELATIVE_PATH);
|
||||
recordCreated = filePlanComponentsAPI.createElectronicRecord(electronicRecord, createTempFile(ELECTRONIC_RECORD_NAME, ELECTRONIC_RECORD_NAME), categoryId);
|
||||
// verify the create request status code
|
||||
assertStatusCode(CREATED);
|
||||
// get newly created electronic record and verify its properties
|
||||
assertTrue(filePlanComponentsAPI.getFilePlanComponent(recordCreated.getId())
|
||||
.getName().startsWith(ELECTRONIC_RECORD_NAME));
|
||||
assertTrue(filePlanComponentsAPI.getFilePlanComponent(recordCreated.getParentId())
|
||||
.getName().startsWith(FOLDER_NAME));
|
||||
assertTrue(record.getName().startsWith(ELECTRONIC_RECORD_NAME));
|
||||
|
||||
assertTrue(unfiledRecordFoldersAPI.getUnfiledRecordFolder(record.getParentId()).getName().equals(unfiledRecordFolderPathEl4));
|
||||
}
|
||||
}
|
||||
|
@@ -27,35 +27,30 @@
|
||||
package org.alfresco.rest.rm.community.fileplancomponents;
|
||||
|
||||
import static java.util.Arrays.asList;
|
||||
|
||||
import static org.alfresco.rest.rm.community.base.AllowableOperations.CREATE;
|
||||
import static org.alfresco.rest.rm.community.base.AllowableOperations.DELETE;
|
||||
import static org.alfresco.rest.rm.community.base.AllowableOperations.UPDATE;
|
||||
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentAlias.FILE_PLAN_ALIAS;
|
||||
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentAlias.TRANSFERS_ALIAS;
|
||||
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentFields.ALLOWABLE_OPERATIONS;
|
||||
import static org.alfresco.utility.data.RandomData.getRandomAlphanumeric;
|
||||
import static org.springframework.http.HttpStatus.FORBIDDEN;
|
||||
import static org.springframework.http.HttpStatus.NOT_FOUND;
|
||||
import static org.springframework.http.HttpStatus.OK;
|
||||
import static org.springframework.http.HttpStatus.UNPROCESSABLE_ENTITY;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertFalse;
|
||||
import static org.testng.Assert.assertTrue;
|
||||
|
||||
import org.alfresco.rest.rm.community.base.BaseRMRestTest;
|
||||
import org.alfresco.rest.rm.community.base.TestData;
|
||||
import org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponent;
|
||||
import org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentProperties;
|
||||
import org.alfresco.rest.rm.community.requests.igCoreAPI.FilePlanComponentAPI;
|
||||
import org.alfresco.rest.rm.community.requests.igCoreAPI.RMSiteAPI;
|
||||
import org.alfresco.rest.rm.community.model.fileplan.FilePlan;
|
||||
import org.alfresco.rest.rm.community.model.transfercontainer.TransferContainer;
|
||||
import org.alfresco.rest.rm.community.model.unfiledcontainer.UnfiledContainer;
|
||||
import org.alfresco.rest.rm.community.requests.gscore.api.RMSiteAPI;
|
||||
import org.alfresco.utility.model.UserModel;
|
||||
import org.alfresco.utility.report.Bug;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
/**
|
||||
* This class contains the tests for
|
||||
* the File Plan CRUD API
|
||||
* This class contains the tests for the File Plan CRUD API
|
||||
*
|
||||
* @author Rodica Sutu
|
||||
* @since 2.6
|
||||
@@ -63,17 +58,19 @@ import org.testng.annotations.Test;
|
||||
public class FilePlanTests extends BaseRMRestTest
|
||||
{
|
||||
/**
|
||||
* <pre>
|
||||
* Given that the RM site doesn't exist
|
||||
* When I use the API to get the File Plan/Holds/Unfiled Records Container/Transfers
|
||||
* Then I get the 404 response code
|
||||
* </pre>
|
||||
*/
|
||||
@Test
|
||||
(
|
||||
description = "Check the GET response code when the RM site doesn't exist",
|
||||
description = "Check the GET response for the special contianers when the RM site doesn't exist",
|
||||
dataProviderClass = TestData.class,
|
||||
dataProvider = "getContainers"
|
||||
)
|
||||
public void getFilePlanComponentWhenRMIsNotCreated(String filePlanComponentAlias) throws Exception
|
||||
public void getContainersWhenRMIsNotCreated(String containerAlias) throws Exception
|
||||
{
|
||||
RMSiteAPI rmSiteAPI = getRestAPIFactory().getRMSiteAPI();
|
||||
|
||||
@@ -84,217 +81,156 @@ public class FilePlanTests extends BaseRMRestTest
|
||||
rmSiteAPI.deleteRMSite();
|
||||
}
|
||||
|
||||
// Get the file plan component
|
||||
getRestAPIFactory().getFilePlanComponentsAPI().getFilePlanComponent(filePlanComponentAlias);
|
||||
if (FILE_PLAN_ALIAS.equalsIgnoreCase(containerAlias))
|
||||
{
|
||||
getRestAPIFactory().getFilePlansAPI().getFilePlan(containerAlias);
|
||||
}
|
||||
else if(TRANSFERS_ALIAS.equalsIgnoreCase(containerAlias))
|
||||
{
|
||||
getRestAPIFactory().getTransferContainerAPI().getTransferContainer(containerAlias);
|
||||
}
|
||||
else
|
||||
{
|
||||
getRestAPIFactory().getUnfiledContainersAPI().getUnfiledContainer(containerAlias);
|
||||
}
|
||||
|
||||
//check the response code is NOT_FOUND
|
||||
// Check the response code is NOT_FOUND
|
||||
assertStatusCode(NOT_FOUND);
|
||||
}
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* Given that a file plan exists
|
||||
* When I ask the API for the details of the file plan
|
||||
* Then I am given the details of the file plan
|
||||
* </pre>
|
||||
*/
|
||||
@Test
|
||||
(
|
||||
description = "Check the GET response for special file plan components when the RM site exit",
|
||||
description = "Check the GET response for the special containers when the RM site exit",
|
||||
dataProviderClass = TestData.class,
|
||||
dataProvider = "getContainersAndTypes"
|
||||
)
|
||||
public void getFilePlanComponentWhenRMIsCreated(String filePlanComponentAlias, String filePlanComponentType) throws Exception
|
||||
public void getContainersWhenRMIsCreated(String containerAlias, String containerType) throws Exception
|
||||
{
|
||||
// Create RM Site if doesn't exist
|
||||
createRMSiteIfNotExists();
|
||||
|
||||
// Get the file plan special container
|
||||
FilePlanComponent filePlanComponent = getRestAPIFactory().getFilePlanComponentsAPI().getFilePlanComponent(filePlanComponentAlias);
|
||||
FilePlan filePlan = null;
|
||||
TransferContainer transferContainer = null;
|
||||
UnfiledContainer unfiledContainer = null;
|
||||
|
||||
if (FILE_PLAN_ALIAS.equalsIgnoreCase(containerAlias))
|
||||
{
|
||||
filePlan = getRestAPIFactory().getFilePlansAPI().getFilePlan(containerAlias);
|
||||
}
|
||||
else if(TRANSFERS_ALIAS.equalsIgnoreCase(containerAlias))
|
||||
{
|
||||
transferContainer = getRestAPIFactory().getTransferContainerAPI().getTransferContainer(containerAlias);
|
||||
}
|
||||
else
|
||||
{
|
||||
unfiledContainer = getRestAPIFactory().getUnfiledContainersAPI().getUnfiledContainer(containerAlias);
|
||||
}
|
||||
|
||||
// Check the response code
|
||||
assertStatusCode(OK);
|
||||
|
||||
// Check the response contains the right node type
|
||||
assertEquals(filePlanComponent.getNodeType(), filePlanComponentType);
|
||||
if (FILE_PLAN_ALIAS.equalsIgnoreCase(containerAlias))
|
||||
{
|
||||
assertEquals(filePlan.getNodeType(), containerType);
|
||||
}
|
||||
else if(TRANSFERS_ALIAS.equalsIgnoreCase(containerAlias))
|
||||
{
|
||||
assertEquals(transferContainer.getNodeType(), containerType);
|
||||
}
|
||||
else
|
||||
{
|
||||
assertEquals(unfiledContainer.getNodeType(), containerType);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* Given that a file plan exists
|
||||
* When I ask the API for the details of the file plan to include the allowableOperations property
|
||||
* Then I am given the allowableOperations property with the update and create operations.
|
||||
* </pre>
|
||||
*/
|
||||
@Test
|
||||
(
|
||||
description = "Check the allowableOperations list returned ",
|
||||
description = "Check the allowableOperations list returned",
|
||||
dataProviderClass = TestData.class,
|
||||
dataProvider = "getContainers"
|
||||
)
|
||||
public void includeAllowableOperations(String specialContainerAlias) throws Exception
|
||||
public void includeAllowableOperations(String containerAlias) throws Exception
|
||||
{
|
||||
// Create RM Site if doesn't exist
|
||||
createRMSiteIfNotExists();
|
||||
|
||||
// Get the file plan special containers with the optional parameter allowableOperations
|
||||
FilePlanComponent filePlanComponent = getRestAPIFactory().getFilePlanComponentsAPI().getFilePlanComponent(specialContainerAlias, "include=" + ALLOWABLE_OPERATIONS);
|
||||
FilePlan filePlan = null;
|
||||
TransferContainer transferContainer = null;
|
||||
UnfiledContainer unfiledContainer = null;
|
||||
|
||||
// Check the list of allowableOperations returned
|
||||
if(specialContainerAlias.equals(TRANSFERS_ALIAS))
|
||||
if (FILE_PLAN_ALIAS.equalsIgnoreCase(containerAlias))
|
||||
{
|
||||
assertTrue(filePlanComponent.getAllowableOperations().containsAll(asList(UPDATE)),
|
||||
"Wrong list of the allowable operations is return" + filePlanComponent.getAllowableOperations().toString());
|
||||
// Check the list of allowableOperations returned
|
||||
filePlan = getRestAPIFactory().getFilePlansAPI().getFilePlan(containerAlias, "include=" + ALLOWABLE_OPERATIONS);
|
||||
|
||||
assertTrue(filePlan.getAllowableOperations().containsAll(asList(UPDATE, CREATE)),
|
||||
"Wrong list of the allowable operations is return" + filePlan.getAllowableOperations().toString());
|
||||
|
||||
// Check the list of allowableOperations doesn't contain DELETE operation
|
||||
assertFalse(filePlan.getAllowableOperations().contains(DELETE),
|
||||
"The list of allowable operations contains delete option" + filePlan.getAllowableOperations().toString());
|
||||
}
|
||||
else if (TRANSFERS_ALIAS.equalsIgnoreCase(containerAlias))
|
||||
{
|
||||
// Check the list of allowableOperations returned
|
||||
transferContainer = getRestAPIFactory().getTransferContainerAPI().getTransferContainer(containerAlias, "include=" + ALLOWABLE_OPERATIONS);
|
||||
|
||||
assertTrue(transferContainer.getAllowableOperations().containsAll(asList(UPDATE)),
|
||||
"Wrong list of the allowable operations is return" + transferContainer.getAllowableOperations().toString());
|
||||
|
||||
// Check the list of allowableOperations doesn't contain DELETE operation
|
||||
assertFalse(transferContainer.getAllowableOperations().contains(DELETE),
|
||||
"The list of allowable operations contains delete option" + transferContainer.getAllowableOperations().toString());
|
||||
|
||||
// Check the list of allowableOperations doesn't contain DELETE operation
|
||||
assertFalse(transferContainer.getAllowableOperations().contains(CREATE),
|
||||
"The list of allowable operations contains delete option" + transferContainer.getAllowableOperations().toString());
|
||||
}
|
||||
else
|
||||
{
|
||||
assertTrue(filePlanComponent.getAllowableOperations().containsAll(asList(UPDATE, CREATE)),
|
||||
"Wrong list of the allowable operations is return" + filePlanComponent.getAllowableOperations().toString());
|
||||
unfiledContainer = getRestAPIFactory().getUnfiledContainersAPI().getUnfiledContainer(containerAlias, "include=" + ALLOWABLE_OPERATIONS);
|
||||
|
||||
// Check the list of allowableOperations returned
|
||||
assertTrue(unfiledContainer.getAllowableOperations().containsAll(asList(UPDATE, CREATE)),
|
||||
"Wrong list of the allowable operations is return" + unfiledContainer.getAllowableOperations().toString());
|
||||
|
||||
// Check the list of allowableOperations doesn't contain DELETE operation
|
||||
assertFalse(unfiledContainer.getAllowableOperations().contains(DELETE),
|
||||
"The list of allowable operations contains delete option" + unfiledContainer.getAllowableOperations().toString());
|
||||
}
|
||||
|
||||
// Check the list of allowableOperations doesn't contains DELETE operation
|
||||
assertFalse(filePlanComponent.getAllowableOperations().contains(DELETE),
|
||||
"The list of allowable operations contains delete option" + filePlanComponent.getAllowableOperations().toString());
|
||||
}
|
||||
|
||||
/**
|
||||
* Given that a file plan exists
|
||||
* When I ask the API to modify the details of the file plan
|
||||
* Then the details of the file are modified
|
||||
* Note: the details of the file plan are limited to title and description.
|
||||
*/
|
||||
@Test
|
||||
@Bug (id = "RM-4295")
|
||||
public void updateFilePlan() throws Exception
|
||||
{
|
||||
String FILE_PLAN_DESCRIPTION = "Description updated " + getRandomAlphanumeric();
|
||||
String FILE_PLAN_TITLE = "Title updated " + getRandomAlphanumeric();
|
||||
|
||||
// Create RM Site if doesn't exist
|
||||
createRMSiteIfNotExists();
|
||||
|
||||
// Build object for updating the filePlan
|
||||
FilePlanComponent filePlanComponent = FilePlanComponent.builder()
|
||||
.properties(FilePlanComponentProperties.builder()
|
||||
.title(FILE_PLAN_TITLE)
|
||||
.description(FILE_PLAN_DESCRIPTION)
|
||||
.build())
|
||||
.build();
|
||||
|
||||
// Update the record category
|
||||
FilePlanComponent renamedFilePlanComponent = getRestAPIFactory().getFilePlanComponentsAPI().updateFilePlanComponent(filePlanComponent, FILE_PLAN_ALIAS);
|
||||
|
||||
// Verify the response status code
|
||||
assertStatusCode(OK);
|
||||
|
||||
// Verify the returned description field for the file plan component
|
||||
assertEquals(renamedFilePlanComponent.getProperties().getDescription(), FILE_PLAN_DESCRIPTION);
|
||||
|
||||
// Verify the returned title field for the file plan component
|
||||
assertEquals(renamedFilePlanComponent.getProperties().getTitle(), FILE_PLAN_TITLE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Given that a file plan exists
|
||||
* When I ask the API to delete the file plan
|
||||
* Then the 422 response code is returned.
|
||||
*/
|
||||
@Test
|
||||
(
|
||||
description = "Check the response code when deleting the special file plan components",
|
||||
dataProviderClass = TestData.class,
|
||||
dataProvider = "getContainers"
|
||||
)
|
||||
public void deleteFilePlanSpecialComponents(String filePlanComponentAlias) throws Exception
|
||||
{
|
||||
// Create RM Site if doesn't exist
|
||||
createRMSiteIfNotExists();
|
||||
|
||||
// Delete the file plan component
|
||||
getRestAPIFactory().getFilePlanComponentsAPI().deleteFilePlanComponent(filePlanComponentAlias);
|
||||
|
||||
// Check the DELETE response status code
|
||||
assertStatusCode(UNPROCESSABLE_ENTITY);
|
||||
}
|
||||
|
||||
/**
|
||||
* Given that a file plan exists and I am a non RM user
|
||||
* When I ask the API to delete the file plan
|
||||
* Then the 403 response code is returned.
|
||||
*/
|
||||
@Test
|
||||
(
|
||||
description = "Check the response code when deleting the special file plan components with non RM user",
|
||||
dataProviderClass = TestData.class,
|
||||
dataProvider = "getContainers"
|
||||
)
|
||||
public void deleteFilePlanSpecialComponentsNonRMUser(String filePlanComponentAlias) throws Exception
|
||||
{
|
||||
// Create RM Site if doesn't exist
|
||||
createRMSiteIfNotExists();
|
||||
|
||||
// Create a random user
|
||||
UserModel nonRMuser = getDataUser().createRandomTestUser("testUser");
|
||||
|
||||
// Delete the file plan component
|
||||
getRestAPIFactory().getFilePlanComponentsAPI(nonRMuser).deleteFilePlanComponent(filePlanComponentAlias);
|
||||
|
||||
// Check the DELETE response status code
|
||||
assertStatusCode(FORBIDDEN);
|
||||
}
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* Given that RM site exists
|
||||
* When I ask to create the file plan
|
||||
* Then the 403 response code is returned.
|
||||
*/
|
||||
@Test
|
||||
(
|
||||
description = "Check the response code when creating the special file plan components",
|
||||
dataProviderClass = TestData.class,
|
||||
dataProvider = "getContainersAndTypes"
|
||||
)
|
||||
@Bug(id = "RM-4296")
|
||||
public void createFilePlanSpecialContainerWhenExists(String filePlanComponentAlias, String filePlanComponentType) throws Exception
|
||||
{
|
||||
// Create RM Site if doesn't exist
|
||||
createRMSiteIfNotExists();
|
||||
|
||||
// Get the RM site ID
|
||||
String rmSiteId = getRestAPIFactory().getRMSiteAPI().getSite().getGuid();
|
||||
String name = filePlanComponentAlias + getRandomAlphanumeric();
|
||||
|
||||
// Build the file plan root properties
|
||||
FilePlanComponent filePlanComponent = FilePlanComponent.builder()
|
||||
.name(name)
|
||||
.nodeType(filePlanComponentType)
|
||||
.properties(FilePlanComponentProperties.builder()
|
||||
.build())
|
||||
.build();
|
||||
|
||||
FilePlanComponentAPI filePlanComponentsAPI = getRestAPIFactory().getFilePlanComponentsAPI();
|
||||
|
||||
// Create the special containers into RM site - parent folder
|
||||
filePlanComponentsAPI.createFilePlanComponent(filePlanComponent, rmSiteId);
|
||||
assertStatusCode(UNPROCESSABLE_ENTITY);
|
||||
|
||||
// Create the special containers into RM site - parent folder
|
||||
filePlanComponentsAPI.createFilePlanComponent(filePlanComponent, FILE_PLAN_ALIAS);
|
||||
assertStatusCode(UNPROCESSABLE_ENTITY);
|
||||
|
||||
// Create the special containers into the root of special containers containers
|
||||
filePlanComponentsAPI.createFilePlanComponent(filePlanComponent, filePlanComponentAlias);
|
||||
assertStatusCode(UNPROCESSABLE_ENTITY);
|
||||
}
|
||||
|
||||
/**
|
||||
* Given that RM site exists
|
||||
* When a non-RM user ask the API for the details of the file plan
|
||||
* When a non-RM user asks the API for the details of the file plan
|
||||
* Then the status code 403 (Permission denied) is return
|
||||
* </pre>
|
||||
*/
|
||||
@Test
|
||||
(
|
||||
description = "Check the response code when the RM site containers are get with non rm users",
|
||||
description = "Check the response code when the RM site containers are get with non-RM users",
|
||||
dataProviderClass = TestData.class,
|
||||
dataProvider = "getContainers"
|
||||
)
|
||||
public void getSpecialFilePlanComponentsWithNonRMuser(String filePlanComponentAlias) throws Exception
|
||||
public void getContainersWithNonRMuser(String containerAlias) throws Exception
|
||||
{
|
||||
// Create RM Site if doesn't exist
|
||||
createRMSiteIfNotExists();
|
||||
@@ -303,7 +239,18 @@ public class FilePlanTests extends BaseRMRestTest
|
||||
UserModel nonRMuser = getDataUser().createRandomTestUser("testUser");
|
||||
|
||||
// Get the special file plan components
|
||||
getRestAPIFactory().getFilePlanComponentsAPI(nonRMuser).getFilePlanComponent(filePlanComponentAlias);
|
||||
if (FILE_PLAN_ALIAS.equalsIgnoreCase(containerAlias))
|
||||
{
|
||||
getRestAPIFactory().getFilePlansAPI(nonRMuser).getFilePlan(containerAlias);
|
||||
}
|
||||
else if(TRANSFERS_ALIAS.equalsIgnoreCase(containerAlias))
|
||||
{
|
||||
getRestAPIFactory().getTransferContainerAPI(nonRMuser).getTransferContainer(containerAlias);
|
||||
}
|
||||
else
|
||||
{
|
||||
getRestAPIFactory().getUnfiledContainersAPI(nonRMuser).getUnfiledContainer(containerAlias);
|
||||
}
|
||||
|
||||
// Check the response status code is FORBIDDEN
|
||||
assertStatusCode(FORBIDDEN);
|
||||
|
@@ -29,11 +29,11 @@ package org.alfresco.rest.rm.community.fileplancomponents;
|
||||
import static org.alfresco.rest.rm.community.base.TestData.ELECTRONIC_RECORD_NAME;
|
||||
import static org.alfresco.rest.rm.community.base.TestData.NONELECTRONIC_RECORD_NAME;
|
||||
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentAlias.FILE_PLAN_ALIAS;
|
||||
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentAlias.HOLDS_ALIAS;
|
||||
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentAlias.TRANSFERS_ALIAS;
|
||||
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentAlias.UNFILED_RECORDS_CONTAINER_ALIAS;
|
||||
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.CONTENT_TYPE;
|
||||
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.NON_ELECTRONIC_RECORD_TYPE;
|
||||
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.UNFILED_RECORD_FOLDER_TYPE;
|
||||
import static org.alfresco.rest.rm.community.utils.FilePlanComponentsUtil.createTempFile;
|
||||
import static org.alfresco.utility.data.RandomData.getRandomAlphanumeric;
|
||||
import static org.springframework.http.HttpStatus.BAD_REQUEST;
|
||||
@@ -43,13 +43,21 @@ import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertFalse;
|
||||
import static org.testng.AssertJUnit.assertTrue;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.alfresco.rest.rm.community.base.BaseRMRestTest;
|
||||
import org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponent;
|
||||
import org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentContent;
|
||||
import org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentProperties;
|
||||
import org.alfresco.rest.rm.community.model.fileplancomponents.RecordBodyFile;
|
||||
import org.alfresco.rest.rm.community.requests.igCoreAPI.FilePlanComponentAPI;
|
||||
import org.alfresco.rest.rm.community.requests.igCoreAPI.RecordsAPI;
|
||||
import org.alfresco.rest.rm.community.model.record.Record;
|
||||
import org.alfresco.rest.rm.community.model.record.RecordBodyFile;
|
||||
import org.alfresco.rest.rm.community.model.record.RecordContent;
|
||||
import org.alfresco.rest.rm.community.model.recordcategory.RecordCategoryChildCollection;
|
||||
import org.alfresco.rest.rm.community.model.recordcategory.RecordCategoryChildEntry;
|
||||
import org.alfresco.rest.rm.community.model.unfiledcontainer.UnfiledContainerChild;
|
||||
import org.alfresco.rest.rm.community.model.unfiledcontainer.UnfiledContainerChildProperties;
|
||||
import org.alfresco.rest.rm.community.requests.gscore.api.RecordCategoryAPI;
|
||||
import org.alfresco.rest.rm.community.requests.gscore.api.RecordFolderAPI;
|
||||
import org.alfresco.rest.rm.community.requests.gscore.api.RecordsAPI;
|
||||
import org.alfresco.rest.rm.community.requests.gscore.api.UnfiledContainerAPI;
|
||||
import org.alfresco.rest.rm.community.requests.gscore.api.UnfiledRecordFolderAPI;
|
||||
import org.alfresco.utility.report.Bug;
|
||||
import org.testng.annotations.DataProvider;
|
||||
import org.testng.annotations.Test;
|
||||
@@ -63,14 +71,14 @@ import org.testng.annotations.Test;
|
||||
*/
|
||||
public class FileRecordsTests extends BaseRMRestTest
|
||||
{
|
||||
private FilePlanComponent electronicRecord = FilePlanComponent.builder()
|
||||
private UnfiledContainerChild electronicRecord = UnfiledContainerChild.builder()
|
||||
.name(ELECTRONIC_RECORD_NAME)
|
||||
.nodeType(CONTENT_TYPE.toString())
|
||||
.content(FilePlanComponentContent.builder().mimeType("text/plain").build())
|
||||
.content(RecordContent.builder().mimeType("text/plain").build())
|
||||
.build();
|
||||
|
||||
private FilePlanComponent nonelectronicRecord = FilePlanComponent.builder()
|
||||
.properties(FilePlanComponentProperties.builder()
|
||||
private UnfiledContainerChild nonelectronicRecord = UnfiledContainerChild.builder()
|
||||
.properties(UnfiledContainerChildProperties.builder()
|
||||
.description(NONELECTRONIC_RECORD_NAME)
|
||||
.title("Title")
|
||||
.build())
|
||||
@@ -78,126 +86,170 @@ public class FileRecordsTests extends BaseRMRestTest
|
||||
.nodeType(NON_ELECTRONIC_RECORD_TYPE.toString())
|
||||
.build();
|
||||
|
||||
/**
|
||||
* Unfiled containers from where record can be filed
|
||||
*/
|
||||
@DataProvider (name = "unfiledContainer")
|
||||
public Object[][] getUnfiledContainer() throws Exception
|
||||
{
|
||||
return new Object[][] {
|
||||
//unfiled container
|
||||
{ getFilePlanComponent(UNFILED_RECORDS_CONTAINER_ALIAS).getId() },
|
||||
// an arbitrary unfiled records folder
|
||||
{ createUnfiledRecordsFolder(UNFILED_RECORDS_CONTAINER_ALIAS.toString(), "Unfiled Folder " + getRandomAlphanumeric()).getId() }
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Invalid containers where electronic and non-electronic records can be filed
|
||||
*/
|
||||
@DataProvider (name = "invalidContainersForFile")
|
||||
public Object[][] getFolderContainers() throws Exception
|
||||
public String[][] getFolderContainers() throws Exception
|
||||
{
|
||||
return new Object[][] {
|
||||
{ getFilePlanComponent(FILE_PLAN_ALIAS).getId()},
|
||||
{ getFilePlanComponent(UNFILED_RECORDS_CONTAINER_ALIAS).getId()},
|
||||
{ getFilePlanComponent(HOLDS_ALIAS).getId() },
|
||||
{ getFilePlanComponent(TRANSFERS_ALIAS).getId() },
|
||||
return new String[][] {
|
||||
{ FILE_PLAN_ALIAS},
|
||||
{ UNFILED_RECORDS_CONTAINER_ALIAS},
|
||||
{ TRANSFERS_ALIAS },
|
||||
// an arbitrary record category
|
||||
{ createCategory(getAdminUser(), FILE_PLAN_ALIAS, "Category " + getRandomAlphanumeric()).getId()},
|
||||
{ createRootCategory(getAdminUser(), "Category " + getRandomAlphanumeric()).getId()},
|
||||
// an arbitrary unfiled records folder
|
||||
{ createUnfiledRecordsFolder(UNFILED_RECORDS_CONTAINER_ALIAS.toString(), "Unfiled Folder " + getRandomAlphanumeric()).getId() }
|
||||
{ createUnfiledContainerChild(UNFILED_RECORDS_CONTAINER_ALIAS, "Unfiled Folder " + getRandomAlphanumeric(), UNFILED_RECORD_FOLDER_TYPE).getId() }
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Given an unfiled record in the root unfiled record container or a unfiled record folder
|
||||
* Given an unfiled record in the root unfiled record container
|
||||
* And an open record folder
|
||||
* When I file the unfiled record into the record folder
|
||||
* Then the record is filed
|
||||
*/
|
||||
@Test
|
||||
(
|
||||
dataProvider = "unfiledContainer",
|
||||
description = "File record from unfiled containers "
|
||||
)
|
||||
public void fileRecordIntoExistingFolder(String unfiledContainerId) throws Exception
|
||||
public void fileRecordIntoExistingFolderFromUnfiledContainer() throws Exception
|
||||
{
|
||||
// get API instances
|
||||
FilePlanComponentAPI filePlanComponentAPI = getRestAPIFactory().getFilePlanComponentsAPI();
|
||||
RecordsAPI recordsAPI = getRestAPIFactory().getRecordsAPI();
|
||||
|
||||
|
||||
// create a record folder
|
||||
String folderId = createCategoryFolderInFilePlan().getId();
|
||||
|
||||
// create records
|
||||
FilePlanComponent recordElectronic = filePlanComponentAPI.createElectronicRecord(electronicRecord, createTempFile(ELECTRONIC_RECORD_NAME, ELECTRONIC_RECORD_NAME), unfiledContainerId);
|
||||
FilePlanComponent recordNonElectId = filePlanComponentAPI.createFilePlanComponent(nonelectronicRecord, unfiledContainerId);
|
||||
UnfiledContainerAPI unfiledContainersAPI = getRestAPIFactory().getUnfiledContainersAPI();
|
||||
UnfiledContainerChild recordElectronic = unfiledContainersAPI.uploadRecord(electronicRecord, UNFILED_RECORDS_CONTAINER_ALIAS,
|
||||
createTempFile(ELECTRONIC_RECORD_NAME, ELECTRONIC_RECORD_NAME));
|
||||
UnfiledContainerChild recordNonElect = unfiledContainersAPI.createUnfiledContainerChild(nonelectronicRecord, UNFILED_RECORDS_CONTAINER_ALIAS);
|
||||
|
||||
// file the record into the folder created
|
||||
RecordBodyFile recordBodyFile = RecordBodyFile.builder().targetParentId(folderId).build();
|
||||
FilePlanComponent recordFiled = recordsAPI.fileRecord(recordBodyFile, recordElectronic.getId());
|
||||
Record recordFiled = recordsAPI.fileRecord(recordBodyFile, recordElectronic.getId());
|
||||
// check the response status
|
||||
assertStatusCode(CREATED);
|
||||
// check the parent id for the record returned
|
||||
assertEquals(recordFiled.getParentId(),folderId);
|
||||
|
||||
|
||||
// check the record is filed into the record folder
|
||||
assertTrue(filePlanComponentAPI.listChildComponents(folderId)
|
||||
RecordFolderAPI recordFolderAPI = getRestAPIFactory().getRecordFolderAPI();
|
||||
assertTrue(recordFolderAPI.getRecordFolderChildren(folderId)
|
||||
.getEntries()
|
||||
.stream()
|
||||
.anyMatch(c->c.getFilePlanComponentModel().getId().equals(recordElectronic.getId())));
|
||||
|
||||
.anyMatch(c -> c.getEntry().getId().equals(recordElectronic.getId())));
|
||||
|
||||
// check the record doesn't exist into unfiled record container
|
||||
assertFalse(filePlanComponentAPI.listChildComponents(unfiledContainerId)
|
||||
.getEntries()
|
||||
.stream()
|
||||
.anyMatch(c -> c.getFilePlanComponentModel().getId().equals(recordElectronic.getId())));
|
||||
|
||||
assertFalse(unfiledContainersAPI.getUnfiledContainerChildren(UNFILED_RECORDS_CONTAINER_ALIAS)
|
||||
.getEntries()
|
||||
.stream()
|
||||
.anyMatch(c -> c.getEntry().getId().equals(recordElectronic.getId())));
|
||||
|
||||
// file the non-electronic record into the folder created
|
||||
FilePlanComponent nonElectRecordFiled = recordsAPI.fileRecord(recordBodyFile, recordNonElectId.getId());
|
||||
Record nonElectRecordFiled = recordsAPI.fileRecord(recordBodyFile, recordNonElect.getId());
|
||||
// check the response status code
|
||||
assertStatusCode(CREATED);
|
||||
// check the parent id for the record returned
|
||||
assertEquals(nonElectRecordFiled.getParentId(), folderId);
|
||||
|
||||
|
||||
// check the record is added into the record folder
|
||||
assertTrue(filePlanComponentAPI.listChildComponents(folderId)
|
||||
assertTrue(recordFolderAPI.getRecordFolderChildren(folderId)
|
||||
.getEntries()
|
||||
.stream()
|
||||
.anyMatch(c -> c.getFilePlanComponentModel().getId().equals(recordNonElectId.getId())));
|
||||
|
||||
.anyMatch(c -> c.getEntry().getId().equals(recordNonElect.getId())));
|
||||
|
||||
// check the record doesn't exist into unfiled record container
|
||||
assertFalse(filePlanComponentAPI.listChildComponents(unfiledContainerId)
|
||||
.getEntries()
|
||||
.stream()
|
||||
.anyMatch(c -> c.getFilePlanComponentModel().getId().equals(recordNonElectId.getId())));
|
||||
assertFalse(unfiledContainersAPI.getUnfiledContainerChildren(UNFILED_RECORDS_CONTAINER_ALIAS)
|
||||
.getEntries()
|
||||
.stream()
|
||||
.anyMatch(c -> c.getEntry().getId().equals(recordNonElect.getId())));
|
||||
}
|
||||
|
||||
/**
|
||||
* Given an unfiled record in the root unfiled record container or a unfiled record folder
|
||||
* Given an unfiled record in a unfiled record folder
|
||||
* And an open record folder
|
||||
* When I file the unfiled record into the record folder
|
||||
* Then the record is filed
|
||||
*/
|
||||
@Test
|
||||
public void fileRecordIntoExistingFolderFromUnfiledRecordFolder() throws Exception
|
||||
{
|
||||
// get API instances
|
||||
RecordsAPI recordsAPI = getRestAPIFactory().getRecordsAPI();
|
||||
|
||||
// create a record folder
|
||||
String folderId = createCategoryFolderInFilePlan().getId();
|
||||
|
||||
// create records
|
||||
UnfiledRecordFolderAPI unfiledRecordFoldersAPI = getRestAPIFactory().getUnfiledRecordFoldersAPI();
|
||||
|
||||
String unfiledRecordFolderId = createUnfiledContainerChild(UNFILED_RECORDS_CONTAINER_ALIAS, "Unfiled Folder " + getRandomAlphanumeric(), UNFILED_RECORD_FOLDER_TYPE).getId();
|
||||
|
||||
UnfiledContainerChild recordElectronic = unfiledRecordFoldersAPI.uploadRecord(electronicRecord, unfiledRecordFolderId, createTempFile(ELECTRONIC_RECORD_NAME, ELECTRONIC_RECORD_NAME));
|
||||
UnfiledContainerChild recordNonElect = unfiledRecordFoldersAPI.createUnfiledRecordFolderChild(nonelectronicRecord, unfiledRecordFolderId);
|
||||
|
||||
// file the record into the folder created
|
||||
RecordBodyFile recordBodyFile = RecordBodyFile.builder().targetParentId(folderId).build();
|
||||
Record recordFiled = recordsAPI.fileRecord(recordBodyFile, recordElectronic.getId());
|
||||
// check the response status
|
||||
assertStatusCode(CREATED);
|
||||
// check the parent id for the record returned
|
||||
assertEquals(recordFiled.getParentId(),folderId);
|
||||
|
||||
// check the record is filed into the record folder
|
||||
RecordFolderAPI recordFolderAPI = getRestAPIFactory().getRecordFolderAPI();
|
||||
assertTrue(recordFolderAPI.getRecordFolderChildren(folderId)
|
||||
.getEntries()
|
||||
.stream()
|
||||
.anyMatch(c -> c.getEntry().getId().equals(recordElectronic.getId())));
|
||||
|
||||
// check the record doesn't exist into unfiled record folder
|
||||
assertFalse(unfiledRecordFoldersAPI.getUnfiledRecordFolderChildren(unfiledRecordFolderId)
|
||||
.getEntries()
|
||||
.stream()
|
||||
.anyMatch(c -> c.getEntry().getId().equals(recordElectronic.getId())));
|
||||
|
||||
// file the non-electronic record into the folder created
|
||||
Record nonElectRecordFiled = recordsAPI.fileRecord(recordBodyFile, recordNonElect.getId());
|
||||
// check the response status code
|
||||
assertStatusCode(CREATED);
|
||||
// check the parent id for the record returned
|
||||
assertEquals(nonElectRecordFiled.getParentId(), folderId);
|
||||
|
||||
// check the record is added into the record folder
|
||||
assertTrue(recordFolderAPI.getRecordFolderChildren(folderId)
|
||||
.getEntries()
|
||||
.stream()
|
||||
.anyMatch(c -> c.getEntry().getId().equals(recordNonElect.getId())));
|
||||
|
||||
// check the record doesn't exist into unfiled record folder
|
||||
assertFalse(unfiledRecordFoldersAPI.getUnfiledRecordFolderChildren(unfiledRecordFolderId)
|
||||
.getEntries()
|
||||
.stream()
|
||||
.anyMatch(c -> c.getEntry().getId().equals(recordNonElect.getId())));
|
||||
}
|
||||
|
||||
/**
|
||||
* Given an unfiled record in the root unfiled record container
|
||||
* And a closed record folder
|
||||
* When I file the unfiled record into the record folder
|
||||
* Then I get an unsupported operation exception
|
||||
*
|
||||
*/
|
||||
@Test
|
||||
(
|
||||
dataProvider = "unfiledContainer",
|
||||
description = "File record from unfiled containers into a closed folder "
|
||||
)
|
||||
public void fileRecordIntoCloseFolder(String unfiledContainerId) throws Exception
|
||||
public void fileRecordIntoCloseFolderFromUnfiledContainer() throws Exception
|
||||
{
|
||||
// get API instances
|
||||
FilePlanComponentAPI filePlanComponentAPI = getRestAPIFactory().getFilePlanComponentsAPI();
|
||||
RecordsAPI recordsAPI = getRestAPIFactory().getRecordsAPI();
|
||||
|
||||
|
||||
// create a record folder
|
||||
String folderId = createCategoryFolderInFilePlan().getId();
|
||||
closeFolder(folderId);
|
||||
// create records
|
||||
FilePlanComponent recordElectronic = filePlanComponentAPI.createElectronicRecord(electronicRecord, createTempFile(ELECTRONIC_RECORD_NAME, ELECTRONIC_RECORD_NAME), unfiledContainerId);
|
||||
FilePlanComponent recordNonElectId = filePlanComponentAPI.createFilePlanComponent(nonelectronicRecord, unfiledContainerId);
|
||||
UnfiledContainerAPI unfiledContainersAPI = getRestAPIFactory().getUnfiledContainersAPI();
|
||||
|
||||
UnfiledContainerChild recordElectronic = unfiledContainersAPI.uploadRecord(electronicRecord, UNFILED_RECORDS_CONTAINER_ALIAS, createTempFile(ELECTRONIC_RECORD_NAME, ELECTRONIC_RECORD_NAME));
|
||||
UnfiledContainerChild recordNonElect = unfiledContainersAPI.createUnfiledContainerChild(nonelectronicRecord, UNFILED_RECORDS_CONTAINER_ALIAS);
|
||||
|
||||
// file the record into the folder created
|
||||
RecordBodyFile recordBodyFile = RecordBodyFile.builder().targetParentId(folderId).build();
|
||||
@@ -205,33 +257,93 @@ public class FileRecordsTests extends BaseRMRestTest
|
||||
// check the response status
|
||||
assertStatusCode(FORBIDDEN);
|
||||
|
||||
// check the record is filed into the record folder
|
||||
assertFalse(filePlanComponentAPI.listChildComponents(folderId)
|
||||
// check the record is not filed into the record folder
|
||||
RecordFolderAPI recordFolderAPI = getRestAPIFactory().getRecordFolderAPI();
|
||||
assertFalse(recordFolderAPI.getRecordFolderChildren(folderId)
|
||||
.getEntries()
|
||||
.stream()
|
||||
.anyMatch(c -> c.getFilePlanComponentModel().getId().equals(recordElectronic.getId())));
|
||||
|
||||
// check the record doesn't exist into unfiled record container
|
||||
assertTrue(filePlanComponentAPI.listChildComponents(unfiledContainerId)
|
||||
.getEntries()
|
||||
.stream()
|
||||
.anyMatch(c -> c.getFilePlanComponentModel().getId().equals(recordElectronic.getId())));
|
||||
|
||||
.anyMatch(c -> c.getEntry().getId().equals(recordElectronic.getId())));
|
||||
|
||||
// check the record exist into unfiled record container
|
||||
assertTrue(unfiledContainersAPI.getUnfiledContainerChildren(UNFILED_RECORDS_CONTAINER_ALIAS)
|
||||
.getEntries()
|
||||
.stream()
|
||||
.anyMatch(c -> c.getEntry().getId().equals(recordElectronic.getId())));
|
||||
|
||||
// file the non-electronic record into the folder created
|
||||
recordsAPI.fileRecord(recordBodyFile, recordNonElectId.getId());
|
||||
recordsAPI.fileRecord(recordBodyFile, recordNonElect.getId());
|
||||
// check the response status code
|
||||
assertStatusCode(FORBIDDEN);
|
||||
|
||||
// check the record is added into the record folder
|
||||
assertFalse(filePlanComponentAPI.listChildComponents(folderId)
|
||||
|
||||
// check the record is not added into the record folder
|
||||
assertFalse(recordFolderAPI.getRecordFolderChildren(folderId)
|
||||
.getEntries()
|
||||
.stream()
|
||||
.anyMatch(c -> c.getFilePlanComponentModel().getId().equals(recordNonElectId.getId())));
|
||||
|
||||
// check the record doesn't exist into unfiled record container
|
||||
assertTrue(filePlanComponentAPI.listChildComponents(unfiledContainerId)
|
||||
.getEntries().stream()
|
||||
.anyMatch(c -> c.getFilePlanComponentModel().getId().equals(recordNonElectId.getId())));
|
||||
.anyMatch(c -> c.getEntry().getId().equals(recordNonElect.getId())));
|
||||
|
||||
// check the record exist into unfiled record container
|
||||
assertTrue(unfiledContainersAPI.getUnfiledContainerChildren(UNFILED_RECORDS_CONTAINER_ALIAS)
|
||||
.getEntries().stream()
|
||||
.anyMatch(c -> c.getEntry().getId().equals(recordNonElect.getId())));
|
||||
}
|
||||
|
||||
/**
|
||||
* Given an unfiled record in a unfiled record folder
|
||||
* And a closed record folder
|
||||
* When I file the unfiled record into the record folder
|
||||
* Then I get an unsupported operation exception
|
||||
*
|
||||
*/
|
||||
@Test
|
||||
public void fileRecordIntoCloseFolderFromUnfiledRecordFolder() throws Exception
|
||||
{
|
||||
// get API instances
|
||||
RecordsAPI recordsAPI = getRestAPIFactory().getRecordsAPI();
|
||||
|
||||
// create a record folder
|
||||
String folderId = createCategoryFolderInFilePlan().getId();
|
||||
closeFolder(folderId);
|
||||
// create records
|
||||
UnfiledRecordFolderAPI unfiledRecordFoldersAPI = getRestAPIFactory().getUnfiledRecordFoldersAPI();
|
||||
|
||||
String unfiledRecordFolderId = createUnfiledContainerChild(UNFILED_RECORDS_CONTAINER_ALIAS, "Unfiled Folder " + getRandomAlphanumeric(), UNFILED_RECORD_FOLDER_TYPE).getId();
|
||||
UnfiledContainerChild recordElectronic = unfiledRecordFoldersAPI.uploadRecord(electronicRecord, unfiledRecordFolderId, createTempFile(ELECTRONIC_RECORD_NAME, ELECTRONIC_RECORD_NAME));
|
||||
UnfiledContainerChild recordNonElect = unfiledRecordFoldersAPI.createUnfiledRecordFolderChild(nonelectronicRecord, unfiledRecordFolderId);
|
||||
|
||||
// file the record into the folder created
|
||||
RecordBodyFile recordBodyFile = RecordBodyFile.builder().targetParentId(folderId).build();
|
||||
recordsAPI.fileRecord(recordBodyFile, recordElectronic.getId());
|
||||
// check the response status
|
||||
assertStatusCode(FORBIDDEN);
|
||||
|
||||
// check the record is not filed into the record folder
|
||||
RecordFolderAPI recordFolderAPI = getRestAPIFactory().getRecordFolderAPI();
|
||||
assertFalse(recordFolderAPI.getRecordFolderChildren(folderId)
|
||||
.getEntries()
|
||||
.stream()
|
||||
.anyMatch(c -> c.getEntry().getId().equals(recordElectronic.getId())));
|
||||
|
||||
// check the record exist into unfiled record folder
|
||||
assertTrue(unfiledRecordFoldersAPI.getUnfiledRecordFolderChildren(unfiledRecordFolderId)
|
||||
.getEntries()
|
||||
.stream()
|
||||
.anyMatch(c -> c.getEntry().getId().equals(recordElectronic.getId())));
|
||||
|
||||
// file the non-electronic record into the folder created
|
||||
recordsAPI.fileRecord(recordBodyFile, recordNonElect.getId());
|
||||
// check the response status code
|
||||
assertStatusCode(FORBIDDEN);
|
||||
|
||||
// check the record is not added into the record folder
|
||||
assertFalse(recordFolderAPI.getRecordFolderChildren(folderId)
|
||||
.getEntries()
|
||||
.stream()
|
||||
.anyMatch(c -> c.getEntry().getId().equals(recordNonElect.getId())));
|
||||
|
||||
// check the record exist into unfiled record folder
|
||||
assertTrue(unfiledRecordFoldersAPI.getUnfiledRecordFolderChildren(unfiledRecordFolderId)
|
||||
.getEntries().stream()
|
||||
.anyMatch(c -> c.getEntry().getId().equals(recordNonElect.getId())));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -245,20 +357,20 @@ public class FileRecordsTests extends BaseRMRestTest
|
||||
public void linkRecordInto() throws Exception
|
||||
{
|
||||
// get API instances
|
||||
FilePlanComponentAPI filePlanComponentAPI = getRestAPIFactory().getFilePlanComponentsAPI();
|
||||
RecordsAPI recordsAPI = getRestAPIFactory().getRecordsAPI();
|
||||
|
||||
|
||||
// create a record folder
|
||||
String parentFolderId = createCategoryFolderInFilePlan().getId();
|
||||
|
||||
// create records
|
||||
FilePlanComponent recordElectronic = filePlanComponentAPI.createElectronicRecord(electronicRecord, createTempFile(ELECTRONIC_RECORD_NAME, ELECTRONIC_RECORD_NAME), UNFILED_RECORDS_CONTAINER_ALIAS);
|
||||
FilePlanComponent recordNonElect = filePlanComponentAPI.createFilePlanComponent(nonelectronicRecord, UNFILED_RECORDS_CONTAINER_ALIAS);
|
||||
UnfiledContainerAPI unfiledContainersAPI = getRestAPIFactory().getUnfiledContainersAPI();
|
||||
UnfiledContainerChild recordElectronic = unfiledContainersAPI.uploadRecord(electronicRecord, UNFILED_RECORDS_CONTAINER_ALIAS, createTempFile(ELECTRONIC_RECORD_NAME, ELECTRONIC_RECORD_NAME));
|
||||
UnfiledContainerChild recordNonElect = unfiledContainersAPI.createUnfiledContainerChild(nonelectronicRecord, UNFILED_RECORDS_CONTAINER_ALIAS);
|
||||
|
||||
// file the record into the folder created
|
||||
RecordBodyFile recordBodyFile = RecordBodyFile.builder().targetParentId(parentFolderId).build();
|
||||
FilePlanComponent recordFiled = recordsAPI.fileRecord(recordBodyFile, recordElectronic.getId());
|
||||
FilePlanComponent nonElectronicFiled = recordsAPI.fileRecord(recordBodyFile, recordNonElect.getId());
|
||||
Record recordFiled = recordsAPI.fileRecord(recordBodyFile, recordElectronic.getId());
|
||||
Record nonElectronicFiled = recordsAPI.fileRecord(recordBodyFile, recordNonElect.getId());
|
||||
// check the response status
|
||||
assertStatusCode(CREATED);
|
||||
|
||||
@@ -269,41 +381,43 @@ public class FileRecordsTests extends BaseRMRestTest
|
||||
// check the response status
|
||||
assertStatusCode(CREATED);
|
||||
// link the electronic record
|
||||
FilePlanComponent recordLink = recordsAPI.fileRecord(recordBodyFile, recordElectronic.getId());
|
||||
Record recordLink = recordsAPI.fileRecord(recordBodyFile, recordElectronic.getId());
|
||||
assertTrue(recordLink.getParentId().equals(parentFolderId));
|
||||
// check the response status code
|
||||
assertStatusCode(CREATED);
|
||||
// link the nonelectronic record
|
||||
FilePlanComponent nonElectronicLink = recordsAPI.fileRecord(recordBodyFile, nonElectronicFiled.getId());
|
||||
Record nonElectronicLink = recordsAPI.fileRecord(recordBodyFile, nonElectronicFiled.getId());
|
||||
assertStatusCode(CREATED);
|
||||
assertTrue(nonElectronicLink.getParentId().equals(parentFolderId));
|
||||
|
||||
// check the record is added into the record folder
|
||||
assertTrue(filePlanComponentAPI.listChildComponents(parentFolderId)
|
||||
RecordFolderAPI recordFolderAPI = getRestAPIFactory().getRecordFolderAPI();
|
||||
assertTrue(recordFolderAPI.getRecordFolderChildren(parentFolderId)
|
||||
.getEntries()
|
||||
.stream()
|
||||
.anyMatch(c -> c.getFilePlanComponentModel().getId().equals(recordFiled.getId()) &&
|
||||
c.getFilePlanComponentModel().getParentId().equals(parentFolderId)));
|
||||
|
||||
.anyMatch(c -> c.getEntry().getId().equals(recordFiled.getId()) &&
|
||||
c.getEntry().getParentId().equals(parentFolderId)));
|
||||
|
||||
// check the record doesn't exist into unfiled record container
|
||||
// TODO add a check after the issue will be fixed RM-4578
|
||||
assertTrue(filePlanComponentAPI.listChildComponents(folderToLink)
|
||||
assertTrue(recordFolderAPI.getRecordFolderChildren(folderToLink)
|
||||
.getEntries().stream()
|
||||
.anyMatch(c -> c.getFilePlanComponentModel().getId().equals(recordFiled.getId())));
|
||||
.anyMatch(c -> c.getEntry().getId().equals(recordFiled.getId())));
|
||||
|
||||
// check the record is added into the record folder
|
||||
assertTrue(filePlanComponentAPI.listChildComponents(parentFolderId)
|
||||
.getEntries().stream()
|
||||
.anyMatch(c -> c.getFilePlanComponentModel().getId().equals(nonElectronicFiled.getId()) &&
|
||||
c.getFilePlanComponentModel().getParentId().equals(parentFolderId)));
|
||||
|
||||
assertTrue(recordFolderAPI.getRecordFolderChildren(parentFolderId)
|
||||
.getEntries()
|
||||
.stream()
|
||||
.anyMatch(c -> c.getEntry().getId().equals(nonElectronicFiled.getId()) &&
|
||||
c.getEntry().getParentId().equals(parentFolderId)));
|
||||
|
||||
// check the record doesn't exist into unfiled record container
|
||||
// TODO add a check after the issue will be fixed RM-4578
|
||||
assertTrue(filePlanComponentAPI.listChildComponents(folderToLink)
|
||||
assertTrue(recordFolderAPI.getRecordFolderChildren(folderToLink)
|
||||
.getEntries().stream()
|
||||
.anyMatch(c -> c.getFilePlanComponentModel().getId().equals(nonElectronicFiled.getId())));
|
||||
.anyMatch(c -> c.getEntry().getId().equals(nonElectronicFiled.getId())));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Given an unfiled or filed record
|
||||
* And a container that is NOT a record folder
|
||||
@@ -313,17 +427,18 @@ public class FileRecordsTests extends BaseRMRestTest
|
||||
@Test
|
||||
(
|
||||
dataProvider = "invalidContainersForFile",
|
||||
description = "File the unfiled record to the container that is not a record foldr"
|
||||
description = "File the unfiled record to the container that is not a record folder"
|
||||
)
|
||||
public void invalidContainerToFile(String containerId) throws Exception
|
||||
{
|
||||
// get API instances
|
||||
FilePlanComponentAPI filePlanComponentAPI = getRestAPIFactory().getFilePlanComponentsAPI();
|
||||
RecordsAPI recordsAPI = getRestAPIFactory().getRecordsAPI();
|
||||
|
||||
|
||||
// create records
|
||||
FilePlanComponent recordElectronic = filePlanComponentAPI.createElectronicRecord(electronicRecord, createTempFile(ELECTRONIC_RECORD_NAME, ELECTRONIC_RECORD_NAME), UNFILED_RECORDS_CONTAINER_ALIAS);
|
||||
FilePlanComponent recordNonElect = filePlanComponentAPI.createFilePlanComponent(nonelectronicRecord, UNFILED_RECORDS_CONTAINER_ALIAS);
|
||||
UnfiledContainerAPI unfiledContainersAPI = getRestAPIFactory().getUnfiledContainersAPI();
|
||||
|
||||
UnfiledContainerChild recordElectronic = unfiledContainersAPI.uploadRecord(electronicRecord, UNFILED_RECORDS_CONTAINER_ALIAS, createTempFile(ELECTRONIC_RECORD_NAME, ELECTRONIC_RECORD_NAME));
|
||||
UnfiledContainerChild recordNonElect = unfiledContainersAPI.createUnfiledContainerChild(nonelectronicRecord, UNFILED_RECORDS_CONTAINER_ALIAS);
|
||||
|
||||
// file the record into the folder created
|
||||
RecordBodyFile recordBodyFile = RecordBodyFile.builder().targetParentId(containerId).build();
|
||||
@@ -334,70 +449,4 @@ public class FileRecordsTests extends BaseRMRestTest
|
||||
// check the response status
|
||||
assertStatusCode(BAD_REQUEST);
|
||||
}
|
||||
|
||||
/**
|
||||
* Given an unfiled record in the root unfiled record container or a unfiled record folder
|
||||
* When I file the unfiled record into the record folder using the relativePath
|
||||
* Then the filePlan structure from relativePath is created and the record is filed into the specified path
|
||||
*/
|
||||
@Test
|
||||
(
|
||||
dataProvider = "unfiledContainer",
|
||||
description = "File record from unfiled containers "
|
||||
)
|
||||
public void fileRecordIntoRelativePath(String unfiledContainerId) throws Exception
|
||||
{
|
||||
// get API instances
|
||||
FilePlanComponentAPI filePlanComponentAPI = getRestAPIFactory().getFilePlanComponentsAPI();
|
||||
RecordsAPI recordsAPI = getRestAPIFactory().getRecordsAPI();
|
||||
|
||||
// create a record folder
|
||||
String RELATIVE_PATH = "CATEGORY" + getRandomAlphanumeric() + "/FOLDER";
|
||||
|
||||
// create records
|
||||
FilePlanComponent recordElectronic = filePlanComponentAPI.createElectronicRecord(electronicRecord, createTempFile(ELECTRONIC_RECORD_NAME, ELECTRONIC_RECORD_NAME), unfiledContainerId);
|
||||
FilePlanComponent recordNonElectId = filePlanComponentAPI.createFilePlanComponent(nonelectronicRecord, unfiledContainerId);
|
||||
|
||||
// file the record into the folder created
|
||||
RecordBodyFile recordBodyFile = RecordBodyFile.builder().relativePath(RELATIVE_PATH).build();
|
||||
FilePlanComponent recordFiled = recordsAPI.fileRecord(recordBodyFile, recordElectronic.getId());
|
||||
|
||||
// check the response status
|
||||
assertStatusCode(CREATED);
|
||||
|
||||
// get the folder ID created
|
||||
String folderId = filePlanComponentAPI.getFilePlanComponent(FILE_PLAN_ALIAS, "relativePath="+RELATIVE_PATH).getId();
|
||||
// check the parent id for the record returned
|
||||
assertEquals(recordFiled.getParentId(), folderId);
|
||||
// check the record is filed into the record folder
|
||||
assertTrue(filePlanComponentAPI.listChildComponents(folderId)
|
||||
.getEntries()
|
||||
.stream()
|
||||
.anyMatch(c -> c.getFilePlanComponentModel().getId().equals(recordElectronic.getId())));
|
||||
|
||||
// check the record doesn't exist into unfiled record container
|
||||
assertFalse(filePlanComponentAPI.listChildComponents(unfiledContainerId)
|
||||
.getEntries()
|
||||
.stream()
|
||||
.anyMatch(c -> c.getFilePlanComponentModel().getId().equals(recordElectronic.getId())));
|
||||
|
||||
// file the non-electronic record into the folder created
|
||||
FilePlanComponent nonElectRecordFiled = recordsAPI.fileRecord(recordBodyFile, recordNonElectId.getId());
|
||||
// check the response status code
|
||||
assertStatusCode(CREATED);
|
||||
// check the parent id for the record returned
|
||||
assertEquals(nonElectRecordFiled.getParentId(), folderId);
|
||||
|
||||
// check the record is added into the record folder
|
||||
assertTrue(filePlanComponentAPI.listChildComponents(folderId)
|
||||
.getEntries()
|
||||
.stream()
|
||||
.anyMatch(c -> c.getFilePlanComponentModel().getId().equals(recordNonElectId.getId())));
|
||||
|
||||
// check the record doesn't exist into unfiled record container
|
||||
assertFalse(filePlanComponentAPI.listChildComponents(unfiledContainerId)
|
||||
.getEntries()
|
||||
.stream()
|
||||
.anyMatch(c -> c.getFilePlanComponentModel().getId().equals(recordNonElectId.getId())));
|
||||
}
|
||||
}
|
||||
|
@@ -26,32 +26,37 @@
|
||||
*/
|
||||
package org.alfresco.rest.rm.community.fileplancomponents;
|
||||
|
||||
import static java.lang.Integer.MAX_VALUE;
|
||||
import static java.util.Arrays.asList;
|
||||
|
||||
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentAlias.FILE_PLAN_ALIAS;
|
||||
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentAlias.HOLDS_ALIAS;
|
||||
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentAlias.TRANSFERS_ALIAS;
|
||||
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.NON_ELECTRONIC_RECORD_TYPE;
|
||||
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.RECORD_CATEGORY_TYPE;
|
||||
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.RECORD_FOLDER_TYPE;
|
||||
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.UNFILED_CONTAINER_TYPE;
|
||||
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.UNFILED_RECORD_FOLDER_TYPE;
|
||||
import static org.alfresco.rest.rm.community.util.PojoUtility.toJson;
|
||||
import static org.alfresco.rest.rm.community.utils.FilePlanComponentsUtil.createNonElectronicRecordModel;
|
||||
import static org.alfresco.rest.rm.community.utils.FilePlanComponentsUtil.createFullNonElectronicUnfiledContainerChildRecordModel;
|
||||
import static org.alfresco.rest.rm.community.utils.FilePlanComponentsUtil.createFullNonElectronicRecordModel;
|
||||
import static org.alfresco.rest.rm.community.utils.FilePlanComponentsUtil.verifyFullNonElectronicRecord;
|
||||
import static org.alfresco.utility.constants.UserRole.SiteManager;
|
||||
import static org.alfresco.utility.data.RandomData.getRandomAlphanumeric;
|
||||
import static org.springframework.http.HttpStatus.BAD_REQUEST;
|
||||
import static org.springframework.http.HttpStatus.CREATED;
|
||||
import static org.springframework.http.HttpStatus.FORBIDDEN;
|
||||
import static org.springframework.http.HttpStatus.UNPROCESSABLE_ENTITY;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertFalse;
|
||||
import static org.testng.Assert.assertTrue;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import org.alfresco.rest.rm.community.base.BaseRMRestTest;
|
||||
import org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponent;
|
||||
import org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentProperties;
|
||||
import org.alfresco.rest.rm.community.requests.igCoreAPI.FilePlanComponentAPI;
|
||||
import org.alfresco.rest.rm.community.model.record.Record;
|
||||
import org.alfresco.rest.rm.community.model.record.RecordProperties;
|
||||
import org.alfresco.rest.rm.community.model.recordcategory.RecordCategoryChild;
|
||||
import org.alfresco.rest.rm.community.model.unfiledcontainer.UnfiledContainerChild;
|
||||
import org.alfresco.rest.rm.community.model.unfiledcontainer.UnfiledContainerChildProperties;
|
||||
import org.alfresco.rest.rm.community.requests.gscore.api.RecordFolderAPI;
|
||||
import org.alfresco.rest.rm.community.requests.gscore.api.RecordsAPI;
|
||||
import org.alfresco.rest.rm.community.requests.gscore.api.UnfiledContainerAPI;
|
||||
import org.alfresco.rest.rm.community.requests.gscore.api.UnfiledRecordFolderAPI;
|
||||
import org.alfresco.utility.constants.UserRole;
|
||||
import org.alfresco.utility.model.SiteModel;
|
||||
import org.alfresco.utility.model.UserModel;
|
||||
@@ -65,45 +70,6 @@ import org.testng.annotations.Test;
|
||||
*/
|
||||
public class NonElectronicRecordTests extends BaseRMRestTest
|
||||
{
|
||||
/**
|
||||
* <pre>
|
||||
* Given a parent container that is NOT a record folder or an unfiled record folder
|
||||
* When I try to create a non-electronic record within the parent container
|
||||
* Then nothing happens
|
||||
* And an error is reported
|
||||
* </pre>
|
||||
* @throws Exception if prerequisites can't be created
|
||||
*/
|
||||
@Test(description = "Non-electronic record can't be created as a child of invalid parent Id")
|
||||
public void cantCreateForInvalidParentIds() throws Exception
|
||||
{
|
||||
// create record category, non-electronic records can't be its children
|
||||
FilePlanComponent recordCategoryModel = FilePlanComponent.builder()
|
||||
.name("Category " + getRandomAlphanumeric())
|
||||
.nodeType(RECORD_CATEGORY_TYPE)
|
||||
.build();
|
||||
|
||||
FilePlanComponentAPI filePlanComponentsAPI = getRestAPIFactory().getFilePlanComponentsAPI();
|
||||
FilePlanComponent recordCategory = filePlanComponentsAPI.createFilePlanComponent(recordCategoryModel, FILE_PLAN_ALIAS);
|
||||
|
||||
// iterate through all invalid parent containers and try to create/file an electronic record
|
||||
asList(FILE_PLAN_ALIAS, TRANSFERS_ALIAS, HOLDS_ALIAS, recordCategory.getId())
|
||||
.stream()
|
||||
.forEach(id ->
|
||||
{
|
||||
try
|
||||
{
|
||||
filePlanComponentsAPI.createFilePlanComponent(createNonElectronicRecordModel(), id);
|
||||
}
|
||||
catch (Exception error)
|
||||
{
|
||||
}
|
||||
|
||||
// Verify the status code
|
||||
assertStatusCode(UNPROCESSABLE_ENTITY);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* Given a parent container that is a record folder
|
||||
@@ -114,6 +80,8 @@ public class NonElectronicRecordTests extends BaseRMRestTest
|
||||
* <pre>
|
||||
* and
|
||||
* <pre>
|
||||
*
|
||||
*
|
||||
* Given a parent container that is an unfiled record folder or the root unfiled record container
|
||||
* When I try to create a non-electronic record within the parent container
|
||||
* Then the non-electronic record is created
|
||||
@@ -126,67 +94,68 @@ public class NonElectronicRecordTests extends BaseRMRestTest
|
||||
dataProvider = "validRootContainers",
|
||||
description = "Non-electronic records can be created in valid containers"
|
||||
)
|
||||
public void canCreateInValidContainers(FilePlanComponent container) throws Exception
|
||||
public void canCreateInValidContainers(String folderId, String type) throws Exception
|
||||
{
|
||||
logger.info("Root container:\n" + toJson(container));
|
||||
logger.info("Root container:\n" + toJson(folderId));
|
||||
|
||||
if (container.getNodeType().equals(RECORD_FOLDER_TYPE))
|
||||
{
|
||||
// only record folders can be open or closed
|
||||
assertFalse(container.getProperties().getIsClosed());
|
||||
}
|
||||
|
||||
// use these properties for non-electronic record to be created
|
||||
// Use these properties for non-electronic record to be created
|
||||
String title = "Title " + getRandomAlphanumeric();
|
||||
String description = "Description " + getRandomAlphanumeric();
|
||||
String box = "Box "+ getRandomAlphanumeric();
|
||||
String file = "File " + getRandomAlphanumeric();
|
||||
String shelf = "Shelf " + getRandomAlphanumeric();
|
||||
String location = "Location " + getRandomAlphanumeric();
|
||||
String storageLocation = "Storage Location " + getRandomAlphanumeric();
|
||||
String name = "Record " + getRandomAlphanumeric();
|
||||
|
||||
Random random = new Random();
|
||||
Integer copies = random.nextInt(Integer.MAX_VALUE);
|
||||
Integer size = random.nextInt(Integer.MAX_VALUE);
|
||||
Integer numberOfCopies = random.nextInt(MAX_VALUE);
|
||||
Integer physicalSize = random.nextInt(MAX_VALUE);
|
||||
|
||||
// set values of all available properties for the non electronic records
|
||||
FilePlanComponent filePlanComponent = FilePlanComponent.builder()
|
||||
.name(name)
|
||||
.nodeType(NON_ELECTRONIC_RECORD_TYPE)
|
||||
.properties(FilePlanComponentProperties.builder()
|
||||
.title(title)
|
||||
.description(description)
|
||||
.box(box)
|
||||
.file(file)
|
||||
.shelf(shelf)
|
||||
.location(location)
|
||||
.numberOfCopies(copies)
|
||||
.physicalSize(size)
|
||||
.build())
|
||||
.build();
|
||||
String nonElectronicId;
|
||||
if (RECORD_FOLDER_TYPE.equalsIgnoreCase(type))
|
||||
{
|
||||
// Only record folders can be opened or closed
|
||||
RecordFolderAPI recordFolderAPI = getRestAPIFactory().getRecordFolderAPI();
|
||||
assertFalse(recordFolderAPI.getRecordFolder(folderId).getProperties().getIsClosed());
|
||||
|
||||
// create non-electronic record
|
||||
FilePlanComponentAPI filePlanComponentsAPI = getRestAPIFactory().getFilePlanComponentsAPI();
|
||||
String nonElectronicId = filePlanComponentsAPI.createFilePlanComponent(
|
||||
filePlanComponent,
|
||||
container.getId()).getId();
|
||||
// Set values of all available properties for the non electronic records
|
||||
Record nonElectrinicRecordModel = createFullNonElectronicRecordModel(name, title, description, box, file, shelf, storageLocation, numberOfCopies, physicalSize);
|
||||
|
||||
// verify the create request status code
|
||||
// Create non-electronic record
|
||||
nonElectronicId = recordFolderAPI.createRecord(nonElectrinicRecordModel, folderId).getId();
|
||||
}
|
||||
else if(UNFILED_CONTAINER_TYPE.equalsIgnoreCase(type))
|
||||
{
|
||||
// Set values of all available properties for the non electronic records
|
||||
UnfiledContainerChild nonElectrinicRecordModel = createFullNonElectronicUnfiledContainerChildRecordModel(name, title, description, box, file, shelf,
|
||||
storageLocation, numberOfCopies, physicalSize);
|
||||
|
||||
// Create non-electronic record
|
||||
UnfiledContainerAPI unfiledContainersAPI = getRestAPIFactory().getUnfiledContainersAPI();
|
||||
nonElectronicId = unfiledContainersAPI.createUnfiledContainerChild(nonElectrinicRecordModel, folderId).getId();
|
||||
}
|
||||
else if(UNFILED_RECORD_FOLDER_TYPE.equalsIgnoreCase(type))
|
||||
{
|
||||
// Set values of all available properties for the non electronic records
|
||||
UnfiledContainerChild nonElectrinicRecordModel = createFullNonElectronicUnfiledContainerChildRecordModel(name, title, description, box, file, shelf,
|
||||
storageLocation, numberOfCopies, physicalSize);
|
||||
|
||||
// Create non-electronic record
|
||||
UnfiledRecordFolderAPI unfiledRecordFoldersAPI = getRestAPIFactory().getUnfiledRecordFoldersAPI();
|
||||
nonElectronicId = unfiledRecordFoldersAPI.createUnfiledRecordFolderChild(nonElectrinicRecordModel, folderId).getId();
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception("Unsuported type = " + type);
|
||||
}
|
||||
|
||||
// Verify the create request status code
|
||||
assertStatusCode(CREATED);
|
||||
|
||||
// get newly created non-electonic record and verify its properties
|
||||
FilePlanComponent nonElectronicRecord = filePlanComponentsAPI.getFilePlanComponent(nonElectronicId);
|
||||
|
||||
assertEquals(title, nonElectronicRecord.getProperties().getTitle());
|
||||
assertEquals(description, nonElectronicRecord.getProperties().getDescription());
|
||||
assertEquals(box, nonElectronicRecord.getProperties().getBox());
|
||||
assertEquals(file, nonElectronicRecord.getProperties().getFile());
|
||||
assertEquals(shelf, nonElectronicRecord.getProperties().getShelf());
|
||||
assertEquals(location, nonElectronicRecord.getProperties().getLocation());
|
||||
assertEquals(copies, nonElectronicRecord.getProperties().getNumberOfCopies());
|
||||
assertEquals(size, nonElectronicRecord.getProperties().getPhysicalSize());
|
||||
assertTrue(nonElectronicRecord.getName().contains(nonElectronicRecord.getProperties().getRmIdentifier()));
|
||||
assertTrue(nonElectronicRecord.getName().contains(name));
|
||||
// Get newly created non-electronic record and verify its properties
|
||||
RecordsAPI recordsAPI = getRestAPIFactory().getRecordsAPI();
|
||||
Record nonElectronicRecord = recordsAPI.getRecord(nonElectronicId);
|
||||
verifyFullNonElectronicRecord(nonElectronicRecord, name, title, description, box, file, shelf, storageLocation, numberOfCopies, physicalSize);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -197,23 +166,23 @@ public class NonElectronicRecordTests extends BaseRMRestTest
|
||||
* Then nothing happens
|
||||
* And an error is reported
|
||||
* </pre>
|
||||
* @throws Exception if prerequisites can't be created
|
||||
* @throws Exception if record can't be created
|
||||
*/
|
||||
@Test(description = "Non-electronic record can't be created in closed record folder")
|
||||
public void cantCreateInClosedFolder() throws Exception
|
||||
{
|
||||
FilePlanComponent recordFolder = createCategoryFolderInFilePlan();
|
||||
RecordCategoryChild recordFolder = createCategoryFolderInFilePlan();
|
||||
|
||||
// the folder should be open
|
||||
// The folder should be open
|
||||
assertFalse(recordFolder.getProperties().getIsClosed());
|
||||
|
||||
// close the folder
|
||||
// Close the folder
|
||||
closeFolder(recordFolder.getId());
|
||||
|
||||
// try to create it, this should fail and throw an exception
|
||||
getRestAPIFactory().getFilePlanComponentsAPI().createFilePlanComponent(createNonElectronicRecordModel(), recordFolder.getId());
|
||||
// Try to create it, this should fail and throw an exception
|
||||
getRestAPIFactory().getRecordFolderAPI().createRecord(createNonElectronicRecordModel(), recordFolder.getId());
|
||||
|
||||
// verify the status code
|
||||
// Verify the status code
|
||||
assertStatusCode(UNPROCESSABLE_ENTITY);
|
||||
}
|
||||
|
||||
@@ -228,61 +197,139 @@ public class NonElectronicRecordTests extends BaseRMRestTest
|
||||
* </pre>
|
||||
* and
|
||||
* <pre>
|
||||
*
|
||||
* Given a parent container that is an unfiled record folder or the root unfiled record container
|
||||
* When I try to create a non-electronic record within the parent container
|
||||
* And I do not provide all the required mandatory property values
|
||||
* Then nothing happens
|
||||
* And an error is reported
|
||||
* </pre>
|
||||
* @throws Exception if prerequisites can't be created
|
||||
* @throws Exception if record can't be created
|
||||
*/
|
||||
@Test
|
||||
(
|
||||
dataProvider = "validRootContainers",
|
||||
description = "Non-electronic record can only be created if all mandatory properties are given"
|
||||
)
|
||||
public void allMandatoryPropertiesRequired(FilePlanComponent container) throws Exception
|
||||
public void allMandatoryPropertiesRequired(String folderId, String type) throws Exception
|
||||
{
|
||||
logger.info("Root container:\n" + toJson(container));
|
||||
if (container.getNodeType().equals(RECORD_FOLDER_TYPE))
|
||||
logger.info("Root container:\n" + toJson(folderId));
|
||||
|
||||
if (type.equals(RECORD_FOLDER_TYPE))
|
||||
{
|
||||
// only record folders can be open or closed
|
||||
assertFalse(container.getProperties().getIsClosed());
|
||||
// Only record folders can be opened or closed
|
||||
RecordFolderAPI recordFolderAPI = getRestAPIFactory().getRecordFolderAPI();
|
||||
assertFalse(recordFolderAPI.getRecordFolder(folderId).getProperties().getIsClosed());
|
||||
// Component without name and title
|
||||
Record noNameOrTitle = Record.builder().nodeType(NON_ELECTRONIC_RECORD_TYPE).build();
|
||||
|
||||
// Component with title only
|
||||
Record titleOnly = Record.builder()
|
||||
.nodeType(NON_ELECTRONIC_RECORD_TYPE)
|
||||
.properties(RecordProperties.builder()
|
||||
.title("Title " + getRandomAlphanumeric())
|
||||
.build())
|
||||
.build();
|
||||
|
||||
// Try to create invalid components
|
||||
asList(noNameOrTitle, titleOnly).stream().forEach(c ->
|
||||
{
|
||||
try
|
||||
{
|
||||
logger.info("Creating non-electronic record with body:\n" + toJson(c));
|
||||
}
|
||||
catch (Exception error)
|
||||
{
|
||||
}
|
||||
|
||||
// This should fail and throw an exception
|
||||
try
|
||||
{
|
||||
getRestAPIFactory().getRecordFolderAPI().createRecord(c, folderId);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
}
|
||||
|
||||
// Verify the status code is BAD_REQUEST
|
||||
assertStatusCode(BAD_REQUEST);
|
||||
});
|
||||
}
|
||||
|
||||
// component without name and title
|
||||
FilePlanComponent noNameOrTitle = getDummyNonElectronicRecord();
|
||||
|
||||
// component with title only
|
||||
FilePlanComponent titleOnly = getDummyNonElectronicRecord();
|
||||
FilePlanComponentProperties properties = FilePlanComponentProperties.builder()
|
||||
.title("Title " + getRandomAlphanumeric())
|
||||
.build();
|
||||
titleOnly.setProperties(properties);
|
||||
|
||||
// try to create invalid components
|
||||
asList(noNameOrTitle, titleOnly).stream().forEach(c ->
|
||||
else if(UNFILED_CONTAINER_TYPE.equalsIgnoreCase(type))
|
||||
{
|
||||
try
|
||||
{
|
||||
logger.info("Creating non-electronic record with body:\n" + toJson(c));
|
||||
}
|
||||
catch (Exception error)
|
||||
{
|
||||
}
|
||||
// Component without name and title
|
||||
UnfiledContainerChild noNameOrTitle = UnfiledContainerChild.builder().nodeType(NON_ELECTRONIC_RECORD_TYPE).build();
|
||||
|
||||
// this should fail and throw an exception
|
||||
try
|
||||
{
|
||||
getRestAPIFactory().getFilePlanComponentsAPI().createFilePlanComponent(c, container.getId());
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
}
|
||||
// Component with title only
|
||||
UnfiledContainerChild titleOnly = UnfiledContainerChild.builder()
|
||||
.nodeType(NON_ELECTRONIC_RECORD_TYPE)
|
||||
.properties(UnfiledContainerChildProperties.builder()
|
||||
.title("Title " + getRandomAlphanumeric())
|
||||
.build())
|
||||
.build();
|
||||
|
||||
// verify the status code is BAD_REQUEST
|
||||
assertStatusCode(BAD_REQUEST);
|
||||
});
|
||||
// Try to create invalid components
|
||||
asList(noNameOrTitle, titleOnly).stream().forEach(c ->
|
||||
{
|
||||
try
|
||||
{
|
||||
logger.info("Creating non-electronic record with body:\n" + toJson(c));
|
||||
}
|
||||
catch (Exception error)
|
||||
{
|
||||
}
|
||||
|
||||
// This should fail and throw an exception
|
||||
try
|
||||
{
|
||||
getRestAPIFactory().getUnfiledContainersAPI().createUnfiledContainerChild(c, folderId);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
}
|
||||
|
||||
// Verify the status code is BAD_REQUEST
|
||||
assertStatusCode(BAD_REQUEST);
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
//we have unfiled record folder type
|
||||
// Component without name and title
|
||||
UnfiledContainerChild noNameOrTitle = UnfiledContainerChild.builder().nodeType(NON_ELECTRONIC_RECORD_TYPE).build();
|
||||
|
||||
// Component with title only
|
||||
UnfiledContainerChild titleOnly = UnfiledContainerChild.builder()
|
||||
.nodeType(NON_ELECTRONIC_RECORD_TYPE)
|
||||
.properties(UnfiledContainerChildProperties.builder()
|
||||
.title("Title " + getRandomAlphanumeric())
|
||||
.build())
|
||||
.build();
|
||||
|
||||
// Try to create invalid components
|
||||
asList(noNameOrTitle, titleOnly).stream().forEach(c ->
|
||||
{
|
||||
try
|
||||
{
|
||||
logger.info("Creating non-electronic record with body:\n" + toJson(c));
|
||||
}
|
||||
catch (Exception error)
|
||||
{
|
||||
}
|
||||
|
||||
// This should fail and throw an exception
|
||||
try
|
||||
{
|
||||
getRestAPIFactory().getUnfiledRecordFoldersAPI().createUnfiledRecordFolderChild(c, folderId);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
}
|
||||
|
||||
// Verify the status code is BAD_REQUEST
|
||||
assertStatusCode(BAD_REQUEST);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -292,62 +339,93 @@ public class NonElectronicRecordTests extends BaseRMRestTest
|
||||
* Then nothing happens
|
||||
* And an error is reported
|
||||
* </pre>
|
||||
* @throws Exception
|
||||
* @throws Exception if record can't be created
|
||||
*/
|
||||
@Test
|
||||
(
|
||||
dataProvider = "validRootContainers",
|
||||
description = "Non-electronic record can't be created if user doesn't have RM privileges"
|
||||
)
|
||||
public void cantCreateIfNoRmPrivileges(FilePlanComponent container) throws Exception
|
||||
public void cantCreateIfNoRmPrivileges(String folderId, String type) throws Exception
|
||||
{
|
||||
UserModel user = createUserWithRole("zzzuser", SiteManager);
|
||||
|
||||
// try to create a fileplan component
|
||||
FilePlanComponent record = FilePlanComponent.builder()
|
||||
.properties(FilePlanComponentProperties.builder()
|
||||
.description("Description")
|
||||
.title("Title")
|
||||
.build())
|
||||
.name("Record Name")
|
||||
.nodeType(NON_ELECTRONIC_RECORD_TYPE)
|
||||
.build();
|
||||
|
||||
|
||||
// this should fail and throw an exception
|
||||
try
|
||||
if (type.equals(RECORD_FOLDER_TYPE))
|
||||
{
|
||||
getRestAPIFactory().getFilePlanComponentsAPI(user).createFilePlanComponent(record, container.getId());
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
}
|
||||
// Try to create a record model
|
||||
Record recordModel = Record.builder()
|
||||
.properties(RecordProperties.builder()
|
||||
.description("Description")
|
||||
.title("Title")
|
||||
.build())
|
||||
.name("Record Name")
|
||||
.nodeType(NON_ELECTRONIC_RECORD_TYPE)
|
||||
.build();
|
||||
|
||||
// user who isn't an RM site member can't access the container path
|
||||
// This should fail and throw an exception
|
||||
try
|
||||
{
|
||||
getRestAPIFactory().getRecordFolderAPI(user).createRecord(recordModel, folderId);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
}
|
||||
}
|
||||
else if(UNFILED_CONTAINER_TYPE.equalsIgnoreCase(type))
|
||||
{
|
||||
// Try to create a record model
|
||||
UnfiledContainerChild recordModel = UnfiledContainerChild.builder()
|
||||
.properties(UnfiledContainerChildProperties.builder()
|
||||
.description("Description")
|
||||
.title("Title")
|
||||
.build())
|
||||
.name("Record Name")
|
||||
.nodeType(NON_ELECTRONIC_RECORD_TYPE)
|
||||
.build();
|
||||
|
||||
// This should fail and throw an exception
|
||||
try
|
||||
{
|
||||
getRestAPIFactory().getUnfiledContainersAPI(user).createUnfiledContainerChild(recordModel, folderId);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Try to create a record model
|
||||
UnfiledContainerChild recordModel = UnfiledContainerChild.builder()
|
||||
.properties(UnfiledContainerChildProperties.builder()
|
||||
.description("Description")
|
||||
.title("Title")
|
||||
.build())
|
||||
.name("Record Name")
|
||||
.nodeType(NON_ELECTRONIC_RECORD_TYPE)
|
||||
.build();
|
||||
|
||||
// This should fail and throw an exception
|
||||
try
|
||||
{
|
||||
getRestAPIFactory().getUnfiledRecordFoldersAPI(user).createUnfiledRecordFolderChild(recordModel, folderId);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
}
|
||||
}
|
||||
// User who isn't an RM site member can't access the container path
|
||||
assertStatusCode(FORBIDDEN);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function to return an empty FilePlanComponent for non-electronic record
|
||||
* @return
|
||||
*/
|
||||
private FilePlanComponent getDummyNonElectronicRecord()
|
||||
{
|
||||
FilePlanComponent component = FilePlanComponent.builder()
|
||||
.nodeType(NON_ELECTRONIC_RECORD_TYPE)
|
||||
.build();
|
||||
return component;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create user with given role and add it to RM site
|
||||
* <br>
|
||||
* Checks whether the user exists in RM site and creates it if required, with password identical
|
||||
* to username. Note the role is a Core API role, not an RM role.
|
||||
* to user name. Note the role is a Core API role, not an RM role.
|
||||
* <br>
|
||||
* For already existing users, no site membership or role verification is performed.
|
||||
* <p>
|
||||
* @param userName username to add
|
||||
* @param userName user name to add
|
||||
* @param userRole user's role
|
||||
* @throws Exception
|
||||
*/
|
||||
@@ -355,17 +433,15 @@ public class NonElectronicRecordTests extends BaseRMRestTest
|
||||
{
|
||||
String siteId = getRestAPIFactory().getRMSiteAPI().getSite().getId();
|
||||
|
||||
// check if user exists
|
||||
// Check if user exists
|
||||
UserModel user = new UserModel();
|
||||
user.setUsername(userName);
|
||||
user.setPassword(userName);
|
||||
|
||||
if (!getDataUser().isUserInRepo(userName))
|
||||
{
|
||||
// user doesn't exist, create it
|
||||
// User doesn't exist, create it
|
||||
user = getDataUser().createUser(userName, userName);
|
||||
user.setUserRole(userRole);
|
||||
|
||||
getDataUser().addUserToSite(user, new SiteModel(siteId), userRole);
|
||||
}
|
||||
|
||||
|
@@ -26,17 +26,23 @@
|
||||
*/
|
||||
package org.alfresco.rest.rm.community.fileplancomponents;
|
||||
|
||||
import static org.alfresco.rest.rm.community.base.TestData.FOLDER_NAME;
|
||||
import static org.alfresco.rest.rm.community.base.TestData.RECORD_CATEGORY_NAME;
|
||||
import static org.alfresco.rest.rm.community.base.TestData.RECORD_CATEGORY_TITLE;
|
||||
import static org.alfresco.rest.rm.community.base.TestData.RECORD_FOLDER_NAME;
|
||||
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentAlias.FILE_PLAN_ALIAS;
|
||||
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentAlias.HOLDS_ALIAS;
|
||||
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentAlias.TRANSFERS_ALIAS;
|
||||
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentAlias.UNFILED_RECORDS_CONTAINER_ALIAS;
|
||||
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentFields.IS_COMPLETED;
|
||||
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentFields.CONTENT;
|
||||
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentFields.PATH;
|
||||
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.CONTENT_TYPE;
|
||||
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.NON_ELECTRONIC_RECORD_TYPE;
|
||||
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.UNFILED_RECORD_FOLDER_TYPE;
|
||||
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.RECORD_FOLDER_TYPE;
|
||||
import static org.alfresco.rest.rm.community.utils.FilePlanComponentsUtil.IMAGE_FILE;
|
||||
import static org.alfresco.rest.rm.community.utils.FilePlanComponentsUtil.createRecordCategoryModel;
|
||||
import static org.alfresco.rest.rm.community.utils.FilePlanComponentsUtil.createTempFile;
|
||||
import static org.alfresco.rest.rm.community.utils.FilePlanComponentsUtil.getFile;
|
||||
import static org.alfresco.utility.data.RandomData.getRandomAlphanumeric;
|
||||
import static org.springframework.http.HttpStatus.BAD_REQUEST;
|
||||
import static org.springframework.http.HttpStatus.OK;
|
||||
@@ -46,55 +52,56 @@ import static org.testng.Assert.assertNotNull;
|
||||
import static org.testng.Assert.fail;
|
||||
import static org.testng.AssertJUnit.assertTrue;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.NoSuchElementException;
|
||||
|
||||
import com.google.common.io.Resources;
|
||||
|
||||
import org.alfresco.rest.rm.community.base.BaseRMRestTest;
|
||||
import org.alfresco.rest.rm.community.base.TestData;
|
||||
import org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponent;
|
||||
import org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentContent;
|
||||
import org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentProperties;
|
||||
import org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentsCollection;
|
||||
import org.alfresco.rest.rm.community.requests.igCoreAPI.FilePlanComponentAPI;
|
||||
import org.alfresco.rest.rm.community.requests.igCoreAPI.RecordsAPI;
|
||||
import org.alfresco.rest.rm.community.model.record.Record;
|
||||
import org.alfresco.rest.rm.community.model.record.RecordContent;
|
||||
import org.alfresco.rest.rm.community.model.record.RecordProperties;
|
||||
import org.alfresco.rest.rm.community.model.recordcategory.RecordCategory;
|
||||
import org.alfresco.rest.rm.community.model.recordcategory.RecordCategoryChild;
|
||||
import org.alfresco.rest.rm.community.model.recordfolder.RecordFolderCollection;
|
||||
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.UnfiledContainerChildProperties;
|
||||
import org.alfresco.rest.rm.community.requests.gscore.api.RecordCategoryAPI;
|
||||
import org.alfresco.rest.rm.community.requests.gscore.api.RecordFolderAPI;
|
||||
import org.alfresco.rest.rm.community.requests.gscore.api.RecordsAPI;
|
||||
import org.alfresco.rest.rm.community.requests.gscore.api.UnfiledRecordFolderAPI;
|
||||
import org.apache.commons.codec.digest.DigestUtils;
|
||||
import org.testng.annotations.DataProvider;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
/**
|
||||
* This class contains the tests for
|
||||
* Read Records API
|
||||
* This class contains the tests for Read Records API
|
||||
*
|
||||
* @author Rodica Sutu
|
||||
* @since 2.6
|
||||
*/
|
||||
public class ReadRecordTests extends BaseRMRestTest
|
||||
{
|
||||
String CATEGORY_NAME=TestData.CATEGORY_NAME +getRandomAlphanumeric();
|
||||
public static final String CATEGORY_NAME = TestData.RECORD_CATEGORY_NAME + getRandomAlphanumeric();
|
||||
|
||||
String ELECTRONIC_RECORD_NAME = "Record electronic" + getRandomAlphanumeric();
|
||||
String NONELECTRONIC_RECORD_NAME = "Record nonelectronic" + getRandomAlphanumeric();
|
||||
public static final String ELECTRONIC_RECORD_NAME = "Record electronic" + getRandomAlphanumeric();
|
||||
public static final String NONELECTRONIC_RECORD_NAME = "Record nonelectronic" + getRandomAlphanumeric();
|
||||
|
||||
private FilePlanComponent electronicRecord = FilePlanComponent.builder()
|
||||
.name(ELECTRONIC_RECORD_NAME)
|
||||
.nodeType(CONTENT_TYPE.toString())
|
||||
.content(FilePlanComponentContent.builder().mimeType("text/plain").build())
|
||||
.build();
|
||||
|
||||
private FilePlanComponent nonelectronicRecord = FilePlanComponent.builder()
|
||||
.properties(FilePlanComponentProperties.builder()
|
||||
.description(NONELECTRONIC_RECORD_NAME)
|
||||
.title("Title")
|
||||
.build())
|
||||
.name(NONELECTRONIC_RECORD_NAME)
|
||||
.nodeType(NON_ELECTRONIC_RECORD_TYPE.toString())
|
||||
.build();
|
||||
private Record electronicRecord = Record.builder()
|
||||
.name(ELECTRONIC_RECORD_NAME)
|
||||
.nodeType(CONTENT_TYPE)
|
||||
.build();
|
||||
|
||||
private Record nonelectronicRecord = Record.builder()
|
||||
.properties(RecordProperties.builder()
|
||||
.description(NONELECTRONIC_RECORD_NAME)
|
||||
.title("Title")
|
||||
.build())
|
||||
.name(NONELECTRONIC_RECORD_NAME)
|
||||
.nodeType(NON_ELECTRONIC_RECORD_TYPE)
|
||||
.build();
|
||||
|
||||
/**
|
||||
* Given a record category or a container which can't contain records
|
||||
@@ -102,12 +109,11 @@ public class ReadRecordTests extends BaseRMRestTest
|
||||
* Then I receive an empty list
|
||||
*/
|
||||
@DataProvider(name="invalidContainersForRecords")
|
||||
public Object[][] getInvalidContainersForRecords() throws Exception
|
||||
public String[][] getInvalidContainersForRecords() throws Exception
|
||||
{
|
||||
return new Object[][] {
|
||||
return new String[][] {
|
||||
{ FILE_PLAN_ALIAS },
|
||||
{ TRANSFERS_ALIAS },
|
||||
{ HOLDS_ALIAS },
|
||||
{ createCategoryFolderInFilePlan().getParentId()}
|
||||
};
|
||||
}
|
||||
@@ -118,31 +124,54 @@ public class ReadRecordTests extends BaseRMRestTest
|
||||
)
|
||||
public void readRecordsFromInvalidContainers(String container) throws Exception
|
||||
{
|
||||
FilePlanComponentAPI filePlanComponentAPI = getRestAPIFactory().getFilePlanComponentsAPI();
|
||||
FilePlanComponent electronicRecord = FilePlanComponent.builder()
|
||||
.name(ELECTRONIC_RECORD_NAME)
|
||||
.nodeType(CONTENT_TYPE)
|
||||
.content(FilePlanComponentContent.builder().mimeType("text/plain").build())
|
||||
.build();
|
||||
FilePlanComponent nonelectronicRecord = FilePlanComponent.builder()
|
||||
.properties(FilePlanComponentProperties.builder()
|
||||
.description("Description")
|
||||
.title("Title")
|
||||
.build())
|
||||
.name(NONELECTRONIC_RECORD_NAME)
|
||||
.nodeType(NON_ELECTRONIC_RECORD_TYPE)
|
||||
.build();
|
||||
Record electronicRecord = Record.builder()
|
||||
.name(ELECTRONIC_RECORD_NAME)
|
||||
.nodeType(CONTENT_TYPE)
|
||||
.content(RecordContent.builder().mimeType("text/plain").build())
|
||||
.build();
|
||||
Record nonelectronicRecord = Record.builder()
|
||||
.properties(RecordProperties.builder()
|
||||
.description("Description")
|
||||
.title("Title")
|
||||
.build())
|
||||
.name(NONELECTRONIC_RECORD_NAME)
|
||||
.nodeType(NON_ELECTRONIC_RECORD_TYPE)
|
||||
.build();
|
||||
//create records
|
||||
filePlanComponentAPI.createFilePlanComponent(electronicRecord, container);
|
||||
filePlanComponentAPI.createFilePlanComponent(nonelectronicRecord, container);
|
||||
RecordFolderAPI recordFolderAPI = getRestAPIFactory().getRecordFolderAPI();
|
||||
recordFolderAPI.createRecord(electronicRecord, container);
|
||||
assertStatusCode(BAD_REQUEST);
|
||||
recordFolderAPI.createRecord(nonelectronicRecord, container);
|
||||
assertStatusCode(BAD_REQUEST);
|
||||
|
||||
|
||||
// List children from API
|
||||
filePlanComponentAPI.listChildComponents(container, "where=(isFile=true)")
|
||||
.assertThat()//check the list returned is empty
|
||||
.entriesListIsEmpty().assertThat().paginationExist();
|
||||
//check response status code
|
||||
assertStatusCode(OK);
|
||||
if(FILE_PLAN_ALIAS.equals(container))
|
||||
{
|
||||
getRestAPIFactory().getFilePlansAPI().getRootRecordCategories(container, "")
|
||||
.assertThat()//check the list returned is not empty
|
||||
.entriesListIsNotEmpty().assertThat().paginationExist();
|
||||
//check response status code
|
||||
assertStatusCode(OK);
|
||||
}
|
||||
else if(TRANSFERS_ALIAS.equals(container))
|
||||
{
|
||||
getRestAPIFactory().getTransferContainerAPI().getTransfers(container, "where=(isFile=true)")
|
||||
.assertThat()//check the list returned is empty
|
||||
.entriesListIsEmpty().assertThat().paginationExist();
|
||||
//check response status code
|
||||
assertStatusCode(OK);
|
||||
}
|
||||
else
|
||||
{
|
||||
String recordCategoryId = getRestAPIFactory().getRecordCategoryAPI().getRecordCategory(container).getId();
|
||||
assertStatusCode(OK);
|
||||
getRestAPIFactory().getRecordCategoryAPI().getRecordCategoryChildren(recordCategoryId)
|
||||
.assertThat()//check the list returned is empty
|
||||
.entriesListCountIs(1).assertThat().paginationExist();
|
||||
String nodeType = getRestAPIFactory().getRecordCategoryAPI().getRecordCategoryChildren(recordCategoryId).getEntries().get(0).getEntry().getNodeType();
|
||||
assertEquals(nodeType, RECORD_FOLDER_TYPE);
|
||||
//check response status code
|
||||
assertStatusCode(OK);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -155,51 +184,49 @@ public class ReadRecordTests extends BaseRMRestTest
|
||||
public void readRecordMetadata() throws Exception
|
||||
{
|
||||
String RELATIVE_PATH = "/" + CATEGORY_NAME + getRandomAlphanumeric() + "/folder";
|
||||
FilePlanComponentAPI filePlanComponentAPI = getRestAPIFactory().getFilePlanComponentsAPI();
|
||||
//create the containers from the relativePath
|
||||
FilePlanComponent recordFolder = FilePlanComponent.builder()
|
||||
.name(FOLDER_NAME)
|
||||
.nodeType(RECORD_FOLDER_TYPE)
|
||||
.relativePath(RELATIVE_PATH)
|
||||
.build();
|
||||
String folderId = filePlanComponentAPI.createFilePlanComponent(recordFolder, FILE_PLAN_ALIAS).getId();
|
||||
//create electronic record
|
||||
|
||||
String recordWithContentId = filePlanComponentAPI.createElectronicRecord(electronicRecord, createTempFile(ELECTRONIC_RECORD_NAME, ELECTRONIC_RECORD_NAME), folderId).getId();
|
||||
RecordCategory recordCategoryModel = createRecordCategoryModel(RECORD_CATEGORY_NAME, RECORD_CATEGORY_TITLE);
|
||||
String recordCategoryId = getRestAPIFactory().getFilePlansAPI().createRootRecordCategory(recordCategoryModel, FILE_PLAN_ALIAS).getId();
|
||||
|
||||
//create the containers from the relativePath
|
||||
RecordCategoryChild recordFolderModel = RecordCategoryChild.builder()
|
||||
.name(RECORD_FOLDER_NAME)
|
||||
.nodeType(RECORD_FOLDER_TYPE)
|
||||
.relativePath(RELATIVE_PATH)
|
||||
.build();
|
||||
|
||||
String recordFolderId = getRestAPIFactory().getRecordCategoryAPI().createRecordCategoryChild(recordFolderModel, recordCategoryId, "include=" + PATH).getId();
|
||||
|
||||
//create electronic record
|
||||
String recordWithContentId = getRestAPIFactory().getRecordFolderAPI().createRecord(electronicRecord, recordFolderId, getFile(IMAGE_FILE)).getId();
|
||||
|
||||
//Get the record created
|
||||
FilePlanComponent recordWithContent= filePlanComponentAPI.getFilePlanComponent(recordWithContentId, "include = "+IS_COMPLETED);
|
||||
Record recordWithContent= getRestAPIFactory().getRecordsAPI().getRecord(recordWithContentId, "include="+IS_COMPLETED +"," + CONTENT);
|
||||
|
||||
//Check the metadata returned
|
||||
assertTrue(recordWithContent.getName().startsWith(ELECTRONIC_RECORD_NAME));
|
||||
assertTrue(recordWithContent.getIsFile());
|
||||
assertFalse(recordWithContent.getIsCategory());
|
||||
assertFalse(recordWithContent.getIsRecordFolder());
|
||||
assertNotNull(recordWithContent.getContent().getEncoding());
|
||||
assertEquals(recordWithContent.getNodeType(),CONTENT_TYPE);
|
||||
assertNotNull(recordWithContent.getContent().getEncoding());
|
||||
assertNotNull(recordWithContent.getContent().getMimeType());
|
||||
assertNotNull(recordWithContent.getAspectNames());
|
||||
assertFalse(recordWithContent.getName().equals(ELECTRONIC_RECORD_NAME));
|
||||
assertTrue(recordWithContent.getName().contains(recordWithContent.getProperties().getRmIdentifier()));
|
||||
assertTrue(recordWithContent.getName().contains(recordWithContent.getProperties().getIdentifier()));
|
||||
assertStatusCode(OK);
|
||||
|
||||
//create non-electronic record
|
||||
String nonElectronicRecordId = filePlanComponentAPI.createFilePlanComponent(nonelectronicRecord, folderId).getId();
|
||||
String nonElectronicRecordId = getRestAPIFactory().getRecordFolderAPI().createRecord(nonelectronicRecord, recordFolderId).getId();
|
||||
//Get the record created
|
||||
FilePlanComponent nonElectronicRecord = filePlanComponentAPI.getFilePlanComponent(nonElectronicRecordId, "include = " + IS_COMPLETED);
|
||||
Record nonElectronicRecord = getRestAPIFactory().getRecordsAPI().getRecord(nonElectronicRecordId, "include=" + IS_COMPLETED +"," + CONTENT);
|
||||
|
||||
//Check the metadata returned
|
||||
assertTrue(nonElectronicRecord.getName().startsWith(NONELECTRONIC_RECORD_NAME));
|
||||
assertTrue(nonElectronicRecord.getIsFile());
|
||||
assertFalse(nonElectronicRecord.getIsCategory());
|
||||
assertFalse(nonElectronicRecord.getIsRecordFolder());
|
||||
assertNotNull(nonElectronicRecord.getContent().getEncoding());
|
||||
assertEquals(nonElectronicRecord.getContent(), null);
|
||||
assertEquals(nonElectronicRecord.getNodeType(), NON_ELECTRONIC_RECORD_TYPE);
|
||||
assertNotNull(nonElectronicRecord.getContent().getEncoding());
|
||||
assertNotNull(nonElectronicRecord.getContent().getMimeType());
|
||||
assertNotNull(nonElectronicRecord.getAspectNames());
|
||||
assertEquals(nonElectronicRecord.getProperties().getDescription(), NONELECTRONIC_RECORD_NAME);
|
||||
assertFalse(nonElectronicRecord.getName().equals(NONELECTRONIC_RECORD_NAME));
|
||||
assertTrue(nonElectronicRecord.getName().contains(nonElectronicRecord.getProperties().getRmIdentifier()));
|
||||
assertTrue(nonElectronicRecord.getName().contains(nonElectronicRecord.getProperties().getIdentifier()));
|
||||
assertStatusCode(OK);
|
||||
}
|
||||
|
||||
@@ -211,43 +238,46 @@ public class ReadRecordTests extends BaseRMRestTest
|
||||
@Test
|
||||
public void readRecordContent() throws Exception
|
||||
{
|
||||
FilePlanComponentAPI filePlanComponentAPI = getRestAPIFactory().getFilePlanComponentsAPI();
|
||||
RecordsAPI recordsAPI = getRestAPIFactory().getRecordsAPI();
|
||||
|
||||
String RECORD_ELECTRONIC = "Record " + getRandomAlphanumeric();
|
||||
String RECORD_ELECTRONIC_BINARY = "Binary Record" + getRandomAlphanumeric();
|
||||
String existentRecordCategoryId = createCategoryFolderInFilePlan().getParentId();
|
||||
|
||||
String RELATIVE_PATH = "/" + CATEGORY_NAME + getRandomAlphanumeric() + "/folder";
|
||||
|
||||
// create the containers from the relativePath
|
||||
FilePlanComponent recordFolder = FilePlanComponent.builder()
|
||||
.name(FOLDER_NAME)
|
||||
RecordCategoryChild recordFolder = RecordCategoryChild.builder()
|
||||
.name(RECORD_FOLDER_NAME)
|
||||
.nodeType(RECORD_FOLDER_TYPE)
|
||||
.relativePath(RELATIVE_PATH)
|
||||
.build();
|
||||
String folderId = filePlanComponentAPI.createFilePlanComponent(recordFolder, FILE_PLAN_ALIAS).getId();
|
||||
RecordCategoryAPI recordCategoryAPI = getRestAPIFactory().getRecordCategoryAPI();
|
||||
String folderId = recordCategoryAPI.createRecordCategoryChild(recordFolder, existentRecordCategoryId).getId();
|
||||
|
||||
// text file as an electronic record
|
||||
FilePlanComponent recordText = FilePlanComponent.builder()
|
||||
.name(RECORD_ELECTRONIC)
|
||||
.nodeType(CONTENT_TYPE)
|
||||
.build();
|
||||
String recordId = filePlanComponentAPI.createElectronicRecord(recordText, createTempFile(RECORD_ELECTRONIC, RECORD_ELECTRONIC), folderId).getId();
|
||||
Record recordText = Record.builder()
|
||||
.name(RECORD_ELECTRONIC)
|
||||
.nodeType(CONTENT_TYPE)
|
||||
.build();
|
||||
RecordFolderAPI recordFolderAPI = getRestAPIFactory().getRecordFolderAPI();
|
||||
String recordId = recordFolderAPI.createRecord(recordText, folderId, createTempFile(RECORD_ELECTRONIC, RECORD_ELECTRONIC)).getId();
|
||||
assertEquals(recordsAPI.getRecordContent(recordId).asString(), RECORD_ELECTRONIC);
|
||||
// Check status code
|
||||
assertStatusCode(OK);
|
||||
|
||||
// binary file as an electronic record
|
||||
FilePlanComponent recordBinary = FilePlanComponent.builder()
|
||||
Record recordBinary = Record.builder()
|
||||
.name(RECORD_ELECTRONIC_BINARY)
|
||||
.nodeType(CONTENT_TYPE)
|
||||
.build();
|
||||
|
||||
String binaryRecordId = filePlanComponentAPI.createElectronicRecord(recordBinary, IMAGE_FILE, folderId).getId();
|
||||
String binaryRecordId = recordFolderAPI.createRecord(recordBinary, folderId, getFile(IMAGE_FILE)).getId();
|
||||
// binary content, therefore compare respective SHA1 checksums in order to verify this is identical content
|
||||
try
|
||||
(
|
||||
InputStream recordContentStream = recordsAPI.getRecordContent(binaryRecordId).asInputStream();
|
||||
FileInputStream localFileStream = new FileInputStream(new File(Resources.getResource(IMAGE_FILE).getFile()));
|
||||
FileInputStream localFileStream = new FileInputStream(getFile(IMAGE_FILE));
|
||||
)
|
||||
{
|
||||
assertEquals(DigestUtils.sha1(recordContentStream), DigestUtils.sha1(localFileStream));
|
||||
@@ -255,11 +285,11 @@ public class ReadRecordTests extends BaseRMRestTest
|
||||
assertStatusCode(OK);
|
||||
|
||||
// electronic record with no content
|
||||
FilePlanComponent recordNoContent = FilePlanComponent.builder()
|
||||
Record recordNoContent = Record.builder()
|
||||
.name(RECORD_ELECTRONIC)
|
||||
.nodeType(CONTENT_TYPE)
|
||||
.build();
|
||||
String recordNoContentId = filePlanComponentAPI.createFilePlanComponent(recordNoContent,folderId).getId();
|
||||
String recordNoContentId = recordFolderAPI.createRecord(recordNoContent,folderId).getId();
|
||||
assertTrue(recordsAPI.getRecordContent(recordNoContentId).asString().isEmpty());
|
||||
assertStatusCode(OK);
|
||||
}
|
||||
@@ -273,18 +303,17 @@ public class ReadRecordTests extends BaseRMRestTest
|
||||
{
|
||||
|
||||
String NONELECTRONIC_RECORD_NAME = "Record nonelectronic" + getRandomAlphanumeric();
|
||||
FilePlanComponentAPI filePlanComponentAPI = getRestAPIFactory().getFilePlanComponentsAPI();
|
||||
FilePlanComponent record = FilePlanComponent.builder()
|
||||
.name(NONELECTRONIC_RECORD_NAME)
|
||||
.nodeType(NON_ELECTRONIC_RECORD_TYPE)
|
||||
.relativePath("/" + CATEGORY_NAME + getRandomAlphanumeric() + "/" + FOLDER_NAME)
|
||||
.build();
|
||||
String folderId = createCategoryFolderInFilePlan().getId();
|
||||
Record record = Record.builder()
|
||||
.name(NONELECTRONIC_RECORD_NAME)
|
||||
.nodeType(NON_ELECTRONIC_RECORD_TYPE)
|
||||
.build();
|
||||
|
||||
String nonElectronicRecord = filePlanComponentAPI.createFilePlanComponent(record, FILE_PLAN_ALIAS).getId();
|
||||
RecordFolderAPI recordFolderAPI = getRestAPIFactory().getRecordFolderAPI();
|
||||
String nonElectronicRecord = recordFolderAPI.createRecord(record, folderId).getId();
|
||||
|
||||
|
||||
assertTrue(getRestAPIFactory().getRecordsAPI().getRecordContent(nonElectronicRecord).asString().isEmpty());
|
||||
assertStatusCode(OK);
|
||||
getRestAPIFactory().getRecordsAPI().getRecordContent(nonElectronicRecord);
|
||||
assertStatusCode(BAD_REQUEST);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -292,10 +321,18 @@ public class ReadRecordTests extends BaseRMRestTest
|
||||
* When I try to read the content
|
||||
* Then I receive an error
|
||||
*/
|
||||
@DataProvider(name="noContentNodes")
|
||||
public String[][] getNonRecordTypes() throws Exception
|
||||
{
|
||||
return new String[][] {
|
||||
{ getFilePlan(FILE_PLAN_ALIAS).getId() },
|
||||
{ getTransferContainer(TRANSFERS_ALIAS).getId() },
|
||||
{ createCategoryFolderInFilePlan().getParentId()}
|
||||
};
|
||||
}
|
||||
@Test
|
||||
(
|
||||
dataProvider = "getContainers",
|
||||
dataProviderClass = TestData.class,
|
||||
dataProvider = "noContentNodes",
|
||||
description = "Reading records from invalid containers"
|
||||
)
|
||||
public void readContentFromInvalidContainers(String container) throws Exception
|
||||
@@ -305,64 +342,49 @@ public class ReadRecordTests extends BaseRMRestTest
|
||||
}
|
||||
|
||||
/**
|
||||
* Given a container that is a record/unfiled folder
|
||||
* Given a container that is a record folder
|
||||
* When I try to record the containers records
|
||||
* Then I receive a list of all the records contained within the record/unfiled folder
|
||||
* Then I receive a list of all the records contained within the record folder
|
||||
*/
|
||||
|
||||
/** Valid root containers where electronic and non-electronic records can be created */
|
||||
@DataProvider (name = "folderContainers")
|
||||
public Object[][] getFolderContainers() throws Exception
|
||||
{
|
||||
return new Object[][] {
|
||||
// an arbitrary record folder
|
||||
{ createCategoryFolderInFilePlan().getId()},
|
||||
// an arbitrary unfiled records folder
|
||||
{ createUnfiledRecordsFolder(UNFILED_RECORDS_CONTAINER_ALIAS.toString(), "Unfiled Folder " + getRandomAlphanumeric()).getId() }
|
||||
};
|
||||
}
|
||||
|
||||
@Test
|
||||
(
|
||||
dataProvider ="folderContainers",
|
||||
description ="List the records from record folder/unfiled record folder"
|
||||
)
|
||||
public void readRecordsFromFolders(String containerId) throws Exception
|
||||
public void readRecordsFromRecordFolder() throws Exception
|
||||
{
|
||||
final int NUMBER_OF_RECORDS = 5;
|
||||
FilePlanComponentAPI filePlanComponentAPI = getRestAPIFactory().getFilePlanComponentsAPI();
|
||||
String containerId = createCategoryFolderInFilePlan().getId();
|
||||
RecordFolderAPI recordFolderAPI = getRestAPIFactory().getRecordFolderAPI();
|
||||
// Create Electronic Records
|
||||
ArrayList<FilePlanComponent> children = new ArrayList<FilePlanComponent>();
|
||||
ArrayList<Record> children = new ArrayList<Record>();
|
||||
for (int i = 0; i < NUMBER_OF_RECORDS; i++)
|
||||
{
|
||||
//build the electronic record
|
||||
FilePlanComponent record = FilePlanComponent.builder()
|
||||
.name(ELECTRONIC_RECORD_NAME +i)
|
||||
.nodeType(CONTENT_TYPE)
|
||||
.build();
|
||||
Record record = Record.builder()
|
||||
.name(ELECTRONIC_RECORD_NAME + i)
|
||||
.nodeType(CONTENT_TYPE)
|
||||
.build();
|
||||
//create a child
|
||||
FilePlanComponent child = filePlanComponentAPI.createElectronicRecord(record, createTempFile(ELECTRONIC_RECORD_NAME + i, ELECTRONIC_RECORD_NAME + i ), containerId);
|
||||
Record child = recordFolderAPI.createRecord(record, containerId, createTempFile(ELECTRONIC_RECORD_NAME + i, ELECTRONIC_RECORD_NAME + i ));
|
||||
|
||||
children.add(child);
|
||||
}
|
||||
//Create NonElectronicRecords
|
||||
for (int i = 0; i < NUMBER_OF_RECORDS; i++)
|
||||
{
|
||||
FilePlanComponent nonelectronicRecord = FilePlanComponent.builder()
|
||||
.properties(FilePlanComponentProperties.builder()
|
||||
.description("Description")
|
||||
.title("Title")
|
||||
.build())
|
||||
.name(NONELECTRONIC_RECORD_NAME+i)
|
||||
.nodeType(NON_ELECTRONIC_RECORD_TYPE)
|
||||
.build();
|
||||
Record nonelectronicRecord = Record.builder()
|
||||
.properties(RecordProperties.builder()
|
||||
.description("Description")
|
||||
.title("Title")
|
||||
.build())
|
||||
.name(NONELECTRONIC_RECORD_NAME+i)
|
||||
.nodeType(NON_ELECTRONIC_RECORD_TYPE)
|
||||
.build();
|
||||
//create records
|
||||
FilePlanComponent child = filePlanComponentAPI.createFilePlanComponent(nonelectronicRecord, containerId);
|
||||
Record child = recordFolderAPI.createRecord(nonelectronicRecord, containerId);
|
||||
|
||||
children.add(child);
|
||||
}
|
||||
|
||||
// List children from API
|
||||
FilePlanComponentsCollection apiChildren =
|
||||
(FilePlanComponentsCollection) filePlanComponentAPI.listChildComponents(containerId).assertThat().entriesListIsNotEmpty();
|
||||
RecordFolderCollection apiChildren = (RecordFolderCollection) recordFolderAPI.getRecordFolderChildren(containerId).assertThat().entriesListIsNotEmpty();
|
||||
|
||||
// Check status code
|
||||
assertStatusCode(OK);
|
||||
@@ -370,106 +392,123 @@ public class ReadRecordTests extends BaseRMRestTest
|
||||
|
||||
// Check listed children against created list
|
||||
apiChildren.getEntries().forEach(c ->
|
||||
{
|
||||
Record record = c.getEntry();
|
||||
assertNotNull(record.getId());
|
||||
logger.info("Checking child " + record.getId());
|
||||
|
||||
try
|
||||
{
|
||||
FilePlanComponent filePlanComponent = c.getFilePlanComponentModel();
|
||||
assertNotNull(filePlanComponent.getId());
|
||||
logger.info("Checking child " + filePlanComponent.getId());
|
||||
// Find this child in created children list
|
||||
Record createdComponent = children.stream()
|
||||
.filter(child -> child.getId().equals(record.getId()))
|
||||
.findFirst()
|
||||
.get();
|
||||
|
||||
try
|
||||
{
|
||||
// Find this child in created children list
|
||||
FilePlanComponent createdComponent = children.stream()
|
||||
.filter(child -> child.getId().equals(filePlanComponent.getId()))
|
||||
.findFirst()
|
||||
.get();
|
||||
// Created by
|
||||
assertEquals(record.getCreatedByUser().getId(), getAdminUser().getUsername());
|
||||
|
||||
// Created by
|
||||
assertEquals(filePlanComponent.getCreatedByUser().getId(), getAdminUser().getUsername());
|
||||
// Is parent Id set correctly
|
||||
assertEquals(record.getParentId(), containerId);
|
||||
|
||||
// Is parent Id set correctly
|
||||
assertEquals(filePlanComponent.getParentId(), containerId);
|
||||
assertTrue(filePlanComponent.getIsFile());
|
||||
//check the record name
|
||||
assertTrue(record.getName().equals(createdComponent.getName()));
|
||||
assertTrue(createdComponent.getName().contains(createdComponent.getProperties().getIdentifier()));
|
||||
assertEquals(createdComponent.getNodeType(), record.getNodeType());
|
||||
|
||||
// Boolean properties related to node type
|
||||
assertFalse(filePlanComponent.getIsRecordFolder());
|
||||
assertFalse(filePlanComponent.getIsCategory());
|
||||
|
||||
//check the record name
|
||||
assertTrue(filePlanComponent.getName().equals(createdComponent.getName()));
|
||||
assertTrue(createdComponent.getName().contains(createdComponent.getProperties().getRmIdentifier()));
|
||||
assertEquals(createdComponent.getNodeType(), filePlanComponent.getNodeType());
|
||||
|
||||
}
|
||||
catch (NoSuchElementException e)
|
||||
{
|
||||
fail("No child element for " + filePlanComponent.getId());
|
||||
}
|
||||
}
|
||||
);
|
||||
catch (NoSuchElementException e)
|
||||
{
|
||||
fail("No child element for " + record.getId());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Given a record
|
||||
* When I try to read the children
|
||||
* Then I receive error
|
||||
* Given a container that is a unfiled record folder
|
||||
* When I try to record the containers records
|
||||
* Then I receive a list of all the records contained within the unfiled record folder
|
||||
*/
|
||||
@Test
|
||||
public void readChildrenOnRecords() throws Exception
|
||||
public void readRecordsFromUnfiledRecordFolder() throws Exception
|
||||
{
|
||||
String RELATIVE_PATH = "CATEGORY" + getRandomAlphanumeric() + "/FOLDER";
|
||||
FilePlanComponentAPI filePlanComponentAPI = getRestAPIFactory().getFilePlanComponentsAPI();
|
||||
FilePlanComponent electRecord = FilePlanComponent.builder()
|
||||
.name(ELECTRONIC_RECORD_NAME)
|
||||
.nodeType(CONTENT_TYPE)
|
||||
.content(FilePlanComponentContent.builder().mimeType("text/plain").build())
|
||||
.build();
|
||||
FilePlanComponent nonElectronic = FilePlanComponent.builder()
|
||||
.properties(FilePlanComponentProperties.builder()
|
||||
.description(NONELECTRONIC_RECORD_NAME)
|
||||
.title("Title")
|
||||
.build())
|
||||
.name(NONELECTRONIC_RECORD_NAME)
|
||||
.nodeType(NON_ELECTRONIC_RECORD_TYPE)
|
||||
.build();
|
||||
final int NUMBER_OF_RECORDS = 5;
|
||||
String containerId = createUnfiledContainerChild(UNFILED_RECORDS_CONTAINER_ALIAS, "Unfiled Folder " + getRandomAlphanumeric(), UNFILED_RECORD_FOLDER_TYPE).getId();
|
||||
//we have unfiled record folder
|
||||
UnfiledRecordFolderAPI unfiledRecordFoldersAPI = getRestAPIFactory().getUnfiledRecordFoldersAPI();
|
||||
// Create Electronic Records
|
||||
ArrayList<UnfiledContainerChild> children = new ArrayList<UnfiledContainerChild>();
|
||||
for (int i = 0; i < NUMBER_OF_RECORDS; i++)
|
||||
{
|
||||
//build the electronic record
|
||||
UnfiledContainerChild record = UnfiledContainerChild.builder()
|
||||
.name(ELECTRONIC_RECORD_NAME + i)
|
||||
.nodeType(CONTENT_TYPE)
|
||||
.build();
|
||||
//create a child
|
||||
UnfiledContainerChild child = unfiledRecordFoldersAPI.uploadRecord(record, containerId, createTempFile(ELECTRONIC_RECORD_NAME + i, ELECTRONIC_RECORD_NAME + i ));
|
||||
|
||||
//create records in Unfiled Container
|
||||
FilePlanComponent recordElecInUnfiled = filePlanComponentAPI.createFilePlanComponent(electRecord, UNFILED_RECORDS_CONTAINER_ALIAS);
|
||||
FilePlanComponent recordNonElecInUnfiled = filePlanComponentAPI.createFilePlanComponent(nonElectronic, UNFILED_RECORDS_CONTAINER_ALIAS);
|
||||
children.add(child);
|
||||
}
|
||||
//Create NonElectronicRecords
|
||||
for (int i = 0; i < NUMBER_OF_RECORDS; i++)
|
||||
{
|
||||
UnfiledContainerChild nonelectronicRecord = UnfiledContainerChild.builder()
|
||||
.properties(UnfiledContainerChildProperties.builder()
|
||||
.description("Description")
|
||||
.title("Title")
|
||||
.build())
|
||||
.name(NONELECTRONIC_RECORD_NAME+i)
|
||||
.nodeType(NON_ELECTRONIC_RECORD_TYPE)
|
||||
.build();
|
||||
//create records
|
||||
UnfiledContainerChild child = unfiledRecordFoldersAPI.createUnfiledRecordFolderChild(nonelectronicRecord, containerId);
|
||||
|
||||
children.add(child);
|
||||
}
|
||||
|
||||
// List children from API
|
||||
UnfiledContainerChildCollection apiChildren = (UnfiledContainerChildCollection) unfiledRecordFoldersAPI.getUnfiledRecordFolderChildren(containerId).assertThat().entriesListIsNotEmpty();
|
||||
|
||||
// List children for the electronic Record
|
||||
filePlanComponentAPI.listChildComponents(recordElecInUnfiled.getId(), "where=(isFile=true)")
|
||||
//check the list returned is empty
|
||||
.assertThat().entriesListIsEmpty().assertThat().paginationExist();
|
||||
// Check status code
|
||||
assertStatusCode(OK);
|
||||
|
||||
// List children for the nonElectronic Record
|
||||
filePlanComponentAPI.listChildComponents(recordNonElecInUnfiled.getId(), "where=(isFile=true)")
|
||||
//check the list returned is empty
|
||||
.assertThat().entriesListIsEmpty().assertThat().paginationExist();
|
||||
// Check status code
|
||||
assertStatusCode(OK);
|
||||
|
||||
//Update the Records objects
|
||||
electRecord.setRelativePath(RELATIVE_PATH);
|
||||
nonElectronic.setRelativePath(RELATIVE_PATH);
|
||||
// Check listed children against created list
|
||||
apiChildren.getEntries().forEach(c ->
|
||||
{
|
||||
UnfiledContainerChild record = c.getEntry();
|
||||
assertNotNull(record.getId());
|
||||
logger.info("Checking child " + record.getId());
|
||||
|
||||
//create records in Unfiled Container
|
||||
FilePlanComponent recordElecFromRecordFolder = filePlanComponentAPI.createFilePlanComponent(electRecord, FILE_PLAN_ALIAS);
|
||||
FilePlanComponent recordNonElecFromRecordFolder = filePlanComponentAPI.createFilePlanComponent(nonElectronic, FILE_PLAN_ALIAS);
|
||||
try
|
||||
{
|
||||
// Find this child in created children list
|
||||
UnfiledContainerChild createdComponent = children.stream()
|
||||
.filter(child -> child.getId().equals(record.getId()))
|
||||
.findFirst()
|
||||
.get();
|
||||
|
||||
// List children for the electronic Record
|
||||
filePlanComponentAPI.listChildComponents(recordElecFromRecordFolder.getId(), "where=(isFile=true)")
|
||||
//check the list returned is empty
|
||||
.assertThat().entriesListIsEmpty().assertThat().paginationExist();
|
||||
// Check status code
|
||||
assertStatusCode(OK);
|
||||
// Created by
|
||||
assertEquals(record.getCreatedByUser().getId(), getAdminUser().getUsername());
|
||||
|
||||
// List children for the nonElectronic Record
|
||||
getRestAPIFactory().getFilePlanComponentsAPI().listChildComponents(recordNonElecFromRecordFolder.getId(), "where=(isFile=true)")
|
||||
//check the list returned is empty
|
||||
.assertThat().entriesListIsEmpty().assertThat().paginationExist();
|
||||
// Check status code
|
||||
assertStatusCode(OK);
|
||||
// Is parent Id set correctly
|
||||
assertEquals(record.getParentId(), containerId);
|
||||
assertTrue(record.getIsRecord());
|
||||
|
||||
// Boolean properties related to node type
|
||||
assertFalse(record.getIsUnfiledRecordFolder());
|
||||
|
||||
//check the record name
|
||||
assertTrue(record.getName().equals(createdComponent.getName()));
|
||||
assertTrue(createdComponent.getName().contains(createdComponent.getProperties().getIdentifier()));
|
||||
assertEquals(createdComponent.getNodeType(), record.getNodeType());
|
||||
|
||||
}
|
||||
catch (NoSuchElementException e)
|
||||
{
|
||||
fail("No child element for " + record.getId());
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@@ -1,411 +0,0 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Records Management Module
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2017 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* -
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
* -
|
||||
* Alfresco is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
* -
|
||||
* Alfresco is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
* -
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
* #L%
|
||||
*/
|
||||
package org.alfresco.rest.rm.community.fileplancomponents;
|
||||
|
||||
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentAlias.FILE_PLAN_ALIAS;
|
||||
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.RECORD_CATEGORY_TYPE;
|
||||
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.RECORD_FOLDER_TYPE;
|
||||
import static org.alfresco.utility.data.RandomData.getRandomAlphanumeric;
|
||||
import static org.springframework.http.HttpStatus.CREATED;
|
||||
import static org.springframework.http.HttpStatus.NOT_FOUND;
|
||||
import static org.springframework.http.HttpStatus.NO_CONTENT;
|
||||
import static org.springframework.http.HttpStatus.OK;
|
||||
import static org.springframework.http.HttpStatus.UNPROCESSABLE_ENTITY;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertFalse;
|
||||
import static org.testng.Assert.assertNotNull;
|
||||
import static org.testng.Assert.assertTrue;
|
||||
import static org.testng.Assert.fail;
|
||||
|
||||
import java.util.ArrayList;
|
||||
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.fileplancomponents.FilePlanComponent;
|
||||
import org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentProperties;
|
||||
import org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentsCollection;
|
||||
import org.alfresco.rest.rm.community.requests.igCoreAPI.FilePlanComponentAPI;
|
||||
import org.alfresco.utility.report.Bug;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
/**
|
||||
* Record category related API tests
|
||||
*
|
||||
* @author Kristijan Conkas
|
||||
* @author Tuna Aksoy
|
||||
* @since 2.6
|
||||
*/
|
||||
public class RecordCategoryTest extends BaseRMRestTest
|
||||
{
|
||||
// Number of children (for children creation test)
|
||||
private static final int NUMBER_OF_CHILDREN = 10;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* Given that a file plan exists
|
||||
* When I ask the API to create a root record category
|
||||
* Then it is created as a root record category
|
||||
*
|
||||
*
|
||||
* Given that a file plan exists
|
||||
* When I use the API to create a folder (cm:folder type) into the fileplan
|
||||
* Then the folder is converted to rma:recordCategory
|
||||
* (see RM-4572 comments)
|
||||
*
|
||||
*/
|
||||
@Test
|
||||
(
|
||||
description = "Create root category",
|
||||
dataProviderClass= TestData.class,
|
||||
dataProvider = "categoryTypes"
|
||||
)
|
||||
public void createCategoryTest(String nodeType) throws Exception
|
||||
{
|
||||
String categoryName = "Category name " + getRandomAlphanumeric();
|
||||
String categoryTitle = "Category title " + getRandomAlphanumeric();
|
||||
|
||||
// Build the record category properties
|
||||
FilePlanComponent recordCategory = FilePlanComponent.builder()
|
||||
.name(categoryName)
|
||||
.nodeType(nodeType)
|
||||
.properties(
|
||||
FilePlanComponentProperties.builder()
|
||||
.title(categoryTitle)
|
||||
.build())
|
||||
.build();
|
||||
|
||||
// Create the record category
|
||||
FilePlanComponent filePlanComponent = getRestAPIFactory().getFilePlanComponentsAPI().createFilePlanComponent(recordCategory, FILE_PLAN_ALIAS);
|
||||
|
||||
// Verify the status code
|
||||
assertStatusCode(CREATED);
|
||||
|
||||
// Verify the returned file plan component
|
||||
assertTrue(filePlanComponent.getIsCategory());
|
||||
assertFalse(filePlanComponent.getIsFile());
|
||||
assertFalse(filePlanComponent.getIsRecordFolder());
|
||||
|
||||
assertEquals(filePlanComponent.getName(), categoryName);
|
||||
assertEquals(filePlanComponent.getNodeType(), RECORD_CATEGORY_TYPE);
|
||||
|
||||
assertEquals(filePlanComponent.getCreatedByUser().getId(), getAdminUser().getUsername());
|
||||
|
||||
// Verify the returned file plan component properties
|
||||
FilePlanComponentProperties filePlanComponentProperties = filePlanComponent.getProperties();
|
||||
assertEquals(filePlanComponentProperties.getTitle(), categoryTitle);
|
||||
assertNotNull(filePlanComponentProperties.getRmIdentifier());
|
||||
logger.info("Aspects: " + filePlanComponent.getAspectNames());
|
||||
}
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* Given that a record category exists
|
||||
* When I ask the API to update the details of the record category
|
||||
* Then the details of the record category are updated
|
||||
*/
|
||||
@Test
|
||||
(
|
||||
description = "Rename root category"
|
||||
)
|
||||
public void renameCategory() throws Exception
|
||||
{
|
||||
// Create record category first
|
||||
String categoryName = "Category name " + getRandomAlphanumeric();
|
||||
String categoryTitle = "Category title " + getRandomAlphanumeric();
|
||||
|
||||
// Build the record category properties
|
||||
FilePlanComponent recordCategory = FilePlanComponent.builder()
|
||||
.name(categoryName)
|
||||
.nodeType(RECORD_CATEGORY_TYPE)
|
||||
.properties(
|
||||
FilePlanComponentProperties.builder()
|
||||
.title(categoryTitle)
|
||||
.build())
|
||||
.build();
|
||||
|
||||
// Create the record category
|
||||
FilePlanComponentAPI filePlanComponentsAPI = getRestAPIFactory().getFilePlanComponentsAPI();
|
||||
FilePlanComponent filePlanComponent = filePlanComponentsAPI.createFilePlanComponent(recordCategory, FILE_PLAN_ALIAS);
|
||||
|
||||
String newCategoryName = "Rename " + categoryName;
|
||||
|
||||
// Build the properties which will be updated
|
||||
FilePlanComponent recordCategoryUpdated = FilePlanComponent.builder().name(newCategoryName).build();
|
||||
|
||||
// Update the record category
|
||||
FilePlanComponent renamedFilePlanComponent = filePlanComponentsAPI.updateFilePlanComponent(recordCategoryUpdated, filePlanComponent.getId());
|
||||
|
||||
// Verify the status code
|
||||
assertStatusCode(OK);
|
||||
|
||||
// Verify the returned file plan component
|
||||
assertEquals(renamedFilePlanComponent.getName(), newCategoryName);
|
||||
|
||||
// Get actual FILE_PLAN_ALIAS id
|
||||
FilePlanComponent parentComponent = filePlanComponentsAPI.getFilePlanComponent(FILE_PLAN_ALIAS);
|
||||
|
||||
// verify renamed component still has this parent
|
||||
assertEquals(renamedFilePlanComponent.getParentId(), parentComponent.getId());
|
||||
}
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* Given that a record category exists
|
||||
* When I ask the API to delete the record category
|
||||
* Then the record category and all its contents is deleted
|
||||
*/
|
||||
@Test
|
||||
(
|
||||
description = "Delete category"
|
||||
)
|
||||
public void deleteCategory() throws Exception
|
||||
{
|
||||
// Create record category first
|
||||
String categoryName = "Category name " + getRandomAlphanumeric();
|
||||
String categoryTitle = "Category title " + getRandomAlphanumeric();
|
||||
|
||||
// Build the record category properties
|
||||
FilePlanComponent recordCategory = FilePlanComponent.builder()
|
||||
.name(categoryName)
|
||||
.nodeType(RECORD_CATEGORY_TYPE)
|
||||
.properties(
|
||||
FilePlanComponentProperties.builder()
|
||||
.title(categoryTitle)
|
||||
.build())
|
||||
.build();
|
||||
|
||||
// Create the record category
|
||||
FilePlanComponentAPI filePlanComponentsAPI = getRestAPIFactory().getFilePlanComponentsAPI();
|
||||
FilePlanComponent filePlanComponent = filePlanComponentsAPI.createFilePlanComponent(recordCategory, FILE_PLAN_ALIAS);
|
||||
|
||||
// Delete the record category
|
||||
filePlanComponentsAPI.deleteFilePlanComponent(filePlanComponent.getId());
|
||||
|
||||
// Verify the status code
|
||||
assertStatusCode(NO_CONTENT);
|
||||
|
||||
// Deleted component should no longer be retrievable
|
||||
filePlanComponentsAPI.getFilePlanComponent(filePlanComponent.getId());
|
||||
assertStatusCode(NOT_FOUND);
|
||||
}
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* Given that a record category exists
|
||||
* When I ask the API to create a record category
|
||||
* Then it is created within the record category
|
||||
*/
|
||||
@Test
|
||||
(
|
||||
description = "Create child category"
|
||||
)
|
||||
public void createSubcategory() throws Exception
|
||||
{
|
||||
// Create root level category
|
||||
FilePlanComponent rootCategory = createCategory(FILE_PLAN_ALIAS, getRandomAlphanumeric());
|
||||
assertNotNull(rootCategory.getId());
|
||||
|
||||
// Create subcategory as a child of rootCategory
|
||||
FilePlanComponent childCategory = createCategory(rootCategory.getId(), getRandomAlphanumeric());
|
||||
|
||||
// Child category created?
|
||||
assertNotNull(childCategory.getId());
|
||||
|
||||
// Verify child category
|
||||
assertEquals(childCategory.getParentId(), rootCategory.getId());
|
||||
assertTrue(childCategory.getIsCategory());
|
||||
assertFalse(childCategory.getIsFile());
|
||||
assertFalse(childCategory.getIsRecordFolder());
|
||||
assertEquals(childCategory.getNodeType(), RECORD_CATEGORY_TYPE);
|
||||
}
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* Given that a record category exists
|
||||
* And contains a number of record categories and record folders
|
||||
* When I ask the APi to get me the children of the record category
|
||||
* Then I am returned the contained record categories and record folders
|
||||
* And their details
|
||||
*/
|
||||
@Test
|
||||
(
|
||||
description = "List children of a category"
|
||||
)
|
||||
public void listChildren() throws Exception
|
||||
{
|
||||
// Create root level category
|
||||
FilePlanComponent rootCategory = createCategory(FILE_PLAN_ALIAS, getRandomAlphanumeric());
|
||||
assertNotNull(rootCategory.getId());
|
||||
|
||||
// Add child categories/folders
|
||||
ArrayList<FilePlanComponent> children = new ArrayList<FilePlanComponent>();
|
||||
for (int i=0; i < NUMBER_OF_CHILDREN; i++)
|
||||
{
|
||||
// Create a child
|
||||
FilePlanComponent child = createComponent(rootCategory.getId(),
|
||||
getRandomAlphanumeric(),
|
||||
// half of the children should be subcategories, the other subfolders
|
||||
(i <= NUMBER_OF_CHILDREN / 2) ? RECORD_CATEGORY_TYPE : RECORD_FOLDER_TYPE);
|
||||
assertNotNull(child.getId());
|
||||
children.add(child);
|
||||
}
|
||||
|
||||
// List children from API
|
||||
FilePlanComponentsCollection apiChildren = getRestAPIFactory().getFilePlanComponentsAPI().listChildComponents(rootCategory.getId());
|
||||
|
||||
// Check status code
|
||||
assertStatusCode(OK);
|
||||
logger.info("parent: " + rootCategory.getId());
|
||||
|
||||
// Check listed children against created list
|
||||
apiChildren.getEntries().forEach(c ->
|
||||
{
|
||||
FilePlanComponent filePlanComponent = c.getFilePlanComponentModel();
|
||||
assertNotNull(filePlanComponent.getId());
|
||||
logger.info("Checking child " + filePlanComponent.getId());
|
||||
|
||||
try
|
||||
{
|
||||
// Find this child in created children list
|
||||
FilePlanComponent createdComponent = children.stream()
|
||||
.filter(child -> child.getId().equals(filePlanComponent.getId()))
|
||||
.findFirst()
|
||||
.get();
|
||||
|
||||
// Created by
|
||||
assertEquals(filePlanComponent.getCreatedByUser().getId(), getAdminUser().getUsername());
|
||||
|
||||
// Is parent Id set correctly?
|
||||
assertEquals(filePlanComponent.getParentId(), rootCategory.getId());
|
||||
|
||||
// Only categories or folders have been created
|
||||
assertFalse(filePlanComponent.getIsFile());
|
||||
|
||||
// Boolean properties related to node type
|
||||
// Only RECORD_CATEGORY_TYPE and RECORD_FOLDER_TYPE have been created
|
||||
if (filePlanComponent.getNodeType().equals(RECORD_CATEGORY_TYPE))
|
||||
{
|
||||
assertTrue(filePlanComponent.getIsCategory());
|
||||
assertFalse(filePlanComponent.getIsRecordFolder());
|
||||
}
|
||||
else
|
||||
{
|
||||
assertTrue(filePlanComponent.getIsRecordFolder());
|
||||
assertFalse(filePlanComponent.getIsCategory());
|
||||
}
|
||||
|
||||
// Does returned object have the same contents as the created one?
|
||||
assertEquals(createdComponent.getName(), filePlanComponent.getName());
|
||||
assertEquals(createdComponent.getNodeType(), filePlanComponent.getNodeType());
|
||||
|
||||
// Verify properties
|
||||
// FIXME: Verify properties
|
||||
assertNotNull(createdComponent.getProperties().getRmIdentifier());
|
||||
}
|
||||
catch (NoSuchElementException e)
|
||||
{
|
||||
fail("No child element for " + filePlanComponent.getId());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Given that a record category exists
|
||||
* When I ask to create a object type which is not a record category or a record folder as a child
|
||||
* Then the children are not created and the 422 response code is returned
|
||||
*/
|
||||
@Test
|
||||
(
|
||||
description = "Create node types not allowed inside a category",
|
||||
dataProviderClass = TestData.class,
|
||||
dataProvider = "childrenNotAllowedForCategory"
|
||||
|
||||
)
|
||||
@Bug (id="RM-4367, RM-4572")
|
||||
public void createTypesNotAllowedInCategory(String nodeType) throws Exception
|
||||
{
|
||||
String COMPONENT_NAME = "Component"+getRandomAlphanumeric();
|
||||
|
||||
//Create the category
|
||||
FilePlanComponent category = createCategory(FILE_PLAN_ALIAS, COMPONENT_NAME);
|
||||
|
||||
//Build node properties
|
||||
FilePlanComponent recordCategory = FilePlanComponent.builder()
|
||||
.name(COMPONENT_NAME)
|
||||
.nodeType(nodeType)
|
||||
.properties(
|
||||
FilePlanComponentProperties.builder()
|
||||
.title("Title for " + COMPONENT_NAME)
|
||||
.build())
|
||||
.build();
|
||||
|
||||
//create the invalid node type
|
||||
getRestAPIFactory().getFilePlanComponentsAPI().createFilePlanComponent(recordCategory, category.getId());
|
||||
assertStatusCode(UNPROCESSABLE_ENTITY);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Helper method to create child category
|
||||
*
|
||||
* @param parentCategoryId The id of the parent category
|
||||
* @param categoryName The name of the category
|
||||
* @return The created category
|
||||
* @throws Exception on unsuccessful component creation
|
||||
*/
|
||||
public FilePlanComponent createCategory(String parentCategoryId, String categoryName) throws Exception
|
||||
{
|
||||
return createComponent(parentCategoryId, categoryName, RECORD_CATEGORY_TYPE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method to create generic child component
|
||||
*
|
||||
* @param parentComponentId The id of the parent file plan component
|
||||
* @param componentName The name of the file plan component
|
||||
* @param componentType The name of the file plan component
|
||||
* @return The created file plan component
|
||||
* @throws Exception
|
||||
*/
|
||||
private FilePlanComponent createComponent(String parentComponentId, String componentName, String componentType) throws Exception
|
||||
{
|
||||
// Build node properties
|
||||
FilePlanComponent component = FilePlanComponent.builder()
|
||||
.name(componentName)
|
||||
.nodeType(componentType)
|
||||
.properties(FilePlanComponentProperties.builder()
|
||||
.title("Title for " + componentName)
|
||||
.build())
|
||||
.build();
|
||||
|
||||
FilePlanComponent filePlanComponent = getRestAPIFactory().getFilePlanComponentsAPI().createFilePlanComponent(component, parentComponentId);
|
||||
assertStatusCode(CREATED);
|
||||
|
||||
return filePlanComponent;
|
||||
}
|
||||
}
|
@@ -0,0 +1,331 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Records Management Module
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2017 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* -
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
* -
|
||||
* Alfresco is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
* -
|
||||
* Alfresco is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
* -
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
* #L%
|
||||
*/
|
||||
package org.alfresco.rest.rm.community.fileplancomponents;
|
||||
|
||||
import static org.alfresco.rest.rm.community.base.TestData.RECORD_CATEGORY_NAME;
|
||||
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentAlias.FILE_PLAN_ALIAS;
|
||||
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.RECORD_CATEGORY_TYPE;
|
||||
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.RECORD_FOLDER_TYPE;
|
||||
import static org.alfresco.utility.data.RandomData.getRandomAlphanumeric;
|
||||
import static org.springframework.http.HttpStatus.CREATED;
|
||||
import static org.springframework.http.HttpStatus.NOT_FOUND;
|
||||
import static org.springframework.http.HttpStatus.NO_CONTENT;
|
||||
import static org.springframework.http.HttpStatus.OK;
|
||||
import static org.springframework.http.HttpStatus.UNPROCESSABLE_ENTITY;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertFalse;
|
||||
import static org.testng.Assert.assertNotNull;
|
||||
import static org.testng.Assert.assertTrue;
|
||||
import static org.testng.Assert.fail;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
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.recordcategory.RecordCategory;
|
||||
import org.alfresco.rest.rm.community.model.recordcategory.RecordCategoryChild;
|
||||
import org.alfresco.rest.rm.community.model.recordcategory.RecordCategoryChildCollection;
|
||||
import org.alfresco.rest.rm.community.model.recordcategory.RecordCategoryProperties;
|
||||
import org.alfresco.rest.rm.community.requests.gscore.api.RecordCategoryAPI;
|
||||
import org.alfresco.utility.report.Bug;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
/**
|
||||
* Record category related API tests
|
||||
*
|
||||
* @author Kristijan Conkas
|
||||
* @author Tuna Aksoy
|
||||
* @since 2.6
|
||||
*/
|
||||
public class RecordCategoryTests extends BaseRMRestTest
|
||||
{
|
||||
/** Number of children (for children creation test) */
|
||||
private static final int NUMBER_OF_CHILDREN = 10;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* Given that a file plan exists
|
||||
* When I ask the API to create a root record category
|
||||
* Then it is created as a root record category
|
||||
* </pre>
|
||||
* <pre>
|
||||
* Given that a file plan exists
|
||||
* When I use the API to create a folder (cm:folder type) into the fileplan
|
||||
* Then the folder is converted to rma:recordCategory
|
||||
* (see RM-4572 comments)
|
||||
* </pre>
|
||||
*/
|
||||
@Test
|
||||
(
|
||||
description = "Create root category",
|
||||
dataProviderClass= TestData.class,
|
||||
dataProvider = "categoryTypes"
|
||||
)
|
||||
public void createCategoryTest(String nodeType) throws Exception
|
||||
{
|
||||
String categoryName = "Category name " + getRandomAlphanumeric();
|
||||
String categoryTitle = "Category title " + getRandomAlphanumeric();
|
||||
|
||||
// Create the root record category
|
||||
RecordCategory rootRecordCategory = createRootCategory(categoryName, categoryTitle);
|
||||
|
||||
// Verify the status code
|
||||
assertStatusCode(CREATED);
|
||||
|
||||
assertEquals(rootRecordCategory.getName(), categoryName);
|
||||
assertEquals(rootRecordCategory.getNodeType(), RECORD_CATEGORY_TYPE);
|
||||
|
||||
assertEquals(rootRecordCategory.getCreatedByUser().getId(), getAdminUser().getUsername());
|
||||
|
||||
// Verify the returned root record category properties
|
||||
RecordCategoryProperties rootRecordCategoryProperties = rootRecordCategory.getProperties();
|
||||
assertEquals(rootRecordCategoryProperties.getTitle(), categoryTitle);
|
||||
assertNotNull(rootRecordCategoryProperties.getIdentifier());
|
||||
logger.info("Aspects: " + rootRecordCategory.getAspectNames());
|
||||
}
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* Given that a record category exists
|
||||
* When I ask the API to update the details of the record category
|
||||
* Then the details of the record category are updated
|
||||
* </pre>
|
||||
*/
|
||||
@Test
|
||||
(
|
||||
description = "Rename root category"
|
||||
)
|
||||
public void renameCategory() throws Exception
|
||||
{
|
||||
// Create record category first
|
||||
String categoryName = "Category name " + getRandomAlphanumeric();
|
||||
String categoryTitle = "Category title " + getRandomAlphanumeric();
|
||||
|
||||
// Create the root record category
|
||||
RecordCategory rootRecordCategory = createRootCategory(categoryName, categoryTitle);
|
||||
|
||||
String newCategoryName = "Rename " + categoryName;
|
||||
|
||||
// Build the properties which will be updated
|
||||
RecordCategory recordCategoryUpdated = RecordCategory.builder().name(newCategoryName).build();
|
||||
|
||||
// Update the record category
|
||||
RecordCategory renamedRecordCategory = getRestAPIFactory().getRecordCategoryAPI().updateRecordCategory(recordCategoryUpdated, rootRecordCategory.getId());
|
||||
|
||||
// Verify the status code
|
||||
assertStatusCode(OK);
|
||||
|
||||
// Verify the returned file plan component
|
||||
assertEquals(renamedRecordCategory.getName(), newCategoryName);
|
||||
|
||||
// Get actual FILE_PLAN_ALIAS id
|
||||
FilePlan filePlan = getRestAPIFactory().getFilePlansAPI().getFilePlan(FILE_PLAN_ALIAS);
|
||||
|
||||
// verify renamed component still has this parent
|
||||
assertEquals(renamedRecordCategory.getParentId(), filePlan.getId());
|
||||
}
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* Given that a record category exists
|
||||
* When I ask the API to delete the record category
|
||||
* Then the record category and all its contents are deleted
|
||||
* </pre>
|
||||
*/
|
||||
@Test
|
||||
(
|
||||
description = "Delete category"
|
||||
)
|
||||
public void deleteCategory() throws Exception
|
||||
{
|
||||
// Create record category first
|
||||
String categoryName = "Category name " + getRandomAlphanumeric();
|
||||
String categoryTitle = "Category title " + getRandomAlphanumeric();
|
||||
|
||||
// Create the root record category
|
||||
RecordCategory rootRecordCategory = createRootCategory(categoryName, categoryTitle);
|
||||
|
||||
// Delete the record category
|
||||
RecordCategoryAPI recordCategoryAPI = getRestAPIFactory().getRecordCategoryAPI();
|
||||
String recordCategoryId = rootRecordCategory.getId();
|
||||
recordCategoryAPI.deleteRecordCategory(recordCategoryId);
|
||||
|
||||
// Verify the status code
|
||||
assertStatusCode(NO_CONTENT);
|
||||
|
||||
// Deleted component should no longer be retrievable
|
||||
recordCategoryAPI.getRecordCategory(recordCategoryId);
|
||||
assertStatusCode(NOT_FOUND);
|
||||
}
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* Given that a record category exists
|
||||
* When I ask the API to create a record category
|
||||
* Then it is created within the record category
|
||||
* </pre>
|
||||
*/
|
||||
@Test
|
||||
(
|
||||
description = "Create child category"
|
||||
)
|
||||
public void createSubcategory() throws Exception
|
||||
{
|
||||
// Create root level category
|
||||
RecordCategory rootCategory = createRootCategory(getRandomAlphanumeric());
|
||||
assertNotNull(rootCategory.getId());
|
||||
|
||||
// Create sub-category as a child of rootCategory
|
||||
RecordCategoryChild recordCategory = createRecordCategoryChild(rootCategory.getId(), RECORD_CATEGORY_NAME, RECORD_CATEGORY_TYPE);
|
||||
|
||||
// Child category created?
|
||||
assertNotNull(recordCategory.getId());
|
||||
|
||||
// Verify child category
|
||||
assertEquals(recordCategory.getParentId(), rootCategory.getId());
|
||||
assertTrue(recordCategory.getIsRecordCategory());
|
||||
assertFalse(recordCategory.getIsRecordFolder());
|
||||
assertEquals(recordCategory.getNodeType(), RECORD_CATEGORY_TYPE);
|
||||
}
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* Given that a record category exists
|
||||
* And contains a number of record categories and record folders
|
||||
* When I ask the API to get me the children of the record category
|
||||
* Then I am returned the contained record categories and record folders and their details
|
||||
* </pre>
|
||||
*/
|
||||
@Test
|
||||
(
|
||||
description = "Get children of a record category"
|
||||
)
|
||||
public void getRecordCategoryChildren() throws Exception
|
||||
{
|
||||
// Create root level category
|
||||
RecordCategory rootRecordCategory = createRootCategory(getRandomAlphanumeric());
|
||||
assertNotNull(rootRecordCategory.getId());
|
||||
|
||||
// Add record category children
|
||||
List<RecordCategoryChild> children = new ArrayList<RecordCategoryChild>();
|
||||
for (int i=0; i < NUMBER_OF_CHILDREN; i++)
|
||||
{
|
||||
// Create a record category child
|
||||
RecordCategoryChild child = createRecordCategoryChild(rootRecordCategory.getId(),
|
||||
getRandomAlphanumeric(),
|
||||
// half of the children should be sub-categories, the other sub-folders
|
||||
(i <= NUMBER_OF_CHILDREN / 2) ? RECORD_CATEGORY_TYPE : RECORD_FOLDER_TYPE);
|
||||
assertNotNull(child.getId());
|
||||
children.add(child);
|
||||
}
|
||||
|
||||
// Get children from API
|
||||
RecordCategoryChildCollection recordCategoryChildren = getRestAPIFactory().getRecordCategoryAPI().getRecordCategoryChildren(rootRecordCategory.getId(),"include=isRecordCategory,isRecordFolder");
|
||||
|
||||
// Check status code
|
||||
assertStatusCode(OK);
|
||||
logger.info("Parent: " + rootRecordCategory.getId());
|
||||
|
||||
// Check listed children against created list
|
||||
recordCategoryChildren.getEntries().forEach(c ->
|
||||
{
|
||||
RecordCategoryChild recordCategoryChild = c.getEntry();
|
||||
String recordCategoryChildId = recordCategoryChild.getId();
|
||||
|
||||
assertNotNull(recordCategoryChildId);
|
||||
logger.info("Checking child " + recordCategoryChildId);
|
||||
|
||||
try
|
||||
{
|
||||
// Find this child in created children list
|
||||
RecordCategoryChild createdComponent = children.stream()
|
||||
.filter(child -> child.getId().equals(recordCategoryChildId))
|
||||
.findFirst()
|
||||
.get();
|
||||
|
||||
// Created by
|
||||
assertEquals(recordCategoryChild.getCreatedByUser().getId(), getAdminUser().getUsername());
|
||||
|
||||
// Is parent id set correctly?
|
||||
assertEquals(recordCategoryChild.getParentId(), rootRecordCategory.getId());
|
||||
|
||||
// Boolean properties related to node type
|
||||
// Only RECORD_CATEGORY_TYPE and RECORD_FOLDER_TYPE have been created
|
||||
if (recordCategoryChild.getNodeType().equals(RECORD_CATEGORY_TYPE))
|
||||
{
|
||||
assertTrue(recordCategoryChild.getIsRecordCategory());
|
||||
assertFalse(recordCategoryChild.getIsRecordFolder());
|
||||
}
|
||||
else
|
||||
{
|
||||
assertTrue(recordCategoryChild.getIsRecordFolder());
|
||||
assertFalse(recordCategoryChild.getIsRecordCategory());
|
||||
}
|
||||
|
||||
// Does returned object have the same contents as the created one?
|
||||
assertEquals(createdComponent.getName(), recordCategoryChild.getName());
|
||||
assertEquals(createdComponent.getNodeType(), recordCategoryChild.getNodeType());
|
||||
|
||||
// FIXME: Verify properties
|
||||
assertNotNull(createdComponent.getProperties().getIdentifier());
|
||||
}
|
||||
catch (NoSuchElementException e)
|
||||
{
|
||||
fail("No child element for " + recordCategoryChildId);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* Given that a record category exists
|
||||
* When I ask to create an object type which is not a record category or a record folder as a child
|
||||
* Then the children are not created and the 422 response code is returned
|
||||
* </pre>
|
||||
*/
|
||||
@Test
|
||||
(
|
||||
description = "Create node types not allowed inside a category",
|
||||
dataProviderClass = TestData.class,
|
||||
dataProvider = "childrenNotAllowedForCategory"
|
||||
)
|
||||
@Bug (id="RM-4367, RM-4572")
|
||||
public void createTypesNotAllowedInCategory(String nodeType) throws Exception
|
||||
{
|
||||
String componentName = "Component" + getRandomAlphanumeric();
|
||||
|
||||
// Create the category
|
||||
RecordCategory rootRecordCategory = createRootCategory(componentName);
|
||||
|
||||
// Create the invalid node type
|
||||
createRecordCategoryChild(rootRecordCategory.getId(), componentName, nodeType);
|
||||
assertStatusCode(UNPROCESSABLE_ENTITY);
|
||||
}
|
||||
}
|
@@ -26,43 +26,51 @@
|
||||
*/
|
||||
package org.alfresco.rest.rm.community.fileplancomponents;
|
||||
|
||||
import static org.alfresco.rest.rm.community.base.TestData.CATEGORY_NAME;
|
||||
import static org.alfresco.rest.rm.community.base.TestData.FOLDER_NAME;
|
||||
import static org.alfresco.rest.rm.community.base.TestData.FOLDER_TITLE;
|
||||
import static java.time.LocalDateTime.now;
|
||||
import static org.alfresco.rest.rm.community.base.TestData.RECORD_CATEGORY_NAME;
|
||||
import static org.alfresco.rest.rm.community.base.TestData.RECORD_FOLDER_NAME;
|
||||
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentAlias.FILE_PLAN_ALIAS;
|
||||
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentAlias.TRANSFERS_ALIAS;
|
||||
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentFields.IS_CLOSED;
|
||||
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentFields.PATH;
|
||||
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.RECORD_CATEGORY_TYPE;
|
||||
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.RECORD_FOLDER_TYPE;
|
||||
import static org.alfresco.rest.rm.community.utils.FilePlanComponentsUtil.TITLE_PREFIX;
|
||||
import static org.alfresco.utility.data.RandomData.getRandomAlphanumeric;
|
||||
import static org.springframework.http.HttpStatus.BAD_REQUEST;
|
||||
import static org.springframework.http.HttpStatus.CREATED;
|
||||
import static org.springframework.http.HttpStatus.NOT_FOUND;
|
||||
import static org.springframework.http.HttpStatus.NO_CONTENT;
|
||||
import static org.springframework.http.HttpStatus.OK;
|
||||
import static org.springframework.http.HttpStatus.UNPROCESSABLE_ENTITY;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertFalse;
|
||||
import static org.testng.Assert.assertNotNull;
|
||||
import static org.testng.Assert.fail;
|
||||
import static org.testng.AssertJUnit.assertTrue;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
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.fileplancomponents.FilePlanComponent;
|
||||
import org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentProperties;
|
||||
import org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentReviewPeriod;
|
||||
import org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentsCollection;
|
||||
import org.alfresco.rest.rm.community.requests.igCoreAPI.FilePlanComponentAPI;
|
||||
import org.alfresco.rest.rm.community.model.common.ReviewPeriod;
|
||||
import org.alfresco.rest.rm.community.model.recordcategory.RecordCategory;
|
||||
import org.alfresco.rest.rm.community.model.recordcategory.RecordCategoryChild;
|
||||
import org.alfresco.rest.rm.community.model.recordcategory.RecordCategoryChildCollection;
|
||||
import org.alfresco.rest.rm.community.model.recordcategory.RecordCategoryChildProperties;
|
||||
import org.alfresco.rest.rm.community.model.recordfolder.RecordFolder;
|
||||
import org.alfresco.rest.rm.community.model.recordfolder.RecordFolderProperties;
|
||||
import org.alfresco.rest.rm.community.requests.gscore.api.FilePlanAPI;
|
||||
import org.alfresco.rest.rm.community.requests.gscore.api.RecordCategoryAPI;
|
||||
import org.alfresco.rest.rm.community.requests.gscore.api.RecordFolderAPI;
|
||||
import org.alfresco.utility.report.Bug;
|
||||
import org.testng.AssertJUnit;
|
||||
import org.testng.annotations.AfterClass;
|
||||
import org.testng.annotations.AfterMethod;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
/**
|
||||
* This class contains the tests for the
|
||||
* the Record Folder CRUD API
|
||||
* This class contains the tests for the Record Folder CRUD API
|
||||
*
|
||||
* @author Rodica Sutu
|
||||
* @since 2.6
|
||||
@@ -70,186 +78,185 @@ import org.testng.annotations.Test;
|
||||
public class RecordFolderTests extends BaseRMRestTest
|
||||
{
|
||||
private static final int NUMBER_OF_FOLDERS = 5;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* Given that a record category exists
|
||||
* When I use the API to create a new record folder
|
||||
* Then it is created within the record category
|
||||
*
|
||||
* </pre>
|
||||
* <pre>
|
||||
* Given that a record category exists
|
||||
* When I use the API to create a folder (cm:folder type)
|
||||
* Then the folder is converted to rma:recordFolder within the record category
|
||||
* (see RM-4572 comments)
|
||||
*
|
||||
* </pre>
|
||||
*/
|
||||
@Test
|
||||
(
|
||||
description = "Create a folder into a record category.",
|
||||
description = "Create a record folder into a record category.",
|
||||
dataProviderClass = TestData.class,
|
||||
dataProvider = "folderTypes"
|
||||
)
|
||||
@Bug (id = "RM-4572")
|
||||
public void createFolderTest(String folderType) throws Exception
|
||||
{
|
||||
String CATEGORY = CATEGORY_NAME + getRandomAlphanumeric();
|
||||
|
||||
// Authenticate with admin user
|
||||
FilePlanComponent filePlanComponent = createCategory(FILE_PLAN_ALIAS, CATEGORY);
|
||||
|
||||
FilePlanComponent recordFolder = FilePlanComponent.builder()
|
||||
.name(FOLDER_NAME)
|
||||
.nodeType(folderType)
|
||||
.properties(FilePlanComponentProperties.builder()
|
||||
.title(FOLDER_TITLE)
|
||||
.build())
|
||||
.build();
|
||||
RecordCategory rootRecordCategory = createRootCategory(RECORD_CATEGORY_NAME + getRandomAlphanumeric());
|
||||
|
||||
// Create the record folder
|
||||
FilePlanComponent folder = getRestAPIFactory().getFilePlanComponentsAPI().createFilePlanComponent(recordFolder, filePlanComponent.getId());
|
||||
RecordCategoryChild recordFolder = createRecordCategoryChild(rootRecordCategory.getId(), RECORD_FOLDER_NAME, folderType);
|
||||
|
||||
// Assert status code
|
||||
assertStatusCode(CREATED);
|
||||
|
||||
// Check folder has been created within the category created
|
||||
assertEquals(filePlanComponent.getId(),folder.getParentId());
|
||||
// Verify the returned properties for the file plan component - record folder
|
||||
assertFalse(folder.getIsCategory());
|
||||
assertFalse(folder.getIsFile());
|
||||
assertTrue(folder.getIsRecordFolder());
|
||||
// Check record folder has been created within the record category
|
||||
AssertJUnit.assertEquals(rootRecordCategory.getId(), recordFolder.getParentId());
|
||||
|
||||
assertEquals(folder.getName(), FOLDER_NAME);
|
||||
assertEquals(folder.getNodeType(), RECORD_FOLDER_TYPE);
|
||||
assertEquals(folder.getCreatedByUser().getId(), getAdminUser().getUsername());
|
||||
// Verify the returned values for the record folder
|
||||
assertFalse(recordFolder.getIsRecordCategory());
|
||||
assertTrue(recordFolder.getIsRecordFolder());
|
||||
AssertJUnit.assertEquals(recordFolder.getName(), RECORD_FOLDER_NAME);
|
||||
AssertJUnit.assertEquals(recordFolder.getNodeType(), RECORD_FOLDER_TYPE);
|
||||
AssertJUnit.assertEquals(recordFolder.getCreatedByUser().getId(), getAdminUser().getUsername());
|
||||
|
||||
// Verify the returned file plan component properties
|
||||
FilePlanComponentProperties folderProperties = folder.getProperties();
|
||||
assertEquals(folderProperties.getTitle(), FOLDER_TITLE);
|
||||
assertNotNull(folderProperties.getRmIdentifier());
|
||||
// Verify the returned record folder properties
|
||||
RecordCategoryChildProperties folderProperties = recordFolder.getProperties();
|
||||
AssertJUnit.assertEquals(folderProperties.getTitle(), TITLE_PREFIX + RECORD_FOLDER_NAME);
|
||||
assertNotNull(folderProperties.getIdentifier());
|
||||
}
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* Given that RM site is created
|
||||
* When I use the API to create a new record folder into transfers container/holds container/unfiled
|
||||
* When I use the API to create a new record folder into transfers/holds/unfiled containers
|
||||
* Then the operation fails
|
||||
* </pre>
|
||||
*/
|
||||
@Test
|
||||
(
|
||||
description = "Create a folder into hold/transfers/unfiled/file plan container",
|
||||
description = "Create a record folder into transfers/unfiled/file plan container",
|
||||
dataProviderClass = TestData.class,
|
||||
dataProvider = "getContainers"
|
||||
)
|
||||
@Bug(id="RM-4327")
|
||||
public void createFolderIntoSpecialContainers(String filePlanComponent) throws Exception
|
||||
public void createRecordFolderIntoSpecialContainers(String containerAlias) throws Exception
|
||||
{
|
||||
FilePlanComponentAPI filePlanComponentsAPI = getRestAPIFactory().getFilePlanComponentsAPI();
|
||||
String componentID = filePlanComponentsAPI.getFilePlanComponent(filePlanComponent).getId();
|
||||
|
||||
// Build the record category properties
|
||||
FilePlanComponent recordFolder = FilePlanComponent.builder()
|
||||
.name(FOLDER_NAME)
|
||||
.nodeType(RECORD_FOLDER_TYPE)
|
||||
.properties(FilePlanComponentProperties.builder()
|
||||
.title(FOLDER_TITLE)
|
||||
.build())
|
||||
.build();
|
||||
String containerId;
|
||||
if (FILE_PLAN_ALIAS.equalsIgnoreCase(containerAlias))
|
||||
{
|
||||
containerId = getRestAPIFactory().getFilePlansAPI().getFilePlan(containerAlias).getId();
|
||||
}
|
||||
else if(TRANSFERS_ALIAS.equalsIgnoreCase(containerAlias))
|
||||
{
|
||||
containerId = getRestAPIFactory().getTransferContainerAPI().getTransferContainer(containerAlias).getId();
|
||||
}
|
||||
else
|
||||
{
|
||||
//is unfiled container
|
||||
containerId = getRestAPIFactory().getUnfiledContainersAPI().getUnfiledContainer(containerAlias).getId();;
|
||||
}
|
||||
|
||||
// Create a record folder
|
||||
filePlanComponentsAPI.createFilePlanComponent(recordFolder, componentID);
|
||||
createRecordFolder(containerId, RECORD_FOLDER_NAME);
|
||||
|
||||
// Check the API Response code
|
||||
assertStatusCode(UNPROCESSABLE_ENTITY);
|
||||
assertStatusCode(BAD_REQUEST);
|
||||
}
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* Given that a record folder exists
|
||||
* When I ask for the details of a record folder
|
||||
* Then I am given the details of a record folder
|
||||
* </pre>
|
||||
*/
|
||||
@Test
|
||||
(
|
||||
description = "Check the details returned for a record folder"
|
||||
description = "Check the details of a record folder"
|
||||
)
|
||||
public void checkTheRecordFolderProperties() throws Exception
|
||||
public void checkRecordFolderDetails() throws Exception
|
||||
{
|
||||
String CATEGORY = CATEGORY_NAME + getRandomAlphanumeric();
|
||||
// Create a category
|
||||
RecordCategory rootRecordCategory = createRootCategory(RECORD_CATEGORY_NAME + getRandomAlphanumeric());
|
||||
|
||||
FilePlanComponent category = createCategory(FILE_PLAN_ALIAS, CATEGORY);
|
||||
FilePlanComponent folder = createFolder(category.getId(),FOLDER_NAME);
|
||||
// Create a folder
|
||||
RecordCategoryChild recordCategoryChild = createRecordFolder(rootRecordCategory.getId(), RECORD_FOLDER_NAME);
|
||||
|
||||
FilePlanComponent folderDetails = getRestAPIFactory().getFilePlanComponentsAPI().getFilePlanComponent(folder.getId(), "include=" + IS_CLOSED);
|
||||
// Get the folder including extra information
|
||||
RecordFolder recordFolder = getRestAPIFactory().getRecordFolderAPI().getRecordFolder(recordCategoryChild.getId(), "include=" + IS_CLOSED);
|
||||
|
||||
// Verify the returned properties for the file plan component - record folder
|
||||
assertEquals(RECORD_FOLDER_TYPE, folderDetails.getNodeType());
|
||||
assertTrue(folderDetails.getIsRecordFolder());
|
||||
assertFalse(folderDetails.getIsCategory());
|
||||
assertFalse(folderDetails.getIsFile());
|
||||
assertFalse(folderDetails.getIsClosed());
|
||||
|
||||
assertEquals(FOLDER_NAME,folderDetails.getName());
|
||||
assertEquals(getAdminUser().getUsername(),folderDetails.getCreatedByUser().getId());
|
||||
assertEquals(getAdminUser().getUsername(), folderDetails.getModifiedByUser().getId());
|
||||
assertEquals(FOLDER_TITLE,folderDetails.getProperties().getTitle());
|
||||
// Verify the returned record folder details
|
||||
AssertJUnit.assertEquals(recordFolder.getNodeType(), RECORD_FOLDER_TYPE);
|
||||
assertTrue(RECORD_FOLDER_TYPE.equals(recordFolder.getNodeType()));
|
||||
AssertJUnit.assertEquals(recordFolder.getName(), RECORD_FOLDER_NAME);
|
||||
AssertJUnit.assertEquals(recordFolder.getCreatedByUser().getId(), getAdminUser().getUsername());
|
||||
AssertJUnit.assertEquals(recordFolder.getModifiedByUser().getId(), getAdminUser().getUsername());
|
||||
AssertJUnit.assertEquals(recordFolder.getProperties().getTitle(), TITLE_PREFIX + RECORD_FOLDER_NAME);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* Given that a record folder exists
|
||||
* When I use the API to update its details
|
||||
* Then the details of the record folder are updated
|
||||
* The above test does treat any custom metadata
|
||||
* Note: the details of the record folder includes any custom meta-data
|
||||
* The above test does treat any custom metadata
|
||||
* Note: The details of the record folder includes any custom meta-data
|
||||
* </pre>
|
||||
*/
|
||||
@Test
|
||||
(
|
||||
description = "Update the details returned for a record folder"
|
||||
description = "Update the details of a record folder"
|
||||
)
|
||||
public void updateTheRecordFolderProperties() throws Exception
|
||||
public void updateRecordFolderDetails() throws Exception
|
||||
{
|
||||
String CATEGORY = CATEGORY_NAME + getRandomAlphanumeric();
|
||||
// Create a record category
|
||||
RecordCategory rootRecordCategory = createRootCategory(RECORD_CATEGORY_NAME + getRandomAlphanumeric());
|
||||
|
||||
//Create a record category
|
||||
FilePlanComponent category = createCategory(FILE_PLAN_ALIAS, CATEGORY);
|
||||
|
||||
//Create a record folder
|
||||
FilePlanComponent folder = createFolder(category.getId(), FOLDER_NAME);
|
||||
// Create a record folder
|
||||
RecordCategoryChild recordCategoryChild = createRecordFolder(rootRecordCategory.getId(), RECORD_FOLDER_NAME);
|
||||
|
||||
// Create record category first
|
||||
String folderDescription = "The folder description is updated" + getRandomAlphanumeric();
|
||||
String folderName = "The folder name is updated" + getRandomAlphanumeric();
|
||||
String folderTitle = "Update title " + getRandomAlphanumeric();
|
||||
String location = "Location"+getRandomAlphanumeric();
|
||||
String location = "Location "+ getRandomAlphanumeric();
|
||||
|
||||
//Create the file plan component properties to update
|
||||
FilePlanComponent recordFolder = FilePlanComponent.builder()
|
||||
.name(folderName)
|
||||
.properties(FilePlanComponentProperties.builder()
|
||||
.title(folderTitle)
|
||||
.description(folderDescription)
|
||||
.vitalRecord(true)
|
||||
.reviewPeriod(new FilePlanComponentReviewPeriod("month","1"))
|
||||
.location(location)
|
||||
.build())
|
||||
.build();
|
||||
// Create the record folder properties to update
|
||||
RecordFolder recordFolder = RecordFolder.builder()
|
||||
.name(folderName)
|
||||
.properties(RecordFolderProperties.builder()
|
||||
.title(folderTitle)
|
||||
.description(folderDescription)
|
||||
.vitalRecordIndicator(true)
|
||||
.reviewPeriod(new ReviewPeriod("month","1"))
|
||||
.location(location)
|
||||
.build())
|
||||
.build();
|
||||
|
||||
// Update the record category
|
||||
FilePlanComponent folderUpdated = getRestAPIFactory().getFilePlanComponentsAPI().updateFilePlanComponent(recordFolder, folder.getId());
|
||||
// Update the record folder
|
||||
RecordFolder updatedRecordFolder = getRestAPIFactory().getRecordFolderAPI().updateRecordFolder(recordFolder, recordCategoryChild.getId());
|
||||
|
||||
// Check the Response Status Code
|
||||
assertStatusCode(OK);
|
||||
|
||||
// Verify the returned properties for the file plan component - record folder
|
||||
assertEquals(folderName, folderUpdated.getName());
|
||||
assertEquals(folderDescription, folderUpdated.getProperties().getDescription());
|
||||
assertEquals(folderTitle, folderUpdated.getProperties().getTitle());
|
||||
assertTrue(folderUpdated.getProperties().getVitalRecord());
|
||||
assertEquals(location, folderUpdated.getProperties().getLocation());
|
||||
assertNotNull(folderUpdated.getProperties().getReviewPeriod().getPeriodType());
|
||||
assertNotNull(folderUpdated.getProperties().getReviewPeriod().getExpression());
|
||||
|
||||
// Verify the returned details for the record folder
|
||||
AssertJUnit.assertEquals(updatedRecordFolder.getName(), folderName);
|
||||
RecordFolderProperties recordFolderProperties = updatedRecordFolder.getProperties();
|
||||
AssertJUnit.assertEquals(recordFolderProperties.getDescription(), folderDescription);
|
||||
AssertJUnit.assertEquals(recordFolderProperties.getTitle(), folderTitle);
|
||||
assertTrue(recordFolderProperties.getVitalRecordIndicator());
|
||||
AssertJUnit.assertEquals(recordFolderProperties.getLocation(), location);
|
||||
assertNotNull(recordFolderProperties.getReviewPeriod().getPeriodType());
|
||||
assertNotNull(recordFolderProperties.getReviewPeriod().getExpression());
|
||||
}
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* Given that a record folder exists
|
||||
* When I use the API to delete the record folder
|
||||
* Then it deleted according to the normal rules governing the deletion of record folders
|
||||
* Then it is deleted according to the normal rules governing the deletion of record folders
|
||||
* </pre>
|
||||
*/
|
||||
@Test
|
||||
(
|
||||
@@ -257,95 +264,93 @@ public class RecordFolderTests extends BaseRMRestTest
|
||||
)
|
||||
public void deleteRecordFolder() throws Exception
|
||||
{
|
||||
String CATEGORY = CATEGORY_NAME + getRandomAlphanumeric();
|
||||
|
||||
// Create the record category
|
||||
FilePlanComponent category = createCategory(FILE_PLAN_ALIAS, CATEGORY);
|
||||
RecordCategory rootRecordCategory = createRootCategory(RECORD_CATEGORY_NAME + getRandomAlphanumeric());
|
||||
|
||||
// Create the record folder
|
||||
FilePlanComponent folder = createFolder(category.getId(), FOLDER_NAME);
|
||||
RecordCategoryChild recordFolder = createRecordFolder(rootRecordCategory.getId(), RECORD_FOLDER_NAME);
|
||||
|
||||
// Delete the Record folder
|
||||
FilePlanComponentAPI filePlanComponentsAPI = getRestAPIFactory().getFilePlanComponentsAPI();
|
||||
filePlanComponentsAPI.deleteFilePlanComponent(folder.getId());
|
||||
// Check the Response Status Code
|
||||
// Delete the record folder
|
||||
RecordFolderAPI recordFolderAPI = getRestAPIFactory().getRecordFolderAPI();
|
||||
String recordFolderId = recordFolder.getId();
|
||||
recordFolderAPI.deleteRecordFolder(recordFolderId);
|
||||
|
||||
// Check the response status code
|
||||
assertStatusCode(NO_CONTENT);
|
||||
|
||||
// Check the File Plan Component is not found
|
||||
filePlanComponentsAPI.getFilePlanComponent(folder.getId());
|
||||
// Check the Response Status Code
|
||||
// Check the record folder is not found
|
||||
recordFolderAPI.getRecordFolder(recordFolderId);
|
||||
|
||||
// Check the response status code
|
||||
assertStatusCode(NOT_FOUND);
|
||||
}
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* Given that a record category exists
|
||||
* And contains several record folders
|
||||
* When I use the APi to get the file plan component children for the existing category
|
||||
* Then I am provided with a list of the contained record folders
|
||||
* And their details
|
||||
* When I use the API to get the record category children for an existing record category
|
||||
* Then I am provided with a list of the contained record category children and their details
|
||||
* </pre>
|
||||
*/
|
||||
@Test
|
||||
(
|
||||
description = "List children of a category"
|
||||
description = "Get children of a record category"
|
||||
)
|
||||
public void listFolders() throws Exception
|
||||
public void getFolders() throws Exception
|
||||
{
|
||||
|
||||
String CATEGORY = CATEGORY_NAME + getRandomAlphanumeric();
|
||||
|
||||
// Authenticate with admin user
|
||||
FilePlanComponent category = createCategory(FILE_PLAN_ALIAS, CATEGORY);
|
||||
RecordCategory rootRecordCategory = createRootCategory(RECORD_CATEGORY_NAME + getRandomAlphanumeric());
|
||||
|
||||
// Add child olders
|
||||
ArrayList<FilePlanComponent> children = new ArrayList<FilePlanComponent>();
|
||||
// Add child folders
|
||||
ArrayList<RecordCategoryChild> children = new ArrayList<RecordCategoryChild>();
|
||||
for (int i = 0; i < NUMBER_OF_FOLDERS; i++)
|
||||
{
|
||||
// Create a child
|
||||
FilePlanComponent child = createFolder(category.getId(),
|
||||
getRandomAlphanumeric());
|
||||
assertNotNull(child.getId());
|
||||
children.add(child);
|
||||
// Create a record folder
|
||||
RecordCategoryChild recordCategoryChild = createRecordFolder(rootRecordCategory.getId(), getRandomAlphanumeric());
|
||||
assertNotNull(recordCategoryChild.getId());
|
||||
children.add(recordCategoryChild);
|
||||
}
|
||||
|
||||
// List children from API
|
||||
FilePlanComponentsCollection apiChildren = getRestAPIFactory().getFilePlanComponentsAPI().listChildComponents(category.getId());
|
||||
// Get record category children from API
|
||||
RecordCategoryChildCollection recordCategoryChildren = getRestAPIFactory().getRecordCategoryAPI().getRecordCategoryChildren(rootRecordCategory.getId(), "include=isRecordCategory,isRecordFolder");
|
||||
|
||||
// Check status code
|
||||
assertStatusCode(OK);
|
||||
|
||||
// Check listed children against created list
|
||||
apiChildren.getEntries().forEach(c ->
|
||||
// Check children against created list
|
||||
recordCategoryChildren.getEntries().forEach(c ->
|
||||
{
|
||||
FilePlanComponent filePlanComponent = c.getFilePlanComponentModel();
|
||||
assertNotNull(filePlanComponent.getId());
|
||||
logger.info("Checking child " + filePlanComponent.getId());
|
||||
RecordCategoryChild recordCategoryChild = c.getEntry();
|
||||
String recordCategoryChildId = recordCategoryChild.getId();
|
||||
assertNotNull(recordCategoryChildId);
|
||||
logger.info("Checking child " + recordCategoryChildId);
|
||||
|
||||
try
|
||||
{
|
||||
// Find this child in created children list
|
||||
FilePlanComponent createdComponent = children.stream()
|
||||
.filter(child -> child.getId().equals(filePlanComponent.getId()))
|
||||
RecordCategoryChild createdComponent = children.stream()
|
||||
.filter(child -> child.getId().equals(recordCategoryChildId))
|
||||
.findFirst()
|
||||
.get();
|
||||
|
||||
// Created by
|
||||
assertEquals(filePlanComponent.getCreatedByUser().getId(), getAdminUser().getUsername());
|
||||
assertEquals(recordCategoryChild.getCreatedByUser().getId(), getAdminUser().getUsername());
|
||||
|
||||
// Is parent Id set correctly
|
||||
assertEquals(filePlanComponent.getParentId(), category.getId());
|
||||
assertFalse(filePlanComponent.getIsFile());
|
||||
// Is parent id set correctly
|
||||
assertEquals(recordCategoryChild.getParentId(), rootRecordCategory.getId());
|
||||
|
||||
// Boolean properties related to node type
|
||||
assertTrue(filePlanComponent.getIsRecordFolder());
|
||||
assertFalse(filePlanComponent.getIsCategory());
|
||||
assertTrue(recordCategoryChild.getIsRecordFolder());
|
||||
assertFalse(recordCategoryChild.getIsRecordCategory());
|
||||
|
||||
assertEquals(createdComponent.getName(), filePlanComponent.getName());
|
||||
assertEquals(createdComponent.getNodeType(), filePlanComponent.getNodeType());
|
||||
assertEquals(createdComponent.getName(), recordCategoryChild.getName());
|
||||
assertEquals(createdComponent.getNodeType(), recordCategoryChild.getNodeType());
|
||||
|
||||
}
|
||||
catch (NoSuchElementException e)
|
||||
{
|
||||
fail("No child element for " + filePlanComponent.getId());
|
||||
fail("No child element for " + recordCategoryChildId);
|
||||
}
|
||||
}
|
||||
);
|
||||
@@ -353,92 +358,107 @@ public class RecordFolderTests extends BaseRMRestTest
|
||||
}
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* Given that I want to create a record folder
|
||||
* When I use the API with the relativePath
|
||||
* Then the categories specified in the relativePath that don't exist are created within the record folder
|
||||
*
|
||||
* Containers in the relativePath that do not exist are created before the node is created
|
||||
* Then the categories specified in the relativePath that don't exist are created
|
||||
* </pre>
|
||||
*/
|
||||
@Test
|
||||
(
|
||||
description = "Create a folder based on the relativePath. " +
|
||||
description = "Create a folder using record-categories endpoint, based on the relativePath. " +
|
||||
"Containers in the relativePath that do not exist are created before the node is created"
|
||||
)
|
||||
public void createFolderWithRelativePath() throws Exception
|
||||
public void createRecordFolderWithRelativePath() throws Exception
|
||||
{
|
||||
//RelativePath specify the container structure to create relative to the record folder to be created
|
||||
String relativePath = LocalDateTime.now().getYear() + "/" + LocalDateTime.now().getMonth() + "/" + LocalDateTime.now().getDayOfMonth();
|
||||
// The record category to be created
|
||||
RecordCategory recordCategoryModel = RecordCategory.builder()
|
||||
.name(RECORD_CATEGORY_NAME)
|
||||
.nodeType(RECORD_CATEGORY_TYPE)
|
||||
.build();
|
||||
FilePlanAPI filePlansAPI = getRestAPIFactory().getFilePlansAPI();
|
||||
RecordCategory createRootRecordCategory = filePlansAPI.createRootRecordCategory(recordCategoryModel, FILE_PLAN_ALIAS, "include=" + PATH);
|
||||
// Check the API response code
|
||||
assertStatusCode(CREATED);
|
||||
String recordCategoryId = createRootRecordCategory.getId();
|
||||
|
||||
//The record folder to be created
|
||||
FilePlanComponent recordFolder = FilePlanComponent.builder()
|
||||
.name(FOLDER_NAME)
|
||||
.nodeType(RECORD_FOLDER_TYPE)
|
||||
.relativePath(relativePath)
|
||||
.build();
|
||||
// relativePath specify the container structure to create relative to the record folder to be created
|
||||
String relativePath = now().getYear() + "/" + now().getMonth() + "/" + now().getDayOfMonth();
|
||||
|
||||
// The record folder to be created
|
||||
RecordCategoryChild recordFolderModel = RecordCategoryChild.builder()
|
||||
.name(RECORD_FOLDER_NAME)
|
||||
.nodeType(RECORD_FOLDER_TYPE)
|
||||
.relativePath(relativePath)
|
||||
.build();
|
||||
|
||||
// Create the record folder
|
||||
FilePlanComponentAPI filePlanComponentsAPI = getRestAPIFactory().getFilePlanComponentsAPI();
|
||||
FilePlanComponent folder = filePlanComponentsAPI.createFilePlanComponent(recordFolder, FILE_PLAN_ALIAS, "include=" + PATH);
|
||||
//Check the API response code
|
||||
RecordCategoryAPI recordCategoryAPI = getRestAPIFactory().getRecordCategoryAPI();
|
||||
RecordCategoryChild recordCategoryChild = recordCategoryAPI.createRecordCategoryChild(recordFolderModel, recordCategoryId, "include=" + PATH);
|
||||
|
||||
// Check the API response code
|
||||
assertStatusCode(CREATED);
|
||||
|
||||
// Verify the returned properties for the file plan component - record folder
|
||||
assertFalse(folder.getIsCategory());
|
||||
assertFalse(folder.getIsFile());
|
||||
assertTrue(folder.getIsRecordFolder());
|
||||
// Verify the returned details for the record folder
|
||||
assertFalse(recordCategoryChild.getIsRecordCategory());
|
||||
assertTrue(recordCategoryChild.getIsRecordFolder());
|
||||
|
||||
//Check the path return contains the RELATIVE_PATH
|
||||
assertTrue(folder.getPath().getName().contains(relativePath));
|
||||
//check the parent is a category
|
||||
assertTrue(filePlanComponentsAPI.getFilePlanComponent(folder.getParentId()).getIsCategory());
|
||||
// Check the path return contains the relativePath
|
||||
AssertJUnit.assertTrue(recordCategoryChild.getPath().getName().contains(relativePath));
|
||||
|
||||
//check the created folder from the server
|
||||
folder = filePlanComponentsAPI.getFilePlanComponent(folder.getId(), "include=" + PATH);
|
||||
//Check the API response code
|
||||
// Check the parent is a category
|
||||
assertNotNull(recordCategoryAPI.getRecordCategory(recordCategoryChild.getParentId()).getId());
|
||||
|
||||
// Check the created folder from the server
|
||||
RecordFolderAPI recordFolderAPI = getRestAPIFactory().getRecordFolderAPI();
|
||||
RecordFolder recordFolder = recordFolderAPI.getRecordFolder(recordCategoryChild.getId(), "include=" + PATH);
|
||||
|
||||
// Check the API response code
|
||||
assertStatusCode(OK);
|
||||
// Verify the returned properties for the file plan component - record folder
|
||||
assertFalse(folder.getIsCategory());
|
||||
assertFalse(folder.getIsFile());
|
||||
assertTrue(folder.getIsRecordFolder());
|
||||
|
||||
//Check the path return contains the RELATIVE_PATH
|
||||
assertTrue(folder.getPath().getName().contains(relativePath));
|
||||
// Verify the returned details for the record folder
|
||||
assertTrue(RECORD_FOLDER_TYPE.equals(recordFolder.getNodeType()));
|
||||
|
||||
//New Relative Path only a part of containers need to be created before the record folder
|
||||
String NEW_RELATIVE_PATH = LocalDateTime.now().getYear() + "/" + LocalDateTime.now().getMonth() + "/" + (LocalDateTime.now().getDayOfMonth() + 1);
|
||||
//The record folder to be created
|
||||
FilePlanComponent recordFolder2 = FilePlanComponent.builder()
|
||||
.name(FOLDER_NAME)
|
||||
.nodeType(RECORD_FOLDER_TYPE)
|
||||
.relativePath(NEW_RELATIVE_PATH)
|
||||
.build();
|
||||
// Check the path return contains the relativePath
|
||||
AssertJUnit.assertTrue(recordFolder.getPath().getName().contains(relativePath));
|
||||
|
||||
// New relative path only a part of containers need to be created before the record folder
|
||||
String newRelativePath = now().getYear() + "/" + now().getMonth() + "/" + (now().getDayOfMonth() + 1);
|
||||
|
||||
// The record folder to be created
|
||||
RecordCategoryChild newRecordFolderModel = RecordCategoryChild.builder()
|
||||
.name(RECORD_FOLDER_NAME)
|
||||
.nodeType(RECORD_FOLDER_TYPE)
|
||||
.relativePath(newRelativePath)
|
||||
.build();
|
||||
|
||||
// Create the record folder
|
||||
FilePlanComponent folder2 = filePlanComponentsAPI.createFilePlanComponent(recordFolder2, FILE_PLAN_ALIAS, "include=" + PATH);
|
||||
//Check the API response code
|
||||
RecordCategoryChild newRecordCategoryChild = recordCategoryAPI.createRecordCategoryChild(newRecordFolderModel, recordCategoryId, "include=" + PATH);
|
||||
|
||||
// Check the API response code
|
||||
assertStatusCode(CREATED);
|
||||
|
||||
// Verify the returned properties for the file plan component - record folder
|
||||
assertFalse(folder2.getIsCategory());
|
||||
assertFalse(folder2.getIsFile());
|
||||
assertTrue(folder2.getIsRecordFolder());
|
||||
//Check the path return contains the NEW_RELATIVE_PATH
|
||||
assertTrue(folder2.getPath().getName().contains(NEW_RELATIVE_PATH));
|
||||
assertFalse(newRecordCategoryChild.getIsRecordCategory());
|
||||
assertTrue(newRecordCategoryChild.getIsRecordFolder());
|
||||
|
||||
//check the parent is a category
|
||||
assertTrue(filePlanComponentsAPI.getFilePlanComponent(folder.getParentId()).getIsCategory());
|
||||
// Check the path return contains the newRelativePath
|
||||
AssertJUnit.assertTrue(newRecordCategoryChild.getPath().getName().contains(newRelativePath));
|
||||
|
||||
// Check the parent is a category
|
||||
assertNotNull(recordCategoryAPI.getRecordCategory(newRecordCategoryChild.getParentId()).getId());
|
||||
|
||||
// Check the folder created on the server
|
||||
folder2 = filePlanComponentsAPI.getFilePlanComponent(folder2.getId(), "include=" + PATH);
|
||||
//Check the API response code
|
||||
RecordFolder newRecordFolder = recordFolderAPI.getRecordFolder(newRecordCategoryChild.getId(), "include=" + PATH);
|
||||
|
||||
// Check the API response code
|
||||
assertStatusCode(OK);
|
||||
|
||||
// Verify the returned properties for the file plan component - record folder
|
||||
assertFalse(folder2.getIsCategory());
|
||||
assertFalse(folder2.getIsFile());
|
||||
assertTrue(folder2.getIsRecordFolder());
|
||||
//Check the path return contains the NEW_RELATIVE_PATH
|
||||
assertTrue(folder2.getPath().getName().contains(NEW_RELATIVE_PATH));
|
||||
// Verify the returned details for the record folder
|
||||
assertTrue(RECORD_FOLDER_TYPE.equals(recordFolder.getNodeType()));
|
||||
|
||||
// Check the path return contains the newRelativePath
|
||||
AssertJUnit.assertTrue(newRecordFolder.getPath().getName().contains(newRelativePath));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -454,55 +474,57 @@ public class RecordFolderTests extends BaseRMRestTest
|
||||
public void openClosedRecordFolder() throws Exception
|
||||
{
|
||||
// Create a record folder
|
||||
FilePlanComponent recordFolder = createCategoryFolderInFilePlan();
|
||||
RecordCategoryChild recordFolder = createCategoryFolderInFilePlan();
|
||||
|
||||
// Assert that the record folder is not closed
|
||||
assertFalse(recordFolder.getProperties().getIsClosed());
|
||||
|
||||
// Get the file plan component API
|
||||
FilePlanComponentAPI filePlanComponentsAPI = getRestAPIFactory().getFilePlanComponentsAPI();
|
||||
// Get the record folder API
|
||||
RecordFolderAPI recordFolderAPI = getRestAPIFactory().getRecordFolderAPI();
|
||||
|
||||
// Create a record folder model to close it
|
||||
FilePlanComponent recordFolderModel = FilePlanComponent.builder()
|
||||
.properties(FilePlanComponentProperties.builder()
|
||||
.isClosed(true)
|
||||
.build())
|
||||
.build();
|
||||
RecordFolder recordFolderModel = RecordFolder.builder()
|
||||
.properties(RecordFolderProperties.builder()
|
||||
.isClosed(true)
|
||||
.build())
|
||||
.build();
|
||||
|
||||
// Make a request to close the record folder
|
||||
FilePlanComponent updatedRecordFolder = filePlanComponentsAPI.updateFilePlanComponent(recordFolderModel, recordFolder.getId());
|
||||
RecordFolder updatedRecordFolder = recordFolderAPI.updateRecordFolder(recordFolderModel, recordFolder.getId());
|
||||
|
||||
//FIXME - remove this workaround after RM-4921 is fixed.
|
||||
updatedRecordFolder = recordFolderAPI.getRecordFolder(updatedRecordFolder.getId());
|
||||
|
||||
// Verify that the record folder is closed now
|
||||
assertTrue(updatedRecordFolder.getProperties().getIsClosed());
|
||||
|
||||
// Create a record folder model to reopen it
|
||||
recordFolderModel = FilePlanComponent.builder()
|
||||
.properties(FilePlanComponentProperties.builder()
|
||||
.isClosed(false)
|
||||
.build())
|
||||
.build();
|
||||
recordFolderModel = RecordFolder.builder()
|
||||
.properties(RecordFolderProperties.builder()
|
||||
.isClosed(false)
|
||||
.build())
|
||||
.build();
|
||||
|
||||
// Make a request to reopen the record folder
|
||||
updatedRecordFolder = filePlanComponentsAPI.updateFilePlanComponent(recordFolderModel, recordFolder.getId());
|
||||
updatedRecordFolder = recordFolderAPI.updateRecordFolder(recordFolderModel, recordFolder.getId());
|
||||
|
||||
//FIXME - remove this workaround after RM-4921 is fixed.
|
||||
updatedRecordFolder = recordFolderAPI.getRecordFolder(updatedRecordFolder.getId());
|
||||
|
||||
// Verify that the record folder is open now
|
||||
assertFalse(updatedRecordFolder.getProperties().getIsClosed());
|
||||
}
|
||||
|
||||
@AfterMethod
|
||||
@AfterClass (alwaysRun = true)
|
||||
public void tearDown() throws Exception
|
||||
{
|
||||
FilePlanComponentAPI filePlanComponentsAPI = getRestAPIFactory().getFilePlanComponentsAPI();
|
||||
filePlanComponentsAPI.listChildComponents(FILE_PLAN_ALIAS).getEntries().forEach(filePlanComponentEntry ->
|
||||
FilePlanAPI filePlansAPI = getRestAPIFactory().getFilePlansAPI();
|
||||
RecordCategoryAPI recordCategoryAPI = getRestAPIFactory().getRecordCategoryAPI();
|
||||
|
||||
filePlansAPI.getRootRecordCategories(FILE_PLAN_ALIAS).getEntries().forEach(recordCategoryEntry ->
|
||||
{
|
||||
try
|
||||
{
|
||||
filePlanComponentsAPI.deleteFilePlanComponent(filePlanComponentEntry.getFilePlanComponentModel().getId());
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
recordCategoryAPI.deleteRecordCategory(recordCategoryEntry.getEntry().getId());
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,353 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Records Management Module
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2017 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* -
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
* -
|
||||
* Alfresco is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
* -
|
||||
* Alfresco is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
* -
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
* #L%
|
||||
*/
|
||||
package org.alfresco.rest.rm.community.fileplancomponents;
|
||||
|
||||
import static java.time.LocalDateTime.now;
|
||||
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentAlias.FILE_PLAN_ALIAS;
|
||||
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentAlias.UNFILED_RECORDS_CONTAINER_ALIAS;
|
||||
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.CONTENT_TYPE;
|
||||
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.NON_ELECTRONIC_RECORD_TYPE;
|
||||
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.UNFILED_CONTAINER_TYPE;
|
||||
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.UNFILED_RECORD_FOLDER_TYPE;
|
||||
import static org.alfresco.utility.data.RandomData.getRandomAlphanumeric;
|
||||
import static org.springframework.http.HttpStatus.BAD_REQUEST;
|
||||
import static org.springframework.http.HttpStatus.OK;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertFalse;
|
||||
import static org.testng.Assert.assertNotNull;
|
||||
import static org.testng.Assert.assertTrue;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.NoSuchElementException;
|
||||
|
||||
import org.alfresco.rest.rm.community.base.BaseRMRestTest;
|
||||
import org.alfresco.rest.rm.community.model.fileplan.FilePlan;
|
||||
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;
|
||||
import org.alfresco.rest.rm.community.requests.gscore.api.UnfiledContainerAPI;
|
||||
import org.testng.annotations.AfterClass;
|
||||
import org.testng.annotations.AfterMethod;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
/**
|
||||
* Unfiled container related API tests
|
||||
*
|
||||
* @author Ana Bozianu
|
||||
* @since 2.6
|
||||
*/
|
||||
public class UnfiledContainerTests extends BaseRMRestTest
|
||||
{
|
||||
/** Number of children (for children creation test) */
|
||||
private static final int NUMBER_OF_CHILDREN = 10;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* Given the RM site exists
|
||||
* When I retrieve the unfiled record conteiner by placeholder
|
||||
* Then the details of the unfiled record container is returned
|
||||
* </pre>
|
||||
*/
|
||||
@Test
|
||||
(
|
||||
description = "Get the unfiled records container"
|
||||
)
|
||||
public void getUnfiledRecordsContainer() throws Exception
|
||||
{
|
||||
// Get the unfiled records container
|
||||
UnfiledContainer container = getRestAPIFactory().getUnfiledContainersAPI().getUnfiledContainer(UNFILED_RECORDS_CONTAINER_ALIAS);
|
||||
|
||||
// Check the response code
|
||||
assertStatusCode(OK);
|
||||
|
||||
// Check the response contains the right node type
|
||||
assertEquals(container.getNodeType(), UNFILED_CONTAINER_TYPE);
|
||||
}
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* Given that an unfiled container exists
|
||||
* When I ask the API to update the details of the unfiled container
|
||||
* Then the details of the unfiled container are updated
|
||||
* </pre>
|
||||
*/
|
||||
@Test
|
||||
(
|
||||
description = "Rename unfiled container"
|
||||
)
|
||||
public void renameUnfiledContainer() throws Exception
|
||||
{
|
||||
String newContainerName = "RenamedUnfiledContainer (" + getRandomAlphanumeric() + ")";
|
||||
|
||||
// Build the properties which will be updated
|
||||
UnfiledContainer unfiledContainerUpdate = UnfiledContainer.builder().name(newContainerName).build();
|
||||
|
||||
// Update the unfiled records container
|
||||
UnfiledContainer renamedUnfiledContainer = getRestAPIFactory().getUnfiledContainersAPI().updateUnfiledContainer(unfiledContainerUpdate, UNFILED_RECORDS_CONTAINER_ALIAS);
|
||||
|
||||
// Verify the status code
|
||||
assertStatusCode(OK);
|
||||
|
||||
// Verify the returned unfiled records container
|
||||
assertEquals(renamedUnfiledContainer.getName(), newContainerName);
|
||||
|
||||
// Get actual FILE_PLAN_ALIAS id
|
||||
FilePlan filePlan = getRestAPIFactory().getFilePlansAPI().getFilePlan(FILE_PLAN_ALIAS);
|
||||
|
||||
// verify renamed component still has this parent
|
||||
assertEquals(renamedUnfiledContainer.getParentId(), filePlan.getId());
|
||||
}
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* Given that an unfiled records container exists
|
||||
* When I ask the API to create a child unfiled record folder
|
||||
* Then it is created within the unfiled records container
|
||||
* </pre>
|
||||
*/
|
||||
@Test
|
||||
(
|
||||
description = "Create unfiled record folder child in unfiled root container"
|
||||
)
|
||||
public void createUnfiledRecordFolderChild() throws Exception
|
||||
{
|
||||
String unfiledRecordFolderName = "UnfiledRecordFolder-" + getRandomAlphanumeric();
|
||||
UnfiledContainerChild unfiledRecordFolder = createUnfiledContainerChild(UNFILED_RECORDS_CONTAINER_ALIAS, unfiledRecordFolderName, UNFILED_RECORD_FOLDER_TYPE);
|
||||
|
||||
assertNotNull(unfiledRecordFolder.getId());
|
||||
UnfiledContainer container = getRestAPIFactory().getUnfiledContainersAPI().getUnfiledContainer(UNFILED_RECORDS_CONTAINER_ALIAS);
|
||||
assertEquals(unfiledRecordFolder.getParentId(), container.getId());
|
||||
assertFalse(unfiledRecordFolder.getIsRecord());
|
||||
assertEquals(unfiledRecordFolder.getNodeType(), UNFILED_RECORD_FOLDER_TYPE);
|
||||
}
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* Given that an unfiled records container exists
|
||||
* When I ask the API to create a child unfiled record folder with relative path
|
||||
* Then it is not supported
|
||||
* </pre>
|
||||
*/
|
||||
@Test
|
||||
(
|
||||
description = "Create unfiled record folder child in unfiled root container"
|
||||
)
|
||||
public void createUnfiledRecordFolderChildWithRealtivePathNotSuported() throws Exception
|
||||
{
|
||||
UnfiledContainerAPI unfiledContainerAPI = getRestAPIFactory().getUnfiledContainersAPI();
|
||||
// relativePath specify the container structure to create relative to
|
||||
// the record folder to be created
|
||||
String relativePath = now().getYear() + "/" + now().getMonth() + "/" + now().getDayOfMonth();
|
||||
|
||||
String unfiledRecordFolderName = "UnfiledRecordFolder-" + getRandomAlphanumeric();
|
||||
|
||||
UnfiledContainerChild unfiledFolderModel = UnfiledContainerChild.builder()
|
||||
.name(unfiledRecordFolderName)
|
||||
.nodeType(UNFILED_RECORD_FOLDER_TYPE)
|
||||
.relativePath(relativePath)
|
||||
.build();
|
||||
unfiledContainerAPI.createUnfiledContainerChild(unfiledFolderModel, UNFILED_RECORDS_CONTAINER_ALIAS);
|
||||
|
||||
// Check the API response code
|
||||
assertStatusCode(BAD_REQUEST);
|
||||
}
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* Given that an unfiled records container exists
|
||||
* When I ask the API to create a child record
|
||||
* Then it is created within the unfiled records container
|
||||
* </pre>
|
||||
*/
|
||||
@Test
|
||||
(
|
||||
description = "Create record child in unfiled root container"
|
||||
)
|
||||
public void createNonElectronicRecordChild() throws Exception
|
||||
{
|
||||
String recordName = "NERecord-" + getRandomAlphanumeric();
|
||||
UnfiledContainerChild unfiledRecord = createUnfiledContainerChild(UNFILED_RECORDS_CONTAINER_ALIAS, recordName, NON_ELECTRONIC_RECORD_TYPE);
|
||||
|
||||
assertNotNull(unfiledRecord.getId());
|
||||
assertTrue(unfiledRecord.getIsRecord());
|
||||
assertEquals(unfiledRecord.getNodeType(), NON_ELECTRONIC_RECORD_TYPE);
|
||||
// check it was created in the unfiled root container
|
||||
UnfiledContainer container = getRestAPIFactory().getUnfiledContainersAPI().getUnfiledContainer(UNFILED_RECORDS_CONTAINER_ALIAS);
|
||||
assertEquals(unfiledRecord.getParentId(), container.getId());
|
||||
// check the name contains the identifier
|
||||
String identifier = unfiledRecord.getProperties().getIdentifier();
|
||||
assertNotNull(identifier);
|
||||
assertEquals(unfiledRecord.getName(), recordName + " (" + identifier + ")");
|
||||
}
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* Given that an unfiled records container exists
|
||||
* When I ask the API to create a child record
|
||||
* Then it is created within the unfiled records container
|
||||
* </pre>
|
||||
*/
|
||||
@Test
|
||||
(
|
||||
description = "Create electronic record child in unfiled root container"
|
||||
)
|
||||
public void createElectronicRecordChild() throws Exception
|
||||
{
|
||||
String recordName = "ERecord-" + getRandomAlphanumeric();
|
||||
UnfiledContainerChild unfiledRecord = createUnfiledContainerChild(UNFILED_RECORDS_CONTAINER_ALIAS, recordName, CONTENT_TYPE);
|
||||
|
||||
assertNotNull(unfiledRecord.getId());
|
||||
assertTrue(unfiledRecord.getIsRecord());
|
||||
assertEquals(unfiledRecord.getNodeType(), CONTENT_TYPE);
|
||||
// check it was created in the unfiled root container
|
||||
UnfiledContainer container = getRestAPIFactory().getUnfiledContainersAPI().getUnfiledContainer(UNFILED_RECORDS_CONTAINER_ALIAS);
|
||||
assertEquals(unfiledRecord.getParentId(), container.getId());
|
||||
// check the name contains the identifier
|
||||
String identifier = unfiledRecord.getProperties().getIdentifier();
|
||||
assertNotNull(identifier);
|
||||
assertEquals(unfiledRecord.getName(), recordName + " (" + identifier + ")");
|
||||
}
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* Given the RM site is created
|
||||
* And contains a number of records and unfiled record folders
|
||||
* When I ask the API to get me the children of the unfiled root container
|
||||
* Then I am returned the contained record and unfiled record folders
|
||||
* </pre>
|
||||
*/
|
||||
@Test
|
||||
(
|
||||
description = "Get children of the root unfiled root container"
|
||||
)
|
||||
public void getUnfiledRootContainerChildren() throws Exception
|
||||
{
|
||||
// Add unfiled root container children
|
||||
List<UnfiledContainerChild> createdChildren = new LinkedList<>();
|
||||
for (int i=0; i < NUMBER_OF_CHILDREN; i++)
|
||||
{
|
||||
String childType;
|
||||
if (i % 3 == 0)
|
||||
{
|
||||
childType = CONTENT_TYPE;
|
||||
}
|
||||
else if (i % 3 == 1)
|
||||
{
|
||||
childType = NON_ELECTRONIC_RECORD_TYPE;
|
||||
}
|
||||
else
|
||||
{
|
||||
childType = UNFILED_RECORD_FOLDER_TYPE;
|
||||
}
|
||||
UnfiledContainerChild child = createUnfiledContainerChild(UNFILED_RECORDS_CONTAINER_ALIAS, getRandomAlphanumeric(), childType);
|
||||
assertNotNull(child.getId());
|
||||
createdChildren.add(child);
|
||||
}
|
||||
|
||||
// Get children from API
|
||||
UnfiledContainerChildCollection listedChildren = getRestAPIFactory().getUnfiledContainersAPI().getUnfiledContainerChildren(UNFILED_RECORDS_CONTAINER_ALIAS);
|
||||
|
||||
// Check status code
|
||||
assertStatusCode(OK);
|
||||
|
||||
// Check listed children contains created list
|
||||
UnfiledContainer unfiledContainer = getRestAPIFactory().getUnfiledContainersAPI().getUnfiledContainer(UNFILED_RECORDS_CONTAINER_ALIAS);
|
||||
List<UnfiledContainerChild> verifiedChildren = new LinkedList<>();
|
||||
listedChildren.getEntries().forEach(c ->
|
||||
{
|
||||
UnfiledContainerChild containerChild = c.getEntry();
|
||||
String childId = containerChild.getId();
|
||||
|
||||
assertNotNull(childId);
|
||||
logger.info("Checking child " + childId);
|
||||
|
||||
try
|
||||
{
|
||||
// Get the element from the created children list
|
||||
UnfiledContainerChild createdComponent = createdChildren.stream()
|
||||
.filter(child -> child.getId().equals(childId))
|
||||
.findFirst()
|
||||
.get();
|
||||
|
||||
// Created by
|
||||
assertEquals(containerChild.getCreatedByUser().getId(), getAdminUser().getUsername());
|
||||
|
||||
// Is parent id set correctly?
|
||||
assertEquals(containerChild.getParentId(), unfiledContainer.getId());
|
||||
|
||||
// Boolean properties related to node type
|
||||
if (containerChild.getNodeType().equals(UNFILED_RECORD_FOLDER_TYPE))
|
||||
{
|
||||
assertFalse(containerChild.getIsRecord());
|
||||
}
|
||||
else
|
||||
{
|
||||
assertTrue(containerChild.getIsRecord());
|
||||
}
|
||||
|
||||
// Does returned object have the same contents as the created one?
|
||||
assertEquals(createdComponent.getName(), containerChild.getName());
|
||||
assertEquals(createdComponent.getNodeType(), containerChild.getNodeType());
|
||||
|
||||
// FIXME: Verify properties
|
||||
assertNotNull(createdComponent.getProperties().getIdentifier());
|
||||
|
||||
// add the element to the matched children list
|
||||
verifiedChildren.add(createdComponent);
|
||||
}
|
||||
catch (NoSuchElementException e)
|
||||
{
|
||||
// the element was not created in this test, continue
|
||||
}
|
||||
});
|
||||
|
||||
// check all the created elements have been returned
|
||||
assertTrue(verifiedChildren.containsAll(createdChildren));
|
||||
assertTrue(createdChildren.containsAll(verifiedChildren));
|
||||
}
|
||||
|
||||
@AfterMethod
|
||||
@AfterClass (alwaysRun = true)
|
||||
public void tearDown() throws Exception
|
||||
{
|
||||
UnfiledContainerChildCollection listedChildren = getRestAPIFactory().getUnfiledContainersAPI()
|
||||
.getUnfiledContainerChildren(UNFILED_RECORDS_CONTAINER_ALIAS);
|
||||
|
||||
listedChildren.getEntries().forEach(UnfiledContainerChildEntry ->
|
||||
{
|
||||
if (UnfiledContainerChildEntry.getEntry().getIsRecord())
|
||||
{
|
||||
getRestAPIFactory().getRecordsAPI().deleteRecord(UnfiledContainerChildEntry.getEntry().getId());
|
||||
}
|
||||
else
|
||||
{
|
||||
getRestAPIFactory().getUnfiledRecordFoldersAPI().deleteUnfiledRecordFolder(UnfiledContainerChildEntry.getEntry().getId());
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
@@ -26,15 +26,18 @@
|
||||
*/
|
||||
package org.alfresco.rest.rm.community.fileplancomponents;
|
||||
|
||||
import static java.time.LocalDateTime.now;
|
||||
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentAlias.UNFILED_RECORDS_CONTAINER_ALIAS;
|
||||
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentFields.PATH;
|
||||
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.CONTENT_TYPE;
|
||||
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.FILE_PLAN_TYPE;
|
||||
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.HOLD_CONTAINER_TYPE;
|
||||
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.HOLD_TYPE;
|
||||
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.NON_ELECTRONIC_RECORD_TYPE;
|
||||
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.RECORD_CATEGORY_TYPE;
|
||||
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.RECORD_FOLDER_TYPE;
|
||||
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.TRANSFER_CONTAINER_TYPE;
|
||||
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.UNFILED_CONTAINER_TYPE;
|
||||
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.UNFILED_RECORD_FOLDER_TYPE;
|
||||
import static org.alfresco.rest.rm.community.utils.FilePlanComponentsUtil.createUnfiledContainerChildModel;
|
||||
import static org.alfresco.utility.data.RandomData.getRandomAlphanumeric;
|
||||
import static org.springframework.http.HttpStatus.CREATED;
|
||||
import static org.springframework.http.HttpStatus.NOT_FOUND;
|
||||
@@ -43,16 +46,20 @@ import static org.springframework.http.HttpStatus.OK;
|
||||
import static org.springframework.http.HttpStatus.UNPROCESSABLE_ENTITY;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertFalse;
|
||||
import static org.testng.Assert.assertNotNull;
|
||||
import static org.testng.Assert.assertTrue;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.alfresco.rest.rm.community.base.BaseRMRestTest;
|
||||
import org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponent;
|
||||
import org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentProperties;
|
||||
import org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentsCollection;
|
||||
import org.alfresco.rest.rm.community.requests.igCoreAPI.FilePlanComponentAPI;
|
||||
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.UnfiledContainerChildProperties;
|
||||
import org.alfresco.rest.rm.community.model.unfiledcontainer.UnfiledRecordFolder;
|
||||
import org.alfresco.rest.rm.community.utils.FilePlanComponentsUtil;
|
||||
import org.testng.annotations.AfterClass;
|
||||
import org.testng.annotations.AfterMethod;
|
||||
import org.testng.annotations.DataProvider;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
@@ -67,15 +74,13 @@ public class UnfiledRecordsFolderTests extends BaseRMRestTest
|
||||
/** invalid root level types, at unfiled records root level these shouldn't be possible to create */
|
||||
|
||||
@DataProvider(name = "invalidRootTypes")
|
||||
public Object[][] createData1()
|
||||
public String[][] createData()
|
||||
{
|
||||
return new Object[][]
|
||||
return new String[][]
|
||||
{
|
||||
{ FILE_PLAN_TYPE },
|
||||
{ RECORD_CATEGORY_TYPE },
|
||||
{ RECORD_FOLDER_TYPE },
|
||||
{ HOLD_TYPE },
|
||||
{ HOLD_CONTAINER_TYPE },
|
||||
{ TRANSFER_CONTAINER_TYPE },
|
||||
{ UNFILED_CONTAINER_TYPE }
|
||||
};
|
||||
@@ -91,70 +96,140 @@ public class UnfiledRecordsFolderTests extends BaseRMRestTest
|
||||
@Test(description = "Create root unfiled records folder")
|
||||
public void createRootUnfiledRecordsFolder() throws Exception
|
||||
{
|
||||
String folderName = "Folder " + getRandomAlphanumeric();
|
||||
String folderTitle = folderName + " Title";
|
||||
String folderDescription = folderName + " Description";
|
||||
String unfiledRecordFolderName = "UnfiledRecordFolder-" + getRandomAlphanumeric();
|
||||
UnfiledContainerChild unfiledRecordFolderChild = createUnfiledContainerChild(UNFILED_RECORDS_CONTAINER_ALIAS, unfiledRecordFolderName, UNFILED_RECORD_FOLDER_TYPE);
|
||||
|
||||
// Build unfiled records folder properties
|
||||
FilePlanComponent unfiledFolder = FilePlanComponent.builder()
|
||||
.name(folderName)
|
||||
.nodeType(UNFILED_RECORD_FOLDER_TYPE)
|
||||
.properties(FilePlanComponentProperties.builder()
|
||||
.title(folderTitle)
|
||||
.description(folderDescription)
|
||||
.build())
|
||||
.build();
|
||||
|
||||
FilePlanComponent filePlanComponent = getRestAPIFactory().getFilePlanComponentsAPI().createFilePlanComponent(unfiledFolder, UNFILED_RECORDS_CONTAINER_ALIAS);
|
||||
|
||||
// Verify the status code
|
||||
assertStatusCode(CREATED);
|
||||
assertNotNull(unfiledRecordFolderChild.getId());
|
||||
|
||||
// Verify the returned file plan component
|
||||
assertFalse(filePlanComponent.getIsCategory());
|
||||
assertFalse(filePlanComponent.getIsFile());
|
||||
assertFalse(filePlanComponent.getIsRecordFolder()); // it is not a _normal_ record folder!
|
||||
assertFalse(unfiledRecordFolderChild.getIsRecord());
|
||||
assertTrue(unfiledRecordFolderChild.getIsUnfiledRecordFolder()); // it is not a _normal_ record folder!
|
||||
|
||||
assertEquals(filePlanComponent.getName(), folderName);
|
||||
assertEquals(filePlanComponent.getNodeType(), UNFILED_RECORD_FOLDER_TYPE);
|
||||
assertEquals(unfiledRecordFolderChild.getName(), unfiledRecordFolderName);
|
||||
assertEquals(unfiledRecordFolderChild.getNodeType(), UNFILED_RECORD_FOLDER_TYPE);
|
||||
|
||||
assertEquals(filePlanComponent.getCreatedByUser().getId(), getAdminUser().getUsername());
|
||||
assertEquals(unfiledRecordFolderChild.getCreatedByUser().getId(), getAdminUser().getUsername());
|
||||
|
||||
UnfiledRecordFolder unfiledRecordFolder = getRestAPIFactory().getUnfiledRecordFoldersAPI().getUnfiledRecordFolder(unfiledRecordFolderChild.getId());
|
||||
// Verify the returned file plan component properties
|
||||
FilePlanComponentProperties filePlanComponentProperties = filePlanComponent.getProperties();
|
||||
assertEquals(filePlanComponentProperties.getTitle(), folderTitle);
|
||||
assertEquals(filePlanComponentProperties.getDescription(), folderDescription);
|
||||
UnfiledContainerChildProperties unfiledRecordFolderChildProperties = unfiledRecordFolder.getProperties();
|
||||
assertEquals(unfiledRecordFolderChildProperties.getTitle(), FilePlanComponentsUtil.TITLE_PREFIX + unfiledRecordFolderName);
|
||||
}
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* Given that I want to create an unfiled record folder
|
||||
* When I use the API with the relativePath
|
||||
* Then the folders specified in the relativePath that don't exist are created
|
||||
* </pre>
|
||||
*/
|
||||
@Test
|
||||
(
|
||||
description = "Create a folder based on the relativePath. " +
|
||||
"Containers in the relativePath that do not exist are created before the node is created"
|
||||
)
|
||||
public void createUnfiledRecordFolderWithRelativePath() throws Exception
|
||||
{
|
||||
String unfiledRecordFolderName1 = "UnfiledRecordFolder-" + getRandomAlphanumeric();
|
||||
UnfiledContainerChild unfiledRecordFolderChild1 = createUnfiledContainerChild(UNFILED_RECORDS_CONTAINER_ALIAS, unfiledRecordFolderName1, UNFILED_RECORD_FOLDER_TYPE);
|
||||
|
||||
String unfiledRecordFolderName2 = "UnfiledRecordFolder-" + getRandomAlphanumeric();
|
||||
|
||||
// relativePath specify the container structure to create relative to the record folder to be created
|
||||
String relativePath = now().getYear() + "/" + now().getMonth() + "/" + now().getDayOfMonth();
|
||||
|
||||
// The record folder to be created
|
||||
UnfiledContainerChild unfiledFolderModel =UnfiledContainerChild.builder()
|
||||
.name(unfiledRecordFolderName2)
|
||||
.nodeType(UNFILED_RECORD_FOLDER_TYPE)
|
||||
.relativePath(relativePath)
|
||||
.build();
|
||||
|
||||
UnfiledContainerChild unfiledRecordFolderChild = getRestAPIFactory().getUnfiledRecordFoldersAPI().createUnfiledRecordFolderChild(unfiledFolderModel, unfiledRecordFolderChild1.getId(), "include=" + PATH);
|
||||
|
||||
// Check the API response code
|
||||
assertStatusCode(CREATED);
|
||||
|
||||
// Verify the returned details for the record folder
|
||||
assertFalse(unfiledRecordFolderChild.getIsRecord());
|
||||
assertTrue(unfiledRecordFolderChild.getIsUnfiledRecordFolder());
|
||||
assertTrue(UNFILED_RECORD_FOLDER_TYPE.equals(unfiledRecordFolderChild.getNodeType()));
|
||||
|
||||
// Check the path return contains the relativePath
|
||||
assertTrue(unfiledRecordFolderChild.getPath().getName().contains(relativePath));
|
||||
|
||||
// Check the parent is a folder, not a record
|
||||
assertTrue(getRestAPIFactory().getUnfiledRecordFoldersAPI().getUnfiledRecordFolder(unfiledRecordFolderChild.getParentId()).getNodeType().equals(UNFILED_RECORD_FOLDER_TYPE));
|
||||
|
||||
// Check the created folder from the server
|
||||
UnfiledRecordFolder recordFolder = getRestAPIFactory().getUnfiledRecordFoldersAPI().getUnfiledRecordFolder(unfiledRecordFolderChild.getId(), "include=" + PATH);
|
||||
|
||||
// Check the API response code
|
||||
assertStatusCode(OK);
|
||||
|
||||
// Check the path return contains the relativePath
|
||||
assertTrue(recordFolder.getPath().getName().contains(relativePath));
|
||||
|
||||
// New relative path only a part of containers need to be created before the record folder
|
||||
String newRelativePath = now().getYear() + "/" + now().getMonth() + "/" + (now().getDayOfMonth() + 1);
|
||||
|
||||
String unfiledRecordFolderName3 = "UnfiledRecordFolder-" + getRandomAlphanumeric();
|
||||
// The record folder to be created
|
||||
UnfiledContainerChild newUnfiledFolderModel =UnfiledContainerChild.builder()
|
||||
.name(unfiledRecordFolderName3)
|
||||
.nodeType(UNFILED_RECORD_FOLDER_TYPE)
|
||||
.relativePath(newRelativePath)
|
||||
.build();
|
||||
|
||||
UnfiledContainerChild newUnfiledRecordFolderChild = getRestAPIFactory().getUnfiledRecordFoldersAPI().createUnfiledRecordFolderChild(newUnfiledFolderModel, unfiledRecordFolderChild1.getId(), "include=" + PATH);
|
||||
|
||||
// Check the API response code
|
||||
assertStatusCode(CREATED);
|
||||
// Check the API response code
|
||||
assertStatusCode(CREATED);
|
||||
|
||||
// Verify the returned properties for the unfiled record folder
|
||||
assertTrue(newUnfiledRecordFolderChild.getIsUnfiledRecordFolder());
|
||||
assertFalse(newUnfiledRecordFolderChild.getIsRecord());
|
||||
|
||||
// Check the path return contains the newRelativePath
|
||||
assertTrue(newUnfiledRecordFolderChild.getPath().getName().contains(newRelativePath));
|
||||
|
||||
// Check the parent is a folder, not a record
|
||||
assertFalse(getRestAPIFactory().getUnfiledRecordFoldersAPI().getUnfiledRecordFolder(newUnfiledRecordFolderChild.getParentId()).equals(UNFILED_RECORD_FOLDER_TYPE));
|
||||
|
||||
// Check the folder created on the server
|
||||
UnfiledRecordFolder newRecordFolder = getRestAPIFactory().getUnfiledRecordFoldersAPI().getUnfiledRecordFolder(newUnfiledRecordFolderChild.getId(), "include=" + PATH);
|
||||
|
||||
// Check the API response code
|
||||
assertStatusCode(OK);
|
||||
|
||||
// Check the path return contains the newRelativePath
|
||||
assertTrue(newRecordFolder.getPath().getName().contains(newRelativePath));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Negative test to verify only unfiled record folders can be created at root level
|
||||
* Negative test to check that invalid types cannot be created at unfiled container root level
|
||||
* Only unfiled record folders and records can be created into unfiled container
|
||||
*/
|
||||
@Test
|
||||
(
|
||||
dataProvider = "invalidRootTypes",
|
||||
description = "Only unfiled records folders can be created at unfiled records root level"
|
||||
description = "Only unfiled records folders can be created at unfiled records root level"
|
||||
)
|
||||
public void onlyRecordFoldersCanBeCreatedAtUnfiledRecordsRoot(String filePlanComponentType)
|
||||
{
|
||||
String folderName = "Folder " + getRandomAlphanumeric();
|
||||
String folderTitle = folderName + " Title";
|
||||
String folderDescription = folderName + " Description";
|
||||
String unfiledRecordFolderName = "UnfiledRecordFolder-" + getRandomAlphanumeric();
|
||||
|
||||
logger.info("creating " + filePlanComponentType);
|
||||
|
||||
// Build unfiled records folder properties
|
||||
FilePlanComponent unfiledFolder = FilePlanComponent.builder()
|
||||
.name(folderName)
|
||||
.nodeType(filePlanComponentType)
|
||||
.properties(FilePlanComponentProperties.builder()
|
||||
.title(folderTitle)
|
||||
.description(folderDescription)
|
||||
.build())
|
||||
.build();
|
||||
UnfiledContainerChild unfiledFolderModel = createUnfiledContainerChildModel(unfiledRecordFolderName, filePlanComponentType);
|
||||
|
||||
try
|
||||
{
|
||||
getRestAPIFactory().getFilePlanComponentsAPI().createFilePlanComponent(unfiledFolder, UNFILED_RECORDS_CONTAINER_ALIAS);
|
||||
getRestAPIFactory().getUnfiledContainersAPI().createUnfiledContainerChild(unfiledFolderModel, UNFILED_RECORDS_CONTAINER_ALIAS);
|
||||
}
|
||||
catch (Exception error)
|
||||
{
|
||||
@@ -174,60 +249,61 @@ public class UnfiledRecordsFolderTests extends BaseRMRestTest
|
||||
@Test(description = "Child unfiled records folder can be created in a parent unfiled records folder")
|
||||
public void childUnfiledRecordsFolderCanBeCreated() throws Exception
|
||||
{
|
||||
String parentFolderName = "Parent Folder " + getRandomAlphanumeric();
|
||||
String childFolderName = "Child Folder " + getRandomAlphanumeric();
|
||||
String childFolderTitle = childFolderName + " Title";
|
||||
String childFolderDescription = childFolderName + " Description";
|
||||
String unfiledParentFolderName = "UnfiledParentFolder" + getRandomAlphanumeric();
|
||||
String unfiledChildFolderName = "UnfiledChildFolder " + getRandomAlphanumeric();
|
||||
String rootUnfiledFolderName = "RootUnfiledFolder" + getRandomAlphanumeric();
|
||||
|
||||
//create root unfiled record folder
|
||||
UnfiledContainerChild createUnfiledContainerChild = createUnfiledContainerChild(UNFILED_RECORDS_CONTAINER_ALIAS, rootUnfiledFolderName, UNFILED_RECORD_FOLDER_TYPE);
|
||||
// No need for fine control, create it using utility function
|
||||
FilePlanComponent parentFolder = createUnfiledRecordsFolder(UNFILED_RECORDS_CONTAINER_ALIAS, parentFolderName);
|
||||
assertEquals(parentFolderName, parentFolder.getName());
|
||||
UnfiledContainerChild unfiledParentFolder = createUnfiledRecordsFolderChild(createUnfiledContainerChild.getId(),
|
||||
unfiledParentFolderName, UNFILED_RECORD_FOLDER_TYPE);
|
||||
assertEquals(unfiledParentFolderName, unfiledParentFolder.getName());
|
||||
|
||||
// Build the unfiled records folder properties
|
||||
FilePlanComponent unfiledFolder = FilePlanComponent.builder()
|
||||
.name(childFolderName)
|
||||
UnfiledContainerChild unfiledChildFolderModel = UnfiledContainerChild.builder().name(unfiledChildFolderName)
|
||||
.nodeType(UNFILED_RECORD_FOLDER_TYPE)
|
||||
.properties(FilePlanComponentProperties.builder()
|
||||
.title(childFolderTitle)
|
||||
.description(childFolderDescription)
|
||||
.build())
|
||||
.properties(UnfiledContainerChildProperties.builder().title(FilePlanComponentsUtil.TITLE_PREFIX + unfiledChildFolderName)
|
||||
.description(FilePlanComponentsUtil.DESCRIPTION_PREFIX + unfiledChildFolderName).build())
|
||||
.build();
|
||||
|
||||
// Create it as a child of parentFolder
|
||||
FilePlanComponentAPI filePlanComponentsAPI = getRestAPIFactory().getFilePlanComponentsAPI();
|
||||
FilePlanComponent childFolder = filePlanComponentsAPI.createFilePlanComponent(unfiledFolder, parentFolder.getId());
|
||||
UnfiledContainerChild unfiledChildFolder = getRestAPIFactory().getUnfiledRecordFoldersAPI()
|
||||
.createUnfiledRecordFolderChild(unfiledChildFolderModel, unfiledParentFolder.getId());
|
||||
|
||||
// Verify the status code
|
||||
assertStatusCode(CREATED);
|
||||
|
||||
// Verify the returned file plan component
|
||||
assertFalse(childFolder.getIsCategory());
|
||||
assertFalse(childFolder.getIsFile());
|
||||
assertFalse(childFolder.getIsRecordFolder()); // it is not a _normal_ record folder!
|
||||
// Verify the returned unfiled child folder
|
||||
assertTrue(unfiledChildFolder.getIsUnfiledRecordFolder());
|
||||
assertFalse(unfiledChildFolder.getIsRecord());
|
||||
|
||||
assertEquals(childFolder.getName(), childFolderName);
|
||||
assertEquals(childFolder.getNodeType(), UNFILED_RECORD_FOLDER_TYPE);
|
||||
assertEquals(childFolder.getCreatedByUser().getId(), getAdminUser().getUsername());
|
||||
assertEquals(unfiledChildFolder.getName(), unfiledChildFolderName);
|
||||
assertEquals(unfiledChildFolder.getNodeType(), UNFILED_RECORD_FOLDER_TYPE);
|
||||
assertEquals(unfiledChildFolder.getCreatedByUser().getId(), getAdminUser().getUsername());
|
||||
|
||||
// Verify the returned file plan component properties
|
||||
FilePlanComponentProperties childProperties = childFolder.getProperties();
|
||||
assertEquals(childProperties.getTitle(), childFolderTitle);
|
||||
assertEquals(childProperties.getDescription(), childFolderDescription);
|
||||
UnfiledRecordFolder unfiledChildRecordFolder = getRestAPIFactory().getUnfiledRecordFoldersAPI()
|
||||
.getUnfiledRecordFolder(unfiledChildFolder.getId());
|
||||
// Verify the returned file plan component properties
|
||||
UnfiledContainerChildProperties unfiledChildFolderProperties = unfiledChildRecordFolder.getProperties();
|
||||
assertEquals(unfiledChildFolderProperties.getTitle(), FilePlanComponentsUtil.TITLE_PREFIX + unfiledChildFolderName);
|
||||
assertEquals(unfiledChildFolderProperties.getDescription(), FilePlanComponentsUtil.DESCRIPTION_PREFIX + unfiledChildFolderName);
|
||||
|
||||
// Does this child point to its parent?
|
||||
assertEquals(childFolder.getParentId(), parentFolder.getId());
|
||||
assertEquals(unfiledChildFolder.getParentId(), unfiledParentFolder.getId());
|
||||
|
||||
// Does child's parent point to it?
|
||||
// Perform another call as our parentFolder had been executed before childFolder existed
|
||||
FilePlanComponentsCollection parentsChildren = filePlanComponentsAPI.listChildComponents(parentFolder.getId());
|
||||
UnfiledContainerChildCollection parentsChildren = getRestAPIFactory().getUnfiledRecordFoldersAPI().getUnfiledRecordFolderChildren(unfiledParentFolder.getId());
|
||||
assertStatusCode(OK);
|
||||
List<String> childIds = parentsChildren.getEntries()
|
||||
.stream()
|
||||
.map(c -> c.getFilePlanComponentModel().getId())
|
||||
.map(c -> c.getEntry().getId())
|
||||
.collect(Collectors.toList());
|
||||
|
||||
// Child folder is listed in parent
|
||||
assertTrue(childIds.contains(childFolder.getId()));
|
||||
assertTrue(childIds.contains(unfiledChildFolder.getId()));
|
||||
|
||||
// There should be only one child
|
||||
assertEquals(1, childIds.size());
|
||||
@@ -244,61 +320,96 @@ public class UnfiledRecordsFolderTests extends BaseRMRestTest
|
||||
public void editUnfiledRecordsFolder() throws Exception
|
||||
{
|
||||
String modified = "Modified ";
|
||||
String folderName = "Folder To Modify" + getRandomAlphanumeric();
|
||||
String unfiledFolderName = "UnfiledFolderToModify" + getRandomAlphanumeric();
|
||||
String rootUnfiledFolderName = "RootUnfiledFolder" + getRandomAlphanumeric();
|
||||
|
||||
//create root unfiledRecordFolder
|
||||
UnfiledContainerChild createUnfiledContainerChild = createUnfiledContainerChild(UNFILED_RECORDS_CONTAINER_ALIAS,rootUnfiledFolderName, UNFILED_RECORD_FOLDER_TYPE);
|
||||
// No need for fine control, create it using utility function
|
||||
FilePlanComponent folderToModify = createUnfiledRecordsFolder(UNFILED_RECORDS_CONTAINER_ALIAS, folderName);
|
||||
assertEquals(folderName, folderToModify.getName());
|
||||
UnfiledContainerChild unfiledFolderToModify = createUnfiledRecordsFolderChild(createUnfiledContainerChild.getId(),
|
||||
unfiledFolderName, UNFILED_RECORD_FOLDER_TYPE);
|
||||
assertEquals(unfiledFolderName, unfiledFolderToModify.getName());
|
||||
|
||||
// Build the properties which will be updated
|
||||
FilePlanComponent folderToUpdate = FilePlanComponent.builder()
|
||||
.name(modified + folderToModify.getName())
|
||||
.properties(FilePlanComponentProperties.builder().
|
||||
title(modified + folderToModify.getProperties().getTitle()).
|
||||
description(modified + folderToModify.getProperties().getDescription())
|
||||
.build())
|
||||
.build();
|
||||
UnfiledRecordFolder unfiledChildFolderModel = UnfiledRecordFolder.builder().name(modified + unfiledFolderName)
|
||||
.properties(UnfiledContainerChildProperties.builder().title(modified + unfiledFolderToModify.getProperties().getTitle())
|
||||
.description(modified + unfiledFolderToModify.getProperties().getDescription()).build())
|
||||
.build();
|
||||
|
||||
// Update the unfiled records folder
|
||||
FilePlanComponentAPI filePlanComponentsAPI = getRestAPIFactory().getFilePlanComponentsAPI();
|
||||
filePlanComponentsAPI.updateFilePlanComponent(folderToUpdate, folderToModify.getId());
|
||||
getRestAPIFactory().getUnfiledRecordFoldersAPI().updateUnfiledRecordFolder(unfiledChildFolderModel, unfiledFolderToModify.getId());
|
||||
// Verify the status code
|
||||
assertStatusCode(OK);
|
||||
|
||||
// This is to ensure the change was actually applied, rather than simply trusting the object returned by PUT
|
||||
FilePlanComponent renamedFolder = filePlanComponentsAPI.getFilePlanComponent(folderToModify.getId());
|
||||
UnfiledRecordFolder renamedUnfiledFolder = getRestAPIFactory().getUnfiledRecordFoldersAPI().getUnfiledRecordFolder(unfiledFolderToModify.getId());
|
||||
|
||||
// Verify the returned file plan component
|
||||
assertEquals(modified + folderToModify.getName(), renamedFolder.getName());
|
||||
assertEquals(modified + folderToModify.getProperties().getTitle(), renamedFolder.getProperties().getTitle());
|
||||
assertEquals(modified + folderToModify.getProperties().getDescription(), renamedFolder.getProperties().getDescription());
|
||||
assertEquals(modified + unfiledFolderToModify.getName(), renamedUnfiledFolder.getName());
|
||||
assertEquals(modified + unfiledFolderToModify.getProperties().getTitle(), renamedUnfiledFolder.getProperties().getTitle());
|
||||
assertEquals(modified + unfiledFolderToModify.getProperties().getDescription(), renamedUnfiledFolder.getProperties().getDescription());
|
||||
}
|
||||
|
||||
/**
|
||||
* Given an unfiled record folder
|
||||
* Given an unfiled record folder and some records inside
|
||||
* When I delete the unfiled record folder via the ReST API
|
||||
* Then the unfiled record folder is deleted
|
||||
* Then the unfiled record folder is deleted and its content too
|
||||
*
|
||||
* @throws Exception for failed actions
|
||||
*/
|
||||
@Test(description = "Delete unfiled record folder")
|
||||
public void deleteUnfiledRecordsFolder() throws Exception
|
||||
{
|
||||
String folderName = "Folder To Delete" + getRandomAlphanumeric();
|
||||
String unfiledFolderName = "UnfiledFolderToDelete" + getRandomAlphanumeric();
|
||||
String nonElectronicRecordName = "NonElectronicRecord" + getRandomAlphanumeric();
|
||||
String electronicRecordName = "ElectronicRecord" + getRandomAlphanumeric();
|
||||
String rootUnfiledFolderName = "RootUnfiledFolder" + getRandomAlphanumeric();
|
||||
|
||||
// Create folderToDelete
|
||||
FilePlanComponent folderToDelete = createUnfiledRecordsFolder(UNFILED_RECORDS_CONTAINER_ALIAS, folderName);
|
||||
assertEquals(folderName, folderToDelete.getName());
|
||||
//create root unfiled record folder
|
||||
UnfiledContainerChild createUnfiledContainerChild = createUnfiledContainerChild(UNFILED_RECORDS_CONTAINER_ALIAS, rootUnfiledFolderName, UNFILED_RECORD_FOLDER_TYPE);
|
||||
// Create unfiledFolderToDelete
|
||||
UnfiledContainerChild unfiledFolderToDelete = createUnfiledRecordsFolderChild(createUnfiledContainerChild.getId(),
|
||||
unfiledFolderName, UNFILED_RECORD_FOLDER_TYPE);
|
||||
assertEquals(unfiledFolderName, unfiledFolderToDelete.getName());
|
||||
|
||||
// Create a non electronic record under unfiledFolderToDelete
|
||||
UnfiledContainerChild nonElectronicRecord = createUnfiledRecordsFolderChild(unfiledFolderToDelete.getId(),
|
||||
nonElectronicRecordName, NON_ELECTRONIC_RECORD_TYPE);
|
||||
assertTrue(nonElectronicRecord.getParentId().equals(unfiledFolderToDelete.getId()));
|
||||
|
||||
// Create an electronic record under unfiledFolderToDelete
|
||||
UnfiledContainerChild electronicRecord = createUnfiledRecordsFolderChild(unfiledFolderToDelete.getId(),
|
||||
electronicRecordName, CONTENT_TYPE);
|
||||
assertTrue(electronicRecord.getParentId().equals(unfiledFolderToDelete.getId()));
|
||||
|
||||
// Delete folderToDelete
|
||||
FilePlanComponentAPI filePlanComponentsAPI = getRestAPIFactory().getFilePlanComponentsAPI();
|
||||
filePlanComponentsAPI.deleteFilePlanComponent(folderToDelete.getId());
|
||||
getRestAPIFactory().getUnfiledRecordFoldersAPI().deleteUnfiledRecordFolder(unfiledFolderToDelete.getId());
|
||||
|
||||
// Verify the status code
|
||||
assertStatusCode(NO_CONTENT);
|
||||
|
||||
// Deleted component should no longer be retrievable
|
||||
filePlanComponentsAPI.getFilePlanComponent(folderToDelete.getId());
|
||||
getRestAPIFactory().getUnfiledRecordFoldersAPI().getUnfiledRecordFolder(unfiledFolderToDelete.getId());
|
||||
assertStatusCode(NOT_FOUND);
|
||||
}
|
||||
|
||||
@AfterMethod
|
||||
@AfterClass (alwaysRun = true)
|
||||
public void tearDown() throws Exception
|
||||
{
|
||||
UnfiledContainerChildCollection listedChildren = getRestAPIFactory().getUnfiledContainersAPI()
|
||||
.getUnfiledContainerChildren(UNFILED_RECORDS_CONTAINER_ALIAS);
|
||||
|
||||
listedChildren.getEntries().forEach(UnfiledContainerChildEntry ->
|
||||
{
|
||||
if (UnfiledContainerChildEntry.getEntry().getIsRecord())
|
||||
{
|
||||
getRestAPIFactory().getRecordsAPI().deleteRecord(UnfiledContainerChildEntry.getEntry().getId());
|
||||
}
|
||||
else
|
||||
{
|
||||
getRestAPIFactory().getUnfiledRecordFoldersAPI().deleteUnfiledRecordFolder(UnfiledContainerChildEntry.getEntry().getId());
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@@ -26,9 +26,16 @@
|
||||
*/
|
||||
package org.alfresco.rest.rm.community.fileplancomponents;
|
||||
|
||||
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentAlias.UNFILED_RECORDS_CONTAINER_ALIAS;
|
||||
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.UNFILED_RECORD_FOLDER_TYPE;
|
||||
import static org.alfresco.rest.rm.community.utils.FilePlanComponentsUtil.IMAGE_FILE;
|
||||
import static org.alfresco.rest.rm.community.utils.FilePlanComponentsUtil.createElectronicRecordModel;
|
||||
import static org.alfresco.rest.rm.community.utils.FilePlanComponentsUtil.createElectronicUnfiledContainerChildModel;
|
||||
import static org.alfresco.rest.rm.community.utils.FilePlanComponentsUtil.createNonElectronicRecordModel;
|
||||
import static org.alfresco.rest.rm.community.utils.FilePlanComponentsUtil.createNonElectronicUnfiledContainerChildModel;
|
||||
import static org.alfresco.rest.rm.community.utils.FilePlanComponentsUtil.createRecordModel;
|
||||
import static org.alfresco.rest.rm.community.utils.FilePlanComponentsUtil.getFile;
|
||||
import static org.alfresco.utility.data.RandomData.getRandomAlphanumeric;
|
||||
import static org.springframework.http.HttpStatus.CREATED;
|
||||
import static org.springframework.http.HttpStatus.FORBIDDEN;
|
||||
import static org.springframework.http.HttpStatus.OK;
|
||||
@@ -37,16 +44,22 @@ import static org.testng.Assert.assertEquals;
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.alfresco.rest.rm.community.base.BaseRMRestTest;
|
||||
import org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponent;
|
||||
import org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentProperties;
|
||||
import org.alfresco.rest.rm.community.model.record.Record;
|
||||
import org.alfresco.rest.rm.community.model.recordcategory.RecordCategoryChild;
|
||||
import org.alfresco.rest.rm.community.model.unfiledcontainer.UnfiledContainerChild;
|
||||
import org.alfresco.rest.rm.community.model.user.UserPermissions;
|
||||
import org.alfresco.rest.rm.community.model.user.UserRoles;
|
||||
import org.alfresco.rest.rm.community.requests.igCoreAPI.FilePlanComponentAPI;
|
||||
import org.alfresco.rest.rm.community.requests.igCoreAPI.RMUserAPI;
|
||||
import org.alfresco.rest.rm.community.requests.gscore.api.RMUserAPI;
|
||||
import org.alfresco.rest.rm.community.requests.gscore.api.RecordCategoryAPI;
|
||||
import org.alfresco.rest.rm.community.requests.gscore.api.RecordFolderAPI;
|
||||
import org.alfresco.rest.rm.community.requests.gscore.api.RecordsAPI;
|
||||
import org.alfresco.rest.rm.community.requests.gscore.api.UnfiledContainerAPI;
|
||||
import org.alfresco.rest.rm.community.requests.gscore.api.UnfiledRecordFolderAPI;
|
||||
import org.alfresco.test.AlfrescoTest;
|
||||
import org.alfresco.utility.constants.UserRole;
|
||||
import org.alfresco.utility.model.SiteModel;
|
||||
import org.alfresco.utility.model.UserModel;
|
||||
import org.testng.annotations.DataProvider;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
/**
|
||||
@@ -58,10 +71,100 @@ import org.testng.annotations.Test;
|
||||
* @since 2.6
|
||||
*/
|
||||
public class UpdateRecordsTests extends BaseRMRestTest
|
||||
{
|
||||
{
|
||||
/* to be used to append to modifications */
|
||||
private final String MODIFIED_PREFIX = "modified_";
|
||||
|
||||
/** Incomplete electronic and non electronic records created in one record folder, unfiled records container and one unfiled record folder */
|
||||
@DataProvider(name = "incompleteRecords")
|
||||
public String[][] getIncompleteRecords() throws Exception
|
||||
{
|
||||
//create electronic and nonElectronic record in record folder
|
||||
String recordFolderId = createCategoryFolderInFilePlan().getId();
|
||||
RecordFolderAPI recordFolderAPI = getRestAPIFactory().getRecordFolderAPI();
|
||||
|
||||
Record electronicRecord = recordFolderAPI.createRecord(createElectronicRecordModel(), recordFolderId, getFile(IMAGE_FILE));
|
||||
assertStatusCode(CREATED);
|
||||
|
||||
Record nonElectronicRecord = recordFolderAPI.createRecord(createNonElectronicRecordModel(), recordFolderId);
|
||||
assertStatusCode(CREATED);
|
||||
|
||||
//create electronic record and nonElectronic record in unfiled records container
|
||||
UnfiledContainerAPI unfiledContainersAPI = getRestAPIFactory().getUnfiledContainersAPI();
|
||||
UnfiledContainerChild electronicRecord1 = unfiledContainersAPI.uploadRecord(createElectronicUnfiledContainerChildModel(), UNFILED_RECORDS_CONTAINER_ALIAS, getFile(IMAGE_FILE));
|
||||
assertStatusCode(CREATED);
|
||||
|
||||
UnfiledContainerChild nonElectronicRecord1 = unfiledContainersAPI.createUnfiledContainerChild(createNonElectronicUnfiledContainerChildModel(), UNFILED_RECORDS_CONTAINER_ALIAS);
|
||||
assertStatusCode(CREATED);
|
||||
|
||||
//create electronic record and nonElectronic record in unfiled record folder
|
||||
String unfiledRecordFolderId = createUnfiledContainerChild(UNFILED_RECORDS_CONTAINER_ALIAS, "Unfiled Folder " + getRandomAlphanumeric(), UNFILED_RECORD_FOLDER_TYPE).getId();
|
||||
UnfiledRecordFolderAPI unfiledRecordFoldersAPI = getRestAPIFactory().getUnfiledRecordFoldersAPI();
|
||||
UnfiledContainerChild electronicRecord2 = unfiledRecordFoldersAPI.uploadRecord(createElectronicUnfiledContainerChildModel(), unfiledRecordFolderId, getFile(IMAGE_FILE));
|
||||
assertStatusCode(CREATED);
|
||||
|
||||
UnfiledContainerChild nonElectronicRecord2 = unfiledRecordFoldersAPI.createUnfiledRecordFolderChild(createNonElectronicUnfiledContainerChildModel(), unfiledRecordFolderId);
|
||||
assertStatusCode(CREATED);
|
||||
|
||||
return new String[][]
|
||||
{
|
||||
// an arbitrary record folder
|
||||
{ electronicRecord.getId(), nonElectronicRecord.getId()},
|
||||
// unfiled records root
|
||||
{ electronicRecord1.getId(), nonElectronicRecord1.getId()},
|
||||
// an arbitrary unfiled records folder
|
||||
{ electronicRecord2.getId(), nonElectronicRecord2.getId()}
|
||||
};
|
||||
}
|
||||
|
||||
/** Complete electronic and non electronic records created in one record folder, unfiled records container and one unfiled record folder */
|
||||
@DataProvider(name = "completeRecords")
|
||||
public String[][] getCompleteRecords() throws Exception
|
||||
{
|
||||
//create electronic and nonElectronic record in record folder
|
||||
String recordFolderId = createCategoryFolderInFilePlan().getId();
|
||||
RecordFolderAPI recordFolderAPI = getRestAPIFactory().getRecordFolderAPI();
|
||||
|
||||
Record electronicRecord = recordFolderAPI.createRecord(createElectronicRecordModel(), recordFolderId, getFile(IMAGE_FILE));
|
||||
assertStatusCode(CREATED);
|
||||
completeRecord(electronicRecord.getId());
|
||||
|
||||
Record nonElectronicRecord = recordFolderAPI.createRecord(createNonElectronicRecordModel(), recordFolderId);
|
||||
assertStatusCode(CREATED);
|
||||
completeRecord(nonElectronicRecord.getId());
|
||||
|
||||
//create electronic record and nonElectronic record in unfiled records container
|
||||
UnfiledContainerAPI unfiledContainersAPI = getRestAPIFactory().getUnfiledContainersAPI();
|
||||
UnfiledContainerChild electronicRecord1 = unfiledContainersAPI.uploadRecord(createElectronicUnfiledContainerChildModel(), UNFILED_RECORDS_CONTAINER_ALIAS, getFile(IMAGE_FILE));
|
||||
assertStatusCode(CREATED);
|
||||
completeRecord(electronicRecord1.getId());
|
||||
|
||||
UnfiledContainerChild nonElectronicRecord1 = unfiledContainersAPI.createUnfiledContainerChild(createNonElectronicUnfiledContainerChildModel(), UNFILED_RECORDS_CONTAINER_ALIAS);
|
||||
assertStatusCode(CREATED);
|
||||
completeRecord(nonElectronicRecord1.getId());
|
||||
|
||||
//create electronic record and nonElectronic record in unfiled record folder
|
||||
String unfiledRecordFolderId = createUnfiledContainerChild(UNFILED_RECORDS_CONTAINER_ALIAS, "Unfiled Folder " + getRandomAlphanumeric(), UNFILED_RECORD_FOLDER_TYPE).getId();
|
||||
UnfiledRecordFolderAPI unfiledRecordFoldersAPI = getRestAPIFactory().getUnfiledRecordFoldersAPI();
|
||||
UnfiledContainerChild electronicRecord2 = unfiledRecordFoldersAPI.uploadRecord(createElectronicUnfiledContainerChildModel(), unfiledRecordFolderId, getFile(IMAGE_FILE));
|
||||
assertStatusCode(CREATED);
|
||||
completeRecord(electronicRecord2.getId());
|
||||
|
||||
UnfiledContainerChild nonElectronicRecord2 = unfiledRecordFoldersAPI.createUnfiledRecordFolderChild(createNonElectronicUnfiledContainerChildModel(), unfiledRecordFolderId);
|
||||
assertStatusCode(CREATED);
|
||||
completeRecord(nonElectronicRecord2.getId());
|
||||
|
||||
return new String[][]
|
||||
{
|
||||
// an arbitrary record folder
|
||||
{ electronicRecord.getId(), nonElectronicRecord.getId()},
|
||||
// unfiled records root
|
||||
{ electronicRecord1.getId(), nonElectronicRecord1.getId()},
|
||||
// an arbitrary unfiled records folder
|
||||
{ electronicRecord2.getId(), nonElectronicRecord2.getId()}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* Given an incomplete record
|
||||
@@ -72,40 +175,30 @@ public class UpdateRecordsTests extends BaseRMRestTest
|
||||
*/
|
||||
@Test
|
||||
(
|
||||
dataProvider = "validRootContainers",
|
||||
dataProvider = "incompleteRecords",
|
||||
description = "Incomplete records can be updated"
|
||||
)
|
||||
@AlfrescoTest(jira="RM-4362")
|
||||
public void incompleteRecordsCanBeUpdated(FilePlanComponent recordFolder) throws Exception
|
||||
public void incompleteRecordsCanBeUpdated(String electronicRecordId, String nonElectronicRecordId) throws Exception
|
||||
{
|
||||
FilePlanComponentAPI filePlanComponentsAPI = getRestAPIFactory().getFilePlanComponentsAPI();
|
||||
// Get the recordsAPI
|
||||
RecordsAPI recordsAPI = getRestAPIFactory().getRecordsAPI();
|
||||
Record electronicRecord = recordsAPI.getRecord(electronicRecordId);
|
||||
Record nonElectronicRecord = recordsAPI.getRecord(nonElectronicRecordId);
|
||||
|
||||
// create electronic and non-electronic records in a folder
|
||||
FilePlanComponent electronicRecord = filePlanComponentsAPI.createElectronicRecord(createElectronicRecordModel(), IMAGE_FILE, recordFolder.getId());
|
||||
assertStatusCode(CREATED);
|
||||
FilePlanComponent nonElectronicRecord = filePlanComponentsAPI.createFilePlanComponent(createNonElectronicRecordModel(), recordFolder.getId());
|
||||
assertStatusCode(CREATED);
|
||||
|
||||
for (FilePlanComponent record: Arrays.asList(electronicRecord, nonElectronicRecord)) {
|
||||
// generate update metadata
|
||||
for (Record record: Arrays.asList(electronicRecord, nonElectronicRecord)) {
|
||||
// Generate update metadata
|
||||
String newName = getModifiedPropertyValue(record.getName());
|
||||
String newTitle = getModifiedPropertyValue(record.getProperties().getTitle());
|
||||
String newDescription = getModifiedPropertyValue(record.getProperties().getDescription());
|
||||
Record recordModel = createRecordModel(newName, newDescription, newTitle);
|
||||
|
||||
FilePlanComponent updateRecord = FilePlanComponent.builder()
|
||||
.name(newName)
|
||||
.properties(FilePlanComponentProperties.builder()
|
||||
.description(newDescription)
|
||||
.title(newTitle)
|
||||
.build())
|
||||
.build();
|
||||
|
||||
// update record
|
||||
filePlanComponentsAPI.updateFilePlanComponent(updateRecord, record.getId());
|
||||
// Update record
|
||||
recordsAPI.updateRecord(recordModel, record.getId());
|
||||
assertStatusCode(OK);
|
||||
|
||||
// verify the update got applied
|
||||
FilePlanComponent updatedRecord = filePlanComponentsAPI.getFilePlanComponent(record.getId());
|
||||
// Verify the original record meta data has been retained
|
||||
Record updatedRecord = recordsAPI.getRecord(record.getId());
|
||||
assertEquals(updatedRecord.getName(), newName);
|
||||
assertEquals(updatedRecord.getProperties().getTitle(), newTitle);
|
||||
assertEquals(updatedRecord.getProperties().getDescription(), newDescription);
|
||||
@@ -127,9 +220,9 @@ public class UpdateRecordsTests extends BaseRMRestTest
|
||||
)
|
||||
@AlfrescoTest(jira="RM-4362")
|
||||
public void userWithEditMetadataCapsCanUpdateMetadata() throws Exception
|
||||
{
|
||||
{
|
||||
RMUserAPI rmUserAPI = getRestAPIFactory().getRMUserAPI();
|
||||
// create test user and add it with collab. privileges
|
||||
// Create test user and add it with collab. privileges
|
||||
UserModel updateUser = getDataUser().createRandomTestUser("updateuser");
|
||||
updateUser.setUserRole(UserRole.SiteCollaborator);
|
||||
getDataUser().addUserToSite(updateUser, new SiteModel(getRestAPIFactory().getRMSiteAPI().getSite().getId()), UserRole.SiteCollaborator);
|
||||
@@ -138,50 +231,44 @@ public class UpdateRecordsTests extends BaseRMRestTest
|
||||
rmUserAPI.assignRoleToUser(updateUser.getUsername(), UserRoles.ROLE_RM_SECURITY_OFFICER);
|
||||
assertStatusCode(OK);
|
||||
|
||||
// create random folder
|
||||
FilePlanComponent randomFolder = createCategoryFolderInFilePlan();
|
||||
logger.info("random folder:" + randomFolder.getName());
|
||||
// Create random folder
|
||||
RecordCategoryChild recordFolder = createCategoryFolderInFilePlan();
|
||||
logger.info("random folder:" + recordFolder.getName());
|
||||
|
||||
// grant updateUser Filing privileges on randomFolder category, this will be
|
||||
// inherited to randomFolder
|
||||
FilePlanComponentAPI filePlanComponentsAPIAsAdmin = getRestAPIFactory().getFilePlanComponentsAPI();
|
||||
rmUserAPI.addUserPermission(filePlanComponentsAPIAsAdmin.getFilePlanComponent(randomFolder.getParentId()),
|
||||
// Grant updateUser Filing privileges on randomFolder category, this will be
|
||||
// Inherited to randomFolder
|
||||
RecordCategoryAPI recordCategoryAPI = getRestAPIFactory().getRecordCategoryAPI();
|
||||
rmUserAPI.addUserPermission(recordCategoryAPI.getRecordCategory(recordFolder.getParentId()).getId(),
|
||||
updateUser, UserPermissions.PERMISSION_FILING);
|
||||
assertStatusCode(OK);
|
||||
|
||||
// create electronic and non-electronic records in a folder
|
||||
FilePlanComponentAPI filePlanComponentsAPI = getRestAPIFactory().getFilePlanComponentsAPI();
|
||||
FilePlanComponent electronicRecord = filePlanComponentsAPI.createElectronicRecord(createElectronicRecordModel(), IMAGE_FILE, randomFolder.getId());
|
||||
|
||||
// Create electronic and non-electronic records in a folder
|
||||
RecordFolderAPI recordFolderAPI = getRestAPIFactory().getRecordFolderAPI();
|
||||
Record electronicRecord = recordFolderAPI.createRecord(createElectronicRecordModel(), recordFolder.getId(), getFile(IMAGE_FILE));
|
||||
assertStatusCode(CREATED);
|
||||
FilePlanComponent nonElectronicRecord = filePlanComponentsAPI.createFilePlanComponent(createNonElectronicRecordModel(), randomFolder.getId());
|
||||
Record nonElectronicRecord = recordFolderAPI.createRecord(createNonElectronicRecordModel(), recordFolder.getId());
|
||||
assertStatusCode(CREATED);
|
||||
|
||||
// get FilePlanComponentAPI instance initialised to updateUser
|
||||
FilePlanComponentAPI filePlanComponentsAPIAsUser = getRestAPIFactory().getFilePlanComponentsAPI(updateUser);
|
||||
// Get recordsAPI instance initialised to updateUser
|
||||
RecordsAPI recordsAPI = getRestAPIFactory().getRecordsAPI(updateUser);
|
||||
|
||||
for (FilePlanComponent record: Arrays.asList(electronicRecord, nonElectronicRecord)) {
|
||||
filePlanComponentsAPIAsUser.getFilePlanComponent(record.getId());
|
||||
for (Record record: Arrays.asList(electronicRecord, nonElectronicRecord))
|
||||
{
|
||||
recordsAPI.getRecord(record.getId());
|
||||
assertStatusCode(OK);
|
||||
|
||||
// generate update metadata
|
||||
// Generate update metadata
|
||||
String newName = getModifiedPropertyValue(record.getName());
|
||||
String newTitle = getModifiedPropertyValue(record.getProperties().getTitle());
|
||||
String newDescription = getModifiedPropertyValue(record.getProperties().getDescription());
|
||||
Record recordModel = createRecordModel(newName, newDescription, newTitle);
|
||||
|
||||
FilePlanComponent updateRecord = FilePlanComponent.builder()
|
||||
.name(newName)
|
||||
.properties(FilePlanComponentProperties.builder()
|
||||
.description(newDescription)
|
||||
.title(newTitle)
|
||||
.build())
|
||||
.build();
|
||||
|
||||
// update record
|
||||
filePlanComponentsAPIAsUser.updateFilePlanComponent(updateRecord, record.getId());
|
||||
// Update record
|
||||
recordsAPI.updateRecord(recordModel, record.getId());
|
||||
assertStatusCode(OK);
|
||||
|
||||
// verify the update got applied
|
||||
FilePlanComponent updatedRecord = filePlanComponentsAPIAsUser.getFilePlanComponent(record.getId());
|
||||
// Verify the update got applied
|
||||
Record updatedRecord = recordsAPI.getRecord(record.getId());
|
||||
assertEquals(updatedRecord.getName(), newName);
|
||||
assertEquals(updatedRecord.getProperties().getTitle(), newTitle);
|
||||
assertEquals(updatedRecord.getProperties().getDescription(), newDescription);
|
||||
@@ -200,46 +287,33 @@ public class UpdateRecordsTests extends BaseRMRestTest
|
||||
*/
|
||||
@Test
|
||||
(
|
||||
dataProvider = "validRootContainers",
|
||||
dataProvider = "completeRecords",
|
||||
description = "Complete records can't be updated"
|
||||
)
|
||||
@AlfrescoTest(jira="RM-4362")
|
||||
public void completeRecordsCantBeUpdated(FilePlanComponent recordFolder) throws Exception
|
||||
public void completeRecordsCantBeUpdated(String electronicRecordId, String nonElectronicRecordId) throws Exception
|
||||
{
|
||||
FilePlanComponentAPI filePlanComponentsAPI = getRestAPIFactory().getFilePlanComponentsAPI();
|
||||
// Get the recordsAPI
|
||||
RecordsAPI recordsAPI = getRestAPIFactory().getRecordsAPI();
|
||||
Record electronicRecord = recordsAPI.getRecord(electronicRecordId);
|
||||
Record nonElectronicRecord = recordsAPI.getRecord(nonElectronicRecordId);
|
||||
|
||||
// create electronic and non-electronic records in a folder
|
||||
FilePlanComponent electronicRecord = filePlanComponentsAPI.createElectronicRecord(createElectronicRecordModel(), IMAGE_FILE, recordFolder.getId());
|
||||
assertStatusCode(CREATED);
|
||||
closeRecord(electronicRecord);
|
||||
|
||||
FilePlanComponent nonElectronicRecord = filePlanComponentsAPI.createFilePlanComponent(createNonElectronicRecordModel(), recordFolder.getId());
|
||||
assertStatusCode(CREATED);
|
||||
closeRecord(nonElectronicRecord);
|
||||
|
||||
for (FilePlanComponent record: Arrays.asList(electronicRecord, nonElectronicRecord)) {
|
||||
// generate update metadata
|
||||
for (Record record: Arrays.asList(electronicRecord, nonElectronicRecord)) {
|
||||
// Generate update metadata
|
||||
String newName = getModifiedPropertyValue(record.getName());
|
||||
String newTitle = getModifiedPropertyValue(record.getProperties().getTitle());
|
||||
String newDescription = getModifiedPropertyValue(record.getProperties().getDescription());
|
||||
Record recordModel = createRecordModel(newName, newDescription, newTitle);
|
||||
|
||||
FilePlanComponent updateRecord = FilePlanComponent.builder()
|
||||
.name(newName)
|
||||
.properties(FilePlanComponentProperties.builder()
|
||||
.description(newDescription)
|
||||
.title(newTitle)
|
||||
.build())
|
||||
.build();
|
||||
|
||||
// attempt to update record
|
||||
filePlanComponentsAPI.updateFilePlanComponent(updateRecord, record.getId());
|
||||
// Update record
|
||||
recordsAPI.updateRecord(recordModel, record.getId());
|
||||
assertStatusCode(FORBIDDEN);
|
||||
|
||||
// verify the original record metatada has been retained
|
||||
FilePlanComponent updatedRecord = filePlanComponentsAPI.getFilePlanComponent(record.getId());
|
||||
// Verify the original record meta data has been retained
|
||||
Record updatedRecord = recordsAPI.getRecord(record.getId());
|
||||
assertEquals(updatedRecord.getName(), record.getName());
|
||||
assertEquals(updatedRecord.getProperties().getTitle(), record.getProperties().getTitle());
|
||||
assertEquals(updatedRecord.getProperties().getDescription(), record.getProperties().getTitle());
|
||||
assertEquals(updatedRecord.getProperties().getDescription(), record.getProperties().getDescription());
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -41,13 +41,12 @@ import java.util.stream.Collectors;
|
||||
import org.alfresco.dataprep.CMISUtil;
|
||||
import org.alfresco.rest.model.RestNodeModel;
|
||||
import org.alfresco.rest.rm.community.base.BaseRMRestTest;
|
||||
import org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponent;
|
||||
import org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentEntry;
|
||||
import org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentProperties;
|
||||
import org.alfresco.rest.rm.community.requests.igCoreAPI.FilePlanComponentAPI;
|
||||
import org.alfresco.rest.rm.community.model.record.Record;
|
||||
import org.alfresco.rest.rm.community.model.record.RecordProperties;
|
||||
import org.alfresco.rest.rm.community.model.unfiledcontainer.UnfiledContainerChildEntry;
|
||||
import org.alfresco.rest.rm.community.requests.gscore.api.UnfiledContainerAPI;
|
||||
import org.alfresco.test.AlfrescoTest;
|
||||
import org.alfresco.utility.constants.UserRole;
|
||||
import org.alfresco.utility.data.DataUser;
|
||||
import org.alfresco.utility.model.FileModel;
|
||||
import org.alfresco.utility.model.FolderModel;
|
||||
import org.alfresco.utility.model.SiteModel;
|
||||
@@ -55,7 +54,6 @@ import org.alfresco.utility.model.UserModel;
|
||||
import org.apache.chemistry.opencmis.client.api.Document;
|
||||
import org.apache.chemistry.opencmis.client.api.SecondaryType;
|
||||
import org.apache.commons.codec.digest.DigestUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.testng.annotations.BeforeClass;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
@@ -67,9 +65,6 @@ import org.testng.annotations.Test;
|
||||
*/
|
||||
public class DeclareDocumentAsRecordTests extends BaseRMRestTest
|
||||
{
|
||||
@Autowired
|
||||
private DataUser dataUser;
|
||||
|
||||
private UserModel testUser, testUserReadOnly;
|
||||
private SiteModel testSite;
|
||||
private FolderModel testFolder;
|
||||
@@ -78,13 +73,13 @@ public class DeclareDocumentAsRecordTests extends BaseRMRestTest
|
||||
public void declareDocumentAsRecordSetup() throws Exception
|
||||
{
|
||||
// create test user and test collaboration site to store documents in
|
||||
testUser = dataUser.createRandomTestUser();
|
||||
testUserReadOnly = dataUser.createRandomTestUser();
|
||||
testUser = getDataUser().createRandomTestUser();
|
||||
testUserReadOnly = getDataUser().createRandomTestUser();
|
||||
|
||||
testSite = dataSite.usingAdmin().createPublicRandomSite();
|
||||
|
||||
dataUser.addUserToSite(testUser, testSite, UserRole.SiteContributor);
|
||||
dataUser.addUserToSite(testUserReadOnly, testSite, UserRole.SiteConsumer);
|
||||
getDataUser().addUserToSite(testUser, testSite, UserRole.SiteContributor);
|
||||
getDataUser().addUserToSite(testUserReadOnly, testSite, UserRole.SiteConsumer);
|
||||
|
||||
testFolder = dataContent.usingSite(testSite).usingUser(testUser).createFolder();
|
||||
}
|
||||
@@ -112,15 +107,15 @@ public class DeclareDocumentAsRecordTests extends BaseRMRestTest
|
||||
.createContent(CMISUtil.DocumentType.TEXT_PLAIN);
|
||||
|
||||
// declare document as record
|
||||
FilePlanComponent record = getRestAPIFactory().getFilesAPI(testUser).declareAsRecord(document.getNodeRefWithoutVersion());
|
||||
Record record = getRestAPIFactory().getFilesAPI(testUser).declareAsRecord(document.getNodeRefWithoutVersion());
|
||||
assertStatusCode(CREATED);
|
||||
|
||||
// verify the declared record is in Unfiled Records folder
|
||||
FilePlanComponentAPI filePlanComponentAPI = getRestAPIFactory().getFilePlanComponentsAPI();
|
||||
List<FilePlanComponentEntry> matchingRecords = filePlanComponentAPI.listChildComponents(UNFILED_RECORDS_CONTAINER_ALIAS)
|
||||
UnfiledContainerAPI unfiledContainersAPI = getRestAPIFactory().getUnfiledContainersAPI();
|
||||
List<UnfiledContainerChildEntry> matchingRecords = unfiledContainersAPI.getUnfiledContainerChildren(UNFILED_RECORDS_CONTAINER_ALIAS)
|
||||
.getEntries()
|
||||
.stream()
|
||||
.filter(e -> e.getFilePlanComponentModel().getId().equals(document.getNodeRefWithoutVersion()))
|
||||
.filter(e -> e.getEntry().getId().equals(document.getNodeRefWithoutVersion()))
|
||||
.collect(Collectors.toList());
|
||||
// there should be only one matching record corresponding this document
|
||||
assertEquals(matchingRecords.size(), 1, "More than one record matching document name");
|
||||
@@ -136,7 +131,7 @@ public class DeclareDocumentAsRecordTests extends BaseRMRestTest
|
||||
|
||||
// verify the new name has the form of "<original name> (<record Id>).<original extension>"
|
||||
String recordName = filesAfterRename.get(0).onModel().getName();
|
||||
assertEquals(recordName, document.getName().replace(".", String.format(" (%s).", record.getProperties().getRmIdentifier())));
|
||||
assertEquals(recordName, document.getName().replace(".", String.format(" (%s).", record.getProperties().getIdentifier())));
|
||||
|
||||
// verify the document in collaboration site is now a record, note the file is now renamed hence folder + doc. name concatenation
|
||||
// this also verifies the document is still in the initial folder
|
||||
@@ -208,16 +203,16 @@ public class DeclareDocumentAsRecordTests extends BaseRMRestTest
|
||||
public void recordCantBeDeclaredARecord() throws Exception
|
||||
{
|
||||
// create a non-electronic record in a random folder
|
||||
FilePlanComponent nonelectronicRecord = FilePlanComponent.builder()
|
||||
.properties(FilePlanComponentProperties.builder()
|
||||
Record nonelectronicRecord = Record.builder()
|
||||
.properties(RecordProperties.builder()
|
||||
.description("Description")
|
||||
.title("Title")
|
||||
.build())
|
||||
.name("Non-Electronic Record")
|
||||
.nodeType(NON_ELECTRONIC_RECORD_TYPE)
|
||||
.build();
|
||||
FilePlanComponent record = getRestAPIFactory().getFilePlanComponentsAPI()
|
||||
.createFilePlanComponent(nonelectronicRecord, createCategoryFolderInFilePlan().getId());
|
||||
Record record = getRestAPIFactory().getRecordFolderAPI()
|
||||
.createRecord(nonelectronicRecord, createCategoryFolderInFilePlan().getId());
|
||||
assertStatusCode(CREATED);
|
||||
|
||||
// try to declare it as a record
|
||||
|
@@ -51,7 +51,7 @@ import static org.testng.Assert.assertNotNull;
|
||||
import org.alfresco.rest.rm.community.base.BaseRMRestTest;
|
||||
import org.alfresco.rest.rm.community.base.TestData;
|
||||
import org.alfresco.rest.rm.community.model.site.RMSite;
|
||||
import org.alfresco.rest.rm.community.requests.igCoreAPI.RMSiteAPI;
|
||||
import org.alfresco.rest.rm.community.requests.gscore.api.RMSiteAPI;
|
||||
import org.alfresco.utility.data.RandomData;
|
||||
import org.alfresco.utility.model.UserModel;
|
||||
import org.alfresco.utility.report.Bug;
|
||||
|
@@ -26,17 +26,32 @@
|
||||
*/
|
||||
package org.alfresco.rest.rm.community.utils;
|
||||
|
||||
import static java.nio.charset.Charset.forName;
|
||||
|
||||
import static com.google.common.io.Resources.getResource;
|
||||
|
||||
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.CONTENT_TYPE;
|
||||
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.NON_ELECTRONIC_RECORD_TYPE;
|
||||
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.RECORD_CATEGORY_TYPE;
|
||||
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.RECORD_FOLDER_TYPE;
|
||||
import static org.alfresco.utility.data.RandomData.getRandomAlphanumeric;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertTrue;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.nio.charset.Charset;
|
||||
|
||||
import org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponent;
|
||||
import org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentProperties;
|
||||
import org.alfresco.rest.rm.community.model.record.Record;
|
||||
import org.alfresco.rest.rm.community.model.record.RecordProperties;
|
||||
import org.alfresco.rest.rm.community.model.recordcategory.RecordCategory;
|
||||
import org.alfresco.rest.rm.community.model.recordcategory.RecordCategoryChild;
|
||||
import org.alfresco.rest.rm.community.model.recordcategory.RecordCategoryChildProperties;
|
||||
import org.alfresco.rest.rm.community.model.recordcategory.RecordCategoryProperties;
|
||||
import org.alfresco.rest.rm.community.model.recordfolder.RecordFolder;
|
||||
import org.alfresco.rest.rm.community.model.recordfolder.RecordFolderProperties;
|
||||
import org.alfresco.rest.rm.community.model.unfiledcontainer.UnfiledContainerChild;
|
||||
import org.alfresco.rest.rm.community.model.unfiledcontainer.UnfiledContainerChildProperties;
|
||||
|
||||
/**
|
||||
* Utility class for file plan component models
|
||||
@@ -51,18 +66,35 @@ public class FilePlanComponentsUtil
|
||||
// Intentionally blank
|
||||
}
|
||||
|
||||
/** image resource file to be used for records body */
|
||||
/** Name of the image resource file to be used for records body */
|
||||
public static final String IMAGE_FILE = "money.JPG";
|
||||
|
||||
/** Title prefix for record category children */
|
||||
public static final String TITLE_PREFIX = "Title for ";
|
||||
|
||||
/** Description prefix for record category children */
|
||||
public static final String DESCRIPTION_PREFIX = "This is the description for";
|
||||
|
||||
|
||||
/**
|
||||
* Helper method to get a file by its name
|
||||
*
|
||||
* @return The file
|
||||
*/
|
||||
public static File getFile(String fileName)
|
||||
{
|
||||
return new File(getResource(fileName).getFile());
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a record model with the given type and a random name (with "Record " prefix)
|
||||
*
|
||||
* @param nodeType The node type
|
||||
* @return The {@link FilePlanComponent} with for the given node type
|
||||
* @return The {@link Record} with for the given node type
|
||||
*/
|
||||
private static FilePlanComponent createRecordModel(String nodeType)
|
||||
private static Record createRecordModel(String nodeType)
|
||||
{
|
||||
return FilePlanComponent.builder()
|
||||
return Record.builder()
|
||||
.name("Record " + getRandomAlphanumeric())
|
||||
.nodeType(nodeType)
|
||||
.build();
|
||||
@@ -71,67 +103,254 @@ public class FilePlanComponentsUtil
|
||||
/**
|
||||
* Creates an electronic record model with a random name (with "Record " prefix)
|
||||
*
|
||||
* @return The electronic record as {@link FilePlanComponent}
|
||||
* @return The electronic record as {@link Record}
|
||||
*/
|
||||
public static FilePlanComponent createElectronicRecordModel()
|
||||
public static Record createElectronicRecordModel()
|
||||
{
|
||||
return createRecordModel(CONTENT_TYPE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a non-electronic unfiled container child model with a random name (with "Record " prefix)
|
||||
*
|
||||
* @return The electronic record as {@link UnfiledContainerChild}
|
||||
*/
|
||||
public static UnfiledContainerChild createElectronicUnfiledContainerChildModel()
|
||||
{
|
||||
return createUnfiledContainerChildRecordModel("Record " + getRandomAlphanumeric(), CONTENT_TYPE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an electronic unfiled container child model with a random name (with "Record " prefix)
|
||||
*
|
||||
* @return The electronic record as {@link UnfiledContainerChild}
|
||||
*/
|
||||
public static UnfiledContainerChild createNonElectronicUnfiledContainerChildModel()
|
||||
{
|
||||
return createUnfiledContainerChildRecordModel("Record " + getRandomAlphanumeric(), NON_ELECTRONIC_RECORD_TYPE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an unfiled records container child record model with the given name and type
|
||||
*
|
||||
* @param name The name of the unfiled records container child
|
||||
* @param nodeType The type of the record category child
|
||||
* @return The {@link UnfiledContainerChild} with the given details
|
||||
*/
|
||||
public static UnfiledContainerChild createUnfiledContainerChildRecordModel(String name, String nodeType)
|
||||
{
|
||||
return UnfiledContainerChild.builder()
|
||||
.name(name)
|
||||
.nodeType(nodeType)
|
||||
.build();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a nonElectronic container child record model with all available properties for the non electronic records
|
||||
*
|
||||
* @param name The name of the unfiled records container child
|
||||
* @param nodeType The type of the record category child
|
||||
* @return The {@link UnfiledContainerChild} with the given details
|
||||
*/
|
||||
public static UnfiledContainerChild createFullNonElectronicUnfiledContainerChildRecordModel(String name, String title, String description, String box, String file,
|
||||
String shelf, String storageLocation, Integer numberOfCopies, Integer physicalSize)
|
||||
{
|
||||
return UnfiledContainerChild.builder()
|
||||
.name(name)
|
||||
.nodeType(NON_ELECTRONIC_RECORD_TYPE)
|
||||
.properties(UnfiledContainerChildProperties.builder()
|
||||
.title(title)
|
||||
.description(description)
|
||||
.box(box)
|
||||
.file(file)
|
||||
.shelf(shelf)
|
||||
.storageLocation(storageLocation)
|
||||
.numberOfCopies(numberOfCopies)
|
||||
.physicalSize(physicalSize)
|
||||
.build())
|
||||
.build();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a non-electronic record model with a random name (with "Record " prefix)
|
||||
*
|
||||
* @return The non-electronic record as {@link FilePlanComponent}
|
||||
* @return The non-electronic record as {@link Record}
|
||||
*/
|
||||
public static FilePlanComponent createNonElectronicRecordModel()
|
||||
public static Record createNonElectronicRecordModel()
|
||||
{
|
||||
return createRecordModel(NON_ELECTRONIC_RECORD_TYPE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a file plan component with the given name, type and title
|
||||
* Creates a non-electronic record model with with all available properties for the non electronic records
|
||||
*
|
||||
* @param name The name of the file plan component
|
||||
* @param type The type of the file plan component
|
||||
* @param title The title of the file plan component
|
||||
* @return The {@link FilePlanComponent} with the given details
|
||||
* @return The non-electronic record as {@link Record}
|
||||
*/
|
||||
public static FilePlanComponent createFilePlanComponentModel(String name, String type, String title)
|
||||
public static Record createFullNonElectronicRecordModel(String name, String title, String description, String box, String file,
|
||||
String shelf, String storageLocation, Integer numberOfCopies, Integer physicalSize)
|
||||
{
|
||||
return FilePlanComponent.builder()
|
||||
return Record.builder()
|
||||
.name(name)
|
||||
.nodeType(NON_ELECTRONIC_RECORD_TYPE)
|
||||
.properties(RecordProperties.builder()
|
||||
.title(title)
|
||||
.description(description)
|
||||
.box(box)
|
||||
.file(file)
|
||||
.shelf(shelf)
|
||||
.storageLocation(storageLocation)
|
||||
.numberOfCopies(numberOfCopies)
|
||||
.physicalSize(physicalSize)
|
||||
.build())
|
||||
.build();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a record model with the given name, description and title
|
||||
*
|
||||
* @param name The name of the record
|
||||
* @param description The description of the record
|
||||
* @param title The title of the record
|
||||
* @return The {@link Record} with the given details
|
||||
*/
|
||||
public static Record createRecordModel(String name, String description, String title)
|
||||
{
|
||||
return Record.builder()
|
||||
.name(name)
|
||||
.nodeType(type)
|
||||
.properties(FilePlanComponentProperties.builder()
|
||||
.title(title)
|
||||
.build())
|
||||
.properties(RecordProperties.builder()
|
||||
.description(description)
|
||||
.title(title)
|
||||
.build())
|
||||
.build();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a record category child model with the given name and type
|
||||
*
|
||||
* @param name The name of the record category child
|
||||
* @param nodeType The type of the record category child
|
||||
* @return The {@link RecordCategoryChild} with the given details
|
||||
*/
|
||||
public static RecordCategoryChild createRecordCategoryChildModel(String name, String nodeType)
|
||||
{
|
||||
return RecordCategoryChild.builder()
|
||||
.name(name)
|
||||
.nodeType(nodeType)
|
||||
.properties(RecordCategoryChildProperties.builder()
|
||||
.title(TITLE_PREFIX + name)
|
||||
.build())
|
||||
.build();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a record category model with the given name and title
|
||||
*
|
||||
* @param name The name of the record category
|
||||
* @param title The title of the record category
|
||||
* @return The {@link RecordCategory} with the given details
|
||||
*/
|
||||
public static RecordCategory createRecordCategoryModel(String name, String title)
|
||||
{
|
||||
return RecordCategory.builder()
|
||||
.name(name)
|
||||
.nodeType(RECORD_CATEGORY_TYPE)
|
||||
.properties(RecordCategoryProperties.builder()
|
||||
.title(title)
|
||||
.build())
|
||||
.build();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a record folder model with the given name and title
|
||||
*
|
||||
* @param name The name of the record folder
|
||||
* @param title The title of the record folder
|
||||
* @return The {@link RecordFolder} with the given details
|
||||
*/
|
||||
public static RecordFolder createRecordFolderModel(String name, String title)
|
||||
{
|
||||
return RecordFolder.builder()
|
||||
.name(name)
|
||||
.nodeType(RECORD_FOLDER_TYPE)
|
||||
.properties(RecordFolderProperties.builder()
|
||||
.title(title)
|
||||
.build())
|
||||
.build();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an unfiled records container child model with the given name and type
|
||||
*
|
||||
* @param name The name of the unfiled records container child
|
||||
* @param nodeType The type of the record category child
|
||||
* @return The {@link UnfiledContainerChild} with the given details
|
||||
*/
|
||||
public static UnfiledContainerChild createUnfiledContainerChildModel(String name, String nodeType)
|
||||
{
|
||||
return UnfiledContainerChild.builder()
|
||||
.name(name)
|
||||
.nodeType(nodeType)
|
||||
.properties(UnfiledContainerChildProperties.builder()
|
||||
.title(TITLE_PREFIX + name)
|
||||
.build())
|
||||
.build();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create temp file with content
|
||||
*
|
||||
* @param name file name
|
||||
* @return {@link File} file
|
||||
* @param name The file name
|
||||
* @return {@link File} The created file
|
||||
*/
|
||||
public static File createTempFile(final String name, String content)
|
||||
{
|
||||
try
|
||||
{
|
||||
// create file
|
||||
// Create file
|
||||
final File file = File.createTempFile(name, ".txt");
|
||||
|
||||
// create writer
|
||||
try (FileOutputStream fos = new FileOutputStream(file);
|
||||
OutputStreamWriter writer = new OutputStreamWriter(fos, Charset.forName("UTF-8").newEncoder()))
|
||||
// Create writer
|
||||
try (OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream(file), forName("UTF-8").newEncoder()))
|
||||
{
|
||||
// place content in file
|
||||
writer.write(content);
|
||||
}
|
||||
|
||||
return file;
|
||||
} catch (Exception exception)
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
throw new RuntimeException("Unable to create test file.", exception);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method to verify all properties of a nonElectronic record
|
||||
*
|
||||
* @param nonElectronicRecord
|
||||
* @param name
|
||||
* @param title
|
||||
* @param description
|
||||
* @param box
|
||||
* @param file
|
||||
* @param shelf
|
||||
* @param storageLocation
|
||||
* @param numberOfCopies
|
||||
* @param physicalSize
|
||||
*/
|
||||
public static void verifyFullNonElectronicRecord(Record nonElectronicRecord, String name, String title, String description, String box, String file,
|
||||
String shelf, String storageLocation, Integer numberOfCopies, Integer physicalSize)
|
||||
{
|
||||
RecordProperties properties = nonElectronicRecord.getProperties();
|
||||
assertEquals(title, properties.getTitle());
|
||||
assertEquals(description, properties.getDescription());
|
||||
assertEquals(box, properties.getBox());
|
||||
assertEquals(file, properties.getFile());
|
||||
assertEquals(shelf, properties.getShelf());
|
||||
assertEquals(storageLocation, properties.getStorageLocation());
|
||||
assertEquals(numberOfCopies, properties.getNumberOfCopies());
|
||||
assertEquals(physicalSize, properties.getPhysicalSize());
|
||||
assertTrue(nonElectronicRecord.getName().contains(properties.getIdentifier()));
|
||||
assertTrue(nonElectronicRecord.getName().contains(name));
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user