Search in sources :

Example 51 with FolderData

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

the class ScheduleFilePlanLoaders method prepareRecordFoldersOnLowestLevel.

/**
 * Helper method for preparing the load events for record folders children from the last level.
 *
 * @param loaderSessionsToCreate - the number of still active loader sessions
 * @param nextEvents - list of prepared events
 */
private void prepareRecordFoldersOnLowestLevel(int loaderSessionsToCreate, List<Event> nextEvents) {
    int skip = 0;
    int limit = 100;
    while (nextEvents.size() < loaderSessionsToCreate) {
        // Get categories needing loading
        List<FolderData> emptyFolders = fileFolderService.getFoldersByCounts(RECORD_CATEGORY_CONTEXT, // max and min level are FILE_PLAN_LEVEL+depth, of last category, where we load lowest level of record folders
        Long.valueOf(maxLevel), // max and min level are FILE_PLAN_LEVEL+depth, of last category, where we load lowest level of record folders
        Long.valueOf(maxLevel), // limit the maximum number of child folders to number of record folder to create - 1
        0L, // limit the maximum number of child folders to number of record folder to create - 1
        Long.valueOf(folderNumber - 1), // Ignore file limits
        null, // Ignore file limits
        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 toCreateFolders = folderNumber - getDirectChildrenByContext(emptyFolder, RECORD_FOLDER_CONTEXT).size();
                auxFileFolderService.incrementFileCount(emptyFolder.getContext(), emptyFolder.getPath(), toCreateFolders);
                folder = auxFileFolderService.getFolder(emptyFolder.getId());
            }
            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)

Example 52 with FolderData

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

the class ScheduleRecordLoaders method prepareRecords.

/**
 * Helper method for preparing events for loading records randomly in the record folders structure or in specified record folder paths.
 *
 * @param loaderSessionsToCreate - the number of still active loader sessions
 * @param nextEvents - list of prepared events
 */
private void prepareRecords(int loaderSessionsToCreate, List<Event> nextEvents) {
    mapOfRecordsPerRecordFolder = calculateListOfEmptyFolders(mapOfRecordsPerRecordFolder, paths, recordsNumber);
    List<FolderData> emptyFolders = (mapOfRecordsPerRecordFolder == null) ? new ArrayList<>() : new ArrayList<>(mapOfRecordsPerRecordFolder.keySet());
    while (nextEvents.size() < loaderSessionsToCreate) {
        if (mapOfRecordsPerRecordFolder == null || mapOfRecordsPerRecordFolder.isEmpty()) {
            break;
        }
        // Schedule a load for each folder
        for (FolderData emptyFolder : emptyFolders) {
            int recordsToCreate = mapOfRecordsPerRecordFolder.get(emptyFolder) - (int) emptyFolder.getFileCount();
            if (recordsToCreate <= 0) {
                mapOfRecordsPerRecordFolder.remove(emptyFolder);
            } else {
                try {
                    DBObject loadData = BasicDBObjectBuilder.start().add(FIELD_CONTEXT, emptyFolder.getContext()).add(FIELD_PATH, emptyFolder.getPath()).add(FIELD_LOAD_OPERATION, LOAD_RECORD_OPERATION).get();
                    int i;
                    for (i = 0; i < recordsToCreate; i++) {
                        Event loadEvent = new Event(getEventNameLoadRecords(), 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 == recordsToCreate) {
                        mapOfRecordsPerRecordFolder.remove(emptyFolder);
                    } else {
                        mapOfRecordsPerRecordFolder.put(emptyFolder, mapOfRecordsPerRecordFolder.get(emptyFolder) - i - 1);
                    }
                } catch (Exception e) {
                    mapOfRecordsPerRecordFolder.remove(emptyFolder);
                    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 53 with FolderData

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

the class LoadSingleComponentUnitTest method testWithUnsuportedOperation.

@Test(expected = IllegalStateException.class)
public void testWithUnsuportedOperation() throws Exception {
    Event mockedEvent = mock(Event.class);
    DBObject mockedData = mock(DBObject.class);
    when(mockedData.get(FIELD_CONTEXT)).thenReturn("someContext");
    when(mockedData.get(FIELD_PATH)).thenReturn("/aPath");
    when(mockedData.get(FIELD_LOAD_OPERATION)).thenReturn("unsuportedOperation");
    FolderData mockedFolder = mock(FolderData.class);
    when(mockedFileFolderService.getFolder("someContext", "/aPath")).thenReturn(mockedFolder);
    when(mockedEvent.getData()).thenReturn(mockedData);
    when(mockedEvent.getSessionId()).thenReturn("someSessionId");
    loadSingleComponent.processEvent(mockedEvent, new StopWatch());
}
Also used : FolderData(org.alfresco.bm.cm.FolderData) Event(org.alfresco.bm.event.Event) DBObject(com.mongodb.DBObject) StopWatch(org.apache.commons.lang3.time.StopWatch) Test(org.junit.Test)

Example 54 with FolderData

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

the class ScheduleFilePlanLoadersUnitTest method testScheduleRootCategories.

@Test
public void testScheduleRootCategories() throws Exception {
    int maxActiveLoaders = 8;
    int rootCategoriesNumber = 4;
    int categoryStructureDepth = 1;
    scheduleFilePlanLoaders.setMaxActiveLoaders(maxActiveLoaders);
    scheduleFilePlanLoaders.setCategoryNumber(rootCategoriesNumber);
    scheduleFilePlanLoaders.setCategoryStructureDepth(categoryStructureDepth);
    FolderData filePlanFolder = mock(FolderData.class);
    when(filePlanFolder.getContext()).thenReturn(FILEPLAN_CONTEXT);
    when(filePlanFolder.getPath()).thenReturn(RECORD_CONTAINER_PATH);
    when(mockedFileFolderService.getFolder(FILEPLAN_CONTEXT, RECORD_CONTAINER_PATH)).thenReturn(filePlanFolder);
    EventResult result = scheduleFilePlanLoaders.processEvent(null, new StopWatch());
    verify(mockedSessionService, times(4)).startSession(any(DBObject.class));
    assertEquals(true, result.isSuccess());
    assertEquals("Raised further 4 events and rescheduled self.", result.getData());
    assertEquals(5, result.getNextEvents().size());
    for (int i = 0; i < 4; i++) {
        Event event = result.getNextEvents().get(i);
        assertEquals(EVENT_LOAD_ROOT_RECORD_CATEGORY, event.getName());
        DBObject dataObj = (DBObject) event.getData();
        assertNotNull(dataObj);
        assertEquals(FILEPLAN_CONTEXT, (String) dataObj.get(FIELD_CONTEXT));
        assertEquals(RECORD_CONTAINER_PATH, (String) dataObj.get(FIELD_PATH));
        assertEquals(LOAD_ROOT_CATEGORY_OPERATION, dataObj.get(FIELD_LOAD_OPERATION));
    }
    assertEquals(EVENT_SCHEDULE_SELF, result.getNextEvents().get(4).getName());
}
Also used : EventResult(org.alfresco.bm.event.EventResult) FolderData(org.alfresco.bm.cm.FolderData) Event(org.alfresco.bm.event.Event) DBObject(com.mongodb.DBObject) StopWatch(org.apache.commons.lang3.time.StopWatch) Test(org.junit.Test)

Example 55 with FolderData

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

the class ScheduleFilePlanLoadersUnitTest method testScheduleRootCategoriesWtith0FilePlanDepth.

@Test
public void testScheduleRootCategoriesWtith0FilePlanDepth() throws Exception {
    int maxActiveLoaders = 8;
    int rootCategoriesNumber = 4;
    int categoryStructureDepth = 0;
    scheduleFilePlanLoaders.setMaxActiveLoaders(maxActiveLoaders);
    scheduleFilePlanLoaders.setCategoryNumber(rootCategoriesNumber);
    scheduleFilePlanLoaders.setCategoryStructureDepth(categoryStructureDepth);
    FolderData mockedFilePlanFolder = mock(FolderData.class);
    when(mockedFilePlanFolder.getContext()).thenReturn(FILEPLAN_CONTEXT);
    when(mockedFilePlanFolder.getPath()).thenReturn("/a");
    List<FolderData> folders = Arrays.asList(mockedFilePlanFolder);
    when(mockedFileFolderService.getFoldersByCounts(FILEPLAN_CONTEXT, 3L, 3L, 0L, Long.valueOf(rootCategoriesNumber - 1), null, null, 0, 100)).thenReturn(folders);
    EventResult result = scheduleFilePlanLoaders.processEvent(null, new StopWatch());
    verify(mockedFileFolderService, never()).createNewFolder(any(FolderData.class));
    verify(mockedSessionService, never()).startSession(any(DBObject.class));
    assertEquals(true, result.isSuccess());
    assertEquals("Loading completed.  Raising 'done' event.", result.getData());
    assertEquals(1, result.getNextEvents().size());
    assertEquals(EVENT_FILE_PLANLOADING_COMPLETE, result.getNextEvents().get(0).getName());
}
Also used : EventResult(org.alfresco.bm.event.EventResult) FolderData(org.alfresco.bm.cm.FolderData) DBObject(com.mongodb.DBObject) StopWatch(org.apache.commons.lang3.time.StopWatch) Test(org.junit.Test)

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