Skip to content

Commit

Permalink
refactor(engine): Extract duplicated code for converting variables
Browse files Browse the repository at this point in the history
  • Loading branch information
saig0 committed Feb 8, 2024
1 parent bc7f8d8 commit d762234
Showing 1 changed file with 12 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ public void completeJob(

final String variables = request.getVariables();
if (!variables.isEmpty()) {
jobRecord.setVariables(BufferUtil.wrapArray(MsgPackConverter.convertToMsgPack(variables)));
jobRecord.setVariables(convertVariablesToMessagePack(variables));
}

writer.writeCommandWithKey(request.getJobKey(), jobRecord, recordMetadata);
Expand Down Expand Up @@ -373,7 +373,7 @@ public void throwError(

final String variables = request.getVariables();
if (!variables.isEmpty()) {
jobRecord.setVariables(BufferUtil.wrapArray(MsgPackConverter.convertToMsgPack(variables)));
jobRecord.setVariables(convertVariablesToMessagePack(variables));
}

writer.writeCommandWithKey(request.getJobKey(), jobRecord, recordMetadata);
Expand All @@ -400,8 +400,7 @@ public void publishMessage(
messageRecord.setTimeToLive(request.getTimeToLive());
final String variables = request.getVariables();
if (!variables.isEmpty()) {
messageRecord.setVariables(
BufferUtil.wrapArray(MsgPackConverter.convertToMsgPack(variables)));
messageRecord.setVariables(convertVariablesToMessagePack(variables));
}

writer.writeCommandWithoutKey(messageRecord, recordMetadata);
Expand Down Expand Up @@ -442,8 +441,7 @@ public void setVariables(

final String variables = request.getVariables();
if (!variables.isEmpty()) {
variableDocumentRecord.setVariables(
BufferUtil.wrapArray(MsgPackConverter.convertToMsgPack(variables)));
variableDocumentRecord.setVariables(convertVariablesToMessagePack(variables));
}

variableDocumentRecord.setScopeKey(request.getElementInstanceKey());
Expand Down Expand Up @@ -596,8 +594,7 @@ public void broadcastSignal(
final SignalRecord command = new SignalRecord().setSignalName(request.getSignalName());

if (!request.getVariables().isEmpty()) {
command.setVariables(
BufferUtil.wrapArray(MsgPackConverter.convertToMsgPack(request.getVariables())));
command.setVariables(convertVariablesToMessagePack(request.getVariables()));
}

writer.writeCommandWithoutKey(
Expand Down Expand Up @@ -629,9 +626,7 @@ final var record = new ProcessInstanceModificationRecord();
instruction.addVariableInstruction(
new ProcessInstanceModificationVariableInstruction()
.setElementId(variable.getScopeId())
.setVariables(
BufferUtil.wrapArray(
MsgPackConverter.convertToMsgPack(variable.getVariables()))));
.setVariables(convertVariablesToMessagePack(variable.getVariables())));
}

record.addActivateInstruction(instruction);
Expand Down Expand Up @@ -668,8 +663,7 @@ private ProcessInstanceCreationRecord createProcessInstanceCreationRecord(

final String variables = request.getVariables();
if (!variables.isEmpty()) {
processInstanceCreationRecord.setVariables(
BufferUtil.wrapArray(MsgPackConverter.convertToMsgPack(variables)));
processInstanceCreationRecord.setVariables(convertVariablesToMessagePack(variables));
}
return processInstanceCreationRecord;
}
Expand All @@ -686,12 +680,16 @@ private DecisionEvaluationRecord createDecisionEvaluationRecord(

final String variables = request.getVariables();
if (!variables.isEmpty()) {
record.setVariables(BufferUtil.wrapArray(MsgPackConverter.convertToMsgPack(variables)));
record.setVariables(convertVariablesToMessagePack(variables));
}

return record;
}

private static DirectBuffer convertVariablesToMessagePack(final String variables) {
return BufferUtil.wrapArray(MsgPackConverter.convertToMsgPack(variables));
}

public String getAddress() {
return "0.0.0.0:" + port;
}
Expand Down

0 comments on commit d762234

Please sign in to comment.