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

The following examples show how to use org.alfresco.service.ServiceRegistry#getNodeService() . 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: RuleServiceIntegrationTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
@BeforeClass public static void setupTest() throws Exception
{
	
	SERVICE_REGISTRY          = (ServiceRegistry)APP_CONTEXT_INIT.getApplicationContext().getBean(ServiceRegistry.SERVICE_REGISTRY);
    NODE_SERVICE              = SERVICE_REGISTRY.getNodeService();
    TRANSACTION_HELPER        = SERVICE_REGISTRY.getTransactionService().getRetryingTransactionHelper();
    ACTION_SERVICE			  = SERVICE_REGISTRY.getActionService();
    RULE_SERVICE			  = SERVICE_REGISTRY.getRuleService();
    CONTENT_SERVICE 		  = SERVICE_REGISTRY.getContentService();
    MAIL_ACTION_EXECUTER 		  = APP_CONTEXT_INIT.getApplicationContext().getBean("OutboundSMTP", ApplicationContextFactory.class).getApplicationContext().getBean("mail", MailActionExecuter.class);
    
    WAS_IN_TEST_MODE = MAIL_ACTION_EXECUTER.isTestMode();
    MAIL_ACTION_EXECUTER.setTestMode(true);
    
    Repository repositoryHelper = (Repository) APP_CONTEXT_INIT.getApplicationContext().getBean("repositoryHelper");
    COMPANY_HOME = repositoryHelper.getCompanyHome();
    
    // Create some static test content
    TEST_FOLDER = STATIC_TEST_NODES.createNode(COMPANY_HOME, "testFolder", ContentModel.TYPE_FOLDER, AuthenticationUtil.getAdminUserName());
   
}
 
Example 2
Source File: RetryingTransactionHelperTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Before
public void setUp() throws Exception
{
    dialect = (Dialect) applicationContext.getBean("dialect");

    serviceRegistry = (ServiceRegistry) applicationContext.getBean(ServiceRegistry.SERVICE_REGISTRY);
    authenticationComponent = (AuthenticationComponent) applicationContext.getBean("authenticationComponent");
    transactionService = serviceRegistry.getTransactionService();
    nodeService = serviceRegistry.getNodeService();
    txnHelper = transactionService.getRetryingTransactionHelper();

    // authenticate
    authenticationComponent.setSystemUserAsCurrentUser();

    StoreRef storeRef = nodeService.createStore(
            StoreRef.PROTOCOL_WORKSPACE,
            "test-" + System.currentTimeMillis());
    rootNodeRef = nodeService.getRootNode(storeRef);
    // Create a node to work on
    workingNodeRef = nodeService.createNode(
            rootNodeRef,
            ContentModel.ASSOC_CHILDREN,
            QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, GUID.generate()),
            ContentModel.TYPE_CMOBJECT).getChildRef();
}
 
Example 3
Source File: RuleTriggerTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Before
public void before() throws Exception
{
    ServiceRegistry serviceRegistry = (ServiceRegistry) applicationContext.getBean(ServiceRegistry.SERVICE_REGISTRY);
    this.nodeService = serviceRegistry.getNodeService();
    this.contentService = serviceRegistry.getContentService();
    
    AuthenticationUtil.setRunAsUser(AuthenticationUtil.getSystemUserName());
    
    this.testStoreRef = this.nodeService.createStore(StoreRef.PROTOCOL_WORKSPACE, "Test_" + System.currentTimeMillis());
    this.rootNodeRef = this.nodeService.getRootNode(this.testStoreRef);
}
 
