Search in sources :

Example 16 with RestVariable

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

the class RestResponseFactory method getVariableValue.

public Object getVariableValue(QueryVariable restVariable) {
    Object value = null;
    if (restVariable.getType() != null) {
        // Try locating a converter if the type has been specified
        RestVariableConverter converter = null;
        for (RestVariableConverter conv : variableConverters) {
            if (conv.getRestTypeName().equals(restVariable.getType())) {
                converter = conv;
                break;
            }
        }
        if (converter == null) {
            throw new ActivitiIllegalArgumentException("Variable '" + restVariable.getName() + "' has unsupported type: '" + restVariable.getType() + "'.");
        }
        RestVariable temp = new RestVariable();
        temp.setValue(restVariable.getValue());
        temp.setType(restVariable.getType());
        temp.setName(restVariable.getName());
        value = converter.getVariableValue(temp);
    } else {
        // Revert to type determined by REST-to-Java mapping when no explicit type has been provided
        value = restVariable.getValue();
    }
    return value;
}
Also used : RestVariable(org.activiti.rest.service.api.engine.variable.RestVariable) IntegerRestVariableConverter(org.activiti.rest.service.api.engine.variable.IntegerRestVariableConverter) RestVariableConverter(org.activiti.rest.service.api.engine.variable.RestVariableConverter) BooleanRestVariableConverter(org.activiti.rest.service.api.engine.variable.BooleanRestVariableConverter) ShortRestVariableConverter(org.activiti.rest.service.api.engine.variable.ShortRestVariableConverter) StringRestVariableConverter(org.activiti.rest.service.api.engine.variable.StringRestVariableConverter) DoubleRestVariableConverter(org.activiti.rest.service.api.engine.variable.DoubleRestVariableConverter) DateRestVariableConverter(org.activiti.rest.service.api.engine.variable.DateRestVariableConverter) LongRestVariableConverter(org.activiti.rest.service.api.engine.variable.LongRestVariableConverter) ActivitiIllegalArgumentException(org.activiti.engine.ActivitiIllegalArgumentException)

Example 17 with RestVariable

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

the class RestResponseFactory method createRestVariable.

public RestVariable createRestVariable(String name, Object value, RestVariableScope scope, String id, int variableType, boolean includeBinaryValue, RestUrlBuilder urlBuilder) {
    RestVariableConverter converter = null;
    RestVariable restVar = new RestVariable();
    restVar.setVariableScope(scope);
    restVar.setName(name);
    if (value != null) {
        // Try converting the value
        for (RestVariableConverter c : variableConverters) {
            if (c.getVariableType().isAssignableFrom(value.getClass())) {
                converter = c;
                break;
            }
        }
        if (converter != null) {
            converter.convertVariableValue(value, restVar);
            restVar.setType(converter.getRestTypeName());
        } else {
            // Revert to default conversion, which is the serializable/byte-array form
            if (value instanceof Byte[] || value instanceof byte[]) {
                restVar.setType(BYTE_ARRAY_VARIABLE_TYPE);
            } else {
                restVar.setType(SERIALIZABLE_VARIABLE_TYPE);
            }
            if (includeBinaryValue) {
                restVar.setValue(value);
            }
            if (variableType == VARIABLE_TASK) {
                restVar.setValueUrl(urlBuilder.buildUrl(RestUrls.URL_TASK_VARIABLE_DATA, id, name));
            } else if (variableType == VARIABLE_EXECUTION) {
                restVar.setValueUrl(urlBuilder.buildUrl(RestUrls.URL_EXECUTION_VARIABLE_DATA, id, name));
            } else if (variableType == VARIABLE_PROCESS) {
                restVar.setValueUrl(urlBuilder.buildUrl(RestUrls.URL_PROCESS_INSTANCE_VARIABLE_DATA, id, name));
            } else if (variableType == VARIABLE_HISTORY_TASK) {
                restVar.setValueUrl(urlBuilder.buildUrl(RestUrls.URL_HISTORIC_TASK_INSTANCE_VARIABLE_DATA, id, name));
            } else if (variableType == VARIABLE_HISTORY_PROCESS) {
                restVar.setValueUrl(urlBuilder.buildUrl(RestUrls.URL_HISTORIC_PROCESS_INSTANCE_VARIABLE_DATA, id, name));
            } else if (variableType == VARIABLE_HISTORY_VARINSTANCE) {
                restVar.setValueUrl(urlBuilder.buildUrl(RestUrls.URL_HISTORIC_VARIABLE_INSTANCE_DATA, id));
            } else if (variableType == VARIABLE_HISTORY_DETAIL) {
                restVar.setValueUrl(urlBuilder.buildUrl(RestUrls.URL_HISTORIC_DETAIL_VARIABLE_DATA, id));
            }
        }
    }
    return restVar;
}
Also used : RestVariable(org.activiti.rest.service.api.engine.variable.RestVariable) IntegerRestVariableConverter(org.activiti.rest.service.api.engine.variable.IntegerRestVariableConverter) RestVariableConverter(org.activiti.rest.service.api.engine.variable.RestVariableConverter) BooleanRestVariableConverter(org.activiti.rest.service.api.engine.variable.BooleanRestVariableConverter) ShortRestVariableConverter(org.activiti.rest.service.api.engine.variable.ShortRestVariableConverter) StringRestVariableConverter(org.activiti.rest.service.api.engine.variable.StringRestVariableConverter) DoubleRestVariableConverter(org.activiti.rest.service.api.engine.variable.DoubleRestVariableConverter) DateRestVariableConverter(org.activiti.rest.service.api.engine.variable.DateRestVariableConverter) LongRestVariableConverter(org.activiti.rest.service.api.engine.variable.LongRestVariableConverter)

