package net.sourceforge.fenixedu.domain.teacher; import net.sourceforge.fenixedu.domain.ExecutionYear; import net.sourceforge.fenixedu.domain.RootDomainObject; import net.sourceforge.fenixedu.domain.Teacher; import net.sourceforge.fenixedu.util.RegimeType; import net.sourceforge.zas.utils.PropertiesManager; import org.apache.commons.lang.StringUtils; import org.joda.time.YearMonthDay; import pt.ist.utl.fenix.utils.Pair; /** * @author Paulo Costa (paulo.costa@iscte.pt) * */ public class Rebides extends Rebides_Base { public Rebides() { super(); setRootDomainObject(RootDomainObject.getInstance()); } public static Double getDefaultMinRebides(){ final String prop = PropertiesManager.getProperty("softplanning.rebides.default.min"); if (!StringUtils.isEmpty(prop)) { return Double.valueOf(prop); } return 6.0; } public static Double getDefaultMaxRebides(){ final String prop = PropertiesManager.getProperty("softplanning.rebides.default.max"); if (!StringUtils.isEmpty(prop)) { return Double.valueOf(prop); } return 6.0; } public static Pair getMinAndMaxFromTeacherForExecutionYear(Teacher teacher, ExecutionYear executionYear) { final Pair result = new Pair(getDefaultMinRebides(), getDefaultMaxRebides()); final YearMonthDay beginDate = executionYear.getBeginDateYearMonthDay(); final YearMonthDay endDate = executionYear.getEndDateYearMonthDay(); final TeacherProfessionalSituation tps = teacher.getLastLegalRegimenWithoutSpecialSituations(beginDate, endDate); if (tps != null) { TeacherStatistics ts = null; for (final TeacherStatistics aux : teacher.getStatistic()) { if (aux.executionYearBelongs(executionYear)) { ts = aux; break; } } for (final Rebides r : RootDomainObject.getInstance().getRebides()) { if (r.getCategory().equals(tps.getCategory()) && r.getRegimeType().equals(tps.getRegimeType())) { final Integer percentage = tps.getPercentage() > 100 ? 100 : tps.getPercentage(); if ((ts != null && ts.getPercentage().equals(r.getPercentage())) || r.getPercentage().equals(percentage)) { return new Pair(r.getMinor(), r.getMajor()); } } } } return result; } /** * Gets the rebides value by with the given category regimeType and pecentage * @param cat * @param regimeType * @param percentage * @return */ public static Rebides getByCategoryAndRegimeAndPercentage(final Category cat, final RegimeType regimeType, final Integer percentage) { if (cat != null && regimeType != null && percentage != null) { for (final Rebides r : RootDomainObject.getInstance().getRebides()) { if (cat.equals(r.getCategory()) && regimeType.equals(r.getRegimeType()) && percentage.equals(r.getPercentage())) { return r; } } } return null; } public void delete() { removeCategory(); removeRootDomainObject(); deleteDomainObject(); } }