use of org.alfresco.rest.rm.community.model.fileplan.FilePlan in project records-management by Alfresco.
the class ScheduleRecordLoadersUnitTest method testUploadRecordsWithNotExistentPreconfiguredPaths.
@Test
public void testUploadRecordsWithNotExistentPreconfiguredPaths() throws Exception {
int maxActiveLoaders = 3;
int recordsNumber = 4;
String configuredPath1 = "/e1/e2/e3";
String configuredPath2 = "/e1/e2/e4";
String paths = configuredPath1 + "," + configuredPath2;
scheduleRecordLoaders.setUploadRecords(true);
scheduleRecordLoaders.setMaxActiveLoaders(maxActiveLoaders);
scheduleRecordLoaders.setRecordsNumber(recordsNumber);
scheduleRecordLoaders.setRecordFolderPaths(paths);
// file plan should be always there
FolderData mockedFilePlanContainer = mock(FolderData.class);
when(mockedFilePlanContainer.getId()).thenReturn("filePlanId");
when(mockedFilePlanContainer.getContext()).thenReturn(FILEPLAN_CONTEXT);
when(mockedFilePlanContainer.getPath()).thenReturn(RECORD_CONTAINER_PATH);
when(mockedFileFolderService.getFolder(FILEPLAN_CONTEXT, RECORD_CONTAINER_PATH)).thenReturn(mockedFilePlanContainer);
when(mockedRestApiFactory.getFilePlansAPI()).thenReturn(mockedFilePlanAPI);
when(mockedRestApiFactory.getRecordCategoryAPI()).thenReturn(mockedRecordCategoryAPI);
FilePlan mockedFilePlan = mock(FilePlan.class);
when(mockedFilePlan.getId()).thenReturn("filePlanId");
when(mockedFilePlanAPI.getFilePlan("filePlanId")).thenReturn(mockedFilePlan);
// e1 root category
RecordCategory mockedE1FilePlanComponent = mock(RecordCategory.class);
when(mockedE1FilePlanComponent.getId()).thenReturn("e1Id");
when(mockedRecordCategoryAPI.getRecordCategory("e1Id")).thenReturn(mockedE1FilePlanComponent);
when(mockedFilePlanAPI.createRootRecordCategory(any(RecordCategory.class), eq("filePlanId"))).thenReturn(mockedE1FilePlanComponent);
String e1Path = RECORD_CONTAINER_PATH + "/e1";
FolderData mockedE1 = mock(FolderData.class);
when(mockedE1.getId()).thenReturn("e1Id");
when(mockedE1.getContext()).thenReturn(RECORD_CATEGORY_CONTEXT);
when(mockedE1.getPath()).thenReturn(e1Path);
when(mockedFileFolderService.getFolder(RECORD_CATEGORY_CONTEXT, e1Path)).thenReturn(null).thenReturn(mockedE1);
when(mockedFileFolderService.getFolder("e1Id")).thenReturn(mockedE1);
// e2 child category
RecordCategory mockedE2childRecordCategory = mock(RecordCategory.class);
when(mockedE2childRecordCategory.getId()).thenReturn("e2Id");
RecordCategoryChild mockedE2RecordCategoryChild = mock(RecordCategoryChild.class);
when(mockedE2RecordCategoryChild.getId()).thenReturn("e2Id");
when(mockedRecordCategoryAPI.getRecordCategory("e2Id")).thenReturn(mockedE2childRecordCategory);
when(mockedRecordCategoryAPI.createRecordCategoryChild(any(RecordCategoryChild.class), eq("e1Id"))).thenReturn(mockedE2RecordCategoryChild);
String e2Path = RECORD_CONTAINER_PATH + "/e1/e2";
FolderData mockedE2 = mock(FolderData.class);
when(mockedE2.getId()).thenReturn("e2Id");
when(mockedE2.getContext()).thenReturn(RECORD_CATEGORY_CONTEXT);
when(mockedE2.getPath()).thenReturn(e2Path);
when(mockedFileFolderService.getFolder(RECORD_CATEGORY_CONTEXT, e2Path)).thenReturn(null).thenReturn(mockedE2);
when(mockedFileFolderService.getFolder("e2Id")).thenReturn(mockedE2);
// e3 record folder
RecordCategoryChild mockedE3RecordFolder = mock(RecordCategoryChild.class);
when(mockedE3RecordFolder.getId()).thenReturn("e3Id");
String e3Path = RECORD_CONTAINER_PATH + "/e1/e2/e3";
FolderData mockedE3 = mock(FolderData.class);
when(mockedE3.getId()).thenReturn("e3Id");
when(mockedE3.getContext()).thenReturn(RECORD_FOLDER_CONTEXT);
when(mockedE3.getPath()).thenReturn(e3Path);
when(mockedFileFolderService.getFolder(RECORD_FOLDER_CONTEXT, e3Path)).thenReturn(null).thenReturn(null).thenReturn(mockedE3);
when(mockedFileFolderService.getFolder("e3Id")).thenReturn(mockedE3);
// e4 record folder
RecordCategoryChild mockedE4RecordFolder = mock(RecordCategoryChild.class);
when(mockedE4RecordFolder.getId()).thenReturn("e4Id");
String e4Path = RECORD_CONTAINER_PATH + "/e1/e2/e4";
FolderData mockedE4 = mock(FolderData.class);
when(mockedE4.getId()).thenReturn("e4Id");
when(mockedE4.getContext()).thenReturn(RECORD_FOLDER_CONTEXT);
when(mockedE4.getPath()).thenReturn(e4Path);
when(mockedFileFolderService.getFolder(RECORD_FOLDER_CONTEXT, e4Path)).thenReturn(null).thenReturn(null).thenReturn(mockedE4);
when(mockedFileFolderService.getFolder("e4Id")).thenReturn(mockedE4);
when(mockedRecordCategoryAPI.createRecordCategoryChild(any(RecordCategoryChild.class), eq("e2Id"))).thenReturn(mockedE3RecordFolder).thenReturn(mockedE4RecordFolder);
when(mockedApplicationContext.getBean("restAPIFactory", RestAPIFactory.class)).thenReturn(mockedRestApiFactory);
EventResult result = scheduleRecordLoaders.processEvent(null, new StopWatch());
verify(mockedFileFolderService, never()).getFoldersByCounts(any(String.class), any(Long.class), any(Long.class), any(Long.class), any(Long.class), any(Long.class), any(Long.class), any(Integer.class), any(Integer.class));
verify(mockedFileFolderService, times(4)).createNewFolder(any(String.class), any(String.class), any(String.class));
verify(mockedFileFolderService, times(4)).incrementFolderCount(any(String.class), any(String.class), eq(1L));
verify(mockedFileFolderService, times(4)).getFolder(any(String.class));
assertEquals(true, result.isSuccess());
verify(mockedSessionService, times(maxActiveLoaders)).startSession(any(DBObject.class));
assertEquals("Raised further " + (maxActiveLoaders) + " events and rescheduled self.", result.getData());
assertEquals(maxActiveLoaders + 1, result.getNextEvents().size());
for (int i = 0; i < maxActiveLoaders; i++) {
Event event = result.getNextEvents().get(i);
assertEquals(EVENT_LOAD_RECORD, event.getName());
DBObject dataObj = (DBObject) event.getData();
assertNotNull(dataObj);
assertEquals(RECORD_FOLDER_CONTEXT, (String) dataObj.get(FIELD_CONTEXT));
assertEquals(LOAD_RECORD_OPERATION, dataObj.get(FIELD_LOAD_OPERATION));
}
assertEquals(EVENT_SCHEDULE_RECORD_LOADERS, result.getNextEvents().get(maxActiveLoaders).getName());
}
use of org.alfresco.rest.rm.community.model.fileplan.FilePlan in project records-management by Alfresco.
the class CreateRMSiteUnitTest method testRMSiteCreation.
@Test
public void testRMSiteCreation() throws Exception {
Event mockedEvent = mock(Event.class);
DBObject mockedData = mock(DBObject.class);
RMSiteAPI mockedRMSiteAPI = mock(RMSiteAPI.class);
RMSite mockedRMSite = mock(RMSite.class);
FilePlanAPI mockedFilePlanAPI = mock(FilePlanAPI.class);
UnfiledContainerAPI mockedUnfiledContainerAPI = mock(UnfiledContainerAPI.class);
TransferContainerAPI mockedTransferContainerAPI = mock(TransferContainerAPI.class);
FilePlan mockedFilePlan = mock(FilePlan.class);
UnfiledContainer mockedUnfiledRecordsContainer = mock(UnfiledContainer.class);
TransferContainer mockedTransfers = mock(TransferContainer.class);
String siteId = randomUUID().toString();
String siteManager = randomUUID().toString();
String password = "password";
when(mockedData.get(FIELD_SITE_ID)).thenReturn(siteId);
when(mockedData.get(FIELD_SITE_MANAGER_NAME)).thenReturn(siteManager);
when(mockedData.get(FIELD_SITE_MANAGER_PASSWORD)).thenReturn(password);
when(mockedEvent.getData()).thenReturn(mockedData);
when(mockedSiteDataService.getSite(siteId)).thenReturn(null);
when(mockedRestAPIFactory.getRMSiteAPI(any(UserModel.class))).thenReturn(mockedRMSiteAPI);
when(mockedRMSiteAPI.createRMSite(any(RMSite.class))).thenReturn(mockedRMSite);
when(mockedRMSiteAPI.existsRMSite()).thenReturn(true);
when(mockedRestAPIFactory.getFilePlansAPI(any(UserModel.class))).thenReturn(mockedFilePlanAPI);
when(mockedFilePlanAPI.getFilePlan(FILE_PLAN_ALIAS)).thenReturn(mockedFilePlan);
when(mockedFilePlan.getId()).thenReturn(randomUUID().toString());
when(mockedRestAPIFactory.getUnfiledContainersAPI(any(UserModel.class))).thenReturn(mockedUnfiledContainerAPI);
when(mockedUnfiledContainerAPI.getUnfiledContainer(UNFILED_RECORDS_CONTAINER_ALIAS)).thenReturn(mockedUnfiledRecordsContainer);
when(mockedUnfiledRecordsContainer.getId()).thenReturn(randomUUID().toString());
when(mockedRestAPIFactory.getTransferContainerAPI(any(UserModel.class))).thenReturn(mockedTransferContainerAPI);
when(mockedTransferContainerAPI.getTransferContainer(TRANSFERS_ALIAS)).thenReturn(mockedTransfers);
when(mockedTransfers.getId()).thenReturn(randomUUID().toString());
RMRestWrapper mockedRmRestWrapper = mock(RMRestWrapper.class);
when(mockedRmRestWrapper.getStatusCode()).thenReturn(HttpStatus.CREATED.toString());
when(mockedRestAPIFactory.getRmRestWrapper()).thenReturn(mockedRmRestWrapper);
EventResult result = createRMSite.processEvent(mockedEvent);
ArgumentCaptor<SiteData> siteData = forClass(SiteData.class);
verify(mockedSiteDataService).addSite(siteData.capture());
ArgumentCaptor<SiteMemberData> siteMemberData = forClass(SiteMemberData.class);
verify(mockedSiteDataService).addSiteMember(siteMemberData.capture());
// Check RM site
SiteData siteDataValue = siteData.getValue();
assertEquals(Scheduled, siteDataValue.getCreationState());
// Check RM admin member
SiteMemberData siteMemberDataValue = siteMemberData.getValue();
assertEquals(Created, siteMemberDataValue.getCreationState());
assertEquals(Administrator.toString(), siteMemberDataValue.getRole());
verify(mockedRMSiteAPI, times(1)).createRMSite(any(RMSite.class));
verify(mockedFileFolderService, times(3)).createNewFolder(any(FolderData.class));
assertEquals(true, result.isSuccess());
assertEquals("Created site: " + siteId + " Site creator: " + siteManager, (String) result.getData());
List<Event> events = result.getNextEvents();
assertEquals(1, events.size());
Event event = events.get(0);
assertEquals(DEFAULT_EVENT_NAME_SITE_CREATED, event.getName());
DBObject data = (DBObject) event.getData();
assertEquals(null, data);
}
use of org.alfresco.rest.rm.community.model.fileplan.FilePlan in project records-management by Alfresco.
the class LoadRootCategoryUnitTest method testLoadRootCategoryOperation.
@Test
public void testLoadRootCategoryOperation() throws Exception {
loadSingleComponent.setEventNameComplete(EVENT_ROOT_RECORD_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_ROOT_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.getFilePlansAPI(any(UserModel.class))).thenReturn(mockedFilePlanAPI);
when(mockedRestApiFactory.getRecordCategoryAPI(any(UserModel.class))).thenReturn(mockedRecordCategoryAPI);
FilePlan mockedFilePlanComponent = mock(FilePlan.class);
when(mockedFilePlanComponent.getId()).thenReturn("folderId");
when(mockedFilePlanAPI.getFilePlan("folderId")).thenReturn(mockedFilePlanComponent);
RecordCategory mockedChildFilePlanComponent = mock(RecordCategory.class);
when(mockedChildFilePlanComponent.getId()).thenReturn(UUID.randomUUID().toString());
when(mockedFilePlanAPI.createRootRecordCategory(any(RecordCategory.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 category.", 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_RECORD_CATEGORY_LOADED, event.getName());
}
use of org.alfresco.rest.rm.community.model.fileplan.FilePlan in project records-management by Alfresco.
the class CreateRMSite method loadSpecialContainersInDB.
private void loadSpecialContainersInDB(String siteId, String siteManager, String password) throws Exception {
UserModel userModel = new UserModel(siteManager, password);
FilePlan filePlanEntity = restAPIFactory.getFilePlansAPI(userModel).getFilePlan(FILE_PLAN_ALIAS);
FolderData filePlan = new FolderData(// already unique
filePlanEntity.getId(), FILEPLAN_CONTEXT, "/" + PATH_SNIPPET_SITES + "/" + siteId + "/" + PATH_SNIPPET_FILE_PLAN, 0L, 0L);
fileFolderService.createNewFolder(filePlan);
// add Unfiled record container
UnfiledContainer unfiledContainer = restAPIFactory.getUnfiledContainersAPI(userModel).getUnfiledContainer(UNFILED_RECORDS_CONTAINER_ALIAS);
FolderData unfiledRecordContainer = new FolderData(// already unique
unfiledContainer.getId(), UNFILED_CONTEXT, "/" + PATH_SNIPPET_SITES + "/" + siteId + "/" + PATH_SNIPPET_FILE_PLAN + "/" + PATH_SNIPPET_UNFILED_RECORD_CONTAINER, 0L, 0L);
fileFolderService.createNewFolder(unfiledRecordContainer);
// add Transfer container
TransferContainer transferContainerEntity = restAPIFactory.getTransferContainerAPI(userModel).getTransferContainer(TRANSFERS_ALIAS);
FolderData transferContainer = new FolderData(// already unique
transferContainerEntity.getId(), TRANSFER_CONTEXT, "/" + PATH_SNIPPET_SITES + "/" + siteId + "/" + PATH_SNIPPET_FILE_PLAN + "/" + PATH_SNIPPET_TRANSFER_CONTAINER, 0L, 0L);
fileFolderService.createNewFolder(transferContainer);
}
use of org.alfresco.rest.rm.community.model.fileplan.FilePlan in project records-management by Alfresco.
the class ScheduleRecordLoadersUnitTest method testUploadRecordsWithNotExistentPreconfiguredSinglePath.
@Test
public void testUploadRecordsWithNotExistentPreconfiguredSinglePath() throws Exception {
int maxActiveLoaders = 8;
int recordsNumber = 4;
String configuredPath1 = "/e1/e2/e3";
String paths = configuredPath1;
scheduleRecordLoaders.setUploadRecords(true);
scheduleRecordLoaders.setMaxActiveLoaders(maxActiveLoaders);
scheduleRecordLoaders.setRecordsNumber(recordsNumber);
scheduleRecordLoaders.setRecordFolderPaths(paths);
// file plan should be always there
FolderData mockedFilePlanContainer = mock(FolderData.class);
when(mockedFilePlanContainer.getId()).thenReturn("filePlanId");
when(mockedFilePlanContainer.getContext()).thenReturn(FILEPLAN_CONTEXT);
when(mockedFilePlanContainer.getPath()).thenReturn(RECORD_CONTAINER_PATH);
when(mockedFileFolderService.getFolder(FILEPLAN_CONTEXT, RECORD_CONTAINER_PATH)).thenReturn(mockedFilePlanContainer);
when(mockedRestApiFactory.getFilePlansAPI()).thenReturn(mockedFilePlanAPI);
when(mockedRestApiFactory.getRecordCategoryAPI()).thenReturn(mockedRecordCategoryAPI);
FilePlan mockedFilePlan = mock(FilePlan.class);
when(mockedFilePlan.getId()).thenReturn("filePlanId");
when(mockedFilePlanAPI.getFilePlan("filePlanId")).thenReturn(mockedFilePlan);
// e1 root category
RecordCategory mockedE1FilePlanComponent = mock(RecordCategory.class);
when(mockedE1FilePlanComponent.getId()).thenReturn("e1Id");
when(mockedRecordCategoryAPI.getRecordCategory("e1Id")).thenReturn(mockedE1FilePlanComponent);
when(mockedFilePlanAPI.createRootRecordCategory(any(RecordCategory.class), eq("filePlanId"))).thenReturn(mockedE1FilePlanComponent);
String e1Path = RECORD_CONTAINER_PATH + "/e1";
FolderData mockedE1 = mock(FolderData.class);
when(mockedE1.getId()).thenReturn("e1Id");
when(mockedE1.getContext()).thenReturn(RECORD_CATEGORY_CONTEXT);
when(mockedE1.getPath()).thenReturn(e1Path);
when(mockedFileFolderService.getFolder(RECORD_CATEGORY_CONTEXT, e1Path)).thenReturn(null).thenReturn(mockedE1);
when(mockedFileFolderService.getFolder("e1Id")).thenReturn(mockedE1);
// e2 child category
RecordCategory mockedE2childRecordCategory = mock(RecordCategory.class);
when(mockedE2childRecordCategory.getId()).thenReturn("e2Id");
RecordCategoryChild mockedE2RecordCategoryChild = mock(RecordCategoryChild.class);
when(mockedE2RecordCategoryChild.getId()).thenReturn("e2Id");
when(mockedRecordCategoryAPI.getRecordCategory("e2Id")).thenReturn(mockedE2childRecordCategory);
when(mockedRecordCategoryAPI.createRecordCategoryChild(any(RecordCategoryChild.class), eq("e1Id"))).thenReturn(mockedE2RecordCategoryChild);
String e2Path = RECORD_CONTAINER_PATH + "/e1/e2";
FolderData mockedE2 = mock(FolderData.class);
when(mockedE2.getId()).thenReturn("e2Id");
when(mockedE2.getContext()).thenReturn(RECORD_CATEGORY_CONTEXT);
when(mockedE2.getPath()).thenReturn(e2Path);
when(mockedFileFolderService.getFolder(RECORD_CATEGORY_CONTEXT, e2Path)).thenReturn(null).thenReturn(mockedE2);
when(mockedFileFolderService.getFolder("e2Id")).thenReturn(mockedE2);
// e3 record folder
RecordCategoryChild mockedE3RecordFolder = mock(RecordCategoryChild.class);
when(mockedE3RecordFolder.getId()).thenReturn("e3Id");
String e3Path = RECORD_CONTAINER_PATH + "/e1/e2/e3";
FolderData mockedE3 = mock(FolderData.class);
when(mockedE3.getId()).thenReturn("e3Id");
when(mockedE3.getContext()).thenReturn(RECORD_FOLDER_CONTEXT);
when(mockedE3.getPath()).thenReturn(e3Path);
when(mockedFileFolderService.getFolder(RECORD_FOLDER_CONTEXT, e3Path)).thenReturn(null).thenReturn(null).thenReturn(mockedE3);
when(mockedFileFolderService.getFolder("e3Id")).thenReturn(mockedE3);
when(mockedRecordCategoryAPI.createRecordCategoryChild(any(RecordCategoryChild.class), eq("e2Id"))).thenReturn(mockedE3RecordFolder);
when(mockedApplicationContext.getBean("restAPIFactory", RestAPIFactory.class)).thenReturn(mockedRestApiFactory);
EventResult result = scheduleRecordLoaders.processEvent(null, new StopWatch());
verify(mockedFileFolderService, never()).getFoldersByCounts(any(String.class), any(Long.class), any(Long.class), any(Long.class), any(Long.class), any(Long.class), any(Long.class), any(Integer.class), any(Integer.class));
verify(mockedFileFolderService, times(3)).createNewFolder(any(String.class), any(String.class), any(String.class));
verify(mockedFileFolderService, times(3)).incrementFolderCount(any(String.class), any(String.class), eq(1L));
verify(mockedFileFolderService, times(3)).getFolder(any(String.class));
verify(mockedSessionService, times(recordsNumber)).startSession(any(DBObject.class));
assertEquals(true, result.isSuccess());
assertEquals("Raised further " + (recordsNumber) + " events and rescheduled self.", result.getData());
assertEquals(recordsNumber + 1, result.getNextEvents().size());
for (int i = 0; i < recordsNumber; i++) {
Event event = result.getNextEvents().get(i);
assertEquals(EVENT_LOAD_RECORD, event.getName());
DBObject dataObj = (DBObject) event.getData();
assertNotNull(dataObj);
assertEquals(RECORD_FOLDER_CONTEXT, (String) dataObj.get(FIELD_CONTEXT));
assertEquals(LOAD_RECORD_OPERATION, dataObj.get(FIELD_LOAD_OPERATION));
}
assertEquals(EVENT_SCHEDULE_RECORD_LOADERS, result.getNextEvents().get(recordsNumber).getName());
}
Aggregations