Merge remote-tracking branch 'remotes/origin/master' into feature/APPS-41_DeclareAndFileAsRecordRuleTests

This commit is contained in:
Claudia Agache
2020-06-16 12:56:20 +03:00
20 changed files with 883 additions and 261 deletions

View File

@@ -15,7 +15,7 @@
<maven.javadoc.skip>false</maven.javadoc.skip> <maven.javadoc.skip>false</maven.javadoc.skip>
<ags.share>alfresco-governance-services-community-share</ags.share> <ags.share>alfresco-governance-services-community-share</ags.share>
<ags.repo>alfresco-governance-services-community-repo</ags.repo> <ags.repo>alfresco-governance-services-community-repo</ags.repo>
<tas.restapi.version>6.0.1.2</tas.restapi.version> <tas.restapi.version>1.38</tas.restapi.version>
<fluent.json.version>2.0.0</fluent.json.version> <fluent.json.version>2.0.0</fluent.json.version>
<jackson.databind.version>2.7.7</jackson.databind.version> <jackson.databind.version>2.7.7</jackson.databind.version>
</properties> </properties>
@@ -54,7 +54,7 @@
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.alfresco.tas</groupId> <groupId>org.alfresco.tas</groupId>
<artifactId>restapi-test</artifactId> <artifactId>restapi</artifactId>
<version>${tas.restapi.version}</version> <version>${tas.restapi.version}</version>
<exclusions> <exclusions>
<exclusion> <exclusion>
@@ -63,18 +63,6 @@
</exclusion> </exclusion>
</exclusions> </exclusions>
</dependency> </dependency>
<dependency>
<groupId>org.alfresco.tas</groupId>
<artifactId>restapi-test</artifactId>
<version>${tas.restapi.version}</version>
<type>test-jar</type>
<exclusions>
<exclusion>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency> <dependency>
<groupId>org.projectlombok</groupId> <groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId> <artifactId>lombok</artifactId>

View File

@@ -56,4 +56,7 @@ public class FilePlanComponentAspects
// retention schedule cut off aspect // retention schedule cut off aspect
public static final String CUT_OFF_ASPECT = "rma:cutOff"; public static final String CUT_OFF_ASPECT = "rma:cutOff";
//declare version as record aspect
public static final String VERSION_AS_RECORD="rmv:versionRecord";
} }

View File

@@ -58,6 +58,7 @@ public class FilePlanComponentFields
public static final String PROPERTIES_RECORD_SEARCH_DISPOSITION_ACTION_NAME = "rma:recordSearchDispositionActionName"; public static final String PROPERTIES_RECORD_SEARCH_DISPOSITION_ACTION_NAME = "rma:recordSearchDispositionActionName";
public static final String PROPERTIES_RECORD_SEARCH_DISPOSITION_EVENTS_ELIGIBLE = "rma:recordSearchDispositionEventsEligible"; public static final String PROPERTIES_RECORD_SEARCH_DISPOSITION_EVENTS_ELIGIBLE = "rma:recordSearchDispositionEventsEligible";
public static final String PROPERTIES_RECORD_SEARCH_DISPOSITION_INSTRUCTIONS = "rma:recordSearchDispositionInstructions"; public static final String PROPERTIES_RECORD_SEARCH_DISPOSITION_INSTRUCTIONS = "rma:recordSearchDispositionInstructions";
public static final String PROPERTIES_RECORD_SEARCH_DISPOSITION_EVENTS = "rma:recordSearchDispositionEvents";
public static final String PROPERTIES_DECLASSIFICATION_REVIEW_COMPLETED_BY = "rma:declassificationReviewCompletedBy"; public static final String PROPERTIES_DECLASSIFICATION_REVIEW_COMPLETED_BY = "rma:declassificationReviewCompletedBy";
public static final String PROPERTIES_DECLASSIFICATION_REVIEW_COMPLETED_AT = "rma:declassificationReviewCompletedAt"; public static final String PROPERTIES_DECLASSIFICATION_REVIEW_COMPLETED_AT = "rma:declassificationReviewCompletedAt";
@@ -87,6 +88,8 @@ public class FilePlanComponentFields
/** Electronic record properties */ /** Electronic record properties */
public static final String PROPERTIES_VERSION_TYPE = "cm:versionType"; public static final String PROPERTIES_VERSION_TYPE = "cm:versionType";
public static final String PROPERTIES_VERSION_LABEL = "cm:versionLabel"; public static final String PROPERTIES_VERSION_LABEL = "cm:versionLabel";
public static final String PROPERTIES_VERSIONED_NODEREF = "rmv:versionedNodeRef";
public static final String PROPERTIES_RMV_VERSIONED = "rmv:versionLabel";
public static final String PROPERTIES_DATE_TIME_ORIGINAL = "exif:dateTimeOriginal"; public static final String PROPERTIES_DATE_TIME_ORIGINAL = "exif:dateTimeOriginal";
public static final String PROPERTIES_EXPOSURE_TIME = "exif:exposureTime"; public static final String PROPERTIES_EXPOSURE_TIME = "exif:exposureTime";
public static final String PROPERTIES_FLASH = "exif:flash"; public static final String PROPERTIES_FLASH = "exif:flash";

View File

@@ -65,11 +65,13 @@ import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanCo
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentFields.PROPERTIES_RESOLUTION_UNIT; import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentFields.PROPERTIES_RESOLUTION_UNIT;
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentFields.PROPERTIES_REVIEW_AS_OF; import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentFields.PROPERTIES_REVIEW_AS_OF;
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentFields.PROPERTIES_RMV_VERSIONED;
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentFields.PROPERTIES_ROOT_NODE_REF; import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentFields.PROPERTIES_ROOT_NODE_REF;
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentFields.PROPERTIES_SHELF; import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentFields.PROPERTIES_SHELF;
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentFields.PROPERTIES_SOFTWARE; import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentFields.PROPERTIES_SOFTWARE;
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentFields.PROPERTIES_STORAGE_LOCATION; import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentFields.PROPERTIES_STORAGE_LOCATION;
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentFields.PROPERTIES_TITLE; import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentFields.PROPERTIES_TITLE;
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentFields.PROPERTIES_VERSIONED_NODEREF;
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentFields.PROPERTIES_VERSION_LABEL; import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentFields.PROPERTIES_VERSION_LABEL;
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentFields.PROPERTIES_VERSION_TYPE; import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentFields.PROPERTIES_VERSION_TYPE;
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentFields.PROPERTIES_X_RESOLUTION; import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentFields.PROPERTIES_X_RESOLUTION;
@@ -133,6 +135,12 @@ public class RecordProperties extends TestModel
@JsonProperty (PROPERTIES_VERSION_LABEL) @JsonProperty (PROPERTIES_VERSION_LABEL)
private String versionLabel; private String versionLabel;
@JsonProperty(PROPERTIES_VERSIONED_NODEREF)
private String versionedNodeRef;
@JsonProperty (PROPERTIES_RMV_VERSIONED)
private String recordVersionLabel;
@JsonProperty (PROPERTIES_DATE_TIME_ORIGINAL) @JsonProperty (PROPERTIES_DATE_TIME_ORIGINAL)
private String dateTimeOriginal; private String dateTimeOriginal;

View File

@@ -32,6 +32,7 @@ import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanCo
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentFields.PROPERTIES_IS_CLOSED; import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentFields.PROPERTIES_IS_CLOSED;
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentFields.PROPERTIES_LOCATION; import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentFields.PROPERTIES_LOCATION;
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentFields.PROPERTIES_OWNER; import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentFields.PROPERTIES_OWNER;
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentFields.PROPERTIES_RECORD_SEARCH_DISPOSITION_EVENTS;
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentFields.PROPERTIES_RECORD_SEARCH_HAS_DISPOSITION_SCHEDULE; import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentFields.PROPERTIES_RECORD_SEARCH_HAS_DISPOSITION_SCHEDULE;
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentFields.PROPERTIES_RECORD_SEARCH_DISPOSITION_PERIOD_EXPRESSION; import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentFields.PROPERTIES_RECORD_SEARCH_DISPOSITION_PERIOD_EXPRESSION;
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentFields.PROPERTIES_RECORD_SEARCH_DISPOSITION_AUTHORITY; import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentFields.PROPERTIES_RECORD_SEARCH_DISPOSITION_AUTHORITY;
@@ -132,6 +133,10 @@ public class RecordCategoryChildProperties extends TestModel
@JsonProperty (PROPERTIES_RECORD_SEARCH_DISPOSITION_INSTRUCTIONS) @JsonProperty (PROPERTIES_RECORD_SEARCH_DISPOSITION_INSTRUCTIONS)
private String recordSearchDispositionInstructions; private String recordSearchDispositionInstructions;
@JsonProperty (PROPERTIES_RECORD_SEARCH_DISPOSITION_EVENTS)
private Boolean recordSearchDispositionEvents;
@JsonProperty (PROPERTIES_OWNER) @JsonProperty (PROPERTIES_OWNER)
private Owner owner; private Owner owner;
} }

View File

