package pt.utl.ist.scripts.runOnce.candidacy; import net.sourceforge.fenixedu.domain.accounting.PaymentCode; import net.sourceforge.fenixedu.domain.accounting.PaymentCodeType; import net.sourceforge.fenixedu.domain.accounting.ServiceAgreementTemplate; import net.sourceforge.fenixedu.domain.accounting.paymentCodes.IndividualCandidacyPaymentCode; import net.sourceforge.fenixedu.domain.phd.PhdProgramServiceAgreementTemplate; import net.sourceforge.fenixedu.util.Money; import pt.utl.ist.scripts.commons.AtomicScript; public class UpdatePaymentCodesWithValueZero extends AtomicScript { /** * update phd payment codes with value zero that were supposed to not be used and now need to have a value since * they've been associated to candidacies of paying phd's (left as it is the Bioengenharia phd payment codes) */ private static final String BIOENGENHARIA_PHD_ACRONYM = "DBioeng"; private static final Money PAYMENT_VALUE = Money.valueOf(100); @Override protected void run() throws Exception { int count = 0; for (PaymentCode paymentCode : rootDomainObject.getPaymentCodesSet()) { if (paymentCode instanceof IndividualCandidacyPaymentCode) { if (paymentCode.getType().equals(PaymentCodeType.PHD_PROGRAM_CANDIDACY_PROCESS) && paymentCode.getMinAmount().isZero()) { if (paymentCode.getMinAmount().equals(paymentCode.getMaxAmount()) && paymentCode.hasPerson() && paymentCode.isNew()) { ServiceAgreementTemplate serviceAgreementTemplate = ((IndividualCandidacyPaymentCode) paymentCode).getAccountingEvent().getPostingRule() .getServiceAgreementTemplate(); String phdAcronym = ((PhdProgramServiceAgreementTemplate) serviceAgreementTemplate).getPhdProgram().getAcronym(); if (!phdAcronym.equalsIgnoreCase(BIOENGENHARIA_PHD_ACRONYM)) { paymentCode.setMinAmount(PAYMENT_VALUE); paymentCode.setMaxAmount(PAYMENT_VALUE); count++; } } } } } System.out.println(count + " payment codes updated to the new value"); } public static final void main(String[] args) { processWriteTransaction(new UpdatePaymentCodesWithValueZero()); } }