Search in sources :

Example 1 with RepositoryFolderConfigBean

use of org.alfresco.util.config.RepositoryFolderConfigBean in project alfresco-repository by Alfresco.

the class ImapServiceImpl method startup.

/**
 * This method is run as System within a single transaction on startup.
 */
public void startup() {
    bindBehaviour();
    // Get NodeRefs for folders to ignore
    this.ignoreExtractionFolders = new HashSet<NodeRef>(ignoreExtractionFoldersBeans.length * 2);
    for (RepositoryFolderConfigBean ignoreExtractionFoldersBean : ignoreExtractionFoldersBeans) {
        NodeRef nodeRef = ignoreExtractionFoldersBean.getFolderPath(namespaceService, nodeService, searchService, fileFolderService);
        if (!ignoreExtractionFolders.add(nodeRef)) {
            // It was already in the set
            throw new AlfrescoRuntimeException("The folder extraction path has been referenced already: \n" + "   Folder: " + ignoreExtractionFoldersBean);
        }
    }
    // Locate or create IMAP home
    imapHomeNodeRef = imapHomeConfigBean.getOrCreateFolderPath(namespaceService, nodeService, searchService, fileFolderService);
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) RepositoryFolderConfigBean(org.alfresco.util.config.RepositoryFolderConfigBean) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException)

Example 2 with RepositoryFolderConfigBean

use of org.alfresco.util.config.RepositoryFolderConfigBean in project alfresco-repository by Alfresco.

the class ImapServiceImplCacheTest method setUp.

@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);
}
Also used : StoreRef(org.alfresco.service.cmr.repository.StoreRef) NodeRef(org.alfresco.service.cmr.repository.NodeRef) ApplicationContext(org.springframework.context.ApplicationContext) FileInfo(org.alfresco.service.cmr.model.FileInfo) RepositoryFolderConfigBean(org.alfresco.util.config.RepositoryFolderConfigBean) ServiceRegistry(org.alfresco.service.ServiceRegistry) ChildApplicationContextFactory(org.alfresco.repo.management.subsystems.ChildApplicationContextFactory) LinkedList(java.util.LinkedList)

Example 3 with RepositoryFolderConfigBean

use of org.alfresco.util.config.RepositoryFolderConfigBean in project alfresco-repository by Alfresco.

the class LoadTester method setUp.

