Example #1
0
  public void validateNodes() {
    for (Node node : listNode) {

      FormEntity form = (FormEntity) node.getElement().getData();
      form.setFormError(false);
      form.setErrorDescription("");

      if (form.getFormType().getName().equalsIgnoreCase(Constants.FORM_TYPE_PROMPT_COLLECT)) {
        boolean foundTarget = false;
        for (Node nodeTarget : node.getListTarget()) {
          if (!(nodeTarget
                  .getForm()
                  .getFormType()
                  .getName()
                  .equalsIgnoreCase(Constants.FORM_TYPE_NOINPUT)
              || nodeTarget
                  .getForm()
                  .getFormType()
                  .getName()
                  .equalsIgnoreCase(Constants.FORM_TYPE_NOMATCH))) {
            foundTarget = true;
          }
        }
        if (!foundTarget) {
          form.setFormError(true);
          form.setErrorDescription("Output is mandatory");
          continue;
        }
      }

      FormEntity aux =
          ServicesFactory.getInstance().getFormService().getByName(form.getName(), true);

      if (aux != null && !aux.getId().equals(form.getId())) {
        form.setFormError(true);
        form.setErrorDescription(
            "Name " + form.getName() + " already assigned to another Element in another Flow");
        continue;
      }

      int startFlow = 0;
      boolean stopFlow = false;
      for (Node nodeAux : listNode) {
        FormEntity formAux = (FormEntity) nodeAux.getElement().getData();
        if (!formAux.getId().equalsIgnoreCase(form.getId())
            && formAux.getName().equalsIgnoreCase(form.getName())
            && !(formAux.getFormType().getName().equalsIgnoreCase(Constants.FORM_TYPE_CHOICE)
                || formAux.getFormType().getName().equalsIgnoreCase(Constants.FORM_TYPE_NOINPUT)
                || formAux.getFormType().getName().equalsIgnoreCase(Constants.FORM_TYPE_NOMATCH))) {
          form.setFormError(true);
          form.setErrorDescription(
              "Name " + form.getName() + " already assigned to another Element.");
          continue;
        }
        if (formAux.getFormType().getName().equalsIgnoreCase(Constants.FORM_TYPE_ANSWER)) {
          startFlow++;
        }
        if (formAux.getFormType().getName().equalsIgnoreCase(Constants.FORM_TYPE_DISCONNECT)
            || formAux.getFormType().getName().equalsIgnoreCase(Constants.FORM_TYPE_TRANSFER)
            || formAux.getFormType().getName().equalsIgnoreCase(Constants.FORM_TYPE_RETURN)) {
          stopFlow = true;
        }
      }

      if (validateFormByType(form)) {
        continue;
      }

      if (form.getFormType().getMandatoryInput() == 1 && node.getListSource().size() == 0) {
        form.setFormError(true);
        form.setErrorDescription("Input is mandatory");
        continue;
      }
      if (form.getFormType().getMandatoryOutput() == 1 && node.getListTarget().size() == 0) {
        form.setFormError(true);
        form.setErrorDescription("Output is mandatory");
        continue;
      }
      if (startFlow == 0) {
        form.setFormError(true);
        form.setErrorDescription("You have to start the flow with the node type 'Answer'");
        continue;
      } else if (startFlow > 1) {
        form.setFormError(true);
        form.setErrorDescription("Node type 'Answer' is allowed only ONE per flow");
        continue;
      }

      if (!stopFlow) {
        form.setFormError(true);
        form.setErrorDescription(
            "You have to finish the flow with the node type 'Disconnect', 'Transfer' or 'Return'");
        continue;
      }
    }
  }