Search in sources :

Example 46 with FolderData

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

the class CreateRMSite method loadSpecialContainersInDB.

private void loadSpecialContainersInDB(String siteId, String siteManager, String password) throws Exception {
    UserModel userModel = new UserModel(siteManager, password);
    FilePlan filePlanEntity = restAPIFactory.getFilePlansAPI(userModel).getFilePlan(FILE_PLAN_ALIAS);
    FolderData filePlan = new FolderData(// already unique
    filePlanEntity.getId(), FILEPLAN_CONTEXT, "/" + PATH_SNIPPET_SITES + "/" + siteId + "/" + PATH_SNIPPET_FILE_PLAN, 0L, 0L);
    fileFolderService.createNewFolder(filePlan);
    // add Unfiled record container
    UnfiledContainer unfiledContainer = restAPIFactory.getUnfiledContainersAPI(userModel).getUnfiledContainer(UNFILED_RECORDS_CONTAINER_ALIAS);
    FolderData unfiledRecordContainer = new FolderData(// already unique
    unfiledContainer.getId(), UNFILED_CONTEXT, "/" + PATH_SNIPPET_SITES + "/" + siteId + "/" + PATH_SNIPPET_FILE_PLAN + "/" + PATH_SNIPPET_UNFILED_RECORD_CONTAINER, 0L, 0L);
    fileFolderService.createNewFolder(unfiledRecordContainer);
    // add Transfer container
    TransferContainer transferContainerEntity = restAPIFactory.getTransferContainerAPI(userModel).getTransferContainer(TRANSFERS_ALIAS);
    FolderData transferContainer = new FolderData(// already unique
    transferContainerEntity.getId(), TRANSFER_CONTEXT, "/" + PATH_SNIPPET_SITES + "/" + siteId + "/" + PATH_SNIPPET_FILE_PLAN + "/" + PATH_SNIPPET_TRANSFER_CONTAINER, 0L, 0L);
    fileFolderService.createNewFolder(transferContainer);
}
Also used : UserModel(org.alfresco.utility.model.UserModel) UnfiledContainer(org.alfresco.rest.rm.community.model.unfiledcontainer.UnfiledContainer) TransferContainer(org.alfresco.rest.rm.community.model.transfercontainer.TransferContainer) FilePlan(org.alfresco.rest.rm.community.model.fileplan.FilePlan) FolderData(org.alfresco.bm.cm.FolderData)

Example 47 with FolderData

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

the class ScheduleUnfiledRecordLoaders method createFolder.

/**
 * Helper method used for creating in alfresco repo and in mongo DB, unfiled record folders from configured path elements.
 *
 * @param path - path element
 * @return created unfiled record folder, or existent unfiled record folder, if it already created
 * @throws Exception
 */
private FolderData createFolder(String path) throws Exception {
    // create inexistent elements from configured paths as admin
    List<String> pathElements = Arrays.asList(split(path, "/"));
    FolderData parentFolder = fileFolderService.getFolder(UNFILED_CONTEXT, UNFILED_RECORD_CONTAINER_PATH);
    // for(String pathElement: pathElements)
    int pathElementsLength = pathElements.size();
    for (int i = 0; i < pathElementsLength; i++) {
        String pathElement = pathElements.get(i);
        FolderData folder = fileFolderService.getFolder(UNFILED_CONTEXT, parentFolder.getPath() + "/" + pathElement);
        if (folder != null) {
            parentFolder = folder;
        } else {
            if (i == 0) {
                // create root unfiled record folder
                parentFolder = createRootUnfiledRecordFolderWithFixedName(parentFolder, pathElement);
            } else {
                // create child unfiled record folder
                parentFolder = createUnfiledRecordFolderWithFixedName(parentFolder, pathElement);
            }
        }
    }
    return parentFolder;
}
Also used : FolderData(org.alfresco.bm.cm.FolderData)

Example 48 with FolderData

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

the class ScheduleUnfiledRecordLoaders method prepareUnfiledRecords.

/**
 * Helper method for preparing events for loading unfiled records randomly in the unfiled record folders structure or in specified unfiled record folder paths.
 *
 * @param loaderSessionsToCreate - the number of still active loader sessions
 * @param nextEvents - list of prepared events
 */
