Java Code Examples for org.alfresco.service.cmr.model.FileFolderService

The following are top voted examples for showing how to use org.alfresco.service.cmr.model.FileFolderService. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: alfresco-repository   File: AlfrescoImapFolder.java   View source code 8 votes vote down vote up
/**
 *  Creates the EML message in the specified folder.
 *  
 *  @param folderFileInfo The folder to create message in.
 *  @param message The original MimeMessage.
 *  @return ID of the new message created 
 * @throws FileNotFoundException 
 * @throws FileExistsException 
 * @throws MessagingException 
 * @throws IOException 
 */
private long createMimeMessageInFolder(
        FileInfo folderFileInfo,
        MimeMessage message,
        Flags flags)
        throws FileExistsException, FileNotFoundException, IOException, MessagingException 
{
    String name = AlfrescoImapConst.MESSAGE_PREFIX + GUID.generate();
    FileFolderService fileFolderService = serviceRegistry.getFileFolderService();
    FileInfo messageFile = fileFolderService.create(folderFileInfo.getNodeRef(), name, ContentModel.TYPE_CONTENT);
    final long newMessageUid = (Long) messageFile.getProperties().get(ContentModel.PROP_NODE_DBID);
    name = AlfrescoImapConst.MESSAGE_PREFIX  + newMessageUid + AlfrescoImapConst.EML_EXTENSION;
    fileFolderService.rename(messageFile.getNodeRef(), name);
    Flags newFlags = new Flags(flags);
    newFlags.add(Flag.RECENT);
    imapService.setFlags(messageFile, newFlags, true);
    
    if (extractAttachmentsEnabled)
    {
        imapService.extractAttachments(messageFile.getNodeRef(), message);
    }
    // Force persistence of the message to the repository
    new IncomingImapMessage(messageFile, serviceRegistry, message);
    return newMessageUid;        
}
 
Example 2
Project: alfresco-repository   File: NodeMonitor.java   View source code 7 votes vote down vote up
/**
 * Class constructor
 * 
 * @param filesysCtx ContentContext
 * @param nodeService NodeService
 * @param policyComponent PolicyComponent
 * @param fileFolderService FileFolderService
 * @param permissionService PermissionService
 * @param transService TransactionService
 */
protected NodeMonitor(ContentContext filesysCtx, NodeService nodeService, PolicyComponent policyComponent,
		FileFolderService fileFolderService, PermissionService permissionService, TransactionService transService) {
	m_filesysCtx    = filesysCtx;
	
	// Set various services

	m_nodeService       = nodeService;
	m_policyComponent   = policyComponent;
	m_fileFolderService = fileFolderService;
	m_permissionService = permissionService;
	m_transService      = transService;
	
	// Initialize the node monitor
	
	init();
}
 
Example 3
Project: alfresco-repository   File: FileFolderLoader.java   View source code 7 votes vote down vote up
/**
 * @param repoState             keep track of repository readiness
 * @param transactionService    ensure proper rollback, where required
 * @param repositoryHelper      access standard repository paths
 * @param fileFolderService     perform actual file-folder manipulation
 */
public FileFolderLoader(
        RepositoryState repoState,
        TransactionService transactionService,
        Repository repositoryHelper,
        FileFolderService fileFolderService,
        NodeService nodeService,
        ContentService contentService,
        BehaviourFilter policyBehaviourFilter)
{
    this.repoState = repoState;
    this.transactionService = transactionService;
    this.repositoryHelper = repositoryHelper;
    this.fileFolderService = fileFolderService;
    this.nodeService = nodeService;
    this.contentService = contentService;
    this.policyBehaviourFilter = policyBehaviourFilter;
    
    this.normalDistribution = new NormalDistributionHelper();
}
 
Example 4
Project: alfresco-remote-api   File: WebDAVHelperIntegrationTest.java   View source code 7 votes vote down vote up
@Before
public void setUp()
{
    AuthenticationUtil.setAdminUserAsFullyAuthenticatedUser();
    
    webDAVHelper = (WebDAVHelper) ctx.getBean("webDAVHelper");
    fileFolderService = (FileFolderService) ctx.getBean("FileFolderService");
    nodeService = (NodeService) ctx.getBean("NodeService");
    
    StoreRef storeRef = nodeService.createStore("workspace", "WebDAVHelperTest-"+UUID.randomUUID());
    rootNodeRef = nodeService.getRootNode(storeRef);
    
    rootFolder = nodeService.createNode(rootNodeRef, ContentModel.ASSOC_CHILDREN,
                ContentModel.ASSOC_CHILDREN, ContentModel.TYPE_FOLDER).getChildRef();
    
    //eventPublisher = (EventPublisherForTestingOnly) ctx.getBean("eventPublisher");
}
 
Example 5
Project: alfresco-repository   File: ModelValidatorTest.java   View source code 7 votes vote down vote up
@Before
public void setUp() throws Exception
{
    ctx = ApplicationContextHelper.getApplicationContext();
    this.modelValidator = (ModelValidator)ctx.getBean("modelValidator");
    this.dictionaryDAO = (DictionaryDAO)ctx.getBean("dictionaryDAO");
    this.qnameDAO = (QNameDAO)ctx.getBean("qnameDAO");
    this.namespaceDAO = (NamespaceDAO)ctx.getBean("namespaceDAO");
    this.nodeService = (NodeService)ctx.getBean("NodeService");
    this.fileFolderService = (FileFolderService)ctx.getBean("FileFolderService");
    this.contentService = (ContentService)ctx.getBean("contentService");
    this.versionService = (VersionService)ctx.getBean("VersionService");
    this.transactionService = (TransactionService)ctx.getBean("TransactionService");
    this.nodeArchiveService = (NodeArchiveService)ctx.getBean("nodeArchiveService");

    this.modelName = "modelvalidatortest" + System.currentTimeMillis();
    addModel();
}
 
