Skip to content

Commit

Permalink
Handle required and optional values from Pulse submissions via Slack.
Browse files Browse the repository at this point in the history
  • Loading branch information
ocielliottc committed Jan 10, 2025
1 parent a8cb08f commit a11ffaf
Showing 1 changed file with 27 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,26 +35,46 @@ public static PulseResponseCreateDTO get(
PulseResponseCreateDTO response = new PulseResponseCreateDTO();
response.setTeamMemberId(lookupUser(memberProfileServices, map));
response.setSubmissionDate(LocalDate.now());

response.setInternalScore(Integer.parseInt(
getMappedValue(values, "internalScore")));
getMappedValue(values, "internalScore", true)));
response.setInternalFeelings(
getMappedValue(values, "internalFeelings"));
response.setExternalScore(Integer.parseInt(
getMappedValue(values, "externalScore")));
getMappedValue(values, "internalFeelings", false));

String score = getMappedValue(values, "externalScore", false);
if (!score.isEmpty()) {
response.setExternalScore(Integer.parseInt(score));
}
response.setExternalFeelings(
getMappedValue(values, "externalFeelings"));
getMappedValue(values, "externalFeelings", false));

return response;
} catch(JsonProcessingException ex) {
throw new BadArgException(ex.getMessage());
} catch(NumberFormatException ex) {
throw new BadArgException("Pulse scores must be integers");
}
} else {
throw new BadArgException("Invalid pulse response body");
}
}

private static String getMappedValue(Map<String, Object> map, String key) {
return (String)((Map<String, Object>)map.get(key)).get("value");
private static String getMappedValue(Map<String, Object> map,
String key, boolean required) {
final String valueKey = "value";
if (map.containsKey(key)) {
final Map<String, Object> other = (Map<String, Object>)map.get(key);
if (other.containsKey(valueKey)) {
return (String)other.get(valueKey);
}
}

if (required) {
throw new BadArgException(
String.format("Expected %s.%s was not found", key, valueKey));
} else {
return "";
}
}

private static UUID lookupUser(MemberProfileServices memberProfileServices,
Expand Down

0 comments on commit a11ffaf

Please sign in to comment.