Search in sources :

Example 6 with SiteData

use of org.alfresco.bm.site.SiteData 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 7 with SiteData

use of org.alfresco.bm.site.SiteData in project records-management by Alfresco.

the class PrepareRMSiteUnitTest method testRMSiteDoesNotExistAndLoadedInMongoDB.

@Test
public void testRMSiteDoesNotExistAndLoadedInMongoDB() throws Exception {
    String username = "bob";
    String password = "secret";
    prepareRMSite.setUsername(username);
    prepareRMSite.setPassword(password);
    when(mockedRestAPIFactory.getRMSiteAPI(any(UserModel.class))).thenReturn(mockedRMSiteAPI);
    when(mockedRMSiteAPI.existsRMSite()).thenReturn(false);
    SiteData mockedSiteData = mock(SiteData.class);
    when(mockedSiteData.getSiteId()).thenReturn(RM_SITE_ID);
    when(mockedSiteData.getCreationState()).thenReturn(Created);
    when(mockedSiteDataService.getSite(RM_SITE_ID)).thenReturn(mockedSiteData);
    People mockedPeople = mock(People.class);
    RestCoreAPI mockedCoreAPI = mock(RestCoreAPI.class);
    when(mockedCoreAPI.usingAuthUser()).thenReturn(mockedPeople);
    when(mockedRestCoreAPI.withCoreAPI()).thenReturn(mockedCoreAPI);
    when(mockedRestCoreAPI.getStatusCode()).thenReturn(HttpStatus.OK.toString());
    EventResult result = prepareRMSite.processEvent(null);
    ArgumentCaptor<UserData> userData = forClass(UserData.class);
    verify(mockedUserDataService).createNewUser(userData.capture());
    // Check RM admin user
    assertEquals(Created, userData.getValue().getCreationState());
    // Check events
    assertEquals(true, result.isSuccess());
    assertEquals("Preparing Records Management: \n", result.getData());
    List<Event> events = result.getNextEvents();
    assertEquals(1, events.size());
    Event event = events.get(0);
    assertEquals(DEFAULT_EVENT_NAME_RM_SITE_PREPARED, event.getName());
    DBObject data = (DBObject) event.getData();
    notNull(data);
    assertEquals(mockedSiteData.getSiteId(), (String) data.get(FIELD_SITE_ID));
    assertEquals(username, (String) data.get(FIELD_SITE_MANAGER_NAME));
    assertEquals(password, (String) data.get(FIELD_SITE_MANAGER_PASSWORD));
    assertEquals(null, (String) data.get(FIELD_ONLY_DB_LOAD));
}
Also used : UserModel(org.alfresco.utility.model.UserModel) SiteData(org.alfresco.bm.site.SiteData) EventResult(org.alfresco.bm.event.EventResult) UserData(org.alfresco.bm.user.UserData) RestCoreAPI(org.alfresco.rest.requests.coreAPI.RestCoreAPI) People(org.alfresco.rest.requests.People) Event(org.alfresco.bm.event.Event) DBObject(com.mongodb.DBObject) Test(org.junit.Test)

Example 8 with SiteData

use of org.alfresco.bm.site.SiteData in project records-management by Alfresco.

the class RMBaseEventProcessorUnitTest method testGetUserWithNoAdminRoleUser.

@Test(expected = IllegalStateException.class)
public void testGetUserWithNoAdminRoleUser() throws Exception {
    Logger mockedLog = mock(Logger.class);
    SiteData mockedSiteData = mock(SiteData.class);
    when(mockedSiteDataService.getSite(PATH_SNIPPET_RM_SITE_ID)).thenReturn(mockedSiteData);
    when(mockedSiteDataService.randomSiteMember(PATH_SNIPPET_RM_SITE_ID, DataCreationState.Created, null, RMRole.Administrator.toString())).thenReturn(null);
    testRMBaseEventProcessor.getRandomUser(mockedLog);
}
Also used : SiteData(org.alfresco.bm.site.SiteData) Logger(org.slf4j.Logger) Test(org.junit.Test)

Example 9 with SiteData

use of org.alfresco.bm.site.SiteData in project records-management by Alfresco.

the class RMBaseEventProcessor method getRandomUser.

/**
 * Gets a random user from the RM site.
 */
public UserData getRandomUser(Logger logger) {
    // Check
    SiteData siteData = siteDataService.getSite(PATH_SNIPPET_RM_SITE_ID);
    if (siteData == null) {
        throw new IllegalStateException("Unable to find site '" + PATH_SNIPPET_RM_SITE_ID + "'");
    }
    SiteMemberData siteMember = siteDataService.randomSiteMember(PATH_SNIPPET_RM_SITE_ID, DataCreationState.Created, null, RMRole.Administrator.toString());
    if (siteMember == null) {
        throw new IllegalStateException("Unable to find a user with specified roles for site: " + PATH_SNIPPET_RM_SITE_ID);
    }
    String username = siteMember.getUsername();
    // Retrieve the user data
    UserData user = userDataService.findUserByUsername(username);
    if (user == null) {
        throw new IllegalStateException("Unable to find a user '" + username + "' linked to site: " + PATH_SNIPPET_RM_SITE_ID);
    }
    // Done
    logger.debug("Found RM site member '" + username + "'");
    return user;
}
Also used : SiteData(org.alfresco.bm.site.SiteData) SiteMemberData(org.alfresco.bm.site.SiteMemberData) UserData(org.alfresco.bm.user.UserData)

Example 10 with SiteData

use of org.alfresco.bm.site.SiteData 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)

Aggregations

SiteData (org.alfresco.bm.site.SiteData)22 EventResult (org.alfresco.bm.event.EventResult)15 Test (org.junit.Test)15 SiteMemberData (org.alfresco.bm.site.SiteMemberData)10 DBObject (com.mongodb.DBObject)9 Event (org.alfresco.bm.event.Event)9 RestSiteContainerModel (org.alfresco.rest.model.RestSiteContainerModel)8 RestSiteModel (org.alfresco.rest.model.RestSiteModel)8 RestCoreAPI (org.alfresco.rest.requests.coreAPI.RestCoreAPI)8 UserData (org.alfresco.bm.user.UserData)6 RestWrapper (org.alfresco.rest.core.RestWrapper)6 RestNodeModelsCollection (org.alfresco.rest.model.RestNodeModelsCollection)6 RestPaginationModel (org.alfresco.rest.model.RestPaginationModel)6 Node (org.alfresco.rest.requests.Node)6 Site (org.alfresco.rest.requests.Site)6 RepoTestModel (org.alfresco.utility.model.RepoTestModel)6 UserModel (org.alfresco.utility.model.UserModel)6 StopWatch (org.apache.commons.lang3.time.StopWatch)6 RestNodeModel (org.alfresco.rest.model.RestNodeModel)4 NodesBuilder (org.alfresco.rest.model.builder.NodesBuilder)4