public ActionForward createParticipator(
      ActionMapping mapping,
      ActionForm form,
      HttpServletRequest request,
      HttpServletResponse response)
      throws FenixServiceException {

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

    if (bean.getOrganization() != null) {

      ExternalContract contract =
          InsertExternalPerson.run(
              new InsertExternalPerson.ServiceArguments(
                  bean.getParticipatorName(), bean.getOrganization()));
      bean.setParticipator(contract.getPerson().getPersonName());
      createParticipation(bean);
    } else {
      request.setAttribute("createUnit", true);
      request.setAttribute("duringCreation", true);
      request.setAttribute("bean", bean);
      setResParticipationRequestAttributes(request, result, bean);
      RenderUtils.invalidateViewState();
      return mapping.findForward("editParticipation");
    }
    return prepareEdit(mapping, form, request, response);
  }
  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");
  }