Search in sources :

Example 11 with FileNotFoundException

use of org.alfresco.service.cmr.model.FileNotFoundException in project alfresco-remote-api by Alfresco.

the class MkcolMethod method postActivity.

/**
 * Create a folder added activity post.
 *
 * @throws WebDAVServerException
 */
private void postActivity(FileInfo fileInfo) throws WebDAVServerException {
    WebDavService davService = getDAVHelper().getServiceRegistry().getWebDavService();
    if (!davService.activitiesEnabled()) {
        // Don't post activities if this behaviour is disabled.
        return;
    }
    String siteId = getSiteId();
    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 path = "/";
        try {
            path = getDAVHelper().getPathFromNode(documentLibrary, fileInfo.getNodeRef());
        } catch (FileNotFoundException error) {
            if (logger.isDebugEnabled()) {
                logger.debug("No " + SiteService.DOCUMENT_LIBRARY + " container found.");
            }
        }
        activityPoster.postFileFolderAdded(siteId, tenantDomain, path, fileInfo);
    }
}
Also used : WebDavService(org.alfresco.service.cmr.webdav.WebDavService) NodeRef(org.alfresco.service.cmr.repository.NodeRef) SiteService(org.alfresco.service.cmr.site.SiteService) FileNotFoundException(org.alfresco.service.cmr.model.FileNotFoundException)

Example 12 with FileNotFoundException

use of org.alfresco.service.cmr.model.FileNotFoundException in project alfresco-remote-api by Alfresco.

the class MoveMethod method executeImpl.

/**
 * Exceute the request
 *
 * @exception WebDAVServerException
 */
protected final void executeImpl() throws WebDAVServerException, Exception {
    NodeRef rootNodeRef = getRootNodeRef();
    // Debug
    if (logger.isDebugEnabled()) {
        logger.debug((isMove() ? "Move" : "Copy") + " from " + getPath() + " to " + getDestinationPath());
    }
    // the source must exist
    String sourcePath = getPath();
    FileInfo sourceInfo = null;
    try {
        sourceInfo = getNodeForPath(rootNodeRef, sourcePath);
    } catch (FileNotFoundException e) {
        throw new WebDAVServerException(HttpServletResponse.SC_NOT_FOUND);
    }
    FileInfo sourceParentInfo = getDAVHelper().getParentNodeForPath(rootNodeRef, sourcePath);
    // the destination parent must exist
    String destPath = getDestinationPath();
    FileInfo destParentInfo = null;
    try {
        if (destPath.endsWith(WebDAVHelper.PathSeperator)) {
            destPath = destPath.substring(0, destPath.length() - 1);
        }
        destParentInfo = getDAVHelper().getParentNodeForPath(rootNodeRef, destPath);
    } catch (FileNotFoundException e) {
        if (logger.isDebugEnabled()) {
            logger.debug("Destination parent folder doesn't exist: " + destPath);
        }
        throw new WebDAVServerException(HttpServletResponse.SC_CONFLICT);
    }
    // check for the existence of the destination node
    FileInfo destInfo = null;
    boolean destNotHidden = false;
    try {
        destInfo = getDAVHelper().getNodeForPath(rootNodeRef, destPath);
        if (!destInfo.getNodeRef().equals(sourceInfo.getNodeRef())) {
            // ALF-7079 (MNT-1601) fix, if destInfo is a hidden shuffle target then pretend it's not there
            destNotHidden = !getFileFolderService().isHidden(destInfo.getNodeRef());
            if (!hasOverWrite() && destNotHidden) {
                if (logger.isDebugEnabled()) {
                    logger.debug("Destination exists but overwrite is not allowed");
                }
                // it exists and we may not overwrite
                throw new WebDAVServerException(HttpServletResponse.SC_PRECONDITION_FAILED);
            }
            checkNode(destInfo);
        }
    } catch (FileNotFoundException e) {
    // destination doesn't exist
    }
    NodeRef sourceNodeRef = sourceInfo.getNodeRef();
    NodeRef sourceParentNodeRef = sourceParentInfo.getNodeRef();
    NodeRef destParentNodeRef = destParentInfo.getNodeRef();
    String name = getDAVHelper().splitPath(destPath)[1];
    moveOrCopy(sourceNodeRef, sourceParentNodeRef, destParentNodeRef, name);
    // Set the response status
    if (!destNotHidden) {
        m_response.setStatus(HttpServletResponse.SC_CREATED);
    } else {
        m_response.setStatus(HttpServletResponse.SC_NO_CONTENT);
    }
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) FileInfo(org.alfresco.service.cmr.model.FileInfo) FileNotFoundException(org.alfresco.service.cmr.model.FileNotFoundException)

