Search in sources :

Example 16 with SiteService

use of org.alfresco.service.cmr.site.SiteService in project alfresco-repository by Alfresco.

the class TemporaryNodesTest method initStaticData.

@BeforeClass
public static void initStaticData() throws Exception {
    COCI_SERVICE = APP_CONTEXT_INIT.getApplicationContext().getBean("checkOutCheckInService", CheckOutCheckInService.class);
    CONTENT_SERVICE = APP_CONTEXT_INIT.getApplicationContext().getBean("ContentService", ContentService.class);
    NODE_SERVICE = APP_CONTEXT_INIT.getApplicationContext().getBean("NodeService", NodeService.class);
    SITE_SERVICE = APP_CONTEXT_INIT.getApplicationContext().getBean("SiteService", SiteService.class);
    TRANSACTION_HELPER = APP_CONTEXT_INIT.getApplicationContext().getBean("retryingTransactionHelper", RetryingTransactionHelper.class);
    VERSION_SERVICE = APP_CONTEXT_INIT.getApplicationContext().getBean("VersionService", VersionService.class);
    Repository repositoryHelper = APP_CONTEXT_INIT.getApplicationContext().getBean("repositoryHelper", Repository.class);
    COMPANY_HOME = repositoryHelper.getCompanyHome();
}
Also used : Repository(org.alfresco.repo.model.Repository) CheckOutCheckInService(org.alfresco.service.cmr.coci.CheckOutCheckInService) SiteService(org.alfresco.service.cmr.site.SiteService) RetryingTransactionHelper(org.alfresco.repo.transaction.RetryingTransactionHelper) NodeService(org.alfresco.service.cmr.repository.NodeService) VersionService(org.alfresco.service.cmr.version.VersionService) ContentService(org.alfresco.service.cmr.repository.ContentService) BeforeClass(org.junit.BeforeClass)

Example 17 with SiteService

use of org.alfresco.service.cmr.site.SiteService in project alfresco-repository by Alfresco.

the class AuthorityServiceTest method setUp.

public void setUp() throws Exception {
    if (AlfrescoTransactionSupport.getTransactionReadState() != TxnReadState.TXN_NONE) {
        throw new AlfrescoRuntimeException("A previous tests did not clean up transaction: " + AlfrescoTransactionSupport.getTransactionId());
    }
    authenticationComponent = (AuthenticationComponent) ctx.getBean("authenticationComponent");
    authenticationService = (MutableAuthenticationService) ctx.getBean("authenticationService");
    authorityService = (AuthorityService) ctx.getBean("authorityService");
    pubAuthorityService = (AuthorityService) ctx.getBean("AuthorityService");
    personService = (PersonService) ctx.getBean("personService");
    authenticationDAO = (MutableAuthenticationDao) ctx.getBean("authenticationDao");
    aclDaoComponent = (AclDAO) ctx.getBean("aclDAO");
    nodeService = (NodeService) ctx.getBean("nodeService");
    authorityBridgeTableCache = (AuthorityBridgeTableAsynchronouslyRefreshedCache) ctx.getBean("authorityBridgeTableCache");
    nodeArchiveService = (NodeArchiveService) ctx.getBean("nodeArchiveService");
    policyComponent = (PolicyComponent) ctx.getBean("policyComponent");
    transactionService = (TransactionService) ctx.getBean(ServiceRegistry.TRANSACTION_SERVICE.getLocalName());
    authorityDAO = ctx.getBean("authorityDAO", AuthorityDAO.class);
    String defaultAdminUser = AuthenticationUtil.getAdminUserName();
    AuthenticationUtil.setFullyAuthenticatedUser(defaultAdminUser);
    // cleanup trashcan
    nodeArchiveService.purgeAllArchivedNodes(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE);
    // note: currently depends on any existing (and/or bootstrap) group data - eg. default site "swsdp" (Sample Web Site Design Project)
    SiteService siteService = (SiteService) ctx.getBean("SiteService");
    SITE_CNT = siteService.listSites(defaultAdminUser).size();
    GRP_CNT = DEFAULT_GRP_CNT + (DEFAULT_SITE_GRP_CNT * SITE_CNT);
    ROOT_GRP_CNT = DEFAULT_GRP_CNT + (DEFAULT_SITE_ROOT_GRP_CNT * SITE_CNT);
    tx = transactionService.getUserTransaction();
    tx.begin();
    for (String user : getAllAuthorities(AuthorityType.USER)) {
        if (user.equals(AuthenticationUtil.getGuestUserName())) {
            continue;
        } else if (user.equals(AuthenticationUtil.getAdminUserName())) {
            continue;
        } else {
            if (personService.personExists(user)) {
                NodeRef person = personService.getPerson(user);
                NodeRef hf = DefaultTypeConverter.INSTANCE.convert(NodeRef.class, nodeService.getProperty(person, ContentModel.PROP_HOMEFOLDER));
                if (hf != null) {
                    nodeService.deleteNode(hf);
                }
                aclDaoComponent.deleteAccessControlEntries(user);
                personService.deletePerson(user);
            }
            if (authenticationDAO.userExists(user)) {
                authenticationDAO.deleteUser(user);
            }
        }
    }
    tx.commit();
    tx = transactionService.getUserTransaction();
    tx.begin();
    if (!authenticationDAO.userExists("andy")) {
        authenticationService.createAuthentication("andy", "andy".toCharArray());
    }
    if (!authenticationDAO.userExists(AuthenticationUtil.getAdminUserName())) {
        authenticationService.createAuthentication(AuthenticationUtil.getAdminUserName(), "admin".toCharArray());
    }
    if (!authenticationDAO.userExists("administrator")) {
        authenticationService.createAuthentication("administrator", "administrator".toCharArray());
    }
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) SiteService(org.alfresco.service.cmr.site.SiteService) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException)

