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

The following examples show how to use org.alfresco.service.ServiceRegistry#getFileFolderService() . 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: ScriptNode.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Constructor
 * 
 * @param nodeRef   The NodeRef this Node wrapper represents
 * @param services  The ServiceRegistry the Node can use to access services
 * @param scope     Root scope for this Node
 */
public ScriptNode(NodeRef nodeRef, ServiceRegistry services, Scriptable scope)
{
    if (nodeRef == null)
    {
        throw new IllegalArgumentException("NodeRef must be supplied.");
    }
    
    if (services == null)
    {
        throw new IllegalArgumentException("The ServiceRegistry must be supplied.");
    }
    
    this.nodeRef = nodeRef;
    this.id = nodeRef.getId();
    this.services = services;
    this.nodeService = services.getNodeService();
    this.fileFolderService = services.getFileFolderService();
    this.retryingTransactionHelper = services.getTransactionService().getRetryingTransactionHelper();
    this.scope = scope;
    renditionService2 = services.getRenditionService2();
    renditionDefinitionRegistry2 = renditionService2.getRenditionDefinitionRegistry2();
    synchronousTransformClient = services.getSynchronousTransformClient();
}
 
Example 2
Source File: SOLRWebScriptTest.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
protected void setUp() throws Exception
{
    super.setUp();
    ctx = getServer().getApplicationContext();

    ServiceRegistry serviceRegistry = (ServiceRegistry) ctx.getBean(ServiceRegistry.SERVICE_REGISTRY);
    transactionService = serviceRegistry.getTransactionService();
    nodeService = serviceRegistry.getNodeService();
    fileFolderService = serviceRegistry.getFileFolderService();
    namespaceService = serviceRegistry.getNamespaceService();
    txnHelper = transactionService.getRetryingTransactionHelper();
    nodeDAO = (NodeDAO)ctx.getBean("nodeDAO");
    solrTrackingComponent = (SOLRTrackingComponent) ctx.getBean("solrTrackingComponent");

    admin = AuthenticationUtil.getAdminUserName();

    AuthenticationUtil.setFullyAuthenticatedUser(admin);
    
    storeRef = nodeService.createStore(StoreRef.PROTOCOL_WORKSPACE, getName() + ".1." + System.currentTimeMillis());
    rootNodeRef = nodeService.getRootNode(storeRef);
}
 
Example 3
Source File: GetMethodRegressionTest.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Before
public void setUp() throws Exception
{
    applicationContext = ApplicationContextHelper.getApplicationContext();
    ServiceRegistry registry = (ServiceRegistry) applicationContext.getBean(ServiceRegistry.SERVICE_REGISTRY);
    davHelper = (WebDAVHelper) applicationContext.getBean(WebDAVHelper.BEAN_NAME);
    auditRegistry = (AuditModelRegistryImpl) applicationContext.getBean(AUDIT_REGISTRY_BEAN_NAME);

    auditService = registry.getAuditService();
    fileFolderService = registry.getFileFolderService();
    transactionService = registry.getTransactionService();

    testingMethod = new GetMethod();
    mockResponse = new MockHttpServletResponse();

    restartTransaction(TransactionActionEnum.ACTION_NONE);
    AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());

    companyHomeNodeRef = registry.getNodeLocatorService().getNode(CompanyHomeNodeLocator.NAME, null, null);
    rootTestFolder = fileFolderService.create(companyHomeNodeRef, ROOT_TEST_FOLDER_NAME, ContentModel.TYPE_FOLDER).getNodeRef();
}
 