@Override
public void setUp() throws Exception {
    ServiceRegistry serviceRegistry = (ServiceRegistry) ctx.getBean("ServiceRegistry");
    authenticationService = serviceRegistry.getAuthenticationService();
    imapService = serviceRegistry.getImapService();
    importerService = serviceRegistry.getImporterService();
    NodeService nodeService = serviceRegistry.getNodeService();
    SearchService searchService = serviceRegistry.getSearchService();
    NamespaceService namespaceService = serviceRegistry.getNamespaceService();
    PersonService personService = serviceRegistry.getPersonService();
    FileFolderService fileFolderService = serviceRegistry.getFileFolderService();
    TransactionService transactionService = serviceRegistry.getTransactionService();
    PermissionService permissionService = serviceRegistry.getPermissionService();
    // start the transaction
    UserTransaction txn = transactionService.getUserTransaction();
    txn.begin();
    authenticationService.authenticate(USER_NAME, USER_PASSWORD.toCharArray());
    anotherUserName = "test_imap_user";
    NodeRef person = personService.getPerson(anotherUserName);
    if (person != null) {
        personService.deletePerson(anotherUserName);
        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);
    }
    if (authenticationService.authenticationExists(anotherUserName)) {
        authenticationService.deleteAuthentication(anotherUserName);
    }
    authenticationService.createAuthentication(anotherUserName, anotherUserName.toCharArray());
    user = new AlfrescoImapUser(anotherUserName + "@alfresco.com", anotherUserName, anotherUserName);
    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();
    ImapServiceImpl imapServiceImpl = (ImapServiceImpl) imapCtx.getBean("imapService");
    // Delete test folder
    nodeRefs = searchService.selectNodes(storeRootNodeRef, companyHomePathInStore + "/" + NamespaceService.CONTENT_MODEL_PREFIX + ":" + TEST_IMAP_ROOT_FOLDER_NAME, null, namespaceService, false);
    if (nodeRefs.size() == 1) {
        NodeRef ch = nodeRefs.get(0);
        nodeService.deleteNode(ch);
    }
    // Creating IMAP test folder for IMAP root
    LinkedList<String> folders = new LinkedList<String>();
    folders.add(TEST_IMAP_ROOT_FOLDER_NAME);
    FileFolderServiceImpl.makeFolders(fileFolderService, companyHomeNodeRef, folders, ContentModel.TYPE_FOLDER);
    // Setting IMAP root
    RepositoryFolderConfigBean imapHome = new RepositoryFolderConfigBean();
    imapHome.setStore(storePath);
    imapHome.setRootPath(companyHomePathInStore);
    imapHome.setFolderPath(TEST_IMAP_ROOT_FOLDER_NAME);
    imapServiceImpl.setImapHome(imapHome);
    // Starting IMAP
    imapServiceImpl.startupInTxn(true);
    nodeRefs = searchService.selectNodes(storeRootNodeRef, companyHomePathInStore + "/" + NamespaceService.CONTENT_MODEL_PREFIX + ":" + TEST_IMAP_ROOT_FOLDER_NAME, null, namespaceService, false);
    // Used to create User's folder
    NodeRef userFolderRef = imapService.getUserImapHomeRef(anotherUserName);
    permissionService.setPermission(userFolderRef, anotherUserName, PermissionService.ALL_PERMISSIONS, true);
    importTestData("imap/load_test_data.acp", userFolderRef);
    reauthenticate(anotherUserName, anotherUserName);
    AlfrescoImapFolder testDataFolder = imapService.getOrCreateMailbox(user, TEST_DATA_FOLDER_NAME, true, false);
    SimpleStoredMessage m = testDataFolder.getMessages().get(0);
    m = testDataFolder.getMessage(m.getUid());
    AlfrescoImapFolder folder = imapService.getOrCreateMailbox(user, TEST_FOLDER_NAME, false, true);
    logger.info("Creating folders...");
    long t = System.currentTimeMillis();
    try {
        for (int i = 0; i < MESSAGE_QUANTITY; i++) {
            System.out.println("i = " + i);
            folder.appendMessage(m.getMimeMessage(), new Flags(), new Date());
        }
    } catch (Exception e) {
        logger.error(e, e);
    }
    t = System.currentTimeMillis() - t;
    logger.info("Create time: " + t + " ms (" + t / 1000 + " s (" + t / 60000 + " min))");
    txn.commit();
}
Also used : PersonService(org.alfresco.service.cmr.security.PersonService) RepositoryFolderConfigBean(org.alfresco.util.config.RepositoryFolderConfigBean) SimpleStoredMessage(com.icegreen.greenmail.store.SimpleStoredMessage) FileFolderService(org.alfresco.service.cmr.model.FileFolderService) PermissionService(org.alfresco.service.cmr.security.PermissionService) NodeRef(org.alfresco.service.cmr.repository.NodeRef) ApplicationContext(org.springframework.context.ApplicationContext) NamespaceService(org.alfresco.service.namespace.NamespaceService) SearchService(org.alfresco.service.cmr.search.SearchService) UserTransaction(javax.transaction.UserTransaction) StoreRef(org.alfresco.service.cmr.repository.StoreRef) TransactionService(org.alfresco.service.transaction.TransactionService) NodeService(org.alfresco.service.cmr.repository.NodeService) Flags(javax.mail.Flags) ChildApplicationContextFactory(org.alfresco.repo.management.subsystems.ChildApplicationContextFactory) LinkedList(java.util.LinkedList) Date(java.util.Date) IOException(java.io.IOException) PropertyMap(org.alfresco.util.PropertyMap) ServiceRegistry(org.alfresco.service.ServiceRegistry)

Example 4 with RepositoryFolderConfigBean

use of org.alfresco.util.config.RepositoryFolderConfigBean in project alfresco-repository by Alfresco.

the class ImapMessageTest method setUp.

