package net.sourceforge.fenixedu.domain.organizationalStructure; import java.util.ArrayList; import java.util.List; import java.util.SortedSet; import java.util.TreeSet; import net.sourceforge.fenixedu.domain.CompetenceCourse; import net.sourceforge.fenixedu.domain.CurricularCourse; import net.sourceforge.fenixedu.domain.Degree; import net.sourceforge.fenixedu.domain.Department; import net.sourceforge.fenixedu.domain.ExecutionYear; import net.sourceforge.fenixedu.domain.administrativeOffice.AdministrativeOffice; import net.sourceforge.fenixedu.domain.exceptions.DomainException; import net.sourceforge.fenixedu.domain.space.Campus; import org.joda.time.YearMonthDay; import pt.utl.ist.fenix.tools.util.i18n.MultiLanguageString; import com.linkare.commons.metainfo.Linkare; public class CompetenceCourseGroupUnit extends CompetenceCourseGroupUnit_Base { private CompetenceCourseGroupUnit() { super(); super.setType(PartyTypeEnum.COMPETENCE_COURSE_GROUP); } @Linkare(author = "Paulo Zenida", comments = "Changed return type from Unit to CompetenceCourseGroupUnit") public static CompetenceCourseGroupUnit createNewInternalCompetenceCourseGroupUnit(MultiLanguageString name, Integer costCenterCode, String acronym, YearMonthDay beginDate, YearMonthDay endDate, Unit parentUnit, AccountabilityType accountabilityType, String webAddress, UnitClassification classification, Boolean canBeResponsibleOfSpaces, Campus campus) { CompetenceCourseGroupUnit competenceCourseGroupUnit = new CompetenceCourseGroupUnit(); competenceCourseGroupUnit.init(name, costCenterCode, acronym, beginDate, endDate, webAddress, classification, canBeResponsibleOfSpaces, campus); competenceCourseGroupUnit.addParentUnit(parentUnit, accountabilityType); checkIfAlreadyExistsOneCompetenceCourseGroupUnitWithSameAcronymAndName(competenceCourseGroupUnit); return competenceCourseGroupUnit; } @Override public void edit(MultiLanguageString unitName, Integer unitCostCenter, String acronym, YearMonthDay beginDate, YearMonthDay endDate, String webAddress, UnitClassification classification, Department department, Degree degree, AdministrativeOffice administrativeOffice, Boolean canBeResponsibleOfSpaces, Campus campus) { super.edit(unitName, unitCostCenter, acronym, beginDate, endDate, webAddress, classification, department, degree, administrativeOffice, canBeResponsibleOfSpaces, campus); checkIfAlreadyExistsOneCompetenceCourseGroupUnitWithSameAcronymAndName(this); } @Override public Accountability addParentUnit(Unit parentUnit, AccountabilityType accountabilityType) { if (parentUnit != null && (!parentUnit.isInternal() || !parentUnit.isScientificAreaUnit())) { throw new DomainException("error.unit.invalid.parentUnit"); } return super.addParentUnit(parentUnit, accountabilityType); } @Override public boolean isCompetenceCourseGroupUnit() { return true; } @Linkare(author = "Paulo Zenida", comments = "Included the additional secondary competence courses") @Override public List getCompetenceCourses() { final SortedSet result = new TreeSet( CompetenceCourse.COMPETENCE_COURSE_COMPARATOR_BY_NAME); result.addAll(super.getCompetenceCourses()); result.addAll(super.getAssociatedCompetenceCourses()); return new ArrayList(result); } @Override public void setType(PartyTypeEnum partyTypeEnum) { throw new DomainException("unit.impossible.set.type"); } public List getCurricularCourses() { List competenceCourses = getCompetenceCourses(); List curricularCourses = new ArrayList(); for (CompetenceCourse competenceCourse : competenceCourses) { curricularCourses.addAll(competenceCourse.getAssociatedCurricularCourses()); } return curricularCourses; } public List getCompetenceCoursesByExecutionYear(ExecutionYear executionYear) { List competenceCourses = this.getCompetenceCourses(); List competenceCoursesByExecutionYear = new ArrayList(); for (CompetenceCourse competenceCourse : competenceCourses) { if (competenceCourse.hasActiveScopesInExecutionYear(executionYear)) { competenceCoursesByExecutionYear.add(competenceCourse); } } return competenceCoursesByExecutionYear; } @Override public void delete() { if (hasAnyCompetenceCourses()) { throw new DomainException("error.unit.cannot.be.deleted"); } super.delete(); } private static void checkIfAlreadyExistsOneCompetenceCourseGroupUnitWithSameAcronymAndName( CompetenceCourseGroupUnit competenceCourseGroupUnit) { for (Unit parentUnit : competenceCourseGroupUnit.getParentUnits()) { for (Unit unit : parentUnit.getAllSubUnits()) { if (!unit.equals(competenceCourseGroupUnit) && competenceCourseGroupUnit.getName().equalsIgnoreCase(unit.getName())) { throw new DomainException("error.unit.already.exists.unit.with.same.name.or.acronym"); } } } } @Linkare(author = "Paulo Zenida") public static List readAllCompetenceCourseGroupUnits() { final List allUnits = Unit.readAllUnits(); final List result = new ArrayList(); for (final Unit unit : allUnits) { if (unit.isCompetenceCourseGroupUnit()) { result.add((CompetenceCourseGroupUnit) unit); } } return result; } @Linkare(author = "Paulo Zenida") @Override public void addAssociatedCompetenceCourses(CompetenceCourse associatedCompetenceCourses) { if (associatedCompetenceCourses != null) { associatedCompetenceCourses.addAdditionalCompetenceCourseGroupUnits(this); } } @Linkare(author = "Paulo Zenida") @Override public void removeAssociatedCompetenceCourses(CompetenceCourse associatedCompetenceCourses) { if (associatedCompetenceCourses != null) { associatedCompetenceCourses.removeAdditionalCompetenceCourseGroupUnits(this); } } }