Search in sources :

Example 1 with IntegerType

use of org.activiti.engine.impl.variable.IntegerType in project Activiti by Activiti.

the class ProcessEngineConfigurationImpl method initVariableTypes.

protected void initVariableTypes() {
    if (variableTypes == null) {
        variableTypes = new DefaultVariableTypes();
        if (customPreVariableTypes != null) {
            for (VariableType customVariableType : customPreVariableTypes) {
                variableTypes.addType(customVariableType);
            }
        }
        variableTypes.addType(new NullType());
        variableTypes.addType(new StringType(getMaxLengthString()));
        variableTypes.addType(new LongStringType(getMaxLengthString() + 1));
        variableTypes.addType(new BooleanType());
        variableTypes.addType(new ShortType());
        variableTypes.addType(new IntegerType());
        variableTypes.addType(new LongType());
        variableTypes.addType(new DateType());
        variableTypes.addType(new DoubleType());
        variableTypes.addType(new UUIDType());
        variableTypes.addType(new JsonType(getMaxLengthString(), objectMapper));
        variableTypes.addType(new LongJsonType(getMaxLengthString() + 1, objectMapper));
        variableTypes.addType(new ByteArrayType());
        variableTypes.addType(new SerializableType());
        variableTypes.addType(new CustomObjectType("item", ItemInstance.class));
        variableTypes.addType(new CustomObjectType("message", MessageInstance.class));
        if (customPostVariableTypes != null) {
            for (VariableType customVariableType : customPostVariableTypes) {
                variableTypes.addType(customVariableType);
            }
        }
    }
}
Also used : JsonType(org.activiti.engine.impl.variable.JsonType) LongJsonType(org.activiti.engine.impl.variable.LongJsonType) LongType(org.activiti.engine.impl.variable.LongType) JPAEntityListVariableType(org.activiti.engine.impl.variable.JPAEntityListVariableType) VariableType(org.activiti.engine.impl.variable.VariableType) JPAEntityVariableType(org.activiti.engine.impl.variable.JPAEntityVariableType) LongStringType(org.activiti.engine.impl.variable.LongStringType) StringType(org.activiti.engine.impl.variable.StringType) SerializableType(org.activiti.engine.impl.variable.SerializableType) ShortType(org.activiti.engine.impl.variable.ShortType) LongStringType(org.activiti.engine.impl.variable.LongStringType) BooleanType(org.activiti.engine.impl.variable.BooleanType) CustomObjectType(org.activiti.engine.impl.variable.CustomObjectType) DefaultVariableTypes(org.activiti.engine.impl.variable.DefaultVariableTypes) IntegerType(org.activiti.engine.impl.variable.IntegerType) MessageInstance(org.activiti.engine.impl.bpmn.webservice.MessageInstance) DoubleType(org.activiti.engine.impl.variable.DoubleType) ByteArrayType(org.activiti.engine.impl.variable.ByteArrayType) UUIDType(org.activiti.engine.impl.variable.UUIDType) NullType(org.activiti.engine.impl.variable.NullType) DateType(org.activiti.engine.impl.variable.DateType) LongJsonType(org.activiti.engine.impl.variable.LongJsonType) ItemInstance(org.activiti.engine.impl.bpmn.data.ItemInstance)

Example 2 with IntegerType

use of org.activiti.engine.impl.variable.IntegerType in project Activiti by Activiti.

the class VariableEventHandler method createData.

