Skip to content

Commit

Permalink
fix(client): load local file variable
Browse files Browse the repository at this point in the history
related to: #4523
  • Loading branch information
venetrius committed Sep 11, 2024
1 parent b834519 commit 3238977
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,10 @@ public class EngineClient {
public static final String FAILURE_RESOURCE_PATH = ID_RESOURCE_PATH + "/failure";
public static final String BPMN_ERROR_RESOURCE_PATH = ID_RESOURCE_PATH + "/bpmnError";
public static final String NAME_PATH_PARAM = "{name}";
public static final String EXECUTION_RESOURCE_PATH = "/execution";
public static final String EXECUTION_ID_RESOURCE_PATH = EXECUTION_RESOURCE_PATH + "/" + ID_PATH_PARAM;
public static final String GET_LOCAL_VARIABLE = EXECUTION_ID_RESOURCE_PATH + "/localVariables/" + NAME_PATH_PARAM;
public static final String GET_LOCAL_BINARY_VARIABLE = GET_LOCAL_VARIABLE + "/data";

public static final String PROCESS_INSTANCE_RESOURCE_PATH = "/process-instance";
public static final String PROCESS_INSTANCE_ID_RESOURCE_PATH = PROCESS_INSTANCE_RESOURCE_PATH + "/" + ID_PATH_PARAM;
public static final String GET_BINARY_VARIABLE =
PROCESS_INSTANCE_ID_RESOURCE_PATH + "/variables/" + NAME_PATH_PARAM + "/data";
protected String baseUrl;
protected String workerId;
protected int maxTasks;
Expand Down Expand Up @@ -147,9 +146,9 @@ public void extendLock(String taskId, long newDuration) {
engineInteraction.postRequest(resourceUrl, payload, Void.class);
}

public byte[] getLocalBinaryVariable(String variableName, String processInstanceId) {
String resourcePath = baseUrl + GET_LOCAL_BINARY_VARIABLE
.replace(ID_PATH_PARAM, processInstanceId)
public byte[] getLocalBinaryVariable(String variableName, String executionId) {
String resourcePath = baseUrl + GET_BINARY_VARIABLE
.replace(ID_PATH_PARAM, executionId)
.replace(NAME_PATH_PARAM, variableName);

return engineInteraction.getRequest(resourcePath);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
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;
Expand Down Expand Up @@ -257,6 +258,10 @@ public <T> 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();
}

Expand Down Expand Up @@ -295,6 +300,10 @@ public <T extends TypedValue> 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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public class DeferredFileValueImpl extends FileValueImpl implements DeferredFile
protected String variableName;
protected String processInstanceId;
protected EngineClient engineClient;
protected String executionId = null;

public DeferredFileValueImpl(String filename, EngineClient engineClient) {
super(PrimitiveValueType.FILE, filename);
Expand All @@ -47,7 +48,7 @@ public DeferredFileValueImpl(String filename, EngineClient engineClient) {

protected void load() {
try {
byte[] bytes = engineClient.getLocalBinaryVariable(variableName, processInstanceId);
byte[] bytes = engineClient.getLocalBinaryVariable(variableName, executionId);
setValue(bytes);

this.isLoaded = true;
Expand Down Expand Up @@ -84,4 +85,14 @@ public String toString() {
return "DeferredFileValueImpl [mimeType=" + mimeType + ", filename=" + filename + ", type=" + type + ", isTransient=" + isTransient + ", isLoaded=" + isLoaded + "]";
}

@Override
public void setExecutionId(String executionId){
this.executionId = executionId;
};

@Override
public String getExecutionId() {
return executionId;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,8 @@ public interface DeferredFileValue extends FileValue {
*/
boolean isLoaded();

void setExecutionId(String executionId);

String getExecutionId();

}

0 comments on commit 3238977

Please sign in to comment.