Example 13 with FileNotFoundException

use of org.alfresco.service.cmr.model.FileNotFoundException in project alfresco-remote-api by Alfresco.

the class MoveMethod method moveOrCopy.

protected void moveOrCopy(NodeRef sourceNodeRef, NodeRef sourceParentNodeRef, NodeRef destParentNodeRef, String name) throws Exception {
    FileFolderService fileFolderService = getFileFolderService();
    NodeRef rootNodeRef = getRootNodeRef();
    String sourcePath = getPath();
    List<String> sourcePathElements = getDAVHelper().splitAllPaths(sourcePath);
    FileInfo sourceFileInfo = null;
    String destPath = getDestinationPath();
    List<String> destPathElements = getDAVHelper().splitAllPaths(destPath);
    FileInfo destFileInfo = null;
    boolean isMove = isMove();
    try {
        // get the node to move
        sourceFileInfo = fileFolderService.resolveNamePath(rootNodeRef, sourcePathElements);
        destFileInfo = fileFolderService.resolveNamePath(rootNodeRef, destPathElements);
    } catch (FileNotFoundException e) {
        if (sourceFileInfo == null) {
            if (logger.isDebugEnabled()) {
                logger.debug("Source node not found: " + sourcePath);
            }
            // nothing to move
            throw new WebDAVServerException(HttpServletResponse.SC_NOT_FOUND);
        }
    }
    LockInfo lockInfo = null;
    if (isMove) {
        lockInfo = checkNode(sourceFileInfo);
    }
    // this is a move
    if (!sourceFileInfo.isFolder() && destFileInfo != null && !sourceFileInfo.equals(destFileInfo)) {
        copyContentOnly(sourceFileInfo, destFileInfo, fileFolderService);
        fileFolderService.setHidden(destFileInfo.getNodeRef(), false);
        if (isMove) {
            if (getDAVHelper().isRenameShuffle(destPath) && !getDAVHelper().isRenameShuffle(sourcePath)) {
                // if temporary or backup file already exists
                // don't delete source that is node with version history
                fileFolderService.setHidden(sourceNodeRef, true);
                // As per the WebDAV spec, we make sure the node is unlocked once moved
                unlock(sourceNodeRef, lockInfo);
            } else {
                fileFolderService.delete(sourceNodeRef);
            }
        }
    } else // If this is a copy then the source is just copied to destination.
    if (!isMove) {
        // MNT-9939 - check overwrite
        if (hasOverWrite() && destFileInfo != null) {
            if (logger.isDebugEnabled()) {
                logger.debug("Destination exists and overwrite is allowed");
            }
            fileFolderService.delete(destFileInfo.getNodeRef());
        }
        fileFolderService.copy(sourceNodeRef, destParentNodeRef, name);
    } else // copied to destination and the source is hidden.
    if (!sourceFileInfo.isFolder() && getDAVHelper().isRenameShuffle(destPath) && !getDAVHelper().isRenameShuffle(sourcePath)) {
        destFileInfo = fileFolderService.create(destParentNodeRef, name, ContentModel.TYPE_CONTENT);
        copyContentOnly(sourceFileInfo, destFileInfo, fileFolderService);
        fileFolderService.setHidden(sourceNodeRef, true);
        // As per the WebDAV spec, we make sure the node is unlocked once moved
        unlock(sourceNodeRef, lockInfo);
    } else if (sourceParentNodeRef.equals(destParentNodeRef)) {
        // MNT-9939 - check overwrite
        if (hasOverWrite() && destFileInfo != null && !sourceFileInfo.equals(destFileInfo)) {
            if (logger.isDebugEnabled()) {
                logger.debug("Destination exists and overwrite is allowed");
            }
            fileFolderService.delete(destFileInfo.getNodeRef());
        }
        fileFolderService.rename(sourceNodeRef, name);
        // MNT-13144 WebDav does not correctly version CAD drawings correctly when saved using Windows mapped drive
        if (!sourceFileInfo.isFolder() && getDAVHelper().isRenameShuffle(name)) {
            fileFolderService.setHidden(sourceFileInfo.getNodeRef(), true);
        }
        // As per the WebDAV spec, we make sure the node is unlocked once moved
        unlock(sourceNodeRef, lockInfo);
    } else {
        // MNT-9939 - check overwrite
        if (hasOverWrite() && destFileInfo != null) {
            if (logger.isDebugEnabled()) {
                logger.debug("Destination exists and overwrite is allowed");
            }
            fileFolderService.delete(destFileInfo.getNodeRef());
        }
        fileFolderService.moveFrom(sourceNodeRef, sourceParentNodeRef, destParentNodeRef, name);
        // As per the WebDAV spec, we make sure the node is unlocked once moved
        unlock(sourceNodeRef, lockInfo);
    }
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) FileInfo(org.alfresco.service.cmr.model.FileInfo) FileNotFoundException(org.alfresco.service.cmr.model.FileNotFoundException) FileFolderService(org.alfresco.service.cmr.model.FileFolderService)

