org.alfresco.service.cmr.model.FileInfo Java Examples

The following examples show how to use org.alfresco.service.cmr.model.FileInfo. 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: XSLTProcessorTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Test
public void testSimplestClasspathTemplate() throws Exception
{
    try
    {
        FileInfo xmlFile = createXmlFile(companyHome);
        XSLTemplateModel model = new XSLTemplateModel();
        model.put(XSLTProcessor.ROOT_NAMESPACE, XMLUtil.parse(xmlFile.getNodeRef(), contentService));

        StringWriter writer = new StringWriter();
        xsltProcessor.process("org/alfresco/repo/template/test_template1.xsl", model, writer);

        String output = writer.toString();
        
        log.debug("XSLT Processor output: " + output);
        assertEquals("Avocado DipBagels, New York StyleBeef Frankfurter, Quarter PoundChicken Pot PieCole SlawEggsHazelnut SpreadPotato ChipsSoy Patties, GrilledTruffles, Dark Chocolate", output);
    }
    catch (Exception ex)
    {
        log.error("Error!", ex);
        fail();
    }
}
 
Example #2
Source File: VirtualFileFolderServiceExtension.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
public FileInfo asFileInfo(VirtualStore smartStore, ActualEnvironment environment, Reference reference)
            throws VirtualizationException
{
    Map<QName, Serializable> properties = smartStore.getProperties(reference);
    QName qNameType = smartStore.getType(reference);
    FileFolderServiceType type = getTrait().getType(qNameType);

    boolean isFolder = type.equals(FileFolderServiceType.FOLDER);

    NodeRef nodeRef = reference.toNodeRef();

    return getTrait().createFileInfo(nodeRef,
                                     qNameType,
                                     isFolder,
                                     false,
                                     properties);
}
 
