Search in sources :

Example 71 with InvalidArgumentException

use of org.alfresco.rest.framework.core.exceptions.InvalidArgumentException in project records-management by Alfresco.

the class RMSitesImpl method validateSite.

/**
 * Even if the method it will be protected in core, we still need to override since we don't need to check if the visibility is set since for RM site it is always PUBLIC.
 * We also don't need to generate the id from title, or to check the id, since the id is always rm.
 * @param site
 * @return
 */
@Override
protected Site validateSite(Site site) {
    // site title - mandatory
    String siteTitle = site.getTitle();
    if ((siteTitle == null) || siteTitle.isEmpty()) {
        throw new InvalidArgumentException("Site title is expected: " + siteTitle);
    } else if (siteTitle.length() > SITE_MAXLEN_TITLE) {
        throw new InvalidArgumentException("Site title exceeds max length of " + SITE_MAXLEN_TITLE + " characters");
    }
    String siteDescription = site.getDescription();
    if (siteDescription == null) {
        // workaround: to avoid Share error (eg. in My Sites dashlet / freemarker template)
        site.setDescription("");
    }
    if ((siteDescription != null) && (siteDescription.length() > SITE_MAXLEN_DESCRIPTION)) {
        throw new InvalidArgumentException("Site description exceeds max length of " + SITE_MAXLEN_DESCRIPTION + " characters");
    }
    return site;
}
Also used : InvalidArgumentException(org.alfresco.rest.framework.core.exceptions.InvalidArgumentException)

Example 72 with InvalidArgumentException

use of org.alfresco.rest.framework.core.exceptions.InvalidArgumentException in project records-management by Alfresco.

the class FilePlanComponentsApiUtils method createRMNode.

/**
 * Create an RM node
 *
 * @param parentNodeRef  the parent of the node
 * @param nodeInfo  the node infos to create
 * @param parameters  the object to get the parameters passed into the request
 * @return the new node
 */
public NodeRef createRMNode(NodeRef parentNodeRef, RMNode nodeInfo, Parameters parameters) {
    mandatory("parentNodeRef", parentNodeRef);
    mandatory("nodeInfo", nodeInfo);
    mandatory("parameters", parameters);
    String nodeName = nodeInfo.getName();
    String nodeType = nodeInfo.getNodeType();
    checkNotBlank(RMNode.PARAM_NAME, nodeName);
    checkNotBlank(RMNode.PARAM_NODE_TYPE, nodeType);
    // Create the node
    NodeRef newNodeRef = null;
    boolean autoRename = Boolean.valueOf(parameters.getParameter(RMNode.PARAM_AUTO_RENAME));
    try {
        QName typeQName = nodes.createQName(nodeType);
        // Existing file/folder name handling
        if (autoRename) {
            NodeRef existingNode = nodeService.getChildByName(parentNodeRef, ContentModel.ASSOC_CONTAINS, nodeName);
            if (existingNode != null) {
                // File already exists, find a unique name
                nodeName = findUniqueName(parentNodeRef, nodeName);
            }
        }
        newNodeRef = fileFolderService.create(parentNodeRef, nodeName, typeQName).getNodeRef();
        // Set the provided properties if any
        Map<QName, Serializable> qnameProperties = mapToNodeProperties(nodeInfo.getProperties());
        if (qnameProperties != null) {
            nodeService.addProperties(newNodeRef, qnameProperties);
        }
        // If electronic record create empty content
        if (!typeQName.equals(RecordsManagementModel.TYPE_NON_ELECTRONIC_DOCUMENT) && dictionaryService.isSubClass(typeQName, ContentModel.TYPE_CONTENT)) {
            writeContent(newNodeRef, nodeName, new ByteArrayInputStream("".getBytes()), false);
        }
        // Add the provided aspects if any
        List<String> aspectNames = nodeInfo.getAspectNames();
        if (aspectNames != null) {
            nodes.addCustomAspects(newNodeRef, aspectNames, ApiNodesModelFactory.EXCLUDED_ASPECTS);
        }
    } catch (InvalidTypeException ex) {
        throw new InvalidArgumentException("The given type:'" + nodeType + "' is invalid '");
    } catch (DuplicateAttributeException ex) {
        // This exception can occur when setting a custom identifier that already exists
        throw new IntegrityException(ex.getMessage(), null);
    }
    return newNodeRef;
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) Serializable(java.io.Serializable) InvalidArgumentException(org.alfresco.rest.framework.core.exceptions.InvalidArgumentException) ByteArrayInputStream(java.io.ByteArrayInputStream) QName(org.alfresco.service.namespace.QName) IntegrityException(org.alfresco.repo.node.integrity.IntegrityException) DuplicateAttributeException(org.alfresco.service.cmr.attributes.DuplicateAttributeException) InvalidTypeException(org.alfresco.repo.model.filefolder.FileFolderServiceImpl.InvalidTypeException)

