Skip to content
This repository has been archived by the owner on Jan 2, 2024. It is now read-only.

Commit

Permalink
Merge pull request #197 from sef-global/development
Browse files Browse the repository at this point in the history
Release ScholarX v1.4
  • Loading branch information
anjula-sack authored Aug 10, 2021
2 parents 3531f66 + f21bdf9 commit 591140c
Show file tree
Hide file tree
Showing 6 changed files with 218 additions and 38 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ before_script:
- mkdir -p src/main/resources/static
- cp -r scholarx-frontend/dist/. src/main/resources/static/
- sudo rm -R scholarx-frontend
- cp src/main/resources/application.yml.example src/main/resources/application.yml
script:
- mvn clean install
deploy:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public EmailService(EmailUtil emailUtil) {
this.emailUtil = emailUtil;
}

public Email sendEmail(String emailAddress, String subject, String message) throws IOException, MessagingException {
public Email sendEmail(String emailAddress, String subject, String message, boolean showButton) throws IOException, MessagingException {
Email email = new Email();
email.setEmail(emailAddress);
email.setSubject(subject);
Expand All @@ -27,6 +27,7 @@ public Email sendEmail(String emailAddress, String subject, String message) thro
model.put("emailAddress", emailAddress);
model.put("subject", subject);
model.put("message", message);
model.put("showButton", showButton);
email.setProps(model);

emailUtil.sendSimpleMessage(email);
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/org/sefglobal/scholarx/service/MentorService.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ public Mentor updateState(long id, EnrolmentState enrolmentState)
* @throws ResourceNotFoundException is thrown if the applying {@link Mentor} doesn't exist
* @throws ResourceNotFoundException is thrown if the applying user's {@link Profile} doesn't exist
* @throws BadRequestException is thrown if the applying {@link Mentor} is not in applicable state
* @throws BadRequestException is thrown if the applying user is already a {@link Mentor}
*/
public Mentee applyAsMentee(long mentorId, long profileId, Mentee mentee)
throws ResourceNotFoundException, BadRequestException {
Expand All @@ -118,6 +119,16 @@ public Mentee applyAsMentee(long mentorId, long profileId, Mentee mentee)
throw new ResourceNotFoundException(msg);
}

Optional<Mentor> alreadyRegisteredMentor = mentorRepository
.findByProfileIdAndProgramId(profileId, optionalMentor.get().getProgram().getId());
if (alreadyRegisteredMentor.isPresent() &&
alreadyRegisteredMentor.get().getState().equals(EnrolmentState.APPROVED)) {
String msg = "Error, Unable to apply as a mentee. " +
"Profile with id: " + profileId + " is already registered as a mentor.";
log.error(msg);
throw new BadRequestException(msg);
}

mentee.setProfile(optionalProfile.get());
mentee.setProgram(optionalMentor.get().getProgram());
mentee.setMentor(optionalMentor.get());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,10 @@ public Program updateProgram(long id, Program program) throws ResourceNotFoundEx
public Program updateState(long id) throws ResourceNotFoundException {
Optional<Program> program = programRepository.findById(id);

final ProgramState nextState = program.get().getState().next();
Thread thread = new Thread(() -> {
try {
switch (program.get().getState().next()) {
switch (nextState) {
case MENTEE_APPLICATION:
programUtil.sendMenteeApplicationEmails(id, program);
break;
Expand All @@ -139,7 +140,8 @@ public Program updateState(long id) throws ResourceNotFoundException {
programUtil.sendMentorConfirmationEmails(id, program);
break;
}
} catch (Exception ignored) {
} catch (Exception exception) {
log.error("Email service error: ", exception);
}
});
thread.start();
Expand All @@ -151,7 +153,6 @@ public Program updateState(long id) throws ResourceNotFoundException {
throw new ResourceNotFoundException(msg);
}

ProgramState nextState = program.get().getState().next();
if (ProgramState.ONGOING.equals(nextState)) {
List<Mentee> approvedMenteeList = menteeRepository.findAllByProgramIdAndState(id, EnrolmentState.APPROVED);
for (Mentee mentee : approvedMenteeList) {
Expand Down
65 changes: 58 additions & 7 deletions src/main/java/org/sefglobal/scholarx/util/ProgramUtil.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.sefglobal.scholarx.util;

import org.apache.commons.lang.StringUtils;
import org.sefglobal.scholarx.model.Mentee;
import org.sefglobal.scholarx.model.Mentor;
import org.sefglobal.scholarx.model.Program;
Expand Down Expand Up @@ -30,35 +31,85 @@ public void sendMenteeApplicationEmails(long id, Optional<Program> program) thro

String message;
for (Mentor mentor : mentors) {
message = "You have been " + mentor.getState().name().toLowerCase();
emailService.sendEmail(mentor.getProfile().getEmail(), program.get().getTitle(), message);

if (mentor.getState().name().equals("APPROVED")) {

message = "Dear " + mentor.getProfile().getFirstName() + ",<br /><br />" +
"<b>Congratulations!</b><br />You have been selected by the " +
"ScholarX committee to be a mentor of the " + program.get().getTitle() +
" program. We will soon open up the program for students to " +
"apply and keep you posted on the progress via email. Until " +
"then, read more about student experience " +
"<a href=\"https://medium.com/search?q=scholarx\">here</a> and reach out to us via " +
"<a href=\"mailto:[email protected]\">[email protected]</a> " +
"for any clarifications.";

emailService.sendEmail(mentor.getProfile().getEmail(), StringUtils.capitalize(mentor.getState().name()), message, false);

} else if (mentor.getState().name().equals("REJECTED")) {

message = "Dear " + mentor.getProfile().getFirstName() + ",<br /><br />" +
"Thank you very much for taking your time to apply for the " + program.get().getTitle() + " program. " +
"However, due to the competitive nature of the mentor applications, your application " +
"did not make it to the final list of mentors for the program. We encourage you to try " +
"again next year and follow us on our social media channels for future programs. " +
"If you have any clarifications, please reach out to us via " +
"<a href=\"mailto:[email protected]\">[email protected]</a>";

emailService.sendEmail(mentor.getProfile().getEmail(), StringUtils.capitalize(mentor.getState().name()), message, false);

}
}
}

public void sendMenteeSelectionEmails(long id, Optional<Program> program) throws IOException, MessagingException {
List<Mentor> approvedMentors = mentorRepository.findAllByProgramIdAndState(id, EnrolmentState.APPROVED);
List<Mentee> mentees = menteeRepository.findAllByProgramId(id);

String message = "You can approve or reject your mentees by visiting the dashboard";
// Notify mentors
for (Mentor mentor : approvedMentors) {
emailService.sendEmail(mentor.getProfile().getEmail(), program.get().getTitle(), message);

String message = "Dear " + mentor.getProfile().getFirstName() + ",<br /><br />" +
"You have student applications waiting to be reviewed. You can approve or reject your mentees " +
"by visiting the <b>ScholarX dashboard.</b>";

emailService.sendEmail(mentor.getProfile().getEmail(), program.get().getTitle(), message, true);
}

// Notify mentees
for (Mentee mentee : mentees) {
String message = "Dear " + mentee.getProfile().getFirstName() + ",<br /><br />" +
"Thank you very much for applying to the " + program.get().getTitle() + " program. Your application has been received. " +
"Mentors will soon review your applications and we will keep you posted on the progress via email. " +
"Until then, read more about student experience <a href=\"https://medium.com/search?q=scholarx\">here</a> and reach out to us via " +
"<a href=\"mailto:[email protected]\">[email protected]</a> " +
"for any clarifications.";

emailService.sendEmail(mentee.getProfile().getEmail(), program.get().getTitle(), message, false);
}
}

public void sendOnGoingEmails(long id, Optional<Program> program) throws IOException, MessagingException {
List<Mentor> approvedMentors = mentorRepository.findAllByProgramIdAndState(id, EnrolmentState.APPROVED);

String message = "You can check your mentees by visiting the dashboard";
for (Mentor mentor : approvedMentors) {
emailService.sendEmail(mentor.getProfile().getEmail(), program.get().getTitle(), message);

String message = "Dear " + mentor.getProfile().getFirstName() + ",<br /><br />" +
"<b>Congratulations!</b><br />Students have accepted you as their mentor. " +
"You can check your mentees and their contact details by visiting the <b>ScholarX dashboard.</b> " +
"Please make the first contact with them as we have instructed them to wait for your email.";

emailService.sendEmail(mentor.getProfile().getEmail(), program.get().getTitle(), message, true);
}
}

public void sendMentorConfirmationEmails(long id, Optional<Program> program) throws IOException, MessagingException {
List<Mentee> mentees = menteeRepository.findAllByProgramId(id);

String message = "You can check your mentor by visiting the dashboard";

for (Mentee mentee : mentees) {
emailService.sendEmail(mentee.getProfile().getEmail(), program.get().getTitle(), message);
emailService.sendEmail(mentee.getProfile().getEmail(), program.get().getTitle(), message, true);
}
}
}
Loading

0 comments on commit 591140c

Please sign in to comment.