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;
}
}
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;
}
}
}
}
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());
}
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());
}
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());
}
Aggregations