Example 73 with InvalidArgumentException

use of org.alfresco.rest.framework.core.exceptions.InvalidArgumentException in project records-management by Alfresco.

the class FilePlanComponentsApiUtils method lookupAndValidateNodeType.

/**
 * lookup node by id and relative path and validate type
 *
 * @param nodeId
 * @param expectedNodeType
 * @param relativePath
 * @return
 * @throws EntityNotFoundException
 */
public NodeRef lookupAndValidateNodeType(String nodeId, QName expectedNodeType, String relativePath, boolean readOnlyRelativePath) throws EntityNotFoundException {
    ParameterCheck.mandatoryString("nodeId", nodeId);
    ParameterCheck.mandatory("expectedNodeType", expectedNodeType);
    NodeRef nodeRef = lookupByPlaceholder(nodeId);
    QName nodeType = nodeService.getType(nodeRef);
    if (!nodeType.equals(expectedNodeType)) {
        throw new InvalidArgumentException("The given id:'" + nodeId + "' (nodeType:" + nodeType.toString() + ") is not valid for this endpoint. Expected nodeType is:" + expectedNodeType.toString());
    }
    if (StringUtils.isNotBlank(relativePath)) {
        nodeRef = lookupAndValidateRelativePath(nodeRef, relativePath, readOnlyRelativePath, expectedNodeType);
    }
    return nodeRef;
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) InvalidArgumentException(org.alfresco.rest.framework.core.exceptions.InvalidArgumentException) QName(org.alfresco.service.namespace.QName)

Example 74 with InvalidArgumentException

use of org.alfresco.rest.framework.core.exceptions.InvalidArgumentException in project records-management by Alfresco.

the class SearchTypesFactory method buildSearchTypesCategoriesEndpoint.

/**
 * Helper method to build search types for categories endpoint
 * @param parameters
 * @param listRecordCategoryChildrenEqualsQueryProperties
 * @return
 */
