/* * Created on Feb 10, 2006 * by mrsp */ package net.sourceforge.fenixedu.domain.organizationalStructure; import java.text.Collator; import java.util.ArrayList; import java.util.Collection; import java.util.Comparator; import java.util.HashSet; import java.util.List; import java.util.Set; import net.sourceforge.fenixedu.domain.CompetenceCourse; import net.sourceforge.fenixedu.domain.Country; import net.sourceforge.fenixedu.domain.ExecutionYear; import net.sourceforge.fenixedu.domain.PartyClassification; import net.sourceforge.fenixedu.domain.RootDomainObject; import net.sourceforge.fenixedu.domain.Site; import net.sourceforge.fenixedu.domain.accounting.Account; import net.sourceforge.fenixedu.domain.accounting.AccountType; import net.sourceforge.fenixedu.domain.contacts.EmailAddress; import net.sourceforge.fenixedu.domain.contacts.MobilePhone; import net.sourceforge.fenixedu.domain.contacts.PartyContact; import net.sourceforge.fenixedu.domain.contacts.PartyContactType; import net.sourceforge.fenixedu.domain.contacts.Phone; import net.sourceforge.fenixedu.domain.contacts.PhysicalAddress; import net.sourceforge.fenixedu.domain.contacts.PhysicalAddressData; import net.sourceforge.fenixedu.domain.contacts.WebAddress; import net.sourceforge.fenixedu.domain.exceptions.DomainException; import net.sourceforge.fenixedu.domain.research.Prize; import net.sourceforge.fenixedu.domain.research.activity.Cooperation; import net.sourceforge.fenixedu.domain.research.activity.CooperationParticipation; import net.sourceforge.fenixedu.domain.research.activity.EventEdition; import net.sourceforge.fenixedu.domain.research.activity.EventEditionParticipation; import net.sourceforge.fenixedu.domain.research.activity.EventParticipation; import net.sourceforge.fenixedu.domain.research.activity.JournalIssue; import net.sourceforge.fenixedu.domain.research.activity.JournalIssueParticipation; import net.sourceforge.fenixedu.domain.research.activity.Participation; import net.sourceforge.fenixedu.domain.research.activity.ResearchEvent; import net.sourceforge.fenixedu.domain.research.activity.ScientificJournal; import net.sourceforge.fenixedu.domain.research.activity.ScientificJournalParticipation; 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 org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.Predicate; import org.apache.commons.collections.comparators.ComparatorChain; import org.apache.commons.lang.StringUtils; import pt.utl.ist.fenix.tools.util.StringNormalizer; import pt.utl.ist.fenix.tools.util.i18n.MultiLanguageString; import com.linkare.commons.metainfo.Linkare; public abstract class Party extends Party_Base implements Comparable { static final public Comparator COMPARATOR_BY_NAME = new Comparator() { public int compare(final Party o1, final Party o2) { return Collator.getInstance().compare(o1.getName(), o2.getName()); } }; static final public Comparator COMPARATOR_BY_NAME_AND_ID = new Comparator() { public int compare(final Party o1, final Party o2) { final ComparatorChain comparatorChain = new ComparatorChain(); comparatorChain.addComparator(Party.COMPARATOR_BY_NAME); comparatorChain.addComparator(Party.COMPARATOR_BY_ID); return comparatorChain.compare(o1, o2); } }; public abstract String getPartyPresentationName(); public abstract void setName(String name); public abstract String getName(); public Party() { super(); setRootDomainObject(RootDomainObject.getInstance()); createAccount(AccountType.INTERNAL); createAccount(AccountType.EXTERNAL); } @Override public void setPartyName(MultiLanguageString partyName) { if (partyName == null || partyName.isEmpty()) { throw new DomainException("error.Party.empty.partyName"); } super.setPartyName(partyName); } @Linkare(author = "Paulo Zenida", comments = "Changed the modifiers order according to the JLS suggestions") @Deprecated @Override public final Country getNationality() { return getCountry(); } @Deprecated @Override public void setNationality(final Country country) { setCountry(country); } public Country getCountry() { return super.getNationality(); } @Linkare(author = "Paulo Zenida", comments = "Changed the modifiers order according to the JLS suggestions") public final void setCountry(final Country country) { super.setNationality(country); } public Account createAccount(AccountType accountType) { checkAccountsFor(accountType); return new Account(accountType, this); } private void checkAccountsFor(AccountType accountType) { if (getAccountBy(accountType) != null) { throw new DomainException("error.party.accounts.accountType.already.exist"); } } public Account getAccountBy(AccountType accountType) { for (final Account account : getAccountsSet()) { if (account.getAccountType() == accountType) { return account; } } return null; } public Account getInternalAccount() { return getAccountBy(AccountType.INTERNAL); } public Account getExternalAccount() { return getAccountBy(AccountType.EXTERNAL); } public PartyTypeEnum getType() { return getPartyType() != null ? getPartyType().getType() : null; } public void setType(PartyTypeEnum partyTypeEnum) { if (partyTypeEnum != null) { PartyType partyType = PartyType.readPartyTypeByType(partyTypeEnum); if (partyType == null) { throw new DomainException("error.Party.unknown.partyType"); } setPartyType(partyType); } else { setPartyType(null); } } public Collection getParentParties(AccountabilityTypeEnum accountabilityTypeEnum, Class parentPartyClass) { final Set result = new HashSet(); for (final Accountability accountability : getParentsSet()) { if (accountability.getAccountabilityType().getType() == accountabilityTypeEnum && parentPartyClass.isAssignableFrom(accountability.getParentParty().getClass())) { result.add(accountability.getParentParty()); } } return result; } public Collection getParentParties(Class parentPartyClass) { final Set result = new HashSet(); for (final Accountability accountability : getParentsSet()) { if (parentPartyClass.isAssignableFrom(accountability.getParentParty().getClass())) { result.add(accountability.getParentParty()); } } return result; } public Collection getParentParties(List accountabilityTypeEnums, Class parentPartyClass) { final Set result = new HashSet(); for (final Accountability accountability : getParentsSet()) { if (accountabilityTypeEnums.contains(accountability.getAccountabilityType().getType()) && parentPartyClass.isAssignableFrom(accountability.getParentParty().getClass())) { result.add(accountability.getParentParty()); } } return result; } public Collection getChildParties(Class childPartyClass) { final Set result = new HashSet(); for (final Accountability accountability : getChildsSet()) { if (childPartyClass.isAssignableFrom(accountability.getChildParty().getClass())) { result.add(accountability.getChildParty()); } } return result; } public Collection getChildParties(AccountabilityTypeEnum accountabilityTypeEnum, Class childPartyClass) { final Set result = new HashSet(); for (final Accountability accountability : getChildsSet()) { if (accountability.getAccountabilityType().getType() == accountabilityTypeEnum && childPartyClass.isAssignableFrom(accountability.getChildParty().getClass())) { result.add(accountability.getChildParty()); } } return result; } public Collection getChildParties(List accountabilityTypeEnums, Class childPartyClass) { final Set result = new HashSet(); for (final Accountability accountability : getChildsSet()) { if (accountabilityTypeEnums.contains(accountability.getAccountabilityType().getType()) && childPartyClass.isAssignableFrom(accountability.getChildParty().getClass())) { result.add(accountability.getChildParty()); } } return result; } protected Collection getChildParties(PartyTypeEnum type, Class childPartyClass) { final Set result = new HashSet(); for (final Accountability accountability : getChildsSet()) { if (accountability.getChildParty().getType() == type && childPartyClass.isAssignableFrom(accountability.getChildParty().getClass())) { result.add(accountability.getChildParty()); } } return result; } public Collection getParentAccountabilities(AccountabilityTypeEnum accountabilityTypeEnum) { final Set result = new HashSet(); for (final Accountability accountability : getParentsSet()) { if (accountability.getAccountabilityType().getType() == accountabilityTypeEnum) { result.add(accountability); } } return result; } public Collection getChildAccountabilities(AccountabilityTypeEnum accountabilityTypeEnum) { final Set result = new HashSet(); for (final Accountability accountability : getChildsSet()) { if (accountability.getAccountabilityType().getType() == accountabilityTypeEnum) { result.add(accountability); } } return result; } public Collection getParentAccountabilities(AccountabilityTypeEnum accountabilityTypeEnum, Class accountabilityClass) { final Set result = new HashSet(); for (final Accountability accountability : getParentsSet()) { if (accountability.getAccountabilityType().getType() == accountabilityTypeEnum && accountabilityClass.isAssignableFrom(accountability.getClass())) { result.add(accountability); } } return result; } public Collection getChildAccountabilities(Class accountabilityClass, AccountabilityTypeEnum... types) { final Set result = new HashSet(); for (final Accountability accountability : getChildsSet()) { AccountabilityTypeEnum accountabilityType = accountability.getAccountabilityType().getType(); if (!isOneOfTypes(accountabilityType, types)) { continue; } if (!accountabilityClass.isAssignableFrom(accountability.getClass())) { continue; } result.add(accountability); } return result; } private boolean isOneOfTypes(AccountabilityTypeEnum type, AccountabilityTypeEnum[] possibilities) { for (AccountabilityTypeEnum t : possibilities) { if (t == type) { return true; } } return false; } public Collection getParentAccountabilitiesByParentClass(Class parentClass) { final Set result = new HashSet(); for (final Accountability accountability : getParentsSet()) { if (parentClass.isAssignableFrom(accountability.getParentParty().getClass())) { result.add(accountability); } } return result; } public Collection getChildAccountabilitiesByChildClass(Class childClass) { final Set result = new HashSet(); for (final Accountability accountability : getChildsSet()) { if (childClass.isAssignableFrom(accountability.getChildParty().getClass())) { result.add(accountability); } } return result; } public Collection getChildAccountabilitiesByAccountabilityClass( Class accountabilityClass) { final Set result = new HashSet(); for (final Accountability accountability : getChildsSet()) { if (accountabilityClass.isAssignableFrom(accountability.getClass())) { result.add(accountability); } } return result; } protected void delete() { if (!canBeDeleted()) { throw new DomainException("error.party.cannot.be.deleted"); } for (; !getAccounts().isEmpty(); getAccounts().get(0).delete()) ; for (; hasAnyPartyContacts(); getPartyContacts().get(0).deleteWithoutCheckRules()) ; if (hasPartySocialSecurityNumber()) { getPartySocialSecurityNumber().delete(); } removeNationality(); removePartyType(); removeRootDomainObject(); deleteDomainObject(); } private boolean canBeDeleted() { return !hasAnyResourceResponsibility() && !hasAnyVehicleAllocations() && !hasAnyPayedReceipts(); } public static Party readByContributorNumber(String contributorNumber) { return PartySocialSecurityNumber.readPartyBySocialSecurityNumber(contributorNumber); } public String getSocialSecurityNumber() { return hasPartySocialSecurityNumber() ? getPartySocialSecurityNumber().getSocialSecurityNumber() : null; } public void setSocialSecurityNumber(String socialSecurityNumber) { if (socialSecurityNumber != null && socialSecurityNumber.length() != 0) { if (hasPartySocialSecurityNumber() && socialSecurityNumber.equals(getPartySocialSecurityNumber().getSocialSecurityNumber())) { return; } final Party party = PartySocialSecurityNumber.readPartyBySocialSecurityNumber(socialSecurityNumber); if (party != null && party != this) { throw new DomainException("error.party.existing.contributor.number"); } else { if (hasPartySocialSecurityNumber()) { getPartySocialSecurityNumber().setSocialSecurityNumber(socialSecurityNumber); } else { new PartySocialSecurityNumber(this, socialSecurityNumber); } } } } public void editContributor(String contributorName, String contributorNumber, String contributorAddress, String areaCode, String areaOfAreaCode, String area, String parishOfResidence, String districtSubdivisionOfResidence, String districtOfResidence) { setName(contributorName); setSocialSecurityNumber(contributorNumber); setDefaultPhysicalAddressData(new PhysicalAddressData(contributorAddress, areaCode, areaOfAreaCode, area, parishOfResidence, districtSubdivisionOfResidence, districtOfResidence, null)); } public boolean isPerson() { return false; } public boolean isUnit() { return false; } public boolean isDepartmentUnit() { return false; } public boolean isCompetenceCourseGroupUnit() { return false; } public boolean isScientificAreaUnit() { return false; } public boolean isAdministrativeOfficeUnit() { return false; } public boolean isDegreeUnit() { return false; } public boolean isAcademicalUnit() { return false; } public boolean isSchoolUnit() { return false; } public boolean isUniversityUnit() { return false; } public boolean isPlanetUnit() { return false; } public boolean isCountryUnit() { return false; } public boolean isSectionUnit() { return false; } public boolean isAggregateUnit() { return false; } public boolean isResearchUnit() { return false; } public boolean hasCompetenceCourses(final CompetenceCourse competenceCourse) { return false; } public boolean hasAdministrativeOffice() { return false; } public boolean hasDegree() { return false; } public boolean hasDepartment() { return false; } public abstract PartyClassification getPartyClassification(); public boolean verifyNameEquality(String[] nameWords) { if (nameWords == null) { return true; } if (getName() != null) { String[] personNameWords = getName().trim().split(" "); StringNormalizer.normalize(personNameWords); int j, i; for (i = 0; i < nameWords.length; i++) { if (!nameWords[i].equals("")) { for (j = 0; j < personNameWords.length; j++) { if (personNameWords[j].equals(nameWords[i])) { break; } } if (j == personNameWords.length) { return false; } } } if (i == nameWords.length) { return true; } } return false; } private List filterParticipationsByYear(List participations, ExecutionYear begin, ExecutionYear end) { List participationsForInterval = new ArrayList(); for (Participation participation : participations) { Integer year = participation.getCivilYear(); if (year == null || (begin == null || begin.isBeforeCivilYear(year) || begin.belongsToCivilYear(year)) && (end == null || end.isAfterCivilYear(year) || end.belongsToCivilYear(year))) { participationsForInterval.add(participation); } } return participationsForInterval; } private List filterParticipationsByType(Class clazz, ScopeType scopeType) { List participations = new ArrayList(); for (Participation participation : getParticipations()) { if (participation.getClass().equals(clazz) && (scopeType == null || participation.scopeMatches(scopeType))) { participations.add(participation); } } return participations; } public List getEventEditionParticipations(ScopeType type, ExecutionYear begin, ExecutionYear end) { return (List) filterParticipationsByYear(getEventEditionParticipations(type), begin, end); } public List getEventEditionParticipations(ExecutionYear begin, ExecutionYear end) { return (List) filterParticipationsByYear(getEventEditionParticipations(), begin, end); } public List getEventEditionParticipations(ScopeType type) { return (List) filterParticipationsByType(EventEditionParticipation.class, type); } public List getEventEditionParticipations() { return getEventEditionParticipations(null); } public List getEventParticipations(ScopeType type) { return (List) filterParticipationsByType(EventParticipation.class, type); } public Set getAssociatedEventEditions(ScopeType type, ExecutionYear begin, ExecutionYear end) { Set eventEditions = new HashSet(); for (EventEditionParticipation participation : getEventEditionParticipations(type, begin, end)) { eventEditions.add(participation.getEventEdition()); } return eventEditions; } public Set getAssociatedEventEditions(ExecutionYear begin, ExecutionYear end) { return getAssociatedEventEditions(null, begin, end); } public Set getAssociatedEventEditions() { return getAssociatedEventEditions(null); } public Set getAssociatedEventEditions(ScopeType type) { return getAssociatedEventEditions(type, null, null); } public List getEventParticipations(ScopeType type, ExecutionYear begin, ExecutionYear end) { return (List) filterParticipationsByYear(getEventParticipations(type), begin, end); } public List getEventParticipation(ExecutionYear begin, ExecutionYear end) { return (List) filterParticipationsByYear(getEventParticipations(), begin, end); } public List getEventParticipations() { return getEventParticipations(null); } public Set getAssociatedEvents(ScopeType type, ExecutionYear begin, ExecutionYear end) { Set events = new HashSet(); for (EventParticipation participation : getEventParticipations(type, begin, end)) { events.add(participation.getEvent()); } return events; } public Set getAssociatedEvents(ExecutionYear begin, ExecutionYear end) { return getAssociatedEvents(null, begin, end); } public Set getAssociatedEvents(ScopeType type) { return getAssociatedEvents(type, null, null); } public Set getAssociatedEvents() { return getAssociatedEvents(null); } public List getScientificJournalParticipations(ScopeType type, ExecutionYear begin, ExecutionYear end) { return (List) filterParticipationsByYear(getScientificJournalParticipations(type), begin, end); } public List getScientificJournalParticipations(ExecutionYear begin, ExecutionYear end) { return (List) filterParticipationsByYear(getScientificJournalParticipations(), begin, end); } public List getScientificJournalParticipations(ScopeType type) { return (List) filterParticipationsByType(ScientificJournalParticipation.class, type); } public List getScientificJournalParticipations() { return getScientificJournalParticipations(null); } public Set getAssociatedScientificJournals(ScopeType type, ExecutionYear begin, ExecutionYear end) { Set journals = new HashSet(); for (ScientificJournalParticipation participation : getScientificJournalParticipations(type, begin, end)) { journals.add(participation.getScientificJournal()); } return journals; } public Set getAssociatedScientificJournals(ExecutionYear begin, ExecutionYear end) { return getAssociatedScientificJournals(null, begin, end); } public Set getAssociatedScientificJournals(ScopeType type) { return getAssociatedScientificJournals(type, null, null); } public Set getAssociatedScientificJournals() { return getAssociatedScientificJournals(null); } public List getJournalIssueParticipations(ScopeType type, ExecutionYear begin, ExecutionYear end) { return (List) filterParticipationsByYear(getJournalIssueParticipations(type), begin, end); } public List getJournalIssueParticipations(ExecutionYear begin, ExecutionYear end) { return (List) filterParticipationsByYear(getJournalIssueParticipations(), begin, end); } public List getJournalIssueParticipations(ScopeType type) { return (List) filterParticipationsByType(JournalIssueParticipation.class, type); } public List getJournalIssueParticipations() { return getJournalIssueParticipations(null); } public Set getAssociatedJournalIssues(ScopeType type, ExecutionYear begin, ExecutionYear end) { Set issues = new HashSet(); for (JournalIssueParticipation participation : this.getJournalIssueParticipations(type, begin, end)) { issues.add(participation.getJournalIssue()); } return issues; } public Set getAssociatedJournalIssues(ExecutionYear begin, ExecutionYear end) { return getAssociatedJournalIssues(null, begin, end); } public Set getAssociatedJournalIssues(ScopeType locationType) { return getAssociatedJournalIssues(locationType, null, null); } public Set getAssociatedJournalIssues() { return getAssociatedJournalIssues(null); } public List getCooperationParticipations(ExecutionYear begin, ExecutionYear end) { return (List) filterParticipationsByYear(getCooperationParticipations(), begin, end); } public List getCooperationParticipations() { List cooperationParticipations = new ArrayList(); for (Participation participation : this.getParticipations()) { if (participation.isCooperationParticipation()) { cooperationParticipations.add((CooperationParticipation) participation); } } return cooperationParticipations; } public Set getAssociatedCooperations(ExecutionYear begin, ExecutionYear end) { Set cooperations = new HashSet(); for (CooperationParticipation participation : getCooperationParticipations(begin, end)) { cooperations.add(participation.getCooperation()); } return cooperations; } public Set getAssociatedCooperations() { return getAssociatedCooperations(null, null); } public List getPartyContacts(final Class clazz, final PartyContactType type) { final List result = new ArrayList(); for (final PartyContact contact : getPartyContactsSet()) { if (clazz.isAssignableFrom(contact.getClass()) && (type == null || contact.getType() == type)) { result.add(contact); } } return result; } public List getPartyContacts(final Class clazz) { return getPartyContacts(clazz, null); } public boolean hasAnyPartyContact(final Class clazz, final PartyContactType type) { for (final PartyContact contact : getPartyContactsSet()) { if (clazz.isAssignableFrom(contact.getClass()) && (type == null || contact.getType() == type)) { return true; } } return false; } public boolean hasAnyPartyContact(final Class clazz) { return hasAnyPartyContact(clazz, null); } @Linkare(author = "Paulo Zenida", comments = "Institutional contacts should not be the default contact") public PartyContact getDefaultPartyContact(final Class clazz) { for (final PartyContact contact : getPartyContactsSet()) { if (clazz.isAssignableFrom(contact.getClass()) && contact.isDefault() && !contact.isInstitutionalType()) { return contact; } } return null; } public boolean hasDefaultPartyContact(final Class clazz) { return getDefaultPartyContact(clazz) != null; } public PartyContact getInstitutionalPartyContact(final Class clazz) { List institutionals = (List) getPartyContacts(EmailAddress.class, PartyContactType.INSTITUTIONAL); return institutionals.isEmpty() ? null : institutionals.get(0); } public boolean hasInstitutionalPartyContact(final Class clazz) { return getInstitutionalPartyContact(clazz) != null; } /* * WebAddress */ public List getWebAddresses() { return (List) getPartyContacts(WebAddress.class); } public boolean hasDefaultWebAddress() { return hasDefaultPartyContact(WebAddress.class); } public WebAddress getDefaultWebAddress() { return (WebAddress) getDefaultPartyContact(WebAddress.class); } public String getDefaultWebAddressUrl() { return hasDefaultWebAddress() ? getDefaultWebAddress().getUrl() : StringUtils.EMPTY; } public void setDefaultWebAddressUrl(final String url) { if (hasDefaultWebAddress()) { getDefaultWebAddress().edit(url); } else { WebAddress.createWebAddress(this, url, PartyContactType.PERSONAL, true); } } /** * @use {@link #getDefaultWebAddressUrl()} */ @Deprecated public String getWebAddress() { return getDefaultWebAddressUrl(); } /** * @use {@link #setDefaultWebAddressUrl(String)} */ @Deprecated public void setWebAddress(String webAddress) { setDefaultWebAddressUrl(webAddress); } /* * Phone */ public List getPhones() { return (List) getPartyContacts(Phone.class); } public boolean hasDefaultPhone() { return hasDefaultPartyContact(Phone.class); } public Phone getDefaultPhone() { return (Phone) getDefaultPartyContact(Phone.class); } public String getDefaultPhoneNumber() { return hasDefaultPhone() ? getDefaultPhone().getNumber() : StringUtils.EMPTY; } public void setDefaultPhoneNumber(final String number) { if (hasDefaultPhone()) { getDefaultPhone().edit(number); } else { Phone.createPhone(this, number, PartyContactType.PERSONAL, true); } } /** * This should not be used because assumes that there is only one work * phone. */ @Deprecated public void setWorkPhoneNumber(final String number) { if (hasAnyPartyContact(Phone.class, PartyContactType.WORK)) { ((Phone) getPartyContacts(Phone.class, PartyContactType.WORK).get(0)).edit(number); } else { Phone.createPhone(this, number, PartyContactType.WORK, false); } } /** * @use {@link #getDefaultPhoneNumber()} */ @Deprecated public String getPhone() { return getDefaultPhoneNumber(); } /** * @use {@link #setDefaultPhoneNumber(String)} */ @Deprecated public void setPhone(String phone) { setDefaultPhoneNumber(phone); } // Currently, a Person can only have one WorkPhone (so use get(0) - // after // interface updates remove these methods) public Phone getPersonWorkPhone() { final List partyContacts = (List) getPartyContacts(Phone.class, PartyContactType.WORK); // actually exists only one return partyContacts.isEmpty() ? null : (Phone) partyContacts.get(0); } @Deprecated public String getWorkPhone() { final Phone workPhone = getPersonWorkPhone(); return workPhone != null ? workPhone.getNumber() : null; } @Deprecated public void setWorkPhone(String workPhone) { setWorkPhoneNumber(workPhone); } /* * MobilePhone */ public List getMobilePhones() { return (List) getPartyContacts(MobilePhone.class); } public boolean hasDefaultMobilePhone() { return hasDefaultPartyContact(MobilePhone.class); } public MobilePhone getDefaultMobilePhone() { return (MobilePhone) getDefaultPartyContact(MobilePhone.class); } public String getDefaultMobilePhoneNumber() { return hasDefaultMobilePhone() ? getDefaultMobilePhone().getNumber() : StringUtils.EMPTY; } public void setDefaultMobilePhoneNumber(final String number) { if (hasDefaultMobilePhone()) { getDefaultMobilePhone().edit(number); } else { MobilePhone.createMobilePhone(this, number, PartyContactType.PERSONAL, true); } } /** * @use {@link getDefaultMobilePhoneNumber} */ @Deprecated public String getMobile() { return getDefaultMobilePhoneNumber(); } /** * @use {@link setDefaultMobilePhoneNumber} */ @Deprecated public void setMobile(String mobile) { setDefaultMobilePhoneNumber(mobile); } /* * EmailAddress */ public List getEmailAddresses() { return (List) getPartyContacts(EmailAddress.class); } public boolean hasDefaultEmailAddress() { return hasDefaultPartyContact(EmailAddress.class); } public EmailAddress getDefaultEmailAddress() { return (EmailAddress) getDefaultPartyContact(EmailAddress.class); } public boolean hasInstitutionalEmailAddress() { return hasInstitutionalPartyContact(EmailAddress.class); } public EmailAddress getInstitutionalEmailAddress() { return (EmailAddress) getInstitutionalPartyContact(EmailAddress.class); } public EmailAddress getInstitutionalOrDefaultEmailAddress() { return hasInstitutionalEmailAddress() ? getInstitutionalEmailAddress() : getDefaultEmailAddress(); } public String getDefaultEmailAddressValue() { return hasDefaultEmailAddress() ? getDefaultEmailAddress().getValue() : StringUtils.EMPTY; } public void setDefaultEmailAddressValue(final String email) { if (hasDefaultEmailAddress()) { getDefaultEmailAddress().setValue(email); } else { EmailAddress.createEmailAddress(this, email, PartyContactType.PERSONAL, true); } } public String getInstitutionalEmailAddressValue() { return hasInstitutionalEmailAddress() ? getInstitutionalEmailAddress().getValue() : StringUtils.EMPTY; } public void setInstitutionalEmailAddressValue(final String email) { if (hasInstitutionalEmailAddress()) { getInstitutionalEmailAddress().setValue(email); } else { EmailAddress.createEmailAddress(this, email, PartyContactType.INSTITUTIONAL, false); } } public String getInstitutionalOrDefaultEmailAddressValue() { EmailAddress email = getInstitutionalOrDefaultEmailAddress(); return (email != null ? email.getValue() : StringUtils.EMPTY); } /** * @use {@link #getDefaultEmailAddressValue()} */ @Deprecated public String getEmail() { return getDefaultEmailAddressValue() == StringUtils.EMPTY ? getInstitutionalEmailAddressValue() : getDefaultEmailAddressValue(); } /** * @use {@link #setDefaultEmailAddressValue(String)} */ @Deprecated public void setEmail(String email) { setDefaultEmailAddressValue(email); } /* * PhysicalAddress */ public List getPhysicalAddresses() { return (List) getPartyContacts(PhysicalAddress.class); } public boolean hasDefaultPhysicalAddress() { return hasDefaultPartyContact(PhysicalAddress.class); } public PhysicalAddress getDefaultPhysicalAddress() { return (PhysicalAddress) getDefaultPartyContact(PhysicalAddress.class); } public void setDefaultPhysicalAddressData(final PhysicalAddressData data) { if (hasDefaultPhysicalAddress()) { getDefaultPhysicalAddress().edit(data); } else { PhysicalAddress.createPhysicalAddress(this, data, PartyContactType.PERSONAL, true); } } private PhysicalAddress getOrCreateDefaultPhysicalAddress() { final PhysicalAddress physicalAdress = getDefaultPhysicalAddress(); return physicalAdress != null ? physicalAdress : PhysicalAddress.createPhysicalAddress(this, null, PartyContactType.PERSONAL, true); } public String getAddress() { return hasDefaultPhysicalAddress() ? getDefaultPhysicalAddress().getAddress() : StringUtils.EMPTY; } @Linkare(author = "Paulo Zenida", comments = "Added check for null") public void setAddress(String address) { final PhysicalAddress physicalAddress = getOrCreateDefaultPhysicalAddress(); if (physicalAddress != null) { physicalAddress.setAddress(address); } } public String getAreaCode() { return hasDefaultPhysicalAddress() ? getDefaultPhysicalAddress().getAreaCode() : StringUtils.EMPTY; } @Linkare(author = "Paulo Zenida", comments = "Added check for null") public void setAreaCode(String areaCode) { final PhysicalAddress physicalAddress = getOrCreateDefaultPhysicalAddress(); if (physicalAddress != null) { physicalAddress.setAreaCode(areaCode); } } public String getAreaOfAreaCode() { return hasDefaultPhysicalAddress() ? getDefaultPhysicalAddress().getAreaOfAreaCode() : StringUtils.EMPTY; } @Linkare(author = "Paulo Zenida", comments = "Added check for null") public void setAreaOfAreaCode(String areaOfAreaCode) { final PhysicalAddress physicalAddress = getOrCreateDefaultPhysicalAddress(); if (physicalAddress != null) { physicalAddress.setAreaOfAreaCode(areaOfAreaCode); } } public String getPostalCode() { return hasDefaultPhysicalAddress() ? getDefaultPhysicalAddress().getPostalCode() : StringUtils.EMPTY; } public String getArea() { return hasDefaultPhysicalAddress() ? getDefaultPhysicalAddress().getArea() : StringUtils.EMPTY; } @Linkare(author = "Paulo Zenida", comments = "Added check for null") public void setArea(String area) { final PhysicalAddress physicalAddress = getOrCreateDefaultPhysicalAddress(); if (physicalAddress != null) { physicalAddress.setArea(area); } } public String getParishOfResidence() { return hasDefaultPhysicalAddress() ? getDefaultPhysicalAddress().getParishOfResidence() : StringUtils.EMPTY; } @Linkare(author = "Paulo Zenida", comments = "Added check for null") public void setParishOfResidence(String parishOfResidence) { final PhysicalAddress physicalAddress = getOrCreateDefaultPhysicalAddress(); if (physicalAddress != null) { physicalAddress.setParishOfResidence(parishOfResidence); } } public String getDistrictSubdivisionOfResidence() { return hasDefaultPhysicalAddress() ? getDefaultPhysicalAddress().getDistrictSubdivisionOfResidence() : StringUtils.EMPTY; } @Linkare(author = "Paulo Zenida", comments = "Added check for null") public void setDistrictSubdivisionOfResidence(String districtSubdivisionOfResidence) { final PhysicalAddress physicalAddress = getOrCreateDefaultPhysicalAddress(); if (physicalAddress != null) { physicalAddress.setDistrictSubdivisionOfResidence(districtSubdivisionOfResidence); } } public String getDistrictOfResidence() { return hasDefaultPhysicalAddress() ? getDefaultPhysicalAddress().getDistrictOfResidence() : StringUtils.EMPTY; } @Linkare(author = "Paulo Zenida", comments = "Added check for null") public void setDistrictOfResidence(String districtOfResidence) { final PhysicalAddress physicalAddress = getOrCreateDefaultPhysicalAddress(); if (physicalAddress != null) { physicalAddress.setDistrictOfResidence(districtOfResidence); } } public Country getCountryOfResidence() { return hasDefaultPhysicalAddress() ? getDefaultPhysicalAddress().getCountryOfResidence() : null; } @Linkare(author = "Paulo Zenida", comments = "Added check for null") public void setCountryOfResidence(Country countryOfResidence) { final PhysicalAddress physicalAddress = getOrCreateDefaultPhysicalAddress(); if (physicalAddress != null) { physicalAddress.setCountryOfResidence(countryOfResidence); } } protected List filterArticlesWithType(List publications, ScopeType locationType) { List publicationsOfType = new ArrayList(); for (ResearchResultPublication publication : publications) { Article article = (Article) publication; if (article.getScope().equals(locationType)) { publicationsOfType.add(publication); } } return publicationsOfType; } protected List filterInproceedingsWithType(List publications, ScopeType locationType) { List publicationsOfType = new ArrayList(); for (ResearchResultPublication publication : publications) { Inproceedings inproceedings = (Inproceedings) publication; if (inproceedings.getScope().equals(locationType)) { publicationsOfType.add(publication); } } return publicationsOfType; } protected List filterResultPublicationsByType( final Class clazz, List publications) { return (List) CollectionUtils.select(publications, new Predicate() { public boolean evaluate(Object arg0) { return clazz.equals(arg0.getClass()); } }); } protected List getResearchResultPublicationsByType( final Class clazz) { return filterResultPublicationsByType(clazz, getResearchResultPublications()); } protected List getResearchResultPublicationsByType( final Class clazz, ExecutionYear executionYear) { return filterResultPublicationsByType(clazz, getResearchResultPublicationsByExecutionYear(executionYear)); } protected List getResearchResultPublicationsByType( final Class clazz, ExecutionYear firstExecutionYear, ExecutionYear lastExecutionYear) { return filterResultPublicationsByType(clazz, getResearchResultPublicationsByExecutionYear(firstExecutionYear, lastExecutionYear)); } public List getResearchResultPublicationsByExecutionYear(ExecutionYear executionYear) { List publicationsForExecutionYear = new ArrayList(); for (ResearchResultPublication publication : getResearchResultPublications()) { if (publication.getYear() == null || executionYear.belongsToCivilYear(publication.getYear())) { publicationsForExecutionYear.add(publication); } } return publicationsForExecutionYear; } protected List getResearchResultPublicationsByExecutionYear(ExecutionYear firstExecutionYear, ExecutionYear lastExecutionYear) { List publicationsForExecutionYear = new ArrayList(); if (firstExecutionYear == null) { firstExecutionYear = ExecutionYear.readFirstExecutionYear(); } if (lastExecutionYear == null || lastExecutionYear.isBefore(firstExecutionYear)) { lastExecutionYear = ExecutionYear.readLastExecutionYear(); } for (ResearchResultPublication publication : getResearchResultPublications()) { if (publication.getYear() == null || ((firstExecutionYear.isBeforeCivilYear(publication.getYear()) || firstExecutionYear .belongsToCivilYear(publication.getYear())) && (lastExecutionYear.isAfterCivilYear(publication .getYear()) || lastExecutionYear.belongsToCivilYear(publication.getYear())))) { publicationsForExecutionYear.add(publication); } } return publicationsForExecutionYear; } public List getPrizes(ExecutionYear executionYear) { List prizes = new ArrayList(); for (Prize prize : this.getPrizes()) { if (executionYear.belongsToCivilYear(prize.getYear())) { prizes.add(prize); } } return prizes; } public abstract List getResearchResultPublications(); public List getBooks() { return this.getResearchResultPublicationsByType(Book.class); } public List getBooks(ExecutionYear executionYear) { return this.getResearchResultPublicationsByType(Book.class, executionYear); } public List getBooks(ExecutionYear firstExecutionYear, ExecutionYear lastExecutionYear) { return this.getResearchResultPublicationsByType(Book.class, firstExecutionYear, lastExecutionYear); } public List getInbooks() { return this.getResearchResultPublicationsByType(BookPart.class); } public List getInbooks(ExecutionYear executionYear) { return this.getResearchResultPublicationsByType(BookPart.class, executionYear); } public List getInbooks(ExecutionYear firstExecutionYear, ExecutionYear lastExecutionYear) { return this.getResearchResultPublicationsByType(BookPart.class, firstExecutionYear, lastExecutionYear); } public List getArticles(ScopeType locationType) { return filterArticlesWithType(this.getResearchResultPublicationsByType(Article.class), locationType); } public List getArticles(ScopeType locationType, ExecutionYear executionYear) { return filterArticlesWithType(this.getResearchResultPublicationsByType(Article.class, executionYear), locationType); } public List getArticles(ScopeType locationType, ExecutionYear firstExecutionYear, ExecutionYear lastExecutionYear) { return filterArticlesWithType(this.getResearchResultPublicationsByType(Article.class, firstExecutionYear, lastExecutionYear), locationType); } public List getArticles() { return this.getResearchResultPublicationsByType(Article.class); } public List getArticles(ExecutionYear executionYear) { return this.getResearchResultPublicationsByType(Article.class, executionYear); } public List getArticles(ExecutionYear firstExecutionYear, ExecutionYear lastExecutionYear) { return this.getResearchResultPublicationsByType(Article.class, firstExecutionYear, lastExecutionYear); } public List getInproceedings(ScopeType locationType) { return filterInproceedingsWithType(this.getResearchResultPublicationsByType(Inproceedings.class), locationType); } public List getInproceedings(ScopeType locationType, ExecutionYear executionYear) { return filterInproceedingsWithType(this.getResearchResultPublicationsByType(Inproceedings.class, executionYear), locationType); } public List getInproceedings(ScopeType locationType, ExecutionYear firstExecutionYear, ExecutionYear lastExecutionYear) { return filterInproceedingsWithType(this.getResearchResultPublicationsByType(Inproceedings.class, firstExecutionYear, lastExecutionYear), locationType); } public List getInproceedings() { return this.getResearchResultPublicationsByType(Inproceedings.class); } public List getInproceedings(ExecutionYear executionYear) { return this.getResearchResultPublicationsByType(Inproceedings.class, executionYear); } public List getInproceedings(ExecutionYear firstExecutionYear, ExecutionYear lastExecutionYear) { return this.getResearchResultPublicationsByType(Inproceedings.class, firstExecutionYear, lastExecutionYear); } public List getProceedings() { return this.getResearchResultPublicationsByType(Proceedings.class); } public List getProceedings(ExecutionYear executionYear) { return this.getResearchResultPublicationsByType(Proceedings.class, executionYear); } public List getProceedings(ExecutionYear firstExecutionYear, ExecutionYear lastExecutionYear) { return this.getResearchResultPublicationsByType(Proceedings.class, firstExecutionYear, lastExecutionYear); } public List getTheses() { return this.getResearchResultPublicationsByType(Thesis.class); } public List getTheses(ExecutionYear executionYear) { return this.getResearchResultPublicationsByType(Thesis.class, executionYear); } public List getTheses(ExecutionYear firstExecutionYear, ExecutionYear lastExecutionYear) { return this.getResearchResultPublicationsByType(Thesis.class, firstExecutionYear, lastExecutionYear); } public List getManuals() { return this.getResearchResultPublicationsByType(Manual.class); } public List getManuals(ExecutionYear executionYear) { return this.getResearchResultPublicationsByType(Manual.class, executionYear); } public List getManuals(ExecutionYear firstExecutionYear, ExecutionYear lastExecutionYear) { return this.getResearchResultPublicationsByType(Manual.class, firstExecutionYear, lastExecutionYear); } public List getTechnicalReports() { return ResearchResultPublication.sort(this.getResearchResultPublicationsByType(TechnicalReport.class)); } public List getTechnicalReports(ExecutionYear executionYear) { return this.getResearchResultPublicationsByType(TechnicalReport.class, executionYear); } public List getTechnicalReports(ExecutionYear firstExecutionYear, ExecutionYear lastExecutionYear) { return this.getResearchResultPublicationsByType(TechnicalReport.class, firstExecutionYear, lastExecutionYear); } public List getOtherPublications() { return this.getResearchResultPublicationsByType(OtherPublication.class); } public List getOtherPublications(ExecutionYear executionYear) { return this.getResearchResultPublicationsByType(OtherPublication.class, executionYear); } public List getOtherPublications(ExecutionYear firstExecutionYear, ExecutionYear lastExecutionYear) { return this.getResearchResultPublicationsByType(OtherPublication.class, firstExecutionYear, lastExecutionYear); } public List getUnstructureds() { return this.getResearchResultPublicationsByType(Unstructured.class); } public List getUnstructureds(ExecutionYear executionYear) { return this.getResearchResultPublicationsByType(Unstructured.class, executionYear); } public List getUnstructureds(ExecutionYear firstExecutionYear, ExecutionYear lastExecutionYear) { return this.getResearchResultPublicationsByType(Unstructured.class, firstExecutionYear, lastExecutionYear); } // // Site // public abstract Site getSite(); protected abstract Site createSite(); /** * Initializes the party's site. This method ensures that if the party has a * site then no other is created and that site is returned. Nevertheless if * the party does not have a site, it is asked to create one by calling * {@link #createSite()}. This allows each specific party to create the * appropriate site. * * @return the newly created site or, if this party already contains a site, * the currently existing one(publication.getYear()) */ public Site initializeSite() { Site site = getSite(); if (site != null) { return site; } else { return createSite(); } } @Override public int compareTo(Party party) { return COMPARATOR_BY_NAME.compare(this, party); } @Linkare(author = "Paulo Zenida") @Override public String getShortDescription() { return getName(); } }