Search in sources :

Example 41 with InvalidArgumentException

use of org.alfresco.rest.framework.core.exceptions.InvalidArgumentException in project alfresco-remote-api by Alfresco.

the class NodesImpl method getFolder.

/**
 * @deprecated note: currently required for backwards compat' (Favourites API)
 */
@Override
public Folder getFolder(NodeRef nodeRef) {
    Type type = getType(nodeRef);
    if ((type != null) && type.equals(Type.FOLDER)) {
        Map<QName, Serializable> properties = nodeService.getProperties(nodeRef);
        Folder folder = new Folder(nodeRef, getParentNodeRef(nodeRef), properties, null, sr);
        setCommonProps(folder, nodeRef, properties);
        return folder;
    } else {
        throw new InvalidArgumentException("Node is not a folder: " + nodeRef.getId());
    }
}
Also used : VersionType(org.alfresco.service.cmr.version.VersionType) ActivityType(org.alfresco.repo.activities.ActivityType) Serializable(java.io.Serializable) InvalidArgumentException(org.alfresco.rest.framework.core.exceptions.InvalidArgumentException) QName(org.alfresco.service.namespace.QName) Folder(org.alfresco.rest.api.model.Folder)

Example 42 with InvalidArgumentException

use of org.alfresco.rest.framework.core.exceptions.InvalidArgumentException in project alfresco-remote-api by Alfresco.

the class NodesImpl method addChildren.

public List<AssocChild> addChildren(String parentNodeId, List<AssocChild> entities) {
    NodeRef parentNodeRef = validateNode(parentNodeId);
    List<AssocChild> result = new ArrayList<>(entities.size());
    for (AssocChild assoc : entities) {
        String childId = assoc.getChildId();
        if (childId == null) {
            throw new InvalidArgumentException("Missing childId");
        }
        QName assocTypeQName = getAssocType(assoc.getAssocType());
        try {
            NodeRef childNodeRef = validateNode(childId);
            String nodeName = (String) nodeService.getProperty(childNodeRef, ContentModel.PROP_NAME);
            QName assocChildQName = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, QName.createValidLocalName(nodeName));
            nodeService.addChild(parentNodeRef, childNodeRef, assocTypeQName, assocChildQName);
        } catch (AssociationExistsException aee) {
            throw new ConstraintViolatedException(aee.getMessage());
        } catch (DuplicateChildNodeNameException dcne) {
            throw new ConstraintViolatedException(dcne.getMessage());
        }
        result.add(assoc);
    }
    return result;
}
Also used : DuplicateChildNodeNameException(org.alfresco.service.cmr.repository.DuplicateChildNodeNameException) NodeRef(org.alfresco.service.cmr.repository.NodeRef) InvalidArgumentException(org.alfresco.rest.framework.core.exceptions.InvalidArgumentException) QName(org.alfresco.service.namespace.QName) AssocChild(org.alfresco.rest.api.model.AssocChild) ArrayList(java.util.ArrayList) AssociationExistsException(org.alfresco.service.cmr.repository.AssociationExistsException) ConstraintViolatedException(org.alfresco.rest.framework.core.exceptions.ConstraintViolatedException)

Example 43 with InvalidArgumentException

use of org.alfresco.rest.framework.core.exceptions.InvalidArgumentException in project alfresco-remote-api by Alfresco.

the class NodesImpl method buildSearchTypesAndIgnoreAspects.

