Skip to content

Commit

Permalink
Merge pull request #113 in TSI/content-management from feature/SRQ-11…
Browse files Browse the repository at this point in the history
…942-2 to release/2.0

* commit 'be1344774b54508a9a8b820dfa1874b3112be80f':
  SRQ-12088 : Throw exceptions when trying to publish empty json
  SRQ-11952 : Fixed target groups
  • Loading branch information
majiccode committed Oct 22, 2019
2 parents 03551e4 + be13447 commit 92a647b
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ public void BuildEntityModel(ref EntityModelData entityModelData, ComponentPrese
List<Condition> conditions = new List<Condition>();
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)
{
Expand Down
2 changes: 2 additions & 0 deletions Sdl.Web.Tridion.Templates.R2/Templates/GenerateEntityModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
2 changes: 2 additions & 0 deletions Sdl.Web.Tridion.Templates.R2/Templates/GeneratePageModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
3 changes: 3 additions & 0 deletions Sdl.Web.Tridion.Templates/Common/TemplateBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,9 @@ protected void OutputSummary(string name, IEnumerable<string> 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);
}
Expand Down

0 comments on commit 92a647b

Please sign in to comment.