Example 6
Project: alfresco-remote-api   File: MoveMethod.java   View source code 7 votes vote down vote up
private void copyContentOnly(FileInfo sourceFileInfo, FileInfo destFileInfo, FileFolderService fileFolderService) throws WebDAVServerException
{
	ContentService contentService = getContentService();
    ContentReader reader = contentService.getReader(sourceFileInfo.getNodeRef(), ContentModel.PROP_CONTENT);
    if (reader == null)
    {
        // There is no content for the node if it is a folder
        if (!sourceFileInfo.isFolder())
        {
            // Non-folders should have content available.
            logger.error("Unable to get ContentReader for source node " + sourceFileInfo.getNodeRef());
            throw new WebDAVServerException(HttpServletResponse.SC_NOT_FOUND);
        }
    }
    else
    {
        ContentWriter contentWriter = contentService.getWriter(destFileInfo.getNodeRef(), ContentModel.PROP_CONTENT, true);
        contentWriter.putContent(reader);
    }
}
 
Example 7
Project: alfresco-repository   File: AlfrescoImapFolder.java   View source code 6 votes vote down vote up
/**
 * Moves the node <code>sourceNodeRef</code> extracted from the message id.
 * A part of a complex move operation.
 * 
 * @param folderInfo FileInfo
 * @param message MimeMessage
 * @param flags Flags
 * @param sourceNodeRef NodeRef
 * @return UUID of the moved node
 * @throws FileExistsException
 * @throws FileNotFoundException
 */
@SuppressWarnings("deprecation")
private long copyOrMoveNode(FileInfo folderInfo, MimeMessage message, Flags flags, NodeRef sourceNodeRef, boolean move)
        throws FileExistsException, FileNotFoundException
{
    FileFolderService fileFolderService = serviceRegistry.getFileFolderService();
    FileFilterMode.setClient(FileFilterMode.Client.imap);
    FileInfo messageFile = null;
    if (move)
    {
        fileFolderService.setHidden(sourceNodeRef, false);
        messageFile = fileFolderService.move(sourceNodeRef, folderInfo.getNodeRef(), null);
    }
    else
    {
        NodeRef newNodeRef = serviceRegistry.getCopyService().copyAndRename(sourceNodeRef, folderInfo.getNodeRef(), ContentModel.ASSOC_CONTAINS, null, false);
        fileFolderService.setHidden(newNodeRef, false);
        messageFile = fileFolderService.getFileInfo(newNodeRef);
    }
    final long newMessageUid = (Long) messageFile.getProperties().get(ContentModel.PROP_NODE_DBID);
    
    imapService.persistMessageHeaders(messageFile.getNodeRef(), message);
    
    Flags newFlags = new Flags(flags);
    newFlags.add(Flag.RECENT);
    
    imapService.setFlags(messageFile, newFlags, true);
    imapService.setFlag(messageFile, Flag.DELETED, false);
    
    return newMessageUid;
}
 
Example 8
Project: alfresco-repository   File: CMISTest.java   View source code 6 votes vote down vote up
protected void checkEncoding(FileFolderService ffs, AuthenticationComponent authenticationComponent,
        final ObjectData objectData, String expectedEncoding)
{
    // Authenticate as system to check the properties in alfresco
    authenticationComponent.setSystemUserAsCurrentUser();
    try
    {
        NodeRef doc1NodeRef = cmisIdToNodeRef(objectData.getId());
        doc1NodeRef.getId();

        FileInfo fileInfo = ffs.getFileInfo(doc1NodeRef);
        Map<QName, Serializable> properties2 = fileInfo.getProperties();

        ContentDataWithId contentData = (ContentDataWithId) properties2
                .get(QName.createQName("{http://www.alfresco.org/model/content/1.0}content"));
        String encoding = contentData.getEncoding();
        
        assertEquals(expectedEncoding, encoding);
    }
    finally
    {
        authenticationComponent.clearCurrentSecurityContext();
    }
}
 
Example 9
Project: alfresco-repository   File: ExporterComponentTest.java   View source code 6 votes vote down vote up
@Override
protected void onSetUpInTransaction() throws Exception
{
    nodeService = (NodeService)applicationContext.getBean(ServiceRegistry.NODE_SERVICE.getLocalName());
    exporterService = (ExporterService)applicationContext.getBean("exporterComponent");
    importerService = (ImporterService)applicationContext.getBean("importerComponent");
    fileFolderService = (FileFolderService) applicationContext.getBean("fileFolderService");
    categoryService = (CategoryService) applicationContext.getBean("categoryService");     
    transactionService = (TransactionService) applicationContext.getBean("transactionService");
    permissionService = (PermissionServiceSPI) applicationContext.getBean("permissionService");

    this.authenticationService = (MutableAuthenticationService) applicationContext.getBean("AuthenticationService");
    this.authenticationComponent = (AuthenticationComponent) applicationContext.getBean("authenticationComponent");
    this.authenticationComponent.setSystemUserAsCurrentUser();
    this.storeRef = nodeService.createStore(StoreRef.PROTOCOL_WORKSPACE, "Test_" + System.currentTimeMillis());
}
 
Example 10
Project: alfresco-repository   File: InviteSenderTest.java   View source code 6 votes vote down vote up
/**
 * @return ServiceRegistry
 */
private ServiceRegistry mockServices()
{
    ActionService mockActionService = mockActionService();
    NodeService mockNodeService = mockNodeService();
    PersonService mockPersonService = mockPersonService();
    SearchService mockSearchService = mockSearchService();
    SiteService mockSiteService = mockSiteService();
    FileFolderService mockFileFolderService = mockFileFolderService();
    RepoAdminService mockRepoAdminService = mockRepoAdminService();
    SysAdminParams sysAdminParams = new SysAdminParamsImpl();

    ServiceRegistry services = mock(ServiceRegistry.class);
    when(services.getActionService()).thenReturn(mockActionService);
    when(services.getNodeService()).thenReturn(mockNodeService);
    when(services.getPersonService()).thenReturn(mockPersonService);
    when(services.getSearchService()).thenReturn(mockSearchService);
    when(services.getSiteService()).thenReturn(mockSiteService);
    when(services.getFileFolderService()).thenReturn(mockFileFolderService);
    when(services.getSysAdminParams()).thenReturn(sysAdminParams);
    when(services.getRepoAdminService()).thenReturn(mockRepoAdminService);
    return services;
}
 
Example 11
Project: alfresco-repository   File: InviteSenderTest.java   View source code 6 votes vote down vote up
/**
 * Mocks up a FileFolderService that claims there are
 *  no localised templates available
 */
