RM-4312: review updates

This commit is contained in:
Silviu Dinuta
2016-11-04 18:40:04 +02:00
parent af1cbfe3ff
commit 567b98b848
4 changed files with 13 additions and 16 deletions

View File

@@ -120,15 +120,14 @@ public abstract class BaseBehaviourBean extends ServiceBaseImpl
/**
* 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
protected void validateNewChildAssociationSubTypesIncluded(NodeRef child, List<QName> acceptedMultipleChildType) throws InvalidParameterException
{
QName childType = getInternalNodeService().getType(child);
if(!validateNodeRef(acceptedMultipleChildType, child))
if(!validateNodeRef(acceptedMultipleChildType, childType))
{
throw new InvalidParameterException("Operation failed. Children of type " + childType + " are not allowed");
}
@@ -138,20 +137,18 @@ public abstract class BaseBehaviourBean extends ServiceBaseImpl
* Checks if the type of the provided nodeRef it is between the sub-types of accepted types
*
* @param acceptedMultipleChildType
* @param nodeRef
* @param nodeType
* @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)
protected boolean validateNodeRef(List<QName> acceptedMultipleChildType, QName nodeType)
{
boolean result = false;
for(QName type : acceptedMultipleChildType)
{
if(instanceOf(nodeRef, type))
if(instanceOf(nodeType, type))
{
result = true;
break;
return true;
}
}
return result;
return false;
}
}

View File

@@ -52,7 +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);
private final static List<QName> ACCEPTED_NON_UNIQUE_CHILD_TYPES = Arrays.asList(TYPE_HOLD);
/**
* On every event
@@ -65,7 +65,7 @@ public class HoldContainerType extends BaseBehaviourBean
public void onCreateChildAssociation(ChildAssociationRef childAssocRef, boolean bNew)
{
// check the created child is of an accepted type
validateNewChildAssociationSubTypesIncluded(childAssocRef.getParentRef(), childAssocRef.getChildRef(), ACCEPTED_NON_UNIQUE_CHILD_TYPES);
validateNewChildAssociationSubTypesIncluded(childAssocRef.getChildRef(), ACCEPTED_NON_UNIQUE_CHILD_TYPES);
}
@Override

View File

@@ -52,7 +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);
private final static List<QName> ACCEPTED_NON_UNIQUE_CHILD_TYPES = Arrays.asList(TYPE_TRANSFER);
/**
* On every event
@@ -65,7 +65,7 @@ public class TransferContainerType extends BaseBehaviourBean
public void onCreateChildAssociation(ChildAssociationRef childAssocRef, boolean bNew)
{
// check the created child is of an accepted type
validateNewChildAssociationSubTypesIncluded(childAssocRef.getParentRef(), childAssocRef.getChildRef(), ACCEPTED_NON_UNIQUE_CHILD_TYPES);
validateNewChildAssociationSubTypesIncluded(childAssocRef.getChildRef(), ACCEPTED_NON_UNIQUE_CHILD_TYPES);
}
@Override

View File

@@ -49,12 +49,12 @@ import org.alfresco.service.namespace.QName;
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);
private final 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)
{
// check the created child is of an accepted type
validateNewChildAssociationSubTypesIncluded(childAssocRef.getParentRef(), childAssocRef.getChildRef(), ACCEPTED_NON_UNIQUE_CHILD_TYPES);
validateNewChildAssociationSubTypesIncluded(childAssocRef.getChildRef(), ACCEPTED_NON_UNIQUE_CHILD_TYPES);
}
}