mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
RM-4312: changed implementation after review
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
@@ -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
|
||||
*
|
||||
@@ -178,8 +175,8 @@ public class FilePlanType extends BaseBehaviourBean
|
||||
{
|
||||
// ensure rules are not inherited
|
||||
nodeService.addAspect(filePlan, RuleModel.ASPECT_IGNORE_INHERITED_RULES, null);
|
||||
|
||||
// set the identifier
|
||||
|
||||
// set the identifier
|
||||
if (nodeService.getProperty(filePlan, PROP_IDENTIFIER) == null)
|
||||
{
|
||||
String id = getIdentifierService().generateIdentifier(filePlan);
|
||||
|
@@ -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
|
||||
|
@@ -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
|
||||
|
@@ -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);
|
||||
}
|
||||
}
|
||||
|
@@ -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.
|
||||
*
|
||||
|
Reference in New Issue
Block a user