private FileFolderService mockFileFolderService()
{
    FileFolderService fileFolderService = mock(FileFolderService.class);
    when(fileFolderService.getLocalizedSibling( (NodeRef)null )).thenAnswer(
            new Answer<NodeRef>()
            {
                public NodeRef answer(InvocationOnMock invocation) throws Throwable
                {
                    Object[] o = invocation.getArguments();
                    if(o == null || o.length == 0) return null;
                    return (NodeRef)o[0];
                }
            }
    );
    return fileFolderService;
}
 
Example 12
Project: alfresco-repository   File: LockableAspectInterceptorTest.java   View source code 6 votes vote down vote up
@Before
public void setUp()
{
    appCtx = ApplicationContextHelper.getApplicationContext();
    // The user that will create locks, this should be different from the user that queries them (ALF-19465)
    lockOwner = "jbloggs";
    // The 'current' user.
    userName = AuthenticationUtil.getAdminUserName();
    AuthenticationUtil.setFullyAuthenticatedUser(userName);
    transactionService = (TransactionService) appCtx.getBean("TransactionService");
    nodeService = (NodeService) appCtx.getBean("NodeService");
    rawNodeService = (NodeService) appCtx.getBean("dbNodeService");
    lockStore = (LockStore) appCtx.getBean("lockStore");
    rootNode = nodeService.getRootNode(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE);
    interceptor = (LockableAspectInterceptor) appCtx.getBean("lockableAspectInterceptor");
    lockService = (LockService)appCtx.getBean("lockService");
    fileFolderService = (FileFolderService) appCtx.getBean("FileFolderService");
    actionService = (ActionService) appCtx.getBean("ActionService");
}
 
Example 13
Project: alfresco-repository   File: SOLRTrackingComponentTest.java   View source code 6 votes vote down vote up
@Override
public void setUp() throws Exception
{
    ServiceRegistry serviceRegistry = (ServiceRegistry) ctx.getBean(ServiceRegistry.SERVICE_REGISTRY);
    transactionService = serviceRegistry.getTransactionService();
    txnHelper = transactionService.getRetryingTransactionHelper();

    solrTrackingComponent = (SOLRTrackingComponent) ctx.getBean("solrTrackingComponent");
    nodeDAO = (NodeDAO)ctx.getBean("nodeDAO");
    qnameDAO = (QNameDAO) ctx.getBean("qnameDAO");
    dictionaryDAO =  (DictionaryDAO)ctx.getBean("dictionaryDAO");
    nodeService = (NodeService)ctx.getBean("NodeService");
    fileFolderService = (FileFolderService)ctx.getBean("FileFolderService");
    dictionaryService = serviceRegistry.getDictionaryService();
    namespaceService = serviceRegistry.getNamespaceService();
    authenticationComponent = (AuthenticationComponent)ctx.getBean("authenticationComponent");

    dbNodeService = (DbNodeServiceImpl)ctx.getBean("dbNodeService");
    dbNodeService.setEnableTimestampPropagation(false);

    authenticationComponent.setSystemUserAsCurrentUser();

    storeRef = nodeService.createStore(StoreRef.PROTOCOL_WORKSPACE, getName() + System.currentTimeMillis());
    rootNodeRef = nodeService.getRootNode(storeRef);
}
 
Example 14
Project: alfresco-repository   File: SOLRTrackingComponentTest.java   View source code 6 votes vote down vote up
SOLRTest(
    RetryingTransactionHelper txnHelper, FileFolderService fileFolderService,
    NodeDAO nodeDAO, QNameDAO qnameDAO, NodeService nodeService, DictionaryService dictionaryService,
    NodeRef rootNodeRef, String containerName, boolean doNodeChecks, boolean doMetaDataChecks)
    {
this.txnHelper = txnHelper;
this.nodeService = nodeService;
this.rootNodeRef = rootNodeRef;
this.fileFolderService = fileFolderService;
this.nodeDAO = nodeDAO;
this.qnameDAO = qnameDAO;
this.dictionaryService = dictionaryService;

this.containerName = containerName;
this.nodeAssertions = new HashMap<NodeRef, NodeAssertions>();
this.nodeIds = new ArrayList<Long>(getExpectedNumNodes());

this.doNodeChecks = doNodeChecks;
this.doMetaDataChecks = doMetaDataChecks;
this.doChecks = doNodeChecks || doMetaDataChecks;
    }
 
Example 15
Project: alfresco-repository   File: SOLRTrackingComponentTest.java   View source code 6 votes vote down vote up
SOLRTestResidualProperties(
    RetryingTransactionHelper txnHelper, FileFolderService fileFolderService,
    NodeDAO nodeDAO, QNameDAO qnameDAO, NodeService nodeService, DictionaryService dictionaryService,
    NodeRef rootNodeRef, String containerName, boolean doNodeChecks, boolean doMetaDataChecks)
    {
super(txnHelper, fileFolderService, nodeDAO, qnameDAO, nodeService, dictionaryService,rootNodeRef, containerName, doNodeChecks, doMetaDataChecks);
    }
 
Example 16
Project: alfresco-repository   File: ExecuteAllRulesActionExecuterTest.java   View source code 6 votes vote down vote up
/**
 * Called at the beginning of all tests
 */
@Override
protected void onSetUpInTransaction() throws Exception
{
    this.checkOutCheckInService = (CheckOutCheckInService) this.applicationContext.getBean("checkOutCheckInService");
    this.nodeService = (NodeService)this.applicationContext.getBean("nodeService");
    this.ruleService = (RuleService)this.applicationContext.getBean("ruleService");
    this.actionService = (ActionService)this.applicationContext.getBean("actionService");
    transactionHelper = (RetryingTransactionHelper)applicationContext.getBean("retryingTransactionHelper");
    fileFolderService = applicationContext.getBean("fileFolderService", FileFolderService.class);
    contentService = applicationContext.getBean("contentService", ContentService.class);
    
    AuthenticationComponent authenticationComponent = (AuthenticationComponent)applicationContext.getBean("authenticationComponent");
    authenticationComponent.setCurrentUser(authenticationComponent.getSystemUserName());
    
    // Create the store and get the root node
    this.testStoreRef = this.nodeService.createStore(
            StoreRef.PROTOCOL_WORKSPACE, "Test_"
                    + System.currentTimeMillis());
    this.rootNodeRef = this.nodeService.getRootNode(this.testStoreRef);

    // Get the executer instance 
    this.executer = (ExecuteAllRulesActionExecuter)this.applicationContext.getBean(ExecuteAllRulesActionExecuter.NAME);
}
 
