use of org.alfresco.bm.cm.FolderData in project records-management by Alfresco.
the class LoadRecordUnitTest method testLoadRecordOperationWithRestAPiException.
@Test
public void testLoadRecordOperationWithRestAPiException() throws Exception {
loadSingleComponent.setEventNameComplete("recordLoaded");
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_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.getRecordFolderAPI(any(UserModel.class))).thenReturn(mockedRecordFolderAPI);
RecordFolder mockedFilePlanComponent = mock(RecordFolder.class);
when(mockedRecordFolderAPI.getRecordFolder("folderId")).thenReturn(mockedFilePlanComponent);
File mockedFile = mock(File.class);
when(mockedTestFileService.getFile()).thenReturn(mockedFile);
Mockito.doThrow(new Exception("someError")).when(mockedRecordFolderAPI).createRecord(any(Record.class), any(String.class), any(File.class));
mockSiteAndUserData();
EventResult result = loadSingleComponent.processEvent(mockedEvent, new StopWatch());
verify(mockedTestFileService, times(1)).getFile();
verify(mockedRecordFolderAPI, times(1)).createRecord(any(Record.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("someError", 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 LoadRootUnfiledRecordFolderUnitTest method testLoadRootUnfiledRecordFolderOperation.
@Test
public void testLoadRootUnfiledRecordFolderOperation() throws Exception {
loadSingleComponent.setEventNameComplete(EVENT_ROOT_UNFILED_RECORD_FOLDER_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_ROOT_UNFILED_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("someContext", "/aPath")).thenReturn(mockedFolder);
when(mockedEvent.getSessionId()).thenReturn("someId");
when(mockedRestApiFactory.getUnfiledContainersAPI(any(UserModel.class))).thenReturn(mockedUnfiledContainerAPI);
UnfiledContainerChild mockedChildFilePlanComponent = mock(UnfiledContainerChild.class);
when(mockedChildFilePlanComponent.getId()).thenReturn(UUID.randomUUID().toString());
when(mockedUnfiledContainerAPI.createUnfiledContainerChild(any(UnfiledContainerChild.class), eq("folderId"))).thenReturn(mockedChildFilePlanComponent);
mockSiteAndUserData();
EventResult result = loadSingleComponent.processEvent(mockedEvent, new StopWatch());
verify(mockedFileFolderService, times(1)).createNewFolder(any(String.class), any(String.class), any(String.class));
verify(mockedFileFolderService, times(1)).incrementFolderCount(any(String.class), any(String.class), any(Long.class));
assertEquals(true, result.isSuccess());
DBObject data = (DBObject) result.getData();
assertEquals("Created 1 root unfiled record folder.", 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_ROOT_UNFILED_RECORD_FOLDER_LOADED, event.getName());
}
use of org.alfresco.bm.cm.FolderData in project records-management by Alfresco.
the class RMBaseEventProcessorUnitTest method testDistributeNumberOfRecords.
@Test
public void testDistributeNumberOfRecords() throws Exception {
Random random = new Random();
int k = random.nextInt(10) + 1;
List<FolderData> listOfFolders = new ArrayList<FolderData>();
int sum = 0;
for (int i = 0; i < k; i++) {
int filesCount = random.nextInt(5) + 1;
FolderData mockedFolder = mock(FolderData.class);
when(mockedFolder.getFileCount()).thenReturn(Long.valueOf(filesCount));
listOfFolders.add(mockedFolder);
sum += filesCount;
}
int numberOfRecords = random.nextInt(100) + 1;
HashMap<FolderData, Integer> distributeNumberOfRecords = testRMBaseEventProcessor.distributeNumberOfRecords(listOfFolders, numberOfRecords);
int expectedSum = sum + numberOfRecords;
int actualSum = 0;
Collection<Integer> values = distributeNumberOfRecords.values();
for (Integer value : values) {
actualSum += value;
}
assertEquals(expectedSum, actualSum);
}
use of org.alfresco.bm.cm.FolderData in project records-management by Alfresco.
the class RMAbstractLoadComponent method processEvent.
@Override
protected EventResult processEvent(Event event) throws Exception {
super.suspendTimer();
if (event == null) {
throw new IllegalStateException("This processor requires an event.");
}
DBObject dataObj = (DBObject) event.getData();
if (dataObj == null) {
throw new IllegalStateException("This processor requires data with field " + FIELD_PATH);
}
String context = (String) dataObj.get(FIELD_CONTEXT);
String path = (String) dataObj.get(FIELD_PATH);
String operation = (String) dataObj.get(FIELD_LOAD_OPERATION);
if (context == null || path == null || isBlank(operation)) {
return new EventResult("Request data not complete for filing unfiled record: " + dataObj, false);
}
// Get the folder
FolderData folder = fileFolderService.getFolder(context, path);
if (folder == null) {
throw new IllegalStateException("No such folder recorded: " + dataObj);
}
// Get the session
String sessionId = event.getSessionId();
if (sessionId == null) {
return new EventResult("Load scheduling should create a session for each loader.", false);
}
switch(operation) {
case FILE_RECORD_OPERATION:
case LOAD_UNFILED_RECORD_OPERATION:
case LOAD_RECORD_OPERATION:
case LOAD_ROOT_CATEGORY_OPERATION:
case LOAD_SUB_CATEGORY_OPERATION:
case LOAD_RECORD_FOLDER_OPERATION:
case LOAD_ROOT_UNFILED_RECORD_FOLDER_OPERATION:
case LOAD_UNFILED_RECORD_FOLDER_OPERATION:
return loadOperation(folder, dataObj, operation);
default:
throw new IllegalStateException("Unsuported operation: " + operation);
}
}
use of org.alfresco.bm.cm.FolderData in project records-management by Alfresco.
the class RMBaseEventProcessor method createRecordCategoryWithFixedName.
/**
* Helper method for creating a child record category with a specified name.
*
* @param folder - container that will contain created child record category
* @param name - the name that created child record category will have
* @return created child record category with a specified name
* @throws Exception
*/
public FolderData createRecordCategoryWithFixedName(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_CATEGORY_TYPE).properties(RecordCategoryChildProperties.builder().title(newfilePlanComponentTitle).description(EMPTY).build()).build();
RecordCategoryAPI recordCategoryAPI = getRestAPIFactory().getRecordCategoryAPI();
RecordCategoryChild recordCategoryChild = recordCategoryAPI.createRecordCategoryChild(recordCategoryChildModel, folder.getId());
String newRecordCategoryChildId = recordCategoryChild.getId();
fileFolderService.createNewFolder(newRecordCategoryChildId, RECORD_CATEGORY_CONTEXT, folderPath + "/" + name);
// Increment counts
fileFolderService.incrementFolderCount(folder.getContext(), folderPath, 1);
createdFolder = fileFolderService.getFolder(newRecordCategoryChildId);
return createdFolder;
}
Aggregations