Java Code Examples for org.alfresco.service.ServiceRegistry#getPermissionService()

The following examples show how to use org.alfresco.service.ServiceRegistry#getPermissionService() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FileImporterTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
public void setUp()
{
    ctx = ApplicationContextHelper.getApplicationContext();
    serviceRegistry = (ServiceRegistry) ctx.getBean(ServiceRegistry.SERVICE_REGISTRY);

    nodeService = serviceRegistry.getNodeService();
    searchService = serviceRegistry.getSearchService();
    dictionaryService = serviceRegistry.getDictionaryService();
    contentService = serviceRegistry.getContentService();
    authenticationService = (MutableAuthenticationService) ctx.getBean("authenticationService");
    authenticationComponent = (AuthenticationComponent) ctx.getBean("authenticationComponent");
    permissionService = serviceRegistry.getPermissionService();
    mimetypeService = serviceRegistry.getMimetypeService();
    namespaceService = serviceRegistry.getNamespaceService();
    transactionService = serviceRegistry.getTransactionService();

    authenticationComponent.setSystemUserAsCurrentUser();
    StoreRef storeRef = nodeService.createStore(StoreRef.PROTOCOL_WORKSPACE, "Test_" + System.currentTimeMillis());
    rootNodeRef = nodeService.getRootNode(storeRef);
}
 
Example 2
Source File: BulkMetadataGet.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Set the service registry
 * 
 * @param services  the service registry
 */
public void setServiceRegistry(ServiceRegistry services)
{
    this.services = services;
    this.nodeService = services.getNodeService();
    this.dictionaryService = services.getDictionaryService();
    this.permissionService = services.getPermissionService();
}
 
Example 3
Source File: AbstractCommentsWebScript.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void setServiceRegistry(ServiceRegistry serviceRegistry)
{
    this.serviceRegistry = serviceRegistry;
    this.nodeService = serviceRegistry.getNodeService();
    this.siteService = serviceRegistry.getSiteService();
    this.contentService = serviceRegistry.getContentService();
    this.personService = serviceRegistry.getPersonService();
    this.permissionService = serviceRegistry.getPermissionService();
}
 