@@ -47,11 +47,13 @@ import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanCo
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentFields.PROPERTIES_PIXEL_Y_DIMENSION; import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentFields.PROPERTIES_PIXEL_Y_DIMENSION;
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentFields.PROPERTIES_RECORD_SEARCH_HAS_DISPOSITION_SCHEDULE; import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentFields.PROPERTIES_RECORD_SEARCH_HAS_DISPOSITION_SCHEDULE;
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentFields.PROPERTIES_RESOLUTION_UNIT; import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentFields.PROPERTIES_RESOLUTION_UNIT;
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentFields.PROPERTIES_RMV_VERSIONED;
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentFields.PROPERTIES_ROOT_NODE_REF; import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentFields.PROPERTIES_ROOT_NODE_REF;
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentFields.PROPERTIES_SHELF; import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentFields.PROPERTIES_SHELF;
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentFields.PROPERTIES_SOFTWARE; import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentFields.PROPERTIES_SOFTWARE;
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentFields.PROPERTIES_STORAGE_LOCATION; import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentFields.PROPERTIES_STORAGE_LOCATION;
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentFields.PROPERTIES_TITLE; import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentFields.PROPERTIES_TITLE;
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentFields.PROPERTIES_VERSIONED_NODEREF;
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentFields.PROPERTIES_VERSION_LABEL; import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentFields.PROPERTIES_VERSION_LABEL;
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentFields.PROPERTIES_VERSION_TYPE; import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentFields.PROPERTIES_VERSION_TYPE;
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentFields.PROPERTIES_X_RESOLUTION; import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentFields.PROPERTIES_X_RESOLUTION;
@@ -111,6 +113,12 @@ public class UnfiledContainerChildProperties extends TestModel
@JsonProperty (PROPERTIES_VERSION_LABEL) @JsonProperty (PROPERTIES_VERSION_LABEL)
private String versionLabel; private String versionLabel;
@JsonProperty(PROPERTIES_VERSIONED_NODEREF)
private String versionedNodeRef;
@JsonProperty (PROPERTIES_RMV_VERSIONED)
private String recordVersionLabel;
@JsonProperty (PROPERTIES_DATE_TIME_ORIGINAL) @JsonProperty (PROPERTIES_DATE_TIME_ORIGINAL)
private String dateTimeOriginal; private String dateTimeOriginal;

View File

@@ -75,4 +75,31 @@ public class ActionsExecutionAPI extends RMModelRequest
return getRmRestWrapper().withCoreAPI().usingActions() return getRmRestWrapper().withCoreAPI().usingActions()
.executeAction(ActionsOnRule.DECLARE_AS_RECORD.getActionValue(), targetNode); .executeAction(ActionsOnRule.DECLARE_AS_RECORD.getActionValue(), targetNode);
} }
/**
* Declares and file a document version as record to a record folder using v1 actions api
*
* @param targetNode the node on which the action is executed
* @param destinationPath the path to the record folder
* @throws Exception
*/
public JSONObject declareAndFileVersionAsRecord(RepoTestModel targetNode, String destinationPath) throws Exception
{
return getRmRestWrapper().withCoreAPI().usingActions()
.executeAction(ActionsOnRule.DECLARE_VERSION_AS_RECORD.getActionValue(), targetNode,
ImmutableMap.of("path", destinationPath));
}
/**
* Declares a document version as record using v1 actions api
*
* @param targetNode the node on which the action is executed
* @throws Exception
*/
public JSONObject declareVersionAsRecord(RepoTestModel targetNode) throws Exception
{
return getRmRestWrapper().withCoreAPI().usingActions()
.executeAction(ActionsOnRule.DECLARE_VERSION_AS_RECORD.getActionValue(), targetNode);
}
} }

View File

@@ -32,6 +32,7 @@ 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.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.FilePlanComponentAlias.UNFILED_RECORDS_CONTAINER_ALIAS;
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentAspects.ASPECTS_COMPLETED_RECORD; import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentAspects.ASPECTS_COMPLETED_RECORD;
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentAspects.VERSION_AS_RECORD;
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.CONTENT_TYPE; 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.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_CATEGORY_TYPE;
@@ -879,4 +880,71 @@ public class BaseRMRestTest extends RestTest
return false; return false;
} }
} }
/**
* Helper method to verify if the document version is declared as record version in unfiled container
*
* @param testFile the file declared as record version
* @param version the document version
* @return true if matching record version is found in unfiled record container, false otherwise
*/
protected boolean isRecordVersionInUnfiledRecords(FileModel testFile, String version)
{
try
{
Utility.sleep(5000, 15000,
() -> {
UnfiledContainerChildEntry matchingRecord = getRestAPIFactory().getUnfiledContainersAPI()
.getUnfiledContainerChildren(UNFILED_RECORDS_CONTAINER_ALIAS, "include=properties,aspectNames")
.getEntries()
.stream()
.filter(e -> e.getEntry().getName().contains(testFile.getName().replace(".txt", ""))
&& e.getEntry().getProperties().getVersionedNodeRef().equals(testFile.getNodeRefWithoutVersion())
&& e.getEntry().getProperties().getRecordVersionLabel().equalsIgnoreCase(version)
)
.findFirst().get();
assertTrue(hasAspect(matchingRecord.getEntry().getId(), VERSION_AS_RECORD));
});
return true;
}
catch (AssertionError | Exception e)
{
return false;
}
}
/**
* Helper method to verify if the document version is declared as record version in a specific record folder
*
* @param testFile the file declared as record version
* @param recordFolder the record folder where the versioned record is filled
* @param version the document version
* @return true if matching record version is found in record folder, false otherwise
*/
protected boolean isRecordVersionInRecordFolder(FileModel testFile, RecordCategoryChild recordFolder,
String version)
{
try
{
Utility.sleep(5000, 15000,
() -> {
RecordFolderEntry matchingRecord = getRestAPIFactory().getRecordFolderAPI()
.getRecordFolderChildren(recordFolder.getId(),"include=properties,aspectNames")
.getEntries()
.stream()
.filter(e -> e.getEntry().getName().contains(testFile.getName().replace(".txt", ""))
&& e.getEntry().getProperties().getVersionedNodeRef().equals(testFile.getNodeRefWithoutVersion())
&& e.getEntry().getProperties().getRecordVersionLabel().equalsIgnoreCase(version)
)
.findFirst().get();
assertTrue(hasAspect(matchingRecord.getEntry().getId(), VERSION_AS_RECORD));
});
return true;
}
catch (AssertionError | Exception e)
{
return false;
}
}
} }

View File