Example 17
Project: alfresco-repository   File: TransitionSimpleWorkflowActionExecuterTest.java   View source code 6 votes vote down vote up
/**
 * Called at the begining of all tests
 */
@SuppressWarnings("deprecation")
@Override
protected void onSetUpInTransaction() throws Exception
{
    super.onSetUpInTransaction();
    
    fileFolderService = (FileFolderService)this.applicationContext.getBean("fileFolderService");
    
    // Create the node used for tests
    NodeRef container = this.nodeService.createNode(
            this.rootNodeRef,
            ContentModel.ASSOC_CHILDREN,
            QName.createQName("{test}testnode"),
            ContentModel.TYPE_CONTENT).getChildRef();
    
    sourceFolder = fileFolderService.create(container, "my source folder", ContentModel.TYPE_FOLDER).getNodeRef();
    destinationFolder = fileFolderService.create(container, "my destination folder", ContentModel.TYPE_FOLDER).getNodeRef();
    node = fileFolderService.create(sourceFolder, "my node.txt", ContentModel.TYPE_CONTENT).getNodeRef();
    
    // Get the executer instance 
    this.acceptExecuter = (TransitionSimpleWorkflowActionExecuter)this.applicationContext.getBean("accept-simpleworkflow");
    this.rejectExecuter = (TransitionSimpleWorkflowActionExecuter)this.applicationContext.getBean("reject-simpleworkflow");       
}
 
Example 18
Project: alfresco-repository   File: FixedAclUpdaterTest.java   View source code 6 votes vote down vote up
private static RetryingTransactionCallback<NodeRef> createFolderHierchyCallback(final NodeRef root,
        final FileFolderService fileFolderService, final String rootName, final int[] filesPerLevel)
{
    RetryingTransactionCallback<NodeRef> cb = new RetryingTransactionCallback<NodeRef>()
    {
        @Override
        public NodeRef execute() throws Throwable
        {
            NodeRef parent = createFile(fileFolderService, root, rootName, ContentModel.TYPE_FOLDER);
            createFolderHierchy(fileFolderService, parent, 0, filesPerLevel);
            return parent;
        }
    };
    return cb;
}
 
Example 19
Project: alfresco-remote-api   File: TaggingServiceTest.java   View source code 5 votes vote down vote up
@Override
protected void setUp() throws Exception
{
    super.setUp();
    
    this.authenticationService = (MutableAuthenticationService)getServer().getApplicationContext().getBean("AuthenticationService");
    this.authenticationComponent = (AuthenticationComponent)getServer().getApplicationContext().getBean("authenticationComponent");
    this.personService = (PersonService)getServer().getApplicationContext().getBean("PersonService");
    this.taggingService = (TaggingService)getServer().getApplicationContext().getBean("TaggingService");        
    this.fileFolderService = (FileFolderService)getServer().getApplicationContext().getBean("FileFolderService");
    this.repositoryHelper = (Repository)getServer().getApplicationContext().getBean("repositoryHelper");
    this.nodeService = (NodeService)getServer().getApplicationContext().getBean("NodeService");
    
    this.authenticationComponent.setSystemUserAsCurrentUser();
    
    // Add a load of tags ready to use
    this.taggingService.createTag(new StoreRef(StoreRef.PROTOCOL_WORKSPACE, "SpacesStore"), TAG_1);
    this.taggingService.createTag(new StoreRef(StoreRef.PROTOCOL_WORKSPACE, "SpacesStore"), TAG_2);
    this.taggingService.createTag(new StoreRef(StoreRef.PROTOCOL_WORKSPACE, "SpacesStore"), TAG_3);
    this.taggingService.createTag(new StoreRef(StoreRef.PROTOCOL_WORKSPACE, "SpacesStore"), TAG_4);
    this.taggingService.createTag(new StoreRef(StoreRef.PROTOCOL_WORKSPACE, "SpacesStore"), TAG_5);     
    
    // Create test node's
    NodeRef testRoot = this.repositoryHelper.getCompanyHome();
    String guid = GUID.generate();
    this.nodeOne = this.fileFolderService.create(testRoot, "test_doc1" + guid + ".txt", ContentModel.TYPE_CONTENT).getNodeRef();
    this.nodeTwo = this.fileFolderService.create(testRoot, "test_dco2" + guid + ".txt", ContentModel.TYPE_CONTENT).getNodeRef();
    
    // Add tags to test nodes
    this.taggingService.addTag(nodeOne, TAG_1);
    this.taggingService.addTag(nodeOne, TAG_2);
    this.taggingService.addTag(nodeTwo, TAG_2);
    
    // Create users
    createUser(TEST_USER);
    
    // Do tests as user one
    this.authenticationComponent.setCurrentUser(TEST_USER);
}
 
Example 20
Project: alfresco-repository   File: OpenCmisLocalTest.java   View source code 5 votes vote down vote up
public void testEncodingForCreateContentStream()
{
    ServiceRegistry serviceRegistry = (ServiceRegistry) ctx.getBean(ServiceRegistry.SERVICE_REGISTRY);
    FileFolderService ffs = serviceRegistry.getFileFolderService();
    // Authenticate as system
    AuthenticationComponent authenticationComponent = (AuthenticationComponent) ctx
            .getBean(BEAN_NAME_AUTHENTICATION_COMPONENT);
    authenticationComponent.setSystemUserAsCurrentUser();
    try
    {
        /* Create the document using openCmis services */
        Repository repository = getRepository("admin", "admin");
        Session session = repository.createSession();
        Folder rootFolder = session.getRootFolder();
        Document document = createDocument(rootFolder, "test_file_" + GUID.generate() + ".txt", session);

        ContentStream content = document.getContentStream();
        assertNotNull(content);

        content = document.getContentStream(BigInteger.valueOf(2), BigInteger.valueOf(4));
        assertNotNull(content);

        NodeRef doc1NodeRef = cmisIdToNodeRef(document.getId());
        FileInfo fileInfo = ffs.getFileInfo(doc1NodeRef);
        Map<QName, Serializable> properties = fileInfo.getProperties();
        ContentDataWithId contentData = (ContentDataWithId) properties
                .get(QName.createQName("{http://www.alfresco.org/model/content/1.0}content"));
        String encoding = contentData.getEncoding();

        assertEquals("ISO-8859-1", encoding);
    }
    finally
    {
        authenticationComponent.clearCurrentSecurityContext();
    }
}
 
