package net.sourceforge.fenixedu.domain.organizationalStructure; import java.util.ArrayList; import java.util.HashSet; import java.util.List; import java.util.Set; 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.iscte.ci.metadata.ISCTE; import pt.ist.fenixWebFramework.services.Service; import pt.utl.ist.fenix.tools.util.i18n.MultiLanguageString; public class CompetenceCourseGroupUnit extends CompetenceCourseGroupUnit_Base { private CompetenceCourseGroupUnit() { super(); super.setType(PartyTypeEnum.COMPETENCE_COURSE_GROUP); } public static Unit 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; } public List getCompetenceCourses() { final SortedSet result = new TreeSet( CompetenceCourse.COMPETENCE_COURSE_COMPARATOR_BY_NAME); for (CCGUContext ccguContext : getCCGUContexts()) { result.add(ccguContext.getCompetenceCourse()); } return new ArrayList(result); } // ISCTE - needed for listing Competence Courses in manager portal (pramc) public List getBolonhaCompetenceCourses() { final SortedSet result = new TreeSet( CompetenceCourse.COMPETENCE_COURSE_COMPARATOR_BY_NAME); for (CCGUContext ccguContext : getCCGUContexts()) { CompetenceCourse competenceCourse = ccguContext.getCompetenceCourse(); if (competenceCourse.isBolonha()) { result.add(competenceCourse); } } return new ArrayList(result); } public List getNotBolonhaCompetenceCourses() { final SortedSet result = new TreeSet( CompetenceCourse.COMPETENCE_COURSE_COMPARATOR_BY_NAME); for (CompetenceCourse course : getCompetenceCourses()) { if (!course.isBolonha()) result.add(course); } return new ArrayList(result); } public List getNotBolonhaOfficialCompetenceCourses() { final SortedSet result = new TreeSet( CompetenceCourse.COMPETENCE_COURSE_COMPARATOR_BY_NAME); for (CompetenceCourse course : getCompetenceCourses()) { if (!course.isBolonha() && course.getIsOfficial()) result.add(course); } return new ArrayList(result); } // end of ISCTE @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; } @ISCTE(author = "Nadir Amin") public Set getCompetenceCoursesBy(ExecutionYear executionYear) { final Set result = new HashSet(); for (final CCGUContext context : getCCGUContexts()) { if (context.isValidOn(executionYear)) { result.add(context.getCompetenceCourse()); } } return result; } @Override public void delete() { if (getCompetenceCourses().size() > 0) { 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"); } } } } public CCGUContext getCurrentContext() { ExecutionYear currentExecutionYear = ExecutionYear.readCurrentExecutionYear(); for (CCGUContext ccguContext : getCCGUContexts()) { if (ccguContext.getBeginExecutionYear().isBefore(currentExecutionYear) && (ccguContext.getEndExecutionYear() == null || ccguContext.getEndExecutionYear().isAfter( currentExecutionYear))) return ccguContext; } return null; } public List getPreviousContexts() { List contexts = new ArrayList(); for (CCGUContext ccguContext : getCCGUContexts()) { if (ccguContext.getEndExecutionYear() != null) contexts.add(ccguContext); } return contexts; } @Service public void copyCompetenceCourses(final ScientificAreaUnit scientificAreaUnit, final ExecutionYear beginExecutionYear, final ExecutionYear endExecutionYear) { if (scientificAreaUnit == null) { throw new DomainException("error.CopyCompetenceCourse.scientificAreaUnit.cannotBeNull"); } final CompetenceCourseGroupUnit destinyCompetenceCourseGroupUnit = scientificAreaUnit.getCompetenceCourseGroupUnits() .get(0); for (final CompetenceCourse competenceCourse : getCompetenceCoursesBy(ExecutionYear.readCurrentExecutionYear())) { new CCGUContext(destinyCompetenceCourseGroupUnit, competenceCourse, beginExecutionYear, endExecutionYear); } } }