Skip to content

Commit aa113b9

Browse files
committed
WIP
1 parent 3254e67 commit aa113b9

File tree

9 files changed

+76
-28
lines changed

9 files changed

+76
-28
lines changed

DataWarehouseAutomation/DataWarehouseAutomation.sln

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RunDwhAutomation", "RunDwhA
5252
EndProject
5353
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SchemaJsonConverter", "SchemaJsonConverter\SchemaJsonConverter.csproj", "{07214B80-37A9-4137-B0F3-109FA0D0926A}"
5454
EndProject
55-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Export", "Export\Export.csproj", "{555AD192-6E8B-49DD-B60C-2E2CC41C0FA2}"
55+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Export", "Export\Export.csproj", "{555AD192-6E8B-49DD-B60C-2E2CC41C0FA2}"
5656
EndProject
5757
Global
5858
GlobalSection(SolutionConfigurationPlatforms) = preSolution

DataWarehouseAutomation/DataWarehouseAutomation/DwaModel/DataItemMapping.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public class DataItemMapping
1616
public List<IDataItem> SourceDataItems { get; set; } = new();
1717

1818
[JsonPropertyName("targetDataItem")]
19-
public DataItem TargetDataItem { get; set; } = new() { Name = "NewTargetDataItem" };
19+
public IDataItem TargetDataItem { get; set; } = new DataItem() { Name = "newTargetDataItem" };
2020

2121
/// <summary>
2222
/// The collection of extension Key/Value pairs.

DataWarehouseAutomation/DataWarehouseAutomation/DwaModel/DataObjectMapping.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,15 @@ public class DataObjectMapping : IMetadata
4848
/// The target object of the mapping. This is always a Data Object type.
4949
/// </summary>
5050
[JsonPropertyName("targetDataObject")]
51-
public DataObject TargetDataObject { get; set; } = new() { Name = "NewTargetDataObject" };
51+
public IDataObject TargetDataObject { get; set; } = new DataObject() { Name = "newTargetDataObject" };
5252

5353
/// <summary>
5454
/// The collection of associated data object for purposes other than source-target relationship.
5555
/// For example for lookups, merge joins, lineage etc.
5656
/// </summary>
5757
[JsonPropertyName("relatedDataObjects")]
5858
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
59-
public List<DataObject>? RelatedDataObjects { get; set; }
59+
public List<IDataObject>? RelatedDataObjects { get; set; }
6060

6161
private List<IDataItem> _dataItems = [];
6262
/// <summary>

DataWarehouseAutomation/DataWarehouseAutomation/DwaModel/DataObjectQuery.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,24 @@ public class DataObjectQuery : IDataObject
3636
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
3737
public DataConnection? DataConnection { get; set; }
3838

39+
private List<IDataItem> _dataItems = [];
40+
/// <summary>
41+
/// The collection of Data Items <see cref="IDataItem"/> associated with this Data Object Query.
42+
/// </summary>
43+
[JsonPropertyName("dataItems")]
44+
[JsonPropertyOrder(order: 40)]
45+
public List<IDataItem> DataItems
46+
{
47+
get
48+
{
49+
return _dataItems;
50+
}
51+
set
52+
{
53+
_dataItems = value;
54+
}
55+
}
56+
3957
/// <summary>
4058
/// Free-form and optional classification for the Data Query for use in generation logic (evaluation).
4159
/// </summary>

DataWarehouseAutomation/DataWarehouseAutomation/Utils/HandleBarsHelpers.cs

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using DataWarehouseAutomation.DwaModel;
2+
using HandlebarsDotNet;
23

34
namespace DataWarehouseAutomation.Utils;
45

@@ -328,7 +329,8 @@ public static void RegisterHandleBarsHelpers()
328329

329330
try
330331
{
331-
DataObjectMapping dataObjectMapping = JsonSerializer.Deserialize<DataObjectMapping>(context.Value.ToString());
332+
333+
var dataObjectMapping = JsonSerializer.Deserialize<DataObjectMapping>(context.Value.ToString(), DefaultJsonOptions.DeserializerOptions);
332334

333335
var outcome = false;
334336

@@ -391,50 +393,61 @@ public static void RegisterHandleBarsHelpers()
391393
}
392394
});
393395