Example 4
Source File: ImapServiceImplTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public void setUp() throws Exception
{
    ctx = ApplicationContextHelper.getApplicationContext();
    ServiceRegistry serviceRegistry = (ServiceRegistry) ctx.getBean("ServiceRegistry");
    transactionService = serviceRegistry.getTransactionService();
    nodeService = serviceRegistry.getNodeService();
    importerService = serviceRegistry.getImporterService();
    personService = serviceRegistry.getPersonService();
    authenticationService = serviceRegistry.getAuthenticationService();
    permissionService = serviceRegistry.getPermissionService();
    imapService = serviceRegistry.getImapService();
    searchService = serviceRegistry.getSearchService();
    namespaceService = serviceRegistry.getNamespaceService();
    fileFolderService = serviceRegistry.getFileFolderService();
    contentService = serviceRegistry.getContentService();
    
    flags = new Flags();
    flags.add(Flags.Flag.SEEN);
    flags.add(Flags.Flag.FLAGGED);
    flags.add(Flags.Flag.ANSWERED);
    flags.add(Flags.Flag.DELETED);

    // start the transaction
    txn = transactionService.getUserTransaction();
    txn.begin();
    authenticationService.authenticate(USER_NAME, USER_PASSWORD.toCharArray());

    // downgrade integrity
    IntegrityChecker.setWarnInTransaction();
    
    anotherUserName = "user" + System.currentTimeMillis();

    PropertyMap testUser = new PropertyMap();
    testUser.put(ContentModel.PROP_USERNAME, anotherUserName);
    testUser.put(ContentModel.PROP_FIRSTNAME, anotherUserName);
    testUser.put(ContentModel.PROP_LASTNAME, anotherUserName);
    testUser.put(ContentModel.PROP_EMAIL, anotherUserName + "@alfresco.com");
    testUser.put(ContentModel.PROP_JOBTITLE, "jobTitle");

    personService.createPerson(testUser);

    // create the ACEGI Authentication instance for the new user
    authenticationService.createAuthentication(anotherUserName, anotherUserName.toCharArray());

    user = new AlfrescoImapUser(anotherUserName + "@alfresco.com", anotherUserName, anotherUserName);

    NodeRef companyHomeNodeRef = findCompanyHomeNodeRef();

    ChildApplicationContextFactory imap = (ChildApplicationContextFactory) ctx.getBean("imap");
    ApplicationContext imapCtx = imap.getApplicationContext();
    imapServiceImpl = (ImapServiceImpl)imapCtx.getBean("imapService");

    // Creating IMAP test folder for IMAP root
    LinkedList<String> folders = new LinkedList<String>();
    folders.add(TEST_IMAP_FOLDER_NAME);
    FileFolderUtil.makeFolders(fileFolderService, companyHomeNodeRef, folders, ContentModel.TYPE_FOLDER);
    
    // Setting IMAP root
    RepositoryFolderConfigBean imapHome = new RepositoryFolderConfigBean();
    imapHome.setStore(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE.toString());
    imapHome.setRootPath(APP_COMPANY_HOME);
    imapHome.setFolderPath(NamespaceService.CONTENT_MODEL_PREFIX + ":" + TEST_IMAP_FOLDER_NAME);
    imapServiceImpl.setImapHome(imapHome);
    
    // Starting IMAP
    imapServiceImpl.startupInTxn(true);

    NodeRef storeRootNodeRef = nodeService.getRootNode(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE);

    List<NodeRef> nodeRefs = searchService.selectNodes(storeRootNodeRef ,
            APP_COMPANY_HOME + "/" + NamespaceService.CONTENT_MODEL_PREFIX + ":" + TEST_IMAP_FOLDER_NAME,
            null,
            namespaceService,
            false);
    testImapFolderNodeRef = nodeRefs.get(0);

    
    /* 
     * Importing test folders:
     * 
     * Test folder contains: "___-___folder_a"
     * 
     * "___-___folder_a" contains: "___-___folder_a_a",
     *                             "___-___file_a",
     *                             "Message_485.eml" (this is IMAP Message)
     *                           
     * "___-___folder_a_a" contains: "____-____file_a_a"
     * 
     */
    importInternal("imap/imapservice_test_folder_a.acp", testImapFolderNodeRef);

    reauthenticate(anotherUserName, anotherUserName);
}
 
Example 5
Source File: HiddenAspectTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Before
public void setup() throws SystemException, NotSupportedException
{
    ServiceRegistry serviceRegistry = (ServiceRegistry) ctx.getBean("ServiceRegistry");
    transactionService = serviceRegistry.getTransactionService();
    nodeService = serviceRegistry.getNodeService();
    fileFolderService = serviceRegistry.getFileFolderService();
    authenticationService = (MutableAuthenticationService) ctx.getBean("AuthenticationService");
    hiddenAspect = (HiddenAspect) ctx.getBean("hiddenAspect");
    interceptor = (FilenameFilteringInterceptor) ctx.getBean("filenameFilteringInterceptor");
    namespacePrefixResolver = (DictionaryNamespaceComponent) ctx.getBean("namespaceService");
    cociService = (CheckOutCheckInService) ctx.getBean("checkOutCheckInService");
    imapService = serviceRegistry.getImapService();
    personService = serviceRegistry.getPersonService();
    permissionService = serviceRegistry.getPermissionService();
    imapEnabled = serviceRegistry.getImapService().getImapServerEnabled();
    
    nodeDAO = (NodeDAO)ctx.getBean("nodeDAO");
    Properties properties = (Properties) ctx.getBean("global-properties");
    cmisDisableHide = Boolean.getBoolean(properties.getProperty("cmis.disable.hidden.leading.period.files"));
    
    // start the transaction
    txn = transactionService.getUserTransaction();
    txn.begin();
    
    username = "user" + System.currentTimeMillis();
    
    PropertyMap testUser = new PropertyMap();
    testUser.put(ContentModel.PROP_USERNAME, username);
    testUser.put(ContentModel.PROP_FIRSTNAME, username);
    testUser.put(ContentModel.PROP_LASTNAME, username);
    testUser.put(ContentModel.PROP_EMAIL, username + "@alfresco.com");
    testUser.put(ContentModel.PROP_JOBTITLE, "jobTitle");

    // authenticate
    AuthenticationUtil.setAdminUserAsFullyAuthenticatedUser();
    
    personService.createPerson(testUser);
    
    // create the ACEGI Authentication instance for the new user
    authenticationService.createAuthentication(username, username.toCharArray());
    
    user = new AlfrescoImapUser(username + "@alfresco.com", username, username);

    // create a test store
    storeRef = nodeService
            .createStore(StoreRef.PROTOCOL_WORKSPACE, getName() + System.currentTimeMillis());
    rootNodeRef = nodeService.getRootNode(storeRef);
    permissionService.setPermission(rootNodeRef, username, PermissionService.CREATE_CHILDREN, true);
    
    AuthenticationUtil.setFullyAuthenticatedUser(username);
    
    topNodeRef = nodeService.createNode(
            rootNodeRef,
            ContentModel.ASSOC_CHILDREN,
            QName.createQName(NamespaceService.ALFRESCO_URI, "working root"),
            ContentModel.TYPE_FOLDER).getChildRef();
    
    AuthenticationUtil.setAdminUserAsFullyAuthenticatedUser();
}
 