Example 18 with RestVariable

use of org.activiti.rest.service.api.engine.variable.RestVariable 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 19 with RestVariable

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

the class ExecutionBaseResource method getVariablesToSet.

protected Map<String, Object> getVariablesToSet(ExecutionActionRequest actionRequest) {
    Map<String, Object> variablesToSet = new HashMap<String, Object>();
    for (RestVariable var : actionRequest.getVariables()) {
        if (var.getName() == null) {
            throw new ActivitiIllegalArgumentException("Variable name is required");
        }
        Object actualVariableValue = restResponseFactory.getVariableValue(var);
        variablesToSet.put(var.getName(), actualVariableValue);
    }
    return variablesToSet;
}
Also used : RestVariable(org.activiti.rest.service.api.engine.variable.RestVariable) HashMap(java.util.HashMap) ActivitiIllegalArgumentException(org.activiti.engine.ActivitiIllegalArgumentException)

Example 20 with RestVariable

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

the class ExecutionVariableResource method updateVariable.

@RequestMapping(value = "/runtime/executions/{executionId}/variables/{variableName}", method = RequestMethod.PUT, produces = "application/json")
public RestVariable updateVariable(@PathVariable("executionId") String executionId, @PathVariable("variableName") String variableName, HttpServletRequest request) {
    Execution execution = getExecutionFromRequest(executionId);
    RestVariable result = null;
    if (request instanceof MultipartHttpServletRequest) {
        result = setBinaryVariable((MultipartHttpServletRequest) request, execution, RestResponseFactory.VARIABLE_EXECUTION, false);
        if (!result.getName().equals(variableName)) {
            throw new ActivitiIllegalArgumentException("Variable name in the body should be equal to the name used in the requested URL.");
        }
    } else {
        RestVariable restVariable = null;
        try {
            restVariable = objectMapper.readValue(request.getInputStream(), RestVariable.class);
        } catch (Exception e) {
            throw new ActivitiIllegalArgumentException("Error converting request body to RestVariable instance", e);
        }
        if (restVariable == null) {
            throw new ActivitiException("Invalid body was supplied");
        }
        if (!restVariable.getName().equals(variableName)) {
            throw new ActivitiIllegalArgumentException("Variable name in the body should be equal to the name used in the requested URL.");
        }
        result = setSimpleVariable(restVariable, execution, false);
    }
    return result;
}
Also used : RestVariable(org.activiti.rest.service.api.engine.variable.RestVariable) ActivitiException(org.activiti.engine.ActivitiException) Execution(org.activiti.engine.runtime.Execution) ActivitiIllegalArgumentException(org.activiti.engine.ActivitiIllegalArgumentException) ActivitiException(org.activiti.engine.ActivitiException) ActivitiObjectNotFoundException(org.activiti.engine.ActivitiObjectNotFoundException) ActivitiIllegalArgumentException(org.activiti.engine.ActivitiIllegalArgumentException) MultipartHttpServletRequest(org.springframework.web.multipart.MultipartHttpServletRequest) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

RestVariable (org.activiti.rest.service.api.engine.variable.RestVariable)25 ActivitiObjectNotFoundException (org.activiti.engine.ActivitiObjectNotFoundException)11 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)11 ActivitiException (org.activiti.engine.ActivitiException)10 ActivitiIllegalArgumentException (org.activiti.engine.ActivitiIllegalArgumentException)9 ByteArrayOutputStream (java.io.ByteArrayOutputStream)7 IOException (java.io.IOException)7 ObjectOutputStream (java.io.ObjectOutputStream)7 HashMap (java.util.HashMap)6 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)6 MultipartHttpServletRequest (org.springframework.web.multipart.MultipartHttpServletRequest)5 ArrayList (java.util.ArrayList)4 RestVariableScope (org.activiti.rest.service.api.engine.variable.RestVariable.RestVariableScope)4 Execution (org.activiti.engine.runtime.Execution)3 List (java.util.List)2 Task (org.activiti.engine.task.Task)2 ActivitiConflictException (org.activiti.rest.exception.ActivitiConflictException)2 BooleanRestVariableConverter (org.activiti.rest.service.api.engine.variable.BooleanRestVariableConverter)2 DateRestVariableConverter (org.activiti.rest.service.api.engine.variable.DateRestVariableConverter)2 DoubleRestVariableConverter (org.activiti.rest.service.api.engine.variable.DoubleRestVariableConverter)2