3
3
using Microsoft . AspNetCore . Http ;
4
4
using Microsoft . Extensions . Configuration ;
5
5
using Microsoft . Extensions . Logging ;
6
- using NetTopologySuite . Geometries ;
7
6
using StrDss . Common ;
8
7
using StrDss . Data ;
9
8
using StrDss . Data . Entities ;
10
9
using StrDss . Data . Repositories ;
11
10
using StrDss . Model ;
12
- using StrDss . Model . OrganizationDtos ;
13
11
using StrDss . Model . RentalReportDtos ;
14
12
using StrDss . Service . CsvHelpers ;
15
13
using StrDss . Service . EmailTemplates ;
16
- using StrDss . Service . HttpClients ;
17
14
using System . Diagnostics ;
18
15
using System . Text ;
19
16
@@ -32,12 +29,12 @@ public class RegistrationService : ServiceBase, IRegistrationService
32
29
private IEmailMessageService _emailService ;
33
30
private IEmailMessageRepository _emailRepo ;
34
31
private IConfiguration _config ;
35
- private IRegistrationApiClient _regClient ;
32
+ private IPermitValidationService _permitValidation ;
36
33
private string ? _apiAccount ;
37
34
38
35
public RegistrationService ( ICurrentUser currentUser , IFieldValidatorService validator , IUnitOfWork unitOfWork , IMapper mapper , IHttpContextAccessor httpContextAccessor ,
39
36
IUploadDeliveryRepository uploadRepo , IRentalListingReportRepository reportRepo , IPhysicalAddressRepository addressRepo ,
40
- IUserRepository userRepo , IEmailMessageService emailService , IEmailMessageRepository emailRepo , IConfiguration config , IRegistrationApiClient regClient ,
37
+ IUserRepository userRepo , IEmailMessageService emailService , IEmailMessageRepository emailRepo , IConfiguration config , IPermitValidationService permitValidation ,
41
38
ILogger < StrDssLogger > logger )
42
39
: base ( currentUser , validator , unitOfWork , mapper , httpContextAccessor , logger )
43
40
{
@@ -48,8 +45,7 @@ public RegistrationService(ICurrentUser currentUser, IFieldValidatorService vali
48
45
_emailService = emailService ;
49
46
_emailRepo = emailRepo ;
50
47
_config = config ;
51
- _regClient = regClient ;
52
- _apiAccount = _config . GetValue < string > ( "REGISTRATION_API_ACCOUNT" ) ;
48
+ _permitValidation = permitValidation ;
53
49
}
54
50
55
51
public async Task ProcessRegistrationDataUploadAsync ( DssUploadDelivery upload )
@@ -132,7 +128,7 @@ public async Task ProcessRegistrationDataUploadAsync(DssUploadDelivery upload)
132
128
{
133
129
UserName = $ "{ user ! . GivenNm } ",
134
130
NumErrors = errorCount ,
135
- Link = GetHostUrl ( ) + "/upload-listing -history" ,
131
+ Link = GetHostUrl ( ) + "/registration-validation -history" ,
136
132
To = new string [ ] { user ! . EmailAddressDsc ! } ,
137
133
Info = $ "{ EmailMessageTypes . ListingUploadError } for { user . FamilyNm } , { user . GivenNm } ",
138
134
From = adminEmail
@@ -179,7 +175,7 @@ private async Task<bool> ProcessUploadLine(DssUploadDelivery upload, long OrgId,
179
175
return false ;
180
176
}
181
177
182
- ( bool isValid , Dictionary < string , List < string > > regErrors ) = await ValidateRegistrationPermitAsync ( row . RegNo , row . RentalUnit , row . RentalStreet , row . RentalPostal ) ;
178
+ ( bool isValid , Dictionary < string , List < string > > regErrors ) = await _permitValidation . ValidateRegistrationPermitAsync ( row . RegNo , row . RentalUnit , row . RentalStreet , row . RentalPostal ) ;
183
179
if ( isValid )
184
180
{
185
181
if ( ! string . IsNullOrEmpty ( row . ListingId ) )
@@ -204,63 +200,15 @@ private async Task<bool> ProcessUploadLine(DssUploadDelivery upload, long OrgId,
204
200
}
205
201
}
206
202
207
- SaveUploadLine ( uploadLine , regErrors , false , ! isValid ) ;
203
+ SaveUploadLine ( uploadLine , regErrors , false , ! isValid , false ) ;
208
204
return isValid ;
209
205
}
210
206
211
- public async Task < ( bool isValid , Dictionary < string , List < string > > errors ) > ValidateRegistrationPermitAsync ( string regNo , string unitNumber , string streetNumber , string postalCode )
212
- {
213
- bool isValid = true ;
214
- Dictionary < string , List < string > > errorDetails = new ( ) ;
215
-
216
- StrDss . Service . HttpClients . Body body = new ( )
217
- {
218
- Identifier = regNo ,
219
- Address = new ( )
220
- {
221
- UnitNumber = unitNumber ,
222
- StreetNumber = streetNumber ,
223
- PostalCode = postalCode
224
- }
225
- } ;
226
-
227
- try
228
- {
229
- Response resp = await _regClient . ValidatePermitAsync ( body , _apiAccount ) ;
230
-
231
- // If we didn't get a Status field back, then there was an error
232
- if ( string . IsNullOrEmpty ( resp . Status ) )
233
- {
234
- isValid = false ;
235
- if ( resp . Errors . Count == 0 )
236
- errorDetails . Add ( "UNKNOWN ERROR" , new List < string > { "Response did not contain a status or error message." } ) ;
237
- else
238
- errorDetails = resp . Errors
239
- . GroupBy ( e => e . Code )
240
- . ToDictionary ( g => g . Key , g => g . Select ( e => e . Message ) . ToList ( ) ) ;
241
- }
242
-
243
- // If the status is not "ACTIVE" then there is an issue with the registration
244
- if ( ! string . Equals ( resp . Status , "ACTIVE" , StringComparison . OrdinalIgnoreCase ) )
245
- {
246
- isValid = false ;
247
- errorDetails . Add ( "INACTIVE PERMIT" , new List < string > { "Error: registration status returned as " + resp . Status } ) ;
248
- }
249
- }
250
- catch ( Exception ex )
251
- {
252
- isValid = false ;
253
- errorDetails . Add ( "EXCEPTION" , new List < string > { ex . Message } ) ;
254
- }
255
-
256
- return ( isValid , errorDetails ) ;
257
- }
258
-
259
- private void SaveUploadLine ( DssUploadLine uploadLine , Dictionary < string , List < string > > errors , bool isValidationFailure , bool isSystemError )
207
+ private void SaveUploadLine ( DssUploadLine uploadLine , Dictionary < string , List < string > > errors , bool isValidationFailure , bool isSystemError , bool useUnderscores = true )
260
208
{
261
209
uploadLine . IsValidationFailure = isValidationFailure ;
262
210
uploadLine . IsSystemFailure = isSystemError ;
263
- uploadLine . ErrorTxt = errors . ParseErrorWithUnderScoredKeyName ( ) ;
211
+ uploadLine . ErrorTxt = useUnderscores ? errors . ParseErrorWithUnderScoredKeyName ( ) : errors . ParseError ( ) ;
264
212
uploadLine . IsProcessed = true ;
265
213
_unitOfWork . Commit ( ) ;
266
214
}
0 commit comments