Skip to content

Commit 7eb4b01

Browse files
authored
Merge pull request #345 from bcgov/applicationscore-poc
Changed code to allow 1:N school Districts relation
2 parents b93c39f + e780d30 commit 7eb4b01

File tree

3 files changed

+14
-31
lines changed

3 files changed

+14
-31
lines changed

OFM.Infrastructure.WebAPI/Models/ApplicationScore/AppicationScore.cs

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -191,15 +191,9 @@ public static class DataverseQueries
191191
<attribute name=""ofm_postal_code"" />
192192
<filter>
193193
<condition attribute=""ofm_postal_code"" operator=""eq"" value=""{{0}}"" />
194+
<condition attribute=""ofm_application_score_calculator"" operator=""eq"" value=""{{1}}"" />
194195
<condition attribute=""statecode"" operator=""eq"" value=""0"" />
195196
</filter>
196-
<link-entity name=""ofm_asc_sd"" from=""ofm_school_districtid"" to=""ofm_school_districtid"" alias=""asc"">
197-
<filter>
198-
<condition attribute=""ofm_application_score_calculatorid"" operator=""eq"" value=""{{1}}"" />
199-
200-
</filter>
201-
</link-entity>
202-
203197
</entity>
204198
</fetch>";
205199
public const string PopulationCentreQuery = $@"ofm_population_centres?fetchXml=
@@ -314,7 +308,7 @@ public static class DataverseQueries
314308
</entity>
315309
</fetch>";
316310

317-
public static string AllSchoolDistrictQuery = $@"ofm_school_districts?$select=ofm_school_district_fullname,ofm_school_district_number,ofm_school_district_name,ofm_postal_code,ofm_name&$filter=statecode eq 0&$expand=ofm_application_score_calculator_ofm_school_district_ofm_school_district($filter=ofm_application_score_calculatorid eq {{0}})";
311+
public static string AllSchoolDistrictQuery = $@"ofm_school_districts?$select=ofm_school_district_fullname,ofm_school_district_number,ofm_school_district_name,ofm_postal_code,ofm_name&$filter=statecode eq 0 and _ofm_application_score_calculator_value eq '{{0}}'";
318312
public static string AllScoreCategoryQuery = "ofm_application_score_categories?$filter=_ofm_application_score_calculator_value eq '{0}'&$select=ofm_name,ofm_maximum_score,ofm_description,ofm_category_display_name,ofm_application_score_group";
319313
public static string AllACCBDataQuery = @$"ofm_accbs?$select=ofm_accbid,ofm_postal_code,ofm_income_indicator,ofm_name&$filter=(_ofm_application_score_calculator_value eq {{0}} and statecode eq 0)";
320314
public static string AllPopulationCentreQuery = $@"ofm_population_centres?$select=ofm_population_centreid,ofm_city,ofm_projected_population,ofm_name,ofm_projected_population&$filter=(_ofm_application_score_calculator_value eq {{0}} and statecode eq 0)";
@@ -539,6 +533,7 @@ public JsonObject Clone(Guid calculatorId)
539533

540534
_data["ofm_application_score_calculator@odata.bind"] = $"ofm_application_score_calculators({calculatorId})";
541535
_data.Remove("ofm_name");
536+
_data.Remove("ofm_school_districtid");
542537
_data.Remove("@odata.etag");
543538
return _data;
544539

@@ -549,7 +544,7 @@ public SchoolDistrict(JsonObject data)
549544
}
550545
public string? SchoolDistrictName => _data.GetPropertyValue<string>("ofm_school_district_name");
551546

552-
public int SchoolDistrictNumber => _data.GetPropertyValue<int>("ofm_school_district_number");
547+
public string? SchoolDistrictNumber => _data.GetPropertyValue<string>("ofm_school_district_number");
553548
public string? PostalCode => _data.GetPropertyValue<string>("ofm_postal_code");
554549

