Java Code Examples for org.alfresco.service.cmr.model.FileInfo#getNodeRef()

The following examples show how to use org.alfresco.service.cmr.model.FileInfo#getNodeRef() . 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: 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 2
Source File: RepoStore.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Gets the node ref for the specified path within this repo store
 * 
 * @param documentPath String
 * @return  node ref
 */
protected NodeRef findNodeRef(String documentPath)
{
    NodeRef node = null;
    try
    {
        String[] pathElements = documentPath.split("/");
        List<String> pathElementsList = Arrays.asList(pathElements);
        FileInfo file = fileService.resolveNamePath(getBaseNodeRef(), pathElementsList);
        node = file.getNodeRef();
    }
    catch (FileNotFoundException e)
    {
        // NOTE: return null
    }
    return node;
}
 
Example 3
Source File: RepoRemoteService.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Utility for getting the parent NodeRef of a relative path.
 * @param base The base node ref.
 * @param path The relative path.
 * @return A Pair with the parent node ref and the name of the child.
 */
private Pair<NodeRef, String> getParentChildRelative(NodeRef base, String path)
{
    List<String> pathList = splitPath(path);
    NodeRef parent;
    String name = null;
    if (pathList.size() == 1)
    {
        parent = base;
        name = pathList.get(0);
    }
    else
    {
        try
        {
            name = pathList.get(pathList.size() - 1);
            pathList.remove(pathList.size() - 1);
            FileInfo info = fFileFolderService.resolveNamePath(base, pathList);
            parent = info.getNodeRef();
        }
        catch (FileNotFoundException e)
        {
            throw new AlfrescoRuntimeException("Not Found: " + pathList, e);
        }
    }
    return new Pair<NodeRef, String>(parent, name);
}
 
Example 4
Source File: BatchImporterImpl.java    From alfresco-bulk-import with Apache License 2.0 5 votes vote down vote up
private NodeRef getParent(final NodeRef target, final BulkImportItem<BulkImportItemVersion> item)
{
    NodeRef result = null;
    
    final String itemParentPath         = item.getRelativePathOfParent();
    List<String> itemParentPathElements = (itemParentPath == null || itemParentPath.length() == 0) ? null : Arrays.asList(itemParentPath.split(REGEX_SPLIT_PATH_ELEMENTS));
    
    if (debug(log)) debug(log, "Finding parent folder '" + itemParentPath + "'.");
    
    if (itemParentPathElements != null && itemParentPathElements.size() > 0)
    {
        FileInfo fileInfo = null;
            
        try
        {
            //####TODO: I THINK THIS WILL FAIL IN THE PRESENCE OF CUSTOM NAMESPACES / PARENT ASSOC QNAMES!!!!
            fileInfo = serviceRegistry.getFileFolderService().resolveNamePath(target, itemParentPathElements, false);
        }
        catch (final FileNotFoundException fnfe)  // This should never be triggered due to the last parameter in the resolveNamePath call, but just in case
        {
            throw new OutOfOrderBatchException(itemParentPath, fnfe);
        }
        
        // Out of order batch submission (child arrived before parent)
        if (fileInfo == null)
        {
            throw new OutOfOrderBatchException(itemParentPath);
        }
        
        result = fileInfo.getNodeRef();
    }
    
    return(result);
}
 
Example 5
Source File: ActivityInfo.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
public ActivityInfo(String parentPath, NodeRef parentNodeRef, String siteId, FileInfo fileInfo)
{
    super();
    this.nodeRef = fileInfo.getNodeRef();
    this.parentPath = parentPath;
    this.parentNodeRef = parentNodeRef;
    this.siteId = siteId;
    this.fileName = fileInfo.getName();
    this.isFolder = fileInfo.isFolder();
    this.fileInfo = fileInfo;
}
 
