public abstract ActionForward fillPersonalDataInvalid(ActionMapping mapping, ActionForm form, HttpServletRequest request,
HttpServletResponse response);
protected ActionForward checkPersonalData(ActionMapping mapping, ActionForm form, HttpServletRequest request,
HttpServletResponse response) {
final PhdProgramCandidacyProcessBean bean = getCandidacyBean();
final PersonBean personBean = bean.getPersonBean();
// First case : get persons by document id value (not type)
final Collection<Person> personsFoundByDocumentId = Person.readByDocumentIdNumber(personBean.getDocumentIdNumber());
if (personsFoundByDocumentId.size() > 1) {
// There's more than one person, throw an error
addErrorMessage(request, "error.phd.public.candidacy.fill.personal.information.and.institution.id.more.than.one");
return fillPersonalDataInvalid(mapping, form, request, response);
}
final Person person = !personsFoundByDocumentId.isEmpty() ? personsFoundByDocumentId.iterator().next() : null;
if (!StringUtils.isEmpty(personBean.getFiscalCode())) {
final Party partyFoundBySocialSecurityNumber =
PartySocialSecurityNumber.readPartyBySocialSecurityNumber(personBean.getFiscalCode());
// Second case : person found by documentId and person found by
// social
// security number must be equal
if (person != null || partyFoundBySocialSecurityNumber != null) {
if (person != partyFoundBySocialSecurityNumber) {
addErrorMessage(request,
"error.phd.public.candidacy.fill.personal.information.and.institution.id.different.ssn");
return fillPersonalDataInvalid(mapping, form, request, response);
}
}
}
if (bean.hasInstitutionId()) {
Person personByIstId = Person.readPersonByUsername(bean.getInstitutionId());
if (personByIstId == null) {
addErrorMessage(request, "error.phd.public.candidacy.fill.personal.information.and.institution.id.noIstIdPerson");
return fillPersonalDataInvalid(mapping, form, request, response);
}
if (person != null && person != personByIstId) {
addErrorMessage(request,
"error.phd.public.candidacy.fill.personal.information.and.institution.id.different.istId");
return fillPersonalDataInvalid(mapping, form, request, response);
}
}
// check if person already exists
if (person != null) {
// Exists
// Third case person exists so the birth date must be equal and also
// ist Id if it has
if (person.getDateOfBirthYearMonthDay().equals(personBean.getDateOfBirth())) {
if (person.getUsername() != null && person.getUsername().equals(bean.getInstitutionId())) {
personBean.setPerson(person);
} else if (person.getUsername() == null && !bean.hasInstitutionId()) {
personBean.setPerson(person);
} else {
addErrorMessage(request,
"error.phd.public.candidacy.fill.personal.information.and.institution.id.different.istIds");
return fillPersonalDataInvalid(mapping, form, request, response);
}
} else {
addErrorMessage(request,
"error.phd.public.candidacy.fill.personal.information.and.institution.id.different.birthday");
return fillPersonalDataInvalid(mapping, form, request, response);
}
// Check if person has an application for this period
if (PhdProgramCandidacyProcess.hasOnlineApplicationForPeriod(person, bean.getPhdCandidacyPeriod())) {
addErrorMessage(request,
"error.phd.public.candidacy.fill.personal.information.and.institution.alreadyHasApplication");
return fillPersonalDataInvalid(mapping, form, request, response);
}
}