Search in sources :

Example 91 with InvalidArgumentException

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

the class WorkflowRestImpl method createItemInProcess.

/**
 *  Create a new item in the process package variable
 */
public Item createItemInProcess(String itemId, String processId) {
    NodeRef nodeRef = getNodeRef(itemId);
    ActivitiScriptNode packageScriptNode = null;
    try {
        packageScriptNode = (ActivitiScriptNode) activitiProcessEngine.getRuntimeService().getVariable(processId, BPM_PACKAGE);
    } catch (ActivitiObjectNotFoundException e) {
        throw new EntityNotFoundException(processId);
    }
    if (packageScriptNode == null) {
        throw new InvalidArgumentException("process doesn't contain a workflow package variable");
    }
    // check if noderef exists
    try {
        nodeService.getProperties(nodeRef);
    } catch (Exception e) {
        throw new EntityNotFoundException("item with id " + nodeRef.toString() + " not found");
    }
    try {
        QName workflowPackageItemId = QName.createQName("wpi", nodeRef.toString());
        nodeService.addChild(packageScriptNode.getNodeRef(), nodeRef, WorkflowModel.ASSOC_PACKAGE_CONTAINS, workflowPackageItemId);
    } catch (Exception e) {
        throw new ApiException("could not add item to process " + e.getMessage(), e);
    }
    Item responseItem = createItemForNodeRef(nodeRef);
    activitiWorkflowEngine.dispatchPackageUpdatedEvent(packageScriptNode, null, null, processId, null);
    return responseItem;
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) Item(org.alfresco.rest.workflow.api.model.Item) InvalidArgumentException(org.alfresco.rest.framework.core.exceptions.InvalidArgumentException) ActivitiScriptNode(org.alfresco.repo.workflow.activiti.ActivitiScriptNode) QName(org.alfresco.service.namespace.QName) EntityNotFoundException(org.alfresco.rest.framework.core.exceptions.EntityNotFoundException) ActivitiObjectNotFoundException(org.activiti.engine.ActivitiObjectNotFoundException) PermissionDeniedException(org.alfresco.rest.framework.core.exceptions.PermissionDeniedException) EntityNotFoundException(org.alfresco.rest.framework.core.exceptions.EntityNotFoundException) ConversionException(org.apache.commons.beanutils.ConversionException) InvalidNodeRefException(org.alfresco.service.cmr.repository.InvalidNodeRefException) ApiException(org.alfresco.rest.framework.core.exceptions.ApiException) ActivitiObjectNotFoundException(org.activiti.engine.ActivitiObjectNotFoundException) InvalidArgumentException(org.alfresco.rest.framework.core.exceptions.InvalidArgumentException) ApiException(org.alfresco.rest.framework.core.exceptions.ApiException)

Example 92 with InvalidArgumentException

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

the class WorkflowRestImpl method getParameter.

/**
 * Get the first parameter value, converted to the requested type.
 * @param parameters used to extract parameter value from
 * @param parameterName name of the parameter
 * @param returnType type of object to return
 * @return the converted parameter value. Null, if the parameter has no value.
 * @throws IllegalArgumentException when no conversion for the given returnType is available or if returnType is null.
 * @throws InvalidArgumentException when conversion to the given type was not possible
 */
@SuppressWarnings("unchecked")
public <T extends Object> T getParameter(Parameters parameters, String parameterName, Class<T> returnType) {
    if (returnType == null) {
        throw new IllegalArgumentException("ReturnType cannot be null");
    }
    try {
        Object result = null;
        String stringValue = parameters.getParameter(parameterName);
        if (stringValue != null) {
            result = ConvertUtils.convert(stringValue, returnType);
            if (result instanceof String) {
                // If a string is returned, no converter has been found
                throw new IllegalArgumentException("Unable to convert parameter to type: " + returnType.getName());
            }
        }
        return (T) result;
    } catch (ConversionException ce) {
        // Conversion failed, wrap in Illegal
        throw new InvalidArgumentException("Parameter value for '" + parameterName + "' should be a valid " + returnType.getSimpleName());
    }
}
Also used : ConversionException(org.apache.commons.beanutils.ConversionException) InvalidArgumentException(org.alfresco.rest.framework.core.exceptions.InvalidArgumentException)

