From 080ba69967ac1a490a343b9bf188646280abda05 Mon Sep 17 00:00:00 2001 From: Nicolas Micoud <58596990+nmicoud@users.noreply.github.com> Date: Thu, 30 Sep 2021 09:56:58 +0200 Subject: [PATCH] =?UTF-8?q?IDEMPIERE-4982=20:=20Methods=20to=20retrieve=20?= =?UTF-8?q?value=20from=20multiple=20process=20para=E2=80=A6=20(#901)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * IDEMPIERE-4982 : Methods to retrieve value from multiple process parameters Co-authored-by: hengsin <152246+hengsin@users.noreply.github.com> --- .../process/ProcessInfoParameter.java | 150 +++++++++++++++++- 1 file changed, 149 insertions(+), 1 deletion(-) diff --git a/org.adempiere.base/src/org/compiere/process/ProcessInfoParameter.java b/org.adempiere.base/src/org/compiere/process/ProcessInfoParameter.java index 2c8d5a718f..9e5836466f 100644 --- a/org.adempiere.base/src/org/compiere/process/ProcessInfoParameter.java +++ b/org.adempiere.base/src/org/compiere/process/ProcessInfoParameter.java @@ -19,6 +19,11 @@ package org.compiere.process; import java.io.Serializable; import java.math.BigDecimal; import java.sql.Timestamp; +import java.util.ArrayList; +import java.util.Arrays; + +import org.compiere.util.DB; +import org.compiere.util.Util; /** @@ -32,10 +37,11 @@ import java.sql.Timestamp; */ public class ProcessInfoParameter implements Serializable { + /** * */ - private static final long serialVersionUID = -8571973325856537109L; + private static final long serialVersionUID = -5396796617617359891L; /** * Construct Parameter @@ -198,6 +204,18 @@ public class ProcessInfoParameter implements Serializable } // getParameterAsTimestamp + /** + * Method getParameter To as String + * @return Object + */ + public String getParameter_ToAsString() + { + if (m_Parameter_To == null) + return null; + return m_Parameter_To.toString(); + } // getParameter_ToAsString + + /** * Method getParameter as String * @return Object @@ -282,4 +300,134 @@ public class ProcessInfoParameter implements Serializable m_ParameterName = ParameterName; } + /** + * Return the value of the parameter as a comma separated integer string. Validate every value is an integer and throws NumberFormatException if one of the value is not a valid integer. + * @return String + */ + public String getParameterAsCSVInt() { + return getParameterAsCSVInt(getParameterAsString()); + } + + /** + * Return the value of the parameter To as a comma separated integer string. Validate every value is an integer and throws NumberFormatException if one of the value is not a valid integer. + * @return String + */ + public String getParameter_ToAsCSVInt() { + return getParameterAsCSVInt(getParameter_ToAsString()); + } + + /** + * Return the value of the parameter as a validated String (all values between commas must be integer) + * @return String + */ + private String getParameterAsCSVInt(String param) { + + if (Util.isEmpty(param)) + return ""; + + String[] strarr = param.split(","); + + for (String par : strarr) + Integer.valueOf(par); + + return param; + } + + /** + * Return the value of the parameter as a String with all values between commas surrounded by quotes + * @return String + */ + public String getParameterAsCSVString() { + return getParameterAsCSVString(getParameterAsString()); + } + + /** + * Return the value of the parameter as a String with all values between commas surrounded by quotes + * @return String + */ + public String getParameter_ToAsCSVString() { + return getParameterAsCSVString(getParameter_ToAsString()); + } + + /** + * Return the value of the parameter as a String with all values between commas surrounded by quotes + * @return String + */ + private String getParameterAsCSVString(String param) { + if (Util.isEmpty(param)) + return ""; + + String[] strarr = ((String) param).split(","); + + StringBuilder whereValidated = new StringBuilder(); + for (String par : strarr) { + if (whereValidated.length() > 0) + whereValidated.append(","); + whereValidated.append(DB.TO_STRING(par)); + } + + return whereValidated.toString(); + } + + /** + * Return the value of the parameter as an array of int. Validate every value is an integer and throws NumberFormatException if one of the value is not a valid integer. + * @return array of int + */ + public int[] getParameterAsIntArray() { + return getParameterAsIntArray(getParameterAsString()); + } + + /** + * Return the value of the parameter To as an array of int. Validate every value is an integer and throws NumberFormatException if one of the value is not a valid integer. + * @return array of int + */ + public int[] getParameterToAsIntArray() { + return getParameterAsIntArray(getParameter_ToAsString()); + } + + /** + * Return the value of the parameter as an array of int. Validate every value is an integer and throws NumberFormatException if one of the value is not a valid integer. + * @return array of int + */ + private int[] getParameterAsIntArray(String param) { + + if (Util.isEmpty(param)) + return new int[0]; + + return Arrays.stream(param.split(",")).mapToInt(Integer::parseInt).toArray(); + } + + /** + * Return the value of the parameter as an array of String. + * @return array of String + */ + public String[] getParameterAsStringArray() { + return getParameterAsStringArray(getParameterAsString()); + } + + /** + * Return the value of the parameter To as an array of String. + * @return array of String + */ + public String[] getParameterToAsStringArray() { + return getParameterAsStringArray(getParameter_ToAsString()); + } + + /** + * Return the value of the parameter as an array of String. + * @return array of String + */ + private String[] getParameterAsStringArray(String param) { + + ArrayList list = new ArrayList(); + + if (!Util.isEmpty(param)) { + for (String par : param.split(",")) + list.add(par); + } + + String[] retValue = new String[list.size()]; + list.toArray(retValue); + return retValue; + } } // ProcessInfoParameter