From ea3bbe141823f1e5b49e2ffe868e6a8aeed40195 Mon Sep 17 00:00:00 2001 From: hieplq Date: Wed, 4 Jun 2014 00:19:25 +0700 Subject: [PATCH] IDEMPIERE-1968:valid check box in info window can manual editable --- .../oracle/201406031604_IDEMPIERE-1968.sql | 22 +++++ .../201406031604_IDEMPIERE-1968.sql | 18 ++++ .../src/org/compiere/model/MInfoColumn.java | 33 ++++++++ .../src/org/compiere/model/MInfoWindow.java | 83 +++++++++++++++++++ 4 files changed, 156 insertions(+) create mode 100644 migration/i2.0z/oracle/201406031604_IDEMPIERE-1968.sql create mode 100644 migration/i2.0z/postgresql/201406031604_IDEMPIERE-1968.sql diff --git a/migration/i2.0z/oracle/201406031604_IDEMPIERE-1968.sql b/migration/i2.0z/oracle/201406031604_IDEMPIERE-1968.sql new file mode 100644 index 0000000000..902b39b2b0 --- /dev/null +++ b/migration/i2.0z/oracle/201406031604_IDEMPIERE-1968.sql @@ -0,0 +1,22 @@ +SET SQLBLANKLINES ON +SET DEFINE OFF + +-- Jun 3, 2014 4:22:36 PM ICT +-- I forgot to set the DICTIONARY_ID_COMMENTS System Configurator +UPDATE AD_Field SET IsReadOnly='Y',Updated=TO_DATE('2014-06-03 16:22:36','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Field_ID=201639 +; +-- Jun 3, 2014 11:42:11 PM ICT +-- I forgot to set the DICTIONARY_ID_COMMENTS System Configurator +UPDATE AD_Column SET AD_Process_ID=NULL,Updated=TO_DATE('2014-06-03 23:42:11','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Column_ID=15759 +; + +-- Jun 3, 2014 11:44:39 PM ICT +UPDATE AD_Column SET IsToolbarButton='N', AD_Reference_ID=10,Updated=TO_DATE('2014-06-03 23:44:39','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Column_ID=15759 +; + +-- Jun 3, 2014 11:47:13 PM ICT +UPDATE AD_Field SET IsDisplayed='N',Updated=TO_DATE('2014-06-03 23:47:13','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Field_ID=13580 +; + +SELECT register_migration_script('201406031604_IDEMPIERE-1968.sql') FROM dual +; diff --git a/migration/i2.0z/postgresql/201406031604_IDEMPIERE-1968.sql b/migration/i2.0z/postgresql/201406031604_IDEMPIERE-1968.sql new file mode 100644 index 0000000000..63addd80f2 --- /dev/null +++ b/migration/i2.0z/postgresql/201406031604_IDEMPIERE-1968.sql @@ -0,0 +1,18 @@ +-- Jun 3, 2014 4:22:36 PM ICT +-- I forgot to set the DICTIONARY_ID_COMMENTS System Configurator +UPDATE AD_Field SET IsReadOnly='Y',Updated=TO_TIMESTAMP('2014-06-03 16:22:36','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Field_ID=201639 +; +-- I forgot to set the DICTIONARY_ID_COMMENTS System Configurator +UPDATE AD_Column SET AD_Process_ID=NULL,Updated=TO_TIMESTAMP('2014-06-03 23:42:11','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Column_ID=15759 +; + +-- Jun 3, 2014 11:44:39 PM ICT +UPDATE AD_Column SET IsToolbarButton='N', AD_Reference_ID=10,Updated=TO_TIMESTAMP('2014-06-03 23:44:39','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Column_ID=15759 +; + +-- Jun 3, 2014 11:47:13 PM ICT +UPDATE AD_Field SET IsDisplayed='N',Updated=TO_TIMESTAMP('2014-06-03 23:47:13','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Field_ID=13580 +; + +SELECT register_migration_script('201406031604_IDEMPIERE-1968.sql') FROM dual +; diff --git a/org.adempiere.base/src/org/compiere/model/MInfoColumn.java b/org.adempiere.base/src/org/compiere/model/MInfoColumn.java index e277a3862b..d296fbbda7 100644 --- a/org.adempiere.base/src/org/compiere/model/MInfoColumn.java +++ b/org.adempiere.base/src/org/compiere/model/MInfoColumn.java @@ -131,5 +131,38 @@ public class MInfoColumn extends X_AD_InfoColumn return true; } + /** + * when change field relate to sql, call valid from infoWindow + */ + @Override + protected boolean afterSave(boolean newRecord, boolean success) { + if (!success) + return success; + // evaluate need valid + boolean isNeedValid = newRecord || is_ValueChanged (MInfoColumn.COLUMNNAME_SelectClause); + + // call valid of parrent + if (isNeedValid){ + MInfoWindow parentInfo = new MInfoWindow (getCtx(), this.getAD_InfoWindow_ID(), get_TrxName()); + parentInfo.validate(); + parentInfo.saveEx(); + } + + + return super.afterSave(newRecord, success); + } + + /** + * when delete record, call valid from parent to set state + * when delete all, valid state is false + * when delete a wrong column can make valid state to true + */ + @Override + protected boolean afterDelete(boolean success) { + MInfoWindow parentInfo = new MInfoWindow (getCtx(), this.getAD_InfoWindow_ID(), get_TrxName()); + parentInfo.validate(); + parentInfo.saveEx(); + return super.afterDelete(success); + } } // MInfoColumn diff --git a/org.adempiere.base/src/org/compiere/model/MInfoWindow.java b/org.adempiere.base/src/org/compiere/model/MInfoWindow.java index ee9a3b7d67..19d431cb13 100644 --- a/org.adempiere.base/src/org/compiere/model/MInfoWindow.java +++ b/org.adempiere.base/src/org/compiere/model/MInfoWindow.java @@ -329,6 +329,17 @@ public class MInfoWindow extends X_AD_InfoWindow } } } + + // evaluate need valid + boolean isNeedValid = is_new() || is_ValueChanged (I_AD_InfoWindow.COLUMNNAME_AD_Table_ID) || is_ValueChanged (I_AD_InfoWindow.COLUMNNAME_WhereClause) || + is_ValueChanged (I_AD_InfoWindow.COLUMNNAME_FromClause) || is_ValueChanged (I_AD_InfoWindow.COLUMNNAME_OrderByClause) || + is_ValueChanged (I_AD_InfoWindow.COLUMNNAME_OtherClause) || is_ValueChanged (I_AD_InfoWindow.COLUMNNAME_IsDistinct); + + // valid config + if (isNeedValid){ + validate(); + } + return true; } @@ -363,4 +374,76 @@ public class MInfoWindow extends X_AD_InfoWindow } + public void validate () + { + // default, before complete check is invalid + this.setIsValid(false); + + // add DISTINCT clause + StringBuilder builder = new StringBuilder("SELECT "); + if (this.isDistinct()) + builder.append("DISTINCT "); + + MInfoColumn[] infoColumns = this.getInfoColumns(); + // none column make this invalid + if (infoColumns.length == 0){ + return; + } + + // build select clause + for (int columnIndex = 0; columnIndex < infoColumns.length; columnIndex++) { + if (columnIndex > 0) + { + builder.append(", "); + } + builder.append(infoColumns[columnIndex].getSelectClause()); + } + + // build from clause + builder.append( " FROM ").append(this.getFromClause()); + + // build where clause add (1=2) because not need get result, decrease load + if (this.getWhereClause() != null && this.getWhereClause().trim().length() > 0) { + builder.append(" WHERE (1=2) AND (").append(this.getWhereClause()).append(")"); + } else { + builder.append(" WHERE 1=2"); + } + + // build other (having) clause + if (this.getOtherClause() != null && this.getOtherClause().trim().length() > 0) { + builder.append(" ").append(this.getOtherClause()); + } + + // build order (having) clause + if (this.getOrderByClause() != null && this.getOrderByClause().trim().length() > 0) { + builder.append(" ORDER BY ").append(this.getOrderByClause()); + } + + // replace env value by dummy value + while(builder.indexOf("@") >= 0) { + int start = builder.indexOf("@"); + int end = builder.indexOf("@", start+1); + if (start >=0 && end > start) { + builder.replace(start, end+1, "0"); + } else { + break; + } + } + + // try run sql + PreparedStatement pstmt = null; + try { + pstmt = DB.prepareStatement(builder.toString(), null); + pstmt.executeQuery(); + }catch (Exception ex){ + log.log(Level.WARNING, ex.getMessage()); + return; + } finally { + DB.close(pstmt); + } + + // valid state + this.setIsValid(true); + } + } // MInfoWindow