예제 #1
0
 @Override
 protected void redirectToCAS(
     final CasConfig casConfig,
     final HttpServletRequest request,
     final HttpServletResponse response)
     throws IOException, ServletException {
   if (UserView.getUser() == null) {
     String pendingRequest = request.getParameter("pendingRequest");
     if (pendingRequest == null) {
       pendingRequest = (String) request.getAttribute("pendingRequest");
     }
     final String barraAsAuthBroker =
         PropertiesManager.getProperty("barra.as.authentication.broker");
     final boolean useBarraAsAuthenticationBroker =
         barraAsAuthBroker != null && barraAsAuthBroker.equals("true");
     final String serviceString =
         encodeUrl(RequestUtils.generateRedirectLink(casConfig.getServiceUrl(), pendingRequest));
     String casLoginUrl = "";
     if (useBarraAsAuthenticationBroker) {
       final String barraLoginUrl = PropertiesManager.getProperty("barra.loginUrl");
       casLoginUrl += barraLoginUrl;
       casLoginUrl += "?next=";
     }
     casLoginUrl += casConfig.getCasLoginUrl();
     final String casLoginString = casLoginUrl + "?service=" + serviceString;
     response.sendRedirect(casLoginString);
   } else {
     response.sendRedirect(request.getContextPath() + "/home.do");
   }
 }
 @Atomic
 public static void store(CreditNote source, String filename, byte[] content) {
   if (PropertiesManager.getBooleanProperty(CONFIG_DSPACE_DOCUMENT_STORE)) {
     new CreditNoteGeneratedDocument(
         source, source.getReceipt().getPerson(), AccessControl.getPerson(), filename, content);
   }
 }
예제 #3
0
 @Override
 public void setDatabaseUrl() throws ExcepcaoPersistencia {
   if (databaseUrl == null) {
     String DBUserName = PropertiesManager.getProperty(connectionProperties.userNamePropertyName);
     String DBUserPass = PropertiesManager.getProperty(connectionProperties.userPassPropertyName);
     String DBUrl = PropertiesManager.getProperty(connectionProperties.urlPropertyName);
     if (DBUserName == null || DBUserPass == null || DBUrl == null) {
       throw new ExcepcaoPersistencia();
     }
     StringBuilder stringBuffer = new StringBuilder();
     stringBuffer.append("jdbc:oracle:thin:");
     stringBuffer.append(DBUserName);
     stringBuffer.append("/");
     stringBuffer.append(DBUserPass);
     stringBuffer.append("@");
     stringBuffer.append(DBUrl);
     databaseUrl = stringBuffer.toString();
   }
 }
/**
 * INFO: when extending this class pay attention to the following aspects
 *
 * <p>Common methods to all candidacies: SearchPersonForCandidacy (used to select/create person for
 * candidacy), FillCandidacyInformation (forward to candidacy page), CreateNewProcess (used to
 * create a new process), CancelCandidacy (must exist an activity with this name in
 * IndividualCandidacyProcess)
 *
 * <p>Common methods to candidacies with precedent degree information:
 * FillPrecedentInformationPostback (used to select between internal and external information),
 * FillPrecedentInformationStudentCurricularPlanPostback (used to set choosed precedent
 * studentCurricularPlan)
 *
 * <p>Must configure the following forwards: intro (common value:
 * /candidacy/mainCandidacyProcess.jsp), list-allowed-activities (common value:
 * /candidacy/listIndividualCandidacyActivities.jsp), prepare-create-new-process (common value:
 * /candidacy/selectPersonForCandidacy.jsp), fill-personal-information (common value:
 * /candidacy/fillPersonalInformation.jsp), fill-candidacy-information (jsp used by each candidacy),
 * cancel-candidacy (common value: /candidacy/cancelCandidacy.jsp)
 */
public abstract class IndividualCandidacyProcessDA extends CaseHandlingDispatchAction {

  private static final String SIBS_ENTITY_CODE = PropertiesManager.getProperty("sibs.entityCode");

  protected abstract Class getParentProcessType();

