/** * Get Lookup Data for Field in context * * @param AD_Field_ID field * @param context context * @param refresh requery * @return lookup pair array */ public ArrayList<NamePair> getLookupData( int windowNo, int AD_Field_ID, Map<String, String> context, boolean refresh) { 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); if (field.isLookup() || field.isButtonLookup()) return field.getAllLookupData(ctx, windowNo); else log.warning("No Lookup: " + field.getColumnName()); return null; } // getLookupData
/** * ************************************************************************ Create Missing * Document Types * * @param ctx context * @param AD_Client_ID client * @param sp server process * @param trx transaction */ public static void createDocumentTypes(Ctx ctx, int AD_Client_ID, SvrProcess sp, Trx trx) { s_log.info("AD_Client_ID=" + AD_Client_ID); String sql = "SELECT rl.Value, rl.Name " + "FROM AD_Ref_List rl " + "WHERE rl.AD_Reference_ID=183" + " AND rl.IsActive='Y' AND NOT EXISTS " + " (SELECT * FROM C_DocType dt WHERE dt.AD_Client_ID=? AND rl.Value=dt.DocBaseType)"; PreparedStatement pstmt = null; ResultSet rs = null; try { pstmt = DB.prepareStatement(sql, trx); pstmt.setInt(1, AD_Client_ID); rs = pstmt.executeQuery(); while (rs.next()) { String name = rs.getString(2); String value = rs.getString(1); s_log.config(name + "=" + value); MDocType dt = new MDocType(ctx, value, name, trx); if (dt.save()) { if (sp != null) sp.addLog(0, null, null, name); else s_log.fine(name); } else { if (sp != null) sp.addLog(0, null, null, "Not created: " + name); else s_log.warning("Not created: " + name); } } } catch (Exception e) { s_log.log(Level.SEVERE, sql, e); } finally { DB.closeResultSet(rs); DB.closeStatement(pstmt); } } // createDocumentTypes
/** * Get Field Lookup Value Direct * * @param windowNo Window * @param AD_Field_ID * @param keyValues array of id values * @param cache * @return list of display values */ public ArrayList<NamePair> getLookupValueDirect( int AD_Field_ID, ArrayList<String> keyValues, boolean cache) { int windowNo = 0; // No Context ArrayList<NamePair> displayValues = new ArrayList<NamePair>(); UIField field = getField(AD_Field_ID, windowNo); // if (cache && field.isLookup()) // field.getLookup().removeAllElements(); if (field == null) log.warning("Cannot find AD_Field_ID=" + AD_Field_ID); // for (int i = 0; i < keyValues.size(); i++) { String key = keyValues.get(i); String value = null; if (field != null) value = field.getLookupDisplay(m_context, windowNo, key, cache); if (value == null) { /* * if(key == null) value = ""; else value = "<" + key + ">"; */ value = ""; } NamePair pp = new ValueNamePair(key, value); displayValues.add(pp); } return displayValues; } // getLookupValueDirect
/** * Get Field * * @param AD_Field_ID id * @param windowNo relative windowNo * @return field or null */ public UIField getField(int AD_Field_ID, int windowNo) { Integer key = Integer.valueOf(AD_Field_ID); UIField field = m_fields.get(key); if (field == null) { UIFieldVOFactory fieldFactory = new UIFieldVOFactory(); UIFieldVO vo = fieldFactory.get(m_context, AD_Field_ID); // m_context.setSOTrx(windowNo, isSOTrx); if (vo != null) { field = new UIField(vo); field.initialize(m_context, windowNo); log.warning("Loaded directly: " + field); // SOTrx may not // be correct m_fields.put(key, field); // save in cache } } // create new return field; } // getField
/** * 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
/** * Get Field Lookup Value Direct * * @param windowNo Window * @param AD_Field_ID * @param keyValues array of id values * @param cache * @return list of display values */ public ArrayList<String> getLookupValueOnlyDirect( int AD_Field_ID, ArrayList<String> keyValues, boolean cache) { int windowNo = 0; // No Context ArrayList<String> displayValues = new ArrayList<String>(); UIField field = getField(AD_Field_ID, windowNo); if (field == null) log.warning("Cannot find AD_Field_ID=" + AD_Field_ID); // for (int i = 0; i < keyValues.size(); i++) { String key = keyValues.get(i); String value = null; if (field != null) value = field.getLookupDisplay(m_context, windowNo, key, cache); if (value == null) { /* * if(key == null) value = ""; else value = "<" + key + ">"; */ value = ""; } displayValues.add(value); } return displayValues; } // getLookupValueDirect
/** * Create Period Controls * * @param ctx context * @param AD_Client_ID client * @param sp server process * @param trx transaction */ public static void createPeriodControls(Ctx ctx, int AD_Client_ID, SvrProcess sp, Trx trx) { s_log.info("AD_Client_ID=" + AD_Client_ID); // Delete Duplicates String sql = "DELETE FROM C_PeriodControl " + "WHERE (C_Period_ID, DocBaseType) IN " + "(SELECT C_Period_ID, DocBaseType " + "FROM C_PeriodControl pc2 " + "GROUP BY C_Period_ID, DocBaseType " + "HAVING COUNT(*) > 1)" + " AND C_PeriodControl_ID NOT IN " + "(SELECT MIN(C_PeriodControl_ID) " + "FROM C_PeriodControl pc3 " + "GROUP BY C_Period_ID, DocBaseType)"; int no = DB.executeUpdate(trx, sql); s_log.info("Duplicates deleted #" + no); // Insert Missing sql = "SELECT DISTINCT p.AD_Client_ID, p.C_Period_ID, dbt.DocBaseType " + "FROM C_Period p, " + "C_DocBaseType dbt " + "WHERE p.AD_Client_ID=? " + " AND NOT EXISTS" + " (SELECT * FROM C_PeriodControl pc " + "WHERE pc.C_Period_ID=p.C_Period_ID AND pc.DocBaseType=dbt.DocBaseType)" + " AND (dbt.AD_Client_ID = 0 OR p.AD_Client_ID = dbt.AD_Client_ID)"; PreparedStatement pstmt = null; ResultSet rs = null; int counter = 0; try { pstmt = DB.prepareStatement(sql, trx); pstmt.setInt(1, AD_Client_ID); rs = pstmt.executeQuery(); while (rs.next()) { int Client_ID = rs.getInt(1); int C_Period_ID = rs.getInt(2); String DocBaseType = rs.getString(3); s_log.config( "AD_Client_ID=" + Client_ID + ", C_Period_ID=" + C_Period_ID + ", DocBaseType=" + DocBaseType); // MPeriodControl pc = new MPeriodControl(ctx, Client_ID, C_Period_ID, DocBaseType, trx); if (pc.save()) { counter++; s_log.fine(pc.toString()); } else s_log.warning("Not saved: " + pc); } } catch (Exception e) { s_log.log(Level.SEVERE, sql, e); } finally { DB.closeResultSet(rs); DB.closeStatement(pstmt); } if (sp != null) sp.addLog(0, null, new BigDecimal(counter), "@C_PeriodControl_ID@ @Created@"); s_log.info("Inserted #" + counter); } // createPeriodControls