예제 #1
0
 public ChangeVO updateRow(
     int windowNo,
     int AD_Tab_ID,
     int queryResultID,
     int relRowNo,
     Map<String, String> context,
     boolean force) {
   if (context == null || context.size() == 0)
     return new ChangeVO(true, Msg.translate(m_context, "NoContext"));
   ArrayList<String[]> data = m_results.get(queryResultID);
   if (data == null || data.size() == 0)
     return new ChangeVO(true, Msg.translate(m_context, "CachedDataNotFound"));
   UITab tab = getTab(AD_Tab_ID);
   if (tab == null) {
     log.config("Not found AD_Tab_ID=" + AD_Tab_ID);
     return new ChangeVO(true, Msg.translate(m_context, "@NotFound@ @AD_Tab_ID@=" + AD_Tab_ID));
   }
   CContext ctx = new CContext(m_context.entrySet());
   ctx.addWindow(windowNo, context);
   ChangeVO retValue;
   if (force) retValue = tab.saveRow(ctx, windowNo, false, null);
   else retValue = tab.saveRow(ctx, windowNo, false, data.get(relRowNo));
   if (retValue.hasError()) return retValue;
   // Update Results
   String[] dataRow = retValue.rowData.clone();
   data.set(relRowNo, dataRow);
   postProcessChangeVO(retValue, windowNo, context, dataRow, tab);
   retValue.trxInfo = GridTab.getTrxInfo(tab.getTableName(), ctx, windowNo, tab.getTabNo());
   if (retValue.isRefreshAll()) {}
   return retValue;
 }
예제 #2
0
  /**
   * Save (Insert new) Row of Tab
   *
   * @param windowNo relative window
   * @param AD_Tab_ID tab
   * @param curRow insert after relative row number in results
   * @param context current (relevant) context of new row
   * @return error message or null
   */
  public ChangeVO insertRow(
      int windowNo, int AD_Tab_ID, int queryResultID, int curRow, Map<String, String> context) {
    if (context == null || context.size() == 0) return new ChangeVO(true, "No Context");
    UITab tab = getTab(AD_Tab_ID);
    if (tab == null) {
      log.config("Not found AD_Tab_ID=" + AD_Tab_ID);
      return new ChangeVO(true, "@NotFound@ @AD_Tab_ID@=" + AD_Tab_ID);
    }

    log.info("Line Amt:" + context.get("LineNetAmt"));
    CContext ctx = new CContext(m_context.entrySet());
    ctx.addWindow(windowNo, context);
    ChangeVO retValue = tab.saveRow(ctx, windowNo, true);
    if (retValue.hasError()) return retValue;
    // Update Results
    ArrayList<String[]> data = m_results.get(queryResultID);
    if (data == null) retValue.addError("Data Not Found");
    else {
      String[] dataRow = retValue.rowData;
      if (curRow >= data.size()) data.add(dataRow);
      else data.add(curRow, dataRow);
      retValue.trxInfo = GridTab.getTrxInfo(tab.getTableName(), ctx, windowNo, tab.getTabNo());
    }
    return retValue;
  } // insertRow
예제 #3
0
 /**
  * Retrieve results for Tab. If the from/to range does not exist, it returns existing rows
  *
  * @param queryResultID stored query identifier provided by client
  * @param fromRow from row first is 0
  * @param noRows number of rows
  * @return array of rows of array of field values or null if error. You get the columnNames via
  *     String[] columns = uiTab.getColumnNames();
  */
 public String[][] getResults(int queryResultID, int fromRow, int noRows) {
   if (noRows < 0) {
     log.config("Invalid: fromRow=" + fromRow + ",noRows" + noRows);
   } else if (noRows == 0) return new String[][] {};
   //
   ArrayList<String[]> resultAll = m_results.get(queryResultID);
   if (resultAll == null) {
     log.config("No Results for queryResultID=" + queryResultID);
     return null;
   }
   if (resultAll.size() < fromRow) {
     log.config(
         "Insufficient Results for queryResultID="
             + queryResultID
             + ", Length="
             + resultAll.size()
             + ", fromRow="
             + fromRow);
     return null;
   }
   // copy
   if (resultAll.size() < noRows) {
     log.config(
         "Insufficient Rows for queryResultID="
             + queryResultID
             + ", Length="
             + resultAll.size()
             + ", fromRow="
             + fromRow
             + ", noRows="
             + noRows);
     noRows = resultAll.size();
   }
   String[][] result = new String[noRows][];
   for (int i = 0; i < noRows; i++) {
     int index = i + fromRow;
     if (index >= resultAll.size()) break;
     result[i] = resultAll.get(index);
   }
   return result;
 } // getResult