  @Override
  public ActionForward execute(
      ActionMapping mapping,
      ActionForm actionForm,
      HttpServletRequest request,
      HttpServletResponse response)
      throws Exception {
    setParentProcess(request);
    request.setAttribute("sibsEntityCode", SIBS_ENTITY_CODE);

    return super.execute(mapping, actionForm, request, response);
  }

  protected void setParentProcess(HttpServletRequest request) {
    final Integer parentProcessId = getIntegerFromRequest(request, "parentProcessId");
    if (parentProcessId != null) {
      request.setAttribute("parentProcess", rootDomainObject.readProcessByOID(parentProcessId));
    } else {
      setProcess(request);
      if (hasProcess(request)) {
        request.setAttribute("parentProcess", getProcess(request).getCandidacyProcess());
      }
    }
  }

  protected CandidacyProcess getParentProcess(final HttpServletRequest request) {
    return (CandidacyProcess) request.getAttribute("parentProcess");
  }

  protected boolean hasParentProcess(final HttpServletRequest request) {
    return getParentProcess(request) != null;
  }

  @Override
  public ActionForward listProcesses(
      ActionMapping mapping,
      ActionForm form,
      HttpServletRequest request,
      HttpServletResponse response) {
    setMainCandidacyProcessInformation(request, getParentProcess(request));
    return mapping.findForward("intro");
  }

  @Override
  protected IndividualCandidacyProcess getProcess(HttpServletRequest request) {
    return (IndividualCandidacyProcess) super.getProcess(request);
  }

  /** Set context information used by intro page */
  protected void setMainCandidacyProcessInformation(
      final HttpServletRequest request, final CandidacyProcess process) {
    request.setAttribute("process", process);
    request.setAttribute("processName", getParentProcessType().getSimpleName());
    request.setAttribute("canCreateProcess", canCreateProcess(getParentProcessType().getName()));
    request.setAttribute(
        "processActivities", process.getAllowedActivities(AccessControl.getUserView()));
    request.setAttribute("canCreateChildProcess", canCreateProcess(getProcessType().getName()));
    request.setAttribute("childProcessName", getProcessType().getSimpleName());
    request.setAttribute("childProcesses", process.getChildProcesses());
    request.setAttribute(
        "executionIntervalId", process.getCandidacyExecutionInterval().getIdInternal());
    request.setAttribute(
        "executionIntervals",
        ExecutionInterval.readExecutionIntervalsWithCandidacyPeriod(
            process.getCandidacyPeriod().getClass()));
  }

  protected List<Activity> getAllowedActivities(final IndividualCandidacyProcess process) {
    List<Activity> activities = process.getAllowedActivities(AccessControl.getUserView());
    ArrayList<Activity> resultActivities = new ArrayList<Activity>();

    for (Activity activity : activities) {
      if (activity.isVisibleForAdminOffice()) {
        resultActivities.add(activity);
      }
    }

    return resultActivities;
  }

  /** Represents the id of the bean used in candidacy pages */
  protected String getIndividualCandidacyProcessBeanName() {
    return "individualCandidacyProcessBean";
  }

  protected IndividualCandidacyProcessBean getIndividualCandidacyProcessBean() {
    return getRenderedObject(getIndividualCandidacyProcessBeanName());
  }

  @Override
  public ActionForward prepareCreateNewProcess(
      ActionMapping mapping,
      ActionForm form,
      HttpServletRequest request,
      HttpServletResponse response) {
    if (!hasParentProcess(request)) {
      addActionMessage(request, "error.IndividualCandidacy.invalid.candidacyProcess");
      return listProcesses(mapping, form, request, response);
    } else {
      setStartInformation(form, request, response);

      /*
       * 06/05/2009 - Skip search Person and step to personal data form. A
       * person will not be created
       *
       * return mapping.findForward("prepare-create-new-process");
       */
      return mapping.findForward("prepare-create-new-process");
      // return mapping.findForward("fill-personal-information");
    }
  }

