package net.sourceforge.fenixedu.domain; import java.lang.ref.SoftReference; import java.text.Collator; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.Comparator; import java.util.Date; import java.util.HashSet; import java.util.Hashtable; import java.util.Iterator; import java.util.List; import java.util.Locale; import java.util.Map; import java.util.ResourceBundle; import java.util.Set; import java.util.SortedSet; import java.util.TreeSet; import net.sourceforge.fenixedu.domain.accessControl.DelegatesGroup; import net.sourceforge.fenixedu.domain.administrativeOffice.AdministrativeOfficeType; import net.sourceforge.fenixedu.domain.curricularPeriod.CurricularPeriod; import net.sourceforge.fenixedu.domain.degree.DegreeType; import net.sourceforge.fenixedu.domain.degree.degreeCurricularPlan.DegreeCurricularPlanState; import net.sourceforge.fenixedu.domain.degreeStructure.CycleType; import net.sourceforge.fenixedu.domain.elections.DelegateElection; import net.sourceforge.fenixedu.domain.elections.YearDelegateElection; import net.sourceforge.fenixedu.domain.exceptions.DomainException; import net.sourceforge.fenixedu.domain.inquiries.OldInquiriesCoursesRes; import net.sourceforge.fenixedu.domain.inquiries.OldInquiriesSummary; import net.sourceforge.fenixedu.domain.inquiries.OldInquiriesTeachersRes; import net.sourceforge.fenixedu.domain.organizationalStructure.FunctionType; import net.sourceforge.fenixedu.domain.organizationalStructure.PersonFunction; import net.sourceforge.fenixedu.domain.person.RoleType; import net.sourceforge.fenixedu.domain.space.Campus; import net.sourceforge.fenixedu.domain.space.Space; import net.sourceforge.fenixedu.domain.student.Registration; import net.sourceforge.fenixedu.domain.student.Student; import net.sourceforge.fenixedu.domain.studentCurriculum.CurriculumModule; import net.sourceforge.fenixedu.domain.studentCurriculum.Dismissal; import net.sourceforge.fenixedu.domain.thesis.Thesis; import net.sourceforge.fenixedu.domain.time.calendarStructure.AcademicInterval; import net.sourceforge.fenixedu.domain.time.calendarStructure.AcademicPeriod; import net.sourceforge.fenixedu.injectionCode.IGroup; import net.sourceforge.fenixedu.util.MarkType; import net.sourceforge.fenixedu.util.StringUtils; import org.apache.commons.collections.comparators.ReverseComparator; import pt.utl.ist.fenix.tools.util.StringAppender; import pt.utl.ist.fenix.tools.util.i18n.Language; import pt.utl.ist.fenix.tools.util.i18n.MultiLanguageString; import com.linkare.commons.metainfo.Linkare; public class Degree extends Degree_Base implements Comparable { public static final String DEFAULT_MINISTRY_CODE = "9999"; private static final Collator collator = Collator.getInstance(); static final public Comparator COMPARATOR_BY_NAME = new Comparator() { public int compare(final Degree o1, final Degree o2) { return collator.compare(o1.getName(), o2.getName()); } }; static final public Comparator COMPARATOR_BY_NAME_AND_ID = new Comparator() { public int compare(final Degree o1, final Degree o2) { final int nameResult = COMPARATOR_BY_NAME.compare(o1, o2); return nameResult == 0 ? COMPARATOR_BY_ID.compare(o1, o2) : nameResult; } }; static final private Comparator COMPARATOR_BY_DEGREE_TYPE = new Comparator() { public int compare(final Degree o1, final Degree o2) { return collator.compare(o1.getDegreeType().getLocalizedName(), o2.getDegreeType().getLocalizedName()); } }; static final public Comparator COMPARATOR_BY_DEGREE_TYPE_AND_NAME_AND_ID = new Comparator() { public int compare(final Degree o1, final Degree o2) { final int typeResult = COMPARATOR_BY_DEGREE_TYPE.compare(o1, o2); return typeResult == 0 ? COMPARATOR_BY_NAME_AND_ID.compare(o1, o2) : typeResult; } }; public int compareTo(final Degree o) { return Degree.COMPARATOR_BY_NAME_AND_ID.compare(this, o); } protected Degree() { super(); setRootDomainObject(RootDomainObject.getInstance()); new DegreeSite(this); } @Linkare(author = "Paulo Zenida", comments = "Added new parameter academicPeriod") public Degree(String name, String nameEn, String code, DegreeType degreeType, GradeScale gradeScale, final AcademicPeriod academicPeriod) { this(); commonFieldsChange(name, nameEn, code, gradeScale, ExecutionYear.readCurrentExecutionYear()); setAcademicPeriod(academicPeriod); if (degreeType == null) { throw new DomainException("degree.degree.type.not.null"); } this.setDegreeType(degreeType); } @Linkare(author = "Paulo Zenida", comments = "Added new parameter academicPeriod") public Degree(String name, String nameEn, String acronym, DegreeType degreeType, Double ectsCredits, GradeScale gradeScale, String prevailingScientificArea, final AcademicPeriod academicPeriod) { this(); commonFieldsChange(name, nameEn, acronym, gradeScale, ExecutionYear.readCurrentExecutionYear()); setAcademicPeriod(academicPeriod); newStructureFieldsChange(degreeType, ectsCredits, prevailingScientificArea); } private void commonFieldsChange(String name, String nameEn, String code, GradeScale gradeScale, ExecutionYear executionYear) { if (name == null) { throw new DomainException("degree.name.not.null"); } else if (nameEn == null) { throw new DomainException("degree.name.en.not.null"); } else if (code == null) { throw new DomainException("degree.code.not.null"); } DegreeInfo degreeInfo = getDegreeInfoFor(executionYear); if (degreeInfo == null) { degreeInfo = tryCreateUsingMostRecentInfo(executionYear); } degreeInfo.setName(MultiLanguageString.i18n().add("pt", name.trim()).add("en", nameEn.trim()).finish()); this.setNome(name); this.setNameEn(nameEn); this.setSigla(code.trim()); this.setGradeScale(gradeScale); } private void newStructureFieldsChange(DegreeType degreeType, Double ectsCredits, String prevailingScientificArea) { if (degreeType == null) { throw new DomainException("degree.degree.type.not.null"); } else if (ectsCredits == null) { throw new DomainException("degree.ectsCredits.not.null"); } this.setDegreeType(degreeType); this.setEctsCredits(ectsCredits); this.setPrevailingScientificArea(prevailingScientificArea == null ? null : prevailingScientificArea.trim()); } public void edit(String name, String nameEn, String code, DegreeType degreeType, GradeScale gradeScale, ExecutionYear executionYear) { commonFieldsChange(name, nameEn, code, gradeScale, executionYear); if (degreeType == null) { throw new DomainException("degree.degree.type.not.null"); } this.setDegreeType(degreeType); } public void edit(String name, String nameEn, String acronym, DegreeType degreeType, Double ectsCredits, GradeScale gradeScale, String prevailingScientificArea, ExecutionYear executionYear, AcademicPeriod academicPeriod) { checkIfCanEdit(degreeType); commonFieldsChange(name, nameEn, acronym, gradeScale, executionYear); setAcademicPeriod(academicPeriod); newStructureFieldsChange(degreeType, ectsCredits, prevailingScientificArea); } private void checkIfCanEdit(final DegreeType degreeType) { if (!this.getDegreeType().equals(degreeType) && hasAnyDegreeCurricularPlans()) { throw new DomainException("degree.cant.edit.bolonhaDegreeType"); } } public Boolean getCanBeDeleted() { if (hasAnyDegreeCurricularPlans()) { return false; } if (hasSite() && getSite().isDeletable()) { return false; } return true; } private void checkDeletion() { if (hasAnyDegreeCurricularPlans()) { throw new DomainException("error.degree.has.degree.curricular.plans"); } if (hasSite() && !getSite().isDeletable()) { throw new DomainException("error.degree.has.site.undeletable"); } } public void delete() { checkDeletion(); Iterator oicrIterator = getAssociatedOldInquiriesCoursesResIterator(); while (oicrIterator.hasNext()) { OldInquiriesCoursesRes oicr = oicrIterator.next(); oicrIterator.remove(); oicr.delete(); } Iterator oitrIterator = getAssociatedOldInquiriesTeachersResIterator(); while (oitrIterator.hasNext()) { OldInquiriesTeachersRes oitr = oitrIterator.next(); oitrIterator.remove(); oitr.delete(); } Iterator oisIterator = getAssociatedOldInquiriesSummariesIterator(); while (oisIterator.hasNext()) { OldInquiriesSummary ois = oisIterator.next(); oisIterator.remove(); ois.delete(); } // Iterator delegatesIterator = getDelegatesIterator(); // while (delegatesIterator.hasNext()) { // Delegate delegate = delegatesIterator.next(); // delegatesIterator.remove(); // delegate.delete(); // } Iterator degreeInfosIterator = getDegreeInfosIterator(); while (degreeInfosIterator.hasNext()) { DegreeInfo degreeInfo = degreeInfosIterator.next(); degreeInfosIterator.remove(); degreeInfo.delete(); } for (; !getParticipatingAnyCurricularCourseCurricularRules().isEmpty(); getParticipatingAnyCurricularCourseCurricularRules() .get(0).delete()) ; for (; hasAnyDelegateElections(); getDelegateElections().get(0).delete()) ; if (hasSite()) { getSite().delete(); } // checkDeletion assures that site is deletable if (hasSender()) { removeSender(); } removeUnit(); removePhdProgram(); removeRootDomainObject(); deleteDomainObject(); } public GradeScale getGradeScaleChain() { return super.getGradeScale() != null ? super.getGradeScale() : getDegreeType().getGradeScale(); } public DegreeCurricularPlan createPreBolonhaDegreeCurricularPlan(String name, DegreeCurricularPlanState state, Date initialDate, Date endDate, Integer degreeDuration, Integer minimalYearForOptionalCourses, Double neededCredits, MarkType markType, Integer numerusClausus, String anotation, GradeScale gradeScale) { if (!this.isBolonhaDegree()) { for (DegreeCurricularPlan dcp : this.getDegreeCurricularPlansSet()) { if (dcp.getName().equalsIgnoreCase(name)) { throw new DomainException("DEGREE.degreeCurricularPlan.existing.name.and.degree"); } } return new DegreeCurricularPlan(this, name, state, initialDate, endDate, degreeDuration, minimalYearForOptionalCourses, neededCredits, markType, numerusClausus, anotation, gradeScale); } else { throw new DomainException("DEGREE.calling.pre.bolonha.method.to.bolonha.degree"); } } @Linkare(author = "Paulo Zenida", comments = "Get the academic period through the invocation to the getAcademicPeriod() from the degree") public DegreeCurricularPlan createBolonhaDegreeCurricularPlan(String name, GradeScale gradeScale, Person creator) { if (this.isBolonhaDegree()) { if (name == null) { throw new DomainException("DEGREE.degree.curricular.plan.name.cannot.be.null"); } for (DegreeCurricularPlan dcp : this.getDegreeCurricularPlansSet()) { if (dcp.getName().equalsIgnoreCase(name)) { throw new DomainException("DEGREE.degreeCurricularPlan.existing.name.and.degree"); } } if (creator == null) { throw new DomainException("DEGREE.degree.curricular.plan.creator.cannot.be.null"); } final Role bolonhaRole = Role.getRoleByRoleType(RoleType.BOLONHA_MANAGER); if (!creator.hasPersonRoles(bolonhaRole)) { creator.addPersonRoles(bolonhaRole); } CurricularPeriod curricularPeriod = new CurricularPeriod(getAcademicPeriod()); return new DegreeCurricularPlan(this, name, gradeScale, creator, curricularPeriod); } else { throw new DomainException("DEGREE.calling.bolonha.method.to.non.bolonha.degree"); } } @Override @Deprecated public DegreeType getTipoCurso() { return getDegreeType(); } @Override @Deprecated public void setTipoCurso(final DegreeType degreeType) { setDegreeType(degreeType); } public DegreeType getDegreeType() { return super.getTipoCurso(); } public void setDegreeType(final DegreeType degreeType) { super.setTipoCurso(degreeType); } @Deprecated public DegreeType getBolonhaDegreeType() { return getDegreeType(); } public boolean isBolonhaDegree() { return getDegreeType().isBolonhaType(); } public boolean isEmpty() { return false; } public boolean isDegreeOrBolonhaDegreeOrBolonhaIntegratedMasterDegree() { return getDegreeType().isDegreeOrBolonhaDegreeOrBolonhaIntegratedMasterDegree(); } public List findDegreeCurricularPlansByState(DegreeCurricularPlanState state) { List result = new ArrayList(); if (!isBolonhaDegree()) { for (DegreeCurricularPlan degreeCurricularPlan : this.getDegreeCurricularPlansSet()) { if (degreeCurricularPlan.getState().equals(state)) { result.add(degreeCurricularPlan); } } } return result; } public List getActiveDegreeCurricularPlans() { List result = new ArrayList(); for (DegreeCurricularPlan degreeCurricularPlan : getDegreeCurricularPlansSet()) { if (degreeCurricularPlan.getState() == DegreeCurricularPlanState.ACTIVE) { result.add(degreeCurricularPlan); } } return result; } public List getPastDegreeCurricularPlans() { List result = new ArrayList(); for (DegreeCurricularPlan degreeCurricularPlan : getDegreeCurricularPlansSet()) { if (degreeCurricularPlan.getState() == DegreeCurricularPlanState.PAST) { result.add(degreeCurricularPlan); } } return result; } public List getDegreeCurricularPlansForYear(ExecutionYear year) { List result = new ArrayList(); for (final DegreeCurricularPlan degreeCurricularPlan : getDegreeCurricularPlansSet()) { if (degreeCurricularPlan.hasExecutionDegreeFor(year)) { result.add(degreeCurricularPlan); } } return result; } public List getExecutionDegrees() { List result = new ArrayList(); for (final DegreeCurricularPlan degreeCurricularPlan : getDegreeCurricularPlansSet()) { result.addAll(degreeCurricularPlan.getExecutionDegrees()); } return result; } public List getExecutionDegreesForExecutionYear(final ExecutionYear executionYear) { final List result = new ArrayList(); for (final DegreeCurricularPlan degreeCurricularPlan : getDegreeCurricularPlansSet()) { final ExecutionDegree executionDegree = degreeCurricularPlan.getExecutionDegreeByYear(executionYear); if (executionDegree != null) { result.add(executionDegree); } } return result; } public List getDegreeCurricularPlansExecutionYears() { Set result = new TreeSet(); for (final DegreeCurricularPlan degreeCurricularPlan : getDegreeCurricularPlansSet()) { for (final ExecutionDegree executionDegree : degreeCurricularPlan.getExecutionDegreesSet()) { result.add(executionDegree.getExecutionYear()); } } return new ArrayList(result); } public List getExecutedCurricularCoursesByExecutionYear(final ExecutionYear executionYear) { if (isBolonhaDegree()) { return Collections.emptyList(); } final List result = new ArrayList(); for (final DegreeCurricularPlan degreeCurricularPlan : getDegreeCurricularPlansSet()) { if (degreeCurricularPlan.getState().equals(DegreeCurricularPlanState.ACTIVE)) { for (final CurricularCourse course : degreeCurricularPlan.getCurricularCourses()) { for (final ExecutionCourse executionCourse : course.getAssociatedExecutionCourses()) { if (executionCourse.getExecutionPeriod().getExecutionYear().equals(executionYear)) { result.add(course); break; } } } } } return result; } public List getExecutedCurricularCoursesByExecutionYearAndYear(final ExecutionYear executionYear, final Integer curricularYear) { if (isBolonhaDegree()) { return Collections.emptyList(); } final List result = new ArrayList(); for (final DegreeCurricularPlan degreeCurricularPlan : getDegreeCurricularPlansSet()) { if (degreeCurricularPlan.getState().equals(DegreeCurricularPlanState.ACTIVE)) { for (final CurricularCourse course : degreeCurricularPlan.getCurricularCourses()) { xpto: for (final ExecutionCourse executionCourse : course.getAssociatedExecutionCourses()) { if (executionCourse.getExecutionPeriod().getExecutionYear().equals(executionYear)) { for (final CurricularCourseScope curricularCourseScope : course.getScopes()) { if (curricularCourseScope.getCurricularSemester().getCurricularYear().getYear().equals( curricularYear)) { result.add(course); break xpto; } } } } } } } return result; } public List getExecutionCourses(String curricularCourseAcronym, ExecutionSemester executionSemester) { final List result = new ArrayList(); for (final DegreeCurricularPlan degreeCurricularPlan : getDegreeCurricularPlansSet()) { for (final CurricularCourse course : degreeCurricularPlan.getCurricularCourses()) { if (course.getAcronym() != null && course.getAcronym().equalsIgnoreCase(curricularCourseAcronym)) { for (final ExecutionCourse executionCourse : course.getAssociatedExecutionCourses()) { if (executionSemester == executionCourse.getExecutionPeriod()) { result.add(executionCourse); } } } } } return result; } public List getExecutionCourses(final CurricularYear curricularYear, final ExecutionSemester executionSemester) { final List result = new ArrayList(); for (final DegreeCurricularPlan degreeCurricularPlan : getDegreeCurricularPlansSet()) { for (final CurricularCourse course : degreeCurricularPlan.getCurricularCourses()) { for (final ExecutionCourse executionCourse : course.getAssociatedExecutionCourses()) { if (executionSemester == executionCourse.getExecutionPeriod()) { for (final DegreeModuleScope scope : course.getDegreeModuleScopes()) { if (scope.getCurricularYear() == curricularYear.getYear() && scope.getCurricularSemester() == executionSemester.getSemester()) { result.add(executionCourse); } } } } } } return result; } @Deprecated public MultiLanguageString getNameFor(final ExecutionYear executionYear) { DegreeInfo degreeInfo = executionYear == null ? getMostRecentDegreeInfo() : getMostRecentDegreeInfo(executionYear); return degreeInfo == null ? MultiLanguageString.i18n().add("pt", super.getNome()).add("en", super.getNameEn()).finish() : degreeInfo.getName(); } @Deprecated public MultiLanguageString getNameFor(final ExecutionSemester executionSemester) { return getNameFor(executionSemester != null ? executionSemester.getExecutionYear() : null); } public MultiLanguageString getNameFor(final AcademicInterval academicInterval) { DegreeInfo degreeInfo = academicInterval == null ? getMostRecentDegreeInfo() : getMostRecentDegreeInfo(academicInterval); return degreeInfo == null ? MultiLanguageString.i18n().add("pt", super.getNome()).add("en", super.getNameEn()).finish() : degreeInfo.getName(); } @Override @Deprecated public String getNome() { return getName(); } @Linkare(author = "Paulo Zenida", comments = "Removed the deprecated annotation. JavaBean property cannot be replaced by method getNameFor(ExecutionYear)") public String getName() { DegreeInfo degreeInfo = getMostRecentDegreeInfo(); return degreeInfo == null ? StringUtils.EMPTY : degreeInfo.getName().getContent(Language.pt); } @Linkare(author = "Paulo Zenida", comments = "Removed the deprecated annotation. JavaBean property cannot be replaced by method getNameFor(ExecutionYear)") public String getNameEn() { DegreeInfo degreeInfo = getMostRecentDegreeInfo(); return degreeInfo == null ? StringUtils.EMPTY : degreeInfo.getName().getContent(Language.en); } final public MultiLanguageString getNameI18N() { return getNameFor(ExecutionYear.readCurrentExecutionYear()); } final public MultiLanguageString getNameI18N(ExecutionYear executionYear) { return getNameFor(executionYear); } final public String getPresentationName() { return getPresentationName(ExecutionYear.readCurrentExecutionYear(), Language.getLocale()); } public String getPresentationName(final ExecutionYear executionYear) { return getPresentationName(executionYear, Language.getLocale()); } protected String getPresentationName(final ExecutionYear executionYear, final Locale locale) { final StringBuilder res = new StringBuilder(); final String degreeType = getDegreeType().getLocalizedName(locale); if (!StringUtils.isEmpty(degreeType)) { res.append(degreeType).append(StringUtils.SINGLE_SPACE); res.append(ResourceBundle.getBundle("resources.ApplicationResources", locale).getString("label.in")); res.append(StringUtils.SINGLE_SPACE); } final MultiLanguageString mls = getNameFor(executionYear); final Language language = Language.valueOf(locale.getLanguage()); res.append(mls.hasContent(language) ? mls.getContent(language) : mls.getPreferedContent()); return res.toString(); } final public String getFilteredName() { return getFilteredName(ExecutionYear.readCurrentExecutionYear(), Language.getLocale()); } final public String getFilteredName(final ExecutionYear executionYear) { return getFilteredName(executionYear, Language.getLocale()); } public String getFilteredName(final ExecutionYear executionYear, final Locale locale) { final StringBuilder res = new StringBuilder(getNameFor(executionYear).getContent(Language.valueOf(locale.getLanguage()))); for (final net.sourceforge.fenixedu.domain.space.Campus campus : Space.getAllCampus()) { final String toRemove = " - " + campus.getName(); if (res.toString().contains(toRemove)) { res.replace(res.indexOf(toRemove), res.indexOf(toRemove) + toRemove.length(), StringUtils.EMPTY); } } return res.toString(); } public OldInquiriesCoursesRes getOldInquiriesCoursesResByCourseCodeAndExecutionPeriod(String code, ExecutionSemester executionSemester) { for (OldInquiriesCoursesRes oldInquiriesCoursesRes : this.getAssociatedOldInquiriesCoursesRes()) { if (oldInquiriesCoursesRes.getCourseCode().equalsIgnoreCase(code) && oldInquiriesCoursesRes.getExecutionPeriod().equals(executionSemester)) { return oldInquiriesCoursesRes; } } return null; } public List getOldInquiriesSummariesByExecutionPeriod(ExecutionSemester executionSemester) { List result = new ArrayList(); for (OldInquiriesSummary oldInquiriesSummary : this.getAssociatedOldInquiriesSummaries()) { if (oldInquiriesSummary.getExecutionPeriod().equals(executionSemester)) { result.add(oldInquiriesSummary); } } return result; } public List getOldInquiriesTeachersResByExecutionPeriodAndCurricularYearAndCourseCode( ExecutionSemester executionSemester, Integer curricularYear, String courseCode) { List result = new ArrayList(); for (OldInquiriesTeachersRes oldInquiriesTeachersRes : this.getAssociatedOldInquiriesTeachersRes()) { if (oldInquiriesTeachersRes.getExecutionPeriod().equals(executionSemester) && oldInquiriesTeachersRes.getCurricularYear().equals(curricularYear) && oldInquiriesTeachersRes.getCourseCode().equalsIgnoreCase(courseCode)) { result.add(oldInquiriesTeachersRes); } } return result; } public List getOldInquiriesTeachersResByExecutionPeriodAndCurricularYearAndCourseCodeAndTeacher( ExecutionSemester executionSemester, Integer curricularYear, String courseCode, Teacher teacher) { List result = new ArrayList(); for (OldInquiriesTeachersRes oldInquiriesTeachersRes : this.getAssociatedOldInquiriesTeachersRes()) { if (oldInquiriesTeachersRes.getExecutionPeriod().equals(executionSemester) && oldInquiriesTeachersRes.getCurricularYear().equals(curricularYear) && oldInquiriesTeachersRes.getCourseCode().equalsIgnoreCase(courseCode) && oldInquiriesTeachersRes.getTeacher().equals(teacher)) { result.add(oldInquiriesTeachersRes); } } return result; } public DegreeCurricularPlan getMostRecentDegreeCurricularPlan() { ExecutionDegree mostRecentExecutionDegree = null; boolean mustGetByInitialDate = false; for (final DegreeCurricularPlan degreeCurricularPlan : this.getActiveDegreeCurricularPlans()) { final ExecutionDegree executionDegree = degreeCurricularPlan.getMostRecentExecutionDegree(); if (mostRecentExecutionDegree == null) { mostRecentExecutionDegree = executionDegree; } else { if (mostRecentExecutionDegree.getExecutionYear().equals(executionDegree.getExecutionYear())) { mustGetByInitialDate = true; } else if (mostRecentExecutionDegree.isBefore(executionDegree)) { mustGetByInitialDate = false; mostRecentExecutionDegree = executionDegree; } } } if (mustGetByInitialDate) { // investigate dcps initial dates return getMostRecentDegreeCurricularPlanByInitialDate(); } else { return (mostRecentExecutionDegree != null) ? mostRecentExecutionDegree.getDegreeCurricularPlan() : null; } } private DegreeCurricularPlan getMostRecentDegreeCurricularPlanByInitialDate() { DegreeCurricularPlan mostRecentDegreeCurricularPlan = null; for (final DegreeCurricularPlan degreeCurricularPlan : this.getActiveDegreeCurricularPlans()) { if (mostRecentDegreeCurricularPlan == null || degreeCurricularPlan.getInitialDateYearMonthDay().isAfter( mostRecentDegreeCurricularPlan.getInitialDateYearMonthDay())) { mostRecentDegreeCurricularPlan = degreeCurricularPlan; } } return mostRecentDegreeCurricularPlan; } public Collection getActiveRegistrations() { final Collection result = new HashSet(); for (final DegreeCurricularPlan degreeCurricularPlan : getActiveDegreeCurricularPlans()) { result.addAll(degreeCurricularPlan.getActiveRegistrations()); } return result; } public DegreeCurricularPlan getLastActiveDegreeCurricularPlan() { DegreeCurricularPlan result = null; ExecutionDegree mostRecentExecutionDegree = null; for (final DegreeCurricularPlan degreeCurricularPlan : getActiveDegreeCurricularPlans()) { final ExecutionDegree executionDegree = degreeCurricularPlan.getMostRecentExecutionDegree(); if (executionDegree == null) { result = degreeCurricularPlan; } else if (mostRecentExecutionDegree == null || mostRecentExecutionDegree.isBefore(executionDegree)) { mostRecentExecutionDegree = executionDegree; } } return (mostRecentExecutionDegree == null) ? result : mostRecentExecutionDegree.getDegreeCurricularPlan(); } // ------------------------------------------------------------- // read static methods // ------------------------------------------------------------- private static final Map> degrees = new Hashtable>(); private static void loadCache() { synchronized (degrees) { degrees.clear(); for (final Degree degree : Degree.readNotEmptyDegrees()) { degrees.put(degree.getSigla().toLowerCase(), new SoftReference(degree)); } } } private static void updateCache(final Degree degree, final String newLowerCaseSigla) { final String currentLowerCaseSigla = (degree.getSigla() != null) ? degree.getSigla().toLowerCase() : StringUtils.EMPTY; synchronized (degrees) { degrees.remove(currentLowerCaseSigla); degrees.put(newLowerCaseSigla, new SoftReference(degree)); } } @Override public void setSigla(final String sigla) { updateCache(this, sigla.toLowerCase()); super.setSigla(sigla); } public static Degree readBySigla(final String sigla) { if (degrees.isEmpty()) { loadCache(); } final String lowerCaseString = sigla.toLowerCase(); final SoftReference degreeReference = degrees.get(lowerCaseString); if (degreeReference != null) { final Degree degree = degreeReference.get(); if (degree != null && degree.getRootDomainObject() == RootDomainObject.getInstance() && degree.getSigla().equalsIgnoreCase(lowerCaseString)) { return degree; } else { loadCache(); final SoftReference otherDegreeReference = degrees.get(lowerCaseString); if (otherDegreeReference != null) { final Degree otherDegree = otherDegreeReference.get(); if (otherDegree != null && otherDegree.getRootDomainObject() == RootDomainObject.getInstance() && otherDegree.getSigla().equalsIgnoreCase(lowerCaseString)) { return otherDegree; } } } } return null; } public static List readNotEmptyDegrees() { final List result = new ArrayList(RootDomainObject.getInstance().getDegrees()); result.remove(readEmptyDegree()); final Iterator it = result.iterator(); while (it.hasNext()) { final Degree degree = it.next(); if (degree.getDegreeType().isDisabledInThisInstitution()) { it.remove(); } } return result; } public static Degree readEmptyDegree() { return EmptyDegree.getInstance(); } public static List readOldDegrees() { List result = new ArrayList(); for (final Degree degree : Degree.readNotEmptyDegrees()) { if (!degree.isBolonhaDegree()) { result.add(degree); } } return result; } public static List readBolonhaDegrees() { List result = new ArrayList(); for (final Degree degree : Degree.readNotEmptyDegrees()) { if (degree.isBolonhaDegree()) { result.add(degree); } } return result; } public static List readBolonhaDegrees(final AdministrativeOfficeType type) { final List result = new ArrayList(); for (final Degree degree : Degree.readNotEmptyDegrees()) { if (degree.isBolonhaDegree() && degree.getDegreeType().getAdministrativeOfficeType() == type) { result.add(degree); } } return result; } public static List readAllByDegreeType(final DegreeType... degreeTypes) { final List degreeTypesList = Arrays.asList(degreeTypes); final List result = new ArrayList(); for (final Degree degree : Degree.readNotEmptyDegrees()) { if (degree.getDegreeType() != null && degreeTypesList.contains(degree.getDegreeType())) { result.add(degree); } } return result; } public static List readAllByDegreeCode(final String degreeCode) { final List result = new ArrayList(); for (final Degree degree : Degree.readNotEmptyDegrees()) { if (degree.getCode() != null && degree.getCode().equals(degreeCode)) { result.add(degree); } } return result; } public MultiLanguageString getQualificationLevel(final ExecutionYear executionYear) { return getMostRecentDegreeInfo(executionYear).getQualificationLevel(); } public MultiLanguageString getProfessionalExits(final ExecutionYear executionYear) { return getMostRecentDegreeInfo(executionYear).getProfessionalExits(); } public DegreeInfo getMostRecentDegreeInfo() { return getMostRecentDegreeInfo(ExecutionYear.readCurrentExecutionYear()); } public DegreeInfo getDegreeInfoFor(ExecutionYear executionYear) { return executionYear.getDegreeInfo(this); } @Deprecated public DegreeInfo getMostRecentDegreeInfo(ExecutionYear executionYear) { DegreeInfo result = null; for (final DegreeInfo degreeInfo : getDegreeInfosSet()) { final ExecutionYear executionYear2 = degreeInfo.getExecutionYear(); if (executionYear == executionYear2) { return degreeInfo; } if (executionYear2.isBefore(executionYear)) { if (result == null || executionYear2.isAfter(result.getExecutionYear())) { result = degreeInfo; } } } return result; } public DegreeInfo getMostRecentDegreeInfo(AcademicInterval academicInterval) { DegreeInfo result = null; for (final DegreeInfo degreeInfo : getDegreeInfosSet()) { AcademicInterval academicInterval2 = degreeInfo.getAcademicInterval(); if (academicInterval.equals(academicInterval2)) return degreeInfo; if (academicInterval2.isBefore(academicInterval)) { if (result == null || academicInterval2.isAfter(result.getAcademicInterval())) result = degreeInfo; } } return result; } @Linkare(author = "Paulo Zenida", comments = "Changed visibility from private to public") public DegreeInfo createCurrentDegreeInfo(ExecutionYear executionYear) { // first let's check if the current degree info exists already final DegreeInfo shouldBeThisOne = executionYear.getDegreeInfo(this); if (shouldBeThisOne != null) { return shouldBeThisOne; } // ok, so let's create a new one based on the most recent one, if // existing return tryCreateUsingMostRecentInfo(executionYear); } private DegreeInfo tryCreateUsingMostRecentInfo(final ExecutionYear executionYear) { final DegreeInfo mostRecentDegreeInfo = getMostRecentDegreeInfo(executionYear); return (mostRecentDegreeInfo != null) ? new DegreeInfo(mostRecentDegreeInfo, executionYear) : new DegreeInfo(this, executionYear); } public DegreeInfo createCurrentDegreeInfo() { return createCurrentDegreeInfo(ExecutionYear.readCurrentExecutionYear()); } @Linkare(author = "Paulo Zenida", comments = "Delegated the invocation of getYears() on degree") public List buildFullCurricularYearList() { final List result = new ArrayList(); for (int i = 1; i <= this.getYears(); i++) { result.add(i); } return result; } public ScientificCommission getMostRecentScientificCommission(Person person) { for (ExecutionYear ey = ExecutionYear.readCurrentExecutionYear(); ey != null; ey = ey.getPreviousExecutionYear()) { for (ScientificCommission member : getScientificCommissionMembers(ey)) { if (member.getPerson() == person) { return member; } } } return null; } public boolean isMemberOfAnyScientificCommission(Person person) { return getMostRecentScientificCommission(person) != null; } public boolean isMemberOfCurrentScientificCommission(Person person) { for (ScientificCommission member : getCurrentScientificCommissionMembers()) { if (member.getPerson() == person) { return true; } } return false; } public boolean isMemberOfCurrentScientificCommission(final Person person, final ExecutionYear executionYear) { if (person != null) { for (ScientificCommission member : getScientificCommissionMembers(executionYear)) { if (member.getPerson() == person) { return true; } } } return false; } public Collection getCurrentScientificCommissionMembers() { for (ExecutionYear ey = ExecutionYear.readCurrentExecutionYear(); ey != null; ey = ey.getPreviousExecutionYear()) { Collection members = getScientificCommissionMembers(ey); if (!members.isEmpty()) { return members; } } return Collections.emptyList(); } public Collection getScientificCommissionMembers(ExecutionYear executionYear) { for (DegreeCurricularPlan degreeCurricularPlan : getDegreeCurricularPlansForYear(executionYear)) { ExecutionDegree executionDegree = degreeCurricularPlan.getExecutionDegreeByYear(executionYear); if (executionDegree != null) { return new ArrayList(executionDegree.getScientificCommissionMembers()); } } return Collections.emptyList(); } public boolean isCoordinator(final Person person, final ExecutionYear executionYear) { for (final Coordinator coordinator : getCoordinators(executionYear, false)) { if (coordinator.getPerson() == person) { return true; } } return false; } final public boolean isCurrentCoordinator(final Person person) { for (final Coordinator coordinator : getCurrentCoordinators(false)) { if (coordinator.getPerson() == person) { return true; } } return false; } /** * Verifies if the given person was a coordinator for this degree regardless * of the execution year. * * @param person * the person to check * @return true if the person was a coordinator for a certain * execution degree */ final public boolean isCoordinatorInSomeExecutionYear(final Person person) { for (Coordinator coordinator : person.getCoordinators()) { if (coordinator.getExecutionDegree().getDegree() == this) { return true; } } return false; } final private Collection getCoordinators(final ExecutionYear executionYear, final boolean responsible) { final Collection result = new HashSet(); for (final DegreeCurricularPlan degreeCurricularPlan : getDegreeCurricularPlansSet()) { final ExecutionDegree executionDegree = degreeCurricularPlan.getExecutionDegreeByYear(executionYear); if (executionDegree != null) { result.addAll(responsible ? executionDegree.getResponsibleCoordinators() : executionDegree.getCoordinatorsList()); } } return result; } final private Collection getCurrentCoordinators(final boolean responsible) { SortedSet years = new TreeSet(new ReverseComparator(ExecutionYear.COMPARATOR_BY_YEAR)); years.addAll(getDegreeCurricularPlansExecutionYears()); ExecutionYear current = ExecutionYear.readCurrentExecutionYear(); for (ExecutionYear year : years) { if (year.isAfter(current)) { continue; } Collection coordinators = getCoordinators(year, responsible); if (!coordinators.isEmpty()) { return coordinators; } } return Collections.emptyList(); } public Collection getResponsibleCoordinators(final ExecutionYear executionYear) { return getCoordinators(executionYear, true); } public Collection getCurrentCoordinators() { return getCurrentCoordinators(false); } public Collection getCurrentResponsibleCoordinators() { return getCurrentCoordinators(true); } public Collection getResponsibleCoordinatorsTeachers(final ExecutionYear executionYear) { final Collection result = new TreeSet(Teacher.TEACHER_COMPARATOR_BY_CATEGORY_AND_NUMBER); collectCoordinatorsTeachers(result, getResponsibleCoordinators(executionYear)); return result; } public Collection getCurrentResponsibleCoordinatorsTeachers() { final Collection result = new TreeSet(Teacher.TEACHER_COMPARATOR_BY_CATEGORY_AND_NUMBER); collectCoordinatorsTeachers(result, getCurrentResponsibleCoordinators()); return result; } final private void collectCoordinatorsTeachers(final Collection result, final Collection coordinators) { for (final Coordinator coordinator : coordinators) { final Teacher teacher = coordinator.getTeacher(); if (teacher != null) { result.add(teacher); } } } public Collection getCampus(ExecutionYear executionYear) { Set result = new HashSet(); for (final DegreeCurricularPlan degreeCurricularPlan : getDegreeCurricularPlansSet()) { final ExecutionDegree executionDegree = degreeCurricularPlan.getExecutionDegreeByYear(executionYear); if (executionDegree != null && executionDegree.hasCampus()) { result.add(executionDegree.getCampus()); } } return new ArrayList(result); } public Collection getCurrentCampus() { ExecutionYear executionYear = ExecutionYear.readCurrentExecutionYear(); Collection result = this.getCampus(executionYear); if (!result.isEmpty()) { return result; } for (; executionYear != null; executionYear = executionYear.getNextExecutionYear()) { result = this.getCampus(executionYear); if (!result.isEmpty()) { return result; } } return new ArrayList(); } public String constructSchoolClassPrefix(final Integer curricularYear) { return isBolonhaDegree() ? StringAppender.append(getSigla(), "0", curricularYear.toString()) : StringUtils.EMPTY; } public List getLastStudentCurricularPlans() { final List result = new ArrayList(); for (final DegreeCurricularPlan degreeCurricularPlan : this.getDegreeCurricularPlansSet()) { for (final StudentCurricularPlan studentCurricularPlan : degreeCurricularPlan.getStudentCurricularPlans()) { if (studentCurricularPlan.getRegistration() == null) { continue; } if (!result.contains(studentCurricularPlan)) { result.add(studentCurricularPlan.getRegistration().getLastStudentDegreeCurricularPlansByDegree(this)); } } } return new ArrayList(result); } public List getStudentCurricularPlans(ExecutionYear executionYear) { List result = new ArrayList(); for (final DegreeCurricularPlan degreeCurricularPlan : getDegreeCurricularPlansForYear(executionYear)) { degreeCurricularPlan.getStudentsCurricularPlans(executionYear, result); } return result; } public boolean isFirstCycle() { return getDegreeType().isFirstCycle(); } public boolean isSecondCycle() { return getDegreeType().isSecondCycle(); } public boolean isAnyPublishedThesisAvailable() { for (DegreeCurricularPlan dcp : getDegreeCurricularPlans()) { for (CurricularCourse curricularCourse : dcp.getDissertationCurricularCourses(null)) { List enrolments = new ArrayList(); for (CurriculumModule module : curricularCourse.getCurriculumModules()) { if (module.isEnrolment()) { enrolments.add((IEnrolment) module); } else if (module.isDismissal()) { Dismissal dismissal = (Dismissal) module; enrolments.addAll(dismissal.getSourceIEnrolments()); } } for (IEnrolment enrolment : enrolments) { Thesis thesis = enrolment.getThesis(); if (thesis != null && thesis.hasPublication()) { return true; } } } } return false; } public boolean isAnyThesisAvailable() { return hasAnyThesis(); } /* * DELEGATE ELECTIONS */ public List getYearDelegateElectionsGivenExecutionYear(ExecutionYear executionYear) { List elections = new ArrayList(); for (DelegateElection election : this.getDelegateElections()) { if (election instanceof YearDelegateElection && election.getExecutionYear().equals(executionYear)) { elections.add((YearDelegateElection) election); } } return elections; } public List getYearDelegateElectionsGivenExecutionYearAndCurricularYear(ExecutionYear executionYear, CurricularYear curricularYear) { List elections = new ArrayList(); for (DelegateElection election : this.getDelegateElections()) { YearDelegateElection yearDelegateElection = (YearDelegateElection) election; if (yearDelegateElection.getExecutionYear().equals(executionYear) && yearDelegateElection.getCurricularYear().equals(curricularYear)) { elections.add(yearDelegateElection); } } return elections; } public YearDelegateElection getYearDelegateElectionWithLastCandidacyPeriod(ExecutionYear executionYear, CurricularYear curricularYear) { List elections = getYearDelegateElectionsGivenExecutionYearAndCurricularYear(executionYear, curricularYear); YearDelegateElection lastYearDelegateElection = null; if (!elections.isEmpty()) { lastYearDelegateElection = Collections.max(elections, DelegateElection.ELECTION_COMPARATOR_BY_CANDIDACY_START_DATE); } return lastYearDelegateElection; } public YearDelegateElection getYearDelegateElectionWithLastVotingPeriod(ExecutionYear executionYear, CurricularYear curricularYear) { List elections = getYearDelegateElectionsGivenExecutionYearAndCurricularYear(executionYear, curricularYear); YearDelegateElection lastYearDelegateElection = null; if (!elections.isEmpty()) { lastYearDelegateElection = Collections.max(elections, DelegateElection.ELECTION_COMPARATOR_BY_VOTING_START_DATE_AND_CANDIDACY_START_DATE); } return lastYearDelegateElection; } /* * ACTIVE DELEGATES */ public List getAllActiveDelegates() { List result = new ArrayList(); for (FunctionType functionType : FunctionType.getAllDelegateFunctionTypes()) { result.addAll(getAllActiveDelegatesByFunctionType(functionType, null)); } return result; } public List getAllActiveYearDelegates() { return getAllActiveDelegatesByFunctionType(FunctionType.DELEGATE_OF_YEAR, null); } public Student getActiveYearDelegateByCurricularYear(CurricularYear curricularYear) { final PersonFunction delegateFunction = getUnit().getActiveYearDelegatePersonFunctionByCurricularYear(curricularYear); return (delegateFunction != null ? delegateFunction.getPerson().getStudent() : null); } public List getAllActiveDelegatesByFunctionType(FunctionType functionType, ExecutionYear executionYear) { List result = new ArrayList(); final List delegateFunctions = getUnit().getAllActiveDelegatePersonFunctionsByFunctionType(functionType, executionYear); for (PersonFunction delegateFunction : delegateFunctions) { result.add(delegateFunction.getPerson().getStudent()); } return result; } public boolean hasActiveDelegateFunctionForStudent(Student student, ExecutionYear executionYear, FunctionType delegateFunctionType) { List delegates = getAllActiveDelegatesByFunctionType(delegateFunctionType, executionYear); for (Student delegate : delegates) { if (delegate.equals(student)) { return true; } } return false; } public boolean hasAnyActiveDelegateFunctionForStudent(Student student) { List delegates = getAllActiveDelegates(); for (Student delegate : delegates) { if (delegate.equals(student)) { return true; } } return false; } public PersonFunction getActiveDelegatePersonFunctionByStudentAndFunctionType(Student student, ExecutionYear executionYear, FunctionType functionType) { for (PersonFunction personFunction : getUnit().getAllActiveDelegatePersonFunctionsByFunctionType(functionType, executionYear)) { if (personFunction.getPerson().getStudent().equals(student)) { return personFunction; } } return null; } /* * DELEGATES FROM GIVEN EXECUTION YEAR (PAST DELEGATES) */ public Student getYearDelegateByExecutionYearAndCurricularYear(ExecutionYear executionYear, CurricularYear curricularYear) { final PersonFunction delegateFunction = getUnit().getYearDelegatePersonFunctionByExecutionYearAndCurricularYear( executionYear, curricularYear); return (delegateFunction != null ? delegateFunction.getPerson().getStudent() : null); } public List getAllDelegatesByExecutionYearAndFunctionType(ExecutionYear executionYear, FunctionType functionType) { List result = new ArrayList(); final List delegateFunctions = getUnit().getAllDelegatePersonFunctionsByExecutionYearAndFunctionType( executionYear, functionType); for (PersonFunction delegateFunction : delegateFunctions) { result.add(delegateFunction.getPerson().getStudent()); } return result; } public List getAllDelegatePersonFunctionsByStudentAndFunctionType(Student student, FunctionType functionType) { return getUnit().getAllDelegatePersonFunctionsByFunctionType(functionType); } /* * STUDENTS FROM DEGREE */ public List getAllStudents() { List result = new ArrayList(); for (Registration registration : getActiveRegistrations()) { result.add(registration.getStudent()); } return result; } public List getStudentsFromGivenCurricularYear(int curricularYear, ExecutionYear executionYear) { List result = new ArrayList(); for (Registration registration : getActiveRegistrations()) { if (registration.getCurricularYear(executionYear) == curricularYear) { result.add(registration.getStudent()); } } return result; } /* * This method is directed to Bolonha Integrated Master Degrees */ public List getSecondCycleStudents(ExecutionYear executionYear) { List result = new ArrayList(); if (getDegreeType() == DegreeType.BOLONHA_INTEGRATED_MASTER_DEGREE) { for (Registration registration : getActiveRegistrations()) { final int studentCurricularYear = registration.getCurricularYear(executionYear); // TODO how to make this not hardcoded? if (studentCurricularYear >= 4 && studentCurricularYear <= 5) { result.add(registration.getStudent()); } } } return result; } /* * This method is directed to Bolonha Integrated Master Degrees */ public List getFirstCycleStudents(ExecutionYear executionYear) { List result = new ArrayList(); if (getDegreeType() == DegreeType.BOLONHA_INTEGRATED_MASTER_DEGREE) { for (Registration registration : getActiveRegistrations()) { final int studentCurricularYear = registration.getCurricularYear(executionYear); // TODO how to make this not hardcoded? if (studentCurricularYear >= 1 && studentCurricularYear <= 3) { result.add(registration.getStudent()); } } } return result; } /* * CURRICULAR COURSES FROM DEGREE */ public Set getAllCurricularCourses(ExecutionYear executionYear) { Set result = new HashSet(); for (DegreeCurricularPlan dcp : getActiveDegreeCurricularPlans()) { result.addAll(dcp.getCurricularCoursesWithExecutionIn(executionYear)); } return result; } public Set getCurricularCoursesFromGivenCurricularYear(int curricularYear, ExecutionYear executionYear) { Set result = new HashSet(); for (DegreeCurricularPlan dcp : getActiveDegreeCurricularPlans()) { result.addAll(dcp.getCurricularCoursesByExecutionYearAndCurricularYear(executionYear, curricularYear)); } return result; } /* * This method is directed to Bolonha Integrated Master Degrees */ public Set getFirstCycleCurricularCourses(ExecutionYear executionYear) { Set result = new HashSet(); for (DegreeCurricularPlan dcp : getActiveDegreeCurricularPlans()) { // TODO how to make this nothardcoded? for (int i = 1; i <= 3; i++) { result.addAll(dcp.getCurricularCoursesByExecutionYearAndCurricularYear(executionYear, i)); } } return result; } /* * This method is directed to Bolonha Integrated Master Degrees */ public Set getSecondCycleCurricularCourses(ExecutionYear executionYear) { Set result = new HashSet(); for (DegreeCurricularPlan dcp : getActiveDegreeCurricularPlans()) { for (int i = 4; i <= 5; i++) { // TODO: how to make this not // hardcoded? result.addAll(dcp.getCurricularCoursesByExecutionYearAndCurricularYear(executionYear, i)); } } return result; } public static List getDegreesDelegatesGroupByDegreeType(DegreeType degreeType) { List result = new ArrayList(); List degrees = Degree.readAllByDegreeType(degreeType); for (Degree degree : degrees) { result.add(new DelegatesGroup(degree)); } return result; } /** * @return true if any of the thesis associated with this * degree is not final */ public boolean hasPendingThesis() { for (Thesis thesis : getThesis()) { if (!thesis.isFinalThesis()) { return true; } } return false; } @Override public Double getEctsCredits() { final Double ectsCredits = super.getEctsCredits(); return (ectsCredits != null) ? ectsCredits : getDegreeType().getDefaultEctsCredits(); } public boolean hasEctsCredits() { return super.getEctsCredits() != null; } @Override @Deprecated public String getCode() { return getMinistryCode(); } @Override @Deprecated public void setCode(final String ministryCode) { setMinistryCode(ministryCode); } @Override public String getMinistryCode() { final String code = super.getCode(); if (!StringUtils.isEmpty(code)) { return code; } final String ministryCode = super.getMinistryCode(); if (!StringUtils.isEmpty(ministryCode)) { return ministryCode; } return DEFAULT_MINISTRY_CODE; } @Override public void setMinistryCode(final String ministryCode) { final String value = ministryCode == null || ministryCode.length() == 0 ? null : ministryCode; super.setMinistryCode(value); super.setCode(value); } @Override public void setIdCardName(final String idCardName) { super.setIdCardName(idCardName.toUpperCase()); } @Override public void setNome(final String nome) { super.setNome(nome); setIdCardName(nome); } public boolean isActive() { ExecutionYear currentExecutionYear = ExecutionYear.readCurrentExecutionYear(); for (DegreeCurricularPlan curricularPlan : getDegreeCurricularPlans()) { if (curricularPlan.getExecutionDegreeByYear(currentExecutionYear) != null) { return true; } } return false; } public PersonFunction getMostSignificantDelegateFunctionForStudent(Student student, ExecutionYear executionYear) { if (hasActiveDelegateFunctionForStudent(student, executionYear, FunctionType.DELEGATE_OF_INTEGRATED_MASTER_DEGREE)) { return getActiveDelegatePersonFunctionByStudentAndFunctionType(student, executionYear, FunctionType.DELEGATE_OF_INTEGRATED_MASTER_DEGREE); } else if (hasActiveDelegateFunctionForStudent(student, executionYear, FunctionType.DELEGATE_OF_MASTER_DEGREE)) { return getActiveDelegatePersonFunctionByStudentAndFunctionType(student, executionYear, FunctionType.DELEGATE_OF_MASTER_DEGREE); } else if (hasActiveDelegateFunctionForStudent(student, executionYear, FunctionType.DELEGATE_OF_DEGREE)) { return getActiveDelegatePersonFunctionByStudentAndFunctionType(student, executionYear, FunctionType.DELEGATE_OF_DEGREE); } else { return getActiveDelegatePersonFunctionByStudentAndFunctionType(student, executionYear, FunctionType.DELEGATE_OF_YEAR); } } public boolean canCreateGratuityEvent() { return true; } public boolean isDEA() { return getDegreeType() == DegreeType.BOLONHA_ADVANCED_SPECIALIZATION_DIPLOMA; } @Linkare(author = "Paulo Zenida") @Override public String getShortDescription() { return getPresentationName(); } @Linkare(author = "Paulo Zenida") @Override public AcademicPeriod getAcademicPeriod() { if (super.getAcademicPeriod() == null) { return getDegreeType().getAcademicPeriod(); } return super.getAcademicPeriod(); } @Linkare(author = "Paulo Zenida") private boolean hasAcademicPeriod() { return super.getAcademicPeriod() != null; } @Linkare(author = "Paulo Zenida") public int getYears() { return hasAcademicPeriod() ? Float.valueOf(getAcademicPeriod().getWeight()).intValue() : getDegreeType().getYears(); } @Linkare(author = "Paulo Zenida") public int getSemesters() { return hasAcademicPeriod() ? Float.valueOf(getAcademicPeriod().getWeight() / AcademicPeriod.SEMESTER.getWeight()) .intValue() : getDegreeType().getSemesters(); } @Linkare(author = "Paulo Zenida") public Integer getYears(final CycleType cycleType) { if (cycleType == null) { return getYears(); } return getDegreeType().hasCycleTypes(cycleType) && hasAcademicPeriod() ? Float.valueOf(getAcademicPeriod().getWeight()) .intValue() : getDegreeType().getYears(cycleType); } @Linkare(author = "Paulo Zenida") public Integer getSemesters(final CycleType cycleType) { if (cycleType == null) { return getSemesters(); } return getDegreeType().hasCycleTypes(cycleType) && hasAcademicPeriod() ? Float.valueOf( getYears(cycleType) / AcademicPeriod.SEMESTER.getWeight()).intValue() : getDegreeType().getSemesters(cycleType); } @Linkare(author = "Paulo Zenida") public double getDefaultEctsCredits() { if (!hasAcademicPeriod()) { return getDegreeType().getDefaultEctsCredits(); } if (getAcademicPeriod().equals(AcademicPeriod.YEAR)) { return 30d; } else if (getAcademicPeriod().equals(AcademicPeriod.TWO_YEAR)) { return 120d; } else if (getAcademicPeriod().equals(AcademicPeriod.THREE_YEAR)) { return 180d; } else if (getAcademicPeriod().equals(AcademicPeriod.FIVE_YEAR)) { return 300d; } else if (getAcademicPeriod().equals(AcademicPeriod.FOUR_YEAR)) { return 240d; } else { return 0d; } } }