|
1 | | -namespace DataWarehouseAutomation; |
| 1 | +using DataWarehouseAutomation.Utils; |
| 2 | + |
| 3 | +namespace DataWarehouseAutomation.DwaModel; |
2 | 4 |
|
3 | 5 | /// <summary> |
4 | 6 | /// The mapping between a source and target data set / table / file. |
@@ -46,15 +48,35 @@ public class DataObjectMapping : IMetadata |
46 | 48 | /// The target object of the mapping. This is always a Data Object type. |
47 | 49 | /// </summary> |
48 | 50 | [JsonPropertyName("targetDataObject")] |
49 | | - public DataObject TargetDataObject { get; set; } = new() { Name = "NewTargetDataObject" }; |
| 51 | + public IDataObject TargetDataObject { get; set; } = new DataObject() { Name = "newTargetDataObject" }; |
50 | 52 |
|
51 | 53 | /// <summary> |
52 | 54 | /// The collection of associated data object for purposes other than source-target relationship. |
53 | 55 | /// For example for lookups, merge joins, lineage etc. |
54 | 56 | /// </summary> |
55 | 57 | [JsonPropertyName("relatedDataObjects")] |
56 | 58 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] |
57 | | - public List<DataObject>? RelatedDataObjects { get; set; } |
| 59 | + public List<IDataObject>? RelatedDataObjects { get; set; } |
| 60 | + |
| 61 | + private List<IDataItem> _dataItems = []; |
| 62 | + /// <summary> |
| 63 | + /// The collection of Data Items <see cref="IDataItem"/> specifically associated with this Data Object Mapping, |
| 64 | + /// used as source/target Data Items/Queries for the mapping or the Mappings BKCM as needed. |
| 65 | + /// </summary> |
| 66 | + [JsonPropertyName("dataItems")] |
| 67 | + [JsonPropertyOrder(order: 55)] |
| 68 | + public List<IDataItem> DataItems |
| 69 | + { |
| 70 | + get |
| 71 | + { |
| 72 | + return _dataItems; |
| 73 | + } |
| 74 | + set |
| 75 | + { |
| 76 | + _dataItems = value; |
| 77 | + isSorted = false; |
| 78 | + } |
| 79 | + } |
58 | 80 |
|
59 | 81 | /// <summary> |
60 | 82 | /// The collection of individual attribute (column or query) mappings. |
@@ -99,6 +121,33 @@ public class DataObjectMapping : IMetadata |
99 | 121 | public string? Notes { get; set; } |
100 | 122 | #endregion |
101 | 123 |
|
| 124 | + #region Json Representation |
| 125 | + private bool isSorted = false; |
| 126 | + |
| 127 | + /// <summary> |
| 128 | + /// Sort all the lists in the metadata object |
| 129 | + /// </summary> |
| 130 | + public void SortLists() |
| 131 | + { |
| 132 | + if (!isSorted) |
| 133 | + { |
| 134 | + isSorted = true; |
| 135 | + SourceDataObjects.Sort(); |
| 136 | + RelatedDataObjects.Sort(); |
| 137 | + DataItemMappings.Sort(); |
| 138 | + BusinessKeyDefinitions.Sort(); |
| 139 | + Classifications.Sort(); |
| 140 | + Extensions.Sort(); |
| 141 | + } |
| 142 | + } |
| 143 | + |
| 144 | + /// <summary> |
| 145 | + /// Get the standard Json representation |
| 146 | + /// </summary> |
| 147 | + [JsonIgnore(Condition = JsonIgnoreCondition.Always)] |
| 148 | + public string Json => JsonSerializer.Serialize(this, DefaultJsonOptions.SerializerOptions); |
| 149 | + #endregion |
| 150 | + |
102 | 151 | #region Methods |
103 | 152 | /// <summary> |
104 | 153 | /// Use this method to assert if two Data Object Mappings are the same, based on their Ids. |
|
0 commit comments