  /**
   * Used by {@link
   * #prepareCreateNewProcess(ActionMapping,ActionForm,HttpServletRequest,HttpServletResponse)}
   * method to init request with necessary information to start creating a new process
   */
  protected abstract void setStartInformation(
      final ActionForm form, final HttpServletRequest request, final HttpServletResponse response);

  public ActionForward prepareCreateNewProcessInvalid(
      ActionMapping mapping,
      ActionForm actionForm,
      HttpServletRequest request,
      HttpServletResponse response) {
    request.setAttribute(
        getIndividualCandidacyProcessBeanName(), getIndividualCandidacyProcessBean());
    return mapping.findForward("prepare-create-new-process");
  }

  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");
    }
  }

  protected boolean showSimilarPersons(
      final ChoosePersonBean choosePersonBean, final Collection<Person> persons) {
    if (!persons.isEmpty()) {
      return true;
    }
    return !Person.findByDateOfBirth(
            choosePersonBean.getDateOfBirth(),
            Person.findInternalPersonMatchingFirstAndLastName(choosePersonBean.getName()))
        .isEmpty();
  }

  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 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 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 fillPersonalInformationInvalid(
      ActionMapping mapping,
      ActionForm actionForm,
      HttpServletRequest request,
      HttpServletResponse response) {
    request.setAttribute(
        getIndividualCandidacyProcessBeanName(), getIndividualCandidacyProcessBean());
    return mapping.findForward("fill-personal-information");
  }

  public ActionForward fillCommonCandidacyInformation(
      ActionMapping mapping,
      ActionForm actionForm,
      HttpServletRequest request,
      HttpServletResponse response) {
    final IndividualCandidacyProcessBean bean = getIndividualCandidacyProcessBean();
    request.setAttribute(getIndividualCandidacyProcessBeanName(), bean);
    return mapping.findForward("fill-common-candidacy-information");
  }

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

  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 fillCandidacyInformationInvalid(
      ActionMapping mapping,
      ActionForm actionForm,
      HttpServletRequest request,
      HttpServletResponse response) {
    request.setAttribute(
        getIndividualCandidacyProcessBeanName(), getIndividualCandidacyProcessBean());
    return mapping.findForward("fill-candidacy-information");
  }

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

    // assuming that when using this method each individual candidacy bean
    // extends IndividualCandidacyProcessWithPrecedentDegreeInformationBean
    final IndividualCandidacyProcessWithPrecedentDegreeInformationBean bean =
        (IndividualCandidacyProcessWithPrecedentDegreeInformationBean)
            getIndividualCandidacyProcessBean();
    request.setAttribute(getIndividualCandidacyProcessBeanName(), bean);
    RenderUtils.invalidateViewState();

    if (bean.hasPrecedentDegreeType()) {
      if (bean.isExternalPrecedentDegreeType()) {
        bean.setPrecedentDegreeInformation(new PrecedentDegreeInformationBean());
      } else if (bean.hasPrecedentStudentCurricularPlan()) {
        createCandidacyPrecedentDegreeInformation(bean, bean.getPrecedentStudentCurricularPlan());
      } else {
        final List<StudentCurricularPlan> scps = bean.getPrecedentStudentCurricularPlans();
        if (scps.size() == 1) {
          createCandidacyPrecedentDegreeInformation(bean, scps.get(0));
          bean.setPrecedentStudentCurricularPlan(scps.get(0));
        }
      }
    }

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

  protected void createCandidacyPrecedentDegreeInformation(
      final IndividualCandidacyProcessWithPrecedentDegreeInformationBean bean,
      final StudentCurricularPlan studentCurricularPlan) {

    if (studentCurricularPlan.isBolonhaDegree()) {
      final CycleType cycleType;

      if (studentCurricularPlan.hasConcludedAnyInternalCycle()) {
        cycleType = studentCurricularPlan.getLastConcludedCycleCurriculumGroup().getCycleType();
      } else {
        cycleType = studentCurricularPlan.getLastOrderedCycleCurriculumGroup().getCycleType();
      }

      bean.setPrecedentDegreeInformation(
          PrecedentDegreeInformationBeanFactory.createBean(studentCurricularPlan, cycleType));
    } else {
      bean.setPrecedentDegreeInformation(
          PrecedentDegreeInformationBeanFactory.createBean(studentCurricularPlan));
    }
  }

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

    // assuming that when using this method each individual candidacy bean
    // extends IndividualCandidacyProcessWithPrecedentDegreeInformationBean
    final IndividualCandidacyProcessWithPrecedentDegreeInformationBean bean =
        (IndividualCandidacyProcessWithPrecedentDegreeInformationBean)
            getIndividualCandidacyProcessBean();
    request.setAttribute(getIndividualCandidacyProcessBeanName(), bean);

    if (bean.hasPrecedentStudentCurricularPlan()) {
      createCandidacyPrecedentDegreeInformation(bean, bean.getPrecedentStudentCurricularPlan());
    }

    RenderUtils.invalidateViewState();
    return mapping.findForward("fill-candidacy-information");
  }

  @Override
  public ActionForward createNewProcess(
      ActionMapping mapping,
      ActionForm form,
      HttpServletRequest request,
      HttpServletResponse response)
      throws FenixFilterException, FenixServiceException {
    try {
      request.setAttribute(
          "process",
          CreateNewProcess.run(getProcessType().getName(), getIndividualCandidacyProcessBean()));
    } catch (DomainException e) {
      addActionMessage(request, e.getMessage(), e.getArgs());
      request.setAttribute(
          getIndividualCandidacyProcessBeanName(), getIndividualCandidacyProcessBean());
      return mapping.findForward("fill-candidacy-information");
    }
    return listProcessAllowedActivities(mapping, form, request, response);
  }

  public ActionForward prepareExecuteCandidacyPayment(
      ActionMapping mapping,
      ActionForm actionForm,
      HttpServletRequest request,
      HttpServletResponse response) {
    if (!getProcess(request).isCandidacyInternal()) {
      return prepareExecuteBindPersonToCandidacy(mapping, actionForm, request, response);
    }

    return mapping.findForward("prepare-candidacy-payment");
  }

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

  public ActionForward executeCancelCandidacy(
      ActionMapping mapping,
      ActionForm actionForm,
      HttpServletRequest request,
      HttpServletResponse response)
      throws FenixFilterException, FenixServiceException {
    try {
      executeActivity(getProcess(request), "CancelCandidacy", null);
    } catch (DomainException e) {
      addActionMessage(request, e.getMessage(), e.getArgs());
      return mapping.findForward("cancel-candidacy");
    }
    return listProcessAllowedActivities(mapping, actionForm, request, response);
  }

  public ActionForward prepareExecuteEditDocuments(
      ActionMapping mapping,
      ActionForm actionForm,
      HttpServletRequest request,
      HttpServletResponse response) {
    final IndividualCandidacyProcess process = getProcess(request);
    request.setAttribute(getIndividualCandidacyProcessBeanName(), process);
    CandidacyProcessDocumentUploadBean uploadBean = new CandidacyProcessDocumentUploadBean();
    uploadBean.setIndividualCandidacyProcess(process);
    request.setAttribute("candidacyDocumentUploadBean", uploadBean);

    RenderUtils.invalidateViewState("individualCandidacyProcessBean.document");

    return mapping.findForward("prepare-edit-candidacy-documents");
  }

  public ActionForward uploadDocument(
      ActionMapping mapping,
      ActionForm actionForm,
      HttpServletRequest request,
      HttpServletResponse response)
      throws FenixFilterException, FenixServiceException, IOException {
    CandidacyProcessDocumentUploadBean uploadBean =
        (CandidacyProcessDocumentUploadBean)
            getObjectFromViewState("individualCandidacyProcessBean.document");
    try {
      IndividualCandidacyDocumentFile documentFile =
          createIndividualCandidacyDocumentFile(
              uploadBean,
              uploadBean
                  .getIndividualCandidacyProcess()
                  .getPersonalDetails()
                  .getDocumentIdNumber());
      uploadBean.setDocumentFile(documentFile);

      executeActivity(getProcess(request), "EditDocuments", uploadBean);
    } catch (DomainException e) {
      addActionMessage(request, e.getMessage(), e.getArgs());
    }

    return prepareExecuteEditDocuments(mapping, actionForm, request, response);
  }

  @Override
  public ActionForward listProcessAllowedActivities(
      ActionMapping mapping,
      ActionForm form,
      HttpServletRequest request,
      HttpServletResponse response) {
    final IndividualCandidacyProcess process = getProcess(request);
    request.setAttribute("activities", getAllowedActivities(process));
    return mapping.findForward("list-allowed-activities");
  }

  protected boolean hasInvalidViewState() {
    List<IViewState> viewStates =
        (List<IViewState>)
            RenderersRequestProcessorImpl.getCurrentRequest()
                .getAttribute(LifeCycleConstants.VIEWSTATE_PARAM_NAME);
    boolean valid = true;
    if (viewStates != null) {
      for (IViewState state : viewStates) {
        valid &= state.isValid();
      }
    }
    return valid;
  }

  protected abstract void prepareInformationForBindPersonToCandidacyOperation(
      HttpServletRequest request, IndividualCandidacyProcess process);

  public ActionForward prepareExecuteBindPersonToCandidacy(
      ActionMapping mapping,
      ActionForm actionForm,
      HttpServletRequest request,
      HttpServletResponse response) {
    IndividualCandidacyProcess individualCandidacyProcess = getProcess(request);
    prepareInformationForBindPersonToCandidacyOperation(request, individualCandidacyProcess);
    setProcess(request);

    return mapping.findForward("select-person-for-bind-with-candidacy");
  }

  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 prepareEditPersonalInformationForBindWithNewPerson(
      ActionMapping mapping,
      ActionForm actionForm,
      HttpServletRequest request,
      HttpServletResponse response) {
    request.setAttribute(
        getIndividualCandidacyProcessBeanName(), getIndividualCandidacyProcessBean());

    return mapping.findForward("edit-personal-information-for-bind");
  }

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

  public ActionForward bindPerson(
      ActionMapping mapping,
      ActionForm actionForm,
      HttpServletRequest request,
      HttpServletResponse response)
      throws FenixFilterException, FenixServiceException {
    try {
      executeActivity(
          getProcess(request), "BindPersonToCandidacy", getIndividualCandidacyProcessBean());
    } catch (DomainException e) {
      addActionMessage(request, e.getMessage(), e.getArgs());
      request.setAttribute(
          getIndividualCandidacyProcessBeanName(), getIndividualCandidacyProcessBean());
      return mapping.findForward("edit-personal-information-for-bind");
    }

    return prepareExecuteCandidacyPayment(mapping, actionForm, request, response);
  }

  protected IndividualCandidacyDocumentFile createIndividualCandidacyDocumentFile(
      CandidacyProcessDocumentUploadBean uploadBean, String documentIdNumber) throws IOException {
    return uploadBean.createIndividualCandidacyDocumentFile(
        getParentProcessType(), documentIdNumber);
  }

  public ActionForward executeChangeProcessCheckedState(
      ActionMapping mapping,
      ActionForm actionForm,
      HttpServletRequest request,
      HttpServletResponse response)
      throws FenixFilterException, FenixServiceException {
    try {
      executeActivity(
          getProcess(request), "ChangeProcessCheckedState", getIndividualCandidacyProcessBean());
    } catch (DomainException e) {
      addActionMessage(request, e.getMessage(), e.getArgs());
      request.setAttribute(
          getIndividualCandidacyProcessBeanName(), getIndividualCandidacyProcessBean());
      return mapping.findForward("change-process-checked-state");
    }

    return listProcessAllowedActivities(mapping, actionForm, request, response);
  }

  public ActionForward executeChangePaymentCheckedState(
      ActionMapping mapping,
      ActionForm actionForm,
      HttpServletRequest request,
      HttpServletResponse response)
      throws FenixFilterException, FenixServiceException {
    try {
      executeActivity(
          getProcess(request), "ChangePaymentCheckedState", getIndividualCandidacyProcessBean());
    } catch (DomainException e) {
      addActionMessage(request, e.getMessage(), e.getArgs());
      request.setAttribute(
          getIndividualCandidacyProcessBeanName(), getIndividualCandidacyProcessBean());
      return mapping.findForward("change-payment-checked-state");
    }

    return listProcessAllowedActivities(mapping, actionForm, request, response);
  }

  public ActionForward prepareExecuteRevertApplicationToStandBy(
      ActionMapping mapping,
      ActionForm actionForm,
      HttpServletRequest request,
      HttpServletResponse response)
      throws FenixFilterException, FenixServiceException {
    try {
      executeActivity(getProcess(request), "RevertApplicationToStandBy", null);
    } catch (DomainException e) {
      addActionMessage(request, e.getMessage(), e.getArgs());
      return listProcessAllowedActivities(mapping, actionForm, request, response);
    }

    return listProcessAllowedActivities(mapping, actionForm, request, response);
  }

  protected void invalidateDocumentFileRelatedViewStates() {
    List<IViewState> viewStates =
        new ArrayList<IViewState>(
            (List<IViewState>)
                RenderersRequestProcessorImpl.getCurrentRequest()
                    .getAttribute(LifeCycleConstants.VIEWSTATE_PARAM_NAME));
    if (viewStates != null) {
      for (IViewState state : viewStates) {
        if (state.getId().indexOf("individualCandidacyProcessBean.document.file") > -1) {
          RenderUtils.invalidateViewState(state.getId());
        }
      }
    }
  }

  protected boolean existsIndividualCandidacyProcessForDocumentId(
      HttpServletRequest request, IDDocumentType documentType, String identification) {
    return getParentProcess(request).getOpenChildProcessByDocumentId(documentType, identification)
        != null;
  }

  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);
  }

  private ActionForward forwardTo(ActionMapping mapping, HttpServletRequest request) {
    if (getFromRequest(request, "userAction").equals("createCandidacy")) {
      return mapping.findForward("fill-candidacy-information");
    } else if (getFromRequest(request, "userAction").equals("editCandidacyQualifications")) {
      return mapping.findForward("edit-candidacy-information");
    }

    return null;
  }

  public ActionForward revokeDocumentFile(
      ActionMapping mapping,
      ActionForm form,
      HttpServletRequest request,
      HttpServletResponse response)
      throws FenixFilterException, FenixServiceException {
    CandidacyProcessDocumentUploadBean uploadBean =
        (CandidacyProcessDocumentUploadBean)
            getObjectFromViewState("individualCandidacyProcessBean.document");
    String documentExternalId = request.getParameter("documentFileOid");
    IndividualCandidacyDocumentFile documentFile =
        IndividualCandidacyDocumentFile.fromExternalId(documentExternalId);
    uploadBean.setDocumentFile(documentFile);

    executeActivity(getProcess(request), "RevokeDocumentFile", uploadBean);

    return prepareExecuteEditDocuments(mapping, form, request, response);
  }

  public ActionForward prepareExecuteRejectCandidacy(
      ActionMapping mapping,
      ActionForm form,
      HttpServletRequest request,
      HttpServletResponse response)
      throws FenixFilterException, FenixServiceException {
    request.setAttribute(
        getIndividualCandidacyProcessBeanName(), getIndividualCandidacyProcessBean());

    return mapping.findForward("reject-candidacy");
  }

  public ActionForward executeRejectCandidacy(
      ActionMapping mapping,
      ActionForm form,
      HttpServletRequest request,
      HttpServletResponse response)
      throws FenixFilterException, FenixServiceException {
    try {
      executeActivity(getProcess(request), "RejectCandidacy", null);
    } catch (DomainException e) {
      addActionMessage(request, e.getMessage(), e.getArgs());
      return mapping.findForward("reject-candidacy");
    }
    return listProcessAllowedActivities(mapping, form, request, response);
  }
}