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 #203 from sef-global/development
Browse files Browse the repository at this point in the history
Release ScholarX v1.4.1
  • Loading branch information
anjula-sack authored Aug 10, 2021
2 parents 591140c + d462558 commit 1009797
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions src/main/java/org/sefglobal/scholarx/util/ProgramUtil.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
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 All @@ -9,11 +8,11 @@
import org.sefglobal.scholarx.service.EmailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;

import javax.mail.MessagingException;
import java.io.IOException;
import java.util.List;
import java.util.Optional;
import java.util.*;

@Component
public class ProgramUtil {
Expand Down Expand Up @@ -64,7 +63,7 @@ public void sendMenteeApplicationEmails(long id, Optional<Program> program) thro

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);
List<Mentee> mentees = getMenteesWithoutDuplicatesByProgramId(id);

// Notify mentors
for (Mentor mentor : approvedMentors) {
Expand Down Expand Up @@ -104,12 +103,27 @@ public void sendOnGoingEmails(long id, Optional<Program> program) throws IOExcep
}

public void sendMentorConfirmationEmails(long id, Optional<Program> program) throws IOException, MessagingException {
List<Mentee> mentees = menteeRepository.findAllByProgramId(id);
List<Mentee> mentees = getMenteesWithoutDuplicatesByProgramId(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, true);
}
}

/**
* Removes mentee duplicates
*/
private List<Mentee> getMenteesWithoutDuplicatesByProgramId(long id) {
List<Mentee> output = new ArrayList<>();
List<Long> idList = new ArrayList<>();
for (Mentee mentee: menteeRepository.findAllByProgramId(id)) {
if (!idList.contains(mentee.getProfile().getId())) {
idList.add(mentee.getProfile().getId());
output.add(mentee);
}
}
return output;
}
}

0 comments on commit 1009797

Please sign in to comment.