/** * */ package pt.utl.ist.scripts.runOnce; import java.util.Collection; import java.util.Set; import net.sourceforge.fenixedu.domain.ExecutionDegree; import net.sourceforge.fenixedu.domain.OccupationPeriod; import net.sourceforge.fenixedu.domain.OccupationPeriodType; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import pt.ist.bennu.core.domain.Bennu; import pt.utl.ist.scripts.commons.AtomicScript; /** * @author Joao Carvalho (joao.pedro.carvalho@ist.utl.pt) * */ public class CheckOccupationPeriodConsistency extends AtomicScript { private static final Logger logger = LoggerFactory.getLogger(CheckOccupationPeriodConsistency.class); private int errors = 0; @SuppressWarnings("deprecation") @Override protected void run() throws Exception { logger.info("Beggining consistency check"); int num = 0; Set degrees = Bennu.getInstance().getExecutionDegreesSet(); for (ExecutionDegree degree : degrees) { check(degree, degree.getPeriodLessonsFirstSemester(), degree.getPeriods(OccupationPeriodType.LESSONS, 1, null), "getPeriodLessonsFirstSemester"); check(degree, degree.getPeriodLessonsSecondSemester(), degree.getPeriods(OccupationPeriodType.LESSONS, 2, null), "getPeriodLessonsSecondSemester"); check(degree, degree.getPeriodExamsFirstSemester(), degree.getPeriods(OccupationPeriodType.EXAMS, 1, null), "getPeriodExamsFirstSemester"); check(degree, degree.getPeriodExamsSecondSemester(), degree.getPeriods(OccupationPeriodType.EXAMS, 2, null), "getPeriodExamsSecondSemester"); check(degree, degree.getPeriodGradeSubmissionNormalSeasonFirstSemester(), degree.getPeriods(OccupationPeriodType.GRADE_SUBMISSION, 1, null), "getPeriodGradeSubmissionNormalSeasonFirstSemester"); check(degree, degree.getPeriodGradeSubmissionNormalSeasonSecondSemester(), degree.getPeriods(OccupationPeriodType.GRADE_SUBMISSION, 2, null), "getPeriodGradeSubmissionNormalSeasonSecondSemester"); check(degree, degree.getPeriodGradeSubmissionSpecialSeason(), degree.getPeriods(OccupationPeriodType.GRADE_SUBMISSION_SPECIAL_SEASON, null, null), "getPeriodGradeSubmissionSpecialSeason"); check(degree, degree.getPeriodExamsSpecialSeason(), degree.getPeriods(OccupationPeriodType.EXAMS_SPECIAL_SEASON, null, null), "getPeriodExamsSpecialSeason"); num++; } logger.info("Consistency check finished. Processed " + num + " degrees, got " + errors + " errors."); } public static void main(String[] args) { process(new CheckOccupationPeriodConsistency()); } private void check(ExecutionDegree degree, OccupationPeriod period, Collection periods, String visible) { if (period == null) { if (!periods.isEmpty()) { logger.error("[" + degree + "] Occupation Periods don't match for " + visible + ": had null, have " + periods); errors += 1; } } else { if (periods.size() != 1) { logger.error("[" + degree + "] Occupation Periods don't match for " + visible + ": have " + periods); errors += 1; } else if (period != periods.iterator().next()) { logger.error("[" + degree + "] Occupation Periods don't match for " + visible + ": had " + period + " have " + periods.iterator().next()); errors += 1; } } } }