Example 4
Source File: FileFolderDuplicateChildTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void setUp() throws Exception
{
    ServiceRegistry serviceRegistry = (ServiceRegistry) ctx.getBean("ServiceRegistry");
    transactionService = serviceRegistry.getTransactionService();
    retryingTransactionHelper = transactionService.getRetryingTransactionHelper();
    nodeService = serviceRegistry.getNodeService();
    fileFolderService = serviceRegistry.getFileFolderService();
    authenticationComponent = (AuthenticationComponent) ctx.getBean("authenticationComponent");

    RetryingTransactionCallback<NodeRef> callback = new RetryingTransactionCallback<NodeRef>()
    {
        public NodeRef execute() throws Throwable
        {
            // authenticate
            authenticationComponent.setCurrentUser(authenticationComponent.getSystemUserName());
            
            // create a test store
            StoreRef storeRef = nodeService.createStore(StoreRef.PROTOCOL_WORKSPACE, getName() + System.currentTimeMillis());
            rootNodeRef = nodeService.getRootNode(storeRef);
            
            // create a folder to import into
            NodeRef nodeRef = nodeService.createNode(
                    rootNodeRef,
                    ContentModel.ASSOC_CHILDREN,
                    QName.createQName(NamespaceService.ALFRESCO_URI, "working root"),
                    ContentModel.TYPE_FOLDER).getChildRef();
            // Done
            return nodeRef;
        }
    };
    workingRootNodeRef = retryingTransactionHelper.doInTransaction(callback, false, true);
}
 
Example 5
Source File: RepositoryStartStopTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void doTestBasicWriteOperations(ApplicationContext ctx) throws Exception
{
    // Grab the beans we need
    serviceRegistry = (ServiceRegistry) ctx.getBean(ServiceRegistry.SERVICE_REGISTRY);
    transactionService = serviceRegistry.getTransactionService();
   
    // So we can write test nodes
    AuthenticationUtil.setRunAsUserSystem();
    
    // Check it looks fine
    assertFalse("The transaction is read-only - further unit tests are pointless.", transactionService.isReadOnly());
    
    // A basic write operation on a node
    RetryingTransactionCallback<Void> addPropertyCallback = new RetryingTransactionCallback<Void>()
    {
        public Void execute() throws Throwable
        {
            NodeService nodeService = serviceRegistry.getNodeService();
            NodeRef rootNodeRef = nodeService.getRootNode(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE);
            nodeService.setProperty(rootNodeRef, ContentModel.PROP_NAME, "SanityCheck");
            writeTestWorked = true;
            return null;
        }
    };
    
    // Now do a write operation, and ensure it worked
    writeTestWorked = false;
    transactionService.getRetryingTransactionHelper().doInTransaction(addPropertyCallback, false, true);
    assertTrue("The Node Write didn't occur or failed with an error", writeTestWorked);
}
 
Example 6
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 7
Source File: CheckOutCheckInServiceImplTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * On setup in transaction implementation
 */
@Before
public void before()
{
    // Set the services
    this.cociService = (CheckOutCheckInService)this.applicationContext.getBean("checkOutCheckInService");
    this.contentService = (ContentService)this.applicationContext.getBean("contentService");
    this.versionService = (VersionService)this.applicationContext.getBean("versionService");
    this.authenticationService = (MutableAuthenticationService)this.applicationContext.getBean("authenticationService");
    this.lockService = (LockService)this.applicationContext.getBean("lockService");
    this.transactionService = (TransactionService)this.applicationContext.getBean("transactionComponent");
    this.permissionService = (PermissionService)this.applicationContext.getBean("permissionService");
    this.copyService = (CopyService)this.applicationContext.getBean("copyService");
    this.personService = (PersonService) this.applicationContext.getBean("PersonService");
    ServiceRegistry serviceRegistry = (ServiceRegistry) this.applicationContext.getBean("ServiceRegistry");
    this.fileFolderService = serviceRegistry.getFileFolderService();
    this.nodeService = serviceRegistry.getNodeService();
    
    // Authenticate as system to create initial test data set
    this.authenticationComponent = (AuthenticationComponent)this.applicationContext.getBean("authenticationComponent");
    authenticationComponent.setSystemUserAsCurrentUser();
    
    RetryingTransactionCallback<Void> processInitWork = new RetryingTransactionCallback<Void>()
    {
        public Void execute() throws Throwable
        {
            initTestData();
            return null;
        }
    };
    // do the init test data in a new retrying transaction because
    // there may be problems with the DB that needs to be retried; 
    // That is how Alfresco works, it relies on optimistic locking and retries
    transactionService.getRetryingTransactionHelper().doInTransaction(processInitWork, false, true);

}
 
