From: Jorg J. <jj...@us...> - 2003-10-27 15:22:50
|
Update of /cvsroot/compiere/dbPort/src/org/compiere/model In directory sc8-pr-cvs1:/tmp/cvs-serv13037/src/org/compiere/model Modified Files: MLookup.java MLocation.java MTabVO.java MRole.java Lookup.java Added Files: MPAttribute.java Log Message: . --- NEW FILE: MPAttribute.java --- /****************************************************************************** * The contents of this file are subject to the Compiere License Version 1.1 * ("License"); You may not use this file except in compliance with the License * You may obtain a copy of the License at http://www.compiere.org/license.html * Software distributed under the License is distributed on an "AS IS" basis, * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for * the specific language governing rights and limitations under the License. * The Original Code is Compiere ERP & CRM Business Solution * The Initial Developer of the Original Code is Jorg Janke and ComPiere, Inc. * Portions created by Jorg Janke are Copyright (C) 1999-2003 Jorg Janke, parts * created by ComPiere are Copyright (C) ComPiere, Inc.; All Rights Reserved. * Contributor(s): ______________________________________. *****************************************************************************/ package org.compiere.model; import java.sql.*; import java.util.*; import java.io.Serializable; import oracle.net.TNSAddress.Description; import org.compiere.util.DB; import org.compiere.util.Env; import org.compiere.util.CCache; import org.compiere.util.NamePair; import org.compiere.util.KeyNamePair; /** * Product Attribute Lookup Model (not Cached) * * @author Jorg Janke * @version $Id: MPAttribute.java,v 1.1 2003/10/27 15:22:39 jjanke Exp $ */ public class MPAttribute extends Lookup implements Serializable { /** * Constructor * @param ctx context * @param WindowNo window no */ public MPAttribute(Properties ctx, int WindowNo) { super(); m_ctx = ctx; m_WindowNo = WindowNo; } // MPAttribute private int m_WindowNo; private Properties m_ctx; private PreparedStatement m_pstmt = null; /** * Get Display for Value (not cached) * @param value Location_ID * @return String Value */ public String getDisplay (Object value) { if (value == null) return ""; NamePair pp = get (value); if (pp == null) return "<" + value.toString() + ">"; return pp.getName(); } // getDisplay /** * The Lookup contains the key (not cached) * @param key Location_ID * @return true if key known */ public boolean containsKey (Object key) { return get(key) != null; } // containsKey /** * Get Object of Key Value * @param value value * @return Object or null */ public NamePair get (Object value) { if (value == null) return null; int M_AttributeSetInstance_ID = 0; if (value instanceof Integer) M_AttributeSetInstance_ID = ((Integer)value).intValue(); else { try { M_AttributeSetInstance_ID = Integer.parseInt(value.toString()); } catch (Exception e) { log.error("get - " + value, e); } } if (M_AttributeSetInstance_ID == 0) return null; // // Statement if (m_pstmt == null) m_pstmt = DB.prepareStatement("SELECT Description " + "FROM M_AttributeSetInstance " + "WHERE M_AttributeSetInstance_ID=?"); // String Description = null; try { m_pstmt.setInt(1, M_AttributeSetInstance_ID); ResultSet rs = m_pstmt.executeQuery(); if (rs.next()) Description = rs.getString(1); // Description rs.close(); } catch (Exception e) { log.error("get", e); } if (Description == null) return null; return new KeyNamePair (M_AttributeSetInstance_ID, Description); } // get /** * Dispose * @see org.compiere.model.Lookup#dispose() */ public void dispose() { try { if (m_pstmt != null) m_pstmt.close(); } catch (SQLException e) { log.error("dispose", e); } log.debug("dispose"); super.dispose(); } // dispose /** * Return data as sorted Array - not implemented * @param mandatory mandatory * @param onlyValidated only validated * @param onlyActive only active * @param temporary force load for temporary display * @return null */ public ArrayList getData (boolean mandatory, boolean onlyValidated, boolean onlyActive, boolean temporary) { log.error("getData - not implemented"); return null; } // getArray /** * Get underlying fully qualified Table.Column Name. * Used for VLookup.actionButton (Zoom) * @return column name */ public String getColumnName() { return "M_AttributeSetInstance_ID"; } // getColumnName } // MPAttribute Index: MLookup.java =================================================================== RCS file: /cvsroot/compiere/dbPort/src/org/compiere/model/MLookup.java,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** MLookup.java 26 Oct 2003 05:54:36 -0000 1.14 --- MLookup.java 27 Oct 2003 15:22:39 -0000 1.15 *************** *** 103,109 **** * Dispose */ ! protected void dispose() { ! log.debug(m_info.KeyColumn + ": dispose"); if (m_loader != null) { --- 103,110 ---- * Dispose */ ! public void dispose() { ! if (m_info != null) ! log.debug(m_info.KeyColumn + ": dispose"); if (m_loader != null) { Index: MLocation.java =================================================================== RCS file: /cvsroot/compiere/dbPort/src/org/compiere/model/MLocation.java,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** MLocation.java 27 Sep 2003 01:22:18 -0000 1.14 --- MLocation.java 27 Oct 2003 15:22:39 -0000 1.15 *************** *** 566,575 **** /** ! * Get underlying fully qualified Table.Column Name ! * @return "" */ public String getColumnName() { ! return ""; } // getColumnName --- 566,576 ---- /** ! * Get underlying fully qualified Table.Column Name. ! * Used for VLookup.actionButton (Zoom) ! * @return column name */ public String getColumnName() { ! return "C_Location_ID"; } // getColumnName Index: MTabVO.java =================================================================== RCS file: /cvsroot/compiere/dbPort/src/org/compiere/model/MTabVO.java,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** MTabVO.java 26 Oct 2003 05:54:36 -0000 1.7 --- MTabVO.java 27 Oct 2003 15:22:39 -0000 1.8 *************** *** 240,243 **** --- 240,251 ---- private static boolean loadTabDetails (MTabVO vo, ResultSet rs) { + MRole role = MRole.getDefault(); + // Server has no default role + if (role == null) + { + int AD_Role_ID = Env.getContextAsInt(vo.ctx, "#AD_Role_ID"); + int AD_User_ID = Env.getContextAsInt(vo.ctx, "#AD_User_ID"); + role = MRole.get(vo.ctx, AD_Role_ID, AD_User_ID, false); + } try { *************** *** 263,267 **** // Access Level vo.AccessLevel = rs.getString("AccessLevel"); ! if (!MRole.getDefault().canView (vo.ctx, vo.AccessLevel)) // No Access { Log.trace(Log.l5_DData, "MTabVO.loadTabDetails", "No Role Access - AD_Tab_ID=" + vo.AD_Tab_ID + " " + vo. Name); --- 271,275 ---- // Access Level vo.AccessLevel = rs.getString("AccessLevel"); ! if (!role.canView (vo.ctx, vo.AccessLevel)) // No Access { Log.trace(Log.l5_DData, "MTabVO.loadTabDetails", "No Role Access - AD_Tab_ID=" + vo.AD_Tab_ID + " " + vo. Name); *************** *** 273,277 **** vo.AD_Table_ID = rs.getInt("AD_Table_ID"); Env.setContext(vo.ctx, vo.WindowNo, vo.TabNo, "AD_Table_ID", String.valueOf(vo.AD_Table_ID)); ! if (!MRole.getDefault().isTableAccess(vo.AD_Table_ID, true)) { Log.trace(Log.l5_DData, "MTabVO.loadTabDetails", "No Table Access - AD_Tab_ID=" + vo.AD_Tab_ID + " " + vo. Name); --- 281,285 ---- vo.AD_Table_ID = rs.getInt("AD_Table_ID"); Env.setContext(vo.ctx, vo.WindowNo, vo.TabNo, "AD_Table_ID", String.valueOf(vo.AD_Table_ID)); ! if (!role.isTableAccess(vo.AD_Table_ID, true)) { Log.trace(Log.l5_DData, "MTabVO.loadTabDetails", "No Table Access - AD_Tab_ID=" + vo.AD_Tab_ID + " " + vo. Name); Index: MRole.java =================================================================== RCS file: /cvsroot/compiere/dbPort/src/org/compiere/model/MRole.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** MRole.java 26 Oct 2003 05:54:36 -0000 1.4 --- MRole.java 27 Oct 2003 15:22:39 -0000 1.5 *************** *** 35,39 **** public static MRole getDefault () { ! return s_role; } // getDefault --- 35,39 ---- public static MRole getDefault () { ! return s_defaultRole; } // getDefault *************** *** 42,63 **** * @see org.compiere.util.DB#loadPreferences * @param ctx context * @return role */ ! public static MRole getDefault (Properties ctx) { int AD_Role_ID = Env.getContextAsInt(Env.getCtx(), "#AD_Role_ID"); int AD_User_ID = Env.getContextAsInt(Env.getCtx(), "#AD_User_ID"); ! // s_log.info("getDefault - AD_Role_ID=" + AD_Role_ID); ! s_role = new MRole (ctx, AD_Role_ID); ! if (AD_Role_ID == 0) ! s_role.load(); // special Handling ! s_role.loadAccess(false); ! s_role.setAD_User_ID(AD_User_ID); ! s_log.info("getDefault - " + s_role); ! return s_role; } // getDefault /** Default Role */ ! private static MRole s_role = null; private static Logger s_log = Logger.getCLogger(MRole.class); --- 42,95 ---- * @see org.compiere.util.DB#loadPreferences * @param ctx context + * @param load if true forces load * @return role */ ! public static MRole getDefault (Properties ctx, boolean load) { int AD_Role_ID = Env.getContextAsInt(Env.getCtx(), "#AD_Role_ID"); int AD_User_ID = Env.getContextAsInt(Env.getCtx(), "#AD_User_ID"); ! if (load || s_defaultRole == null) ! { ! s_defaultRole = get (ctx, AD_Role_ID, AD_User_ID, load); ! } ! else if (s_defaultRole.getAD_Role_ID() != AD_Role_ID ! || s_defaultRole.getAD_User_ID() != AD_User_ID) ! { ! s_defaultRole = get (ctx, AD_Role_ID, AD_User_ID, load); ! } ! return s_defaultRole; } // getDefault + /** + * Get Role for User + * @param ctx, context + * @param AD_Role_ID role + * @param AD_User_ID user + * @param load if true forces load + * @return role + */ + public static MRole get (Properties ctx, int AD_Role_ID, int AD_User_ID, boolean load) + { + s_log.info("get - AD_Role_ID=" + AD_Role_ID + ", AD_User_ID=" + AD_User_ID + ", load=" + load); + String key = AD_Role_ID + "_" + AD_User_ID; + MRole role = (MRole)s_roles.get (key); + if (role == null) + { + role = new MRole (ctx, AD_Role_ID); + if (AD_Role_ID == 0) + role.load(); // special Handling + // role.loadAccess(false); // lazy loading + role.setAD_User_ID(AD_User_ID); + s_log.info("get - " + role); + } + return role; + } // get + + /** Default Role */ ! private static MRole s_defaultRole = null; ! /** Role/User Cache */ ! private static CCache s_roles = new CCache("MRole", 5); ! /** Log */ private static Logger s_log = Logger.getCLogger(MRole.class); *************** *** 187,190 **** --- 219,230 ---- } // setAD_User_ID + /** + * Get Logged in user + * @return AD_User_ID user requesting info + */ + public int getAD_User_ID() + { + return m_AD_User_ID; + } // getAD_User_ID /** *************** *** 276,281 **** if (m_tableAccessLevel != null && m_tableName != null && !reload) return; ! m_tableAccessLevel = new HashMap(200); ! m_tableName = new HashMap(200); PreparedStatement pstmt = null; String sql = "SELECT AD_Table_ID, AccessLevel, TableName FROM AD_Table WHERE IsActive='Y'"; --- 316,321 ---- if (m_tableAccessLevel != null && m_tableName != null && !reload) return; ! m_tableAccessLevel = new HashMap(500); ! m_tableName = new HashMap(500); PreparedStatement pstmt = null; String sql = "SELECT AD_Table_ID, AccessLevel, TableName FROM AD_Table WHERE IsActive='Y'"; *************** *** 691,695 **** if (!isTableAccess(AD_Table_ID, ro)) // No Access to Table return false; ! boolean retValue = true; // assuming exclusive for (int i = 0; i < m_columnAccess.length; i++) --- 731,736 ---- if (!isTableAccess(AD_Table_ID, ro)) // No Access to Table return false; ! loadColumnAccess(false); ! boolean retValue = true; // assuming exclusive for (int i = 0; i < m_columnAccess.length; i++) *************** *** 748,752 **** if (!isTableAccess(AD_Table_ID, ro)) // No Access to Table return false; ! boolean negativeList = true; for (int i = 0; i < m_tableAccess.length; i++) --- 789,794 ---- if (!isTableAccess(AD_Table_ID, ro)) // No Access to Table return false; ! loadRecordAccess(false); ! boolean negativeList = true; for (int i = 0; i < m_tableAccess.length; i++) *************** *** 986,1002 **** } // getTaskAccess ! /*************************************************************************/ ! ! /** ! * Add Access SQL ! * @param rw true for rw access ! * @return SQL ! */ ! public String addAccessSQL (String sql, boolean rw) ! { ! // works for simple tables ! log.error("addAccessSQL - might not be parsed -" + sql); ! return addAccessSQL (sql, null, true, rw); ! } // add /** --- 1028,1032 ---- } // getTaskAccess ! /************************************************************************* /** *************** *** 1055,1058 **** --- 1085,1089 ---- msg += "\n = " + SQL; log.error(msg); + Trace.printStack(); tableName = TableNameIn; } *************** *** 1217,1226 **** // 3 - Client Shared requires C or O else if (X_AD_Table.ACCESSLEVEL_ClientPlusOrganization.equals(TableLevel) ! && (!(userLevel.charAt(1) != 'C' || userLevel.charAt(2) != 'O')) ) retValue = false; // 6 - System/Client requires S or C else if (X_AD_Table.ACCESSLEVEL_SystemPlusClient.equals(TableLevel) ! && (!(userLevel.charAt(0) != 'S' || userLevel.charAt(1) != 'C')) ) retValue = false; --- 1248,1257 ---- // 3 - Client Shared requires C or O else if (X_AD_Table.ACCESSLEVEL_ClientPlusOrganization.equals(TableLevel) ! && (!(userLevel.charAt(1) == 'C' || userLevel.charAt(2) == 'O')) ) retValue = false; // 6 - System/Client requires S or C else if (X_AD_Table.ACCESSLEVEL_SystemPlusClient.equals(TableLevel) ! && (!(userLevel.charAt(0) == 'S' || userLevel.charAt(1) == 'C')) ) retValue = false; *************** *** 1278,1281 **** --- 1309,1313 ---- private int getAD_Table_ID (String tableName) { + loadTableInfo(false); Integer ii = (Integer)m_tableName.get(tableName); if (ii != null) *************** *** 1293,1296 **** --- 1325,1330 ---- private String getRecordWhere (int AD_Table_ID, String keyColumnName) { + loadRecordAccess(false); + StringBuffer sb = new StringBuffer(); // Role Access Index: Lookup.java =================================================================== RCS file: /cvsroot/compiere/dbPort/src/org/compiere/model/Lookup.java,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** Lookup.java 4 Oct 2003 03:55:45 -0000 1.9 --- Lookup.java 27 Oct 2003 15:22:39 -0000 1.10 *************** *** 299,303 **** /** ! * Get underlying fully qualified Table.Column Name * @return column name */ --- 299,304 ---- /** ! * Get underlying fully qualified Table.Column Name. ! * Used for VLookup.actionButton (Zoom) * @return column name */ *************** *** 391,395 **** * Dispose - clear items w/o firing events */ ! protected void dispose() { while (m_worker != null && m_worker.isAlive()) --- 392,396 ---- * Dispose - clear items w/o firing events */ ! public void dispose() { while (m_worker != null && m_worker.isAlive()) *************** *** 397,401 **** m_worker = null; // ! p_data.clear(); p_data = null; m_selectedObject = null; --- 398,403 ---- m_worker = null; // ! if (p_data != null) ! p_data.clear(); p_data = null; m_selectedObject = null; |