Search in sources :

Example 16 with FileInfo

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

the class UnlockMethod method attemptUnlock.

/**
 * The main unlock implementation.
 *
 * @throws WebDAVServerException
 */
protected void attemptUnlock() throws WebDAVServerException {
    if (logger.isDebugEnabled()) {
        logger.debug("Unlock node; path=" + getPath() + ", token=" + getLockToken());
    }
    FileInfo lockNodeInfo = null;
    try {
        lockNodeInfo = getNodeForPath(getRootNodeRef(), getPath());
    } catch (FileNotFoundException e) {
        throw new WebDAVServerException(HttpServletResponse.SC_NOT_FOUND);
    }
    // Parse the lock token
    String[] lockInfoFromRequest = WebDAV.parseLockToken(getLockToken());
    if (lockInfoFromRequest == null) {
        // Bad lock token
        throw new WebDAVServerException(HttpServletResponse.SC_PRECONDITION_FAILED);
    }
    NodeRef nodeRef = lockNodeInfo.getNodeRef();
    LockInfo lockInfo = getDAVLockService().getLockInfo(nodeRef);
    if (lockInfo == null) {
        if (logger.isDebugEnabled()) {
            logger.debug("Unlock token=" + getLockToken() + " Not locked - no info in lock store.");
        }
        // Node is not locked
        throw new WebDAVServerException(HttpServletResponse.SC_PRECONDITION_FAILED);
    }
    if (!lockInfo.isLocked()) {
        if (logger.isDebugEnabled()) {
            logger.debug("Unlock token=" + getLockToken() + " Not locked");
        }
        // Node is not locked
        throw new WebDAVServerException(HttpServletResponse.SC_PRECONDITION_FAILED);
    } else if (lockInfo.isExpired()) {
        if (logger.isDebugEnabled()) {
            logger.debug("Unlock token=" + getLockToken() + " Lock expired");
        }
        // Return a success status
        m_response.setStatus(HttpServletResponse.SC_NO_CONTENT);
        removeNoContentAspect(nodeRef);
    } else if (lockInfo.isExclusive()) {
        String currentUser = getAuthenticationService().getCurrentUserName();
        if (currentUser.equals(lockInfo.getOwner())) {
            try {
                getDAVLockService().unlock(nodeRef);
            } catch (UnableToReleaseLockException e) {
                throw new WebDAVServerException(HttpServletResponse.SC_PRECONDITION_FAILED, e);
            }
            // Indicate that the unlock was successful
            m_response.setStatus(HttpServletResponse.SC_NO_CONTENT);
            removeNoContentAspect(nodeRef);
            if (logger.isDebugEnabled()) {
                logger.debug("Unlock token=" + getLockToken() + " Successful");
            }
        } else {
            if (logger.isDebugEnabled()) {
                logger.debug("Unlock token=" + getLockToken() + " Not lock owner");
            }
            // Node is not locked
            throw new WebDAVServerException(HttpServletResponse.SC_PRECONDITION_FAILED);
        }
    } else if (lockInfo.isShared()) {
        Set<String> sharedLocks = lockInfo.getSharedLockTokens();
        if (sharedLocks.contains(m_strLockToken)) {
            sharedLocks.remove(m_strLockToken);
            // Indicate that the unlock was successful
            m_response.setStatus(HttpServletResponse.SC_NO_CONTENT);
            removeNoContentAspect(nodeRef);
            // DEBUG
            if (logger.isDebugEnabled()) {
                logger.debug("Unlock token=" + getLockToken() + " Successful");
            }
        }
    } else {
        throw new IllegalStateException("Invalid LockInfo state: " + lockInfo);
    }
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) Set(java.util.Set) FileInfo(org.alfresco.service.cmr.model.FileInfo) FileNotFoundException(org.alfresco.service.cmr.model.FileNotFoundException) UnableToReleaseLockException(org.alfresco.service.cmr.lock.UnableToReleaseLockException)

Example 17 with FileInfo

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

