package net.sourceforge.fenixedu.domain.studentCurriculum; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.HashSet; import java.util.List; import java.util.Locale; import java.util.Set; import net.sourceforge.fenixedu.domain.CurricularCourse; import net.sourceforge.fenixedu.domain.Enrolment; import net.sourceforge.fenixedu.domain.ExecutionSemester; import net.sourceforge.fenixedu.domain.ExecutionYear; import net.sourceforge.fenixedu.domain.curricularRules.CurricularRuleType; import net.sourceforge.fenixedu.domain.curricularRules.ICurricularRule; import net.sourceforge.fenixedu.domain.degreeStructure.Context; import net.sourceforge.fenixedu.domain.degreeStructure.CourseGroup; import net.sourceforge.fenixedu.domain.degreeStructure.DegreeModule; import net.sourceforge.fenixedu.domain.enrolment.IDegreeModuleToEvaluate; import net.sourceforge.fenixedu.domain.exceptions.DomainException; import net.sourceforge.fenixedu.domain.student.curriculum.Curriculum; import org.joda.time.DateTime; import pt.utl.ist.fenix.tools.util.i18n.Language; import pt.utl.ist.fenix.tools.util.i18n.MultiLanguageString; public abstract class NoCourseGroupCurriculumGroup extends NoCourseGroupCurriculumGroup_Base { protected NoCourseGroupCurriculumGroup() { super(); } protected void init(final RootCurriculumGroup curriculumGroup) { checkParameters(curriculumGroup); this.setCurriculumGroup(curriculumGroup); } private void checkParameters(final RootCurriculumGroup curriculumGroup) { if (curriculumGroup == null) { throw new DomainException("error.NoCourseGroupCurriculumGroup.invalid.curriculumGroup"); } } public static NoCourseGroupCurriculumGroup createNewNoCourseGroupCurriculumGroup( final NoCourseGroupCurriculumGroupType groupType, final RootCurriculumGroup curriculumGroup) { switch (groupType) { case PROPAEDEUTICS: return new PropaedeuticsCurriculumGroup(curriculumGroup); case EXTRA_CURRICULAR: return new ExtraCurriculumGroup(curriculumGroup); case STANDALONE: return new StandaloneCurriculumGroup(curriculumGroup); default: throw new DomainException("error.unknown.NoCourseGroupCurriculumGroupType"); } } @Override public boolean isNoCourseGroupCurriculumGroup() { return true; } @Override public MultiLanguageString getName() { final MultiLanguageString result = new MultiLanguageString(); result.setContent(Language.pt, getNoCourseGroupCurriculumGroupType().getLocalizedName(new Locale(Language.pt.name()))); result.setContent(Language.en, getNoCourseGroupCurriculumGroupType().getLocalizedName(new Locale(Language.en.name()))); return result; } @Override public List getCurricularCourseContextsToEnrol(ExecutionSemester executionSemester) { return Collections.emptyList(); } @Override public List getCourseGroupContextsToEnrol(ExecutionSemester executionSemester) { return Collections.emptyList(); } @Override public Collection getCurricularCoursesToDismissal(final ExecutionSemester executionSemester) { return Collections.EMPTY_LIST; } @Override public boolean hasDegreeModule(DegreeModule degreeModule) { for (final CurriculumModule curriculumModule : this.getCurriculumModules()) { if (curriculumModule.hasDegreeModule(degreeModule)) { return true; } } return false; } @Override public boolean hasCourseGroup(CourseGroup courseGroup) { for (final CurriculumModule curriculumModule : getCurriculumModules()) { if (!curriculumModule.isLeaf()) { final CurriculumGroup group = (CurriculumGroup) curriculumModule; if (group.hasCourseGroup(courseGroup)) { return true; } } } return false; } /** * Flat structure below NoCourseGroupCurriculumGroup */ @Override public CurriculumGroup findCurriculumGroupFor(final CourseGroup courseGroup) { for (final CurriculumModule each : getCurriculumModulesSet()) { if (!each.isLeaf() && each.getDegreeModule() == courseGroup) { return (CurriculumGroup) each; } } return null; } @Override public Integer getChildOrder(final ExecutionSemester executionSemester) { return Integer.MAX_VALUE; } @Override protected Integer searchChildOrderForChild(final CurriculumGroup child, final ExecutionSemester executionSemester) { final List result = new ArrayList(getCurriculumModulesSet()); Collections.sort(result, CurriculumModule.COMPARATOR_BY_NAME_AND_ID); return result.indexOf(child); } @Override public Set getDegreeModulesToEvaluate(ExecutionSemester executionSemester) { return Collections.EMPTY_SET; } @Override public Set getCurricularRules(ExecutionSemester executionSemester) { return Collections.emptySet(); } @Override public ConclusionValue isConcluded(ExecutionYear executionYear) { return ConclusionValue.CONCLUDED; } @Override final public Curriculum getCurriculum(final DateTime when, final ExecutionYear executionYear) { return Curriculum.createEmpty(this, executionYear); } @Override public Double getCreditsConcluded(ExecutionYear executionYear) { return Double.valueOf(0d); } @Override public boolean canAdd(CurriculumLine curriculumLine) { return false; } @Override public Collection getCurricularCoursePossibleGroups(CurricularCourse curricularCourse) { return Collections.singleton((CurriculumGroup) this); } @Override public Collection getCurricularCoursePossibleGroupsWithoutNoCourseGroupCurriculumGroups( CurricularCourse curricularCourse) { return Collections.emptyList(); } @Override public Double getAprovedEctsCredits() { return Double.valueOf(0d); } @Override public Collection getNoCourseGroupCurriculumGroups() { Collection res = new HashSet(); res.add(this); res.addAll(super.getNoCourseGroupCurriculumGroups()); return res; } @Override public ICurricularRule getMostRecentActiveCurricularRule(final CurricularRuleType ruleType, final ExecutionYear executionYear) { return null; } abstract public NoCourseGroupCurriculumGroupType getNoCourseGroupCurriculumGroupType(); @Override public int getNumberOfAllApprovedCurriculumLines() { return 0; } @Override public Collection getSpecialSeasonEnrolments(final ExecutionYear executionYear) { return Collections.emptyList(); } @Override public int getNumberOfAllApprovedEnrolments(ExecutionSemester executionSemester) { return 0; } /** * Used to check if enrolment childs can give accumulated ects credits * correct value */ public boolean allowAccumulatedEctsCredits() { return false; } @Override public Set getAllCurriculumGroupsWithoutNoCourseGroupCurriculumGroups() { return Collections.emptySet(); } }