From 8e6133e0941ac267c1a3a5b5ed8fce4df9f0872a Mon Sep 17 00:00:00 2001 From: Carlos Ruiz Date: Wed, 13 Feb 2008 03:30:34 +0000 Subject: [PATCH] [ 1755177 ] ad_changelog should have an 'action' field [ 1783027 ] Add descriptive info to AD_Session (like Role) [ 1755175 ] ad_changelog should capture insert too --- .../org/compiere/model/I_AD_ChangeLog.java | 13 +++ base/src/org/compiere/model/I_AD_Session.java | 38 +++++++++ base/src/org/compiere/model/MChangeLog.java | 9 +-- base/src/org/compiere/model/MSession.java | 12 +++ base/src/org/compiere/model/PO.java | 8 +- .../org/compiere/model/X_AD_ChangeLog.java | 32 ++++++++ base/src/org/compiere/model/X_AD_Session.java | 79 +++++++++++++++++++ .../compiere/process/ChangeLogProcess.java | 3 +- 8 files changed, 183 insertions(+), 11 deletions(-) diff --git a/base/src/org/compiere/model/I_AD_ChangeLog.java b/base/src/org/compiere/model/I_AD_ChangeLog.java index a9ec25bcd2..1c52dc6b8f 100644 --- a/base/src/org/compiere/model/I_AD_ChangeLog.java +++ b/base/src/org/compiere/model/I_AD_ChangeLog.java @@ -127,6 +127,19 @@ public interface I_AD_ChangeLog */ public String getDescription(); + /** Column name EventChangeLog */ + public static final String COLUMNNAME_EventChangeLog = "EventChangeLog"; + + /** Set Event Change Log. + * Type of Event in Change Log + */ + public void setEventChangeLog (String EventChangeLog); + + /** Get Event Change Log. + * Type of Event in Change Log + */ + public String getEventChangeLog(); + /** Column name IsCustomization */ public static final String COLUMNNAME_IsCustomization = "IsCustomization"; diff --git a/base/src/org/compiere/model/I_AD_Session.java b/base/src/org/compiere/model/I_AD_Session.java index 9ef1f817bf..4a2058210b 100644 --- a/base/src/org/compiere/model/I_AD_Session.java +++ b/base/src/org/compiere/model/I_AD_Session.java @@ -33,6 +33,7 @@ package org.compiere.model; import java.math.BigDecimal; +import java.sql.Timestamp; import org.compiere.util.KeyNamePair; /** Generated Interface for AD_Session @@ -56,6 +57,21 @@ public interface I_AD_Session /** Load Meta Data */ + /** Column name AD_Role_ID */ + public static final String COLUMNNAME_AD_Role_ID = "AD_Role_ID"; + + /** Set Role. + * Responsibility Role + */ + public void setAD_Role_ID (int AD_Role_ID); + + /** Get Role. + * Responsibility Role + */ + public int getAD_Role_ID(); + + public I_AD_Role getAD_Role() throws Exception; + /** Column name AD_Session_ID */ public static final String COLUMNNAME_AD_Session_ID = "AD_Session_ID"; @@ -69,6 +85,28 @@ public interface I_AD_Session */ public int getAD_Session_ID(); + /** Column name Description */ + public static final String COLUMNNAME_Description = "Description"; + + /** Set Description. + * Optional short description of the record + */ + public void setDescription (String Description); + + /** Get Description. + * Optional short description of the record + */ + public String getDescription(); + + /** Column name LoginDate */ + public static final String COLUMNNAME_LoginDate = "LoginDate"; + + /** Set Login date */ + public void setLoginDate (Timestamp LoginDate); + + /** Get Login date */ + public Timestamp getLoginDate(); + /** Column name Processed */ public static final String COLUMNNAME_Processed = "Processed"; diff --git a/base/src/org/compiere/model/MChangeLog.java b/base/src/org/compiere/model/MChangeLog.java index 77e659a225..ad57bb11bd 100644 --- a/base/src/org/compiere/model/MChangeLog.java +++ b/base/src/org/compiere/model/MChangeLog.java @@ -168,13 +168,10 @@ public class MChangeLog extends X_AD_ChangeLog // setOldValue (OldValue); setNewValue (NewValue); + setEventChangeLog(event); // EVENT / Release 3.3.1t_2007-12-05 ADempiere - if (event != null) - setDescription(event + " / " + Adempiere.MAIN_VERSION + "_" - + Adempiere.DATE_VERSION + " " + Adempiere.getImplementationVersion()); - else - setDescription(Adempiere.MAIN_VERSION + "_" - + Adempiere.DATE_VERSION + " " + Adempiere.getImplementationVersion()); + // Drop description from AD_ChangeLog - pass it to AD_Session to save disk space + // setDescription(Adempiere.MAIN_VERSION + "_" + Adempiere.DATE_VERSION + " " + Adempiere.getImplementationVersion()); } // MChangeLog diff --git a/base/src/org/compiere/model/MSession.java b/base/src/org/compiere/model/MSession.java index 839aea5977..165749aa14 100644 --- a/base/src/org/compiere/model/MSession.java +++ b/base/src/org/compiere/model/MSession.java @@ -20,6 +20,8 @@ import java.net.*; import java.sql.*; import java.util.*; import java.util.logging.*; + +import org.compiere.Adempiere; import org.compiere.util.*; /** @@ -142,6 +144,11 @@ public class MSession extends X_AD_Session setRemote_Host(Remote_Host); if (WebSession != null) setWebSession(WebSession); + setDescription(Adempiere.MAIN_VERSION + "_" + + Adempiere.DATE_VERSION + " " + + Adempiere.getImplementationVersion()); + setAD_Role_ID(Env.getContextAsInt(ctx, "#AD_Role_ID")); + setLoginDate(Env.getContextAsDate(ctx, "#Date")); } // MSession /** @@ -157,6 +164,11 @@ public class MSession extends X_AD_Session InetAddress lh = InetAddress.getLocalHost(); setRemote_Addr(lh.getHostAddress()); setRemote_Host(lh.getHostName()); + setDescription(Adempiere.MAIN_VERSION + "_" + + Adempiere.DATE_VERSION + " " + + Adempiere.getImplementationVersion()); + setAD_Role_ID(Env.getContextAsInt(ctx, "#AD_Role_ID")); + setLoginDate(Env.getContextAsDate(ctx, "#Date")); } catch (UnknownHostException e) { diff --git a/base/src/org/compiere/model/PO.java b/base/src/org/compiere/model/PO.java index cd0b311b39..42ffbab10b 100644 --- a/base/src/org/compiere/model/PO.java +++ b/base/src/org/compiere/model/PO.java @@ -2195,7 +2195,7 @@ public abstract class PO MChangeLog cLog = session.changeLog ( m_trxName, AD_ChangeLog_ID, p_info.getAD_Table_ID(), p_info.getColumn(i).AD_Column_ID, - get_ID(), getAD_Client_ID(), getAD_Org_ID(), oldV, newV, "UPDATE"); + get_ID(), getAD_Client_ID(), getAD_Org_ID(), oldV, newV, MChangeLog.EVENTCHANGELOG_Update); if (cLog != null) AD_ChangeLog_ID = cLog.getAD_ChangeLog_ID(); } @@ -2407,14 +2407,14 @@ public abstract class PO && !p_info.isEncrypted(i) // not encrypted && !p_info.isVirtualColumn(i) // no virtual column && !"Password".equals(columnName) - && p_info.getColumn(i).IsKey // log just the key - to log all columns comment this line + // && p_info.getColumn(i).IsKey // log all record - to log just ID uncomment this line ) { // change log on new MChangeLog cLog = session.changeLog ( m_trxName, AD_ChangeLog_ID, p_info.getAD_Table_ID(), p_info.getColumn(i).AD_Column_ID, - get_ID(), getAD_Client_ID(), getAD_Org_ID(), null, value, "INSERT"); + get_ID(), getAD_Client_ID(), getAD_Org_ID(), null, value, MChangeLog.EVENTCHANGELOG_Insert); if (cLog != null) AD_ChangeLog_ID = cLog.getAD_ChangeLog_ID(); } @@ -2680,7 +2680,7 @@ public abstract class PO MChangeLog cLog = session.changeLog ( m_trxName != null ? m_trxName : localTrxName, AD_ChangeLog_ID, AD_Table_ID, p_info.getColumn(i).AD_Column_ID, - Record_ID, getAD_Client_ID(), getAD_Org_ID(), value, null, "DELETE"); + Record_ID, getAD_Client_ID(), getAD_Org_ID(), value, null, MChangeLog.EVENTCHANGELOG_Delete); if (cLog != null) AD_ChangeLog_ID = cLog.getAD_ChangeLog_ID(); } diff --git a/base/src/org/compiere/model/X_AD_ChangeLog.java b/base/src/org/compiere/model/X_AD_ChangeLog.java index c08b278568..3c2b0caa95 100644 --- a/base/src/org/compiere/model/X_AD_ChangeLog.java +++ b/base/src/org/compiere/model/X_AD_ChangeLog.java @@ -244,6 +244,38 @@ public class X_AD_ChangeLog extends PO implements I_AD_ChangeLog, I_Persistent return (String)get_Value(COLUMNNAME_Description); } + /** EventChangeLog AD_Reference_ID=53238 */ + public static final int EVENTCHANGELOG_AD_Reference_ID=53238; + /** Insert = I */ + public static final String EVENTCHANGELOG_Insert = "I"; + /** Delete = D */ + public static final String EVENTCHANGELOG_Delete = "D"; + /** Update = U */ + public static final String EVENTCHANGELOG_Update = "U"; + /** Set Event Change Log. + @param EventChangeLog + Type of Event in Change Log + */ + public void setEventChangeLog (String EventChangeLog) + { + + if (EventChangeLog == null || EventChangeLog.equals("I") || EventChangeLog.equals("D") || EventChangeLog.equals("U")); else throw new IllegalArgumentException ("EventChangeLog Invalid value - " + EventChangeLog + " - Reference_ID=53238 - I - D - U"); + if (EventChangeLog != null && EventChangeLog.length() > 1) + { + log.warning("Length > 1 - truncated"); + EventChangeLog = EventChangeLog.substring(0, 1); + } + set_Value (COLUMNNAME_EventChangeLog, EventChangeLog); + } + + /** Get Event Change Log. + @return Type of Event in Change Log + */ + public String getEventChangeLog () + { + return (String)get_Value(COLUMNNAME_EventChangeLog); + } + /** Set Customization. @param IsCustomization The change is a customization of the data dictionary and can be applied after Migration diff --git a/base/src/org/compiere/model/X_AD_Session.java b/base/src/org/compiere/model/X_AD_Session.java index 07ee043657..90763fcea0 100644 --- a/base/src/org/compiere/model/X_AD_Session.java +++ b/base/src/org/compiere/model/X_AD_Session.java @@ -17,8 +17,11 @@ /** Generated Model - DO NOT CHANGE */ package org.compiere.model; +import java.lang.reflect.Constructor; import java.sql.ResultSet; +import java.sql.Timestamp; import java.util.Properties; +import java.util.logging.Level; import org.compiere.util.KeyNamePair; /** Generated Model for AD_Session @@ -71,6 +74,45 @@ public class X_AD_Session extends PO implements I_AD_Session, I_Persistent return sb.toString(); } + public I_AD_Role getAD_Role() throws Exception + { + Class clazz = MTable.getClass(I_AD_Role.Table_Name); + I_AD_Role result = null; + try { + Constructor constructor = null; + constructor = clazz.getDeclaredConstructor(new Class[]{Properties.class, int.class, String.class}); + result = (I_AD_Role)constructor.newInstance(new Object[] {getCtx(), new Integer(getAD_Role_ID()), get_TrxName()}); + } catch (Exception e) { + log.log(Level.SEVERE, "(id) - Table=" + Table_Name + ",Class=" + clazz, e); + log.saveError("Error", "Table=" + Table_Name + ",Class=" + clazz); + throw e; + } + return result; + } + + /** Set Role. + @param AD_Role_ID + Responsibility Role + */ + public void setAD_Role_ID (int AD_Role_ID) + { + if (AD_Role_ID < 0) + set_Value (COLUMNNAME_AD_Role_ID, null); + else + set_Value (COLUMNNAME_AD_Role_ID, Integer.valueOf(AD_Role_ID)); + } + + /** Get Role. + @return Responsibility Role + */ + public int getAD_Role_ID () + { + Integer ii = (Integer)get_Value(COLUMNNAME_AD_Role_ID); + if (ii == null) + return 0; + return ii.intValue(); + } + /** Set Session. @param AD_Session_ID User Session Online or Web @@ -101,6 +143,43 @@ public class X_AD_Session extends PO implements I_AD_Session, I_Persistent return new KeyNamePair(get_ID(), String.valueOf(getAD_Session_ID())); } + /** Set Description. + @param Description + Optional short description of the record + */ + public void setDescription (String Description) + { + + if (Description != null && Description.length() > 255) + { + log.warning("Length > 255 - truncated"); + Description = Description.substring(0, 255); + } + set_Value (COLUMNNAME_Description, Description); + } + + /** Get Description. + @return Optional short description of the record + */ + public String getDescription () + { + return (String)get_Value(COLUMNNAME_Description); + } + + /** Set Login date. + @param LoginDate Login date */ + public void setLoginDate (Timestamp LoginDate) + { + set_Value (COLUMNNAME_LoginDate, LoginDate); + } + + /** Get Login date. + @return Login date */ + public Timestamp getLoginDate () + { + return (Timestamp)get_Value(COLUMNNAME_LoginDate); + } + /** Set Processed. @param Processed The document has been processed diff --git a/base/src/org/compiere/process/ChangeLogProcess.java b/base/src/org/compiere/process/ChangeLogProcess.java index a3aec58bd4..b79215f7a6 100644 --- a/base/src/org/compiere/process/ChangeLogProcess.java +++ b/base/src/org/compiere/process/ChangeLogProcess.java @@ -200,7 +200,8 @@ public class ChangeLogProcess extends SvrProcess m_oldRecord_ID = cLog.getRecord_ID(); // Insert - new value is null and UnDo only - m_isInsert = cLog.isNewNull() && p_CheckNewValue != null; + // m_isInsert = cLog.isNewNull() && p_CheckNewValue != null; + m_isInsert = MChangeLog.EVENTCHANGELOG_Insert.equals(cLog.getEventChangeLog()); if (m_isInsert) { m_sqlInsert = new StringBuffer ("INSERT INTO ")