mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-10-08 14:51:49 +00:00
Merge master into
feature/RM-4312_ConstraintForCreatingRecordFolderInSpecialContainers
This commit is contained in:
@@ -27,16 +27,22 @@
|
||||
|
||||
package org.alfresco.module.org_alfresco_module_rm.model;
|
||||
|
||||
import java.security.InvalidParameterException;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.alfresco.error.AlfrescoRuntimeException;
|
||||
import org.alfresco.module.org_alfresco_module_rm.util.ServiceBaseImpl;
|
||||
import org.alfresco.repo.policy.BehaviourFilter;
|
||||
import org.alfresco.repo.policy.annotation.BehaviourRegistry;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import com.google.common.collect.Sets;
|
||||
|
||||
/**
|
||||
* Convenient base class for behaviour beans.
|
||||
*
|
||||
@@ -87,4 +93,28 @@ public abstract class BaseBehaviourBean extends ServiceBaseImpl
|
||||
return behaviours.get(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method that checks if the newly created child association complies with the RM rules
|
||||
* @param parent the parent node
|
||||
* @param childType the child node
|
||||
* @param acceptedUniqueChildType a list of node types that are accepted as children of the provided parent only once
|
||||
* @param acceptedMultipleChildType a list of node types that are accepted as children of the provided parent multiple times
|
||||
* @throws InvalidParameterException if the child association doesn't comply with the RM rules
|
||||
*/
|
||||
protected void validateNewChildAssociation(NodeRef parent, NodeRef child, List<QName> acceptedUniqueChildType, List<QName> acceptedMultipleChildType) throws InvalidParameterException
|
||||
{
|
||||
QName childType = getInternalNodeService().getType(child);
|
||||
if(acceptedUniqueChildType.contains(childType))
|
||||
{
|
||||
// check the user is not trying to create multiple children of a type that is only accepted once
|
||||
if(nodeService.getChildAssocs(parent, Sets.newHashSet(childType)).size() > 1)
|
||||
{
|
||||
throw new InvalidParameterException("Operation failed. Multiple children of this type are not allowed.");
|
||||
}
|
||||
}
|
||||
else if(!acceptedMultipleChildType.contains(childType))
|
||||
{
|
||||
throw new InvalidParameterException("Operation failed. Children of type " + childType + " are not allowed");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -27,8 +27,10 @@
|
||||
|
||||
package org.alfresco.module.org_alfresco_module_rm.model.rma.type;
|
||||
|
||||
import org.alfresco.error.AlfrescoRuntimeException;
|
||||
import org.alfresco.model.ContentModel;
|
||||
import java.security.InvalidParameterException;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.alfresco.module.org_alfresco_module_rm.fileplan.FilePlanService;
|
||||
import org.alfresco.module.org_alfresco_module_rm.identifier.IdentifierService;
|
||||
import org.alfresco.module.org_alfresco_module_rm.model.BaseBehaviourBean;
|
||||
@@ -45,6 +47,9 @@ import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
||||
import org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork;
|
||||
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
|
||||
@@ -61,6 +66,9 @@ public class FilePlanType extends BaseBehaviourBean
|
||||
NodeServicePolicies.OnCreateNodePolicy,
|
||||
NodeServicePolicies.OnDeleteNodePolicy
|
||||
{
|
||||
private static List<QName> ACCEPTED_UNIQUE_CHILD_TYPES = Arrays.asList(TYPE_HOLD_CONTAINER, TYPE_TRANSFER_CONTAINER, TYPE_UNFILED_RECORD_CONTAINER);
|
||||
private static List<QName> ACCEPTED_NON_UNIQUE_CHILD_TYPES = Arrays.asList(TYPE_RECORD_CATEGORY);
|
||||
|
||||
/** file plan service */
|
||||
private FilePlanService filePlanService;
|
||||
|
||||
@@ -147,20 +155,8 @@ public class FilePlanType extends BaseBehaviourBean
|
||||
@Override
|
||||
public void onCreateChildAssociation(ChildAssociationRef childAssocRef, boolean bNew)
|
||||
{
|
||||
// ensure we are not trying to put content in the file plan root node
|
||||
NodeRef nodeRef = childAssocRef.getChildRef();
|
||||
if (instanceOf(nodeRef, ContentModel.TYPE_CONTENT))
|
||||
{
|
||||
throw new AlfrescoRuntimeException("Operation failed, because you can't place content in the root of the file plan.");
|
||||
}
|
||||
|
||||
// ensure we are not trying to put a record folder in the root of the file plan
|
||||
NodeRef parent = childAssocRef.getParentRef();
|
||||
if (getFilePlanService().isFilePlan(parent) && getRecordFolderService().isRecordFolder(nodeRef))
|
||||
{
|
||||
throw new AlfrescoRuntimeException("Operation failed, because you can not place a record folder in the root of the file plan.");
|
||||
}
|
||||
|
||||
// check the created child is of an accepted type
|
||||
validateNewChildAssociation(childAssocRef.getParentRef(), childAssocRef.getChildRef(), ACCEPTED_UNIQUE_CHILD_TYPES, ACCEPTED_NON_UNIQUE_CHILD_TYPES);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user