394-
// lookupExtension allows a lookup of an extension value by key value. Pass in the Extensions list and the string key value.
395-
Handlebars.RegisterHelper("lookupExtension", (writer, context, parameters) =>
396+
// Block helper that evalues is a certain classification exists in the list of classifications.
397+
Handlebars.RegisterHelper("hasClassification", (output, options, context, parameters) =>
396398
{
397399
// Check if the parameters are valid.
398400
if (parameters.Length != 2 || parameters[1] is not string)
399401
{
400-
throw new HandlebarsException("{{lookupExtension}} helper expects two arguments: a List<Extension> and a string lookup key");
402+
throw new HandlebarsException("{{hasClassification}} helper expects two arguments: a List<DataClassification> and a string lookup key");
401403
}
402404

403405
try
404406
{
405-
var extensionList = JsonSerializer.Deserialize<List<Extension>>(parameters[0].ToString() ?? string.Empty);
406-
var key = (string)parameters[1];
407-
var result = extensionList?.Find(i => i.Key.Equals(key, StringComparison.OrdinalIgnoreCase))?.Value ?? "";
407+
var test = parameters[0];
408408

409+
var classifications = JsonSerializer.Deserialize<List<DataClassification>>(parameters[0].ToString() ?? string.Empty);
410+
var classificationName = (string)parameters[1];
411+
var result = classifications?.Find(i => i.Classification.ToString().Equals(classificationName, StringComparison.OrdinalIgnoreCase)).Classification;
409412

410-
writer.WriteSafeString($"{result}");
413+
if (result != null && result !="")
414+
{
415+
// Regular block, a classification has been found
416+
options.Template(output, context);
417+
}
418+
else
419+
{
420+
// Else block, no classification with the input name has been found.
421+
options.Inverse(output, context);
422+
}
411423
}
412424
catch (Exception exception)
413425
{
414-
throw new HandlebarsException($"{{lookupExtension}} encountered an error: the list of extensions provided as the first argument could not be deserialized. The reported error is :{exception.Message}");
426+
throw new HandlebarsException($"{{hasClassification}} encountered an error: the list of classifications provided as the first argument could not be deserialized. The reported error is :{exception.Message}");
415427
}
416428
});
417429

418-
419-
Handlebars.RegisterHelper("hasClassification", (writer, context, parameters) =>
430+
// lookupExtension allows a lookup of an extension value by key. Pass in the Extensions list and the string key value as parameters.
431+
Handlebars.RegisterHelper("lookupExtension", (writer, context, parameters) =>
420432
{
421433
// Check if the parameters are valid.
422434
if (parameters.Length != 2 || parameters[1] is not string)
423435
{
424-
throw new HandlebarsException("{{hasClassification}} helper expects two arguments: a List<DataClassification> and a string lookup key");
436+
throw new HandlebarsException("{{lookupExtension}} helper expects two arguments: a List<Extension> and a string lookup key");
425437
}
426438

427439
try
428440
{
429-
var classifictions = JsonSerializer.Deserialize<List<DataClassification>>(parameters[0].ToString() ?? string.Empty);
430-
var classificationName = (string)parameters[1];
431-
var result = classifictions?.Find(i => i.Classification.ToString().Equals(classificationName, StringComparison.OrdinalIgnoreCase)).Classification ?? "";
441+
var extensionList = JsonSerializer.Deserialize<List<Extension>>(parameters[0].ToString() ?? string.Empty);
442+
var key = (string)parameters[1];
443+
var result = extensionList?.Find(i => i.Key.Equals(key, StringComparison.OrdinalIgnoreCase))?.Value ?? "";
444+
432445

433446
writer.WriteSafeString($"{result}");
434447
}
435448
catch (Exception exception)
436449
{
437-
throw new HandlebarsException($"{{hasClassification}} encountered an error: the list of classifications provided as the first argument could not be deserialized. The reported error is :{exception.Message}");
450+
throw new HandlebarsException($"{{lookupExtension}} encountered an error: the list of extensions provided as the first argument could not be deserialized. The reported error is :{exception.Message}");
438451
}
439452
});
440453
}

DataWarehouseAutomation/Example_Project/Examples.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66
<AssemblyName>Example_Handlebars</AssemblyName>
77
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
88
</PropertyGroup>
9-
<ItemGroup>
10-
<ProjectReference Include="..\DataWarehouseAutomation\DataWarehouseAutomation.csproj" />
11-
</ItemGroup>
129
<ItemGroup>
1310
<PackageReference Include="Handlebars.Net" Version="2.1.4" />
1411
<PackageReference Include="System.Data.DataSetExtensions" Version="4.5.0" />
1512
</ItemGroup>
13+
<ItemGroup>
14+
<ProjectReference Include="..\DataWarehouseAutomation\DataWarehouseAutomation.csproj" />
15+
</ItemGroup>
1616
</Project>

DataWarehouseAutomation/RunDwhAutomation/RunDwhAutomation.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,14 @@
3131
<Install>false</Install>
3232
</BootstrapperPackage>
3333
</ItemGroup>
34-
<ItemGroup>
35-
<ProjectReference Include="..\DataWarehouseAutomation\DataWarehouseAutomation.csproj" />
36-
</ItemGroup>
3734
<ItemGroup>
3835
<PackageReference Include="CommandLineParser" Version="2.9.1" />
3936
<PackageReference Include="Handlebars.Net" Version="2.1.4" />
4037
<PackageReference Include="Microsoft.NETCore.Platforms" Version="7.0.4" />
4138
<PackageReference Include="NETStandard.Library" Version="2.0.3" />
4239
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
4340
</ItemGroup>
41+
<ItemGroup>
42+
<ProjectReference Include="..\DataWarehouseAutomation\DataWarehouseAutomation.csproj" />
43+
</ItemGroup>
4444
</Project>

DataWarehouseAutomation/Sample_Metadata/sampleCustomFunctions.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
}
2020
],
2121
"targetDataObject": {
22+
"dataObjectType": "dataObject",
2223
"name": "ExampleTargetDataObject"
2324
},
2425
"dataItemMappings": [
@@ -30,6 +31,7 @@
3031
}
3132
],
3233
"targetDataItem": {
34+
"dataItemType": "dataItem",
3335
"name": "FIRST_NAME"
3436
}
3537
},
@@ -41,6 +43,7 @@
4143
}
4244
],
4345
"targetDataItem": {
46+
"dataItemType": "dataItem",
4447
"name": "LAST_NAME"
4548
}
4649
},
@@ -52,6 +55,7 @@
5255
}
5356
],
5457
"targetDataItem": {
58+
"dataItemType": "dataItem",
5559
"name": "DATE_OF_BIRTH",
5660
"classifications": [
5761
{
@@ -95,6 +99,14 @@
9599
"key": "second key",
96100
"value": "second value"
97101
}
102+
],
103+
"classifications": [
104+
{
105+
"classification": "firstClassification"
106+
},
107+
{
108+
"classification": "secondClassification"
109+
}
98110
]
99111
}
100112
]

