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..6b77d9a93c --- /dev/null +++ b/backend/Origam.DA.Service/MetaModelUpgrade/UpdateScriptContainers/PageParameterMappingScriptContainer.cs @@ -0,0 +1,41 @@ +#region license + +/* +Copyright 2005 - 2024 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..2cc27a7b81 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:"); 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">