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.paymentCodes.IndividualCandidacyPaymentCode; import org.joda.time.LocalDate; import org.joda.time.YearMonthDay; import pt.utl.ist.scripts.commons.AtomicScript; public class UpdatePaymentCodesDate extends AtomicScript { private static final YearMonthDay NEW_START_DATE = new YearMonthDay(2013, 07, 15); @Override protected void run() throws Exception { int count = 0; LocalDate startDate = new LocalDate(2013, 07, 29); for (PaymentCode paymentCode : rootDomainObject.getPaymentCodesSet()) { if (paymentCode instanceof IndividualCandidacyPaymentCode) { if (paymentCode.getType().equals(PaymentCodeType.EXTERNAL_DEGREE_TRANSFER_INDIVIDUAL_CANDIDACY_PROCESS) || paymentCode.getType().equals(PaymentCodeType.INTERNAL_DEGREE_TRANSFER_INDIVIDUAL_CANDIDACY_PROCESS)) { if (paymentCode.getStartDate().toDateMidnight().toLocalDate().equals(startDate)) { paymentCode.setStartDate(NEW_START_DATE); count++; } } } } System.out.println(count + " payment codes updated to the new value"); } public static final void main(String[] args) { processWriteTransaction(new UpdatePaymentCodesDate()); } }