예제 #4
0
 /**
  * Execute Query for Tab
  *
  * @param AD_Tab_ID tab
  * @param queryVO optional query
  * @param context record context for link columns and other variables
  * @param queryResultID stored query identifier provided by client
  * @return number of records or -1 if error
  */
 public int executeQuery(
     int AD_Tab_ID, QueryVO queryVO, HashMap<String, String> context, int queryResultID) {
   UITab tab = getTab(AD_Tab_ID);
   if (tab == null) {
     log.config("Not found AD_Tab_ID=" + AD_Tab_ID);
     return -1;
   }
   ArrayList<String[]> result = tab.executeQueryString(queryVO, context, m_context);
   if (result == null) {
     log.config("Not Result for AD_Tab_ID=" + AD_Tab_ID);
     return -1;
   }
   MRole role = getRole();
   // return -1 to indicate query exceeds
   if (role.isQueryMax(result.size())) {
     m_results.put(queryResultID, new ArrayList<String[]>());
     return -1;
   }
   m_results.put(queryResultID, result);
   return result.size();
 } // executeQuery
예제 #5
0
 public Query createQuery(int AD_Tab_ID, QueryVO queryVO, WindowCtx ctx, String tableName) {
   UITab tab = getTab(AD_Tab_ID);
   String whereClause = tab.getWhereClause();
   if (tab == null) {
     log.config("Not found AD_Tab_ID=" + AD_Tab_ID);
     return null;
   }
   Query result = tab.createQueryForReport(m_context, queryVO);
   if (result == null) {
     result = new Query(tableName);
   }
   if (whereClause != null && whereClause.length() != 0) {
     QueryRestriction restriction = new QueryRestriction(whereClause);
     result.addRestriction(restriction);
   }
   return result;
 } // executeQuery
예제 #6
0
  /**
   * Field Changed
   *
   * @param windowNo relative window
   * @param AD_Field_ID field
   * @param AD_Tab_ID tab
   * @param oldValue old field value
   * @param newValue new field value
   * @param context record context
   * @return Field Change VO
   */
  public ChangeVO fieldChanged(
      int windowNo,
      int AD_Field_ID,
      int AD_Tab_ID,
      String oldValue,
      String newValue,
      Map<String, String> context) {
    // Same Values
    if (oldValue == null || oldValue.equals(Null.NULLString)) oldValue = "";
    if (newValue == null || newValue.equals(Null.NULLString)) newValue = "";
    if (oldValue.equals(newValue)) return null;
    //
    UITab tab = getTab(AD_Tab_ID);
    if (tab == null) {
      log.config("Not found AD_Tab_ID=" + AD_Tab_ID);
      return null;
    }
    UIField field = getField(AD_Field_ID, windowNo);
    if (field == null) {
      log.warning("Cannot find AD_Field_ID=" + AD_Field_ID);
      return null;
    }

    CContext ctx = new CContext(m_context.entrySet());
    ctx.addWindow(windowNo, context);
    CContext origCtx = new CContext(m_context.entrySet());
    origCtx.addWindow(windowNo, context);
    ChangeVO change = null;
    try {
      // reset the thread active flag, in case the thread is reused later on
      CThreadUtil.setCalloutActive(false);
      change =
          tab.fieldChanged(
              origCtx, ctx, new ArrayList<UIField>(5), windowNo, field, oldValue, newValue);
      CThreadUtil.setCalloutActive(false);
      ctx.setContext(windowNo, field.getColumnName(), change.newConfirmedFieldValue);
    } catch (Exception e) {
      log.severe("fieldChange error:" + field.getColumnName() + e.getMessage());
    } finally {
      CThreadUtil.setCalloutActive(false);
    }

    return change;
  } // fieldChanged
