use of org.alfresco.bm.cm.FolderData in project records-management by Alfresco.
the class LoadRecordFolderUnitTest method testLoadRecordFolderOperationWithExceptionOnRestApi.
@Test
public void testLoadRecordFolderOperationWithExceptionOnRestApi() throws Exception {
loadSingleComponent.setEventNameComplete(EVENT_RECORD_FOLDER_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_RECORD_FOLDER_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());
}
use of org.alfresco.bm.cm.FolderData in project records-management by Alfresco.
the class ScheduleUnfiledRecordFolderLoaders method prepareUnfiledRecordFolders.
/**
* Helper method for preparing the load of unfiled record folders children.
*
* @param loaderSessionsToCreate - the number of still active loader sessions
* @param nextEvents - list of prepared events
*/
private void prepareUnfiledRecordFolders(int loaderSessionsToCreate, List<Event> nextEvents) {
int skip = 0;
int limit = 100;
while (nextEvents.size() < loaderSessionsToCreate) {
// Get folders needing loading
List<FolderData> emptyFolders = fileFolderService.getFoldersByCounts(UNFILED_CONTEXT, // min level is 5, level of root unfiled record folders
Long.valueOf(UNFILED_RECORD_CONTAINER_LEVEL + 1), // max level is 4+unfiledRecordFolderDepth-1
Long.valueOf(maxLevel - 1), // limit the maximum number of child folders to rootUnfiledRecordFolderNumber - 1
0L, // limit the maximum number of child folders to rootUnfiledRecordFolderNumber - 1
Long.valueOf(unfiledRecordFolderNumber - 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 = unfiledRecordFolderNumber - (int) emptyFolder.getFolderCount();
auxFileFolderService.incrementFolderCount(emptyFolder.getContext(), emptyFolder.getPath(), toCreateFolders);
folder = auxFileFolderService.getFolder(emptyFolder.getId());
}
int foldersToCreate = (int) folder.getFolderCount();
DBObject loadData = BasicDBObjectBuilder.start().add(FIELD_CONTEXT, emptyFolder.getContext()).add(FIELD_PATH, emptyFolder.getPath()).add(FIELD_LOAD_OPERATION, LOAD_UNFILED_RECORD_FOLDER_OPERATION).get();
int j;
for (j = 0; j < foldersToCreate; j++) {
Event loadEvent = new Event(getEventNameLoadUnfiledRecordFolder(), loadData);
// Each load event must be associated with a session
String recordFolderSessionId = sessionService.startSession(loadData);
loadEvent.setSessionId(recordFolderSessionId);
// Add the event to the list
nextEvents.add(loadEvent);
// Check if we have enough
if (nextEvents.size() >= loaderSessionsToCreate) {
break;
}
}
if (j == foldersToCreate) {
auxFileFolderService.incrementFolderCount(emptyFolder.getContext(), emptyFolder.getPath(), -foldersToCreate);
} else {
auxFileFolderService.incrementFolderCount(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 ScheduleUnfiledRecordFolderLoaders method prepareRootUnfiledRecordFolders.
/**
* Helper method for preparing the events that load the root unfiled record folders.
*
* @param loaderSessionsToCreate - the number of still active loader sessions
* @param nextEvents - list of prepared events
*/
private void prepareRootUnfiledRecordFolders(int loaderSessionsToCreate, List<Event> nextEvents) {
// get unfiledRecordContainer folder
FolderData unfiledRecordContainer = fileFolderService.getFolder(UNFILED_CONTEXT, UNFILED_RECORD_CONTAINER_PATH);
if (rootUnfiledRecordFoldersToLoad == null) {
rootUnfiledRecordFoldersToLoad = Math.max(rootUnfiledRecordFolderNumber - (int) unfiledRecordContainer.getFolderCount(), 0);
}
while (nextEvents.size() < loaderSessionsToCreate) {
if (rootUnfiledRecordFoldersToLoad == 0) {
// No root unfiled record folders needed
break;
}
// Schedule a load for each folder
for (int i = 0; i < rootUnfiledRecordFoldersToLoad; i++) {
DBObject loadData = BasicDBObjectBuilder.start().add(FIELD_CONTEXT, unfiledRecordContainer.getContext()).add(FIELD_PATH, unfiledRecordContainer.getPath()).add(FIELD_LOAD_OPERATION, LOAD_ROOT_UNFILED_RECORD_FOLDER_OPERATION).get();
Event loadEvent = new Event(getEventNameLoadRootUnfiledRecordFolder(), 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);
rootUnfiledRecordFoldersToLoad--;
// 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 ScheduleUnfiledRecordLoaders method calculateListOfEmptyFolders.
/**
* Helper method that initialize the unfiled record folders that can receive loaded unfiled records.
* This method, also calculates the number of records to add to the initialized unfiled record folders.
*/
private void calculateListOfEmptyFolders() {
if (mapOfRecordsPerUnfiledRecordFolder == null) {
mapOfRecordsPerUnfiledRecordFolder = new LinkedHashMap<FolderData, Integer>();
List<FolderData> unfiledRecordFoldersThatNeedRecords = new ArrayList<FolderData>();
if (paths == null || paths.isEmpty()) {
unfiledRecordFoldersThatNeedRecords.addAll(initialiseFoldersToExistingStructure(UNFILED_CONTEXT));
} else {
LinkedHashSet<FolderData> unfiledFolderStructerFromExistentProvidedPaths = new LinkedHashSet<FolderData>();
for (String path : paths) {
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 {
try {
folder = createFolder(path);
unfiledRecordFoldersThatNeedRecords.add(folder);
} catch (Exception e) {
// something went wrong on creating current path structure, not all required paths will be created
}
}
}
// add unfiled record folders from existent paths
if (!unfiledFolderStructerFromExistentProvidedPaths.isEmpty()) {
unfiledRecordFoldersThatNeedRecords.addAll(unfiledFolderStructerFromExistentProvidedPaths);
}
// 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 (unfiledRecordFoldersThatNeedRecords.isEmpty()) {
unfiledRecordFoldersThatNeedRecords.addAll(initialiseFoldersToExistingStructure(UNFILED_CONTEXT));
}
}
if (!unfiledRecordFoldersThatNeedRecords.isEmpty()) {
mapOfRecordsPerUnfiledRecordFolder = distributeNumberOfRecords(unfiledRecordFoldersThatNeedRecords, unfiledRecordsNumber);
}
}
}
use of org.alfresco.bm.cm.FolderData in project records-management by Alfresco.
the class RMBaseEventProcessor method createRootUnfiledRecordFolderWithFixedName.
/**
* Helper method for creating a root unfiled record folder with a specified name.
*
* @param folder - container that will contain created root unfiled record folder
* @param name - the name that created root unfiled record folder will have
* @return created root unfiled record folder with a specified name
* @throws Exception
*/
public FolderData createRootUnfiledRecordFolderWithFixedName(FolderData folder, String name) throws Exception {
FolderData createdFolder = null;
String folderPath = folder.getPath();
String newfilePlanComponentTitle = "title: " + name;
// Build root unfiled record folder properties
UnfiledContainerChild unfiledContainerChildModel = UnfiledContainerChild.builder().name(name).nodeType(UNFILED_RECORD_FOLDER_TYPE).properties(UnfiledContainerChildProperties.builder().title(newfilePlanComponentTitle).description(EMPTY).build()).build();
UnfiledContainerAPI unfiledContainersAPI = getRestAPIFactory().getUnfiledContainersAPI();
UnfiledContainerChild rootUnfiledRecordFolder = unfiledContainersAPI.createUnfiledContainerChild(unfiledContainerChildModel, folder.getId());
String newRootUnfiledRecordFolderId = rootUnfiledRecordFolder.getId();
fileFolderService.createNewFolder(newRootUnfiledRecordFolderId, UNFILED_CONTEXT, folderPath + "/" + name);
// Increment counts
fileFolderService.incrementFolderCount(folder.getContext(), folderPath, 1);
createdFolder = fileFolderService.getFolder(newRootUnfiledRecordFolderId);
return createdFolder;
}
Aggregations