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

The following examples show how to use org.alfresco.service.cmr.model.FileNotFoundException. 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: PortableHomeFolderManager.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Modifies (if required) the leaf folder name in the {@code homeFolderPath} by
 * appending {@code "-N"} (where N is an integer starting with 1), so that a
 * new folder will be created.
 * @param root folder.
 * @param homeFolderPath the full path. Only the final element is used.
 */
public void modifyHomeFolderNameIfItExists(NodeRef root, List<String> homeFolderPath)
{
    int n = 0;
    int last = homeFolderPath.size()-1;
    String name = homeFolderPath.get(last);
    String homeFolderName = name;
    try
    {
        do
        {
            if (n > 0)
            {
                homeFolderName = name+'-'+n;
                homeFolderPath.set(last, homeFolderName);
            }
            n++;
        } while (fileFolderService.resolveNamePath(root, homeFolderPath, false) != null);
    }
    catch (FileNotFoundException e)
    {
        // Should not be thrown as call to resolveNamePath passes in false
    }
}
 
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: 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 #4
Source File: FileFolderLoaderTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Test
public void testFolderMissing() throws Exception
{
    try
    {
        AuthenticationUtil.pushAuthentication();
        AuthenticationUtil.setAdminUserAsFullyAuthenticatedUser();
        fileFolderLoader.createFiles(
                sharedHomePath + "/Missing",
                0, 256, 1024L, 1024L, Long.MAX_VALUE, false,
                10, 256L);
        fail("Folder does not exist");
    }
    catch (AlfrescoRuntimeException e)
    {
        // Expected
        assertTrue(e.getCause() instanceof FileNotFoundException);
    }
    finally
    {
        AuthenticationUtil.popAuthentication();
    }
}
 
Example #5
Source File: ScriptNode.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Helper to set the 'name' property for the node.
 * 
 * @param name Name to set
 */
public void setName(String name)
{
    if (name != null)
    {
        QName typeQName = getQNameType();
        if ((services.getDictionaryService().isSubClass(typeQName, ContentModel.TYPE_FOLDER) &&
             !services.getDictionaryService().isSubClass(typeQName, ContentModel.TYPE_SYSTEM_FOLDER)) ||
             services.getDictionaryService().isSubClass(typeQName, ContentModel.TYPE_CONTENT))
        {
            try
            {
               this.services.getFileFolderService().rename(this.nodeRef, name);
            }
            catch (FileNotFoundException e)
            {
                throw new AlfrescoRuntimeException("Failed to rename node " + nodeRef + " to " + name, e);
            }
        }
        this.getProperties().put(ContentModel.PROP_NAME.toString(), name.toString());
    }
}
 
Example #6
Source File: ImapServiceImplTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * @param root - {@link NodeRef} instance, which determines <code>Alfresco IMAP</code> root node
 * @param actualNode - {@link NodeRef} instance, which determines mailbox in actual state
 * @throws FileNotFoundException
 */
private void assertMailboxInUserImapHomeDirectory(NodeRef root, NodeRef actualNode) throws FileNotFoundException
{
    List<String> path = fileFolderService.getNameOnlyPath(root, actualNode);

    int satisfactionFlag = 0;
    for (String element : path)
    {
        if (TEST_IMAP_FOLDER_NAME.equals(element) || USER_NAME.equals(element))
        {
            satisfactionFlag++;
        }

        if (satisfactionFlag > 1)
        {
            break;
        }
    }

    assertTrue(satisfactionFlag > 1);
}
 
Example #7
Source File: NodesImpl.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 6 votes vote down vote up
private void rename(NodeRef nodeRef, String name)
{
    try
    {
        fileFolderService.rename(nodeRef, name);
    }
    catch (FileNotFoundException fnfe)
    {
        // convert checked exception
        throw new EntityNotFoundException(nodeRef.getId());
    }
    catch (FileExistsException fee)
    {
        // duplicate - name clash
        throw new ConstraintViolatedException("Name already exists in target parent: " + name);
    }
}
 
Example #8
Source File: QuickShareRestApiTest.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * This test verifies that copying a shared node does not across the shared aspect and it's associated properties.
 * @throws IOException 
 * @throws UnsupportedEncodingException 
 * @throws JSONException 
 * @throws FileNotFoundException 
 * @throws FileExistsException 
 */
