-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial version of Pulse Response submission through Slack.
- Loading branch information
1 parent
7fe227e
commit cf2a90b
Showing
8 changed files
with
276 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
...java/com/objectcomputing/checkins/services/pulseresponse/SlackPulseResponseConverter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package com.objectcomputing.checkins.services.pulseresponse; | ||
|
||
import com.objectcomputing.checkins.exceptions.BadArgException; | ||
import com.objectcomputing.checkins.services.memberprofile.MemberProfile; | ||
import com.objectcomputing.checkins.services.memberprofile.MemberProfileServices; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.fasterxml.jackson.core.type.TypeReference; | ||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
|
||
import java.util.Map; | ||
import java.util.UUID; | ||
import java.time.LocalDate; | ||
|
||
public class SlackPulseResponseConverter { | ||
public static PulseResponseCreateDTO get( | ||
MemberProfileServices memberProfileServices, String body) { | ||
final String key = "payload="; | ||
final int start = body.indexOf(key); | ||
if (start >= 0) { | ||
try { | ||
// Get the map of values from the string body | ||
final ObjectMapper mapper = new ObjectMapper(); | ||
final Map<String, Object> map = | ||
mapper.readValue(body.substring(start + key.length()), | ||
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"); | ||
|
||
// Create the pulse DTO and fill in the values. | ||
PulseResponseCreateDTO response = new PulseResponseCreateDTO(); | ||
response.setTeamMemberId(lookupUser(memberProfileServices, map)); | ||
response.setSubmissionDate(LocalDate.now()); | ||
response.setInternalScore(Integer.parseInt( | ||
getMappedValue(values, "internalScore"))); | ||
response.setInternalFeelings( | ||
getMappedValue(values, "internalFeelings")); | ||
response.setExternalScore(Integer.parseInt( | ||
getMappedValue(values, "externalScore"))); | ||
response.setExternalFeelings( | ||
getMappedValue(values, "externalFeelings")); | ||
|
||
return response; | ||
} catch(JsonProcessingException ex) { | ||
throw new BadArgException(ex.getMessage()); | ||
} | ||
} 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 UUID lookupUser(MemberProfileServices memberProfileServices, | ||
Map<String, Object> map) { | ||
// Get the user's profile map. | ||
Map<String, Object> user = (Map<String, Object>)map.get("user"); | ||
Map<String, Object> profile = (Map<String, Object>)user.get("profile"); | ||
|
||
// Lookup the user based on the email address. | ||
String email = (String)profile.get("email"); | ||
MemberProfile member = memberProfileServices.findByWorkEmail(email); | ||
return member.getId(); | ||
} | ||
} |
Oops, something went wrong.