RM-4312: changed implementation after review

This commit is contained in:
Silviu Dinuta
2016-11-04 18:05:05 +02:00
parent ab59884d72
commit a4feae7485
9 changed files with 173 additions and 140 deletions

View File

@@ -117,4 +117,41 @@ public abstract class BaseBehaviourBean extends ServiceBaseImpl
throw new InvalidParameterException("Operation failed. Children of type " + childType + " are not allowed");
}
}
/**
* Helper method that checks if the newly created child association is between the sub-types of accepted types.
* @param parent the parent node
* @param childType the child node
* @param acceptedMultipleChildType a list of node types that are accepted as children of the provided parent multiple times
* @throws InvalidParameterException if the child association isn't between the sub-types of accepted types
*/
protected void validateNewChildAssociationSubTypesIncluded(NodeRef parent, NodeRef child, List<QName> acceptedMultipleChildType) throws InvalidParameterException
{
QName childType = getInternalNodeService().getType(child);
if(!validateNodeRef(acceptedMultipleChildType, child))
{
throw new InvalidParameterException("Operation failed. Children of type " + childType + " are not allowed");
}
}
/**
* Checks if the type of the provided nodeRef it is between the sub-types of accepted types
*
* @param acceptedMultipleChildType
* @param nodeRef
* @return true if the type of the nodeRef is between the sub-types of accepted types, or false otherwise
*/
protected boolean validateNodeRef(List<QName> acceptedMultipleChildType, NodeRef nodeRef)
{
boolean result = false;
for(QName type : acceptedMultipleChildType)
{
if(instanceOf(nodeRef, type))
{
result = true;
break;
}
}
return result;
}
}

View File

