Search in sources :

Example 1 with ActivityInfo

use of org.alfresco.service.cmr.activities.ActivityInfo in project alfresco-remote-api by Alfresco.

the class NodesImpl method updateExistingFile.

private Node updateExistingFile(NodeRef parentNodeRef, NodeRef nodeRef, String fileName, BasicContentInfo contentInfo, InputStream stream, Parameters parameters, Boolean versionMajor, String versionComment) {
    boolean isVersioned = versionService.isVersioned(nodeRef);
    behaviourFilter.disableBehaviour(nodeRef, ContentModel.ASPECT_VERSIONABLE);
    try {
        writeContent(nodeRef, fileName, stream, true);
        if ((isVersioned) || (versionMajor != null) || (versionComment != null)) {
            VersionType versionType = null;
            if (versionMajor != null) {
                versionType = (versionMajor ? VersionType.MAJOR : VersionType.MINOR);
            } else {
                // note: it is possible to have versionable aspect but no versions (=> no version label)
                if ((!isVersioned) || (nodeService.getProperty(nodeRef, ContentModel.PROP_VERSION_LABEL) == null)) {
                    versionType = VersionType.MAJOR;
                } else {
                    versionType = VersionType.MINOR;
                }
            }
            createVersion(nodeRef, isVersioned, versionType, versionComment);
        }
        ActivityInfo activityInfo = getActivityInfo(parentNodeRef, nodeRef);
        postActivity(Activity_Type.UPDATED, activityInfo, false);
        extractMetadata(nodeRef);
    } finally {
        behaviourFilter.enableBehaviour(nodeRef, ContentModel.ASPECT_VERSIONABLE);
    }
    return getFolderOrDocumentFullInfo(nodeRef, null, null, parameters);
}
Also used : ActivityInfo(org.alfresco.service.cmr.activities.ActivityInfo) VersionType(org.alfresco.service.cmr.version.VersionType)

Example 2 with ActivityInfo

use of org.alfresco.service.cmr.activities.ActivityInfo in project alfresco-remote-api by Alfresco.

the class NodesImpl method createNodeImpl.

private NodeRef createNodeImpl(NodeRef parentNodeRef, String nodeName, QName nodeTypeQName, Map<QName, Serializable> props, QName assocTypeQName) {
    NodeRef newNode = null;
    if (props == null) {
        props = new HashMap<>(1);
    }
    props.put(ContentModel.PROP_NAME, nodeName);
    validatePropValues(props);
    QName assocQName = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, QName.createValidLocalName(nodeName));
    try {
        newNode = nodeService.createNode(parentNodeRef, assocTypeQName, assocQName, nodeTypeQName, props).getChildRef();
    } catch (DuplicateChildNodeNameException dcne) {
        // duplicate - name clash
        throw new ConstraintViolatedException(dcne.getMessage());
    }
    ActivityInfo activityInfo = getActivityInfo(parentNodeRef, newNode);
    postActivity(Activity_Type.ADDED, activityInfo, false);
    return newNode;
}
Also used : DuplicateChildNodeNameException(org.alfresco.service.cmr.repository.DuplicateChildNodeNameException) NodeRef(org.alfresco.service.cmr.repository.NodeRef) ActivityInfo(org.alfresco.service.cmr.activities.ActivityInfo) QName(org.alfresco.service.namespace.QName) ConstraintViolatedException(org.alfresco.rest.framework.core.exceptions.ConstraintViolatedException)

Example 3 with ActivityInfo

use of org.alfresco.service.cmr.activities.ActivityInfo 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)

Example 4 with ActivityInfo

use of org.alfresco.service.cmr.activities.ActivityInfo in project alfresco-remote-api by Alfresco.

the class NodesImpl method getContent.

