Example #1
0
  /**
   * Executes the block main action
   *
   * @param dataSet a value of type 'DataSet'
   * @return the port to go to the next block
   */
  public Port after(UserInfoInterface userInfo, ProcessData procData) {
    Port outPort;

    String login = userInfo.getUtilizador();

    try {
      String sCondition = null;
      boolean bEvalResult = false;

      sCondition = this.getAttribute("condition");

      if (StringUtils.isEmpty(sCondition)) {
        Logger.warning(
            login,
            this,
            "after",
            procData.getSignature() + "empty condition to evaluate!! Assuming false");
        bEvalResult = false;
      } else {
        try {
          bEvalResult = procData.query(userInfo, sCondition);
          Logger.debug(login, this, "after", sCondition + " evaluated " + bEvalResult);
        } catch (Exception ei) {
          bEvalResult = false;
          Logger.error(
              login,
              this,
              "after",
              procData.getSignature()
                  + "caught exception evaluation condition (assuming false): "
                  + sCondition,
              ei);
        }
      }

      if (bEvalResult) {
        outPort = portTrue;
      } else {
        outPort = portFalse;
      }

      this.addToLog(
          "Evaluated '" + sCondition + "' to '" + bEvalResult + "', using " + outPort.getName());
    } catch (Exception e) {
      Logger.error(
          login, this, "after", procData.getSignature() + "caught exception: " + e.getMessage(), e);
      outPort = portFalse;
    }

    this.addToLog("Using '" + outPort.getName() + "';");
    this.saveLogs(userInfo, procData, this);

    return outPort;
  }
Example #2
0
  public void generate(
      UserInfoInterface userInfo, ProcessData process, ParserContext ch, Field field, boolean even)
      throws SAXException {
    Logger.info(userInfo.getUtilizador(), this, "generate", "Generating from template");
    // TODO if disabled, return;

    String template = field.getProperties().get("template");

    IFlowData flow = BeanFactory.getFlowHolderBean().getFlow(userInfo, process.getFlowId());
    Form formTemplate = null;
    if (flow != null) formTemplate = flow.getFormTemplate(template);
    if (null == formTemplate) {
      // ignore or throw error?
      Logger.error(
          userInfo.getUtilizador(),
          this,
          "generate",
          "Could not parse template: '" + template + "'");
      ch.startElement("field");
      ch.addElement("type", "message");
      ch.addElement("text", "Template de formulário inválida");
      ch.addElement("even_field", String.valueOf(even));
      ch.endElement("field");
      return;
    }

    // allways get first tab
    Tab tab = formTemplate.getTabs().get(0);
    for (Field subField : tab.getFields()) {
      IWidget subfieldWidget = newWidget(subField.getType());
      subfieldWidget.generate(userInfo, process, ch, subField, even);
      even = !even;
    }
  }
  /**
   * Executes the block main action
   *
   * @param dataSet a value of type 'DataSet'
   * @return the port to go to the next block
   */
  public Port after(UserInfoInterface userInfo, ProcessData procData) {
    Port outPort = portFalse;

    try {

      String sLogin = null;
      String sPass = null;

      sLogin = this.getAttribute(LOGIN_ATTR);
      sLogin = procData.transform(userInfo, sLogin);

      try {
        sPass = procData.transform(userInfo, this.getAttribute(PASS_ATTR));
      } catch (Exception ee) {
      }

      AuthProfile ap = BeanFactory.getAuthProfileBean();

      boolean bOk = ap.checkUser(sLogin, sPass);

      Logger.info(
          userInfo.getUtilizador(),
          this,
          "after",
          "["
              + procData.getFlowId()
              + ","
              + procData.getPid()
              + ","
              + procData.getSubPid()
              + "] "
              + "checked authentication for "
              + sLogin
              + ": "
              + bOk);

      if (bOk) {
        outPort = portTrue;
      } else {
        outPort = portFalse;
      }
    } catch (Exception e) {
      Logger.error(
          userInfo.getUtilizador(),
          this,
          "after",
          procData.getSignature(this.getId()) + "Exception caught: " + e.getMessage());
      e.printStackTrace();
    }

    return outPort;
  }