From ac788994fbe03e0a2f0023a65d7de0c60dcdad59 Mon Sep 17 00:00:00 2001 From: AlejandroP Date: Mon, 21 Mar 2022 12:01:49 -0300 Subject: [PATCH] - Unwrapped input support for SDTs in API Objects. Issue 95219 --- .../GxClasses.Web/Middleware/GXRouting.cs | 2 +- .../GxClasses/Middleware/GXHttpModules.cs | 2 +- .../GxClasses/Middleware/GXHttpServices.cs | 1 + .../GxClasses/Services/GxRestWrapper.cs | 6 ++++ .../GxClasses/Services/ReflectionHelper.cs | 28 +++++++++++++++++++ 5 files changed, 37 insertions(+), 2 deletions(-) diff --git a/dotnet/src/dotnetcore/GxClasses.Web/Middleware/GXRouting.cs b/dotnet/src/dotnetcore/GxClasses.Web/Middleware/GXRouting.cs index 541f99487..065dcb659 100644 --- a/dotnet/src/dotnetcore/GxClasses.Web/Middleware/GXRouting.cs +++ b/dotnet/src/dotnetcore/GxClasses.Web/Middleware/GXRouting.cs @@ -450,7 +450,7 @@ public void ServicesGroupSetting() { object p = JSONHelper.Deserialize(content); MapGroup m = p as MapGroup; - if (m != null) + if (m != null && m.Name != null && m.Mappings != null) { if (String.IsNullOrEmpty(m.BasePath)) diff --git a/dotnet/src/dotnetframework/GxClasses/Middleware/GXHttpModules.cs b/dotnet/src/dotnetframework/GxClasses/Middleware/GXHttpModules.cs index a95c5ff5d..ea847a093 100644 --- a/dotnet/src/dotnetframework/GxClasses/Middleware/GXHttpModules.cs +++ b/dotnet/src/dotnetframework/GxClasses/Middleware/GXHttpModules.cs @@ -131,7 +131,7 @@ public void ServicesGroupSetting(string webPath) object p = JSONHelper.Deserialize(File.ReadAllText(grp)); #pragma warning restore SCS0018 MapGroup m = p as MapGroup; - if (m != null) + if (m != null && m.Name != null && m.Mappings != null ) { if (String.IsNullOrEmpty(m.BasePath)) diff --git a/dotnet/src/dotnetframework/GxClasses/Middleware/GXHttpServices.cs b/dotnet/src/dotnetframework/GxClasses/Middleware/GXHttpServices.cs index 4ae3c1f9d..002094ef4 100644 --- a/dotnet/src/dotnetframework/GxClasses/Middleware/GXHttpServices.cs +++ b/dotnet/src/dotnetframework/GxClasses/Middleware/GXHttpServices.cs @@ -295,6 +295,7 @@ public override void webExecute() GxFile gxFile = new GxFile(tempDir, FileUtil.getTempFileName(tempDir), GxFileType.PrivateAttribute); gxFile.Create(hpf.InputStream); + string uri = gxFile.GetURI(); string url = (PathUtil.IsAbsoluteUrl(uri)) ? uri : context.PathToUrl(uri); diff --git a/dotnet/src/dotnetframework/GxClasses/Services/GxRestWrapper.cs b/dotnet/src/dotnetframework/GxClasses/Services/GxRestWrapper.cs index 4a6046603..aad982ed0 100644 --- a/dotnet/src/dotnetframework/GxClasses/Services/GxRestWrapper.cs +++ b/dotnet/src/dotnetframework/GxClasses/Services/GxRestWrapper.cs @@ -133,6 +133,7 @@ public virtual Task MethodBodyExecute(object key) if (!String.IsNullOrEmpty(this._serviceMethod)) { innerMethod = this._serviceMethod; + bodyParameters = PreProcessApiSdtParameter(_procWorker, innerMethod, bodyParameters); } Dictionary outputParameters = ReflectionHelper.CallMethod(_procWorker, innerMethod, bodyParameters, _gxContext); Dictionary formatParameters = ReflectionHelper.ParametersFormat(_procWorker, innerMethod); @@ -186,6 +187,11 @@ private Dictionary ReadBodyParameters() return ReadRequestParameters(_httpContext.Request.GetInputStream()); #endif } + + private Dictionary PreProcessApiSdtParameter(GXBaseObject procWorker, string innerMethod, Dictionary bodyParameters) + { + return ReflectionHelper.GetWrappedParameter(procWorker, innerMethod, bodyParameters); + } private string PreProcessReplicatorParameteres(GXBaseObject procWorker, string innerMethod, Dictionary bodyParameters) { var methodInfo = procWorker.GetType().GetMethod(innerMethod); diff --git a/dotnet/src/dotnetframework/GxClasses/Services/ReflectionHelper.cs b/dotnet/src/dotnetframework/GxClasses/Services/ReflectionHelper.cs index c500e40b6..49818f2e4 100644 --- a/dotnet/src/dotnetframework/GxClasses/Services/ReflectionHelper.cs +++ b/dotnet/src/dotnetframework/GxClasses/Services/ReflectionHelper.cs @@ -7,6 +7,7 @@ using System.Text.RegularExpressions; using GeneXus.Utils; using System.Linq; +using Jayrock.Json; using Type = System.Type; @@ -67,6 +68,33 @@ public static bool MethodHasInputParameters(object instance, String methodName) return false; } + public static Dictionary GetWrappedParameter(object instance, String methodName, Dictionary bodyParameters) + { + MethodInfo methodInfo = instance.GetType().GetMethod(methodName); + var methodParameters = methodInfo.GetParameters(); + List inputParameters = new List(); + foreach (var methodParameter in methodParameters) + { + if (!methodParameter.IsOut) + { + inputParameters.Add(methodParameter); + } + } + if (inputParameters.Count == 1 && bodyParameters.Count>1) + { + ParameterInfo pInfo = inputParameters[0]; + if (pInfo.ParameterType.IsSubclassOf(typeof(GxUserType))) + { + var gxParameterName = GxParameterName(pInfo.Name).ToLower(); + Dictionary parameters = new Dictionary(); + JObject jparms = new JObject(bodyParameters); + parameters.Add(gxParameterName,jparms); + return parameters; + } + } + return bodyParameters; + } + private static object ConvertSingleJsonItem(object value, Type newType, IGxContext context) { if (value!= null && value.GetType() == newType)