예제 #7
0
 /**
  * Create new Row with Default values. The new Row is not saved in Results
  *
  * @param windowNo relative window
  * @param AD_Tab_ID tab
  * @param context record context for parent columns and other variables
  * @return array of field values or null if error. You get the columnNames via String[] columns =
  *     uiTab.getColumnNames();
  */
 public ChangeVO newRow(int windowNo, int AD_Tab_ID, Map<String, String> context) {
   UITab tab = getTab(AD_Tab_ID);
   if (tab == null) {
     log.config("Not found AD_Tab_ID=" + AD_Tab_ID);
     return null;
   }
   CContext ctx = new CContext(m_context.entrySet());
   ctx.addWindow(windowNo, context);
   ctx.setIsSOTrx(windowNo, tab.isSOTrx());
   ChangeVO change = tab.newRow(ctx, windowNo);
   /**
    * Very likely not needed if (change.changedDropDowns == null) change.changedDropDowns = new
    * HashMap<String,ArrayList<NamePair>>(); for(UIField f:tab.getFields()) { if
    * (f.isDependentValue()) change.changedDropDowns.put(f.getColumnName(),
    * getLookupValues(windowNo, f.getAD_Field_ID(), change.changedFields)); }
    */
   tab.canUpdate(ctx, windowNo, change);
   return change;
 } // newRow
예제 #8
0
 /**
  * Refresh current row of Tab
  *
  * @param windowNo relative window
  * @param AD_Tab_ID tab
  * @param relRowNo relative row number in results
  * @param context current (relevant) context of new row
  * @return error message or null
  */
 public ChangeVO refreshRow(
     int windowNo, int AD_Tab_ID, int queryResultID, int relRowNo, Map<String, String> context) {
   if (context == null || context.size() == 0) return new ChangeVO(true, "No Context");
   UITab tab = getTab(AD_Tab_ID);
   if (tab == null) {
     log.config("Not found AD_Tab_ID=" + AD_Tab_ID);
     return new ChangeVO(true, "@NotFound@ @AD_Tab_ID@=" + AD_Tab_ID);
   }
   CContext ctx = new CContext(m_context.entrySet());
   ctx.addWindow(windowNo, context);
   ChangeVO retValue = tab.refreshRow(ctx, windowNo);
   if (retValue.hasError()) return retValue;
   // Update Results
   ArrayList<String[]> data = m_results.get(queryResultID);
   if (data == null) retValue.addError("Data Not Found");
   else {
     String[] dataRow = retValue.rowData.clone();
     data.set(relRowNo, dataRow);
     postProcessChangeVO(retValue, windowNo, context, dataRow, tab);
     retValue.trxInfo = GridTab.getTrxInfo(tab.getTableName(), ctx, windowNo, tab.getTabNo());
   }
   return retValue;
 } // refreshRow
예제 #9
0
 /**
  * Delete existing Row
  *
  * @param windowNo relative window
  * @param AD_Tab_ID tab
  * @param relRowNo relative row number in results
  * @return error message or null
  */
 public ChangeVO deleteRow(int windowNo, int AD_Tab_ID, int queryResultID, int relRowNo) {
   UITab tab = getTab(AD_Tab_ID);
   if (tab == null) {
     log.config("Not found AD_Tab_ID=" + AD_Tab_ID);
     return new ChangeVO(true, "@NotFound@ @AD_Tab_ID@=" + AD_Tab_ID);
   }
   ArrayList<String[]> data = m_results.get(queryResultID);
   if (data == null) return new ChangeVO(true, "Data Not Found");
   String[] rowData = data.get(relRowNo);
   // Copy Data into Context
   Map<String, String> context = new HashMap<String, String>();
   String[] columns = tab.getColumnNames();
   for (int i = 0; i < columns.length; i++) {
     String column = columns[i];
     context.put(column, rowData[i]);
   }
   CContext ctx = new CContext(m_context.entrySet());
   ctx.addWindow(windowNo, context);
   ChangeVO retValue = tab.deleteRow(ctx, windowNo);
   if (retValue.hasError()) return retValue;
   // Update Results
   data.remove(relRowNo);
   return retValue;
 } // deleteRow