public void testCopy() throws UnsupportedEncodingException, IOException, JSONException, FileExistsException, FileNotFoundException 
{
    final int expectedStatusOK = 200;
    
    String testNodeRef = testNode.toString().replace("://", "/");

    // As user one ...
    
    // share
    Response rsp = sendRequest(new PostRequest(SHARE_URL.replace("{node_ref_3}", testNodeRef), "", APPLICATION_JSON), expectedStatusOK, USER_ONE);
    JSONObject jsonRsp = new JSONObject(new JSONTokener(rsp.getContentAsString()));
    String sharedId = jsonRsp.getString("sharedId");
    assertNotNull(sharedId);
    assertEquals(22, sharedId.length()); // note: we may have to adjust/remove this check if we change length of id (or it becomes variable length)

    AuthenticationUtil.setFullyAuthenticatedUser(USER_ONE);
    FileInfo copyFileInfo = fileFolderService.copy(testNode, userOneHome, "Copied node");
    NodeRef copyNodeRef = copyFileInfo.getNodeRef();
    
    assertFalse(nodeService.hasAspect(copyNodeRef, QuickShareModel.ASPECT_QSHARE));
}
 
Example #9
Source File: AlfrescoImapFolder.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 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 #10
Source File: AlfrescoImapFolder.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Copies message with the given UID to the specified {@link MailFolder}.
 * 
 * @param uid - UID of the message
 * @param toFolder - reference to the destination folder.
 * @throws MessagingException 
 * @throws IOException 
 * @throws FileNotFoundException 
 * @throws FileExistsException 
 */
@Override
protected long copyMessageInternal(
        long uid, MailFolder toFolder)
        throws MessagingException, FileExistsException, FileNotFoundException, IOException 
{
    AlfrescoImapFolder toImapMailFolder = (AlfrescoImapFolder) toFolder;

    NodeRef destFolderNodeRef = toImapMailFolder.getFolderInfo().getNodeRef();

    FileInfo sourceMessageFileInfo = searchMails().get(uid);

    if (serviceRegistry.getNodeService().hasAspect(sourceMessageFileInfo.getNodeRef(), ImapModel.ASPECT_IMAP_CONTENT))
    {
            //Generate body of message
        MimeMessage newMessage = new ImapModelMessage(sourceMessageFileInfo, serviceRegistry, true);
        return toImapMailFolder.appendMessageInternal(newMessage, imapService.getFlags(sourceMessageFileInfo), new Date());
    }
    else
    {
        String fileName = (String) serviceRegistry.getNodeService().getProperty(sourceMessageFileInfo.getNodeRef(), ContentModel.PROP_NAME);
        String newFileName = imapService.generateUniqueFilename(destFolderNodeRef, fileName);
        FileInfo messageFileInfo = serviceRegistry.getFileFolderService().copy(sourceMessageFileInfo.getNodeRef(), destFolderNodeRef, newFileName);
        return (Long)messageFileInfo.getProperties().get(ContentModel.PROP_NODE_DBID);
    }
}
 
Example #11
Source File: AlfrescoImapFolder.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Appends message to the folder.
 * 
 * @param message - message.
 * @param flags - message flags.
 * @param internalDate - not used. Current date used instead.
 */
@Override
protected long appendMessageInternal(
        MimeMessage message,
        Flags flags,
        Date internalDate)
        throws FileExistsException, FileNotFoundException, IOException, MessagingException 
{
    long uid;
    NodeRef sourceNodeRef = extractNodeRef(message);
    if (sourceNodeRef != null)
    {
        uid = copyOrMoveNode(this.folderInfo, message, flags, sourceNodeRef, false);
    }
    else
    {
        uid = createMimeMessageInFolder(this.folderInfo, message, flags);
    }
    // Invalidate current folder status
    this.folderStatus = null;
    return uid;
}
 
Example #12
Source File: WebDAVHelperIntegrationTest.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Test
public void cannotGetNodeForPathWithIncorrectCase() throws FileNotFoundException
{
    FileInfo folderInfo = fileFolderService.create(rootFolder, "my_folder", ContentModel.TYPE_FOLDER);
    fileFolderService.create(folderInfo.getNodeRef(), "my_file.txt", ContentModel.TYPE_CONTENT);
    
    try
    {
        webDAVHelper.getNodeForPath(rootFolder, "My_Folder/My_File.txt");
        fail("FileNotFoundException should have been thrown.");
    }
    catch (FileNotFoundException e)
    {
        // Got here, good.
    }
}
 
