package net.sourceforge.fenixedu.domain.assiduousness; import java.util.ArrayList; import java.util.List; import net.sourceforge.fenixedu.domain.RootDomainObject; import org.joda.time.LocalDate; import org.joda.time.Partial; public class AssiduousnessExemption extends AssiduousnessExemption_Base { public AssiduousnessExemption(Integer year, String description) { super(); setYear(year); setDescription(description); setRootDomainObject(RootDomainObject.getInstance()); } public static int getAssiduousnessExemptionDaysQuantity(Integer year) { int numberOfDays = 0; for (AssiduousnessExemption assiduousnessExemption : RootDomainObject.getInstance().getAssiduousnessExemptions()) { if (assiduousnessExemption.getYear().equals(year)) { numberOfDays += assiduousnessExemption.getNumberOfDays(); } } return numberOfDays; } public static int getAssiduousnessExemptionDaysQuantityByDate(LocalDate date) { int numberOfDays = 0; for (AssiduousnessExemption assiduousnessExemption : RootDomainObject.getInstance().getAssiduousnessExemptions()) { if (assiduousnessExemption.getYear().equals(date.getYear()) && assiduousnessExemption.hasAnyShiftAfterDate(date)) { numberOfDays += assiduousnessExemption.getNumberOfDays(); } } return numberOfDays; } private boolean hasAnyShiftAfterDate(LocalDate date) { for (AssiduousnessExemptionShift assiduousnessExemptionShift : getAssiduousnessExemptionShifts()) { Partial firstShiftDate = assiduousnessExemptionShift.getPartialShift().getSortedPartials().get(0); if (firstShiftDate.isAfter(date)) { return true; } } return false; } private int getNumberOfDays() { AssiduousnessExemptionShift assiduousnessExemptionShift = getAssiduousnessExemptionShifts().get(0); return assiduousnessExemptionShift.getPartialShift().getPartials().size(); } public void delete() { deleteShifts(); removeRootDomainObject(); deleteDomainObject(); } public void edit(Integer year, String description) { setYear(year); setDescription(description); } public void deleteShifts() { List list = new ArrayList(getAssiduousnessExemptionShifts()); for (AssiduousnessExemptionShift assiduousnessExemptionShift : list) { assiduousnessExemptionShift.delete(); } } }