Skip to content

Commit 3552705

Browse files
authored
Merge pull request #2863 from objectcomputing/bugfix-2814/handle-partial-submissions
Bugfix 2814/handle partial submissions
2 parents f2dfdc3 + 22b6925 commit 3552705

File tree

5 files changed

+61
-104
lines changed

5 files changed

+61
-104
lines changed

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

Lines changed: 1 addition & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public class PulseResponse {
7777
protected PulseResponse() {
7878
}
7979

80-
public PulseResponse(UUID id, Integer internalScore, @Nullable Integer externalScore, LocalDate submissionDate, @Nullable UUID teamMemberId, String internalFeelings, String externalFeelings) {
80+
public PulseResponse(UUID id, Integer internalScore, @Nullable Integer externalScore, LocalDate submissionDate, @Nullable UUID teamMemberId, @Nullable String internalFeelings, @Nullable String externalFeelings) {
8181
this.id = id;
8282
this.internalScore = internalScore;
8383
this.externalScore = externalScore;
@@ -91,62 +91,6 @@ public PulseResponse(Integer internalScore, Integer externalScore, LocalDate sub
9191
this(null, internalScore, externalScore, submissionDate, teamMemberId, internalFeelings, externalFeelings);
9292
}
9393

94-
public UUID getId() {
95-
return this.id;
96-
}
97-
98-
public void setId(UUID id) {
99-
this.id = id;
100-
}
101-
102-
public Integer getInternalScore() {
103-
return internalScore;
104-
}
105-
106-
public void setInternalScore(Integer internalScore) {
107-
this.internalScore = internalScore;
108-
}
109-
110-
public Integer getExternalScore() {
111-
return externalScore;
112-
}
113-
114-
public void setExternalScore(Integer externalScore) {
115-
this.externalScore = externalScore;
116-
}
117-
118-
public LocalDate getSubmissionDate() {
119-
return submissionDate;
120-
}
121-
122-
public void setSubmissionDate(LocalDate submissionDate) {
123-
this.submissionDate = submissionDate;
124-
}
125-
126-
public UUID getTeamMemberId() {
127-
return this.teamMemberId;
128-
}
129-
130-
public void setTeamMemberId(UUID teamMemberId) {
131-
this.teamMemberId = teamMemberId;
132-
}
133-
134-
public String getInternalFeelings() {
135-
return internalFeelings;
136-
}
137-
138-
public void setInternalFeelings(String internalFeelings) {
139-
this.internalFeelings = internalFeelings;
140-
}
141-
142-
public String getExternalFeelings() {
143-
return externalFeelings;
144-
}
145-
146-
public void setExternalFeelings(String externalFeelings) {
147-
this.externalFeelings = externalFeelings;
148-
}
149-
15094
@Override
15195
public boolean equals(Object o) {
15296
if (this == o) return true;

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

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ public HttpResponse commandPulseResponse(
148148

149149
@Secured(SecurityRule.IS_ANONYMOUS)
150150
@Post(uri = "/external", consumes = MediaType.APPLICATION_FORM_URLENCODED)
151-
public HttpResponse<PulseResponse> externalPulseResponse(
151+
public HttpResponse externalPulseResponse(
152152
@Header("X-Slack-Signature") String signature,
153153
@Header("X-Slack-Request-Timestamp") String timestamp,
154154
@Body String requestBody,
@@ -174,6 +174,12 @@ public HttpResponse<PulseResponse> externalPulseResponse(
174174
PulseResponseCreateDTO pulseResponseDTO =
175175
slackPulseResponseConverter.get(memberProfileServices,
176176
(String)body.get(key));
177+
// If we receive a null DTO, that means that this is not the
178+
// actual submission of the form. We can just return 200 so
179+
// that Slack knows to continue without error.
180+
if (pulseResponseDTO == null) {
181+
return HttpResponse.ok();
182+
}
177183

178184
// DEBUG Only
179185
LOG.info("Request has been converted");
@@ -195,11 +201,7 @@ public HttpResponse<PulseResponse> externalPulseResponse(
195201
return HttpResponse.status(HttpStatus.CONFLICT,
196202
"Already submitted today");
197203
} else {
198-
return HttpResponse.created(pulseResponse)
199-
.headers(headers -> headers.location(
200-
URI.create(String.format("%s/%s",
201-
request.getPath(),
202-
pulseResponse.getId()))));
204+
return HttpResponse.ok();
203205
}
204206
} else {
205207
return HttpResponse.unprocessableEntity();

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

Lines changed: 48 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -35,42 +35,51 @@ public PulseResponseCreateDTO get(
3535
final ObjectMapper mapper = new ObjectMapper();
3636
final Map<String, Object> map =
3737
mapper.readValue(body, new TypeReference<>() {});
38-
final Map<String, Object> view =
39-
(Map<String, Object>)map.get("view");
40-
final Map<String, Object> state =
41-
(Map<String, Object>)view.get("state");
42-
final Map<String, Object> values =
43-
(Map<String, Object>)state.get("values");
44-
45-
dumpMap(values, "");
46-
47-
// Create the pulse DTO and fill in the values.
48-
PulseResponseCreateDTO response = new PulseResponseCreateDTO();
49-
response.setTeamMemberId(lookupUser(memberProfileServices, map));
50-
response.setSubmissionDate(LocalDate.now());
51-
52-
// Internal Score
53-
Map<String, Object> internalBlock =
54-
(Map<String, Object>)values.get("internalNumber");
55-
response.setInternalScore(Integer.parseInt(getMappedValue(
56-
internalBlock, "internalScore", "selected_option", true)));
57-
// Internal Feelings
58-
response.setInternalFeelings(getMappedValue(
59-
values, "internaltext", "internalFeelings", false));
60-
61-
// External Score
62-
Map<String, Object> externalBlock =
63-
(Map<String, Object>)values.get("externalNumber");
64-
String score = getMappedValue(externalBlock, "externalScore",
65-
"selected_option", false);
66-
if (score != null && !score.isEmpty()) {
67-
response.setExternalScore(Integer.parseInt(score));
38+
final String type = (String)map.get("type");
39+
40+
if (type.equals("view_submission")) {
41+
final Map<String, Object> view =
42+
(Map<String, Object>)map.get("view");
43+
final Map<String, Object> state =
44+
(Map<String, Object>)view.get("state");
45+
final Map<String, Object> values =
46+
(Map<String, Object>)state.get("values");
47+
48+
dumpMap(values, "");
49+
50+
// Create the pulse DTO and fill in the values.
51+
PulseResponseCreateDTO response = new PulseResponseCreateDTO();
52+
response.setTeamMemberId(lookupUser(memberProfileServices, map));
53+
response.setSubmissionDate(LocalDate.now());
54+
55+
// Internal Score
56+
Map<String, Object> internalBlock =
57+
(Map<String, Object>)values.get("internalNumber");
58+
response.setInternalScore(Integer.parseInt(getMappedValue(
59+
internalBlock, "internalScore", "selected_option", true)));
60+
// Internal Feelings
61+
response.setInternalFeelings(getMappedValue(
62+
values, "internaltext", "internalFeelings", false));
63+
64+
// External Score
65+
Map<String, Object> externalBlock =
66+
(Map<String, Object>)values.get("externalNumber");
67+
String score = getMappedValue(externalBlock, "externalScore",
68+
"selected_option", false);
69+
if (score != null && !score.isEmpty()) {
70+
response.setExternalScore(Integer.parseInt(score));
71+
}
72+
// External Feelings
73+
response.setExternalFeelings(getMappedValue(
74+
values, "externalText", "externalFeelings", false));
75+
76+
return response;
77+
} else {
78+
// If it's not a view submission, we need to return null so
79+
// the the caller knows that this is not the full pulse
80+
// response.
81+
return null;
6882
}
69-
// External Feelings
70-
response.setExternalFeelings(getMappedValue(
71-
values, "externalText", "externalFeelings", false));
72-
73-
return response;
7483
} catch(JsonProcessingException ex) {
7584
LOG.error(ex.getMessage());
7685
throw new BadArgException(ex.getMessage());
@@ -83,12 +92,12 @@ public PulseResponseCreateDTO get(
8392
private String getMappedValue(Map<String, Object> map, String key1,
8493
String key2, boolean required) {
8594
final String valueKey = "value";
86-
if (map.containsKey(key1)) {
95+
if (map != null && map.containsKey(key1)) {
8796
Map<String, Object> firstMap = (Map<String, Object>)map.get(key1);
88-
if (firstMap.containsKey(key2)) {
97+
if (firstMap != null && firstMap.containsKey(key2)) {
8998
final Map<String, Object> secondMap =
9099
(Map<String, Object>)firstMap.get(key2);
91-
if (secondMap.containsKey(valueKey)) {
100+
if (secondMap != null && secondMap.containsKey(valueKey)) {
92101
return (String)secondMap.get(valueKey);
93102
}
94103
}
@@ -100,7 +109,7 @@ private String getMappedValue(Map<String, Object> map, String key1,
100109
String.format("Expected %s.%s.%s was not found",
101110
key1, key2, valueKey));
102111
} else {
103-
return "";
112+
return null;
104113
}
105114
}
106115

server/src/main/resources/db/dev/R__Load_testing_data.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ VALUES
6060
INSERT INTO member_profile -- Unreal Ulysses
6161
(id, firstName, lastName, title, pdlid, location, workEmail, employeeid, startdate, biotext, supervisorid, birthDate, last_seen)
6262
VALUES
63-
('dfe2f986-fac0-11eb-9a03-0242ac130003', PGP_SYM_ENCRYPT('Unreal','${aeskey}'), PGP_SYM_ENCRYPT('Ulysses','${aeskey}'), PGP_SYM_ENCRYPT('Test Engineer 2','${aeskey}'), '1c813446-c65a-4f49-b980-0193f7bfff8c', PGP_SYM_ENCRYPT('St. Louis','${aeskey}'), PGP_SYM_ENCRYPT('[email protected]','${aeskey}'), '010101012', '2021-05-22', PGP_SYM_ENCRYPT('Test user 2','${aeskey}'), 'e4b2fe52-1915-4544-83c5-21b8f871f6db', '1950-01-01', '2021-05-22');
63+
('dfe2f986-fac0-11eb-9a03-0242ac130003', PGP_SYM_ENCRYPT('Unreal','${aeskey}'), PGP_SYM_ENCRYPT('Ulysses','${aeskey}'), PGP_SYM_ENCRYPT('Test Engineer 2','${aeskey}'), '1c813446-c65a-4f49-b980-0193f7bfff8c', PGP_SYM_ENCRYPT('St. Louis','${aeskey}'), PGP_SYM_ENCRYPT('[email protected]','${aeskey}'), '010101012', '2021-05-22', PGP_SYM_ENCRYPT('Test user 2','${aeskey}'), 'e4b2fe52-1915-4544-83c5-21b8f871f6db', '1950-02-01', '2021-05-22');
6464

6565
INSERT INTO member_profile -- Kazuhira Miller
6666
(id, firstName, lastName, title, pdlid, location, workEmail, employeeid, startdate, biotext, supervisorid, birthDate, last_seen)

web-ui/src/pages/PulseReportPage.jsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,9 @@ const PulseReportPage = () => {
228228
internalScores: []
229229
};
230230
}
231-
averages.externalScores.push(externalScore);
231+
if (externalScore != null) {
232+
averages.externalScores.push(externalScore);
233+
}
232234
averages.internalScores.push(internalScore);
233235
}
234236
}

0 commit comments

Comments
 (0)