|
1 |
| -using System.IO.Enumeration; |
| 1 | +using System.Drawing; |
| 2 | +using System.IO.Enumeration; |
2 | 3 | using System.Linq;
|
3 | 4 | using System.Text.Json;
|
4 | 5 | using System.Text.Json.Nodes;
|
|
18 | 19 |
|
19 | 20 | if (!string.IsNullOrEmpty(jsonSchema))
|
20 | 21 | {
|
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"; |
23 | 24 |
|
24 | 25 | var exceptionList = new List<string>
|
25 | 26 | {
|
|
31 | 32 | {
|
32 | 33 | // TODO
|
33 | 34 | // Infer group for classification.Set property upon import.
|
34 |
| - // Adding Name to dataObjectMappingList |
35 |
| - // Updating dataObjectMapping Name |
36 |
| - |
37 | 35 |
|
38 | 36 | if (!exceptionList.Contains(Path.GetFileName(file)))
|
39 | 37 | {
|
|
44 | 42 |
|
45 | 43 | // Create a JSON object, which can be modified at runtime.
|
46 | 44 | var jsonObject = JsonNode.Parse(jsonFile).AsObject();
|
47 |
| - |
| 45 | + |
48 | 46 | #region Generation Specific Data Object
|
49 | 47 |
|
50 | 48 | if (jsonObject["generationSpecificMetadata"] != null)
|
|
100 | 98 | }
|
101 | 99 |
|
102 | 100 | #endregion
|
103 |
| - |
| 101 | + |
104 | 102 | // Start parsing.
|
105 |
| - var dataObjectMappingJsonObjectList = new List<JsonObject>(); |
| 103 | + var dataObjectMappingJsonArray = new JsonArray(); |
106 | 104 |
|
107 | 105 | foreach (var dataObjectMapping in jsonObject["dataObjectMappings"].AsArray())
|
108 | 106 | {
|
|
114 | 112 | jsonObjectDataObjectMapping.Remove("mappingName");
|
115 | 113 | jsonObjectDataObjectMapping.Add("name", mappingNameNode);
|
116 | 114 |
|
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 | + } |
118 | 122 |
|
| 123 | + // Rename the mapping classifications. |
119 | 124 | var mappingClassificationsNode = jsonObjectDataObjectMapping["mappingClassifications"];
|
120 | 125 | jsonObjectDataObjectMapping.Remove("mappingClassifications");
|
121 | 126 | jsonObjectDataObjectMapping.Add("classifications", mappingClassificationsNode);
|
122 | 127 |
|
| 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 | + |
123 | 185 | // Rename the business key definitions.
|
124 |
| - var businessKeyDefinitionsNode = jsonObjectDataObjectMapping["businessKeys"]; |
| 186 | + var businessKeyDefinitionsNode = jsonObjectDataObjectMapping["businessKeys"]; |
125 | 187 | jsonObjectDataObjectMapping.Remove("businessKeys");
|
126 | 188 | jsonObjectDataObjectMapping.Add("businessKeyDefinitions", businessKeyDefinitionsNode);
|
127 | 189 |
|
|
144 | 206 | // Replace properties with newer names (upgrade).
|
145 | 207 | ReplaceDataObjectProperties(dataObjectJsonObject);
|
146 | 208 |
|
| 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 | + |
147 | 217 | // Data Items.
|
148 | 218 | var dataItems = new List<JsonObject>();
|
149 | 219 | foreach (var dataItem in dataObjectJsonObject["dataItems"].AsArray())
|
|
462 | 532 |
|
463 | 533 | #endregion
|
464 | 534 |
|
465 |
| - dataObjectMappingJsonObjectList.Add(jsonObjectDataObjectMapping); |
| 535 | + dataObjectMappingJsonArray.Add(jsonObjectDataObjectMapping); |
466 | 536 | }
|
467 | 537 |
|
468 | 538 | // 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; |
473 | 540 |
|
474 | 541 | // Finalisation
|
475 | 542 | var options = new JsonSerializerOptions { WriteIndented = true };
|
|
485 | 552 |
|
486 | 553 | try
|
487 | 554 | {
|
488 |
| - var test = JsonSerializer.Deserialize<DataObjectMappingList>(jsonObject.ToJsonString()); |
| 555 | + var testSerialisation = JsonSerializer.Deserialize<DataObjectMappingList>(jsonObject.ToJsonString()); |
489 | 556 | }
|
490 | 557 | catch (Exception ex)
|
491 | 558 | {
|
|
0 commit comments