Skip to content

Commit

Permalink
Pull request finos#60: SYMPHONYP-1135 summary field in workresponse
Browse files Browse the repository at this point in the history
Merge in SYMPHONYP/symphony-java-toolkit from feature/SYMPHONYP-1135-summary-feature to spring-bot-master-db

* commit '580710a949ac2c366075c0cb1db5c16141e0fb86':
  SYMPHONYP-1135 summary field in workresponse
  • Loading branch information
vaibhav-db committed Aug 7, 2024
2 parents f8762de + 580710a commit 6be5abe
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public class WorkResponse extends DataResponse {
public static final String DEFAULT_FORM_TEMPLATE_VIEW = "default-view";
public static final String ERRORS_KEY = "errors";
public static final String OBJECT_KEY = "form";
public static final String SUMMARY_KEY = "summary-key";

private final WorkMode mode;
private final Class<?> formClass;
Expand All @@ -45,13 +46,27 @@ public WorkResponse(Addressable to, Object o, WorkMode m) {
this(to, o, m, null, null);
}

/**
* Call this contructor to create a work response with summary
*/
public WorkResponse(Addressable to, Object o, WorkMode m, String summary) {
this(to, createEntityMapWithSummay(o, null, null, summary), getTemplateNameForObject(m, o), m, o.getClass());
}

public static Map<String, Object> createEntityMap(Object o, ButtonList buttons, ErrorMap errors) {
Map<String, Object> json = new HashMap<>();
json.put(ButtonList.KEY, buttons == null ? new ButtonList() : buttons);
json.put(ERRORS_KEY, errors == null ? new ErrorMap() : errors);
json.put(OBJECT_KEY, o);
return json;
}

public static Map<String, Object> createEntityMapWithSummay(Object o, ButtonList buttons, ErrorMap errors, String summary) {
Map<String, Object> map = createEntityMap(o, buttons, errors);
map.put(SUMMARY_KEY, summary);

return map;
}

public static String getTemplateNameForObject(WorkMode m, Object o) {
return getTemplateNameForClass(m, o.getClass());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,11 @@
import java.util.concurrent.CompletionException;
import java.util.function.BiFunction;

import org.apache.commons.lang3.StringUtils;
import org.finos.springbot.teams.TeamsException;
import org.finos.springbot.teams.content.TeamsAddressable;
import org.finos.springbot.teams.conversations.TeamsErrorResourceResponse;
import org.finos.springbot.teams.history.StorageIDResponseHandler;
import org.finos.springbot.teams.history.TeamsHistory;
import org.finos.springbot.teams.response.TeamsWorkResponse;
import org.finos.springbot.teams.response.templating.EntityMarkupTemplateProvider;
import org.finos.springbot.teams.response.templating.MarkupAndEntities;
import org.finos.springbot.teams.state.TeamsStateStorage;
Expand Down Expand Up @@ -114,12 +112,7 @@ public ResourceResponse apply(Response t) {

if (tt == TemplateType.ADAPTIVE_CARD) {
JsonNode cardJson = workTemplater.template(wr);
String responseSummary = null;
if( wr instanceof TeamsWorkResponse) {
responseSummary = ((TeamsWorkResponse) wr).getSummary() ;
}

return sendCardResponse(cardJson, ta, wr.getData(), responseSummary)
return sendCardResponse(cardJson, ta, wr.getData())
.handle(handleErrorAndStorage(cardJson, ta, wr.getData(), t)).get();
} else {
MarkupAndEntities mae = displayTemplater.template(wr);
Expand Down Expand Up @@ -178,13 +171,7 @@ private BiFunction<? super ResourceResponse, Throwable, ResourceResponse> handle
JsonNode buttonsJson = workTemplater.template(null);
wr.getData().put(AdaptiveCardTemplateProvider.FORMID_KEY, "just-buttons");
JsonNode expandedJson = workTemplater.applyTemplate(buttonsJson, wr);

String responseSummary = null;
if( wr instanceof TeamsWorkResponse) {
responseSummary = ((TeamsWorkResponse) wr).getSummary() ;
}

return sendCardResponse(expandedJson, (TeamsAddressable) wr.getAddress(), wr.getData(), responseSummary).get();
return sendCardResponse(expandedJson, (TeamsAddressable) wr.getAddress(), wr.getData()).get();
} else {
return rr;
}
Expand Down Expand Up @@ -232,13 +219,13 @@ private BiFunction<? super ResourceResponse, Throwable, ResourceResponse> handle
};
}

protected CompletableFuture<ResourceResponse> sendCardResponse(JsonNode json, TeamsAddressable address, Map<String, Object> data, String responseSummary) throws Exception {
protected CompletableFuture<ResourceResponse> sendCardResponse(JsonNode json, TeamsAddressable address, Map<String, Object> data) throws Exception {
Activity out = Activity.createMessageActivity();
Attachment body = new Attachment();
body.setContentType("application/vnd.microsoft.card.adaptive");
body.setContent(json);
if(StringUtils.isNotBlank(responseSummary)) {
out.setSummary(responseSummary);
if(data.containsKey(WorkResponse.SUMMARY_KEY)) {
out.setSummary(data.get(WorkResponse.SUMMARY_KEY).toString());
}
out.getAttachments().add(body);
return ah.handleActivity(out, address);
Expand Down

This file was deleted.

0 comments on commit 6be5abe

Please sign in to comment.