Skip to content

Commit c937472

Browse files
authored
Merge pull request #2861 from objectcomputing/bugfix-2814/add-block-id-for-values
It looks like a block id is required to retrieve values from the post…
2 parents f73d257 + 2368e10 commit c937472

File tree

2 files changed

+42
-12
lines changed

2 files changed

+42
-12
lines changed

server/src/main/java/com/objectcomputing/checkins/services/pulseresponse/SlackPulseResponseConverter.java

Lines changed: 38 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -42,22 +42,25 @@ public PulseResponseCreateDTO get(
4242
final Map<String, Object> values =
4343
(Map<String, Object>)state.get("values");
4444

45+
dumpMap(values, "");
46+
4547
// Create the pulse DTO and fill in the values.
4648
PulseResponseCreateDTO response = new PulseResponseCreateDTO();
4749
response.setTeamMemberId(lookupUser(memberProfileServices, map));
4850
response.setSubmissionDate(LocalDate.now());
4951

50-
response.setInternalScore(Integer.parseInt(
51-
getMappedValue(values, "internalScore", true)));
52-
response.setInternalFeelings(
53-
getMappedValue(values, "internalFeelings", false));
52+
response.setInternalScore(Integer.parseInt(getMappedValue(
53+
values, "internalNumber", "internalScore", true)));
54+
response.setInternalFeelings(getMappedValue(
55+
values, "internaltext", "internalFeelings", false));
5456

55-
String score = getMappedValue(values, "externalScore", false);
57+
String score = getMappedValue(values, "externalScore",
58+
"externalScore", false);
5659
if (!score.isEmpty()) {
5760
response.setExternalScore(Integer.parseInt(score));
5861
}
59-
response.setExternalFeelings(
60-
getMappedValue(values, "externalFeelings", false));
62+
response.setExternalFeelings(getMappedValue(
63+
values, "externalText", "externalFeelings", false));
6164

6265
return response;
6366
} catch(JsonProcessingException ex) {
@@ -69,20 +72,32 @@ public PulseResponseCreateDTO get(
6972
}
7073
}
7174

72-
private String getMappedValue(Map<String, Object> map,
75+
private String getMappedValue(Map<String, Object> map, String blockId,
7376
String key, boolean required) {
77+
if (!map.containsKey(blockId)) {
78+
if (required) {
79+
throw new BadArgException(
80+
String.format("Block ID - %s was not found", blockId));
81+
} else {
82+
return "";
83+
}
84+
}
85+
Map<String, Object> blockMap = (Map<String, Object>)map.get(blockId);
86+
7487
final String valueKey = "value";
75-
if (map.containsKey(key)) {
76-
final Map<String, Object> other = (Map<String, Object>)map.get(key);
88+
if (blockMap.containsKey(key)) {
89+
final Map<String, Object> other =
90+
(Map<String, Object>)blockMap.get(key);
7791
if (other.containsKey(valueKey)) {
7892
return (String)other.get(valueKey);
7993
}
8094
}
8195

8296
if (required) {
83-
LOG.error("Expected {}.{} was not found", key, valueKey);
97+
LOG.error("Expected {}.{}.{} was not found", blockId, key, valueKey);
8498
throw new BadArgException(
85-
String.format("Expected %s.%s was not found", key, valueKey));
99+
String.format("Expected %s.%s.%s was not found",
100+
blockId, key, valueKey));
86101
} else {
87102
return "";
88103
}
@@ -101,4 +116,15 @@ private UUID lookupUser(MemberProfileServices memberProfileServices,
101116
MemberProfile member = memberProfileServices.findByWorkEmail(email);
102117
return member.getId();
103118
}
119+
120+
// DEBUG Only
121+
private void dumpMap(Map<?, ?> map, String indent) {
122+
for (Map.Entry<?, ?> entry : map.entrySet()) {
123+
LOG.info(indent + entry.getKey() + " : " + entry.getValue());
124+
125+
if (entry.getValue() instanceof Map) {
126+
dumpMap((Map<?, ?>) entry.getValue(), indent + " ");
127+
}
128+
}
129+
}
104130
}

server/src/main/resources/slack/pulse_slack_blocks.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"blocks": [
1919
{
2020
"type": "section",
21+
"block_id": "internalNumber",
2122
"text": {
2223
"type": "plain_text",
2324
"text": "How are you feeling about work today?"
@@ -71,6 +72,7 @@
7172
},
7273
{
7374
"type": "input",
75+
"block_id": "internalText",
7476
"optional": true,
7577
"element": {
7678
"type": "plain_text_input",
@@ -88,6 +90,7 @@
8890
},
8991
{
9092
"type": "section",
93+
"block_id": "externalNumber",
9194
"text": {
9295
"type": "plain_text",
9396
"text": "How are you feeling about life outside of work?"
@@ -141,6 +144,7 @@
141144
},
142145
{
143146
"type": "input",
147+
"block_id": "externalText",
144148
"optional": true,
145149
"element": {
146150
"type": "plain_text_input",

0 commit comments

Comments
 (0)