Search in sources :

Example 1 with Action

use of org.alfresco.rest.api.model.Action in project alfresco-remote-api by Alfresco.

the class ActionsImpl method executeAction.

@Override
public Action executeAction(Action action, Parameters parameters) {
    if (action == null) {
        throw new InvalidArgumentException("action is null");
    }
    if (action.getActionDefinitionId() == null || action.getActionDefinitionId().isEmpty()) {
        throw new InvalidArgumentException("action.actionDefinitionId is null or empty");
    }
    org.alfresco.service.cmr.action.ActionDefinition actionDef = null;
    try {
        actionDef = actionService.getActionDefinition(action.getActionDefinitionId());
    } catch (NoSuchBeanDefinitionException nsbdx) {
    // Intentionally empty.
    }
    // the result of getActionDefinition can be null and not throw the exception.
    if (actionDef == null) {
        throw new EntityNotFoundException(action.getActionDefinitionId());
    }
    // targetId is optional, however, currently targetId must be a valid node ID.
    NodeRef actionedUponNodeRef = null;
    if (action.getTargetId() != null && !action.getTargetId().isEmpty()) {
        // Does it exist in the repo?
        actionedUponNodeRef = new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, action.getTargetId());
        if (!nodeService.exists(actionedUponNodeRef)) {
            throw new EntityNotFoundException(action.getTargetId());
        }
    }
    org.alfresco.service.cmr.action.Action cmrAction;
    if (action.getParams() != null && !action.getParams().isEmpty()) {
        cmrAction = actionService.createAction(action.getActionDefinitionId(), extractActionParams(actionDef, action.getParams()));
    } else {
        cmrAction = actionService.createAction(action.getActionDefinitionId());
    }
    actionService.executeAction(cmrAction, actionedUponNodeRef, true, true);
    // Create user result.
    Action result = new Action();
    result.setId(cmrAction.getId());
    return result;
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) Action(org.alfresco.rest.api.model.Action) InvalidArgumentException(org.alfresco.rest.framework.core.exceptions.InvalidArgumentException) EntityNotFoundException(org.alfresco.rest.framework.core.exceptions.EntityNotFoundException) NoSuchBeanDefinitionException(org.springframework.beans.factory.NoSuchBeanDefinitionException)

Aggregations

Action (org.alfresco.rest.api.model.Action)1 EntityNotFoundException (org.alfresco.rest.framework.core.exceptions.EntityNotFoundException)1 InvalidArgumentException (org.alfresco.rest.framework.core.exceptions.InvalidArgumentException)1 NodeRef (org.alfresco.service.cmr.repository.NodeRef)1 NoSuchBeanDefinitionException (org.springframework.beans.factory.NoSuchBeanDefinitionException)1