protected Map<String, Object> createData(ActivitiVariableEvent variableEvent) {
    Map<String, Object> data = new HashMap<String, Object>();
    putInMapIfNotNull(data, Fields.NAME, variableEvent.getVariableName());
    putInMapIfNotNull(data, Fields.PROCESS_DEFINITION_ID, variableEvent.getProcessDefinitionId());
    putInMapIfNotNull(data, Fields.PROCESS_INSTANCE_ID, variableEvent.getProcessInstanceId());
    putInMapIfNotNull(data, Fields.EXECUTION_ID, variableEvent.getExecutionId());
    putInMapIfNotNull(data, Fields.VALUE, variableEvent.getVariableValue());
    VariableType variableType = variableEvent.getVariableType();
    if (variableType instanceof BooleanType) {
        putInMapIfNotNull(data, Fields.VALUE_BOOLEAN, (Boolean) variableEvent.getVariableValue());
        putInMapIfNotNull(data, Fields.VALUE, variableEvent.getVariableValue());
        putInMapIfNotNull(data, Fields.VARIABLE_TYPE, TYPE_BOOLEAN);
    } else if (variableType instanceof StringType || variableType instanceof LongStringType) {
        putInMapIfNotNull(data, Fields.VALUE_STRING, (String) variableEvent.getVariableValue());
        putInMapIfNotNull(data, Fields.VARIABLE_TYPE, TYPE_STRING);
    } else if (variableType instanceof ShortType) {
        Short value = (Short) variableEvent.getVariableValue();
        putInMapIfNotNull(data, Fields.VALUE_SHORT, value);
        putInMapIfNotNull(data, Fields.VARIABLE_TYPE, TYPE_SHORT);
        if (value != null) {
            putInMapIfNotNull(data, Fields.VALUE_INTEGER, value.intValue());
            putInMapIfNotNull(data, Fields.VALUE_LONG, value.longValue());
            putInMapIfNotNull(data, Fields.VALUE_DOUBLE, value.doubleValue());
        }
    } else if (variableType instanceof IntegerType) {
        Integer value = (Integer) variableEvent.getVariableValue();
        putInMapIfNotNull(data, Fields.VALUE_INTEGER, value);
        putInMapIfNotNull(data, Fields.VARIABLE_TYPE, TYPE_INTEGER);
        if (value != null) {
            putInMapIfNotNull(data, Fields.VALUE_LONG, value.longValue());
            putInMapIfNotNull(data, Fields.VALUE_DOUBLE, value.doubleValue());
        }
    } else if (variableType instanceof LongType) {
        Long value = (Long) variableEvent.getVariableValue();
        putInMapIfNotNull(data, Fields.VALUE_LONG, value);
        putInMapIfNotNull(data, Fields.VARIABLE_TYPE, TYPE_LONG);
        if (value != null) {
            putInMapIfNotNull(data, Fields.VALUE_DOUBLE, value.doubleValue());
        }
    } else if (variableType instanceof DoubleType) {
        Double value = (Double) variableEvent.getVariableValue();
        putInMapIfNotNull(data, Fields.VALUE_DOUBLE, value);
        putInMapIfNotNull(data, Fields.VARIABLE_TYPE, TYPE_DOUBLE);
        if (value != null) {
            putInMapIfNotNull(data, Fields.VALUE_INTEGER, value.intValue());
            putInMapIfNotNull(data, Fields.VALUE_LONG, value.longValue());
        }
    } else if (variableType instanceof DateType) {
        Date value = (Date) variableEvent.getVariableValue();
        putInMapIfNotNull(data, Fields.VALUE_DATE, value != null ? value.getTime() : null);
        putInMapIfNotNull(data, Fields.VARIABLE_TYPE, TYPE_DATE);
    } else if (variableType instanceof UUIDType) {
        String value = null;
        if (variableEvent.getVariableValue() instanceof UUID) {
            value = ((UUID) variableEvent.getVariableValue()).toString();
        } else {
            value = (String) variableEvent.getVariableValue();
        }
        putInMapIfNotNull(data, Fields.VALUE_UUID, value);
        putInMapIfNotNull(data, Fields.VALUE_STRING, value);
        putInMapIfNotNull(data, Fields.VARIABLE_TYPE, TYPE_UUID);
    } else if (variableType instanceof SerializableType || (variableEvent.getVariableValue() != null && (variableEvent.getVariableValue() instanceof Object))) {
        // Last try: serialize it to json
        ObjectMapper objectMapper = new ObjectMapper();
        try {
            String value = objectMapper.writeValueAsString(variableEvent.getVariableValue());
            putInMapIfNotNull(data, Fields.VALUE_JSON, value);
            putInMapIfNotNull(data, Fields.VARIABLE_TYPE, TYPE_JSON);
            putInMapIfNotNull(data, Fields.VALUE, value);
        } catch (JsonProcessingException e) {
            // Nothing to do about it
            logger.debug("Could not serialize variable value " + variableEvent.getVariableValue());
        }
    }
    return data;
}
Also used : LongType(org.activiti.engine.impl.variable.LongType) VariableType(org.activiti.engine.impl.variable.VariableType) HashMap(java.util.HashMap) StringType(org.activiti.engine.impl.variable.StringType) LongStringType(org.activiti.engine.impl.variable.LongStringType) SerializableType(org.activiti.engine.impl.variable.SerializableType) ShortType(org.activiti.engine.impl.variable.ShortType) BooleanType(org.activiti.engine.impl.variable.BooleanType) LongStringType(org.activiti.engine.impl.variable.LongStringType) Date(java.util.Date) IntegerType(org.activiti.engine.impl.variable.IntegerType) DoubleType(org.activiti.engine.impl.variable.DoubleType) UUIDType(org.activiti.engine.impl.variable.UUIDType) UUID(java.util.UUID) DateType(org.activiti.engine.impl.variable.DateType) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Aggregations

BooleanType (org.activiti.engine.impl.variable.BooleanType)2 DateType (org.activiti.engine.impl.variable.DateType)2 DoubleType (org.activiti.engine.impl.variable.DoubleType)2 IntegerType (org.activiti.engine.impl.variable.IntegerType)2 LongStringType (org.activiti.engine.impl.variable.LongStringType)2 LongType (org.activiti.engine.impl.variable.LongType)2 SerializableType (org.activiti.engine.impl.variable.SerializableType)2 ShortType (org.activiti.engine.impl.variable.ShortType)2 StringType (org.activiti.engine.impl.variable.StringType)2 UUIDType (org.activiti.engine.impl.variable.UUIDType)2 VariableType (org.activiti.engine.impl.variable.VariableType)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 UUID (java.util.UUID)1 ItemInstance (org.activiti.engine.impl.bpmn.data.ItemInstance)1 MessageInstance (org.activiti.engine.impl.bpmn.webservice.MessageInstance)1 ByteArrayType (org.activiti.engine.impl.variable.ByteArrayType)1 CustomObjectType (org.activiti.engine.impl.variable.CustomObjectType)1