Example 6
Source File: FileFolderServiceImplTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public void setUp() throws Exception
{
    ServiceRegistry serviceRegistry = (ServiceRegistry) ctx.getBean("ServiceRegistry");
    transactionService = serviceRegistry.getTransactionService();
    nodeService = serviceRegistry.getNodeService();
    fileFolderService = serviceRegistry.getFileFolderService();
    permissionService = serviceRegistry.getPermissionService();
    authenticationService = (MutableAuthenticationService) ctx.getBean("AuthenticationService");
    dictionaryDAO = (DictionaryDAO) ctx.getBean("dictionaryDAO");
    tenantService = (TenantService) ctx.getBean("tenantService");
    cociService = serviceRegistry.getCheckOutCheckInService();
    
    // start the transaction
    txn = transactionService.getUserTransaction();
    txn.begin();

    // downgrade integrity
    IntegrityChecker.setWarnInTransaction();

    // authenticate
    AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());

    // create a test store
    StoreRef storeRef = nodeService
            .createStore(StoreRef.PROTOCOL_WORKSPACE, getName() + System.currentTimeMillis());
    rootNodeRef = nodeService.getRootNode(storeRef);

    // create a folder to import into
    workingRootNodeRef = nodeService.createNode(
            rootNodeRef,
            ContentModel.ASSOC_CHILDREN,
            QName.createQName(NamespaceService.ALFRESCO_URI, "working root"),
            ContentModel.TYPE_FOLDER).getChildRef();

    // import the test data
    ImporterService importerService = serviceRegistry.getImporterService();
    Location importLocation = new Location(workingRootNodeRef);
    InputStream is = getClass().getClassLoader().getResourceAsStream(IMPORT_VIEW);
    if (is == null)
    {
        throw new NullPointerException("Test resource not found: " + IMPORT_VIEW);
    }
    Reader reader = new InputStreamReader(is);
    importerService.importView(reader, importLocation, null, null);

    // Load test model
    DictionaryBootstrap bootstrap = new DictionaryBootstrap();
    List<String> bootstrapModels = new ArrayList<String>();
    bootstrapModels.add("org/alfresco/repo/model/filefolder/testModel.xml");
    List<String> labels = new ArrayList<String>();
    bootstrap.setModels(bootstrapModels);
    bootstrap.setLabels(labels);
    bootstrap.setDictionaryDAO(dictionaryDAO);
    bootstrap.setTenantService(tenantService);
    bootstrap.bootstrap();
    
    workingRootNodeRef1 = nodeService.createNode(
            rootNodeRef,
            ContentModel.ASSOC_CHILDREN,
            QName.createQName(NamespaceService.ALFRESCO_URI, "working root1"),
            QName.createQName("http://www.alfresco.org/test/filefoldertest/1.0", "folder")).getChildRef();
    nodeService.createNode(
            workingRootNodeRef1,
            ContentModel.ASSOC_CONTAINS,
            QName.createQName(NamespaceService.ALFRESCO_URI, "node1"),
            ContentModel.TYPE_CONTENT).getChildRef();
    nodeService.createNode(
            workingRootNodeRef1,
            QName.createQName("http://www.alfresco.org/test/filefoldertest/1.0", "contains1"),
            QName.createQName(NamespaceService.ALFRESCO_URI, "node2"),
            ContentModel.TYPE_CONTENT).getChildRef();
    
    // Make sure we hit the MLTranslationInterceptor, which is part of the Foundation API
    // See MNT-9114: FileFolderService method not registered in MLTranslationInterceptor
    I18NUtil.setContentLocale(Locale.ENGLISH);
}
 