@@ -0,0 +1,304 @@
/*-
* #%L
* Alfresco Records Management Module
* %%
* Copyright (C) 2005 - 2020 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.files;
import static org.alfresco.rest.rm.community.base.TestData.HOLD_DESCRIPTION;
import static org.alfresco.rest.rm.community.base.TestData.HOLD_REASON;
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.model.user.UserPermissions.PERMISSION_FILING;
import static org.alfresco.rest.rm.community.model.user.UserPermissions.PERMISSION_READ_RECORDS;
import static org.alfresco.rest.rm.community.model.user.UserRoles.ROLE_RM_POWER_USER;
import static org.alfresco.utility.data.RandomData.getRandomAlphanumeric;
import static org.alfresco.utility.data.RandomData.getRandomName;
import static org.alfresco.utility.report.log.Step.STEP;
import static org.springframework.http.HttpStatus.ACCEPTED;
import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertTrue;
import java.io.File;
import java.util.List;
import org.alfresco.dataprep.CMISUtil;
import org.alfresco.rest.rm.community.base.BaseRMRestTest;
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.unfiledcontainer.UnfiledContainerChild;
import org.alfresco.rest.rm.community.util.DockerHelper;
import org.alfresco.rest.v0.HoldsAPI;
import org.alfresco.rest.v0.service.RoleService;
import org.alfresco.test.AlfrescoTest;
import org.alfresco.utility.Utility;
import org.alfresco.utility.model.FileModel;
import org.alfresco.utility.model.FolderModel;
import org.alfresco.utility.model.SiteModel;
import org.alfresco.utility.model.UserModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
/**
* API tests for declaring a document version as record and filing to a record folder location within the file plan
*
* @author Rodica Sutu
* @since 3.4
*/
@AlfrescoTest (jira = "APPS-35")
public class FileVersionAsRecordTests extends BaseRMRestTest
{
private final static String DESTINATION_PATH_NOT_FOUND_EXC = "Unable to execute declare-version-record action, " +
"because the destination path could not be found.";
private final static String INVALID_DESTINATION_PATH_EXC = "Unable to execute declare-version-record action, " +
"because the destination path is invalid.";
private final static String DESTINATION_PATH_NOT_RECORD_FOLDER_EXC = "Unable to execute declare-version-record " +
"action, because the destination path is not a record folder.";
private final static String ACCESS_DENIED_EXC = "Access Denied. You do not have the appropriate " +
"permissions to perform this operation.";
private final static String HOLD_NAME = getRandomName("holdName");
private UserModel userFillingPermission, userReadOnlyPermission;
private SiteModel publicSite;
private FileModel testFile;
private FolderModel testFolder;
private RecordCategory recordCategory;
private RecordCategoryChild recordFolder, closedRecordFolder, heldRecordFolder;
private UnfiledContainerChild unfiledContainerFolder;
@Autowired
private RoleService roleService;
@Autowired
private DockerHelper dockerHelper;
@Autowired
private HoldsAPI holdsAPI;
@BeforeClass (alwaysRun = true)
public void declareAndFileVersionAsRecordSetup() throws Exception
{
STEP("Create test collaboration site to store documents in.");
publicSite = dataSite.usingAdmin().createPublicRandomSite();
STEP("Create a test folder within the collaboration site");
testFolder = dataContent.usingAdmin().usingSite(publicSite).createFolder();
STEP("Create record categories and record folders");
recordCategory = createRootCategory(getRandomName("recordCategory"));
recordFolder = createFolder(recordCategory.getId(), getRandomName("recordFolder"));
closedRecordFolder = createFolder(recordCategory.getId(), getRandomName("closedRecordFolder"));
closeFolder(closedRecordFolder.getId());
unfiledContainerFolder = createUnfiledContainerChild(UNFILED_RECORDS_CONTAINER_ALIAS,
"Unfiled Folder " + getRandomAlphanumeric(), UNFILED_RECORD_FOLDER_TYPE);
heldRecordFolder = createFolder(recordCategory.getId(), getRandomName("heldRecordFolder"));
holdsAPI.createHold(getAdminUser().getUsername(), getAdminUser().getPassword(), HOLD_NAME, HOLD_REASON, HOLD_DESCRIPTION);
holdsAPI.addItemToHold(getAdminUser().getUsername(), getAdminUser().getPassword(), heldRecordFolder.getId(),
HOLD_NAME);
STEP("Create rm users with different permissions on the record category");
userFillingPermission = roleService.createCollaboratorWithRMRoleAndPermission(publicSite, recordCategory,
ROLE_RM_POWER_USER, PERMISSION_FILING);
userReadOnlyPermission = roleService.createCollaboratorWithRMRoleAndPermission(publicSite, recordCategory,
ROLE_RM_POWER_USER, PERMISSION_READ_RECORDS);
}
@BeforeMethod (alwaysRun = true)
public void createDocument()
{
STEP("Create a document in the collaboration site");
testFile = dataContent.usingSite(publicSite)
.usingAdmin()
.createContent(CMISUtil.DocumentType.TEXT_PLAIN);
}
/**
* Given I am calling the "declare version as record" action
* And I am not providing a location parameter value
* When I execute the action
* Then the document is declared as a version record
* And is placed in the Unfiled Records location
*/
@Test
public void declareVersionAndFileNoLocationUsingActionsAPI() throws Exception
{
STEP("Declare document version as record without providing a location parameter value using v1 actions api");
getRestAPIFactory().getActionsAPI(userReadOnlyPermission).declareVersionAsRecord(testFile);
STEP("Verify the declared version record is placed in the Unfiled Records folder and is a record version");
assertTrue(isRecordVersionInUnfiledRecords(testFile, "1.0"), "Version record should be filed to Unfiled " +
"Records folder");
}
/**
* Given I am calling the "declare version as record" action
* And I provide a valid record folder in the location parameter
* When I execute the action
* Then the document is declared as a version record
* And is filed to the record folder specified
*/
@Test
public void fileVersionAsRecordToValidLocationUsingActionsAPI() throws Exception
{
STEP("Declare document version as record with a location parameter value");
getRestAPIFactory().getActionsAPI(userFillingPermission).declareAndFileVersionAsRecord(testFile,
Utility.buildPath(recordCategory.getName(), recordFolder.getName()));
STEP("Verify the declared version record is placed in the record folder");
assertTrue(isRecordVersionInRecordFolder(testFile, recordFolder, "1.0"), "Record version should be filed to " +
"record folder");
}
/**
* Invalid destination paths where version records can't be filed
*/
@DataProvider (name = "invalidDestinationPaths")
public Object[][] getInvalidDestinationPaths()
{
return new String[][]
{
{ "/", DESTINATION_PATH_NOT_FOUND_EXC },
{ "Unfiled Records", INVALID_DESTINATION_PATH_EXC },
{ "Transfers", INVALID_DESTINATION_PATH_EXC },
{ "Holds", INVALID_DESTINATION_PATH_EXC },
{ "rm/documentlibrary", DESTINATION_PATH_NOT_FOUND_EXC },
{ recordCategory.getName(), DESTINATION_PATH_NOT_RECORD_FOLDER_EXC },
// a closed record folder
{ Utility.buildPath(recordCategory.getName(), closedRecordFolder.getName()),
ACCESS_DENIED_EXC },
// a frozen record folder
{ Utility.buildPath(recordCategory.getName(), heldRecordFolder.getName()),
ACCESS_DENIED_EXC },
// an arbitrary unfiled records folder
{ "Unfiled Records/" + unfiledContainerFolder.getName(), INVALID_DESTINATION_PATH_EXC },
// a collaboration site folder
{ testFolder.getCmisLocation(), DESTINATION_PATH_NOT_FOUND_EXC }
};
}
/**
* Given I am calling the "declare version as record" action
* And I provide an invalid record folder in the path parameter
* When I execute the action
* Then I receive an error indicating that I have attempted to file version as record a document into an invalid
* record folder
* And the document is not declared as a version record
*/
@Test (dataProvider = "invalidDestinationPaths")
public void declareVersionAndFileToInvalidLocationUsingActionsAPI(String containerPath, String expectedException) throws Exception
{
STEP("Declare document as record version with an invalid location parameter value");
getRestAPIFactory().getActionsAPI().declareAndFileVersionAsRecord(testFile, containerPath);
assertStatusCode(ACCEPTED);
STEP("Check the exception thrown in alfresco logs");
//Retry the operation because sometimes it takes few seconds to throw the exception
Utility.sleep(6000, 30000, () ->
{
List<String> alfrescoLogs = dockerHelper.getAlfrescoLogs();
assertTrue(alfrescoLogs.stream().anyMatch(logLine -> logLine.contains(expectedException)));
});
}
/**
* Given I am an user with read only permissions on a record folder
* When I declare and file a version record to the record folder
* Then I receive an error indicating that the access is denied
* And the document is not declared as a record
*/
@Test
public void declareAndFileByUserWithReadOnlyPermission() throws Exception
{
STEP("Declare document as record with a record folder as location parameter");
getRestAPIFactory().getActionsAPI(userReadOnlyPermission).declareAndFileVersionAsRecord(testFile,
Utility.buildPath(recordCategory.getName(), recordFolder.getName()));
STEP("Check that the record version is not added to the record folder");
assertFalse(isRecordVersionInRecordFolder(testFile, recordFolder, "1.0"), "Record version is filed to " +
"record folder where the user doesn't have filling permission");
}
/**
* Given I am calling the "declare version as record" action for a minor document version
* And I am not providing a path parameter value
* When I execute the action
* Then the document version is declared as a version record
* And is placed in the Unfiled Records location
*/
@Test
public void declareVersionAsRecordMinorVersionUsingActionsAPI() throws Exception
{
STEP("Update document in the collaboration site");
dataContent.usingSite(publicSite).usingAdmin().usingResource(testFile).updateContent("This is the new content" +
"for " + testFile.getName());
STEP("Declare document version as record with providing a location parameter value using v1 actions api");
getRestAPIFactory().getActionsAPI(userFillingPermission).declareAndFileVersionAsRecord(testFile,
Utility.buildPath(recordCategory.getName(), recordFolder.getName()));
STEP("Verify the declared version record is placed in the record folder and is a record version");
assertTrue(isRecordVersionInRecordFolder(testFile, recordFolder, "1.1"), "Record should be filed to fileplan " +
"location");
}
/**
* Given I am calling the "declare version as record" action for a major document version
* And I am not providing a path parameter value
* When I execute the action
* Then the document version is declared as a version record version
* And is placed in the Unfiled Records location
*/
@Test
public void declareVersionAsRecordMajorVersionUsingActionsAPI() throws Exception
{
STEP("Update document in the collaboration site");
File sampleFile = Utility.getResourceTestDataFile("SampleTextFile_10kb.txt");
restClient.authenticateUser(getAdminUser()).withCoreAPI().usingParams("majorVersion=true").usingNode(testFile).updateNodeContent(sampleFile);
STEP("Declare document version as record with providing a location parameter value using v1 actions api");
getRestAPIFactory().getActionsAPI(userFillingPermission).declareAndFileVersionAsRecord(testFile,
Utility.buildPath(recordCategory.getName(), recordFolder.getName()));
STEP("Verify the declared version record is placed in the record folder and is a record version");
assertTrue(isRecordVersionInRecordFolder(testFile, recordFolder, "2.0"), "Version record should be filed to " +
"the record folder");
}
@AfterClass (alwaysRun = true)
public void declareAndFileVersionAsRecordCleanUp()
{
holdsAPI.deleteHold(getAdminUser().getUsername(), getAdminUser().getPassword(), HOLD_NAME);
deleteRecordCategory(recordCategory.getId());
//delete created collaboration site
dataSite.deleteSite(publicSite);
//delete users
getDataUser().deleteUser(userFillingPermission);
getDataUser().deleteUser(userReadOnlyPermission);
}
}

View File