Example 93 with InvalidArgumentException

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

the class CommentsImpl method deleteComment.

@Override
public void deleteComment(String nodeId, String commentNodeId) {
    try {
        NodeRef nodeRef = nodes.validateNode(nodeId);
        NodeRef commentNodeRef = nodes.validateNode(commentNodeId);
        if (!nodeRef.equals(commentService.getDiscussableAncestor(commentNodeRef))) {
            throw new InvalidArgumentException("Unexpected " + nodeId + "," + commentNodeId);
        }
        commentService.deleteComment(commentNodeRef);
    } catch (IllegalArgumentException e) {
        throw new ConstraintViolatedException(e.getMessage());
    }
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) InvalidArgumentException(org.alfresco.rest.framework.core.exceptions.InvalidArgumentException) ConstraintViolatedException(org.alfresco.rest.framework.core.exceptions.ConstraintViolatedException)

Example 94 with InvalidArgumentException

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

the class ActivitiesImpl method getUserActivities.

public CollectionWithPagingInfo<Activity> getUserActivities(String personId, final Parameters parameters) {
    personId = people.validatePerson(personId);
    Paging paging = parameters.getPaging();
    String siteId = parameters.getParameter("siteId");
    String who = parameters.getParameter("who");
    ActivityWho activityWho = null;
    if (who != null) {
        try {
            activityWho = ActivityWho.valueOf(who);
        } catch (IllegalArgumentException e) {
            throw new InvalidArgumentException("Parameter who should be one of " + Arrays.toString(ActivityWho.values()));
        }
    }
    if (siteId != null && !siteId.equals("")) {
        SiteInfo siteInfo = sites.validateSite(siteId);
        if (siteInfo == null) {
            // site does not exist
            throw new EntityNotFoundException(siteId);
        }
        // set the site id to the short name (to deal with case sensitivity issues with using the siteId from the url)
        siteId = siteInfo.getShortName();
    }
    try {
        PagingResults<ActivityFeedEntity> activities = null;
        if (activityWho == null) {
            activities = activityService.getPagedUserFeedEntries(personId, siteId, false, false, -1, Util.getPagingRequest(paging));
        } else if (activityWho.equals(ActivityWho.me)) {
            activities = activityService.getPagedUserFeedEntries(personId, siteId, false, true, -1, Util.getPagingRequest(paging));
        } else if (activityWho.equals(ActivityWho.others)) {
            activities = activityService.getPagedUserFeedEntries(personId, siteId, true, false, -1, Util.getPagingRequest(paging));
        } else {
            throw new InvalidArgumentException("Who argument is invalid.");
        }
        List<ActivityFeedEntity> feedEntities = activities.getPage();
        List<Activity> ret = new ArrayList<Activity>(feedEntities.size());
        for (ActivityFeedEntity entity : feedEntities) {
            String feedSiteId = getSiteId(entity.getSiteNetwork());
            String networkId = tenantService.getDomain(entity.getSiteNetwork());
            Activity activity = new Activity(entity.getId(), networkId, feedSiteId, entity.getFeedUserId(), entity.getPostUserId(), entity.getPostDate(), entity.getActivityType(), getActivitySummary(entity));
            ret.add(activity);
        }
        return CollectionWithPagingInfo.asPaged(paging, ret, activities.hasMoreItems(), activities.getTotalResultCount().getFirst());
    } catch (JSONException e) {
        throw new AlfrescoRuntimeException("", e);
    }
}
Also used : SiteInfo(org.alfresco.service.cmr.site.SiteInfo) Paging(org.alfresco.rest.framework.resource.parameters.Paging) ArrayList(java.util.ArrayList) Activity(org.alfresco.rest.api.model.Activity) JSONException(org.json.JSONException) EntityNotFoundException(org.alfresco.rest.framework.core.exceptions.EntityNotFoundException) ActivityFeedEntity(org.alfresco.repo.domain.activities.ActivityFeedEntity) InvalidArgumentException(org.alfresco.rest.framework.core.exceptions.InvalidArgumentException) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException)

Example 95 with InvalidArgumentException

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

the class GroupsFilter 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)

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