Example 8
Source File: ActivitiSpringTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
protected void setUp() throws Exception
{
    ConfigurableApplicationContext appContext = loadContext();
    this.repo = (RepositoryService) appContext.getBean("activitiRepositoryService");
    this.runtime = (RuntimeService) appContext.getBean("activitiRuntimeService");
    
    ServiceRegistry serviceRegistry = (ServiceRegistry) appContext.getBean(ServiceRegistry.SERVICE_REGISTRY);
    authenticationComponent = (AuthenticationComponent) appContext.getBean("authenticationComponent");
    TransactionService transactionService = serviceRegistry.getTransactionService();
    nodeService = serviceRegistry.getNodeService();
    txnHelper = transactionService.getRetryingTransactionHelper();

    // authenticate
    authenticationComponent.setSystemUserAsCurrentUser();
    
    StoreRef storeRef = nodeService.createStore(
            StoreRef.PROTOCOL_WORKSPACE,
            "test-" + getName() + "-" + System.currentTimeMillis());
    NodeRef rootNodeRef = nodeService.getRootNode(storeRef);
    // Create a node to work on
    workingNodeRef = nodeService.createNode(
            rootNodeRef,
            ContentModel.ASSOC_CHILDREN,
            QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, getName()),
            ContentModel.TYPE_CMOBJECT).getChildRef();

    String resource = "org/alfresco/repo/workflow/activiti/testTransaction.bpmn20.xml";
    ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
    InputStream input= classLoader.getResourceAsStream(resource);
    this.deployment = repo.createDeployment()
    .addInputStream(resource, input)
    .deploy();
}
 
Example 9
Source File: UpdateTagScopesActionExecuterTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Before
@Override
public void setUp() throws Exception
{
    applicationContext = ApplicationContextHelper.getApplicationContext();
    final ServiceRegistry registry = (ServiceRegistry) applicationContext.getBean(ServiceRegistry.SERVICE_REGISTRY);

    nodeService = registry.getNodeService();
    actionService = registry.getActionService();
    actionExecuter = (UpdateTagScopesActionExecuter) applicationContext.getBean(UPDATE_TAGSCOPE_ACTION_EXECUTER_BEAN_NAME);
    taggingService = registry.getTaggingService();
    fileFolderService = registry.getFileFolderService();
    transactionService = registry.getTransactionService();
    actionTrackingService = (ActionTrackingService) applicationContext.getBean(ACTION_TRACKING_SERVICE_BEAN_NAME);

    AuthenticationUtil.setAdminUserAsFullyAuthenticatedUser();

    expectedTagScopes = new LinkedList<NodeRef>();
    testTags = new LinkedList<String>();

    transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<Void>()
    {
        @Override
        public Void execute() throws Throwable
        {
            createTestContent(registry, expectedTagScopes);
            return null;
        }
    }, false, true);

    waitForTagScopeUpdate();

    transaction = transactionService.getUserTransaction();
    transaction.begin();
}
 
Example 10
Source File: JscriptWorkflowTask.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Creates a new instance of a workflow task from a WorkflowTask from the CMR workflow object model
 * 
 * @param task
 *            an instance of WorkflowTask from CMR workflow object model
 * @param serviceRegistry
 *            Service Registry object
 */