@@ -27,7 +27,6 @@
package org.alfresco.module.org_alfresco_module_rm.model.rma.type;
import java.security.InvalidParameterException;
import java.util.Arrays;
import java.util.List;
@@ -49,8 +48,6 @@ import org.alfresco.service.cmr.repository.ChildAssociationRef;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.namespace.QName;
import com.google.common.collect.Sets;
/**
* rma:filePlan behaviour bean
*

View File

@@ -26,6 +26,9 @@
*/
package org.alfresco.module.org_alfresco_module_rm.model.rma.type;
import java.util.Arrays;
import java.util.List;
import org.alfresco.error.AlfrescoRuntimeException;
import org.alfresco.model.ContentModel;
import org.alfresco.module.org_alfresco_module_rm.model.BaseBehaviourBean;
@@ -35,6 +38,7 @@ 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;
/**
@@ -48,6 +52,7 @@ public class HoldContainerType extends BaseBehaviourBean
implements NodeServicePolicies.OnCreateChildAssociationPolicy, NodeServicePolicies.OnCreateNodePolicy
{
private final static String MSG_ERROR_ADD_CONTENT_CONTAINER = "rm.service.error-add-content-container";
private static List<QName> ACCEPTED_NON_UNIQUE_CHILD_TYPES = Arrays.asList(TYPE_HOLD);
/**
* On every event
@@ -59,17 +64,8 @@ public class HoldContainerType extends BaseBehaviourBean
@Behaviour(kind = BehaviourKind.ASSOCIATION)
public void onCreateChildAssociation(ChildAssociationRef childAssocRef, boolean bNew)
{
NodeRef nodeRef = childAssocRef.getChildRef();
if (instanceOf(nodeRef, ContentModel.TYPE_CONTENT) == true) { throw new AlfrescoRuntimeException(
I18NUtil.getMessage(MSG_ERROR_ADD_CONTENT_CONTAINER)); }
// ensure we are not trying to put a record folder in the hold container
NodeRef parent = childAssocRef.getParentRef();
if (isHoldContainer(parent) && isRecordFolder(nodeRef))
{
throw new AlfrescoRuntimeException("Operation failed, because you can not place a record folder in the hold container.");
}
// check the created child is of an accepted type
validateNewChildAssociationSubTypesIncluded(childAssocRef.getParentRef(), childAssocRef.getChildRef(), ACCEPTED_NON_UNIQUE_CHILD_TYPES);
}
@Override

View File

@@ -26,6 +26,9 @@
*/
package org.alfresco.module.org_alfresco_module_rm.model.rma.type;
import java.util.Arrays;
import java.util.List;
import org.alfresco.error.AlfrescoRuntimeException;
import org.alfresco.model.ContentModel;
import org.alfresco.module.org_alfresco_module_rm.model.BaseBehaviourBean;
@@ -35,6 +38,7 @@ 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;
/**
@@ -48,6 +52,7 @@ public class TransferContainerType extends BaseBehaviourBean
implements NodeServicePolicies.OnCreateChildAssociationPolicy, NodeServicePolicies.OnCreateNodePolicy
{
private final static String MSG_ERROR_ADD_CONTENT_CONTAINER = "rm.service.error-add-content-container";
private static List<QName> ACCEPTED_NON_UNIQUE_CHILD_TYPES = Arrays.asList(TYPE_TRANSFER);
/**
* On every event
@@ -59,17 +64,8 @@ public class TransferContainerType extends BaseBehaviourBean
@Behaviour(kind = BehaviourKind.ASSOCIATION)
public void onCreateChildAssociation(ChildAssociationRef childAssocRef, boolean bNew)
{
// ensure not content to be added in transfer container
NodeRef nodeRef = childAssocRef.getChildRef();
if (instanceOf(nodeRef, ContentModel.TYPE_CONTENT) == true) { throw new AlfrescoRuntimeException(
I18NUtil.getMessage(MSG_ERROR_ADD_CONTENT_CONTAINER)); }
// ensure we are not trying to put a record folder in the transfer container
NodeRef parent = childAssocRef.getParentRef();
if (isTransferContainer(parent) && isRecordFolder(nodeRef))
{
throw new AlfrescoRuntimeException("Operation failed, because you can not place a record folder in the transfer container.");
}
// check the created child is of an accepted type
validateNewChildAssociationSubTypesIncluded(childAssocRef.getParentRef(), childAssocRef.getChildRef(), ACCEPTED_NON_UNIQUE_CHILD_TYPES);
}
@Override

View File

@@ -27,14 +27,17 @@
package org.alfresco.module.org_alfresco_module_rm.model.rma.type;
import org.alfresco.error.AlfrescoRuntimeException;
import java.util.Arrays;
import java.util.List;
import org.alfresco.model.ContentModel;
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;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.namespace.QName;
/**
* rma:unfiledRecordContainer behaviour bean
@@ -46,16 +49,12 @@ import org.alfresco.service.cmr.repository.NodeRef;
public class UnfiledRecordContainerType extends BaseBehaviourBean
implements NodeServicePolicies.OnCreateChildAssociationPolicy
{
private static List<QName> ACCEPTED_NON_UNIQUE_CHILD_TYPES = Arrays.asList(TYPE_UNFILED_RECORD_FOLDER, ContentModel.TYPE_CONTENT, TYPE_NON_ELECTRONIC_DOCUMENT);
@Override
@Behaviour(kind = BehaviourKind.ASSOCIATION)
public void onCreateChildAssociation(ChildAssociationRef childAssocRef, boolean isNewNode)
{
// ensure we are not trying to put a record folder in the unfiled records container
NodeRef nodeRef = childAssocRef.getChildRef();
NodeRef parent = childAssocRef.getParentRef();
if (isUnfiledRecordsContainer(parent) && isRecordFolder(nodeRef))
{
throw new AlfrescoRuntimeException("Operation failed, because you can not place a record folder in the unfiled records container.");
}
// check the created child is of an accepted type
validateNewChildAssociationSubTypesIncluded(childAssocRef.getParentRef(), childAssocRef.getChildRef(), ACCEPTED_NON_UNIQUE_CHILD_TYPES);
}
}

View File

@@ -383,32 +383,6 @@ public class ServiceBaseImpl implements RecordsManagementModel, ApplicationConte
return instanceOf(nodeRef, TYPE_UNFILED_RECORD_CONTAINER);
}
/**
* Indicates whether the given node reference is a transfers container or not.
*
* @param nodeRef node reference
* @return boolean true if rma:transferContainer or sub-type, false otherwise
*/
public boolean isTransferContainer(NodeRef nodeRef)
{
ParameterCheck.mandatory("nodeRef", nodeRef);
return instanceOf(nodeRef, TYPE_TRANSFER_CONTAINER);
}
/**
* Indicates whether the given node reference is a hold container or not.
*
* @param nodeRef node reference
* @return boolean true if rma:holdContainer or sub-type, false otherwise
*/
public boolean isHoldContainer(NodeRef nodeRef)
{
ParameterCheck.mandatory("nodeRef", nodeRef);
return instanceOf(nodeRef, TYPE_HOLD_CONTAINER);
}
/**
* Indicates whether a record is complete or not.
*

View File

@@ -29,11 +29,13 @@ package org.alfresco.module.org_alfresco_module_rm.model.rma.type;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import org.alfresco.error.AlfrescoRuntimeException;
import org.alfresco.model.ContentModel;
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;
@@ -48,47 +50,31 @@ public class HoldContainerTypeUnitTest extends BaseUnitTest
/** test object */
private @InjectMocks HoldContainerType holdContainerType;
/**
* Having the Unfilled Record container and a folder having the aspect ASPECT_HIDDEN When adding a child association
* between the folder and the container Then the folder type shouldn't be renamed
*/
@Test (expected = AlfrescoRuntimeException.class)
public void testAddContentToHoldContainer()
@Test (expected = InvalidParameterException.class)
public void testAddNonHoldTypeToHoldContainer()
{
QName type = AlfMock.generateQName();
when(mockedDictionaryService.isSubClass(type, TYPE_HOLD)).thenReturn(false);
NodeRef nodeRef= AlfMock.generateNodeRef(mockedNodeService, type);
NodeRef holdContainer = createHoldContainer();
/*
* When adding a child association between the folder and the container
*/
NodeRef record = generateNodeRef(ContentModel.TYPE_CONTENT);
ChildAssociationRef childAssoc = new ChildAssociationRef( ContentModel.TYPE_CONTENT, holdContainer,
ContentModel.TYPE_CONTENT, record);
holdContainerType.onCreateChildAssociation(childAssoc, true);
}
@Test(expected = AlfrescoRuntimeException.class)
public void testAddRecordFolderToHoldContainer()
{
NodeRef recordFolder = generateNodeRef(TYPE_RECORD_FOLDER, true);
NodeRef holdContainer = createHoldContainer();
NodeRef holdContainer = generateNodeRef(TYPE_HOLD_CONTAINER, true);
ChildAssociationRef mockedChildAssoc = mock(ChildAssociationRef.class);
when(mockedChildAssoc.getChildRef()).thenReturn(recordFolder);
when(mockedChildAssoc.getChildRef()).thenReturn(nodeRef);
when(mockedChildAssoc.getParentRef()).thenReturn(holdContainer);
holdContainerType.onCreateChildAssociation(mockedChildAssoc, true);
}
/**
* Generates a record management container
*
* @return reference to the generated container
*/
private NodeRef createHoldContainer()
@Test
public void testAddHoldTypeToHoldContainer()
{
QName type = AlfMock.generateQName();
when(mockedDictionaryService.isSubClass(type, TYPE_HOLD)).thenReturn(true);
NodeRef holdFolder= AlfMock.generateNodeRef(mockedNodeService, type);
NodeRef holdContainer = generateNodeRef(TYPE_HOLD_CONTAINER, true);
return holdContainer;
ChildAssociationRef mockedChildAssoc = mock(ChildAssociationRef.class);
when(mockedChildAssoc.getChildRef()).thenReturn(holdFolder);
when(mockedChildAssoc.getParentRef()).thenReturn(holdContainer);
holdContainerType.onCreateChildAssociation(mockedChildAssoc, true);
}
}

