Search in sources :

Example 6 with VariableValueDto

use of org.camunda.bpm.engine.rest.dto.VariableValueDto in project camunda-bpm-platform by camunda.

the class AbstractVariablesResource method setBinaryVariable.

public void setBinaryVariable(String variableKey, MultipartFormData payload) {
    FormPart dataPart = payload.getNamedPart("data");
    FormPart objectTypePart = payload.getNamedPart("type");
    FormPart valueTypePart = payload.getNamedPart("valueType");
    if (objectTypePart != null) {
        Object object = null;
        if (dataPart.getContentType() != null && dataPart.getContentType().toLowerCase().contains(MediaType.APPLICATION_JSON)) {
            object = deserializeJsonObject(objectTypePart.getTextContent(), dataPart.getBinaryContent());
        } else {
            throw new InvalidRequestException(Status.BAD_REQUEST, "Unrecognized content type for serialized java type: " + dataPart.getContentType());
        }
        if (object != null) {
            setVariableEntity(variableKey, Variables.objectValue(object).create());
        }
    } else {
        String valueTypeName = DEFAULT_BINARY_VALUE_TYPE;
        if (valueTypePart != null) {
            if (valueTypePart.getTextContent() == null) {
                throw new InvalidRequestException(Status.BAD_REQUEST, "Form part with name 'valueType' must have a text/plain value");
            }
            valueTypeName = valueTypePart.getTextContent();
        }
        VariableValueDto valueDto = VariableValueDto.fromFormPart(valueTypeName, dataPart);
        try {
            TypedValue typedValue = valueDto.toTypedValue(engine, objectMapper);
            setVariableEntity(variableKey, typedValue);
        } catch (AuthorizationException e) {
            throw e;
        } catch (ProcessEngineException e) {
            String errorMessage = String.format("Cannot put %s variable %s: %s", getResourceTypeName(), variableKey, e.getMessage());
            throw new RestException(Status.INTERNAL_SERVER_ERROR, e, errorMessage);
        }
    }
}
Also used : FormPart(org.camunda.bpm.engine.rest.mapper.MultipartFormData.FormPart) VariableValueDto(org.camunda.bpm.engine.rest.dto.VariableValueDto) AuthorizationException(org.camunda.bpm.engine.AuthorizationException) RestException(org.camunda.bpm.engine.rest.exception.RestException) InvalidRequestException(org.camunda.bpm.engine.rest.exception.InvalidRequestException) ProcessEngineException(org.camunda.bpm.engine.ProcessEngineException) TypedValue(org.camunda.bpm.engine.variable.value.TypedValue)

Example 7 with VariableValueDto

use of org.camunda.bpm.engine.rest.dto.VariableValueDto in project camunda-bpm-platform by camunda.

the class HalVariableValue method fromVariableInstance.

public static HalVariableValue fromVariableInstance(VariableInstance variableInstance) {
    HalVariableValue dto = new HalVariableValue();
    VariableValueDto variableValueDto = VariableValueDto.fromTypedValue(variableInstance.getTypedValue());
    dto.name = variableInstance.getName();
    dto.value = variableValueDto.getValue();
    dto.type = variableValueDto.getType();
    dto.valueInfo = variableValueDto.getValueInfo();
    return dto;
}
Also used : VariableValueDto(org.camunda.bpm.engine.rest.dto.VariableValueDto)

Aggregations

VariableValueDto (org.camunda.bpm.engine.rest.dto.VariableValueDto)7 VariableMap (org.camunda.bpm.engine.variable.VariableMap)3 HashMap (java.util.HashMap)2 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 DmnDecisionResultEntries (org.camunda.bpm.dmn.engine.DmnDecisionResultEntries)1 AuthorizationException (org.camunda.bpm.engine.AuthorizationException)1 ProcessEngineException (org.camunda.bpm.engine.ProcessEngineException)1 RuntimeService (org.camunda.bpm.engine.RuntimeService)1 InvalidRequestException (org.camunda.bpm.engine.rest.exception.InvalidRequestException)1 RestException (org.camunda.bpm.engine.rest.exception.RestException)1 FormPart (org.camunda.bpm.engine.rest.mapper.MultipartFormData.FormPart)1 SignalEventReceivedBuilder (org.camunda.bpm.engine.runtime.SignalEventReceivedBuilder)1 TypedValue (org.camunda.bpm.engine.variable.value.TypedValue)1