private void prepareUnfiledRecords(int loaderSessionsToCreate, List<Event> nextEvents) {
    calculateListOfEmptyFolders();
    List<FolderData> emptyFolders = (mapOfRecordsPerUnfiledRecordFolder == null) ? new ArrayList<>() : new ArrayList<>(mapOfRecordsPerUnfiledRecordFolder.keySet());
    while (nextEvents.size() < loaderSessionsToCreate) {
        if (mapOfRecordsPerUnfiledRecordFolder == null || mapOfRecordsPerUnfiledRecordFolder.isEmpty()) {
            break;
        }
        // Schedule a load for each folder
        for (FolderData emptyFolder : emptyFolders) {
            int recordsToCreate = mapOfRecordsPerUnfiledRecordFolder.get(emptyFolder) - (int) emptyFolder.getFileCount();
            if (recordsToCreate <= 0) {
                mapOfRecordsPerUnfiledRecordFolder.remove(emptyFolder);
            } else {
                try {
                    DBObject loadData = BasicDBObjectBuilder.start().add(FIELD_CONTEXT, emptyFolder.getContext()).add(FIELD_PATH, emptyFolder.getPath()).add(FIELD_LOAD_OPERATION, LOAD_UNFILED_RECORD_OPERATION).get();
                    int i;
                    for (i = 0; i < recordsToCreate; i++) {
                        Event loadEvent = new Event(getEventNameLoadUnfiledRecords(), loadData);
                        String sessionId = sessionService.startSession(loadData);
                        loadEvent.setSessionId(sessionId);
                        // Add the event to the list
                        nextEvents.add(loadEvent);
                        // Check if we have enough
                        if (nextEvents.size() >= loaderSessionsToCreate) {
                            break;
                        }
                    }
                    if (i == recordsToCreate) {
                        mapOfRecordsPerUnfiledRecordFolder.remove(emptyFolder);
                    } else {
                        mapOfRecordsPerUnfiledRecordFolder.put(emptyFolder, mapOfRecordsPerUnfiledRecordFolder.get(emptyFolder) - i - 1);
                    }
                } catch (Exception e) {
                    mapOfRecordsPerUnfiledRecordFolder.remove(emptyFolder);
                    // The lock was already applied; find another
                    continue;
                }
            }
            // Check if we have enough
            if (nextEvents.size() >= loaderSessionsToCreate) {
                break;
            }
        }
    }
}
Also used : FolderData(org.alfresco.bm.cm.FolderData) Event(org.alfresco.bm.event.Event) DBObject(com.mongodb.DBObject)

Example 49 with FolderData

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

the class ScheduleFilePlanLoaders method prepareRootCategories.

/**
 * Helper method for preparing the events that load the root record categories.
 *
 * @param loaderSessionsToCreate - the number of still active loader sessions
 * @param nextEvents - list of prepared events
 */
private void prepareRootCategories(int loaderSessionsToCreate, List<Event> nextEvents) {
    // get filePlan folder
    FolderData filePlan = fileFolderService.getFolder(FILEPLAN_CONTEXT, RECORD_CONTAINER_PATH);
    if (rootCategoriesToLoad == null) {
        rootCategoriesToLoad = Math.max(categoryNumber - (int) filePlan.getFolderCount(), 0);
    }
    while (nextEvents.size() < loaderSessionsToCreate) {
        if (rootCategoriesToLoad == 0) {
            // No root record categories needed
            break;
        }
        for (int i = 0; i < rootCategoriesToLoad; i++) {
            DBObject loadData = BasicDBObjectBuilder.start().add(FIELD_CONTEXT, filePlan.getContext()).add(FIELD_PATH, filePlan.getPath()).add(FIELD_LOAD_OPERATION, LOAD_ROOT_CATEGORY_OPERATION).get();
            Event loadEvent = new Event(getEventNameLoadRootRecordCategory(), loadData);
            // Each load event must be associated with a session
            String sessionId = sessionService.startSession(loadData);
            loadEvent.setSessionId(sessionId);
            // Add the event to the list
            nextEvents.add(loadEvent);
            rootCategoriesToLoad--;
            // Check if we have enough
            if (nextEvents.size() >= loaderSessionsToCreate) {
                break;
            }
        }
    }
}
Also used : FolderData(org.alfresco.bm.cm.FolderData) Event(org.alfresco.bm.event.Event) DBObject(com.mongodb.DBObject)

Example 50 with FolderData

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

the class ScheduleFilePlanLoaders method prepareSubCategoriesAndRecordFolders.

/**
 * Helper method for preparing the load events for record categories children and record folders children without the last level of record folders.
 *
 * @param loaderSessionsToCreate - the number of still active loader sessions
 * @param nextEvents - list of prepared events
 */