public Set<QName> buildSearchTypesCategoriesEndpoint(Parameters parameters, Set<String> listRecordCategoryChildrenEqualsQueryProperties) {
    Set<QName> searchTypeQNames = new HashSet<>();
    Query q = parameters.getQuery();
    boolean includeRecordFolders = false;
    boolean includeRecordCategories = false;
    if (q != null) {
        // filtering via "where" clause
        MapBasedQueryWalker propertyWalker = new MapBasedQueryWalker(listRecordCategoryChildrenEqualsQueryProperties, null);
        QueryHelper.walk(q, propertyWalker);
        Boolean isRecordFolder = propertyWalker.getProperty(RecordCategoryChild.PARAM_IS_RECORD_FOLDER, WhereClauseParser.EQUALS, Boolean.class);
        Boolean isRecordCategory = propertyWalker.getProperty(RecordCategoryChild.PARAM_IS_RECORD_CATEGORY, WhereClauseParser.EQUALS, Boolean.class);
        if ((isRecordFolder != null && isRecordFolder.booleanValue()) || (isRecordCategory != null && !isRecordCategory.booleanValue())) {
            includeRecordFolders = true;
        } else if ((isRecordFolder != null && !isRecordFolder.booleanValue()) || (isRecordCategory != null && isRecordCategory.booleanValue())) {
            includeRecordCategories = true;
        }
        String nodeTypeQNameStr = propertyWalker.getProperty(RecordCategoryChild.PARAM_NODE_TYPE, WhereClauseParser.EQUALS, String.class);
        QName filterNodeTypeQName;
        if (nodeTypeQNameStr != null) {
            if ((isRecordFolder != null) || (isRecordCategory != null)) {
                throw new InvalidArgumentException("Invalid filter - nodeType and isRecordFolder/isRecordCategory are mutually exclusive");
            }
            Pair<QName, Boolean> pair = parseNodeTypeFilter(nodeTypeQNameStr);
            filterNodeTypeQName = pair.getFirst();
            if (nodeTypeQNameStr.equals(RecordsManagementModel.TYPE_RECORD_FOLDER)) {
                includeRecordFolders = true;
            } else if (filterNodeTypeQName.equals(RecordsManagementModel.TYPE_RECORD_CATEGORY)) {
                includeRecordCategories = true;
            } else {
                throw new InvalidParameterException("Filter nodeType: " + nodeTypeQNameStr + " is invalid for this endpoint");
            }
        }
    } else {
        includeRecordCategories = true;
        includeRecordFolders = true;
    }
    if (includeRecordFolders) {
        searchTypeQNames.add(RecordsManagementModel.TYPE_RECORD_FOLDER);
    }
    if (includeRecordCategories) {
        searchTypeQNames.add(RecordsManagementModel.TYPE_RECORD_CATEGORY);
    }
    return searchTypeQNames;
}
Also used : InvalidParameterException(java.security.InvalidParameterException) InvalidArgumentException(org.alfresco.rest.framework.core.exceptions.InvalidArgumentException) Query(org.alfresco.rest.framework.resource.parameters.where.Query) QName(org.alfresco.service.namespace.QName) MapBasedQueryWalker(org.alfresco.rest.workflow.api.impl.MapBasedQueryWalker) HashSet(java.util.HashSet)

Example 75 with InvalidArgumentException

use of org.alfresco.rest.framework.core.exceptions.InvalidArgumentException in project records-management by Alfresco.

the class SearchTypesFactory method buildSearchTypesForUnfiledEndpoint.

/**
 * Helper method to build search types for unfiled container and unfiled record folders endpoints
 * @param parameters
 * @param listFolderChildrenEqualsQueryProperties
 * @return
 */
