diff --git a/.travis.yml b/.travis.yml index e1c4bd87..62be52cd 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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: diff --git a/src/main/java/org/sefglobal/scholarx/service/EmailService.java b/src/main/java/org/sefglobal/scholarx/service/EmailService.java index a2ee98c6..eb83e295 100644 --- a/src/main/java/org/sefglobal/scholarx/service/EmailService.java +++ b/src/main/java/org/sefglobal/scholarx/service/EmailService.java @@ -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); @@ -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); diff --git a/src/main/java/org/sefglobal/scholarx/service/MentorService.java b/src/main/java/org/sefglobal/scholarx/service/MentorService.java index 690775ef..1f7a56f3 100644 --- a/src/main/java/org/sefglobal/scholarx/service/MentorService.java +++ b/src/main/java/org/sefglobal/scholarx/service/MentorService.java @@ -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 { @@ -118,6 +119,16 @@ public Mentee applyAsMentee(long mentorId, long profileId, Mentee mentee) throw new ResourceNotFoundException(msg); } + Optional 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()); diff --git a/src/main/java/org/sefglobal/scholarx/service/ProgramService.java b/src/main/java/org/sefglobal/scholarx/service/ProgramService.java index 69c24f7b..57ec015e 100644 --- a/src/main/java/org/sefglobal/scholarx/service/ProgramService.java +++ b/src/main/java/org/sefglobal/scholarx/service/ProgramService.java @@ -123,9 +123,10 @@ public Program updateProgram(long id, Program program) throws ResourceNotFoundEx public Program updateState(long id) throws ResourceNotFoundException { Optional 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; @@ -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(); @@ -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 approvedMenteeList = menteeRepository.findAllByProgramIdAndState(id, EnrolmentState.APPROVED); for (Mentee mentee : approvedMenteeList) { diff --git a/src/main/java/org/sefglobal/scholarx/util/ProgramUtil.java b/src/main/java/org/sefglobal/scholarx/util/ProgramUtil.java index 15e6e6ed..00d5f8f9 100644 --- a/src/main/java/org/sefglobal/scholarx/util/ProgramUtil.java +++ b/src/main/java/org/sefglobal/scholarx/util/ProgramUtil.java @@ -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; @@ -30,26 +31,75 @@ public void sendMenteeApplicationEmails(long id, Optional 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() + ",

" + + "Congratulations!
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 " + + "here and reach out to us via " + + "sustainableedufoundation@gmail.com " + + "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() + ",

" + + "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 " + + "sustainableedufoundation@gmail.com"; + + emailService.sendEmail(mentor.getProfile().getEmail(), StringUtils.capitalize(mentor.getState().name()), message, false); + + } } } public void sendMenteeSelectionEmails(long id, Optional program) throws IOException, MessagingException { List approvedMentors = mentorRepository.findAllByProgramIdAndState(id, EnrolmentState.APPROVED); + List 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() + ",

" + + "You have student applications waiting to be reviewed. You can approve or reject your mentees " + + "by visiting the ScholarX dashboard."; + + emailService.sendEmail(mentor.getProfile().getEmail(), program.get().getTitle(), message, true); + } + + // Notify mentees + for (Mentee mentee : mentees) { + String message = "Dear " + mentee.getProfile().getFirstName() + ",

" + + "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 here and reach out to us via " + + "sustainableedufoundation@gmail.com " + + "for any clarifications."; + + emailService.sendEmail(mentee.getProfile().getEmail(), program.get().getTitle(), message, false); } } public void sendOnGoingEmails(long id, Optional program) throws IOException, MessagingException { List 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() + ",

" + + "Congratulations!
Students have accepted you as their mentor. " + + "You can check your mentees and their contact details by visiting the ScholarX dashboard. " + + "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); } } @@ -57,8 +107,9 @@ public void sendMentorConfirmationEmails(long id, Optional program) thr List 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); } } } diff --git a/src/main/resources/templates/scholarx.html b/src/main/resources/templates/scholarx.html index 816e7777..d0cf81b7 100644 --- a/src/main/resources/templates/scholarx.html +++ b/src/main/resources/templates/scholarx.html @@ -1,68 +1,181 @@ - + + ScholarX email template - + - -
- + + +
+
-
- +
+ - - -
- + +
+ +
+

-

- -
- -
-

-

- View Dashboard -

+

+

+ Best regards,
+ Dharana Jayawardane,
+ Program Manager,
+ ScholarX,
+ Sustainable Education Foundation +

+

+ + View Dashboard + +

-

- f - t +

+

+ + facebook-icon + + + facebook-icon + + + facebook-icon + + + facebook-icon + +

+

+ © Sustainable Education Foundation - SEF 2021

-

© Sustainable Education Foundation - SEF 2021

@@ -71,4 +184,6 @@
+ +