Example 6
Source File: UpdateTagScopesActionExecuterTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Creates simple hierarchy with documents tagged on the first layer only
 * 
 * @param registry - {@link ServiceRegistry} instance
 * @param createdTagScopes - {@link List}&lt;{@link NodeRef}&gt; instance which contains all tag scope folders
 */
private void createTestContent(ServiceRegistry registry, List<NodeRef> createdTagScopes)
{
    NodeRef rootNode = registry.getNodeLocatorService().getNode(CompanyHomeNodeLocator.NAME, null, null);

    NodeRef currentParent = rootNode;
    for (int i = 0; i < TAGSCOPE_LAYERS; i++)
    {
        FileInfo newFolder = fileFolderService.create(currentParent, String.format(TEST_FOLDER_NAME_PATTERN, i), ContentModel.TYPE_FOLDER);
        currentParent = newFolder.getNodeRef();

        if (null != createdTagScopes)
        {
            createdTagScopes.add(currentParent);
        }

        nodeService.addAspect(currentParent, ContentModel.ASPECT_TAGSCOPE, null);

        for (int j = 0; j < TEST_DOCUMENTS_AMOUNT; j++)
        {
            FileInfo newDocument = fileFolderService.create(currentParent, String.format(TEST_DOCUMENT_NAME_PATTERN, i, j), ContentModel.TYPE_CONTENT);
            nodeService.addAspect(newDocument.getNodeRef(), ContentModel.ASPECT_TAGGABLE, null);

            if (0 == i)
            {
                for (int k = 0; k < TEST_TAGS_AMOUNT; k++)
                {
                    String tagName = String.format(TEST_TAG_NAME_PATTERN, k, j, i);
                    testTags.add(tagName);
                    taggingService.addTag(newDocument.getNodeRef(), tagName);
                }
            }
        }
    }
}
 
Example 7
Source File: RepoRemoteService.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
public Pair<NodeRef, Boolean> lookup(NodeRef base, String path) 
{
    List<String> pathList = splitPath(path);
    try 
    {
        FileInfo info = fFileFolderService.resolveNamePath(base, pathList);
        return new Pair<NodeRef, Boolean>(info.getNodeRef(), info.isFolder());
    } 
    catch (FileNotFoundException e) 
    {
        return null;
    }
}
 
Example 8
Source File: RepoRemoteService.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
public NodeRef createDirectory(NodeRef base, String path) 
{
    Pair<NodeRef, String> parentChild = getParentChildRelative(base, path);
    FileInfo created = fFileFolderService.create(parentChild.getFirst(), 
                                                 parentChild.getSecond(),
                                                 ContentModel.TYPE_FOLDER);
    return created.getNodeRef();
}
 
Example 9
Source File: AbstractBulkFileSystemImportWebScript.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 5 votes vote down vote up
protected NodeRef convertPathToNodeRef(String targetPath) throws FileNotFoundException
{
    NodeRef result          = null;
    NodeRef companyHome     = repository.getCompanyHome();
    String  cleanTargetPath = targetPath.replaceAll("/+", "/");
	
    if (cleanTargetPath.startsWith(COMPANY_HOME_PATH))
        cleanTargetPath = cleanTargetPath.substring(COMPANY_HOME_PATH.length());
    
    if (cleanTargetPath.startsWith("/"))
        cleanTargetPath = cleanTargetPath.substring(1);
    
    if (cleanTargetPath.endsWith("/"))
        cleanTargetPath = cleanTargetPath.substring(0, cleanTargetPath.length() - 1);
    
    if (cleanTargetPath.length() == 0)
        result = companyHome;
    else
    {
    	FileInfo info = fileFolderService.resolveNamePath(companyHome, Arrays.asList(cleanTargetPath.split("/")));
        if(info == null)
        	throw new WebScriptException("could not determine NodeRef for path :'"+cleanTargetPath+"'");
        
        result = info.getNodeRef();
    }
    
    return(result);
}
 
Example 10
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 11
Source File: JSONConversionComponent.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * 
 * @param nodeInfo FileInfo
 * @param rootJSONObject JSONObject
 * @param useShortQNames boolean
 */
