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());
}
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));
}
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));
}
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);
}
}
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;
}
Aggregations