Example 4
Source File: LargeArchiveAndRestoreTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public void setUp() throws Exception
{
    ctx = ApplicationContextHelper.getApplicationContext();
    ServiceRegistry serviceRegistry = (ServiceRegistry) ctx.getBean("ServiceRegistry");
    nodeService = serviceRegistry.getNodeService();
    fileFolderService = serviceRegistry.getFileFolderService();
    nodeArchiveService = (NodeArchiveService) ctx.getBean("nodeArchiveService");
    authenticationComponent = (AuthenticationComponent) ctx.getBean("authenticationComponent");
    transactionService = serviceRegistry.getTransactionService();
    
    try
    {
        authenticationComponent.setSystemUserAsCurrentUser();
        
        // create a test store
        StoreRef storeRef = new StoreRef(StoreRef.PROTOCOL_WORKSPACE, "SpacesStore");
        rootNodeRef = nodeService.getRootNode(storeRef);
    }
    finally
    {
        authenticationComponent.clearCurrentSecurityContext();
    }
}
 
Example 5
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 6
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 7
Source File: FixedAclUpdaterTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void setUp() throws Exception
{
    ctx = ApplicationContextHelper.getApplicationContext();
    ServiceRegistry serviceRegistry = (ServiceRegistry) ctx.getBean(ServiceRegistry.SERVICE_REGISTRY);
    txnHelper = serviceRegistry.getTransactionService().getRetryingTransactionHelper();
    fileFolderService = serviceRegistry.getFileFolderService();
    repository = (Repository) ctx.getBean("repositoryHelper");
    fixedAclUpdater = (FixedAclUpdater) ctx.getBean("fixedAclUpdater");
    permissionsDaoComponent = (PermissionsDaoComponent) ctx.getBean("admPermissionsDaoComponent");
    permissionService = (PermissionService) ctx.getBean("permissionService");
    nodeDAO = (NodeDAO) ctx.getBean("nodeDAO");

    AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getSystemUserName());

    NodeRef home = repository.getCompanyHome();
    // create a folder hierarchy for which will change permission inheritance
    int[] filesPerLevel = { 5, 5, 10 };
    RetryingTransactionCallback<NodeRef> cb1 = createFolderHierchyCallback(home, fileFolderService, "rootFolderAsyncCall",
            filesPerLevel);
    folderAsyncCallNodeRef = txnHelper.doInTransaction(cb1);

    RetryingTransactionCallback<NodeRef> cb2 = createFolderHierchyCallback(home, fileFolderService, "rootFolderSyncCall",
            filesPerLevel);
    folderSyncCallNodeRef = txnHelper.doInTransaction(cb2);

    // change setFixedAclMaxTransactionTime to lower value so setInheritParentPermissions on created folder
    // hierarchy require async call
    setFixedAclMaxTransactionTime(permissionsDaoComponent, home, 50);

}
 
Example 8
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 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: 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 11
Source File: AbstractMultilingualTestCases.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
protected void setUp() throws Exception
{
    nodeArchiveService = (NodeArchiveService) ctx.getBean("nodeArchiveService");
    serviceRegistry = (ServiceRegistry) ctx.getBean(ServiceRegistry.SERVICE_REGISTRY);
    authenticationComponent = (AuthenticationComponent) ctx.getBean("AuthenticationComponent");
    transactionService = serviceRegistry.getTransactionService();
    nodeService = serviceRegistry.getNodeService();
    fileFolderService = serviceRegistry.getFileFolderService();
    versionService = serviceRegistry.getVersionService();
    multilingualContentService = (MultilingualContentService) ctx.getBean("MultilingualContentService");
    contentFilterLanguagesService = (ContentFilterLanguagesService) ctx.getBean("ContentFilterLanguagesService");
    editionService = (EditionService) ctx.getBean("EditionService");

    // Run as admin
    authenticationComponent.setCurrentUser(AuthenticationUtil.getAdminUserName());

    // Create a folder to work in
    RetryingTransactionCallback<NodeRef> createFolderCallback = new RetryingTransactionCallback<NodeRef>()
    {
        public NodeRef execute() throws Exception
        {
            StoreRef storeRef = new StoreRef(StoreRef.PROTOCOL_WORKSPACE, "SpacesStore");
            NodeRef rootNodeRef = nodeService.getRootNode(storeRef);
            // Create the folder
            NodeRef folderNodeRef = nodeService.createNode(
                    rootNodeRef,
                    ContentModel.ASSOC_CHILDREN,
                    QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "testFolder"),
                    ContentModel.TYPE_FOLDER).getChildRef();
            // done
            return folderNodeRef;
        }
    };
    folderNodeRef = transactionService.getRetryingTransactionHelper().doInTransaction(createFolderCallback);
}
 