Example 14 with FileNotFoundException

use of org.alfresco.service.cmr.model.FileNotFoundException in project alfresco-remote-api by Alfresco.

the class PropFindMethod method executeImpl.

/**
 * Execute the main WebDAV request processing
 *
 * @exception WebDAVServerException
 */
protected void executeImpl() throws WebDAVServerException, Exception {
    m_response.setStatus(WebDAV.WEBDAV_SC_MULTI_STATUS);
    FileInfo pathNodeInfo = null;
    try {
        // Check that the path exists
        pathNodeInfo = getDAVHelper().getNodeForPath(getRootNodeRef(), m_strPath);
    } catch (FileNotFoundException e) {
        // The path is not valid - send a 404 error back to the client
        throw new WebDAVServerException(HttpServletResponse.SC_NOT_FOUND);
    }
    // Note the null check, as root node may be null in cloud.
    if (pathNodeInfo.getNodeRef() != null && getFileFolderService().isHidden(pathNodeInfo.getNodeRef())) {
        throw new WebDAVServerException(HttpServletResponse.SC_NOT_FOUND);
    }
    // Set the response content type
    m_response.setContentType(WebDAV.XML_CONTENT_TYPE);
    // Create multistatus response
    XMLWriter xml = createXMLWriter();
    xml.startDocument();
    String nsdec = generateNamespaceDeclarations(m_namespaces);
    xml.startElement(WebDAV.DAV_NS, WebDAV.XML_MULTI_STATUS + nsdec, WebDAV.XML_NS_MULTI_STATUS + nsdec, getDAVHelper().getNullAttributes());
    // Create the path for the current location in the tree
    StringBuilder baseBuild = new StringBuilder(256);
    baseBuild.append(getPath());
    if (baseBuild.length() == 0 || baseBuild.charAt(baseBuild.length() - 1) != WebDAVHelper.PathSeperatorChar) {
        baseBuild.append(WebDAVHelper.PathSeperatorChar);
    }
    String basePath = baseBuild.toString();
    // Output the response for the root node, depth zero
    generateResponseForNode(xml, pathNodeInfo, basePath);
    // level and output node details a level at a time
    if (getDepth() != WebDAV.DEPTH_0 && pathNodeInfo.isFolder()) {
        // Create the initial list of nodes to report
        List<FileInfo> nodeInfos = new ArrayList<FileInfo>(10);
        nodeInfos.add(pathNodeInfo);
        int curDepth = WebDAV.DEPTH_1;
        // Save the base path length
        int baseLen = baseBuild.length();
        // List of next level of nodes to report
        List<FileInfo> nextNodeInfos = null;
        if (getDepth() > WebDAV.DEPTH_1) {
            nextNodeInfos = new ArrayList<FileInfo>(10);
        }
        // Loop reporting each level of nodes to the requested depth
        while (curDepth <= getDepth() && nodeInfos != null) {
            // Clear out the next level of nodes, if required
            if (nextNodeInfos != null) {
                nextNodeInfos.clear();
            }
            for (FileInfo curNodeInfo : nodeInfos) {
                // Get the list of child nodes for the current node
                List<FileInfo> childNodeInfos = getDAVHelper().getChildren(curNodeInfo);
                // can skip the current node if it doesn't have children
                if (childNodeInfos.size() == 0) {
                    continue;
                }
                // Output the child node details
                // Generate the base path for the current parent node
                baseBuild.setLength(baseLen);
                try {
                    String pathSnippet = null;
                    if ((pathNodeInfo.getNodeRef() == null) && (curNodeInfo.getNodeRef() == null)) {
                        // TODO review - note: can be null in case of Thor
                        pathSnippet = "/";
                    } else {
                        pathSnippet = getDAVHelper().getPathFromNode(pathNodeInfo.getNodeRef(), curNodeInfo.getNodeRef());
                    }
                    baseBuild.append(pathSnippet);
                } catch (FileNotFoundException e) {
                    // move to the next node
                    continue;
                }
                int curBaseLen = baseBuild.length();
                // Output the child node details
                for (FileInfo curChildInfo : childNodeInfos) {
                    // Build the path for the current child node
                    baseBuild.setLength(curBaseLen);
                    baseBuild.append(curChildInfo.getName());
                    // Output the current child node details
                    generateResponseForNode(xml, curChildInfo, baseBuild.toString());
                    // If the child is a folder add it to the list of next level nodes
                    if (nextNodeInfos != null && curChildInfo.isFolder()) {
                        nextNodeInfos.add(curChildInfo);
                    }
                }
            }
            // Update the current tree depth
            curDepth++;
            // Move the next level of nodes to the current node list
            nodeInfos = nextNodeInfos;
        }
    }
    // Close the outer XML element
    xml.endElement(WebDAV.DAV_NS, WebDAV.XML_MULTI_STATUS, WebDAV.XML_NS_MULTI_STATUS);
    // Send remaining data
    flushXML(xml);
}
Also used : FileInfo(org.alfresco.service.cmr.model.FileInfo) FileNotFoundException(org.alfresco.service.cmr.model.FileNotFoundException) ArrayList(java.util.ArrayList) XMLWriter(org.dom4j.io.XMLWriter)

