Search in sources :

Example 6 with RestVariableScope

use of org.activiti.rest.service.api.engine.variable.RestVariable.RestVariableScope in project Activiti by Activiti.

the class TaskVariableResource method deleteVariable.

@RequestMapping(value = "/runtime/tasks/{taskId}/variables/{variableName}", method = RequestMethod.DELETE)
public void deleteVariable(@PathVariable("taskId") String taskId, @PathVariable("variableName") String variableName, @RequestParam(value = "scope", required = false) String scopeString, HttpServletResponse response) {
    Task task = getTaskFromRequest(taskId);
    // Determine scope
    RestVariableScope scope = RestVariableScope.LOCAL;
    if (scopeString != null) {
        scope = RestVariable.getScopeFromString(scopeString);
    }
    if (!hasVariableOnScope(task, variableName, scope)) {
        throw new ActivitiObjectNotFoundException("Task '" + task.getId() + "' doesn't have a variable '" + variableName + "' in scope " + scope.name().toLowerCase(), VariableInstanceEntity.class);
    }
    if (scope == RestVariableScope.LOCAL) {
        taskService.removeVariableLocal(task.getId(), variableName);
    } else {
        // Safe to use executionId, as the hasVariableOnScope whould have stopped a global-var update on standalone task
        runtimeService.removeVariable(task.getExecutionId(), variableName);
    }
    response.setStatus(HttpStatus.NO_CONTENT.value());
}
Also used : Task(org.activiti.engine.task.Task) RestVariableScope(org.activiti.rest.service.api.engine.variable.RestVariable.RestVariableScope) ActivitiObjectNotFoundException(org.activiti.engine.ActivitiObjectNotFoundException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 7 with RestVariableScope

use of org.activiti.rest.service.api.engine.variable.RestVariable.RestVariableScope in project Activiti by Activiti.

the class HistoricTaskInstanceVariableDataResource method getVariableFromRequest.

public RestVariable getVariableFromRequest(boolean includeBinary, String taskId, String variableName, String scope, HttpServletRequest request) {
    RestVariableScope variableScope = RestVariable.getScopeFromString(scope);
    HistoricTaskInstanceQuery taskQuery = historyService.createHistoricTaskInstanceQuery().taskId(taskId);
    if (variableScope != null) {
        if (variableScope == RestVariableScope.GLOBAL) {
            taskQuery.includeProcessVariables();
        } else {
            taskQuery.includeTaskLocalVariables();
        }
    } else {
        taskQuery.includeTaskLocalVariables().includeProcessVariables();
    }
    HistoricTaskInstance taskObject = taskQuery.singleResult();
    if (taskObject == null) {
        throw new ActivitiObjectNotFoundException("Historic task instance '" + taskId + "' couldn't be found.", HistoricTaskInstanceEntity.class);
    }
    Object value = null;
    if (variableScope != null) {
        if (variableScope == RestVariableScope.GLOBAL) {
            value = taskObject.getProcessVariables().get(variableName);
        } else {
            value = taskObject.getTaskLocalVariables().get(variableName);
        }
    } else {
        // look for local task variables first
        if (taskObject.getTaskLocalVariables().containsKey(variableName)) {
            value = taskObject.getTaskLocalVariables().get(variableName);
        } else {
            value = taskObject.getProcessVariables().get(variableName);
        }
    }
    if (value == null) {
        throw new ActivitiObjectNotFoundException("Historic task instance '" + taskId + "' variable value for " + variableName + " couldn't be found.", VariableInstanceEntity.class);
    } else {
        return restResponseFactory.createRestVariable(variableName, value, null, taskId, RestResponseFactory.VARIABLE_HISTORY_TASK, includeBinary);
    }
}
Also used : HistoricTaskInstance(org.activiti.engine.history.HistoricTaskInstance) RestVariableScope(org.activiti.rest.service.api.engine.variable.RestVariable.RestVariableScope) HistoricTaskInstanceQuery(org.activiti.engine.history.HistoricTaskInstanceQuery) ActivitiObjectNotFoundException(org.activiti.engine.ActivitiObjectNotFoundException)

Example 8 with RestVariableScope

use of org.activiti.rest.service.api.engine.variable.RestVariable.RestVariableScope in project Activiti by Activiti.

the class BaseVariableCollectionResource method processVariables.

protected List<RestVariable> processVariables(Execution execution, String scope, int variableType) {
    List<RestVariable> result = new ArrayList<RestVariable>();
    Map<String, RestVariable> variableMap = new HashMap<String, RestVariable>();
    // Check if it's a valid execution to get the variables for
    RestVariableScope variableScope = RestVariable.getScopeFromString(scope);
    if (variableScope == null) {
        // Use both local and global variables
        addLocalVariables(execution, variableType, variableMap);
        addGlobalVariables(execution, variableType, variableMap);
    } else if (variableScope == RestVariableScope.GLOBAL) {
        addGlobalVariables(execution, variableType, variableMap);
    } else if (variableScope == RestVariableScope.LOCAL) {
        addLocalVariables(execution, variableType, variableMap);
    }
    // Get unique variables from map
    result.addAll(variableMap.values());
    return result;
}
Also used : RestVariable(org.activiti.rest.service.api.engine.variable.RestVariable) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) RestVariableScope(org.activiti.rest.service.api.engine.variable.RestVariable.RestVariableScope)

