use of org.alfresco.rest.rm.community.requests.gscore.api.UnfiledContainerAPI in project records-management by Alfresco.
the class DeclareInPlaceRecordsUnitTest method testDeclareAsRecordWithNotDeclaredFail.
@Test
public void testDeclareAsRecordWithNotDeclaredFail() throws Exception {
String fileId = "testFileId";
String username = "testUserName";
String password = "testPassword";
long delay = 10L;
declareInPlaceRecords.setDeclareInPlaceRecordDelay(delay);
Event mockedEvent = mock(Event.class);
DBObject mockedData = mock(DBObject.class);
when(mockedData.get(FIELD_ID)).thenReturn(fileId);
when(mockedData.get(FIELD_USERNAME)).thenReturn(username);
when(mockedData.get(FIELD_PASSWORD)).thenReturn(password);
when(mockedEvent.getData()).thenReturn(mockedData);
RecordData dbRecord = new RecordData(fileId, RecordContext.IN_PLACE_RECORD, "testFileName", "testFilePath", "testInPlacePath", ExecutionState.SCHEDULED);
when(mockedRecordService.getRecord(fileId)).thenReturn(dbRecord);
FilesAPI mockedFilesAPI = mock(FilesAPI.class);
when(mockedRestAPIFactory.getFilesAPI(any(UserModel.class))).thenReturn(mockedFilesAPI);
Record record = mock(Record.class);
when(record.getName()).thenReturn("newRecordName");
when(record.getParentId()).thenReturn("recordParentId");
when(mockedFilesAPI.declareAsRecord(fileId)).thenReturn(record);
RMRestWrapper mockedRmRestWrapper = mock(RMRestWrapper.class);
when(mockedRmRestWrapper.getStatusCode()).thenReturn(Integer.toString(HttpStatus.CREATED.value()));
when(mockedRestAPIFactory.getRmRestWrapper()).thenReturn(mockedRmRestWrapper);
UnfiledContainer mockedUnfiledContainer = mock(UnfiledContainer.class);
when(mockedUnfiledContainer.getId()).thenReturn("unfiledContainerID");
UnfiledContainerAPI mockedUnfiledContainerAPI = mock(UnfiledContainerAPI.class);
when(mockedUnfiledContainerAPI.getUnfiledContainer(FilePlanComponentAlias.UNFILED_RECORDS_CONTAINER_ALIAS)).thenReturn(mockedUnfiledContainer);
when(mockedRestAPIFactory.getUnfiledContainersAPI()).thenReturn(mockedUnfiledContainerAPI);
when(mockedApplicationContext.getBean("restAPIFactory", RestAPIFactory.class)).thenReturn(mockedRestAPIFactory);
EventResult result = declareInPlaceRecords.processEvent(mockedEvent, new StopWatch());
assertEquals(false, result.isSuccess());
assertEquals("Declaring record with id=" + fileId + " didn't take place.", result.getData());
}
use of org.alfresco.rest.rm.community.requests.gscore.api.UnfiledContainerAPI 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.requests.gscore.api.UnfiledContainerAPI in project records-management by Alfresco.
the class RMBaseEventProcessor method uploadElectronicRecordInUnfiledContext.
/**
* Helper method for uploading one record on specified unfiled container or unfiled record folder.
*
* @param folder - unfiled container or unfiled record folder that will contain uploaded records
* @param userModel - UserModel instance with wich rest api will be called
* @param nameIdentifier - a string identifier that the uploaded records will start with
* @param loadFilePlanComponentDelay - delay between upload record operations
* @throws Exception
*/
public void uploadElectronicRecordInUnfiledContext(FolderData folder, UserModel userModel, String nameIdentifier, // to-check: type of exception
long loadFilePlanComponentDelay) throws // to-check: type of exception
Exception {
String unique;
boolean isUnfiledContainer = fileFolderService.getFolder(UNFILED_CONTEXT, UNFILED_RECORD_CONTAINER_PATH).equals(folder);
String folderPath = folder.getPath();
File file = testFileService.getFile();
if (file == null) {
throw new RuntimeException("No test files exist for upload: " + testFileService);
}
unique = UUID.randomUUID().toString();
String newfilePlanComponentName = nameIdentifier + unique + "-" + file.getName();
String newfilePlanComponentTitle = "title: " + newfilePlanComponentName;
// Build record properties
UnfiledContainerChild unfiledContainerChildModel = UnfiledContainerChild.builder().name(newfilePlanComponentName).nodeType(CONTENT_TYPE).properties(UnfiledContainerChildProperties.builder().title(newfilePlanComponentTitle).description(EMPTY).build()).build();
String newRecordId;
String newRecordName;
if (isUnfiledContainer) {
UnfiledContainerAPI unfiledContainersAPI = getRestAPIFactory().getUnfiledContainersAPI(userModel);
UnfiledContainerChild uploadedRecord = unfiledContainersAPI.uploadRecord(unfiledContainerChildModel, folder.getId(), file);
newRecordId = uploadedRecord.getId();
newRecordName = uploadedRecord.getName();
} else {
UnfiledRecordFolderAPI unfiledRecordFoldersAPI = getRestAPIFactory().getUnfiledRecordFoldersAPI(userModel);
UnfiledContainerChild uploadedRecord = unfiledRecordFoldersAPI.uploadRecord(unfiledContainerChildModel, folder.getId(), file);
newRecordId = uploadedRecord.getId();
newRecordName = uploadedRecord.getName();
}
RecordData record = new RecordData(newRecordId, RecordContext.RECORD, newRecordName, folderPath, null, ExecutionState.UNFILED_RECORD_DECLARED);
recordService.createRecord(record);
fileFolderService.incrementFileCount(folder.getContext(), folderPath, 1);
}
use of org.alfresco.rest.rm.community.requests.gscore.api.UnfiledContainerAPI in project records-management by Alfresco.
the class DeclareInPlaceRecordsUnitTest method testDeclareAsRecordWithSuccess.
@Test
public void testDeclareAsRecordWithSuccess() throws Exception {
String fileId = "testFileId";
String username = "testUserName";
String password = "testPassword";
long delay = 10L;
declareInPlaceRecords.setDeclareInPlaceRecordDelay(delay);
Event mockedEvent = mock(Event.class);
DBObject mockedData = mock(DBObject.class);
when(mockedData.get(FIELD_ID)).thenReturn(fileId);
when(mockedData.get(FIELD_USERNAME)).thenReturn(username);
when(mockedData.get(FIELD_PASSWORD)).thenReturn(password);
when(mockedEvent.getData()).thenReturn(mockedData);
RecordData dbRecord = new RecordData(fileId, RecordContext.IN_PLACE_RECORD, "testFileName", "testFilePath", "testInPlacePath", ExecutionState.SCHEDULED);
when(mockedRecordService.getRecord(fileId)).thenReturn(dbRecord);
FilesAPI mockedFilesAPI = mock(FilesAPI.class);
when(mockedRestAPIFactory.getFilesAPI(any(UserModel.class))).thenReturn(mockedFilesAPI);
Record record = mock(Record.class);
when(record.getName()).thenReturn("newRecordName");
when(record.getParentId()).thenReturn("unfiledContainerID");
when(mockedFilesAPI.declareAsRecord(fileId)).thenReturn(record);
RMRestWrapper mockedRmRestWrapper = mock(RMRestWrapper.class);
when(mockedRmRestWrapper.getStatusCode()).thenReturn(Integer.toString(HttpStatus.CREATED.value()));
when(mockedRestAPIFactory.getRmRestWrapper()).thenReturn(mockedRmRestWrapper);
UnfiledContainer mockedUnfiledContainer = mock(UnfiledContainer.class);
when(mockedUnfiledContainer.getId()).thenReturn("unfiledContainerID");
UnfiledContainerAPI mockedUnfiledContainerAPI = mock(UnfiledContainerAPI.class);
when(mockedUnfiledContainerAPI.getUnfiledContainer(FilePlanComponentAlias.UNFILED_RECORDS_CONTAINER_ALIAS)).thenReturn(mockedUnfiledContainer);
when(mockedRestAPIFactory.getUnfiledContainersAPI()).thenReturn(mockedUnfiledContainerAPI);
FolderData mockedParentFolder = mock(FolderData.class);
when(mockedParentFolder.getPath()).thenReturn(UNFILED_RECORD_CONTAINER_PATH);
when(mockedFileFolderService.getFolder("unfiledContainerID")).thenReturn(mockedParentFolder);
when(mockedApplicationContext.getBean("restAPIFactory", RestAPIFactory.class)).thenReturn(mockedRestAPIFactory);
EventResult result = declareInPlaceRecords.processEvent(mockedEvent, new StopWatch());
assertEquals(true, result.isSuccess());
assertEquals("Declaring file as record: \nsuccess", result.getData());
assertEquals(1, result.getNextEvents().size());
assertEquals(declareInPlaceRecords.getEventNameInPlaceRecordsDeclared(), result.getNextEvents().get(0).getName());
}
use of org.alfresco.rest.rm.community.requests.gscore.api.UnfiledContainerAPI in project records-management by Alfresco.
the class CreateRMSiteUnitTest method testLoadingInDbExistentRmSite.
@Test
public void testLoadingInDbExistentRmSite() 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(mockedData.get(FIELD_ONLY_DB_LOAD)).thenReturn(true);
when(mockedEvent.getData()).thenReturn(mockedData);
when(mockedRestAPIFactory.getRMSiteAPI(any(UserModel.class))).thenReturn(mockedRMSiteAPI);
when(mockedRMSiteAPI.existsRMSite()).thenReturn(true);
String guuid = randomUUID().toString();
when(mockedRMSite.getGuid()).thenReturn(guuid);
when(mockedRMSiteAPI.getSite()).thenReturn(mockedRMSite);
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());
EventResult result = createRMSite.processEvent(mockedEvent);
verify(mockedRMSiteAPI, never()).createRMSite(any(RMSite.class));
verify(mockedSiteDataService, times(1)).addSite(any(SiteData.class));
verify(mockedSiteDataService, times(1)).addSiteMember(any(SiteMemberData.class));
verify(mockedFileFolderService, times(3)).createNewFolder(any(FolderData.class));
assertEquals(true, result.isSuccess());
assertEquals("RM site already exists, just loading it in the DB.", (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);
}
Aggregations