View File

@@ -29,16 +29,18 @@ package org.alfresco.module.org_alfresco_module_rm.model.rma.type;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import org.alfresco.error.AlfrescoRuntimeException;
import org.alfresco.model.ContentModel;
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 TransferContainerTypeTest
* Unit test for TransferContainerType
*
* @author Mihai Cozma
* @since 2.4
@@ -48,47 +50,32 @@ public class TransferContainerTypeUnitTest extends BaseUnitTest
/** test object */
private @InjectMocks TransferContainerType transferContainerType;
/**
* Having the Unfilled Record container and a folder having the aspect ASPECT_HIDDEN When adding a child association
* between the folder and the container Then the folder type shouldn't be renamed
*/
@Test(expected = AlfrescoRuntimeException.class)
public void testAddContentToTransferContainerTest()
@Test(expected = InvalidParameterException.class)
public void testAddNonTransferTypeToTransferContainerTest()
{
NodeRef transferContainer = generateNodeRef(TYPE_TRANSFER_CONTAINER, true);
NodeRef transferContainer = createTransferContainer();
QName type = AlfMock.generateQName();
when(mockedDictionaryService.isSubClass(type, TYPE_TRANSFER)).thenReturn(false);
NodeRef nodeRef = AlfMock.generateNodeRef(mockedNodeService, type);
/*
* When adding a child association between the folder and the container
*/
NodeRef record = generateNodeRef(ContentModel.TYPE_CONTENT);
ChildAssociationRef childAssoc = new ChildAssociationRef(ContentModel.TYPE_CONTENT, transferContainer,
ContentModel.TYPE_CONTENT, record);
transferContainerType.onCreateChildAssociation(childAssoc, true);
}
@Test(expected = AlfrescoRuntimeException.class)
public void testAddRecordFolderToTransferContainer()
{
NodeRef recordFolder = generateNodeRef(TYPE_RECORD_FOLDER, true);
NodeRef holdContainer = generateNodeRef(TYPE_TRANSFER_CONTAINER, true);
ChildAssociationRef mockedChildAssoc = mock(ChildAssociationRef.class);
when(mockedChildAssoc.getChildRef()).thenReturn(recordFolder);
when(mockedChildAssoc.getParentRef()).thenReturn(holdContainer);
when(mockedChildAssoc.getChildRef()).thenReturn(nodeRef);
when(mockedChildAssoc.getParentRef()).thenReturn(transferContainer);
transferContainerType.onCreateChildAssociation(mockedChildAssoc, true);
}
/**
* Generates a record management container
*
* @return reference to the generated container
*/
private NodeRef createTransferContainer()
@Test
public void testAddTransferFolderToTransferContainer()
{
NodeRef holdContainer = generateNodeRef(TYPE_TRANSFER, true);
QName type = AlfMock.generateQName();
when(mockedDictionaryService.isSubClass(type, TYPE_TRANSFER)).thenReturn(true);
NodeRef transferFolder= AlfMock.generateNodeRef(mockedNodeService, type);
return holdContainer;
NodeRef transferContainer = generateNodeRef(TYPE_TRANSFER_CONTAINER, true);
ChildAssociationRef mockedChildAssoc = mock(ChildAssociationRef.class);
when(mockedChildAssoc.getChildRef()).thenReturn(transferFolder);
when(mockedChildAssoc.getParentRef()).thenReturn(transferContainer);
transferContainerType.onCreateChildAssociation(mockedChildAssoc, true);
}
}