the class WebDAVHelper method getNodeForPath.

/**
 * Get the file info for the given paths
 *
 * @param rootNodeRef       the acting webdav root
 * @param path              the path to search for
 * @return                  Return the file info for the path
 * @throws FileNotFoundException
 *                          if the path doesn't refer to a valid node
 */
public FileInfo getNodeForPath(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");
    }
    FileFolderService fileFolderService = getFileFolderService();
    // Check for the root path
    if (path.length() == 0 || path.equals(PathSeperator)) {
        return fileFolderService.getFileInfo(rootNodeRef);
    }
    // split the paths up
    List<String> splitPath = splitAllPaths(path);
    // find it
    FileInfo fileInfo = m_fileFolderService.resolveNamePath(rootNodeRef, splitPath);
    String fileName = splitPath.get(splitPath.size() - 1);
    if (!fileInfo.getName().equals(fileName)) {
        throw new FileNotFoundException("Requested filename " + fileName + " does not match case of " + fileInfo.getName());
    }
    // done
    if (logger.isDebugEnabled()) {
        logger.debug("Fetched node for path: \n" + "   root: " + rootNodeRef + "\n" + "   path: " + path + "\n" + "   result: " + fileInfo);
    }
    return fileInfo;
}
Also used : FileInfo(org.alfresco.service.cmr.model.FileInfo) FileNotFoundException(org.alfresco.service.cmr.model.FileNotFoundException) FileFolderService(org.alfresco.service.cmr.model.FileFolderService)

Example 18 with FileInfo

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

the class WebDAVMethod method getWorkingCopy.

/**
 * Returns a working copy of node for current user.
 *
 * @param nodeRef node reference
 * @return Returns the working copy's file information
 */
protected FileInfo getWorkingCopy(NodeRef nodeRef) {
    FileInfo result = null;
    NodeRef workingCopy = getServiceRegistry().getCheckOutCheckInService().getWorkingCopy(nodeRef);
    if (workingCopy != null) {
        String workingCopyOwner = getNodeService().getProperty(workingCopy, ContentModel.PROP_WORKING_COPY_OWNER).toString();
        if (workingCopyOwner.equals(getAuthenticationService().getCurrentUserName())) {
            result = getFileFolderService().getFileInfo(workingCopy);
        }
    }
    return result;
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) FileInfo(org.alfresco.service.cmr.model.FileInfo)

Example 19 with FileInfo

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

the class NodesImpl method resolveNodeByPath.

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();
}
Also used : AccessDeniedException(org.alfresco.repo.security.permissions.AccessDeniedException) FileInfo(org.alfresco.service.cmr.model.FileInfo) FileNotFoundException(org.alfresco.service.cmr.model.FileNotFoundException) NotFoundException(org.alfresco.rest.framework.core.exceptions.NotFoundException) FileNotFoundException(org.alfresco.service.cmr.model.FileNotFoundException) EntityNotFoundException(org.alfresco.rest.framework.core.exceptions.EntityNotFoundException) EntityNotFoundException(org.alfresco.rest.framework.core.exceptions.EntityNotFoundException)

Example 20 with FileInfo

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

the class NodesImpl method getActivityInfo.