Example #13
Source File: WebDAVHelperIntegrationTest.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Test
public void cannotGetNodeForFolderPathWithIncorrectCase() throws FileNotFoundException
{
    FileInfo folderInfo = fileFolderService.create(rootFolder, "my_folder", ContentModel.TYPE_FOLDER);
    fileFolderService.create(folderInfo.getNodeRef(), "my_file.txt", ContentModel.TYPE_CONTENT);
    
    try
    {
        webDAVHelper.getNodeForPath(rootFolder, "My_Folder");
        fail("FileNotFoundException should have been thrown.");
    }
    catch (FileNotFoundException e)
    {
        // Got here, good.
    }
}
 
Example #14
Source File: RepoRemoteService.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
public void rename(NodeRef base, String src, String dst) 
{
    NodeRef srcRef = lookup(base, src).getFirst();
    if (srcRef == null)
    {
        throw new AlfrescoRuntimeException("Not Found: " + src);
    }
    Pair<NodeRef, String> parentChild = getParentChildRelative(base, dst);
    try
    {
        fFileFolderService.move(srcRef, parentChild.getFirst(), parentChild.getSecond());
    }
    catch (FileNotFoundException e)
    {
        throw new AlfrescoRuntimeException("Parent Not Found: " + dst, e);
    }
}
 
Example #15
Source File: SiteServiceImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * @see org.alfresco.service.cmr.site.SiteService#getContainer(java.lang.String, String)
 */
public NodeRef getContainer(String shortName, String componentId)
{
    ParameterCheck.mandatoryString("componentId", componentId);

    // retrieve site
    NodeRef siteNodeRef = getSiteNodeRef(shortName);
    if (siteNodeRef == null)
    {
       throw new SiteDoesNotExistException(shortName);
    }

    // retrieve component folder within site
    // NOTE: component id is used for folder name
    NodeRef containerNodeRef = null;
    try
    {
        containerNodeRef = findContainer(siteNodeRef, componentId);
    } 
    catch (FileNotFoundException e)
    {
        //NOOP
    }

    return containerNodeRef;
}
 
Example #16
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 #17
Source File: ImapServiceImplTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * @param user - {@link AlfrescoImapUser} instance, which determines a user who has enough permissions to rename a node
 * @param root - {@link NodeRef} instance, which determines <code>Alfresco IMAP</code> root node
 * @param targetNodePath - {@link String} value, which determines a path in IMAP notation to a node which should be renamed
 * @param targetNode - {@link FileInfo} instance, which determines a node, located at the <code>targetNodePath</code> path
 * @throws FileNotFoundException
 */
private void assertMailboxRenaming(AlfrescoImapUser user, NodeRef root, String targetNodePath, List<String> renamedNodeName, String renamedNodePath, FileInfo targetNode)
        throws FileNotFoundException
{
    AlfrescoImapFolder mailbox = imapService.getOrCreateMailbox(user, targetNodePath, true, false);
    assertNotNull(("Just created mailbox can't be received by full path via the ImapService. Path: '" + targetNodePath + "'"), mailbox);
    assertNotNull(mailbox.getFolderInfo());
    assertNotNull(mailbox.getFolderInfo().getNodeRef());

    imapService.renameMailbox(user, targetNodePath, renamedNodePath);

    NodeRef actualNode = null;

    if (null != targetNode)
    {
        FileInfo actualFileInfo = fileFolderService.resolveNamePath(root, renamedNodeName);
        assertNotNull(actualFileInfo);
        assertNotNull(actualFileInfo.getNodeRef());
        actualNode = actualFileInfo.getNodeRef();
    }
    else
    {
        mailbox = imapService.getOrCreateMailbox(user, renamedNodePath, true, false);
        assertNotNull(mailbox);
        actualNode = mailbox.getFolderInfo().getNodeRef();
    }

    assertNotNull(("Can't receive renamed node by full path: '" + renamedNodePath + "'"), actualNode);

    if (null != targetNode)
    {
        assertEquals(targetNode.getNodeRef(), actualNode);
    }
    else
    {
        assertMailboxInUserImapHomeDirectory(root, actualNode);
    }
}
 
Example #18
Source File: DeleteMethod.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Create a deletion activity post.
 * 
 * @param parent The FileInfo for the deleted file's parent.
 * @param deletedFile The FileInfo for the deleted file.
 * @throws WebDAVServerException 
 */
