package net.sourceforge.fenixedu.dataTransferObject.teacher.distribution; import java.util.ArrayList; import java.util.Formatter; import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Set; import net.sourceforge.fenixedu.dataTransferObject.DataTranferObject; import net.sourceforge.fenixedu.domain.ProfessionalSituationType; /** * amak, jpmsit * */ public class DistributionTeacherServicesByTeachersDTO extends DataTranferObject { public class ExecutionCourseTeacherServiceDTO { private Integer executionCourseIdInternal; private String executionCourseName; private Integer hoursSpentByTeacher; private Map courseDegreesList; private String executionPeriodName; private Map> executionYearsSet; public ExecutionCourseTeacherServiceDTO(Integer idInternal, String name, Integer hours, Map executionCourseDegreesNameMap, Map> executionYearsMap, String periodName) { super(); this.executionCourseIdInternal = idInternal; this.hoursSpentByTeacher = hours; this.executionCourseName = name; this.executionYearsSet = executionYearsMap; this.executionPeriodName = periodName; this.courseDegreesList = executionCourseDegreesNameMap; } public Integer getExecutionCourseIdInternal() { return executionCourseIdInternal; } public String getExecutionCourseName() { return executionCourseName; } public Integer getHoursSpentByTeacher() { return hoursSpentByTeacher; } public Map getCourseDegreesList() { return courseDegreesList; } public String getExecutionPeriodName() { return executionPeriodName; } public String getDescription() { StringBuilder finalString = new StringBuilder(getExecutionCourseName()); finalString.append("("); Set degreeIdSet = courseDegreesList.keySet(); Iterator iteratorDegreeIdSet = degreeIdSet.iterator(); if (iteratorDegreeIdSet.hasNext()) { Integer firstDegreeIdInternal = iteratorDegreeIdSet.next(); finalString.append(courseDegreesList.get(firstDegreeIdInternal)); finalString.append(" ("); Set firstCurricularYearsSet = executionYearsSet.get(firstDegreeIdInternal); Iterator iteratorFirstCurricularYearsSet = firstCurricularYearsSet.iterator(); if (iteratorFirstCurricularYearsSet.hasNext()) { finalString.append(iteratorFirstCurricularYearsSet.next()); while (iteratorFirstCurricularYearsSet.hasNext()) { finalString.append(", "); finalString.append(iteratorFirstCurricularYearsSet.next()); } finalString.append("šano"); } finalString.append(")"); while (iteratorDegreeIdSet.hasNext()) { finalString.append(", "); Integer degreeIdInternal = iteratorDegreeIdSet.next(); finalString.append(courseDegreesList.get(degreeIdInternal)); finalString.append(" ("); Set curricularYearsSet = executionYearsSet.get(degreeIdInternal); Iterator iteratorCurricularYearsSet = curricularYearsSet.iterator(); if (iteratorCurricularYearsSet.hasNext()) { finalString.append(iteratorCurricularYearsSet.next()); while (iteratorCurricularYearsSet.hasNext()) { finalString.append(", "); finalString.append(iteratorCurricularYearsSet.next()); } finalString.append("šano"); } finalString.append(")"); } finalString.append(")"); } finalString.append("/"); finalString.append("("); finalString.append(executionPeriodName); finalString.append(")"); finalString.append(" - "); finalString.append(hoursSpentByTeacher); return finalString.toString(); } } public class TeacherCreditsInfoDTO { private List exemptionTypes; private String functionName; private Double credits; TeacherCreditsInfoDTO(List exemptionTypes, Double credits) { this.exemptionTypes = exemptionTypes; this.credits = credits; } TeacherCreditsInfoDTO(String functionName, Double credits) { this.functionName = functionName; this.credits = credits; } public Double getCredits() { return credits; } public List getExemptionTypes() { return exemptionTypes; } public String getFunctionName() { return functionName; } } public class TeacherDistributionServiceEntryDTO implements Comparable { private Integer teacherIdInternal; private Integer teacherNumber; private String teacherCategory; private String teacherName; private Integer teacherRequiredHours; private Double teacherAccumulatedCredits; List executionCourseTeacherServiceList; List managementFunctionList; List exemptionSituationList; public TeacherDistributionServiceEntryDTO(Integer internal, Integer teacherNumber, String category, String name, Integer hours, Double accumulatedCredits) { this.teacherNumber = teacherNumber; teacherCategory = category; teacherIdInternal = internal; teacherName = name; teacherRequiredHours = hours; teacherAccumulatedCredits = accumulatedCredits; executionCourseTeacherServiceList = new ArrayList(); managementFunctionList = new ArrayList(); exemptionSituationList = new ArrayList(); } public List getExecutionCourseTeacherServiceList() { return executionCourseTeacherServiceList; } public String getTeacherCategory() { return teacherCategory; } public Integer getTeacherIdInternal() { return teacherIdInternal; } public String getTeacherName() { return teacherName; } public Integer getTeacherRequiredHours() { return teacherRequiredHours; } public Double getTeacherSpentCredits() { double credits = 0d; for (TeacherCreditsInfoDTO managementCredits : managementFunctionList) { credits += managementCredits.getCredits(); } for (TeacherCreditsInfoDTO exemptionCredits : exemptionSituationList) { credits += exemptionCredits.getCredits(); } return credits; } public void addExecutionCourse(ExecutionCourseTeacherServiceDTO executionCourse) { executionCourseTeacherServiceList.add(executionCourse); } public Integer getTeacherNumber() { return teacherNumber; } private String getFormattedValue(Double value) { StringBuilder sb = new StringBuilder(); Formatter formatter = new Formatter(sb); formatter.format("%.1f", value); return sb.toString(); } public String getFormattedTeacherSpentCredits() { return getFormattedValue(getTeacherSpentCredits()); } public String getFormattedTeacherAccumulatedCredits() { return getFormattedValue(getAccumulatedCredits()); } public Integer getTotalLecturedHours() { int totalHours = 0; for (ExecutionCourseTeacherServiceDTO executionCourse : executionCourseTeacherServiceList) { totalHours += executionCourse.getHoursSpentByTeacher(); } return totalHours; } public Integer getAvailability() { double availability = getTeacherRequiredHours() - getTotalLecturedHours() - getTeacherSpentCredits(); return Double.valueOf(StrictMath.ceil(StrictMath.abs(availability)) * StrictMath.signum(availability)).intValue(); } public Double getAccumulatedCredits() { return teacherAccumulatedCredits; } public int compareTo(Object obj) { if (obj instanceof TeacherDistributionServiceEntryDTO) { TeacherDistributionServiceEntryDTO teacher1 = (TeacherDistributionServiceEntryDTO) obj; return this.getTeacherNumber().compareTo(teacher1.getTeacherNumber()); } return 0; } public void setTeacherRequiredHours(Integer teacherRequiredHours) { this.teacherRequiredHours = teacherRequiredHours; } public List getManagementFunctionList() { return managementFunctionList; } public void addToManagementFunction(String function, Double credits) { managementFunctionList.add(new TeacherCreditsInfoDTO(function, credits)); } public void addToExemptionSituation(List exemptionType, Double credits) { exemptionSituationList.add(new TeacherCreditsInfoDTO(exemptionType, credits)); } public List getExemptionSituationList() { return exemptionSituationList; } } private Map teachersMap; public DistributionTeacherServicesByTeachersDTO() { teachersMap = new HashMap(); } public void addTeacher(Integer key, Integer teacherNumber, String category, String name, Integer hours, Double accumulatedCredits) { TeacherDistributionServiceEntryDTO t = new TeacherDistributionServiceEntryDTO(key, teacherNumber, category, name, hours, accumulatedCredits); if (!teachersMap.containsKey(key)) { teachersMap.put(key, t); } } public void addExecutionCourseToTeacher(Integer keyTeacher, Integer executionCourseIdInternal, String executionCourseName, Integer hours, Map executionCourseDegreesNameSet, Map> curricularYearsSet, String periodName) { ExecutionCourseTeacherServiceDTO executionCourse = new ExecutionCourseTeacherServiceDTO(executionCourseIdInternal, executionCourseName, hours, executionCourseDegreesNameSet, curricularYearsSet, periodName); teachersMap.get(keyTeacher).addExecutionCourse(executionCourse); } public void addHoursToTeacher(Integer keyTeacher, Integer hours) { TeacherDistributionServiceEntryDTO teacher = teachersMap.get(keyTeacher); if (teacher != null) { teacher.setTeacherRequiredHours(teacher.getTeacherRequiredHours() + hours); } } public boolean isTeacherPresent(Integer keyTeacher) { return teachersMap.containsKey((keyTeacher)); } public Map getTeachersMap() { return teachersMap; } public void addManagementFunctionToTeacher(Integer keyTeacher, String managementFunction, Double credits) { TeacherDistributionServiceEntryDTO teacher = teachersMap.get(keyTeacher); if (teacher != null) { teacher.addToManagementFunction(managementFunction, credits); } } public void addExemptionSituationToTeacher(Integer keyTeacher, List exemptionTypes, Double credits) { TeacherDistributionServiceEntryDTO teacher = teachersMap.get(keyTeacher); if (teacher != null) { teacher.addToExemptionSituation(exemptionTypes, credits); } } }