package net.sourceforge.fenixedu.domain.organizationalStructure; import java.util.ArrayList; import java.util.Collection; import java.util.List; import net.sourceforge.fenixedu.domain.Person; import net.sourceforge.fenixedu.domain.ResearchUnitSite; import net.sourceforge.fenixedu.domain.exceptions.DomainException; import net.sourceforge.fenixedu.domain.space.Campus; import net.sourceforge.fenixedu.injectionCode.AccessControl; import org.apache.commons.lang.StringUtils; import org.joda.time.YearMonthDay; import pt.utl.ist.fenix.tools.util.i18n.MultiLanguageString; public class ResearchUnit extends ResearchUnit_Base { private ResearchUnit() { super(); super.setType(PartyTypeEnum.RESEARCH_UNIT); } // public static ResearchUnit createNewResearchUnit(MultiLanguageString name, Integer costCenterCode, String acronym, YearMonthDay beginDate, YearMonthDay endDate, Unit parentUnit, AccountabilityType accountabilityType, String webAddress, UnitClassification classification, Boolean canBeResponsibleOfSpaces, Campus campus) { ResearchUnit researchUnit = new ResearchUnit(); researchUnit.init(name, costCenterCode, acronym, beginDate, endDate, webAddress, classification, canBeResponsibleOfSpaces, campus); researchUnit.addParentUnit(parentUnit, accountabilityType); checkIfAlreadyExistsOneResearchUnitWithSameNameOrAcronym(researchUnit); return researchUnit; } @Override public void setAcronym(String acronym) { if (StringUtils.isEmpty(acronym)) { throw new DomainException("acronym.cannot.be.null"); } super.setAcronym(acronym); } @Override public boolean isResearchUnit() { return true; } @Override public void setType(PartyTypeEnum partyTypeEnum) { throw new DomainException("unit.impossible.set.type"); } private static void checkIfAlreadyExistsOneResearchUnitWithSameNameOrAcronym( ResearchUnit researchUnit) { PartyType type = PartyType.readPartyTypeByType(PartyTypeEnum.RESEARCH_UNIT); for (Party party : type.getParties()) { ResearchUnit unit = (ResearchUnit) party; if (!unit.equals(researchUnit) && unit.isResearchUnit() && researchUnit.getName().equalsIgnoreCase(unit.getName()) && researchUnit.getAcronym().equalsIgnoreCase(unit.getAcronym())) { throw new DomainException("error.unit.already.exists.unit.with.same.name.or.acronym"); } } } public Collection getResearchContracts() { return (Collection) getChildAccountabilities(AccountabilityTypeEnum.RESEARCH_CONTRACT); } public Collection getActivePeopleForContract(Class clazz) { AccountabilityType accountabilityType = Function .readAccountabilityTypeByType(AccountabilityTypeEnum.RESEARCH_CONTRACT); YearMonthDay today = new YearMonthDay(); List people = new ArrayList(); for (Accountability accountability : getChildsSet()) { if (accountability.getAccountabilityType().equals(accountabilityType) && (accountability.getEndDate() == null || accountability.getEndDate() .isAfter(today)) && clazz.isAssignableFrom(accountability.getClass())) { people.add((Person) accountability.getChildParty()); } } return people; } public Collection getActiveResearchContracts(Class clazz) { ; AccountabilityType accountabilityType = Function .readAccountabilityTypeByType(AccountabilityTypeEnum.RESEARCH_CONTRACT); YearMonthDay today = new YearMonthDay(); List accountabilities = new ArrayList(); for (Accountability accountability : getChildsSet()) { if (accountability.getAccountabilityType().equals(accountabilityType) && (accountability.getEndDate() == null || accountability.getEndDate() .isAfter(today)) && clazz.isAssignableFrom(accountability.getClass())) { accountabilities.add(accountability); } } return accountabilities; } public Collection getAllCurrentActiveSubUnits() { return this.getAllActiveSubUnits(new YearMonthDay(), AccountabilityTypeEnum.ORGANIZATIONAL_STRUCTURE); } public boolean isUserAbleToInsertOthersPublications(Person person) { return getPublicationCollaborators().contains(person); } public boolean isCurrentUserAbleToInsertOthersPublications() { return isUserAbleToInsertOthersPublications(AccessControl.getPerson()); } public void setPublicationCollaborators(List collaborators) { getPublicationCollaborators().clear(); getPublicationCollaborators().addAll(collaborators); } @Override protected ResearchUnitSite createSite() { return new ResearchUnitSite(this); } }