@Override
public void setUp() throws Exception {
    ctx = ApplicationContextHelper.getApplicationContext();
    logger.debug("In SetUp");
    serviceRegistry = (ServiceRegistry) ctx.getBean("ServiceRegistry");
    transactionService = serviceRegistry.getTransactionService();
    nodeService = serviceRegistry.getNodeService();
    importerService = serviceRegistry.getImporterService();
    personService = serviceRegistry.getPersonService();
    authenticationService = serviceRegistry.getAuthenticationService();
    searchService = serviceRegistry.getSearchService();
    namespaceService = serviceRegistry.getNamespaceService();
    fileFolderService = serviceRegistry.getFileFolderService();
    // start the transaction
    UserTransaction txn = transactionService.getUserTransaction();
    txn.begin();
    authenticationService.authenticate(ADMIN_USER_NAME, ADMIN_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());
    StoreRef storeRef = new StoreRef(storePath);
    storeRootNodeRef = nodeService.getRootNode(storeRef);
    List<NodeRef> nodeRefs = searchService.selectNodes(storeRootNodeRef, companyHomePathInStore, null, namespaceService, false);
    NodeRef companyHomeNodeRef = nodeRefs.get(0);
    nodeRefs = searchService.selectNodes(storeRootNodeRef, companyHomePathInStore + "/" + NamespaceService.CONTENT_MODEL_PREFIX + ":" + IMAP_FOLDER_NAME, null, namespaceService, false);
    if (nodeRefs != null && nodeRefs.size() > 0) {
        fileFolderService.delete(nodeRefs.get(0));
    }
    ChildApplicationContextFactory imap = (ChildApplicationContextFactory) ctx.getBean("imap");
    ApplicationContext imapCtx = imap.getApplicationContext();
    ImapServiceImpl imapServiceImpl = (ImapServiceImpl) imapCtx.getBean("imapService");
    imapServer = (AlfrescoImapServer) imapCtx.getBean("imapServer");
    if (!imapServer.isImapServerEnabled()) {
        imapServer.setImapServerEnabled(true);
        imapServer.setHost(HOST);
        imapServer.setPort(PORT);
        imapServer.startup();
    }
    // Creating IMAP test folder for IMAP root
    LinkedList<String> folders = new LinkedList<String>();
    folders.add(IMAP_FOLDER_NAME);
    FileFolderUtil.makeFolders(fileFolderService, companyHomeNodeRef, folders, ContentModel.TYPE_FOLDER);
    // Setting IMAP root
    RepositoryFolderConfigBean imapHome = new RepositoryFolderConfigBean();
    imapHome.setStore(storePath);
    imapHome.setRootPath(companyHomePathInStore);
    imapHome.setFolderPath(NamespaceService.CONTENT_MODEL_PREFIX + ":" + IMAP_FOLDER_NAME);
    imapServiceImpl.setImapHome(imapHome);
    // Starting IMAP
    imapServiceImpl.startupInTxn(true);
    nodeRefs = searchService.selectNodes(storeRootNodeRef, companyHomePathInStore + "/" + NamespaceService.CONTENT_MODEL_PREFIX + ":" + 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);
    txn.commit();
    // Init mail client session
    Properties props = new Properties();
    props.setProperty("mail.imap.partialfetch", "false");
    this.session = Session.getDefaultInstance(props, null);
    // Get the store
    this.store = session.getStore(PROTOCOL);
    // this.store.connect(HOST, PORT, anotherUserName, anotherUserName);
    this.store.connect(imapServer.getHost(), imapServer.getPort(), anotherUserName, anotherUserName);
    // Get folder
    folder = (IMAPFolder) store.getFolder(TEST_FOLDER);
    folder.open(Folder.READ_ONLY);
    logger.debug("End SetUp");
}
Also used : UserTransaction(javax.transaction.UserTransaction) StoreRef(org.alfresco.service.cmr.repository.StoreRef) RepositoryFolderConfigBean(org.alfresco.util.config.RepositoryFolderConfigBean) ChildApplicationContextFactory(org.alfresco.repo.management.subsystems.ChildApplicationContextFactory) Properties(java.util.Properties) LinkedList(java.util.LinkedList) NodeRef(org.alfresco.service.cmr.repository.NodeRef) ApplicationContext(org.springframework.context.ApplicationContext) PropertyMap(org.alfresco.util.PropertyMap)

Example 5 with RepositoryFolderConfigBean

use of org.alfresco.util.config.RepositoryFolderConfigBean in project alfresco-repository by Alfresco.

the class ImapServiceImplTest method setUp.

@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);
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) ApplicationContext(org.springframework.context.ApplicationContext) PropertyMap(org.alfresco.util.PropertyMap) RepositoryFolderConfigBean(org.alfresco.util.config.RepositoryFolderConfigBean) ServiceRegistry(org.alfresco.service.ServiceRegistry) Flags(javax.mail.Flags) ChildApplicationContextFactory(org.alfresco.repo.management.subsystems.ChildApplicationContextFactory) LinkedList(java.util.LinkedList)

Aggregations

NodeRef (org.alfresco.service.cmr.repository.NodeRef)5 RepositoryFolderConfigBean (org.alfresco.util.config.RepositoryFolderConfigBean)5 LinkedList (java.util.LinkedList)4 ChildApplicationContextFactory (org.alfresco.repo.management.subsystems.ChildApplicationContextFactory)4 ApplicationContext (org.springframework.context.ApplicationContext)4 ServiceRegistry (org.alfresco.service.ServiceRegistry)3 StoreRef (org.alfresco.service.cmr.repository.StoreRef)3 PropertyMap (org.alfresco.util.PropertyMap)3 Flags (javax.mail.Flags)2 UserTransaction (javax.transaction.UserTransaction)2 SimpleStoredMessage (com.icegreen.greenmail.store.SimpleStoredMessage)1 IOException (java.io.IOException)1 Date (java.util.Date)1 Properties (java.util.Properties)1 AlfrescoRuntimeException (org.alfresco.error.AlfrescoRuntimeException)1 FileFolderService (org.alfresco.service.cmr.model.FileFolderService)1 FileInfo (org.alfresco.service.cmr.model.FileInfo)1 NodeService (org.alfresco.service.cmr.repository.NodeService)1 SearchService (org.alfresco.service.cmr.search.SearchService)1 PermissionService (org.alfresco.service.cmr.security.PermissionService)1