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

The following examples show how to use org.alfresco.service.ServiceRegistry#getSearchService() . 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: AuditMethodInterceptorTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
@SuppressWarnings("deprecation")
@Override
public void setUp() throws Exception
{
    auditModelRegistry = (AuditModelRegistryImpl) ctx.getBean("auditModel.modelRegistry");
    serviceRegistry = (ServiceRegistry) ctx.getBean(ServiceRegistry.SERVICE_REGISTRY);
    auditComponent = (AuditComponent) ctx.getBean("auditComponent");
    auditService = serviceRegistry.getAuditService();
    transactionService = serviceRegistry.getTransactionService();
    transactionServiceImpl = (TransactionServiceImpl) ctx.getBean("transactionService");
    nodeService = serviceRegistry.getNodeService();
    searchService = serviceRegistry.getSearchService();

    AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getSystemUserName());
    nodeRef = nodeService.getRootNode(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE);

    // Register the models
    URL modelUrlMnt11072 = ResourceUtils.getURL("classpath:alfresco/testaudit/alfresco-audit-test-mnt-11072.xml");
    URL modelUrlMnt16748 = ResourceUtils.getURL("classpath:alfresco/testaudit/alfresco-audit-test-mnt-16748.xml");
    auditModelRegistry.registerModel(modelUrlMnt11072);
    auditModelRegistry.registerModel(modelUrlMnt16748);
    auditModelRegistry.loadAuditModels();
}
 
Example 2
Source File: FileFolderPerformanceTester.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public void setUp() throws Exception
{
    ServiceRegistry serviceRegistry = (ServiceRegistry) ctx.getBean(ServiceRegistry.SERVICE_REGISTRY);
    retryingTransactionHelper = (RetryingTransactionHelper) ctx.getBean("retryingTransactionHelper");
    authenticationComponent = (AuthenticationComponent) ctx.getBean("authenticationComponent");
    
    fileFolderService = serviceRegistry.getFileFolderService();
    searchService = serviceRegistry.getSearchService();
    namespaceService = serviceRegistry.getNamespaceService();
    nodeService = getNodeService();
    
    authenticate(USERNAME);
    
    rootFolderRef = getOrCreateRootFolder();
    
    dataFile = AbstractContentTransformerTest.loadQuickTestFile("txt");
}
 
Example 3
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 4
Source File: InviteSender.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
public InviteSender(ServiceRegistry services, Repository repository, MessageService messageService)
{
    this.actionService = services.getActionService();
    this.nodeService = services.getNodeService();
    this.personService = services.getPersonService();
    this.searchService = services.getSearchService();
    this.siteService = services.getSiteService();
    this.fileFolderService = services.getFileFolderService();
    this.repoAdminService = services.getRepoAdminService();
    this.namespaceService = services.getNamespaceService();
    this.repository = repository;
    this.messageService = messageService;
}
 
Example 5
Source File: TransactionCleanupTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
  @Before
  public void before()
  {
  	ServiceRegistry serviceRegistry = (ServiceRegistry)ctx.getBean("ServiceRegistry");
      NamespaceService namespaceService = serviceRegistry.getNamespaceService();
this.transactionService = serviceRegistry.getTransactionService();
this.authenticationService = (MutableAuthenticationService)ctx.getBean("authenticationService");
this.nodeService = serviceRegistry.getNodeService();
this.searchService = serviceRegistry.getSearchService();
this.nodeDAO = (NodeDAO)ctx.getBean("nodeDAO");
this.nodesCache = (SimpleCache<Serializable, Serializable>) ctx.getBean("node.nodesSharedCache");
      this.worker = (DeletedNodeCleanupWorker)ctx.getBean("nodeCleanup.deletedNodeCleanup");
      this.worker.setMinPurgeAgeDays(0);

  	this.helper = transactionService.getRetryingTransactionHelper();
      authenticationService.authenticate("admin", "admin".toCharArray());
      
StoreRef storeRef = new StoreRef(StoreRef.PROTOCOL_WORKSPACE, "SpacesStore");
NodeRef storeRoot = nodeService.getRootNode(storeRef);
List<NodeRef> nodeRefs = searchService.selectNodes(
        storeRoot, "/app:company_home", null, namespaceService, false);
final NodeRef companyHome = nodeRefs.get(0);

  	RetryingTransactionHelper.RetryingTransactionCallback<NodeRef> createNode = new RetryingTransactionHelper.RetryingTransactionCallback<NodeRef>()
  	{
	@Override
	public NodeRef execute() throws Throwable
	{
		return nodeService.createNode(companyHome, ContentModel.ASSOC_CONTAINS, QName.createQName("test", GUID.generate()), ContentModel.TYPE_CONTENT).getChildRef();
	}
  	};
  	this.nodeRef1 = helper.doInTransaction(createNode, false, true);
  	this.nodeRef2 = helper.doInTransaction(createNode, false, true);
  	this.nodeRef3 = helper.doInTransaction(createNode, false, true);
  	this.nodeRef4 = helper.doInTransaction(createNode, false, true);
  	this.nodeRef5 = helper.doInTransaction(createNode, false, true);
  }
 
Example 6
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 7
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 8
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);

}