@@ -7,11 +7,12 @@
<!-- Declare as Record action --> <!-- Declare as Record action -->
<!-- TODO rename --> <!-- TODO rename -->
<bean id="create-record" parent="action-executer" class="org.alfresco.module.org_alfresco_module_rm.action.dm.CreateRecordAction"> <bean id="create-record" parent="action-executer"
class="org.alfresco.module.org_alfresco_module_rm.action.dm.CreateRecordAction">
<property name="recordService" ref="RecordService" /> <property name="recordService" ref="RecordService" />
<property name="authenticationUtil" ref="rm.authenticationUtil" /> <property name="authenticationUtil" ref="rm.authenticationUtil" />
<property name="filePlanService" ref="FilePlanService" /> <property name="filePlanService" ref="FilePlanService" />
<property name="nodeService" ref="NodeService" /> <property name="nodeService" ref="NodeService" />
<property name="applicableTypes"> <property name="applicableTypes">
<list> <list>
<value>{http://www.alfresco.org/model/content/1.0}content</value> <value>{http://www.alfresco.org/model/content/1.0}content</value>
@@ -26,6 +27,8 @@
<property name="filePlanService" ref="FilePlanService" /> <property name="filePlanService" ref="FilePlanService" />
<property name="dictionaryService" ref="DictionaryService" /> <property name="dictionaryService" ref="DictionaryService" />
<property name="authenticationUtil" ref="rm.authenticationUtil" /> <property name="authenticationUtil" ref="rm.authenticationUtil" />
<property name="recordService" ref="RecordService" />
<property name="capabilityService" ref="CapabilityService" />
<property name="applicableTypes"> <property name="applicableTypes">
<list> <list>
<value>{http://www.alfresco.org/model/content/1.0}content</value> <value>{http://www.alfresco.org/model/content/1.0}content</value>

View File

@@ -62,6 +62,27 @@
<property name="index" value="40" /> <property name="index" value="40" />
</bean> </bean>
<bean id="rmFileVersionRecordsCapability"
parent="declarativeCapability">
<property name="name" value="FileVersionRecords" />
<property name="permission" value="FileVersionRecords" />
<property name="kinds">
<list>
<value>RECORD_FOLDER</value>
</list>
</property>
<property name="conditions">
<map>
<entry key="capabilityCondition.filling" value="true" />
<entry key="capabilityCondition.cutoff" value="false" />
<entry key="capabilityCondition.frozen" value="false" />
<entry key="capabilityCondition.closed" value="false" />
</map>
</property>
<property name="group"><ref bean="folderControlGroup" /></property>
<property name="index" value="50" />
</bean>
<!-- Unassignable --> <!-- Unassignable -->
<bean id="rmCreateRecordFolderCapability" <bean id="rmCreateRecordFolderCapability"

View File

@@ -54,8 +54,10 @@ create-record.hide-record.display-label=Hide Record
create-record.path.display-label=Record Folder Location create-record.path.display-label=Record Folder Location
# Declare As Version Record # Declare As Version Record
declare-as-version-record.title=Declare Version as Record declare-as-version-record.title=Declare Version as Record
declare-as-version-record.description=Declares this version of the file as a record declare-as-version-record.description=Declares this version of the file as a record and optionally files it
declare-as-version-record.file-plan.display-label=File Plan declare-as-version-record.file-plan.display-label=File Plan
declare-as-version-record.path.display-label=Record Folder Location
# Complete record # Complete record
declareRecord.title=Complete Record declareRecord.title=Complete Record
declareRecord.description=Completes a record declareRecord.description=Completes a record

View File

@@ -23,6 +23,7 @@ capability.CreateModifyDestroyFolders.title=Create Modify Destroy Folders
capability.CloseFolders.title=Close Folders capability.CloseFolders.title=Close Folders
capability.ReOpenFolders.title=Re-Open Folders capability.ReOpenFolders.title=Re-Open Folders
capability.DeclareRecordsInClosedFolders.title=Complete Records in Closed Folders capability.DeclareRecordsInClosedFolders.title=Complete Records in Closed Folders
capability.FileVersionRecords.title=File Version Records
# Vital Records # Vital Records
capability.group.vitalRecords.title=Vital Records capability.group.vitalRecords.title=Vital Records

View File

@@ -28,6 +28,7 @@
<includePermissionGroup type="rma:filePlanComponent" permissionGroup="CloseFolders"/> <includePermissionGroup type="rma:filePlanComponent" permissionGroup="CloseFolders"/>
<includePermissionGroup type="rma:filePlanComponent" permissionGroup="DeclareRecordsInClosedFolders"/> <includePermissionGroup type="rma:filePlanComponent" permissionGroup="DeclareRecordsInClosedFolders"/>
<includePermissionGroup type="rma:filePlanComponent" permissionGroup="ReOpenFolders"/> <includePermissionGroup type="rma:filePlanComponent" permissionGroup="ReOpenFolders"/>
<includePermissionGroup type="rma:filePlanComponent" permissionGroup="FileVersionRecords" />
<includePermissionGroup type="rma:filePlanComponent" permissionGroup="CycleVitalRecords"/> <includePermissionGroup type="rma:filePlanComponent" permissionGroup="CycleVitalRecords"/>
<includePermissionGroup type="rma:filePlanComponent" permissionGroup="PlanningReviewCycles"/> <includePermissionGroup type="rma:filePlanComponent" permissionGroup="PlanningReviewCycles"/>
<includePermissionGroup type="rma:filePlanComponent" permissionGroup="UpdateTriggerDates"/> <includePermissionGroup type="rma:filePlanComponent" permissionGroup="UpdateTriggerDates"/>
@@ -114,7 +115,8 @@
<permissionGroup name="AddModifyEventDates" expose="false" allowFullControl="false"/> <permissionGroup name="AddModifyEventDates" expose="false" allowFullControl="false"/>
<permissionGroup name="CloseFolders" expose="false" allowFullControl="false"/> <permissionGroup name="CloseFolders" expose="false" allowFullControl="false"/>
<permissionGroup name="DeclareRecordsInClosedFolders" expose="false" allowFullControl="false"/> <permissionGroup name="DeclareRecordsInClosedFolders" expose="false" allowFullControl="false"/>
<permissionGroup name="ReOpenFolders" expose="false" allowFullControl="false"/> <permissionGroup name="FileVersionRecords" expose="false" allowFullControl="false"/>
<permissionGroup name="ReOpenFolders" expose="false" allowFullControl="false" />
<permissionGroup name="CycleVitalRecords" expose="false" allowFullControl="false"/> <permissionGroup name="CycleVitalRecords" expose="false" allowFullControl="false"/>
<permissionGroup name="PlanningReviewCycles" expose="false" allowFullControl="false"/> <permissionGroup name="PlanningReviewCycles" expose="false" allowFullControl="false"/>
<permissionGroup name="UpdateTriggerDates" expose="false" allowFullControl="false"/> <permissionGroup name="UpdateTriggerDates" expose="false" allowFullControl="false"/>
@@ -232,6 +234,10 @@
<grantedToGroup permissionGroup="ReOpenFolders"/> <grantedToGroup permissionGroup="ReOpenFolders"/>
</permission> </permission>
<permission name="_FileVersionRecords" expose="false">
<grantedToGroup permissionGroup="FileVersionRecords" />
</permission>
<permission name="_CycleVitalRecords" expose="false"> <permission name="_CycleVitalRecords" expose="false">
<grantedToGroup permissionGroup="CycleVitalRecords"/> <grantedToGroup permissionGroup="CycleVitalRecords"/>
</permission> </permission>

View File

@@ -49,7 +49,8 @@
"RequestRecordInformation", "RequestRecordInformation",
"FileUnfiledRecords", "FileUnfiledRecords",
"RejectRecords", "RejectRecords",
"LinkToRecords" "LinkToRecords",
"FileVersionRecords"
] ]
}, },
{ {
@@ -74,7 +75,8 @@
"FileUnfiledRecords", "FileUnfiledRecords",
"RejectRecords", "RejectRecords",
"LinkToRecords", "LinkToRecords",
"ManageAccessControls" "ManageAccessControls",
"FileVersionRecords"
] ]
}, },
{ {
@@ -145,8 +147,8 @@
"DeleteHold", "DeleteHold",
"EndRetention", "EndRetention",
"EditHold", "EditHold",
"ManageAccessControls" "ManageAccessControls",
"FileVersionRecords"
] ]
}, },
{ {
@@ -219,7 +221,8 @@
"FileHoldReport", "FileHoldReport",
"DeleteHold", "DeleteHold",
"EditHold", "EditHold",
"EndRetention" "EndRetention",
"FileVersionRecords"
] ]
} }
] ]

View File

