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