use of org.alfresco.bm.cm.FolderData in project records-management by Alfresco.
the class RMBaseEventProcessor method createRootRecordCategoryWithFixedName.
/**
* Helper method for creating a root record category with a specified name.
*
* @param folder - container that will contain created root record category
* @param name - the name that created root record category will have
* @return created root record category with a specified name
* @throws Exception
*/
public FolderData createRootRecordCategoryWithFixedName(FolderData folder, String name) throws Exception {
FolderData createdFolder = null;
String folderPath = folder.getPath();
String newfilePlanComponentTitle = "title: " + name;
// Build root category properties
RecordCategory recordCategoryModel = RecordCategory.builder().name(name).nodeType(RECORD_CATEGORY_TYPE).properties(RecordCategoryProperties.builder().title(newfilePlanComponentTitle).description(EMPTY).build()).build();
FilePlanAPI filePlansAPI = getRestAPIFactory().getFilePlansAPI();
RecordCategory rootCategory = filePlansAPI.createRootRecordCategory(recordCategoryModel, folder.getId());
String newRootCategoryId = rootCategory.getId();
fileFolderService.createNewFolder(newRootCategoryId, RECORD_CATEGORY_CONTEXT, folderPath + "/" + name);
// Increment counts
fileFolderService.incrementFolderCount(folder.getContext(), folderPath, 1);
createdFolder = fileFolderService.getFolder(newRootCategoryId);
return createdFolder;
}
use of org.alfresco.bm.cm.FolderData in project records-management by Alfresco.
the class RMBaseEventProcessor method distributeNumberOfRecords.
/**
* Helper method to distribute the number of records to create on the given list of folders.
*
* @param listOfFolders - list of available folders to distribute records into
* @param numberOfRecords - number of records to be distributed
* @return a map with folders as keys and the number of records to create on that folder as values.
*/
public LinkedHashMap<FolderData, Integer> distributeNumberOfRecords(List<FolderData> listOfFolders, int numberOfRecords) {
LinkedHashMap<FolderData, Integer> mapOfRecordsPerFolder = new LinkedHashMap<FolderData, Integer>();
int[] generateRandomValues = generateRandomValues(listOfFolders.size(), numberOfRecords);
int counter = 0;
for (FolderData folder : listOfFolders) {
int records = (int) (folder.getFileCount() + generateRandomValues[counter]);
mapOfRecordsPerFolder.put(folder, records);
counter++;
}
return mapOfRecordsPerFolder;
}
use of org.alfresco.bm.cm.FolderData in project records-management by Alfresco.
the class RMBaseEventProcessor method calculateListOfEmptyFolders.
/**
* Helper method that initialize the record folders that can receive records.
* This method, also calculates the number of records to add to the initialized record folders.
*
* @param mapOfRecordsPerRecordFolder - linked hash map with available record folders as keys and calculated number of records to load/file in each record folder
* @param paths - record category or record folder paths to load/file records in
* @param numberOrRecords - number of records to load/file
*/
public LinkedHashMap<FolderData, Integer> calculateListOfEmptyFolders(LinkedHashMap<FolderData, Integer> mapOfRecordsPerRecordFolder, List<String> paths, int numberOrRecords) {
if (mapOfRecordsPerRecordFolder == null) {
mapOfRecordsPerRecordFolder = new LinkedHashMap<FolderData, Integer>();
List<FolderData> recordFoldersThatNeedRecords = new ArrayList<FolderData>();
if (paths == null || paths.isEmpty()) {
// get the existing file plan folder structure
recordFoldersThatNeedRecords.addAll(initialiseFoldersToExistingStructure(RECORD_FOLDER_CONTEXT));
} else {
LinkedHashSet<FolderData> structureFromExistentProvidedPaths = new LinkedHashSet<FolderData>();
for (String path : paths) {
if (!path.startsWith("/")) {
path = "/" + path;
}
// if the path is category and exists
FolderData folder = fileFolderService.getFolder(RECORD_CATEGORY_CONTEXT, RECORD_CONTAINER_PATH + path);
if (// if folder is not a category verify if it is a record folder and exists
folder == null) {
folder = fileFolderService.getFolder(RECORD_FOLDER_CONTEXT, RECORD_CONTAINER_PATH + path);
}
if (// if folder exists
folder != null) {
structureFromExistentProvidedPaths.addAll(getRecordFolders(folder));
} else {
try {
folder = createRecordCategoryOrRecordFolder(path);
recordFoldersThatNeedRecords.add(folder);
} catch (Exception e) {
// something went wrong on creating current path structure, not all required paths will be created
logger.debug("Path elements of " + path + "could not be created.", e);
}
}
}
// add record folders from existent paths
if (!structureFromExistentProvidedPaths.isEmpty()) {
recordFoldersThatNeedRecords.addAll(structureFromExistentProvidedPaths);
}
// initialize to existing structure in this case
if (recordFoldersThatNeedRecords.isEmpty()) {
recordFoldersThatNeedRecords.addAll(initialiseFoldersToExistingStructure(RECORD_FOLDER_CONTEXT));
}
}
if (!recordFoldersThatNeedRecords.isEmpty()) {
mapOfRecordsPerRecordFolder = distributeNumberOfRecords(recordFoldersThatNeedRecords, numberOrRecords);
}
}
return mapOfRecordsPerRecordFolder;
}
use of org.alfresco.bm.cm.FolderData in project records-management by Alfresco.
the class RMBaseEventProcessor method createRecordFolderWithFixedName.
/**
* Helper method for creating a child record folder with a specified name.
*
* @param folder - container that will contain created child record folder
* @param name - the name that created child record folder will have
* @return created child record folder with a specified name
* @throws Exception
*/
public FolderData createRecordFolderWithFixedName(FolderData folder, String name) throws Exception {
FolderData createdFolder = null;
String folderPath = folder.getPath();
String newfilePlanComponentTitle = "title: " + name;
// Build filePlan component records folder properties
RecordCategoryChild recordCategoryChildModel = RecordCategoryChild.builder().name(name).nodeType(RECORD_FOLDER_TYPE).properties(RecordCategoryChildProperties.builder().title(newfilePlanComponentTitle).description(EMPTY).build()).build();
RecordCategoryAPI recordCategoryAPI = getRestAPIFactory().getRecordCategoryAPI();
RecordCategoryChild recordFolderChild = recordCategoryAPI.createRecordCategoryChild(recordCategoryChildModel, folder.getId());
String newRecordFolderChildId = recordFolderChild.getId();
fileFolderService.createNewFolder(newRecordFolderChildId, RECORD_FOLDER_CONTEXT, folderPath + "/" + name);
// Increment counts
fileFolderService.incrementFolderCount(folder.getContext(), folderPath, 1);
createdFolder = fileFolderService.getFolder(newRecordFolderChildId);
return createdFolder;
}
use of org.alfresco.bm.cm.FolderData in project records-management by Alfresco.
the class LoadUnfiledRecordUnitTest method testLoadUnfiledRecordOperationInUnfiledRecordFolder.
@Test
public void testLoadUnfiledRecordOperationInUnfiledRecordFolder() throws Exception {
loadSingleComponent.setEventNameComplete(EVENT_UNFILED_RECORD_LOADED);
loadSingleComponent.setDelay(1L);
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);
UnfiledContainerChild mockRecord1 = mock(UnfiledContainerChild.class);
String recordId1 = "recordId1";
String recordName1 = "recordName1";
when(mockRecord1.getId()).thenReturn(recordId1);
when(mockRecord1.getName()).thenReturn(recordName1);
when(mockedUnfiledRecordFolderAPI.uploadRecord(any(UnfiledContainerChild.class), eq("folderId"), any(File.class))).thenReturn(mockRecord1).thenReturn(null);
File mockedFile = mock(File.class);
when(mockedTestFileService.getFile()).thenReturn(mockedFile);
mockSiteAndUserData();
EventResult result = loadSingleComponent.processEvent(mockedEvent, new StopWatch());
verify(mockedTestFileService, times(1)).getFile();
verify(mockedUnfiledRecordFolderAPI, times(1)).uploadRecord(any(UnfiledContainerChild.class), eq("folderId"), any(File.class));
verify(mockedFileFolderService, times(1)).incrementFileCount(any(String.class), any(String.class), any(Long.class));
assertEquals(true, result.isSuccess());
DBObject data = (DBObject) result.getData();
assertEquals("Created 1 record.", data.get("msg"));
assertEquals("/aPath", data.get(FIELD_PATH));
assertEquals("aUser", data.get("username"));
assertEquals(1, result.getNextEvents().size());
Event event = result.getNextEvents().get(0);
assertEquals(EVENT_UNFILED_RECORD_LOADED, event.getName());
DBObject eventData = (DBObject) event.getData();
assertEquals("someContext", eventData.get(FIELD_CONTEXT));
assertEquals("/aPath", eventData.get(FIELD_PATH));
}
Aggregations