Example 21
Project: alfresco-repository   File: HomeFolderProviderSynchronizer.java   View source code 5 votes vote down vote up
public HomeFolderProviderSynchronizer(
        TransactionService transactionService,
        AuthorityService authorityService, PersonService personService,
        FileFolderService fileFolderService, NodeService nodeService,
        PortableHomeFolderManager homeFolderManager,
        TenantAdminService tenantAdminService)
{
    this.transactionService = transactionService;
    this.authorityService = authorityService;
    this.personService = personService;
    this.fileFolderService = fileFolderService;
    this.nodeService = nodeService;
    this.homeFolderManager = homeFolderManager;
    this.tenantAdminService = tenantAdminService;
}
 
Example 22
Project: alfresco-remote-api   File: TestEnterpriseAtomPubTCK.java   View source code 5 votes vote down vote up
@Before
public void setup() throws Exception
{
	JettyComponent jetty = getTestFixture().getJettyComponent();
	
	final SearchService searchService = (SearchService)jetty.getApplicationContext().getBean("searchService");;
	final NodeService nodeService = (NodeService)jetty.getApplicationContext().getBean("nodeService");
	final FileFolderService fileFolderService = (FileFolderService)jetty.getApplicationContext().getBean("fileFolderService");
	final NamespaceService namespaceService = (NamespaceService)jetty.getApplicationContext().getBean("namespaceService");
	final TransactionService transactionService = (TransactionService)jetty.getApplicationContext().getBean("transactionService");
	final String name = "abc" + System.currentTimeMillis();

	transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<Void>()
	{
		@Override
		public Void execute() throws Throwable
		{
			AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());

               Repository repositoryHelper = (Repository)jetty.getApplicationContext().getBean("repositoryHelper");
			NodeRef companyHome = repositoryHelper.getCompanyHome();
			fileFolderService.create(companyHome, name, ContentModel.TYPE_FOLDER).getNodeRef();

			return null;
		}
	}, false, true);

   	int port = jetty.getPort();
   	Map<String, String> cmisParameters = new HashMap<String, String>();
   	cmisParameters.put(TestParameters.DEFAULT_RELATIONSHIP_TYPE, "R:cm:replaces");
   	cmisParameters.put(TestParameters.DEFAULT_TEST_FOLDER_PARENT, "/" + name);
   	clientContext = new OpenCMISClientContext(BindingType.ATOMPUB,
   			MessageFormat.format(CMIS_URL, "localhost", String.valueOf(port), "alfresco"), "admin", "admin", cmisParameters, jetty.getApplicationContext());

       overrideVersionableAspectProperties(jetty.getApplicationContext());
}
 
Example 23
Project: alfresco-repository   File: PortableHomeFolderManager.java   View source code 5 votes vote down vote up
private NodeRef createNewParentIfRequired(NodeRef root,
        List<String> homeFolderPath, FileFolderService fileFolderService)
{
    if (homeFolderPath.size() > 1)
    {
        List<String> parentPath = new ArrayList<String>(homeFolderPath);
        parentPath.remove(parentPath.size()-1);
        return FileFolderUtil.makeFolders(fileFolderService, root,
                parentPath, ContentModel.TYPE_FOLDER).getNodeRef();
    }
    else
    {
        return root;
    }
}
 
Example 24
Project: alfresco-repository   File: CMISTest.java   View source code 5 votes vote down vote up
@Before
public void before()
{
    this.actionService = (ActionService)ctx.getBean("actionService");
    this.ruleService = (RuleService)ctx.getBean("ruleService");
	this.fileFolderService = (FileFolderService)ctx.getBean("FileFolderService");
	this.transactionService = (TransactionService)ctx.getBean("transactionService");
	this.nodeService = (NodeService)ctx.getBean("NodeService");
	this.contentService = (ContentService)ctx.getBean("ContentService");
    this.versionService = (VersionService) ctx.getBean("versionService");
    this.lockService = (LockService) ctx.getBean("lockService");
    this.taggingService = (TaggingService) ctx.getBean("TaggingService");
    this.namespaceService = (NamespaceService) ctx.getBean("namespaceService");
    this.repositoryHelper = (Repository)ctx.getBean("repositoryHelper");
	this.factory = (AlfrescoCmisServiceFactory)ctx.getBean("CMISServiceFactory");
    this.versionService = (VersionService) ctx.getBean("versionService");
	this.cmisConnector = (CMISConnector) ctx.getBean("CMISConnector");
    this.nodeDAO = (NodeDAO) ctx.getBean("nodeDAO");
    this.authorityService = (AuthorityService)ctx.getBean("AuthorityService");
    this.auditSubsystem = (AuditModelRegistryImpl) ctx.getBean("Audit");
    this.permissionService = (PermissionService) ctx.getBean("permissionService");
	this.dictionaryDAO = (DictionaryDAO)ctx.getBean("dictionaryDAO");
	this.cmisDictionaryService = (CMISDictionaryService)ctx.getBean("OpenCMISDictionaryService1.1");
    this.auditDAO = (AuditDAO) ctx.getBean("auditDAO");
    this.nodeArchiveService = (NodeArchiveService) ctx.getBean("nodeArchiveService");
    this.dictionaryService = (DictionaryService) ctx.getBean("dictionaryService");
    this.workflowService = (WorkflowService) ctx.getBean("WorkflowService");
    this.workflowAdminService = (WorkflowAdminService) ctx.getBean("workflowAdminService");
    this.authenticationContext = (AuthenticationContext) ctx.getBean("authenticationContext");
    this.tenantAdminService = (TenantAdminService) ctx.getBean("tenantAdminService");
    this.tenantService = (TenantService) ctx.getBean("tenantService");
    this.searchService = (SearchService) ctx.getBean("SearchService");
    this.auditComponent = (AuditComponentImpl) ctx.getBean("auditComponent");

    this.globalProperties = (java.util.Properties) ctx.getBean("global-properties");
    this.globalProperties.setProperty(VersionableAspectTest.AUTO_VERSION_PROPS_KEY, "true");
}
 
