Search in sources :

Example 41 with FolderData

use of org.alfresco.bm.cm.FolderData in project records-management by Alfresco.

the class RMBaseEventProcessor method getRecordFolders.

/**
 * Obtains all record folders underneath specified parent if the parent is a category or the parent itself if it is a record folder
 *
 * @param parentFolder - the parent folder to retrieve children folders from
 * @return all record folders underneath specified parent if the parent is a category or the parent itself if it is a record folder
 */
protected Set<FolderData> getRecordFolders(FolderData parentFolder) {
    LinkedHashSet<FolderData> result = new LinkedHashSet<FolderData>();
    String context = parentFolder.getContext();
    if (RECORD_CATEGORY_CONTEXT.equals(context)) {
        List<FolderData> directCategoryChildren = getDirectChildrenByContext(parentFolder, RECORD_CATEGORY_CONTEXT);
        if (!directCategoryChildren.isEmpty()) {
            for (FolderData childFolder : directCategoryChildren) {
                result.addAll(getRecordFolders(childFolder));
            }
        }
        List<FolderData> directRecordFolderChildren = getDirectChildrenByContext(parentFolder, RECORD_FOLDER_CONTEXT);
        if (!directRecordFolderChildren.isEmpty()) {
            Iterator<FolderData> iterator = directRecordFolderChildren.iterator();
            while (iterator.hasNext()) {
                FolderData childFolder = iterator.next();
                if (childFolder.getPath().endsWith("locked") && !isIdValid(childFolder.getId(), RECORD_FOLDER_CONTEXT)) {
                    iterator.remove();
                }
            }
            result.addAll(directRecordFolderChildren);
        }
    } else if (RECORD_FOLDER_CONTEXT.equals(context)) {
        if (!parentFolder.getPath().endsWith("locked") || (parentFolder.getPath().endsWith("locked") && isIdValid(parentFolder.getId(), RECORD_FOLDER_CONTEXT))) {
            result.add(parentFolder);
        }
    }
    return result;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) FolderData(org.alfresco.bm.cm.FolderData)

Example 42 with FolderData

use of org.alfresco.bm.cm.FolderData in project records-management by Alfresco.

the class RMBaseEventProcessor method getUnfiledRecordFolders.

/**
 * Obtains all unfiled record folders underneath specified parent folder plus the parent folder
 *
 * @param parentFolder - the parent folder that we need to get unfiled record folders from
 * @return all unfiled record folders underneath specified parent folder plus the parent folder
 */
public Set<FolderData> getUnfiledRecordFolders(FolderData parentFolder) {
    LinkedHashSet<FolderData> result = new LinkedHashSet<FolderData>();
    int skip = 0;
    int limit = 100;
    List<FolderData> directChildren = new ArrayList<FolderData>();
    List<FolderData> childFolders = fileFolderService.getChildFolders(UNFILED_CONTEXT, parentFolder.getPath(), skip, limit);
    while (!childFolders.isEmpty()) {
        directChildren.addAll(childFolders);
        skip += limit;
        childFolders = fileFolderService.getChildFolders(UNFILED_CONTEXT, parentFolder.getPath(), skip, limit);
    }
    if (!directChildren.isEmpty()) {
        for (FolderData childFolder : directChildren) {
            result.addAll(getUnfiledRecordFolders(childFolder));
        }
    }
    if (!parentFolder.getPath().endsWith("locked") || (parentFolder.getPath().endsWith("locked") && isIdValid(parentFolder.getId(), UNFILED_CONTEXT))) {
        result.add(parentFolder);
    }
    return result;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) FolderData(org.alfresco.bm.cm.FolderData) ArrayList(java.util.ArrayList)

Example 43 with FolderData

use of org.alfresco.bm.cm.FolderData in project records-management by Alfresco.

the class RMBaseEventProcessor method createRecordCategoryOrRecordFolder.

/**
 * Helper method used for creating in alfresco repo and in mongo DB, root record categories, record categories and record folders from configured path elements.
 *
 * @param path - path element
 * @return created record folder, or existing record folder, if already created
 * @throws Exception
 */
public FolderData createRecordCategoryOrRecordFolder(String path) throws Exception {
    // create inexistent elements from configured paths as admin
    List<String> pathElements = Arrays.asList(split(path, "/"));
    FolderData parentFolder = fileFolderService.getFolder(FILEPLAN_CONTEXT, RECORD_CONTAINER_PATH);
    // for(String pathElement: pathElements)
    int pathElementsLength = pathElements.size();
    // when one path does not exist it must have at least path elements, one for root record category and one for record folder
    if (pathElementsLength == 1) {
        throw new Exception("At least 2 path elemets needed for creating record folders in which we can create records");
    }
    for (int i = 0; i < pathElementsLength; i++) {
        String pathElement = pathElements.get(i);
        FolderData folder = fileFolderService.getFolder(RECORD_CATEGORY_CONTEXT, parentFolder.getPath() + "/" + pathElement);
        if (folder != null) {
            parentFolder = folder;
        } else {
            if (i == 0) {
                // create root category
                parentFolder = createRootRecordCategoryWithFixedName(parentFolder, pathElement);
            } else if (pathElementsLength > 1 && i == (pathElementsLength - 1)) {
                // create record folder
                parentFolder = createRecordFolderWithFixedName(parentFolder, pathElement);
            } else {
                // create child category
                parentFolder = createRecordCategoryWithFixedName(parentFolder, pathElement);
            }
        }
    }
    return parentFolder;
}
Also used : FolderData(org.alfresco.bm.cm.FolderData) BeansException(org.springframework.beans.BeansException)

