Skip to content

Commit cd5d7cf

Browse files
committed
Update Program.cs
1 parent 3b12036 commit cd5d7cf

File tree

1 file changed

+84
-17
lines changed
  • DataWarehouseAutomation/SchemaJsonConverter

1 file changed

+84
-17
lines changed

DataWarehouseAutomation/SchemaJsonConverter/Program.cs

Lines changed: 84 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.IO.Enumeration;
1+
using System.Drawing;
2+
using System.IO.Enumeration;
23
using System.Linq;
34
using System.Text.Json;
45
using System.Text.Json.Nodes;
@@ -18,8 +19,8 @@
1819

1920
if (!string.IsNullOrEmpty(jsonSchema))
2021
{
21-
var inputMetadataDirectory = @"D:\TeamEnvironments\VDW\Metadata";
22-
var outputMetadataDirectory = @"D:\TeamEnvironments\VDW\MetadataV2";
22+
var inputMetadataDirectory = @"C:\AutomationEnvironments\VDW\Metadata";
23+
var outputMetadataDirectory = @"C:\AutomationEnvironments\VDW\MetadataV2";
2324

2425
var exceptionList = new List<string>
2526
{
@@ -31,9 +32,6 @@
3132
{
3233
// TODO
3334
// Infer group for classification.Set property upon import.
34-
// Adding Name to dataObjectMappingList
35-
// Updating dataObjectMapping Name
36-
3735

3836
if (!exceptionList.Contains(Path.GetFileName(file)))
3937
{
@@ -44,7 +42,7 @@
4442

4543
// Create a JSON object, which can be modified at runtime.
4644
var jsonObject = JsonNode.Parse(jsonFile).AsObject();
47-
45+
4846
#region Generation Specific Data Object
4947

5048
if (jsonObject["generationSpecificMetadata"] != null)
@@ -100,9 +98,9 @@
10098
}
10199

102100
#endregion
103-
101+
104102
// Start parsing.
105-
var dataObjectMappingJsonObjectList = new List<JsonObject>();
103+
var dataObjectMappingJsonArray = new JsonArray();
106104

107105
foreach (var dataObjectMapping in jsonObject["dataObjectMappings"].AsArray())
108106
{
@@ -114,14 +112,78 @@
114112
jsonObjectDataObjectMapping.Remove("mappingName");
115113
jsonObjectDataObjectMapping.Add("name", mappingNameNode);
116114

117-
// Rename the mapping classifications.
115+
var getName = jsonObjectDataObjectMapping.TryGetPropertyValue("name", out var mappingNameJsonNode).ToString();
116+
117+
// Add the mapping name as a 'name' to the list of mappings, only once.
118+
if (jsonObject["dataObjectMappings"].AsArray().IndexOf(dataObjectMapping) == 0)
119+
{
120+
jsonObject["name"] = mappingNameJsonNode.ToString();
121+
}
118122

123+
// Rename the mapping classifications.
119124
var mappingClassificationsNode = jsonObjectDataObjectMapping["mappingClassifications"];
120125
jsonObjectDataObjectMapping.Remove("mappingClassifications");
121126
jsonObjectDataObjectMapping.Add("classifications", mappingClassificationsNode);
122127

128+
// Update the classifications
129+
if (jsonObjectDataObjectMapping["classifications"] != null)
130+
{
131+
try
132+
{
133+
foreach (var classification in jsonObjectDataObjectMapping["classifications"].AsArray())
134+
{
135+
var classificationJsonObject = JsonNode.Parse(classification.ToJsonString()).AsObject();
136+
var getClassification = classificationJsonObject
137+
.TryGetPropertyValue("classification", out var classificationValue).ToString();
138+
139+
140+
// public string groupValue) => classificationValue.ToString()
141+
//switch
142+
// {
143+
// "CoreBusinessConcept" => new NewSwitch(0xFF, 0x00, 0x00),
144+
// _ => throw new ArgumentException(message: "error", paramName: nameof(color)),
145+
// };
146+
147+
string groupValue = classificationValue.ToString() switch
148+
{
149+
"Source" => "Solution Layer",
150+
"Core Business Concept" => "Logical",
151+
"CoreBusinessConcept" => "Logical",
152+
"Integration" => "Solution Layer",
153+
"Context" => "Logical",
154+
"Persistent Staging" => "Solution Layer",
155+
"PersistentStaging" => "Solution Layer",
156+
"Staging" => "Solution Layer",
157+
"Thing" => "Conceptual",
158+
"Presentation" => "Solution Layer",
159+
"Natural Business Relationship" => "Logical",
160+
"NaturalBusinessRelationship" => "Logical",
161+
"Natural Business Relationship Context" => "Logical",
162+
"NaturalBusinessRelationshipContext" => "Logical",
163+
"Natural Business Relationship Context Driving Key" => "Logical",
164+
"NaturalBusinessRelationshipContextDrivingKey" => "Logical",
165+
"Person" => "Conceptual",
166+
"Place" => "Conceptual",
167+
"Hub" => "Physical",
168+
"Event" => "Physical",
169+
"Satellite" => "Conceptual",
170+
"Link" => "Physical",
171+
_ => "Unknown"
172+
};
173+
174+
classificationJsonObject.Add("group",groupValue);
175+
}
176+
177+
178+
}
179+
catch (Exception ex)
180+
{
181+
182+
}
183+
}
184+
123185
// Rename the business key definitions.
124-
var businessKeyDefinitionsNode = jsonObjectDataObjectMapping["businessKeys"];
186+
var businessKeyDefinitionsNode = jsonObjectDataObjectMapping["businessKeys"];
125187
jsonObjectDataObjectMapping.Remove("businessKeys");
126188
jsonObjectDataObjectMapping.Add("businessKeyDefinitions", businessKeyDefinitionsNode);
127189

@@ -144,6 +206,14 @@
144206
// Replace properties with newer names (upgrade).
145207
ReplaceDataObjectProperties(dataObjectJsonObject);
146208

209+
var getSourceDataObjectName = dataObjectJsonObject.TryGetPropertyValue("name", out var sourceDataObjectNameJsonNode).ToString();
210+
211+
// Add the mapping name as a 'name' to the list of mappings, only once.
212+
if (jsonObject["dataObjectMappings"].AsArray().IndexOf(dataObjectMapping) == 0)
213+
{
214+
jsonObjectDataObjectMapping["name"] = sourceDataObjectNameJsonNode.ToString() + " to " + mappingNameJsonNode.ToString();
215+
}
216+
147217
// Data Items.
148218
var dataItems = new List<JsonObject>();
149219
foreach (var dataItem in dataObjectJsonObject["dataItems"].AsArray())
@@ -462,14 +532,11 @@
462532

463533
#endregion
464534

465-
dataObjectMappingJsonObjectList.Add(jsonObjectDataObjectMapping);
535+
dataObjectMappingJsonArray.Add(jsonObjectDataObjectMapping);
466536
}
467537

468538
// Put the data object mappings back into the main object.
469-
foreach (var dataObjectMappingJsonObject in dataObjectMappingJsonObjectList)
470-
{
471-
jsonObject["dataObjectMappings"]![dataObjectMappingJsonObjectList.IndexOf(dataObjectMappingJsonObject)] = dataObjectMappingJsonObject;
472-
}
539+
jsonObject["dataObjectMappings"] = dataObjectMappingJsonArray;
473540

474541
// Finalisation
475542
var options = new JsonSerializerOptions { WriteIndented = true };
@@ -485,7 +552,7 @@
485552

486553
try
487554
{
488-
var test = JsonSerializer.Deserialize<DataObjectMappingList>(jsonObject.ToJsonString());
555+
var testSerialisation = JsonSerializer.Deserialize<DataObjectMappingList>(jsonObject.ToJsonString());
489556
}
490557
catch (Exception ex)
491558
{

0 commit comments

Comments
 (0)