Skip to content

Commit

Permalink
Minor changes to the way variables are handled
Browse files Browse the repository at this point in the history
  • Loading branch information
aljoshakoecher committed Mar 25, 2022
1 parent cbedc28 commit 826a96f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,40 @@ public class ExecutionRequest {
private String skillIri;
private String commandTypeIri;
private Parameters[] parameters;
private Boolean selfResetting;


// Getters & Setters
public String getCommandTypeIri() {
return commandTypeIri;
}

public void setCommandTypeIri(String commandTypeIri) {
this.commandTypeIri = commandTypeIri;
}

public String getSkillIri() {
return skillIri;
}

public void setSkillIri(String skillIri) {
this.skillIri = skillIri;
}

public Parameters[] getParameters() {
return parameters;
}

public void setParameters(Parameters[] parameters) {
this.parameters = parameters;
}

public Boolean isSelfResetting() {
return this.selfResetting;
}


public void setSelfResetting(Boolean selfResetting) {
this.selfResetting = selfResetting;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ public void execute(DelegateExecution execution) throws Exception {
final String ERROR_ABORTING = "Error_Status_Aborting";
final String ERROR_STOPPING = "Error_Status_Stopping";

Boolean isSelfResetting = false;

/***** Reading variables and deserialize them *****/
System.out.println("Task " + execution.getCurrentActivityName() + " starting...");
Expand All @@ -54,9 +53,8 @@ public void execute(DelegateExecution execution) throws Exception {
ExecutionRequest executionRequest = gson.fromJson(execution.getVariable("executionRequest").toString(), ExecutionRequest.class);
System.out.println("Input msg: \n" + gson.toJson(executionRequest));

isSelfResetting = Boolean.parseBoolean(execution.getVariable("isSelfResetting").toString());
Boolean selfResetting = executionRequest.isSelfResetting();


/***** Create websocket listening to state changes *****/
CurrentStateSocket socket = new CurrentStateSocket(new URI("ws://localhost:9091/skills"), lockObject);

Expand Down Expand Up @@ -91,13 +89,15 @@ public void execute(DelegateExecution execution) throws Exception {
HttpResponse outputs = http.createRequest().post().url(EXECUTION_URL).contentType(CONTENT_TYPE).payload(gson.toJson(getOutputs)).execute();
System.out.println("Request getOutputs: \n" + gson.toJson(getOutputs));
System.out.println("Response getOutputs: \n" + outputs.getResponse());
Type skillResponseType = new TypeToken<ArrayList<SkillResponse>>() {}.getType();
List<SkillResponse> skillResponse = gson.fromJson(outputs.getResponse(), skillResponseType);
Type skillResponseType = new TypeToken<ArrayList<SkillResponse>>(){}.getType();
List<SkillResponse> skillResponses = gson.fromJson(outputs.getResponse(), skillResponseType);


// Every output gets set as "<activityID>_<output local name>"
for (int i = 0; i < skillResponse.size(); i++) {
for (SkillResponse skillResponse : skillResponses) {
String activityId = execution.getCurrentActivityId();
String variableId = activityId + "_" + skillResponse.get(i).getName();
execution.setVariable(variableId, skillResponse.get(i).getValue());
String variableId = activityId + "_" + skillResponse.getName();
execution.setVariable(variableId, skillResponse.getValue());
}

/***** Error handling *****/
Expand All @@ -120,7 +120,7 @@ public void execute(DelegateExecution execution) throws Exception {


/***** Reset task if selfResetting *****/
if (isSelfResetting) {
if (selfResetting) {
System.out.println("Self Resetting is activated. Resetting Task " + execution.getCurrentActivityName());
executionRequest.setCommandTypeIri(COMMAND_TYPE_IRI_RESET);
http.createRequest().post().url(EXECUTION_URL).contentType(CONTENT_TYPE).payload(gson.toJson(executionRequest)).execute();
Expand Down

0 comments on commit 826a96f

Please sign in to comment.