Example 44 with FolderData

use of org.alfresco.bm.cm.FolderData in project records-management by Alfresco.

the class RMBaseEventProcessor method initialiseFoldersToExistingStructure.

/**
 * Helper method to obtain all folders with specified context.
 *
 * @param context - context of the wanted folders
 * @return all folders with specified context.
 */
public List<FolderData> initialiseFoldersToExistingStructure(String context) {
    List<FolderData> existingFolderStructure = new ArrayList<FolderData>();
    int skip = 0;
    int limit = 100;
    List<FolderData> emptyFolders = fileFolderService.getFoldersByCounts(context, null, null, null, null, null, null, skip, limit);
    while (!emptyFolders.isEmpty()) {
        existingFolderStructure.addAll(emptyFolders);
        skip += limit;
        emptyFolders = fileFolderService.getFoldersByCounts(context, null, null, null, null, null, null, skip, limit);
    }
    // check for locked folders
    Iterator<FolderData> iterator = existingFolderStructure.iterator();
    while (iterator.hasNext()) {
        FolderData folder = iterator.next();
        if (folder.getPath().endsWith("locked") && !isIdValid(folder.getId(), context)) {
            iterator.remove();
        }
    }
    return existingFolderStructure;
}
Also used : FolderData(org.alfresco.bm.cm.FolderData) ArrayList(java.util.ArrayList)

Example 45 with FolderData

use of org.alfresco.bm.cm.FolderData in project records-management by Alfresco.

the class RMBaseEventProcessor method createUnfiledRecordFolderWithFixedName.

/**
 * Helper method for creating a child unfiled record folder with a specified name.
 *
 * @param folder - container that will contain created child unfiled record folder
 * @param name - the name that created child unfiled record folder will have
 * @return created child unfiled record folder with a specified name
 * @throws Exception
 */
public FolderData createUnfiledRecordFolderWithFixedName(FolderData folder, String name) throws Exception {
    FolderData createdFolder = null;
    String folderPath = folder.getPath();
    String newfilePlanComponentTitle = "title: " + name;
    // Build unfiled record folder properties
    UnfiledContainerChild unfiledRecordFolderChildModel = UnfiledContainerChild.builder().name(name).nodeType(UNFILED_RECORD_FOLDER_TYPE).properties(UnfiledContainerChildProperties.builder().title(newfilePlanComponentTitle).description(EMPTY).build()).build();
    UnfiledRecordFolderAPI unfiledRecordFoldersAPI = getRestAPIFactory().getUnfiledRecordFoldersAPI();
    UnfiledContainerChild unfiledRecordFolderChild = unfiledRecordFoldersAPI.createUnfiledRecordFolderChild(unfiledRecordFolderChildModel, folder.getId());
    String newUnfiledRecordFolderChildId = unfiledRecordFolderChild.getId();
    fileFolderService.createNewFolder(newUnfiledRecordFolderChildId, UNFILED_CONTEXT, folderPath + "/" + name);
    // Increment counts
    fileFolderService.incrementFolderCount(folder.getContext(), folderPath, 1);
    createdFolder = fileFolderService.getFolder(newUnfiledRecordFolderChildId);
    return createdFolder;
}
Also used : UnfiledRecordFolderAPI(org.alfresco.rest.rm.community.requests.gscore.api.UnfiledRecordFolderAPI) UnfiledContainerChild(org.alfresco.rest.rm.community.model.unfiledcontainer.UnfiledContainerChild) FolderData(org.alfresco.bm.cm.FolderData)

Aggregations

FolderData (org.alfresco.bm.cm.FolderData)94 DBObject (com.mongodb.DBObject)76 Event (org.alfresco.bm.event.Event)70 Test (org.junit.Test)69 EventResult (org.alfresco.bm.event.EventResult)68 StopWatch (org.apache.commons.lang3.time.StopWatch)68 LoadSingleComponentUnitTest (org.alfresco.bm.dataload.LoadSingleComponentUnitTest)23 UserModel (org.alfresco.utility.model.UserModel)21 UnfiledContainerChild (org.alfresco.rest.rm.community.model.unfiledcontainer.UnfiledContainerChild)14 RecordData (org.alfresco.bm.dataload.rm.services.RecordData)10 File (java.io.File)9 RecordCategoryChild (org.alfresco.rest.rm.community.model.recordcategory.RecordCategoryChild)8 ArrayList (java.util.ArrayList)7 RecordCategory (org.alfresco.rest.rm.community.model.recordcategory.RecordCategory)7 UnfiledContainer (org.alfresco.rest.rm.community.model.unfiledcontainer.UnfiledContainer)7 LinkedHashSet (java.util.LinkedHashSet)5 FilePlan (org.alfresco.rest.rm.community.model.fileplan.FilePlan)5 Record (org.alfresco.rest.rm.community.model.record.Record)4 RecordFolder (org.alfresco.rest.rm.community.model.recordfolder.RecordFolder)3 RecordCategoryAPI (org.alfresco.rest.rm.community.requests.gscore.api.RecordCategoryAPI)2