@SuppressWarnings("unchecked")
protected void setRootValues(final FileInfo nodeInfo, final JSONObject rootJSONObject, final boolean useShortQNames)
{
    final NodeRef nodeRef = nodeInfo.getNodeRef();
    
    rootJSONObject.put("nodeRef", nodeInfo.getNodeRef().toString());
    rootJSONObject.put("type", nameToString(nodeInfo.getType(), useShortQNames));                   
    rootJSONObject.put("isContainer", nodeInfo.isFolder()); //node.getIsContainer() || node.getIsLinkToContainer());
    rootJSONObject.put("isLocked", isLocked(nodeInfo.getNodeRef()));
    
    rootJSONObject.put("isLink", nodeInfo.isLink());
    if (nodeInfo.isLink())
    {
        NodeRef targetNodeRef = nodeInfo.getLinkNodeRef();
        if (targetNodeRef != null)
        {
            rootJSONObject.put("linkedNode", toJSONObject(targetNodeRef, useShortQNames));
        }
    }    
    
    // TODO should this be moved to the property output since we may have more than one content property
    //      or a non-standard content property 
    
    if (nodeInfo.isFolder() == false)
    {
        final ContentData cdata = nodeInfo.getContentData();
        if (cdata != null)
        {
            String contentURL = MessageFormat.format(
                    CONTENT_DOWNLOAD_API_URL, new Object[]{
                            nodeRef.getStoreRef().getProtocol(),
                            nodeRef.getStoreRef().getIdentifier(),
                            nodeRef.getId(),
                            URLEncoder.encode(nodeInfo.getName())});
            
            rootJSONObject.put("contentURL", contentURL);
            rootJSONObject.put("mimetype", cdata.getMimetype());
            Map<String, String> mimetypeDescriptions;
            mimetypeDescriptions = mimetypeService.getDisplaysByMimetype();

            if (mimetypeDescriptions.containsKey(cdata.getMimetype()))
            {
                rootJSONObject.put("mimetypeDisplayName", mimetypeDescriptions.get(cdata.getMimetype()));
            }
            rootJSONObject.put("encoding", cdata.getEncoding());
            rootJSONObject.put("size", cdata.getSize());
        }
    }
}
 
Example 12
Source File: NodesImpl.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 4 votes vote down vote up
protected NodeRef resolveNodeByPath(final NodeRef parentNodeRef, String path, boolean checkForCompanyHome)
{
    final List<String> pathElements = getPathElements(path);

    if (!pathElements.isEmpty() && checkForCompanyHome)
    {
        /*
        if (nodeService.getRootNode(parentNodeRef.getStoreRef()).equals(parentNodeRef))
        {
            // special case
            NodeRef chNodeRef = repositoryHelper.getCompanyHome();
            String chName = (String) nodeService.getProperty(chNodeRef, ContentModel.PROP_NAME);
            if (chName.equals(pathElements.get(0)))
            {
                pathElements = pathElements.subList(1, pathElements.size());
                parentNodeRef = chNodeRef;
            }
        }
        */
    }

    FileInfo fileInfo = null;
    try
    {
        if (!pathElements.isEmpty())
        {
            fileInfo = fileFolderService.resolveNamePath(parentNodeRef, pathElements);
        }
        else
        {
            fileInfo = fileFolderService.getFileInfo(parentNodeRef);
            if (fileInfo == null)
            {
                throw new EntityNotFoundException(parentNodeRef.getId());
            }
        }
    }
    catch (FileNotFoundException fnfe)
    {
        // convert checked exception
        throw new NotFoundException("The entity with relativePath: " + path + " was not found.");
    }
    catch (AccessDeniedException ade)
    {
        // return 404 instead of 403 (as per security review - uuid vs path)
        throw new NotFoundException("The entity with relativePath: " + path + " was not found.");
    }

    return fileInfo.getNodeRef();
}
 
