Search in sources :

Example 1 with UserData

use of org.alfresco.bm.user.UserData in project records-management by Alfresco.

the class PrepareRMSiteMembersUnitTest method testNoUsersToChoseFrom.

@Test
public void testNoUsersToChoseFrom() throws Exception {
    prepareRMSiteMembers.setRole("Administrator");
    prepareRMSiteMembers.setAssignRMRoleToUsers(true);
    prepareRMSiteMembers.setUserCount(1);
    when(mockedUserDataService.getUsersByCreationState(DataCreationState.Created, 0, 100)).thenReturn(new ArrayList<UserData>());
    EventResult result = prepareRMSiteMembers.processEvent(null);
    assertEquals(true, result.isSuccess());
    assertEquals(PrepareRMSiteMembers.NO_USERS_AVAILABLE_MSG, result.getData());
    List<Event> nextEvents = result.getNextEvents();
    assertEquals(1, nextEvents.size());
    assertEquals(prepareRMSiteMembers.getEventNameContinueLoadingData(), nextEvents.get(0).getName());
}
Also used : EventResult(org.alfresco.bm.event.EventResult) UserData(org.alfresco.bm.user.UserData) Event(org.alfresco.bm.event.Event) Test(org.junit.Test)

Example 2 with UserData

use of org.alfresco.bm.user.UserData 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 3 with UserData

use of org.alfresco.bm.user.UserData in project records-management by Alfresco.

the class PrepareRMSiteUnitTest method testRMSiteDoesExistAndNotLoadedInMongoDB.

@Test
public void testRMSiteDoesExistAndNotLoadedInMongoDB() 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);
    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());
    List<Event> events = result.getNextEvents();
    assertEquals(1, events.size());
    Event event = events.get(0);
    assertEquals("loadRMSiteIntoDB", event.getName());
    DBObject data = (DBObject) event.getData();
    notNull(data);
    assertEquals(RM_SITE_ID, (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(true, (Boolean) data.get(FIELD_ONLY_DB_LOAD));
}
Also used : UserModel(org.alfresco.utility.model.UserModel) 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 4 with UserData

use of org.alfresco.bm.user.UserData in project records-management by Alfresco.

the class RMAbstractLoadComponent method loadOperation.

/**
 * Helper method to load component specified by operation parameter in specified folder.
 *
 * @param folder - the folder to load component in
 * @param dataObj - the query object that has record id information when filing one record
 * @param operation - load operation, that specifies which type of component to load
 * @return EventResult - the loading result or error if there was an exception on loading
 */
private EventResult loadOperation(FolderData folder, DBObject dataObj, String operation) {
    if (FILE_RECORD_OPERATION.equals(operation)) {
        String recordId = (String) dataObj.get(FIELD_RECORD_ID);
        if (isBlank(recordId)) {
            return new EventResult("Request data not complete for filing unfiled record: " + dataObj, false);
        }
    }
    UserData user = getRandomUser(logger);
    String username = user.getUsername();
    String password = user.getPassword();
    UserModel userModel = new UserModel(username, password);
    try {
        List<Event> scheduleEvents = new ArrayList<Event>();
        String message = executeOperation(folder, dataObj, operation, userModel);
        DBObject eventData = BasicDBObjectBuilder.start().add(FIELD_CONTEXT, folder.getContext()).add(FIELD_PATH, folder.getPath()).get();
        Event nextEvent = new Event(getEventNameComplete(), eventData);
        scheduleEvents.add(nextEvent);
        DBObject resultData = BasicDBObjectBuilder.start().add("msg", message).add("path", folder.getPath()).add("username", username).get();
        return new EventResult(resultData, scheduleEvents);
    } catch (Exception e) {
        String error = e.getMessage();
        String stack = ExceptionUtils.getStackTrace(e);
        // Grab REST API information
        DBObject data = BasicDBObjectBuilder.start().append("error", error).append("username", username).append("path", folder.getPath()).append("stack", stack).get();
        // Build failure result
        return new EventResult(data, false);
    }
}
Also used : UserModel(org.alfresco.utility.model.UserModel) EventResult(org.alfresco.bm.event.EventResult) UserData(org.alfresco.bm.user.UserData) ArrayList(java.util.ArrayList) Event(org.alfresco.bm.event.Event) DBObject(com.mongodb.DBObject)

Example 5 with UserData

use of org.alfresco.bm.user.UserData 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)

Aggregations

UserData (org.alfresco.bm.user.UserData)14 Event (org.alfresco.bm.event.Event)11 EventResult (org.alfresco.bm.event.EventResult)11 Test (org.junit.Test)9 SiteMemberData (org.alfresco.bm.site.SiteMemberData)7 UserModel (org.alfresco.utility.model.UserModel)7 DBObject (com.mongodb.DBObject)6 SiteData (org.alfresco.bm.site.SiteData)6 People (org.alfresco.rest.requests.People)4 RestCoreAPI (org.alfresco.rest.requests.coreAPI.RestCoreAPI)4 ArrayList (java.util.ArrayList)2 BasicDBObjectBuilder (com.mongodb.BasicDBObjectBuilder)1 RMRole (org.alfresco.bm.dataload.rm.role.RMRole)1 Logger (org.slf4j.Logger)1