Example 15 with FileNotFoundException

use of org.alfresco.service.cmr.model.FileNotFoundException in project alfresco-remote-api by Alfresco.

the class PropPatchMethod method executeImpl.

@Override
protected void executeImpl() throws WebDAVServerException, Exception {
    FileInfo pathNodeInfo = null;
    try {
        // Check that the path exists
        pathNodeInfo = getNodeForPath(getRootNodeRef(), m_strPath);
    } catch (FileNotFoundException e) {
        // The path is not valid - send a 404 error back to the client
        throw new WebDAVServerException(HttpServletResponse.SC_NOT_FOUND);
    }
    checkNode(pathNodeInfo);
    // Create the path for the current location in the tree
    StringBuilder baseBuild = new StringBuilder(256);
    baseBuild.append(getPath());
    if (baseBuild.length() == 0 || baseBuild.charAt(baseBuild.length() - 1) != WebDAVHelper.PathSeperatorChar) {
        baseBuild.append(WebDAVHelper.PathSeperatorChar);
    }
    basePath = baseBuild.toString();
    // Build the href string for the current node
    boolean isFolder = pathNodeInfo.isFolder();
    strHRef = getURLForPath(m_request, basePath, isFolder);
    // Do the real work: patch the properties
    patchProperties(pathNodeInfo, basePath);
}
Also used : FileInfo(org.alfresco.service.cmr.model.FileInfo) FileNotFoundException(org.alfresco.service.cmr.model.FileNotFoundException)

Aggregations

FileNotFoundException (org.alfresco.service.cmr.model.FileNotFoundException)31 NodeRef (org.alfresco.service.cmr.repository.NodeRef)23 FileInfo (org.alfresco.service.cmr.model.FileInfo)22 FileFolderService (org.alfresco.service.cmr.model.FileFolderService)7 FileExistsException (org.alfresco.service.cmr.model.FileExistsException)6 ArrayList (java.util.ArrayList)5 AlfrescoRuntimeException (org.alfresco.error.AlfrescoRuntimeException)5 RunAsWork (org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork)5 QName (org.alfresco.service.namespace.QName)4 HashMap (java.util.HashMap)3 List (java.util.List)3 RetryingTransactionCallback (org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback)3 WebDavService (org.alfresco.service.cmr.webdav.WebDavService)3 Date (java.util.Date)2 HashSet (java.util.HashSet)2 LinkedHashSet (java.util.LinkedHashSet)2 Set (java.util.Set)2 StringTokenizer (java.util.StringTokenizer)2 TimerTask (java.util.TimerTask)2 FileContentReader (org.alfresco.repo.content.filestore.FileContentReader)2