Example 13
Source File: ThumbnailServiceTest.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
protected void setUp() throws Exception
{
    super.setUp();       
 
    this.fileFolderService = (FileFolderService)getServer().getApplicationContext().getBean("FileFolderService");
    this.contentService = (ContentService)getServer().getApplicationContext().getBean("ContentService");
    synchronousTransformClient = (SynchronousTransformClient) getServer().getApplicationContext().getBean("synchronousTransformClient");
    this.repositoryHelper = (Repository)getServer().getApplicationContext().getBean("repositoryHelper");
    this.authenticationService = (MutableAuthenticationService)getServer().getApplicationContext().getBean("AuthenticationService");
    this.personService = (PersonService)getServer().getApplicationContext().getBean("PersonService");
    try
    {
        this.transactionService = (TransactionServiceImpl) getServer().getApplicationContext().getBean("transactionComponent");
    }
    catch (ClassCastException e)
    {
        throw new AlfrescoRuntimeException("The ThumbnailServiceTest needs direct access to the TransactionServiceImpl");
    }
    
    AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getSystemUserName());
    
    this.testRoot = this.repositoryHelper.getCompanyHome();
    
    // Get test content
    InputStream pdfStream = ThumbnailServiceTest.class.getClassLoader().getResourceAsStream("org/alfresco/repo/web/scripts/thumbnail/test_doc.pdf");        
    assertNotNull(pdfStream);
    InputStream jpgStream = ThumbnailServiceTest.class.getClassLoader().getResourceAsStream("org/alfresco/repo/web/scripts/thumbnail/test_image.jpg");
    assertNotNull(jpgStream);
    
    String guid = GUID.generate();
    
    // Create new nodes and set test content
    FileInfo fileInfoPdf = this.fileFolderService.create(this.testRoot, "test_doc" + guid + ".pdf", ContentModel.TYPE_CONTENT);
    this.pdfNode = fileInfoPdf.getNodeRef();
    ContentWriter contentWriter = this.contentService.getWriter(fileInfoPdf.getNodeRef(), ContentModel.PROP_CONTENT, true);
    contentWriter.setEncoding("UTF-8");
    contentWriter.setMimetype(MimetypeMap.MIMETYPE_PDF);
    contentWriter.putContent(pdfStream);
    
    FileInfo fileInfoJpg = this.fileFolderService.create(this.testRoot, "test_image" + guid + ".jpg", ContentModel.TYPE_CONTENT);
    this.jpgNode = fileInfoJpg.getNodeRef();
    contentWriter = this.contentService.getWriter(fileInfoJpg.getNodeRef(), ContentModel.PROP_CONTENT, true);
    contentWriter.setEncoding("UTF-8");
    contentWriter.setMimetype(MimetypeMap.MIMETYPE_IMAGE_JPEG);
    contentWriter.putContent(jpgStream);        
}
 
Example 14
Source File: HiddenAspect.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
private void applyHidden(FileInfo fileInfo, HiddenFileInfo filter)
{
    NodeRef nodeRef = fileInfo.getNodeRef();

    if(!hasHiddenAspect(nodeRef))
    {
        // the file matches a pattern, apply the hidden and aspect control aspects
        addHiddenAspect(nodeRef, filter);
    }
    else
    {
        nodeService.setProperty(nodeRef, ContentModel.PROP_VISIBILITY_MASK, filter.getVisibilityMask());
        nodeService.setProperty(nodeRef, ContentModel.PROP_CASCADE_HIDDEN, filter.cascadeHiddenAspect());
        nodeService.setProperty(nodeRef, ContentModel.PROP_CASCADE_INDEX_CONTROL, filter.cascadeIndexControlAspect());
    }

    if(!hasIndexControlAspect(nodeRef))
    {
        addIndexControlAspect(nodeRef);
    }
    
    if(fileInfo.isFolder() && (filter.cascadeHiddenAspect() || filter.cascadeIndexControlAspect()))
    {
        PagingRequest pagingRequest = new PagingRequest(0, Integer.MAX_VALUE, null);
        PagingResults<FileInfo> results = fileFolderService.list(nodeRef, true, true, null, null, pagingRequest);
        List<FileInfo> files = results.getPage();

        // apply the hidden aspect to all folders and folders and then recursively to all sub-folders, unless the sub-folder
        // already has the hidden aspect applied (it may have been applied for a different pattern).
        for(FileInfo file : files)
        {
            behaviourFilter.disableBehaviour(file.getNodeRef(), ContentModel.ASPECT_LOCKABLE);
            try
            {
                applyHidden(file, filter);
            }
            finally
            {
                behaviourFilter.enableBehaviour(file.getNodeRef(), ContentModel.ASPECT_LOCKABLE);
            }
        }
    }
}
 
