use of org.camunda.bpm.engine.variable.value.SerializableValue in project camunda-bpm-platform by camunda.
the class VariableValueDto method fromTypedValue.
public static void fromTypedValue(VariableValueDto dto, TypedValue typedValue, boolean preferSerializedValue) {
ValueType type = typedValue.getType();
if (type != null) {
String typeName = type.getName();
dto.setType(toRestApiTypeName(typeName));
dto.setValueInfo(type.getValueInfo(typedValue));
}
if (typedValue instanceof SerializableValue) {
SerializableValue serializableValue = (SerializableValue) typedValue;
if (serializableValue.isDeserialized() && !preferSerializedValue) {
dto.setValue(serializableValue.getValue());
} else {
dto.setValue(serializableValue.getValueSerialized());
}
} else if (typedValue instanceof FileValue) {
// do not set the value for FileValues since we don't want to send megabytes over the network without explicit request
} else {
dto.setValue(typedValue.getValue());
}
}
use of org.camunda.bpm.engine.variable.value.SerializableValue in project camunda-bpm-platform by camunda.
the class DefaultFormHandler method fireFormPropertyHistoryEvents.
protected void fireFormPropertyHistoryEvents(VariableMap properties, VariableScope variableScope) {
final ProcessEngineConfigurationImpl processEngineConfiguration = Context.getProcessEngineConfiguration();
HistoryLevel historyLevel = processEngineConfiguration.getHistoryLevel();
if (historyLevel.isHistoryEventProduced(HistoryEventTypes.FORM_PROPERTY_UPDATE, variableScope)) {
// fire history events
final ExecutionEntity executionEntity;
final String taskId;
if (variableScope instanceof ExecutionEntity) {
executionEntity = (ExecutionEntity) variableScope;
taskId = null;
} else if (variableScope instanceof TaskEntity) {
TaskEntity task = (TaskEntity) variableScope;
executionEntity = task.getExecution();
taskId = task.getId();
} else {
executionEntity = null;
taskId = null;
}
if (executionEntity != null) {
for (final String variableName : properties.keySet()) {
final TypedValue value = properties.getValueTyped(variableName);
// NOTE: SerializableValues are never stored as form properties
if (!(value instanceof SerializableValue) && value.getValue() != null && value.getValue() instanceof String) {
final String stringValue = (String) value.getValue();
HistoryEventProcessor.processHistoryEvents(new HistoryEventProcessor.HistoryEventCreator() {
@Override
public HistoryEvent createHistoryEvent(HistoryEventProducer producer) {
return producer.createFormPropertyUpdateEvt(executionEntity, variableName, stringValue, taskId);
}
});
}
}
}
}
}
use of org.camunda.bpm.engine.variable.value.SerializableValue in project camunda-bpm-platform by camunda.
the class AbstractSerializableValueSerializer method canWriteValue.
protected boolean canWriteValue(TypedValue typedValue) {
if (!(typedValue instanceof SerializableValue) && !(typedValue instanceof UntypedValueImpl)) {
return false;
}
if (typedValue instanceof SerializableValue) {
SerializableValue serializableValue = (SerializableValue) typedValue;
String requestedDataFormat = serializableValue.getSerializationDataFormat();
if (!serializableValue.isDeserialized()) {
// serialized object => dataformat must match
return serializationDataFormat.equals(requestedDataFormat);
} else {
final boolean canSerialize = typedValue.getValue() == null || canSerializeValue(typedValue.getValue());
return canSerialize && (requestedDataFormat == null || serializationDataFormat.equals(requestedDataFormat));
}
} else {
return typedValue.getValue() == null || canSerializeValue(typedValue.getValue());
}
}
use of org.camunda.bpm.engine.variable.value.SerializableValue in project camunda-bpm-platform by camunda.
the class PaContextSwitchTest method testNoContextSwitchOnInnerCommand.
/**
* This test ensures that when the {@link ProcessApplicationContext} API is used,
* the context switch is only performed for outer-most command and not if a second, nested
* command is executed; => in nested commands, the engine is already in the correct context
*/
@Test
@OperateOnDeployment("pa1")
public void testNoContextSwitchOnInnerCommand() throws Exception {
ProcessInstance pi = withProcessApplicationContext(new Callable<ProcessInstance>() {
@Override
public ProcessInstance call() throws Exception {
return runtimeService.startProcessInstanceByKey("process");
}
}, "pa2");
JsonSerializable expectedJsonSerializable = RuntimeServiceDelegate.createJsonSerializable();
String expectedJsonString = expectedJsonSerializable.toExpectedJsonString(JsonDataFormatConfigurator.DATE_FORMAT);
SerializableValue serializedValue = runtimeService.getVariableTyped(pi.getId(), RuntimeServiceDelegate.VARIABLE_NAME, false);
String actualJsonString = serializedValue.getValueSerialized();
ObjectMapper objectMapper = new ObjectMapper();
JsonNode actualJsonTree = objectMapper.readTree(actualJsonString);
JsonNode expectedJsonTree = objectMapper.readTree(expectedJsonString);
// JsonNode#equals makes a deep comparison
Assert.assertEquals(expectedJsonTree, actualJsonTree);
}
use of org.camunda.bpm.engine.variable.value.SerializableValue in project camunda-bpm-platform by camunda.
the class AbstractVariableScope method checkJavaSerialization.
/**
* Checks, if Java serialization will be used and if it is allowed to be used.
* @param variableName
* @param value
*/
protected void checkJavaSerialization(String variableName, TypedValue value) {
ProcessEngineConfigurationImpl processEngineConfiguration = Context.getProcessEngineConfiguration();
if (value instanceof SerializableValue && !processEngineConfiguration.isJavaSerializationFormatEnabled()) {
SerializableValue serializableValue = (SerializableValue) value;
// if Java serialization is prohibited
if (!serializableValue.isDeserialized()) {
String javaSerializationDataFormat = Variables.SerializationDataFormats.JAVA.getName();
String requestedDataFormat = serializableValue.getSerializationDataFormat();
if (requestedDataFormat == null) {
// check if Java serializer will be used
final TypedValueSerializer serializerForValue = TypedValueField.getSerializers().findSerializerForValue(serializableValue, processEngineConfiguration.getFallbackSerializerFactory());
if (serializerForValue != null) {
requestedDataFormat = serializerForValue.getSerializationDataformat();
}
}
if (javaSerializationDataFormat.equals(requestedDataFormat)) {
throw ProcessEngineLogger.CORE_LOGGER.javaSerializationProhibitedException(variableName);
}
}
}
}
Aggregations