Example 18 with SiteService

use of org.alfresco.service.cmr.site.SiteService in project alfresco-repository by Alfresco.

the class SiteServiceImplTest method testDeleteSite.

@Test
public void testDeleteSite() {
    @SuppressWarnings("deprecation") SiteService smallSiteService = (SiteService) this.applicationContext.getBean("siteService");
    // Create a test group
    final String testGroupName = "siteServiceImplTestGroup_" + GUID.generate();
    String testGroup = AuthenticationUtil.runAs(new AuthenticationUtil.RunAsWork<String>() {

        public String doWork() throws Exception {
            return authorityService.createAuthority(AuthorityType.GROUP, testGroupName);
        }
    }, AuthenticationUtil.getAdminUserName());
    // Create a test site
    String siteShortName = "testUpdateSite";
    this.siteService.createSite(TEST_SITE_PRESET, siteShortName, TEST_TITLE, TEST_DESCRIPTION, SiteVisibility.PUBLIC);
    SiteInfo siteInfo = this.siteService.getSite(siteShortName);
    assertNotNull(siteInfo);
    // Add the test group as a member of the site
    this.siteService.setMembership(siteShortName, testGroup, SiteModel.SITE_CONTRIBUTOR);
    // Delete the site
    this.siteService.deleteSite(siteShortName);
    assertNull(this.siteService.getSite(siteShortName));
    NodeRef archivedNodeRef = nodeArchiveService.getArchivedNode(siteInfo.getNodeRef());
    assertTrue("Deleted sites can be recovered from the Trash.", nodeService.exists(archivedNodeRef));
    // related site groups should remain after site delete but should be deleted on site purge from trashcan.
    // Such case is tested in SiteServiceImplMoreTest.deleteSiteAndRestoreEnsuringSiteGroupsAreRecovered
    assertTrue(authorityService.authorityExists(((SiteServiceImpl) smallSiteService).getSiteGroup(siteShortName, true)));
    assertTrue(authorityService.authorityExists(((SiteServiceImpl) smallSiteService).getSiteGroup(siteShortName)));
    Set<String> permissions = permissionService.getSettablePermissions(SiteModel.TYPE_SITE);
    for (String permission : permissions) {
        String siteRoleGroup = ((SiteServiceImpl) smallSiteService).getSiteRoleGroup(siteShortName, permission, true);
        assertTrue(authorityService.authorityExists(siteRoleGroup));
    }
    // Ensure that the added "normal" groups have not been deleted
    assertTrue(authorityService.authorityExists(testGroup));
}
Also used : SiteInfo(org.alfresco.service.cmr.site.SiteInfo) NodeRef(org.alfresco.service.cmr.repository.NodeRef) SiteService(org.alfresco.service.cmr.site.SiteService) AuthenticationUtil(org.alfresco.repo.security.authentication.AuthenticationUtil) FilterPropString(org.alfresco.repo.node.getchildren.FilterPropString) AccessDeniedException(org.alfresco.repo.security.permissions.AccessDeniedException) UnknownAuthorityException(org.alfresco.repo.security.authority.UnknownAuthorityException) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) BaseAlfrescoSpringTest(org.alfresco.util.BaseAlfrescoSpringTest) Test(org.junit.Test)

Example 19 with SiteService

use of org.alfresco.service.cmr.site.SiteService in project alfresco-repository by Alfresco.

the class TaggingServiceImplTest method setUp.

