use of org.activiti.engine.impl.variable.StringType 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);
}
}
}
}
use of org.activiti.engine.impl.variable.StringType 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;
}
Aggregations