@@ -27,12 +27,12 @@
package org.alfresco.module.org_alfresco_module_rm.action.dm; package org.alfresco.module.org_alfresco_module_rm.action.dm;
import java.util.Arrays; import static org.alfresco.module.org_alfresco_module_rm.action.dm.RecordActionUtils.resolvePath;
import java.util.List; import java.util.List;
import org.alfresco.error.AlfrescoRuntimeException;
import org.alfresco.model.ContentModel;
import org.alfresco.module.org_alfresco_module_rm.action.AuditableActionExecuterAbstractBase; import org.alfresco.module.org_alfresco_module_rm.action.AuditableActionExecuterAbstractBase;
import org.alfresco.module.org_alfresco_module_rm.action.dm.RecordActionUtils.Services;
import org.alfresco.module.org_alfresco_module_rm.fileplan.FilePlanService; 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.model.RecordsManagementModel;
import org.alfresco.module.org_alfresco_module_rm.record.RecordService; import org.alfresco.module.org_alfresco_module_rm.record.RecordService;
@@ -43,11 +43,6 @@ import org.alfresco.service.cmr.action.ParameterDefinition;
import org.alfresco.service.cmr.dictionary.DataTypeDefinition; import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService; import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.namespace.QName;
import org.springframework.util.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/** /**
* Creates a new record from an existing content object. * Creates a new record from an existing content object.
@@ -59,9 +54,6 @@ import org.apache.commons.logging.LogFactory;
public class CreateRecordAction extends AuditableActionExecuterAbstractBase public class CreateRecordAction extends AuditableActionExecuterAbstractBase
implements RecordsManagementModel implements RecordsManagementModel
{ {
/** Logger */
private static final Log LOGGER = LogFactory.getLog(CreateRecordAction.class);
/** Action name */ /** Action name */
public static final String NAME = "create-record"; public static final String NAME = "create-record";
@@ -70,20 +62,26 @@ public class CreateRecordAction extends AuditableActionExecuterAbstractBase
public static final String PARAM_HIDE_RECORD = "hide-record"; public static final String PARAM_HIDE_RECORD = "hide-record";
public static final String PARAM_PATH = "path"; public static final String PARAM_PATH = "path";
/** Node service */ /**
* Node service
*/
private NodeService nodeService; private NodeService nodeService;
/** File plan service */ /**
* File plan service
*/
private FilePlanService filePlanService; private FilePlanService filePlanService;
/** Authentication util */ /**
* Authentication util
*/
private AuthenticationUtil authenticationUtil; private AuthenticationUtil authenticationUtil;
/** Record service */ /** Record service */
private RecordService recordService; private RecordService recordService;
/** /**
* @param nodeService node service * @param nodeService node service
*/ */
public void setNodeService(NodeService nodeService) public void setNodeService(NodeService nodeService)
{ {
@@ -91,7 +89,7 @@ public class CreateRecordAction extends AuditableActionExecuterAbstractBase
} }
/** /**
* @param filePlanService file plan service * @param filePlanService file plan service
*/ */
public void setFilePlanService(FilePlanService filePlanService) public void setFilePlanService(FilePlanService filePlanService)
{ {
@@ -99,13 +97,14 @@ public class CreateRecordAction extends AuditableActionExecuterAbstractBase
} }
/** /**
* @param authenticationUtil authentication util * @param authenticationUtil authentication util
*/ */
public void setAuthenticationUtil(AuthenticationUtil authenticationUtil) public void setAuthenticationUtil(AuthenticationUtil authenticationUtil)
{ {
this.authenticationUtil = authenticationUtil; this.authenticationUtil = authenticationUtil;
} }
/** /**
* @param recordService record service * @param recordService record service
*/ */
@@ -131,12 +130,13 @@ public class CreateRecordAction extends AuditableActionExecuterAbstractBase
Boolean hideRecordValue = ((Boolean) action.getParameterValue(PARAM_HIDE_RECORD)); Boolean hideRecordValue = ((Boolean) action.getParameterValue(PARAM_HIDE_RECORD));
if (hideRecordValue != null) if (hideRecordValue != null)
{ {
hideRecord = hideRecordValue.booleanValue(); hideRecord = hideRecordValue;
} }
if (pathParameter != null && !pathParameter.isEmpty()) if (pathParameter != null && !pathParameter.isEmpty())
{ {
destinationRecordFolder = resolvePath(filePlan, pathParameter); RecordActionUtils.Services services = new Services(nodeService, filePlanService, authenticationUtil);
destinationRecordFolder = resolvePath(services, filePlan, pathParameter, NAME);
} }
synchronized (this) synchronized (this)
@@ -162,102 +162,4 @@ public class CreateRecordAction extends AuditableActionExecuterAbstractBase
params.add(new ParameterDefinitionImpl(PARAM_PATH, DataTypeDefinition.TEXT, false, getParamDisplayLabel(PARAM_PATH))); params.add(new ParameterDefinitionImpl(PARAM_PATH, DataTypeDefinition.TEXT, false, getParamDisplayLabel(PARAM_PATH)));
params.add(new ParameterDefinitionImpl(PARAM_HIDE_RECORD, DataTypeDefinition.BOOLEAN, false, getParamDisplayLabel(PARAM_HIDE_RECORD))); params.add(new ParameterDefinitionImpl(PARAM_HIDE_RECORD, DataTypeDefinition.BOOLEAN, false, getParamDisplayLabel(PARAM_HIDE_RECORD)));
} }
/**
* Helper method to get the target record folder node reference from the action path parameter
*
* @param filePlan The filePlan containing the path
* @param pathParameter The path
* @return The NodeRef of the resolved path
*/
private NodeRef resolvePath(NodeRef filePlan, final String pathParameter)
{
NodeRef destinationFolder;
if (filePlan == null)
{
filePlan = getDefaultFilePlan();
}
final String[] pathElementsArray = StringUtils.tokenizeToStringArray(pathParameter, "/", false, true);
if ((pathElementsArray != null) && (pathElementsArray.length > 0))
{
destinationFolder = resolvePath(filePlan, Arrays.asList(pathElementsArray));
// destination must be a record folder
QName nodeType = nodeService.getType(destinationFolder);
if (!nodeType.equals(RecordsManagementModel.TYPE_RECORD_FOLDER))
{
throw new AlfrescoRuntimeException("Unable to execute " + NAME + " action, because the destination path is not a record folder.");
}
}
else
{
throw new AlfrescoRuntimeException("Unable to execute " + NAME + " action, because the destination path could not be found.");
}
return destinationFolder;
}
/**
* Helper method to recursively get the next path element node reference from the action path parameter
*
* @param parent The parent of the path elements
* @param pathElements The path elements still to be resolved
* @return The NodeRef of the resolved path element
*/
private NodeRef resolvePath(NodeRef parent, List<String> pathElements)
{
NodeRef nodeRef;
String childName = pathElements.get(0);
nodeRef = nodeService.getChildByName(parent, ContentModel.ASSOC_CONTAINS, childName);
if (nodeRef == null)
{
throw new AlfrescoRuntimeException("Unable to execute " + NAME + " action, because the destination path could not be found.");
}
else
{
QName nodeType = nodeService.getType(nodeRef);
if (nodeType.equals(RecordsManagementModel.TYPE_HOLD_CONTAINER) ||
nodeType.equals(RecordsManagementModel.TYPE_TRANSFER_CONTAINER) ||
nodeType.equals(RecordsManagementModel.TYPE_UNFILED_RECORD_CONTAINER))
{
throw new AlfrescoRuntimeException("Unable to execute " + NAME + " action, because the destination path is invalid.");
}
}
if (pathElements.size() > 1)
{
nodeRef = resolvePath(nodeRef, pathElements.subList(1, pathElements.size()));
}
return nodeRef;
}
/**
* Helper method to get the default RM filePlan
*
* @return The NodeRef of the default RM filePlan
*/
private NodeRef getDefaultFilePlan()
{
NodeRef filePlan = authenticationUtil.runAsSystem(new org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork<NodeRef>()
{
@Override
public NodeRef doWork()
{
return filePlanService.getFilePlanBySiteId(FilePlanService.DEFAULT_RM_SITE_ID);
}
});
// if the file plan is still null, raise an exception
if (filePlan == null)
{
if (LOGGER.isDebugEnabled())
{
LOGGER.debug("Unable to execute " + NAME + " action, because the fileplan path could not be determined. Make sure at least one file plan has been created.");
throw new AlfrescoRuntimeException("Unable to execute " + NAME + " action, because the fileplan path could not be determined.");
}
}
return filePlan;
}
} }

View File

