Skip to content

Commit 9fb3e98

Browse files
committed
Update Program.cs
1 parent b7ce732 commit 9fb3e98

File tree

1 file changed

+90
-66
lines changed
  • DataWarehouseAutomation/SchemaJsonConverter

1 file changed

+90
-66
lines changed

DataWarehouseAutomation/SchemaJsonConverter/Program.cs

Lines changed: 90 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919

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

2525
var exceptionList = new List<string>
2626
{
@@ -64,6 +64,9 @@
6464
// Connection.
6565
UpdateDataConnection(dataObjectJsonObject);
6666

67+
// Update the classifications
68+
UpdateClassifications(dataObjectJsonObject);
69+
6770
jsonObject["generationSpecificMetadata"]!["selectedDataObject"] = dataObjectJsonObject;
6871

6972
// Data items.
@@ -126,57 +129,10 @@
126129
jsonObjectDataObjectMapping.Add("classifications", mappingClassificationsNode);
127130

128131
// 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-
string groupValue = classificationValue.ToString() switch
140-
{
141-
"Source" => "Solution Layer",
142-
"Core Business Concept" => "Logical",
143-
"CoreBusinessConcept" => "Logical",
144-
"Integration" => "Solution Layer",
145-
"Context" => "Logical",
146-
"Persistent Staging" => "Solution Layer",
147-
"PersistentStaging" => "Solution Layer",
148-
"Staging" => "Solution Layer",
149-
"StagingArea" => "Solution Layer",
150-
"Thing" => "Conceptual",
151-
"Presentation" => "Solution Layer",
152-
"Natural Business Relationship" => "Logical",
153-
"NaturalBusinessRelationship" => "Logical",
154-
"Natural Business Relationship Context" => "Logical",
155-
"NaturalBusinessRelationshipContext" => "Logical",
156-
"Natural Business Relationship Context Driving Key" => "Logical",
157-
"NaturalBusinessRelationshipContextDrivingKey" => "Logical",
158-
"Person" => "Conceptual",
159-
"Place" => "Conceptual",
160-
"Hub" => "Physical",
161-
"Event" => "Physical",
162-
"Satellite" => "Conceptual",
163-
"Link" => "Physical",
164-
_ => "Unknown"
165-
};
166-
167-
classificationJsonObject.Add("group",groupValue);
168-
}
169-
170-
171-
}
172-
catch (Exception ex)
173-
{
174-
175-
}
176-
}
132+
UpdateClassifications(jsonObjectDataObjectMapping);
177133

178134
// Rename the business key definitions.
179-
var businessKeyDefinitionsNode = jsonObjectDataObjectMapping["businessKeys"];
135+
var businessKeyDefinitionsNode = jsonObjectDataObjectMapping["businessKeys"];
180136
jsonObjectDataObjectMapping.Remove("businessKeys");
181137
jsonObjectDataObjectMapping.Add("businessKeyDefinitions", businessKeyDefinitionsNode);
182138

@@ -199,6 +155,9 @@
199155
// Replace properties with newer names (upgrade).
200156
ReplaceDataObjectProperties(dataObjectJsonObject);
201157

158+
// Update the classifications
159+
UpdateClassifications(dataObjectJsonObject);
160+
202161
var getSourceDataObjectName = dataObjectJsonObject.TryGetPropertyValue("name", out var sourceDataObjectNameJsonNode).ToString();
203162

204163
// Add the mapping name as a 'name' to the list of mappings, only once.
@@ -276,6 +235,9 @@
276235
// Connection.
277236
UpdateDataConnection(dataObjectJsonObject);
278237

238+
// Update the classifications
239+
UpdateClassifications(dataObjectJsonObject);
240+
279241
jsonObjectDataObjectMapping["targetDataObject"] = dataObjectJsonObject;
280242

281243
/// Data items.
@@ -334,6 +296,9 @@
334296
// Connection.
335297
UpdateDataConnection(dataObjectJsonObject);
336298

