From 3d6ac16d00871ef3b536a9f1fef8d82e4ab7ad3d Mon Sep 17 00:00:00 2001 From: hieplq Date: Thu, 4 Jan 2024 22:15:35 +0700 Subject: [PATCH] IDEMPIERE-5062:Min/Max Validation for Process Parameters is not implemented (#2176) * IDEMPIERE-5062:Min/Max Validation for Process Parameters is not implemented https://idempiere.atlassian.net/browse/IDEMPIERE-5062?focusedCommentId=50418 * IDEMPIERE-5062:Min/Max Validation for Process Parameters is not implemented (report all error at one) https://idempiere.atlassian.net/browse/IDEMPIERE-5062?focusedCommentId=50331 * Update ProcessParameterPanel.java - tests --------- Co-authored-by: Carlos Ruiz --- .../webui/apps/ProcessParameterPanel.java | 53 +++++++++++++------ 1 file changed, 38 insertions(+), 15 deletions(-) diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/ProcessParameterPanel.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/ProcessParameterPanel.java index e6cc827601..d144f70c1a 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/ProcessParameterPanel.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/ProcessParameterPanel.java @@ -79,6 +79,7 @@ import org.compiere.util.Util; import org.zkoss.zk.ui.Component; import org.zkoss.zk.ui.HtmlBasedComponent; import org.zkoss.zk.ui.WrongValueException; +import org.zkoss.zk.ui.WrongValuesException; import org.zkoss.zk.ui.event.Event; import org.zkoss.zk.ui.event.EventListener; import org.zkoss.zk.ui.event.Events; @@ -579,18 +580,23 @@ public class ProcessParameterPanel extends Panel implements if (log.isLoggable(Level.CONFIG)) log.config(""); //mandatory fields validation + Map wrongValidateComponents = new HashMap<>(); int size = m_mFields.size(); for (int i = 0; i < size; i++) { GridField field = (GridField) m_mFields.get(i); GridField field2 = (GridField) m_mFields2.get(i); WEditor wEditor = (WEditor) m_wEditors.get(i); + if (wEditor.getComponent() instanceof InputElement) + ((InputElement)wEditor.getComponent()).clearErrorMessage(); WEditor wEditor2 = (WEditor) m_wEditors2.get(i); + if (wEditor2 != null && wEditor2.getComponent() instanceof InputElement) + ((InputElement)wEditor2.getComponent()).clearErrorMessage(); Object data = wEditor.getValue(); String msg = validate(data, field.getValueMin(), field.getValueMax(), field.isMandatory(true), field.getDisplayType()); if (msg != null) { field.setInserting(true); // set editable (i.e. updateable) otherwise deadlock field.setError(true); - throw new WrongValueException(wEditor.getComponent(), msg); + wrongValidateComponents.put(wEditor.getComponent(), msg); } if (m_wEditors2.get(i) != null) { // is a range data = wEditor2.getValue(); @@ -598,12 +604,22 @@ public class ProcessParameterPanel extends Panel implements if (msg != null) { field2.setInserting(true); // set editable (i.e. updateable) otherwise deadlock field2.setError(true); - throw new WrongValueException(wEditor2.getComponent(), msg); + wrongValidateComponents.put(wEditor2.getComponent(), msg); } } } // field loop + List wrongValues = new ArrayList(); + + wrongValidateComponents.forEach((component, msg) -> { + WrongValueException wrongValueException = new WrongValueException(component, msg); + wrongValues.add(wrongValueException); + }); + + if (wrongValues.size() > 0) + throw new WrongValuesException(wrongValues.toArray(new WrongValueException[0])); + /** call {@link IProcessParameterListener} validate(ProcessParameterPanel) **/ if (m_processInfo.getAD_Process_ID() > 0) { String className = MProcess.get(Env.getCtx(), m_processInfo.getAD_Process_ID()).getClassname(); @@ -645,7 +661,7 @@ public class ProcessParameterPanel extends Panel implements Timestamp valueMax_TS = null; if (fieldType == DisplayType.Date) { - SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-mm-dd"); + SimpleDateFormat dateFormat = new SimpleDateFormat(DisplayType.DEFAULT_DATE_FORMAT); if (value != null) { try { value_TS = new Timestamp(dateFormat.parse(value.toString()).getTime()); } catch (Exception ex){} } @@ -655,6 +671,13 @@ public class ProcessParameterPanel extends Panel implements if (valueMax != null) { try { valueMax_TS = new Timestamp(dateFormat.parse(valueMax).getTime()); } catch (Exception ex){} } + + if (value_TS != null && valueMin_TS != null && value_TS.before(valueMin_TS)) + return Msg.getMsg(Env.getCtx(), "LessThanMinValue", new Object[] {valueMin}); + + if (value_TS != null && valueMax_TS != null && value_TS.after(valueMax_TS)) + return Msg.getMsg(Env.getCtx(), "MoreThanMaxValue", new Object[] {valueMax}); + } else if (DisplayType.isNumeric(fieldType)) { if (value != null) { try { value_BD = new BigDecimal(value.toString()); } catch (Exception ex){} @@ -665,20 +688,20 @@ public class ProcessParameterPanel extends Panel implements if (valueMax != null) { try { valueMax_BD = new BigDecimal(valueMax); } catch (Exception ex){} } + + if (value_BD != null && valueMin_BD != null && valueMin_BD.compareTo(value_BD) > 0) + return Msg.getMsg(Env.getCtx(), "LessThanMinValue", new Object[] {valueMin}); + + if (value_BD != null && valueMax_BD != null && valueMax_BD.compareTo(value_BD) < 0) + return Msg.getMsg(Env.getCtx(), "MoreThanMaxValue", new Object[] {valueMax}); + } else { + if (value != null && valueMin != null && valueMin.compareTo(value.toString()) > 0) + return Msg.getMsg(Env.getCtx(), "LessThanMinValue", new Object[] {valueMin}); + + if (value != null && valueMax != null && valueMax.compareTo(value.toString()) < 0) + return Msg.getMsg(Env.getCtx(), "MoreThanMaxValue", new Object[] {valueMax}); } - if ( (value_TS != null && valueMin_TS != null && value_TS.before(valueMin_TS)) - || (value_BD != null && valueMin_BD != null && valueMin_BD.compareTo(value_BD) > 0) - || (value != null && valueMin != null && valueMin.compareTo(value.toString()) > 0) - ) - return Msg.getMsg(Env.getCtx(), "LessThanMinValue", new Object[] {valueMin}); - - if ( (value_TS != null && valueMax_TS != null && value_TS.after(valueMax_TS)) - || (value_BD != null && valueMax_BD != null && valueMax_BD.compareTo(value_BD) < 0) - || (value != null && valueMax != null && valueMax.compareTo(value.toString()) < 0) - ) - return Msg.getMsg(Env.getCtx(), "MoreThanMaxValue", new Object[] {valueMax}); - return null; }