Example 7
Source File: DocumentLinkServiceImplTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public void setUp() throws Exception
{
    ctx = ApplicationContextHelper.getApplicationContext();
    // Set up the services
    ServiceRegistry serviceRegistry = (ServiceRegistry) ctx.getBean("ServiceRegistry");
    transactionService = serviceRegistry.getTransactionService();
    documentLinkService = serviceRegistry.getDocumentLinkService();
    permissionService = serviceRegistry.getPermissionService();
    personService = serviceRegistry.getPersonService();
    siteService = serviceRegistry.getSiteService();
    fileFolderService = serviceRegistry.getFileFolderService();
    nodeService = serviceRegistry.getNodeService();
    cociService = serviceRegistry.getCheckOutCheckInService();

    // Start the transaction
    txn = transactionService.getUserTransaction();
    txn.begin();

    // Authenticate
    AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());

    /* Create the test user */
    Map<QName, Serializable> props = new HashMap<QName, Serializable>();
    props.put(ContentModel.PROP_USERNAME, TEST_USER);
    personService.createPerson(props);

    /*
     * Create the working test root 1 to which the user has read/write
     * permission
     */
    site1 = siteService.createSite("site1", GUID.generate(), "myTitle", "myDescription", SiteVisibility.PUBLIC).getNodeRef();
    permissionService.setPermission(site1, TEST_USER, PermissionService.ALL_PERMISSIONS, true);
    site1Folder1 = fileFolderService.create(site1, site1Folder1Name, ContentModel.TYPE_FOLDER).getNodeRef();
    site1File1 = fileFolderService.create(site1Folder1, site1File1Name, ContentModel.TYPE_CONTENT).getNodeRef();
    site1File2 = fileFolderService.create(site1Folder1, GUID.generate(), ContentModel.TYPE_CONTENT).getNodeRef();
    site1Folder2 = fileFolderService.create(site1, GUID.generate(), ContentModel.TYPE_FOLDER).getNodeRef();
    site1Folder3 = fileFolderService.create(site1, GUID.generate(), ContentModel.TYPE_FOLDER).getNodeRef();
    // create a link of site1File1 in site1Folder3 to test regular deletion
     documentLinkService.createDocumentLink(site1File2, site1Folder3);

    /* Create the working test root 2 to which the user has no permission */
    NodeRef site2 = siteService.createSite("site2", GUID.generate(), "myTitle", "myDescription", SiteVisibility.PRIVATE).getNodeRef();
    permissionService.setPermission(site2, TEST_USER, PermissionService.ALL_PERMISSIONS, false);
    site2File = fileFolderService.create(site2, GUID.generate(), ContentModel.TYPE_CONTENT).getNodeRef();
    site2Folder1 = fileFolderService.create(site2, GUID.generate(), ContentModel.TYPE_FOLDER).getNodeRef();
    site2Folder2 = fileFolderService.create(site2, GUID.generate(), ContentModel.TYPE_FOLDER).getNodeRef();
    // Create a link of site1File1 in site2Folder2 to test the deletion
    // without permission
    linkOfFile1Site2 = documentLinkService.createDocumentLink(site1File2, site2Folder2);
}
 
