package net.sourceforge.fenixedu.domain; import java.io.Serializable; import java.text.ParseException; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.HashSet; import java.util.Iterator; import java.util.LinkedList; import java.util.List; import java.util.ResourceBundle; import java.util.Set; import java.util.SortedSet; import java.util.TreeSet; import net.sourceforge.fenixedu.applicationTier.Servico.teacher.professorship.ResponsibleForValidator; import net.sourceforge.fenixedu.applicationTier.Servico.teacher.professorship.ResponsibleForValidator.InvalidCategory; import net.sourceforge.fenixedu.applicationTier.Servico.teacher.professorship.ResponsibleForValidator.MaxResponsibleForExceed; import net.sourceforge.fenixedu.applicationTier.security.PasswordEncryptor; import net.sourceforge.fenixedu.dataTransferObject.InfoPersonEditor; import net.sourceforge.fenixedu.dataTransferObject.externalServices.PersonInformationFromUniqueCardDTO; import net.sourceforge.fenixedu.dataTransferObject.person.ExternalPersonBean; import net.sourceforge.fenixedu.dataTransferObject.person.PersonBean; import net.sourceforge.fenixedu.domain.accessControl.PersonGroup; import net.sourceforge.fenixedu.domain.accounting.AcademicEvent; import net.sourceforge.fenixedu.domain.accounting.Entry; import net.sourceforge.fenixedu.domain.accounting.Event; import net.sourceforge.fenixedu.domain.accounting.EventType; import net.sourceforge.fenixedu.domain.accounting.Receipt; import net.sourceforge.fenixedu.domain.accounting.ResidenceEvent; import net.sourceforge.fenixedu.domain.accounting.ServiceAgreement; import net.sourceforge.fenixedu.domain.accounting.ServiceAgreementTemplate; import net.sourceforge.fenixedu.domain.accounting.events.AdministrativeOfficeFeeAndInsuranceEvent; import net.sourceforge.fenixedu.domain.accounting.events.AnnualEvent; import net.sourceforge.fenixedu.domain.accounting.events.PastAdministrativeOfficeFeeAndInsuranceEvent; import net.sourceforge.fenixedu.domain.accounting.events.gratuity.GratuityEvent; import net.sourceforge.fenixedu.domain.accounting.events.insurance.InsuranceEvent; import net.sourceforge.fenixedu.domain.administrativeOffice.AdministrativeOffice; import net.sourceforge.fenixedu.domain.assiduousness.util.AssiduousnessState; import net.sourceforge.fenixedu.domain.candidacy.Candidacy; import net.sourceforge.fenixedu.domain.candidacy.CandidacySituationType; import net.sourceforge.fenixedu.domain.candidacy.DFACandidacy; import net.sourceforge.fenixedu.domain.candidacy.DegreeCandidacy; import net.sourceforge.fenixedu.domain.candidacy.StudentCandidacy; import net.sourceforge.fenixedu.domain.candidacyProcess.IndividualCandidacy; import net.sourceforge.fenixedu.domain.candidacyProcess.IndividualCandidacyPersonalDetails; import net.sourceforge.fenixedu.domain.candidacyProcess.graduatedPerson.DegreeCandidacyForGraduatedPerson; import net.sourceforge.fenixedu.domain.candidacyProcess.over23.Over23IndividualCandidacy; import net.sourceforge.fenixedu.domain.candidacyProcess.secondCycle.SecondCycleIndividualCandidacy; import net.sourceforge.fenixedu.domain.candidacyProcess.standalone.StandaloneIndividualCandidacy; import net.sourceforge.fenixedu.domain.cardGeneration.CardGenerationBatch; import net.sourceforge.fenixedu.domain.cardGeneration.CardGenerationEntry; import net.sourceforge.fenixedu.domain.cardGeneration.CardGenerationProblem; import net.sourceforge.fenixedu.domain.contacts.EmailAddress; import net.sourceforge.fenixedu.domain.contacts.MobilePhone; 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.degree.DegreeType; import net.sourceforge.fenixedu.domain.documents.AnnualIRSDeclarationDocument; import net.sourceforge.fenixedu.domain.documents.GeneratedDocument; import net.sourceforge.fenixedu.domain.exceptions.DomainException; import net.sourceforge.fenixedu.domain.finalDegreeWork.Proposal; import net.sourceforge.fenixedu.domain.grant.owner.GrantOwner; import net.sourceforge.fenixedu.domain.homepage.Homepage; import net.sourceforge.fenixedu.domain.inquiries.InquiryResponsePeriod; import net.sourceforge.fenixedu.domain.inquiries.teacher.InquiryResponsePeriodType; import net.sourceforge.fenixedu.domain.messaging.AnnouncementBoard; import net.sourceforge.fenixedu.domain.messaging.Forum; import net.sourceforge.fenixedu.domain.messaging.ForumSubscription; import net.sourceforge.fenixedu.domain.organizationalStructure.Accountability; import net.sourceforge.fenixedu.domain.organizationalStructure.AccountabilityType; import net.sourceforge.fenixedu.domain.organizationalStructure.AccountabilityTypeEnum; import net.sourceforge.fenixedu.domain.organizationalStructure.Contract; import net.sourceforge.fenixedu.domain.organizationalStructure.DepartmentUnit; import net.sourceforge.fenixedu.domain.organizationalStructure.EmployeeContract; import net.sourceforge.fenixedu.domain.organizationalStructure.ExternalContract; import net.sourceforge.fenixedu.domain.organizationalStructure.Function; import net.sourceforge.fenixedu.domain.organizationalStructure.FunctionType; import net.sourceforge.fenixedu.domain.organizationalStructure.Invitation; import net.sourceforge.fenixedu.domain.organizationalStructure.Party; import net.sourceforge.fenixedu.domain.organizationalStructure.PersonFunction; import net.sourceforge.fenixedu.domain.organizationalStructure.ResearchContract; import net.sourceforge.fenixedu.domain.organizationalStructure.ResearchUnit; import net.sourceforge.fenixedu.domain.organizationalStructure.Unit; import net.sourceforge.fenixedu.domain.person.Gender; import net.sourceforge.fenixedu.domain.person.IDDocumentType; import net.sourceforge.fenixedu.domain.person.IdDocument; import net.sourceforge.fenixedu.domain.person.IdDocumentTypeObject; import net.sourceforge.fenixedu.domain.person.MaritalStatus; import net.sourceforge.fenixedu.domain.person.PersonName; import net.sourceforge.fenixedu.domain.person.RoleType; import net.sourceforge.fenixedu.domain.phd.alert.PhdAlertMessage; import net.sourceforge.fenixedu.domain.projectsManagement.ProjectAccess; import net.sourceforge.fenixedu.domain.research.Researcher; import net.sourceforge.fenixedu.domain.research.result.ResearchResult; import net.sourceforge.fenixedu.domain.research.result.ResultParticipation; import net.sourceforge.fenixedu.domain.research.result.patent.ResearchResultPatent; import net.sourceforge.fenixedu.domain.research.result.publication.ResearchResultPublication; import net.sourceforge.fenixedu.domain.space.Campus; import net.sourceforge.fenixedu.domain.space.PersonSpaceOccupation; import net.sourceforge.fenixedu.domain.space.Space; import net.sourceforge.fenixedu.domain.student.Registration; import net.sourceforge.fenixedu.domain.student.Student; import net.sourceforge.fenixedu.domain.teacherServiceDistribution.TSDProcess; import net.sourceforge.fenixedu.domain.thesis.ThesisEvaluationParticipant; import net.sourceforge.fenixedu.domain.util.FactoryExecutor; import net.sourceforge.fenixedu.domain.vigilancy.ExamCoordinator; import net.sourceforge.fenixedu.domain.vigilancy.UnavailablePeriod; import net.sourceforge.fenixedu.domain.vigilancy.Vigilancy; import net.sourceforge.fenixedu.domain.vigilancy.VigilantGroup; import net.sourceforge.fenixedu.domain.vigilancy.VigilantWrapper; import net.sourceforge.fenixedu.injectionCode.AccessControl; import net.sourceforge.fenixedu.util.ByteArray; import net.sourceforge.fenixedu.util.ContentType; import net.sourceforge.fenixedu.util.Money; import net.sourceforge.fenixedu.util.PeriodState; import net.sourceforge.fenixedu.util.StringFormatter; import net.sourceforge.fenixedu.util.UsernameUtils; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.Predicate; import org.apache.commons.lang.StringUtils; import org.joda.time.DateTime; import org.joda.time.YearMonthDay; import pt.ist.fenixWebFramework.security.accessControl.Checked; import pt.ist.fenixWebFramework.services.Service; import pt.utl.ist.fenix.tools.smtp.EmailSender; import pt.utl.ist.fenix.tools.util.DateFormatUtil; 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 Person extends Person_Base { static { Role.PersonRole.addListener(new PersonRoleListener()); } /*************************************************************************** * BUSINESS SERVICES * **************************************************************************/ private IdDocument getIdDocument() { final Iterator documentIterator = getIdDocumentsSet().iterator(); return documentIterator.hasNext() ? documentIterator.next() : null; } @Override public void setPartyName(MultiLanguageString partyName) { throw new UnsupportedOperationException(); } @Override public String getName() { return super.getPartyName().getPreferedContent(); } @Override public void setName(String name) { if (name == null || StringUtils.isEmpty(name.trim())) { throw new DomainException("error.person.empty.name"); } String formattedName = StringFormatter.prettyPrint(name); MultiLanguageString partyName = super.getPartyName(); partyName = partyName == null ? new MultiLanguageString() : partyName; partyName.setContent(Language.getDefaultLanguage(), formattedName); super.setPartyName(partyName); PersonName personName = getPersonName(); personName = personName == null ? new PersonName(this) : personName; personName.setName(formattedName); } @Override public void setDocumentIdNumber(String documentIdNumber) { if (documentIdNumber == null || StringUtils.isEmpty(documentIdNumber.trim())) { throw new DomainException("error.person.empty.documentIdNumber"); } IdDocument idDocument = getIdDocument(); if (idDocument == null) { idDocument = new IdDocument(this, documentIdNumber, (IdDocumentTypeObject) null); } else { idDocument.setValue(documentIdNumber); } super.setDocumentIdNumber(documentIdNumber); } @Override public void setIdDocumentType(IDDocumentType idDocumentType) { if (idDocumentType == null) { throw new DomainException("error.person.empty.idDocumentType"); } IdDocument idDocument = getIdDocument(); if (idDocument == null) { idDocument = new IdDocument(this, null, idDocumentType); } else { idDocument.setIdDocumentType(idDocumentType); } super.setIdDocumentType(idDocumentType); } public void setIdentification(String documentIdNumber, IDDocumentType idDocumentType) { if (documentIdNumber != null && idDocumentType != null && checkIfDocumentNumberIdAndDocumentIdTypeExists(documentIdNumber, idDocumentType)) { throw new DomainException("error.person.existent.docIdAndType"); } setDocumentIdNumber(documentIdNumber); setIdDocumentType(idDocumentType); } private boolean checkIfDocumentNumberIdAndDocumentIdTypeExists(final String documentIDNumber, final IDDocumentType documentType) { Person person = readByDocumentIdNumberAndIdDocumentType(documentIDNumber, documentType); return person != null && !person.equals(this); } @Linkare(author = "Paulo Zenida", comments = "This method should be final since it is called inside the constructor (best practice)") public final String getValidatedName() { return StringFormatter.personNameValidator(getName(), Language.getLanguage()); } @Linkare(author = "Paulo Zenida", comments = "The constructor should not depend on overridable methods (best practice). So, make sure it invokes the super methods") public Person() { super(); super.setMaritalStatus(MaritalStatus.UNKNOWN); createLoginIdentificationAndUserIfNecessary(); setIsPassInKerberos(Boolean.FALSE); super.setAvailablePhoto(Boolean.FALSE); } /** * * @deprecated use Person(PersonBean personBean) * @see Person(PersonBean personBean) */ @Deprecated public Person(InfoPersonEditor personToCreate, Country country) { super(); if (personToCreate.getIdInternal() != null) { throw new DomainException("error.person.existentPerson"); } createLoginIdentificationAndUserIfNecessary(); setProperties(personToCreate); setCountry(country); setIsPassInKerberos(Boolean.FALSE); } public Person(final String name, final String identificationDocumentNumber, final IDDocumentType identificationDocumentType, final Gender gender) { this(); setName(name); setGender(gender); setMaritalStatus(MaritalStatus.SINGLE); setIdentification(identificationDocumentNumber, identificationDocumentType); } public Person(final PersonBean personBean) { super(); setProperties(personBean); if (personBean.createLoginIdentificationAndUserIfNecessary()) { createLoginIdentificationAndUserIfNecessary(); setIsPassInKerberos(Boolean.FALSE); } PhysicalAddress.createPhysicalAddress(this, personBean.getPhysicalAddressData(), PartyContactType.PERSONAL, true); Phone.createPhone(this, personBean.getPhone(), PartyContactType.PERSONAL, true); MobilePhone.createMobilePhone(this, personBean.getMobile(), PartyContactType.PERSONAL, true); EmailAddress.createEmailAddress(this, personBean.getEmail(), PartyContactType.PERSONAL, true); WebAddress.createWebAddress(this, personBean.getWebAddress(), PartyContactType.PERSONAL, true); } public Person(final IndividualCandidacyPersonalDetails candidacyPersonalDetails) { this(); this.setCountry(candidacyPersonalDetails.getCountry()); this.setDateOfBirthYearMonthDay(candidacyPersonalDetails.getDateOfBirthYearMonthDay()); this.setDocumentIdNumber(candidacyPersonalDetails.getDocumentIdNumber()); this.setExpirationDateOfDocumentIdYearMonthDay(candidacyPersonalDetails.getExpirationDateOfDocumentIdYearMonthDay()); this.setGender(candidacyPersonalDetails.getGender()); this.setIdDocumentType(candidacyPersonalDetails.getIdDocumentType()); this.setName(candidacyPersonalDetails.getName()); this.setSocialSecurityNumber(candidacyPersonalDetails.getSocialSecurityNumber()); PhysicalAddressData physicalAddressData = new PhysicalAddressData(candidacyPersonalDetails.getAddress(), candidacyPersonalDetails.getAreaCode(), "", candidacyPersonalDetails.getArea(), "", "", "", candidacyPersonalDetails.getCountryOfResidence()); PhysicalAddress.createPhysicalAddress(this, physicalAddressData, PartyContactType.PERSONAL, true); Phone.createPhone(this, candidacyPersonalDetails.getTelephoneContact(), PartyContactType.PERSONAL, true); EmailAddress.createEmailAddress(this, candidacyPersonalDetails.getEmail(), PartyContactType.PERSONAL, true); } private Person(final String name, final Gender gender, final PhysicalAddressData data, final String phone, final String mobile, final String homepage, final String email, final String documentIDNumber, final IDDocumentType documentType) { this(); setName(name); setGender(gender); setIdentification(documentIDNumber, documentType); PhysicalAddress.createPhysicalAddress(this, data, PartyContactType.PERSONAL, true); Phone.createPhone(this, phone, PartyContactType.PERSONAL, true); MobilePhone.createMobilePhone(this, mobile, PartyContactType.PERSONAL, true); EmailAddress.createEmailAddress(this, email, PartyContactType.PERSONAL, true); WebAddress.createWebAddress(this, homepage, PartyContactType.PERSONAL, true); } static public Person createExternalPerson(final String name, final Gender gender, final PhysicalAddressData data, final String phone, final String mobile, final String homepage, final String email, final String documentIdNumber, final IDDocumentType documentType) { return new Person(name, gender, data, phone, mobile, homepage, email, documentIdNumber, documentType); } public Person(final String name, final Gender gender, final String documentIDNumber, final IDDocumentType documentType) { this(); setName(name); setGender(gender); setIdentification(documentIDNumber, documentType); } public Person(PersonBean creator, boolean createExternalPerson) { this(creator); if (createExternalPerson) { getPersonRolesSet().clear(); final User user = getUser(); final Login login = (Login) user.getIdentificationsSet().iterator().next(); login.setEndDateDateTime(login.getBeginDateDateTime()); login.setActive(Boolean.FALSE); } } @Checked("RolePredicates.MANAGER_OR_ACADEMIC_ADMINISTRATIVE_OFFICE_OR_GRANT_OWNER_MANAGER_PREDICATE") public Person edit(PersonBean personBean) { setProperties(personBean); setDefaultPhysicalAddressData(personBean.getPhysicalAddressData()); setDefaultPhoneNumber(personBean.getPhone()); setDefaultMobilePhoneNumber(personBean.getMobile()); setDefaultWebAddressUrl(personBean.getWebAddress()); setDefaultEmailAddressValue(personBean.getEmail()); return this; } public Person editByPublicCandidate(PersonBean personBean) { setName(personBean.getName()); setGender(personBean.getGender()); setIdentification(personBean.getDocumentIdNumber(), personBean.getIdDocumentType()); setExpirationDateOfDocumentIdYearMonthDay(personBean.getDocumentIdExpirationDate()); setSocialSecurityNumber(personBean.getSocialSecurityNumber()); setDateOfBirthYearMonthDay(personBean.getDateOfBirth()); setCountry(personBean.getNationality()); setDefaultPhysicalAddressData(personBean.getPhysicalAddressData()); setDefaultPhoneNumber(personBean.getPhone()); setDefaultEmailAddressValue(personBean.getEmail()); return this; } @Checked("RolePredicates.MANAGER_OR_ACADEMIC_ADMINISTRATIVE_OFFICE_OR_GRANT_OWNER_MANAGER_PREDICATE") public Person edit(IndividualCandidacyPersonalDetails candidacyExternalDetails) { this.setCountry(candidacyExternalDetails.getCountry()); this.setDateOfBirthYearMonthDay(candidacyExternalDetails.getDateOfBirthYearMonthDay()); this.setIdentification(candidacyExternalDetails.getDocumentIdNumber(), candidacyExternalDetails.getIdDocumentType()); this.setExpirationDateOfDocumentIdYearMonthDay(candidacyExternalDetails.getExpirationDateOfDocumentIdYearMonthDay()); this.setGender(candidacyExternalDetails.getGender()); this.setName(candidacyExternalDetails.getName()); this.setSocialSecurityNumber(candidacyExternalDetails.getSocialSecurityNumber()); PhysicalAddressData physicalAddressData = new PhysicalAddressData(candidacyExternalDetails.getAddress(), candidacyExternalDetails.getAreaCode(), this.getDefaultPhysicalAddress().getAreaOfAreaCode(), candidacyExternalDetails.getArea(), this.getDefaultPhysicalAddress().getParishOfResidence(), this .getDefaultPhysicalAddress().getDistrictSubdivisionOfResidence(), this.getDefaultPhysicalAddress() .getDistrictOfResidence(), candidacyExternalDetails.getCountryOfResidence()); setDefaultPhysicalAddressData(physicalAddressData); setDefaultPhoneNumber(candidacyExternalDetails.getTelephoneContact()); setDefaultEmailAddressValue(candidacyExternalDetails.getEmail()); return this; } public void edit(PersonInformationFromUniqueCardDTO personDTO) throws ParseException { final String dateFormat = "dd MM yyyy"; if (!StringUtils.isEmpty(personDTO.getName())) { setName(personDTO.getName()); } if (!StringUtils.isEmpty(personDTO.getGender())) { setGender(personDTO.getGender().equalsIgnoreCase("m") ? Gender.MALE : Gender.FEMALE); } if (!StringUtils.isEmpty(personDTO.getDocumentIdEmissionLocation())) { setEmissionLocationOfDocumentId(personDTO.getDocumentIdEmissionLocation()); } if (!StringUtils.isEmpty(personDTO.getDocumentIdEmissionDate())) { setEmissionDateOfDocumentIdYearMonthDay(YearMonthDay.fromDateFields(DateFormatUtil.parse(dateFormat, personDTO .getDocumentIdEmissionDate()))); } if (!StringUtils.isEmpty(personDTO.getDocumentIdExpirationDate())) { setExpirationDateOfDocumentIdYearMonthDay(YearMonthDay.fromDateFields(DateFormatUtil.parse(dateFormat, personDTO .getDocumentIdExpirationDate()))); } if (!StringUtils.isEmpty(personDTO.getFiscalNumber())) { setSocialSecurityNumber(personDTO.getFiscalNumber()); } if (!StringUtils.isEmpty(personDTO.getBirthDate())) { setDateOfBirthYearMonthDay(YearMonthDay.fromDateFields(DateFormatUtil.parse(dateFormat, personDTO.getBirthDate()))); } if (!StringUtils.isEmpty(personDTO.getNationality())) { setNationality(Country.readByThreeLetterCode(personDTO.getNationality())); } if (!StringUtils.isEmpty(personDTO.getMotherName())) { setNameOfMother(personDTO.getMotherName()); } if (!StringUtils.isEmpty(personDTO.getFatherName())) { setNameOfFather(personDTO.getFatherName()); } if (personDTO.getPhoto() != null) { setPersonalPhoto(new Photograph(ContentType.JPG, new ByteArray(personDTO.getPhoto()), PhotoType.INSTITUTIONAL)); } final PhysicalAddressData physicalAddress = new PhysicalAddressData(); physicalAddress.setAddress(personDTO.getAddress()); physicalAddress.setAreaCode(personDTO.getPostalCode()); physicalAddress.setAreaOfAreaCode(personDTO.getPostalArea()); physicalAddress.setArea(personDTO.getLocality()); physicalAddress.setParishOfResidence(personDTO.getParish()); physicalAddress.setDistrictSubdivisionOfResidence(personDTO.getMunicipality()); physicalAddress.setDistrictOfResidence(personDTO.getDistrict()); physicalAddress.setCountryOfResidence(Country.readByTwoLetterCode(personDTO.getCountry())); if (!physicalAddress.isEmpty()) { setDefaultPhysicalAddressData(physicalAddress); } } public void edit(String name, String address, String phone, String mobile, String homepage, String email) { setName(name); setAddress(address); setDefaultPhoneNumber(phone); setDefaultMobilePhoneNumber(mobile); setDefaultEmailAddressValue(email); setDefaultWebAddressUrl(homepage); } public void editPersonalData(String documentIdNumber, IDDocumentType documentType, String personName, String socialSecurityNumber) { setName(personName); setIdentification(documentIdNumber, documentType); setSocialSecurityNumber(socialSecurityNumber); } public void editPersonWithExternalData(final PersonBean personBean) { editPersonWithExternalData(personBean, false); } public Person editPersonWithExternalData(final PersonBean personBean, final boolean updateExistingContacts) { setProperties(personBean); setDefaultPhysicalAddressData(personBean.getPhysicalAddressData()); if (updateExistingContacts) { setDefaultPhoneNumber(personBean.getPhone()); setDefaultMobilePhoneNumber(personBean.getMobile()); setDefaultWebAddressUrl(personBean.getWebAddress()); setDefaultEmailAddressValue(personBean.getEmail()); } else { Phone.createPhone(this, personBean.getPhone(), PartyContactType.PERSONAL, !hasDefaultPhone()); MobilePhone.createMobilePhone(this, personBean.getMobile(), PartyContactType.PERSONAL, !hasDefaultMobilePhone()); EmailAddress.createEmailAddress(this, personBean.getEmail(), PartyContactType.PERSONAL, !hasDefaultEmailAddress()); WebAddress.createWebAddress(this, personBean.getWebAddress(), PartyContactType.PERSONAL, !hasDefaultWebAddress()); } return this; } @Deprecated public void update(InfoPersonEditor updatedPersonalData, Country country) { updateProperties(updatedPersonalData); if (country != null) { setCountry(country); } } /** * * @deprecated use edit(PersonBean personBean) * @see edit(PersonBean personBean) */ @Deprecated public void edit(InfoPersonEditor personToEdit, Country country) { setProperties(personToEdit); if (country != null) { setCountry(country); } } @Linkare(author = "Paulo Zenida", comments = "Constructor depends on this method. It is a good practice to guarantee it cannot be changed") public final Login getLoginIdentification() { User personUser = getUser(); return (personUser == null) ? null : personUser.readUserLoginIdentification(); } public Set getLoginAliasOrderByImportance() { Login login = getLoginIdentification(); return (login != null) ? login.getLoginAliasOrderByImportance() : new HashSet(); } public Set getLoginAlias() { Login login = getLoginIdentification(); return (login != null) ? login.getAliasSet() : new HashSet(); } public boolean hasUsername(String username) { Login login = getLoginIdentification(); return (login != null) ? login.hasUsername(username) : false; } public String getUsername() { Login login = getLoginIdentification(); return (login != null) ? login.getUsername() : null; } public void setUsername(RoleType roleType) { Login login = createLoginIdentificationAndUserIfNecessary(); login.setUsername(roleType); } public String getPassword() { Login login = getLoginIdentification(); return (login != null) ? login.getPassword() : null; } public void setPassword(String password) { createLoginIdentificationAndUserIfNecessary().setPassword(password); } @Linkare(author = "Paulo Zenida", comments = "This method should be final since it is called inside the constructor (best practice)") public final void setIsPassInKerberos(Boolean isPassInKerberos) { createLoginIdentificationAndUserIfNecessary().setIsPassInKerberos(isPassInKerberos); } public Boolean getIsPassInKerberos() { Login login = getLoginIdentification(); return (login != null) ? login.getIsPassInKerberos() : null; } public void setIstUsername() { createLoginIdentificationAndUserIfNecessary().setUserUID(); } @Linkare(author = "Paulo Zenida", comments = "This method should be final since it is called inside the constructor (best practice)") public final Login createLoginIdentificationAndUserIfNecessary() { Login login = getLoginIdentification(); if (login == null) { User user = getUser(); if (user == null) { user = new User(this); } login = new Login(getUser()); } return login; } public String getIstUsername() { return (getUser() != null) ? getUser().getUserUId() : null; } public void changeUsername(RoleType roleType) { setUsername(roleType); } public void changePassword(String oldPassword, String newPassword) { if (newPassword == null) { throw new DomainException("error.person.invalidNullPassword"); } if (getUser() == null) { throw new DomainException("error.person.unExistingUser"); } if (newPassword.equals("")) { throw new DomainException("error.person.invalidEmptyPassword"); } setPassword(PasswordEncryptor.encryptPassword(newPassword)); } public void addAlias(Role role) { setUsername(role.getRoleType()); } public void removeAlias(Role removedRole) { Login loginIdentification = getLoginIdentification(); if (loginIdentification != null) { loginIdentification.removeAlias(removedRole.getRoleType()); } } public void updateIstUsername() { setIstUsername(); } public Role getPersonRole(RoleType roleType) { for (Role role : this.getPersonRoles()) { if (role.getRoleType().equals(roleType)) { return role; } } return null; } @Override public void addPersonRoles(Role personRoles) { if (!hasPersonRoles(personRoles)) { super.addPersonRoles(personRoles); } } public void addPersonRoleByRoleType(RoleType roleType) { this.addPersonRoles(Role.getRoleByRoleType(roleType)); } public Boolean hasRole(final RoleType roleType) { for (final Role role : this.getPersonRoles()) { if (role.getRoleType() == roleType) { return true; } } return false; } public Registration getStudentByType(DegreeType degreeType) { for (Registration registration : this.getStudents()) { if (registration.getDegreeType().equals(degreeType)) { return registration; } } return null; } // FIXME: Remove as soon as possible. @Deprecated public Registration getStudentByUsername() { Login loginIdentification = getLoginIdentification(); if (loginIdentification != null) { List loginAlias = loginIdentification.getRoleLoginAlias(RoleType.STUDENT); for (final Registration registration : this.getStudents()) { for (LoginAlias alias : loginAlias) { if (alias.getAlias().contains(registration.getNumber().toString())) { return registration; } } } } return null; } @Override public List getResearchResultPublications() { List resultPublications = new ArrayList(); ResearchResult result = null; for (ResultParticipation resultParticipation : this.getResultParticipations()) { result = resultParticipation.getResult(); // filter only publication participations if (result instanceof ResearchResultPublication) { resultPublications.add((ResearchResultPublication) result); } } return resultPublications; } public List getResearchResultPatents() { List resultPatents = new ArrayList(); ResearchResult result = null; for (ResultParticipation resultParticipation : this.getResultParticipations()) { result = resultParticipation.getResult(); // filter only patent participations if (result instanceof ResearchResultPatent) { resultPatents.add((ResearchResultPatent) result); } } return resultPatents; } public List getResearchResultPatentsByExecutionYear(ExecutionYear executionYear) { List resultPatents = new ArrayList(); for (ResearchResultPatent patent : getResearchResultPatents()) { if (executionYear.belongsToCivilYear(patent.getApprovalYear())) { resultPatents.add(patent); } } return resultPatents; } public Boolean getIsExamCoordinatorInCurrentYear() { ExamCoordinator examCoordinator = this.getExamCoordinatorForGivenExecutionYear(ExecutionYear.readCurrentExecutionYear()); return (examCoordinator == null) ? false : true; } public List getVisibleVigilantGroups(ExecutionYear executionYear) { Set groups = new HashSet(); Employee employee = this.getEmployee(); if (employee != null) { Department department = employee.getLastDepartmentWorkingPlace(executionYear.getBeginDateYearMonthDay(), executionYear.getEndDateYearMonthDay()); groups.addAll(department.getVigilantGroupsForGivenExecutionYear(executionYear)); } else { for (VigilantWrapper vigilantWrapper : this.getVigilantWrapperForExecutionYear(executionYear)) { groups.add(vigilantWrapper.getVigilantGroup()); } } return new ArrayList(groups); } public List getVigilantWrapperForExecutionYear(ExecutionYear executionYear) { List wrappers = new ArrayList(); for (VigilantWrapper wrapper : getVigilantWrappers()) { if (wrapper.getExecutionYear() == executionYear) { wrappers.add(wrapper); } } return wrappers; } public List getVigilantGroupsForExecutionYear(ExecutionYear executionYear) { List groups = new ArrayList(); for (VigilantWrapper wrapper : getVigilantWrappers()) { VigilantGroup group = wrapper.getVigilantGroup(); if (group.getExecutionYear().equals(executionYear)) { groups.add(group); } } return groups; } public boolean isAllowedToSpecifyUnavailablePeriod() { DateTime currentDate = new DateTime(); List groupsForYear = getVigilantGroupsForExecutionYear(ExecutionYear.readCurrentExecutionYear()); for (VigilantGroup group : groupsForYear) { if (group.canSpecifyUnavailablePeriodIn(currentDate)) { return true; } } return false; } public List getVigilanciesForYear(ExecutionYear executionYear) { List vigilancies = new ArrayList(); for (VigilantWrapper vigilantWrapper : this.getVigilantWrappers()) { if (vigilantWrapper.getExecutionYear().equals(executionYear)) { vigilancies.addAll(vigilantWrapper.getVigilancies()); } } return vigilancies; } public ExamCoordinator getExamCoordinatorForGivenExecutionYear(ExecutionYear executionYear) { List examCoordinators = this.getExamCoordinators(); for (ExamCoordinator examCoordinator : examCoordinators) { if (examCoordinator.getExecutionYear().equals(executionYear)) { return examCoordinator; } } return null; } public Boolean isExamCoordinatorForVigilantGroup(VigilantGroup group) { ExamCoordinator coordinator = getExamCoordinatorForGivenExecutionYear(group.getExecutionYear()); return (coordinator == null) ? Boolean.FALSE : group.getExamCoordinators().contains(coordinator); } public ExamCoordinator getCurrentExamCoordinator() { return getExamCoordinatorForGivenExecutionYear(ExecutionYear.readCurrentExecutionYear()); } public double getVigilancyPointsForGivenYear(ExecutionYear executionYear) { List vigilants = this.getVigilantWrapperForExecutionYear(executionYear); if (vigilants.isEmpty()) return 0; else { double points = 0; for (VigilantWrapper vigilant : vigilants) { points += vigilant.getPoints(); } return points; } } public double getTotalVigilancyPoints() { List vigilants = this.getVigilantWrappers(); double points = 0; for (VigilantWrapper vigilant : vigilants) { points += vigilant.getPoints(); } return points; } /*************************************************************************** * PRIVATE METHODS * **************************************************************************/ private void setProperties(InfoPersonEditor infoPerson) { setName(infoPerson.getNome()); setIdentification(infoPerson.getNumeroDocumentoIdentificacao(), infoPerson.getTipoDocumentoIdentificacao()); setFiscalCode(infoPerson.getCodigoFiscal()); setDefaultPhysicalAddressData(infoPerson.getPhysicalAddressData()); setDefaultWebAddressUrl(infoPerson.getEnderecoWeb()); setDefaultPhoneNumber(infoPerson.getTelefone()); setDefaultMobilePhoneNumber(infoPerson.getTelemovel()); setDefaultEmailAddressValue(infoPerson.getEmail()); setWorkPhoneNumber(infoPerson.getWorkPhone()); setDistrictSubdivisionOfBirth(infoPerson.getConcelhoNaturalidade()); if (infoPerson.getDataEmissaoDocumentoIdentificacao() != null) { setEmissionDateOfDocumentIdYearMonthDay(YearMonthDay .fromDateFields(infoPerson.getDataEmissaoDocumentoIdentificacao())); } if (infoPerson.getDataValidadeDocumentoIdentificacao() != null) { setExpirationDateOfDocumentIdYearMonthDay(YearMonthDay.fromDateFields(infoPerson .getDataValidadeDocumentoIdentificacao())); } setDistrictOfBirth(infoPerson.getDistritoNaturalidade()); setMaritalStatus((infoPerson.getMaritalStatus() == null) ? MaritalStatus.UNKNOWN : infoPerson.getMaritalStatus()); setParishOfBirth(infoPerson.getFreguesiaNaturalidade()); setEmissionLocationOfDocumentId(infoPerson.getLocalEmissaoDocumentoIdentificacao()); if (infoPerson.getNascimento() != null) { setDateOfBirthYearMonthDay(YearMonthDay.fromDateFields(infoPerson.getNascimento())); } setNameOfMother(infoPerson.getNomeMae()); setNameOfFather(infoPerson.getNomePai()); setSocialSecurityNumber(infoPerson.getNumContribuinte()); setProfession(infoPerson.getProfissao()); setGender(infoPerson.getSexo()); setAvailableEmail(infoPerson.getAvailableEmail() != null ? infoPerson.getAvailableEmail() : Boolean.TRUE); setAvailableWebSite(infoPerson.getAvailableWebSite() != null ? infoPerson.getAvailableWebSite() : Boolean.TRUE); setAvailablePhoto(Boolean.TRUE); } private void updateProperties(InfoPersonEditor infoPerson) { setName(valueToUpdateIfNewNotNull(getName(), infoPerson.getNome())); setIdentification(valueToUpdateIfNewNotNull(getDocumentIdNumber(), infoPerson.getNumeroDocumentoIdentificacao()), (IDDocumentType) valueToUpdateIfNewNotNull(getIdDocumentType(), infoPerson.getTipoDocumentoIdentificacao())); setFiscalCode(valueToUpdateIfNewNotNull(getFiscalCode(), infoPerson.getCodigoFiscal())); setEmissionDateOfDocumentIdYearMonthDay(infoPerson.getDataEmissaoDocumentoIdentificacao() != null ? YearMonthDay .fromDateFields(infoPerson.getDataEmissaoDocumentoIdentificacao()) : getEmissionDateOfDocumentIdYearMonthDay()); setEmissionLocationOfDocumentId(valueToUpdateIfNewNotNull(getEmissionLocationOfDocumentId(), infoPerson .getLocalEmissaoDocumentoIdentificacao())); setExpirationDateOfDocumentIdYearMonthDay(infoPerson.getDataValidadeDocumentoIdentificacao() != null ? YearMonthDay .fromDateFields(infoPerson.getDataValidadeDocumentoIdentificacao()) : getExpirationDateOfDocumentIdYearMonthDay()); MaritalStatus maritalStatus = (MaritalStatus) valueToUpdateIfNewNotNull(getMaritalStatus(), infoPerson.getMaritalStatus()); setMaritalStatus((maritalStatus == null) ? MaritalStatus.UNKNOWN : maritalStatus); setDateOfBirthYearMonthDay(infoPerson.getNascimento() != null ? YearMonthDay.fromDateFields(infoPerson.getNascimento()) : getDateOfBirthYearMonthDay()); setParishOfBirth(valueToUpdateIfNewNotNull(getParishOfBirth(), infoPerson.getFreguesiaNaturalidade())); setDistrictSubdivisionOfBirth(valueToUpdateIfNewNotNull(getDistrictSubdivisionOfBirth(), infoPerson .getConcelhoNaturalidade())); setDistrictOfBirth(valueToUpdateIfNewNotNull(getDistrictOfBirth(), infoPerson.getDistritoNaturalidade())); setNameOfMother(valueToUpdateIfNewNotNull(getNameOfMother(), infoPerson.getNomeMae())); setNameOfFather(valueToUpdateIfNewNotNull(getNameOfFather(), infoPerson.getNomePai())); setSocialSecurityNumber(valueToUpdateIfNewNotNull(getSocialSecurityNumber(), infoPerson.getNumContribuinte())); setProfession(valueToUpdateIfNewNotNull(getProfession(), infoPerson.getProfissao())); setGender((Gender) valueToUpdateIfNewNotNull(getGender(), infoPerson.getSexo())); PhysicalAddressData data = new PhysicalAddressData(); data.setAddress(valueToUpdateIfNewNotNull(getAddress(), infoPerson.getMorada())); data.setAreaCode(valueToUpdateIfNewNotNull(getAreaCode(), infoPerson.getCodigoPostal())); data.setAreaOfAreaCode(valueToUpdateIfNewNotNull(getAreaOfAreaCode(), infoPerson.getLocalidadeCodigoPostal())); data.setArea(valueToUpdateIfNewNotNull(getArea(), infoPerson.getLocalidade())); data.setParishOfResidence(valueToUpdateIfNewNotNull(getParishOfResidence(), infoPerson.getFreguesiaMorada())); data.setDistrictSubdivisionOfResidence(valueToUpdateIfNewNotNull(getDistrictSubdivisionOfResidence(), infoPerson .getConcelhoMorada())); data.setDistrictOfResidence(valueToUpdateIfNewNotNull(getDistrictOfResidence(), infoPerson.getDistritoMorada())); data.setCountryOfResidence(getCountryOfResidence()); setDefaultPhysicalAddressData(data); if (!hasAnyPartyContact(Phone.class)) { Phone.createPhone(this, infoPerson.getTelefone(), PartyContactType.PERSONAL, true); Phone.createPhone(this, infoPerson.getWorkPhone(), PartyContactType.WORK, true); } if (!hasAnyPartyContact(MobilePhone.class)) { MobilePhone.createMobilePhone(this, infoPerson.getTelemovel(), PartyContactType.PERSONAL, false); } if (!hasAnyPartyContact(EmailAddress.class) && EmailSender.emailAddressFormatIsValid(infoPerson.getEmail())) { EmailAddress.createEmailAddress(this, infoPerson.getEmail(), PartyContactType.PERSONAL, false); } if (!hasAnyPartyContact(WebAddress.class) && !StringUtils.isEmpty(infoPerson.getEnderecoWeb())) { WebAddress.createWebAddress(this, infoPerson.getEnderecoWeb(), PartyContactType.PERSONAL, false); } } private String valueToUpdateIfNewNotNull(String actualValue, String newValue) { if (newValue == null || newValue.length() == 0) { return actualValue; } return newValue; } private Object valueToUpdateIfNewNotNull(Object actualValue, Object newValue) { if (newValue == null) { return actualValue; } return newValue; } @Linkare(author = "Paulo Zenida", comments = "Added the residence logic code") private void setProperties(final PersonBean personBean) { setName(personBean.getName()); setGender(personBean.getGender()); setIdentification(personBean.getDocumentIdNumber(), personBean.getIdDocumentType()); setEmissionLocationOfDocumentId(personBean.getDocumentIdEmissionLocation()); setEmissionDateOfDocumentIdYearMonthDay(personBean.getDocumentIdEmissionDate()); setExpirationDateOfDocumentIdYearMonthDay(personBean.getDocumentIdExpirationDate()); setSocialSecurityNumber(personBean.getSocialSecurityNumber()); setProfession(personBean.getProfession()); setMaritalStatus(personBean.getMaritalStatus()); setDateOfBirthYearMonthDay(personBean.getDateOfBirth()); setCountry(personBean.getNationality()); setParishOfBirth(personBean.getParishOfBirth()); setDistrictSubdivisionOfBirth(personBean.getDistrictSubdivisionOfBirth()); setDistrictOfBirth(personBean.getDistrictOfBirth()); setCountryOfBirth(personBean.getCountryOfBirth()); setNameOfMother(personBean.getMotherName()); setNameOfFather(personBean.getFatherName()); setAvailableEmail(personBean.isEmailAvailable()); setAvailablePhoto(personBean.isPhotoAvailable()); setAvailableWebSite(personBean.isHomepageAvailable()); setResidenceBean(personBean.getResidence()); } /*************************************************************************** * OTHER METHODS * **************************************************************************/ public String getSlideName() { return "/photos/person/P" + getIdInternal(); } public String getSlideNameForCandidateDocuments() { return "/candidateDocuments/person/P" + getIdInternal(); } public void removeRoleByType(final RoleType roleType) { final Role role = getPersonRole(roleType); if (role != null) { removePersonRoles(role); } } public void indicatePrivledges(final Set roles) { getPersonRoles().retainAll(roles); getPersonRoles().addAll(roles); } public List getActivePersonFunctions() { return getPersonFunctions(null, false, true, false); } public List getInactivePersonFunctions() { return getPersonFunctions(null, false, false, false); } public List getActiveInherentPersonFunctions() { List inherentFunctions = new ArrayList(); for (PersonFunction accountability : getActivePersonFunctions()) { inherentFunctions.addAll(accountability.getFunction().getInherentFunctions()); } return inherentFunctions; } /** * The main difference between this method and * {@link #getActivePersonFunctions()} is that person functions with a * virtual function are also included. This method also collects person * functions from the given unit and all subunits. * * @see Function#isVirtual() */ public List getAllActivePersonFunctions(Unit unit) { return getPersonFunctions(unit, true, true, null); } public boolean containsActivePersonFunction(Function function) { for (PersonFunction personFunction : getActivePersonFunctions()) { if (personFunction.getFunction().equals(function)) { return true; } } return false; } public boolean hasAnyPersonFunctions() { return !getPersonFunctions().isEmpty(); } public Collection getAllActivePersonFunctions(FunctionType functionType) { Set personFunctions = new HashSet(); for (PersonFunction personFunction : getActivePersonFunctions()) { if (personFunction.getFunction().isOfFunctionType(functionType)) { personFunctions.add(personFunction); } } return personFunctions; } public Collection getPersonFunctions() { return (Collection) getParentAccountabilities(AccountabilityTypeEnum.MANAGEMENT_FUNCTION, PersonFunction.class); } public Collection getPersonFunctions(Function function) { Collection personFunctions = getPersonFunctions(); Iterator iterator = personFunctions.iterator(); while (iterator.hasNext()) { PersonFunction element = iterator.next(); if (element.getFunction() == function) { continue; } iterator.remove(); } return personFunctions; } public List getPersonFuntions(YearMonthDay begin, YearMonthDay end) { return getPersonFuntions(AccountabilityTypeEnum.MANAGEMENT_FUNCTION, begin, end); } public List getPersonFunctions(Unit unit, boolean includeSubUnits, Boolean active, Boolean virtual) { return getPersonFunctions(unit, includeSubUnits, active, virtual, AccountabilityTypeEnum.MANAGEMENT_FUNCTION); } public boolean hasActivePersonFunction(FunctionType functionType, Unit unit) { YearMonthDay currentDate = new YearMonthDay(); for (PersonFunction personFunction : (Collection) getParentAccountabilities( AccountabilityTypeEnum.MANAGEMENT_FUNCTION, PersonFunction.class)) { if (personFunction.getUnit().equals(unit) && personFunction.getFunction().getFunctionType() == functionType && personFunction.isActive(currentDate)) { return true; } } return false; } public Collection getPersonFunctions(AccountabilityTypeEnum accountabilityTypeEnum) { return (Collection) getParentAccountabilities(accountabilityTypeEnum, PersonFunction.class); } public List getPersonFuntions(AccountabilityTypeEnum accountabilityTypeEnum, YearMonthDay begin, YearMonthDay end) { List result = new ArrayList(); for (Accountability accountability : (Collection) getParentAccountabilities(accountabilityTypeEnum, PersonFunction.class)) { if (accountability.belongsToPeriod(begin, end)) { result.add((PersonFunction) accountability); } } return result; } public List getPersonFunctions(Unit unit) { return getPersonFunctions(unit, false, null, null); } /** * Filters all parent PersonFunction accountabilities and returns all the * PersonFunctions that selection indicated in the parameters. * * @param unit * filter all PersonFunctions to this unit, or null * for all PersonFunctions * @param includeSubUnits * if even subunits of the given unit are considered * @param active * the state of the function, null for all * PersonFunctions */ public List getPersonFunctions(Unit unit, boolean includeSubUnits, Boolean active, Boolean virtual, AccountabilityTypeEnum accountabilityTypeEnum) { List result = new ArrayList(); Collection allSubUnits = Collections.emptyList(); if (includeSubUnits) { allSubUnits = unit.getAllSubUnits(); } YearMonthDay today = new YearMonthDay(); for (PersonFunction personFunction : getPersonFunctions(accountabilityTypeEnum)) { if (active != null && (personFunction.isActive(today) == !active)) { continue; } if (virtual != null && (personFunction.getFunction().isVirtual() == !virtual)) { continue; } Unit functionUnit = personFunction.getUnit(); if (unit == null || functionUnit.equals(unit) || (includeSubUnits && allSubUnits.contains(functionUnit))) { result.add(personFunction); } } return result; } public List getPersonFunctions(Party party, boolean includeSubUnits, Boolean active, Boolean virtual, AccountabilityTypeEnum accountabilityTypeEnum) { if (party.isUnit()) { return getPersonFunctions((Unit) party, includeSubUnits, active, virtual, AccountabilityTypeEnum.MANAGEMENT_FUNCTION); } List result = new ArrayList(); YearMonthDay today = new YearMonthDay(); for (PersonFunction personFunction : getPersonFunctions(accountabilityTypeEnum)) { if (active != null && (personFunction.isActive(today) == !active)) { continue; } if (virtual != null && (personFunction.getFunction().isVirtual() == !virtual)) { continue; } if (personFunction.getParentParty().isPerson()) { Person functionPerson = (Person) personFunction.getParentParty(); if (party == null || functionPerson.equals(party)) { result.add(personFunction); } } } return result; } public boolean hasFunctionType(FunctionType functionType, AccountabilityTypeEnum accountabilityTypeEnum) { for (PersonFunction accountability : getPersonFunctions(null, false, true, false, accountabilityTypeEnum)) { if (accountability.getFunction().getFunctionType() == functionType) { return true; } } return false; } public PersonFunction addPersonFunction(Function function, YearMonthDay begin, YearMonthDay end, Double credits) { return new PersonFunction(function.getUnit(), this, function, begin, end, credits); } /** * @return a group that only contains this person */ public PersonGroup getPersonGroup() { return new PersonGroup(this); } /** * * IMPORTANT: This method is evil and should NOT be used! You are NOT God! * * * @return true if the person have been deleted, false otherwise */ @Override public void delete() { if (!canBeDeleted()) { throw new DomainException("error.person.cannot.be.deleted"); } if (getPersonalPhotoEvenIfRejected() != null) { getPersonalPhotoEvenIfRejected().delete(); } if (hasParkingParty()) { getParkingParty().delete(); } if (hasAssociatedPersonAccount()) { getAssociatedPersonAccount().delete(); } if (hasHomepage()) { getHomepage().delete(); } getPersonRoles().clear(); if (hasUser()) { getUser().delete(); } if (hasStudent()) { getStudent().delete(); } if (hasPersonName()) { getPersonName().delete(); } getManageableDepartmentCredits().clear(); getBookmarkedBoards().clear(); getPersonRoles().clear(); getManageableDepartmentCredits().clear(); getThesisEvaluationParticipants().clear(); for (; !getIdDocumentsSet().isEmpty(); getIdDocumentsSet().iterator().next().delete()) ; for (; !getScientificCommissions().isEmpty(); getScientificCommissions().iterator().next().delete()) ; removeNationality(); removeCountryOfBirth(); super.delete(); } private boolean canBeDeleted() { return !hasAnyChilds() && !hasAnyParents() && !hasAnyDomainObjectActionLogs() && !hasAnyExportGroupingReceivers() && !hasAnyPersistentGroups() && !hasAnyPersonSpaceOccupations() && !hasAnyPunctualRoomsOccupationComments() && !hasAnyVehicleAllocations() && !hasAnyPunctualRoomsOccupationRequests() && !hasAnyPunctualRoomsOccupationRequestsToProcess() && !hasAnyAssociatedQualifications() && !hasAnyAssociatedAlteredCurriculums() && !hasAnyEnrolmentEvaluations() && !hasAnyExportGroupingSenders() && !hasAnyResponsabilityTransactions() && !hasAnyMasterDegreeCandidates() && !hasAnyGuides() && !hasAnyProjectAccesses() && !hasEmployee() && !hasTeacher() && !hasGrantOwner() && !hasAnyPayedGuides() && !hasAnyPayedReceipts() && !hasParking() && !hasAnyResearchInterests() && !hasAnyProjectParticipations() && !hasAnyParticipations() && !hasAnyBoards() && !hasAnyPersonFunctions() && (!hasHomepage() || getHomepage().isDeletable()) && !hasLibraryCard() && !hasAnyAcademicServiceRequests() && !hasAnyCardGenerationEntries() && !hasAnyInternalGuidings() && !hasAnyCreatedQualifications() && !hasAnyCreateJobs(); } private boolean hasParking() { if (hasParkingParty()) { return getParkingParty().hasAnyVehicles(); } return false; } public ExternalContract getExternalContract() { Collection externalContracts = (Collection) getParentAccountabilities( AccountabilityTypeEnum.WORKING_CONTRACT, ExternalContract.class); Iterator iter = externalContracts.iterator(); return iter.hasNext() ? externalContracts.iterator().next() : null; } public boolean hasExternalContract() { return getExternalContract() != null; } public ResearchContract getExternalResearchContract() { Collection externalContracts = (Collection) getParentAccountabilities( AccountabilityTypeEnum.RESEARCH_CONTRACT, ResearchContract.class); Iterator iter = externalContracts.iterator(); if (iter.hasNext()) { ResearchContract contract = externalContracts.iterator().next(); if (Boolean.TRUE.equals(contract.getExternalContract())) { return contract; } } return null; } public boolean hasExternalResearchContract() { return getExternalResearchContract() != null; } private static class PersonRoleListener extends dml.runtime.RelationAdapter { @Override public void beforeAdd(Role newRole, Person person) { // Do nothing!! } @Override public void afterAdd(Role insertedRole, Person person) { if (person != null && insertedRole != null) { addDependencies(insertedRole, person); person.addAlias(insertedRole); person.updateIstUsername(); } } @Override public void beforeRemove(Role roleToBeRemoved, Person person) { if (person != null && roleToBeRemoved != null && person.hasRole(roleToBeRemoved.getRoleType())) { removeDependencies(person, roleToBeRemoved); } } @Override public void afterRemove(Role removedRole, Person person) { if (person != null && removedRole != null) { person.removeAlias(removedRole); person.updateIstUsername(); } } private void addDependencies(Role role, Person person) { switch (role.getRoleType()) { case PERSON: addRoleIfNotPresent(person, RoleType.MESSAGING); break; case TEACHER: addRoleIfNotPresent(person, RoleType.PERSON); addRoleIfNotPresent(person, RoleType.EMPLOYEE); addRoleIfNotPresent(person, RoleType.RESEARCHER); addRoleIfNotPresent(person, RoleType.DEPARTMENT_MEMBER); break; case DELEGATE: case OPERATOR: case GEP: case MANAGER: case WEBSITE_MANAGER: case RESOURCE_ALLOCATION_MANAGER: case RESOURCE_MANAGER: case EMPLOYEE: case STUDENT: case ALUMNI: case GRANT_OWNER: case SPACE_MANAGER_SUPER_USER: case SPACE_MANAGER: addRoleIfNotPresent(person, RoleType.PERSON); break; case DIRECTIVE_COUNCIL: case SEMINARIES_COORDINATOR: case COORDINATOR: case DEGREE_ADMINISTRATIVE_OFFICE: case DEGREE_ADMINISTRATIVE_OFFICE_SUPER_USER: case MASTER_DEGREE_ADMINISTRATIVE_OFFICE: case DEPARTMENT_CREDITS_MANAGER: case GRANT_OWNER_MANAGER: case TREASURY: case CREDITS_MANAGER: case EXAM_COORDINATOR: case DEPARTMENT_ADMINISTRATIVE_OFFICE: case PERSONNEL_SECTION: case PROJECTS_MANAGER: case IT_PROJECTS_MANAGER: case INSTITUCIONAL_PROJECTS_MANAGER: addRoleIfNotPresent(person, RoleType.EMPLOYEE); break; case RESEARCHER: addRoleIfNotPresent(person, RoleType.PERSON); new Researcher(person); break; default: break; } } private static void removeDependencies(Person person, Role removedRole) { switch (removedRole.getRoleType()) { case PERSON: removeRoleIfPresent(person, RoleType.TEACHER); removeRoleIfPresent(person, RoleType.EMPLOYEE); removeRoleIfPresent(person, RoleType.STUDENT); removeRoleIfPresent(person, RoleType.GEP); removeRoleIfPresent(person, RoleType.GRANT_OWNER); removeRoleIfPresent(person, RoleType.MANAGER); removeRoleIfPresent(person, RoleType.OPERATOR); removeRoleIfPresent(person, RoleType.RESOURCE_ALLOCATION_MANAGER); removeRoleIfPresent(person, RoleType.WEBSITE_MANAGER); removeRoleIfPresent(person, RoleType.MESSAGING); removeRoleIfPresent(person, RoleType.ALUMNI); removeRoleIfPresent(person, RoleType.SPACE_MANAGER); removeRoleIfPresent(person, RoleType.SPACE_MANAGER_SUPER_USER); break; case TEACHER: removeRoleIfPresent(person, RoleType.EMPLOYEE); removeRoleIfPresent(person, RoleType.RESEARCHER); removeRoleIfPresent(person, RoleType.DEPARTMENT_MEMBER); removeRoleIfPresent(person, RoleType.DELEGATE); break; case EMPLOYEE: removeRoleIfPresent(person, RoleType.SEMINARIES_COORDINATOR); removeRoleIfPresent(person, RoleType.RESEARCHER); removeRoleIfPresent(person, RoleType.GRANT_OWNER_MANAGER); removeRoleIfPresent(person, RoleType.SEMINARIES_COORDINATOR); removeRoleIfPresent(person, RoleType.DIRECTIVE_COUNCIL); removeRoleIfPresent(person, RoleType.COORDINATOR); removeRoleIfPresent(person, RoleType.CREDITS_MANAGER); removeRoleIfPresent(person, RoleType.TREASURY); removeRoleIfPresent(person, RoleType.DEGREE_ADMINISTRATIVE_OFFICE); removeRoleIfPresent(person, RoleType.DEGREE_ADMINISTRATIVE_OFFICE_SUPER_USER); removeRoleIfPresent(person, RoleType.MASTER_DEGREE_ADMINISTRATIVE_OFFICE); removeRoleIfPresent(person, RoleType.DEPARTMENT_CREDITS_MANAGER); removeRoleIfPresent(person, RoleType.DEPARTMENT_ADMINISTRATIVE_OFFICE); removeRoleIfPresent(person, RoleType.PERSONNEL_SECTION); // removeRoleIfPresent(person, RoleType.PROJECTS_MANAGER); // removeRoleIfPresent(person, // RoleType.INSTITUCIONAL_PROJECTS_MANAGER); break; case STUDENT: removeRoleIfPresent(person, RoleType.DELEGATE); break; default: break; } } private static void removeRoleIfPresent(Person person, RoleType roleType) { if (person.hasRole(roleType)) { person.removeRoleByType(roleType); } } private static void addRoleIfNotPresent(Person person, RoleType roleType) { if (!person.hasRole(roleType)) { person.addPersonRoleByRoleType(roleType); } } } @Deprecated public Registration readStudentByDegreeType(DegreeType degreeType) { for (final Registration registration : this.getStudents()) { if (registration.getDegreeType().equals(degreeType)) { return registration; } } return null; } public Registration readRegistrationByDegreeCurricularPlan(DegreeCurricularPlan degreeCurricularPlan) { return getStudent().readRegistrationByDegreeCurricularPlan(degreeCurricularPlan); } public MasterDegreeCandidate getMasterDegreeCandidateByExecutionDegree(final ExecutionDegree executionDegree) { for (final MasterDegreeCandidate masterDegreeCandidate : this.getMasterDegreeCandidatesSet()) { if (masterDegreeCandidate.getExecutionDegree() == executionDegree) { return masterDegreeCandidate; } } return null; } public DFACandidacy getDFACandidacyByExecutionDegree(final ExecutionDegree executionDegree) { for (final Candidacy candidacy : this.getCandidaciesSet()) { if (candidacy instanceof DFACandidacy) { final DFACandidacy dfaCandidacy = (DFACandidacy) candidacy; if (dfaCandidacy.getExecutionDegree().equals(executionDegree)) { return dfaCandidacy; } } } return null; } public DegreeCandidacy getDegreeCandidacyByExecutionDegree(final ExecutionDegree executionDegree) { for (final Candidacy candidacy : this.getCandidaciesSet()) { if (candidacy instanceof DegreeCandidacy && candidacy.isActive()) { final DegreeCandidacy degreeCandidacy = (DegreeCandidacy) candidacy; if (degreeCandidacy.getExecutionDegree().equals(executionDegree)) { return degreeCandidacy; } } } return null; } public List getDegreeCandidaciesFor(final ExecutionYear executionYear, final CandidacySituationType candidacySituationType) { final List result = new ArrayList(); for (final Candidacy candidacy : this.getCandidaciesSet()) { if (candidacy instanceof DegreeCandidacy) { final DegreeCandidacy degreeCandidacy = (DegreeCandidacy) candidacy; if (degreeCandidacy.getActiveCandidacySituation().getCandidacySituationType() == candidacySituationType && degreeCandidacy.getExecutionDegree().getExecutionYear() == executionYear) { result.add((DegreeCandidacy) candidacy); } } } return result; } public boolean hasDegreeCandidacyForExecutionDegree(ExecutionDegree executionDegree) { return (getDegreeCandidacyByExecutionDegree(executionDegree) != null); } public StudentCandidacy getStudentCandidacyForExecutionDegree(ExecutionDegree executionDegree) { for (final Candidacy candidacy : this.getCandidaciesSet()) { if (candidacy instanceof StudentCandidacy && candidacy.isActive()) { final StudentCandidacy studentCandidacy = (StudentCandidacy) candidacy; if (studentCandidacy.getExecutionDegree().equals(executionDegree)) { return studentCandidacy; } } } return null; } public boolean hasStudentCandidacyForExecutionDegree(ExecutionDegree executionDegree) { return (getStudentCandidacyForExecutionDegree(executionDegree) != null); } public Collection getInvitationsOrderByDate() { Set invitations = new TreeSet(Invitation.CONTRACT_COMPARATOR_BY_BEGIN_DATE); invitations .addAll((Collection) getParentAccountabilities(AccountabilityTypeEnum.INVITATION, Invitation.class)); return invitations; } public List getActiveInvitations() { YearMonthDay today = new YearMonthDay(); List invitations = new ArrayList(); for (Accountability accoutAccountability : getParentAccountabilities(AccountabilityTypeEnum.INVITATION, Invitation.class)) { if (((Invitation) accoutAccountability).isActive(today)) { invitations.add((Invitation) accoutAccountability); } } return invitations; } public boolean isInvited(YearMonthDay date) { for (Invitation invitation : (Collection) getParentAccountabilities(AccountabilityTypeEnum.INVITATION, Invitation.class)) { if (invitation.isActive(date)) { return true; } } return false; } public boolean hasAnyInvitation() { return !getParentAccountabilities(AccountabilityTypeEnum.INVITATION, Invitation.class).isEmpty(); } // ------------------------------------------------------------- // static methods // ------------------------------------------------------------- public static Person readPersonByUsernameWithOpenedLogin(final String username) { final Login login = Login.readLoginByUsername(username); final User user = login == null ? null : (login.isOpened()) ? login.getUser() : null; return user == null ? null : user.getPerson(); } public static Person readPersonByUsername(final String username) { final Login login = Login.readLoginByUsername(username); final User user = login == null ? null : login.getUser(); return user == null ? null : user.getPerson(); } public static Person readPersonByIstUsername(final String istUsername) { final User user = User.readUserByUserUId(istUsername); return user == null ? null : user.getPerson(); } public static Collection readByDocumentIdNumber(final String documentIdNumber) { Collection result = new ArrayList(); for (final IdDocument idDocument : IdDocument.find(documentIdNumber)) { result.add(idDocument.getPerson()); } return result; } public static Person readByDocumentIdNumberAndIdDocumentType(final String documentIdNumber, final IDDocumentType idDocumentType) { for (final IdDocument idDocument : IdDocument.find(documentIdNumber)) { if (idDocument.getIdDocumentType().getValue() == idDocumentType) { return idDocument.getPerson(); } } return null; } public static Person readByDocumentIdNumberAndDateOfBirth(final String documentIdNumber, final YearMonthDay dateOfBirth) { for (final IdDocument idDocument : IdDocument.find(documentIdNumber)) { final Person person = idDocument.getPerson(); if (person.getDateOfBirthYearMonthDay().equals(dateOfBirth)) { return person; } } return null; } public static Collection findByDateOfBirth(final YearMonthDay dateOfBirth, final Collection persons) { List result = new ArrayList(); for (Person person : persons) { if (person.getDateOfBirthYearMonthDay() == null || person.getDateOfBirthYearMonthDay().equals(dateOfBirth)) { result.add(person); } } return result; } // used by grant owner public static List readPersonsByName(final String name, final Integer startIndex, final Integer numberOfElementsInSpan) { final Collection personsList = readPersonsByName(name, Integer.MAX_VALUE); if (startIndex != null && numberOfElementsInSpan != null && !personsList.isEmpty()) { int finalIndex = Math.min(personsList.size(), startIndex + numberOfElementsInSpan); final List result = new ArrayList(finalIndex - startIndex); final Iterator iter = personsList.iterator(); for (int i = 0; i <= finalIndex && iter.hasNext(); i++) { final Person person = iter.next(); if (i >= startIndex) { result.add(person); } } return result; } return Collections.EMPTY_LIST; } public static Integer countAllByName(final String name) { return readPersonsByName(name, Integer.MAX_VALUE).size(); } public static Collection readPersonsByName(final String name, final int size) { return findPerson(name.replace('%', ' '), size); } public static Collection findPerson(final String name, final int size) { final Collection people = new ArrayList(); for (final PersonName personName : PersonName.findPerson(name, size)) { people.add(personName.getPerson()); } return people; } public static Collection readPersonsByName(final String name) { return findPerson(name.replace('%', ' ')); } public static List readAllPersons() { List allPersons = new ArrayList(); for (Party party : RootDomainObject.getInstance().getPartys()) { if (party.isPerson()) { allPersons.add((Person) party); } } return allPersons; } public static List readPersonsByRoleType(RoleType roleType) { return new ArrayList(Role.getRoleByRoleType(roleType).getAssociatedPersonsSet()); } public static Collection readPersonsByNameAndRoleType(final String name, RoleType roleType) { final Collection people = findPerson(name); for (final Iterator iter = people.iterator(); iter.hasNext();) { final Person person = iter.next(); if (!person.hasRole(roleType)) { iter.remove(); } } return people; } public SortedSet getActiveStudentCurricularPlansSortedByDegreeTypeAndDegreeName() { final SortedSet studentCurricularPlans = new TreeSet( StudentCurricularPlan.STUDENT_CURRICULAR_PLAN_COMPARATOR_BY_DEGREE_TYPE_AND_DEGREE_NAME); for (final Registration registration : getStudentsSet()) { final StudentCurricularPlan studentCurricularPlan = registration.getActiveStudentCurricularPlan(); if (studentCurricularPlan != null) { studentCurricularPlans.add(studentCurricularPlan); } } return studentCurricularPlans; } public SortedSet getCompletedStudentCurricularPlansSortedByDegreeTypeAndDegreeName() { final SortedSet studentCurricularPlans = new TreeSet( StudentCurricularPlan.STUDENT_CURRICULAR_PLAN_COMPARATOR_BY_DEGREE_TYPE_AND_DEGREE_NAME); for (final Registration registration : getStudentsSet()) { if (registration.isConcluded()) { StudentCurricularPlan lastStudent = registration.getLastStudentCurricularPlan(); if (lastStudent != null) { studentCurricularPlans.add(lastStudent); } } } return studentCurricularPlans; } public List readProjectAccessesByCoordinator(final Integer coordinatorCode, Boolean it) { final List result = new ArrayList(); for (final ProjectAccess projectAccess : getProjectAccessesSet()) { if (projectAccess.getKeyProjectCoordinator().equals(coordinatorCode) && projectAccess.getItProject().equals(it)) { if (!projectAccess.getProjectAccessInterval().containsNow()) { continue; } result.add(projectAccess); } } return result; } public Set getCurrentAttends() { final Set attends = new HashSet(); for (final Registration registration : getStudentsSet()) { for (final Attends attend : registration.getAssociatedAttendsSet()) { final ExecutionCourse executionCourse = attend.getExecutionCourse(); final ExecutionSemester executionSemester = executionCourse.getExecutionPeriod(); if (executionSemester.getState().equals(PeriodState.CURRENT)) { attends.add(attend); } } } return attends; } public boolean hasIstUsername() { if (this.getIstUsername() != null) { return true; } if (UsernameUtils.shouldHaveUID(this)) { setIstUsername(); return getIstUsername() != null; } return false; } public static class FindPersonFactory implements Serializable, FactoryExecutor { private Integer institutionalNumber; public Integer getInstitutionalNumber() { return institutionalNumber; } public void setInstitutionalNumber(Integer institutionalNumber) { this.institutionalNumber = institutionalNumber; } transient Set people = null; public FindPersonFactory execute() { people = Person.findPerson(this); return this; } public Set getPeople() { return people; } } public static Set findPerson(final FindPersonFactory findPersonFactory) { final Set people = new HashSet(); if (findPersonFactory.getInstitutionalNumber() != null) { Teacher teacher = Teacher.readByNumber(findPersonFactory.getInstitutionalNumber()); if (teacher != null) { people.add(teacher.getPerson()); } Employee employee = Employee.readByNumber(findPersonFactory.getInstitutionalNumber()); if (employee != null) { people.add(employee.getPerson()); } for (Registration registration : Registration.readByNumber(findPersonFactory.getInstitutionalNumber())) { people.add(registration.getPerson()); } } return people; } private Set getEventsFromType(Class clazz) { Set events = new HashSet(); for (Event event : getEventsSet()) { if (clazz.isAssignableFrom(event.getClass())) { events.add(event); } } return events; } public Set getAcademicEvents() { return getEventsFromType(AcademicEvent.class); } public Set getResidencePaymentEvents() { return getEventsFromType(ResidenceEvent.class); } public Set getNotPayedEventsPayableOn(AdministrativeOffice administrativeOffice, Class eventClass, boolean withInstallments) { final Set result = new HashSet(); for (final Event event : getEventsFromType(eventClass)) { if (event.isOpen() && event.hasInstallments() == withInstallments && isPayableOnAdministrativeOffice(administrativeOffice, event)) { result.add(event); } } return result; } public Set getNotPayedEventsPayableOn(AdministrativeOffice administrativeOffice, boolean withInstallments) { return getNotPayedEventsPayableOn(administrativeOffice, AcademicEvent.class, withInstallments); } public Set getNotPayedEventsPayableOn(AdministrativeOffice administrativeOffice) { final Set result = new HashSet(); for (final Event event : getAcademicEvents()) { if (event.isOpen() && isPayableOnAdministrativeOffice(administrativeOffice, event)) { result.add(event); } } return result; } private boolean isPayableOnAdministrativeOffice(AdministrativeOffice administrativeOffice, final Event event) { return ((administrativeOffice == null) || (event.isPayableOnAdministrativeOffice(administrativeOffice))); } public List getPayedEvents(Class eventClass) { final List result = new ArrayList(); for (final Event event : getEventsFromType(eventClass)) { if (event.isClosed()) { result.add(event); } } return result; } public List getPayedEvents() { return getPayedEvents(AcademicEvent.class); } public List getEventsWithPayments() { final List result = new ArrayList(); for (final Event event : getAcademicEvents()) { if (!event.isCancelled() && event.hasAnyPayments()) { result.add(event); } } return result; } public Set getPaymentsWithoutReceipt() { return getPaymentsWithoutReceiptByAdministrativeOffice(null); } public Set getPaymentsWithoutReceiptByAdministrativeOffice(AdministrativeOffice administrativeOffice) { final Set result = new HashSet(); for (final Event event : getAcademicEvents()) { if (!event.isCancelled() && isPayableOnAdministrativeOffice(administrativeOffice, event)) { result.addAll(event.getEntriesWithoutReceipt()); } } return result; } public Set getPayments(Class eventClass) { final Set result = new HashSet(); for (final Event event : getEventsFromType(eventClass)) { if (!event.isCancelled()) { result.addAll(event.getPositiveEntries()); } } return result; } public Set getPayments() { return getPayments(AcademicEvent.class); } public Set getEventsByEventTypes(final EventType... eventTypes) { return getEventsByEventTypes(Arrays.asList(eventTypes)); } public Set getEventsByEventTypes(final Collection eventTypes) { final Set result = new HashSet(); for (final EventType eventType : eventTypes) { for (final Event event : getAcademicEvents()) { if (!event.isCancelled() && event.getEventType() == eventType) { result.add(event); } } } return result; } public Set getEventsByEventType(final EventType eventType) { return getEventsByEventTypeAndClass(eventType, null); } public Set getEventsByEventTypeAndClass(final EventType eventType, final Class clazz) { final Set result = new HashSet(); for (final Event event : getAcademicEvents()) { if (!event.isCancelled() && event.getEventType() == eventType && (clazz == null || event.getClass().equals(clazz))) { result.add(event); } } return result; } public Set getAnnualEventsFor(final ExecutionYear executionYear) { final Set result = new HashSet(); for (final Event event : getEventsSet()) { if (event instanceof AnnualEvent) { final AnnualEvent annualEvent = (AnnualEvent) event; if (annualEvent.isFor(executionYear) && !annualEvent.isCancelled()) { result.add(annualEvent); } } } return result; } public Set getOpenAnnualEventsFor(final ExecutionYear executionYear) { final Set result = new HashSet(); for (final Event event : getEventsSet()) { if (event instanceof AnnualEvent) { final AnnualEvent annualEvent = (AnnualEvent) event; if (annualEvent.isFor(executionYear) && annualEvent.isOpen()) { result.add(annualEvent); } } } return result; } public boolean hasInsuranceEventOrAdministrativeOfficeFeeInsuranceEventFor(final ExecutionYear executionYear) { return hasInsuranceEventFor(executionYear) || hasAdministrativeOfficeFeeInsuranceEventFor(executionYear); } public Set getNotCancelledInsuranceEvents() { final Set result = new HashSet(); for (final Event event : getEventsByEventType(EventType.INSURANCE)) { final InsuranceEvent specificEvent = (InsuranceEvent) event; if (!specificEvent.isCancelled()) { result.add(specificEvent); } } return result; } public Set getNotCancelledInsuranceEventsUntil(final ExecutionYear executionYear) { final Set result = new HashSet(); for (final Event event : getEventsByEventType(EventType.INSURANCE)) { final InsuranceEvent specificEvent = (InsuranceEvent) event; if (!specificEvent.isCancelled() && specificEvent.getExecutionYear().isBeforeOrEquals(executionYear)) { result.add(specificEvent); } } return result; } public InsuranceEvent getInsuranceEventFor(final ExecutionYear executionYear) { for (final Event event : getEventsByEventType(EventType.INSURANCE)) { final InsuranceEvent insuranceEvent = (InsuranceEvent) event; if (!insuranceEvent.isCancelled() && insuranceEvent.isFor(executionYear)) { return insuranceEvent; } } return null; } public boolean hasInsuranceEventFor(final ExecutionYear executionYear) { return getInsuranceEventFor(executionYear) != null; } public Set getNotCancelledAdministrativeOfficeFeeAndInsuranceEvents( final AdministrativeOffice office) { final Set result = new HashSet(); for (final Event event : getEventsByEventType(EventType.ADMINISTRATIVE_OFFICE_FEE_INSURANCE)) { final AdministrativeOfficeFeeAndInsuranceEvent specificEvent = (AdministrativeOfficeFeeAndInsuranceEvent) event; if (!specificEvent.isCancelled() && specificEvent.getAdministrativeOffice() == office) { result.add(specificEvent); } } return result; } public Set getNotCancelledAdministrativeOfficeFeeAndInsuranceEventsUntil( final AdministrativeOffice office, final ExecutionYear executionYear) { final Set result = new HashSet(); for (final Event event : getEventsByEventType(EventType.ADMINISTRATIVE_OFFICE_FEE_INSURANCE)) { final AdministrativeOfficeFeeAndInsuranceEvent specificEvent = (AdministrativeOfficeFeeAndInsuranceEvent) event; if (!specificEvent.isCancelled() && specificEvent.getAdministrativeOffice() == office && specificEvent.getExecutionYear().isBeforeOrEquals(executionYear)) { result.add(specificEvent); } } return result; } public AdministrativeOfficeFeeAndInsuranceEvent getAdministrativeOfficeFeeInsuranceEventFor(final ExecutionYear executionYear) { for (final Event event : getEventsByEventType(EventType.ADMINISTRATIVE_OFFICE_FEE_INSURANCE)) { final AdministrativeOfficeFeeAndInsuranceEvent administrativeOfficeFeeAndInsuranceEvent = (AdministrativeOfficeFeeAndInsuranceEvent) event; if (!administrativeOfficeFeeAndInsuranceEvent.isCancelled() && administrativeOfficeFeeAndInsuranceEvent.isFor(executionYear)) { return administrativeOfficeFeeAndInsuranceEvent; } } return null; } public boolean hasAdministrativeOfficeFeeInsuranceEventFor(final ExecutionYear executionYear) { return getAdministrativeOfficeFeeInsuranceEventFor(executionYear) != null; } public Set getEventsSupportingPaymentByOtherParties() { final Set result = new HashSet(); for (final Event event : getEventsSet()) { if (!event.isCancelled() && event.isOtherPartiesPaymentsSupported()) { result.add(event); } } return result; } public Set getGratuityEvents() { return (Set) getEventsByEventTypes(EventType.getGratuityEventTypes()); } public List getEventsWithExemptionAppliable() { final List result = new ArrayList(); for (final Event event : getEventsSet()) { if (!event.isCancelled() && event.isExemptionAppliable()) { result.add(event); } } return result; } public Money getMaxDeductableAmountForLegalTaxes(final EventType eventType, final int civilYear) { Money result = Money.ZERO; for (final Event event : (Set) getEventsByEventType(eventType)) { result = result.add(event.getMaxDeductableAmountForLegalTaxes(civilYear)); } return result; } public Set getReceiptsByAdministrativeOffice(AdministrativeOffice administrativeOffice) { final Set result = new HashSet(); for (final Receipt receipt : getReceipts()) { if (receipt.isFromAdministrativeOffice(administrativeOffice)) { result.add(receipt); } } return result; } static public Party createContributor(final String contributorName, final String contributorNumber, final PhysicalAddressData data) { Person externalPerson = createExternalPerson(contributorName, Gender.MALE, data, null, null, null, null, String .valueOf(System.currentTimeMillis()), IDDocumentType.EXTERNAL); externalPerson.setSocialSecurityNumber(contributorNumber); new ExternalContract(externalPerson, RootDomainObject.getInstance().getExternalInstitutionUnit(), new YearMonthDay(), null); return externalPerson; } public Collection getCurrentExecutionCoursesAnnouncementBoards() { final Collection result = new HashSet(); result.addAll(getTeacherCurrentExecutionCourseAnnouncementBoards()); result.addAll(getStudentCurrentExecutionCourseAnnouncementBoards()); return result; } private Collection getTeacherCurrentExecutionCourseAnnouncementBoards() { if (!hasTeacher()) { return Collections.emptyList(); } final Collection result = new HashSet(); for (final Professorship professorship : getTeacher().getProfessorships()) { if (professorship.getExecutionCourse().getExecutionPeriod() == ExecutionSemester.readActualExecutionSemester()) { final AnnouncementBoard board = professorship.getExecutionCourse().getBoard(); if (board != null && board.hasReaderOrWriter(this)) { result.add(board); } } } return result; } private Collection getStudentCurrentExecutionCourseAnnouncementBoards() { if (!hasStudent()) { return Collections.emptyList(); } final Collection result = new HashSet(); for (final Registration registration : getStudent().getRegistrationsSet()) { for (final Attends attends : registration.getAssociatedAttendsSet()) { if (attends.getExecutionCourse().isLecturedIn(ExecutionSemester.readActualExecutionSemester())) { final AnnouncementBoard board = attends.getExecutionCourse().getBoard(); if (board != null && board.hasReaderOrWriter(this)) { result.add(board); } } } } return result; } @Override final public boolean isPerson() { return true; } final public boolean isFemale() { return getGender() == Gender.FEMALE; } final public boolean isMale() { return getGender() == Gender.MALE; } @Deprecated public List getStudents() { return hasStudent() ? getStudent().getRegistrations() : Collections.EMPTY_LIST; } @Deprecated public boolean hasAnyStudents() { return getStudentsCount() > 0; } @Deprecated public int getStudentsCount() { return hasStudent() ? getStudent().getRegistrationsCount() : 0; } @Deprecated public Set getStudentsSet() { return hasStudent() ? getStudent().getRegistrationsSet() : Collections.EMPTY_SET; } @Override public PartyClassification getPartyClassification() { final Teacher teacher = getTeacher(); if (teacher != null) { if (teacher.getCurrentWorkingDepartment() != null && !teacher.isMonitor(ExecutionSemester.readActualExecutionSemester())) { return PartyClassification.TEACHER; } } final Employee employee = getEmployee(); if (employee != null && employee.getAssiduousness() != null && employee.getAssiduousness().getCurrentStatus() != null && employee.getAssiduousness().getCurrentStatus().getState() == AssiduousnessState.ACTIVE && teacher == null) { return PartyClassification.EMPLOYEE; } final GrantOwner grantOwner = getGrantOwner(); if (grantOwner != null && grantOwner.hasCurrentContract()) { return PartyClassification.GRANT_OWNER; } if (isPersonResearcher()) { return PartyClassification.RESEARCHER; } final Student student = getStudent(); if (student != null) { final DegreeType degreeType = student.getMostSignificantDegreeType(); if (degreeType != null) { if (hasActiveDegree(student, degreeType)) { return PartyClassification.getClassificationByDegreeType(degreeType); } } } return PartyClassification.PERSON; } private boolean hasActiveDegree(Student student, DegreeType degreeType) { for (final Registration registration : student.getRegistrationsSet()) { if (registration.getDegreeType() == degreeType) { for (final StudentCurricularPlan studentCurricularPlan : registration.getStudentCurricularPlansSet()) { final DegreeCurricularPlan degreeCurricularPlan = studentCurricularPlan.getDegreeCurricularPlan(); if (degreeCurricularPlan.getExecutionDegreeByYear(ExecutionYear.readCurrentExecutionYear()) != null) { return true; } } } } return false; } public static class PersonBeanFactoryEditor extends PersonBean implements FactoryExecutor { public PersonBeanFactoryEditor(final Person person) { super(person); } public Object execute() { getPerson().edit(this); return null; } } public static class ExternalPersonBeanFactoryCreator extends ExternalPersonBean implements FactoryExecutor { public ExternalPersonBeanFactoryCreator() { super(); } public Object execute() { final Person person = new Person(this, true); Unit unit = getUnit(); if (unit == null) { unit = Unit.findFirstUnitByName(getUnitName()); if (unit == null) { throw new DomainException("error.unit.does.not.exist"); } } new ExternalContract(person, unit, new YearMonthDay(), null); return person; } } public static class AnyPersonSearchBean implements Serializable { String name; String documentIdNumber; IDDocumentType idDocumentType; public String getDocumentIdNumber() { return documentIdNumber; } public void setDocumentIdNumber(String documentIdNumber) { this.documentIdNumber = documentIdNumber; } public IDDocumentType getIdDocumentType() { return idDocumentType; } public void setIdDocumentType(IDDocumentType idDocumentType) { this.idDocumentType = idDocumentType; } public String getName() { return name; } public void setName(String name) { this.name = name; } private boolean matchesAnyCriteriaField(final String[] nameValues, final String string, final String stringFromPerson) { return isSpecified(string) && areNamesPresent(stringFromPerson, nameValues); } public SortedSet search() { final SortedSet people = new TreeSet(Party.COMPARATOR_BY_NAME_AND_ID); if (isSpecified(name)) { people.addAll(findPerson(name)); } if (isSpecified(documentIdNumber)) { for (final IdDocument idDocument : RootDomainObject.getInstance().getIdDocumentsSet()) { final String[] documentIdNumberValues = documentIdNumber == null ? null : StringNormalizer.normalize( documentIdNumber).toLowerCase().split("\\p{Space}+"); if (matchesAnyCriteriaField(documentIdNumberValues, documentIdNumber, idDocument.getValue())) { people.add(idDocument.getPerson()); } } } return people; } public SortedSet getSearch() { return search(); } public boolean getHasBeenSubmitted() { return isSpecified(name) || isSpecified(documentIdNumber); } private boolean isSpecified(final String string) { return string != null && string.length() > 0; } private boolean areNamesPresent(String name, String[] searchNameParts) { String nameNormalized = StringNormalizer.normalize(name).toLowerCase(); for (int i = 0; i < searchNameParts.length; i++) { String namePart = searchNameParts[i]; if (!nameNormalized.contains(namePart)) { return false; } } return true; } } public Registration getRegistration(ExecutionCourse executionCourse) { return executionCourse.getRegistration(this); } public SortedSet getOrganizationalUnitsPresentation() { final SortedSet organizationalUnits = new TreeSet(); for (final Accountability accountability : getParentsSet()) { if (isOrganizationalUnitsForPresentation(accountability)) { final Party party = accountability.getParentParty(); organizationalUnits.add(party.getName()); } } if (getStudent() != null) { for (final Registration registration : getStudent().getRegistrationsSet()) { if (registration.isActive()) { final DegreeCurricularPlan degreeCurricularPlan = registration.getLastDegreeCurricularPlan(); final Degree degree = degreeCurricularPlan.getDegree(); organizationalUnits.add(degree.getPresentationName()); } } } return organizationalUnits; } private boolean isOrganizationalUnitsForPresentation(final Accountability accountability) { final AccountabilityType accountabilityType = accountability.getAccountabilityType(); final AccountabilityTypeEnum accountabilityTypeEnum = accountabilityType.getType(); return accountabilityTypeEnum == AccountabilityTypeEnum.WORKING_CONTRACT; } @Override public String getNickname() { final String nickname = super.getNickname(); return nickname == null ? getName() : nickname; } @Override public void setNickname(String nickname) { if (!validNickname(nickname)) { throw new DomainException("error.invalid.nickname"); } super.setNickname(nickname); } private static final Set namePartsToIgnore = new HashSet(5); static { namePartsToIgnore.add("de"); namePartsToIgnore.add("da"); namePartsToIgnore.add("do"); namePartsToIgnore.add("a"); namePartsToIgnore.add("e"); namePartsToIgnore.add("i"); namePartsToIgnore.add("o"); namePartsToIgnore.add("u"); } private boolean validNickname(final String name) { if (name != null && name.length() > 0) { final String normalizedName = StringNormalizer.normalize(name.replace('-', ' ')).toLowerCase(); final String normalizedPersonName = StringNormalizer.normalize(getName().replace('-', ' ')).toLowerCase(); final String[] nameParts = normalizedName.split(" "); final String[] personNameParts = normalizedPersonName.split(" "); int matches = 0; for (final String namePart : nameParts) { if (!contains(personNameParts, namePart)) { return false; } if (!namePartsToIgnore.contains(namePart)) { matches++; } } if (matches >= 2) { return true; } } return false; } private boolean contains(final String[] strings, final String xpto) { if (xpto == null) { return false; } for (final String string : strings) { if (string.length() == xpto.length() && string.hashCode() == xpto.hashCode() && string.equals(xpto)) { return true; } } return false; } public String getHomepageWebAddress() { if (hasHomepage() && getHomepage().isHomepageActivated()) return "/homepage/" + getUsername(); if (isDefaultWebAddressVisible() && getDefaultWebAddress().hasUrl()) return getDefaultWebAddress().getUrl(); return null; } @Deprecated public boolean hasAvailableWebSite() { return getAvailableWebSite() != null && getAvailableWebSite().booleanValue(); } public Collection getCoordinatedExecutionDegrees(DegreeCurricularPlan degreeCurricularPlan) { Set result = new TreeSet(ExecutionDegree.EXECUTION_DEGREE_COMPARATORY_BY_YEAR); for (Coordinator coordinator : getCoordinators()) { if (coordinator.getExecutionDegree().getDegreeCurricularPlan().equals(degreeCurricularPlan)) { result.add(coordinator.getExecutionDegree()); } } return result; } public boolean isCoordinatorFor(DegreeCurricularPlan degreeCurricularPlan, ExecutionYear executionYear) { for (final ExecutionDegree executionDegree : degreeCurricularPlan.getExecutionDegreesSet()) { if (executionDegree.getExecutionYear() == executionYear) { return executionDegree.getCoordinatorByTeacher(this) != null; } } return false; } public boolean isResponsibleOrCoordinatorFor(CurricularCourse curricularCourse, ExecutionSemester executionSemester) { final Teacher teacher = getTeacher(); return (teacher != null && teacher.isResponsibleFor(curricularCourse, executionSemester)) || isCoordinatorFor(curricularCourse.getDegreeCurricularPlan(), executionSemester.getExecutionYear()); } private final static List degreeTypesForIsMasterDegreeOrBolonhaMasterDegreeCoordinator = Arrays .asList(new DegreeType[] { DegreeType.MASTER_DEGREE, DegreeType.BOLONHA_MASTER_DEGREE }); public boolean isMasterDegreeOrBolonhaMasterDegreeCoordinatorFor(ExecutionYear executionYear) { return isCoordinatorFor(executionYear, degreeTypesForIsMasterDegreeOrBolonhaMasterDegreeCoordinator); } private final static List degreeTypesForisDegreeOrBolonhaDegreeOrBolonhaIntegratedMasterDegreeCoordinatorFor = Arrays .asList(new DegreeType[] { DegreeType.DEGREE, DegreeType.BOLONHA_DEGREE, DegreeType.BOLONHA_INTEGRATED_MASTER_DEGREE }); public boolean isDegreeOrBolonhaDegreeOrBolonhaIntegratedMasterDegreeCoordinatorFor(ExecutionYear executionYear) { return isCoordinatorFor(executionYear, degreeTypesForisDegreeOrBolonhaDegreeOrBolonhaIntegratedMasterDegreeCoordinatorFor); } public boolean isCoordinatorFor(ExecutionYear executionYear, List degreeTypes) { for (final Coordinator coordinator : getCoordinatorsSet()) { final ExecutionDegree executionDegree = coordinator.getExecutionDegree(); if (executionDegree != null && executionDegree.getExecutionYear() == executionYear && degreeTypes.contains(executionDegree.getDegree().getDegreeType())) { return true; } } return false; } public ServiceAgreement getServiceAgreementFor(final ServiceAgreementTemplate serviceAgreementTemplate) { for (final ServiceAgreement serviceAgreement : getServiceAgreementsSet()) { if (serviceAgreement.getServiceAgreementTemplate() == serviceAgreementTemplate) { return serviceAgreement; } } return null; } public boolean hasServiceAgreementFor(final ServiceAgreementTemplate serviceAgreementTemplate) { return getServiceAgreementFor(serviceAgreementTemplate) != null; } public boolean isHomePageAvailable() { return hasHomepage() && getHomepage().getActivated(); } public boolean isAdministrativeOfficeEmployee() { return getEmployee() != null && getEmployee().getAdministrativeOffice() != null; } public List getPunctualRoomsOccupationRequestsOrderByMoreRecentComment() { List result = new ArrayList(); result.addAll(getPunctualRoomsOccupationRequests()); if (!result.isEmpty()) { Collections.sort(result, PunctualRoomsOccupationRequest.COMPARATOR_BY_MORE_RECENT_COMMENT_INSTANT); } return result; } public List getPunctualRoomsOccupationRequestsToProcessOrderByDate() { List result = new ArrayList(); for (PunctualRoomsOccupationRequest request : getPunctualRoomsOccupationRequestsToProcess()) { if (!request.getCurrentState().equals(RequestState.RESOLVED)) { result.add(request); } } if (!result.isEmpty()) { Collections.sort(result, PunctualRoomsOccupationRequest.COMPARATOR_BY_INSTANT); } return result; } public String getFirstAndLastName() { String[] name = getName().split(" "); return name[0] + " " + name[name.length - 1]; } private List getImportantRoles(final List mainRoles) { if (getPersonRolesCount() != 0) { boolean teacher = false, employee = false, researcher = false; List roles = new ArrayList(getPersonRolesSet()); Collections.sort(roles, Role.COMPARATOR_BY_ROLE_TYPE); ResourceBundle bundle = ResourceBundle.getBundle("resources.EnumerationResources"); for (final Role personRole : roles) { if (personRole.getRoleType() == RoleType.TEACHER) { mainRoles.add(bundle.getString(personRole.getRoleType().toString())); teacher = true; } else if (personRole.getRoleType() == RoleType.STUDENT) { mainRoles.add(bundle.getString(personRole.getRoleType().toString())); } else if (personRole.getRoleType() == RoleType.GRANT_OWNER) { mainRoles.add(bundle.getString(personRole.getRoleType().toString())); } else if (!teacher && personRole.getRoleType() == RoleType.EMPLOYEE) { employee = true; } else if (personRole.getRoleType() == RoleType.RESEARCHER) { mainRoles.add(bundle.getString(personRole.getRoleType().toString())); researcher = true; } else if (personRole.getRoleType() == RoleType.ALUMNI) { mainRoles.add(bundle.getString(personRole.getRoleType().toString())); } } if ((employee && !teacher && !researcher)) { mainRoles.add(0, bundle.getString(RoleType.EMPLOYEE.toString())); } } return mainRoles; } public List getMainRoles() { return getImportantRoles(new ArrayList()); } public String getMostImportantAlias() { final Login login = getLoginIdentification(); return (login != null) ? login.getMostImportantAlias() : ""; } public static Collection findPerson(final String name) { final Collection people = new ArrayList(); for (final PersonName personName : PersonName.findPerson(name, Integer.MAX_VALUE)) { people.add(personName.getPerson()); } return people; } public static Collection findInternalPerson(final String name) { final Collection people = new ArrayList(); for (final PersonName personName : PersonName.findInternalPerson(name, Integer.MAX_VALUE)) { people.add(personName.getPerson()); } return people; } public static Collection findInternalPersonByNameAndRole(final String name, final RoleType roleType) { final Role role = Role.getRoleByRoleType(roleType); return CollectionUtils.select(findInternalPerson(name), new Predicate() { @Override public boolean evaluate(Object arg0) { return ((Person) arg0).hasPersonRoles(role); } }); } public static Collection findInternalPersonMatchingFirstAndLastName(final String completeName) { if (completeName != null) { String[] splittedName = completeName.split(" "); return splittedName.length > 0 ? findInternalPerson(splittedName[0] + " " + splittedName[splittedName.length - 1]) : Collections.EMPTY_LIST; } return Collections.EMPTY_LIST; } public static Collection findExternalPerson(final String name) { final Collection people = new ArrayList(); for (final PersonName personName : PersonName.findExternalPerson(name, Integer.MAX_VALUE)) { people.add(personName.getPerson()); } return people; } public static Collection findPersonByDocumentID(final String documentIDValue) { final Collection people = new ArrayList(); if (!StringUtils.isEmpty(documentIDValue)) { for (final IdDocument idDocument : IdDocument.find(documentIDValue)) { people.add(idDocument.getPerson()); } } return people; } public static Person readPersonByEmailAddress(final String email) { final EmailAddress emailAddress = EmailAddress.find(email); return (emailAddress != null && emailAddress.getParty().isPerson()) ? (Person) emailAddress.getParty() : null; } public String getUnitText() { if (getEmployee() != null && getEmployee().getLastWorkingPlace() != null) { return getEmployee().getLastWorkingPlace().getNameWithAcronym(); } else if (hasExternalContract()) { return getExternalContract().getInstitutionUnit().getPresentationNameWithParents(); } return ""; } public List getThesisEvaluationParticipants(ExecutionSemester executionSemester) { ArrayList participants = new ArrayList(); for (ThesisEvaluationParticipant participant : this.getThesisEvaluationParticipants()) { if (participant.getThesis().getEnrolment().getExecutionYear().equals(executionSemester.getExecutionYear())) { participants.add(participant); } } Collections.sort(participants, ThesisEvaluationParticipant.COMPARATOR_BY_STUDENT_NUMBER); return participants; } public Set findFinalDegreeWorkProposals() { final Set proposals = new HashSet(); proposals.addAll(getAssociatedProposalsByCoorientatorSet()); proposals.addAll(getAssociatedProposalsByOrientatorSet()); return proposals; } @Override public List getTSDProcesses() { Department department = hasTeacher() ? getTeacher().getCurrentWorkingDepartment() : null; return department == null ? Collections.EMPTY_LIST : (List) CollectionUtils.select(department .getTSDProcesses(), new Predicate() { public boolean evaluate(Object arg0) { TSDProcess tsd = (TSDProcess) arg0; return tsd.hasAnyPermission(Person.this); } }); } public List getTSDProcesses(ExecutionSemester period) { Department department = hasTeacher() ? getTeacher().getCurrentWorkingDepartment() : null; return department == null ? Collections.EMPTY_LIST : (List) CollectionUtils.select(department .getTSDProcessesByExecutionPeriod(period), new Predicate() { public boolean evaluate(Object arg0) { TSDProcess tsd = (TSDProcess) arg0; return tsd.hasAnyPermission(Person.this); } }); } public List getTSDProcesses(ExecutionYear year) { Department department = hasTeacher() ? getTeacher().getCurrentWorkingDepartment() : null; return department == null ? Collections.EMPTY_LIST : (List) CollectionUtils.select(department .getTSDProcessesByExecutionYear(year), new Predicate() { public boolean evaluate(Object arg0) { TSDProcess tsd = (TSDProcess) arg0; return tsd.hasAnyPermission(Person.this); } }); } public List getWorkingResearchUnits() { List units = new ArrayList(); Collection parentAccountabilities = getParentAccountabilities(AccountabilityTypeEnum.RESEARCH_CONTRACT); YearMonthDay currentDate = new YearMonthDay(); for (Accountability accountability : parentAccountabilities) { if (accountability.isActive(currentDate)) { units.add((ResearchUnit) accountability.getParentParty()); } } return units; } public List getWorkingResearchUnitsAndParents() { Set baseUnits = new HashSet(); for (ResearchUnit unit : getWorkingResearchUnits()) { baseUnits.add(unit); for (Unit parentUnit : unit.getAllActiveParentUnits(new YearMonthDay())) { if (parentUnit.isResearchUnit()) { baseUnits.add((ResearchUnit) parentUnit); } } } return new ArrayList(baseUnits); } public Set getAssociatedResearchOrDepartmentUnits() { Set units = new HashSet(); Set parentAccountabilities = new HashSet(); parentAccountabilities.addAll(getParentAccountabilities(AccountabilityTypeEnum.RESEARCH_CONTRACT)); parentAccountabilities.addAll(getParentAccountabilities(AccountabilityTypeEnum.WORKING_CONTRACT)); for (Accountability accountability : parentAccountabilities) { Unit unit = getActiveAncestorUnitFromAccountability(accountability); if (unit != null) { units.add(unit); } } return units; } private Unit getActiveAncestorUnitFromAccountability(Accountability accountability) { YearMonthDay currentDate = new YearMonthDay(); if (!accountability.isActive(currentDate)) { return null; } Unit parentUnit = (Unit) accountability.getParentParty(); if (isResearchDepartmentScientificOrSectionUnitType(parentUnit)) { return parentUnit; } for (Unit grandParentUnit : parentUnit.getParentUnits()) { if (isResearchDepartmentScientificOrSectionUnitType(grandParentUnit)) return grandParentUnit; } return null; } private boolean isResearchDepartmentScientificOrSectionUnitType(Unit unit) { return unit.isResearchUnit() || unit.isDepartmentUnit() || unit.isScientificAreaUnit() || unit.isSectionUnit(); } // FIXME Anil : This method is identical to getWorkingResearchUnitNames public String getAssociatedResearchOrDepartmentUnitsNames() { String names = ""; Set units = getAssociatedResearchOrDepartmentUnits(); int length = units.size(); for (Unit unit : units) { names += unit.getName(); if (--length > 0) { names += ", "; } } return names; } public String getWorkingResearchUnitNames() { String names = ""; List units = getWorkingResearchUnits(); int length = units.size(); for (ResearchUnit unit : units) { names += unit.getName(); if (--length > 0) { names += ", "; } } return names; } public boolean isExternalPerson() { return !hasActiveInternalContract() && (hasExternalContract() || hasExternalResearchContract()); } private boolean hasActiveInternalContract() { Collection contracts = (Collection) getParentAccountabilities( AccountabilityTypeEnum.WORKING_CONTRACT, EmployeeContract.class); YearMonthDay currentDate = new YearMonthDay(); for (EmployeeContract employeeContract : contracts) { if (employeeContract.isActive(currentDate)) { return true; } } return false; } public boolean isPhotoAvailableToCurrentUser() { if (isPhotoPubliclyAvailable()) { return true; } Person requester = AccessControl.getPerson(); if (requester != null) { if (requester.equals(this)) { return true; } if (requester.hasRole(RoleType.MANAGER) || requester.hasRole(RoleType.DIRECTIVE_COUNCIL)) { return true; } if (this.hasRole(RoleType.STUDENT) && (requester.hasRole(RoleType.TEACHER) || requester.hasRole(RoleType.ACADEMIC_ADMINISTRATIVE_OFFICE))) { return true; } if (requester.hasRole(RoleType.STUDENT) || requester.hasRole(RoleType.ALUMNI)) { return getAvailablePhoto(); } } return false; } @Override public Photograph getPersonalPhoto() { Photograph photo = super.getPersonalPhoto(); if (photo == null) return null; do { if (photo.getState() == PhotoState.APPROVED) return photo; photo = photo.getPrevious(); } while (photo != null); return null; } public Photograph getPersonalPhotoEvenIfPending() { Photograph photo = super.getPersonalPhoto(); if (photo == null) return null; do { if (photo.getState() != PhotoState.REJECTED && photo.getState() != PhotoState.USER_REJECTED) return photo; photo = photo.getPrevious(); } while (photo != null); return null; } public Photograph getPersonalPhotoEvenIfRejected() { return super.getPersonalPhoto(); } @Override public void setPersonalPhoto(Photograph photo) { if (super.getPersonalPhoto() != null) photo.setPrevious(super.getPersonalPhoto()); super.setPersonalPhoto(photo); } public List getPhotographHistory() { LinkedList history = new LinkedList(); for (Photograph photo = super.getPersonalPhoto(); photo != null; photo = photo.getPrevious()) { history.addFirst(photo); } return history; } public boolean isPhotoPubliclyAvailable() { Boolean availablePhoto = getAvailablePhoto(); if (availablePhoto == null || !availablePhoto) { return false; } if (!isHomePageAvailable()) { return false; } Boolean showPhotoInHomepage = getHomepage().getShowPhoto(); return showPhotoInHomepage != null && showPhotoInHomepage; } public boolean isDefaultEmailVisible() { return getDefaultEmailAddress() == null ? false : getDefaultEmailAddress().getVisibleToPublic(); } public boolean isDefaultWebAddressVisible() { return getDefaultWebAddress() == null ? false : getDefaultWebAddress().getVisibleToPublic(); } @Deprecated public Boolean getAvailableEmail() { return isDefaultEmailVisible(); } @Deprecated public void setAvailableEmail(Boolean available) { if (getDefaultEmailAddress() != null) getDefaultEmailAddress().setVisibleToPublic(available); } @Deprecated public Boolean getAvailableWebSite() { return isDefaultWebAddressVisible(); } @Deprecated public void setAvailableWebSite(Boolean available) { if (getDefaultWebAddress() != null) getDefaultWebAddress().setVisibleToPublic(available); } public List getUploadedFiles(Unit unit) { List files = new ArrayList(); for (UnitFile file : getUploadedFiles()) { if (file.getUnit().equals(unit)) { files.add(file); } } return files; } public String getPresentationName() { return getName() + " (" + getUsername() + ")"; } @Override public String getPartyPresentationName() { return getPresentationName(); } @Override public Homepage getSite() { return getHomepage(); } @Override protected Homepage createSite() { return new Homepage(this); } @Override public Homepage initializeSite() { return (Homepage) super.initializeSite(); } public PersonFunction getActiveGGAEDelegatePersonFunction() { for (PersonFunction personFunction : getActivePersonFunctions()) { if (personFunction.getFunction().getFunctionType().equals(FunctionType.DELEGATE_OF_GGAE)) { return personFunction; } } return null; } public List getAllGGAEDelegatePersonFunctions() { List result = new ArrayList(); for (PersonFunction personFunction : getPersonFunctions()) { if (personFunction.getFunction().getFunctionType().equals(FunctionType.DELEGATE_OF_GGAE)) { result.add(personFunction); } } return result; } public boolean isPersonResearcher() { return getPersonRole(RoleType.RESEARCHER) != null; } public Integer getMostSignificantNumber() { if (getPartyClassification().equals(PartyClassification.TEACHER)) { return getTeacher().getTeacherNumber(); } if (getPartyClassification().equals(PartyClassification.EMPLOYEE)) { return getEmployee().getEmployeeNumber(); } if (getPartyClassification().equals(PartyClassification.RESEARCHER) && getEmployee() != null) { return getEmployee().getEmployeeNumber(); } if (getStudent() != null) { return getStudent().getNumber(); // DegreeType degreeType = // getStudent().getMostSignificantDegreeType(); // Collection registrations = getStudent() // .getRegistrationsByDegreeType(degreeType); // for (Registration registration : registrations) { // StudentCurricularPlan scp = // registration.getActiveStudentCurricularPlan(); // if (scp != null) { // return getStudent().getNumber(); // } // } } if (getPartyClassification().equals(PartyClassification.GRANT_OWNER)) { return getGrantOwner().getNumber(); } return 0; } public List getActivePersonSpaces() { List result = new ArrayList(); Set personSpaceOccupationsSet = getPersonSpaceOccupationsSet(); YearMonthDay current = new YearMonthDay(); for (PersonSpaceOccupation personSpaceOccupation : personSpaceOccupationsSet) { if (personSpaceOccupation.contains(current)) { result.add(personSpaceOccupation.getSpace()); } } return result; } public AdministrativeOffice getEmployeeAdministrativeOffice() { return hasEmployee() ? getEmployee().getAdministrativeOffice() : null; } public Campus getEmployeeCampus() { return hasEmployee() ? getEmployee().getCurrentCampus() : null; } public Collection getForuns(final ExecutionSemester executionSemester) { Collection foruns = new HashSet(); if (getTeacher() != null) { foruns.addAll(getTeacher().getForuns(executionSemester)); } if (getStudent() != null) { foruns.addAll(getStudent().getForuns(executionSemester)); } for (ForumSubscription forumSubscription : getForumSubscriptionsSet()) { foruns.add(forumSubscription.getForum()); } return foruns; } public Set getCardGenerationProblems(final CardGenerationBatch cardGenerationBatch) { final Set cardGenerationProblems = new HashSet(); for (final CardGenerationProblem cardGenerationProblem : getCardGenerationProblemsSet()) { if (cardGenerationProblem.getCardGenerationBatch() == cardGenerationBatch) { cardGenerationProblems.add(cardGenerationProblem); } } return cardGenerationProblems; } public int getNumberOfCardGenerationEntries() { int result = 0; for (final CardGenerationEntry cardGenerationEntry : getCardGenerationEntriesSet()) { result++; } return result; } private boolean hasValidIndividualCandidacy(final Class clazz, final ExecutionInterval executionInterval) { for (final IndividualCandidacyPersonalDetails candidacyDetails : getIndividualCandidacies()) { IndividualCandidacy candidacy = candidacyDetails.getCandidacy(); if (!candidacy.isCancelled() && candidacy.getClass().equals(clazz) && candidacy.isFor(executionInterval)) { return true; } } return false; } public boolean hasValidOver23IndividualCandidacy(final ExecutionInterval executionInterval) { return hasValidIndividualCandidacy(Over23IndividualCandidacy.class, executionInterval); } public boolean hasValidSecondCycleIndividualCandidacy(final ExecutionInterval executionInterval) { return hasValidIndividualCandidacy(SecondCycleIndividualCandidacy.class, executionInterval); } public boolean hasValidDegreeCandidacyForGraduatedPerson(final ExecutionInterval executionInterval) { return hasValidIndividualCandidacy(DegreeCandidacyForGraduatedPerson.class, executionInterval); } public boolean hasValidStandaloneIndividualCandidacy(final ExecutionInterval executionInterval) { return hasValidIndividualCandidacy(StandaloneIndividualCandidacy.class, executionInterval); } public List getFormations() { List formations = new ArrayList(); for (Qualification qualification : getAssociatedQualifications()) { if (qualification instanceof Formation) { formations.add((Formation) qualification); } } return formations; } public Qualification getLastQualification() { return hasAnyAssociatedQualifications() ? Collections .max(getAssociatedQualifications(), Qualification.COMPARATOR_BY_YEAR) : null; } public boolean hasGratuityOrAdministrativeOfficeFeeAndInsuranceDebtsFor(final ExecutionYear executionYear) { for (final AnnualEvent annualEvent : getAnnualEventsFor(executionYear)) { if (annualEvent instanceof GratuityEvent || annualEvent instanceof AdministrativeOfficeFeeAndInsuranceEvent) { if (annualEvent.isOpen()) { return true; } } } return false; } public Set getAnnualIRSDocuments() { final Set result = new HashSet(); for (final GeneratedDocument each : getAddressedDocument()) { if (each instanceof AnnualIRSDeclarationDocument) { result.add((AnnualIRSDeclarationDocument) each); } } return result; } public AnnualIRSDeclarationDocument getAnnualIRSDocumentFor(final Integer year) { for (final AnnualIRSDeclarationDocument each : getAnnualIRSDocuments()) { if (each.getYear().compareTo(year) == 0) { return each; } } return null; } public boolean hasAnnualIRSDocumentFor(final Integer year) { return getAnnualIRSDocumentFor(year) != null; } public Person getIncompatibleVigilantPerson() { return getIncompatiblePerson() != null ? getIncompatiblePerson() : getIncompatibleVigilant(); } public void setIncompatibleVigilantPerson(Person person) { setIncompatibleVigilant(person); setIncompatiblePerson(null); } public void removeIncompatibleVigilantPerson() { setIncompatibleVigilant(null); setIncompatiblePerson(null); } public List getUnavailablePeriodsForGivenYear(ExecutionYear executionYear) { List unavailablePeriods = this.getUnavailablePeriods(); List unavailablePeriodsForGivenYear = new ArrayList(); for (UnavailablePeriod unavailablePeriod : unavailablePeriods) { if (unavailablePeriod.getBeginDate().getYear() == executionYear.getBeginCivilYear() || unavailablePeriod.getBeginDate().getYear() == executionYear.getEndCivilYear()) { unavailablePeriodsForGivenYear.add(unavailablePeriod); } } return unavailablePeriodsForGivenYear; } public boolean hasAnyAdministrativeOfficeFeeAndInsuranceEventInDebt() { for (final Event event : getEventsByEventType(EventType.ADMINISTRATIVE_OFFICE_FEE_INSURANCE)) { if (event.isInDebt()) { return true; } } return false; } public boolean hasAnyPastAdministrativeOfficeFeeAndInsuranceEventInDebt() { for (final Event event : getEventsByEventType(EventType.ADMINISTRATIVE_OFFICE_FEE_INSURANCE)) { final AdministrativeOfficeFeeAndInsuranceEvent administrativeOfficeFeeAndInsuranceEvent = (AdministrativeOfficeFeeAndInsuranceEvent) event; if (administrativeOfficeFeeAndInsuranceEvent instanceof PastAdministrativeOfficeFeeAndInsuranceEvent) { if (event.isInDebt()) { return true; } } } return false; } public boolean hasCoordinationExecutionDegreeReportsToAnswer() { return !getCoordinationExecutionDegreeReportsToAnswer().isEmpty(); } public Collection getCoordinationExecutionDegreeReportsToAnswer() { Collection result = new ArrayList(); InquiryResponsePeriod responsePeriod = InquiryResponsePeriod.readOpenPeriod(InquiryResponsePeriodType.COORDINATOR); if (responsePeriod != null) { for (Coordinator coordinator : getCoordinators()) { if (coordinator.isResponsible() && !coordinator.getExecutionDegree().getDegreeType().isThirdCycle() && coordinator.getExecutionDegree().getExecutionYear().getExecutionPeriods().contains( responsePeriod.getExecutionPeriod())) { CoordinatorExecutionDegreeCoursesReport report = coordinator.getExecutionDegree() .getExecutionDegreeCoursesReports(responsePeriod.getExecutionPeriod()); if (report == null || report.isEmpty()) { result.add(coordinator.getExecutionDegree()); } } } } return result; } public Professorship getProfessorshipByExecutionCourse(final ExecutionCourse executionCourse) { return (Professorship) CollectionUtils.find(getProfessorships(), new Predicate() { public boolean evaluate(Object arg0) { Professorship professorship = (Professorship) arg0; return professorship.getExecutionCourse() == executionCourse; } }); } public void updateResponsabilitiesFor(Integer executionYearId, List executionCourses) throws MaxResponsibleForExceed, InvalidCategory { if (executionYearId == null || executionCourses == null) throw new NullPointerException(); boolean responsible; for (final Professorship professorship : this.getProfessorships()) { final ExecutionCourse executionCourse = professorship.getExecutionCourse(); if (executionCourse.getExecutionPeriod().getExecutionYear().getIdInternal().equals(executionYearId)) { responsible = executionCourses.contains(executionCourse.getIdInternal()); if (!professorship.getResponsibleFor().equals(Boolean.valueOf(responsible)) && this.getTeacher() != null) { ResponsibleForValidator.getInstance().validateResponsibleForList(this.getTeacher(), executionCourse, professorship); professorship.setResponsibleFor(responsible); } } } } @SuppressWarnings("unchecked") public List getResponsableProfessorships() { List result = new ArrayList(); for (Professorship professorship : getProfessorships()) { if (professorship.isResponsibleFor()) { result.add(professorship); } } return result; } public boolean hasProfessorshipForExecutionCourse(final ExecutionCourse executionCourse) { return (getProfessorshipByExecutionCourse(executionCourse) != null); } public Set getUnreadedPhdAlertMessages() { final Set result = new HashSet(); for (final PhdAlertMessage message : getPhdAlertMessages()) { if (!message.isReaded()) { result.add(message); } } return result; } @Linkare(author = "Paulo Zenida") public List getWorkingUnits() { List units = new ArrayList(); Collection parentAccountabilities = getParentAccountabilities(AccountabilityTypeEnum.WORKING_CONTRACT); YearMonthDay currentDate = new YearMonthDay(); for (Accountability accountability : parentAccountabilities) { if (accountability.isActive(currentDate) && !units.contains(accountability.getParentParty())) { units.add((Unit) accountability.getParentParty()); } } return units; } @Linkare(author = "Paulo Zenida") @Override public List getManageableDepartmentCredits() { final List result = new ArrayList(); for (final Unit unit : getWorkingUnits()) { if (unit.isDepartmentUnit()) { result.add(((DepartmentUnit) unit).getDepartment()); } } return result; } @Linkare(author = "Paulo Zenida") public Unit getCurrentWorkingPlace() { if (super.getCurrentWorkingPlace() != null) { return super.getCurrentWorkingPlace(); } if (hasEmployee()) { Contract contract = getEmployee().getCurrentWorkingContract(); return (contract != null) ? contract.getWorkingUnit() : null; } return null; } @Linkare(author = "Paulo Zenida") @Service public static void setCurrentWorkingPlace(final Person person, final Unit currentWorkingPlace) { person.setCurrentWorkingPlace(currentWorkingPlace); } @Linkare(author = "Paulo Zenida", comments = "Override method so that the district may be fetched from the new residence object") @Override public Country getCountryOfResidence() { return hasResidence() ? getResidence().getCountry() : super.getCountryOfResidence(); } @Linkare(author = "Paulo Zenida", comments = "Override method so that the district may be fetched from the new residence object") @Override public String getDistrictOfResidence() { return hasResidence() ? getResidence().getDistrict() : super.getDistrictOfResidence(); } @Linkare(author = "Paulo Zenida", comments = "Override method so that the district may be fetched from the new residence object") @Override public String getDistrictSubdivisionOfResidence() { return hasResidence() ? getResidence().getDistrictSubdivision() : super.getDistrictSubdivisionOfResidence(); } @Linkare(author = "Paulo Zenida", comments = "Override method so that the district may be fetched from the new residence object") @Override public String getParishOfResidence() { return hasResidence() ? getResidence().getParish() : super.getParishOfResidence(); } @Linkare(author = "Paulo Zenida") private void setResidenceBean(final PersonBean.ResidenceBean residenceBean) { final PersonResidence personResidence = getOrCreateResidence(); if (residenceBean.isValid()) { personResidence.edit(residenceBean); } } private PersonResidence getOrCreateResidence() { return hasResidence() ? getResidence() : new PersonResidence(this); } @Linkare(author = "Paulo Zenida", comments = "Necessary, specially for migration purposes") public void setResidenceCountry(final Country country) { getOrCreateResidence().setCountry(country); } @Linkare(author = "Paulo Zenida", comments = "Necessary, specially for migration purposes") public void setResidenceDistrict(final String district) { getOrCreateResidence().setDistrict(district); } @Linkare(author = "Paulo Zenida", comments = "Necessary, specially for migration purposes") public void setResidenceDistrictSubdivision(final String districtSubdivision) { getOrCreateResidence().setDistrictSubdivision(districtSubdivision); } @Linkare(author = "Paulo Zenida", comments = "Necessary, specially for migration purposes") public void setResidenceParish(final String parish) { getOrCreateResidence().setParish(parish); } }