diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/action/impl/RejectAction.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/action/impl/RejectAction.java index 06e3f5c7b4..31ea3ed0bd 100644 --- a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/action/impl/RejectAction.java +++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/action/impl/RejectAction.java @@ -43,6 +43,9 @@ public class RejectAction extends RMActionExecuterAbstractBase /** Parameter names */ public static final String PARAM_REASON = "reason"; + /** Action name */ + public static final String NAME = "reject"; + /** * @see org.alfresco.repo.action.executer.ActionExecuterAbstractBase#executeImpl(org.alfresco.service.cmr.action.Action, org.alfresco.service.cmr.repository.NodeRef) */ diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/record/RecordServiceImpl.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/record/RecordServiceImpl.java index c8274b612e..d69e4b1d7d 100644 --- a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/record/RecordServiceImpl.java +++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/record/RecordServiceImpl.java @@ -428,7 +428,7 @@ public class RecordServiceImpl implements RecordService, } @Override - public void rejectRecord(final NodeRef nodeRef, String reason) + public void rejectRecord(final NodeRef nodeRef, final String reason) { ParameterCheck.mandatory("NodeRef", nodeRef); ParameterCheck.mandatoryString("Reason", reason); @@ -463,7 +463,7 @@ public class RecordServiceImpl implements RecordService, // save the reject reason Map aspectProperties = new HashMap(1); - aspectProperties.put(PROP_REJECT_REASON, (Serializable) parentAssoc.getParentRef()); + aspectProperties.put(PROP_REJECT_REASON, reason); nodeService.addAspect(nodeRef, ASPECT_REJECT_REASON_RECORD, aspectProperties); // move the record into the collaboration site diff --git a/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/action/RejectActionTest.java b/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/action/RejectActionTest.java new file mode 100644 index 0000000000..54f8294cf7 --- /dev/null +++ b/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/action/RejectActionTest.java @@ -0,0 +1,131 @@ +/* + * Copyright (C) 2005-2012 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.action; + +import org.alfresco.module.org_alfresco_module_rm.action.dm.CreateRecordAction; +import org.alfresco.module.org_alfresco_module_rm.action.impl.RejectAction; +import org.alfresco.module.org_alfresco_module_rm.security.ExtendedSecurityService; +import org.alfresco.module.org_alfresco_module_rm.test.util.BaseRMTestCase; +import org.alfresco.service.cmr.action.Action; +import org.alfresco.service.cmr.action.ActionService; + +/** + * Reject Action Unit Test + * + * @author Tuna Aksoy + * @since 2.1 + */ +public class RejectActionTest extends BaseRMTestCase +{ + /** Services */ + protected ActionService rmActionService; + protected ExtendedSecurityService extendedSecurityService; + + /** Reject reason */ + private final String REJECT_REASON = "rejectReason:Not valid!£$%^&*()_+"; + + @Override + protected void initServices() + { + super.initServices(); + + rmActionService = (ActionService) applicationContext.getBean("ActionService"); + extendedSecurityService = (ExtendedSecurityService) applicationContext.getBean("ExtendedSecurityService"); + } + + @Override + protected boolean isUserTest() + { + return true; + } + + @Override + protected boolean isCollaborationSiteTest() + { + return true; + } + + public void testRejectAction() + { + doTestInTransaction(new Test() + { + public Void run() + { + // Create a record from the document + Action createAction = rmActionService.createAction(CreateRecordAction.NAME); + rmActionService.executeAction(createAction, dmDocument); + + // Check if the document is a record now + assertTrue(recordService.isRecord(dmDocument)); + + // The record should have the original location information + assertNotNull(nodeService.getProperty(dmDocument, PROP_ORIGINAL_LOCATION)); + + // Check the parents. In this case the document should have two parents (doclib and fileplan) + assertTrue(nodeService.getParentAssocs(dmDocument).size() == 2); + + return null; + } + }, + dmCollaborator); + + doTestInTransaction(new FailureTest("Cannot reject a record without a reason.", IllegalArgumentException.class) + { + public void run() + { + // The test should fail if the reject reason is not supplied + Action rejectAction = rmActionService.createAction(RejectAction.NAME); + rmActionService.executeAction(rejectAction, dmDocument); + } + }, + dmCollaborator); + + doTestInTransaction(new Test() + { + public Void run() + { + // Create the reject action and add the reject reason + Action rejectAction = rmActionService.createAction(RejectAction.NAME); + rejectAction.setParameterValue(RejectAction.PARAM_REASON, REJECT_REASON); + rmActionService.executeAction(rejectAction, dmDocument); + + // The "record" aspect should be removed + assertFalse(nodeService.hasAspect(dmDocument, ASPECT_RECORD)); + + // The "file plan component" should be removed + assertFalse(nodeService.hasAspect(dmDocument, ASPECT_FILE_PLAN_COMPONENT)); + + // The "identifier" property should be removed + assertNull(nodeService.getProperty(dmDocument, PROP_IDENTIFIER)); + + // The reject reason should be saved + assertTrue(((String) nodeService.getProperty(dmDocument, PROP_REJECT_REASON)).equals(REJECT_REASON)); + + // The record should be removed from the file plan + assertTrue(nodeService.getParentAssocs(dmDocument).size() == 1); + + // The extended reader information should be removed + assertNull(extendedSecurityService.getExtendedReaders(dmDocument)); + + return null; + } + }, + dmCollaborator); + } +}