RM-4326: allow creation under hold type only from HoldServiceImpl

This commit is contained in:
Silviu Dinuta
2016-11-08 20:40:51 +02:00
parent 18e86553de
commit 9746ee9ff3
10 changed files with 183 additions and 77 deletions

View File

@@ -86,6 +86,8 @@
<bean id="rma.transfer" class="org.alfresco.module.org_alfresco_module_rm.model.rma.type.TransferType" parent="rm.baseBehaviour" />
<bean id="rma.hold" class="org.alfresco.module.org_alfresco_module_rm.model.rma.type.HoldType" parent="rm.baseBehaviour" />
<bean id="rma.unfiledRecordsContainer" class="org.alfresco.module.org_alfresco_module_rm.model.rma.type.UnfiledRecordContainerType" parent="rm.baseBehaviour">
</bean>

View File

@@ -1499,6 +1499,7 @@
<property name="recordFolderService" ref="RecordFolderService" />
<property name="permissionService" ref="PermissionService"/>
<property name="recordsManagementAuditService" ref="RecordsManagementAuditService" />
<property name="holdType" ref="rma.hold" />
</bean>
<bean id="HoldService"

View File

@@ -44,6 +44,7 @@ import org.alfresco.module.org_alfresco_module_rm.audit.event.AuditEvent;
import org.alfresco.module.org_alfresco_module_rm.capability.RMPermissionModel;
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.rma.type.HoldType;
import org.alfresco.module.org_alfresco_module_rm.record.RecordService;
import org.alfresco.module.org_alfresco_module_rm.recordfolder.RecordFolderService;
import org.alfresco.module.org_alfresco_module_rm.util.ServiceBaseImpl;
@@ -102,6 +103,8 @@ public class HoldServiceImpl extends ServiceBaseImpl
/** records management audit service */
private RecordsManagementAuditService recordsManagementAuditService;
private HoldType holdType;
/**
* Set the file plan service
*
@@ -160,6 +163,11 @@ public class HoldServiceImpl extends ServiceBaseImpl
this.recordsManagementAuditService = recordsManagementAuditService;
}
public void setHoldType(HoldType holdType)
{
this.holdType = holdType;
}
/**
* Initialise hold service
*/
@@ -594,7 +602,15 @@ public class HoldServiceImpl extends ServiceBaseImpl
}
// Link the record to the hold
holdType.disable();
try
{
nodeService.addChild(hold, nodeRef, ASSOC_FROZEN_RECORDS, ASSOC_FROZEN_RECORDS);
}
finally
{
holdType.enable();
}
// audit item being added to the hold
recordsManagementAuditService.auditEvent(nodeRef, AUDIT_ADD_TO_HOLD);

View File

@@ -0,0 +1,79 @@
/*
* #%L
* Alfresco Records Management Module
* %%
* Copyright (C) 2005 - 2016 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.model.rma.type;
import java.security.InvalidParameterException;
import org.alfresco.module.org_alfresco_module_rm.model.BaseBehaviourBean;
import org.alfresco.repo.node.NodeServicePolicies;
import org.alfresco.repo.policy.annotation.Behaviour;
import org.alfresco.repo.policy.annotation.BehaviourBean;
import org.alfresco.repo.policy.annotation.BehaviourKind;
import org.alfresco.service.cmr.repository.ChildAssociationRef;
/**
* rma:transferContainer behaviour bean
*
* @author Silviu Dinuta
* @since 2.6
*/
@BehaviourBean(defaultType = "rma:hold")
public class HoldType extends BaseBehaviourBean implements NodeServicePolicies.OnCreateChildAssociationPolicy
{
private static final String BEHAVIOUR_NAME = "onCreateChildAssocsForHoldType";
/**
* Disable the behaviours for this transaction
*
*/
public void disable()
{
getBehaviour(BEHAVIOUR_NAME).disable();
}
/**
* Enable behaviours for this transaction
*
*/
public void enable()
{
getBehaviour(BEHAVIOUR_NAME).enable();
}
@Override
@Behaviour
(
kind = BehaviourKind.ASSOCIATION,
name = BEHAVIOUR_NAME
)
public void onCreateChildAssociation(ChildAssociationRef childAssocRef, boolean isNewNode)
{
throw new InvalidParameterException("Operation failed. Creation is not allowed in Hold Folders");
}
}

View File

@@ -407,14 +407,7 @@ public class RMNodesImpl extends NodesImpl implements RMNodes
public void checkPostPermission(String nodeId)
{
NodeRef parentNodeRef = validateOrLookupNode(nodeId, null);
QName parentNodeRefType = nodeService.getType(parentNodeRef);
if(RecordsManagementModel.TYPE_HOLD.equals(parentNodeRefType))
{
throw new PermissionDeniedException("POST request not allowed in Hold Folder.");
}
else
{
SiteInfo siteInfo = siteService.getSite(FilePlanService.DEFAULT_RM_SITE_ID);
if(siteInfo !=null)
{
@@ -425,5 +418,4 @@ public class RMNodesImpl extends NodesImpl implements RMNodes
}
}
}
}
}

View File

@@ -31,7 +31,6 @@ import java.util.ArrayList;
import java.util.List;
import org.alfresco.rest.api.model.Node;
import org.alfresco.rest.framework.core.exceptions.PermissionDeniedException;
import org.alfresco.rest.framework.resource.RelationshipResource;
import org.alfresco.rest.framework.resource.actions.interfaces.MultiPartRelationshipResourceAction;
import org.alfresco.rest.framework.resource.actions.interfaces.RelationshipResourceAction;

View File

