Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public class PulseResponse {
protected PulseResponse() {
}

public PulseResponse(UUID id, Integer internalScore, @Nullable Integer externalScore, LocalDate submissionDate, @Nullable UUID teamMemberId, String internalFeelings, String externalFeelings) {
public PulseResponse(UUID id, Integer internalScore, @Nullable Integer externalScore, LocalDate submissionDate, @Nullable UUID teamMemberId, @Nullable String internalFeelings, @Nullable String externalFeelings) {
this.id = id;
this.internalScore = internalScore;
this.externalScore = externalScore;
Expand All @@ -91,62 +91,6 @@ public PulseResponse(Integer internalScore, Integer externalScore, LocalDate sub
this(null, internalScore, externalScore, submissionDate, teamMemberId, internalFeelings, externalFeelings);
}

public UUID getId() {
return this.id;
}

public void setId(UUID id) {
this.id = id;
}

public Integer getInternalScore() {
return internalScore;
}

public void setInternalScore(Integer internalScore) {
this.internalScore = internalScore;
}

public Integer getExternalScore() {
return externalScore;
}

public void setExternalScore(Integer externalScore) {
this.externalScore = externalScore;
}

public LocalDate getSubmissionDate() {
return submissionDate;
}

public void setSubmissionDate(LocalDate submissionDate) {
this.submissionDate = submissionDate;
}

public UUID getTeamMemberId() {
return this.teamMemberId;
}

public void setTeamMemberId(UUID teamMemberId) {
this.teamMemberId = teamMemberId;
}

public String getInternalFeelings() {
return internalFeelings;
}

public void setInternalFeelings(String internalFeelings) {
this.internalFeelings = internalFeelings;
}

public String getExternalFeelings() {
return externalFeelings;
}

public void setExternalFeelings(String externalFeelings) {
this.externalFeelings = externalFeelings;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ public HttpResponse commandPulseResponse(

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

// DEBUG Only
LOG.info("Request has been converted");
Expand All @@ -195,11 +201,7 @@ public HttpResponse<PulseResponse> externalPulseResponse(
return HttpResponse.status(HttpStatus.CONFLICT,
"Already submitted today");
} else {
return HttpResponse.created(pulseResponse)
.headers(headers -> headers.location(
URI.create(String.format("%s/%s",
request.getPath(),
pulseResponse.getId()))));
return HttpResponse.ok();
}
} else {
return HttpResponse.unprocessableEntity();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,42 +35,51 @@ public PulseResponseCreateDTO get(
final ObjectMapper mapper = new ObjectMapper();
final Map<String, Object> map =
mapper.readValue(body, new TypeReference<>() {});
final Map<String, Object> view =
(Map<String, Object>)map.get("view");
final Map<String, Object> state =
(Map<String, Object>)view.get("state");
final Map<String, Object> values =
(Map<String, Object>)state.get("values");

dumpMap(values, "");

// Create the pulse DTO and fill in the values.
PulseResponseCreateDTO response = new PulseResponseCreateDTO();
response.setTeamMemberId(lookupUser(memberProfileServices, map));
response.setSubmissionDate(LocalDate.now());

// Internal Score
Map<String, Object> internalBlock =
(Map<String, Object>)values.get("internalNumber");
response.setInternalScore(Integer.parseInt(getMappedValue(
internalBlock, "internalScore", "selected_option", true)));
// Internal Feelings
response.setInternalFeelings(getMappedValue(
values, "internaltext", "internalFeelings", false));

// External Score
Map<String, Object> externalBlock =
(Map<String, Object>)values.get("externalNumber");
String score = getMappedValue(externalBlock, "externalScore",
"selected_option", false);
if (score != null && !score.isEmpty()) {
response.setExternalScore(Integer.parseInt(score));
final String type = (String)map.get("type");

if (type.equals("view_submission")) {
final Map<String, Object> view =
(Map<String, Object>)map.get("view");
final Map<String, Object> state =
(Map<String, Object>)view.get("state");
final Map<String, Object> values =
(Map<String, Object>)state.get("values");

dumpMap(values, "");

// Create the pulse DTO and fill in the values.
PulseResponseCreateDTO response = new PulseResponseCreateDTO();
response.setTeamMemberId(lookupUser(memberProfileServices, map));
response.setSubmissionDate(LocalDate.now());

// Internal Score
Map<String, Object> internalBlock =
(Map<String, Object>)values.get("internalNumber");
response.setInternalScore(Integer.parseInt(getMappedValue(
internalBlock, "internalScore", "selected_option", true)));
// Internal Feelings
response.setInternalFeelings(getMappedValue(
values, "internaltext", "internalFeelings", false));

// External Score
Map<String, Object> externalBlock =
(Map<String, Object>)values.get("externalNumber");
String score = getMappedValue(externalBlock, "externalScore",
"selected_option", false);
if (score != null && !score.isEmpty()) {
response.setExternalScore(Integer.parseInt(score));
}
// External Feelings
response.setExternalFeelings(getMappedValue(
values, "externalText", "externalFeelings", false));

return response;
} else {
// If it's not a view submission, we need to return null so
// the the caller knows that this is not the full pulse
// response.
return null;
}
// External Feelings
response.setExternalFeelings(getMappedValue(
values, "externalText", "externalFeelings", false));

return response;
} catch(JsonProcessingException ex) {
LOG.error(ex.getMessage());
throw new BadArgException(ex.getMessage());
Expand All @@ -83,12 +92,12 @@ public PulseResponseCreateDTO get(
private String getMappedValue(Map<String, Object> map, String key1,
String key2, boolean required) {
final String valueKey = "value";
if (map.containsKey(key1)) {
if (map != null && map.containsKey(key1)) {
Map<String, Object> firstMap = (Map<String, Object>)map.get(key1);
if (firstMap.containsKey(key2)) {
if (firstMap != null && firstMap.containsKey(key2)) {
final Map<String, Object> secondMap =
(Map<String, Object>)firstMap.get(key2);
if (secondMap.containsKey(valueKey)) {
if (secondMap != null && secondMap.containsKey(valueKey)) {
return (String)secondMap.get(valueKey);
}
}
Expand All @@ -100,7 +109,7 @@ private String getMappedValue(Map<String, Object> map, String key1,
String.format("Expected %s.%s.%s was not found",
key1, key2, valueKey));
} else {
return "";
return null;
}
}

Expand Down
2 changes: 1 addition & 1 deletion server/src/main/resources/db/dev/R__Load_testing_data.sql
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ VALUES
INSERT INTO member_profile -- Unreal Ulysses
(id, firstName, lastName, title, pdlid, location, workEmail, employeeid, startdate, biotext, supervisorid, birthDate, last_seen)
VALUES
('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('testing2@objectcomputing.com','${aeskey}'), '010101012', '2021-05-22', PGP_SYM_ENCRYPT('Test user 2','${aeskey}'), 'e4b2fe52-1915-4544-83c5-21b8f871f6db', '1950-01-01', '2021-05-22');
('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('testing2@objectcomputing.com','${aeskey}'), '010101012', '2021-05-22', PGP_SYM_ENCRYPT('Test user 2','${aeskey}'), 'e4b2fe52-1915-4544-83c5-21b8f871f6db', '1950-02-01', '2021-05-22');

INSERT INTO member_profile -- Kazuhira Miller
(id, firstName, lastName, title, pdlid, location, workEmail, employeeid, startdate, biotext, supervisorid, birthDate, last_seen)
Expand Down
4 changes: 3 additions & 1 deletion web-ui/src/pages/PulseReportPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,9 @@ const PulseReportPage = () => {
internalScores: []
};
}
averages.externalScores.push(externalScore);
if (externalScore != null) {
averages.externalScores.push(externalScore);
}
averages.internalScores.push(internalScore);
}
}
Expand Down
Loading