package net.sourceforge.fenixedu.domain; import java.text.Collator; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.Comparator; import java.util.Date; import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; import java.util.TreeSet; import net.sourceforge.fenixedu.applicationTier.Servico.exceptions.ExistingCompetenceCourseInformationException; import net.sourceforge.fenixedu.commons.CollectionUtils; import net.sourceforge.fenixedu.domain.degreeStructure.BibliographicReferences; import net.sourceforge.fenixedu.domain.degreeStructure.CompetenceCourseInformation; import net.sourceforge.fenixedu.domain.degreeStructure.CompetenceCourseInformationChangeRequest; import net.sourceforge.fenixedu.domain.degreeStructure.CompetenceCourseLevel; import net.sourceforge.fenixedu.domain.degreeStructure.CompetenceCourseLoad; import net.sourceforge.fenixedu.domain.degreeStructure.CurricularStage; import net.sourceforge.fenixedu.domain.degreeStructure.RegimeType; import net.sourceforge.fenixedu.domain.degreeStructure.BibliographicReferences.BibliographicReference; import net.sourceforge.fenixedu.domain.degreeStructure.BibliographicReferences.BibliographicReferenceType; import net.sourceforge.fenixedu.domain.exceptions.DomainException; import net.sourceforge.fenixedu.domain.organizationalStructure.CompetenceCourseGroupUnit; import net.sourceforge.fenixedu.domain.organizationalStructure.DepartmentUnit; import net.sourceforge.fenixedu.domain.organizationalStructure.ScientificAreaUnit; import net.sourceforge.fenixedu.domain.time.calendarStructure.AcademicPeriod; import net.sourceforge.fenixedu.util.StringFormatter; import net.sourceforge.fenixedu.util.UniqueAcronymCreator; import org.apache.commons.beanutils.BeanComparator; import org.apache.commons.collections.Predicate; import org.apache.commons.collections.comparators.ComparatorChain; import org.joda.time.YearMonthDay; import pt.ist.fenixWebFramework.security.accessControl.Checked; 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 CompetenceCourse extends CompetenceCourse_Base { @Linkare(author = "Paulo Zenida", comments = "Changed the implementation to include the idInternal and, hence, distinct between competence courses with the same name but different ids") public static final Comparator COMPETENCE_COURSE_COMPARATOR_BY_NAME = new ComparatorChain(); static { ((ComparatorChain) COMPETENCE_COURSE_COMPARATOR_BY_NAME) .addComparator(new BeanComparator("name", Collator.getInstance())); ((ComparatorChain) COMPETENCE_COURSE_COMPARATOR_BY_NAME).addComparator(new BeanComparator("idInternal")); } protected CompetenceCourse() { super(); setRootDomainObject(RootDomainObject.getInstance()); } public CompetenceCourse(String code, String name, Collection departments) { this(); super.setCurricularStage(CurricularStage.OLD); fillFields(code, name); if (departments != null) { addDepartments(departments); } } @Linkare(author = "Paulo Zenida", comments = "Delegated in the new created method having code as parameter") public CompetenceCourse(String name, String nameEn, Boolean basic, RegimeType regimeType, CompetenceCourseLevel competenceCourseLevel, CompetenceCourseType type, CurricularStage curricularStage, CompetenceCourseGroupUnit unit) { this(null, name, nameEn, basic, regimeType, competenceCourseLevel, type, curricularStage, unit); } @Linkare(author = "Paulo Zenida") public CompetenceCourse(final String code, String name, String nameEn, Boolean basic, RegimeType regimeType, CompetenceCourseLevel competenceCourseLevel, CompetenceCourseType type, CurricularStage curricularStage, CompetenceCourseGroupUnit unit) { this(); super.setCurricularStage(curricularStage); setType(type); super.setCode(code == null ? String.valueOf(getIdInternal()) : code); if (!unit.isCompetenceCourseGroupUnit()) { throw new DomainException(""); } super.setCompetenceCourseGroupUnit(unit); CompetenceCourseInformation competenceCourseInformation = new CompetenceCourseInformation(name.trim(), nameEn.trim(), basic, regimeType, competenceCourseLevel, ExecutionSemester.readActualExecutionSemester()); super.addCompetenceCourseInformations(competenceCourseInformation); // unique acronym creation try { final UniqueAcronymCreator uniqueAcronymCreator = new UniqueAcronymCreator( "name", "acronym", (Set) CompetenceCourse.readBolonhaCompetenceCourses(), true); competenceCourseInformation.setAcronym(uniqueAcronymCreator.create(this).getLeft()); } catch (Exception e) { // Linkare - Changed by Paulo Zenida System.out.println("competence.course.unable.to.create.acronym"); competenceCourseInformation.setAcronym(code); // Linkare - End changes by Paulo Zenida } } @Linkare(author = "Paulo Zenida") public static void checkIfCanCreateCompetenceCourse(final String name, final String nameEn) throws ExistingCompetenceCourseInformationException { final String normalizedName = StringFormatter.normalize(name); final String normalizedNameEn = StringFormatter.normalize(nameEn); for (final CompetenceCourse competenceCourse : CompetenceCourse.readBolonhaCompetenceCourses()) { if (StringFormatter.normalize(competenceCourse.getName()).equals(normalizedName)) { throw new ExistingCompetenceCourseInformationException("error.existingCompetenceCourseWithSameName", competenceCourse.getDepartmentUnit().getName()); } if (StringFormatter.normalize(competenceCourse.getNameEn()).equals(normalizedNameEn)) { throw new ExistingCompetenceCourseInformationException("error.existingCompetenceCourseWithSameNameEn", competenceCourse.getDepartmentUnit().getName()); } } } @Linkare(author = "Paulo Zenida") public static void checkIfCodeAlreadyExists(String code) throws ExistingCompetenceCourseInformationException { for (final CompetenceCourse competenceCourse : CompetenceCourse.readBolonhaCompetenceCourses()) { if (competenceCourse.getCode() != null && competenceCourse.getCode().equals(code)) { throw new ExistingCompetenceCourseInformationException("error.existingCompetenceCourseWithSameCode", competenceCourse.getDepartmentUnit().getName()); } } } public boolean isBolonha() { return !getCurricularStage().equals(CurricularStage.OLD); } public void addCompetenceCourseLoad(Double theoreticalHours, Double problemsHours, Double laboratorialHours, Double seminaryHours, Double fieldWorkHours, Double trainingPeriodHours, Double tutorialOrientationHours, Double autonomousWorkHours, Double ectsCredits, Integer order, AcademicPeriod academicPeriod) { checkIfCanEdit(false); getRecentCompetenceCourseInformation().addCompetenceCourseLoads( new CompetenceCourseLoad(theoreticalHours, problemsHours, laboratorialHours, seminaryHours, fieldWorkHours, trainingPeriodHours, tutorialOrientationHours, autonomousWorkHours, ectsCredits, order, academicPeriod)); } public BibliographicReference getBibliographicReference(Integer oid) { return getRecentCompetenceCourseInformation().getBibliographicReferences().getBibliographicReference(oid); } public BibliographicReferences getBibliographicReferences() { return getBibliographicReferences(null); } public BibliographicReferences getBibliographicReferences(final ExecutionSemester period) { final CompetenceCourseInformation information = findCompetenceCourseInformationForExecutionPeriod(period); return (information != null) ? information.getBibliographicReferences() : null; } public List getMainBibliographicReferences() { return getMainBibliographicReferences(null); } @Linkare(author = "Paulo Zenida", comments = "Prevented NullPointerException from being thrown when there are no bibliographic references.") public List getMainBibliographicReferences(final ExecutionSemester period) { return this.getBibliographicReferences(period) != null ? this.getBibliographicReferences(period) .getMainBibliographicReferences() : Collections. emptyList(); } public List getSecondaryBibliographicReferences() { return getSecondaryBibliographicReferences(null); } @Linkare(author = "Paulo Zenida", comments = "Prevented NullPointerException from being thrown when there are no bibliographic references.") public List getSecondaryBibliographicReferences(final ExecutionSemester period) { return this.getBibliographicReferences(period) != null ? this.getBibliographicReferences(period) .getSecondaryBibliographicReferences() : Collections. emptyList(); } public List getAllBibliographicReferences( final ExecutionSemester executionSemester) { final List result = new ArrayList(); result.addAll(getMainBibliographicReferences(executionSemester)); result.addAll(getSecondaryBibliographicReferences(executionSemester)); return result; } public void createBibliographicReference(String year, String title, String authors, String reference, String url, BibliographicReferenceType type) { checkIfCanEdit(false); getBibliographicReferences().createBibliographicReference(year, title, authors, reference, url, type); getRecentCompetenceCourseInformation().setBibliographicReferences(getBibliographicReferences()); } public void editBibliographicReference(Integer oid, String year, String title, String authors, String reference, String url, BibliographicReferenceType type) { getBibliographicReferences().editBibliographicReference(oid, year, title, authors, reference, url, type); getRecentCompetenceCourseInformation().setBibliographicReferences(getBibliographicReferences()); } public void deleteBibliographicReference(Integer oid) { getBibliographicReferences().deleteBibliographicReference(oid); getRecentCompetenceCourseInformation().setBibliographicReferences(getBibliographicReferences()); } public void switchBibliographicReferencePosition(Integer oldPosition, Integer newPosition) { getBibliographicReferences().switchBibliographicReferencePosition(oldPosition, newPosition); getRecentCompetenceCourseInformation().setBibliographicReferences(getBibliographicReferences()); } private void fillFields(String code, String name) { if (code == null || code.length() == 0) { throw new DomainException("invalid.competenceCourse.values"); } if (name == null || name.length() == 0) { throw new DomainException("invalid.competenceCourse.values"); } super.setCode(code); super.setName(name); } public void edit(String code, String name, Collection departments) { fillFields(code, name); for (final Department department : this.getDepartments()) { if (!departments.contains(department)) { super.removeDepartments(department); } } for (final Department department : departments) { if (!hasDepartments(department)) { super.addDepartments(department); } } } public void edit(String name, String nameEn, Boolean basic, CompetenceCourseLevel competenceCourseLevel, CompetenceCourseType type, CurricularStage curricularStage) { changeCurricularStage(curricularStage); setType(type); getRecentCompetenceCourseInformation().edit(name.trim(), nameEn.trim(), basic, competenceCourseLevel); // unique acronym creation String acronym = null; try { final UniqueAcronymCreator uniqueAcronymCreator = new UniqueAcronymCreator( "name", "acronym", (Set) CompetenceCourse.readBolonhaCompetenceCourses(), true); acronym = uniqueAcronymCreator.create(this).getLeft(); } catch (Exception e) { throw new DomainException("competence.course.unable.to.create.acronym"); } getRecentCompetenceCourseInformation().setAcronym(acronym); } public void editAcronym(String acronym) { Set bolonhaCompetenceCourses = (Set) CompetenceCourse.readBolonhaCompetenceCourses(); for (final CompetenceCourse competenceCourse : bolonhaCompetenceCourses) { if (!competenceCourse.equals(this) && competenceCourse.getAcronym().equalsIgnoreCase(acronym.trim())) { throw new DomainException("competenceCourse.existing.acronym", competenceCourse.getName(), competenceCourse .getDepartmentUnit().getDepartment().getRealName()); } } getRecentCompetenceCourseInformation().setAcronym(acronym); } public void changeCurricularStage(CurricularStage curricularStage) { if (curricularStage.equals(CurricularStage.APPROVED)) { super.setCreationDateYearMonthDay(new YearMonthDay()); } setCurricularStage(curricularStage); } private void checkIfCanEdit(boolean scientificCouncilEdit) { if (!scientificCouncilEdit && this.getCurricularStage().equals(CurricularStage.APPROVED)) { throw new DomainException("competenceCourse.approved"); } } public void edit(String objectives, String program, String evaluationMethod, String objectivesEn, String programEn, String evaluationMethodEn) { getRecentCompetenceCourseInformation().edit(objectives, program, evaluationMethod, objectivesEn, programEn, evaluationMethodEn); } public void delete() { if (hasAnyAssociatedCurricularCourses()) { throw new DomainException("mustDeleteCurricularCoursesFirst"); } else if (this.getCurricularStage().equals(CurricularStage.APPROVED)) { throw new DomainException("competenceCourse.approved"); } getDepartments().clear(); removeCompetenceCourseGroupUnit(); for (; !getCompetenceCourseInformations().isEmpty(); getCompetenceCourseInformations().get(0).delete()) ; removeRootDomainObject(); super.deleteDomainObject(); } public void addCurricularCourses(Collection curricularCourses) { for (CurricularCourse curricularCourse : curricularCourses) { addAssociatedCurricularCourses(curricularCourse); } } public void addDepartments(Collection departments) { for (Department department : departments) { super.addDepartments(department); } } private TreeSet getOrderedCompetenceCourseInformations() { TreeSet informations = new TreeSet( CompetenceCourseInformation.COMPARATORY_BY_EXECUTION_PERIOD); informations.addAll(getCompetenceCourseInformationsSet()); return informations; } private CompetenceCourseInformation getRecentCompetenceCourseInformation() { final Set competenceCourseInformations = getCompetenceCourseInformationsSet(); if (competenceCourseInformations.isEmpty()) { return null; } return Collections.max(competenceCourseInformations, CompetenceCourseInformation.COMPARATORY_BY_EXECUTION_PERIOD); } private CompetenceCourseInformation getOldestCompetenceCourseInformation() { final Set competenceCourseInformations = getCompetenceCourseInformationsSet(); if (competenceCourseInformations.isEmpty()) { return null; } return Collections.min(competenceCourseInformations, CompetenceCourseInformation.COMPARATORY_BY_EXECUTION_PERIOD); } public boolean isCompetenceCourseInformationDefinedAtExecutionPeriod(final ExecutionSemester executionSemester) { final CompetenceCourseInformation information = findCompetenceCourseInformationForExecutionPeriod(executionSemester); return information != null && information.getExecutionPeriod().equals(executionSemester); } public CompetenceCourseInformation findCompetenceCourseInformationForExecutionPeriod(final ExecutionSemester executionSemester) { if (!isBolonha()) { return null; } if (executionSemester == null) { return getRecentCompetenceCourseInformation(); } if (executionSemester.isBefore(getOldestCompetenceCourseInformation().getExecutionPeriod())) { return null; } CompetenceCourseInformation minCompetenceCourseInformation = null; for (final CompetenceCourseInformation competenceCourseInformation : getOrderedCompetenceCourseInformations()) { if (competenceCourseInformation.getExecutionPeriod().isAfter(executionSemester)) { return minCompetenceCourseInformation; } else { minCompetenceCourseInformation = competenceCourseInformation; } } return minCompetenceCourseInformation; } public CompetenceCourseInformation findCompetenceCourseInformationForExecutionYear(final ExecutionYear executionYear) { if (!isBolonha()) { return null; } if (executionYear == null) { return getRecentCompetenceCourseInformation(); } if (executionYear.isBefore(getOldestCompetenceCourseInformation().getExecutionYear())) { return null; } CompetenceCourseInformation minCompetenceCourseInformation = null; for (final CompetenceCourseInformation competenceCourseInformation : getOrderedCompetenceCourseInformations()) { if (competenceCourseInformation.getExecutionYear().isBeforeOrEquals(executionYear)) { minCompetenceCourseInformation = competenceCourseInformation; } else { return minCompetenceCourseInformation; } } return minCompetenceCourseInformation; } public String getName(final ExecutionSemester period) { final CompetenceCourseInformation information = findCompetenceCourseInformationForExecutionPeriod(period); if ((super.getName() == null || super.getName().length() == 0) && information != null) { return information.getName(); } return super.getName(); } @Override public String getName() { return getName(null); } public String getNameEn(final ExecutionSemester period) { final CompetenceCourseInformation information = findCompetenceCourseInformationForExecutionPeriod(period); return information != null ? information.getNameEn() : null; } @Linkare(author = "Paulo Zenida", comments = "When no name in english, return the name.") public String getNameEn() { final String nameEn = getNameEn(null); return nameEn == null ? getName(null) : nameEn; } public String getAcronym(final ExecutionSemester period) { final CompetenceCourseInformation information = findCompetenceCourseInformationForExecutionPeriod(period); return information != null ? information.getAcronym() : null; } public String getAcronym() { return getAcronym(null); } public void setAcronym(String acronym) { getRecentCompetenceCourseInformation().setAcronym(acronym); } public boolean isBasic(final ExecutionSemester period) { final CompetenceCourseInformation information = findCompetenceCourseInformationForExecutionPeriod(period); return information != null ? information.getBasic() : null; } public boolean isBasic() { return isBasic(null); } public RegimeType getRegime(final ExecutionSemester period) { final CompetenceCourseInformation information = findCompetenceCourseInformationForExecutionPeriod(period); return information != null ? information.getRegime() : null; } public RegimeType getRegime(final ExecutionYear executionYear) { final CompetenceCourseInformation information = findCompetenceCourseInformationForExecutionYear(executionYear); return information != null ? information.getRegime() : null; } public RegimeType getRegime() { return getRegime((ExecutionSemester) null); } public void setRegime(RegimeType regimeType) { getRecentCompetenceCourseInformation().setRegime(regimeType); } public CompetenceCourseLevel getCompetenceCourseLevel(final ExecutionSemester period) { final CompetenceCourseInformation information = findCompetenceCourseInformationForExecutionPeriod(period); return information != null ? information.getCompetenceCourseLevel() : null; } public CompetenceCourseLevel getCompetenceCourseLevel() { return getCompetenceCourseLevel(null); } public List getCompetenceCourseLoads(final ExecutionSemester period) { final CompetenceCourseInformation information = findCompetenceCourseInformationForExecutionPeriod(period); return information != null ? information.getCompetenceCourseLoads() : null; } public List getCompetenceCourseLoads() { return getCompetenceCourseLoads(null); } public int getCompetenceCourseLoadsCount(final ExecutionSemester period) { final CompetenceCourseInformation information = findCompetenceCourseInformationForExecutionPeriod(period); return information != null ? information.getCompetenceCourseLoadsCount() : 0; } public int getCompetenceCourseLoadsCount() { return getCompetenceCourseLoadsCount(null); } public String getObjectives(final ExecutionSemester period) { final CompetenceCourseInformation information = findCompetenceCourseInformationForExecutionPeriod(period); return information != null ? information.getObjectives() : null; } public String getObjectives() { return getObjectives(null); } public String getProgram(final ExecutionSemester period) { final CompetenceCourseInformation information = findCompetenceCourseInformationForExecutionPeriod(period); return information != null ? information.getProgram() : null; } public String getProgram() { return getProgram(null); } public String getEvaluationMethod(final ExecutionSemester period) { final CompetenceCourseInformation information = findCompetenceCourseInformationForExecutionPeriod(period); return information != null ? information.getEvaluationMethod() : null; } public String getEvaluationMethod() { return getEvaluationMethod(null); } public String getObjectivesEn(final ExecutionSemester period) { final CompetenceCourseInformation information = findCompetenceCourseInformationForExecutionPeriod(period); return information != null ? information.getObjectivesEn() : null; } public String getObjectivesEn() { return getObjectivesEn(null); } public String getProgramEn(final ExecutionSemester period) { final CompetenceCourseInformation information = findCompetenceCourseInformationForExecutionPeriod(period); return information != null ? information.getProgramEn() : null; } public String getProgramEn() { return getProgramEn(null); } public String getEvaluationMethodEn(final ExecutionSemester period) { final CompetenceCourseInformation information = findCompetenceCourseInformationForExecutionPeriod(period); return information != null ? information.getEvaluationMethodEn() : null; } public String getEvaluationMethodEn() { return getEvaluationMethodEn(null); } public double getTheoreticalHours() { return getTheoreticalHours((Integer) null, (ExecutionSemester) null); } public Double getTheoreticalHours(final Integer order) { return getTheoreticalHours(order, (ExecutionSemester) null); } public double getTheoreticalHours(final ExecutionSemester period) { return getTheoreticalHours(null, period); } public double getTheoreticalHours(Integer order, ExecutionSemester period) { final CompetenceCourseInformation information = findCompetenceCourseInformationForExecutionPeriod(period); return (information != null) ? information.getTheoreticalHours(order) : 0.0; } public double getProblemsHours() { return getProblemsHours((Integer) null, (ExecutionSemester) null); } public Double getProblemsHours(final Integer order) { return getProblemsHours(order, (ExecutionSemester) null); } public double getProblemsHours(final ExecutionSemester period) { return getProblemsHours(null, period); } public double getProblemsHours(final Integer order, final ExecutionSemester period) { final CompetenceCourseInformation information = findCompetenceCourseInformationForExecutionPeriod(period); return (information != null) ? information.getProblemsHours(order) : 0.0; } public double getLaboratorialHours() { return getLaboratorialHours((Integer) null, (ExecutionSemester) null); } public Double getLaboratorialHours(final Integer order) { return getLaboratorialHours(order, (ExecutionSemester) null); } public double getLaboratorialHours(final ExecutionSemester period) { return getLaboratorialHours(null, period); } public double getLaboratorialHours(Integer order, ExecutionSemester period) { final CompetenceCourseInformation information = findCompetenceCourseInformationForExecutionPeriod(period); return (information != null) ? information.getLaboratorialHours(order) : 0.0; } public double getSeminaryHours() { return getSeminaryHours((Integer) null, (ExecutionSemester) null); } public double getSeminaryHours(final ExecutionSemester period) { return getSeminaryHours(null, period); } public Double getSeminaryHours(final Integer order) { return getSeminaryHours(order, (ExecutionSemester) null); } public double getSeminaryHours(final Integer order, final ExecutionSemester period) { final CompetenceCourseInformation information = findCompetenceCourseInformationForExecutionPeriod(period); return (information != null) ? information.getSeminaryHours(order) : 0.0; } public double getFieldWorkHours() { return getFieldWorkHours((Integer) null, (ExecutionSemester) null); } public double getFieldWorkHours(final ExecutionSemester period) { return getFieldWorkHours(null, period); } public Double getFieldWorkHours(final Integer order) { return getFieldWorkHours(order, (ExecutionSemester) null); } public double getFieldWorkHours(final Integer order, final ExecutionSemester period) { final CompetenceCourseInformation information = findCompetenceCourseInformationForExecutionPeriod(period); return (information != null) ? information.getFieldWorkHours(order) : 0.0; } public double getTrainingPeriodHours() { return getTrainingPeriodHours((Integer) null, (ExecutionSemester) null); } public double getTrainingPeriodHours(final ExecutionSemester period) { return getTrainingPeriodHours(null, period); } public Double getTrainingPeriodHours(final Integer order) { return getTrainingPeriodHours(order, (ExecutionSemester) null); } public double getTrainingPeriodHours(final Integer order, final ExecutionSemester period) { final CompetenceCourseInformation information = findCompetenceCourseInformationForExecutionPeriod(period); return (information != null) ? information.getTrainingPeriodHours(order) : 0.0; } public double getTutorialOrientationHours() { return getTutorialOrientationHours((Integer) null, (ExecutionSemester) null); } public Double getTutorialOrientationHours(final Integer order) { return getTutorialOrientationHours(order, (ExecutionSemester) null); } public double getTutorialOrientationHours(final ExecutionSemester period) { return getTutorialOrientationHours(null, period); } public double getTutorialOrientationHours(final Integer order, final ExecutionSemester period) { final CompetenceCourseInformation information = findCompetenceCourseInformationForExecutionPeriod(period); return (information != null) ? information.getTutorialOrientationHours(order) : 0.0; } public double getAutonomousWorkHours() { return getAutonomousWorkHours((Integer) null, (ExecutionSemester) null); } public double getAutonomousWorkHours(final ExecutionSemester period) { return getAutonomousWorkHours((Integer) null, period); } public Double getAutonomousWorkHours(final Integer order) { return getAutonomousWorkHours(order, (ExecutionSemester) null); } final public Double getAutonomousWorkHours(final Integer order, final ExecutionYear year) { final CompetenceCourseInformation information = findCompetenceCourseInformationForExecutionYear(year); return (information != null) ? information.getAutonomousWorkHours(order) : 0.0; } public Double getAutonomousWorkHours(final Integer order, final ExecutionSemester period) { final CompetenceCourseInformation information = findCompetenceCourseInformationForExecutionPeriod(period); return (information != null) ? information.getAutonomousWorkHours(order) : 0.0; } public double getContactLoad() { return getContactLoad((Integer) null, (ExecutionSemester) null); } public Double getContactLoad(final ExecutionSemester period) { return getContactLoad(null, period); } public Double getContactLoad(final Integer order) { return getContactLoad(order, (ExecutionSemester) null); } final public Double getContactLoad(final Integer order, final ExecutionYear executionYear) { return getContactLoad(order, executionYear == null ? null : executionYear.getFirstExecutionPeriod()); } public Double getContactLoad(final Integer order, final ExecutionSemester period) { final CompetenceCourseInformation information = findCompetenceCourseInformationForExecutionPeriod(period); return (information != null) ? information.getContactLoad(order) : 0.0; } public double getTotalLoad() { return getTotalLoad((Integer) null, (ExecutionSemester) null); } public Double getTotalLoad(final Integer order) { return getTotalLoad(order, (ExecutionSemester) null); } public double getTotalLoad(final ExecutionSemester period) { return getTotalLoad((Integer) null, period); } final public Double getTotalLoad(final Integer order, final ExecutionYear executionYear) { return getTotalLoad(order, executionYear == null ? null : executionYear.getFirstExecutionPeriod()); } public Double getTotalLoad(final Integer order, final ExecutionSemester period) { final CompetenceCourseInformation information = findCompetenceCourseInformationForExecutionPeriod(period); return (information != null) ? information.getTotalLoad(order) : 0.0; } public double getEctsCredits() { return getEctsCredits((Integer) null, (ExecutionSemester) null); } public double getEctsCredits(final Integer order) { return getEctsCredits(order, (ExecutionSemester) null); } public double getEctsCredits(final ExecutionSemester executionSemester) { return getEctsCredits((Integer) null, executionSemester); } final public Double getEctsCredits(final Integer order, final ExecutionYear executionYear) { return getEctsCredits(order, executionYear == null ? null : executionYear.getFirstExecutionPeriod()); } public Double getEctsCredits(final Integer order, final ExecutionSemester executionSemester) { final CompetenceCourseInformation information = findCompetenceCourseInformationForExecutionPeriod(executionSemester); return (information != null) ? information.getEctsCredits(order) : 0.0; } public Map> getAssociatedCurricularCoursesGroupedByDegree() { Map> curricularCoursesMap = new HashMap>(); for (CurricularCourse curricularCourse : getAssociatedCurricularCourses()) { Degree degree = curricularCourse.getDegreeCurricularPlan().getDegree(); List curricularCourses = curricularCoursesMap.get(degree); if (curricularCourses == null) { curricularCourses = new ArrayList(); curricularCoursesMap.put(degree, curricularCourses); } curricularCourses.add(curricularCourse); } return curricularCoursesMap; } public Set presentIn() { Set result = new HashSet(); for (CurricularCourse curricularCourse : this.getAssociatedCurricularCourses()) { result.add(curricularCourse.getDegreeCurricularPlan()); } return result; } public boolean isAssociatedToAnyDegree(final Set degrees) { for (final CurricularCourse curricularCourse : getAssociatedCurricularCoursesSet()) { final DegreeCurricularPlan degreeCurricularPlan = curricularCourse.getDegreeCurricularPlan(); final Degree degree = degreeCurricularPlan.getDegree(); if (degrees.contains(degree)) { return true; } } return false; } @SuppressWarnings("unchecked") public List getCurricularCoursesWithActiveScopesInExecutionPeriod(final ExecutionSemester executionSemester) { return (List) CollectionUtils.select(getAssociatedCurricularCourses(), new Predicate() { public boolean evaluate(Object arg0) { CurricularCourse curricularCourse = (CurricularCourse) arg0; for (DegreeModuleScope moduleScope : curricularCourse.getDegreeModuleScopes()) { if (moduleScope.isActiveForExecutionPeriod(executionSemester)) { return true; } } return false; } }); } public CurricularCourse getCurricularCourse(final DegreeCurricularPlan degreeCurricularPlan) { for (final CurricularCourse curricularCourse : getAssociatedCurricularCoursesSet()) { if (curricularCourse.getDegreeCurricularPlan() == degreeCurricularPlan) { return curricularCourse; } } return null; } public List getActiveEnrollments(ExecutionYear executionYear) { List results = new ArrayList(); for (CurricularCourse curricularCourse : getAssociatedCurricularCourses()) { results.addAll(curricularCourse.getActiveEnrollments(executionYear)); } return results; } public List getActiveEnrollments(ExecutionSemester executionSemester) { List results = new ArrayList(); for (CurricularCourse curricularCourse : getAssociatedCurricularCourses()) { curricularCourse.addActiveEnrollments(results, executionSemester); } return results; } public Boolean hasActiveScopesInExecutionYear(ExecutionYear executionYear) { List executionSemesters = executionYear.getExecutionPeriods(); List curricularCourses = this.getAssociatedCurricularCourses(); for (ExecutionSemester executionSemester : executionSemesters) { for (CurricularCourse curricularCourse : curricularCourses) { if (curricularCourse.getActiveDegreeModuleScopesInAcademicInterval(executionSemester.getAcademicInterval()) .size() > 0) { return Boolean.TRUE; } } } return Boolean.FALSE; } public boolean hasActiveScopesInExecutionPeriod(ExecutionSemester executionSemester) { List curricularCourses = this.getAssociatedCurricularCourses(); for (CurricularCourse curricularCourse : curricularCourses) { if (curricularCourse.getActiveDegreeModuleScopesInAcademicInterval(executionSemester.getAcademicInterval()).size() > 0) { return true; } } return false; } public boolean hasDepartmentUnit() { return getDepartmentUnit() != null; } public DepartmentUnit getDepartmentUnit() { final CompetenceCourseGroupUnit competenceCourseGroupUnit = getCompetenceCourseGroupUnit(); return competenceCourseGroupUnit == null ? null : competenceCourseGroupUnit.getDepartmentUnit(); } @Linkare(author = "Paulo Zenida") public Set getAdditionalDepartmentUnits() { final Set result = new TreeSet(); for (final ScientificAreaUnit scientificAreaUnit : getAdditionalScientificAreaUnits()) { result.add(scientificAreaUnit.getDepartmentUnit()); } return result; } public List getSortedCompetenceCourseLoads(final ExecutionSemester period) { final List result = new ArrayList(getCompetenceCourseLoadsCount(period)); result.addAll(getCompetenceCourseLoads(period)); Collections.sort(result); return result; } public List getSortedCompetenceCourseLoads() { final List result = new ArrayList(getCompetenceCourseLoadsCount()); result.addAll(getCompetenceCourseLoads()); Collections.sort(result); return result; } @Override @Checked("CompetenceCoursePredicates.writePredicate") public void addCompetenceCourseInformations(CompetenceCourseInformation competenceCourseInformations) { super.addCompetenceCourseInformations(competenceCourseInformations); } @Override @Checked("CompetenceCoursePredicates.writePredicate") public void addDepartments(Department departments) { super.addDepartments(departments); } @Override @Checked("CompetenceCoursePredicates.writePredicate") public void removeCompetenceCourseInformations(CompetenceCourseInformation competenceCourseInformations) { super.removeCompetenceCourseInformations(competenceCourseInformations); } @Override @Checked("CompetenceCoursePredicates.writePredicate") public void removeDepartments(Department departments) { super.removeDepartments(departments); } @Override @Checked("CompetenceCoursePredicates.writePredicate") public void removeCompetenceCourseGroupUnit() { super.removeCompetenceCourseGroupUnit(); } @Override @Checked("CompetenceCoursePredicates.writePredicate") public void setCode(String code) { super.setCode(code); } @Override @Checked("CompetenceCoursePredicates.writePredicate") public void setCreationDate(Date creationDate) { super.setCreationDate(creationDate); } @Override @Checked("CompetenceCoursePredicates.editCurricularStagePredicate") public void setCurricularStage(CurricularStage curricularStage) { if (this.hasAnyAssociatedCurricularCourses() && curricularStage.equals(CurricularStage.DRAFT)) { throw new DomainException("competenceCourse.has.already.associated.curricular.courses"); } super.setCurricularStage(curricularStage); } @Override @Checked("CompetenceCoursePredicates.writePredicate") public void setName(String name) { super.setName(name); } @Override @Checked("CompetenceCoursePredicates.writePredicate") public void setCompetenceCourseGroupUnit(CompetenceCourseGroupUnit competenceCourseGroupUnit) { super.setCompetenceCourseGroupUnit(competenceCourseGroupUnit); } @Override @Checked("CompetenceCoursePredicates.writePredicate") public void addAssociatedCurricularCourses(CurricularCourse associatedCurricularCourses) { super.addAssociatedCurricularCourses(associatedCurricularCourses); } public ScientificAreaUnit getScientificAreaUnit() { if (this.getCompetenceCourseGroupUnit().hasAnyParentUnits()) { if (this.getCompetenceCourseGroupUnit().getParentUnits().size() > 1) { throw new DomainException("compentence.course.should.have.only.one.scientific.area"); } return (ScientificAreaUnit) this.getCompetenceCourseGroupUnit().getParentUnits().iterator().next(); } return null; } @Linkare(author = "Paulo Zenida") public Set getAdditionalScientificAreaUnits() { final Set result = new TreeSet(); for (final CompetenceCourseGroupUnit competenceCourseGroupUnit : getAdditionalCompetenceCourseGroupUnits()) { result.addAll((Collection) competenceCourseGroupUnit .getParentParties(ScientificAreaUnit.class)); } return result; } @Linkare(author = "Paulo Zenida") public Set getScientificAreaUnits() { final Set result = new TreeSet(); result.add(getScientificAreaUnit()); result.addAll(getAdditionalScientificAreaUnits()); return result; } public boolean isAnual() { return getRegime() == RegimeType.ANUAL; } public boolean isAnual(final ExecutionYear executionYear) { return getRegime(executionYear) == RegimeType.ANUAL; } public boolean isSemestrial(final ExecutionYear executionYear) { return getRegime(executionYear) == RegimeType.SEMESTRIAL; } public boolean isApproved() { return getCurricularStage() == CurricularStage.APPROVED; } @Linkare(author = "Paulo Zenida", comments = "Checked if it is already associated to this group unit in the additional group units") public void transfer(CompetenceCourseGroupUnit competenceCourseGroupUnit) { if (hasCompetenceCourseGroupUnit(competenceCourseGroupUnit)) { throw new DomainException("error.already.has.competenceCourseGroupUnit"); } super.setCompetenceCourseGroupUnit(competenceCourseGroupUnit); } public MultiLanguageString getNameI18N() { final MultiLanguageString multiLanguageString = new MultiLanguageString(); if (getName() != null && getName().length() > 0) { multiLanguageString.setContent(Language.pt, getName()); } if (getNameEn() != null && getNameEn().length() > 0) { multiLanguageString.setContent(Language.en, getNameEn()); } return multiLanguageString; } public MultiLanguageString getObjectivesI18N() { final MultiLanguageString multiLanguageString = new MultiLanguageString(); if (getObjectives() != null && getObjectives().length() > 0) { multiLanguageString.setContent(Language.pt, getObjectives()); } if (getObjectivesEn() != null && getObjectivesEn().length() > 0) { multiLanguageString.setContent(Language.en, getObjectivesEn()); } return multiLanguageString; } public MultiLanguageString getProgramI18N() { final MultiLanguageString multiLanguageString = new MultiLanguageString(); if (getProgram() != null && getProgram().length() > 0) { multiLanguageString.setContent(Language.pt, getProgram()); } if (getProgramEn() != null && getProgramEn().length() > 0) { multiLanguageString.setContent(Language.en, getProgramEn()); } return multiLanguageString; } public List getExecutionCoursesByExecutionPeriod(final ExecutionSemester executionSemester) { Set executionCourseSet = new HashSet(); List curricularCourseList = getCurricularCoursesWithActiveScopesInExecutionPeriod(executionSemester); for (CurricularCourse curricularCourse : curricularCourseList) { executionCourseSet.addAll(curricularCourse.getExecutionCoursesByExecutionPeriod(executionSemester)); } List executionCourseList = new ArrayList(); executionCourseList.addAll(executionCourseSet); return executionCourseList; } public boolean hasEnrolmentForPeriod(ExecutionSemester executionSemester) { for (CurricularCourse curricularCourse : getAssociatedCurricularCourses()) { if (curricularCourse.hasEnrolmentForPeriod(executionSemester)) { return true; } } return false; } public boolean isDissertation() { return getType() == CompetenceCourseType.DISSERTATION; } public Integer getDraftCompetenceCourseInformationChangeRequestsCount() { int count = 0; for (CompetenceCourseInformationChangeRequest request : getCompetenceCourseInformationChangeRequests()) { if (request.getApproved() == null) { count++; } } return count; } public CompetenceCourseInformationChangeRequest getCompetenceCourseInformationChangeRequests(final ExecutionSemester period) { for (CompetenceCourseInformationChangeRequest request : getCompetenceCourseInformationChangeRequests()) { if (request.getExecutionPeriod() == period) { return request; } } return null; } @Override public void addCompetenceCourseInformationChangeRequests(CompetenceCourseInformationChangeRequest request) { if (getCompetenceCourseInformationChangeRequests(request.getExecutionPeriod()) != null) { throw new DomainException("error.can.only.exist.one.request.per.execution.period"); } super.addCompetenceCourseInformationChangeRequests(request); } public boolean hasOneCourseLoad(final ExecutionYear executionYear) { final CompetenceCourseInformation information = findCompetenceCourseInformationForExecutionYear(executionYear); return information != null && information.getCompetenceCourseLoadsCount() == 1; } public ExecutionSemester getStartExecutionSemester() { return getOldestCompetenceCourseInformation().getExecutionPeriod(); } // ------------------------------------------------------------- // read static methods // ------------------------------------------------------------- static public List readOldCompetenceCourses() { final List result = new ArrayList(); for (final CompetenceCourse competenceCourse : RootDomainObject.getInstance().getCompetenceCoursesSet()) { if (!competenceCourse.isBolonha()) { result.add(competenceCourse); } } return result; } static public Collection readBolonhaCompetenceCourses() { final Set result = new TreeSet(COMPETENCE_COURSE_COMPARATOR_BY_NAME); for (final CompetenceCourse competenceCourse : RootDomainObject.getInstance().getCompetenceCoursesSet()) { if (competenceCourse.isBolonha()) { result.add(competenceCourse); } } return result; } static public Collection readApprovedBolonhaCompetenceCourses() { final Set result = new TreeSet(COMPETENCE_COURSE_COMPARATOR_BY_NAME); for (final CompetenceCourse competenceCourse : RootDomainObject.getInstance().getCompetenceCoursesSet()) { if (competenceCourse.isBolonha() && competenceCourse.isApproved()) { result.add(competenceCourse); } } return result; } static public Collection readApprovedBolonhaDissertations() { final List result = new ArrayList(); for (final CompetenceCourse competenceCourse : RootDomainObject.getInstance().getCompetenceCoursesSet()) { if (competenceCourse.isBolonha() && competenceCourse.isApproved() && competenceCourse.isDissertation()) { result.add(competenceCourse); } } return result; } @Linkare(author = "Paulo Zenida", comments = "Created to be used on the fenix-migration project") public static CompetenceCourse readCompetenceCourseByCode(final String code) { final Collection competenceCourses = readBolonhaCompetenceCourses(); for (final CompetenceCourse competenceCourse : competenceCourses) { if (competenceCourse.getCode().equals(code)) { return competenceCourse; } } return null; } @Linkare(author = "Paulo Zenida") public String getPresentationName() { return getCode() + " - " + getName(); } @Linkare(author = "Paulo Zenida") public String getPresentationName(final ExecutionSemester executionSemester) { return getCode() + " - " + getName(executionSemester); } @Linkare(author = "Paulo Zenida") public String getPresentationNameEn() { return getCode() + " - " + getNameEn(); } @Linkare(author = "Paulo Zenida") public String getPresentationNameEn(final ExecutionSemester executionSemester) { return getCode() + " - " + getNameEn(executionSemester); } @Linkare(author = "Paulo Zenida") @Override public String getShortDescription() { return getPresentationName(); } @Linkare(author = "Paulo Zenida") @Override public void addAdditionalCompetenceCourseGroupUnits(final CompetenceCourseGroupUnit competenceCourseGroupUnit) { if (hasCompetenceCourseGroupUnit(competenceCourseGroupUnit)) { throw new DomainException("error.already.has.competenceCourseGroupUnit"); } super.addAdditionalCompetenceCourseGroupUnits(competenceCourseGroupUnit); } @Linkare(author = "Paulo Zenida") @Override public void removeAdditionalCompetenceCourseGroupUnits(final CompetenceCourseGroupUnit competenceCourseGroupUnit) { if (getCompetenceCourseGroupUnit() == competenceCourseGroupUnit) { throw new DomainException("error.cannot.remove.main.competenceCourseGroupUnit"); } if (!hasCompetenceCourseGroupUnit(competenceCourseGroupUnit)) { throw new DomainException("error.dont.have.competenceCourseGroupUnit"); } super.removeAdditionalCompetenceCourseGroupUnits(competenceCourseGroupUnit); } @Linkare(author = "Paulo Zenida") private boolean hasCompetenceCourseGroupUnit(final CompetenceCourseGroupUnit competenceCourseGroupUnit) { return (getCompetenceCourseGroupUnit() != null && getCompetenceCourseGroupUnit() == competenceCourseGroupUnit) || (getAdditionalCompetenceCourseGroupUnits().contains(competenceCourseGroupUnit)); } }