Search in sources :

Example 1 with RestVariableConverter

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

the class RestResponseFactory method getVariableValue.

public Object getVariableValue(RestVariable 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() + "'.");
        }
        value = converter.getVariableValue(restVariable);
    } else {
        // Revert to type determined by REST-to-Java mapping when no explicit type has been provided
        value = restVariable.getValue();
    }
    return value;
}
Also used : 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 2 with RestVariableConverter

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

use of org.activiti.rest.service.api.engine.variable.RestVariableConverter 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)

Aggregations

BooleanRestVariableConverter (org.activiti.rest.service.api.engine.variable.BooleanRestVariableConverter)3 DateRestVariableConverter (org.activiti.rest.service.api.engine.variable.DateRestVariableConverter)3 DoubleRestVariableConverter (org.activiti.rest.service.api.engine.variable.DoubleRestVariableConverter)3 IntegerRestVariableConverter (org.activiti.rest.service.api.engine.variable.IntegerRestVariableConverter)3 LongRestVariableConverter (org.activiti.rest.service.api.engine.variable.LongRestVariableConverter)3 RestVariableConverter (org.activiti.rest.service.api.engine.variable.RestVariableConverter)3 ShortRestVariableConverter (org.activiti.rest.service.api.engine.variable.ShortRestVariableConverter)3 StringRestVariableConverter (org.activiti.rest.service.api.engine.variable.StringRestVariableConverter)3 ActivitiIllegalArgumentException (org.activiti.engine.ActivitiIllegalArgumentException)2 RestVariable (org.activiti.rest.service.api.engine.variable.RestVariable)2