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

Commit 591140c

Browse files
authored
Merge pull request #197 from sef-global/development
Release ScholarX v1.4
2 parents 3531f66 + f21bdf9 commit 591140c

File tree

6 files changed

+218
-38
lines changed

6 files changed

+218
-38
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ before_script:
1010
- mkdir -p src/main/resources/static
1111
- cp -r scholarx-frontend/dist/. src/main/resources/static/
1212
- sudo rm -R scholarx-frontend
13+
- cp src/main/resources/application.yml.example src/main/resources/application.yml
1314
script:
1415
- mvn clean install
1516
deploy:

src/main/java/org/sefglobal/scholarx/service/EmailService.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public EmailService(EmailUtil emailUtil) {
1717
this.emailUtil = emailUtil;
1818
}
1919

20-
public Email sendEmail(String emailAddress, String subject, String message) throws IOException, MessagingException {
20+
public Email sendEmail(String emailAddress, String subject, String message, boolean showButton) throws IOException, MessagingException {
2121
Email email = new Email();
2222
email.setEmail(emailAddress);
2323
email.setSubject(subject);
@@ -27,6 +27,7 @@ public Email sendEmail(String emailAddress, String subject, String message) thro
2727
model.put("emailAddress", emailAddress);
2828
model.put("subject", subject);
2929
model.put("message", message);
30+
model.put("showButton", showButton);
3031
email.setProps(model);
3132

3233
emailUtil.sendSimpleMessage(email);

src/main/java/org/sefglobal/scholarx/service/MentorService.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ public Mentor updateState(long id, EnrolmentState enrolmentState)
9393
* @throws ResourceNotFoundException is thrown if the applying {@link Mentor} doesn't exist
9494
* @throws ResourceNotFoundException is thrown if the applying user's {@link Profile} doesn't exist
9595
* @throws BadRequestException is thrown if the applying {@link Mentor} is not in applicable state
96+
* @throws BadRequestException is thrown if the applying user is already a {@link Mentor}
9697
*/
9798
public Mentee applyAsMentee(long mentorId, long profileId, Mentee mentee)
9899
throws ResourceNotFoundException, BadRequestException {
@@ -118,6 +119,16 @@ public Mentee applyAsMentee(long mentorId, long profileId, Mentee mentee)
118119
throw new ResourceNotFoundException(msg);
119120
}
120121

122+
Optional<Mentor> alreadyRegisteredMentor = mentorRepository
123+
.findByProfileIdAndProgramId(profileId, optionalMentor.get().getProgram().getId());
124+
if (alreadyRegisteredMentor.isPresent() &&
125+
alreadyRegisteredMentor.get().getState().equals(EnrolmentState.APPROVED)) {
126+
String msg = "Error, Unable to apply as a mentee. " +
127+
"Profile with id: " + profileId + " is already registered as a mentor.";
128+
log.error(msg);
129+
throw new BadRequestException(msg);
130+
}
131+
121132
mentee.setProfile(optionalProfile.get());
122133
mentee.setProgram(optionalMentor.get().getProgram());
123134
mentee.setMentor(optionalMentor.get());

src/main/java/org/sefglobal/scholarx/service/ProgramService.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,10 @@ public Program updateProgram(long id, Program program) throws ResourceNotFoundEx
123123
public Program updateState(long id) throws ResourceNotFoundException {
124124
Optional<Program> program = programRepository.findById(id);
125125

126+
final ProgramState nextState = program.get().getState().next();
126127
Thread thread = new Thread(() -> {
127128
try {
128-
switch (program.get().getState().next()) {
129+
switch (nextState) {
129130
case MENTEE_APPLICATION:
130131
programUtil.sendMenteeApplicationEmails(id, program);
131132
break;
@@ -139,7 +140,8 @@ public Program updateState(long id) throws ResourceNotFoundException {
139140
programUtil.sendMentorConfirmationEmails(id, program);
140141
break;
141142
}
142-
} catch (Exception ignored) {
143+
} catch (Exception exception) {
144+
log.error("Email service error: ", exception);
143145
}
144146
});
145147
thread.start();
@@ -151,7 +153,6 @@ public Program updateState(long id) throws ResourceNotFoundException {
151153
throw new ResourceNotFoundException(msg);
152154
}
153155

154-
ProgramState nextState = program.get().getState().next();
155156
if (ProgramState.ONGOING.equals(nextState)) {
156157
List<Mentee> approvedMenteeList = menteeRepository.findAllByProgramIdAndState(id, EnrolmentState.APPROVED);
157158
for (Mentee mentee : approvedMenteeList) {

src/main/java/org/sefglobal/scholarx/util/ProgramUtil.java

Lines changed: 58 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.sefglobal.scholarx.util;
22

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

3132
String message;
3233
for (Mentor mentor : mentors) {
33-
message = "You have been " + mentor.getState().name().toLowerCase();
34-
emailService.sendEmail(mentor.getProfile().getEmail(), program.get().getTitle(), message);
34+
35+
if (mentor.getState().name().equals("APPROVED")) {
36+
37+
message = "Dear " + mentor.getProfile().getFirstName() + ",<br /><br />" +
38+
"<b>Congratulations!</b><br />You have been selected by the " +
39+
"ScholarX committee to be a mentor of the " + program.get().getTitle() +
40+
" program. We will soon open up the program for students to " +
41+
"apply and keep you posted on the progress via email. Until " +
42+
"then, read more about student experience " +
43+
"<a href=\"https://medium.com/search?q=scholarx\">here</a> and reach out to us via " +
44+
"<a href=\"mailto:[email protected]\">[email protected]</a> " +
45+
"for any clarifications.";
46+
47+
emailService.sendEmail(mentor.getProfile().getEmail(), StringUtils.capitalize(mentor.getState().name()), message, false);
48+
49+
} else if (mentor.getState().name().equals("REJECTED")) {
50+
51+
message = "Dear " + mentor.getProfile().getFirstName() + ",<br /><br />" +
52+
"Thank you very much for taking your time to apply for the " + program.get().getTitle() + " program. " +
53+
"However, due to the competitive nature of the mentor applications, your application " +
54+
"did not make it to the final list of mentors for the program. We encourage you to try " +
55+
"again next year and follow us on our social media channels for future programs. " +
56+
"If you have any clarifications, please reach out to us via " +
57+
"<a href=\"mailto:[email protected]\">[email protected]</a>";
58+
59+
emailService.sendEmail(mentor.getProfile().getEmail(), StringUtils.capitalize(mentor.getState().name()), message, false);
60+
61+
}
3562
}
3663
}
3764

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

41-
String message = "You can approve or reject your mentees by visiting the dashboard";
69+
// Notify mentors
4270
for (Mentor mentor : approvedMentors) {
43-
emailService.sendEmail(mentor.getProfile().getEmail(), program.get().getTitle(), message);
71+
72+
String message = "Dear " + mentor.getProfile().getFirstName() + ",<br /><br />" +
73+
"You have student applications waiting to be reviewed. You can approve or reject your mentees " +
74+
"by visiting the <b>ScholarX dashboard.</b>";
75+
76+
emailService.sendEmail(mentor.getProfile().getEmail(), program.get().getTitle(), message, true);
77+
}
78+
79+
// Notify mentees
80+
for (Mentee mentee : mentees) {
81+
String message = "Dear " + mentee.getProfile().getFirstName() + ",<br /><br />" +
82+
"Thank you very much for applying to the " + program.get().getTitle() + " program. Your application has been received. " +
83+
"Mentors will soon review your applications and we will keep you posted on the progress via email. " +
84+
"Until then, read more about student experience <a href=\"https://medium.com/search?q=scholarx\">here</a> and reach out to us via " +
85+
"<a href=\"mailto:[email protected]\">[email protected]</a> " +
86+
"for any clarifications.";
87+
88+
emailService.sendEmail(mentee.getProfile().getEmail(), program.get().getTitle(), message, false);
4489
}
4590
}
4691

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

50-
String message = "You can check your mentees by visiting the dashboard";
5195
for (Mentor mentor : approvedMentors) {
52-
emailService.sendEmail(mentor.getProfile().getEmail(), program.get().getTitle(), message);
96+
97+
String message = "Dear " + mentor.getProfile().getFirstName() + ",<br /><br />" +
98+
"<b>Congratulations!</b><br />Students have accepted you as their mentor. " +
99+
"You can check your mentees and their contact details by visiting the <b>ScholarX dashboard.</b> " +
100+
"Please make the first contact with them as we have instructed them to wait for your email.";
101+
102+
emailService.sendEmail(mentor.getProfile().getEmail(), program.get().getTitle(), message, true);
53103
}
54104
}
55105

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

59109
String message = "You can check your mentor by visiting the dashboard";
110+
60111
for (Mentee mentee : mentees) {
61-
emailService.sendEmail(mentee.getProfile().getEmail(), program.get().getTitle(), message);
112+
emailService.sendEmail(mentee.getProfile().getEmail(), program.get().getTitle(), message, true);
62113
}
63114
}
64115
}

0 commit comments

Comments
 (0)