コード例 #1
0
  private BusinessPartnerCategoryData getEditVariables(Connection con, VariablesSecureApp vars)
      throws IOException, ServletException {
    BusinessPartnerCategoryData data = new BusinessPartnerCategoryData();
    ServletException ex = null;
    try {
      data.adOrgId = vars.getRequiredGlobalVariable("inpadOrgId", windowId + "|AD_Org_ID");
      data.adOrgIdr = vars.getStringParameter("inpadOrgId_R");
      data.cBpGroupId = vars.getRequestGlobalVariable("inpcBpGroupId", windowId + "|C_BP_Group_ID");
      data.value = vars.getStringParameter("inpvalue");
      data.name = vars.getRequiredStringParameter("inpname");
      data.description = vars.getStringParameter("inpdescription");
      data.isactive = vars.getStringParameter("inpisactive", "N");
      data.isdefault = vars.getStringParameter("inpisdefault", "N");
      data.adClientId = vars.getRequiredGlobalVariable("inpadClientId", windowId + "|AD_Client_ID");
      data.createdby = vars.getUser();
      data.updatedby = vars.getUser();
      data.adUserClient = Utility.getContext(this, vars, "#User_Client", windowId, accesslevel);
      data.adOrgClient =
          Utility.getContext(this, vars, "#AccessibleOrgTree", windowId, accesslevel);
      data.updatedTimeStamp = vars.getStringParameter("updatedTimestamp");

      if (data.value.equals(""))
        data.value =
            Utility.getDocumentNoConnection(con, this, vars.getClient(), "C_BP_Group", true);
    } catch (ServletException e) {
      vars.setEditionData(tabId, data);
      throw e;
    }
    // Behavior with exception for numeric fields is to catch last one if we have multiple ones
    if (ex != null) {
      vars.setEditionData(tabId, data);
      throw ex;
    }
    return data;
  }
コード例 #2
0
  private int saveRecord(VariablesSecureApp vars, OBError myError, char type)
      throws IOException, ServletException {
    BusinessPartnerCategoryData data = null;
    int total = 0;
    if (org.openbravo.erpCommon.utility.WindowAccessData.hasReadOnlyAccess(
        this, vars.getRole(), tabId)) {
      OBError newError =
          Utility.translateError(
              this,
              vars,
              vars.getLanguage(),
              Utility.messageBD(this, "NoWriteAccess", vars.getLanguage()));
      myError.setError(newError);
      vars.setMessage(tabId, myError);
    } else {
      Connection con = null;
      try {
        con = this.getTransactionConnection();
        data = getEditVariables(con, vars);
        data.dateTimeFormat = vars.getSessionValue("#AD_SqlDateTimeFormat");
        String strSequence = "";
        if (type == 'I') {
          strSequence = SequenceIdData.getUUID();
          if (log4j.isDebugEnabled()) log4j.debug("Sequence: " + strSequence);
          data.cBpGroupId = strSequence;
        }
        if (Utility.isElementInList(
                Utility.getContext(this, vars, "#User_Client", windowId, accesslevel),
                data.adClientId)
            && Utility.isElementInList(
                Utility.getContext(this, vars, "#User_Org", windowId, accesslevel), data.adOrgId)) {
          if (type == 'I') {
            total = data.insert(con, this);
          } else {
            // Check the version of the record we are saving is the one in DB
            if (BusinessPartnerCategoryData.getCurrentDBTimestamp(this, data.cBpGroupId)
                .equals(vars.getStringParameter("updatedTimestamp"))) {
              total = data.update(con, this);
            } else {
              myError.setMessage(
                  Replace.replace(
                      Replace.replace(
                          Utility.messageBD(this, "SavingModifiedRecord", vars.getLanguage()),
                          "\\n",
                          "<br/>"),
                      "&quot;",
                      "\""));
              myError.setType("Error");
              vars.setSessionValue(tabId + "|concurrentSave", "true");
            }
          }

        } else {
          OBError newError =
              Utility.translateError(
                  this,
                  vars,
                  vars.getLanguage(),
                  Utility.messageBD(this, "NoWriteAccess", vars.getLanguage()));
          myError.setError(newError);
        }
        releaseCommitConnection(con);
      } catch (Exception ex) {
        OBError newError = Utility.translateError(this, vars, vars.getLanguage(), ex.getMessage());
        myError.setError(newError);
        try {
          releaseRollbackConnection(con);
        } catch (final Exception e) { // do nothing
        }
      }

      if (myError.isEmpty() && total == 0) {
        OBError newError =
            Utility.translateError(this, vars, vars.getLanguage(), "@CODE=DBExecuteError");
        myError.setError(newError);
      }
      vars.setMessage(tabId, myError);

      if (!myError.isEmpty()) {
        if (data != null) {
          if (type == 'I') {
            data.cBpGroupId = "";
          } else {

          }
          vars.setEditionData(tabId, data);
        }
      } else {
        vars.setSessionValue(windowId + "|C_BP_Group_ID", data.cBpGroupId);
      }
    }
    return total;
  }