Example 12
Source File: LanguagesTest.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) ctx.getBean("ServiceRegistry");
    transactionService = serviceRegistry.getTransactionService();
    nodeService = serviceRegistry.getNodeService();
    fileFolderService = serviceRegistry.getFileFolderService();
    
    // 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();
}
 
Example 13
Source File: DuplicateAuthorityTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void setUp() throws Exception
{
    if (AlfrescoTransactionSupport.getTransactionReadState() != TxnReadState.TXN_NONE)
    {
        throw new AlfrescoRuntimeException(
                "A previous tests did not clean up transaction: " +
                AlfrescoTransactionSupport.getTransactionId());
    }
    
    ServiceRegistry serviceRegistry = (ServiceRegistry) ctx.getBean("ServiceRegistry");
    transactionService = serviceRegistry.getTransactionService();
    retryingTransactionHelper = transactionService.getRetryingTransactionHelper();
    retryingTransactionHelper.setMaxRetryWaitMs(10);
    nodeService = serviceRegistry.getNodeService();
    fileFolderService = serviceRegistry.getFileFolderService();
    authenticationComponent = (AuthenticationComponent) ctx.getBean("authenticationComponent");
    authorityService = (AuthorityService) ctx.getBean("authorityService");
    personService = (PersonService) ctx.getBean("personService");

    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 14
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 15
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 16
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 17
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 18
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 19
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 20
Source File: AuditComponentTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public void setUp() throws Exception
{
    auditModelRegistry = (AuditModelRegistryImpl) ctx.getBean("auditModel.modelRegistry");
    //MNT-10807 : Auditing does not take into account audit.filter.alfresco-access.transaction.user
    UserAuditFilter userAuditFilter = new UserAuditFilter();
    userAuditFilter.setUserFilterPattern("~System;~null;.*");
    userAuditFilter.afterPropertiesSet();
    auditComponent = (AuditComponentImpl) ctx.getBean("auditComponent");
    auditComponent.setUserAuditFilter(userAuditFilter);
    serviceRegistry = (ServiceRegistry) ctx.getBean(ServiceRegistry.SERVICE_REGISTRY);
    auditService = serviceRegistry.getAuditService();
    transactionService = serviceRegistry.getTransactionService();
    transactionServiceImpl = (TransactionServiceImpl) ctx.getBean("transactionService");
    nodeService = serviceRegistry.getNodeService();
    fileFolderService = serviceRegistry.getFileFolderService();
    
    // Register the test model
    URL testModelUrl = ResourceUtils.getURL("classpath:alfresco/testaudit/alfresco-audit-test.xml");
    auditModelRegistry.registerModel(testModelUrl);
    auditModelRegistry.loadAuditModels();
    
    RunAsWork<NodeRef> testRunAs = new RunAsWork<NodeRef>()
    {
        public NodeRef doWork() throws Exception
        {
            return nodeService.getRootNode(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE);
        }
    };
    nodeRef = AuthenticationUtil.runAs(testRunAs, AuthenticationUtil.getSystemUserName());

    // Authenticate
    user = "User-" + getName();
    AuthenticationUtil.setFullyAuthenticatedUser(user);

    final RetryingTransactionCallback<Void> resetDisabledPathsCallback = new RetryingTransactionCallback<Void>()
    {
        public Void execute() throws Throwable
        {
            auditComponent.resetDisabledPaths(APPLICATION_TEST);
            auditComponent.resetDisabledPaths(APPLICATION_ACTIONS_TEST);
            return null;
        }
    };
    transactionService.getRetryingTransactionHelper().doInTransaction(resetDisabledPathsCallback);
}