protected void postActivity(FileInfo parent, FileInfo deletedFile, String siteId) throws WebDAVServerException
{
    WebDavService davService = getDAVHelper().getServiceRegistry().getWebDavService();
    if (!davService.activitiesEnabled())
    {
        // Don't post activities if this behaviour is disabled.
        return;
    }
    
    String tenantDomain = getTenantDomain();
    
    // Check there is enough information to publish site activity.
    if (!siteId.equals(WebDAVHelper.EMPTY_SITE_ID))
    {
        SiteService siteService = getServiceRegistry().getSiteService();
        NodeRef documentLibrary = siteService.getContainer(siteId, SiteService.DOCUMENT_LIBRARY);
        String parentPath = "/";
        try
        {
            parentPath = getDAVHelper().getPathFromNode(documentLibrary, parent.getNodeRef());
        }
        catch (FileNotFoundException error)
        {
            if (logger.isDebugEnabled())
            {
                logger.debug("No " + SiteService.DOCUMENT_LIBRARY + " container found.");
            }
        }
        
        activityPoster.postFileFolderDeleted(siteId, tenantDomain, parentPath, parent, deletedFile);
    }  
}
 
Example #19
Source File: WebDAVHelper.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 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 #20
Source File: WebDAVHelperIntegrationTest.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Test
public void canGetNodeForPathWithCorrectCase() throws FileNotFoundException
{
    FileInfo folderInfo = fileFolderService.create(rootFolder, "my_folder", ContentModel.TYPE_FOLDER);
    FileInfo fileInfo = fileFolderService.create(folderInfo.getNodeRef(), "my_file.txt", ContentModel.TYPE_CONTENT);
    
    FileInfo found = webDAVHelper.getNodeForPath(rootFolder, "my_folder/my_file.txt");
    // Sanity check, but the main test is that we haven't have a FileNotFoundException thrown.
    assertEquals(fileInfo, found);
    
    found = webDAVHelper.getNodeForPath(rootFolder, "my_folder");
    assertEquals(folderInfo, found);
}
 
Example #21
Source File: WebDAVHelperIntegrationTest.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Test
public void canGetNodeForRootFolderPath() throws FileNotFoundException
{
    FileInfo folderInfo = fileFolderService.create(rootFolder, "my_folder", ContentModel.TYPE_FOLDER);
    fileFolderService.create(folderInfo.getNodeRef(), "my_file.txt", ContentModel.TYPE_CONTENT);
    
    FileInfo found = webDAVHelper.getNodeForPath(rootFolder, "/");
    assertEquals(rootFolder, found.getNodeRef());
}
 