예제 #10
0
  /**
   * ************************************************************************* Get Window in default
   * context based on Role
   *
   * @param windowNO relative window
   * @param AD_Window_ID window
   * @param AD_Menu_ID menu
   * @return WindowVO or null
   */
  public UIWindow getWindow(int windowNO, int AD_Window_ID, int AD_Menu_ID) {
    UIWindow win = null;
    // win = m_windows.get(AD_Window_ID);
    // if (win != null)
    // {
    // win.clearLookupCache();
    // return win;
    // }
    UIWindowVOFactory winFactory = new UIWindowVOFactory();
    UIWindowVO winVO = null;
    int AD_UserDef_Win_ID = -1;
    WindowVOCacheKey vokey =
        new WindowVOCacheKey(
            AD_Window_ID, m_context.getAD_Role_ID(), AD_Menu_ID, Env.getAD_Language(m_context));

    // note, the usage of m_context below in constructing window is only for
    // language, menu, role,
    // and those are already included in the cache key, so we can safely
    // assume the win is correctly cached
    if (Userdef_Winids.get(null, vokey) == null) {
      winVO = winFactory.get(m_context, AD_Window_ID, AD_Menu_ID);
      if (winVO == null) {
        log.config("No Window - AD_Window_ID=" + AD_Window_ID + ",AD_Menu_ID=" + AD_Menu_ID);
        return null;
      }
      int theAD_UserDef_Win_ID = winVO.getAD_UserDef_Win_ID();

      if (Userdef_Winids.putIfAbsent(vokey, theAD_UserDef_Win_ID) == null)
        AD_UserDef_Win_ID = theAD_UserDef_Win_ID;
    } else AD_UserDef_Win_ID = Userdef_Winids.get(m_context, vokey);

    WindowCacheKey key =
        new WindowCacheKey(
            AD_Window_ID,
            AD_UserDef_Win_ID,
            m_context.getAD_Role_ID(),
            AD_Menu_ID,
            Env.getAD_Language(m_context));
    win = UIWindows.get(null, key);
    if (win == null) {
      // log.warning("key:" + key + " not found, create");
      if (winVO == null) winVO = winFactory.get(m_context, AD_Window_ID, AD_Menu_ID);
      if (winVO == null) {
        log.config("No Window - AD_Window_ID=" + AD_Window_ID + ",AD_Menu_ID=" + AD_Menu_ID);
        return null;
      }
      UIWindow newWin = new UIWindow(winVO);
      AD_Window_ID = newWin.getAD_Window_ID();
      //
      UIFieldVOFactory fieldFactory = new UIFieldVOFactory();
      newWin.setFields(fieldFactory.getAll(m_context, AD_Window_ID, AD_UserDef_Win_ID));
      //
      UITabVOFactory tabFactory = new UITabVOFactory();
      // setTabVOs initrlize tabs but not fields, 'cuz fields needs to be
      // copied over and initialized later
      newWin.setTabVOsWithFieldsUninitialized(
          m_context, tabFactory.getAll(m_context, AD_Window_ID, AD_UserDef_Win_ID), windowNO);
      win = UIWindows.putIfAbsent(key, newWin);
      if (win == null) win = newWin;
    }
    // deep copy the window object so we hold a separate window object for
    // each user session
    UIWindow duplicatedWin = (UIWindow) DeepCopy.copy(win);
    log.fine(duplicatedWin.toString());
    fillTabsFieldsAndInitFieldsAndCreateDependencyRelations(duplicatedWin, windowNO);

    MSession session = MSession.get(m_context);
    if (session != null)
      session.windowLog(
          m_context.getAD_Client_ID(),
          m_context.getAD_Org_ID(),
          duplicatedWin.getAD_Window_ID(),
          0);

    return duplicatedWin;
  } // getWindowVO