use of org.alfresco.bm.cm.FolderData in project records-management by Alfresco.
the class LoadUnfiledRecordUnitTest method testLoadUnfiledRecordOperationInUnfiledRecordFolderWithNoFileException.
@Test
public void testLoadUnfiledRecordOperationInUnfiledRecordFolderWithNoFileException() throws Exception {
loadSingleComponent.setEventNameComplete(EVENT_UNFILED_RECORD_LOADED);
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(LOAD_UNFILED_RECORD_OPERATION);
when(mockedEvent.getData()).thenReturn(mockedData);
FolderData mockedFolder = mock(FolderData.class);
when(mockedFolder.getId()).thenReturn("folderId");
when(mockedFolder.getPath()).thenReturn("/aPath");
when(mockedFolder.getContext()).thenReturn("someContext");
when(mockedFileFolderService.getFolder("someContext", "/aPath")).thenReturn(mockedFolder);
when(mockedEvent.getSessionId()).thenReturn("someId");
when(mockedRestApiFactory.getUnfiledContainersAPI(any(UserModel.class))).thenReturn(mockedUnfiledContainerAPI);
when(mockedRestApiFactory.getUnfiledRecordFoldersAPI(any(UserModel.class))).thenReturn(mockedUnfiledRecordFolderAPI);
FolderData mockedFolder1 = mock(FolderData.class);
when(mockedFileFolderService.getFolder(UNFILED_CONTEXT, UNFILED_RECORD_CONTAINER_PATH)).thenReturn(mockedFolder1);
mockSiteAndUserData();
EventResult result = loadSingleComponent.processEvent(mockedEvent, new StopWatch());
verify(mockedFileFolderService, never()).deleteFolder(mockedFolder.getContext(), mockedFolder.getPath() + "/locked", false);
verify(mockedTestFileService, times(1)).getFile();
verify(mockedUnfiledRecordFolderAPI, never()).uploadRecord(any(UnfiledContainerChild.class), eq("folderId"), any(File.class));
verify(mockedFileFolderService, never()).incrementFileCount(any(String.class), any(String.class), any(Long.class));
assertEquals(false, result.isSuccess());
DBObject data = (DBObject) result.getData();
assertNotNull(data.get("error"));
assertEquals("No test files exist for upload: mockedTestFileService", data.get("error"));
assertEquals("aUser", data.get("username"));
assertEquals(mockedFolder.getPath(), data.get("path"));
assertNotNull(data.get("stack"));
assertEquals(0, result.getNextEvents().size());
}
use of org.alfresco.bm.cm.FolderData in project records-management by Alfresco.
the class ScheduleFilePlanLoaders method calculateMaxChildren.
/**
* Helper method to calculate maximum children that one category should have in order to be returned in search result for categories that still need sub-categories and record folders.
*/
private void calculateMaxChildren() {
if (maxChildren == null) {
// get one category to check existing number of categories and record folders
List<FolderData> categories = fileFolderService.getFoldersByCounts(RECORD_CATEGORY_CONTEXT, // ignore levels
null, // ignore levels
null, // ignore folder limits
null, // ignore folder limits
null, // Ignore file limits
null, // Ignore file limits
null, 0, 1);
if (folderCategoryMix) {
maxChildren = folderNumber + childCategNumber - 1;
if (!categories.isEmpty()) {
FolderData existentRecordCategory = categories.get(0);
int childCategoriesNumber = getDirectChildrenByContext(existentRecordCategory, RECORD_CATEGORY_CONTEXT).size();
int childRecordFoldersNumber = getDirectChildrenByContext(existentRecordCategory, RECORD_FOLDER_CONTEXT).size();
maxChildren = Math.max(folderNumber, childRecordFoldersNumber) + Math.max(childCategNumber, childCategoriesNumber) - 1;
}
} else {
maxChildren = childCategNumber - 1;
if (!categories.isEmpty()) {
FolderData existentRecordCategory = categories.get(0);
int childCategoriesNumber = getDirectChildrenByContext(existentRecordCategory, RECORD_CATEGORY_CONTEXT).size();
int folderCount = (int) existentRecordCategory.getFolderCount();
maxChildren = Math.max(folderCount, folderCount + childCategNumber - childCategoriesNumber) - 1;
}
}
}
}
use of org.alfresco.bm.cm.FolderData in project records-management by Alfresco.
the class ScheduleFilingUnfiledRecords method prepareUnfiledRecords.
/**
* Helper method for preparing events for filing unfiled 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 prepareUnfiledRecords(int loaderSessionsToCreate, List<Event> nextEvents) {
int numberOfRecords = recordFilingLimit;
// initialiaze the number of records to file to all only once if the limit is set to 0
if (mapOfRecordsPerRecordFolder == null && recordFilingLimit == 0) {
List<String> listOfUnfiledRecordFoldersPaths = null;
if (fileFromUnfiledPaths != null && fileFromUnfiledPaths.size() > 0) {
listOfUnfiledRecordFoldersPaths = getListOfUnfiledRecordFoldersPaths();
}
numberOfRecords = (int) recordService.getRecordCountInSpecifiedPaths(ExecutionState.UNFILED_RECORD_DECLARED.name(), listOfUnfiledRecordFoldersPaths);
}
// if the number of records to load is not greater than 0, nothing to file
if (mapOfRecordsPerRecordFolder == null && numberOfRecords == 0) {
return;
}
mapOfRecordsPerRecordFolder = calculateListOfEmptyFolders(mapOfRecordsPerRecordFolder, fileToRecordFolderPaths, numberOfRecords);
List<FolderData> emptyFolders = new ArrayList<FolderData>();
emptyFolders.addAll(mapOfRecordsPerRecordFolder.keySet());
while (nextEvents.size() < loaderSessionsToCreate) {
if (mapOfRecordsPerRecordFolder == null || mapOfRecordsPerRecordFolder.size() == 0) {
break;
}
// Schedule a load for each folder
for (FolderData emptyFolder : emptyFolders) {
int recordsToFile = mapOfRecordsPerRecordFolder.get(emptyFolder) - (int) emptyFolder.getFileCount();
if (recordsToFile <= 0) {
mapOfRecordsPerRecordFolder.remove(emptyFolder);
} else {
try {
List<String> listOfUnfiledRecordFoldersPaths = null;
if (fileFromUnfiledPaths != null && fileFromUnfiledPaths.size() > 0) {
listOfUnfiledRecordFoldersPaths = getListOfUnfiledRecordFoldersPaths();
}
boolean notEnoughRecordsInDb = false;
int i;
for (i = 0; i < recordsToFile; i++) {
RecordData randomRecord = recordService.getRandomRecord(ExecutionState.UNFILED_RECORD_DECLARED.name(), listOfUnfiledRecordFoldersPaths);
if (randomRecord == null) {
notEnoughRecordsInDb = true;
break;
}
DBObject loadData = BasicDBObjectBuilder.start().add(FIELD_CONTEXT, emptyFolder.getContext()).add(FIELD_PATH, emptyFolder.getPath()).add(FIELD_LOAD_OPERATION, FILE_RECORD_OPERATION).add(FIELD_RECORD_ID, randomRecord.getId()).get();
Event loadEvent = new Event(getEventNameFileUnfiledRecords(), 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);
randomRecord.setExecutionState(ExecutionState.UNFILED_RECORD_SCHEDULED_FOR_FILING);
recordService.updateRecord(randomRecord);
// Check if we have enough
if (nextEvents.size() >= loaderSessionsToCreate) {
break;
}
}
if (// all records prepared for this folder
i == recordsToFile) {
mapOfRecordsPerRecordFolder.remove(emptyFolder);
} else // did not reached the end of the for
{
if (// exited because there are no more records to file in mongoDB
notEnoughRecordsInDb) {
mapOfRecordsPerRecordFolder = null;
break;
} else // exited because reached maximum active loaders
{
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 ScheduleFilingUnfiledRecords method getListOfUnfiledRecordFoldersPaths.
/**
* Helper method for obtaining parent paths to file unfiled records from.
*
* @return all parent paths to file unfiled records from.
*/
private List<String> getListOfUnfiledRecordFoldersPaths() {
LinkedHashSet<String> allUnfiledParentPaths = getAllUnfiledParentPaths();
List<String> availableUnfiledRecordFolderPaths = new ArrayList<>();
LinkedHashSet<FolderData> unfiledFolderStructerFromExistentProvidedPaths = new LinkedHashSet<FolderData>();
for (String path : fileFromUnfiledPaths) {
if (path.equals("/")) {
path = "";
} else if (!path.startsWith("/")) {
path = "/" + path;
}
FolderData folder = fileFolderService.getFolder(UNFILED_CONTEXT, UNFILED_RECORD_CONTAINER_PATH + path);
if (// if folder exists
folder != null) {
unfiledFolderStructerFromExistentProvidedPaths.addAll(getUnfiledRecordFolders(folder));
} else {
// unfiledRecordFolder with specified path does not exist
}
}
// add unfiled record folders from existent paths
if (unfiledFolderStructerFromExistentProvidedPaths.size() > 0) {
for (FolderData availableFolder : unfiledFolderStructerFromExistentProvidedPaths) {
String availableFolderPath = availableFolder.getPath();
if (allUnfiledParentPaths.contains(availableFolderPath)) {
availableUnfiledRecordFolderPaths.add(availableFolderPath);
}
}
}
// configured paths did not existed in db and something went wrong with creation for all of them, initialize to existing structure in this case
if (availableUnfiledRecordFolderPaths.size() == 0) {
availableUnfiledRecordFolderPaths.addAll(allUnfiledParentPaths);
}
return availableUnfiledRecordFolderPaths;
}
use of org.alfresco.bm.cm.FolderData in project records-management by Alfresco.
the class LoadSubCategoryUnitTest method testLoadSubCategoryOperationWithExceptionOnRestApi.
@Test
public void testLoadSubCategoryOperationWithExceptionOnRestApi() throws Exception {
loadSingleComponent.setEventNameComplete(EVENT_SUB_CATEGORY_LOADED);
Event mockedEvent = mock(Event.class);
DBObject mockedData = mock(DBObject.class);
when(mockedData.get(FIELD_CONTEXT)).thenReturn(FILEPLAN_CONTEXT);
when(mockedData.get(FIELD_PATH)).thenReturn("/aPath");
when(mockedData.get(FIELD_LOAD_OPERATION)).thenReturn(LOAD_SUB_CATEGORY_OPERATION);
when(mockedEvent.getData()).thenReturn(mockedData);
FolderData mockedFolder = mock(FolderData.class);
when(mockedFolder.getId()).thenReturn("folderId");
when(mockedFolder.getPath()).thenReturn("/aPath");
when(mockedFileFolderService.getFolder(FILEPLAN_CONTEXT, "/aPath")).thenReturn(mockedFolder);
loadSingleComponent.setFileFolderService(mockedFileFolderService);
when(mockedEvent.getSessionId()).thenReturn("someId");
when(mockedRestApiFactory.getRecordCategoryAPI(any(UserModel.class))).thenReturn(mockedRecordCategoryAPI);
Mockito.doThrow(new Exception("someError")).when(mockedRecordCategoryAPI).createRecordCategoryChild(any(RecordCategoryChild.class), any(String.class));
mockSiteAndUserData();
EventResult result = loadSingleComponent.processEvent(mockedEvent, new StopWatch());
verify(mockedFileFolderService, never()).createNewFolder(any(String.class), any(String.class), any(String.class));
verify(mockedFileFolderService, never()).incrementFolderCount(any(String.class), any(String.class), any(Long.class));
assertEquals(false, result.isSuccess());
DBObject data = (DBObject) result.getData();
assertNotNull(data.get("error"));
assertEquals("aUser", data.get("username"));
assertEquals(mockedFolder.getPath(), data.get("path"));
assertNotNull(data.get("stack"));
assertEquals(0, result.getNextEvents().size());
}
Aggregations