Skip to content

Commit

Permalink
Fixed Teams double-response issue #286
Browse files Browse the repository at this point in the history
  • Loading branch information
robmoffat committed Feb 1, 2022
1 parent 0371dd8 commit adf003b
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
Binary file modified .DS_Store
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

import java.util.Map;

import org.finos.springbot.workflow.annotations.Work;
import org.finos.springbot.workflow.response.Response;
import org.finos.springbot.workflow.response.WorkResponse;
import org.finos.springbot.workflow.response.handlers.ResponseHandler;
import org.finos.springbot.workflow.tags.TagSupport;

/**
* This class is responsible for generating a unique storage ID number and adding it
Expand All @@ -30,12 +32,23 @@ public StorageIDResponseHandler(TeamsHistory th) {
public void accept(Response t) {
if (t instanceof WorkResponse) {
Map<String, Object> data = ((WorkResponse) t).getData();
if ((data != null) && (!data.containsKey(STORAGE_ID_KEY))) {
if ((data != null) && (!data.containsKey(STORAGE_ID_KEY)) && (needsStoring(data))) {
data.put(STORAGE_ID_KEY, th.createStorageId());
}
}
}

private boolean needsStoring(Map<String, Object> data) {
for(Object o2: data.values()) {
Work w = o2 != null ? o2.getClass().getAnnotation(Work.class) : null;
if ((w != null) && (w.index())) {
return true;
}
}

return false;
}

@Override
public int getOrder() {
return ResponseHandler.HIGHEST_PRECEDENCE;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ public MessageActivityHandler(

@Override
protected CompletableFuture<Void> onMessageActivity(TurnContext turnContext) {
return CompletableFuture.completedFuture(null)
.thenRun(() -> handleActivity(turnContext));
}

protected void handleActivity(TurnContext turnContext) {
try {
Activity a = turnContext.getActivity();

Expand All @@ -81,9 +86,6 @@ protected CompletableFuture<Void> onMessageActivity(TurnContext turnContext) {
} finally {
CurrentTurnContext.CURRENT_CONTEXT.set(null);
}

// errors are handled using Spring's ErrorHandler rather than this.
return new CompletableFuture<Void>();
}

protected FormAction processForm(TurnContext turnContext, Activity a) throws ClassNotFoundException {
Expand Down

0 comments on commit adf003b

Please sign in to comment.