Merge branch 'feature/RM-4357_and_RM_4373' into 'master'

Feature/rm 4357 and rm 4373

Merge branch for RM-4357 and RM-4373. Original merge requests:
- RM-4357 : https://gitlab.alfresco.com/records-management/records-management/merge_requests/624
- RM-4373 : https://gitlab.alfresco.com/records-management/records-management/merge_requests/631

this merge contains conflict fixes and test fixes for both RM-4357 and RM-4373

See merge request !641
This commit is contained in:
Ana Bozianu
2016-11-18 12:18:03 +00:00
11 changed files with 189 additions and 158 deletions

View File

@@ -32,6 +32,7 @@ import static org.alfresco.rest.rm.community.base.AllowableOperations.CREATE;
import static org.alfresco.rest.rm.community.base.AllowableOperations.DELETE;
import static org.alfresco.rest.rm.community.base.AllowableOperations.UPDATE;
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentAlias.FILE_PLAN_ALIAS;
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentAlias.TRANSFERS_ALIAS;
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentFields.NAME;
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentFields.NODE_TYPE;
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentFields.PROPERTIES;
@@ -162,8 +163,16 @@ public class FilePlanTests extends BaseRestTest
FilePlanComponent filePlanComponent = filePlanComponentAPI.withParams("include=allowableOperations").getFilePlanComponent(specialContainerAlias);
// Check the list of allowableOperations returned
assertTrue(filePlanComponent.getAllowableOperations().containsAll(asList(UPDATE, CREATE)),
if(specialContainerAlias.equals(TRANSFERS_ALIAS.toString()))
{
assertTrue(filePlanComponent.getAllowableOperations().containsAll(asList(UPDATE)),
"Wrong list of the allowable operations is return" + filePlanComponent.getAllowableOperations().toString());
}
else
{
assertTrue(filePlanComponent.getAllowableOperations().containsAll(asList(UPDATE, CREATE)),
"Wrong list of the allowable operations is return" + filePlanComponent.getAllowableOperations().toString());
}
// Check the list of allowableOperations doesn't contains DELETE operation
assertFalse(filePlanComponent.getAllowableOperations().contains(DELETE),

View File

@@ -94,6 +94,23 @@
</property>
</bean>
<bean id="rmEditTransferCapability"
parent="declarativeCapability">
<property name="name" value="EditTransfer"/>
<property name="private" value="true"/>
<property name="kinds">
<list>
<value>TRANSFER_CONTAINER</value>
<value>TRANSFER</value>
</list>
</property>
<property name="conditions">
<map>
<entry key="capabilityCondition.filling" value="true"/>
</map>
</property>
</bean>
<bean id="rmDeleteTransferContainerCapability"
parent="declarativeCapability">
<property name="name" value="DeleteTransferContainer"/>

View File

@@ -4,7 +4,7 @@
<beans>
<!-- Public Capabilities -->
<bean id="rmCreateHoldCapability"
parent="declarativeCapability">
<property name="name" value="CreateHold"/>
@@ -30,6 +30,7 @@
<property name="permission" value="EditHold"/>
<property name="kinds">
<list>
<value>HOLD_CONTAINER</value>
<value>HOLD</value>
</list>
</property>

View File

@@ -46,6 +46,7 @@
<ref bean="rmEditRecordMetadataCapability"/>
<ref bean="rmModifyUnfiledRecordsContainerFolderCapability"/>
<ref bean="rmEditHoldCapability"/>
<ref bean="rmEditTransferCapability"/>
</list>
</property>
</bean>
@@ -64,6 +65,7 @@
<ref bean="rmEditRecordMetadataCapability"/>
<ref bean="rmModifyUnfiledRecordsContainerFolderCapability"/>
<ref bean="rmEditHoldCapability"/>
<ref bean="rmEditTransferCapability"/>
</list>
</property>
</bean>

View File

@@ -44,4 +44,5 @@ rm.action.multiple.children.type-error-message=Operation failed. Children of typ
rm.action.create.transfer.container.child-error-message=Operation failed. Creation is not allowed in Transfer Container.
rm.action.create.transfer.child-error-message=Operation failed. Creation is not allowed in Transfer Folders.
rm.action.create.record.folder.child-error-message=Only records can be created in record folders but it was {0}
rm.action.transfer-non-editable=The metadata of transfer nodes is not editable.

View File

@@ -27,6 +27,7 @@
<property name="quickShareLinks" ref="rm.QuickShareLinks"/>
<property name="filePlanService" ref="FilePlanService"/>
<property name="recordsManagementServiceRegistry" ref="RecordsManagementServiceRegistry"/>
<property name="capabilityService" ref="CapabilityService"/>
</bean>
<bean id="rm.Nodes" class="org.springframework.aop.framework.ProxyFactoryBean">

View File

@@ -129,7 +129,7 @@ public class FilePlanComponentAspect extends BaseBehaviourBean
)
public void onUpdateProperties(final NodeRef nodeRef, final Map<QName, Serializable> before, final Map<QName, Serializable> after)
{
AuthenticationUtil.runAs(new RunAsWork<Void>()
AuthenticationUtil.runAsSystem(new RunAsWork<Void>()
{
@Override
public Void doWork()
@@ -141,7 +141,7 @@ public class FilePlanComponentAspect extends BaseBehaviourBean
return null;
}
}, AuthenticationUtil.getAdminUserName());
});
}
/**

View File

@@ -27,6 +27,9 @@
package org.alfresco.module.org_alfresco_module_rm.model.rma.type;
import java.io.Serializable;
import java.util.Map;
import org.alfresco.module.org_alfresco_module_rm.model.BaseBehaviourBean;
import org.alfresco.repo.node.NodeServicePolicies;
import org.alfresco.repo.node.integrity.IntegrityException;
@@ -34,6 +37,8 @@ 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;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.namespace.QName;
import org.springframework.extensions.surf.util.I18NUtil;
/**
@@ -43,10 +48,15 @@ import org.springframework.extensions.surf.util.I18NUtil;
* @since 2.6
*/
@BehaviourBean(defaultType = "rma:transfer")
public class TransferType extends BaseBehaviourBean implements NodeServicePolicies.OnCreateChildAssociationPolicy
public class TransferType extends BaseBehaviourBean
implements NodeServicePolicies.OnCreateChildAssociationPolicy,
NodeServicePolicies.OnUpdatePropertiesPolicy
{
private final static String MSG_ERROR_ADD_CHILD_TO_TRANSFER = "rm.action.create.transfer.child-error-message";
private static final String BEHAVIOUR_NAME = "onCreateChildAssocsForTransferType";
private final static String MSG_ERROR_EDIT_TRANSFER_PROPERTIES = "rm.action.transfer-non-editable";
private static final String CREATE_CHILD_BEHAVIOUR_NAME = "onCreateChildAssocsForTransferType";
private static final String EDIT_PROPERTIES_BEHAVIOUR_NAME = "onEditTransferProperties";
/**
* Disable the behaviours for this transaction
@@ -54,7 +64,8 @@ public class TransferType extends BaseBehaviourBean implements NodeServicePolici
*/
public void disable()
{
getBehaviour(BEHAVIOUR_NAME).disable();
getBehaviour(CREATE_CHILD_BEHAVIOUR_NAME).disable();
getBehaviour(EDIT_PROPERTIES_BEHAVIOUR_NAME).disable();
}
/**
@@ -63,7 +74,8 @@ public class TransferType extends BaseBehaviourBean implements NodeServicePolici
*/
public void enable()
{
getBehaviour(BEHAVIOUR_NAME).enable();
getBehaviour(CREATE_CHILD_BEHAVIOUR_NAME).enable();
getBehaviour(EDIT_PROPERTIES_BEHAVIOUR_NAME).enable();
}
/**
@@ -73,10 +85,24 @@ public class TransferType extends BaseBehaviourBean implements NodeServicePolici
@Behaviour
(
kind = BehaviourKind.ASSOCIATION,
name = BEHAVIOUR_NAME
name = CREATE_CHILD_BEHAVIOUR_NAME
)
public void onCreateChildAssociation(ChildAssociationRef childAssocRef, boolean isNewNode)
{
throw new IntegrityException(I18NUtil.getMessage(MSG_ERROR_ADD_CHILD_TO_TRANSFER), null);
}
@Override
@Behaviour
(
kind = BehaviourKind.CLASS,
name = EDIT_PROPERTIES_BEHAVIOUR_NAME
)
public void onUpdateProperties(NodeRef nodeRef, Map<QName, Serializable> before, Map<QName, Serializable> after)
{
if(!authenticationUtil.isRunAsUserTheSystemUser())
{
throw new IntegrityException(I18NUtil.getMessage(MSG_ERROR_EDIT_TRANSFER_PROPERTIES), null);
}
}
}

View File

@@ -182,6 +182,7 @@ public class TransferServiceImpl extends ServiceBaseImpl
NodeRef transferContainer = filePlanService.getTransferContainer(root);
transferContainerType.disable();
transferType.disable();
try
{
transferNodeRef = nodeService.createNode(transferContainer,
@@ -194,6 +195,7 @@ public class TransferServiceImpl extends ServiceBaseImpl
finally
{
transferContainerType.enable();
transferType.enable();
}
// Bind the hold node reference to the transaction
AlfrescoTransactionSupport.bindResource(KEY_TRANSFER_NODEREF, transferNodeRef);

View File

@@ -33,17 +33,14 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import org.alfresco.model.ContentModel;
import org.alfresco.module.org_alfresco_module_rm.RecordsManagementServiceRegistry;
import org.alfresco.module.org_alfresco_module_rm.capability.CapabilityService;
import org.alfresco.module.org_alfresco_module_rm.disposition.DispositionSchedule;
import org.alfresco.module.org_alfresco_module_rm.disposition.DispositionService;
import org.alfresco.module.org_alfresco_module_rm.fileplan.FilePlanService;
import org.alfresco.module.org_alfresco_module_rm.model.RecordsManagementModel;
import org.alfresco.repo.model.Repository;
import org.alfresco.repo.site.SiteModel;
import org.alfresco.repo.tenant.TenantUtil;
import org.alfresco.rest.api.impl.NodesImpl;
import org.alfresco.rest.api.model.Node;
import org.alfresco.rest.api.model.UserInfo;
@@ -54,14 +51,14 @@ import org.alfresco.rm.rest.api.model.RecordCategoryNode;
import org.alfresco.rm.rest.api.model.RecordFolderNode;
import org.alfresco.rm.rest.api.model.RecordNode;
import org.alfresco.service.cmr.dictionary.DictionaryService;
import org.alfresco.service.cmr.repository.ChildAssociationRef;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.namespace.NamespaceService;
import org.alfresco.service.namespace.QName;
import org.alfresco.util.Pair;
import org.alfresco.util.ParameterCheck;
import net.sf.acegisecurity.vote.AccessDecisionVoter;
/**
* Centralizes access to the repository.
*
@@ -79,14 +76,10 @@ public class RMNodesImpl extends NodesImpl implements RMNodes
private FilePlanService filePlanService;
private NodeService nodeService;
private RecordsManagementServiceRegistry serviceRegistry;
private Repository repositoryHelper;
private DictionaryService dictionaryService;
private DispositionService dispositionService;
private CapabilityService capabilityService;
/**
* TODO to remove this after isSpecialNode is made protected in core implementation(REPO-1459)
*/
private ConcurrentHashMap<String,NodeRef> ddCache = new ConcurrentHashMap<>();
public void init()
{
super.init();
@@ -100,17 +93,16 @@ public class RMNodesImpl extends NodesImpl implements RMNodes
this.serviceRegistry = serviceRegistry;
}
public void setRepositoryHelper(Repository repositoryHelper)
{
super.setRepositoryHelper(repositoryHelper);
this.repositoryHelper = repositoryHelper;
}
public void setFilePlanService(FilePlanService filePlanService)
{
this.filePlanService = filePlanService;
}
public void setCapabilityService(CapabilityService capabilityService)
{
this.capabilityService = capabilityService;
}
@Override
public Node getFolderOrDocument(final NodeRef nodeRef, NodeRef parentNodeRef, QName nodeTypeQName, List<String> includeParam, Map<String, UserInfo> mapUserInfo)
{
@@ -121,26 +113,6 @@ public class RMNodesImpl extends NodesImpl implements RMNodes
nodeTypeQName = nodeService.getType(nodeRef);
}
//TODO to remove this part of code after isSpecialNode will be made protected on core, will not need this anymore since the right allowed operations will be returned from core(REPO-1459).
if (includeParam.contains(PARAM_INCLUDE_ALLOWABLEOPERATIONS) && originalNode.getAllowableOperations() != null)
{
List<String> allowableOperations = originalNode.getAllowableOperations();
List<String> modifiedAllowableOperations = new ArrayList<>();
modifiedAllowableOperations.addAll(allowableOperations);
for (String op : allowableOperations)
{
if (op.equals(OP_DELETE) && (isSpecialNode(nodeRef, nodeTypeQName)))
{
// special case: do not return "delete" (as an allowable op) for specific system nodes
modifiedAllowableOperations.remove(op);
}
}
originalNode.setAllowableOperations((modifiedAllowableOperations.size() > 0 )? modifiedAllowableOperations : null);
}
RMNodeType type = getType(nodeTypeQName, nodeRef);
FileplanComponentNode node = null;
if (mapUserInfo == null)
@@ -191,9 +163,57 @@ public class RMNodesImpl extends NodesImpl implements RMNodes
}
}
if (includeParam.contains(PARAM_INCLUDE_ALLOWABLEOPERATIONS))
{
// If the user does not have any of the mapped permissions then "allowableOperations" is not returned (rather than an empty array)
List<String> allowableOperations = getAllowableOperations(nodeRef, type);
node.setAllowableOperations((allowableOperations.size() > 0 )? allowableOperations : null);
}
return node;
}
/**
* Helper method that generates allowable operation for the provided node
* @param nodeRef the node to get the allowable operations for
* @param type the type of the provided nodeRef
* @return a sublist of [{@link Nodes.OP_DELETE}, {@link Nodes.OP_CREATE}, {@link Nodes.OP_UPDATE}] representing the allowable operations for the provided node
*/
private List<String> getAllowableOperations(NodeRef nodeRef, RMNodeType type)
{
List<String> allowableOperations = new ArrayList<>();
NodeRef filePlan = filePlanService.getFilePlanBySiteId(FilePlanService.DEFAULT_RM_SITE_ID);
boolean isFilePlan = nodeRef.equals(filePlan);
boolean isTransferContainer = nodeRef.equals(filePlanService.getTransferContainer(filePlan));
boolean isUnfiledContainer = nodeRef.equals(filePlanService.getUnfiledContainer(filePlan));
boolean isHoldsContainer = nodeRef.equals(filePlanService.getHoldContainer(filePlan)) ;
boolean isSpecialContainer = isFilePlan || isTransferContainer || isUnfiledContainer || isHoldsContainer;
// DELETE
if(!isSpecialContainer &&
capabilityService.getCapability("Delete").evaluate(nodeRef) == AccessDecisionVoter.ACCESS_GRANTED)
{
allowableOperations.add(OP_DELETE);
}
// CREATE
if(type != RMNodeType.FILE &&
!isTransferContainer &&
capabilityService.getCapability("FillingPermissionOnly").evaluate(nodeRef) == AccessDecisionVoter.ACCESS_GRANTED)
{
allowableOperations.add(OP_CREATE);
}
// UPDATE
if (capabilityService.getCapability("Update").evaluate(nodeRef) == AccessDecisionVoter.ACCESS_GRANTED)
{
allowableOperations.add(OP_UPDATE);
}
return allowableOperations;
}
@Override
public NodeRef validateNode(String nodeId)
{
@@ -297,85 +317,4 @@ public class RMNodesImpl extends NodesImpl implements RMNodes
return new Pair<>(searchTypeQNames, ignoreAspectQNames);
}
/**
* TODO only override core method when will be made protected in core(REPO-1459).
*
* @param nodeRef
* @param type
* @return
*/
private boolean isSpecialNode(NodeRef nodeRef, QName type)
{
// Check for File Plan, Transfers Container, Holds Container, Unfiled Records Container
NodeRef filePlan = filePlanService.getFilePlanBySiteId(FilePlanService.DEFAULT_RM_SITE_ID);
if(filePlan != null)
{
if(filePlan.equals(nodeRef))
{
return true;
}
else if(filePlanService.getTransferContainer(filePlan).equals(nodeRef))
{
return true;
}
else if(filePlanService.getHoldContainer(filePlan).equals(nodeRef))
{
return true;
}
else if(filePlanService.getUnfiledContainer(filePlan).equals(nodeRef))
{
return true;
}
}
//TODO just run super after method after it will be made protected on core(REPO-1459)
return isCoreSpecialNode(nodeRef, type);
}
/**
* Copied from core implementation, because it is protected and we can't extend it with our special nodes.
*
* TODO to remove when isSpecialNode method will be made protected in core (REPO-1459).
*
* @param nodeRef
* @param type
* @return
*/
private boolean isCoreSpecialNode(NodeRef nodeRef, QName type)
{
// Check for Company Home, Sites and Data Dictionary (note: must be tenant-aware)
if (nodeRef.equals(repositoryHelper.getCompanyHome()))
{
return true;
}
else if (type.equals(SiteModel.TYPE_SITES) || type.equals(SiteModel.TYPE_SITE))
{
// note: alternatively, we could inject SiteServiceInternal and use getSitesRoot (or indirectly via node locator)
return true;
}
else
{
String tenantDomain = TenantUtil.getCurrentDomain();
NodeRef ddNodeRef = ddCache.get(tenantDomain);
if (ddNodeRef == null)
{
List<ChildAssociationRef> ddAssocs = nodeService.getChildAssocs(
repositoryHelper.getCompanyHome(),
ContentModel.ASSOC_CONTAINS,
QName.createQName(NamespaceService.APP_MODEL_1_0_URI, "dictionary"));
if (ddAssocs.size() == 1)
{
ddNodeRef = ddAssocs.get(0).getChildRef();
ddCache.put(tenantDomain, ddNodeRef);
}
}
if (nodeRef.equals(ddNodeRef))
{
return true;
}
}
return false;
}
}

