/* * Created on Sep 16, 2005 * by mrsp */ package net.sourceforge.fenixedu.domain.organizationalStructure; import java.util.ArrayList; import java.util.Collection; import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Locale; import java.util.ResourceBundle; import java.util.Set; import java.util.SortedSet; import java.util.TreeSet; import net.sourceforge.fenixedu._development.PropertiesManager; import net.sourceforge.fenixedu.domain.Country; import net.sourceforge.fenixedu.domain.Degree; import net.sourceforge.fenixedu.domain.Department; import net.sourceforge.fenixedu.domain.Employee; import net.sourceforge.fenixedu.domain.ExecutionYear; import net.sourceforge.fenixedu.domain.ExternalCurricularCourse; import net.sourceforge.fenixedu.domain.InstitutionSite; import net.sourceforge.fenixedu.domain.NonAffiliatedTeacher; import net.sourceforge.fenixedu.domain.PartyClassification; import net.sourceforge.fenixedu.domain.Person; import net.sourceforge.fenixedu.domain.RootDomainObject; import net.sourceforge.fenixedu.domain.Teacher; import net.sourceforge.fenixedu.domain.UnitFile; import net.sourceforge.fenixedu.domain.UnitFileTag; import net.sourceforge.fenixedu.domain.UnitSite; import net.sourceforge.fenixedu.domain.accessControl.PersistentGroup; import net.sourceforge.fenixedu.domain.accessControl.PersistentGroupMembers; import net.sourceforge.fenixedu.domain.administrativeOffice.AdministrativeOffice; import net.sourceforge.fenixedu.domain.assiduousness.ExtraWorkRequest; import net.sourceforge.fenixedu.domain.assiduousness.UnitExtraWorkAmount; import net.sourceforge.fenixedu.domain.contacts.PartyContactType; import net.sourceforge.fenixedu.domain.contacts.PhysicalAddress; import net.sourceforge.fenixedu.domain.contacts.PhysicalAddressData; import net.sourceforge.fenixedu.domain.exceptions.DomainException; import net.sourceforge.fenixedu.domain.research.result.ResultUnitAssociation; import net.sourceforge.fenixedu.domain.research.result.patent.ResearchResultPatent; import net.sourceforge.fenixedu.domain.research.result.publication.Article; import net.sourceforge.fenixedu.domain.research.result.publication.Book; import net.sourceforge.fenixedu.domain.research.result.publication.BookPart; import net.sourceforge.fenixedu.domain.research.result.publication.Inproceedings; import net.sourceforge.fenixedu.domain.research.result.publication.Manual; import net.sourceforge.fenixedu.domain.research.result.publication.OtherPublication; import net.sourceforge.fenixedu.domain.research.result.publication.Proceedings; import net.sourceforge.fenixedu.domain.research.result.publication.ResearchResultPublication; import net.sourceforge.fenixedu.domain.research.result.publication.ScopeType; import net.sourceforge.fenixedu.domain.research.result.publication.TechnicalReport; import net.sourceforge.fenixedu.domain.research.result.publication.Thesis; import net.sourceforge.fenixedu.domain.research.result.publication.Unstructured; import net.sourceforge.fenixedu.domain.space.Campus; import net.sourceforge.fenixedu.domain.util.FunctionalityPrinters; import net.sourceforge.fenixedu.domain.util.email.UnitBasedSender; import net.sourceforge.fenixedu.domain.vigilancy.ExamCoordinator; import net.sourceforge.fenixedu.domain.vigilancy.VigilantGroup; import net.sourceforge.fenixedu.injectionCode.AccessControl; import net.sourceforge.fenixedu.injectionCode.IGroup; import net.sourceforge.fenixedu.util.Month; import net.sourceforge.fenixedu.util.domain.OrderedRelationAdapter; import org.apache.commons.lang.StringUtils; import org.joda.time.DateTimeFieldType; import org.joda.time.Partial; import org.joda.time.YearMonthDay; import pt.ist.fenixWebFramework.services.Service; import pt.utl.ist.fenix.tools.util.StringNormalizer; import pt.utl.ist.fenix.tools.util.i18n.Language; import pt.utl.ist.fenix.tools.util.i18n.MultiLanguageString; import com.linkare.commons.metainfo.Linkare; public class Unit extends Unit_Base { private static final ResourceBundle applicationResourcesBundle = ResourceBundle.getBundle("resources.ApplicationResources", new Locale("pt")); public static OrderedRelationAdapter FUNCTION_ORDERED_ADAPTER; static { FUNCTION_ORDERED_ADAPTER = new OrderedRelationAdapter("activeFunctions", "functionOrder"); UnitFunction.addListener(FUNCTION_ORDERED_ADAPTER); } protected Unit() { super(); } protected void init(MultiLanguageString name, Integer costCenterCode, String acronym, YearMonthDay beginDate, YearMonthDay endDate, String webAddress, UnitClassification classification, Boolean canBeResponsibleOfSpaces, Campus campus) { setPartyName(name); if (acronym != null) { setAcronym(acronym); } if (getCostCenterCode() == null || !getCostCenterCode().equals(costCenterCode)) { setCostCenterCode(costCenterCode); } setBeginDateYearMonthDay(beginDate); setEndDateYearMonthDay(endDate); setClassification(classification); setCanBeResponsibleOfSpaces(canBeResponsibleOfSpaces); setCampus(campus); setDefaultWebAddressUrl(webAddress); } @Override public void setPartyName(MultiLanguageString partyName) { super.setPartyName(partyName); setName(partyName.getPreferedContent()); } @Override public String getName() { return getPartyName().getPreferedContent(); } @Override public void setName(String name) { if (name == null || StringUtils.isEmpty(name.trim())) { throw new DomainException("error.unit.empty.name"); } MultiLanguageString partyName = getPartyName(); partyName = partyName == null ? new MultiLanguageString() : partyName; partyName.setContent(Language.getDefaultLanguage(), name); super.setPartyName(partyName); UnitName unitName = getUnitName(); unitName = unitName == null ? new UnitName(this) : unitName; unitName.setName(name); } public void edit(MultiLanguageString name, String acronym) { setPartyName(name); setAcronym(acronym); } 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) { init(unitName, unitCostCenter, acronym, beginDate, endDate, webAddress, classification, canBeResponsibleOfSpaces, campus); } @Override public void setCanBeResponsibleOfSpaces(Boolean canBeResponsibleOfSpaces) { super.setCanBeResponsibleOfSpaces(canBeResponsibleOfSpaces != null ? canBeResponsibleOfSpaces : Boolean.FALSE); } public void setCostCenterCode(Integer costCenterCode) { final UnitCostCenterCode otherUnitCostCenterCode = UnitCostCenterCode.find(costCenterCode); if (otherUnitCostCenterCode != null && otherUnitCostCenterCode.getUnit() != this) { throw new DomainException("error.costCenter.alreadyExists"); } final UnitCostCenterCode unitCostCenterCode = getUnitCostCenterCode(); if (unitCostCenterCode == null && costCenterCode != null) { new UnitCostCenterCode(this, costCenterCode); } else if (unitCostCenterCode != null && costCenterCode != null) { unitCostCenterCode.setCostCenterCode(costCenterCode); } else if (unitCostCenterCode != null && costCenterCode == null) { unitCostCenterCode.delete(); } } public Integer getCostCenterCode() { final UnitCostCenterCode unitCostCenterCode = getUnitCostCenterCode(); return unitCostCenterCode == null ? null : unitCostCenterCode.getCostCenterCode(); } @jvstm.cps.ConsistencyPredicate protected boolean checkDateInterval() { final YearMonthDay start = getBeginDateYearMonthDay(); final YearMonthDay end = getEndDateYearMonthDay(); return start != null && (end == null || !start.isAfter(end)); } @Override public void delete() { if (!canBeDeleted()) { throw new DomainException("error.unit.cannot.be.deleted"); } if (hasAnyParentUnits()) { getParents().get(0).delete(); } if (hasSite()) { getSite().delete(); } for (; !getUnitFileTagsSet().isEmpty(); getUnitFileTags().get(0).delete()) ; getUnitName().delete(); getFunctionalityPrinters().clear(); getAllowedPeopleToUploadFiles().clear(); removeRootDomainObjectForEarthUnit(); removeRootDomainObjectForExternalInstitutionUnit(); removeRootDomainObjectForInstitutionUnit(); removeCampus(); removeUnitAcronym(); super.delete(); } @Linkare(author = "Paulo Zenida", comments = "Changed visibility from private to public") public boolean canBeDeleted() { return (!hasAnyParents() || (getParentsCount() == 1 && getParentUnits().size() == 1)) && !hasAnyChilds() && !hasAnyFunctions() && !hasAnyVigilantGroups() && !hasAnyAssociatedNonAffiliatedTeachers() && !hasAnyPayedGuides() && !hasAnyPayedReceipts() && !hasAnyExtraPayingUnitAuthorizations() && !hasAnyExtraWorkingUnitAuthorizations() && !hasAnyExternalCurricularCourses() && !hasAnyResultUnitAssociations() && !hasUnitServiceAgreementTemplate() && !hasAnyResearchInterests() && !hasAnyProjectParticipations() && !hasAnyParticipations() && !hasAnyBoards() && (!hasSite() || getSite().isDeletable()) && !hasAnyOwnedReceipts() && !hasAnyCreatedReceipts() && !hasAnyProtocols() && !hasAnyPartnerProtocols() && !hasAnyPrecedentDegreeInformations() && !hasAnyCandidacyPrecedentDegreeInformations() && !hasAnyUnitSpaceOccupations() && !hasAnyExamCoordinators() && !hasAnyExtraWorkRequests() && !hasAnyExternalRegistrationDatas() && !hasAnyUnitExtraWorkAmounts() && !hasAnyCooperation() && !hasAnyFiles() && !hasAnyPersistentGroups() && !hasAnyExternalCourseLoadRequests() && !hasAnyExternalProgramCertificateRequests(); } @Override public Campus getCampus() { Campus campus = super.getCampus(); if (campus != null) { return campus; } Collection parentUnits = getParentUnits(); if (parentUnits.size() == 1) { campus = parentUnits.iterator().next().getCampus(); } return campus; } public boolean isInternal() { if (this.equals(UnitUtils.readInstitutionUnit())) { return true; } for (final Unit parentUnit : getParentUnits()) { if (parentUnit.isInternal()) { return true; } } return false; } public boolean isNoOfficialExternal() { if (this.equals(UnitUtils.readExternalInstitutionUnit())) { return true; } for (final Unit parentUnit : getParentUnits()) { if (parentUnit.isNoOfficialExternal()) { return true; } } return false; } public boolean isOfficialExternal() { return !isInternal() && !isNoOfficialExternal(); } public boolean isActive(YearMonthDay currentDate) { return (!this.getBeginDateYearMonthDay().isAfter(currentDate) && (this.getEndDateYearMonthDay() == null || !this .getEndDateYearMonthDay().isBefore(currentDate))); } @Override public boolean isUnit() { return true; } public List getTopUnits() { Unit unit = this; List allTopUnits = new ArrayList(); if (unit.hasAnyParentUnits()) { for (Unit parentUnit : this.getParentUnits()) { if (!parentUnit.hasAnyParentUnits() && !allTopUnits.contains(parentUnit)) { allTopUnits.add(parentUnit); } else if (parentUnit.hasAnyParentUnits()) { for (Unit parentUnit2 : parentUnit.getTopUnits()) { if (!allTopUnits.contains(parentUnit2)) { allTopUnits.add(parentUnit2); } } } } } return allTopUnits; } public Department getDepartment() { return null; } public Degree getDegree() { return null; } public DepartmentUnit getDepartmentUnit() { if (this.isDepartmentUnit()) { return (DepartmentUnit) this; } else { for (Unit parentUnit : getParentUnits()) { if (parentUnit.isDepartmentUnit()) { return (DepartmentUnit) parentUnit; } else if (parentUnit.hasAnyParentUnits()) { Unit departmentUnit = parentUnit.getDepartmentUnit(); if (departmentUnit == null) { continue; } else { return (DepartmentUnit) departmentUnit; } } } } return null; } @Linkare(author = "Paulo Zenida", comments = "Changed the modifiers order according to the JLS suggestions") public final Collection getFunctions(final FunctionType functionType) { final Collection result = new HashSet(); for (final Function function : getFunctionsSet()) { if (function.getFunctionType() == functionType) { result.add(function); } } return result; } @Linkare(author = "Paulo Zenida", comments = "Changed the modifiers order according to the JLS suggestions") public final Function getUnitCoordinatorFunction() { final Collection possibleCoordinators = getFunctions(FunctionType.ASSIDUOUSNESS_RESPONSIBLE); if (possibleCoordinators.isEmpty()) { throw new DomainException("Unit.no.one.entitled.to.be.unit.coordinator"); } else if (possibleCoordinators.size() > 1) { throw new DomainException("Unit.more.than.one.person.entitled.to.be.unit.coordinator"); } return possibleCoordinators.iterator().next(); } @Linkare(author = "Paulo Zenida", comments = "Changed the modifiers order according to the JLS suggestions") public final Person getActiveUnitCoordinator() { return getActiveUnitCoordinator(new YearMonthDay()); } @Linkare(author = "Paulo Zenida", comments = "Changed implementation so that a DomainException is not thrown. When there is no coordinator" + " function, look in the specific properties file") public final Person getActiveUnitCoordinator(final YearMonthDay yearMonthDay) { try { for (final Accountability accountability : getUnitCoordinatorFunction().getAccountabilitiesSet()) { if (accountability.isPersonFunction() && accountability.isActive(yearMonthDay)) { return ((PersonFunction) accountability).getPerson(); } } } catch (DomainException e) { final Integer employeeNumber = PropertiesManager.getIntegerProperty(getCostCenterCode() + ".coordinator.employee.number"); if (employeeNumber != null) { final Employee employee = Employee.readByNumber(employeeNumber); return employee == null ? null : employee.getPerson(); } } return null; } public List getInactiveSubUnits(YearMonthDay currentDate) { return getSubUnitsByState(currentDate, false); } public List getActiveSubUnits(YearMonthDay currentDate) { return getSubUnitsByState(currentDate, true); } private List getSubUnitsByState(YearMonthDay currentDate, boolean state) { List allSubUnits = new ArrayList(); for (Unit subUnit : this.getSubUnits()) { if (subUnit.isActive(currentDate) == state) { allSubUnits.add(subUnit); } } return allSubUnits; } public List getInactiveParentUnits(YearMonthDay currentDate) { return getParentUnitsByState(currentDate, false); } public List getActiveParentUnits(YearMonthDay currentDate) { return getParentUnitsByState(currentDate, true); } private List getParentUnitsByState(YearMonthDay currentDate, boolean state) { List allParentUnits = new ArrayList(); for (Unit subUnit : this.getParentUnits()) { if (subUnit.isActive(currentDate) == state) { allParentUnits.add(subUnit); } } return allParentUnits; } public List getInactiveSubUnits(YearMonthDay currentDate, AccountabilityTypeEnum accountabilityTypeEnum) { return getSubUnitsByState(currentDate, accountabilityTypeEnum, false); } public List getActiveSubUnits(YearMonthDay currentDate, AccountabilityTypeEnum accountabilityTypeEnum) { return getSubUnitsByState(currentDate, accountabilityTypeEnum, true); } private List getSubUnitsByState(YearMonthDay currentDate, AccountabilityTypeEnum accountabilityTypeEnum, boolean state) { List allSubUnits = new ArrayList(); for (Unit subUnit : getSubUnits(accountabilityTypeEnum)) { if (subUnit.isActive(currentDate) == state) { allSubUnits.add(subUnit); } } return allSubUnits; } public List getActiveSubUnits(YearMonthDay currentDate, List accountabilityTypeEnums) { return getSubUnitsByState(currentDate, accountabilityTypeEnums, true); } public List getInactiveSubUnits(YearMonthDay currentDate, List accountabilityTypeEnums) { return getSubUnitsByState(currentDate, accountabilityTypeEnums, false); } private List getSubUnitsByState(YearMonthDay currentDate, List accountabilityTypeEnums, boolean state) { List allSubUnits = new ArrayList(); for (Unit subUnit : this.getSubUnits(accountabilityTypeEnums)) { if (subUnit.isActive(currentDate) == state) { allSubUnits.add(subUnit); } } return allSubUnits; } public List getAllInactiveParentUnits(YearMonthDay currentDate) { Set allInactiveParentUnits = new HashSet(); allInactiveParentUnits.addAll(getInactiveParentUnits(currentDate)); for (Unit subUnit : getParentUnits()) { allInactiveParentUnits.addAll(subUnit.getAllInactiveParentUnits(currentDate)); } return new ArrayList(allInactiveParentUnits); } public List getAllActiveParentUnits(YearMonthDay currentDate) { Set allActiveParentUnits = new HashSet(); allActiveParentUnits.addAll(getActiveParentUnits(currentDate)); for (Unit subUnit : getParentUnits()) { allActiveParentUnits.addAll(subUnit.getAllActiveParentUnits(currentDate)); } return new ArrayList(allActiveParentUnits); } public List getAllInactiveSubUnits(YearMonthDay currentDate) { Set allInactiveSubUnits = new HashSet(); allInactiveSubUnits.addAll(getInactiveSubUnits(currentDate)); for (Unit subUnit : getSubUnits()) { allInactiveSubUnits.addAll(subUnit.getAllInactiveSubUnits(currentDate)); } return new ArrayList(allInactiveSubUnits); } public List getAllActiveSubUnits(YearMonthDay currentDate) { Set allActiveSubUnits = new HashSet(); allActiveSubUnits.addAll(getActiveSubUnits(currentDate)); for (Unit subUnit : getSubUnits()) { allActiveSubUnits.addAll(subUnit.getAllActiveSubUnits(currentDate)); } return new ArrayList(allActiveSubUnits); } public List getAllActiveSubUnits(YearMonthDay currentDate, AccountabilityTypeEnum accountabilityTypeEnum) { Set allActiveSubUnits = new HashSet(); allActiveSubUnits.addAll(getActiveSubUnits(currentDate, accountabilityTypeEnum)); for (Unit subUnit : getSubUnits(accountabilityTypeEnum)) { allActiveSubUnits.addAll(subUnit.getAllActiveSubUnits(currentDate)); } return new ArrayList(allActiveSubUnits); } public List getAllInactiveSubUnits(YearMonthDay currentDate, AccountabilityTypeEnum accountabilityTypeEnum) { Set allInactiveSubUnits = new HashSet(); allInactiveSubUnits.addAll(getInactiveSubUnits(currentDate, accountabilityTypeEnum)); for (Unit subUnit : getSubUnits(accountabilityTypeEnum)) { allInactiveSubUnits.addAll(subUnit.getAllInactiveSubUnits(currentDate)); } return new ArrayList(allInactiveSubUnits); } public Collection getAllSubUnits() { Set allSubUnits = new HashSet(); Collection subUnits = getSubUnits(); allSubUnits.addAll(subUnits); for (Unit subUnit : subUnits) { allSubUnits.addAll(subUnit.getAllSubUnits()); } return allSubUnits; } public Collection getAllParentUnits() { Set allParentUnits = new HashSet(); Collection parentUnits = getParentUnits(); allParentUnits.addAll(parentUnits); for (Unit subUnit : parentUnits) { allParentUnits.addAll(subUnit.getAllParentUnits()); } return allParentUnits; } public Collection getExternalPersons() { return (Collection) getChildAccountabilities(ExternalContract.class, AccountabilityTypeEnum.WORKING_CONTRACT); } public List getWorkingContracts() { List contracts = new ArrayList(); contracts.addAll(getEmployeeContractsByType(AccountabilityTypeEnum.WORKING_CONTRACT)); return contracts; } private Collection getEmployeeContractsByType(AccountabilityTypeEnum contractType) { return (Collection) getChildAccountabilities(EmployeeContract.class, contractType); } public List getWorkingContracts(YearMonthDay begin, YearMonthDay end) { List contracts = new ArrayList(); for (Contract contract : getWorkingContracts()) { if (contract.belongsToPeriod(begin, end)) { contracts.add(contract); } } return contracts; } public List getContracts(YearMonthDay begin, YearMonthDay end, AccountabilityTypeEnum... types) { List contracts = new ArrayList(); for (Contract contract : getContracts(types)) { if (contract.belongsToPeriod(begin, end)) { contracts.add(contract); } } return contracts; } public Collection getContracts(AccountabilityTypeEnum... types) { return (Collection) getChildAccountabilities(Contract.class, types); } public List getAllTeachers() { List teachers = new ArrayList(); List employees = getAllWorkingEmployees(); for (Employee employee : employees) { Teacher teacher = employee.getPerson().getTeacher(); if (teacher != null && !teacher.getAllLegalRegimensWithoutSpecialSituations().isEmpty()) { teachers.add(teacher); } } return teachers; } public List getAllTeachers(YearMonthDay begin, YearMonthDay end) { List teachers = new ArrayList(); List employees = getAllWorkingEmployees(begin, end); for (Employee employee : employees) { Teacher teacher = employee.getPerson().getTeacher(); if (teacher != null && !teacher.getAllLegalRegimensWithoutSpecialSituations(begin, end).isEmpty()) { teachers.add(teacher); } } return teachers; } public List getAllCurrentTeachers() { List teachers = new ArrayList(); List employees = getAllCurrentActiveWorkingEmployees(); for (Employee employee : employees) { Teacher teacher = employee.getPerson().getTeacher(); if (teacher != null && teacher.getCurrentLegalRegimenWithoutSpecialSitutions() != null) { teachers.add(teacher); } } return teachers; } public List getAllCurrentNonTeacherEmployees() { List employees = getAllCurrentActiveWorkingEmployees(); for (Iterator iter = employees.iterator(); iter.hasNext();) { Employee employee = iter.next(); Teacher teacher = employee.getPerson().getTeacher(); if (teacher != null && teacher.getCurrentLegalRegimenWithoutSpecialSitutions() != null) { iter.remove(); } } return employees; } public Teacher getTeacherByPeriod(Integer teacherNumber, YearMonthDay begin, YearMonthDay end) { for (Employee employee : getAllWorkingEmployees(begin, end)) { Teacher teacher = employee.getPerson().getTeacher(); if (teacher != null && teacher.getTeacherNumber().equals(teacherNumber) && !teacher.getAllLegalRegimensWithoutSpecialSituations(begin, end).isEmpty()) { return teacher; } } return null; } public List getAllWorkingEmployees() { Set employees = new HashSet(); for (Contract contract : getWorkingContracts()) { employees.add(contract.getEmployee()); } for (Unit subUnit : getSubUnits()) { employees.addAll(subUnit.getAllWorkingEmployees()); } return new ArrayList(employees); } public List getAllWorkingEmployees(YearMonthDay begin, YearMonthDay end) { Set employees = new HashSet(); for (Contract contract : getWorkingContracts(begin, end)) { employees.add(contract.getEmployee()); } for (Unit subUnit : getSubUnits()) { employees.addAll(subUnit.getAllWorkingEmployees(begin, end)); } return new ArrayList(employees); } public List getAllCurrentActiveWorkingEmployees() { Set employees = new HashSet(); YearMonthDay currentDate = new YearMonthDay(); for (Contract contract : getWorkingContracts()) { Employee employee = contract.getEmployee(); if (employee.getActive().booleanValue() && contract.isActive(currentDate)) { employees.add(employee); } } for (Unit subUnit : getSubUnits()) { employees.addAll(subUnit.getAllCurrentActiveWorkingEmployees()); } return new ArrayList(employees); } public Collection getParentUnits() { return (Collection) getParentParties(Unit.class); } public Collection getParentUnits(AccountabilityTypeEnum accountabilityTypeEnum) { return (Collection) getParentParties(accountabilityTypeEnum, Unit.class); } public Collection getParentUnits(List accountabilityTypeEnums) { return (Collection) getParentParties(accountabilityTypeEnums, Unit.class); } public Collection getSubUnits() { return (Collection) getChildParties(Unit.class); } public boolean hasSubUnit(final Unit unit) { if (unit != null) { for (final Unit child : getSubUnits()) { if (child.equals(unit)) { return true; } } } return false; } public Collection getSubUnits(AccountabilityTypeEnum accountabilityTypeEnum) { return (Collection) getChildParties(accountabilityTypeEnum, Unit.class); } public Collection getSubUnits(List accountabilityTypeEnums) { return (Collection) getChildParties(accountabilityTypeEnums, Unit.class); } public Collection getSubUnits(final PartyTypeEnum type) { return (Collection) getChildParties(type, Unit.class); } public boolean hasAnyParentUnits() { return !getParentUnits().isEmpty(); } public boolean hasAnySubUnits() { return !getSubUnits().isEmpty(); } public Collection getParentByOrganizationalStructureAccountabilityType() { return (Collection) getParentParties(AccountabilityTypeEnum.ORGANIZATIONAL_STRUCTURE, Unit.class); } @Service /* * @See UnitMailSenderAction */ public UnitBasedSender getOneUnitBasedSender() { if (hasAnyUnitBasedSender()) { return getUnitBasedSender().get(0); } else { return UnitBasedSender.newInstance(this); } } public int getUnitDepth() { int depth = 0; for (Unit unit : getParentUnits()) { depth = Math.max(depth, 1 + unit.getUnitDepth()); } return depth; } public Accountability addParentUnit(Unit parentUnit, AccountabilityType accountabilityType) { if (this.equals(parentUnit)) { throw new DomainException("error.unit.equals.parentUnit"); } if (getParentUnits(accountabilityType.getType()).contains(parentUnit)) { throw new DomainException("error.unit.parentUnit.is.already.parentUnit"); } YearMonthDay currentDate = new YearMonthDay(); List subUnits = (parentUnit.isActive(currentDate)) ? getAllActiveSubUnits(currentDate) : getAllInactiveSubUnits(currentDate); if (subUnits.contains(parentUnit)) { throw new DomainException("error.unit.parentUnit.is.already.subUnit"); } return new Accountability(parentUnit, this, accountabilityType); } public AdministrativeOffice getAdministrativeOffice() { for (Unit parentUnit : getParentUnits(AccountabilityTypeEnum.ADMINISTRATIVE_STRUCTURE)) { if (parentUnit.isAdministrativeOfficeUnit()) { return (parentUnit).getAdministrativeOffice(); } } return null; } public NonAffiliatedTeacher findNonAffiliatedTeacherByName(final String name) { for (final NonAffiliatedTeacher nonAffiliatedTeacher : getAssociatedNonAffiliatedTeachersSet()) { if (nonAffiliatedTeacher.getName().equalsIgnoreCase(name)) { return nonAffiliatedTeacher; } } return null; } public Unit getChildUnitByAcronym(String acronym) { for (Unit subUnit : getSubUnits()) { if ((subUnit.getAcronym() != null) && (subUnit.getAcronym().equals(acronym))) { return subUnit; } } return null; } public static List readAllUnits() { final List allUnits = new ArrayList(); for (final Party party : RootDomainObject.getInstance().getPartys()) { if (party.isUnit()) { allUnits.add((Unit) party); } } return allUnits; } /** * This method should be used only for Unit types where acronyms are unique. */ public static Unit readUnitByAcronymAndType(String acronym, PartyTypeEnum partyTypeEnum) { if (acronym != null && !acronym.equals("") && partyTypeEnum != null && (partyTypeEnum.equals(PartyTypeEnum.DEGREE_UNIT) || partyTypeEnum.equals(PartyTypeEnum.DEPARTMENT) || partyTypeEnum.equals(PartyTypeEnum.PLANET) || partyTypeEnum.equals(PartyTypeEnum.COUNTRY) || partyTypeEnum.equals(PartyTypeEnum.DEPARTMENT) || partyTypeEnum.equals(PartyTypeEnum.UNIVERSITY) || partyTypeEnum.equals(PartyTypeEnum.SCHOOL) || partyTypeEnum.equals(PartyTypeEnum.RESEARCH_UNIT))) { UnitAcronym unitAcronymByAcronym = UnitAcronym.readUnitAcronymByAcronym(acronym); if (unitAcronymByAcronym != null) { for (Unit unit : unitAcronymByAcronym.getUnitsSet()) { if (unit.getType() != null && unit.getType().equals(partyTypeEnum)) { return unit; } } } } return null; } public static List readUnitsByAcronym(String acronym, boolean shouldNormalize) { List result = new ArrayList(); if (!StringUtils.isEmpty(acronym.trim())) { UnitAcronym unitAcronymByAcronym = UnitAcronym.readUnitAcronymByAcronym(acronym, shouldNormalize); if (unitAcronymByAcronym != null) { result.addAll(unitAcronymByAcronym.getUnitsSet()); } } return result; } public static List readUnitsByAcronym(String acronym) { return readUnitsByAcronym(acronym, false); } public static Unit readByCostCenterCode(Integer costCenterCode) { final UnitCostCenterCode unitCostCenterCode = UnitCostCenterCode.find(costCenterCode); return unitCostCenterCode == null ? null : unitCostCenterCode.getUnit(); } public Collection getParentUnitsByOrganizationalStructureAccountabilityType() { return (Collection) getParentParties(AccountabilityTypeEnum.ORGANIZATIONAL_STRUCTURE, Unit.class); } public static Unit createNewUnit(MultiLanguageString unitName, Integer costCenterCode, String acronym, YearMonthDay beginDate, YearMonthDay endDate, Unit parentUnit, AccountabilityType accountabilityType, String webAddress, UnitClassification classification, Boolean canBeResponsibleOfSpaces, Campus campus) { Unit unit = new Unit(); unit.init(unitName, costCenterCode, acronym, beginDate, endDate, webAddress, classification, canBeResponsibleOfSpaces, campus); if (parentUnit != null && accountabilityType != null) { unit.addParentUnit(parentUnit, accountabilityType); } return unit; } public static Unit createNewNoOfficialExternalInstitution(String unitName) { return createNewNoOfficialExternalInstitution(unitName, null); } public static Unit createNewNoOfficialExternalInstitution(String unitName, Country country) { Unit externalInstitutionUnit = UnitUtils.readExternalInstitutionUnit(); Unit noOfficialExternalInstitutionUnit = new Unit(); noOfficialExternalInstitutionUnit.init(new MultiLanguageString(Language.getDefaultLanguage(), unitName), null, null, new YearMonthDay(), null, null, null, null, null); noOfficialExternalInstitutionUnit.addParentUnit(externalInstitutionUnit, AccountabilityType .readByType(AccountabilityTypeEnum.ORGANIZATIONAL_STRUCTURE)); noOfficialExternalInstitutionUnit.setCountry(country); return noOfficialExternalInstitutionUnit; } public static Party createContributor(final String contributorName, final String contributorNumber, final PhysicalAddressData data) { final Unit contributor = Unit.createNewNoOfficialExternalInstitution(contributorName); contributor.setSocialSecurityNumber(contributorNumber); PhysicalAddress.createPhysicalAddress(contributor, data, PartyContactType.PERSONAL, true); return contributor; } public List getVigilantGroupsForGivenExecutionYear(ExecutionYear executionYear) { List groups = new ArrayList(); for (Unit unit : getSubUnits()) { groups.addAll(unit.getVigilantGroupsForGivenExecutionYear(executionYear)); } for (VigilantGroup group : getVigilantGroups()) { if (group.getExecutionYear().equals(executionYear)) { groups.add(group); } } return groups; } public List getExamCoordinatorsForGivenYear(ExecutionYear executionYear) { List examCoordinators = new ArrayList(); for (ExamCoordinator coordinator : this.getExamCoordinators()) { if (coordinator.getExecutionYear().equals(executionYear)) { examCoordinators.add(coordinator); } } return examCoordinators; } @Override public PartyClassification getPartyClassification() { return PartyClassification.UNIT; } public static Unit findFirstExternalUnitByName(final String unitName) { if (unitName == null || unitName.length() == 0) { return null; } for (final Party party : RootDomainObject.getInstance().getExternalInstitutionUnit().getSubUnits()) { if (!party.isPerson() && unitName.equalsIgnoreCase(party.getName())) { final Unit unit = (Unit) party; return unit; } } return null; } public static Unit findFirstUnitByName(final String unitNameString) { if (StringUtils.isEmpty(unitNameString)) { return null; } final Collection unitNames = UnitName.find(unitNameString, Integer.MAX_VALUE); for (final UnitName unitName : unitNames) { final Unit unit = unitName.getUnit(); if (StringNormalizer.normalize(unitNameString).equalsIgnoreCase(StringNormalizer.normalize(unit.getName()))) { return unit; } } return null; } public String getNameWithAcronym() { String name = getName().trim(); return (getAcronym() == null || StringUtils.isEmpty(getAcronym().trim())) ? name : name + " (" + getAcronym().trim() + ")"; } public String getPresentationName() { StringBuilder builder = new StringBuilder(); builder.append(getNameWithAcronym()); if (getCostCenterCode() != null) { builder.append(" [c.c. ").append(getCostCenterCode()).append("]"); } return builder.toString(); } public String getPresentationNameWithParents() { String parentUnits = getParentUnitsPresentationName(); return (!StringUtils.isEmpty(parentUnits.trim())) ? parentUnits + " - " + getPresentationName() : getPresentationName(); } public String getPresentationNameWithParentsAndBreakLine() { String parentUnits = getParentUnitsPresentationNameWithBreakLine(); return (!StringUtils.isEmpty(parentUnits.trim())) ? parentUnits + applicationResourcesBundle.getString("label.html.breakLine") + getPresentationName() : getPresentationName(); } public String getParentUnitsPresentationNameWithBreakLine() { return getParentUnitsPresentationName(applicationResourcesBundle.getString("label.html.breakLine")); } public String getParentUnitsPresentationName() { return getParentUnitsPresentationName(" - "); } private String getParentUnitsPresentationName(String separator) { StringBuilder builder = new StringBuilder(); List parentUnits = getParentUnitsPath(); int index = 1; for (Unit unit : parentUnits) { if (!unit.isAggregateUnit()) { if (index == 1) { builder.append(unit.getNameWithAcronym()); } else { builder.append(separator + unit.getNameWithAcronym()); } } index++; } return builder.toString(); } public String getUnitPath(String separator) { return getUnitPath(separator, true); } public String getUnitPath(String separator, boolean addInstitutionalUnit) { StringBuilder builder = new StringBuilder(); List parentUnits = getParentUnitsPath(addInstitutionalUnit); int index = 1; for (Unit unit : parentUnits) { if (!unit.isAggregateUnit()) { if (index == 1) { builder.append(unit.getAcronym()); } else { builder.append(separator + unit.getAcronym()); } } index++; } builder.append("/"); builder.append(this.getAcronym()); return builder.toString(); } public List getParentUnitsPath() { return getParentUnitsPath(true); } public List getParentUnitsPath(boolean addInstitutionalUnit) { List parentUnits = new ArrayList(); Unit searchedUnit = this; Unit externalInstitutionUnit = UnitUtils.readExternalInstitutionUnit(); Unit institutionUnit = UnitUtils.readInstitutionUnit(); Unit earthUnit = UnitUtils.readEarthUnit(); while (searchedUnit.getParentUnits().size() == 1) { Unit parentUnit = searchedUnit.getParentUnits().iterator().next(); if (addInstitutionalUnit || parentUnit != institutionUnit) { parentUnits.add(0, parentUnit); } if (parentUnit != institutionUnit && parentUnit != externalInstitutionUnit && parentUnit != earthUnit) { searchedUnit = parentUnit; continue; } break; } if (searchedUnit.getParentUnits().size() > 1) { if (searchedUnit.isInternal() && addInstitutionalUnit) { parentUnits.add(0, institutionUnit); } else if (searchedUnit.isNoOfficialExternal()) { parentUnits.add(0, externalInstitutionUnit); } else { parentUnits.add(0, earthUnit); } } return parentUnits; } public String getDirectParentUnitsPresentationName() { StringBuilder builder = new StringBuilder(); for (Unit unit : getParentUnits()) { if (!unit.isAggregateUnit()) { builder.append(unit.getNameWithAcronym()); } } return builder.toString(); } public String getShortPresentationName() { final StringBuilder stringBuilder = new StringBuilder(); for (final Unit unit : getParentUnits()) { if (!unit.isAggregateUnit() && unit != RootDomainObject.getInstance().getInstitutionUnit()) { stringBuilder.append(unit.getName()); stringBuilder.append(" - "); } } stringBuilder.append(getName()); return stringBuilder.toString(); } public SortedSet getSortedExternalChilds() { final SortedSet result = new TreeSet(Unit.COMPARATOR_BY_NAME_AND_ID); for (final Unit unit : getSubUnits()) { if (!unit.isInternal()) { result.add(unit); } } return result; } public List getAllExternalCurricularCourses() { return new ArrayList(getExternalCurricularCourses()); } public static void mergeExternalUnits(Unit fromUnit, Unit destinationUnit) { if (fromUnit == null || destinationUnit == null || fromUnit.equals(destinationUnit)) { throw new DomainException("error.merge.external.units.equals.units"); } if (!fromUnit.isNoOfficialExternal() || destinationUnit.isInternal()) { throw new DomainException("error.merge.external.units.invalid.units"); } Collection externalContracts = fromUnit .getChildAccountabilitiesByAccountabilityClass(ExternalContract.class); destinationUnit.getChilds().addAll(externalContracts); destinationUnit.getPayedReceipts().addAll(fromUnit.getPayedReceipts()); destinationUnit.getPayedGuides().addAll(fromUnit.getPayedGuides()); destinationUnit.getResultUnitAssociations().addAll(fromUnit.getResultUnitAssociations()); destinationUnit.getAssociatedNonAffiliatedTeachers().addAll(fromUnit.getAssociatedNonAffiliatedTeachers()); destinationUnit.getPrecedentDegreeInformations().addAll(fromUnit.getPrecedentDegreeInformations()); fromUnit.delete(); } public String[] getPrinterNamesByFunctionalityName(final String name) { for (FunctionalityPrinters functionalityPrinters : getFunctionalityPrintersSet()) { if (functionalityPrinters.getFunctionality().equals(name)) { return functionalityPrinters.getPrinterNames(); } } return new String[0]; } public boolean isSiteAvailable() { return hasSite(); } public List getAssociatedPatents() { Set patents = new HashSet(); for (ResultUnitAssociation association : getResultUnitAssociations()) { if (association.getResult() instanceof ResearchResultPatent) { patents.add((ResearchResultPatent) association.getResult()); } } return new ArrayList(patents); } public List getAccessibileFiles(Person person) { List files = new ArrayList(); for (UnitFile file : getFiles()) { if (file.isPersonAllowedToAccess(person)) { files.add(file); } } return files; } public List getAccessibileFiles(Person person, Collection tag) { List files = new ArrayList(); for (UnitFile file : getAccessibileFiles(person)) { if (file.hasUnitFileTags(tag)) { files.add(file); } } return files; } public List getAccessibileFiles(Person person, UnitFileTag tag) { List files = new ArrayList(); if (tag != null) { for (UnitFile file : tag.getTaggedFiles()) { if (file.isPersonAllowedToAccess(person)) { files.add(file); } } } return files; } public List getAccessibileFiles(Person person, String tagName) { return getAccessibileFiles(person, getUnitFileTag(tagName)); } public UnitFileTag getUnitFileTag(String name) { for (UnitFileTag tag : getUnitFileTags()) { if (tag.getName().equalsIgnoreCase(name)) { return tag; } } return null; } public void removeGroupFromUnitFiles(PersistentGroupMembers members) { PersistentGroup group = new PersistentGroup(members); for (UnitFile file : getFiles()) { file.updatePermissions(group); } } public boolean isUserAllowedToUploadFiles(Person person) { return getAllowedPeopleToUploadFiles().contains(person); } public boolean isCurrentUserAllowedToUploadFiles() { return isUserAllowedToUploadFiles(AccessControl.getPerson()); } public void setAllowedPeopleToUploadFiles(List allowedPeople) { getAllowedPeopleToUploadFiles().clear(); getAllowedPeopleToUploadFiles().addAll(allowedPeople); } public MultiLanguageString getNameI18n() { return getPartyName(); } public List getExtraWorkRequests(int year, Month month, int hoursDoneInYear, Month hoursDoneInMonth) { Partial partialDate = new Partial().with(DateTimeFieldType.year(), year).with(DateTimeFieldType.monthOfYear(), month.ordinal() + 1); Partial hoursDonePartialDate = new Partial().with(DateTimeFieldType.year(), hoursDoneInYear).with( DateTimeFieldType.monthOfYear(), hoursDoneInMonth.ordinal() + 1); List extraWorkRequestList = new ArrayList(); for (ExtraWorkRequest extraWorkRequest : getExtraWorkRequests()) { if (extraWorkRequest.getPartialPayingDate().equals(partialDate) && extraWorkRequest.getHoursDoneInPartialDate().equals(hoursDonePartialDate)) { extraWorkRequestList.add(extraWorkRequest); } } return extraWorkRequestList; } public UnitExtraWorkAmount getUnitExtraWorkAmountByYear(Integer year) { for (UnitExtraWorkAmount unitExtraWorkAmount : getUnitExtraWorkAmounts()) { if (unitExtraWorkAmount.getYear().equals(year)) { return unitExtraWorkAmount; } } return null; } public List getUserDefinedGroups() { final List groups = new ArrayList(); for (final PersistentGroupMembers persistentMembers : this.getPersistentGroups()) { groups.add(new PersistentGroup(persistentMembers)); } return groups; } public boolean isEarth() { return this.equals(RootDomainObject.getInstance().getEarthUnit()); } public List getExtraWorkRequestsByDoneAndPayingDates(Integer doneYear, Month doneMonth, Integer payingYear, Month payingMonth) { Partial donePartialDate = new Partial().with(DateTimeFieldType.year(), doneYear).with(DateTimeFieldType.monthOfYear(), doneMonth.ordinal() + 1); Partial payingPartialDate = new Partial().with(DateTimeFieldType.year(), payingYear).with( DateTimeFieldType.monthOfYear(), payingMonth.ordinal() + 1); List extraWorkRequestList = new ArrayList(); for (ExtraWorkRequest extraWorkRequest : getExtraWorkRequests()) { if (extraWorkRequest.getHoursDoneInPartialDate().equals(donePartialDate) && extraWorkRequest.getPartialPayingDate().equals(payingPartialDate)) { extraWorkRequestList.add(extraWorkRequest); } } return extraWorkRequestList; } @Override public String getPartyPresentationName() { return getPresentationNameWithParents(); } /** * Used by messaging system * * @return Groups to used as recipients */ public List getGroups() { List groups = new ArrayList(); groups.addAll(getDefaultGroups()); groups.addAll(getUserDefinedGroups()); return groups; } protected List getDefaultGroups() { return new ArrayList(); } public boolean isUserAbleToDefineGroups(Person person) { UnitSite site = getSite(); return (site == null) ? false : site.getManagers().contains(person); } public boolean isCurrentUserAbleToDefineGroups() { return isUserAbleToDefineGroups(AccessControl.getPerson()); } /** * Used by UnitBasedSender as sender group members * * @return members allowed to use the UnitBasedSenders */ public Collection getPossibleGroupMembers() { HashSet people = new HashSet(); for (Employee employee : getAllWorkingEmployees(new YearMonthDay(), null)) { people.add(employee.getPerson()); } return people; } public Collection getVirtualFunctions() { return getFunctions(FunctionType.VIRTUAL); } public void setFunctionsOrder(Collection functions) { Unit.FUNCTION_ORDERED_ADAPTER.updateOrder(this, functions); } public Collection getFunctions(boolean active) { List result = new ArrayList(); YearMonthDay today = new YearMonthDay(); for (Function function : getFunctions()) { if (function.isActive(today) != active) { continue; } result.add(function); } return result; } public Collection getActiveFunctions() { return getFunctions(true); } public Collection getInactiveFunctions() { return getFunctions(false); } public SortedSet getOrderedFunctions() { SortedSet functions = new TreeSet(Function.COMPARATOR_BY_ORDER); functions.addAll(getFunctions()); return functions; } public SortedSet getOrderedActiveFunctions() { SortedSet functions = new TreeSet(Function.COMPARATOR_BY_ORDER); functions.addAll(getActiveFunctions()); return functions; } @Override protected UnitSite createSite() { if (this == RootDomainObject.getInstance().getInstitutionUnit()) { // TODO: to be removed if institution unit becomes a specific // class return InstitutionSite.initialize(); } else { return new UnitSite(this); } } @Override public UnitSite initializeSite() { return (UnitSite) super.initializeSite(); } @Override public List getFunctions() { List result = new ArrayList(); for (Function function : super.getFunctions()) { if (function.getType().equals(AccountabilityTypeEnum.MANAGEMENT_FUNCTION)) { result.add(function); } } return result; } /* * ResearchResultPublication getters */ public List getBooks(Boolean checkSubunits) { return this.getResearchResultPublicationsByType(Book.class, checkSubunits); } public List getBooks(ExecutionYear executionYear, Boolean checkSubunits) { return this.getResearchResultPublicationsByType(Book.class, executionYear, checkSubunits); } public List getBooks(ExecutionYear firstExecutionYear, ExecutionYear lastExecutionYear, Boolean checkSubunits) { return this.getResearchResultPublicationsByType(Book.class, firstExecutionYear, lastExecutionYear, checkSubunits); } public List getInbooks(Boolean checkSubunits) { return this.getResearchResultPublicationsByType(BookPart.class, checkSubunits); } public List getInbooks(ExecutionYear executionYear, Boolean checkSubunits) { return this.getResearchResultPublicationsByType(BookPart.class, executionYear, checkSubunits); } public List getInbooks(ExecutionYear firstExecutionYear, ExecutionYear lastExecutionYear, Boolean checkSubunits) { return this.getResearchResultPublicationsByType(BookPart.class, firstExecutionYear, lastExecutionYear, checkSubunits); } public List getArticles(ScopeType locationType, Boolean checkSubunits) { return filterArticlesWithType(this.getResearchResultPublicationsByType(Article.class, checkSubunits), locationType); } public List getArticles(ScopeType locationType, ExecutionYear executionYear, Boolean checkSubunits) { return filterArticlesWithType(this.getResearchResultPublicationsByType(Article.class, executionYear, checkSubunits), locationType); } public List getArticles(ScopeType locationType, ExecutionYear firstExecutionYear, ExecutionYear lastExecutionYear, Boolean checkSubunits) { return filterArticlesWithType(this.getResearchResultPublicationsByType(Article.class, firstExecutionYear, lastExecutionYear, checkSubunits), locationType); } public List getArticles(Boolean checkSubunits) { return this.getResearchResultPublicationsByType(Article.class, checkSubunits); } public List getArticles(ExecutionYear executionYear, Boolean checkSubunits) { return this.getResearchResultPublicationsByType(Article.class, executionYear, checkSubunits); } public List getArticles(ExecutionYear firstExecutionYear, ExecutionYear lastExecutionYear, Boolean checkSubunits) { return this.getResearchResultPublicationsByType(Article.class, firstExecutionYear, lastExecutionYear, checkSubunits); } public List getInproceedings(ScopeType locationType, Boolean checkSubunits) { return filterInproceedingsWithType(this.getResearchResultPublicationsByType(Inproceedings.class, checkSubunits), locationType); } public List getInproceedings(ScopeType locationType, ExecutionYear executionYear, Boolean checkSubunits) { return filterInproceedingsWithType(this.getResearchResultPublicationsByType(Inproceedings.class, executionYear, checkSubunits), locationType); } public List getInproceedings(ScopeType locationType, ExecutionYear firstExecutionYear, ExecutionYear lastExecutionYear, Boolean checkSubunits) { return filterInproceedingsWithType(this.getResearchResultPublicationsByType(Inproceedings.class, firstExecutionYear, lastExecutionYear, checkSubunits), locationType); } public List getInproceedings(Boolean checkSubunits) { return this.getResearchResultPublicationsByType(Inproceedings.class, checkSubunits); } public List getInproceedings(ExecutionYear executionYear, Boolean checkSubunits) { return this.getResearchResultPublicationsByType(Inproceedings.class, executionYear, checkSubunits); } public List getInproceedings(ExecutionYear firstExecutionYear, ExecutionYear lastExecutionYear, Boolean checkSubunits) { return this .getResearchResultPublicationsByType(Inproceedings.class, firstExecutionYear, lastExecutionYear, checkSubunits); } public List getProceedings(Boolean checkSubunits) { return this.getResearchResultPublicationsByType(Proceedings.class, checkSubunits); } public List getProceedings(ExecutionYear executionYear, Boolean checkSubunits) { return this.getResearchResultPublicationsByType(Proceedings.class, executionYear, checkSubunits); } public List getProceedings(ExecutionYear firstExecutionYear, ExecutionYear lastExecutionYear, Boolean checkSubunits) { return this.getResearchResultPublicationsByType(Proceedings.class, firstExecutionYear, lastExecutionYear, checkSubunits); } public List getTheses(Boolean checkSubunits) { return this.getResearchResultPublicationsByType(Thesis.class, checkSubunits); } public List getTheses(ExecutionYear executionYear, Boolean checkSubunits) { return this.getResearchResultPublicationsByType(Thesis.class, executionYear, checkSubunits); } public List getTheses(ExecutionYear firstExecutionYear, ExecutionYear lastExecutionYear, Boolean checkSubunits) { return this.getResearchResultPublicationsByType(Thesis.class, firstExecutionYear, lastExecutionYear, checkSubunits); } public List getManuals(Boolean checkSubunits) { return this.getResearchResultPublicationsByType(Manual.class, checkSubunits); } public List getManuals(ExecutionYear executionYear, Boolean checkSubunits) { return this.getResearchResultPublicationsByType(Manual.class, executionYear, checkSubunits); } public List getManuals(ExecutionYear firstExecutionYear, ExecutionYear lastExecutionYear, Boolean checkSubunits) { return this.getResearchResultPublicationsByType(Manual.class, firstExecutionYear, lastExecutionYear, checkSubunits); } public List getTechnicalReports(Boolean checkSubunits) { return this.getResearchResultPublicationsByType(TechnicalReport.class, checkSubunits); } public List getTechnicalReports(ExecutionYear executionYear, Boolean checkSubunits) { return this.getResearchResultPublicationsByType(TechnicalReport.class, executionYear, checkSubunits); } public List getTechnicalReports(ExecutionYear firstExecutionYear, ExecutionYear lastExecutionYear, Boolean checkSubunits) { return this.getResearchResultPublicationsByType(TechnicalReport.class, firstExecutionYear, lastExecutionYear, checkSubunits); } public List getOtherPublications(Boolean checkSubunits) { return this.getResearchResultPublicationsByType(OtherPublication.class, checkSubunits); } public List getOtherPublications(ExecutionYear executionYear, Boolean checkSubunits) { return this.getResearchResultPublicationsByType(OtherPublication.class, executionYear, checkSubunits); } public List getOtherPublications(ExecutionYear firstExecutionYear, ExecutionYear lastExecutionYear, Boolean checkSubunits) { return this.getResearchResultPublicationsByType(OtherPublication.class, firstExecutionYear, lastExecutionYear, checkSubunits); } public List getUnstructureds(Boolean checkSubunits) { return this.getResearchResultPublicationsByType(Unstructured.class, checkSubunits); } public List getUnstructureds(ExecutionYear executionYear, Boolean checkSubunits) { return this.getResearchResultPublicationsByType(Unstructured.class, executionYear, checkSubunits); } public List getUnstructureds(ExecutionYear firstExecutionYear, ExecutionYear lastExecutionYear, Boolean checkSubunits) { return this.getResearchResultPublicationsByType(Unstructured.class, firstExecutionYear, lastExecutionYear, checkSubunits); } @Override public List getResearchResultPublications() { Set publications = new HashSet(); for (ResultUnitAssociation association : getResultUnitAssociations()) { if (association.getResult() instanceof ResearchResultPublication) { publications.add((ResearchResultPublication) association.getResult()); } } return new ArrayList(publications); } public List getResearchResultPublications(Boolean checkSubunits) { List publications = new ArrayList(getResearchResultPublications()); if (checkSubunits.equals(Boolean.TRUE)) { Set uniquePublications = new HashSet(publications); for (Unit unit : getAllSubUnits()) { uniquePublications.addAll(unit.getResearchResultPublications()); } return new ArrayList(uniquePublications); } return publications; } protected List getResearchResultPublicationsByType( final Class clazz, Boolean checkSubunits) { return filterResultPublicationsByType(clazz, getResearchResultPublications(checkSubunits)); } protected List getResearchResultPublicationsByType( final Class clazz, ExecutionYear executionYear, Boolean checkSubunits) { return filterResultPublicationsByType(clazz, getResearchResultPublicationsByExecutionYear(executionYear, checkSubunits)); } protected List getResearchResultPublicationsByType( final Class clazz, ExecutionYear firstExecutionYear, ExecutionYear lastExecutionYear, Boolean checkSubunits) { return filterResultPublicationsByType(clazz, getResearchResultPublicationsByExecutionYear(firstExecutionYear, lastExecutionYear, checkSubunits)); } protected List getResearchResultPublicationsByExecutionYear(ExecutionYear executionYear, Boolean checkSubunits) { List publications = getResearchResultPublicationsByExecutionYear(executionYear); if (checkSubunits.equals(Boolean.TRUE)) { Set uniquePublications = new HashSet(publications); for (Unit unit : getAllSubUnits()) { uniquePublications.addAll(unit.getResearchResultPublicationsByExecutionYear(executionYear)); } return new ArrayList(uniquePublications); } return publications; } protected List getResearchResultPublicationsByExecutionYear(ExecutionYear firstExecutionYear, ExecutionYear lastExecutionYear, Boolean checkSubunits) { List publications = getResearchResultPublicationsByExecutionYear(firstExecutionYear, lastExecutionYear); if (checkSubunits.equals(Boolean.TRUE)) { Set uniquePublications = new HashSet(publications); for (Unit unit : getAllSubUnits()) { uniquePublications.addAll(unit .getResearchResultPublicationsByExecutionYear(firstExecutionYear, lastExecutionYear)); } return new ArrayList(uniquePublications); } return publications; } @Override public Country getCountry() { if (super.getCountry() != null) { return super.getCountry(); } for (final Unit unit : getParentUnits()) { final Country country = unit.getCountry(); if (country != null) { return country; } } return null; } @Override public void setAcronym(String acronym) { super.setAcronym(acronym); UnitAcronym unitAcronym = UnitAcronym.readUnitAcronymByAcronym(acronym); if (unitAcronym == null) { unitAcronym = new UnitAcronym(acronym); } setUnitAcronym(unitAcronym); } public boolean hasCurrentActiveWorkingEmployee(final Employee employee) { final YearMonthDay currentDate = new YearMonthDay(); for (final Contract contract : getWorkingContracts()) { final Employee employeeFromContract = contract.getEmployee(); if (employee == employeeFromContract && employeeFromContract.getActive().booleanValue() && contract.isActive(currentDate)) { return true; } } for (final Unit subUnit : getSubUnits()) { if (subUnit.hasCurrentActiveWorkingEmployee(employee)) { return true; } } return false; } public Boolean hasParentUnit(Unit parentUnit) { for (Unit parent : getParentUnits()) { if (parent.equals(parentUnit)) { return Boolean.TRUE; } } return Boolean.FALSE; } public static Unit getParentUnit(String unitNormalizedName, Class clazz) { if (StringUtils.isEmpty(unitNormalizedName)) { return null; } for (final UnitName unitName : UnitName.find(unitNormalizedName, Integer.MAX_VALUE)) { final Unit unit = unitName.getUnit(); if (unit.getClass().equals(clazz)) { return unit; } } return null; } public static Unit getParentUnitByNormalizedName(Unit childUnit, String parentNormalizedName) { for (Unit possibleParent : childUnit.getParentUnits()) { if (parentNormalizedName.equalsIgnoreCase(StringNormalizer.normalize(possibleParent.getName()))) { return possibleParent; } } return null; } public void deleteParentUnitRelation(Unit parentUnit) { for (Accountability relation : this.getParents()) { if (relation.getParentParty().equals(parentUnit)) { relation.delete(); return; } } } public Boolean isOfficial() { return Boolean.FALSE; } }