From 768fd2109aa3b34e8e6ddcdf62eb233d35f43741 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=A1clav=20Urb=C3=A1nek?= Date: Fri, 5 Jan 2024 10:21:18 +0100 Subject: [PATCH 1/4] FEATURE: Workflow api now accepts an unnamed object or list of objects as a body json parameter. It could be mapped directly to a datastructure entity when a new field 'DatastructureEntityName' is set in the corresponding page parameter mapping. --- .../PageParameterMappingScriptContainer.cs | 41 +++++++++++++++++++ .../Pages/PageParameterMapping.cs | 17 ++++++-- .../Origam.Server/Pages/UserApiProcessor.cs | 15 ++++++- 3 files changed, 69 insertions(+), 4 deletions(-) create mode 100644 backend/Origam.DA.Service/MetaModelUpgrade/UpdateScriptContainers/PageParameterMappingScriptContainer.cs diff --git a/backend/Origam.DA.Service/MetaModelUpgrade/UpdateScriptContainers/PageParameterMappingScriptContainer.cs b/backend/Origam.DA.Service/MetaModelUpgrade/UpdateScriptContainers/PageParameterMappingScriptContainer.cs new file mode 100644 index 0000000000..e773041ca2 --- /dev/null +++ b/backend/Origam.DA.Service/MetaModelUpgrade/UpdateScriptContainers/PageParameterMappingScriptContainer.cs @@ -0,0 +1,41 @@ +#region license + +/* +Copyright 2005 - 2023 Advantage Solutions, s. r. o. + +This file is part of ORIGAM (http://www.origam.org). + +ORIGAM is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +ORIGAM is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with ORIGAM. If not, see . +*/ + +#endregion + +using System; +using System.Collections.Generic; +using System.Xml.Linq; + +namespace Origam.DA.Service.MetaModelUpgrade.UpdateScriptContainers +{ + class PageParameterMappingScriptContainer : UpgradeScriptContainer + { + public override string FullTypeName { get; } = "Origam.Schema.GuiModel.PageParameterMapping"; + public override List OldFullTypeNames { get; } + public override string[] OldPropertyXmlNames { get; } + + public PageParameterMappingScriptContainer() + { + AddEmptyUpgrade("6.0.0", "6.0.1"); + } + } +} diff --git a/backend/Origam.Schema.GuiModel/Pages/PageParameterMapping.cs b/backend/Origam.Schema.GuiModel/Pages/PageParameterMapping.cs index b944b25c07..78d6504a3a 100644 --- a/backend/Origam.Schema.GuiModel/Pages/PageParameterMapping.cs +++ b/backend/Origam.Schema.GuiModel/Pages/PageParameterMapping.cs @@ -32,7 +32,7 @@ namespace Origam.Schema.GuiModel [SchemaItemDescription("Parameter Mapping", "Parameter Mappings", "file-mapping.png")] [HelpTopic("Parameter+Mapping")] [XmlModelRoot(CategoryConst)] - [ClassMetaVersion("6.0.0")] + [ClassMetaVersion("6.0.1")] public class PageParameterMapping : AbstractSchemaItem { public const string CategoryConst = "PageParameterMapping"; @@ -50,10 +50,21 @@ private void Init() [Description("Name of url query string parameter, e.g. in case http://my-api/my-page?searchstring=value the mapped parametr should be 'searchstring'")] [XmlAttribute ("mappedParameter")] public string MappedParameter { get; set; } = ""; - - public Guid DataConstantId; [Category("Mapping")] + [Description("Name of a datastructure entity in a mapped context " + + "store's datastructure. If defined, the incoming json body is " + + "wrapped by a new object with the given name. So that way, the" + + " original input json object is expected as just datastructure " + + "entity object itself or a list of datastructure entity objects" + + " on json top level.")] + [DefaultValue("")] + [XmlAttribute("entityName")] + public string DatastructureEntityName { get; set; } = ""; + + public Guid DataConstantId; + + [Category("Mapping")] [TypeConverter(typeof(DataConstantConverter))] [RefreshProperties(RefreshProperties.Repaint)] [XmlReference("defaultValue", "DataConstantId")] diff --git a/backend/Origam.Server/Pages/UserApiProcessor.cs b/backend/Origam.Server/Pages/UserApiProcessor.cs index ee60e1b7cb..cf4afcfe8a 100644 --- a/backend/Origam.Server/Pages/UserApiProcessor.cs +++ b/backend/Origam.Server/Pages/UserApiProcessor.cs @@ -42,6 +42,7 @@ using Origam.Extensions; using Origam.Service.Core; using ImageMagick; +using IdentityServer4.Extensions; namespace Origam.Server.Pages { @@ -508,7 +509,19 @@ private static void MapFileToParameter(IHttpContextWrapper context, Dictionary(body); XmlDocument xd = new XmlDocument(); // deserialize from JSON to XML - xd = (XmlDocument)JsonConvert.DeserializeXmlNode(body, "ROOT"); + if (ppm.DatastructureEntityName.IsNullOrEmpty()) + { + xd = (XmlDocument)JsonConvert + .DeserializeXmlNode(body, "ROOT"); + } + else + { + xd = (XmlDocument)JsonConvert + .DeserializeXmlNode( + "{\"" + ppm.DatastructureEntityName + + "\" :" + body + "}" + , "ROOT"); + } if (log.IsDebugEnabled) { log.Debug("Intermediate JSON deserialized XML:"); From 5aec30ca2f6ca157f6a1b298ae469d76fe457309 Mon Sep 17 00:00:00 2001 From: Vaclav Urbanek Date: Fri, 5 Jan 2024 13:34:55 +0100 Subject: [PATCH 2/4] DEV: update model-tests - new version of PageParameterMapping schema item --- .../Api/Page/apipublictest-api-body-input-data-page.origam | 7 ++++++- .../Page/apipublictest-api-body-input-workflow-page.origam | 7 ++++++- model-tests/model/Security/Page/adminaddUser.origam | 2 +- .../model/Security/Page/confirmUserEmail.json.origam | 2 +- model-tests/model/Widgets/Page/Attachment.origam | 2 +- 5 files changed, 15 insertions(+), 5 deletions(-) diff --git a/model-tests/model/Api/Page/apipublictest-api-body-input-data-page.origam b/model-tests/model/Api/Page/apipublictest-api-body-input-data-page.origam index 418872bbb2..e70f469ece 100644 --- a/model-tests/model/Api/Page/apipublictest-api-body-input-data-page.origam +++ b/model-tests/model/Api/Page/apipublictest-api-body-input-data-page.origam @@ -1,5 +1,10 @@ - + - + + xmlns:ppm="http://schemas.origam.com/Origam.Schema.GuiModel.PageParameterMapping/6.0.1"> Date: Fri, 5 Jan 2024 13:57:30 +0100 Subject: [PATCH 3/4] DEV: whitespace fix --- backend/Origam.Server/Pages/UserApiProcessor.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/Origam.Server/Pages/UserApiProcessor.cs b/backend/Origam.Server/Pages/UserApiProcessor.cs index cf4afcfe8a..2cc27a7b81 100644 --- a/backend/Origam.Server/Pages/UserApiProcessor.cs +++ b/backend/Origam.Server/Pages/UserApiProcessor.cs @@ -512,7 +512,7 @@ private static void MapFileToParameter(IHttpContextWrapper context, Dictionary Date: Fri, 5 Jan 2024 16:19:06 +0100 Subject: [PATCH 4/4] DEV: fix license year --- .../PageParameterMappingScriptContainer.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/Origam.DA.Service/MetaModelUpgrade/UpdateScriptContainers/PageParameterMappingScriptContainer.cs b/backend/Origam.DA.Service/MetaModelUpgrade/UpdateScriptContainers/PageParameterMappingScriptContainer.cs index e773041ca2..6b77d9a93c 100644 --- a/backend/Origam.DA.Service/MetaModelUpgrade/UpdateScriptContainers/PageParameterMappingScriptContainer.cs +++ b/backend/Origam.DA.Service/MetaModelUpgrade/UpdateScriptContainers/PageParameterMappingScriptContainer.cs @@ -1,7 +1,7 @@ #region license /* -Copyright 2005 - 2023 Advantage Solutions, s. r. o. +Copyright 2005 - 2024 Advantage Solutions, s. r. o. This file is part of ORIGAM (http://www.origam.org).