Search in sources :

Example 11 with SiteService

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;
}
Also used : SiteService(org.alfresco.service.cmr.site.SiteService) SysAdminParamsImpl(org.alfresco.repo.admin.SysAdminParamsImpl) NodeService(org.alfresco.service.cmr.repository.NodeService) PersonService(org.alfresco.service.cmr.security.PersonService) SearchService(org.alfresco.service.cmr.search.SearchService) SysAdminParams(org.alfresco.repo.admin.SysAdminParams) FileFolderService(org.alfresco.service.cmr.model.FileFolderService) ServiceRegistry(org.alfresco.service.ServiceRegistry) ActionService(org.alfresco.service.cmr.action.ActionService) RepoAdminService(org.alfresco.service.cmr.admin.RepoAdminService)

Example 12 with SiteService

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;
}
Also used : SiteService(org.alfresco.service.cmr.site.SiteService)

Example 13 with 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());
}
Also used : SiteInfo(org.alfresco.service.cmr.site.SiteInfo) RetryingTransactionHelper(org.alfresco.repo.transaction.RetryingTransactionHelper) ActivityPostEntity(org.alfresco.repo.domain.activities.ActivityPostEntity) SiteService(org.alfresco.service.cmr.site.SiteService) ActivityPostDAO(org.alfresco.repo.domain.activities.ActivityPostDAO) RetryingTransactionCallback(org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback) NodeArchiveService(org.alfresco.repo.node.archive.NodeArchiveService)

Example 14 with SiteService

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));
}
Also used : SiteInfo(org.alfresco.service.cmr.site.SiteInfo) NodeRef(org.alfresco.service.cmr.repository.NodeRef) SiteService(org.alfresco.service.cmr.site.SiteService) RetryingTransactionHelper(org.alfresco.repo.transaction.RetryingTransactionHelper)

Example 15 with SiteService

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;
}
Also used : Serializable(java.io.Serializable) RetryingTransactionHelper(org.alfresco.repo.transaction.RetryingTransactionHelper) QName(org.alfresco.service.namespace.QName) AuthorityService(org.alfresco.service.cmr.security.AuthorityService) PersonService(org.alfresco.service.cmr.security.PersonService) SiteService(org.alfresco.service.cmr.site.SiteService)

Aggregations

SiteService (org.alfresco.service.cmr.site.SiteService)19 RetryingTransactionHelper (org.alfresco.repo.transaction.RetryingTransactionHelper)8 NodeRef (org.alfresco.service.cmr.repository.NodeRef)7 NodeService (org.alfresco.service.cmr.repository.NodeService)6 SiteInfo (org.alfresco.service.cmr.site.SiteInfo)6 PersonService (org.alfresco.service.cmr.security.PersonService)4 ActionService (org.alfresco.service.cmr.action.ActionService)3 CheckOutCheckInService (org.alfresco.service.cmr.coci.CheckOutCheckInService)3 FileFolderService (org.alfresco.service.cmr.model.FileFolderService)3 FileNotFoundException (org.alfresco.service.cmr.model.FileNotFoundException)3 QName (org.alfresco.service.namespace.QName)3 AlfrescoRuntimeException (org.alfresco.error.AlfrescoRuntimeException)2 NodeArchiveService (org.alfresco.repo.node.archive.NodeArchiveService)2 RetryingTransactionCallback (org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback)2 ServiceRegistry (org.alfresco.service.ServiceRegistry)2 SearchService (org.alfresco.service.cmr.search.SearchService)2 AuthorityService (org.alfresco.service.cmr.security.AuthorityService)2 VersionService (org.alfresco.service.cmr.version.VersionService)2 WebDavService (org.alfresco.service.cmr.webdav.WebDavService)2 BeforeClass (org.junit.BeforeClass)2