Skip to content

Commit

Permalink
Initial code for adding a bi-weekly pulse survey email.
Browse files Browse the repository at this point in the history
  • Loading branch information
ocielliottc committed Sep 11, 2024
1 parent 2700c76 commit 8cb30dd
Show file tree
Hide file tree
Showing 5 changed files with 157 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package com.objectcomputing.checkins.services.pulse;

import com.objectcomputing.checkins.configuration.CheckInsConfiguration;
import com.objectcomputing.checkins.notifications.email.EmailSender;
import com.objectcomputing.checkins.notifications.email.MailJetFactory;
import com.objectcomputing.checkins.services.memberprofile.MemberProfileServices;

import jakarta.inject.Named;

import java.util.stream.Collectors;
import java.util.List;

class PulseEmail {
private final EmailSender emailSender;
private final CheckInsConfiguration checkInsConfiguration;
private final MemberProfileServices memberProfileServices;

private final String SUBJECT = "Check Out the Pulse Survey!";

public PulseEmail(@Named(MailJetFactory.HTML_FORMAT) EmailSender emailSender,
CheckInsConfiguration checkInsConfiguration,
MemberProfileServices memberProfileServices) {
this.emailSender = emailSender;
this.checkInsConfiguration = checkInsConfiguration;
this.memberProfileServices = memberProfileServices;
}

private List<String> getActiveTeamMembers() {
List<String> profiles = memberProfileServices.findAll().stream()
.filter(p -> p.getTerminationDate() == null)
.map(p -> p.getWorkEmail())
.collect(Collectors.toList());
return profiles;
}

private String getEmailContent() {
/*
<mjml>
<mj-body>
<mj-section>
<mj-column>
<mj-divider border-color="#2559a7"></mj-divider>
<mj-text font-size="16px" font-family="'Helvetica Neue', Helvetica, Arial, sans-serif" color="#4d4c4f">Please fill out your Pulse survey, if you haven't already done so. We want to know how you're doing!</mj-text>
<mj-text font-size="16px" font-family="'Helvetica Neue', Helvetica, Arial, sans-serif" color="#4d4c4f">Click <a href="%s/pulse" target="_blank">here</a> to begin.</mj-text>
</mj-column>
</mj-section>
</mj-body>
</mjml>
*/
return String.format("""
<html>
<body>
<div style="margin:0px auto;float: left; max-width:600px;">
<p style="border-top:solid 4px #2559a7;font-size:1px;margin:0px auto;width:100%%;"></p>
<p></p>
<div style="font-family:'Helvetica Neue', Helvetica, Arial, sans-serif;font-size:16px;line-height:1;text-align:left;color:#4d4c4f;">
Please fill out your Pulse survey, if you haven't already done so. We want to know how you're doing!</div>
<p></p>
<div style="font-family:'Helvetica Neue', Helvetica, Arial, sans-serif;font-size:16px;line-height:1;text-align:left;color:#4d4c4f;">
Click <a href="%s/pulse" target="_blank">here</a> to begin.</div>
</div>
</div>
</body>
</html>
""", checkInsConfiguration.getWebAddress());
}

public void send() {
final List<String> recipients = getActiveTeamMembers();
final String content = getEmailContent();
emailSender.sendEmail(null, null, SUBJECT, content,
recipients.toArray(new String[recipients.size()]));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.objectcomputing.checkins.services.pulse;

import java.time.LocalDate;

public interface PulseServices {
public void sendPendingEmail(LocalDate now);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package com.objectcomputing.checkins.services.pulse;

import com.objectcomputing.checkins.configuration.CheckInsConfiguration;
import com.objectcomputing.checkins.notifications.email.EmailSender;
import com.objectcomputing.checkins.notifications.email.MailJetFactory;
import com.objectcomputing.checkins.services.memberprofile.MemberProfileServices;

import jakarta.inject.Named;
import jakarta.inject.Singleton;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Map;
import java.util.HashMap;
import java.time.LocalDate;
import java.time.DayOfWeek;
import java.time.temporal.ChronoUnit;
import java.time.temporal.TemporalAdjusters;

@Singleton
public class PulseServicesImpl implements PulseServices {
private static final Logger LOG = LoggerFactory.getLogger(PulseServicesImpl.class);
private final EmailSender emailSender;
private final CheckInsConfiguration checkInsConfiguration;
private final MemberProfileServices memberProfileServices;
private final Map<String, Boolean> sent = new HashMap<String, Boolean>();

public PulseServicesImpl(
@Named(MailJetFactory.HTML_FORMAT) EmailSender emailSender,
CheckInsConfiguration checkInsConfiguration,
MemberProfileServices memberProfileServices) {
this.emailSender = emailSender;
this.checkInsConfiguration = checkInsConfiguration;
this.memberProfileServices = memberProfileServices;

}

public void sendPendingEmail(LocalDate check) {
if (check.getDayOfWeek() == DayOfWeek.MONDAY) {
LOG.info("Checking for pending Pulse email");
LocalDate now = LocalDate.now();
LocalDate start = now.with(TemporalAdjusters.firstInMonth(
DayOfWeek.MONDAY));
do {
if (start.getDayOfMonth() == check.getDayOfMonth()) {
LOG.info("Check day of month matches interval day");
String key = new StringBuilder(start.getMonth().toString())
.append("_")
.append(String.valueOf(start.getDayOfMonth()))
.toString();
if (!sent.containsKey(key)) {
LOG.info("Sending Pulse Email");
send();
sent.put(key, true);
}
break;
}
start = start.plus(2, ChronoUnit.WEEKS);
} while(start.getMonth() == now.getMonth());
}
}

private void send() {
PulseEmail email = new PulseEmail(emailSender, checkInsConfiguration,
memberProfileServices);
email.send();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.objectcomputing.checkins.services.feedback_request.FeedbackRequest;
import com.objectcomputing.checkins.services.feedback_request.FeedbackRequestRepository;
import com.objectcomputing.checkins.services.feedback_request.FeedbackRequestServicesImpl;
import com.objectcomputing.checkins.services.pulse.PulseServices;
import jakarta.inject.Singleton;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -16,11 +17,14 @@ public class CheckServicesImpl implements CheckServices {
private static final Logger LOG = LoggerFactory.getLogger(CheckServicesImpl.class);
private final FeedbackRequestServicesImpl feedbackRequestServices;
private final FeedbackRequestRepository feedbackRequestRepository;
private final PulseServices pulseServices;

public CheckServicesImpl(FeedbackRequestServicesImpl feedbackRequestServices,
FeedbackRequestRepository feedbackRequestRepository) {
FeedbackRequestRepository feedbackRequestRepository,
PulseServices pulseServices) {
this.feedbackRequestServices = feedbackRequestServices;
this.feedbackRequestRepository = feedbackRequestRepository;
this.pulseServices = pulseServices;
}

@Override
Expand All @@ -33,6 +37,7 @@ public boolean sendScheduledEmails() {
req.setStatus("sent");
feedbackRequestRepository.update(req);
}
pulseServices.sendPendingEmail(today);
return true;
}

Expand Down
2 changes: 1 addition & 1 deletion web-ui/src/pages/PulsePage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ const PulsePage = () => {
score={externalScore}
setComment={setExternalComment}
setScore={setExternalScore}
title="How you feeling about life outside of work?"
title="How are you feeling about life outside of work?"
/>
<Button onClick={submit} variant="contained">
Submit
Expand Down

0 comments on commit 8cb30dd

Please sign in to comment.