diff --git a/Sdl.Web.DXAResolver/Resolver.cs b/Sdl.Web.DXAResolver/Resolver.cs index df283cf..f9a33b7 100644 --- a/Sdl.Web.DXAResolver/Resolver.cs +++ b/Sdl.Web.DXAResolver/Resolver.cs @@ -96,11 +96,17 @@ private List GatherLinkedComponents(Component component) } } + HashSet linkedComponents = new HashSet(); foreach (var linkField in componentLinkFields) { if (linkField.Values != null) { - components.AddRange(linkField.Values); + foreach (var c in linkField.Values) + { + if (linkedComponents.Contains(c.Id)) continue; + linkedComponents.Add(c.Id); + components.Add(c); + } } } return components; diff --git a/Sdl.Web.Tridion.Templates.R2/Data/DataModelBuilderPipeline.cs b/Sdl.Web.Tridion.Templates.R2/Data/DataModelBuilderPipeline.cs index a815580..467ad5f 100644 --- a/Sdl.Web.Tridion.Templates.R2/Data/DataModelBuilderPipeline.cs +++ b/Sdl.Web.Tridion.Templates.R2/Data/DataModelBuilderPipeline.cs @@ -90,12 +90,16 @@ public DataModelBuilderPipeline( ILogger logger = null ) { + string[] typeNames = modelBuilderTypeNames.ToArray(); + if (typeNames == null || typeNames.Length == 0) + throw new DxaException("No model builder type names specified."); + Session = renderedItem.ResolvedItem.Item.Session; RenderedItem = renderedItem; Settings = settings; Logger = logger ?? new TemplatingLoggerAdapter(TemplatingLogger.GetLogger(GetType())); - foreach (string modelBuilderTypeName in modelBuilderTypeNames) + foreach (string modelBuilderTypeName in typeNames) { string qualifiedTypeName = modelBuilderTypeName.Contains(".") ? modelBuilderTypeName : $"Sdl.Web.Tridion.Templates.R2.Data.{modelBuilderTypeName}"; Type modelBuilderType = Type.GetType(qualifiedTypeName, throwOnError: true); diff --git a/Sdl.Web.Tridion.Templates.R2/Data/DefaultPageMetaModelBuilder.cs b/Sdl.Web.Tridion.Templates.R2/Data/DefaultPageMetaModelBuilder.cs index 733e16e..f9fbfad 100644 --- a/Sdl.Web.Tridion.Templates.R2/Data/DefaultPageMetaModelBuilder.cs +++ b/Sdl.Web.Tridion.Templates.R2/Data/DefaultPageMetaModelBuilder.cs @@ -161,7 +161,7 @@ private void ExtractKeyValuePairs(XmlElement xmlElement, IDictionary result, string name, string value) + { + if (result.ContainsKey(name)) + { + result[name] = $"{result[name]}, {value}"; + } + else + { + result.Add(name, value); } } diff --git a/Sdl.Web.Tridion.Templates.R2/Data/TargetGroups/AddTargetGroupsModelBuilder.cs b/Sdl.Web.Tridion.Templates.R2/Data/TargetGroups/AddTargetGroupsModelBuilder.cs index e8e36a8..a24a6ca 100644 --- a/Sdl.Web.Tridion.Templates.R2/Data/TargetGroups/AddTargetGroupsModelBuilder.cs +++ b/Sdl.Web.Tridion.Templates.R2/Data/TargetGroups/AddTargetGroupsModelBuilder.cs @@ -21,9 +21,9 @@ public void BuildEntityModel(ref EntityModelData entityModelData, ComponentPrese List conditions = new List(); foreach (var condition in cp.Conditions) { - var mapped = MapConditions(condition.TargetGroup.Conditions); - if (mapped == null || mapped.Count <= 0) continue; - conditions.AddRange(mapped); + var mapped = MapTargetGroupCondition(condition); + if (mapped == null) continue; + conditions.Add(mapped); } if (conditions.Count > 0) { diff --git a/Sdl.Web.Tridion.Templates.R2/Templates/GenerateEntityModel.cs b/Sdl.Web.Tridion.Templates.R2/Templates/GenerateEntityModel.cs index 07bf80b..4bb3038 100644 --- a/Sdl.Web.Tridion.Templates.R2/Templates/GenerateEntityModel.cs +++ b/Sdl.Web.Tridion.Templates.R2/Templates/GenerateEntityModel.cs @@ -53,6 +53,8 @@ public override void Transform(Engine engine, Package package) DataModelBuilderPipeline modelBuilderPipeline = new DataModelBuilderPipeline(renderedItem, settings, modelBuilderTypeNames); EntityModelData entityModel = modelBuilderPipeline.CreateEntityModel(component, ct, includeComponentTemplateData); OutputJson = JsonSerialize(entityModel, IsPreview, DataModelBinder.SerializerSettings); + if (string.IsNullOrEmpty(OutputJson)) + throw new DxaException("Output Json is empty!"); } catch (Exception ex) { diff --git a/Sdl.Web.Tridion.Templates.R2/Templates/GeneratePageModel.cs b/Sdl.Web.Tridion.Templates.R2/Templates/GeneratePageModel.cs index daf70e9..30360aa 100644 --- a/Sdl.Web.Tridion.Templates.R2/Templates/GeneratePageModel.cs +++ b/Sdl.Web.Tridion.Templates.R2/Templates/GeneratePageModel.cs @@ -46,6 +46,8 @@ public override void Transform(Engine engine, Package package) DataModelBuilderPipeline modelBuilderPipeline = new DataModelBuilderPipeline(renderedItem, settings, modelBuilderTypeNames); PageModelData pageModel = modelBuilderPipeline.CreatePageModel(page); OutputJson = JsonSerialize(pageModel, IsPreview, DataModelBinder.SerializerSettings); + if (string.IsNullOrEmpty(OutputJson)) + throw new DxaException("Output Json is empty!"); } catch (Exception ex) { diff --git a/Sdl.Web.Tridion.Templates/Common/TemplateBase.cs b/Sdl.Web.Tridion.Templates/Common/TemplateBase.cs index d4b81c1..aa55509 100644 --- a/Sdl.Web.Tridion.Templates/Common/TemplateBase.cs +++ b/Sdl.Web.Tridion.Templates/Common/TemplateBase.cs @@ -176,6 +176,9 @@ protected void OutputSummary(string name, IEnumerable files) summaries.Add(summary); string summariesJson = JsonSerialize(summaries, IsPreview); + if (string.IsNullOrEmpty(summariesJson)) + throw new DxaException("Output Json should not be empty."); + outputItem = Package.CreateStringItem(ContentType.Text, summariesJson); Package.PushItem(Package.OutputName, outputItem); }