Example #3
Source File: MoveMethod.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 6 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 #4
Source File: ActivityPosterImpl.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 6 votes vote down vote up
private void postFileFolderActivity(
            String activityType,
            String siteId,
            String tenantDomain,
            String path,
            NodeRef parentNodeRef,
            FileInfo contentNodeInfo) throws WebDAVServerException
{
    String fileName = contentNodeInfo.getName();
    NodeRef nodeRef = contentNodeInfo.getNodeRef();
    
    try
    {
        poster.postFileFolderActivity(activityType, path, tenantDomain, siteId,
                               parentNodeRef, nodeRef, fileName,
                               appTool, Client.asType(ClientType.webdav),contentNodeInfo);
    }
    catch (AlfrescoRuntimeException are)
    {
        logger.error("Failed to post activity.", are);
        throw new WebDAVServerException(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
    }
}
 
Example #5
Source File: ImapServiceImplTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
public void testGetFlags() throws Exception
{
    NavigableMap<Long, FileInfo> fis = imapService.getFolderStatus(authenticationService.getCurrentUserName(), testImapFolderNodeRef, ImapViewMode.ARCHIVE).search;
    if (fis != null && fis.size() > 0)
    {
        FileInfo messageFileInfo = fis.firstEntry().getValue();
        
        reauthenticate(USER_NAME, USER_PASSWORD);
        
        permissionService.setPermission(testImapFolderNodeRef, anotherUserName, PermissionService.WRITE, true);
        
        imapService.setFlags(messageFileInfo, flags, true);
        
        reauthenticate(anotherUserName, anotherUserName);

        Flags fl = imapService.getFlags(messageFileInfo);
        assertTrue(fl.contains(flags));
    }
}
 
Example #6
Source File: ExporterComponentTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Round-trip of export then import will result in the imported content having the same categories
 * assigned to it as for the exported content -- provided the source and destination stores are the same.
 */
@SuppressWarnings("unchecked")
@Category(RedundantTests.class)
@Test
public void testRoundTripKeepsCategoriesWhenWithinSameStore() throws Exception
{   
    // Use a store ref that has the bootstrapped categories
    StoreRef storeRef = StoreRef.STORE_REF_WORKSPACE_SPACESSTORE;
    NodeRef rootNode = nodeService.getRootNode(storeRef);
    
    ChildAssociationRef contentChildAssocRef = createContentWithCategories(storeRef, rootNode);
    
    // Export/import
    File acpFile = exportContent(contentChildAssocRef.getParentRef());
    FileInfo importFolderFileInfo = importContent(acpFile, rootNode);
    
    // Check categories
    NodeRef importedFileNode = fileFolderService.searchSimple(importFolderFileInfo.getNodeRef(), "test.txt");
    assertNotNull("Couldn't find imported file: test.txt", importedFileNode);
    assertTrue(nodeService.hasAspect(importedFileNode, ContentModel.ASPECT_GEN_CLASSIFIABLE));
    List<NodeRef> importedFileCategories = (List<NodeRef>)
        nodeService.getProperty(importedFileNode, ContentModel.PROP_CATEGORIES);
    assertCategoriesEqual(importedFileCategories,
                "Regions",
                "Software Document Classification");
}
 
Example #7
Source File: AlfrescoImapFolder.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Marks all messages in the folder as deleted using {@link javax.mail.Flags.Flag#DELETED} flag.
 */
@Override
public void deleteAllMessagesInternal() throws FolderException
{
    if (isReadOnly())
    {
        throw new FolderException("Can't delete all - Permission denied");
    }
    
    for (Map.Entry<Long, FileInfo> entry : searchMails().entrySet())
    {
        imapService.setFlag(entry.getValue(), Flags.Flag.DELETED, true);
        // comment out to physically remove content.
        // fileFolderService.delete(fileInfo.getNodeRef());
    }
}
 
Example #8
Source File: XSLTFunctionsTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Test
public void testPathParseXMLDocument()
{
    String path = "path/to/xml/files";
    List<String> pathElements = Arrays.asList(path.split("/"));
    FileInfo folder = FileFolderServiceImpl.makeFolders(fileFolderService, companyHome, pathElements, ContentModel.TYPE_FOLDER);
    FileInfo file = createXmlFile(folder.getNodeRef());
    
    try
    {
        Document doc = xsltFunctions.parseXMLDocument(companyHome, path + "/" + file.getName());
        NodeList foodNodes = doc.getElementsByTagName("food");
        assertEquals(10, foodNodes.getLength());
    }
    catch (Exception ex)
    {
        log.error("Error!", ex);
        fail(ex.getMessage());
    }
}
 
Example #9
Source File: FileFolderServiceImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Auditable(parameters = {"contextNodeRef", "files", "folders", "ignoreQNames", "sortProps", "pagingRequest"})
@Override
@Extend(traitAPI = FileFolderServiceTrait.class, extensionAPI = FileFolderServiceExtension.class)
public PagingResults<FileInfo> list(NodeRef contextNodeRef,
                                  boolean files,
                                  boolean folders,
                                  Set<QName> ignoreQNames,
                                  List<Pair<QName, Boolean>> sortProps,
                                  PagingRequest pagingRequest)
{
    ParameterCheck.mandatory("contextNodeRef", contextNodeRef);
    ParameterCheck.mandatory("pagingRequest", pagingRequest);
    
    Pair<Set<QName>,Set<QName>> pair = buildSearchTypesAndIgnoreAspects(files, folders, ignoreQNames);
    Set<QName> searchTypeQNames = pair.getFirst();
    Set<QName> ignoreAspectQNames = pair.getSecond();
    
    // execute query
    final CannedQueryResults<NodeRef> results = listImpl(contextNodeRef, null, searchTypeQNames, ignoreAspectQNames, sortProps, pagingRequest);
    return getPagingResults(pagingRequest, results);
}
 
Example #10
Source File: WebDAVMethod.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Returns node Lock token in consideration of WebDav lock depth. 
 * 
 * @param nodeInfo FileInfo
 * @return String Lock token
 */
protected LockInfo getNodeLockInfo(final FileInfo nodeInfo)
{
    if (nodeInfo.getNodeRef() == null)
    {
        // TODO review - note: can be null in case of Thor root
        return new LockInfoImpl();
    }
    
    // perf optimisation - effectively run against unprotected nodeService (to bypass repeated permission checks)
    return AuthenticationUtil.runAs(new RunAsWork<LockInfo>()
    {
        public LockInfo doWork() throws Exception
        {
            return getNodeLockInfoImpl(nodeInfo);
        }
    }, AuthenticationUtil.getSystemUserName());
}
 
Example #11
Source File: RuleServiceImplTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
private void createNothingToDoScript(String scriptName)
{
    NodeRef storeRootNodeRef = nodeService.getRootNode(new StoreRef("workspace://SpacesStore"));
    NodeRef scriptFolderRef = searchService.selectNodes(storeRootNodeRef, "/app:company_home/app:dictionary/app:scripts", null, namespaceService, false).get(0);
    
    try
    {
        FileInfo fileInfo = fileFolderService.create(scriptFolderRef, scriptName, ContentModel.TYPE_CONTENT);

        ContentWriter writer = fileFolderService.getWriter(fileInfo.getNodeRef());
        assertNotNull("Writer is null", writer);
        // write some content
        String content = "function main(){}\nmain();";
        writer.putContent(content);
    }
    catch (FileExistsException exc)
    {
        // file was created before
    }
}
 
Example #12
Source File: XSLTProcessorTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Test
public void testSimplestStringTemplate() throws Exception
{
    try
    {
        FileInfo file = createXmlFile(companyHome);
        XSLTemplateModel model = new XSLTemplateModel();
        model.put(XSLTProcessor.ROOT_NAMESPACE, XMLUtil.parse(file.getNodeRef(), contentService));

        StringWriter writer = new StringWriter();
        xsltProcessor.processString(verySimpleXSLT, model, writer);
        String output = writer.toString();
        
        log.debug("XSLT Processor output: " + output);
        assertEquals("Avocado DipBagels, New York StyleBeef Frankfurter, Quarter PoundChicken Pot PieCole SlawEggsHazelnut SpreadPotato ChipsSoy Patties, GrilledTruffles, Dark Chocolate", output);
    }
    catch (Exception ex)
    {
        log.error("Error!", ex);
        fail();
    }
}
 
Example #13
Source File: XSLTRenderingEngine.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * @param nodeRef NodeRef
 * @return String
 */
private String getPath(NodeRef nodeRef)
{
    StringBuilder sb = new StringBuilder();
    try
    {
        List<FileInfo> parentFileInfoList = fileFolderService.getNamePath(null, nodeRef);
        for (FileInfo fileInfo : parentFileInfoList)
        {
            sb.append('/');
            sb.append(fileInfo.getName());
        }
    }
    catch (FileNotFoundException ex)
    {
        log.info("Unexpected problem: error while calculating path to node " + nodeRef, ex);
    }
    String path = sb.toString();
    return path;
}
 
Example #14
Source File: CronScheduledQueryBasedTemplateActionDefinitionTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Check the nodes to be indexed
 * 
 * @param nodes
 * @throws Exception
 */
private void checkNodes(List<FileInfo> nodes) throws Exception
{
    SearchService searchService = registry.getSearchService();
    
    boolean notFound = false;
    for (int i = 1; i <= 40; i++)
    {
        notFound = false;
        for (FileInfo fileInfo : nodes)
        {
            ResultSet resultSet = searchService.query(storeRef, SearchService.LANGUAGE_LUCENE, "PATH:\"/app:company_home//cm:" + TEST_FOLDER_NAME + "//cm:" + fileInfo.getName() + "\"");
            if (resultSet.length() == 0)
            {
                notFound = true;
                break;
            }
        }
        if (notFound)
        {
            Thread.sleep(500);
        }
        else
        {
            break;
        }
    }
    assertFalse("The content was not created or indexed correctly.", notFound);
}
 
Example #15
Source File: FileFolderDuplicateChildTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
public FileInfo execute() throws Throwable
{
    authenticationComponent.setCurrentUser(authenticationComponent.getSystemUserName());
    return fileFolderService.create(
            workingRootNodeRef,
            "F" + number,
            ContentModel.TYPE_CONTENT);
}
 
Example #16
Source File: ImapServiceImplTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Test attachment extraction with a TNEF message
 * @throws Exception
 */
public void testAttachmentExtraction() throws Exception
{
    AuthenticationUtil.setRunAsUserSystem();
    /**
     * Load a TNEF message
     */
    ClassPathResource fileResource = new ClassPathResource("imap/test-tnef-message.eml");
    assertNotNull("unable to find test resource test-tnef-message.eml", fileResource);
    InputStream is = new FileInputStream(fileResource.getFile());
    MimeMessage message = new MimeMessage(Session.getDefaultInstance(new Properties()), is);

    NodeRef companyHomeNodeRef = findCompanyHomeNodeRef();

    FileInfo f1 = fileFolderService.create(companyHomeNodeRef, "ImapServiceImplTest", ContentModel.TYPE_FOLDER);
    FileInfo f2 = fileFolderService.create(f1.getNodeRef(), "test-tnef-message.eml", ContentModel.TYPE_CONTENT);
    
    ContentWriter writer = fileFolderService.getWriter(f2.getNodeRef());
    writer.putContent(new FileInputStream(fileResource.getFile()));
    
    imapService.extractAttachments(f2.getNodeRef(), message);

    List<AssociationRef> targetAssocs = nodeService.getTargetAssocs(f2.getNodeRef(), ImapModel.ASSOC_IMAP_ATTACHMENTS_FOLDER);
    assertTrue("attachment folder is found", targetAssocs.size() == 1);
    NodeRef attachmentFolderRef = targetAssocs.get(0).getTargetRef();
    
    assertNotNull(attachmentFolderRef);

    List<FileInfo> files = fileFolderService.listFiles(attachmentFolderRef);
    assertTrue("three files not found", files.size() == 3);

}
 
Example #17
Source File: SiteServiceImplTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Creates a site with a simple content tree within it.
 * The content looks like
 * <pre>
 * [site] {siteShortName}
 *    |
 *    --- [siteContainer] {componentId}
 *          |
 *          --- [cm:content] fileFolderPrefix + "file.txt"
 *          |
 *          |-- [folder] fileFolderPrefix + "folder"
 *                  |
 *                  |-- [cm:content] fileFolderPrefix + "fileInFolder.txt"
 *                  |
 *                  |-- [folder] fileFolderPrefix + "subfolder"
 *                         |
 *                         |-- [cm:content] fileFolderPrefix + "fileInSubfolder.txt"
 * </pre>
 * 
 * @param siteShortName short name for the site
 * @param componentId the component id for the container
 * @param visibility visibility for the site.
 * @param fileFolderPrefix a prefix String to put on all folders/files created.
 */
private SiteInfo createTestSiteWithContent(String siteShortName, String componentId, SiteVisibility visibility, String fileFolderPrefix)
{
         // Create a public site
         SiteInfo siteInfo = this.siteService.createSite(TEST_SITE_PRESET, 
                                                    siteShortName, 
                                                         TEST_TITLE, 
                                                         TEST_DESCRIPTION, 
                                                         visibility);
    
    NodeRef siteContainer = this.siteService.createContainer(siteShortName, componentId, ContentModel.TYPE_FOLDER, null);
    FileInfo fileInfo = this.fileFolderService.create(siteContainer, fileFolderPrefix + "file.txt", ContentModel.TYPE_CONTENT);
         ContentWriter writer = this.fileFolderService.getWriter(fileInfo.getNodeRef());
         writer.putContent("Just some old content that doesn't mean anything");
         
    FileInfo folder1Info = this.fileFolderService.create(siteContainer, fileFolderPrefix + "folder", ContentModel.TYPE_FOLDER);

    FileInfo fileInfo2 = this.fileFolderService.create(folder1Info.getNodeRef(), fileFolderPrefix + "fileInFolder.txt", ContentModel.TYPE_CONTENT);
    ContentWriter writer2 = this.fileFolderService.getWriter(fileInfo2.getNodeRef());
    writer2.putContent("Just some old content that doesn't mean anything");
    
    FileInfo folder2Info = this.fileFolderService.create(folder1Info.getNodeRef(), fileFolderPrefix + "subfolder", ContentModel.TYPE_FOLDER);

    FileInfo fileInfo3 = this.fileFolderService.create(folder2Info.getNodeRef(), fileFolderPrefix + "fileInSubfolder.txt", ContentModel.TYPE_CONTENT);
    ContentWriter writer3 = this.fileFolderService.getWriter(fileInfo3.getNodeRef());
    writer3.putContent("Just some old content that doesn't mean anything");
    
     return siteInfo;
}
 
Example #18
Source File: ActivityPosterImpl.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void postFileFolderUpdated(
            String siteId,
            String tenantDomain,
            FileInfo nodeInfo) throws WebDAVServerException
{
    if (! nodeInfo.isFolder())
    {
        postFileFolderActivity(ActivityType.FILE_UPDATED, siteId, tenantDomain, null, null, nodeInfo);
    }
}
 
Example #19
Source File: FileFolderServiceImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * @see #search(NodeRef, String, boolean, boolean, boolean)
 */
@Override
@Extend(traitAPI=FileFolderServiceTrait.class,extensionAPI=FileFolderServiceExtension.class)
public List<FileInfo> search(NodeRef contextNodeRef, String namePattern, boolean includeSubFolders)
{
    return search(contextNodeRef, namePattern, true, true, includeSubFolders);
}
 
Example #20
Source File: FileFolderServiceImplTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void testLongFileNames() throws Exception
{
    String fileName = "12345678901234567890123456789012345678901234567890"
            + "12345678901234567890123456789012345678901234567890"
            + "12345678901234567890123456789012345678901234567890"
            + "12345678901234567890123456789012345678901234567890"
            + "12345678901234567890123456789012345678901234567890"
            + "12345678901234567890123456789012345678901234567890";
    FileInfo fileInfo = fileFolderService.create(workingRootNodeRef, fileName, ContentModel.TYPE_CONTENT);
    // see if we can get it again
    NodeRef fileNodeRef = fileFolderService.searchSimple(workingRootNodeRef, fileName);
    assertNotNull("Long filename not found", fileNodeRef);
    assertEquals(fileInfo.getNodeRef(), fileNodeRef);
}
 
Example #21
Source File: VirtualFileFolderServiceExtension.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public PagingResults<FileInfo> list(NodeRef contextNodeRef, boolean files, boolean folders, Set<QName> ignoreQNames,
            List<Pair<QName, Boolean>> sortProps, PagingRequest pagingRequest)
{

    return VirtualFileFolderServiceExtension.this.list(contextNodeRef,
                                                       files,
                                                       folders,
                                                       null,
                                                       ignoreQNames,
                                                       sortProps,
                                                       pagingRequest);
}
 
Example #22
Source File: FileFolderServicePropagationTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Test
public void testPreservingPropertiesOfParentFolderMnt8109() throws Exception
{
    try
    {
        Thread.sleep(1000);
    }
    catch (Exception e)
    {
        // Just stop to wait for the end of...
    }

    // Enabling preservation of modification properties data...
    fileFolderService.setPreserveAuditableData(true);
    transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<Void>()
    {
        @Override
        public Void execute() throws Throwable
        {
            AuthenticationUtil.setFullyAuthenticatedUser(TEST_USER_NAME);
            moveObjectAndAssert(testFile);
            return null;
        }
    });

    transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<Void>()
    {
        @Override
        public Void execute() throws Throwable
        {
            FileInfo actualParent = fileFolderService.getFileInfo(getAndAssertSingleParent(testFile));
            assertEquals(testEmptyFolder.getModifiedDate(), actualParent.getModifiedDate());
            assertEquals(testEmptyFolder.getProperties().get(ContentModel.PROP_MODIFIER), actualParent.getProperties().get(ContentModel.PROP_MODIFIER));
            return null;
        }
    });
}
 
