Search in sources :

Example 16 with SiteData

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

the class CreateRMSiteUnitTest method testCreationWhenRMSiteAleadyInDb.

@Test
public void testCreationWhenRMSiteAleadyInDb() throws Exception {
    Event mockedEvent = mock(Event.class);
    DBObject mockedData = mock(DBObject.class);
    SiteData mockedSiteData = mock(SiteData.class);
    String siteId = randomUUID().toString();
    when(mockedData.get(FIELD_SITE_ID)).thenReturn(siteId);
    when(mockedData.get(FIELD_SITE_MANAGER_NAME)).thenReturn(randomUUID().toString());
    when(mockedData.get(FIELD_SITE_MANAGER_PASSWORD)).thenReturn("password");
    when(mockedEvent.getData()).thenReturn(mockedData);
    when(mockedSiteDataService.getSite(siteId)).thenReturn(mockedSiteData);
    when(mockedSiteData.getCreationState()).thenReturn(Created);
    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 already exists in DB: " + mockedSiteData, result.getData());
    assertEquals(0, result.getNextEvents().size());
}
Also used : SiteData(org.alfresco.bm.site.SiteData) SiteMemberData(org.alfresco.bm.site.SiteMemberData) EventResult(org.alfresco.bm.event.EventResult) Event(org.alfresco.bm.event.Event) DBObject(com.mongodb.DBObject) Test(org.junit.Test)

Example 17 with SiteData

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

the class PrepareRMSiteUnitTest method testRMSiteDoesExistAndLoadedInMongoDB.

@Test
public void testRMSiteDoesExistAndLoadedInMongoDB() 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(true);
    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("RM Site already created, continue loading data.", result.getData());
    List<Event> events = result.getNextEvents();
    assertEquals(1, events.size());
    Event event = events.get(0);
    assertEquals("scheduleFilePlanLoaders", event.getName());
    DBObject data = (DBObject) event.getData();
    assertNull(data);
}
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 18 with SiteData

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

the class PrepareRMSite method processEvent.

/**
 * @see org.alfresco.bm.event.AbstractEventProcessor#processEvent(org.alfresco.bm.event.Event)
 */
@Override
protected EventResult processEvent(Event event) throws Exception {
    StringBuilder msg = new StringBuilder("Preparing Records Management: \n");
    List<Event> events = new ArrayList<Event>(10);
    UserModel userModel = new UserModel(getUsername(), getPassword());
    // authenticate with provided credentials and verify that they are valid
    restCoreAPI.authenticateUser(userModel);
    restCoreAPI.withCoreAPI().usingAuthUser().getPerson();
    String statusCode = restCoreAPI.getStatusCode();
    if (HttpStatus.valueOf(Integer.parseInt(statusCode)) != HttpStatus.OK) {
        return new EventResult("Provided RM Site Creator does not exist, or provided credentials are not valid.", false);
    }
    UserData rmAdmin = userDataService.findUserByUsername(getUsername());
    if (rmAdmin == null) {
        rmAdmin = new UserData();
        rmAdmin.setCreationState(Created);
        rmAdmin.setDomain(RM_SITE_DOMAIN);
        rmAdmin.setUsername(getUsername());
        rmAdmin.setPassword(getPassword());
        userDataService.createNewUser(rmAdmin);
    } else {
        // Check for creation
        if (rmAdmin.getCreationState() != Created) {
            userDataService.setUserCreationState(getUsername(), Created);
            msg.append("   Updating user " + getUsername() + " state to created.\n");
        }
    }
    SiteData rmSite = siteDataService.getSite(RM_SITE_ID);
    BasicDBObjectBuilder builder = BasicDBObjectBuilder.start();
    builder.add(FIELD_SITE_ID, RM_SITE_ID).add(FIELD_SITE_MANAGER_NAME, getUsername()).add(FIELD_SITE_MANAGER_PASSWORD, getPassword());
    boolean existsRMSite = restAPIFactory.getRMSiteAPI(userModel).existsRMSite();
    // RM site exists and it is loaded in MongoDB
    if (existsRMSite && rmSite != null && rmSite.getCreationState() == Created) {
        return new EventResult("RM Site already created, continue loading data.", new Event(getEventNameContinueLoadingData(), null));
    }
    // RM site exists and it is not loaded in MongoDB
    if (existsRMSite && rmSite == null) {
        builder.add(FIELD_ONLY_DB_LOAD, true);
        DBObject data = builder.get();
        events.add(new Event(getEventNameLoadRMSiteIntoDB(), data));
    }
    // RM site does not exist and will be created
    if (!existsRMSite) {
        DBObject data = builder.get();
        events.add(new Event(getEventNameRMSitePrepared(), data));
    }
    // Done
    return new EventResult(msg.toString(), events);
}
Also used : UserModel(org.alfresco.utility.model.UserModel) SiteData(org.alfresco.bm.site.SiteData) EventResult(org.alfresco.bm.event.EventResult) BasicDBObjectBuilder(com.mongodb.BasicDBObjectBuilder) UserData(org.alfresco.bm.user.UserData) ArrayList(java.util.ArrayList) Event(org.alfresco.bm.event.Event) DBObject(com.mongodb.DBObject)

