Search in sources :

Example 31 with InvalidArgumentException

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

the class GroupsImpl method getGroupsSortProp.

private Pair<String, Boolean> getGroupsSortProp(Parameters parameters) {
    Pair<String, Boolean> sortProp;
    List<SortColumn> sortCols = parameters.getSorting();
    if ((sortCols != null) && (sortCols.size() > 0)) {
        if (sortCols.size() > 1) {
            throw new InvalidArgumentException("Multiple sort fields not allowed.");
        }
        SortColumn sortCol = sortCols.get(0);
        String sortPropName = SORT_PARAMS_TO_NAMES.get(sortCol.column);
        if (sortPropName == null) {
            throw new InvalidArgumentException("Invalid sort field: " + sortCol.column);
        }
        sortProp = new Pair<>(sortPropName, (sortCol.asc ? Boolean.TRUE : Boolean.FALSE));
    } else {
        sortProp = getGroupsSortPropDefault();
    }
    return sortProp;
}
Also used : InvalidArgumentException(org.alfresco.rest.framework.core.exceptions.InvalidArgumentException) SortColumn(org.alfresco.rest.framework.resource.parameters.SortColumn)

Example 32 with InvalidArgumentException

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

the class NodesImpl method addTargets.

public List<AssocTarget> addTargets(String sourceNodeId, List<AssocTarget> entities) {
    List<AssocTarget> result = new ArrayList<>(entities.size());
    NodeRef srcNodeRef = validateNode(sourceNodeId);
    for (AssocTarget assoc : entities) {
        String targetNodeId = assoc.getTargetId();
        if (targetNodeId == null) {
            throw new InvalidArgumentException("Missing targetId");
        }
        String assocTypeStr = assoc.getAssocType();
        QName assocTypeQName = getAssocType(assocTypeStr);
        try {
            NodeRef tgtNodeRef = validateNode(targetNodeId);
            nodeAssocService.createAssociation(srcNodeRef, tgtNodeRef, assocTypeQName);
        } catch (AssociationExistsException aee) {
            throw new ConstraintViolatedException("Node association '" + assocTypeStr + "' already exists from " + sourceNodeId + " to " + targetNodeId);
        } catch (IllegalArgumentException iae) {
            // note: for now, we assume it is invalid assocType - alternatively, we could attempt to pre-validate via dictionary.getAssociation
            throw new InvalidArgumentException(sourceNodeId + "," + assocTypeStr + "," + targetNodeId);
        }
        result.add(assoc);
    }
    return result;
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) InvalidArgumentException(org.alfresco.rest.framework.core.exceptions.InvalidArgumentException) QName(org.alfresco.service.namespace.QName) ArrayList(java.util.ArrayList) AssocTarget(org.alfresco.rest.api.model.AssocTarget) AssociationExistsException(org.alfresco.service.cmr.repository.AssociationExistsException) ConstraintViolatedException(org.alfresco.rest.framework.core.exceptions.ConstraintViolatedException)

Example 33 with InvalidArgumentException

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

the class NodesImpl method updateContent.

@Override
public Node updateContent(String fileNodeId, BasicContentInfo contentInfo, InputStream stream, Parameters parameters) {
    if (contentInfo.getMimeType().toLowerCase().startsWith("multipart")) {
        throw new UnsupportedMediaTypeException("Cannot update using " + contentInfo.getMimeType());
    }
    final NodeRef nodeRef = validateNode(fileNodeId);
    if (!nodeMatches(nodeRef, Collections.singleton(ContentModel.TYPE_CONTENT), null, false)) {
        throw new InvalidArgumentException("NodeId of content is expected: " + nodeRef.getId());
    }
    Boolean versionMajor = null;
    String str = parameters.getParameter(PARAM_VERSION_MAJOR);
    if (str != null) {
        versionMajor = Boolean.valueOf(str);
    }
    String versionComment = parameters.getParameter(PARAM_VERSION_COMMENT);
    String fileName = parameters.getParameter(PARAM_NAME);
    if (fileName != null) {
        // optionally rename, before updating the content
        nodeService.setProperty(nodeRef, ContentModel.PROP_NAME, fileName);
    } else {
        fileName = (String) nodeService.getProperty(nodeRef, ContentModel.PROP_NAME);
    }
    return updateExistingFile(null, nodeRef, fileName, contentInfo, stream, parameters, versionMajor, versionComment);
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) InvalidArgumentException(org.alfresco.rest.framework.core.exceptions.InvalidArgumentException) UnsupportedMediaTypeException(org.alfresco.rest.framework.core.exceptions.UnsupportedMediaTypeException) FilterPropBoolean(org.alfresco.repo.node.getchildren.FilterPropBoolean)

Example 34 with InvalidArgumentException

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

the class NodesImpl method parseNodeTypeFilter.

private Pair<QName, Boolean> parseNodeTypeFilter(String nodeTypeStr) {
    // default nodeType filtering is without subTypes (unless nodeType value is suffixed with ' INCLUDESUBTYPES')
    boolean filterIncludeSubTypes = false;
    int idx = nodeTypeStr.lastIndexOf(' ');
    if (idx > 0) {
        String suffix = nodeTypeStr.substring(idx);
        if (suffix.equalsIgnoreCase(" " + PARAM_INCLUDE_SUBTYPES)) {
            filterIncludeSubTypes = true;
            nodeTypeStr = nodeTypeStr.substring(0, idx);
        }
    }
    QName filterNodeTypeQName = createQName(nodeTypeStr);
    if (dictionaryService.getType(filterNodeTypeQName) == null) {
        throw new InvalidArgumentException("Unknown filter nodeType: " + nodeTypeStr);
    }
    return new Pair<>(filterNodeTypeQName, filterIncludeSubTypes);
}
Also used : InvalidArgumentException(org.alfresco.rest.framework.core.exceptions.InvalidArgumentException) QName(org.alfresco.service.namespace.QName) Pair(org.alfresco.util.Pair)

Example 35 with InvalidArgumentException

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

the class NodesImpl method requestRenditions.

private void requestRenditions(List<ThumbnailDefinition> thumbnailDefs, Node fileNode) {
    if (thumbnailDefs != null) {
        ThumbnailRegistry registry = thumbnailService.getThumbnailRegistry();
        for (ThumbnailDefinition thumbnailDef : thumbnailDefs) {
            NodeRef sourceNodeRef = fileNode.getNodeRef();
            String mimeType = fileNode.getContent().getMimeType();
            long size = fileNode.getContent().getSizeInBytes();
            // Check if anything is currently available to generate thumbnails for the specified mimeType
            if (!registry.isThumbnailDefinitionAvailable(null, mimeType, size, sourceNodeRef, thumbnailDef)) {
                throw new InvalidArgumentException("Unable to create thumbnail '" + thumbnailDef.getName() + "' for " + mimeType + " as no transformer is currently available.");
            }
            Action action = ThumbnailHelper.createCreateThumbnailAction(thumbnailDef, sr);
            // Queue async creation of thumbnail
            actionService.executeAction(action, sourceNodeRef, true, true);
        }
    }
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) ThumbnailDefinition(org.alfresco.repo.thumbnail.ThumbnailDefinition) Action(org.alfresco.service.cmr.action.Action) InvalidArgumentException(org.alfresco.rest.framework.core.exceptions.InvalidArgumentException) ThumbnailRegistry(org.alfresco.repo.thumbnail.ThumbnailRegistry)

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