@Before
public void setUp() throws Exception {
    // Detect any dangling transactions as there is a lot of direct UserTransaction manipulation
    if (AlfrescoTransactionSupport.getTransactionReadState() != TxnReadState.TXN_NONE) {
        throw new IllegalStateException("There should not be any transactions when starting test: " + AlfrescoTransactionSupport.getTransactionId() + " started at " + new Date(AlfrescoTransactionSupport.getTransactionStartTime()));
    }
    // Get services
    this.taggingService = (TaggingServiceImpl) applicationContext.getBean("taggingService");
    this.nodeService = (NodeService) applicationContext.getBean("NodeService");
    this.fileFolderService = (FileFolderService) applicationContext.getBean("FileFolderService");
    this.copyService = (CopyService) applicationContext.getBean("CopyService");
    this.checkOutCheckInService = (CheckOutCheckInService) applicationContext.getBean("CheckoutCheckinService");
    this.actionService = (ActionService) applicationContext.getBean("ActionService");
    this.transactionService = (TransactionService) applicationContext.getBean("transactionComponent");
    this.siteService = applicationContext.getBean("SiteService", SiteService.class);
    // MNT-10807 : Auditing does not take into account audit.filter.alfresco-access.transaction.user
    UserAuditFilter userAuditFilter = new UserAuditFilter();
    userAuditFilter.setUserFilterPattern("System;.*");
    userAuditFilter.afterPropertiesSet();
    AuditComponent auditComponent = (AuditComponent) applicationContext.getBean("auditComponent");
    auditComponent.setUserAuditFilter(userAuditFilter);
    AuditServiceImpl auditServiceImpl = (AuditServiceImpl) applicationContext.getBean("auditService");
    auditServiceImpl.setAuditComponent(auditComponent);
    this.auditService = (AuditService) applicationContext.getBean("auditService");
    this.scriptService = (ScriptService) applicationContext.getBean("scriptService");
    this.actionTrackingService = (ActionTrackingService) applicationContext.getBean("actionTrackingService");
    this.authenticationComponent = (AuthenticationComponent) applicationContext.getBean("authenticationComponent");
    this.personService = (PersonService) applicationContext.getBean("PersonService");
    this.permissionService = (PermissionService) applicationContext.getBean("PermissionService");
    this.authenticationService = (MutableAuthenticationService) applicationContext.getBean("authenticationService");
    this.nodeRefPropInterceptor = (NodeRefPropertyMethodInterceptor) applicationContext.getBean("nodeRefPropertyInterceptor");
    if (init == false) {
        this.transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<Void>() {

            @Override
            public Void execute() throws Throwable {
                // Authenticate as the system user
                authenticationComponent.setSystemUserAsCurrentUser();
                // Create the store and get the root node
                TaggingServiceImplTest.storeRef = nodeService.createStore(StoreRef.PROTOCOL_WORKSPACE, "Test_" + System.currentTimeMillis());
                TaggingServiceImplTest.rootNode = nodeService.getRootNode(TaggingServiceImplTest.storeRef);
                // Create the required tagging category
                NodeRef catContainer = nodeService.createNode(TaggingServiceImplTest.rootNode, ContentModel.ASSOC_CHILDREN, QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "categoryContainer"), ContentModel.TYPE_CONTAINER).getChildRef();
                NodeRef catRoot = nodeService.createNode(catContainer, ContentModel.ASSOC_CHILDREN, QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "categoryRoot"), ContentModel.TYPE_CATEGORYROOT).getChildRef();
                nodeService.createNode(catRoot, ContentModel.ASSOC_CATEGORIES, ContentModel.ASPECT_TAGGABLE, ContentModel.TYPE_CATEGORY).getChildRef();
                init = true;
                return null;
            }
        });
    }
    // We want to know when tagging actions have finished running
    asyncOccurs = new AsyncOccurs();
    ((PolicyComponent) applicationContext.getBean("policyComponent")).bindClassBehaviour(AsynchronousActionExecutionQueuePolicies.OnAsyncActionExecute.QNAME, ActionModel.TYPE_ACTION, new JavaBehaviour(asyncOccurs, "onAsyncActionExecute", NotificationFrequency.EVERY_EVENT));
    // We do want action tracking whenever the tag scope updater runs
    UpdateTagScopesActionExecuter updateTagsAction = (UpdateTagScopesActionExecuter) applicationContext.getBean("update-tagscope");
    updateTagsAction.setTrackStatus(true);
    // Create the folders and documents to be tagged
    createTestDocumentsAndFolders();
}
Also used : PolicyComponent(org.alfresco.repo.policy.PolicyComponent) UserAuditFilter(org.alfresco.repo.audit.UserAuditFilter) AuditComponent(org.alfresco.repo.audit.AuditComponent) SiteService(org.alfresco.service.cmr.site.SiteService) JavaBehaviour(org.alfresco.repo.policy.JavaBehaviour) AuditServiceImpl(org.alfresco.repo.audit.AuditServiceImpl) Before(org.junit.Before)

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