@@ -51,6 +51,7 @@ import java.util.Map;
import org.alfresco.error.AlfrescoRuntimeException;
import org.alfresco.model.ContentModel;
import org.alfresco.module.org_alfresco_module_rm.model.rma.type.HoldType;
import org.alfresco.module.org_alfresco_module_rm.test.util.BaseUnitTest;
import org.alfresco.service.cmr.repository.ChildAssociationRef;
import org.alfresco.service.cmr.repository.NodeRef;
@@ -61,6 +62,7 @@ import org.junit.Before;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Spy;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
@@ -82,6 +84,9 @@ public class HoldServiceImplUnitTest extends BaseUnitTest
protected NodeRef hold;
protected NodeRef hold2;
@Mock
private HoldType mockedHoldType;
@Spy @InjectMocks HoldServiceImpl holdService;
@Before

View File

@@ -0,0 +1,72 @@
/*
* #%L
* Alfresco Records Management Module
* %%
* Copyright (C) 2005 - 2016 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.model.rma.type;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import java.security.InvalidParameterException;
import org.alfresco.module.org_alfresco_module_rm.test.util.AlfMock;
import org.alfresco.module.org_alfresco_module_rm.test.util.BaseUnitTest;
import org.alfresco.service.cmr.repository.ChildAssociationRef;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.namespace.QName;
import org.junit.Test;
import org.mockito.InjectMocks;
/**
* Unit test for HoldType
*
* @author Silviu Dinuta
* @since 2.6
*
*/
public class HoldTypeUnitTest extends BaseUnitTest
{
/** test object */
private @InjectMocks HoldType holdType;
/**
* Given that we try to add to hold folder,
* Then InvalidParameterException is thrown.
*/
@Test(expected = InvalidParameterException.class)
public void testAddToHoldFolderTest()
{
NodeRef holdFolder = generateNodeRef(TYPE_HOLD, true);
QName type = AlfMock.generateQName();
NodeRef nodeRef = AlfMock.generateNodeRef(mockedNodeService, type);
ChildAssociationRef mockedChildAssoc = mock(ChildAssociationRef.class);
when(mockedChildAssoc.getChildRef()).thenReturn(nodeRef);
when(mockedChildAssoc.getParentRef()).thenReturn(holdFolder);
holdType.onCreateChildAssociation(mockedChildAssoc, true);
}
}

View File

@@ -755,22 +755,6 @@ public class RMNodesImplUnitTest extends BaseUnitTest
rmNodesImpl.checkPostPermission(parentNodeRef.getId());
}
@Test
public void testCheckPostPermissionForHoldFolder() throws Exception
{
NodeRef parentNodeRef = AlfMock.generateNodeRef(mockedNodeService);
when(mockedNodeService.getType(parentNodeRef)).thenReturn(RecordsManagementModel.TYPE_HOLD);
try
{
rmNodesImpl.checkPostPermission(parentNodeRef.getId());
fail("Expected ecxeption as post should not be permitted on the Hold Folder");
}
catch(PermissionDeniedException ex)
{
assertEquals("POST request not allowed in Hold Folder.", ex.getMsgId());
}
}
@Test
public void testCheckPostPermission() throws Exception
{

View File

@@ -122,29 +122,6 @@ public class FileplanComponentChildrenRelationUnitTest extends BaseUnitTest
verify(mockedRMNodes, never()).createNode(parentNodeRef.getId(), nodeInfos.get(0), mockedParameters);
}
@Test
public void testCreateOnHoldFolder() throws Exception
{
Parameters mockedParameters = mock(Parameters.class);
NodeRef parentNodeRef = AlfMock.generateNodeRef(mockedNodeService);
List<Node> nodeInfos = new ArrayList<Node>();
Node mokedNodeInfo = mock(Node.class);
nodeInfos.add(mokedNodeInfo);
Mockito.doThrow(new PermissionDeniedException("POST request not allowed in Hold Folder.")).when(mockedRMNodes).checkPostPermission(parentNodeRef.getId());
try
{
filePlanComponentChildrenRelation.create(parentNodeRef.getId(), nodeInfos, mockedParameters);
fail("Expected ecxeption as POST request is not allowed in Hold Folder.");
}
catch(PermissionDeniedException ex)
{
assertEquals("POST request not allowed in Hold Folder.", ex.getMsgId());
}
verify(mockedRMNodes, never()).createNode(parentNodeRef.getId(), nodeInfos.get(0), mockedParameters);
}
@Test
public void testUpload() throws Exception
{
@@ -176,25 +153,4 @@ public class FileplanComponentChildrenRelationUnitTest extends BaseUnitTest
}
verify(mockedRMNodes, never()).upload(parentNodeRef.getId(), mockedFormData, mockedParameters);
}
@Test
public void testUploadOnHoldFolder() throws Exception
{
Parameters mockedParameters = mock(Parameters.class);
NodeRef parentNodeRef = AlfMock.generateNodeRef(mockedNodeService);
FormData mockedFormData = mock(FormData.class);
WithResponse mockedWithResponse = mock(WithResponse.class);
Mockito.doThrow(new PermissionDeniedException("POST request not allowed in Hold Folder.")).when(mockedRMNodes).checkPostPermission(parentNodeRef.getId());
try
{
filePlanComponentChildrenRelation.create(parentNodeRef.getId(), mockedFormData, mockedParameters, mockedWithResponse);
fail("Expected ecxeption as POST request is not allowed in Hold Folder.");
}
catch(PermissionDeniedException ex)
{
assertEquals("POST request not allowed in Hold Folder.", ex.getMsgId());
}
verify(mockedRMNodes, never()).upload(parentNodeRef.getId(), mockedFormData, mockedParameters);
}
}