private void prepareSubCategoriesAndRecordFolders(int loaderSessionsToCreate, List<Event> nextEvents) {
    int skip = 0;
    int limit = 100;
    while (nextEvents.size() < loaderSessionsToCreate) {
        // Get categories needing loading
        // the maximum number of children a folder should contain so that it will be picked up for further loading
        calculateMaxChildren();
        List<FolderData> emptyFolders = fileFolderService.getFoldersByCounts(RECORD_CATEGORY_CONTEXT, // min level FILE_PLAN_LEVEL + 1 = 4, root categories
        Long.valueOf(FILE_PLAN_LEVEL + 1), // last level will be for record folders, FILE_PLAN_LEVEL+depth-1 required
        Long.valueOf(maxLevel - 1), // maximum number of sub folders so that it will be picked up for further loading
        0L, // maximum number of sub folders so that it will be picked up for further loading
        Long.valueOf(maxChildren), null, null, skip, limit);
        if (emptyFolders.isEmpty()) {
            // The folders were populated in the mean time
            break;
        }
        // Schedule a load for each folder
        for (FolderData emptyFolder : emptyFolders) {
            FolderData folder = auxFileFolderService.getFolder(emptyFolder.getContext(), emptyFolder.getPath());
            if (folder == null) {
                auxFileFolderService.createNewFolder(emptyFolder.getId(), emptyFolder.getContext(), emptyFolder.getPath());
                int toCreateCateg = childCategNumber - getDirectChildrenByContext(emptyFolder, RECORD_CATEGORY_CONTEXT).size();
                auxFileFolderService.incrementFolderCount(emptyFolder.getContext(), emptyFolder.getPath(), toCreateCateg);
                if (this.folderCategoryMix) {
                    int toCreateFolders = folderNumber - getDirectChildrenByContext(emptyFolder, RECORD_FOLDER_CONTEXT).size();
                    auxFileFolderService.incrementFileCount(emptyFolder.getContext(), emptyFolder.getPath(), toCreateFolders);
                }
                folder = auxFileFolderService.getFolder(emptyFolder.getId());
            }
            int categoriesToCreate = (int) folder.getFolderCount();
            DBObject loadData = BasicDBObjectBuilder.start().add(FIELD_CONTEXT, emptyFolder.getContext()).add(FIELD_PATH, emptyFolder.getPath()).add(FIELD_LOAD_OPERATION, LOAD_SUB_CATEGORY_OPERATION).get();
            int i;
            for (i = 0; i < categoriesToCreate; i++) {
                Event loadEvent = new Event(getEventNameLoadSubCategory(), loadData);
                // Each load event must be associated with a session
                String sessionId = sessionService.startSession(loadData);
                loadEvent.setSessionId(sessionId);
                // Add the event to the list
                nextEvents.add(loadEvent);
                // Check if we have enough
                if (nextEvents.size() >= loaderSessionsToCreate) {
                    break;
                }
            }
            if (i == categoriesToCreate) {
                auxFileFolderService.incrementFolderCount(emptyFolder.getContext(), emptyFolder.getPath(), -categoriesToCreate);
            } else {
                auxFileFolderService.incrementFolderCount(emptyFolder.getContext(), emptyFolder.getPath(), -i - 1);
            }
            if (this.folderCategoryMix) {
                int foldersToCreate = (int) folder.getFileCount();
                DBObject loadRecordFolderData = BasicDBObjectBuilder.start().add(FIELD_CONTEXT, emptyFolder.getContext()).add(FIELD_PATH, emptyFolder.getPath()).add(FIELD_LOAD_OPERATION, LOAD_RECORD_FOLDER_OPERATION).get();
                int j;
                for (j = 0; j < foldersToCreate; j++) {
                    Event loadRecordFolderEvent = new Event(getEventNameLoadRecordFolder(), loadRecordFolderData);
                    // Each load event must be associated with a session
                    String recordFolderSessionId = sessionService.startSession(loadRecordFolderData);
                    loadRecordFolderEvent.setSessionId(recordFolderSessionId);
                    // Add the event to the list
                    nextEvents.add(loadRecordFolderEvent);
                    // Check if we have enough
                    if (nextEvents.size() >= loaderSessionsToCreate) {
                        break;
                    }
                }
                if (j == foldersToCreate) {
                    auxFileFolderService.incrementFileCount(emptyFolder.getContext(), emptyFolder.getPath(), -foldersToCreate);
                } else {
                    auxFileFolderService.incrementFileCount(emptyFolder.getContext(), emptyFolder.getPath(), -j - 1);
                }
            }
            // Check if we have enough
            if (nextEvents.size() >= loaderSessionsToCreate) {
                break;
            }
        }
        skip += limit;
    }
}
Also used : FolderData(org.alfresco.bm.cm.FolderData) Event(org.alfresco.bm.event.Event) DBObject(com.mongodb.DBObject)

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