Example 15
Source File: FileFolderLoaderTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * 10 files; 10 per txn; force storage; identical
 */
@Test
public void testLoad_04() throws Exception
{
    try
    {
        AuthenticationUtil.pushAuthentication();
        AuthenticationUtil.setAdminUserAsFullyAuthenticatedUser();
        int created = fileFolderLoader.createFiles(
                writeFolderPath,
                10, 10, 1024L, 1024L, 1L, true,
                10, 256L);
        assertEquals("Incorrect number of files generated.", 10, created);
        // Count
        assertEquals(10, nodeService.countChildAssocs(writeFolderNodeRef, true));
        // Check the files
        List<FileInfo> fileInfos = fileFolderService.listFiles(writeFolderNodeRef);
        String lastText = null;
        String lastDescr = null;
        String lastUrl = null;
        for (FileInfo fileInfo : fileInfos)
        {
            NodeRef fileNodeRef = fileInfo.getNodeRef();
            // The URLs must all be unique as we wrote the physical binaries
            ContentReader reader = fileFolderService.getReader(fileNodeRef);
            assertEquals("UTF-8", reader.getEncoding());
            assertEquals(MimetypeMap.MIMETYPE_TEXT_PLAIN, reader.getMimetype());
            assertEquals(1024L, reader.getSize());
            if (lastUrl == null)
            {
                lastUrl = reader.getContentUrl();
            }
            else
            {
                assertNotEquals("We expect unique URLs: ", lastUrl, reader.getContentUrl());
                lastUrl = reader.getContentUrl();
            }
            // Check content
            if (lastText == null)
            {
                lastText = reader.getContentString();
            }
            else
            {
                String currentStr = reader.getContentString();
                assertEquals("All text must be identical due to same seed. ", lastText, currentStr);
                lastText = currentStr;
            }
            // Check description
            if (lastDescr == null)
            {
                lastDescr = DefaultTypeConverter.INSTANCE.convert(String.class, nodeService.getProperty(fileNodeRef, ContentModel.PROP_DESCRIPTION));
                assertEquals("cm:description length is incorrect. ", 256, lastDescr.getBytes().length);
            }
            else
            {
                String currentDescr = DefaultTypeConverter.INSTANCE.convert(String.class, nodeService.getProperty(fileNodeRef, ContentModel.PROP_DESCRIPTION));
                assertEquals("All descriptions must be identical due to varying seed. ", lastDescr, currentDescr);
                lastDescr = currentDescr;
            }
        }
    }
    finally
    {
        AuthenticationUtil.popAuthentication();
    }
}
 
Example 16
Source File: RemoteFileFolderLoaderTest.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Load 15 files with default sizes
 */