protected Pair<Set<QName>, Set<QName>> buildSearchTypesAndIgnoreAspects(final Parameters parameters) {
    // filters
    Boolean includeFolders = null;
    Boolean includeFiles = null;
    QName filterNodeTypeQName = null;
    // note: for files/folders, include subtypes by default (unless filtering by a specific nodeType - see below)
    boolean filterIncludeSubTypes = true;
    Query q = parameters.getQuery();
    if (q != null) {
        // filtering via "where" clause
        MapBasedQueryWalker propertyWalker = createListChildrenQueryWalker();
        QueryHelper.walk(q, propertyWalker);
        Boolean isFolder = propertyWalker.getProperty(PARAM_ISFOLDER, WhereClauseParser.EQUALS, Boolean.class);
        Boolean isFile = propertyWalker.getProperty(PARAM_ISFILE, WhereClauseParser.EQUALS, Boolean.class);
        if (isFolder != null) {
            includeFolders = isFolder;
        }
        if (isFile != null) {
            includeFiles = isFile;
        }
        if (Boolean.TRUE.equals(includeFiles) && Boolean.TRUE.equals(includeFolders)) {
            throw new InvalidArgumentException("Invalid filter (isFile=true and isFolder=true) - a node cannot be both a file and a folder");
        }
        String nodeTypeStr = propertyWalker.getProperty(PARAM_NODETYPE, WhereClauseParser.EQUALS, String.class);
        if ((nodeTypeStr != null) && (!nodeTypeStr.isEmpty())) {
            if ((isFile != null) || (isFolder != null)) {
                throw new InvalidArgumentException("Invalid filter - nodeType and isFile/isFolder are mutually exclusive");
            }
            Pair<QName, Boolean> pair = parseNodeTypeFilter(nodeTypeStr);
            filterNodeTypeQName = pair.getFirst();
            filterIncludeSubTypes = pair.getSecond();
        }
    }
    if (filterNodeTypeQName == null) {
        if ((includeFiles == null) && (includeFolders == null)) {
            // no additional filtering
            filterNodeTypeQName = ContentModel.TYPE_CMOBJECT;
        } else if ((includeFiles != null) && (includeFolders != null)) {
            if ((!includeFiles) && (!includeFolders)) {
                // no files or folders
                filterNodeTypeQName = ContentModel.TYPE_CMOBJECT;
            }
        } else if ((includeFiles != null) && (!includeFiles)) {
            // no files
            filterNodeTypeQName = ContentModel.TYPE_CMOBJECT;
        } else if ((includeFolders != null) && (!includeFolders)) {
            // no folders
            filterNodeTypeQName = ContentModel.TYPE_CMOBJECT;
        }
    }
    return buildSearchTypesAndIgnoreAspects(filterNodeTypeQName, filterIncludeSubTypes, ignoreQNames, includeFiles, includeFolders);
}
Also used : InvalidArgumentException(org.alfresco.rest.framework.core.exceptions.InvalidArgumentException) Query(org.alfresco.rest.framework.resource.parameters.where.Query) GetChildrenCannedQuery(org.alfresco.repo.node.getchildren.GetChildrenCannedQuery) QName(org.alfresco.service.namespace.QName) MapBasedQueryWalker(org.alfresco.rest.workflow.api.impl.MapBasedQueryWalker) FilterPropBoolean(org.alfresco.repo.node.getchildren.FilterPropBoolean)

Example 44 with InvalidArgumentException

use of org.alfresco.rest.framework.core.exceptions.InvalidArgumentException in project alfresco-remote-api by Alfresco.

the class QuickShareLinksImpl method create.

/**
 * Create quick share.
 * <p>
 * Requires authenticated access.
 *
 * @param nodeIds
 * @param parameters
 * @return
 */
