Search in sources :

Example 36 with InvalidArgumentException

use of org.alfresco.rest.framework.core.exceptions.InvalidArgumentException 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 37 with InvalidArgumentException

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

the class NodesImpl method mapToNodeAspects.

public Set<QName> mapToNodeAspects(List<String> aspectNames) {
    Set<QName> nodeAspects = new HashSet<>(aspectNames.size());
    for (String aspectName : aspectNames) {
        QName aspectQName = createQName(aspectName);
        AspectDefinition ad = dictionaryService.getAspect(aspectQName);
        if (ad != null) {
            nodeAspects.add(aspectQName);
        } else {
            throw new InvalidArgumentException("Unknown aspect: " + aspectName);
        }
    }
    return nodeAspects;
}
Also used : InvalidArgumentException(org.alfresco.rest.framework.core.exceptions.InvalidArgumentException) QName(org.alfresco.service.namespace.QName) AspectDefinition(org.alfresco.service.cmr.dictionary.AspectDefinition) LinkedHashSet(java.util.LinkedHashSet) HashSet(java.util.HashSet)

Example 38 with InvalidArgumentException

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

the class NodesImpl method mapToNodeProperties.

public Map<QName, Serializable> mapToNodeProperties(Map<String, Object> props) {
    Map<QName, Serializable> nodeProps = new HashMap<>(props.size());
    for (Entry<String, Object> entry : props.entrySet()) {
        String propName = entry.getKey();
        QName propQName = createQName(propName);
        PropertyDefinition pd = dictionaryService.getProperty(propQName);
        if (pd != null) {
            Serializable value = null;
            if (entry.getValue() != null) {
                if (pd.getDataType().getName().equals(DataTypeDefinition.NODE_REF)) {
                    String nodeRefString = (String) entry.getValue();
                    if (!NodeRef.isNodeRef(nodeRefString)) {
                        value = new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, nodeRefString);
                    } else {
                        value = new NodeRef(nodeRefString);
                    }
                } else {
                    value = (Serializable) entry.getValue();
                }
            }
            nodeProps.put(propQName, value);
        } else {
            throw new InvalidArgumentException("Unknown property: " + propName);
        }
    }
    return nodeProps;
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) Serializable(java.io.Serializable) InvalidArgumentException(org.alfresco.rest.framework.core.exceptions.InvalidArgumentException) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) QName(org.alfresco.service.namespace.QName) PropertyDefinition(org.alfresco.service.cmr.dictionary.PropertyDefinition)

Example 39 with InvalidArgumentException

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

the class NodesImpl method getDocument.

/**
 * @deprecated note: currently required for backwards compat' (Favourites API)
 */
@Override
public Document getDocument(NodeRef nodeRef) {
    Type type = getType(nodeRef);
    if ((type != null) && type.equals(Type.DOCUMENT)) {
        Map<QName, Serializable> properties = nodeService.getProperties(nodeRef);
        Document doc = new Document(nodeRef, getParentNodeRef(nodeRef), properties, null, sr);
        doc.setVersionLabel((String) properties.get(ContentModel.PROP_VERSION_LABEL));
        ContentData cd = (ContentData) properties.get(ContentModel.PROP_CONTENT);
        if (cd != null) {
            doc.setSizeInBytes(BigInteger.valueOf(cd.getSize()));
            doc.setMimeType((cd.getMimetype()));
        }
        setCommonProps(doc, nodeRef, properties);
        return doc;
    } else {
        throw new InvalidArgumentException("Node is not a file: " + nodeRef.getId());
    }
}
Also used : VersionType(org.alfresco.service.cmr.version.VersionType) ActivityType(org.alfresco.repo.activities.ActivityType) Serializable(java.io.Serializable) ContentData(org.alfresco.service.cmr.repository.ContentData) InvalidArgumentException(org.alfresco.rest.framework.core.exceptions.InvalidArgumentException) QName(org.alfresco.service.namespace.QName) Document(org.alfresco.rest.api.model.Document)

Example 40 with InvalidArgumentException

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

the class NodesImpl method moveOrCopyNode.

@Override
public Node moveOrCopyNode(String sourceNodeId, String targetParentId, String name, Parameters parameters, boolean isCopy) {
    if ((sourceNodeId == null) || (sourceNodeId.isEmpty())) {
        throw new InvalidArgumentException("Missing sourceNodeId");
    }
    if ((targetParentId == null) || (targetParentId.isEmpty())) {
        throw new InvalidArgumentException("Missing targetParentId");
    }
    final NodeRef parentNodeRef = validateOrLookupNode(targetParentId, null);
    final NodeRef sourceNodeRef = validateOrLookupNode(sourceNodeId, null);
    FileInfo fi = moveOrCopyImpl(sourceNodeRef, parentNodeRef, name, isCopy);
    return getFolderOrDocument(fi.getNodeRef().getId(), parameters);
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) InvalidArgumentException(org.alfresco.rest.framework.core.exceptions.InvalidArgumentException) FileInfo(org.alfresco.service.cmr.model.FileInfo)

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