public JscriptWorkflowTask(WorkflowTask task, 
            ServiceRegistry serviceRegistry,
            Scriptable scope)
{
    this.serviceRegistry = serviceRegistry;
    this.namespaceProvider = new DefaultNamespaceProvider(serviceRegistry.getNamespaceService());
    this.workflowService = serviceRegistry.getWorkflowService();
    this.nodeService = serviceRegistry.getNodeService();
    this.dictionaryService = serviceRegistry.getDictionaryService();
    this.authenticationService = serviceRegistry.getAuthenticationService();
    this.task = task;
    this.setScope(scope);
}
 
Example 11
Source File: FFCLoadsOfFiles.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
public static void doExample(ServiceRegistry serviceRegistry) throws Exception
    {
        //
        // locate the company home node
        //
        SearchService searchService = serviceRegistry.getSearchService();
        NodeService nodeService = serviceRegistry.getNodeService();
        NamespaceService namespaceService = serviceRegistry.getNamespaceService();
        StoreRef storeRef = new StoreRef(StoreRef.PROTOCOL_WORKSPACE, "SpacesStore");
        NodeRef rootNodeRef = nodeService.getRootNode(storeRef);
        List<NodeRef> results = searchService.selectNodes(rootNodeRef, "/app:company_home", null, namespaceService, false);
        if (results.size() == 0)
        {
            throw new AlfrescoRuntimeException("Can't find /app:company_home");
        }
        NodeRef companyHomeNodeRef = results.get(0);
        results = searchService.selectNodes(companyHomeNodeRef, "./cm:LoadTest", null, namespaceService, false);
        final NodeRef loadTestHome;
        if (results.size() == 0)
        {
            loadTestHome = nodeService.createNode(
                    companyHomeNodeRef,
                    ContentModel.ASSOC_CHILDREN,
                    QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "LoadTest"),
                    ContentModel.TYPE_FOLDER).getChildRef();
        }
        else
        {
            loadTestHome = results.get(0);
        }

        if ((currentDoc + docsPerTx) > totalNumDocs)
        {
        	docsPerTx = totalNumDocs - currentDoc;
        }
        // Create new Space
        String spaceName = "Bulk Load Space (" + System.currentTimeMillis() + ") from " + currentDoc + " to " + (currentDoc + docsPerTx - 1) + " of " + totalNumDocs;
        Map<QName, Serializable> spaceProps = new HashMap<QName, Serializable>();
    	spaceProps.put(ContentModel.PROP_NAME, spaceName);
        NodeRef  newSpace = nodeService.createNode(loadTestHome, ContentModel.ASSOC_CONTAINS, QName.createQName(NamespaceService.CONTENT_MODEL_PREFIX, spaceName),ContentModel.TYPE_FOLDER,spaceProps).getChildRef();
        

        // create new content node within new Space home
        for (int k = 1;k<=docsPerTx;k++)
        {
    		currentDoc++;
    		System.out.println("About to start document " + currentDoc);
        	// assign name
        	String name = "BulkLoad (" + System.currentTimeMillis() + ") " + currentDoc ;
        	Map<QName, Serializable> contentProps = new HashMap<QName, Serializable>();
        	contentProps.put(ContentModel.PROP_NAME, name);
        	
        	// create content node
        	// NodeService nodeService = serviceRegistry.getNodeService();
        	ChildAssociationRef association = nodeService.createNode(newSpace, 
        			ContentModel.ASSOC_CONTAINS, 
        			QName.createQName(NamespaceService.CONTENT_MODEL_PREFIX, name),
        			ContentModel.TYPE_CONTENT,
        			contentProps);
        	NodeRef content = association.getChildRef();
        
        	// add titled aspect (for Web Client display)
        	Map<QName, Serializable> titledProps = new HashMap<QName, Serializable>();
        	titledProps.put(ContentModel.PROP_TITLE, name);
        	titledProps.put(ContentModel.PROP_DESCRIPTION, name);
        	nodeService.addAspect(content, ContentModel.ASPECT_TITLED, titledProps);
        	
        	//
        	// write some content to new node
        	//

        	ContentService contentService = serviceRegistry.getContentService();
        	ContentWriter writer = contentService.getWriter(content, ContentModel.PROP_CONTENT, true);
        	writer.setMimetype(MimetypeMap.MIMETYPE_TEXT_PLAIN);
        	writer.setEncoding("UTF-8");
        	String text = "This is some text in a doc";
        	writer.putContent(text);
    		System.out.println("About to get child assocs ");        	
        	//Circa
//        	nodeService.getChildAssocs(newSpace);
    	       for (int count=0;count<=10000;count++)
    	        {
    	        	nodeService.getChildAssocs(newSpace);
    	        }
       	
        }
    	//doSearch(searchService);
 		System.out.println("About to end transaction " );

    }
 
