package pt.utl.ist.scripts.runOnce; import net.sourceforge.fenixedu.domain.PublicCandidacyHashCode; import net.sourceforge.fenixedu.domain.phd.candidacy.PhdCandidacyPeriod; import net.sourceforge.fenixedu.domain.phd.candidacy.PhdCandidacyReferee; import net.sourceforge.fenixedu.domain.phd.candidacy.PhdCandidacyRefereeLetter; import net.sourceforge.fenixedu.domain.phd.candidacy.PhdProgramCandidacyProcess; import net.sourceforge.fenixedu.util.phd.EPFLPhdCandidacyProcessProperties; import org.joda.time.DateTime; import pt.utl.ist.scripts.commons.AtomicScript; public class ResendPhdReferersEmails extends AtomicScript { @Override protected void run() throws Exception { //Locale locale = Language.getLocale(); //final ResourceBundle bundle = ResourceBundle.getBundle("resources.PhdResources", locale); final String xpto = EPFLPhdCandidacyProcessProperties.getPublicCandidacyRefereeFormLink(); System.out.println(xpto); int haveLetters = 0; int noLetters = 0; final DateTime now = new DateTime(); for (final PublicCandidacyHashCode hashCode : rootDomainObject.getCandidacyHashCodesSet()) { if (hashCode instanceof PhdCandidacyReferee) { final PhdCandidacyReferee referee = (PhdCandidacyReferee) hashCode; final PhdProgramCandidacyProcess candidacyProcess = referee.getPhdProgramCandidacyProcess(); final PhdCandidacyPeriod candidacyPeriod = candidacyProcess.getPublicPhdCandidacyPeriod(); if (candidacyPeriod != null && candidacyPeriod.contains(now)) { final PhdCandidacyRefereeLetter letter = referee.getLetter(); if (letter == null) { noLetters++; System.out.println(referee.getEmail() + " - " + referee.getName()); System.out.println(referee.getCandidatePerson().getName()); System.out.println(); referee.sendEmail(); } else { haveLetters++; } } } } System.out.println("No letter: " + noLetters); System.out.println("Have letter: " + haveLetters); System.out.println("Done."); } public static void main(String[] args) { processWriteTransaction(new ResendPhdReferersEmails()); System.exit(0); } }