DataWarehouseAutomation/Sample_Templates/TemplateSampleCustomFunctions.Handlebars

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ The name of the dataObjectMapping is '{{dataObjectMappings.0.name}}'
33

44
The time is {{now}}.
55

6+
{{#hasClassification dataObjectMappings.0.classifications "secondClassification"}}Classification 'secondClassification' found.{{else}}Classification 'secondClassification' not found.{{/hasClassification}}
7+
68
{{#replicate 3}}
79
This value is replicated 3 times!
810
{{/replicate}}
@@ -28,16 +30,19 @@ This adds brackets around the string value: {{stringwrap "Example" "[" "]"}}
2830
{{!-- Demonstrating the array lookup --}}
2931
{{#each dataObjectMappings}}
3032
Working on mapping {{name}}
33+
3134
{{#each dataItemMappings}}
3235
Found a data item mapping from {{sourceDataItems.0.name}} to {{targetDataItem.name}}
36+
37+
{{targetDataItem.classifications.0.classification}}
38+
{{#hasClassification targetDataItem.classifications "multiActiveKey"}}Classification 'multiActiveKey' found.{{else}}Classification 'multiActiveKey' not found.{{/hasClassification}}
39+
3340
{{/each}}
3441

3542
{{#exists multiActiveKey}}There is a multi-active key!{{else}}No multi-active key is found in this data object mapping.{{/exists}}
3643
{{#exists multiActiveKey "DATE_OF_BIRTH"}}There is a multi-active key which is not DATE_OF_BIRTH{{else}}No multi-active key with DATE_OF_BIRTH is found in this data object mapping.{{/exists}}
3744
{{#exists targetDataItem}}There is a target data item in this mapping!{{else}}No target data items are defined in this mapping.{{/exists}}
3845

39-
{{#hasClassification ./targetDataItem.classifications "multiActiveKey"}}There is a classification called multiActiveKey{{/hasClassification}}
40-
4146
{{#targetDataItemExists "FIRST_NAME"}}FIRST_NAME exists{{else}}FIRST_NAME does not exist{{/targetDataItemExists}}
4247
{{#targetDataItemExists "NAME"}}NAME exists{{else}}NAME does not exist{{/targetDataItemExists}}
4348
{{#targetDataItemExists "DATE_OF_BIRTH"}}DATE_OF_BIRTH exists{{else}}DATE_OF_BIRTH does not exist{{/targetDataItemExists}}

0 commit comments

Comments
 (0)