555550
public string? SchoolDistrictFullName => _data.GetPropertyValue<string>("ofm_school_district_fullname");
@@ -640,7 +635,7 @@ public JsonObject Clone(Guid calculatorId) {
640635

641636
public decimal? MaximumFeeAmount => _data.GetPropertyValue<decimal>("ofm_threshold_fee");
642637
public string? ProgramType => _data.GetFormattedValue("_ofm_childcare_category_value");
643-
public int ProgramTypeValue => _data.GetPropertyValue<int>("_ofm_childcare_category_value");
638+
public string? ProgramTypeValue => _data.GetPropertyValue<string>("_ofm_childcare_category_value");
644639

645640
public string? Region => _data.GetFormattedValue("_ofm_region_value");
646641
public Guid? RegionId => _data.GetPropertyValue<Guid>("_ofm_region_value");

OFM.Infrastructure.WebAPI/Services/Processes/ApplicationScore/DataverseRepository.cs

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ public interface IDataverseRepository
116116
Task<(IEnumerable<PopulationCentre> populationCentres, bool? moreData, string nextPage)> GetPopulationCentres(Guid calculatorId, string? nextPage);
117117
Task CreateAccbIncomesBatchAsync(IEnumerable<JsonObject> accbs);
118118
Task<IEnumerable<ScoreCategory>> CreateScoreCategoriesBatchAsync(IEnumerable<JsonObject> categories);
119-
Task AssociateSchoolDistrictsBatchAsync(IEnumerable<JsonObject> schoolDistricts, Guid calculatorId);
119+
Task CreateSchoolDistrictsBatchAsync(IEnumerable<JsonObject> schoolDistricts, Guid calculatorId);
120120
Task<Guid> CreateScoreCalculatorAsync(JsonObject scoreCalculator);
121121
Task CreateScoreParametersBatchAsync(IEnumerable<JsonObject> parameters);
122122
Task CreateThresholdFeesBatchAsync(IEnumerable<JsonObject> fees);
@@ -386,32 +386,20 @@ public async Task<IEnumerable<ScoreCategory>> CreateScoreCategoriesBatchAsync(IE
386386
return response.Result.Select(x => new ScoreCategory(x));
387387

388388
}
389-
public async Task AssociateSchoolDistrictsBatchAsync(IEnumerable<JsonObject> schoolDistricts, Guid calcId)
389+
public async Task CreateSchoolDistrictsBatchAsync(IEnumerable<JsonObject> schoolDistricts, Guid calcId)
390390
{
391391
if (schoolDistricts == null || !schoolDistricts.Any())
392392
return;
393-
394-
var calculator = await d365WebApiService.SendRetrieveRequestAsync(appUserService.AZSystemAppUser, $"ofm_application_score_calculators({calcId})");
395-
if (!calculator.IsSuccessStatusCode)
396-
{
397-
var responseBody = await calculator.Content.ReadAsStringAsync();
398-
throw new Exception($"AssociateSchoolDistrictsBatchAsync(Guid {calcId}): HTTP Failure: {responseBody}");
399-
}
400-
401-
402393
var batchRequests = schoolDistricts.Select(x =>
403394
{
404-
var association = new JsonObject();
405-
association["@odata.id"] = calculator?.RequestMessage?.RequestUri?.AbsoluteUri;
406-
var requestUri = $"ofm_school_districts({x.GetPropertyValue<Guid>("ofm_school_districtid")})/ofm_application_score_calculator_ofm_school_district_ofm_school_district/$ref";
407-
return new CreateRequest(requestUri, association);
395+
return new CreateRequest("ofm_school_districts", x);
408396
}
409397
).ToList<HttpRequestMessage>();
410398

411399
var response = await d365WebApiService.SendBatchMessageAsync(appUserService.AZSystemAppUser, batchRequests, null);
412400
if (!response.CompletedWithNoErrors)
413401
{
414-
throw new Exception($"Upsert of Application Score failed: Batch HTTP Failure: {string.Join(" | ", response.Errors)}");
402+
throw new Exception($"Create of School District failed: Batch HTTP Failure: {string.Join(" | ", response.Errors)}");
415403
}
416404
}
417405
public async Task<Guid> CreateScoreCalculatorAsync(JsonObject scoreCalculator)
@@ -439,7 +427,7 @@ public async Task CreateScoreParametersBatchAsync(IEnumerable<JsonObject> parame
439427
var response = await d365WebApiService.SendBatchMessageAsync(appUserService.AZSystemAppUser, batchRequests, null);
440428
if (!response.CompletedWithNoErrors)
441429
{
442-
throw new Exception($"Upsert of Application Score failed: Batch HTTP Failure: {string.Join(" | ", response.Errors)}");
430+
throw new Exception($"Upsert of Application Score Parameter failed: Batch HTTP Failure: {string.Join(" | ", response.Errors)}");
443431
}
444432
}
445433
public async Task CreateThresholdFeesBatchAsync(IEnumerable<JsonObject> fees)
@@ -450,7 +438,7 @@ public async Task CreateThresholdFeesBatchAsync(IEnumerable<JsonObject> fees)
450438
var response = await d365WebApiService.SendBatchMessageAsync(appUserService.AZSystemAppUser, batchRequests, null);
451439
if (!response.CompletedWithNoErrors)
452440
{
453-
throw new Exception($"Upsert of Application Score failed: Batch HTTP Failure: {string.Join(" | ", response.Errors)}");
441+
throw new Exception($"Upsert of Threshold fees failed: Batch HTTP Failure: {string.Join(" | ", response.Errors)}");
454442
}
455443
}
456444
public async Task CreatePopulationCentresBatchAsync(IEnumerable<JsonObject> centres)
@@ -462,7 +450,7 @@ public async Task CreatePopulationCentresBatchAsync(IEnumerable<JsonObject> cent
462450
var response = await d365WebApiService.SendBatchMessageAsync(appUserService.AZSystemAppUser, batchRequests, null);
463451
if (!response.CompletedWithNoErrors)
464452
{
465-
throw new Exception($"Upsert of Application Score failed: Batch HTTP Failure: {string.Join(" | ", response.Errors)}");
453+
throw new Exception($"Upsert of Population Centres failed: Batch HTTP Failure: {string.Join(" | ", response.Errors)}");
466454
}
467455
}
468456

OFM.Infrastructure.WebAPI/Services/Processes/ApplicationScore/P805CreateScoreCalculatorVersionProvider.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,11 +129,11 @@ public async Task<JsonObject> RunProcessAsync(ID365AppUserService appUserService
129129
if (calcVersion.GetPropertyValue<bool>("ofm_copy_school_district"))
130130
{
131131
var districts = await dataverseRepository.GetSchoolDistricts(originalCalcId, null);
132-
await dataverseRepository.AssociateSchoolDistrictsBatchAsync(districts.districts?.Select(x => x.Clone(calcId)), calcId);
132+
await dataverseRepository.CreateSchoolDistrictsBatchAsync(districts.districts?.Select(x => x.Clone(calcId)), calcId);
133133
while (districts.moreData.Value)
134134
{
135135
districts = await dataverseRepository.GetSchoolDistricts(originalCalcId, districts.nextPage);
136-
await dataverseRepository.AssociateSchoolDistrictsBatchAsync(districts.districts?.Select(x => x.Clone(calcId)), calcId);
136+
await dataverseRepository.CreateSchoolDistrictsBatchAsync(districts.districts?.Select(x => x.Clone(calcId)), calcId);
137137
}
138138
}
139139

0 commit comments

Comments
 (0)