@@ -27,23 +27,32 @@
package org.alfresco.module.org_alfresco_module_rm.action.dm; package org.alfresco.module.org_alfresco_module_rm.action.dm;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
import org.alfresco.error.AlfrescoRuntimeException; import org.alfresco.error.AlfrescoRuntimeException;
import org.alfresco.model.ContentModel; import org.alfresco.model.ContentModel;
import org.alfresco.module.org_alfresco_module_rm.action.AuditableActionExecuterAbstractBase; import org.alfresco.module.org_alfresco_module_rm.action.AuditableActionExecuterAbstractBase;
import org.alfresco.module.org_alfresco_module_rm.action.dm.RecordActionUtils.Services;
import org.alfresco.module.org_alfresco_module_rm.capability.CapabilityService;
import org.alfresco.module.org_alfresco_module_rm.fileplan.FilePlanService; 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.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.module.org_alfresco_module_rm.util.AuthenticationUtil;
import org.alfresco.module.org_alfresco_module_rm.version.RecordableVersionService; import org.alfresco.module.org_alfresco_module_rm.version.RecordableVersionService;
import org.alfresco.repo.action.ParameterDefinitionImpl;
import org.alfresco.repo.security.permissions.AccessDeniedException;
import org.alfresco.service.cmr.action.Action; import org.alfresco.service.cmr.action.Action;
import org.alfresco.service.cmr.action.ParameterDefinition; import org.alfresco.service.cmr.action.ParameterDefinition;
import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
import org.alfresco.service.cmr.dictionary.DictionaryService; import org.alfresco.service.cmr.dictionary.DictionaryService;
import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService; import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.namespace.QName; import org.alfresco.service.namespace.QName;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.springframework.extensions.surf.util.I18NUtil;
/** /**
* Creates a new record from the 'current' document version. * Creates a new record from the 'current' document version.
@@ -63,6 +72,9 @@ public class DeclareAsVersionRecordAction extends AuditableActionExecuterAbstrac
/** Parameter names */ /** Parameter names */
public static final String PARAM_FILE_PLAN = "file-plan"; public static final String PARAM_FILE_PLAN = "file-plan";
public static final String PARAM_PATH = "path";
private static final String FILE_VERSION_RECORDS_CAPABILITY = "FileVersionRecords";
/** Sync Model URI */ /** Sync Model URI */
private static final String SYNC_MODEL_1_0_URI = "http://www.alfresco.org/model/sync/1.0"; private static final String SYNC_MODEL_1_0_URI = "http://www.alfresco.org/model/sync/1.0";
@@ -79,12 +91,18 @@ public class DeclareAsVersionRecordAction extends AuditableActionExecuterAbstrac
/** Dictionary service */ /** Dictionary service */
private DictionaryService dictionaryService; private DictionaryService dictionaryService;
/** recordable version service */ /** Recordable version service */
private RecordableVersionService recordableVersionService; private RecordableVersionService recordableVersionService;
/** authentication util */ /** Authentication util */
private AuthenticationUtil authenticationUtil; private AuthenticationUtil authenticationUtil;
/** Record service */
private RecordService recordService;
/** Capability service */
private CapabilityService capabilityService;
/** /**
* @param nodeService node service * @param nodeService node service
*/ */
@@ -118,13 +136,29 @@ public class DeclareAsVersionRecordAction extends AuditableActionExecuterAbstrac
} }
/** /**
* @param authenticationUtil authentication util * @param authenticationUtil authentication util
*/ */
public void setAuthenticationUtil(AuthenticationUtil authenticationUtil) public void setAuthenticationUtil(AuthenticationUtil authenticationUtil)
{ {
this.authenticationUtil = authenticationUtil; this.authenticationUtil = authenticationUtil;
} }
/**
* @param recordService record service
*/
public void setRecordService(RecordService recordService)
{
this.recordService = recordService;
}
/**
* @param capabilityService capability service
*/
public void setCapabilityService(CapabilityService capabilityService)
{
this.capabilityService = capabilityService;
}
/** /**
* @see org.alfresco.repo.action.executer.ActionExecuterAbstractBase#executeImpl(org.alfresco.service.cmr.action.Action, org.alfresco.service.cmr.repository.NodeRef) * @see org.alfresco.repo.action.executer.ActionExecuterAbstractBase#executeImpl(org.alfresco.service.cmr.action.Action, org.alfresco.service.cmr.repository.NodeRef)
*/ */
@@ -147,87 +181,51 @@ public class DeclareAsVersionRecordAction extends AuditableActionExecuterAbstrac
logger.debug("Can not declare version as record, because " + actionedUponNodeRef.toString() + " is not a supported type."); logger.debug("Can not declare version as record, because " + actionedUponNodeRef.toString() + " is not a supported type.");
} }
} }
else if (!nodeService.hasAspect(actionedUponNodeRef, ContentModel.ASPECT_VERSIONABLE)) else if (isActionEligible(actionedUponNodeRef))
{
if (logger.isDebugEnabled())
{
logger.debug("Can not declare version record, because " + actionedUponNodeRef.toString() + " does not have the versionable aspect applied.");
}
}
else if (nodeService.hasAspect(actionedUponNodeRef, ASPECT_RECORD))
{
// Do not declare version record if the actioned upon node is already a record!
if (logger.isDebugEnabled())
{
logger.debug("Can not declare version record, because " + actionedUponNodeRef.toString() + " is already a record.");
}
}
else if (nodeService.hasAspect(actionedUponNodeRef, ContentModel.ASPECT_WORKING_COPY))
{
// We can not create records from working copies
if (logger.isDebugEnabled())
{
logger.debug("Can not declare version record, because " + actionedUponNodeRef.toString() + " is a working copy.");
}
}
else if (nodeService.hasAspect(actionedUponNodeRef, ASPECT_RECORD_REJECTION_DETAILS))
{
// can not create a record from a previously rejected one
if (logger.isDebugEnabled())
{
logger.debug("Can not declare version record, because " + actionedUponNodeRef.toString() + " has previously been rejected.");
}
}
else if (nodeService.hasAspect(actionedUponNodeRef, ASPECT_SYNCED))
{
// can't declare the record if the node is sync'ed
if (logger.isDebugEnabled())
{
logger.debug("Can't declare version record, because " + actionedUponNodeRef.toString() + " is synched content.");
}
}
else
{ {
NodeRef filePlan = (NodeRef)action.getParameterValue(PARAM_FILE_PLAN); NodeRef filePlan = (NodeRef)action.getParameterValue(PARAM_FILE_PLAN);
if (filePlan == null) if (filePlan == null)
{ {
// TODO .. eventually make the file plan parameter required filePlan = RecordActionUtils.getDefaultFilePlan(authenticationUtil, filePlanService, NAME);
}
filePlan = authenticationUtil.runAs(new org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork<NodeRef>() // verify that the provided file plan is actually a file plan
else if (!filePlanService.isFilePlan(filePlan))
{
if (logger.isDebugEnabled())
{ {
@Override logger.debug("Can not declare version record, because the provided file plan node reference is not a file plan.");
public NodeRef doWork() }
{ throw new AlfrescoRuntimeException("Can not declare version record, because the provided file plan node reference is not a file plan.");
return filePlanService.getFilePlanBySiteId(FilePlanService.DEFAULT_RM_SITE_ID); }
}
}, authenticationUtil.getAdminUserName());
// if the file plan is still null, raise an exception // resolve destination record folder if path supplied
if (filePlan == null) NodeRef destinationRecordFolder = null;
String pathParameter = (String) action.getParameterValue(PARAM_PATH);
if (pathParameter != null && !pathParameter.isEmpty())
{
RecordActionUtils.Services services = new Services(nodeService, filePlanService, authenticationUtil);
destinationRecordFolder = RecordActionUtils.resolvePath(services, filePlan, pathParameter, NAME);
}
// create record from latest version
if (destinationRecordFolder != null)
{
boolean hasCapability = capabilityService.hasCapability(destinationRecordFolder, FILE_VERSION_RECORDS_CAPABILITY);
// validate destination record folder
if (hasCapability)
{ {
if (logger.isDebugEnabled()) NodeRef recordedVersion = recordableVersionService.createRecordFromLatestVersion(destinationRecordFolder, actionedUponNodeRef);
{ recordService.file(recordedVersion);
logger.debug("Can not declare version record, because the default file plan can not be determined. Make sure at least one file plan has been created."); }
} else
throw new AlfrescoRuntimeException("Can not declare version record, because the default file plan can not be determined."); {
throw new AccessDeniedException(I18NUtil.getMessage("permissions.err_access_denied"));
} }
} }
else else
{ {
// verify that the provided file plan is actually a file plan recordableVersionService.createRecordFromLatestVersion(filePlan, actionedUponNodeRef);
if (!filePlanService.isFilePlan(filePlan))
{
if (logger.isDebugEnabled())
{
logger.debug("Can not declare version record, because the provided file plan node reference is not a file plan.");
}
throw new AlfrescoRuntimeException("Can not declare version record, because the provided file plan node reference is not a file plan.");
}
} }
// create record from latest version
recordableVersionService.createRecordFromLatestVersion(filePlan, actionedUponNodeRef);
} }
} }
@@ -239,6 +237,38 @@ public class DeclareAsVersionRecordAction extends AuditableActionExecuterAbstrac
{ {
// NOTE: commented out for now so that it doesn't appear in the UI ... enable later when multi-file plan support is added // NOTE: commented out for now so that it doesn't appear in the UI ... enable later when multi-file plan support is added
//params.add(new ParameterDefinitionImpl(PARAM_FILE_PLAN, DataTypeDefinition.NODE_REF, false, getParamDisplayLabel(PARAM_FILE_PLAN))); //params.add(new ParameterDefinitionImpl(PARAM_FILE_PLAN, DataTypeDefinition.NODE_REF, false, getParamDisplayLabel(PARAM_FILE_PLAN)));
params.add(new ParameterDefinitionImpl(PARAM_PATH, DataTypeDefinition.TEXT, false, getParamDisplayLabel(PARAM_PATH)));
} }
/* Check aspects that stop declaring the version as record.*/
private boolean isActionEligible(NodeRef actionedUponNodeRef)
{
Map<QName, String> mappedAspects = new HashMap<>();
mappedAspects.put(ASPECT_RECORD, " is already a record.");
mappedAspects.put(ContentModel.ASPECT_WORKING_COPY, " is a working copy.");
mappedAspects.put(ASPECT_RECORD_REJECTION_DETAILS, " has previously been rejected.");
mappedAspects.put(ASPECT_SYNCED, " is synched content.");
for (Map.Entry<QName, String> aspect : mappedAspects.entrySet())
{
if (nodeService.hasAspect(actionedUponNodeRef, aspect.getKey()))
{
if (logger.isDebugEnabled())
{
logger.debug("Can not declare version record, because " + actionedUponNodeRef.toString() + aspect.getValue());
}
return false;
}
}
if (!nodeService.hasAspect(actionedUponNodeRef, ContentModel.ASPECT_VERSIONABLE))
{
if (logger.isDebugEnabled())
{
logger.debug("Can not declare version record, because " + actionedUponNodeRef.toString() + " does not have the versionable aspect applied.");
}
return false;
}
return true;
}
} }

View File