// note: see also org.alfresco.opencmis.ActivityPosterImpl
protected ActivityInfo getActivityInfo(NodeRef parentNodeRef, NodeRef nodeRef) {
    // runAs system, eg. user may not have permission see one or more parents (irrespective of whether in a site context of not)
    SiteInfo siteInfo = AuthenticationUtil.runAs(new RunAsWork<SiteInfo>() {

        @Override
        public SiteInfo doWork() throws Exception {
            return siteService.getSite(nodeRef);
        }
    }, AuthenticationUtil.getSystemUserName());
    String siteId = (siteInfo != null ? siteInfo.getShortName() : null);
    if (siteId != null && !siteId.equals("")) {
        FileInfo fileInfo = fileFolderService.getFileInfo(nodeRef);
        if (fileInfo != null) {
            boolean isContent = isSubClass(fileInfo.getType(), ContentModel.TYPE_CONTENT);
            if (fileInfo.isFolder() || isContent) {
                return new ActivityInfo(null, parentNodeRef, siteId, fileInfo);
            }
        }
    } else {
        if (logger.isDebugEnabled()) {
            logger.debug("Non-site activity, so ignored " + nodeRef);
        }
    }
    return null;
}
Also used : SiteInfo(org.alfresco.service.cmr.site.SiteInfo) ActivityInfo(org.alfresco.service.cmr.activities.ActivityInfo) FileInfo(org.alfresco.service.cmr.model.FileInfo) FileExistsException(org.alfresco.service.cmr.model.FileExistsException) PermissionDeniedException(org.alfresco.rest.framework.core.exceptions.PermissionDeniedException) AccessDeniedException(org.alfresco.repo.security.permissions.AccessDeniedException) DuplicateChildNodeNameException(org.alfresco.service.cmr.repository.DuplicateChildNodeNameException) NotFoundException(org.alfresco.rest.framework.core.exceptions.NotFoundException) ConcurrencyFailureException(org.springframework.dao.ConcurrencyFailureException) ConstraintViolatedException(org.alfresco.rest.framework.core.exceptions.ConstraintViolatedException) ApiException(org.alfresco.rest.framework.core.exceptions.ApiException) IntegrityException(org.alfresco.repo.node.integrity.IntegrityException) IOException(java.io.IOException) RequestEntityTooLargeException(org.alfresco.rest.framework.core.exceptions.RequestEntityTooLargeException) DisabledServiceException(org.alfresco.rest.framework.core.exceptions.DisabledServiceException) InvalidArgumentException(org.alfresco.rest.framework.core.exceptions.InvalidArgumentException) FileNotFoundException(org.alfresco.service.cmr.model.FileNotFoundException) ContentQuotaException(org.alfresco.service.cmr.usage.ContentQuotaException) UnsupportedMediaTypeException(org.alfresco.rest.framework.core.exceptions.UnsupportedMediaTypeException) AssociationExistsException(org.alfresco.service.cmr.repository.AssociationExistsException) InsufficientStorageException(org.alfresco.rest.framework.core.exceptions.InsufficientStorageException) EntityNotFoundException(org.alfresco.rest.framework.core.exceptions.EntityNotFoundException) InvalidNodeRefException(org.alfresco.service.cmr.repository.InvalidNodeRefException) NodeLockedException(org.alfresco.service.cmr.lock.NodeLockedException) ContentIOException(org.alfresco.service.cmr.repository.ContentIOException) ContentLimitViolationException(org.alfresco.repo.content.ContentLimitViolationException)

Aggregations

FileInfo (org.alfresco.service.cmr.model.FileInfo)101 NodeRef (org.alfresco.service.cmr.repository.NodeRef)82 WebApiDescription (org.alfresco.rest.framework.WebApiDescription)34 FileNotFoundException (org.alfresco.service.cmr.model.FileNotFoundException)26 HashMap (java.util.HashMap)20 RetryingTransactionCallback (org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback)20 QName (org.alfresco.service.namespace.QName)20 AbstractList (java.util.AbstractList)13 UserInfo (org.alfresco.rest.api.model.UserInfo)13 WebApiParam (org.alfresco.rest.framework.WebApiParam)11 Test (org.junit.Test)11 ArrayList (java.util.ArrayList)10 AccessDeniedException (org.alfresco.repo.security.permissions.AccessDeniedException)10 FileFolderService (org.alfresco.service.cmr.model.FileFolderService)9 IOException (java.io.IOException)8 EntityNotFoundException (org.alfresco.rest.framework.core.exceptions.EntityNotFoundException)8 Serializable (java.io.Serializable)7 List (java.util.List)7 ContentWriter (org.alfresco.service.cmr.repository.ContentWriter)7 FacesContext (javax.faces.context.FacesContext)6