package net.sourceforge.fenixedu.domain.organizationalStructure; import java.util.ArrayList; import java.util.List; import net.sourceforge.fenixedu.domain.ExternalCurricularCourse; import net.sourceforge.fenixedu.domain.RootDomainObject; import net.sourceforge.fenixedu.domain.exceptions.DomainException; import org.apache.commons.lang.StringUtils; import com.linkare.commons.metainfo.Linkare; public abstract class AcademicalInstitutionUnit extends AcademicalInstitutionUnit_Base { @Override public boolean isAcademicalUnit() { return true; } @Override public void setAcronym(String acronym) { if (StringUtils.isEmpty(acronym)) { throw new DomainException("error.unit.empty.acronym"); } super.setAcronym(acronym); } @Override public List getAllExternalCurricularCourses() { final List result = new ArrayList(getExternalCurricularCourses()); for (Unit subUnit : getSubUnits()) { if (subUnit.isDepartmentUnit()) { result.addAll(subUnit.getExternalCurricularCourses()); } } return result; } @Override public Boolean isOfficial() { return (getOfficial() != null && getOfficial().equals(Boolean.TRUE)); } public Boolean isOfficialAndIsType(AcademicalInstitutionType type) { return (isOfficial() && getInstitutionType().equals(type)); } protected static List readOfficialUnits() { final List officialUnits = new ArrayList(); for (final UnitName unitName : RootDomainObject.getInstance().getUnitName()) { if (unitName.getUnit().isOfficial()) { officialUnits.add((AcademicalInstitutionUnit) unitName.getUnit()); } } return officialUnits; } public static List readOfficialParentUnitsByType(AcademicalInstitutionType type) { final List parentUnits = new ArrayList(); Unit countryUnit = CountryUnit.getDefault(); for (final AcademicalInstitutionUnit unit : readOfficialUnits()) { if (unit.hasParentUnit(countryUnit) && unit.isOfficialAndIsType(type)) { parentUnits.add(unit); } } return parentUnits; } public static List readOfficialChildUnits(AcademicalInstitutionUnit parentUnit) { final List childUnits = new ArrayList(); for (final AcademicalInstitutionUnit unit : readOfficialUnits()) { if (unit.hasParentUnit(parentUnit)) { childUnits.add(unit); } } return childUnits; } public static List readOtherAcademicUnits() { final List otherUnits = new ArrayList(); for (final UnitName unitName : RootDomainObject.getInstance().getUnitName()) { if (unitName.getUnit().isAcademicalUnit() && !unitName.getUnit().isOfficial()) { otherUnits.add((AcademicalInstitutionUnit) unitName.getUnit()); } } return otherUnits; } public Boolean hasAnyOfficialChilds() { for (final AcademicalInstitutionUnit unit : readOfficialUnits()) { if (unit.hasParentUnit(this)) { return Boolean.TRUE; } } return Boolean.FALSE; } public abstract String getFullPresentationName(); @Linkare(author = "Ricardo Espírito Santo") public static AcademicalInstitutionUnit readAcademicalInstitutionUnitByCode(String code) { for (final Unit unit : readAllUnits()) { if (unit.isAcademicalUnit()) { final AcademicalInstitutionUnit academicalInstitutionUnit = (AcademicalInstitutionUnit) unit; if (StringUtils.equals(academicalInstitutionUnit.getCode(), code)){ return academicalInstitutionUnit; } } } return null; } }