Search in sources :

Example 1 with RestVariable

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

the class HistoricProcessInstanceVariableDataResource method getVariableData.

@RequestMapping(value = "/history/historic-process-instances/{processInstanceId}/variables/{variableName}/data", method = RequestMethod.GET)
@ResponseBody
public byte[] getVariableData(@PathVariable("processInstanceId") String processInstanceId, @PathVariable("variableName") String variableName, HttpServletRequest request, HttpServletResponse response) {
    try {
        byte[] result = null;
        RestVariable variable = getVariableFromRequest(true, processInstanceId, variableName, request);
        if (RestResponseFactory.BYTE_ARRAY_VARIABLE_TYPE.equals(variable.getType())) {
            result = (byte[]) variable.getValue();
            response.setContentType("application/octet-stream");
        } else if (RestResponseFactory.SERIALIZABLE_VARIABLE_TYPE.equals(variable.getType())) {
            ByteArrayOutputStream buffer = new ByteArrayOutputStream();
            ObjectOutputStream outputStream = new ObjectOutputStream(buffer);
            outputStream.writeObject(variable.getValue());
            outputStream.close();
            result = buffer.toByteArray();
            response.setContentType("application/x-java-serialized-object");
        } else {
            throw new ActivitiObjectNotFoundException("The variable does not have a binary data stream.", null);
        }
        return result;
    } catch (IOException ioe) {
        // Re-throw IOException
        throw new ActivitiException("Unexpected exception getting variable data", ioe);
    }
}
Also used : RestVariable(org.activiti.rest.service.api.engine.variable.RestVariable) ActivitiException(org.activiti.engine.ActivitiException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) ObjectOutputStream(java.io.ObjectOutputStream) ActivitiObjectNotFoundException(org.activiti.engine.ActivitiObjectNotFoundException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 2 with RestVariable

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

the class RestResponseFactory method createBinaryRestVariable.

public RestVariable createBinaryRestVariable(String name, RestVariableScope scope, String type, String taskId, String executionId, String processInstanceId) {
    RestUrlBuilder urlBuilder = createUrlBuilder();
    RestVariable restVar = new RestVariable();
    restVar.setVariableScope(scope);
    restVar.setName(name);
    restVar.setType(type);
    if (taskId != null) {
        restVar.setValueUrl(urlBuilder.buildUrl(RestUrls.URL_TASK_VARIABLE_DATA, taskId, name));
    }
    if (executionId != null) {
        restVar.setValueUrl(urlBuilder.buildUrl(RestUrls.URL_EXECUTION_VARIABLE_DATA, executionId, name));
    }
    if (processInstanceId != null) {
        restVar.setValueUrl(urlBuilder.buildUrl(RestUrls.URL_PROCESS_INSTANCE_VARIABLE_DATA, processInstanceId, name));
    }
    return restVar;
}
Also used : RestVariable(org.activiti.rest.service.api.engine.variable.RestVariable)

Example 3 with RestVariable

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

the class BaseExecutionVariableResource method getVariableDataByteArray.

protected byte[] getVariableDataByteArray(Execution execution, String variableName, String scope, HttpServletResponse response) {
    try {
        byte[] result = null;
        RestVariable variable = getVariableFromRequest(execution, variableName, scope, true);
        if (RestResponseFactory.BYTE_ARRAY_VARIABLE_TYPE.equals(variable.getType())) {
            result = (byte[]) variable.getValue();
            response.setContentType("application/octet-stream");
        } else if (RestResponseFactory.SERIALIZABLE_VARIABLE_TYPE.equals(variable.getType())) {
            ByteArrayOutputStream buffer = new ByteArrayOutputStream();
            ObjectOutputStream outputStream = new ObjectOutputStream(buffer);
            outputStream.writeObject(variable.getValue());
            outputStream.close();
            result = buffer.toByteArray();
            response.setContentType("application/x-java-serialized-object");
        } else {
            throw new ActivitiObjectNotFoundException("The variable does not have a binary data stream.", null);
        }
        return result;
    } catch (IOException ioe) {
        throw new ActivitiException("Error getting variable " + variableName, ioe);
    }
}
Also used : RestVariable(org.activiti.rest.service.api.engine.variable.RestVariable) ActivitiException(org.activiti.engine.ActivitiException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) ObjectOutputStream(java.io.ObjectOutputStream) ActivitiObjectNotFoundException(org.activiti.engine.ActivitiObjectNotFoundException)

Example 4 with RestVariable

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

the class BaseVariableCollectionResource method addGlobalVariables.

protected void addGlobalVariables(Execution execution, int variableType, Map<String, RestVariable> variableMap) {
    Map<String, Object> rawVariables = runtimeService.getVariables(execution.getId());
    List<RestVariable> globalVariables = restResponseFactory.createRestVariables(rawVariables, execution.getId(), variableType, RestVariableScope.GLOBAL);
    // since local variables get precedence over global ones at all times.
    for (RestVariable var : globalVariables) {
        if (!variableMap.containsKey(var.getName())) {
            variableMap.put(var.getName(), var);
        }
    }
}
Also used : RestVariable(org.activiti.rest.service.api.engine.variable.RestVariable)

Example 5 with RestVariable

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

the class TaskResource method completeTask.

protected void completeTask(Task task, TaskActionRequest actionRequest) {
    if (actionRequest.getVariables() != null) {
        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);
        }
        taskService.complete(task.getId(), variablesToSet);
    } else {
        taskService.complete(task.getId());
    }
}
Also used : RestVariable(org.activiti.rest.service.api.engine.variable.RestVariable) HashMap(java.util.HashMap) ActivitiIllegalArgumentException(org.activiti.engine.ActivitiIllegalArgumentException)

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