private void checkNeededSchemas(
      HttpServletRequest request, ResearchResult result, ResultParticipationCreationBean bean) {
    String resultParticipationsSchema = "resultParticipation.withoutRole";
    String createResultParticipationSchema = "resultParticipation.creation";

    if ((bean.getParticipator() != null
            || (bean.getParticipatorName() != null && bean.getParticipatorName().length() > 0))
        && (bean.isBeanExternal() || bean.isUnitExternal())) {
      createResultParticipationSchema = "resultParticipation.fullCreation";
    }

    // Defining schemas with roles
    if (result.getIsPossibleSelectPersonRole()) {
      resultParticipationsSchema = "resultParticipation.full";
      if (!bean.isBeanExternal()) {
        createResultParticipationSchema = "resultParticipation.creationWithRole";
      } else {
        if (bean.getParticipator() == null) {
          if (bean.getParticipatorName().length() == 0) {
            createResultParticipationSchema = "resultParticipation.creationWithRole";
          } else {
            createResultParticipationSchema = "resultParticipation.fullCreationWithRole";
          }
        } else {
          bean.setOrganization(
              bean.getParticipator().getPerson().getExternalContract().getInstitutionUnit());
          createResultParticipationSchema = "resultParticipation.creationWithRole";
        }
      }
    }

    createResultParticipationSchema += (bean.isBeanExternal()) ? ".external" : ".internal";

    request.setAttribute("listSchema", resultParticipationsSchema);
    request.setAttribute("createSchema", createResultParticipationSchema);
  }
  public ActionForward create(
      ActionMapping mapping,
      ActionForm form,
      HttpServletRequest request,
      HttpServletResponse response)
      throws FenixServiceException {
    final ResultParticipationCreationBean bean = getRenderedObject("bean");

    request.setAttribute("bean", bean);
    try {
      if (bean.getParticipator() == null) {
        if (bean.isBeanExternal()) {
          request.setAttribute("name", bean.getParticipatorName());
          request.setAttribute("needToCreatePerson", true);
          schemasStateAutomaton(request, bean.getResult(), bean, false);
        } else {
          throw new DomainException("error.label.invalidNameForPersonInSelection");
        }
      } else {
        createParticipation(bean);
        schemasStateAutomaton(request, bean.getResult(), bean, false);
      }
    } catch (Exception e) {
      final ActionForward defaultForward = backToResultList(mapping, form, request, response);
      if (bean != null) {
        bean.reset();
      }
      return processException(request, mapping, defaultForward, e);
    }

    // bean.reset();
    checkRolesInCreation(request);
    request.setAttribute("bean", bean);
    request.setAttribute("result", bean.getResult());
    RenderUtils.invalidateViewState();
    return mapping.findForward("editParticipation");
  }
  public ActionForward prepareCreateParticipator(
      ActionMapping mapping,
      ActionForm form,
      HttpServletRequest request,
      HttpServletResponse response)
      throws FenixServiceException {

    ResearchResult result = getResultFromRequest(request);
    ResultParticipationCreationBean bean =
        (ResultParticipationCreationBean)
            RenderUtils.getViewState("bean").getMetaObject().getObject();
    bean.setUnitParticipationType(ParticipationType.EXTERNAL);

    setResParticipationRequestAttributes(request, result, bean);
    request.setAttribute("bean", bean);
    if (bean.getParticipator() != null) {
      request.setAttribute("needToCreatePerson", true);
      addActionMessage(request, "label.cannot.select.person.to.create.new");
      return mapping.findForward("editParticipation");
    }
    request.setAttribute("duringCreation", true);
    request.setAttribute("createUnit", true);
    return mapping.findForward("editParticipation");
  }