public Set<QName> buildSearchTypesForUnfiledEndpoint(Parameters parameters, Set<String> listFolderChildrenEqualsQueryProperties) {
    Set<QName> searchTypeQNames = new HashSet<>();
    Query q = parameters.getQuery();
    boolean includeUnfiledRecordFolders = false;
    boolean includeRecords = false;
    boolean includeSubTypes = false;
    if (q != null) {
        // filtering via "where" clause
        MapBasedQueryWalker propertyWalker = new MapBasedQueryWalker(listFolderChildrenEqualsQueryProperties, null);
        QueryHelper.walk(q, propertyWalker);
        Boolean isUnfiledRecordFolder = propertyWalker.getProperty(UnfiledChild.PARAM_IS_UNFILED_RECORD_FOLDER, WhereClauseParser.EQUALS, Boolean.class);
        Boolean isRecord = propertyWalker.getProperty(UnfiledChild.PARAM_IS_RECORD, WhereClauseParser.EQUALS, Boolean.class);
        if ((isUnfiledRecordFolder != null && isUnfiledRecordFolder.booleanValue()) || (isRecord != null && !isRecord.booleanValue())) {
            includeUnfiledRecordFolders = true;
        } else if ((isUnfiledRecordFolder != null && !isUnfiledRecordFolder.booleanValue()) || (isRecord != null && isRecord.booleanValue())) {
            includeRecords = true;
        }
        String nodeTypeQNameStr = propertyWalker.getProperty(UnfiledChild.PARAM_NODE_TYPE, WhereClauseParser.EQUALS, String.class);
        QName filterNodeTypeQName;
        if (nodeTypeQNameStr != null) {
            if ((isUnfiledRecordFolder != null) || (isRecord != null)) {
                throw new InvalidArgumentException("Invalid filter - nodeType and isUnfiledRecordFolder/isRecord are mutually exclusive");
            }
            Pair<QName, Boolean> pair = parseNodeTypeFilter(nodeTypeQNameStr);
            filterNodeTypeQName = pair.getFirst();
            includeSubTypes = pair.getSecond();
            if (nodeTypeQNameStr.equals(RecordsManagementModel.TYPE_UNFILED_RECORD_FOLDER)) {
                includeUnfiledRecordFolders = true;
            } else if (filterNodeTypeQName.equals(ContentModel.TYPE_CONTENT)) {
                includeRecords = true;
            } else if (dictionaryService.isSubClass(filterNodeTypeQName, ContentModel.TYPE_CONTENT)) {
                searchTypeQNames.add(filterNodeTypeQName);
                if (includeSubTypes) {
                    Collection<QName> qnames = dictionaryService.getSubTypes(filterNodeTypeQName, true);
                    searchTypeQNames.addAll(qnames);
                }
            } else {
                throw new InvalidParameterException("Filter nodeType: " + nodeTypeQNameStr + " is invalid for this endpoint");
            }
        }
    } else {
        includeRecords = true;
        includeUnfiledRecordFolders = true;
        includeSubTypes = true;
    }
    if (includeUnfiledRecordFolders) {
        searchTypeQNames.add(RecordsManagementModel.TYPE_UNFILED_RECORD_FOLDER);
    }
    if (includeRecords) {
        if (includeSubTypes) {
            Collection<QName> qnames = dictionaryService.getSubTypes(ContentModel.TYPE_CONTENT, true);
            searchTypeQNames.addAll(qnames);
        } else {
            searchTypeQNames.add(ContentModel.TYPE_CONTENT);
            searchTypeQNames.add(RecordsManagementModel.TYPE_NON_ELECTRONIC_DOCUMENT);
        }
    }
    return searchTypeQNames;
}
Also used : InvalidParameterException(java.security.InvalidParameterException) InvalidArgumentException(org.alfresco.rest.framework.core.exceptions.InvalidArgumentException) Query(org.alfresco.rest.framework.resource.parameters.where.Query) QName(org.alfresco.service.namespace.QName) MapBasedQueryWalker(org.alfresco.rest.workflow.api.impl.MapBasedQueryWalker) HashSet(java.util.HashSet)

Aggregations

InvalidArgumentException (org.alfresco.rest.framework.core.exceptions.InvalidArgumentException)132 NodeRef (org.alfresco.service.cmr.repository.NodeRef)39 QName (org.alfresco.service.namespace.QName)37 EntityNotFoundException (org.alfresco.rest.framework.core.exceptions.EntityNotFoundException)31 ConstraintViolatedException (org.alfresco.rest.framework.core.exceptions.ConstraintViolatedException)24 ArrayList (java.util.ArrayList)22 Test (org.junit.Test)20 PermissionDeniedException (org.alfresco.rest.framework.core.exceptions.PermissionDeniedException)17 Serializable (java.io.Serializable)12 SortColumn (org.alfresco.rest.framework.resource.parameters.SortColumn)12 SearchParameters (org.alfresco.service.cmr.search.SearchParameters)11 Paging (org.alfresco.rest.framework.resource.parameters.Paging)10 ApiException (org.alfresco.rest.framework.core.exceptions.ApiException)9 NotFoundException (org.alfresco.rest.framework.core.exceptions.NotFoundException)9 SiteInfo (org.alfresco.service.cmr.site.SiteInfo)9 Pair (org.alfresco.util.Pair)9 HashMap (java.util.HashMap)8 HashSet (java.util.HashSet)8 Params (org.alfresco.rest.framework.resource.parameters.Params)8 RelationshipResourceNotFoundException (org.alfresco.rest.framework.core.exceptions.RelationshipResourceNotFoundException)7