@Override
public BinaryResource getContent(NodeRef nodeRef, Parameters parameters, boolean recordActivity) {
    if (!nodeMatches(nodeRef, Collections.singleton(ContentModel.TYPE_CONTENT), null, false)) {
        throw new InvalidArgumentException("NodeId of content is expected: " + nodeRef.getId());
    }
    Map<QName, Serializable> nodeProps = nodeService.getProperties(nodeRef);
    ContentData cd = (ContentData) nodeProps.get(ContentModel.PROP_CONTENT);
    String name = (String) nodeProps.get(ContentModel.PROP_NAME);
    org.alfresco.rest.framework.resource.content.ContentInfo ci = null;
    String mimeType = null;
    if (cd != null) {
        mimeType = cd.getMimetype();
        ci = new org.alfresco.rest.framework.resource.content.ContentInfoImpl(mimeType, cd.getEncoding(), cd.getSize(), cd.getLocale());
    }
    // By default set attachment header (with filename) unless attachment=false *and* content type is pre-configured as non-attach
    boolean attach = true;
    String attachment = parameters.getParameter("attachment");
    if (attachment != null) {
        Boolean a = Boolean.valueOf(attachment);
        if (!a) {
            if (nonAttachContentTypes.contains(mimeType)) {
                attach = false;
            } else {
                logger.warn("Ignored attachment=false for " + nodeRef.getId() + " since " + mimeType + " is not in the whitelist for non-attach content types");
            }
        }
    }
    String attachFileName = (attach ? name : null);
    if (recordActivity) {
        final ActivityInfo activityInfo = getActivityInfo(getParentNodeRef(nodeRef), nodeRef);
        postActivity(Activity_Type.DOWNLOADED, activityInfo, true);
    }
    return new NodeBinaryResource(nodeRef, ContentModel.PROP_CONTENT, ci, attachFileName);
}
Also used : ActivityInfo(org.alfresco.service.cmr.activities.ActivityInfo) Serializable(java.io.Serializable) QName(org.alfresco.service.namespace.QName) ContentInfoImpl(org.alfresco.rest.framework.resource.content.ContentInfoImpl) NodeBinaryResource(org.alfresco.rest.framework.resource.content.NodeBinaryResource) InvalidArgumentException(org.alfresco.rest.framework.core.exceptions.InvalidArgumentException) ContentData(org.alfresco.service.cmr.repository.ContentData) FilterPropBoolean(org.alfresco.repo.node.getchildren.FilterPropBoolean)

Example 5 with ActivityInfo

use of org.alfresco.service.cmr.activities.ActivityInfo in project alfresco-remote-api by Alfresco.

the class NodesImpl method deleteNode.

@Override
public void deleteNode(String nodeId, Parameters parameters) {
    NodeRef nodeRef = validateOrLookupNode(nodeId, null);
    if (isSpecialNode(nodeRef, getNodeType(nodeRef))) {
        throw new PermissionDeniedException("Cannot delete: " + nodeId);
    }
    // default false (if not provided)
    boolean permanentDelete = Boolean.valueOf(parameters.getParameter(PARAM_PERMANENT));
    if (permanentDelete == true) {
        boolean isAdmin = authorityService.hasAdminAuthority();
        if (!isAdmin) {
            String owner = ownableService.getOwner(nodeRef);
            if (!AuthenticationUtil.getRunAsUser().equals(owner)) {
                // non-owner/non-admin cannot permanently delete (even if they have delete permission)
                throw new PermissionDeniedException("Non-owner/non-admin cannot permanently delete: " + nodeId);
            }
        }
        // Set as temporary to delete node instead of archiving.
        nodeService.addAspect(nodeRef, ContentModel.ASPECT_TEMPORARY, null);
    }
    final ActivityInfo activityInfo = getActivityInfo(getParentNodeRef(nodeRef), nodeRef);
    postActivity(Activity_Type.DELETED, activityInfo, true);
    fileFolderService.delete(nodeRef);
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) ActivityInfo(org.alfresco.service.cmr.activities.ActivityInfo) PermissionDeniedException(org.alfresco.rest.framework.core.exceptions.PermissionDeniedException)

Aggregations

ActivityInfo (org.alfresco.service.cmr.activities.ActivityInfo)6 ConstraintViolatedException (org.alfresco.rest.framework.core.exceptions.ConstraintViolatedException)2 InvalidArgumentException (org.alfresco.rest.framework.core.exceptions.InvalidArgumentException)2 PermissionDeniedException (org.alfresco.rest.framework.core.exceptions.PermissionDeniedException)2 DuplicateChildNodeNameException (org.alfresco.service.cmr.repository.DuplicateChildNodeNameException)2 NodeRef (org.alfresco.service.cmr.repository.NodeRef)2 QName (org.alfresco.service.namespace.QName)2 IOException (java.io.IOException)1 Serializable (java.io.Serializable)1 ContentLimitViolationException (org.alfresco.repo.content.ContentLimitViolationException)1 FilterPropBoolean (org.alfresco.repo.node.getchildren.FilterPropBoolean)1 IntegrityException (org.alfresco.repo.node.integrity.IntegrityException)1 AccessDeniedException (org.alfresco.repo.security.permissions.AccessDeniedException)1 ApiException (org.alfresco.rest.framework.core.exceptions.ApiException)1 DisabledServiceException (org.alfresco.rest.framework.core.exceptions.DisabledServiceException)1 EntityNotFoundException (org.alfresco.rest.framework.core.exceptions.EntityNotFoundException)1 InsufficientStorageException (org.alfresco.rest.framework.core.exceptions.InsufficientStorageException)1 NotFoundException (org.alfresco.rest.framework.core.exceptions.NotFoundException)1 RequestEntityTooLargeException (org.alfresco.rest.framework.core.exceptions.RequestEntityTooLargeException)1 UnsupportedMediaTypeException (org.alfresco.rest.framework.core.exceptions.UnsupportedMediaTypeException)1