Example 25
Project: alfresco-remote-api   File: WebDAVHelper.java   View source code 5 votes vote down vote up
/**
 * Return the relative path for the node walking back to the specified root node
 * 
 * @param rootNodeRef the root below which the path will be valid
 * @param nodeRef the node's path to get
 * @return Returns string of form <b>/A/B/C</b> where C represents the from node and 
 */
public final String getPathFromNode(NodeRef rootNodeRef, NodeRef nodeRef) throws FileNotFoundException
{
    // Check if the nodes are valid, or equal
    if (rootNodeRef == null || nodeRef == null)
        throw new IllegalArgumentException("Invalid node(s) in getPathFromNode call");
    
    // short cut if the path node is the root node
    if (rootNodeRef.equals(nodeRef))
        return "";
    
    FileFolderService fileFolderService = getFileFolderService();
    
    // get the path elements
    List<String> pathInfos = fileFolderService.getNameOnlyPath(rootNodeRef, nodeRef);
    
    // build the path string
    StringBuilder sb = new StringBuilder(pathInfos.size() * 20);
    for (String fileInfo : pathInfos)
    {
        sb.append(WebDAVHelper.PathSeperatorChar);
        sb.append(fileInfo);
    }
    // done
    if (logger.isDebugEnabled())
    {
        logger.debug("Build name path for node: \n" +
                "   root: " + rootNodeRef + "\n" +
                "   target: " + nodeRef + "\n" +
                "   path: " + sb);
    }
    return sb.toString();
}
 
Example 26
Project: alfresco-remote-api   File: SurfConfigTest.java   View source code 5 votes vote down vote up
@Override
protected void setUp() throws Exception
{
    super.setUp();
    this.siteService = (SiteService) getServer().getApplicationContext().getBean("SiteService");
    this.nodeService = (NodeService) getServer().getApplicationContext().getBean("NodeService");
    this.permissionService = (PermissionService) getServer().getApplicationContext().getBean("PermissionService");
    this.fileFolderService = (FileFolderService) getServer().getApplicationContext().getBean("FileFolderService");

    createUser(USER_ONE);
    createUser(USER_TWO);
    createUser(USER_THREE);

    AuthenticationUtil.setFullyAuthenticatedUser(USER_ONE);
}
 
Example 27
Project: alfresco-file-transfer-receiver   File: FileTransferReceiverUnitTest.java   View source code 5 votes vote down vote up
/**
 * Called during the transaction setup
 */
@SuppressWarnings(value={"deprecation"})
protected void onSetUp() throws Exception
{

    super.onSetUp();
    // Get the required services
    this.transferService = (TransferService2)this.applicationContext.getBean("TransferService2");
    this.nodeService = (NodeService) this.applicationContext.getBean("nodeService");
    this.fileFolderService = (FileFolderService)this.applicationContext.getBean("fileFolderService");
}
 
Example 28
Project: alfresco-remote-api   File: RemoteFileFolderLoaderTest.java   View source code 5 votes vote down vote up
@Override
protected void setUp() throws Exception
{
    super.setUp();
    
    this.repositoryHelper = (Repository)getServer().getApplicationContext().getBean("repositoryHelper");
    this.nodeService = (NodeService)getServer().getApplicationContext().getBean("nodeService");
    this.transactionService = (TransactionService) getServer().getApplicationContext().getBean("TransactionService");
    this.fileFolderService = (FileFolderService) getServer().getApplicationContext().getBean("FileFolderService");

    // Get the path of the shared folder home
    final NodeRef companyHomeNodeRef = repositoryHelper.getCompanyHome();
    final NodeRef sharedHomeNodeRef = repositoryHelper.getSharedHome();
    RetryingTransactionCallback<NodeRef> createFolderWork = new RetryingTransactionCallback<NodeRef>()
    {
        @Override
        public NodeRef execute() throws Throwable
        {
            List<FileInfo> sharedHomeFileInfos = fileFolderService.getNamePath(companyHomeNodeRef, sharedHomeNodeRef);
            sharedHomePath = "/" + sharedHomeFileInfos.get(0).getName();

            String folderName = UUID.randomUUID().toString();
            // Create a folder
            FileInfo folderInfo = fileFolderService.create(sharedHomeNodeRef, folderName, ContentModel.TYPE_FOLDER);
            loadHomePath = sharedHomePath + "/" + folderName;
            // Done
            return folderInfo.getNodeRef();
        }
    };
    AuthenticationUtil.pushAuthentication();            // Will be cleared later
    AuthenticationUtil.setAdminUserAsFullyAuthenticatedUser();

    loadHomeNodeRef = transactionService.getRetryingTransactionHelper().doInTransaction(createFolderWork);
}
 
Example 29
Project: alfresco-repository   File: AbstractBulkImportTests.java   View source code 5 votes vote down vote up
@Before
public void setup() throws SystemException, NotSupportedException
{
    try
    {
        nodeService = (NodeService)ctx.getBean("nodeService");
        fileFolderService = (FileFolderService)ctx.getBean("fileFolderService");
        transactionService = (TransactionService)ctx.getBean("transactionService");
        bulkImporter = (MultiThreadedBulkFilesystemImporter)ctx.getBean("bulkFilesystemImporter");
        contentService = (ContentService)ctx.getBean("contentService");
        actionService = (ActionService)ctx.getBean("actionService");
        ruleService = (RuleService)ctx.getBean("ruleService");
        versionService = (VersionService)ctx.getBean("versionService");

        AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());

        String s = "BulkFilesystemImport" + System.currentTimeMillis();

        txn = transactionService.getUserTransaction();
        txn.begin();

        AuthenticationUtil.pushAuthentication();
        AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());

        StoreRef storeRef = nodeService.createStore(StoreRef.PROTOCOL_WORKSPACE, s);
        rootNodeRef = nodeService.getRootNode(storeRef);
        top = nodeService.createNode(rootNodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName("{namespace}top"), ContentModel.TYPE_FOLDER).getChildRef();
        
        topLevelFolder = fileFolderService.create(top, s, ContentModel.TYPE_FOLDER);

        txn.commit();
    }
    catch(Throwable e)
    {
        fail(e.getMessage());
    }
}
 
