RM-4619 - moved the conversion to the specific types before the type check

This commit is contained in:
Ana Bozianu
2017-01-26 12:05:17 +02:00
parent 4fac165cdb
commit c84c951c52
3 changed files with 32 additions and 33 deletions

View File

@@ -30,6 +30,7 @@ package org.alfresco.module.org_alfresco_module_rm.model.rma.type;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import org.alfresco.model.ContentModel;
import org.alfresco.module.org_alfresco_module_rm.fileplan.FilePlanService; 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.identifier.IdentifierService;
import org.alfresco.module.org_alfresco_module_rm.model.BaseBehaviourBean; import org.alfresco.module.org_alfresco_module_rm.model.BaseBehaviourBean;
@@ -208,11 +209,23 @@ public class FilePlanType extends BaseBehaviourBean
*/ */
@Behaviour @Behaviour
( (
kind = BehaviourKind.ASSOCIATION kind = BehaviourKind.ASSOCIATION,
notificationFrequency = NotificationFrequency.TRANSACTION_COMMIT
) )
@Override @Override
public void onCreateChildAssociation(ChildAssociationRef childAssocRef, boolean bNew) public void onCreateChildAssociation(ChildAssociationRef childAssocRef, boolean bNew)
{ {
NodeRef child = childAssocRef.getChildRef();
// We need to automatically cast the created folder to category if it is a plain folder
// This occurs if the RM folder has been created via IMap, WebDav, etc
// Ignore hidden files. Some modules use hidden files to store information (see RM-3283)
if (nodeService.getType(child) == ContentModel.TYPE_FOLDER &&
!nodeService.hasAspect(child, ContentModel.ASPECT_HIDDEN))
{
nodeService.setType(child, TYPE_RECORD_CATEGORY);
}
// check the created child is of an accepted type // check the created child is of an accepted type
validateNewChildAssociation(childAssocRef.getParentRef(), childAssocRef.getChildRef(), ACCEPTED_UNIQUE_CHILD_TYPES, ACCEPTED_NON_UNIQUE_CHILD_TYPES); validateNewChildAssociation(childAssocRef.getParentRef(), childAssocRef.getChildRef(), ACCEPTED_UNIQUE_CHILD_TYPES, ACCEPTED_NON_UNIQUE_CHILD_TYPES);
} }

View File

@@ -31,6 +31,7 @@ import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import org.alfresco.model.ContentModel;
import org.alfresco.module.org_alfresco_module_rm.model.BaseBehaviourBean; import org.alfresco.module.org_alfresco_module_rm.model.BaseBehaviourBean;
import org.alfresco.module.org_alfresco_module_rm.recordfolder.RecordFolderService; import org.alfresco.module.org_alfresco_module_rm.recordfolder.RecordFolderService;
import org.alfresco.module.org_alfresco_module_rm.security.FilePlanPermissionService; import org.alfresco.module.org_alfresco_module_rm.security.FilePlanPermissionService;
@@ -107,18 +108,31 @@ public class RecordCategoryType extends BaseBehaviourBean
@Override @Override
@Behaviour @Behaviour
( (
kind = BehaviourKind.ASSOCIATION kind = BehaviourKind.ASSOCIATION,
notificationFrequency = NotificationFrequency.TRANSACTION_COMMIT
) )
public void onCreateChildAssociation(ChildAssociationRef childAssocRef, boolean bNew) public void onCreateChildAssociation(ChildAssociationRef childAssocRef, boolean bNew)
{ {
NodeRef nodeRef = childAssocRef.getChildRef(); NodeRef child = childAssocRef.getChildRef();
NodeRef parentRef = childAssocRef.getParentRef(); NodeRef parentRef = childAssocRef.getParentRef();
validateNewChildAssociation(parentRef, nodeRef, ACCEPTED_UNIQUE_CHILD_TYPES, ACCEPTED_NON_UNIQUE_CHILD_TYPES); QName childType = nodeService.getType(child);
// We need to automatically cast the created folder to record folder if it is a plain folder
// This occurs if the RM folder has been created via IMap, WebDav, etc
// Ignore hidden files. Some modules use hidden files to store information (see RM-3283)
if ( childType == ContentModel.TYPE_FOLDER &&
!nodeService.hasAspect(child, ContentModel.ASPECT_HIDDEN))
{
nodeService.setType(child, TYPE_RECORD_FOLDER);
}
if (bNew) if (bNew)
{ {
// setup the record folder // setup the record folder
recordFolderService.setupRecordFolder(nodeRef); recordFolderService.setupRecordFolder(child);
} }
validateNewChildAssociation(parentRef, child, ACCEPTED_UNIQUE_CHILD_TYPES, ACCEPTED_NON_UNIQUE_CHILD_TYPES);
} }
/** /**

View File

@@ -27,7 +27,6 @@
package org.alfresco.module.org_alfresco_module_rm.model.rma.type; package org.alfresco.module.org_alfresco_module_rm.model.rma.type;
import org.alfresco.error.AlfrescoRuntimeException;
import org.alfresco.model.ContentModel; import org.alfresco.model.ContentModel;
import org.alfresco.module.org_alfresco_module_rm.identifier.IdentifierService; import org.alfresco.module.org_alfresco_module_rm.identifier.IdentifierService;
import org.alfresco.module.org_alfresco_module_rm.model.BaseBehaviourBean; import org.alfresco.module.org_alfresco_module_rm.model.BaseBehaviourBean;
@@ -44,7 +43,6 @@ import org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork;
import org.alfresco.service.cmr.repository.ChildAssociationRef; import org.alfresco.service.cmr.repository.ChildAssociationRef;
import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.namespace.QName; import org.alfresco.service.namespace.QName;
import org.springframework.extensions.surf.util.I18NUtil;
/** /**
* rma:recordsManagementContainer behaviour bean. * rma:recordsManagementContainer behaviour bean.
@@ -152,32 +150,6 @@ public class RecordsManagementContainerType extends BaseBehaviourBean
} }
else else
{ {
// We need to automatically cast the created folder to RM type if it is a plain folder
// This occurs if the RM folder has been created via IMap, WebDav, etc
if (!nodeService.hasAspect(child, ASPECT_FILE_PLAN_COMPONENT))
{
// Throw exception if the type is not cm:folder
if (!ContentModel.TYPE_FOLDER.equals(childType))
{
throw new AlfrescoRuntimeException(I18NUtil.getMessage(MSG_CANNOT_CAST_TO_RM_TYPE));
}
// check the type of the parent to determine what 'kind' of artifact to create
NodeRef parent = childAssocRef.getParentRef();
QName parentType = nodeService.getType(parent);
if (dictionaryService.isSubClass(parentType, TYPE_FILE_PLAN))
{
// create a rma:recordCategoty since we are in the root of the file plan
nodeService.setType(child, TYPE_RECORD_CATEGORY);
}
else
{
// create a rma:recordFolder and initialise record folder
nodeService.setType(child, TYPE_RECORD_FOLDER);
recordFolderService.setupRecordFolder(child);
}
}
// Catch all to generate the rm id (assuming it doesn't already have one!) // Catch all to generate the rm id (assuming it doesn't already have one!)
setIdenifierProperty(child); setIdenifierProperty(child);
} }