Merge remote-tracking branch 'origin/master' into feature/RM-4361_ReadRecordsRestAPI

This commit is contained in:
Kristijan Conkas
2017-01-05 14:18:16 +00:00
9 changed files with 893 additions and 23 deletions

View File

@@ -0,0 +1,56 @@
/*
* #%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.model.fileplancomponents;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import org.alfresco.utility.model.TestModel;
/**
* POJO for File records
*
* @author Rodica Sutu
* @since 2.6
*/
@Builder
@Data
@EqualsAndHashCode (callSuper = true)
@NoArgsConstructor
@AllArgsConstructor
public class RecordBodyFile extends TestModel
{
@JsonProperty
private String targetParentId;
@JsonProperty
private String relativePath;
}

View File

@@ -28,12 +28,19 @@ package org.alfresco.rest.rm.community.requests.igCoreAPI;
import static com.jayway.restassured.RestAssured.given;
import static org.alfresco.rest.core.RestRequest.requestWithBody;
import static org.alfresco.rest.rm.community.util.ParameterCheck.mandatoryObject;
import static org.alfresco.rest.rm.community.util.ParameterCheck.mandatoryString;
import static org.alfresco.rest.rm.community.util.PojoUtility.toJson;
import static org.apache.commons.lang3.StringUtils.EMPTY;
import static org.springframework.http.HttpMethod.POST;
import com.jayway.restassured.response.Response;
import com.jayway.restassured.response.ResponseBody;
import org.alfresco.rest.core.RMRestWrapper;
import org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponent;
import org.alfresco.rest.rm.community.model.fileplancomponents.RecordBodyFile;
import org.alfresco.rest.rm.community.requests.RMModelRequest;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
@@ -81,4 +88,62 @@ public class RecordsAPI extends RMModelRequest
getRMRestWrapper().setStatusCode(Integer.toString(response.getStatusCode()));
return response.getBody();
}
/**
* File the record recordId into file plan structure based on the location sent via the request body
*
* @param recordBodyFile The properties where to file the record
* @param recordId The id of the record to file
* @return The {@link FilePlanComponent} with the given properties
* @throws Exception for the following cases:
* <ul>
* <li>Invalid parameter: {@code recordBodyFile} is not a valid format,{@code recordId} is not a record</li>
* <li>authentication fails</li>
* <li>current user does not have permission to file to {@code fileplanComponentId}</li>
* <li>{@code recordId} does not exist</li>
* <li>targetParentId from recordBodyFile does not exist</li>
* <li>model integrity exception: the action breaks system's integrity restrictions</li>
* </ul>
*
*/
public FilePlanComponent fileRecord(RecordBodyFile recordBodyFile, String recordId) throws Exception
{
mandatoryObject("recordBodyFile", recordBodyFile);
mandatoryString("recordId", recordId);
return fileRecord(recordBodyFile, recordId, EMPTY);
}
/**
* File the record recordId into file plan structure based on the location sent via the request body
*
* @param recordBodyFile The properties where to file the record
* @param recordId The id of the record to file
* @return The {@link FilePlanComponent} with the given properties
* @throws Exception for the following cases:
* <ul>
* <li>Invalid parameter: {@code recordBodyFile} is not a valid format,{@code recordId} is not a record</li>
* <li>authentication fails</li>
* <li>current user does not have permission to file to {@code fileplanComponentId}</li>
* <li>{@code recordId} does not exist</li>
* <li>targetParentId from recordBodyFile does not exist</li>
* <li>model integrity exception: the action breaks system's integrity restrictions</li>
* </ul>
*
*/
public FilePlanComponent fileRecord(RecordBodyFile recordBodyFile, String recordId, String parameters) throws Exception
{
mandatoryObject("requestBodyFile", recordBodyFile);
mandatoryString("recordId", recordId);
return getRMRestWrapper().processModel(FilePlanComponent.class, requestWithBody(
POST,
toJson(recordBodyFile),
"/records/{recordId}/file?{parameters}",
recordId,
parameters
));
}
}