View File

@@ -30,10 +30,14 @@ package org.alfresco.module.org_alfresco_module_rm.model.rma.type;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import org.alfresco.error.AlfrescoRuntimeException;
import java.security.InvalidParameterException;
import org.alfresco.model.ContentModel;
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;
@@ -48,14 +52,71 @@ public class UnfiledRecordContainerTypeUnitTest extends BaseUnitTest
@InjectMocks
private UnfiledRecordContainerType unfiledRecordContainerType;
@Test(expected = AlfrescoRuntimeException.class)
public void testAddRecordFolderToTransferContainer()
@Test(expected = InvalidParameterException.class)
public void testAddNonAcceptedTypeToUnfiledRecordContainer()
{
NodeRef recordFolder = generateNodeRef(TYPE_RECORD_FOLDER, true);
NodeRef holdContainer = generateNodeRef(TYPE_UNFILED_RECORD_CONTAINER, true);
QName type = AlfMock.generateQName();
when(mockedDictionaryService.isSubClass(type, TYPE_UNFILED_RECORD_FOLDER)).thenReturn(false);
when(mockedDictionaryService.isSubClass(type, ContentModel.TYPE_CONTENT)).thenReturn(false);
when(mockedDictionaryService.isSubClass(type, TYPE_NON_ELECTRONIC_DOCUMENT)).thenReturn(false);
NodeRef nodeRef= AlfMock.generateNodeRef(mockedNodeService, type);
NodeRef unfiledRecordContainer = generateNodeRef(TYPE_UNFILED_RECORD_CONTAINER, true);
ChildAssociationRef mockedChildAssoc = mock(ChildAssociationRef.class);
when(mockedChildAssoc.getChildRef()).thenReturn(recordFolder);
when(mockedChildAssoc.getParentRef()).thenReturn(holdContainer);
when(mockedChildAssoc.getChildRef()).thenReturn(nodeRef);
when(mockedChildAssoc.getParentRef()).thenReturn(unfiledRecordContainer);
unfiledRecordContainerType.onCreateChildAssociation(mockedChildAssoc, true);
}
@Test
public void testAddUnfiledRecordFolderTypeToUnfiledRecordContainer()
{
QName type = AlfMock.generateQName();
when(mockedDictionaryService.isSubClass(type, TYPE_UNFILED_RECORD_FOLDER)).thenReturn(true);
when(mockedDictionaryService.isSubClass(type, ContentModel.TYPE_CONTENT)).thenReturn(false);
when(mockedDictionaryService.isSubClass(type, TYPE_NON_ELECTRONIC_DOCUMENT)).thenReturn(false);
NodeRef nodeRef= AlfMock.generateNodeRef(mockedNodeService, type);
NodeRef unfiledRecordContainer = generateNodeRef(TYPE_UNFILED_RECORD_CONTAINER, true);
ChildAssociationRef mockedChildAssoc = mock(ChildAssociationRef.class);
when(mockedChildAssoc.getChildRef()).thenReturn(nodeRef);
when(mockedChildAssoc.getParentRef()).thenReturn(unfiledRecordContainer);
unfiledRecordContainerType.onCreateChildAssociation(mockedChildAssoc, true);
}
@Test
public void testAddContentTypeToUnfiledRecordContainer()
{
QName type = AlfMock.generateQName();
when(mockedDictionaryService.isSubClass(type, TYPE_UNFILED_RECORD_FOLDER)).thenReturn(false);
when(mockedDictionaryService.isSubClass(type, ContentModel.TYPE_CONTENT)).thenReturn(true);
when(mockedDictionaryService.isSubClass(type, TYPE_NON_ELECTRONIC_DOCUMENT)).thenReturn(false);
NodeRef nodeRef= AlfMock.generateNodeRef(mockedNodeService, type);
NodeRef unfiledRecordContainer = generateNodeRef(TYPE_UNFILED_RECORD_CONTAINER, true);
ChildAssociationRef mockedChildAssoc = mock(ChildAssociationRef.class);
when(mockedChildAssoc.getChildRef()).thenReturn(nodeRef);
when(mockedChildAssoc.getParentRef()).thenReturn(unfiledRecordContainer);
unfiledRecordContainerType.onCreateChildAssociation(mockedChildAssoc, true);
}
@Test
public void testNonElectronicDocumentTypeToUnfiledRecordContainer()
{
QName type = AlfMock.generateQName();
when(mockedDictionaryService.isSubClass(type, TYPE_UNFILED_RECORD_FOLDER)).thenReturn(false);
when(mockedDictionaryService.isSubClass(type, ContentModel.TYPE_CONTENT)).thenReturn(false);
when(mockedDictionaryService.isSubClass(type, TYPE_NON_ELECTRONIC_DOCUMENT)).thenReturn(true);
NodeRef nodeRef= AlfMock.generateNodeRef(mockedNodeService, type);
NodeRef unfiledRecordContainer = generateNodeRef(TYPE_UNFILED_RECORD_CONTAINER, true);
ChildAssociationRef mockedChildAssoc = mock(ChildAssociationRef.class);
when(mockedChildAssoc.getChildRef()).thenReturn(nodeRef);
when(mockedChildAssoc.getParentRef()).thenReturn(unfiledRecordContainer);
unfiledRecordContainerType.onCreateChildAssociation(mockedChildAssoc, true);
}
}