Example 8
Source File: VirtualizationIntegrationTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Before
public void setUp() throws Exception
{
    ctx = ApplicationContextHelper.getApplicationContext(CONFIG_LOCATIONS);;
    
    virtualizationConfigTestBootstrap = ctx.getBean(VIRTUALIZATION_CONFIG_TEST_BOOTSTRAP_BEAN_ID,
                                                    VirtualizationConfigTestBootstrap.class);

    // Get the required services
    ServiceRegistry serviceRegistry = (ServiceRegistry) ctx.getBean("ServiceRegistry");

    transactionService = serviceRegistry.getTransactionService();
    retryingTransactionHelper = serviceRegistry.getRetryingTransactionHelper();
    nodeService = serviceRegistry.getNodeService();
    contentService = serviceRegistry.getContentService();
    fileAndFolderService = serviceRegistry.getFileFolderService();
    permissionService = serviceRegistry.getPermissionService();

    authenticationComponent = ctx.getBean("authenticationComponent",
                                          AuthenticationComponent.class);

    environment = ctx.getBean("actualEnvironment",
                              ActualEnvironment.class);

    typeAndAspectsFormProcessor = ctx.getBean("typeAndAspectsFormProcessor",
                                              TypeAndAspectsFormProcessor.class);

    constraints = ctx.getBean("systemTemplateLocations",
                              SystemTemplateLocationsConstraint.class);

    Repository repository = ctx.getBean("repositoryHelper",
                                        Repository.class);

    if (!virtualizationConfigTestBootstrap.areVirtualFoldersEnabled())
    {
        // "use the force" and enable virtual folders
        SpringExtensionBundle vfBundle = ctx.getBean("smartFoldersBundle",
                                                     SpringExtensionBundle.class);
        vfBundle.start();
    }
    else
    {
        logger.info("Virtual folders are spring-enabled.");
    }

    this.authenticationComponent.setSystemUserAsCurrentUser();

    // start the transaction
    txn = transactionService.getUserTransaction();
    txn.begin();

    AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());
    companyHomeNodeRef = repository.getCompanyHome();
    testRootFolder = fileAndFolderService.create(companyHomeNodeRef,
                                                 TEST_ROOT_FOLDER_NAME,
                                                 ContentModel.TYPE_FOLDER);

    virtualFolder1NodeRef = createVirtualizedFolder(testRootFolder.getNodeRef(),
                                                    VIRTUAL_FOLDER_1_NAME,
                                                    TEST_TEMPLATE_1_JSON_SYS_PATH);
    rootNodeRef = nodeService.getRootNode(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE);
    setupMocks();
}
 