View File

@@ -110,16 +110,25 @@ public interface TestData
public static String CATEGORY_TITLE = "CATEGORY TITLE" + getRandomAlphanumeric();
/**
* The default FOLDER name used when creating categories
* The default FOLDER name used when creating folders
*/
public static String FOLDER_NAME = "FOLDER NAME" + getRandomAlphanumeric();
/**
* The default FOLDER title used when creating categories
* The default FOLDER title used when creating folders
*/
public static String FOLDER_TITLE = "FOLDER TITLE" + getRandomAlphanumeric();
/**
* 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
*/
public static String NONELECTRONIC_RECORD_NAME = "Record nonelectronic" + getRandomAlphanumeric();
/**
* Data Provider with:
* with the object types not allowed as children for a record category

View File

@@ -0,0 +1,403 @@
/*
* #%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.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.utils.FilePlanComponentsUtil.createTempFile;
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.testng.Assert.assertEquals;
import static org.testng.Assert.assertFalse;
import static org.testng.AssertJUnit.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.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.utility.report.Bug;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
/**
* This class contains the tests for
* File Unfiled Record Action REST API
*
* @author Rodica Sutu
* @since 2.6
*/
public class FileRecordsTests extends BaseRMRestTest
{
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();
/**
* 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
{
return new Object[][] {
{ getFilePlanComponent(FILE_PLAN_ALIAS).getId()},
{ getFilePlanComponent(UNFILED_RECORDS_CONTAINER_ALIAS).getId()},
{ getFilePlanComponent(HOLDS_ALIAS).getId() },
{ getFilePlanComponent(TRANSFERS_ALIAS).getId() },
// an arbitrary record category
{ createCategory(getAdminUser(), FILE_PLAN_ALIAS, "Category " + getRandomAlphanumeric()).getId()},
// an arbitrary unfiled records folder
{ createUnfiledRecordsFolder(UNFILED_RECORDS_CONTAINER_ALIAS.toString(), "Unfiled Folder " + getRandomAlphanumeric()).getId() }
};
}
/**
* Given an unfiled record in the root unfiled record container or 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
(
dataProvider = "unfiledContainer",
description = "File record from unfiled containers "
)
public void fileRecordIntoExistingFolder(String unfiledContainerId) 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);
// file the record into the folder created
RecordBodyFile recordBodyFile = RecordBodyFile.builder().targetParentId(folderId).build();
FilePlanComponent 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)
.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())));
}
/**
* Given an unfiled record in the root unfiled record container or 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
(
dataProvider = "unfiledContainer",
description = "File record from unfiled containers into a closed folder "
)
public void fileRecordIntoCloseFolder(String unfiledContainerId) 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);
// 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 filed into the record folder
assertFalse(filePlanComponentAPI.listChildComponents(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())));
// file the non-electronic record into the folder created
recordsAPI.fileRecord(recordBodyFile, recordNonElectId.getId());
// check the response status code
assertStatusCode(FORBIDDEN);
// check the record is added into the record folder
assertFalse(filePlanComponentAPI.listChildComponents(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())));
}
/**
* Given a filed record in a record folder
* And an open record folder
* When I file the filed record into the record folder
* Then the record is filed in both locations
*/
@Test
@Bug(id="RM-4578")
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);
// 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());
// check the response status
assertStatusCode(CREATED);
// create the second folder
String folderToLink = createCategoryFolderInFilePlan().getId();
recordBodyFile = RecordBodyFile.builder().targetParentId(folderToLink).build();
// check the response status
assertStatusCode(CREATED);
// link the electronic record
FilePlanComponent 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());
assertStatusCode(CREATED);
assertTrue(nonElectronicLink.getParentId().equals(parentFolderId));
// check the record is added into the record folder
assertTrue(filePlanComponentAPI.listChildComponents(parentFolderId)
.getEntries()
.stream()
.anyMatch(c -> c.getFilePlanComponentModel().getId().equals(recordFiled.getId()) &&
c.getFilePlanComponentModel().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)
.getEntries().stream()
.anyMatch(c -> c.getFilePlanComponentModel().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)));
// 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)
.getEntries().stream()
.anyMatch(c -> c.getFilePlanComponentModel().getId().equals(nonElectronicFiled.getId())));
}
/**
* Given an unfiled or filed record
* And a container that is NOT a record folder
* When I file the unfiled or filed record to the container
* Then I get an unsupported operation exception
*/
@Test
(
dataProvider = "invalidContainersForFile",
description = "File the unfiled record to the container that is not a record foldr"
)
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);
// file the record into the folder created
RecordBodyFile recordBodyFile = RecordBodyFile.builder().targetParentId(containerId).build();
recordsAPI.fileRecord(recordBodyFile, recordElectronic.getId());
assertStatusCode(BAD_REQUEST);
recordsAPI.fileRecord(recordBodyFile, recordNonElect.getId());
// 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())));
}
}