Example 30
Project: alfresco-repository   File: SiteServiceImplMoreTest.java   View source code 5 votes vote down vote up
@BeforeClass public static void initStaticData() throws Exception
{
    AUTHORITY_SERVICE         = APP_CONTEXT_INIT.getApplicationContext().getBean("AuthorityService", AuthorityService.class);
    NAMESPACE_SERVICE         = APP_CONTEXT_INIT.getApplicationContext().getBean("namespaceService", NamespaceService.class);
    NODE_SERVICE              = APP_CONTEXT_INIT.getApplicationContext().getBean("NodeService", NodeService.class);
    NODE_ARCHIVE_SERVICE      = APP_CONTEXT_INIT.getApplicationContext().getBean("nodeArchiveService", NodeArchiveService.class);
    SITE_SERVICE              = APP_CONTEXT_INIT.getApplicationContext().getBean("siteService", SiteService.class);
    COCI_SERVICE              = APP_CONTEXT_INIT.getApplicationContext().getBean("checkOutCheckInService", CheckOutCheckInService.class);
    TRANSACTION_HELPER        = APP_CONTEXT_INIT.getApplicationContext().getBean("retryingTransactionHelper", RetryingTransactionHelper.class);
    PERMISSION_SERVICE        = APP_CONTEXT_INIT.getApplicationContext().getBean("permissionServiceImpl", PermissionService.class);
    AUTHENTICATION_SERVICE    = APP_CONTEXT_INIT.getApplicationContext().getBean("authenticationService", MutableAuthenticationService.class);
    PERSON_SERVICE            = APP_CONTEXT_INIT.getApplicationContext().getBean("PersonService", PersonService.class);
    FILE_FOLDER_SERVICE       = APP_CONTEXT_INIT.getApplicationContext().getBean("FileFolderService",FileFolderService.class);
    AUTHENTICATION_COMPONENT  = APP_CONTEXT_INIT.getApplicationContext().getBean("authenticationComponent",AuthenticationComponent.class);
    LOCK_SERVICE              = APP_CONTEXT_INIT.getApplicationContext().getBean("lockService",LockService.class);
    
    // We'll create this test content as admin.
    final String admin = AuthenticationUtil.getAdminUserName();
    
    TEST_SITE_NAME = GUID.generate();
    TEST_SUB_SITE_NAME = GUID.generate();
    
    final QName subSiteType = QName.createQName("testsite", "testSubsite", NAMESPACE_SERVICE);
    
    STATIC_TEST_SITES.createSite("sitePreset", TEST_SITE_NAME, "siteTitle", "siteDescription", SiteVisibility.PUBLIC, admin);
    STATIC_TEST_SITES.createSite("sitePreset", TEST_SUB_SITE_NAME, "siteTitle", "siteDescription", SiteVisibility.PUBLIC, subSiteType, admin);
    
    TEST_SITE_WITH_MEMBERS = STATIC_TEST_SITES.createTestSiteWithUserPerRole(SiteServiceImplMoreTest.class.getSimpleName(), "sitePreset", SiteVisibility.PUBLIC, admin);
}
 
Example 31
Project: alfresco-repository   File: XSLTFunctionsTest.java   View source code 5 votes vote down vote up
@SuppressWarnings("deprecation")
@Override
protected void onSetUpInTransaction() throws Exception
{
    super.onSetUpInTransaction();
    this.xsltFunctions = (XSLTFunctions) this.applicationContext.getBean("xsltFunctions");
    this.nodeService = (NodeService) this.applicationContext.getBean("NodeService");
    this.contentService = (ContentService) this.applicationContext.getBean("ContentService");
    this.fileFolderService = (FileFolderService) this.applicationContext.getBean("FileFolderService");
    this.repositoryHelper = (Repository) this.applicationContext.getBean("repositoryHelper");
    this.companyHome = repositoryHelper.getCompanyHome();
}
 
Example 32
Project: alfresco-repository   File: XSLTRenderingEngineTest.java   View source code 5 votes vote down vote up
@SuppressWarnings("deprecation")
@Override
protected void onSetUpInTransaction() throws Exception
{
    super.onSetUpInTransaction();
    this.nodeService = (NodeService) this.applicationContext.getBean("NodeService");
    this.contentService = (ContentService) this.applicationContext.getBean("ContentService");
    this.fileFolderService = (FileFolderService) this.applicationContext.getBean("FileFolderService");
    this.xsltProcessor = (TemplateProcessor) this.applicationContext.getBean("xsltProcessor");
    this.templateService = (TemplateService) this.applicationContext.getBean("TemplateService");
    this.renditionService = (RenditionService) this.applicationContext.getBean("RenditionService");
    
    this.companyHome = this.applicationContext.getBean("repositoryHelper", Repository.class).getCompanyHome();
}
 
Example 33
Project: alfresco-repository   File: RuleServiceImplTest.java   View source code 5 votes vote down vote up
@Override
  protected void onSetUpInTransaction() throws Exception 
  {
      super.onSetUpInTransaction();        
      this.permissionService = (PermissionService)this.applicationContext.getBean("permissionService");
this.authenticationService = (MutableAuthenticationService)this.applicationContext.getBean("authenticationService");
      this.searchService = (SearchService) applicationContext.getBean("SearchService");
      this.namespaceService = (NamespaceService) applicationContext.getBean("NamespaceService");
      this.fileFolderService = (FileFolderService) applicationContext.getBean("FileFolderService");
  }
 
