diff --git a/rm-server/config/alfresco/module/org_alfresco_module_rm/rm-action-context.xml b/rm-server/config/alfresco/module/org_alfresco_module_rm/rm-action-context.xml
index ae95fdc820..f8db542201 100644
--- a/rm-server/config/alfresco/module/org_alfresco_module_rm/rm-action-context.xml
+++ b/rm-server/config/alfresco/module/org_alfresco_module_rm/rm-action-context.xml
@@ -413,8 +413,6 @@
-
-
@@ -968,6 +966,7 @@
class="org.alfresco.module.org_alfresco_module_rm.action.impl.FileReportAction"
parent="rmAction">
+
@@ -1016,10 +1015,10 @@
-
+
-
+
diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/action/impl/FileReportAction.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/action/impl/FileReportAction.java
index ad852d527c..4859a9280b 100644
--- a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/action/impl/FileReportAction.java
+++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/action/impl/FileReportAction.java
@@ -21,6 +21,7 @@ package org.alfresco.module.org_alfresco_module_rm.action.impl;
import org.alfresco.error.AlfrescoRuntimeException;
import org.alfresco.model.ContentModel;
import org.alfresco.module.org_alfresco_module_rm.action.RMActionExecuterAbstractBase;
+import org.alfresco.module.org_alfresco_module_rm.capability.CapabilityService;
import org.alfresco.module.org_alfresco_module_rm.report.Report;
import org.alfresco.module.org_alfresco_module_rm.report.ReportModel;
import org.alfresco.module.org_alfresco_module_rm.report.ReportService;
@@ -30,6 +31,7 @@ import org.alfresco.repo.security.authentication.AuthenticationUtil;
import org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork;
import org.alfresco.service.cmr.action.Action;
import org.alfresco.service.cmr.repository.NodeRef;
+import org.alfresco.service.cmr.security.AccessStatus;
import org.alfresco.service.namespace.QName;
import org.apache.commons.lang.StringUtils;
import org.springframework.extensions.surf.util.I18NUtil;
@@ -58,6 +60,9 @@ public class FileReportAction extends RMActionExecuterAbstractBase implements Re
/** Report service */
private ReportService reportService;
+ /** Capability service */
+ private CapabilityService capabilityService;
+
/**
* @return Report service
*/
@@ -66,6 +71,14 @@ public class FileReportAction extends RMActionExecuterAbstractBase implements Re
return this.reportService;
}
+ /**
+ * @return Capability service
+ */
+ protected CapabilityService getCapabilityService()
+ {
+ return this.capabilityService;
+ }
+
/**
* @param reportService report service
*/
@@ -74,6 +87,14 @@ public class FileReportAction extends RMActionExecuterAbstractBase implements Re
this.reportService = reportService;
}
+ /**
+ * @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)
@@ -94,6 +115,9 @@ public class FileReportAction extends RMActionExecuterAbstractBase implements Re
// get the destination
final NodeRef destination = getDestination(action);
+ // Check the filing permission only capability for the destination
+ checkFilingPermissionOnlyCapability(destination);
+
// generate the report
final Report report = getReportService().generateReport(reportType, actionedUponNodeRef, mimetype);
@@ -112,6 +136,19 @@ public class FileReportAction extends RMActionExecuterAbstractBase implements Re
action.setParameterValue(ActionExecuterAbstractBase.PARAM_RESULT, filedReportName);
}
+ /**
+ * Checks if the destination is frozen, closed, cut off or not. In case if it is an exception will be thrown.
+ *
+ * @param nodeRef The destination node reference for which the capability should be checked
+ */
+ private void checkFilingPermissionOnlyCapability(NodeRef nodeRef)
+ {
+ if (AccessStatus.DENIED.equals(capabilityService.getCapability("FillingPermissionOnly").hasPermission(nodeRef)))
+ {
+ throw new AlfrescoRuntimeException("The destination is either frozen, closed or cut off!");
+ }
+ }
+
/**
* Retrieves the value of the given parameter. If the parameter has not been
* passed from the UI an error will be thrown
diff --git a/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/legacy/action/ActionTestSuite.java b/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/legacy/action/ActionTestSuite.java
index 73bc7e9388..c9fdd2b62a 100644
--- a/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/legacy/action/ActionTestSuite.java
+++ b/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/legacy/action/ActionTestSuite.java
@@ -35,7 +35,8 @@ import org.junit.runners.Suite.SuiteClasses;
CreateRecordActionTest.class,
HideRecordActionTest.class,
RejectActionTest.class,
- FileToActionTest.class
+ FileToActionTest.class,
+ FileReportActionTest.class
})
public class ActionTestSuite
{
diff --git a/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/legacy/action/FileReportActionTest.java b/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/legacy/action/FileReportActionTest.java
new file mode 100644
index 0000000000..f1e17bfa7c
--- /dev/null
+++ b/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/legacy/action/FileReportActionTest.java
@@ -0,0 +1,101 @@
+/*
+ * 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 org.alfresco.module.org_alfresco_module_rm.action.impl.FileReportAction;
+import org.alfresco.module.org_alfresco_module_rm.test.util.BaseRMTestCase;
+import org.alfresco.repo.content.MimetypeMap;
+import org.alfresco.service.cmr.action.Action;
+import org.alfresco.service.cmr.repository.NodeRef;
+import org.apache.commons.lang.StringUtils;
+import org.springframework.extensions.webscripts.GUID;
+
+/**
+ * File report action unit test
+ *
+ * @author Tuna Aksoy
+ * @since 2.2
+ * @version 1.0
+ */
+public class FileReportActionTest extends BaseRMTestCase
+{
+ @Override
+ protected boolean isUserTest()
+ {
+ return true;
+ }
+
+ public void testFileReport()
+ {
+ fileReport(MimetypeMap.MIMETYPE_HTML);
+ }
+
+ public void testfileReportDefaultMimetype()
+ {
+ fileReport(null);
+ }
+
+ private void fileReport(final String mimeType)
+ {
+ // create record folder
+ final NodeRef recordFolder = recordFolderService.createRecordFolder(rmContainer, GUID.generate());
+
+ // create hold
+ final NodeRef hold = holdService.createHold(filePlan, "holdName", "holdReason", "holdDescription");
+
+ doTestInTransaction(new FailureTest()
+ {
+ @Override
+ public void run() throws Exception
+ {
+ // close the record folder
+ recordFolderService.closeRecordFolder(recordFolder);
+
+ // execute action
+ executeAction(mimeType, recordFolder, hold);
+ }
+ });
+
+ doTestInTransaction(new Test()
+ {
+ public Void run()
+ {
+ // reopen the record folder
+ nodeService.setProperty(recordFolder, PROP_IS_CLOSED, false);
+
+ // execute action
+ executeAction(mimeType, recordFolder, hold);
+
+ return null;
+ }
+ }, ADMIN_USER);
+ }
+
+ private void executeAction(String mimeType, NodeRef recordFolder, NodeRef hold)
+ {
+ Action action = actionService.createAction(FileReportAction.NAME);
+ if (StringUtils.isNotBlank(mimeType))
+ {
+ action.setParameterValue(FileReportAction.MIMETYPE, mimeType);
+ }
+ action.setParameterValue(FileReportAction.DESTINATION, recordFolder.toString());
+ action.setParameterValue(FileReportAction.REPORT_TYPE, "rmr:destructionReport");
+ actionService.executeAction(action, hold);
+ }
+}
diff --git a/rm-server/unit-test/java/org/alfresco/module/org_alfresco_module_rm/action/impl/FileReportActionUnitTest.java b/rm-server/unit-test/java/org/alfresco/module/org_alfresco_module_rm/action/impl/FileReportActionUnitTest.java
index ee08b88244..5da2c6697f 100644
--- a/rm-server/unit-test/java/org/alfresco/module/org_alfresco_module_rm/action/impl/FileReportActionUnitTest.java
+++ b/rm-server/unit-test/java/org/alfresco/module/org_alfresco_module_rm/action/impl/FileReportActionUnitTest.java
@@ -19,46 +19,34 @@
package org.alfresco.module.org_alfresco_module_rm.action.impl;
import static org.mockito.Mockito.doReturn;
-import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyZeroInteractions;
import org.alfresco.error.AlfrescoRuntimeException;
-import org.alfresco.model.ContentModel;
-import org.alfresco.module.org_alfresco_module_rm.report.Report;
import org.alfresco.module.org_alfresco_module_rm.test.util.BaseUnitTest;
-import org.alfresco.repo.action.executer.ActionExecuterAbstractBase;
import org.alfresco.repo.content.MimetypeMap;
import org.alfresco.service.cmr.action.Action;
import org.alfresco.service.cmr.repository.NodeRef;
-import org.alfresco.service.namespace.QName;
import org.junit.Test;
import org.mockito.InjectMocks;
import org.mockito.Mock;
/**
* Unit test for file report action.
- *
+ *
* @author Roy Wetherall
* @since 2.2
*/
public class FileReportActionUnitTest extends BaseUnitTest
{
- /** report name */
- private static final String REPORT_NAME = "testReportName";
-
/** actioned upon node reference */
private NodeRef actionedUponNodeRef;
-
+
/** mocked action */
private @Mock Action mockedAction;
-
- /** mocked report */
- private @Mock Report mockedReport;
-
+
/** file report action */
private @InjectMocks FileReportAction fileReportAction;
-
+
/**
* @see org.alfresco.module.org_alfresco_module_rm.test.util.BaseUnitTest#before()
*/
@@ -66,14 +54,14 @@ public class FileReportActionUnitTest extends BaseUnitTest
public void before()
{
super.before();
-
+
// actioned upon node reference
actionedUponNodeRef = generateRecord();
-
+
// mocked action
fileReportAction.setAuditable(false);
}
-
+
/**
* Helper to mock an action parameter value
*/
@@ -81,7 +69,7 @@ public class FileReportActionUnitTest extends BaseUnitTest
{
doReturn(value).when(mockedAction).getParameterValue(name);
}
-
+
/**
* given the destination is not set, ensure that an exception is thrown
*/
@@ -89,23 +77,23 @@ public class FileReportActionUnitTest extends BaseUnitTest
public void destinationNotSet()
{
// == given ==
-
+
// set action parameter values
mockActionParameterValue(FileReportAction.MIMETYPE, MimetypeMap.MIMETYPE_HTML);
mockActionParameterValue(FileReportAction.REPORT_TYPE, "rma:destructionReport");
-
+
// expected exception
exception.expect(AlfrescoRuntimeException.class);
-
+
// == when ==
-
+
// execute action
fileReportAction.executeImpl(mockedAction, actionedUponNodeRef);
-
+
// == then ==
- verifyZeroInteractions(mockedReportService, mockedNodeService);
+ verifyZeroInteractions(mockedReportService, mockedNodeService);
}
-
+
/**
* given no report type set, ensure that an exception is thrown
*/
@@ -113,100 +101,20 @@ public class FileReportActionUnitTest extends BaseUnitTest
public void reportTypeNotSet()
{
// == given ==
-
+
// set action parameter values
mockActionParameterValue(FileReportAction.MIMETYPE, MimetypeMap.MIMETYPE_HTML);
mockActionParameterValue(FileReportAction.DESTINATION, generateNodeRef().toString());
-
+
// expected exception
exception.expect(AlfrescoRuntimeException.class);
-
+
// == when ==
-
+
// execute action
fileReportAction.executeImpl(mockedAction, actionedUponNodeRef);
-
+
// == then ==
- verifyZeroInteractions(mockedReportService, mockedNodeService);
- }
-
- /**
- * given the file report action is executed, ensure the service interactions and returned result
- * are correct.
- */
- @Test
- public void fileReport()
- {
- // == given ==
-
- // data
- NodeRef destination = generateNodeRef();
- NodeRef filedReport = generateNodeRef();
- String reportType = "rma:destructionReport";
- QName reportTypeQName = QName.createQName(RM_URI, "destructionReport");
- String mimetype = MimetypeMap.MIMETYPE_HTML;
-
- // set action parameter values
- mockActionParameterValue(FileReportAction.MIMETYPE, mimetype);
- mockActionParameterValue(FileReportAction.DESTINATION, destination.toString());
- mockActionParameterValue(FileReportAction.REPORT_TYPE, reportType);
-
- // setup service interactions
- doReturn(mockedReport).when(mockedReportService).generateReport(reportTypeQName, actionedUponNodeRef, mimetype);
- doReturn(filedReport).when(mockedReportService).fileReport(destination, mockedReport);
- doReturn(REPORT_NAME).when(mockedNodeService).getProperty(filedReport, ContentModel.PROP_NAME);
-
- // == when ==
-
- // execute action
- fileReportAction.executeImpl(mockedAction, actionedUponNodeRef);
-
- // == then ==
-
- // verify interactions
- verify(mockedReportService, times(1)).generateReport(reportTypeQName, actionedUponNodeRef, mimetype);
- verify(mockedReportService, times(1)).fileReport(destination, mockedReport);
- verify(mockedNodeService, times(1)).getProperty(filedReport, ContentModel.PROP_NAME);
- verify(mockedAction, times(1)).setParameterValue(ActionExecuterAbstractBase.PARAM_RESULT, REPORT_NAME);
- }
-
- /**
- * given the file report action is executed with no mimetype set, ensure that a report is generated
- * with the default mimetype.
- */
- @Test
- public void fileReportDefaultMimetype()
- {
- // == given ==
-
- // data
- NodeRef destination = generateNodeRef();
- NodeRef filedReport = generateNodeRef();
- String reportType = "rma:destructionReport";
- QName reportTypeQName = QName.createQName(RM_URI, "destructionReport");
- String mimetype = MimetypeMap.MIMETYPE_HTML;
-
- // set action parameter values
- mockActionParameterValue(FileReportAction.DESTINATION, destination.toString());
- mockActionParameterValue(FileReportAction.REPORT_TYPE, reportType);
-
- // setup service interactions
- doReturn(mockedReport).when(mockedReportService).generateReport(reportTypeQName, actionedUponNodeRef, mimetype);
- doReturn(filedReport).when(mockedReportService).fileReport(destination, mockedReport);
- doReturn(REPORT_NAME).when(mockedNodeService).getProperty(filedReport, ContentModel.PROP_NAME);
-
- // == when ==
-
- // execute action
- fileReportAction.executeImpl(mockedAction, actionedUponNodeRef);
-
- // == then ==
-
- // verify interactions
- verify(mockedReportService, times(1)).generateReport(reportTypeQName, actionedUponNodeRef, mimetype);
- verify(mockedReportService, times(1)).fileReport(destination, mockedReport);
- verify(mockedNodeService, times(1)).getProperty(filedReport, ContentModel.PROP_NAME);
- verify(mockedAction, times(1)).setParameterValue(ActionExecuterAbstractBase.PARAM_RESULT, REPORT_NAME);
-
+ verifyZeroInteractions(mockedReportService, mockedNodeService);
}
}