View File

@@ -97,6 +97,7 @@
<property name="nodeService" ref="NodeService"/>
<property name="fileFolderService" ref="FileFolderService"/>
<property name="dictionaryService" ref="DictionaryService"/>
<property name="authenticationUtil" ref="rm.authenticationUtil"/>
</bean>
<bean id="Records" class="org.springframework.aop.framework.ProxyFactoryBean">

View File

@@ -33,8 +33,8 @@ import org.alfresco.model.ContentModel;
import org.alfresco.module.org_alfresco_module_rm.fileplan.FilePlanService;
import org.alfresco.module.org_alfresco_module_rm.model.RecordsManagementModel;
import org.alfresco.module.org_alfresco_module_rm.record.RecordService;
import org.alfresco.module.org_alfresco_module_rm.util.AuthenticationUtil;
import org.alfresco.repo.node.integrity.IntegrityException;
import org.alfresco.repo.security.authentication.AuthenticationUtil;
import org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork;
import org.alfresco.rest.api.model.Node;
import org.alfresco.rest.framework.core.exceptions.InvalidArgumentException;
@@ -48,10 +48,17 @@ import org.alfresco.service.cmr.model.FileFolderService;
import org.alfresco.service.cmr.model.FileNotFoundException;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.dao.ConcurrencyFailureException;
import org.springframework.extensions.surf.util.ParameterCheck;
/**
* Centralizes access to record services
*
* @author Ana Bozianu
* @since 2.6
*/
public class RecordsImpl implements Records, InitializingBean
{
protected RecordService recordService;
@@ -59,6 +66,7 @@ public class RecordsImpl implements Records, InitializingBean
protected NodeService nodeService;
protected FileFolderService fileFolderService;
protected DictionaryService dictionaryService;
protected AuthenticationUtil authenticationUtil;
protected RMNodes nodes;
public void setRecordService(RecordService recordService)
@@ -86,6 +94,11 @@ public class RecordsImpl implements Records, InitializingBean
this.dictionaryService = dictionaryService;
}
public void setAuthenticationUtil(AuthenticationUtil authenticationUtil)
{
this.authenticationUtil = authenticationUtil;
}
public void setNodes(RMNodes nodes)
{
this.nodes = nodes;
@@ -94,17 +107,11 @@ public class RecordsImpl implements Records, InitializingBean
@Override
public Node declareFileAsRecord(String fileId, Parameters parameters)
{
// Parameter check
if ((fileId == null) || (fileId.isEmpty()))
{
throw new InvalidArgumentException("Missing fileId");
}
// Get file to be declared
NodeRef fileNodeRef = nodes.validateNode(fileId) ;
// Get fileplan
NodeRef filePlan = AuthenticationUtil.runAsSystem(new RunAsWork<NodeRef>()
NodeRef filePlan = authenticationUtil.runAsSystem(new RunAsWork<NodeRef>()
{
@Override
public NodeRef doWork()
@@ -126,10 +133,7 @@ public class RecordsImpl implements Records, InitializingBean
@Override
public Node fileOrLinkRecord(String recordId, TargetContainer target, Parameters parameters)
{
ParameterCheck.mandatoryString("recordId", recordId);
if((target.getTargetParentId() == null || target.getTargetParentId().isEmpty()) &&
(target.getRelativePath() == null || target.getRelativePath().isEmpty()))
if(StringUtils.isBlank(target.getTargetParentId()) && StringUtils.isBlank(target.getRelativePath()))
{
throw new InvalidParameterException("No target folder information was provided");
}
@@ -142,7 +146,7 @@ public class RecordsImpl implements Records, InitializingBean
if(parentContainerId == null || parentContainerId.isEmpty())
{
// If target container not provided get fileplan
parentContainerId = AuthenticationUtil.runAsSystem(new RunAsWork<String>()
parentContainerId = authenticationUtil.runAsSystem(new RunAsWork<String>()
{
@Override
public String doWork()

View File

@@ -87,12 +87,7 @@ public class RecordsEntityResource implements BinaryResourceAction.Read,
@WebApiDescription(title = "File record", description="File a record into fileplan.")
public Node fileRecord(String recordId, TargetContainer target, Parameters parameters, WithResponse withResponse)
{
try{
return records.fileOrLinkRecord(recordId, target, parameters);
}catch(Exception ex)
{
throw ex;
}
return records.fileOrLinkRecord(recordId, target, parameters);
}
@Override

View File

@@ -0,0 +1,337 @@
/*
* #%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.rm.rest.api.impl;
import static org.alfresco.model.ContentModel.TYPE_CONTENT;
import static org.alfresco.module.org_alfresco_module_rm.model.RecordsManagementModel.TYPE_RECORD_FOLDER;
import static org.alfresco.module.org_alfresco_module_rm.model.RecordsManagementModel.TYPE_UNFILED_RECORD_CONTAINER;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import java.security.InvalidParameterException;
import org.alfresco.module.org_alfresco_module_rm.fileplan.FilePlanService;
import org.alfresco.module.org_alfresco_module_rm.record.RecordService;
import org.alfresco.module.org_alfresco_module_rm.test.util.AlfMock;
import org.alfresco.module.org_alfresco_module_rm.test.util.MockAuthenticationUtilHelper;
import org.alfresco.module.org_alfresco_module_rm.util.AuthenticationUtil;
import org.alfresco.rest.framework.resource.parameters.Parameters;
import org.alfresco.rm.rest.api.RMNodes;
import org.alfresco.rm.rest.api.Records;
import org.alfresco.rm.rest.api.model.TargetContainer;
import org.alfresco.service.cmr.dictionary.DictionaryService;
import org.alfresco.service.cmr.model.FileFolderService;
import org.alfresco.service.cmr.repository.ChildAssociationRef;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.junit.Before;
import org.junit.Test;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
/**
* Unit tests for RecordsImpl
*
* @author Ana Bozianu
* @since 2.6
*/
public class RecordsImplUnitTest
{
@Mock
private RecordService mockedRecordService;
@Mock
protected FilePlanService mockedFilePlanService;
@Mock
protected NodeService mockedNodeService;
@Mock
protected FileFolderService mockedFileFolderService;
@Mock
protected DictionaryService mockedDictionaryService;
@Mock
protected AuthenticationUtil mockedAuthenticationUtil;
@Mock
protected RMNodes mockedNodes;
@InjectMocks
private RecordsImpl recordsImpl;
@Before
public void before()
{
MockitoAnnotations.initMocks(this);
// setup mocked authentication util
MockAuthenticationUtilHelper.setup(mockedAuthenticationUtil);
}
/**
* Given a file and an existing fileplan
* When declaring a file as record
* Then a record is created under the existing fileplan from the provided file
*/
@Test
public void testDeclareFileAsRecord()
{
/*
* Given a file and an existing fileplan
*/
NodeRef mockedFile = AlfMock.generateNodeRef(mockedNodeService);
when(mockedNodes.validateNode(mockedFile.getId())).thenReturn(mockedFile);
NodeRef fileplan = AlfMock.generateNodeRef(mockedNodeService);
when(mockedFilePlanService.getFilePlanBySiteId(FilePlanService.DEFAULT_RM_SITE_ID)).thenReturn(fileplan);
/*
* When declare the file as record
*/
Parameters params = Mockito.mock(Parameters.class);
when(params.getParameter(Records.PARAM_HIDE_RECORD)).thenReturn("true");
recordsImpl.declareFileAsRecord(mockedFile.getId(), params);
/*
* Then a record is created under the existing fileplan from the provided file
*/
verify(mockedRecordService).createRecord(fileplan, mockedFile, false);
verify(mockedNodes).getFolderOrDocument(mockedFile.getId(), params);
}
/**
* Given a record
* When trying to filing a record providing a blank destination path
* Then an InvalidParameterException is thrown
*/
@Test(expected=InvalidParameterException.class)
public void testFileRecord_BlankDestinationPath()
{
/*
* Given a record
*/
NodeRef mockedRecord = AlfMock.generateNodeRef(mockedNodeService);
when(mockedNodes.validateNode(mockedRecord.getId())).thenReturn(mockedRecord);
/*
* When trying to filing a record providing a blank destination path
*/
Parameters params = Mockito.mock(Parameters.class);
TargetContainer target = new TargetContainer();
recordsImpl.fileOrLinkRecord(mockedRecord.getId(), target, params);
}
/**
* Given an unfiled record and an existing record folder
* When trying to file the record in the record folder
* Then the record is moved under the destination folder
*/
@Test
public void testFileRecord_DestinationById() throws Exception
{
/*
* Given an unfiled record and an existing record folder
*/
// mock the record to file
NodeRef mockedRecord = AlfMock.generateNodeRef(mockedNodeService);
when(mockedNodes.validateNode(mockedRecord.getId())).thenReturn(mockedRecord);
// mock the current primary parent
NodeRef mockedPrimaryParent = AlfMock.generateNodeRef(mockedNodeService);
ChildAssociationRef mockedChildAssoc = mock(ChildAssociationRef.class);
when(mockedChildAssoc.getParentRef()).thenReturn(mockedPrimaryParent);
when(mockedNodeService.getPrimaryParent(mockedRecord)).thenReturn(mockedChildAssoc);
when(mockedNodeService.getType(mockedPrimaryParent)).thenReturn(TYPE_UNFILED_RECORD_CONTAINER);
when(mockedDictionaryService.isSubClass(TYPE_UNFILED_RECORD_CONTAINER, TYPE_RECORD_FOLDER)).thenReturn(false);
// mock the target record folder to file the record into
NodeRef mockedTargetRecordFolder = AlfMock.generateNodeRef(mockedNodeService);
when(mockedNodes.getOrCreatePath(mockedTargetRecordFolder.getId(), null, TYPE_CONTENT)).thenReturn(mockedTargetRecordFolder);
when(mockedNodeService.getType(mockedTargetRecordFolder)).thenReturn(TYPE_RECORD_FOLDER);
when(mockedDictionaryService.isSubClass(TYPE_RECORD_FOLDER, TYPE_RECORD_FOLDER)).thenReturn(true);
/*
* When trying to file the record in the record folder
*/
TargetContainer destination = new TargetContainer();
destination.setTargetParentId(mockedTargetRecordFolder.getId());
Parameters params = Mockito.mock(Parameters.class);
recordsImpl.fileOrLinkRecord(mockedRecord.getId(), destination, params);
/*
* Then the record is moved under the destination folder
*/
verify(mockedNodes).getOrCreatePath(mockedTargetRecordFolder.getId(), null, TYPE_CONTENT);
verify(mockedFileFolderService).moveFrom(mockedRecord, mockedPrimaryParent, mockedTargetRecordFolder, null);
}
/**
* Given an unfiled record
* and an existing record folder with relative path category/recordFolder from fileplan
* When trying to file the record using a relative path and no target id
* Then the record is moved under the destination folder relative to the fileplan
*/
@Test
public void testFileRecord_DestinationRelativeToFileplan() throws Exception
{
/*
* Given an unfiled record and an existing record folder
*/
// mock the record to file
NodeRef mockedRecord = AlfMock.generateNodeRef(mockedNodeService);
when(mockedNodes.validateNode(mockedRecord.getId())).thenReturn(mockedRecord);
// mock the current primary parent
NodeRef mockedPrimaryParent = AlfMock.generateNodeRef(mockedNodeService);
ChildAssociationRef mockedChildAssoc = mock(ChildAssociationRef.class);
when(mockedChildAssoc.getParentRef()).thenReturn(mockedPrimaryParent);
when(mockedNodeService.getPrimaryParent(mockedRecord)).thenReturn(mockedChildAssoc);
when(mockedNodeService.getType(mockedPrimaryParent)).thenReturn(TYPE_UNFILED_RECORD_CONTAINER);
when(mockedDictionaryService.isSubClass(TYPE_UNFILED_RECORD_CONTAINER, TYPE_RECORD_FOLDER)).thenReturn(false);
// mock the fileplan
NodeRef fileplan = AlfMock.generateNodeRef(mockedNodeService);
when(mockedFilePlanService.getFilePlanBySiteId(FilePlanService.DEFAULT_RM_SITE_ID)).thenReturn(fileplan);
// mock the target record folder to file the record into
String relativePath = "category/recordFolder";
NodeRef mockedTargetRecordFolder = AlfMock.generateNodeRef(mockedNodeService);
when(mockedNodes.getOrCreatePath(fileplan.getId(), relativePath, TYPE_CONTENT)).thenReturn(mockedTargetRecordFolder);
when(mockedNodeService.getType(mockedTargetRecordFolder)).thenReturn(TYPE_RECORD_FOLDER);
when(mockedDictionaryService.isSubClass(TYPE_RECORD_FOLDER, TYPE_RECORD_FOLDER)).thenReturn(true);
/*
* When trying to file the record using a relative path and no target id
*/
TargetContainer destination = new TargetContainer();
destination.setRelativePath(relativePath);
Parameters params = Mockito.mock(Parameters.class);
recordsImpl.fileOrLinkRecord(mockedRecord.getId(), destination, params);
/*
* Then the record is moved under the destination folder relative to the fileplan
*/
verify(mockedNodes).getOrCreatePath(fileplan.getId(), relativePath, TYPE_CONTENT);
verify(mockedFileFolderService).moveFrom(mockedRecord, mockedPrimaryParent, mockedTargetRecordFolder, null);
}
/**
* Given an unfiled record
* and an existing record folder with relative path category/recordFolder from a given category
* When trying to file the record describing the target folder with the category id and the relative path
* Then the record is moved under the correct destination folder
*/
@Test
public void testFileRecord_DestinationRelativeToProvidedId() throws Exception
{
/*
* Given an unfiled record and an existing record folder with relative path category/recordFolder from a given category
*/
// mock the record to file
NodeRef mockedRecord = AlfMock.generateNodeRef(mockedNodeService);
when(mockedNodes.validateNode(mockedRecord.getId())).thenReturn(mockedRecord);
// mock the current primary parent
NodeRef mockedPrimaryParent = AlfMock.generateNodeRef(mockedNodeService);
ChildAssociationRef mockedChildAssoc = mock(ChildAssociationRef.class);
when(mockedChildAssoc.getParentRef()).thenReturn(mockedPrimaryParent);
when(mockedNodeService.getPrimaryParent(mockedRecord)).thenReturn(mockedChildAssoc);
when(mockedNodeService.getType(mockedPrimaryParent)).thenReturn(TYPE_UNFILED_RECORD_CONTAINER);
when(mockedDictionaryService.isSubClass(TYPE_UNFILED_RECORD_CONTAINER, TYPE_RECORD_FOLDER)).thenReturn(false);
// mock the target category
NodeRef mockedTargetCategory = AlfMock.generateNodeRef(mockedNodeService);
// mock the target record folder to file the record into
String relativePath = "category/recordFolder";
NodeRef mockedTargetRecordFolder = AlfMock.generateNodeRef(mockedNodeService);
when(mockedNodes.getOrCreatePath(mockedTargetCategory.getId(), relativePath, TYPE_CONTENT)).thenReturn(mockedTargetRecordFolder);
when(mockedNodeService.getType(mockedTargetRecordFolder)).thenReturn(TYPE_RECORD_FOLDER);
when(mockedDictionaryService.isSubClass(TYPE_RECORD_FOLDER, TYPE_RECORD_FOLDER)).thenReturn(true);
/*
* When trying to file the record describing the target folder with the category id and the relative path
*/
TargetContainer destination = new TargetContainer();
destination.setTargetParentId(mockedTargetCategory.getId());
destination.setRelativePath(relativePath);
Parameters params = Mockito.mock(Parameters.class);
recordsImpl.fileOrLinkRecord(mockedRecord.getId(), destination, params);
/*
* Then the record is moved under the correct destination folder
*/
verify(mockedNodes).getOrCreatePath(mockedTargetCategory.getId(), relativePath, TYPE_CONTENT);
verify(mockedFileFolderService).moveFrom(mockedRecord, mockedPrimaryParent, mockedTargetRecordFolder, null);
}
/**
* Given an filed record and an existing record folder
* When trying to link the record to the record folder
* Then the record is linked to the destination folder
*/
@Test
public void testLinkRecord()
{
/*
* Given an filed record and an existing record folder
*/
// mock the record to link
NodeRef mockedRecord = AlfMock.generateNodeRef(mockedNodeService);
when(mockedNodes.validateNode(mockedRecord.getId())).thenReturn(mockedRecord);
// mock the current primary parent
NodeRef mockedPrimaryParent = AlfMock.generateNodeRef(mockedNodeService);
ChildAssociationRef mockedChildAssoc = mock(ChildAssociationRef.class);
when(mockedChildAssoc.getParentRef()).thenReturn(mockedPrimaryParent);
when(mockedNodeService.getPrimaryParent(mockedRecord)).thenReturn(mockedChildAssoc);
when(mockedNodeService.getType(mockedPrimaryParent)).thenReturn(TYPE_RECORD_FOLDER);
when(mockedDictionaryService.isSubClass(TYPE_RECORD_FOLDER, TYPE_RECORD_FOLDER)).thenReturn(true);
// mock the target record folder to file the record into
NodeRef mockedTargetRecordFolder = AlfMock.generateNodeRef(mockedNodeService);
when(mockedNodes.getOrCreatePath(mockedTargetRecordFolder.getId(), null, TYPE_CONTENT)).thenReturn(mockedTargetRecordFolder);
when(mockedNodeService.getType(mockedTargetRecordFolder)).thenReturn(TYPE_RECORD_FOLDER);
/*
* When trying to link the record to the record folder
*/
TargetContainer destination = new TargetContainer();
destination.setTargetParentId(mockedTargetRecordFolder.getId());
Parameters params = Mockito.mock(Parameters.class);
recordsImpl.fileOrLinkRecord(mockedRecord.getId(), destination, params);
/*
* Then the record is linked to the destination folder
*/
verify(mockedNodes).getOrCreatePath(mockedTargetRecordFolder.getId(), null, TYPE_CONTENT);
verify(mockedRecordService).link(mockedRecord, mockedTargetRecordFolder);
}
}

View File

@@ -667,7 +667,7 @@ paths:
type: string
- name: hideRecord
in: query
description: Flag to indicate whether the record should be hiden from the curent parent folder.
description: Flag to indicate whether the record should be hidden from the current parent folder.
type: boolean
default: false
- $ref: '#/parameters/IGNodeEntryIncludeParam'