Example #23
Source File: VirtualFileFolderServiceExtensionTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Test
public void testListNonVirtualizable() throws Exception
{
    NodeRef nv = createVirtualizedFolder(testRootFolder.getNodeRef(),
                                         "TestVirtualFileFolderService_testListNonVirtualizable",
                                         null);
    List<FileInfo> emptyList = fileAndFolderService.list(nv);

    assertTrue(emptyList.isEmpty());
}
 
Example #24
Source File: AlfrescoImapFolder.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
private List<SimpleStoredMessage> convertToMessages(Collection<FileInfo> fileInfos)
{
    if (logger.isDebugEnabled())
    {
        logger.debug("[convertToMessages] " + this);
    }
    if (fileInfos == null || fileInfos.size() == 0)
    {
        logger.debug("[convertToMessages] - fileInfos is empty or null");
        return Collections.emptyList();
    }
    List<SimpleStoredMessage> result = new LinkedList<SimpleStoredMessage>();
    for (FileInfo fileInfo : fileInfos)
    {
        try
        {
            result.add(imapService.createImapMessage(fileInfo, true));
            if (logger.isDebugEnabled())
            {
                logger.debug("[convertToMessages] Message added: " + fileInfo.getName());
            }
        }
        catch (MessagingException e)
        {
            logger.warn("[convertToMessages] Invalid message! File name:" + fileInfo.getName(), e);
        }
    }
    return result;
}
 