Example 9
Source File: ArchiveAndRestoreTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public void setUp() throws Exception
{
    ctx = ApplicationContextHelper.getApplicationContext();
    
    ServiceRegistry serviceRegistry = (ServiceRegistry) ctx.getBean("ServiceRegistry");
    nodeArchiveService = (NodeArchiveService) ctx.getBean("nodeArchiveService");
    nodeService = serviceRegistry.getNodeService();
    permissionService = serviceRegistry.getPermissionService();
    authenticationService = serviceRegistry.getAuthenticationService();
    authenticationComponent = (AuthenticationComponent) ctx.getBean("authenticationComponent");
    ownableService = (OwnableService) ctx.getBean("ownableService");
    transactionService = serviceRegistry.getTransactionService();
    DictionaryDAO dictionaryDao = (DictionaryDAO) ctx.getBean("dictionaryDAO");

    ClassLoader cl = ArchiveAndRestoreTest.class.getClassLoader();
    // load the test model
    InputStream modelStream = cl.getResourceAsStream("org/alfresco/repo/node/archive/archiveTest_model.xml");
    assertNotNull(modelStream);
    M2Model model = M2Model.createModel(modelStream);
    dictionaryDao.putModel(model);

    // Start a transaction
    txn = transactionService.getUserTransaction();
    txn.begin();
    
    // downgrade integrity checks
    IntegrityChecker.setWarnInTransaction();
    
    try
    {
        authenticationComponent.setSystemUserAsCurrentUser();
        // Create the work store
        workStoreRef = nodeService.createStore(StoreRef.PROTOCOL_WORKSPACE, getName() + System.currentTimeMillis());
        workStoreRootNodeRef = nodeService.getRootNode(workStoreRef);
        archiveStoreRef = nodeService.createStore(StoreRef.PROTOCOL_WORKSPACE, "archive" + getName() + System.currentTimeMillis());
        archiveStoreRootNodeRef = nodeService.getRootNode(archiveStoreRef);
        
        // Map the work store to the archive store.  This will already be wired into the NodeService.
        StoreArchiveMap archiveMap = (StoreArchiveMap) ctx.getBean("storeArchiveMap");
        archiveMap.put(workStoreRef, archiveStoreRef);
        
        TestWithUserUtils.createUser(USER_A, USER_A, workStoreRootNodeRef, nodeService, authenticationService);
        TestWithUserUtils.createUser(USER_B, USER_B, workStoreRootNodeRef, nodeService, authenticationService);
        TestWithUserUtils.createUser(USER_C, USER_C, workStoreRootNodeRef, nodeService, authenticationService);
        // grant A and B rights to the work store
        permissionService.setPermission(
                workStoreRootNodeRef,
                USER_A,
                PermissionService.ALL_PERMISSIONS,
                true);
        permissionService.setPermission(
                workStoreRootNodeRef,
                USER_B,
                PermissionService.ALL_PERMISSIONS,
                true);
        permissionService.setPermission(
                workStoreRootNodeRef,
                USER_C,
                PermissionService.ALL_PERMISSIONS,
                false);
    }
    finally
    {
        authenticationComponent.clearCurrentSecurityContext();
    }
    // authenticate as normal user
    authenticationService.authenticate(USER_A, USER_A.toCharArray());
    createNodeStructure();
}
 
Example 10
Source File: NodeServiceTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
@BeforeClass public static void setup() throws Exception
{
    I18NUtil.setLocale(null);

    serviceRegistry = (ServiceRegistry) APP_CONTEXT_INIT.getApplicationContext().getBean(ServiceRegistry.SERVICE_REGISTRY);
    nodeService = serviceRegistry.getNodeService();
    personService = serviceRegistry.getPersonService();
    contentService = serviceRegistry.getContentService();
    permissionService = serviceRegistry.getPermissionService();
    nodeDAO = (NodeDAO) APP_CONTEXT_INIT.getApplicationContext().getBean("nodeDAO");
    txnService = serviceRegistry.getTransactionService();
    policyComponent = (PolicyComponent) APP_CONTEXT_INIT.getApplicationContext().getBean("policyComponent");
    cannedQueryDAOForTesting = (CannedQueryDAO) APP_CONTEXT_INIT.getApplicationContext().getBean("cannedQueryDAOForTesting");
    
    // Get the caches for later testing
    nodesCache = (SimpleCache<Serializable, ValueHolder<Serializable>>) APP_CONTEXT_INIT.getApplicationContext().getBean("node.nodesSharedCache");
    propsCache = (SimpleCache<Serializable, ValueHolder<Serializable>>) APP_CONTEXT_INIT.getApplicationContext().getBean("node.propertiesSharedCache");
    aspectsCache = (SimpleCache<Serializable, ValueHolder<Serializable>>) APP_CONTEXT_INIT.getApplicationContext().getBean("node.aspectsSharedCache");
    
    // Clear the caches to remove fluff
    nodesCache.clear();
    propsCache.clear();
    aspectsCache.clear();
    
    AuthenticationUtil.setRunAsUserSystem();
    
    // create a first store directly
    RetryingTransactionCallback<NodeRef> createStoreWork = new RetryingTransactionCallback<NodeRef>()
    {
        public NodeRef execute()
        {
            StoreRef storeRef = nodeService.createStore(
                    StoreRef.PROTOCOL_WORKSPACE,
                    "Test_" + System.nanoTime());
            return nodeService.getRootNode(storeRef);
        }
    };
    rootNodeRef = txnService.getRetryingTransactionHelper().doInTransaction(createStoreWork);
    
    final QNameDAO qnameDAO = (QNameDAO) APP_CONTEXT_INIT.getApplicationContext().getBean("qnameDAO");
    deletedTypeQNameId = txnService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<Long>()
    {
        @Override
        public Long execute() throws Throwable
        {
            return qnameDAO.getOrCreateQName(ContentModel.TYPE_DELETED).getFirst();
        }
    });

}
 