Example 34
Project: alfresco-remote-api   File: AbstractWorkflowRestApiTest.java   View source code 5 votes vote down vote up
@Override
protected void setUp() throws Exception
{
    super.setUp();
    ApplicationContext appContext = getServer().getApplicationContext();

    namespaceService = (NamespaceService) appContext.getBean("NamespaceService");
    workflowService = (WorkflowService) appContext.getBean("WorkflowService");
    MutableAuthenticationService authenticationService = (MutableAuthenticationService) appContext.getBean("AuthenticationService");
    PersonService personService = (PersonService) appContext.getBean("PersonService");
    SearchService searchService = (SearchService) appContext.getBean("SearchService");
    FileFolderService fileFolderService = (FileFolderService) appContext.getBean("FileFolderService");
    nodeService = (NodeService) appContext.getBean("NodeService");
    
    // for the purposes of the tests make sure workflow engine is enabled/visible.
    WorkflowAdminServiceImpl workflowAdminService = (WorkflowAdminServiceImpl) appContext.getBean("workflowAdminService");
    this.wfTestHelper = new WorkflowTestHelper(workflowAdminService, getEngine(), true);
    
    AuthorityService authorityService = (AuthorityService) appContext.getBean("AuthorityService");
    personManager = new TestPersonManager(authenticationService, personService, nodeService);
    groupManager = new TestGroupManager(authorityService);

    authenticationComponent = (AuthenticationComponent) appContext.getBean("authenticationComponent");
    dictionaryService = (DictionaryService) appContext.getBean("dictionaryService");

    personManager.createPerson(USER1);
    personManager.createPerson(USER2);
    personManager.createPerson(USER3);

    authenticationComponent.setSystemUserAsCurrentUser();

    groupManager.addUserToGroup(GROUP, USER2);

    packageRef = workflowService.createPackage(null);

    NodeRef companyHome = searchService.selectNodes(nodeService.getRootNode(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE), COMPANY_HOME, null, namespaceService, false).get(0);

    contentNodeRef = fileFolderService.create(companyHome, TEST_CONTENT + System.currentTimeMillis(), ContentModel.TYPE_CONTENT).getNodeRef();

    authenticationComponent.clearCurrentSecurityContext();
}
 
Example 35
Project: alfresco-repository   File: XSLTProcessorTest.java   View source code 5 votes vote down vote up
@SuppressWarnings("deprecation")
@Override
protected void onSetUpInTransaction() throws Exception
{
    super.onSetUpInTransaction();
    this.nodeService = (NodeService) this.applicationContext.getBean("NodeService");
    this.contentService = (ContentService) this.applicationContext.getBean("ContentService");
    this.fileFolderService = (FileFolderService) this.applicationContext.getBean("FileFolderService");
    this.xsltProcessor = (TemplateProcessor) this.applicationContext.getBean("xsltProcessor");
    this.templateService = (TemplateService) this.applicationContext.getBean("TemplateService");
    this.repositoryHelper = (Repository) this.applicationContext.getBean("repositoryHelper");
    this.companyHome = repositoryHelper.getCompanyHome();
}
 
Example 36
Project: alfresco-repository   File: SOLRTrackingComponentTest.java   View source code 5 votes vote down vote up
SOLRTest1(
    RetryingTransactionHelper txnHelper, FileFolderService fileFolderService,
    NodeDAO nodeDAO, QNameDAO qnameDAO, NodeService nodeService, DictionaryService dictionaryService,
    NodeRef rootNodeRef, String containerName, boolean doNodeChecks, boolean doMetaDataChecks)
    {
super(txnHelper, fileFolderService, nodeDAO, qnameDAO, nodeService, dictionaryService, rootNodeRef, containerName, doNodeChecks, doMetaDataChecks);
    }
 
Example 37
Project: alfresco-repository   File: SOLRTrackingComponentTest.java   View source code 5 votes vote down vote up
SOLRTest3(
    RetryingTransactionHelper txnHelper, FileFolderService fileFolderService,
    NodeDAO nodeDAO, QNameDAO qnameDAO, NodeService nodeService, DictionaryService dictionaryService, 
    NodeRef rootNodeRef, String containerName, boolean doNodeChecks, boolean doMetaDataChecks)
    {
super(txnHelper, fileFolderService, nodeDAO, qnameDAO, nodeService, dictionaryService, rootNodeRef, containerName, doNodeChecks, doMetaDataChecks);
    }
 
Example 38
Project: alfresco-repository   File: SOLRTrackingComponentTest.java   View source code 5 votes vote down vote up
SOLRTest100Nodes(
    RetryingTransactionHelper txnHelper, FileFolderService fileFolderService,
    NodeDAO nodeDAO, QNameDAO qnameDAO, NodeService nodeService, DictionaryService dictionaryService,
    NodeRef rootNodeRef, String containerName, boolean doNodeChecks, boolean doMetaDataChecks)
    {
super(txnHelper, fileFolderService, nodeDAO, qnameDAO, nodeService, dictionaryService, rootNodeRef, containerName, doNodeChecks, doMetaDataChecks);
    }
 
Example 39
Project: alfresco-repository   File: SOLRTrackingComponentTest.java   View source code 5 votes vote down vote up
SOLRTest4(
    RetryingTransactionHelper txnHelper, FileFolderService fileFolderService,
    NodeDAO nodeDAO, QNameDAO qnameDAO, NodeService nodeService, DictionaryService dictionaryService,
    NodeRef rootNodeRef, String containerName, boolean doNodeChecks, boolean doMetaDataChecks)
    {
super(txnHelper, fileFolderService, nodeDAO, qnameDAO, nodeService, dictionaryService, rootNodeRef, containerName, doNodeChecks, doMetaDataChecks);
    }
 
Example 40
Project: alfresco-repository   File: SOLRTrackingComponentTest.java   View source code 5 votes vote down vote up
SOLRTest5(
    RetryingTransactionHelper txnHelper, FileFolderService fileFolderService,
    NodeDAO nodeDAO, QNameDAO qnameDAO, NodeService nodeService, DictionaryService dictionaryService,
    NodeRef rootNodeRef, String containerName, boolean doNodeChecks, boolean doMetaDataChecks)
    {
super(txnHelper, fileFolderService, nodeDAO, qnameDAO, nodeService, dictionaryService, rootNodeRef, containerName, doNodeChecks, doMetaDataChecks);
    }