Search in sources :

Example 1 with SerializableValue

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());
    }
}
Also used : FileValue(org.camunda.bpm.engine.variable.value.FileValue) SerializableValue(org.camunda.bpm.engine.variable.value.SerializableValue) SerializableValueType(org.camunda.bpm.engine.variable.type.SerializableValueType) FileValueType(org.camunda.bpm.engine.variable.type.FileValueType) ValueType(org.camunda.bpm.engine.variable.type.ValueType) PrimitiveValueType(org.camunda.bpm.engine.variable.type.PrimitiveValueType)

Example 2 with SerializableValue

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);
                        }
                    });
                }
            }
        }
    }
}
Also used : TaskEntity(org.camunda.bpm.engine.impl.persistence.entity.TaskEntity) ExecutionEntity(org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity) SerializableValue(org.camunda.bpm.engine.variable.value.SerializableValue) HistoryLevel(org.camunda.bpm.engine.impl.history.HistoryLevel) HistoryEventProcessor(org.camunda.bpm.engine.impl.history.event.HistoryEventProcessor) HistoryEventProducer(org.camunda.bpm.engine.impl.history.producer.HistoryEventProducer) HistoryEvent(org.camunda.bpm.engine.impl.history.event.HistoryEvent) ProcessEngineConfigurationImpl(org.camunda.bpm.engine.impl.cfg.ProcessEngineConfigurationImpl) TypedValue(org.camunda.bpm.engine.variable.value.TypedValue)

Example 3 with SerializableValue

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());
    }
}
Also used : UntypedValueImpl(org.camunda.bpm.engine.variable.impl.value.UntypedValueImpl) SerializableValue(org.camunda.bpm.engine.variable.value.SerializableValue)

Example 4 with SerializableValue

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);
}
Also used : SerializableValue(org.camunda.bpm.engine.variable.value.SerializableValue) JsonSerializable(org.camunda.bpm.integrationtest.functional.spin.dataformat.JsonSerializable) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) JsonNode(com.fasterxml.jackson.databind.JsonNode) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) OperateOnDeployment(org.jboss.arquillian.container.test.api.OperateOnDeployment) Test(org.junit.Test) AbstractFoxPlatformIntegrationTest(org.camunda.bpm.integrationtest.util.AbstractFoxPlatformIntegrationTest)

Example 5 with SerializableValue

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);
            }
        }
    }
}
Also used : SerializableValue(org.camunda.bpm.engine.variable.value.SerializableValue) TypedValueSerializer(org.camunda.bpm.engine.impl.variable.serializer.TypedValueSerializer) ProcessEngineConfigurationImpl(org.camunda.bpm.engine.impl.cfg.ProcessEngineConfigurationImpl)

Aggregations

SerializableValue (org.camunda.bpm.engine.variable.value.SerializableValue)5 ProcessEngineConfigurationImpl (org.camunda.bpm.engine.impl.cfg.ProcessEngineConfigurationImpl)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 HistoryLevel (org.camunda.bpm.engine.impl.history.HistoryLevel)1 HistoryEvent (org.camunda.bpm.engine.impl.history.event.HistoryEvent)1 HistoryEventProcessor (org.camunda.bpm.engine.impl.history.event.HistoryEventProcessor)1 HistoryEventProducer (org.camunda.bpm.engine.impl.history.producer.HistoryEventProducer)1 ExecutionEntity (org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity)1 TaskEntity (org.camunda.bpm.engine.impl.persistence.entity.TaskEntity)1 TypedValueSerializer (org.camunda.bpm.engine.impl.variable.serializer.TypedValueSerializer)1 ProcessInstance (org.camunda.bpm.engine.runtime.ProcessInstance)1 UntypedValueImpl (org.camunda.bpm.engine.variable.impl.value.UntypedValueImpl)1 FileValueType (org.camunda.bpm.engine.variable.type.FileValueType)1 PrimitiveValueType (org.camunda.bpm.engine.variable.type.PrimitiveValueType)1 SerializableValueType (org.camunda.bpm.engine.variable.type.SerializableValueType)1 ValueType (org.camunda.bpm.engine.variable.type.ValueType)1 FileValue (org.camunda.bpm.engine.variable.value.FileValue)1 TypedValue (org.camunda.bpm.engine.variable.value.TypedValue)1 JsonSerializable (org.camunda.bpm.integrationtest.functional.spin.dataformat.JsonSerializable)1