Example 11
Source File: IncompleteNodeTaggerTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
public void setUp() throws Exception
{
    ApplicationContext ctx = ApplicationContextHelper.getApplicationContext();
    DictionaryDAO dictionaryDao = (DictionaryDAO) ctx.getBean("dictionaryDAO");
    ClassLoader cl = BaseNodeServiceTest.class.getClassLoader();
    // load the test model
    InputStream modelStream = cl.getResourceAsStream("org/alfresco/repo/node/integrity/IntegrityTest_model.xml");
    assertNotNull(modelStream);
    M2Model model = M2Model.createModel(modelStream);
    dictionaryDao.putModel(model);

    tagger = (IncompleteNodeTagger) ctx.getBean("incompleteNodeTagger");

    serviceRegistry = (ServiceRegistry) ctx.getBean(ServiceRegistry.SERVICE_REGISTRY);
    nodeService = serviceRegistry.getNodeService();
    authenticationService = serviceRegistry.getAuthenticationService();
    permissionService = serviceRegistry.getPermissionService();
    this.authenticationComponent = (AuthenticationComponent) ctx.getBean("authenticationComponent");
    
    this.authenticationComponent.setSystemUserAsCurrentUser();
    
    String user = getName();
    if (!authenticationService.authenticationExists(user))
    {
        authenticationService.createAuthentication(user, user.toCharArray());
    }
    
    // begin a transaction
    TransactionService transactionService = serviceRegistry.getTransactionService();
    txn = transactionService.getUserTransaction();
    txn.begin();
    StoreRef storeRef = new StoreRef(StoreRef.PROTOCOL_WORKSPACE, getName());
    if (!nodeService.exists(storeRef))
    {
        nodeService.createStore(storeRef.getProtocol(), storeRef.getIdentifier());
        rootNodeRef = nodeService.getRootNode(storeRef);
        // Make sure our user can do everything
        permissionService.setPermission(rootNodeRef, user, PermissionService.ALL_PERMISSIONS, true);
    }
    else
    {
        rootNodeRef = nodeService.getRootNode(storeRef);
    }
    
    properties = new PropertyMap();
    properties.put(IntegrityTest.TEST_PROP_TEXT_C, "abc");
    
    // Authenticate as a test-specific user
    authenticationComponent.setCurrentUser(user);
}
 
Example 12
Source File: ScriptCommentService.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 4 votes vote down vote up
public void setServiceRegistry(ServiceRegistry serviceRegistry)
{
    this.serviceRegistry = serviceRegistry;
    this.nodeService = serviceRegistry.getNodeService();
    this.permissionService = serviceRegistry.getPermissionService();
}
 
Example 13
Source File: PermissionActionEvaluator.java    From alfresco-repository with GNU Lesser General Public License v3.0 3 votes vote down vote up
/**
 * Construct
 * 
 * @param serviceRegistry ServiceRegistry
 * @param action Action
 * @param permission String...
 */
protected PermissionActionEvaluator(ServiceRegistry serviceRegistry, Action action, String... permission)
{
    super(serviceRegistry, action);
    this.permissions = permission;
    this.permissionService = serviceRegistry.getPermissionService();
}