@@ -0,0 +1,175 @@
/*
* #%L
* Alfresco Records Management Module
* %%
* Copyright (C) 2005 - 2020 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.module.org_alfresco_module_rm.action.dm;
import java.util.Arrays;
import java.util.List;
import org.alfresco.error.AlfrescoRuntimeException;
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.util.AuthenticationUtil;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.namespace.QName;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.util.StringUtils;
/**
* Utility class containing helper methods for record
*/
public class RecordActionUtils
{
/**
* Logger
*/
private static final Logger LOGGER = LoggerFactory.getLogger(RecordActionUtils.class);
/** Private constructor to prevent instantiation. */
private RecordActionUtils()
{
}
static class Services
{
private NodeService nodeService;
private FilePlanService filePlanService;
private AuthenticationUtil authenticationUtil;
Services(NodeService nodeService, FilePlanService filePlanService, AuthenticationUtil authenticationUtil)
{
this.nodeService = nodeService;
this.filePlanService = filePlanService;
this.authenticationUtil = authenticationUtil;
}
public NodeService getNodeService()
{
return nodeService;
}
public FilePlanService getFilePlanService()
{
return filePlanService;
}
public AuthenticationUtil getAuthenticationUtil()
{
return authenticationUtil;
}
}
/**
* Helper method to get the target record folder node reference from the action path parameter
*
* @param filePlan The filePlan containing the path
* @param pathParameter The path
* @return The NodeRef of the resolved path
*/
static NodeRef resolvePath(Services services, NodeRef filePlan, final String pathParameter, String actionName)
{
NodeRef destinationFolder;
if (filePlan == null)
{
filePlan = getDefaultFilePlan(services.getAuthenticationUtil(), services.getFilePlanService(), actionName);
}
final String[] pathElementsArray = StringUtils.tokenizeToStringArray(pathParameter, "/", false, true);
if (pathElementsArray.length > 0)
{
destinationFolder = resolvePath(services.getNodeService(), filePlan, Arrays.asList(pathElementsArray), actionName);
// destination must be a record folder
QName nodeType = services.getNodeService().getType(destinationFolder);
if (!nodeType.equals(RecordsManagementModel.TYPE_RECORD_FOLDER))
{
throw new AlfrescoRuntimeException("Unable to execute " + actionName + " action, because the destination path is not a record folder.");
}
}
else
{
throw new AlfrescoRuntimeException("Unable to execute " + actionName + " action, because the destination path could not be found.");
}
return destinationFolder;
}
/**
* Helper method to recursively get the next path element node reference from the action path parameter
*
* @param parent The parent of the path elements
* @param pathElements The path elements still to be resolved
* @return The NodeRef of the resolved path element
*/
static NodeRef resolvePath(NodeService nodeService, NodeRef parent, List<String> pathElements, String actionName)
{
NodeRef nodeRef;
String childName = pathElements.get(0);
nodeRef = nodeService.getChildByName(parent, ContentModel.ASSOC_CONTAINS, childName);
if (nodeRef == null)
{
throw new AlfrescoRuntimeException("Unable to execute " + actionName + " action, because the destination path could not be found.");
}
QName nodeType = nodeService.getType(nodeRef);
if (nodeType.equals(RecordsManagementModel.TYPE_HOLD_CONTAINER) ||
nodeType.equals(RecordsManagementModel.TYPE_TRANSFER_CONTAINER) ||
nodeType.equals(RecordsManagementModel.TYPE_UNFILED_RECORD_CONTAINER))
{
throw new AlfrescoRuntimeException("Unable to execute " + actionName + " action, because the destination path is invalid.");
}
if (pathElements.size() > 1)
{
nodeRef = resolvePath(nodeService, nodeRef, pathElements.subList(1, pathElements.size()), actionName);
}
return nodeRef;
}
/**
* Helper method to get the default RM filePlan
*
* @return The NodeRef of the default RM filePlan
*/
static NodeRef getDefaultFilePlan(AuthenticationUtil authenticationUtil, FilePlanService filePlanService, String actionName)
{
NodeRef filePlan = authenticationUtil.runAsSystem(() -> filePlanService.getFilePlanBySiteId(FilePlanService.DEFAULT_RM_SITE_ID));
// if the file plan is still null, raise an exception
if (filePlan == null)
{
final String logMessage =
String.format("Unable to execute %s action, because the fileplan path could not be determined. Make sure at least one file plan has been created.", actionName);
LOGGER.debug(logMessage);
throw new AlfrescoRuntimeException(logMessage);
}
return filePlan;
}
}

View File

