use of org.alfresco.service.cmr.site.SiteService in project alfresco-repository by Alfresco.
the class InviteSenderTest method mockServices.
/**
* @return ServiceRegistry
*/
private ServiceRegistry mockServices() {
ActionService mockActionService = mockActionService();
NodeService mockNodeService = mockNodeService();
PersonService mockPersonService = mockPersonService();
SearchService mockSearchService = mockSearchService();
SiteService mockSiteService = mockSiteService();
FileFolderService mockFileFolderService = mockFileFolderService();
RepoAdminService mockRepoAdminService = mockRepoAdminService();
SysAdminParams sysAdminParams = new SysAdminParamsImpl();
ServiceRegistry services = mock(ServiceRegistry.class);
when(services.getActionService()).thenReturn(mockActionService);
when(services.getNodeService()).thenReturn(mockNodeService);
when(services.getPersonService()).thenReturn(mockPersonService);
when(services.getSearchService()).thenReturn(mockSearchService);
when(services.getSiteService()).thenReturn(mockSiteService);
when(services.getFileFolderService()).thenReturn(mockFileFolderService);
when(services.getSysAdminParams()).thenReturn(sysAdminParams);
when(services.getRepoAdminService()).thenReturn(mockRepoAdminService);
return services;
}
use of org.alfresco.service.cmr.site.SiteService in project alfresco-repository by Alfresco.
the class InviteSenderTest method mockSiteService.
/**
* Mocks up a SiteService that returns appropriate SiteInfo.
*
* @return SiteService
*/
private SiteService mockSiteService() {
SiteService siteService = mock(SiteService.class);
when(siteInfo.getShortName()).thenReturn(siteShortName);
when(siteService.getSite(siteName)).thenReturn(siteInfo);
return siteService;
}
use of org.alfresco.service.cmr.site.SiteService in project alfresco-repository by Alfresco.
the class TemporarySites method after.
@Override
protected void after() {
final RetryingTransactionHelper transactionHelper = (RetryingTransactionHelper) appContextRule.getApplicationContext().getBean("retryingTransactionHelper");
final SiteService siteService = appContextRule.getApplicationContext().getBean("siteService", SiteService.class);
final ActivityPostDAO postDAO = appContextRule.getApplicationContext().getBean("postDAO", ActivityPostDAO.class);
final NodeArchiveService nodeArchiveService = (NodeArchiveService) appContextRule.getApplicationContext().getBean("nodeArchiveService");
// Run as admin to ensure all sites can be deleted irrespective of which user created them.
AuthenticationUtil.runAs(new RunAsWork<Void>() {
@Override
public Void doWork() throws Exception {
transactionHelper.doInTransaction(new RetryingTransactionCallback<Void>() {
@Override
public Void execute() throws Throwable {
for (SiteInfo site : temporarySites) {
final String shortName = site.getShortName();
if (siteService.getSite(shortName) != null) {
log.debug("Deleting temporary site " + shortName);
siteService.deleteSite(shortName);
}
}
for (String username : temporarySiteUsers) {
log.debug("Deleting temporary site user " + username);
deletePerson(username);
}
// Clean all the post feeds
int deletedCnt = 0;
Date keepDate = new Date(System.currentTimeMillis() + (120 * 1000L));
for (ActivityPostEntity.STATUS status : ActivityPostEntity.STATUS.values()) {
deletedCnt += postDAO.deletePosts(keepDate, status);
}
log.debug("Deleted " + deletedCnt + " post feeds.");
return null;
}
});
transactionHelper.doInTransaction(new RetryingTransactionCallback<Void>() {
@Override
public Void execute() throws Throwable {
for (SiteInfo site : temporarySites) {
log.debug("Purging temporary site from trashcan: " + site.getShortName());
nodeArchiveService.purgeArchivedNode(nodeArchiveService.getArchivedNode(site.getNodeRef()));
}
return null;
}
});
return null;
}
}, AuthenticationUtil.getAdminUserName());
}
use of org.alfresco.service.cmr.site.SiteService in project alfresco-repository by Alfresco.
the class TemporarySites method createTestSiteWithUserPerRole.
/**
* This method creates a test site (of Alfresco type <code>st:site</code>) and one user for each of the Share Site Roles.
* This method will be run in its own transaction and will be run with the specified user as the fully authenticated user,
* thus ensuring the named user is the creator of the new site.
* The site and its users will be deleted automatically by the rule.
*
* @param sitePreset the site preset.
* @param visibility the Site visibility.
* @param siteCreator the username of a user who will be used to create the site (user must exist of course).
* @return the {@link SiteInfo} object for the newly created site.
*/
public TestSiteAndMemberInfo createTestSiteWithUserPerRole(final String siteShortName, String sitePreset, SiteVisibility visibility, String siteCreator) {
// create the site
SiteInfo result = this.createSite(sitePreset, siteShortName, null, null, visibility, siteCreator);
// create the users
final RetryingTransactionHelper transactionHelper = appContextRule.getApplicationContext().getBean("retryingTransactionHelper", RetryingTransactionHelper.class);
final SiteService siteService = appContextRule.getApplicationContext().getBean("siteService", SiteService.class);
AuthenticationUtil.pushAuthentication();
AuthenticationUtil.setFullyAuthenticatedUser(siteCreator);
// Create users for this test site that cover the various roles.
List<String> userNames = transactionHelper.doInTransaction(new RetryingTransactionCallback<List<String>>() {
public List<String> execute() throws Throwable {
List<String> users = new ArrayList<String>(4);
for (String shareRole : SiteModel.STANDARD_PERMISSIONS) {
final String userName = siteShortName + "_" + shareRole + "_" + GUID.generate();
log.debug("Creating temporary site user " + userName);
createPerson(userName);
siteService.setMembership(siteShortName, userName, shareRole);
users.add(userName);
temporarySiteUsers.add(userName);
}
return users;
}
});
NodeRef doclibFolder = transactionHelper.doInTransaction(new RetryingTransactionCallback<NodeRef>() {
public NodeRef execute() throws Throwable {
return siteService.getContainer(siteShortName, SiteService.DOCUMENT_LIBRARY);
}
});
AuthenticationUtil.popAuthentication();
return new TestSiteAndMemberInfo(result, doclibFolder, userNames.get(0), userNames.get(1), userNames.get(2), userNames.get(3));
}
use of org.alfresco.service.cmr.site.SiteService in project alfresco-repository by Alfresco.
the class TemporarySites method createTestSiteWithGroups.
/*
* This method creates a test site with n groups.
*/
public List<String> createTestSiteWithGroups(final String siteShortName, String sitePreset, SiteVisibility visibility, String siteCreator, int noOfGroups) {
// create the site
this.createSite(sitePreset, siteShortName, null, null, visibility, siteCreator);
// create the users
final RetryingTransactionHelper transactionHelper = appContextRule.getApplicationContext().getBean("retryingTransactionHelper", RetryingTransactionHelper.class);
final SiteService siteService = appContextRule.getApplicationContext().getBean("siteService", SiteService.class);
final AuthorityService authorityService = appContextRule.getApplicationContext().getBean("authorityService", AuthorityService.class);
final PersonService personService = appContextRule.getApplicationContext().getBean("personService", PersonService.class);
AuthenticationUtil.pushAuthentication();
AuthenticationUtil.setFullyAuthenticatedUser(siteCreator);
// Create group with one user and add it to the site
List<String> groupIds = transactionHelper.doInTransaction(new RetryingTransactionCallback<List<String>>() {
public List<String> execute() throws Throwable {
List<String> groups = new ArrayList<String>(noOfGroups);
for (int i = 0; i < noOfGroups; i++) {
String shareRole = SiteModel.STANDARD_PERMISSIONS.get(i % 4);
final String groupName = "Test_Group_" + GUID.generate();
final String userName = "Test_User_" + GUID.generate();
log.debug("Creating temporary site user " + userName);
final Map<QName, Serializable> properties = new HashMap<QName, Serializable>();
properties.put(ContentModel.PROP_USERNAME, userName);
properties.put(ContentModel.PROP_FIRSTNAME, GUID.generate());
properties.put(ContentModel.PROP_LASTNAME, GUID.generate());
properties.put(ContentModel.PROP_EMAIL, GUID.generate() + "@test.com");
personService.createPerson(properties);
log.debug("Creating temporary site group " + groupName);
final String groupId = authorityService.createAuthority(AuthorityType.GROUP, groupName);
authorityService.setAuthorityDisplayName(groupId, GUID.generate());
authorityService.addAuthority(groupId, userName);
siteService.setMembership(siteShortName, groupId, shareRole);
groups.add(userName);
}
return groups;
}
});
return groupIds;
}
Aggregations