Example #22
Source File: Utils.java    From alfresco-bulk-import with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a human-readable rendition of the repository path of the given NodeRef.
 * 
 * @param serviceRegistry The ServiceRegistry <i>(must not be null)</i>.
 * @param nodeRef         The nodeRef from which to derive a path <i>(may be null)</i>.
 * @return The human-readable path <i>(will be null if the nodeRef is null or the nodeRef doesn't exist)</i>.
 */
public final static String convertNodeRefToPath(final ServiceRegistry serviceRegistry, final NodeRef nodeRef)
{
    String result = null;
    
    if (nodeRef != null)
    {
        List<FileInfo> pathElements = null;
        
        try
        {
            pathElements = serviceRegistry.getFileFolderService().getNamePath(null, nodeRef);   // Note: violates Google Code issue #132, but allowable in this case since this is a R/O method without an obvious alternative

            if (pathElements != null && pathElements.size() > 0)
            {
                StringBuilder temp = new StringBuilder();
                
                for (FileInfo pathElement : pathElements)
                {
                    temp.append("/");
                    temp.append(pathElement.getName());
                }
                
                result = temp.toString();
            }
        }
        catch (final FileNotFoundException fnfe)
        {
            // Do nothing
        }
    }
    
    return(result);
}
 
Example #23
Source File: AbstractBulkFilesystemImporter.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
protected final String getRepositoryPath(NodeRef nodeRef)
{
    String result = null;
    
    if (nodeRef != null)
    {
        List<FileInfo> pathElements = null;
        
        try
        {
            pathElements = fileFolderService.getNamePath(null, nodeRef);

            if (pathElements != null && pathElements.size() > 0)
            {
                StringBuilder temp = new StringBuilder();
                
                for (FileInfo pathElement : pathElements)
                {
                    temp.append("/");
                    temp.append(pathElement.getName());
                }
                
                result = temp.toString();
            }
        }
        catch (final FileNotFoundException fnfe)
        {
            // Do nothing
        }
    }
    
    return(result);
}
 
Example #24
Source File: WebDAVHelper.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 5 votes vote down vote up
public final FileInfo getParentNodeForPath(NodeRef rootNodeRef, String path) throws FileNotFoundException
{
    if (rootNodeRef == null)
    {
        throw new IllegalArgumentException("Root node may not be null");
    }
    else if (path == null)
    {
        throw new IllegalArgumentException("Path may not be null");
    }
    // shorten the path
    String[] paths = splitPath(path);
    return getNodeForPath(rootNodeRef, paths[0]);
}
 
Example #25
Source File: FileFolderServiceImplTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void testGetNamePath() throws Exception
{
    FileInfo fileInfo = getByName(NAME_L1_FILE_A, false);
    assertNotNull(fileInfo);
    NodeRef nodeRef = fileInfo.getNodeRef();

    List<FileInfo> infoPaths = fileFolderService.getNamePath(workingRootNodeRef, nodeRef);
    assertEquals("Not enough elements", 2, infoPaths.size());
    assertEquals("First level incorrent", NAME_L0_FOLDER_A, infoPaths.get(0).getName());
    assertEquals("Second level incorrent", NAME_L1_FILE_A, infoPaths.get(1).getName());

    // pass in a null root and make sure that it still works
    infoPaths = fileFolderService.getNamePath(null, nodeRef);
    assertEquals("Not enough elements", 3, infoPaths.size());
    assertEquals("First level incorrent", workingRootNodeRef.getId(), infoPaths.get(0).getName());
    assertEquals("Second level incorrent", NAME_L0_FOLDER_A, infoPaths.get(1).getName());
    assertEquals("Third level incorrent", NAME_L1_FILE_A, infoPaths.get(2).getName());

    // check that a non-aligned path is detected
    NodeRef startRef = getByName(NAME_L0_FOLDER_B, true).getNodeRef();
    try
    {
        fileFolderService.getNamePath(startRef, nodeRef);
        fail("Failed to detect non-aligned path from root to target node");
    }
    catch (FileNotFoundException e)
    {
        // expected
    }
}
 
Example #26
Source File: ActivityPosterImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
private 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 "";
    
    // get the path elements
    List<FileInfo> pathInfos = fileFolderService.getNamePath(rootNodeRef, nodeRef);
    
    // build the path string
    StringBuilder sb = new StringBuilder(pathInfos.size() * 20);
    for (FileInfo fileInfo : pathInfos)
    {
        sb.append(PathSeperatorChar);
        sb.append(fileInfo.getName());
    }
    // done
    if (logger.isDebugEnabled())
    {
        logger.debug("Build name path for node: \n" +
                "   root: " + rootNodeRef + "\n" +
                "   target: " + nodeRef + "\n" +
                "   path: " + sb);
    }
    return sb.toString();
}
 
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: 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 #29
Source File: FileFolderServicePropagationTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void moveObjectAndAssert(FileInfo object) throws FileNotFoundException
{
    FileInfo moved = fileFolderService.move(object.getNodeRef(), testEmptyFolder.getNodeRef(), object.getName());
    assertParent(moved, testEmptyFolder);
    assertEquals(object.getModifiedDate(), moved.getModifiedDate());
    assertEquals(object.getProperties().get(ContentModel.PROP_MODIFIER), moved.getProperties().get(ContentModel.PROP_MODIFIER));
}
 
Example #30
Source File: ActivityPosterImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
public ActivityInfo getActivityInfo(NodeRef nodeRef)
{
    SiteInfo siteInfo = siteService.getSite(nodeRef);
    String siteId = (siteInfo != null ? siteInfo.getShortName() : null);
    if(siteId != null && !siteId.equals(""))
    {
        NodeRef parentNodeRef = nodeService.getPrimaryParent(nodeRef).getParentRef();
        FileInfo fileInfo = fileFolderService.getFileInfo(nodeRef);
        String name = fileInfo.getName();
        boolean isFolder = fileInfo.isFolder();
            
        NodeRef documentLibrary = siteService.getContainer(siteId, SiteService.DOCUMENT_LIBRARY);
        String parentPath = "/";
        try
        {
            parentPath = getPathFromNode(documentLibrary, parentNodeRef);
        }
        catch (FileNotFoundException error)
        {
            if (logger.isDebugEnabled())
            {
                logger.debug("No " + SiteService.DOCUMENT_LIBRARY + " container found.");
            }
        }
        
        return new ActivityInfo(nodeRef, parentPath, parentNodeRef, siteId, name, isFolder);
    }
    else
    {
        return null;
    }
}