Search in sources :

Example 1 with RMSiteAPI

use of org.alfresco.rest.rm.community.requests.gscore.api.RMSiteAPI 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 RMSiteAPI

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

the class CreateRMSite method processEvent.

@Override
public EventResult processEvent(Event event) throws Exception {
    mandatoryObject("event", event);
    DBObject dataObj = (DBObject) event.getData();
    if (dataObj == null) {
        throw new IllegalStateException("This processor requires data object with fields '" + FIELD_SITE_ID + ", " + FIELD_SITE_MANAGER_NAME + "'.");
    }
    String siteId = (String) dataObj.get(FIELD_SITE_ID);
    String siteManager = (String) dataObj.get(FIELD_SITE_MANAGER_NAME);
    String siteManagersPassword = (String) dataObj.get(FIELD_SITE_MANAGER_PASSWORD);
    Boolean onlyLoadInDb = (Boolean) dataObj.get(FIELD_ONLY_DB_LOAD);
    if (isBlank(siteId) || isBlank(siteManager) || isBlank(siteManagersPassword)) {
        return new EventResult("Requests data not complete for site creation: " + dataObj, false);
    }
    SiteData site = siteDataService.getSite(siteId);
    if (site != null) {
        if (site.getCreationState() == Created) {
            return new EventResult("RM Site already exists in DB: " + site, false);
        }
        if (site.getCreationState() != Created) {
            return new EventResult("Site state has changed: " + site, false);
        }
    }
    String msg = null;
    RMSiteAPI rmSiteAPI = restAPIFactory.getRMSiteAPI(new UserModel(siteManager, siteManagersPassword));
    String guid = null;
    if (onlyLoadInDb == null) {
        RMSite siteModel = RMSite.builder().compliance(STANDARD).title(RM_SITE_TITLE).description(RM_SITE_DESC).build();
        RMSite rmSite = rmSiteAPI.createRMSite(siteModel);
        String statusCode = restAPIFactory.getRmRestWrapper().getStatusCode();
        if (HttpStatus.valueOf(Integer.parseInt(statusCode)) != HttpStatus.CREATED) {
            return new EventResult("RM site could not be created.", false);
        }
        guid = rmSite.getGuid();
        msg = "Created site: " + siteId + " Site creator: " + siteManager;
    } else {
        RMSite alreadyCreatedRMSite = rmSiteAPI.getSite();
        guid = alreadyCreatedRMSite.getGuid();
        msg = "RM site already exists, just loading it in the DB.";
    }
    if (site == null) {
        // Create data
        site = new SiteData();
        site.setSiteId(siteId);
        site.setTitle(RM_SITE_TITLE);
        site.setGuid(RM_SITE_GUID);
        site.setDomain(RM_SITE_DOMAIN);
        site.setDescription(RM_SITE_DESC);
        site.setSitePreset(RM_SITE_PRESET);
        site.setVisibility(RM_SITE_VISIBILITY);
        site.setType(RM_SITE_TYPE);
        site.setCreationState(Scheduled);
        siteDataService.addSite(site);
    }
    // Start by marking them as failures in order to handle all eventualities
    siteDataService.setSiteCreationState(siteId, null, Failed);
    siteDataService.setSiteMemberCreationState(siteId, siteManager, Failed);
    SiteMemberData siteMember = siteDataService.getSiteMember(RM_SITE_ID, siteManager);
    if (siteMember == null) {
        // Record the administrator
        SiteMemberData rmAdminMember = new SiteMemberData();
        rmAdminMember.setCreationState(Created);
        rmAdminMember.setRole(Administrator.toString());
        rmAdminMember.setSiteId(RM_SITE_ID);
        rmAdminMember.setUsername(siteManager);
        siteDataService.addSiteMember(rmAdminMember);
    }
    // Mark the site.
    siteDataService.setSiteCreationState(siteId, guid, Created);
    siteDataService.setSiteMemberCreationState(siteId, siteManager, Created);
    loadSpecialContainersInDB(siteId, siteManager, siteManagersPassword);
    event = new Event(eventNameSiteCreated, null);
    if (logger.isDebugEnabled()) {
        logger.debug(msg);
    }
    return new EventResult(msg, event);
}
Also used : SiteData(org.alfresco.bm.site.SiteData) UserModel(org.alfresco.utility.model.UserModel) RMSiteAPI(org.alfresco.rest.rm.community.requests.gscore.api.RMSiteAPI) SiteMemberData(org.alfresco.bm.site.SiteMemberData) EventResult(org.alfresco.bm.event.EventResult) RMSite(org.alfresco.rest.rm.community.model.site.RMSite) Event(org.alfresco.bm.event.Event) DBObject(com.mongodb.DBObject)

Example 3 with RMSiteAPI

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

the class CreateRMSiteUnitTest method testRMSiteCreationNotPossible.

@Test
public void testRMSiteCreationNotPossible() throws Exception {
    Event mockedEvent = mock(Event.class);
    DBObject mockedData = mock(DBObject.class);
    RMSiteAPI mockedRMSiteAPI = mock(RMSiteAPI.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);
    RMRestWrapper mockedRmRestWrapper = mock(RMRestWrapper.class);
    when(mockedRmRestWrapper.getStatusCode()).thenReturn(HttpStatus.FORBIDDEN.toString());
    when(mockedRestAPIFactory.getRmRestWrapper()).thenReturn(mockedRmRestWrapper);
    EventResult result = createRMSite.processEvent(mockedEvent);
    verify(mockedSiteDataService, never()).addSite(any(SiteData.class));
    verify(mockedSiteDataService, never()).addSiteMember(any(SiteMemberData.class));
    assertEquals(false, result.isSuccess());
    assertEquals("RM site could not be created.", result.getData());
    assertEquals(0, result.getNextEvents().size());
}
Also used : UserModel(org.alfresco.utility.model.UserModel) SiteData(org.alfresco.bm.site.SiteData) RMSiteAPI(org.alfresco.rest.rm.community.requests.gscore.api.RMSiteAPI) SiteMemberData(org.alfresco.bm.site.SiteMemberData) EventResult(org.alfresco.bm.event.EventResult) Event(org.alfresco.bm.event.Event) DBObject(com.mongodb.DBObject) RMRestWrapper(org.alfresco.rest.core.RMRestWrapper) Test(org.junit.Test)

Example 4 with RMSiteAPI

use of org.alfresco.rest.rm.community.requests.gscore.api.RMSiteAPI 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)

Aggregations

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