@SuppressWarnings("unchecked")
public void testLoad_15_default() throws Exception
{
    JSONObject body = new JSONObject();
    body.put(FileFolderLoaderPost.KEY_FOLDER_PATH, loadHomePath);
    body.put(FileFolderLoaderPost.KEY_FILE_COUNT, 15);
    body.put(FileFolderLoaderPost.KEY_FILES_PER_TXN, 10);
    
    Response response = null;
    try
    {
        AuthenticationUtil.pushAuthentication();
        AuthenticationUtil.setFullyAuthenticatedUser("hhoudini");
        response = sendRequest(
                new PostRequest(URL,  body.toString(), "application/json"),
                Status.STATUS_OK,
                "hhoudini");
    }
    finally
    {
        AuthenticationUtil.popAuthentication();
    }
    assertEquals("{\"count\":15}", response.getContentAsString());
    
    // Check file(s)
    assertEquals(15, nodeService.countChildAssocs(loadHomeNodeRef, true));
    // Size should be default
    List<FileInfo> fileInfos = fileFolderService.list(loadHomeNodeRef);
    for (FileInfo fileInfo : fileInfos)
    {
        NodeRef fileNodeRef = fileInfo.getNodeRef();
        ContentReader reader = fileFolderService.getReader(fileNodeRef);
        // Expect spoofing by default
        assertTrue(reader.getContentUrl().startsWith(FileContentStore.SPOOF_PROTOCOL));
        assertTrue(
                "Default file size not correct: " + reader,
                FileFolderLoaderPost.DEFAULT_MIN_FILE_SIZE < reader.getSize() &&
                    reader.getSize() < FileFolderLoaderPost.DEFAULT_MAX_FILE_SIZE);
        // Check creator
        assertEquals("hhoudini", nodeService.getProperty(fileNodeRef, ContentModel.PROP_CREATOR));
        // We also expect the default language description to be present
        String description = (String) nodeService.getProperty(fileNodeRef, ContentModel.PROP_DESCRIPTION);
        assertNotNull("No description", description);
        assertEquals("Description length incorrect: \"" + description + "\"", 128L, description.getBytes("UTF-8").length);
    }
}
 
Example 17
Source File: FileFolderServiceImplTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
@SuppressWarnings("unused")
public void testGetLocalizedSibling() throws Exception
{
    FileInfo base = fileFolderService.create(workingRootNodeRef, "Something.ftl", ContentModel.TYPE_CONTENT);
    NodeRef node = base.getNodeRef();
    NodeRef nodeFr = fileFolderService.create(workingRootNodeRef, "Something_fr.ftl", ContentModel.TYPE_CONTENT).getNodeRef();
    NodeRef nodeFrFr = fileFolderService.create(workingRootNodeRef, "Something_fr_FR..ftl", ContentModel.TYPE_CONTENT).getNodeRef();
    NodeRef nodeEn = fileFolderService.create(workingRootNodeRef, "Something_en.ftl", ContentModel.TYPE_CONTENT).getNodeRef();
    NodeRef nodeEnUs = fileFolderService.create(workingRootNodeRef, "Something_en_US.ftl", ContentModel.TYPE_CONTENT).getNodeRef();
    
    I18NUtil.setLocale(Locale.US);
    assertEquals("Match fail for " + I18NUtil.getLocale(), nodeEnUs, fileFolderService.getLocalizedSibling(node));
    I18NUtil.setLocale(Locale.UK);
    assertEquals("Match fail for " + I18NUtil.getLocale(), nodeEn, fileFolderService.getLocalizedSibling(node));
    I18NUtil.setLocale(Locale.CHINESE);
    assertEquals("Match fail for " + I18NUtil.getLocale(), node, fileFolderService.getLocalizedSibling(node));

    // Now use French as the base and check that the original is returned
    
    I18NUtil.setLocale(Locale.US);
    assertEquals("Match fail for " + I18NUtil.getLocale(), nodeFr, fileFolderService.getLocalizedSibling(nodeFr));
    I18NUtil.setLocale(Locale.UK);
    assertEquals("Match fail for " + I18NUtil.getLocale(), nodeFr, fileFolderService.getLocalizedSibling(nodeFr));
    I18NUtil.setLocale(Locale.CHINESE);
    assertEquals("Match fail for " + I18NUtil.getLocale(), nodeFr, fileFolderService.getLocalizedSibling(nodeFr));
    
    
    // Check that extensions like .get.html.ftl work
    FileInfo mbase = fileFolderService.create(workingRootNodeRef, "Another.get.html.ftl", ContentModel.TYPE_CONTENT);
    NodeRef mnode = mbase.getNodeRef();
    NodeRef mnodeFr = fileFolderService.create(workingRootNodeRef, "Another_fr.get.html.ftl", ContentModel.TYPE_CONTENT).getNodeRef();
    
    // Should get the base version, except for when French
    I18NUtil.setLocale(Locale.UK);
    assertEquals("Match fail for " + I18NUtil.getLocale(), mnode, fileFolderService.getLocalizedSibling(mnode));
    I18NUtil.setLocale(Locale.FRENCH);
    assertEquals("Match fail for " + I18NUtil.getLocale(), mnodeFr, fileFolderService.getLocalizedSibling(mnode));
    I18NUtil.setLocale(Locale.CHINESE);
    assertEquals("Match fail for " + I18NUtil.getLocale(), mnode, fileFolderService.getLocalizedSibling(mnode));
    I18NUtil.setLocale(Locale.US);
    assertEquals("Match fail for " + I18NUtil.getLocale(), mnode, fileFolderService.getLocalizedSibling(mnode));
}
 