299+
// Update the classifications
300+
UpdateClassifications(dataObjectJsonObject);
301+
337302
// Data Items.
338303
var dataItems = new List<JsonObject>();
339304
foreach (var dataItem in dataObjectJsonObject["dataItems"].AsArray())
@@ -458,32 +423,37 @@
458423
// Change isHardCodedValue into extension.
459424
if (dataItemJsonObject.ContainsKey("isHardCodedValue"))
460425
{
461-
var keyExists = dataItemJsonObject.TryGetPropertyValue("key", out var jsonNode).ToString();
426+
var keyExists = dataItemJsonObject.TryGetPropertyValue("isHardCodedValue", out var jsonNode).ToString();
462427

463428
if (keyExists == "True")
464429
{
465430
if (jsonNode != null && jsonNode.ToString() == "true")
466431
{
467-
// Create an extension.
468-
var extension = new JsonObject()
469-
{
470-
["key"] = "isHardCodedValue",
471-
["value"] = "true",
472-
["notes"] = "database name"
473-
};
474-
475-
// Extensions
476-
if (dataItemJsonObject["extensions"] == null)
477-
{
478-
dataItemJsonObject.Add("extensions", extension);
479-
}
480-
else
432+
try
481433
{
434+
// Create an extension.
435+
var extension = new JsonObject()
436+
{
437+
["key"] = "isHardCodedValue",
438+
["value"] = "true",
439+
["notes"] = "database name"
440+
};
441+
442+
// Extensions
482443
var extensionArray = new JsonArray();
444+
if (dataItemJsonObject["extensions"] == null)
445+
{
446+
dataItemJsonObject.Add("extensions", extensionArray);
447+
}
448+
483449
extensionArray = dataItemJsonObject["extensions"]?.AsArray();
484450
extensionArray.Add(extension);
485451
dataItemJsonObject["extensions"] = extensionArray;
486452
}
453+
catch (Exception ex)
454+
{
455+
//
456+
}
487457
}
488458
}
489459

@@ -625,6 +595,60 @@ void ReplaceDataItemProperties(JsonObject jsonObject)
625595
RenameProperty("dataItemClassification", "classifications", jsonObject);
626596
}
627597

598+
void UpdateClassifications(JsonObject jsonObject)
599+
{
600+
if (jsonObject["classifications"] != null)
601+
{
602+
var classificationArray = new JsonArray();
603+
try
604+
{
605+
foreach (var classification in jsonObject["classifications"].AsArray())
606+
{
607+
var classificationJsonObject = JsonNode.Parse(classification.ToJsonString()).AsObject();
608+
var getClassification = classificationJsonObject.TryGetPropertyValue("classification", out var classificationValue).ToString();
609+
610+
string groupValue = classificationValue.ToString() switch
611+
{
612+
"Source" => "Solution Layer",
613+
"Core Business Concept" => "Logical",
614+
"CoreBusinessConcept" => "Logical",
615+
"Integration" => "Solution Layer",
616+
"Context" => "Logical",
617+
"Persistent Staging" => "Solution Layer",
618+
"PersistentStaging" => "Solution Layer",
619+
"Staging" => "Solution Layer",
620+
"StagingArea" => "Solution Layer",
621+
"Thing" => "Conceptual",
622+
"Presentation" => "Solution Layer",
623+
"Natural Business Relationship" => "Logical",
624+
"NaturalBusinessRelationship" => "Logical",
625+
"Natural Business Relationship Context" => "Logical",
626+
"NaturalBusinessRelationshipContext" => "Logical",
627+
"Natural Business Relationship Context Driving Key" => "Logical",
628+
"NaturalBusinessRelationshipContextDrivingKey" => "Logical",
629+
"Person" => "Conceptual",
630+
"Place" => "Conceptual",
631+
"Hub" => "Physical",
632+
"Event" => "Physical",
633+
"Satellite" => "Conceptual",
634+
"Link" => "Physical",
635+
_ => "Unknown"
636+
};
637+
638+
classificationJsonObject.Add("group", groupValue);
639+
640+
classificationArray.Add(classificationJsonObject);
641+
}
642+
}
643+
catch (Exception ex)
644+
{
645+
// To do
646+
}
647+
648+
jsonObject["classifications"] = classificationArray;
649+
}
650+
}
651+
628652
void UpdateDataConnection(JsonObject dataObjectJsonObject)
629653
{
630654
// Connection.

0 commit comments

Comments
 (0)