@@ -24,9 +24,9 @@ public class DataSetVersionMapping : ICreatedUpdatedTimestamps<DateTimeOffset, D
24
24
public FilterMappingPlan FilterMappingPlan { get ; set ; } = null ! ;
25
25
26
26
public bool LocationMappingsComplete { get ; set ; }
27
-
27
+
28
28
public bool FilterMappingsComplete { get ; set ; }
29
-
29
+
30
30
public DateTimeOffset Created { get ; set ; }
31
31
32
32
public DateTimeOffset ? Updated { get ; set ; }
@@ -38,18 +38,18 @@ public void Configure(EntityTypeBuilder<DataSetVersionMapping> builder)
38
38
builder . Property ( mapping => mapping . Id )
39
39
. HasValueGenerator < UuidV7ValueGenerator > ( ) ;
40
40
41
- builder . HasIndex ( mapping => new { mapping . SourceDataSetVersionId } )
41
+ builder . HasIndex ( mapping => new { mapping . SourceDataSetVersionId } )
42
42
. HasDatabaseName ( "IX_DataSetVersionMappings_SourceDataSetVersionId" )
43
43
. IsUnique ( ) ;
44
44
45
- builder . HasIndex ( mapping => new { mapping . TargetDataSetVersionId } )
45
+ builder . HasIndex ( mapping => new { mapping . TargetDataSetVersionId } )
46
46
. HasDatabaseName ( "IX_DataSetVersionMappings_TargetDataSetVersionId" )
47
47
. IsUnique ( ) ;
48
48
49
49
builder . OwnsOne ( v => v . LocationMappingPlan , locations =>
50
50
{
51
51
locations . ToJson ( ) ;
52
- locations . OwnsMany ( l => l . Mappings , locationMappings =>
52
+ locations . OwnsMany ( l => l . Levels , locationMappings =>
53
53
{
54
54
locationMappings . OwnsMany ( mapping => mapping . Mappings , locationMapping =>
55
55
{
@@ -59,9 +59,10 @@ public void Configure(EntityTypeBuilder<DataSetVersionMapping> builder)
59
59
} ) ;
60
60
} ) ;
61
61
62
- locations . OwnsMany ( locations => locations . Candidates , locationTargets =>
62
+ locations . OwnsMany ( location => location . Levels , level =>
63
63
{
64
- locationTargets . OwnsMany ( mapping => mapping . Candidates ) ;
64
+ level . OwnsMany ( mapping => mapping . Mappings ) ;
65
+ level . OwnsMany ( mapping => mapping . Candidates ) ;
65
66
} ) ;
66
67
} ) ;
67
68
@@ -75,7 +76,7 @@ public void Configure(EntityTypeBuilder<DataSetVersionMapping> builder)
75
76
filterMapping . Property ( mapping => mapping . Type )
76
77
. HasConversion ( new EnumToEnumValueConverter < MappingType > ( ) ) ;
77
78
78
- filterMapping . OwnsMany ( mapping => mapping . Options , filterOptionMapping =>
79
+ filterMapping . OwnsMany ( mapping => mapping . OptionMappings , filterOptionMapping =>
79
80
{
80
81
filterOptionMapping . OwnsOne ( mapping => mapping . Source ) ;
81
82
filterOptionMapping . Property ( mapping => mapping . Type )
@@ -107,7 +108,7 @@ public enum MappingType
107
108
/// The user has manually chosen a mapping candidate for this source element.
108
109
/// </summary>
109
110
ManualMapped ,
110
-
111
+
111
112
/// <summary>
112
113
/// The user has manually indicated that no mapping candidate exists for this source element.
113
114
/// </summary>
@@ -117,7 +118,7 @@ public enum MappingType
117
118
/// The server has automatically selected a likely mapping candidate for this source element.
118
119
/// </summary>
119
120
AutoMapped ,
120
-
121
+
121
122
/// <summary>
122
123
/// The server has automatically indicated that no likely mapping candidate exists for this source element.
123
124
/// </summary>
@@ -127,13 +128,20 @@ public enum MappingType
127
128
/// <summary>
128
129
/// This base class represents an element from the DataSetVersions that can be mapped.
129
130
/// </summary>
130
- public abstract class MappableElement
131
+ public abstract record MappableElement
131
132
{
132
133
/// <summary>
133
134
/// This is a synthetic identifier which is used to identify source and target
134
135
/// elements in lieu of using actual database ids.
135
136
/// </summary>
136
- public string Key { get ; set ; }
137
+ public string Key { get ; set ; } = string . Empty ;
138
+ }
139
+
140
+ public abstract record MappableElementWithOptions < TMappableOption >
141
+ : MappableElement
142
+ where TMappableOption : MappableElement
143
+ {
144
+ public List < TMappableOption > Options { get ; set ; } = [ ] ;
137
145
}
138
146
139
147
/// <summary>
@@ -142,90 +150,110 @@ public abstract class MappableElement
142
150
/// the type of mapping that has been performed (e.g. the user choosing a candidate Location from
143
151
/// the target DataSetVersion) and the candidate key (if a candidate has been chosen).
144
152
/// </summary>
145
- public abstract class LeafMapping < TMappableElement >
146
- where TMappableElement : MappableElement
153
+ public abstract record Mapping < TMappableElement >
154
+ where TMappableElement : class
147
155
{
148
- public MappingType Type { get ; set ; }
156
+ public MappingType Type { get ; set ; } = MappingType . None ;
149
157
150
158
public TMappableElement Source { get ; set ; } = null ! ;
151
159
152
160
public string ? CandidateKey { get ; set ; }
153
161
}
154
162
155
- public abstract class ParentMapping < TMappableElement , TOption , TOptionMapping >
163
+ /// <summary>
164
+ /// This base class represents a mapping for a parent element which then itself also contains
165
+ /// child elements (or "options") that can themselves be mapped.
166
+ /// </summary>
167
+ public abstract record ParentMapping < TMappableElement , TOption , TOptionMapping >
168
+ : Mapping < TMappableElement >
156
169
where TMappableElement : MappableElement
157
170
where TOption : MappableElement
158
- where TOptionMapping : LeafMapping < TOption >
171
+ where TOptionMapping : Mapping < TOption >
159
172
{
160
- public MappingType Type { get ; set ; }
161
-
162
- public TMappableElement Source { get ; set ; } = null ! ;
163
-
164
- public List < TOptionMapping > Options { get ; set ; } = [ ] ;
165
-
166
- public string ? CandidateKey { get ; set ; }
173
+ public List < TOptionMapping > OptionMappings { get ; set ; } = [ ] ;
167
174
}
168
175
169
- public class LocationOption : MappableElement
176
+ /// <summary>
177
+ /// This represents a location option that is potentially mappable to another location option
178
+ /// from the same geographic level.
179
+ /// </summary>
180
+ public record LocationOption : MappableElement
170
181
{
171
182
public string Label { get ; set ; } = string . Empty ;
172
-
173
- protected string ? Code { get ; set ; }
174
-
175
- protected string ? OldCode { get ; set ; }
176
-
177
- protected string ? Urn { get ; set ; }
178
-
179
- protected string ? LaEstab { get ; set ; }
180
-
181
- protected string ? Ukprn { get ; set ; }
182
183
}
183
184
184
- public class LocationOptionMapping : LeafMapping < LocationOption > ;
185
+ /// <summary>
186
+ /// This represents the mapping, or failure to map, of a source location option to a target
187
+ /// location option from the same geographic level.
188
+ /// </summary>
189
+ public record LocationOptionMapping : Mapping < LocationOption > ;
185
190
186
- public class LocationLevelMappingPlan
191
+ /// <summary>
192
+ /// This represents a single geographic level's worth of location mappings from the source
193
+ /// data set version and potential candidates to map to from the target data set version.
194
+ /// </summary>
195
+ public record LocationLevelMappings
187
196
{
188
197
public GeographicLevel Level { get ; set ; }
189
198
190
199
public List < LocationOptionMapping > Mappings { get ; set ; } = [ ] ;
191
- }
192
-
193
- public class LocationLevelMappingCandidates
194
- {
195
- public GeographicLevel Level { get ; set ; }
196
200
197
201
public List < LocationOption > Candidates { get ; set ; } = [ ] ;
198
202
}
199
203
204
+ /// <summary>
205
+ /// This represents the overall mapping plan for all the geographic levels
206
+ /// and locations from the source data set version to the target version.
207
+ /// </summary>
200
208
public class LocationMappingPlan
201
209
{
202
- public List < LocationLevelMappingPlan > Mappings { get ; set ; }
203
-
204
- public List < LocationLevelMappingCandidates > Candidates { get ; set ; }
210
+ public List < LocationLevelMappings > Levels { get ; set ; } = [ ] ;
205
211
}
206
212
207
- public class FilterOption : MappableElement
213
+ /// <summary>
214
+ /// This represents a filter option that is potentially mappable to another filter option.
215
+ /// </summary>
216
+ public record FilterOption : MappableElement
208
217
{
209
218
public string Label { get ; set ; } = string . Empty ;
210
219
}
211
220
212
- public class Filter : MappableElement
221
+ /// <summary>
222
+ /// This represents a filter that is potentially mappable to another filter.
223
+ /// </summary>
224
+ public record Filter : MappableElement
213
225
{
214
226
public string Label { get ; set ; } = string . Empty ;
215
227
}
216
228
217
- public class FilterMappingCandidate : MappableElement
229
+ /// <summary>
230
+ /// This represents a candidate filter and all of its candidate filter options from
231
+ /// the target data set version that could be mapped to from filters and filter options
232
+ /// from the source version.
233
+ /// </summary>
234
+ public record FilterMappingCandidate : MappableElementWithOptions < FilterOption >
218
235
{
219
236
public string Label { get ; set ; } = string . Empty ;
220
-
221
- public List < FilterOption > Options { get ; set ; } = [ ] ;
222
237
}
223
238
224
- public class FilterOptionMapping : LeafMapping < FilterOption > ;
239
+ /// <summary>
240
+ /// This represents a potential mapping of a filter option from the source data set version
241
+ /// to a filter option in the target version. In order to be mappable, both filter options'
242
+ /// parent filters must firstly be mapped to each other.
243
+ /// </summary>
244
+ public record FilterOptionMapping : Mapping < FilterOption > ;
225
245
226
- public class FilterMapping : ParentMapping < Filter , FilterOption , FilterOptionMapping > ;
246
+ /// <summary>
247
+ /// This represents a potential mapping of a filter from the source data set version
248
+ /// to a filter in the target version.
249
+ /// </summary>
250
+ public record FilterMapping : ParentMapping < Filter , FilterOption , FilterOptionMapping > ;
227
251
228
- public class FilterMappingPlan
252
+ /// <summary>
253
+ /// This represents the overall mapping plan for filters and filter options from the source
254
+ /// data set version to filters and filter options in the target data set version.
255
+ /// </summary>
256
+ public record FilterMappingPlan
229
257
{
230
258
public List < FilterMapping > Mappings { get ; set ; } = [ ] ;
231
259
0 commit comments