Example 18
Source File: SiteServiceTest.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 4 votes vote down vote up
private NodeRef copyToSite(NodeRef fileRef, NodeRef destRef) throws Exception
{
    FileInfo copiedFileInfo = fileFolderService.copy(fileRef, destRef, null);
    return copiedFileInfo.getNodeRef();
}
 
Example 19
Source File: ImapServiceImplTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
public void testMailboxRenamingInDeepHierarchyForMNT9055() throws Exception
{
    reauthenticate(USER_NAME, USER_PASSWORD);
    AlfrescoImapUser poweredUser = new AlfrescoImapUser((USER_NAME + "@alfresco.com"), USER_NAME, USER_PASSWORD);

    NodeRef root = findCompanyHomeNodeRef();

    NodeRef parent = root;

    FileInfo targetNode = null;
    String targetNodeName = IMAP_ROOT;
    StringBuilder fullPath = new StringBuilder();
    List<String> fullPathList = new LinkedList<String>();
    String renamedNodeName = "Renamed-" + System.currentTimeMillis();

    for (int i = 0; i < 10; i++)
    {
        fullPath.append(targetNodeName).append(AlfrescoImapConst.HIERARCHY_DELIMITER);
        targetNodeName = new StringBuilder("Test").append(i).append("-").append(System.currentTimeMillis()).toString();

        if (i < 9)
        {
            fullPathList.add(targetNodeName);
        }

        targetNode = fileFolderService.create(parent, targetNodeName, ContentModel.TYPE_FOLDER);
        assertNotNull(targetNode);

        parent = targetNode.getNodeRef();
        assertNotNull(parent);
    }

    String path = fullPath.toString();
    String targetNodePath = path + targetNodeName;
    String renamedNodePath = path + renamedNodeName;

    List<String> renamedFullPathList = new LinkedList<String>(fullPathList);
    renamedFullPathList.add(renamedNodeName);
    fullPathList.add(targetNodeName);

    assertMailboxRenaming(poweredUser, root, targetNodePath, renamedFullPathList, renamedNodePath, targetNode);

    AlfrescoImapFolder mailbox = imapService.getOrCreateMailbox(poweredUser, renamedNodePath, true, false);
    assertMailboxNotNull(mailbox);

    List<String> pathAfterRenaming = fileFolderService.getNameOnlyPath(root, mailbox.getFolderInfo().getNodeRef());

    assertPathHierarchy(fullPathList, pathAfterRenaming);

    FileInfo renamedNode = fileFolderService.resolveNamePath(root, pathAfterRenaming);
    assertNotNull(renamedNode);
    assertEquals(targetNode.getNodeRef(), renamedNode.getNodeRef());
}
 
