From 502291a31319b230cafc5eabc10f1aea786506bc Mon Sep 17 00:00:00 2001 From: Heng Sin Low Date: Fri, 8 Mar 2013 12:57:51 +0800 Subject: [PATCH] IDEMPIERE-704 The Min. value and Max. value validation of column is not working. --- .../oracle/201303071224_IDEMPIERE-704.sql | 23 +++ .../postgresql/201303071224_IDEMPIERE-704.sql | 23 +++ .../src/org/compiere/model/GridTable.java | 19 ++- .../src/org/compiere/model/PO.java | 144 ++++++++---------- .../src/org/compiere/model/POInfo.java | 19 +-- 5 files changed, 130 insertions(+), 98 deletions(-) create mode 100644 migration/i1.0a-release/oracle/201303071224_IDEMPIERE-704.sql create mode 100644 migration/i1.0a-release/postgresql/201303071224_IDEMPIERE-704.sql diff --git a/migration/i1.0a-release/oracle/201303071224_IDEMPIERE-704.sql b/migration/i1.0a-release/oracle/201303071224_IDEMPIERE-704.sql new file mode 100644 index 0000000000..a80072eaac --- /dev/null +++ b/migration/i1.0a-release/oracle/201303071224_IDEMPIERE-704.sql @@ -0,0 +1,23 @@ +-- Mar 7, 2013 8:21:59 PM MYT +-- IDEMPIERE-704 The Min. value and Max. value validation of column is not working +INSERT INTO AD_Message (MsgType,MsgText,AD_Message_ID,EntityType,AD_Message_UU,Value,IsActive,Updated,CreatedBy,UpdatedBy,AD_Client_ID,AD_Org_ID,Created) VALUES ('E','Entered value is more than the maximum ({0}) allowed',200150,'D','af92320e-f5a9-4dee-a1d4-3bfa8bbf3dbd','MoreThanMaxValue','Y',TO_DATE('2013-03-07 20:21:57','YYYY-MM-DD HH24:MI:SS'),100,100,0,0,TO_DATE('2013-03-07 20:21:57','YYYY-MM-DD HH24:MI:SS')) +; + +-- Mar 7, 2013 8:21:59 PM MYT +-- IDEMPIERE-704 The Min. value and Max. value validation of column is not working +INSERT INTO AD_Message_Trl (AD_Language,AD_Message_ID, MsgText,MsgTip, IsTranslated,AD_Client_ID,AD_Org_ID,Created,Createdby,Updated,UpdatedBy,AD_Message_Trl_UU ) SELECT l.AD_Language,t.AD_Message_ID, t.MsgText,t.MsgTip, 'N',t.AD_Client_ID,t.AD_Org_ID,t.Created,t.Createdby,t.Updated,t.UpdatedBy,Generate_UUID() FROM AD_Language l, AD_Message t WHERE l.IsActive='Y' AND l.IsSystemLanguage='Y' AND l.IsBaseLanguage='N' AND t.AD_Message_ID=200150 AND NOT EXISTS (SELECT * FROM AD_Message_Trl tt WHERE tt.AD_Language=l.AD_Language AND tt.AD_Message_ID=t.AD_Message_ID) +; + +-- Mar 7, 2013 8:22:22 PM MYT +-- IDEMPIERE-704 The Min. value and Max. value validation of column is not working +INSERT INTO AD_Message (MsgType,MsgText,AD_Message_ID,EntityType,AD_Message_UU,Value,IsActive,Updated,CreatedBy,UpdatedBy,AD_Client_ID,AD_Org_ID,Created) VALUES ('E','Entered value is less than the minimum ({0}) required',200151,'D','4402e2b3-803e-4bd2-b77c-86059fe10346','LessThanMinValue','Y',TO_DATE('2013-03-07 20:22:21','YYYY-MM-DD HH24:MI:SS'),100,100,0,0,TO_DATE('2013-03-07 20:22:21','YYYY-MM-DD HH24:MI:SS')) +; + +-- Mar 7, 2013 8:22:22 PM MYT +-- IDEMPIERE-704 The Min. value and Max. value validation of column is not working +INSERT INTO AD_Message_Trl (AD_Language,AD_Message_ID, MsgText,MsgTip, IsTranslated,AD_Client_ID,AD_Org_ID,Created,Createdby,Updated,UpdatedBy,AD_Message_Trl_UU ) SELECT l.AD_Language,t.AD_Message_ID, t.MsgText,t.MsgTip, 'N',t.AD_Client_ID,t.AD_Org_ID,t.Created,t.Createdby,t.Updated,t.UpdatedBy,Generate_UUID() FROM AD_Language l, AD_Message t WHERE l.IsActive='Y' AND l.IsSystemLanguage='Y' AND l.IsBaseLanguage='N' AND t.AD_Message_ID=200151 AND NOT EXISTS (SELECT * FROM AD_Message_Trl tt WHERE tt.AD_Language=l.AD_Language AND tt.AD_Message_ID=t.AD_Message_ID) +; + +SELECT register_migration_script('201303071224_IDEMPIERE-704.sql') FROM dual +; + diff --git a/migration/i1.0a-release/postgresql/201303071224_IDEMPIERE-704.sql b/migration/i1.0a-release/postgresql/201303071224_IDEMPIERE-704.sql new file mode 100644 index 0000000000..e3ef0ddf91 --- /dev/null +++ b/migration/i1.0a-release/postgresql/201303071224_IDEMPIERE-704.sql @@ -0,0 +1,23 @@ +-- Mar 7, 2013 8:21:59 PM MYT +-- IDEMPIERE-704 The Min. value and Max. value validation of column is not working +INSERT INTO AD_Message (MsgType,MsgText,AD_Message_ID,EntityType,AD_Message_UU,Value,IsActive,Updated,CreatedBy,UpdatedBy,AD_Client_ID,AD_Org_ID,Created) VALUES ('E','Entered value is more than the maximum ({0}) allowed',200150,'D','af92320e-f5a9-4dee-a1d4-3bfa8bbf3dbd','MoreThanMaxValue','Y',TO_TIMESTAMP('2013-03-07 20:21:57','YYYY-MM-DD HH24:MI:SS'),100,100,0,0,TO_TIMESTAMP('2013-03-07 20:21:57','YYYY-MM-DD HH24:MI:SS')) +; + +-- Mar 7, 2013 8:21:59 PM MYT +-- IDEMPIERE-704 The Min. value and Max. value validation of column is not working +INSERT INTO AD_Message_Trl (AD_Language,AD_Message_ID, MsgText,MsgTip, IsTranslated,AD_Client_ID,AD_Org_ID,Created,Createdby,Updated,UpdatedBy,AD_Message_Trl_UU ) SELECT l.AD_Language,t.AD_Message_ID, t.MsgText,t.MsgTip, 'N',t.AD_Client_ID,t.AD_Org_ID,t.Created,t.Createdby,t.Updated,t.UpdatedBy,Generate_UUID() FROM AD_Language l, AD_Message t WHERE l.IsActive='Y' AND l.IsSystemLanguage='Y' AND l.IsBaseLanguage='N' AND t.AD_Message_ID=200150 AND NOT EXISTS (SELECT * FROM AD_Message_Trl tt WHERE tt.AD_Language=l.AD_Language AND tt.AD_Message_ID=t.AD_Message_ID) +; + +-- Mar 7, 2013 8:22:22 PM MYT +-- IDEMPIERE-704 The Min. value and Max. value validation of column is not working +INSERT INTO AD_Message (MsgType,MsgText,AD_Message_ID,EntityType,AD_Message_UU,Value,IsActive,Updated,CreatedBy,UpdatedBy,AD_Client_ID,AD_Org_ID,Created) VALUES ('E','Entered value is less than the minimum ({0}) required',200151,'D','4402e2b3-803e-4bd2-b77c-86059fe10346','LessThanMinValue','Y',TO_TIMESTAMP('2013-03-07 20:22:21','YYYY-MM-DD HH24:MI:SS'),100,100,0,0,TO_TIMESTAMP('2013-03-07 20:22:21','YYYY-MM-DD HH24:MI:SS')) +; + +-- Mar 7, 2013 8:22:22 PM MYT +-- IDEMPIERE-704 The Min. value and Max. value validation of column is not working +INSERT INTO AD_Message_Trl (AD_Language,AD_Message_ID, MsgText,MsgTip, IsTranslated,AD_Client_ID,AD_Org_ID,Created,Createdby,Updated,UpdatedBy,AD_Message_Trl_UU ) SELECT l.AD_Language,t.AD_Message_ID, t.MsgText,t.MsgTip, 'N',t.AD_Client_ID,t.AD_Org_ID,t.Created,t.Createdby,t.Updated,t.UpdatedBy,Generate_UUID() FROM AD_Language l, AD_Message t WHERE l.IsActive='Y' AND l.IsSystemLanguage='Y' AND l.IsBaseLanguage='N' AND t.AD_Message_ID=200151 AND NOT EXISTS (SELECT * FROM AD_Message_Trl tt WHERE tt.AD_Language=l.AD_Language AND tt.AD_Message_ID=t.AD_Message_ID) +; + +SELECT register_migration_script('201303071224_IDEMPIERE-704.sql') FROM dual +; + diff --git a/org.adempiere.base/src/org/compiere/model/GridTable.java b/org.adempiere.base/src/org/compiere/model/GridTable.java index d9a752639f..1c3aa68d9c 100644 --- a/org.adempiere.base/src/org/compiere/model/GridTable.java +++ b/org.adempiere.base/src/org/compiere/model/GridTable.java @@ -2121,7 +2121,24 @@ public class GridTable extends AbstractTableModel || ((value != null && dbValue != null && value.getClass().equals(byte[].class) && dbValue.getClass().equals(byte[].class)) && Arrays.equals((byte[])oldValue, (byte[])dbValue)) ) { - po.set_ValueNoCheck (columnName, value); + if (!po.set_ValueNoCheck (columnName, value)) + { + ValueNamePair lastError = CLogger.retrieveError(); + if (lastError != null) { + String adMessage = lastError.getValue(); + String adMessageArgument = lastError.getName().trim(); + + StringBuilder info = new StringBuilder(adMessageArgument); + + if (!adMessageArgument.endsWith(";")) info.append(";"); + info.append(field.getHeader()); + + fireDataStatusEEvent(adMessage, info.toString(), true); + } else { + fireDataStatusEEvent("Set value failed", field.getHeader(), true); + } + return SAVE_ERROR; + } } // Original != DB else diff --git a/org.adempiere.base/src/org/compiere/model/PO.java b/org.adempiere.base/src/org/compiere/model/PO.java index e0920ae018..c9f6fc9ece 100644 --- a/org.adempiere.base/src/org/compiere/model/PO.java +++ b/org.adempiere.base/src/org/compiere/model/PO.java @@ -683,6 +683,18 @@ public abstract class PO * @return true if value set */ protected final boolean set_Value (String ColumnName, Object value) + { + return set_Value(ColumnName, value, true); + } + + /************************************************************************** + * Set Value + * @param ColumnName column name + * @param value value + * @param checkWritable + * @return true if value set + */ + protected final boolean set_Value (String ColumnName, Object value, boolean checkWritable) { if (value instanceof String && ColumnName.equals("WhereClause") && value.toString().toUpperCase().indexOf("=NULL") != -1) @@ -692,6 +704,7 @@ public abstract class PO if (index < 0) { log.log(Level.SEVERE, "Column not found - " + ColumnName); + log.saveError("ColumnNotFound", "Column not found - " + ColumnName); return false; } if (ColumnName.endsWith("_ID") && value instanceof String ) @@ -705,7 +718,7 @@ public abstract class PO } } - return set_Value (index, value); + return set_Value (index, value, checkWritable); } // setValue /** @@ -727,6 +740,19 @@ public abstract class PO * @return true if value set */ protected final boolean set_Value (int index, Object value) + { + return set_Value(index, value, true); + } + + /** + * Set Value if updateable and correct class. + * (and to NULL if not mandatory) + * @param index index + * @param value value + * @param checkWritable + * @return true if value set + */ + protected final boolean set_Value (int index, Object value, boolean checkWritable) { if (index < 0 || index >= get_ColumnCount()) { @@ -736,26 +762,32 @@ public abstract class PO String ColumnName = p_info.getColumnName(index); String colInfo = " - " + ColumnName; // - if (p_info.isVirtualColumn(index)) + if (checkWritable) { - log.log(Level.WARNING, "Virtual Column" + colInfo); - return false; - } - - // - // globalqss -- Bug 1618469 - is throwing not updateable even on new records - // if (!p_info.isColumnUpdateable(index)) - if ( ( ! p_info.isColumnUpdateable(index) ) && ( ! is_new() ) ) - { - colInfo += " - NewValue=" + value + " - OldValue=" + get_Value(index); - log.log(Level.WARNING, "Column not updateable" + colInfo); - return false; + if (p_info.isVirtualColumn(index)) + { + log.log(Level.WARNING, "Virtual Column" + colInfo); + log.saveError("VirtualColumn", "Virtual Column" + colInfo); + return false; + } + + // + // globalqss -- Bug 1618469 - is throwing not updateable even on new records + // if (!p_info.isColumnUpdateable(index)) + if ( ( ! p_info.isColumnUpdateable(index) ) && ( ! is_new() ) ) + { + colInfo += " - NewValue=" + value + " - OldValue=" + get_Value(index); + log.log(Level.WARNING, "Column not updateable" + colInfo); + log.saveError("ColumnReadonly", "Column not updateable" + colInfo); + return false; + } } // if (value == null) { if (p_info.isColumnMandatory(index)) { + log.saveError("FillMandatory", ColumnName + " is mandatory."); throw new IllegalArgumentException (ColumnName + " is mandatory."); } m_newValues[index] = Null.NULL; // correct @@ -793,6 +825,9 @@ public abstract class PO log.log(Level.SEVERE, ColumnName + " - Class invalid: " + value.getClass().toString() + ", Should be " + p_info.getColumnClass(index).toString() + ": " + value); + log.saveError("WrongDataType", ColumnName + + " - Class invalid: " + value.getClass().toString() + + ", Should be " + p_info.getColumnClass(index).toString() + ": " + value); return false; } else @@ -800,6 +835,9 @@ public abstract class PO log.log(Level.SEVERE, ColumnName + " - Class invalid: " + value.getClass().toString() + ", Should be " + p_info.getColumnClass(index).toString() + ": " + value); + log.saveError("WrongDataType", ColumnName + + " - Class invalid: " + value.getClass().toString() + + ", Should be " + p_info.getColumnClass(index).toString() + ": " + value); return false; } // Validate (Min/Max) @@ -807,6 +845,12 @@ public abstract class PO if (error != null) { log.log(Level.WARNING, ColumnName + "=" + value + " - " + error); + int separatorIndex = error.indexOf(";"); + if (separatorIndex > 0) { + log.saveError(error.substring(0,separatorIndex), error.substring(separatorIndex+1)); + } else { + log.saveError(error, ColumnName); + } return false; } // Length for String @@ -831,6 +875,8 @@ public abstract class PO StringBuilder validValues = new StringBuilder(); for (ValueNamePair vp : MRefList.getList(getCtx(), p_info.getColumn(index).AD_Reference_Value_ID, false)) validValues.append(" - ").append(vp.getValue()); + log.saveError("Validate", ColumnName + " Invalid value - " + + value + " - Reference_ID=" + p_info.getColumn(index).AD_Reference_Value_ID + validValues.toString()); throw new IllegalArgumentException(ColumnName + " Invalid value - " + value + " - Reference_ID=" + p_info.getColumn(index).AD_Reference_Value_ID + validValues.toString()); } @@ -878,75 +924,7 @@ public abstract class PO */ public final boolean set_ValueNoCheck (String ColumnName, Object value) { - int index = get_ColumnIndex(ColumnName); - if (index < 0) - { - log.log(Level.SEVERE, "Column not found - " + ColumnName); - return false; - } - if (value == null) - m_newValues[index] = Null.NULL; // write direct - else - { - // matching class or generic object - if (value.getClass().equals(p_info.getColumnClass(index)) - || p_info.getColumnClass(index) == Object.class) - m_newValues[index] = value; // correct - // Integer can be set as BigDecimal - else if (value.getClass() == BigDecimal.class - && p_info.getColumnClass(index) == Integer.class) - m_newValues[index] = new Integer (((BigDecimal)value).intValue()); - // Set Boolean - else if (p_info.getColumnClass(index) == Boolean.class - && ("Y".equals(value) || "N".equals(value)) ) - m_newValues[index] = new Boolean("Y".equals(value)); - else if (p_info.getColumnClass(index) == Integer.class - && value.getClass() == String.class) - { - try - { - int intValue = Integer.parseInt((String)value); - m_newValues[index] = Integer.valueOf(intValue); - } - catch (Exception e) - { - log.warning (ColumnName - + " - Class invalid: " + value.getClass().toString() - + ", Should be " + p_info.getColumnClass(index).toString() + ": " + value); - m_newValues[index] = null; - } - } - else - { - log.warning (ColumnName - + " - Class invalid: " + value.getClass().toString() - + ", Should be " + p_info.getColumnClass(index).toString() + ": " + value); - m_newValues[index] = value; // correct - } - // Validate (Min/Max) - String error = p_info.validate(index, value); - if (error != null) - log.warning(ColumnName + "=" + value + " - " + error); - // length for String - if (p_info.getColumnClass(index) == String.class) - { - String stringValue = value.toString(); - int length = p_info.getFieldLength(index); - if (stringValue.length() > length && length > 0) - { - log.warning(ColumnName + " - Value too long - truncated to length=" + length); - m_newValues[index] = stringValue.substring(0,length); - } - } - } - if (log.isLoggable(Level.FINEST)) log.finest(ColumnName + " = " + m_newValues[index] - + " (" + (m_newValues[index]==null ? "-" : m_newValues[index].getClass().getName()) + ")"); - set_Keys (ColumnName, m_newValues[index]); - - // FR 2962094 Fill ProcessedOn when the Processed column is changing from N to Y - setProcessedOn(ColumnName, value, m_oldValues[index]); - - return true; + return set_Value(ColumnName, value, false); } // set_ValueNoCheck /** diff --git a/org.adempiere.base/src/org/compiere/model/POInfo.java b/org.adempiere.base/src/org/compiere/model/POInfo.java index b644e3463f..5a96799af7 100644 --- a/org.adempiere.base/src/org/compiere/model/POInfo.java +++ b/org.adempiere.base/src/org/compiere/model/POInfo.java @@ -663,7 +663,7 @@ public class POInfo implements Serializable // Mandatory (i.e. not null if (m_columns[index].IsMandatory && value == null) { - return "IsMandatory"; + return "FillMandatory"; } if (value == null) return null; @@ -686,10 +686,7 @@ public class POInfo implements Serializable int comp = m_columns[index].ValueMin_BD.compareTo(value_BD); if (comp > 0) { - return "MinValue=" + m_columns[index].ValueMin_BD - + "(" + m_columns[index].ValueMin + ")" - + " - compared with Numeric Value=" + value_BD + "(" + value + ")" - + " - results in " + comp; + return "LessThanMinValue"+";"+m_columns[index].ValueMin_BD.toPlainString(); } } else // String @@ -697,9 +694,7 @@ public class POInfo implements Serializable int comp = m_columns[index].ValueMin.compareTo(value.toString()); if (comp > 0) { - return "MinValue=" + m_columns[index].ValueMin - + " - compared with String Value=" + value - + " - results in " + comp; + return "LessThanMinValue"+";"+m_columns[index].ValueMin; } } } @@ -718,9 +713,7 @@ public class POInfo implements Serializable int comp = m_columns[index].ValueMax_BD.compareTo(value_BD); if (comp < 0) { - return "MaxValue=" + m_columns[index].ValueMax_BD + "(" + m_columns[index].ValueMax + ")" - + " - compared with Numeric Value=" + value_BD + "(" + value + ")" - + " - results in " + comp; + return "MoreThanMaxValue"+";"+m_columns[index].ValueMax_BD.toPlainString(); } } else // String @@ -728,9 +721,7 @@ public class POInfo implements Serializable int comp = m_columns[index].ValueMax.compareTo(value.toString()); if (comp < 0) { - return "MaxValue=" + m_columns[index].ValueMax - + " - compared with String Value=" + value - + " - results in " + comp; + return "MoreThanMaxValue"+";"+m_columns[index].ValueMax; } } }