Example 19 with SiteData

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

the class ScheduleInPlaceRecordLoaders method getCollaborationSiteDoclib.

/**
 *  Helper method that makes sure the site exists on the server and loads it in the benchmark DB
 *
 * @param eventOutputMsg
 * @return the collaboration site's document library id
 * @throws Exception
 */
private String getCollaborationSiteDoclib(StringBuilder eventOutputMsg) throws Exception {
    // Check if the collaboration site exists on server using the REST api
    RestSiteModel colabSite = restCoreAPI.withCoreAPI().usingSite(collabSiteId).getSite();
    if (Integer.parseInt(restCoreAPI.getStatusCode()) == HttpStatus.SC_NOT_FOUND) {
        // The collaboration site doesn't exist, create it
        colabSite = restCoreAPI.withCoreAPI().usingSite(collabSiteId).createSite();
    }
    // Store the collaboration site in benchmark's DB
    SiteData colabSiteData = siteDataService.getSite(collabSiteId);
    if (colabSiteData == null) {
        // Store site info in Benchmark's DB
        colabSiteData = new SiteData();
        colabSiteData.setSiteId(collabSiteId);
        colabSiteData.setTitle(colabSite.getTitle());
        colabSiteData.setGuid(colabSite.getGuid());
        colabSiteData.setDescription(colabSite.getDescription());
        colabSiteData.setSitePreset(colabSite.getPreset());
        colabSiteData.setVisibility(colabSite.getVisibility().toString());
        colabSiteData.setCreationState(Created);
        siteDataService.addSite(colabSiteData);
        eventOutputMsg.append(" Added site \"" + collabSiteId + "\" as created.\n");
    }
    // Get site's document library
    RestSiteContainerModel documentLibrary = restCoreAPI.withCoreAPI().usingSite(collabSiteId).getSiteContainer("documentLibrary");
    return documentLibrary.getId();
}
Also used : SiteData(org.alfresco.bm.site.SiteData) RestSiteModel(org.alfresco.rest.model.RestSiteModel) RestSiteContainerModel(org.alfresco.rest.model.RestSiteContainerModel)

Example 20 with SiteData

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

the class CreateRMSiteMembers method processEvent.

@Override
protected EventResult processEvent(Event event) throws Exception {
    List<Event> nextEvents = new ArrayList<Event>();
    // Schedule events for each site member to be created
    int numSitesMembers = 0;
    List<SiteMemberData> pendingSiteMembers = siteDataService.getSiteMembers(PATH_SNIPPET_RM_SITE_ID, DataCreationState.NotScheduled, null, 0, batchSize);
    if (pendingSiteMembers.isEmpty()) {
        // There is nothing more to do
        Event doneEvent = new Event(eventNameRMSiteMembersCreated, System.currentTimeMillis(), null);
        nextEvents.add(doneEvent);
    } else {
        long nextEventTime = System.currentTimeMillis();
        for (SiteMemberData siteMember : pendingSiteMembers) {
            // Do we need to schedule it?
            String siteId = siteMember.getSiteId();
            String username = siteMember.getUsername();
            SiteData site = siteDataService.getSite(siteId);
            // Ignore RM site not been prepared.
            if (site == null) {
                // This site member cannot be created, so we mark it as an immediate failure
                siteDataService.setSiteMemberCreationState(siteId, username, DataCreationState.Failed);
                continue;
            }
            // RM Site created
            nextEventTime += memberCreationDelay;
            DBObject dataObj = new BasicDBObject().append(CreateRMSiteMember.FIELD_USERNAME, username);
            Event nextEvent = new Event(eventNameCreateRMSiteMember, nextEventTime, dataObj);
            nextEvents.add(nextEvent);
            numSitesMembers++;
            // The member creation is now scheduled
            siteDataService.setSiteMemberCreationState(siteId, username, DataCreationState.Scheduled);
        }
        // Reschedule for the next batch (might be zero next time)
        Event self = new Event(eventNameCreateRMSiteMembers, nextEventTime + memberCreationDelay, null);
        nextEvents.add(self);
    }
    // Return messages + next events
    return new EventResult(MessageFormat.format(SCHEDULED_MEMBERS_MSG_TEMPLATE, numSitesMembers), nextEvents);
}
Also used : SiteData(org.alfresco.bm.site.SiteData) BasicDBObject(com.mongodb.BasicDBObject) SiteMemberData(org.alfresco.bm.site.SiteMemberData) EventResult(org.alfresco.bm.event.EventResult) ArrayList(java.util.ArrayList) Event(org.alfresco.bm.event.Event) DBObject(com.mongodb.DBObject) BasicDBObject(com.mongodb.BasicDBObject)

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