From f021e8f5f1e0c4e2d001116b0b4939cc927408a7 Mon Sep 17 00:00:00 2001 From: Carlos Ruiz Date: Fri, 5 Sep 2014 19:23:26 -0500 Subject: [PATCH] IDEMPIERE-1970 Improve t_selection logic for info window / change viewID to point to an info column instead of a column --- .../oracle/201409051741_IDEMPIERE-1970.sql | 37 ++++++++++++ .../201409051741_IDEMPIERE-1970.sql | 34 +++++++++++ .../src/org/adempiere/model/MInfoProcess.java | 25 +------- .../org/compiere/model/I_AD_InfoProcess.java | 18 +++--- .../org/compiere/model/X_AD_InfoProcess.java | 30 +++++----- .../org/adempiere/webui/info/InfoWindow.java | 60 ++++++++++--------- .../org/adempiere/webui/panel/InfoPanel.java | 18 +++--- 7 files changed, 138 insertions(+), 84 deletions(-) create mode 100644 migration/i2.0z/oracle/201409051741_IDEMPIERE-1970.sql create mode 100644 migration/i2.0z/postgresql/201409051741_IDEMPIERE-1970.sql diff --git a/migration/i2.0z/oracle/201409051741_IDEMPIERE-1970.sql b/migration/i2.0z/oracle/201409051741_IDEMPIERE-1970.sql new file mode 100644 index 0000000000..4e895ce214 --- /dev/null +++ b/migration/i2.0z/oracle/201409051741_IDEMPIERE-1970.sql @@ -0,0 +1,37 @@ +SET SQLBLANKLINES ON +SET DEFINE OFF + +update ad_infoprocess set ad_column_id=null where ad_column_id is not null; + +ALTER TABLE AD_INFOPROCESS RENAME COLUMN AD_COLUMN_ID TO AD_INFOCOLUMN_ID; + +ALTER TABLE AD_INFOPROCESS DROP CONSTRAINT ADCOLUMN_ADINFOPROCESS; + +-- Sep 5, 2014 5:40:41 PM COT +-- IDEMPIERE-1970 Improve t_selection logic for info window +INSERT INTO AD_Val_Rule (Code,AD_Val_Rule_ID,EntityType,Name,Type,AD_Val_Rule_UU,CreatedBy,UpdatedBy,Updated,AD_Org_ID,IsActive,AD_Client_ID,Created) VALUES ('AD_InfoColumn.AD_InfoWindow_ID=@AD_InfoWindow_ID@',200065,'D','AD_InfoColumn from Info Window','S','010f3e1f-dd6c-48c7-8fe1-945e0a2482a2',100,100,TO_DATE('2014-09-05 17:40:37','YYYY-MM-DD HH24:MI:SS'),0,'Y',0,TO_DATE('2014-09-05 17:40:37','YYYY-MM-DD HH24:MI:SS')) +; + +-- Sep 5, 2014 5:40:55 PM COT +UPDATE AD_Column SET FieldLength=10, IsUpdateable='N', ColumnName='AD_InfoColumn_ID', Description='Info Window Column', Help='Column in the Info Window for display and/or selection. If used for selection, the column cannot be a SQL expression. The SQL clause must be fully qualified based on the FROM clause in the Info Window definition', Name='Info Column', FKConstraintName=NULL, AD_Element_ID=3069, AD_Val_Rule_ID=200065,Updated=TO_DATE('2014-09-05 17:40:55','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Column_ID=211377 +; + +-- Sep 5, 2014 5:41:00 PM COT +UPDATE AD_Column SET FKConstraintName='ADInfoColumn_ADInfoProcess', FKConstraintType='N',Updated=TO_DATE('2014-09-05 17:41:00','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Column_ID=211377 +; + +-- Sep 5, 2014 5:41:00 PM COT +ALTER TABLE AD_InfoProcess MODIFY AD_InfoColumn_ID NUMBER(10) DEFAULT NULL +; + +-- Sep 5, 2014 5:41:00 PM COT +ALTER TABLE AD_InfoProcess ADD CONSTRAINT ADInfoColumn_ADInfoProcess FOREIGN KEY (AD_InfoColumn_ID) REFERENCES ad_infocolumn(ad_infocolumn_id) DEFERRABLE INITIALLY DEFERRED +; + +-- Sep 5, 2014 5:44:01 PM COT +UPDATE AD_Column SET IsUpdateable='Y',Updated=TO_DATE('2014-09-05 17:44:01','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Column_ID=211377 +; + +SELECT register_migration_script('201409051741_IDEMPIERE-1970.sql') FROM dual +; + diff --git a/migration/i2.0z/postgresql/201409051741_IDEMPIERE-1970.sql b/migration/i2.0z/postgresql/201409051741_IDEMPIERE-1970.sql new file mode 100644 index 0000000000..582bff9bdd --- /dev/null +++ b/migration/i2.0z/postgresql/201409051741_IDEMPIERE-1970.sql @@ -0,0 +1,34 @@ +update ad_infoprocess set ad_column_id=null where ad_column_id is not null; + +ALTER TABLE ad_infoprocess RENAME ad_column_id TO ad_infocolumn_id; + +ALTER TABLE ad_infoprocess DROP CONSTRAINT adcolumn_adinfoprocess CASCADE; + +-- Sep 5, 2014 5:40:41 PM COT +-- IDEMPIERE-1970 Improve t_selection logic for info window +INSERT INTO AD_Val_Rule (Code,AD_Val_Rule_ID,EntityType,Name,Type,AD_Val_Rule_UU,CreatedBy,UpdatedBy,Updated,AD_Org_ID,IsActive,AD_Client_ID,Created) VALUES ('AD_InfoColumn.AD_InfoWindow_ID=@AD_InfoWindow_ID@',200065,'D','AD_InfoColumn from Info Window','S','010f3e1f-dd6c-48c7-8fe1-945e0a2482a2',100,100,TO_TIMESTAMP('2014-09-05 17:40:37','YYYY-MM-DD HH24:MI:SS'),0,'Y',0,TO_TIMESTAMP('2014-09-05 17:40:37','YYYY-MM-DD HH24:MI:SS')) +; + +-- Sep 5, 2014 5:40:55 PM COT +UPDATE AD_Column SET FieldLength=10, IsUpdateable='N', ColumnName='AD_InfoColumn_ID', Description='Info Window Column', Help='Column in the Info Window for display and/or selection. If used for selection, the column cannot be a SQL expression. The SQL clause must be fully qualified based on the FROM clause in the Info Window definition', Name='Info Column', FKConstraintName=NULL, AD_Element_ID=3069, AD_Val_Rule_ID=200065,Updated=TO_TIMESTAMP('2014-09-05 17:40:55','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Column_ID=211377 +; + +-- Sep 5, 2014 5:41:00 PM COT +UPDATE AD_Column SET FKConstraintName='ADInfoColumn_ADInfoProcess', FKConstraintType='N',Updated=TO_TIMESTAMP('2014-09-05 17:41:00','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Column_ID=211377 +; + +-- Sep 5, 2014 5:41:00 PM COT +INSERT INTO t_alter_column values('ad_infoprocess','AD_InfoColumn_ID','NUMERIC(10)',null,'NULL') +; + +-- Sep 5, 2014 5:41:00 PM COT +ALTER TABLE AD_InfoProcess ADD CONSTRAINT ADInfoColumn_ADInfoProcess FOREIGN KEY (AD_InfoColumn_ID) REFERENCES ad_infocolumn(ad_infocolumn_id) DEFERRABLE INITIALLY DEFERRED +; + +-- Sep 5, 2014 5:44:01 PM COT +UPDATE AD_Column SET IsUpdateable='Y',Updated=TO_TIMESTAMP('2014-09-05 17:44:01','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Column_ID=211377 +; + +SELECT register_migration_script('201409051741_IDEMPIERE-1970.sql') FROM dual +; + diff --git a/org.adempiere.base/src/org/adempiere/model/MInfoProcess.java b/org.adempiere.base/src/org/adempiere/model/MInfoProcess.java index d9d4d37b25..8e6de42a8b 100644 --- a/org.adempiere.base/src/org/adempiere/model/MInfoProcess.java +++ b/org.adempiere.base/src/org/adempiere/model/MInfoProcess.java @@ -16,7 +16,7 @@ package org.adempiere.model; import java.sql.ResultSet; import java.util.Properties; import java.util.logging.Level; -import org.compiere.model.MColumn; + import org.compiere.model.MProcess; import org.compiere.model.X_AD_InfoProcess; import org.compiere.util.Env; @@ -33,7 +33,7 @@ public class MInfoProcess extends X_AD_InfoProcess { /** * */ - private static final long serialVersionUID = -2167041563372362436L; + private static final long serialVersionUID = 2478699719088685214L; /** * {@inheritDoc} @@ -89,25 +89,4 @@ public class MInfoProcess extends X_AD_InfoProcess { return retValue; } - /** - * name of column define is ViewID - * @return - */ - public String getViewIDName (){ - // no column define - if (getAD_Column_ID() == 0) - return null; - - // return cache value - if (m_viewIDName != null) - return m_viewIDName; - - MColumn viewIDColumn = (MColumn)getAD_Column(); - if (viewIDColumn != null){ - return viewIDColumn.getColumnName(); -} - - return null; - } - } diff --git a/org.adempiere.base/src/org/compiere/model/I_AD_InfoProcess.java b/org.adempiere.base/src/org/compiere/model/I_AD_InfoProcess.java index da0c5bfbba..69120a0d3d 100644 --- a/org.adempiere.base/src/org/compiere/model/I_AD_InfoProcess.java +++ b/org.adempiere.base/src/org/compiere/model/I_AD_InfoProcess.java @@ -49,20 +49,20 @@ public interface I_AD_InfoProcess */ public int getAD_Client_ID(); - /** Column name AD_Column_ID */ - public static final String COLUMNNAME_AD_Column_ID = "AD_Column_ID"; + /** Column name AD_InfoColumn_ID */ + public static final String COLUMNNAME_AD_InfoColumn_ID = "AD_InfoColumn_ID"; - /** Set ViewID Column. - * Name of unique column in a view. value of this column will save to t_selection table + /** Set Info Column. + * Info Window Column */ - public void setAD_Column_ID (int AD_Column_ID); + public void setAD_InfoColumn_ID (int AD_InfoColumn_ID); - /** Get ViewID Column. - * Name of unique column in a view. value of this column will save to t_selection table + /** Get Info Column. + * Info Window Column */ - public int getAD_Column_ID(); + public int getAD_InfoColumn_ID(); - public org.compiere.model.I_AD_Column getAD_Column() throws RuntimeException; + public org.compiere.model.I_AD_InfoColumn getAD_InfoColumn() throws RuntimeException; /** Column name AD_InfoProcess_ID */ public static final String COLUMNNAME_AD_InfoProcess_ID = "AD_InfoProcess_ID"; diff --git a/org.adempiere.base/src/org/compiere/model/X_AD_InfoProcess.java b/org.adempiere.base/src/org/compiere/model/X_AD_InfoProcess.java index 0003f046d5..0592a21475 100644 --- a/org.adempiere.base/src/org/compiere/model/X_AD_InfoProcess.java +++ b/org.adempiere.base/src/org/compiere/model/X_AD_InfoProcess.java @@ -30,7 +30,7 @@ public class X_AD_InfoProcess extends PO implements I_AD_InfoProcess, I_Persiste /** * */ - private static final long serialVersionUID = 20140606L; + private static final long serialVersionUID = 20140905L; /** Standard Constructor */ public X_AD_InfoProcess (Properties ctx, int AD_InfoProcess_ID, String trxName) @@ -76,29 +76,29 @@ public class X_AD_InfoProcess extends PO implements I_AD_InfoProcess, I_Persiste return sb.toString(); } - public org.compiere.model.I_AD_Column getAD_Column() throws RuntimeException + public org.compiere.model.I_AD_InfoColumn getAD_InfoColumn() throws RuntimeException { - return (org.compiere.model.I_AD_Column)MTable.get(getCtx(), org.compiere.model.I_AD_Column.Table_Name) - .getPO(getAD_Column_ID(), get_TrxName()); } + return (org.compiere.model.I_AD_InfoColumn)MTable.get(getCtx(), org.compiere.model.I_AD_InfoColumn.Table_Name) + .getPO(getAD_InfoColumn_ID(), get_TrxName()); } - /** Set ViewID Column. - @param AD_Column_ID - Name of unique column in a view. value of this column will save to t_selection table + /** Set Info Column. + @param AD_InfoColumn_ID + Info Window Column */ - public void setAD_Column_ID (int AD_Column_ID) + public void setAD_InfoColumn_ID (int AD_InfoColumn_ID) { - if (AD_Column_ID < 1) - set_Value (COLUMNNAME_AD_Column_ID, null); + if (AD_InfoColumn_ID < 1) + set_Value (COLUMNNAME_AD_InfoColumn_ID, null); else - set_Value (COLUMNNAME_AD_Column_ID, Integer.valueOf(AD_Column_ID)); + set_Value (COLUMNNAME_AD_InfoColumn_ID, Integer.valueOf(AD_InfoColumn_ID)); } - /** Get ViewID Column. - @return Name of unique column in a view. value of this column will save to t_selection table + /** Get Info Column. + @return Info Window Column */ - public int getAD_Column_ID () + public int getAD_InfoColumn_ID () { - Integer ii = (Integer)get_Value(COLUMNNAME_AD_Column_ID); + Integer ii = (Integer)get_Value(COLUMNNAME_AD_InfoColumn_ID); if (ii == null) return 0; return ii.intValue(); diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/info/InfoWindow.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/info/InfoWindow.java index 2aa7672d75..62e54d548e 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/info/InfoWindow.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/info/InfoWindow.java @@ -612,12 +612,15 @@ public class InfoWindow extends InfoPanel implements ValueChangeListener, EventL if (infoColumn.isDisplayed(infoContext, p_WindowNo)) { ColumnInfo columnInfo = null; + String colSQL = infoColumn.getSelectClause(); + if (! colSQL.toUpperCase().contains(" AS ")) + colSQL += " AS " + infoColumn.getColumnName(); if (infoColumn.getAD_Reference_ID() == DisplayType.ID) { if (infoColumn.getSelectClause().equalsIgnoreCase(keySelectClause)) continue; - columnInfo = new ColumnInfo(infoColumn.get_Translation("Name"), infoColumn.getSelectClause(), DisplayType.getClass(infoColumn.getAD_Reference_ID(), true)); + columnInfo = new ColumnInfo(infoColumn.get_Translation("Name"), colSQL, DisplayType.getClass(infoColumn.getAD_Reference_ID(), true)); } else if (DisplayType.isLookup(infoColumn.getAD_Reference_ID())) { @@ -627,8 +630,8 @@ public class InfoWindow extends InfoPanel implements ValueChangeListener, EventL editor = WebEditorFactory.getEditor(gridFields.get(i), true); editor.setMandatory(false); editor.setReadWrite(false); - editorMap.put(infoColumn.getSelectClause(), editor); - columnInfo = new ColumnInfo(infoColumn.get_Translation("Name"), infoColumn.getSelectClause(), ValueNamePair.class, (String)null); + editorMap.put(colSQL, editor); + columnInfo = new ColumnInfo(infoColumn.get_Translation("Name"), colSQL, ValueNamePair.class, (String)null); } else { @@ -637,7 +640,7 @@ public class InfoWindow extends InfoPanel implements ValueChangeListener, EventL } else { - columnInfo = new ColumnInfo(infoColumn.get_Translation("Name"), infoColumn.getSelectClause(), DisplayType.getClass(infoColumn.getAD_Reference_ID(), true)); + columnInfo = new ColumnInfo(infoColumn.get_Translation("Name"), colSQL, DisplayType.getClass(infoColumn.getAD_Reference_ID(), true)); } columnInfo.setColDescription(infoColumn.get_Translation("Description")); columnInfo.setGridField(gridFields.get(i)); @@ -681,9 +684,12 @@ public class InfoWindow extends InfoPanel implements ValueChangeListener, EventL editor = WebEditorFactory.getEditor(gridField, true); editor.setMandatory(false); editor.setReadWrite(false); - editorMap.put(infoColumn.getSelectClause(), editor); - - ColumnInfo columnInfo = new ColumnInfo(infoColumn.get_Translation("Name"), infoColumn.getSelectClause(), KeyNamePair.class, (String)null); + + String colSQL = infoColumn.getSelectClause(); + if (! colSQL.toUpperCase().contains(" AS ")) + colSQL += " AS " + infoColumn.getColumnName(); + editorMap.put(colSQL, editor); + ColumnInfo columnInfo = new ColumnInfo(infoColumn.get_Translation("Name"), colSQL, KeyNamePair.class, (String)null); return columnInfo; } @@ -916,7 +922,6 @@ public class InfoWindow extends InfoPanel implements ValueChangeListener, EventL String fromClause = m_sqlMain.substring(fromIndex); // get alias of main table - String alias = getTableName(); StringBuilder sqlBuilder = new StringBuilder(selectClause); // reset flag relate viewID to recount @@ -924,29 +929,25 @@ public class InfoWindow extends InfoPanel implements ValueChangeListener, EventL isHasViewID = false; // add View_ID column to select clause - for (MInfoProcess infoProcess : infoProcessList){ - String columnInQuery = infoProcess.getViewIDName(); + for (MInfoProcess infoProcess : infoProcessList) { // this process hasn't viewID column, next other infoProcess - if (columnInQuery == null) + if (infoProcess.getAD_InfoColumn_ID() <= 0) continue; - - // add alias of main table to column - columnInQuery = alias + "." + columnInQuery; - + + MInfoColumn infocol = (MInfoColumn) infoProcess.getAD_InfoColumn(); // maintain varial relate to ViewID, it can init just one time when load infoWindow define // but let it here for simple logic control numOfViewID++; isHasViewID = true; - - // if query is include this viewID column, not need add - if (sqlBuilder.toString().toLowerCase().contains(columnInQuery.toLowerCase())){ - continue; + + if (! infocol.isDisplayed()) { + // add column to SELECT clause of main sql + sqlBuilder.append(", "); + sqlBuilder.append (infocol.getSelectClause()); + sqlBuilder.append(" AS "); + sqlBuilder.append (infocol.getColumnName()); + sqlBuilder.append(" "); } - - // add column to SELECT clause of main sql - sqlBuilder.append(", "); - sqlBuilder.append (columnInQuery); - sqlBuilder.append(" "); } sqlBuilder.append(fromClause); @@ -1594,12 +1595,15 @@ public class InfoWindow extends InfoPanel implements ValueChangeListener, EventL if (infoColumn.isDisplayed(infoContext, p_WindowNo)) { ColumnInfo columnInfo = null; + String colSQL = infoColumn.getSelectClause(); + if (! colSQL.toUpperCase().contains(" AS ")) + colSQL += " AS " + infoColumn.getColumnName(); if (infoColumn.getAD_Reference_ID() == DisplayType.ID) { if (infoColumn.getSelectClause().equalsIgnoreCase(keySelectClause)) continue; - columnInfo = new ColumnInfo(infoColumn.get_Translation("Name"), infoColumn.getSelectClause(), DisplayType.getClass(infoColumn.getAD_Reference_ID(), true)); + columnInfo = new ColumnInfo(infoColumn.get_Translation("Name"), colSQL, DisplayType.getClass(infoColumn.getAD_Reference_ID(), true)); } else if (DisplayType.isLookup(infoColumn.getAD_Reference_ID())) { @@ -1609,8 +1613,8 @@ public class InfoWindow extends InfoPanel implements ValueChangeListener, EventL editor = WebEditorFactory.getEditor(getGridField(infoColumn), true); editor.setMandatory(false); editor.setReadWrite(false); - editorMap.put(infoColumn.getSelectClause(), editor); - columnInfo = new ColumnInfo(infoColumn.get_Translation("Name"), infoColumn.getSelectClause(), ValueNamePair.class, (String)null); + editorMap.put(colSQL, editor); + columnInfo = new ColumnInfo(infoColumn.get_Translation("Name"), colSQL, ValueNamePair.class, (String)null); } else { @@ -1620,7 +1624,7 @@ public class InfoWindow extends InfoPanel implements ValueChangeListener, EventL } else { - columnInfo = new ColumnInfo(infoColumn.get_Translation("Name"), infoColumn.getSelectClause(), DisplayType.getClass(infoColumn.getAD_Reference_ID(), true)); + columnInfo = new ColumnInfo(infoColumn.get_Translation("Name"), colSQL, DisplayType.getClass(infoColumn.getAD_Reference_ID(), true)); } columnInfo.setColDescription(infoColumn.get_Translation("Description")); columnInfo.setGridField(getGridField(infoColumn)); diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/panel/InfoPanel.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/panel/InfoPanel.java index 576ba81248..5143bfbae3 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/panel/InfoPanel.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/panel/InfoPanel.java @@ -60,6 +60,7 @@ import org.adempiere.webui.session.SessionManager; import org.adempiere.webui.window.FDialog; import org.compiere.minigrid.ColumnInfo; import org.compiere.minigrid.IDColumn; +import org.compiere.model.MInfoColumn; import org.compiere.model.MInfoWindow; import org.compiere.model.MPInstance; import org.compiere.model.MProcess; @@ -518,21 +519,20 @@ public abstract class InfoPanel extends Window implements EventListener, * IDEMPIERE-1970 */ protected void readViewID(ResultSet rs, List data) throws SQLException { - if (infoProcessList == null || infoProcessList.length == 0){ + if (infoProcessList == null || infoProcessList.length == 0) { return; } - + // with each process have viewID, read it form resultSet by name for (MInfoProcess infoProcess : infoProcessList){ - if (infoProcess.getAD_Column_ID() == 0){ + if (infoProcess.getAD_InfoColumn_ID() <= 0) continue; - } - String viewIDSql = infoProcess.getViewIDName(); - String viewIDValue = rs.getString(viewIDSql); - if (rs.wasNull()){ + MInfoColumn infocol = (MInfoColumn) infoProcess.getAD_InfoColumn(); + String viewIDValue = rs.getString(infocol.getColumnName()); + if (rs.wasNull()) { data.add(null); - }else{ + } else { data.add(viewIDValue); } } @@ -1511,7 +1511,7 @@ public abstract class InfoPanel extends Window implements EventListener, return index; } // just increase index when process is have ViewID column - if (infoProcessList[i].getAD_Column_ID() > 0) + if (infoProcessList[i].getAD_InfoColumn_ID() > 0) index++; } return -1;