public List<QuickShareLink> create(List<QuickShareLink> nodeIds, Parameters parameters) {
    checkEnabled();
    List<QuickShareLink> result = new ArrayList<>(nodeIds.size());
    List<String> includeParam = parameters != null ? parameters.getInclude() : Collections.<String>emptyList();
    for (QuickShareLink qs : nodeIds) {
        String nodeId = qs.getNodeId();
        if (nodeId == null) {
            throw new InvalidArgumentException("A valid nodeId must be specified !");
        }
        NodeRef nodeRef = new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, nodeId);
        try {
            // Note: will throw InvalidNodeRefException (=> 404) if node does not exist
            String sharedId = (String) nodeService.getProperty(nodeRef, QuickShareModel.PROP_QSHARE_SHAREDID);
            if (sharedId != null) {
                throw new ConstraintViolatedException("sharedId already exists: " + nodeId + " [" + sharedId + "]");
            }
            // Note: since we already check node exists above, we can assume that InvalidNodeRefException (=> 404) here means not content (see type check)
            try {
                QuickShareDTO qsDto = quickShareService.shareContent(nodeRef, qs.getExpiresAt());
                result.add(getQuickShareInfo(qsDto.getId(), false, includeParam));
            } catch (InvalidNodeRefException inre) {
                throw new InvalidArgumentException("Unable to create shared link to non-file content: " + nodeId);
            } catch (QuickShareLinkExpiryActionException ex) {
                throw new InvalidArgumentException(ex.getMessage());
            }
        } catch (AccessDeniedException ade) {
            throw new PermissionDeniedException("Unable to create shared link to node that does not exist: " + nodeId);
        } catch (InvalidNodeRefException inre) {
            logger.warn("Unable to create shared link: [" + nodeRef + "]");
            throw new EntityNotFoundException(nodeId);
        }
    }
    return result;
}
Also used : AccessDeniedException(org.alfresco.repo.security.permissions.AccessDeniedException) ArrayList(java.util.ArrayList) QuickShareLinkExpiryActionException(org.alfresco.repo.quickshare.QuickShareLinkExpiryActionException) EntityNotFoundException(org.alfresco.rest.framework.core.exceptions.EntityNotFoundException) ConstraintViolatedException(org.alfresco.rest.framework.core.exceptions.ConstraintViolatedException) NodeRef(org.alfresco.service.cmr.repository.NodeRef) InvalidArgumentException(org.alfresco.rest.framework.core.exceptions.InvalidArgumentException) QuickShareDTO(org.alfresco.service.cmr.quickshare.QuickShareDTO) InvalidNodeRefException(org.alfresco.service.cmr.repository.InvalidNodeRefException) PermissionDeniedException(org.alfresco.rest.framework.core.exceptions.PermissionDeniedException) QuickShareLink(org.alfresco.rest.api.model.QuickShareLink)

Example 45 with InvalidArgumentException

use of org.alfresco.rest.framework.core.exceptions.InvalidArgumentException in project alfresco-remote-api by Alfresco.

the class RenditionsImpl method getRenditionByName.

protected NodeRef getRenditionByName(NodeRef nodeRef, String renditionId, Parameters parameters) {
    if (nodeRef == null) {
        return null;
    }
    if (StringUtils.isEmpty(renditionId)) {
        throw new InvalidArgumentException("renditionId can't be null or empty.");
    }
    // Thumbnails have a cm: prefix.
    QName renditionQName = QName.resolveToQName(namespaceService, renditionId);
    ChildAssociationRef nodeRefRendition = renditionService.getRenditionByName(nodeRef, renditionQName);
    if (nodeRefRendition == null) {
        return null;
    }
    return tenantService.getName(nodeRef, nodeRefRendition.getChildRef());
}
Also used : InvalidArgumentException(org.alfresco.rest.framework.core.exceptions.InvalidArgumentException) QName(org.alfresco.service.namespace.QName) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef)

Aggregations

InvalidArgumentException (org.alfresco.rest.framework.core.exceptions.InvalidArgumentException)124 NodeRef (org.alfresco.service.cmr.repository.NodeRef)36 QName (org.alfresco.service.namespace.QName)36 EntityNotFoundException (org.alfresco.rest.framework.core.exceptions.EntityNotFoundException)30 ConstraintViolatedException (org.alfresco.rest.framework.core.exceptions.ConstraintViolatedException)22 ArrayList (java.util.ArrayList)21 Test (org.junit.Test)20 PermissionDeniedException (org.alfresco.rest.framework.core.exceptions.PermissionDeniedException)16 Serializable (java.io.Serializable)11 SearchParameters (org.alfresco.service.cmr.search.SearchParameters)11 Paging (org.alfresco.rest.framework.resource.parameters.Paging)10 SortColumn (org.alfresco.rest.framework.resource.parameters.SortColumn)10 ApiException (org.alfresco.rest.framework.core.exceptions.ApiException)9 HashMap (java.util.HashMap)8 HashSet (java.util.HashSet)8 Params (org.alfresco.rest.framework.resource.parameters.Params)8 SiteInfo (org.alfresco.service.cmr.site.SiteInfo)8 NotFoundException (org.alfresco.rest.framework.core.exceptions.NotFoundException)7 Pair (org.alfresco.util.Pair)7 List (java.util.List)6