Search in sources :

Example 1 with FilePlanAPI

use of org.alfresco.rest.rm.community.requests.gscore.api.FilePlanAPI 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);
}
Also used : SiteData(org.alfresco.bm.site.SiteData) FilePlan(org.alfresco.rest.rm.community.model.fileplan.FilePlan) DBObject(com.mongodb.DBObject) FilePlanAPI(org.alfresco.rest.rm.community.requests.gscore.api.FilePlanAPI) UnfiledContainer(org.alfresco.rest.rm.community.model.unfiledcontainer.UnfiledContainer) UserModel(org.alfresco.utility.model.UserModel) RMSiteAPI(org.alfresco.rest.rm.community.requests.gscore.api.RMSiteAPI) TransferContainer(org.alfresco.rest.rm.community.model.transfercontainer.TransferContainer) SiteMemberData(org.alfresco.bm.site.SiteMemberData) RMSite(org.alfresco.rest.rm.community.model.site.RMSite) EventResult(org.alfresco.bm.event.EventResult) FolderData(org.alfresco.bm.cm.FolderData) TransferContainerAPI(org.alfresco.rest.rm.community.requests.gscore.api.TransferContainerAPI) Event(org.alfresco.bm.event.Event) UnfiledContainerAPI(org.alfresco.rest.rm.community.requests.gscore.api.UnfiledContainerAPI) RMRestWrapper(org.alfresco.rest.core.RMRestWrapper) Test(org.junit.Test)

Example 2 with FilePlanAPI

use of org.alfresco.rest.rm.community.requests.gscore.api.FilePlanAPI in project records-management by Alfresco.

the class RMBaseEventProcessor method createRootCategory.

/**
 * Helper method for creating one root record category with the name starting with provided nameIdentifier and a random generated string.
 *
 * @param folder - container that will contain created root record categories
 * @param userModel - UserModel instance with which rest api will be called
 * @param nameIdentifier - a string identifier that the created root record categories will start with
 * @param context - the context for created root record categories
 * @param loadFilePlanComponentDelay - delay between creation of root record categories
 * @throws Exception
 */
public void createRootCategory(FolderData folder, UserModel userModel, String nameIdentifier, String context, long loadFilePlanComponentDelay) throws Exception {
    String unique;
    String folderPath = folder.getPath();
    unique = UUID.randomUUID().toString();
    String newfilePlanComponentName = nameIdentifier + unique;
    String newfilePlanComponentTitle = "title: " + newfilePlanComponentName;
    // Build root record category properties
    RecordCategory recordCategoryModel = RecordCategory.builder().name(newfilePlanComponentName).nodeType(RECORD_CATEGORY_TYPE).properties(RecordCategoryProperties.builder().title(newfilePlanComponentTitle).description(EMPTY).build()).build();
    FilePlanAPI filePlansAPI = getRestAPIFactory().getFilePlansAPI(userModel);
    RecordCategory rootRecordCategory = filePlansAPI.createRootRecordCategory(recordCategoryModel, folder.getId());
    String newRootRecordCategoryId = rootRecordCategory.getId();
    fileFolderService.createNewFolder(newRootRecordCategoryId, context, folderPath + "/" + newfilePlanComponentName);
    TimeUnit.MILLISECONDS.sleep(loadFilePlanComponentDelay);
    // Increment counts
    fileFolderService.incrementFolderCount(folder.getContext(), folderPath, 1);
}
Also used : FilePlanAPI(org.alfresco.rest.rm.community.requests.gscore.api.FilePlanAPI) RecordCategory(org.alfresco.rest.rm.community.model.recordcategory.RecordCategory)

Example 3 with FilePlanAPI

use of org.alfresco.rest.rm.community.requests.gscore.api.FilePlanAPI 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);
}
Also used : SiteData(org.alfresco.bm.site.SiteData) FilePlan(org.alfresco.rest.rm.community.model.fileplan.FilePlan) DBObject(com.mongodb.DBObject) FilePlanAPI(org.alfresco.rest.rm.community.requests.gscore.api.FilePlanAPI) UnfiledContainer(org.alfresco.rest.rm.community.model.unfiledcontainer.UnfiledContainer) UserModel(org.alfresco.utility.model.UserModel) RMSiteAPI(org.alfresco.rest.rm.community.requests.gscore.api.RMSiteAPI) TransferContainer(org.alfresco.rest.rm.community.model.transfercontainer.TransferContainer) SiteMemberData(org.alfresco.bm.site.SiteMemberData) RMSite(org.alfresco.rest.rm.community.model.site.RMSite) EventResult(org.alfresco.bm.event.EventResult) FolderData(org.alfresco.bm.cm.FolderData) TransferContainerAPI(org.alfresco.rest.rm.community.requests.gscore.api.TransferContainerAPI) Event(org.alfresco.bm.event.Event) UnfiledContainerAPI(org.alfresco.rest.rm.community.requests.gscore.api.UnfiledContainerAPI) Test(org.junit.Test)

Example 4 with FilePlanAPI

use of org.alfresco.rest.rm.community.requests.gscore.api.FilePlanAPI 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;
}
Also used : FilePlanAPI(org.alfresco.rest.rm.community.requests.gscore.api.FilePlanAPI) FolderData(org.alfresco.bm.cm.FolderData) RecordCategory(org.alfresco.rest.rm.community.model.recordcategory.RecordCategory)

Aggregations

FilePlanAPI (org.alfresco.rest.rm.community.requests.gscore.api.FilePlanAPI)4 FolderData (org.alfresco.bm.cm.FolderData)3 DBObject (com.mongodb.DBObject)2 Event (org.alfresco.bm.event.Event)2 EventResult (org.alfresco.bm.event.EventResult)2 SiteData (org.alfresco.bm.site.SiteData)2 SiteMemberData (org.alfresco.bm.site.SiteMemberData)2 FilePlan (org.alfresco.rest.rm.community.model.fileplan.FilePlan)2 RecordCategory (org.alfresco.rest.rm.community.model.recordcategory.RecordCategory)2 RMSite (org.alfresco.rest.rm.community.model.site.RMSite)2 TransferContainer (org.alfresco.rest.rm.community.model.transfercontainer.TransferContainer)2 UnfiledContainer (org.alfresco.rest.rm.community.model.unfiledcontainer.UnfiledContainer)2 RMSiteAPI (org.alfresco.rest.rm.community.requests.gscore.api.RMSiteAPI)2 TransferContainerAPI (org.alfresco.rest.rm.community.requests.gscore.api.TransferContainerAPI)2 UnfiledContainerAPI (org.alfresco.rest.rm.community.requests.gscore.api.UnfiledContainerAPI)2 UserModel (org.alfresco.utility.model.UserModel)2 Test (org.junit.Test)2 RMRestWrapper (org.alfresco.rest.core.RMRestWrapper)1