View File

@@ -28,7 +28,6 @@
package org.alfresco.rm.rest.api.impl;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
@@ -42,6 +41,8 @@ import java.util.ArrayList;
import java.util.List;
import org.alfresco.model.ContentModel;
import org.alfresco.module.org_alfresco_module_rm.capability.Capability;
import org.alfresco.module.org_alfresco_module_rm.capability.CapabilityService;
import org.alfresco.module.org_alfresco_module_rm.disposition.DispositionSchedule;
import org.alfresco.module.org_alfresco_module_rm.model.RecordsManagementModel;
import org.alfresco.module.org_alfresco_module_rm.test.util.AlfMock;
@@ -69,6 +70,8 @@ import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import net.sf.acegisecurity.vote.AccessDecisionVoter;
/**
* Unit Test class for RMNodesImpl.
*
@@ -98,10 +101,17 @@ public class RMNodesImplUnitTest extends BaseUnitTest
@Mock
private ServiceRegistry mockedServiceRegistry;
@Mock
private CapabilityService mockedCapabilityService;
@InjectMocks
private RMNodesImpl rmNodesImpl;
private Capability deleteCapability;
private Capability createCapability;
private Capability updateCapability;
@Before
public void before()
{
@@ -112,6 +122,12 @@ public class RMNodesImplUnitTest extends BaseUnitTest
when(mockedNamespaceService.getPrefixes(any(String.class))).thenReturn(prefixes);
when(mockedNamespaceService.getNamespaceURI(any(String.class))).thenReturn(RM_URI);
deleteCapability = mock(Capability.class);
when(mockedCapabilityService.getCapability("Delete")).thenReturn(deleteCapability);
createCapability = mock(Capability.class);
when(mockedCapabilityService.getCapability("FillingPermissionOnly")).thenReturn(createCapability);
updateCapability = mock(Capability.class);
when(mockedCapabilityService.getCapability("Update")).thenReturn(updateCapability);
}
@Test
@@ -155,19 +171,13 @@ public class RMNodesImplUnitTest extends BaseUnitTest
setPermissions(nodeRef, AccessStatus.ALLOWED);
when(deleteCapability.evaluate(nodeRef)).thenReturn(AccessDecisionVoter.ACCESS_GRANTED);
when(createCapability.evaluate(nodeRef)).thenReturn(AccessDecisionVoter.ACCESS_GRANTED);
when(updateCapability.evaluate(nodeRef)).thenReturn(AccessDecisionVoter.ACCESS_GRANTED);
when(mockedFilePlanService.getFilePlanBySiteId(RM_SITE_ID)).thenReturn(nodeRef);
Node folderOrDocument = rmNodesImpl.getFolderOrDocument(nodeRef, null, null, includeParamList, null);
assertNotNull(folderOrDocument);
assertTrue(FileplanComponentNode.class.isInstance(folderOrDocument));
FileplanComponentNode resultNode = (FileplanComponentNode) folderOrDocument;
assertEquals(false, resultNode.getIsRecordFolder());
assertEquals(false, resultNode.getIsFile());
assertEquals(false, resultNode.getIsCategory());
List<String> allowableOperations = resultNode.getAllowableOperations();
assertTrue("Create operation should be available for FilePlan.", allowableOperations.contains(RMNodes.OP_CREATE));
assertTrue("Update operation should be available for FilePlan.", allowableOperations.contains(RMNodes.OP_UPDATE));
assertFalse("Delete operation should note be available for FilePlan.", allowableOperations.contains(RMNodes.OP_DELETE));
checksAllowedOperations(folderOrDocument, true, true, false);
}
@Test
@@ -205,8 +215,8 @@ public class RMNodesImplUnitTest extends BaseUnitTest
public void testGetTransferContainerAllowableOperations() throws Exception
{
NodeRef nodeRef = AlfMock.generateNodeRef(mockedNodeService);
when(mockedNodeService.getType(nodeRef)).thenReturn(RecordsManagementModel.TYPE_RECORD_CATEGORY);
when(mockedDictionaryService.isSubClass(RecordsManagementModel.TYPE_RECORD_CATEGORY, ContentModel.TYPE_FOLDER)).thenReturn(true);
when(mockedNodeService.getType(nodeRef)).thenReturn(RecordsManagementModel.TYPE_TRANSFER_CONTAINER);
when(mockedDictionaryService.isSubClass(RecordsManagementModel.TYPE_TRANSFER_CONTAINER, ContentModel.TYPE_FOLDER)).thenReturn(true);
setupCompanyHomeAndPrimaryParent(nodeRef);
@@ -219,16 +229,22 @@ public class RMNodesImplUnitTest extends BaseUnitTest
when(mockedFilePlanService.getFilePlanBySiteId(RM_SITE_ID)).thenReturn(filePlanNodeRef);
when(mockedFilePlanService.getTransferContainer(filePlanNodeRef)).thenReturn(nodeRef);
when(deleteCapability.evaluate(nodeRef)).thenReturn(AccessDecisionVoter.ACCESS_GRANTED);
when(createCapability.evaluate(nodeRef)).thenReturn(AccessDecisionVoter.ACCESS_GRANTED);
when(updateCapability.evaluate(nodeRef)).thenReturn(AccessDecisionVoter.ACCESS_GRANTED);
when(mockedFilePlanService.isFilePlanComponent(nodeRef)).thenReturn(true);
Node folderOrDocument = rmNodesImpl.getFolderOrDocument(nodeRef, null, null, includeParamList, null);
checkSpecialContainersAllowedOperations(folderOrDocument);
checksAllowedOperations(folderOrDocument, false, true, false);
}
@Test
public void testGetHoldContainerAllowableOperations() throws Exception
{
NodeRef nodeRef = AlfMock.generateNodeRef(mockedNodeService);
when(mockedNodeService.getType(nodeRef)).thenReturn(RecordsManagementModel.TYPE_RECORD_CATEGORY);
when(mockedDictionaryService.isSubClass(RecordsManagementModel.TYPE_RECORD_CATEGORY, ContentModel.TYPE_FOLDER)).thenReturn(true);
when(mockedNodeService.getType(nodeRef)).thenReturn(RecordsManagementModel.TYPE_HOLD_CONTAINER);
when(mockedDictionaryService.isSubClass(RecordsManagementModel.TYPE_HOLD_CONTAINER, ContentModel.TYPE_FOLDER)).thenReturn(true);
setupCompanyHomeAndPrimaryParent(nodeRef);
@@ -245,16 +261,22 @@ public class RMNodesImplUnitTest extends BaseUnitTest
when(mockedFilePlanService.getHoldContainer(filePlanNodeRef)).thenReturn(nodeRef);
when(deleteCapability.evaluate(nodeRef)).thenReturn(AccessDecisionVoter.ACCESS_GRANTED);
when(createCapability.evaluate(nodeRef)).thenReturn(AccessDecisionVoter.ACCESS_GRANTED);
when(updateCapability.evaluate(nodeRef)).thenReturn(AccessDecisionVoter.ACCESS_GRANTED);
when(mockedFilePlanService.isFilePlanComponent(nodeRef)).thenReturn(true);
Node folderOrDocument = rmNodesImpl.getFolderOrDocument(nodeRef, null, null, includeParamList, null);
checkSpecialContainersAllowedOperations(folderOrDocument);
checksAllowedOperations(folderOrDocument, true, true, false);
}
@Test
public void testGetUnfiledContainerAllowableOperations() throws Exception
{
NodeRef nodeRef = AlfMock.generateNodeRef(mockedNodeService);
when(mockedNodeService.getType(nodeRef)).thenReturn(RecordsManagementModel.TYPE_RECORD_CATEGORY);
when(mockedDictionaryService.isSubClass(RecordsManagementModel.TYPE_RECORD_CATEGORY, ContentModel.TYPE_FOLDER)).thenReturn(true);
when(mockedNodeService.getType(nodeRef)).thenReturn(RecordsManagementModel.TYPE_UNFILED_RECORD_CONTAINER);
when(mockedDictionaryService.isSubClass(RecordsManagementModel.TYPE_UNFILED_RECORD_CONTAINER, ContentModel.TYPE_FOLDER)).thenReturn(true);
setupCompanyHomeAndPrimaryParent(nodeRef);
@@ -274,8 +296,14 @@ public class RMNodesImplUnitTest extends BaseUnitTest
when(mockedFilePlanService.getUnfiledContainer(filePlanNodeRef)).thenReturn(nodeRef);
when(deleteCapability.evaluate(nodeRef)).thenReturn(AccessDecisionVoter.ACCESS_GRANTED);
when(createCapability.evaluate(nodeRef)).thenReturn(AccessDecisionVoter.ACCESS_GRANTED);
when(updateCapability.evaluate(nodeRef)).thenReturn(AccessDecisionVoter.ACCESS_GRANTED);
when(mockedFilePlanService.isFilePlanComponent(nodeRef)).thenReturn(true);
Node folderOrDocument = rmNodesImpl.getFolderOrDocument(nodeRef, null, null, includeParamList, null);
checkSpecialContainersAllowedOperations(folderOrDocument);
checksAllowedOperations(folderOrDocument, true, true, false);
}
@Test
@@ -621,18 +649,23 @@ public class RMNodesImplUnitTest extends BaseUnitTest
when(mockedPermissionService.hasPermission(nodeRef, PermissionService.ADD_CHILDREN)).thenReturn(permissionToSet);
}
private void checkSpecialContainersAllowedOperations(Node containerNode)
private void checksAllowedOperations(Node containerNode, boolean allowCreate, boolean allowUpdate, boolean allowDelete)
{
assertNotNull(containerNode);
assertTrue(RecordCategoryNode.class.isInstance(containerNode));
RecordCategoryNode resultNode = (RecordCategoryNode) containerNode;
assertEquals(false, resultNode.getIsRecordFolder());
assertEquals(false, resultNode.getIsFile());
assertEquals(true, resultNode.getIsCategory());
assertTrue(FileplanComponentNode.class.isInstance(containerNode));
FileplanComponentNode resultNode = (FileplanComponentNode) containerNode;
List<String> allowableOperations = resultNode.getAllowableOperations();
assertTrue("Create operation should be available for provided container.", allowableOperations.contains(RMNodes.OP_CREATE));
assertTrue("Update operation should be available for provided container.", allowableOperations.contains(RMNodes.OP_UPDATE));
assertFalse("Delete operation should note be available for provided container.", allowableOperations.contains(RMNodes.OP_DELETE));
assertEquals("Create operation should " + (allowCreate?"":"not ") + "be available for provided container.",
allowCreate,
allowableOperations.contains(RMNodes.OP_CREATE));
assertEquals("Update operation should " + (allowCreate?"":"not ") + "be available for provided container.",
allowUpdate,
allowableOperations.contains(RMNodes.OP_UPDATE));
assertEquals("Delete operation should " + (allowCreate?"":"not ") + "be available for provided container.",
allowDelete,
allowableOperations.contains(RMNodes.OP_DELETE));
}
}