package net.sourceforge.fenixedu.domain.organizationalStructure; import java.util.Collection; import net.sourceforge.fenixedu.domain.degree.DegreeType; 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.utl.ist.fenix.tools.util.StringNormalizer; import pt.utl.ist.fenix.tools.util.i18n.MultiLanguageString; public class AggregateUnit extends AggregateUnit_Base { private AggregateUnit() { super(); super.setType(PartyTypeEnum.AGGREGATE_UNIT); } public static AggregateUnit createNewAggregateUnit(MultiLanguageString name, Integer costCenterCode, String acronym, YearMonthDay beginDate, YearMonthDay endDate, Unit parentUnit, AccountabilityType accountabilityType, String webAddress, UnitClassification classification, Boolean canBeResponsibleOfSpaces, Campus campus) { AggregateUnit aggregateUnit = new AggregateUnit(); aggregateUnit.init(name, costCenterCode, acronym, beginDate, endDate, webAddress, classification, canBeResponsibleOfSpaces, campus); aggregateUnit.addParentUnit(parentUnit, accountabilityType); return aggregateUnit; } @Override public void setType(PartyTypeEnum partyTypeEnum) { throw new DomainException("unit.impossible.set.type"); } @Override public boolean isAggregateUnit() { return true; } @ISCTE public AggregateUnit getDegreeAggregatorOfDegreeType(final DegreeType degreeType) { final Collection childPartyTypes = getChildPartyTypes(); if (childPartyTypes.size() == 1 && childPartyTypes.contains(PartyTypeEnum.DEGREE_UNIT)) { boolean valid = true; for (Unit unit : getSubUnits()) { final DegreeUnit degreeUnit = (DegreeUnit) unit; if (!degreeUnit.hasDegree() || degreeUnit.getDegree().getDegreeType() != degreeType) { valid = false; break; } } if (valid) { return this; } } else if (childPartyTypes.isEmpty()) { final String normalizedDegreeType = StringNormalizer.normalizeAndRemoveNonAlphaNumeric(degreeType.getLocalizedName() .replace("Bolonha", "")); final String normalizedAggregatorName = StringNormalizer.normalizeAndRemoveNonAlphaNumeric(getName()); if (normalizedAggregatorName.equals(normalizedDegreeType)) { return this; } } for (Unit unit : getSubUnits()) { if (unit.isAggregateUnit()) { final AggregateUnit aggregateUnit = ((AggregateUnit) unit).getDegreeAggregatorOfDegreeType(degreeType); if (aggregateUnit != null) { return aggregateUnit; } } } return null; } }