Example 9 with RestVariableScope

use of org.activiti.rest.service.api.engine.variable.RestVariable.RestVariableScope in project Activiti by Activiti.

the class ExecutionVariableResource method deleteVariable.

@RequestMapping(value = "/runtime/executions/{executionId}/variables/{variableName}", method = RequestMethod.DELETE)
public void deleteVariable(@PathVariable("executionId") String executionId, @PathVariable("variableName") String variableName, @RequestParam(value = "scope", required = false) String scope, HttpServletResponse response) {
    Execution execution = getExecutionFromRequest(executionId);
    // Determine scope
    RestVariableScope variableScope = RestVariableScope.LOCAL;
    if (scope != null) {
        variableScope = RestVariable.getScopeFromString(scope);
    }
    if (!hasVariableOnScope(execution, variableName, variableScope)) {
        throw new ActivitiObjectNotFoundException("Execution '" + execution.getId() + "' doesn't have a variable '" + variableName + "' in scope " + variableScope.name().toLowerCase(), VariableInstanceEntity.class);
    }
    if (variableScope == RestVariableScope.LOCAL) {
        runtimeService.removeVariableLocal(execution.getId(), variableName);
    } else {
        // Safe to use parentId, as the hasVariableOnScope would have stopped a global-var update on a root-execution
        runtimeService.removeVariable(execution.getParentId(), variableName);
    }
    response.setStatus(HttpStatus.NO_CONTENT.value());
}
Also used : Execution(org.activiti.engine.runtime.Execution) RestVariableScope(org.activiti.rest.service.api.engine.variable.RestVariable.RestVariableScope) ActivitiObjectNotFoundException(org.activiti.engine.ActivitiObjectNotFoundException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 10 with RestVariableScope

use of org.activiti.rest.service.api.engine.variable.RestVariable.RestVariableScope in project Activiti by Activiti.

the class BaseExecutionVariableResource method setSimpleVariable.

protected RestVariable setSimpleVariable(RestVariable restVariable, Execution execution, boolean isNew) {
    if (restVariable.getName() == null) {
        throw new ActivitiIllegalArgumentException("Variable name is required");
    }
    // Figure out scope, revert to local is omitted
    RestVariableScope scope = restVariable.getVariableScope();
    if (scope == null) {
        scope = RestVariableScope.LOCAL;
    }
    Object actualVariableValue = restResponseFactory.getVariableValue(restVariable);
    setVariable(execution, restVariable.getName(), actualVariableValue, scope, isNew);
    return constructRestVariable(restVariable.getName(), actualVariableValue, scope, execution.getId(), false);
}
Also used : ActivitiIllegalArgumentException(org.activiti.engine.ActivitiIllegalArgumentException) RestVariableScope(org.activiti.rest.service.api.engine.variable.RestVariable.RestVariableScope)

Aggregations

RestVariableScope (org.activiti.rest.service.api.engine.variable.RestVariable.RestVariableScope)14 ActivitiIllegalArgumentException (org.activiti.engine.ActivitiIllegalArgumentException)6 ActivitiObjectNotFoundException (org.activiti.engine.ActivitiObjectNotFoundException)6 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4 RestVariable (org.activiti.rest.service.api.engine.variable.RestVariable)4 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)4 Task (org.activiti.engine.task.Task)3 IOException (java.io.IOException)2 ObjectInputStream (java.io.ObjectInputStream)2 List (java.util.List)2 Execution (org.activiti.engine.runtime.Execution)2 ActivitiConflictException (org.activiti.rest.exception.ActivitiConflictException)2 ActivitiContentNotSupportedException (org.activiti.rest.exception.ActivitiContentNotSupportedException)2 MultipartFile (org.springframework.web.multipart.MultipartFile)2 MultipartHttpServletRequest (org.springframework.web.multipart.MultipartHttpServletRequest)2 HistoricTaskInstance (org.activiti.engine.history.HistoricTaskInstance)1 HistoricTaskInstanceQuery (org.activiti.engine.history.HistoricTaskInstanceQuery)1