Example 20
Source File: ImapServiceImplTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
public void testMiddleMailboxRenamingInDeepHierarchyForMNT9055() throws Exception
{
    reauthenticate(USER_NAME, USER_PASSWORD);
    AlfrescoImapUser poweredUser = new AlfrescoImapUser((USER_NAME + "@alfresco.com"), USER_NAME, USER_PASSWORD);

    NodeRef root = findCompanyHomeNodeRef();

    NodeRef parent = root;

    String middleName = null; // Name of the middle folder
    FileInfo targetNode = null; // A leaf folder
    FileInfo middleNode = null; // A middle folder
    String targetNodeName = IMAP_ROOT; // Current folder name
    StringBuilder fullPath = new StringBuilder(); // Path from the middle to the leaf folder
    StringBuilder fullLeftPath = new StringBuilder(); // Path to the middle folder
    List<String> fullLeftPathList = new LinkedList<String>(); // Path elements to the middle folder
    List<String> fullRightPathList = new LinkedList<String>(); // Path from the middle to the leaf folder
    String renamedNodeName = "Renamed-" + System.currentTimeMillis();

    for (int i = 0; i < 10; i++)
    {
        if (i <= 5)
        {
            fullLeftPath.append(targetNodeName).append(AlfrescoImapConst.HIERARCHY_DELIMITER);
        }
        else
        {
            if (i > 6)
            {
                fullPath.append(targetNodeName).append(AlfrescoImapConst.HIERARCHY_DELIMITER);
            }
        }

        targetNodeName = new StringBuilder("Test").append(i).append("-").append(System.currentTimeMillis()).toString();

        if (i < 5)
        {
            fullLeftPathList.add(targetNodeName);
        }
        else
        {
            if (i > 5)
            {
                fullRightPathList.add(targetNodeName);
            }
        }

        targetNode = fileFolderService.create(parent, targetNodeName, ContentModel.TYPE_FOLDER);
        assertNotNull(targetNode);
        assertNotNull(targetNode.getNodeRef());

        parent = targetNode.getNodeRef();

        if (5 == i)
        {
            middleName = targetNodeName;
            middleNode = targetNode;
        }
    }

    String path = fullLeftPath.toString();
    String targetNodePath = path + middleName;
    String renamedNodePath = path + renamedNodeName;

    List<String> renamedFullLeftPathList = new LinkedList<String>(fullLeftPathList);
    renamedFullLeftPathList.add(renamedNodeName);
    fullLeftPathList.add(middleName);

    assertMailboxRenaming(poweredUser, root, targetNodePath, renamedFullLeftPathList, renamedNodePath, middleNode);

    AlfrescoImapFolder mailbox = imapService.getOrCreateMailbox(poweredUser, renamedNodePath, true, false);
    assertMailboxNotNull(mailbox);

    List<String> pathAfterRenaming = fileFolderService.getNameOnlyPath(root, mailbox.getFolderInfo().getNodeRef());

    assertPathHierarchy(fullLeftPathList, pathAfterRenaming);

    FileInfo renamedNode = fileFolderService.resolveNamePath(root, pathAfterRenaming);
    assertNotNull(renamedNode);
    assertEquals(middleNode.getNodeRef(), renamedNode.getNodeRef());

    String fullRenamedPath = new StringBuilder(path).append(renamedNodeName).append(AlfrescoImapConst.HIERARCHY_DELIMITER).append(fullPath).append(targetNodeName).toString();
    mailbox = imapService.getOrCreateMailbox(poweredUser, fullRenamedPath, true, false);
    assertMailboxNotNull(mailbox);

    assertEquals(targetNode.getNodeRef(), mailbox.getFolderInfo().getNodeRef());

    pathAfterRenaming = fileFolderService.getNameOnlyPath(middleNode.getNodeRef(), targetNode.getNodeRef());
    assertPathHierarchy(fullRightPathList, pathAfterRenaming);
}