@@ -38,12 +38,15 @@ import static org.mockito.Mockito.verify;
import org.alfresco.error.AlfrescoRuntimeException; import org.alfresco.error.AlfrescoRuntimeException;
import org.alfresco.model.ContentModel; import org.alfresco.model.ContentModel;
import org.alfresco.module.org_alfresco_module_rm.action.BaseActionUnitTest; import org.alfresco.module.org_alfresco_module_rm.action.BaseActionUnitTest;
import org.alfresco.module.org_alfresco_module_rm.capability.CapabilityService;
import org.alfresco.module.org_alfresco_module_rm.fileplan.FilePlanService; import org.alfresco.module.org_alfresco_module_rm.fileplan.FilePlanService;
import org.alfresco.service.cmr.action.Action; import org.alfresco.service.cmr.action.Action;
import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.namespace.QName; import org.alfresco.service.namespace.QName;
import org.junit.Test; import org.junit.Test;
import org.mockito.InjectMocks; import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.springframework.extensions.webscripts.GUID;
/** /**
* Declare as version record action unit test. * Declare as version record action unit test.
@@ -60,9 +63,18 @@ public class DeclareAsVersionRecordActionUnitTest extends BaseActionUnitTest
/** actioned upon node reference */ /** actioned upon node reference */
private NodeRef actionedUponNodeRef; private NodeRef actionedUponNodeRef;
/** destination record folder node reference */
private NodeRef destinationRecordFolderNodeRef;
/** parent destination node reference */
private NodeRef parentDestinationNodeRef;
/** declare as version record action */ /** declare as version record action */
private @InjectMocks DeclareAsVersionRecordAction declareAsVersionRecordAction; private @InjectMocks DeclareAsVersionRecordAction declareAsVersionRecordAction;
@Mock
private CapabilityService mockedCapabilityService;
/** /**
* @see org.alfresco.module.org_alfresco_module_rm.test.util.BaseUnitTest#before() * @see org.alfresco.module.org_alfresco_module_rm.test.util.BaseUnitTest#before()
*/ */
@@ -76,6 +88,12 @@ public class DeclareAsVersionRecordActionUnitTest extends BaseActionUnitTest
// mocked actioned upon noderef // mocked actioned upon noderef
actionedUponNodeRef = generateNodeRef(); actionedUponNodeRef = generateNodeRef();
// mocked destination record folder nodeRef
destinationRecordFolderNodeRef = generateNodeRef();
// mocked parent destination nodeRef
parentDestinationNodeRef = generateNodeRef();
} }
/** /**
@@ -200,13 +218,7 @@ public class DeclareAsVersionRecordActionUnitTest extends BaseActionUnitTest
public void noFilePlanParameterNoDefaultFilePlan() public void noFilePlanParameterNoDefaultFilePlan()
{ {
// setup // setup
doReturn(true).when(mockedNodeService).exists(actionedUponNodeRef); setupMockedAspects();
doReturn(true).when(mockedDictionaryService).isSubClass(any(QName.class), eq(ContentModel.TYPE_CONTENT));
doReturn(true).when(mockedNodeService).hasAspect(actionedUponNodeRef, ContentModel.ASPECT_VERSIONABLE);
doReturn(false).when(mockedNodeService).hasAspect(actionedUponNodeRef, ASPECT_RECORD);
doReturn(false).when(mockedNodeService).hasAspect(actionedUponNodeRef, ContentModel.ASPECT_WORKING_COPY);
doReturn(false).when(mockedNodeService).hasAspect(actionedUponNodeRef, ASPECT_RECORD_REJECTION_DETAILS);
doReturn(false).when(mockedNodeService).hasAspect(actionedUponNodeRef, ASPECT_SYNCED);
// no default file plan // no default file plan
doReturn(null).when(mockedFilePlanService).getFilePlanBySiteId(FilePlanService.DEFAULT_RM_SITE_ID); doReturn(null).when(mockedFilePlanService).getFilePlanBySiteId(FilePlanService.DEFAULT_RM_SITE_ID);
@@ -214,13 +226,13 @@ public class DeclareAsVersionRecordActionUnitTest extends BaseActionUnitTest
// expect exception // expect exception
exception.expect(AlfrescoRuntimeException.class); exception.expect(AlfrescoRuntimeException.class);
// exceute action // execute action
declareAsVersionRecordAction.executeImpl(mock(Action.class), actionedUponNodeRef); declareAsVersionRecordAction.executeImpl(mock(Action.class), actionedUponNodeRef);
} }
/** /**
* Given that no file plan is provided * Given that no file plan is provided
* And adefault file plan exists * And a default file plan exists
* When I execute the action * When I execute the action
* Then a version record is declared * Then a version record is declared
*/ */
@@ -228,18 +240,12 @@ public class DeclareAsVersionRecordActionUnitTest extends BaseActionUnitTest
public void noFilePlanParameterDefaultFilePlan() public void noFilePlanParameterDefaultFilePlan()
{ {
// setup // setup
doReturn(true).when(mockedNodeService).exists(actionedUponNodeRef); setupMockedAspects();
doReturn(true).when(mockedDictionaryService).isSubClass(any(QName.class), eq(ContentModel.TYPE_CONTENT));
doReturn(true).when(mockedNodeService).hasAspect(actionedUponNodeRef, ContentModel.ASPECT_VERSIONABLE);
doReturn(false).when(mockedNodeService).hasAspect(actionedUponNodeRef, ASPECT_RECORD);
doReturn(false).when(mockedNodeService).hasAspect(actionedUponNodeRef, ContentModel.ASPECT_WORKING_COPY);
doReturn(false).when(mockedNodeService).hasAspect(actionedUponNodeRef, ASPECT_RECORD_REJECTION_DETAILS);
doReturn(false).when(mockedNodeService).hasAspect(actionedUponNodeRef, ASPECT_SYNCED);
// no default file plan // no default file plan
doReturn(filePlan).when(mockedFilePlanService).getFilePlanBySiteId(FilePlanService.DEFAULT_RM_SITE_ID); doReturn(filePlan).when(mockedFilePlanService).getFilePlanBySiteId(FilePlanService.DEFAULT_RM_SITE_ID);
// exceute action // execute action
declareAsVersionRecordAction.executeImpl(mock(Action.class), actionedUponNodeRef); declareAsVersionRecordAction.executeImpl(mock(Action.class), actionedUponNodeRef);
verify(mockedRecordableVersionService, times(1)).createRecordFromLatestVersion(filePlan, actionedUponNodeRef); verify(mockedRecordableVersionService, times(1)).createRecordFromLatestVersion(filePlan, actionedUponNodeRef);
} }
@@ -254,13 +260,7 @@ public class DeclareAsVersionRecordActionUnitTest extends BaseActionUnitTest
public void invalidFilePlanParameter() public void invalidFilePlanParameter()
{ {
// setup // setup
doReturn(true).when(mockedNodeService).exists(actionedUponNodeRef); setupMockedAspects();
doReturn(true).when(mockedDictionaryService).isSubClass(any(QName.class), eq(ContentModel.TYPE_CONTENT));
doReturn(true).when(mockedNodeService).hasAspect(actionedUponNodeRef, ContentModel.ASPECT_VERSIONABLE);
doReturn(false).when(mockedNodeService).hasAspect(actionedUponNodeRef, ASPECT_RECORD);
doReturn(false).when(mockedNodeService).hasAspect(actionedUponNodeRef, ContentModel.ASPECT_WORKING_COPY);
doReturn(false).when(mockedNodeService).hasAspect(actionedUponNodeRef, ASPECT_RECORD_REJECTION_DETAILS);
doReturn(false).when(mockedNodeService).hasAspect(actionedUponNodeRef, ASPECT_SYNCED);
// not a file plan is provided in the parameters // not a file plan is provided in the parameters
mockActionParameterValue(DeclareAsVersionRecordAction.PARAM_FILE_PLAN, generateNodeRef()); mockActionParameterValue(DeclareAsVersionRecordAction.PARAM_FILE_PLAN, generateNodeRef());
@@ -268,7 +268,7 @@ public class DeclareAsVersionRecordActionUnitTest extends BaseActionUnitTest
// expect exception // expect exception
exception.expect(AlfrescoRuntimeException.class); exception.expect(AlfrescoRuntimeException.class);
// exceute action // execute action
declareAsVersionRecordAction.executeImpl(getMockedAction(), actionedUponNodeRef); declareAsVersionRecordAction.executeImpl(getMockedAction(), actionedUponNodeRef);
} }
@@ -282,6 +282,75 @@ public class DeclareAsVersionRecordActionUnitTest extends BaseActionUnitTest
public void validFilePlanParameter() public void validFilePlanParameter()
{ {
// setup // setup
setupMockedAspects();
// not a file plan is provided in the parameters
NodeRef myFilePlan = generateNodeRef(TYPE_FILE_PLAN);
doReturn(true).when(mockedFilePlanService).isFilePlan(myFilePlan);
mockActionParameterValue(DeclareAsVersionRecordAction.PARAM_FILE_PLAN, myFilePlan);
// execute action
declareAsVersionRecordAction.executeImpl(getMockedAction(), actionedUponNodeRef);
verify(mockedRecordableVersionService, times(1)).createRecordFromLatestVersion(myFilePlan, actionedUponNodeRef);
}
/**
* Given that a valid location is provided
* When I execute the action
* Then a version record is declared in the provided location
*/
@Test
public void validDestinationRecordFolderProvided()
{
String pathParameter = GUID.generate();
// setup
setupMockedAspects();
mockActionParameterValue(DeclareAsVersionRecordAction.PARAM_PATH, pathParameter);
// provided location
doReturn(destinationRecordFolderNodeRef).when(mockedNodeService).getChildByName(filePlan, ContentModel.ASSOC_CONTAINS, pathParameter);
doReturn(TYPE_RECORD_FOLDER).when(mockedNodeService).getType(destinationRecordFolderNodeRef);
// capability check
doReturn(true).when(mockedCapabilityService).hasCapability(destinationRecordFolderNodeRef, "FileVersionRecords");
// file plan service
doReturn(filePlan).when(mockedFilePlanService).getFilePlanBySiteId(FilePlanService.DEFAULT_RM_SITE_ID);
// execute action
declareAsVersionRecordAction.executeImpl(getMockedAction(), actionedUponNodeRef);
verify(mockedRecordableVersionService, times(1)).createRecordFromLatestVersion(destinationRecordFolderNodeRef, actionedUponNodeRef);
}
/**
* Given that an invalid location is provided
* When I execute the action
* Then an exception is thrown
*/
@Test
public void invalidDestinationRecordFolderProvided()
{
String childName = GUID.generate();
// setup
setupMockedAspects();
// provided location
doReturn(destinationRecordFolderNodeRef).when(mockedNodeService).getChildByName(parentDestinationNodeRef, ContentModel.ASSOC_CONTAINS, childName);
doReturn(TYPE_RECORD_FOLDER).when(mockedNodeService).getType(destinationRecordFolderNodeRef);
// capability check
doReturn(false).when(mockedCapabilityService).hasCapability(destinationRecordFolderNodeRef, "EditRecordMetadata");
// expect exception
exception.expect(AlfrescoRuntimeException.class);
// execute action
declareAsVersionRecordAction.executeImpl(getMockedAction(), actionedUponNodeRef);
}
private void setupMockedAspects()
{
doReturn(true).when(mockedNodeService).exists(actionedUponNodeRef); doReturn(true).when(mockedNodeService).exists(actionedUponNodeRef);
doReturn(true).when(mockedDictionaryService).isSubClass(any(QName.class), eq(ContentModel.TYPE_CONTENT)); doReturn(true).when(mockedDictionaryService).isSubClass(any(QName.class), eq(ContentModel.TYPE_CONTENT));
doReturn(true).when(mockedNodeService).hasAspect(actionedUponNodeRef, ContentModel.ASPECT_VERSIONABLE); doReturn(true).when(mockedNodeService).hasAspect(actionedUponNodeRef, ContentModel.ASPECT_VERSIONABLE);
@@ -289,14 +358,5 @@ public class DeclareAsVersionRecordActionUnitTest extends BaseActionUnitTest
doReturn(false).when(mockedNodeService).hasAspect(actionedUponNodeRef, ContentModel.ASPECT_WORKING_COPY); doReturn(false).when(mockedNodeService).hasAspect(actionedUponNodeRef, ContentModel.ASPECT_WORKING_COPY);
doReturn(false).when(mockedNodeService).hasAspect(actionedUponNodeRef, ASPECT_RECORD_REJECTION_DETAILS); doReturn(false).when(mockedNodeService).hasAspect(actionedUponNodeRef, ASPECT_RECORD_REJECTION_DETAILS);
doReturn(false).when(mockedNodeService).hasAspect(actionedUponNodeRef, ASPECT_SYNCED); doReturn(false).when(mockedNodeService).hasAspect(actionedUponNodeRef, ASPECT_SYNCED);
// not a file plan is provided in the parameters
NodeRef myFilePlan = generateNodeRef(TYPE_FILE_PLAN);
doReturn(true).when(mockedFilePlanService).isFilePlan(myFilePlan);
mockActionParameterValue(DeclareAsVersionRecordAction.PARAM_FILE_PLAN, myFilePlan);
// exceute action
declareAsVersionRecordAction.executeImpl(getMockedAction(), actionedUponNodeRef);
verify(mockedRecordableVersionService, times(1)).createRecordFromLatestVersion(myFilePlan, actionedUponNodeRef);
} }
} }

View File

@@ -37,11 +37,16 @@
<script src='lib/jquery.slideto.min.js' type='text/javascript'></script> <script src='lib/jquery.slideto.min.js' type='text/javascript'></script>
<script src='lib/jquery.wiggle.min.js' type='text/javascript'></script> <script src='lib/jquery.wiggle.min.js' type='text/javascript'></script>
<script src='lib/jquery.ba-bbq.min.js' type='text/javascript'></script> <script src='lib/jquery.ba-bbq.min.js' type='text/javascript'></script>
<script src='lib/handlebars-2.0.0.js' type='text/javascript'></script> <script src='lib/handlebars-4.0.5.js' type='text/javascript'></script>
<script src='lib/underscore-min.js' type='text/javascript'></script> <script src='lib/object-assign-pollyfill.js' type='text/javascript'></script>
<script src='lib/es5-shim.js' type='text/javascript'></script>
<script src='lib/js-yaml.min.js' type='text/javascript'></script>
<script src='lib/sanitize-html.min.js' type='text/javascript'></script>
<script src='lib/lodash.min.js' type='text/javascript'></script>
<script src='lib/backbone-min.js' type='text/javascript'></script> <script src='lib/backbone-min.js' type='text/javascript'></script>
<script src='swagger-ui.js' type='text/javascript'></script> <script src='swagger-ui.js' type='text/javascript'></script>
<script src='lib/highlight.7.3.pack.js' type='text/javascript'></script> <script src='lib/highlight.9.1.0.pack.js' type='text/javascript'></script>
<script src='lib/highlight.9.1.0.pack_extended.js' type='text/javascript'></script>
<script src='lib/jsoneditor.min.js' type='text/javascript'></script> <script src='lib/jsoneditor.min.js' type='text/javascript'></script>
<script src='lib/marked.js' type='text/javascript'></script> <script src='lib/marked.js' type='text/javascript'></script>
<script src='lib/swagger-oauth.js' type='text/javascript'></script> <script src='lib/swagger-oauth.js' type='text/javascript'></script>