Example 12
Source File: AbstractWorkflowServiceIntegrationTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
@SuppressWarnings("deprecation")
@Before
public void before() throws Exception
{
    serviceRegistry = (ServiceRegistry) applicationContext.getBean(ServiceRegistry.SERVICE_REGISTRY);
    this.workflowService = serviceRegistry.getWorkflowService();
    this.authenticationComponent = (AuthenticationComponent) applicationContext.getBean("authenticationComponent");
    this.nodeService = serviceRegistry.getNodeService();
    this.historyService = (HistoryService) applicationContext.getBean("activitiHistoryService");
    Repository repositoryHelper = (Repository) applicationContext.getBean("repositoryHelper");
    this.companyHome = repositoryHelper.getCompanyHome();
    try
    {
        this.transactionService = (TransactionServiceImpl) serviceRegistry.getTransactionService();
    }
    catch (ClassCastException e)
    {
        throw new AlfrescoRuntimeException("The AbstractWorkflowServiceIntegrationTest needs direct access to the TransactionServiceImpl");
    }

    MutableAuthenticationService authenticationService = serviceRegistry.getAuthenticationService();
    AuthorityService authorityService = serviceRegistry.getAuthorityService();
    PersonService personService = serviceRegistry.getPersonService();

    authenticationComponent.setSystemUserAsCurrentUser();

    WorkflowAdminServiceImpl workflowAdminService = (WorkflowAdminServiceImpl) applicationContext.getBean(WorkflowAdminServiceImpl.NAME);
    this.wfTestHelper = new WorkflowTestHelper(workflowAdminService, getEngine(), true);
    
    // create test users
    this.personManager = new TestPersonManager(authenticationService, personService, nodeService);
    this.groupManager = new TestGroupManager(authorityService);
    
    personManager.createPerson(USER1);
    personManager.createPerson(USER2);
    personManager.createPerson(USER3);
    personManager.createPerson(USER4);

    // create test groups
    groupManager.addGroupToParent(GROUP, SUB_GROUP);
    
    // add users to groups
    groupManager.addUserToGroup(GROUP, USER1);
    groupManager.addUserToGroup(SUB_GROUP, USER2);
    
    personManager.setUser(USER1);
}
 
Example 13
Source File: OpenCmisLocalTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * MNT-14687 - Creating a document as checkedout and then cancelling the
 * checkout should delete the document.
 * 
 * This test would have fit better within CheckOutCheckInServiceImplTest but
 * was added here to make use of existing methods
 */
