diff --git a/clients/java/client/src/it/java/org/camunda/bpm/client/variable/FileSerializationIT.java b/clients/java/client/src/it/java/org/camunda/bpm/client/variable/FileSerializationIT.java index 49522436d05..c36af2da712 100644 --- a/clients/java/client/src/it/java/org/camunda/bpm/client/variable/FileSerializationIT.java +++ b/clients/java/client/src/it/java/org/camunda/bpm/client/variable/FileSerializationIT.java @@ -46,10 +46,12 @@ import org.camunda.bpm.client.util.RecordingExternalTaskHandler; import org.camunda.bpm.client.util.RecordingInvocationHandler; import org.camunda.bpm.client.util.RecordingInvocationHandler.RecordedInvocation; +import org.camunda.bpm.client.variable.impl.value.DeferredFileValueImpl; import org.camunda.bpm.client.variable.value.DeferredFileValue; import org.camunda.bpm.engine.variable.Variables; import org.camunda.bpm.engine.variable.value.FileValue; import org.camunda.bpm.engine.variable.value.TypedValue; +import org.camunda.bpm.model.bpmn.Bpmn; import org.camunda.bpm.model.bpmn.BpmnModelInstance; import org.camunda.commons.utils.IoUtil; import org.junit.Before; @@ -63,6 +65,8 @@ public class FileSerializationIT { protected static final String VARIABLE_NAME_FILE = "fileVariable"; protected static final String VARIABLE_VALUE_FILE_NAME = "aFileName.txt"; protected static final byte[] VARIABLE_VALUE_FILE_VALUE = "ABC".getBytes(); + protected static final String LOCAL_VARIABLE_NAME_FILE = "localFileName.txt"; + protected static final String VARIABLE_VALUE_FILE_ENCODING = "UTF-8"; protected static final String VARIABLE_VALUE_FILE_MIME_TYPE = "text/plain"; @@ -117,6 +121,41 @@ public void shouldGet() { .isEqualTo(new String(VARIABLE_VALUE_FILE_VALUE)); } + @Test + public void shouldGetLocalAndGlobalVariables() { + // given + ProcessDefinitionDto processDefinitionDto = engineRule.deploy( + Bpmn.createExecutableProcess("process") + .startEvent("startEvent") + .serviceTask("serviceTaskFoo") + .camundaExternalTask(EXTERNAL_TASK_TOPIC_FOO) + // create the local file variable with the same content but different name + .camundaInputParameter(LOCAL_VARIABLE_NAME_FILE, "${execution.getVariableTyped('fileVariable')}") + .serviceTask("serviceTaskBar") + .camundaExternalTask(EXTERNAL_TASK_TOPIC_BAR) + .endEvent("endEvent") + .done() + ).get(0); + + engineRule.startProcessInstance(processDefinitionDto.getId(), VARIABLE_NAME_FILE, VARIABLE_VALUE_FILE); + + // when + client.subscribe(EXTERNAL_TASK_TOPIC_FOO) + .handler(handler) + .open(); + + clientRule.waitForFetchAndLockUntil(() -> !handler.getHandledTasks().isEmpty()); + + ExternalTask task = handler.getHandledTasks().get(0); + + // then + assertThat(task.getAllVariables().size()).isEqualTo(2); + assertThat(IoUtil.inputStreamAsString(task.getVariable(VARIABLE_NAME_FILE))) + .isEqualTo(new String(VARIABLE_VALUE_FILE_VALUE)); + assertThat(IoUtil.inputStreamAsString(task.getVariable(LOCAL_VARIABLE_NAME_FILE))) + .isEqualTo(new String(VARIABLE_VALUE_FILE_VALUE)); + } + @Test public void shouldGetAll() { // given @@ -145,7 +184,9 @@ public void shouldGetAll() { @Test public void shouldGetTyped_Deferred() { // given - engineRule.startProcessInstance(processDefinition.getId(), VARIABLE_NAME_FILE, VARIABLE_VALUE_FILE); + ProcessInstanceDto processInstanceDto = engineRule.startProcessInstance(processDefinition.getId(), + VARIABLE_NAME_FILE, + VARIABLE_VALUE_FILE); client.subscribe(EXTERNAL_TASK_TOPIC_FOO) .handler(handler) @@ -163,6 +204,48 @@ public void shouldGetTyped_Deferred() { assertThat(typedValue.isLoaded()).isFalse(); assertThat(typedValue.getEncoding()).isNull(); assertThat(typedValue.getMimeType()).isNull(); + + DeferredFileValueImpl typedValueImpl = (DeferredFileValueImpl) typedValue; + assertThat(typedValueImpl.getExecutionId()).isEqualTo(task.getExecutionId()); + } + + @Test + public void shouldGetVariableTypedForLocalVariable() { + // given + ProcessDefinitionDto processDefinitionDto = engineRule.deploy( + Bpmn.createExecutableProcess("process") + .startEvent("startEvent") + .serviceTask("serviceTaskFoo") + .camundaExternalTask(EXTERNAL_TASK_TOPIC_FOO) + // create the local file variable with the same content but different name + .camundaInputParameter(LOCAL_VARIABLE_NAME_FILE, "${execution.getVariableTyped('fileVariable')}") + .serviceTask("serviceTaskBar") + .camundaExternalTask(EXTERNAL_TASK_TOPIC_BAR) + .endEvent("endEvent") + .done() + ).get(0); + + engineRule.startProcessInstance(processDefinitionDto.getId(), VARIABLE_NAME_FILE, VARIABLE_VALUE_FILE); + + // when + client.subscribe(EXTERNAL_TASK_TOPIC_FOO) + .handler(handler) + .open(); + + clientRule.waitForFetchAndLockUntil(() -> !handler.getHandledTasks().isEmpty()); + + ExternalTask task = handler.getHandledTasks().get(0); + + // then + DeferredFileValue typedValue = task.getVariableTyped(LOCAL_VARIABLE_NAME_FILE); + assertThat(typedValue.getFilename()).isEqualTo(VARIABLE_VALUE_FILE_NAME); + assertThat(typedValue.getType()).isEqualTo(FILE); + assertThat(typedValue.isLoaded()).isFalse(); + assertThat(typedValue.getEncoding()).isNull(); + assertThat(typedValue.getMimeType()).isNull(); + + InputStream value = typedValue.getValue(); + assertThat(IoUtil.inputStreamAsString(value)).isEqualTo(new String(VARIABLE_VALUE_FILE_VALUE)); } @Test diff --git a/clients/java/client/src/main/java/org/camunda/bpm/client/task/impl/ExternalTaskImpl.java b/clients/java/client/src/main/java/org/camunda/bpm/client/task/impl/ExternalTaskImpl.java index ad8c00061e9..f1223d45ff2 100644 --- a/clients/java/client/src/main/java/org/camunda/bpm/client/task/impl/ExternalTaskImpl.java +++ b/clients/java/client/src/main/java/org/camunda/bpm/client/task/impl/ExternalTaskImpl.java @@ -25,7 +25,6 @@ import org.camunda.bpm.client.task.ExternalTask; import org.camunda.bpm.client.variable.impl.TypedValueField; import org.camunda.bpm.client.variable.impl.VariableValue; -import org.camunda.bpm.client.variable.value.DeferredFileValue; import org.camunda.bpm.engine.variable.VariableMap; import org.camunda.bpm.engine.variable.Variables; import org.camunda.bpm.engine.variable.value.TypedValue; @@ -258,10 +257,6 @@ public T getVariable(String variableName) { VariableValue variableValue = receivedVariableMap.get(variableName); if (variableValue != null) { - if(variableValue.getTypedValue() instanceof DeferredFileValue) { - DeferredFileValue deferredFileValue = (DeferredFileValue) variableValue.getTypedValue(); - deferredFileValue.setExecutionId(this.executionId); - } value = (T) variableValue.getValue(); } @@ -300,10 +295,6 @@ public T getVariableTyped(String variableName, boolean de VariableValue variableValue = receivedVariableMap.get(variableName); if (variableValue != null) { typedValue = variableValue.getTypedValue(deserializeObjectValues); - if(typedValue instanceof DeferredFileValue) { - DeferredFileValue deferredFileValue = (DeferredFileValue) typedValue; - deferredFileValue.setExecutionId(this.executionId); - } } return (T) typedValue; diff --git a/clients/java/client/src/main/java/org/camunda/bpm/client/variable/impl/TypedValues.java b/clients/java/client/src/main/java/org/camunda/bpm/client/variable/impl/TypedValues.java index f72e7adbf39..cd72d1b9282 100644 --- a/clients/java/client/src/main/java/org/camunda/bpm/client/variable/impl/TypedValues.java +++ b/clients/java/client/src/main/java/org/camunda/bpm/client/variable/impl/TypedValues.java @@ -69,7 +69,7 @@ public Map serializeVariables(Map varia @SuppressWarnings("rawtypes") public Map wrapVariables(ExternalTask externalTask, Map variables) { - String processInstanceId = externalTask.getProcessInstanceId(); + String executionId = externalTask.getExecutionId(); Map result = new HashMap<>(); @@ -80,7 +80,7 @@ public Map wrapVariables(ExternalTask externalTask, Map { - protected String processInstanceId; + protected String executionId; protected String variableName; protected TypedValueField typedValueField; protected ValueMappers mappers; @@ -30,8 +30,8 @@ public class VariableValue { protected ValueMapper serializer; protected T cachedValue; - public VariableValue(String processInstanceId, String variableName, TypedValueField typedValueField, ValueMappers mappers) { - this.processInstanceId = processInstanceId; + public VariableValue(String executionId, String variableName, TypedValueField typedValueField, ValueMappers mappers) { + this.executionId = executionId; this.variableName = variableName; this.typedValueField = typedValueField; this.mappers = mappers; @@ -63,7 +63,7 @@ public T getTypedValue(boolean deserializeValue) { if (cachedValue instanceof DeferredFileValueImpl) { DeferredFileValueImpl fileValue = (DeferredFileValueImpl) cachedValue; - fileValue.setProcessInstanceId(processInstanceId); + fileValue.setExecutionId(executionId); fileValue.setVariableName(variableName); } } @@ -83,7 +83,7 @@ public ValueMapper getSerializer() { public String toString() { return "VariableValue [" + "cachedValue=" + cachedValue + ", " - + "processInstanceId=" + processInstanceId + ", " + + "executionId=" + executionId + ", " + "variableName=" + variableName + ", " + "typedValueField=" + typedValueField + "]"; } diff --git a/clients/java/client/src/main/java/org/camunda/bpm/client/variable/impl/value/DeferredFileValueImpl.java b/clients/java/client/src/main/java/org/camunda/bpm/client/variable/impl/value/DeferredFileValueImpl.java index aeea49e855a..bc973e280c0 100644 --- a/clients/java/client/src/main/java/org/camunda/bpm/client/variable/impl/value/DeferredFileValueImpl.java +++ b/clients/java/client/src/main/java/org/camunda/bpm/client/variable/impl/value/DeferredFileValueImpl.java @@ -37,9 +37,8 @@ public class DeferredFileValueImpl extends FileValueImpl implements DeferredFile protected boolean isLoaded = false; protected String variableName; - protected String processInstanceId; + protected String executionId; protected EngineClient engineClient; - protected String executionId = null; public DeferredFileValueImpl(String filename, EngineClient engineClient) { super(PrimitiveValueType.FILE, filename); @@ -72,20 +71,14 @@ public InputStream getValue() { return super.getValue(); } - public void setProcessInstanceId(String processInstanceId) { - this.processInstanceId = processInstanceId; - } - public void setVariableName(String variableName) { this.variableName = variableName; } - @Override public void setExecutionId(String executionId){ this.executionId = executionId; }; - @Override public String getExecutionId() { return executionId; } @@ -93,7 +86,7 @@ public String getExecutionId() { @Override public String toString() { return "DeferredFileValueImpl [mimeType=" + mimeType + ", filename=" + filename + ", type=" + type + ", " - + "isTransient=" + isTransient + ", isLoaded=" + isLoaded + ", processInstanceId" + processInstanceId + ", executionId" + executionId + "]"; + + "isTransient=" + isTransient + ", isLoaded=" + isLoaded + "]"; } } diff --git a/clients/java/client/src/main/java/org/camunda/bpm/client/variable/value/DeferredFileValue.java b/clients/java/client/src/main/java/org/camunda/bpm/client/variable/value/DeferredFileValue.java index c8158ff55de..1eea30f8e93 100644 --- a/clients/java/client/src/main/java/org/camunda/bpm/client/variable/value/DeferredFileValue.java +++ b/clients/java/client/src/main/java/org/camunda/bpm/client/variable/value/DeferredFileValue.java @@ -39,20 +39,4 @@ public interface DeferredFileValue extends FileValue { */ boolean isLoaded(); - /** - * Sets the executionId, which defines the scope of the DeferredFileValue. - * This identifier ensures that the correct scope is applied when loading the file value. - * - * @param executionId defines the scope of the DeferredFileValue - */ - void setExecutionId(String executionId); - - /** - * Returns the executionId, which specifies the scope of the DeferredFileValue. - * This identifier ensures that the correct scope is applied when loading the file value. - * - * @return the executionId which defines the scope of the DeferredFileValue - */ - String getExecutionId(); - } diff --git a/clients/java/client/src/test/java/org/camunda/bpm/client/task/ExternalTaskImplTest.java b/clients/java/client/src/test/java/org/camunda/bpm/client/task/ExternalTaskImplTest.java index 65d504eddde..9cd1e151c10 100644 --- a/clients/java/client/src/test/java/org/camunda/bpm/client/task/ExternalTaskImplTest.java +++ b/clients/java/client/src/test/java/org/camunda/bpm/client/task/ExternalTaskImplTest.java @@ -139,8 +139,8 @@ public void shouldDisplayAttributesIncludingMapsInToString() { task.setWorkerId("wi"); Map receivedVariables = new LinkedHashMap<>(); - receivedVariables.put("rv1", generateVariableValue("pii", "variable1", ValueType.STRING.getName(), "value1", 42, "vi2")); - receivedVariables.put("rv2", generateVariableValue("pii", "variable2", ValueType.INTEGER.getName(), 99, 42, "vi2", 87L)); + receivedVariables.put("rv1", generateVariableValue(task.getExecutionId(), "variable1", ValueType.STRING.getName(), "value1", 42, "vi2")); + receivedVariables.put("rv2", generateVariableValue(task.getExecutionId(), "variable2", ValueType.INTEGER.getName(), 99, 42, "vi2", 87L)); task.setReceivedVariableMap(receivedVariables); Map variables = new LinkedHashMap<>(); @@ -163,9 +163,9 @@ public void shouldDisplayAttributesIncludingMapsInToString() { + "processDefinitionVersionTag=versionTag, " + "processInstanceId=pii, " + "receivedVariableMap={" - + "rv1=VariableValue [cachedValue=null, processInstanceId=pii, variableName=variable1, typedValueField=" + + "rv1=VariableValue [cachedValue=null, executionId=ei, variableName=variable1, typedValueField=" + "TypedValueField [type=string, value=value1, valueInfo={vi1=42, vi2=vi2}]], " - + "rv2=VariableValue [cachedValue=null, processInstanceId=pii, variableName=variable2, typedValueField=" + + "rv2=VariableValue [cachedValue=null, executionId=ei, variableName=variable2, typedValueField=" + "TypedValueField [type=integer, value=99, valueInfo={vi1=42, vi2=vi2, vi3=87}]]" + "}, " + "retries=34, " @@ -184,10 +184,10 @@ public void shouldDisplayAttributesIncludingMapsInToString() { private static final ValueMappers DEFAULT_MAPPERS = new DefaultValueMappers(Variables.SerializationDataFormats.JSON.getName()); @SuppressWarnings("rawtypes") - private static VariableValue generateVariableValue(String processInstanceId, String variableName, + private static VariableValue generateVariableValue(String executionId, String variableName, final String typeI, final Object valueI, Object... valueInfos) { TypedValueField typedValueField = generateTypedValueField(typeI, valueI, valueInfos); - return new VariableValue(processInstanceId, variableName, typedValueField, DEFAULT_MAPPERS); + return new VariableValue(executionId, variableName, typedValueField, DEFAULT_MAPPERS); } private static TypedValueField generateTypedValueField(final String typeI, final Object valueI, Object... valueInfos) {