diff --git a/rm-server/config/alfresco/module/org_alfresco_module_rm/action-context.xml b/rm-server/config/alfresco/module/org_alfresco_module_rm/action-context.xml index 3f5c40a98b..718cf02066 100644 --- a/rm-server/config/alfresco/module/org_alfresco_module_rm/action-context.xml +++ b/rm-server/config/alfresco/module/org_alfresco_module_rm/action-context.xml @@ -40,4 +40,12 @@ + + + + + + + + \ No newline at end of file diff --git a/rm-server/config/alfresco/module/org_alfresco_module_rm/messages/actions.properties b/rm-server/config/alfresco/module/org_alfresco_module_rm/messages/actions.properties index 690be465e8..96b9a22e7b 100644 --- a/rm-server/config/alfresco/module/org_alfresco_module_rm/messages/actions.properties +++ b/rm-server/config/alfresco/module/org_alfresco_module_rm/messages/actions.properties @@ -181,6 +181,10 @@ fileReport.description=File report # Delete Hold deleteHold.title=Delete Hold deleteHold.description=Delete hold +# Recordable version config +recordable-version-config.title=Recordable Version Config +recordable-version-config.description=Recordable Version Config +recordable-version-config.version.display-label=Recorded Versions # Action parameter constraints rm-ac-is-kind-kinds.record_category=Record Category @@ -189,4 +193,8 @@ rm-ac-is-kind-kinds.record=Record rm-ac-disposition-action-relative-positions.next=Next rm-ac-disposition-action-relative-positions.previous=Previous -rm-ac-disposition-action-relative-positions.any=Any \ No newline at end of file +rm-ac-disposition-action-relative-positions.any=Any + +ac-versions.none=None +ac-versions.major_only=Major Revisions Only +ac-versions.all=All Revisions \ No newline at end of file diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/action/constraint/VersionParameterConstraint.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/action/constraint/VersionParameterConstraint.java new file mode 100644 index 0000000000..c1677f84d8 --- /dev/null +++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/action/constraint/VersionParameterConstraint.java @@ -0,0 +1,50 @@ +/* + * Copyright (C) 2005-2014 Alfresco Software Limited. + * + * This file is part of Alfresco + * + * 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 . + */ +package org.alfresco.module.org_alfresco_module_rm.action.constraint; + +import java.util.HashMap; +import java.util.Map; + +import org.alfresco.module.org_alfresco_module_rm.version.RecordableVersionPolicy; +import org.alfresco.repo.action.constraint.BaseParameterConstraint; + +/** + * Recordable version config constraint + * + * @author Tuna Aksoy + * @since 2.3 + */ +public class VersionParameterConstraint extends BaseParameterConstraint +{ + /** + * @see org.alfresco.repo.action.constraint.BaseParameterConstraint#getAllowableValuesImpl() + */ + @Override + protected Map getAllowableValuesImpl() + { + RecordableVersionPolicy[] recordableVersionPolicies = RecordableVersionPolicy.values(); + Map allowableValues = new HashMap(recordableVersionPolicies.length); + for (RecordableVersionPolicy recordableVersionPolicy : recordableVersionPolicies) + { + String policy = recordableVersionPolicy.toString(); + allowableValues.put(policy, getI18NLabel(policy)); + } + return allowableValues; + } +} diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/action/dm/RecordableVersionConfigAction.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/action/dm/RecordableVersionConfigAction.java new file mode 100644 index 0000000000..9acea4eb60 --- /dev/null +++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/action/dm/RecordableVersionConfigAction.java @@ -0,0 +1,195 @@ +/* + * Copyright (C) 2005-2014 Alfresco Software Limited. + * + * This file is part of Alfresco + * + * 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 . + */ +package org.alfresco.module.org_alfresco_module_rm.action.dm; + +import static org.alfresco.model.ContentModel.ASPECT_VERSIONABLE; +import static org.alfresco.model.ContentModel.TYPE_CONTENT; +import static org.alfresco.module.org_alfresco_module_rm.model.RecordsManagementModel.ASPECT_RECORD; +import static org.alfresco.module.org_alfresco_module_rm.version.RecordableVersionModel.PROP_RECORDABLE_VERSION_POLICY; +import static org.alfresco.service.cmr.dictionary.DataTypeDefinition.TEXT; +import static org.apache.commons.logging.LogFactory.getLog; + +import java.util.List; + +import org.alfresco.module.org_alfresco_module_rm.action.AuditableActionExecuterAbstractBase; +import org.alfresco.module.org_alfresco_module_rm.version.RecordableVersionPolicy; +import org.alfresco.repo.action.ParameterDefinitionImpl; +import org.alfresco.service.cmr.action.Action; +import org.alfresco.service.cmr.action.ParameterDefinition; +import org.alfresco.service.cmr.dictionary.DictionaryService; +import org.alfresco.service.cmr.repository.NodeRef; +import org.alfresco.service.cmr.repository.NodeService; +import org.alfresco.service.namespace.QName; +import org.apache.commons.logging.Log; + +/** + * Sets the recordable version config for a document within a collaboration site. + * + * Note: This is a 'normal' dm action, rather than a records management action. + * + * @author Tuna Aksoy + * @since 2.3 + */ +public class RecordableVersionConfigAction extends AuditableActionExecuterAbstractBase +{ + /** Logger */ + private static Log LOGGER = getLog(RecordableVersionConfigAction.class); + + /** Action name */ + public static final String NAME = "recordable-version-config"; + + /** Parameter names */ + public static final String PARAM_VERSION = "version"; + + /** Node service */ + private NodeService nodeService; + + /** Dictionary service */ + private DictionaryService dictionaryService; + + /** + * Gets the node service + * + * @return The node service + */ + protected NodeService getNodeService() + { + return this.nodeService; + } + + /** + * Sets the node service + * + * @param nodeService The node service + */ + public void setNodeService(NodeService nodeService) + { + this.nodeService = nodeService; + } + + /** + * Gets the dictionary service + * + * @return The dictionary service + */ + protected DictionaryService getDictionaryService() + { + return this.dictionaryService; + } + + /** + * @see org.alfresco.repo.action.executer.ActionExecuterAbstractBase#setDictionaryService(org.alfresco.service.cmr.dictionary.DictionaryService) + */ + public void setDictionaryService(DictionaryService dictionaryService) + { + this.dictionaryService = dictionaryService; + } + + /** + * @see org.alfresco.repo.action.executer.ActionExecuterAbstractBase#executeImpl(org.alfresco.service.cmr.action.Action, org.alfresco.service.cmr.repository.NodeRef) + */ + @Override + protected void executeImpl(Action action, NodeRef actionedUponNodeRef) + { + if (passedChecks(actionedUponNodeRef)) + { + String version = (String) action.getParameterValue(PARAM_VERSION); + getNodeService().setProperty(actionedUponNodeRef, PROP_RECORDABLE_VERSION_POLICY, RecordableVersionPolicy.valueOf(version)); + } + } + + /** + * @see org.alfresco.repo.action.ParameterizedItemAbstractBase#addParameterDefinitions(java.util.List) + */ + @Override + protected void addParameterDefinitions(List paramList) + { + paramList.add(new ParameterDefinitionImpl(PARAM_VERSION, TEXT, true, getParamDisplayLabel(PARAM_VERSION), false, "ac-versions")); + } + + /** + * Helper method to do checks on the actioned upon node reference + * + * @param actionedUponNodeRef The actioned upon node reference + * @return true if the actioned upon node reference passes the checks, false otherwise + */ + private boolean passedChecks(NodeRef actionedUponNodeRef) + { + boolean passedChecks = true; + + if (!getNodeService().exists(actionedUponNodeRef)) + { + passedChecks = false; + if (LOGGER.isDebugEnabled()) + { + String message = buildLogMessage(actionedUponNodeRef, "' because the node does not exist."); + LOGGER.debug(message); + } + } + + QName type = getNodeService().getType(actionedUponNodeRef); + if (!getDictionaryService().isSubClass(type, TYPE_CONTENT)) + { + passedChecks = false; + if (LOGGER.isDebugEnabled()) + { + String message = buildLogMessage(actionedUponNodeRef, "' because the type of the node '" + type.getLocalName() + "' is not supported."); + LOGGER.debug(message); + } + } + + if (getNodeService().hasAspect(actionedUponNodeRef, ASPECT_RECORD)) + { + passedChecks = false; + if (LOGGER.isDebugEnabled()) + { + String message = buildLogMessage(actionedUponNodeRef, "' because the rule cannot be applied to records."); + LOGGER.debug(message); + } + } + + if (!getNodeService().hasAspect(actionedUponNodeRef, ASPECT_VERSIONABLE)) + { + passedChecks = false; + if (LOGGER.isDebugEnabled()) + { + String buildLogMessage = buildLogMessage(actionedUponNodeRef, "' because the rule cannot be applied to records."); + LOGGER.debug(buildLogMessage); + } + } + + return passedChecks; + } + + /** + * Helper method to construct log message + * + * @param actionedUponNodeRef The actioned upon node reference + * @param messagePart The message which should be appended. + * @return The constructed log message + */ + private String buildLogMessage(NodeRef actionedUponNodeRef, String messagePart) + { + StringBuilder sb = new StringBuilder(); + sb.append("Cannot set recordable version config for '"); + sb.append(actionedUponNodeRef.toString()); + sb.append(messagePart); + return sb.toString(); + } +} diff --git a/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/legacy/action/RecordableVersionConfigActionTest.java b/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/legacy/action/RecordableVersionConfigActionTest.java new file mode 100644 index 0000000000..1d15c27b03 --- /dev/null +++ b/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/legacy/action/RecordableVersionConfigActionTest.java @@ -0,0 +1,143 @@ +/* + * Copyright (C) 2005-2014 Alfresco Software Limited. + * + * This file is part of Alfresco + * + * 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 . + */ +package org.alfresco.module.org_alfresco_module_rm.test.legacy.action; + +import static org.alfresco.module.org_alfresco_module_rm.action.dm.RecordableVersionConfigAction.NAME; +import static org.alfresco.module.org_alfresco_module_rm.action.dm.RecordableVersionConfigAction.PARAM_VERSION; +import static org.alfresco.module.org_alfresco_module_rm.version.RecordableVersionModel.PROP_RECORDABLE_VERSION_POLICY; +import static org.alfresco.module.org_alfresco_module_rm.version.RecordableVersionPolicy.ALL; +import static org.alfresco.module.org_alfresco_module_rm.version.RecordableVersionPolicy.MAJOR_ONLY; +import static org.alfresco.module.org_alfresco_module_rm.version.RecordableVersionPolicy.NONE; + +import java.io.Serializable; + +import org.alfresco.model.ContentModel; +import org.alfresco.module.org_alfresco_module_rm.action.dm.CreateRecordAction; +import org.alfresco.module.org_alfresco_module_rm.test.util.BaseRMTestCase; +import org.alfresco.service.cmr.action.Action; +import org.alfresco.service.cmr.repository.NodeRef; + +/** + * Recordable version config action test + * + * @author Tuna Aksoy + * @since 2.3 + */ +public class RecordableVersionConfigActionTest extends BaseRMTestCase +{ + /** + * @see org.alfresco.module.org_alfresco_module_rm.test.util.BaseRMTestCase#isUserTest() + */ + @Override + protected boolean isUserTest() + { + return true; + } + + /** + * @see org.alfresco.module.org_alfresco_module_rm.test.util.BaseRMTestCase#isCollaborationSiteTest() + */ + @Override + protected boolean isCollaborationSiteTest() + { + return true; + } + + public void testRecordableVersionConfigAction() + { + doTestInTransaction(new Test() + { + public Void run() + { + Action action = actionService.createAction(NAME); + action.setParameterValue(PARAM_VERSION, MAJOR_ONLY.toString()); + nodeService.addAspect(dmDocument, ASPECT_VERSIONABLE, null); + actionService.executeAction(action, dmDocument); + return null; + } + + public void test(Void result) throws Exception + { + Serializable version = nodeService.getProperty(dmDocument, PROP_RECORDABLE_VERSION_POLICY); + assertNotNull(version); + assertEquals(MAJOR_ONLY.toString(), (String) version); + }; + }, + dmCollaborator); + + doTestInTransaction(new Test() + { + public Void run() + { + Action action = actionService.createAction(NAME); + action.setParameterValue(PARAM_VERSION, ALL.toString()); + actionService.executeAction(action, dmFolder); + return null; + } + + public void test(Void result) throws Exception + { + assertNull(nodeService.getProperty(dmFolder, PROP_RECORDABLE_VERSION_POLICY)); + }; + }, + dmCollaborator); + + doTestInTransaction(new Test() + { + final NodeRef document1 = fileFolderService.create(dmFolder, "another document", ContentModel.TYPE_CONTENT).getNodeRef(); + public Void run() + { + Action action = actionService.createAction(NAME); + action.setParameterValue(PARAM_VERSION, NONE.toString()); + nodeService.removeAspect(document1, ASPECT_VERSIONABLE); + actionService.executeAction(action, document1); + return null; + } + + public void test(Void result) throws Exception + { + assertNull(nodeService.getProperty(document1, PROP_RECORDABLE_VERSION_POLICY)); + }; + }, + dmCollaborator); + + + doTestInTransaction(new Test() + { + final NodeRef document2 = fileFolderService.create(dmFolder, "testfile.txt", ContentModel.TYPE_CONTENT).getNodeRef(); + public Void run() + { + Action createAction = actionService.createAction(CreateRecordAction.NAME); + createAction.setParameterValue(CreateRecordAction.PARAM_FILE_PLAN, filePlan); + actionService.executeAction(createAction, document2); + + Action action = actionService.createAction(NAME); + action.setParameterValue(PARAM_VERSION, MAJOR_ONLY.toString()); + actionService.executeAction(action, document2); + return null; + } + + public void test(Void result) throws Exception + { + assertNull(nodeService.getProperty(document2, PROP_RECORDABLE_VERSION_POLICY)); + }; + }, + dmCollaborator); + } +}