Example #25
Source File: AlfrescoImapFolder.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Deletes messages marked with {@link javax.mail.Flags.Flag#DELETED}. Note that this message deletes all messages with this flag.
 */
@Override
protected void expungeInternal() throws FolderException
{
    if (isReadOnly())
    {
        throw new FolderException("Can't expunge - Permission denied");
    }

    for (Map.Entry<Long, FileInfo> entry : searchMails().entrySet())
    {
        imapService.expungeMessage(entry.getValue());
    }
}
 
Example #26
Source File: LargeArchiveAndRestoreTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
private NodeRef addFolder(NodeRef parentNodeRef, String foldername, int depth)
{
    System.out.println(makeTabs(depth) + "Creating folder " + foldername + " in parent " + parentNodeRef);
    FileInfo info = fileFolderService.create(parentNodeRef, foldername, ContentModel.TYPE_FOLDER);
    String name = info.getName();
    if (!name.equals(foldername))
    {
        String msg = "A foldername '" + foldername + "' was not persisted: " + info;
        logger.error(msg);
        rollbackMessages.add(msg);
    }
    return info.getNodeRef();
}
 
Example #27
Source File: FileFolderServicePropagationTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void moveObjectAndAssertAbsenceOfPropertiesPreserving(FileInfo object) throws FileNotFoundException
{
    FileInfo moved = fileFolderService.move(object.getNodeRef(), testEmptyFolder.getNodeRef(), object.getName());
    assertParent(moved, testEmptyFolder);
    assertTrue("Modification time difference MUST BE greater or equal than 1 000 milliseconds!", (moved.getModifiedDate().getTime() - object.getModifiedDate().getTime()) >= 1000);
    assertEquals(TEST_USER_NAME, moved.getProperties().get(ContentModel.PROP_MODIFIER));
}
 
Example #28
Source File: AlfrescoImapFolder.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Constructs {@link AlfrescoImapFolder} object.
 * 
 * @param folderInfo - reference to the {@link FileInfo} object representing the folder.
 * @param userName - name of user (e.g. "admin" for admin user).
 * @param folderName - name of the folder.
 * @param folderPath - path of the folder.
 * @param viewMode - defines view mode. Can be one of the following: {@link ImapViewMode#ARCHIVE} or {@link ImapViewMode#VIRTUAL}.
 * @param extractAttachmentsEnabled boolean
 * @param imapService ImapService
 * @param serviceRegistry ServiceRegistry
 * @param mountPointId - id of the mount point.
 */
public AlfrescoImapFolder(
        FileInfo folderInfo,
        String userName,
        String folderName,
        String folderPath,
        ImapViewMode viewMode,
        boolean extractAttachmentsEnabled,
        ImapService imapService,
        ServiceRegistry serviceRegistry,
        int mountPointId)
{
    this(folderInfo, userName, folderName, folderPath, viewMode, imapService, serviceRegistry, null, extractAttachmentsEnabled, mountPointId);
}
 
Example #29
Source File: XSLTFunctions.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
public Map<String, Document> parseXMLDocuments(final String typeName, NodeRef rootNode, String repoPath)
        throws IOException, SAXException
{
    final Map<String, Document> result = new TreeMap<String, Document>();

    String[] pathElements = breakDownPath(repoPath);

    try
    {
        FileInfo file = fileService.resolveNamePath(rootNode, Arrays.asList(pathElements));

        if (file.isFolder())
        {
            QName typeQName = QName.createQName(typeName, namespaceService);
            Set<QName> types = new HashSet<QName>(dictionaryService.getSubTypes(typeQName, true));
            types.add(typeQName);
            List<ChildAssociationRef> children = nodeService.getChildAssocs(file.getNodeRef(), types);
            for (ChildAssociationRef child : children)
            {
                String name = (String) nodeService.getProperty(child.getChildRef(), ContentModel.PROP_NAME);
                Document doc = XMLUtil.parse(child.getChildRef(), contentService);
                result.put(name, doc);
            }
        }
    }
    catch (Exception ex)
    {
        log.warn("Unexpected exception caught in call to parseXMLDocuments", ex);
    }
    return result;
}
 
Example #30
Source File: XSLTRenderingEngineTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Test
public void testImportXMLDocument() throws Exception
{
    try
    {
        FileInfo file = createXmlFile(companyHome);
        createXmlFile(companyHome, "TestTableXML.xml", testTableXml);
        FileInfo testImportTable = createXmlFile(companyHome, "TestImportTableXML.xml", testImportTableXml);

        RenditionDefinition def = renditionService.createRenditionDefinition(QName.createQName("Test"), XSLTRenderingEngine.NAME);
        def.setParameterValue(XSLTRenderingEngine.PARAM_TEMPLATE_NODE, testImportTable.getNodeRef());

        ChildAssociationRef rendition = renditionService.render(file.getNodeRef(), def);
        
        assertNotNull(rendition);
        
        ContentReader reader = contentService.getReader(rendition.getChildRef(), ContentModel.PROP_CONTENT);
        assertNotNull(reader);
        String output = reader.getContentString();
        
        log.debug("XSLT Processor output: " + output);
        Diff myDiff = new Diff("<html>\n<body>\n<h2>My CD Collection</h2>\n<table border=\"1\">\n<tr bgcolor=\"#9acd32\">\n<th>Title</th><th>Artist</th>\n</tr>\n<tr>\n<td></td><td></td>\n</tr>\n</table>\n</body>\n</html>\n", output);
        assertTrue("Pieces of XML are similar " + myDiff, myDiff.similar());
    }
    catch (Exception ex)
    {
        log.error("Error!", ex);
        fail();
    }
}