diff --git a/source/java/org/alfresco/service/cmr/model/FileFolderUtil.java b/source/java/org/alfresco/service/cmr/model/FileFolderUtil.java index 1dc4ff6016..eb28ed927c 100644 --- a/source/java/org/alfresco/service/cmr/model/FileFolderUtil.java +++ b/source/java/org/alfresco/service/cmr/model/FileFolderUtil.java @@ -125,69 +125,105 @@ public class FileFolderUtil List pathElementDetails, QName folderTypeQName, BehaviourFilter behaviourFilter, Set parentBehavioursToDisable) { - validate(pathElementDetails, service, folderTypeQName); - - NodeRef currentParentRef = parentNodeRef; - // just loop and create if necessary - for (PathElementDetails pathElement : pathElementDetails) - { - // does it exist? - // Navigation should not check permissions - NodeRef nodeRef = AuthenticationUtil.runAs( - new SearchAsSystem(service, currentParentRef, pathElement.getFolderName()), - AuthenticationUtil.getSystemUserName()); - - if (nodeRef == null) - { - if ((behaviourFilter != null) && (parentBehavioursToDisable != null)) - { - for (QName parentBehaviourToDisable : parentBehavioursToDisable) - { - behaviourFilter.disableBehaviour(currentParentRef, parentBehaviourToDisable); - } - } - - try - { - // not present - make it - // If this uses the public service it will check create - // permissions - FileInfo createdFileInfo = service.create(currentParentRef, pathElement.getFolderName(), folderTypeQName); - currentParentRef = createdFileInfo.getNodeRef(); - - Map> requireddAspects = pathElement.getAspects(); - if (requireddAspects.size() > 0 && nodeService != null) - { - for (QName aspect : requireddAspects.keySet()) - { - nodeService.addAspect(currentParentRef, aspect, requireddAspects.get(aspect)); - } - } - } - finally - { - if ((behaviourFilter != null) && (parentBehavioursToDisable != null)) - { - for (QName parentBehaviourToDisable : parentBehavioursToDisable) - { - behaviourFilter.enableBehaviour(currentParentRef, parentBehaviourToDisable); - } - } - } - } - else - { - // it exists - currentParentRef = nodeRef; - } - } - // done - // Used to call toFileInfo((currentParentRef, true); - // If this uses the public service this will check the final read access - FileInfo fileInfo = service.getFileInfo(currentParentRef); - - // Should we check the type? - return fileInfo; + return makeFolders(service, nodeService, parentNodeRef, pathElementDetails, folderTypeQName, behaviourFilter, parentBehavioursToDisable, null); + } + + /** + * Checks for the presence of, and creates as necessary, the folder + * structure in the provided paths with the following options: + *
    + *
  • Option to disable parent behaviour(s) when creating sub-folder.
  • + *
  • Each folder has the option to have its own set of aspects
  • + *
+ * + * @param service the FileFolderService object + * @param nodeService the NodeService object + * @param parentNodeRef the node under which the path will be created + * @param pathElementDetails the list of folder hierarchy where each folder + * can have its own set of aspects - may not be empty + * @param folderTypeQName the types of nodes to create. This must be a valid + * subtype of {@link org.alfresco.model.ContentModel#TYPE_FOLDER + * they folder type} + * @param behaviourFilter the BehaviourFilter object + * @param parentBehavioursToDisable the set of behaviours that must be + * disabled + * @param allFoldersRefsInThePath (Optional) if an instance of a Set is provided, + * then it'd be populated with nodeRefs of all + * the folders that have been specified in the path + * elements details.({@code pathElementDetails}). + * @return Returns the {@code FileInfo} of the last folder in the path. + */ + public static FileInfo makeFolders(FileFolderService service, NodeService nodeService, NodeRef parentNodeRef, + List pathElementDetails, QName folderTypeQName, BehaviourFilter behaviourFilter, + Set parentBehavioursToDisable, Set allFoldersRefsInThePath) + { + validate(pathElementDetails, service, folderTypeQName); + + NodeRef currentParentRef = parentNodeRef; + // just loop and create if necessary + for (PathElementDetails pathElement : pathElementDetails) + { + // does it exist? + // Navigation should not check permissions + NodeRef nodeRef = AuthenticationUtil.runAs( + new SearchAsSystem(service, currentParentRef, pathElement.getFolderName()), + AuthenticationUtil.getSystemUserName()); + + if (nodeRef == null) + { + if ((behaviourFilter != null) && (parentBehavioursToDisable != null)) + { + for (QName parentBehaviourToDisable : parentBehavioursToDisable) + { + behaviourFilter.disableBehaviour(currentParentRef, parentBehaviourToDisable); + } + } + + try + { + // not present - make it + // If this uses the public service it will check create + // permissions + FileInfo createdFileInfo = service.create(currentParentRef, pathElement.getFolderName(), folderTypeQName); + currentParentRef = createdFileInfo.getNodeRef(); + + Map> requireddAspects = pathElement.getAspects(); + if (requireddAspects.size() > 0 && nodeService != null) + { + for (QName aspect : requireddAspects.keySet()) + { + nodeService.addAspect(currentParentRef, aspect, requireddAspects.get(aspect)); + } + } + } + finally + { + if ((behaviourFilter != null) && (parentBehavioursToDisable != null)) + { + for (QName parentBehaviourToDisable : parentBehavioursToDisable) + { + behaviourFilter.enableBehaviour(currentParentRef, parentBehaviourToDisable); + } + } + } + } + else + { + // it exists + currentParentRef = nodeRef; + } + if (allFoldersRefsInThePath != null) + { + allFoldersRefsInThePath.add(currentParentRef); + } + } + // done + // Used to call toFileInfo((currentParentRef, true); + // If this uses the public service this will check the final read access + FileInfo fileInfo = service.getFileInfo(currentParentRef); + + // Should we check the type? + return fileInfo; } private static void validate(List pathElements, FileFolderService service, QName folderTypeQName)