From 02ddce255ecfae30aab3b84327479d801120798d Mon Sep 17 00:00:00 2001 From: likp Date: Wed, 26 Mar 2025 16:27:00 +0100 Subject: [PATCH 1/3] Fix for selection expressions --- .../Api2/DataSelection/SelectionHandler.cs | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/PxWeb/Code/Api2/DataSelection/SelectionHandler.cs b/PxWeb/Code/Api2/DataSelection/SelectionHandler.cs index f1249904..df57173e 100644 --- a/PxWeb/Code/Api2/DataSelection/SelectionHandler.cs +++ b/PxWeb/Code/Api2/DataSelection/SelectionHandler.cs @@ -106,20 +106,30 @@ private static bool ExpandSelectionExpressionsAndVerifyValues(IPXModelBuilder bu { var modelVariable = model.Meta.Variables.GetByCode(variable.VariableCode); + var valueCodes = variable.ValueCodes.ToList(); - for (int i = 0; i < variable.ValueCodes.Count; i++) + foreach (var valueCode in valueCodes) { - var valueCode = variable.ValueCodes[i]; // Try to get the value using the code specified by the API user Value? pxValue = modelVariable.Values.FirstOrDefault(x => x.Code.Equals(valueCode, System.StringComparison.InvariantCultureIgnoreCase)); if (pxValue is null) { - return ExpandSelectionExpression(variable, modelVariable, valueCode, out problem); + if (ExpandSelectionExpression(variable, modelVariable, valueCode, out problem)) + { + variable.ValueCodes.Remove(valueCode); + } + else + { + return false; + } } else { - variable.ValueCodes[i] = pxValue.Code; + if (valueCode != pxValue.Code) + { + variable.ValueCodes[variable.ValueCodes.IndexOf(valueCode)] = pxValue.Code; + } } } From 0edcd2b2241d0aac1ab34d54a70e07c973e5e41a Mon Sep 17 00:00:00 2001 From: likp Date: Wed, 26 Mar 2025 16:35:52 +0100 Subject: [PATCH 2/3] Refactored function --- .../Api2/DataSelection/SelectionHandler.cs | 42 +++++++++++-------- 1 file changed, 24 insertions(+), 18 deletions(-) diff --git a/PxWeb/Code/Api2/DataSelection/SelectionHandler.cs b/PxWeb/Code/Api2/DataSelection/SelectionHandler.cs index df57173e..f5c5d707 100644 --- a/PxWeb/Code/Api2/DataSelection/SelectionHandler.cs +++ b/PxWeb/Code/Api2/DataSelection/SelectionHandler.cs @@ -113,24 +113,7 @@ private static bool ExpandSelectionExpressionsAndVerifyValues(IPXModelBuilder bu // Try to get the value using the code specified by the API user Value? pxValue = modelVariable.Values.FirstOrDefault(x => x.Code.Equals(valueCode, System.StringComparison.InvariantCultureIgnoreCase)); - if (pxValue is null) - { - if (ExpandSelectionExpression(variable, modelVariable, valueCode, out problem)) - { - variable.ValueCodes.Remove(valueCode); - } - else - { - return false; - } - } - else - { - if (valueCode != pxValue.Code) - { - variable.ValueCodes[variable.ValueCodes.IndexOf(valueCode)] = pxValue.Code; - } - } + return ExpandValue(ref problem, variable, modelVariable, valueCode, pxValue); } //Verify that variables have at least one value selected for mandatory varibles @@ -145,6 +128,29 @@ private static bool ExpandSelectionExpressionsAndVerifyValues(IPXModelBuilder bu return true; } + private static bool ExpandValue(ref Problem? problem, VariableSelection variable, Variable modelVariable, string valueCode, Value? pxValue) + { + if (pxValue is null) + { + if (ExpandSelectionExpression(variable, modelVariable, valueCode, out problem)) + { + variable.ValueCodes.Remove(valueCode); + } + else + { + return false; + } + } + else + { + if (valueCode != pxValue.Code) + { + variable.ValueCodes[variable.ValueCodes.IndexOf(valueCode)] = pxValue.Code; + } + } + return true; + } + /// /// Expand selection expression and add to selection /// This method should only be From 54fd4ef7453f031bf429d4d061aa20f66c493feb Mon Sep 17 00:00:00 2001 From: likp Date: Wed, 26 Mar 2025 16:41:07 +0100 Subject: [PATCH 3/3] Refactored take 2 --- PxWeb/Code/Api2/DataSelection/SelectionHandler.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/PxWeb/Code/Api2/DataSelection/SelectionHandler.cs b/PxWeb/Code/Api2/DataSelection/SelectionHandler.cs index f5c5d707..c6b97b8e 100644 --- a/PxWeb/Code/Api2/DataSelection/SelectionHandler.cs +++ b/PxWeb/Code/Api2/DataSelection/SelectionHandler.cs @@ -113,7 +113,10 @@ private static bool ExpandSelectionExpressionsAndVerifyValues(IPXModelBuilder bu // Try to get the value using the code specified by the API user Value? pxValue = modelVariable.Values.FirstOrDefault(x => x.Code.Equals(valueCode, System.StringComparison.InvariantCultureIgnoreCase)); - return ExpandValue(ref problem, variable, modelVariable, valueCode, pxValue); + if (!ExpandValue(ref problem, variable, modelVariable, valueCode, pxValue)) + { + return false; + } } //Verify that variables have at least one value selected for mandatory varibles