public void testCancelCheckoutWhileInCheckedOutState()
{
    ServiceRegistry serviceRegistry = (ServiceRegistry) ctx.getBean(ServiceRegistry.SERVICE_REGISTRY);
    CheckOutCheckInService cociService = serviceRegistry.getCheckOutCheckInService();

    // Authenticate as system
    AuthenticationComponent authenticationComponent = (AuthenticationComponent) ctx.getBean(BEAN_NAME_AUTHENTICATION_COMPONENT);
    authenticationComponent.setSystemUserAsCurrentUser();

    /* Create the document using openCmis services */
    Repository repository = getRepository("admin", "admin");
    Session session = repository.createSession();
    Folder rootFolder = session.getRootFolder();

    // Set file properties
    String docname = "myDoc-" + GUID.generate() + ".txt";
    Map<String, String> props = new HashMap<String, String>();
    {
        props.put(PropertyIds.OBJECT_TYPE_ID, BaseTypeId.CMIS_DOCUMENT.value());
        props.put(PropertyIds.NAME, docname);
    }

    // Create some content
    byte[] byteContent = "Some content".getBytes();
    InputStream stream = new ByteArrayInputStream(byteContent);
    ContentStream contentStream = new ContentStreamImpl(docname, BigInteger.valueOf(byteContent.length), MIME_PLAIN_TEXT, stream);

    // Create the document
    Document doc1 = rootFolder.createDocument(props, contentStream, VersioningState.CHECKEDOUT);
    NodeRef doc1NodeRef = cmisIdToNodeRef(doc1.getId());
    NodeRef doc1WorkingCopy = cociService.getWorkingCopy(doc1NodeRef);

    /* Cancel Checkout */
    cociService.cancelCheckout(doc1WorkingCopy);

    /* Check if both the working copy and the document were deleted */
    NodeService nodeService = serviceRegistry.getNodeService();
    assertFalse(nodeService.exists(doc1NodeRef));
    assertFalse(nodeService.exists(doc1WorkingCopy));
}
 
Example 14
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 15
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 16
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 17
Source File: ImapServiceImplCacheTest.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");
    nodeService = serviceRegistry.getNodeService();
    authenticationService = serviceRegistry.getAuthenticationService();
    imapService = serviceRegistry.getImapService();
    searchService = serviceRegistry.getSearchService();
    namespaceService = serviceRegistry.getNamespaceService();
    fileFolderService = serviceRegistry.getFileFolderService();
    contentService = serviceRegistry.getContentService();
    
    authenticationService.authenticate(USER_NAME, USER_PASSWORD.toCharArray());

    String storePath = "workspace://SpacesStore";
    String companyHomePathInStore = "/app:company_home";

    StoreRef storeRef = new StoreRef(storePath);

    NodeRef storeRootNodeRef = nodeService.getRootNode(storeRef);

    List<NodeRef> nodeRefs = searchService.selectNodes(storeRootNodeRef, companyHomePathInStore, null, namespaceService, false);
    NodeRef companyHomeNodeRef = nodeRefs.get(0);

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

    // Creating IMAP test folder for IMAP root
    LinkedList<String> folders = new LinkedList<String>();
    folders.add(TEST_IMAP_FOLDER_NAME);
    FileInfo folder = FileFolderUtil.makeFolders(fileFolderService, companyHomeNodeRef, folders, ContentModel.TYPE_FOLDER);
    oldFile = fileFolderService.create(folder.getNodeRef(), "oldFile", ContentModel.TYPE_CONTENT);
    
    // Setting IMAP root
    RepositoryFolderConfigBean imapHome = new RepositoryFolderConfigBean();
    imapHome.setStore(storePath);
    imapHome.setRootPath(companyHomePathInStore);
    imapHome.setFolderPath(NamespaceService.CONTENT_MODEL_PREFIX + ":" + TEST_IMAP_FOLDER_NAME);
    imapServiceImpl.setImapHome(imapHome);
    
    // Starting IMAP
    imapServiceImpl.startupInTxn(true);
    
    nodeRefs = searchService.selectNodes(storeRootNodeRef,
            companyHomePathInStore + "/" + NamespaceService.CONTENT_MODEL_PREFIX + ":" + TEST_IMAP_FOLDER_NAME,
            null,
            namespaceService,
            false);
    testImapFolderNodeRef = nodeRefs.get(0);

}
 
Example 18
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 19
Source File: RenditionServiceImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Injects the ServiceRegistry bean.
 * @param serviceRegistry ServiceRegistry
 */
public void setServiceRegistry(ServiceRegistry serviceRegistry)
{
    this.contentService = serviceRegistry.getContentService();
    this.nodeService = serviceRegistry.getNodeService();
}
 
Example 20
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();
        }
    });

}