public ActionForward fillPersonalInformation(
      ActionMapping mapping,
      ActionForm actionForm,
      HttpServletRequest request,
      HttpServletResponse response) {

    final IndividualCandidacyProcessBean bean = getIndividualCandidacyProcessBean();
    final ChoosePersonBean choosePersonBean = bean.getChoosePersonBean();
    request.setAttribute(getIndividualCandidacyProcessBeanName(), bean);
    bean.setPersonBean(
        new PersonBean(
            choosePersonBean.getName(),
            choosePersonBean.getIdentificationNumber(),
            choosePersonBean.getDocumentType(),
            choosePersonBean.getDateOfBirth()));

    // bean.getPersonBean().setAddress("Some address");
    // bean.getPersonBean().setArea("Some area");
    // bean.getPersonBean().setAreaOfAreaCode("2345-2341");
    // bean.getPersonBean().setCountryOfBirth(Country.readByTwoLetterCode("AF"));
    // bean.getPersonBean().setCountryOfResidence(Country.readByTwoLetterCode("PT"));
    // bean.getPersonBean().setDistrictOfBirth("Some district of birth");
    // bean.getPersonBean().setDistrictOfResidence("Some district of residence");
    // bean.getPersonBean().setDistrictSubdivisionOfBirth("district subdivision of birth");
    // bean.getPersonBean().setDistrictSubdivisionOfResidence("district subdivision of residence");
    // bean.getPersonBean().setGender(Gender.MALE);
    // bean.getPersonBean().setPhone("12313234132");
    // bean.getPersonBean().setNationality(Country.readByTwoLetterCode("AF"));
    // bean.getPersonBean().setAreaCode("1223-123");

    bean.removeChoosePersonBean();
    return mapping.findForward("fill-personal-information");
  }
 public ActionForward searchAgainPersonForCandidacy(
     ActionMapping mapping,
     ActionForm actionForm,
     HttpServletRequest request,
     HttpServletResponse response) {
   final IndividualCandidacyProcessBean bean = getIndividualCandidacyProcessBean();
   request.setAttribute(getIndividualCandidacyProcessBeanName(), bean);
   bean.getChoosePersonBean().setFirstTimeSearch(true);
   bean.getChoosePersonBean().setPerson(null);
   RenderUtils.invalidateViewState();
   return mapping.findForward("prepare-create-new-process");
 }
  public ActionForward addConcludedHabilitationsEntry(
      ActionMapping mapping,
      ActionForm form,
      HttpServletRequest request,
      HttpServletResponse response) {
    IndividualCandidacyProcessBean bean = getIndividualCandidacyProcessBean();
    bean.addConcludedFormationBean();

    request.setAttribute(getIndividualCandidacyProcessBeanName(), bean);
    invalidateDocumentFileRelatedViewStates();

    return forwardTo(mapping, request);
  }
  public ActionForward removeConcludedHabilitationsEntry(
      ActionMapping mapping,
      ActionForm form,
      HttpServletRequest request,
      HttpServletResponse response) {
    IndividualCandidacyProcessBean bean = getIndividualCandidacyProcessBean();
    Integer index = getIntegerFromRequest(request, "removeIndex");
    bean.removeFormationConcludedBean(index);

    request.setAttribute(getIndividualCandidacyProcessBeanName(), bean);
    invalidateDocumentFileRelatedViewStates();

    return forwardTo(mapping, request);
  }
  public ActionForward prepareEditPersonalInformationForBindWithSelectedPerson(
      ActionMapping mapping,
      ActionForm actionForm,
      HttpServletRequest request,
      HttpServletResponse response) {
    IndividualCandidacyProcessBean bean = getIndividualCandidacyProcessBean();
    request.setAttribute(
        getIndividualCandidacyProcessBeanName(), getIndividualCandidacyProcessBean());

    if (bean.getChoosePersonBean().getPerson() == null) {
      addActionMessage(request, "error.candidacy.select.person.for.bind");
      return mapping.findForward("select-person-for-bind-with-candidacy");
    }

    return mapping.findForward("edit-personal-information-for-bind");
  }
  public ActionForward fillCandidacyInformation(
      ActionMapping mapping,
      ActionForm actionForm,
      HttpServletRequest request,
      HttpServletResponse response) {

    final IndividualCandidacyProcessBean bean = getIndividualCandidacyProcessBean();
    request.setAttribute(getIndividualCandidacyProcessBeanName(), bean);

    if (!StringUtils.isEmpty(bean.getPersonBean().getSocialSecurityNumber())) {
      Party existingSocialSecurityNumberParty =
          Person.readByContributorNumber(bean.getPersonBean().getSocialSecurityNumber());

      if (existingSocialSecurityNumberParty != null
          && existingSocialSecurityNumberParty != bean.getPersonBean().getPerson()) {
        // found person with same contributor number
        addActionMessage(request, "error.party.existing.contributor.number");
        return mapping.findForward("fill-personal-information");
      }
    }

    try {
      DegreeOfficePublicCandidacyHashCode candidacyHashCode =
          DegreeOfficePublicCandidacyHashCodeOperations.getUnusedOrCreateNewHashCode(
              getProcessType(), getParentProcess(request), bean.getPersonBean().getEmail());
      bean.setPublicCandidacyHashCode(candidacyHashCode);
    } catch (HashCodeForEmailAndProcessAlreadyBounded e) {
      addActionMessage(request, "error.candidacy.hash.code.already.bounded");
      return mapping.findForward("fill-personal-information");
    }

    return mapping.findForward("fill-candidacy-information");
  }
  public ActionForward selectPersonForCandidacy(
      ActionMapping mapping,
      ActionForm actionForm,
      HttpServletRequest request,
      HttpServletResponse response) {

    final IndividualCandidacyProcessBean bean = getIndividualCandidacyProcessBean();
    request.setAttribute(getIndividualCandidacyProcessBeanName(), bean);

    if (!bean.hasChoosenPerson()) {
      addActionMessage(request, "error.candidacy.must.select.any.person");
      return mapping.findForward("prepare-create-new-process");
    }

    if (existsIndividualCandidacyProcessForDocumentId(
        request,
        bean.getChoosePersonBean().getPerson().getIdDocumentType(),
        bean.getChoosePersonBean().getPerson().getDocumentIdNumber())) {
      addActionMessage(request, "error.candidacy.already.exists.for.this.person");
      return mapping.findForward("prepare-create-new-process");
    }

    bean.setPersonBean(new PersonBean(bean.getChoosePersonBean().getPerson()));
    bean.removeChoosePersonBean();
    return mapping.findForward("fill-personal-information");
  }
  public ActionForward searchPersonForCandidacy(
      ActionMapping mapping,
      ActionForm actionForm,
      HttpServletRequest request,
      HttpServletResponse response) {

    final IndividualCandidacyProcessBean bean = getIndividualCandidacyProcessBean();
    request.setAttribute(getIndividualCandidacyProcessBeanName(), bean);

    final ChoosePersonBean choosePersonBean = bean.getChoosePersonBean();

    if (!choosePersonBean.hasPerson()) {
      if (choosePersonBean.isFirstTimeSearch()) {
        final Collection<Person> persons =
            Person.findPersonByDocumentID(choosePersonBean.getIdentificationNumber());
        choosePersonBean.setFirstTimeSearch(false);
        if (showSimilarPersons(choosePersonBean, persons)) {
          RenderUtils.invalidateViewState();
          return mapping.findForward("prepare-create-new-process");
        }
      }
      bean.setPersonBean(
          new PersonBean(
              choosePersonBean.getName(),
              choosePersonBean.getIdentificationNumber(),
              choosePersonBean.getDocumentType(),
              choosePersonBean.getDateOfBirth()));

      // bean.getPersonBean().setAddress("Some address");
      // bean.getPersonBean().setArea("Some area");
      // bean.getPersonBean().setAreaOfAreaCode("2345-2341");
      // //bean.getPersonBean().setCountryOfBirth(Country.readByTwoLetterCode("AF"));
      // bean.getPersonBean().setCountryOfResidence(Country.readByTwoLetterCode("PT"));
      // bean.getPersonBean().setDistrictOfBirth("Some district of birth");
      // bean.getPersonBean().setDistrictOfResidence("Some district of residence");
      // bean.getPersonBean().setDistrictSubdivisionOfBirth("district subdivision of birth");
      // bean.getPersonBean().setDistrictSubdivisionOfResidence("district subdivision of
      // residence");
      // bean.getPersonBean().setGender(Gender.MALE);
      // bean.getPersonBean().setPhone("12313234132");
      // bean.getPersonBean().setNationality(Country.readByTwoLetterCode("AF"));
      // bean.getPersonBean().setAreaCode("1223-123");

      return mapping.findForward("fill-personal-information");

    } else {
      bean.setPersonBean(new PersonBean(bean.getChoosePersonBean().getPerson()));

      // bean.getPersonBean().setAddress("Some address");
      // bean.getPersonBean().setArea("Some area");
      // bean.getPersonBean().setAreaOfAreaCode("2345-2341");
      // bean.getPersonBean().setCountryOfBirth(Country.readByTwoLetterCode("AF"));
      // bean.getPersonBean().setCountryOfResidence(Country.readByTwoLetterCode("PT"));
      // bean.getPersonBean().setDistrictOfBirth("Some district of birth");
      // bean.getPersonBean().setDistrictOfResidence("Some district of residence");
      // bean.getPersonBean().setDistrictSubdivisionOfBirth("district subdivision of birth");
      // bean.getPersonBean().setDistrictSubdivisionOfResidence("district subdivision of
      // residence");
      // bean.getPersonBean().setGender(Gender.MALE);
      // bean.getPersonBean().setPhone("12313234132");
      // bean.getPersonBean().setNationality(Country.readByTwoLetterCode("AF"));
      // bean.getPersonBean().setAreaCode("1223-123");

      return mapping.findForward("fill-personal-information");
    }
  }