Skip to content

Commit 5e39633

Browse files
authored
Merge pull request #548 from bcgov/yj
Yj
2 parents 70627c8 + 3e3ad8e commit 5e39633

File tree

7 files changed

+98
-16
lines changed

7 files changed

+98
-16
lines changed

database/ddl/STR_DSS_Views_Sprint_9.sql

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ CREATE OR REPLACE VIEW dss_rental_listing_vw AS select drl.rental_listing_id
4545
, drl.nights_booked_qty as nights_booked_ytd_qty
4646
, drl.separate_reservations_qty as separate_reservations_ytd_qty
4747
, drl.business_licence_no
48-
, drl.
4948
, drl.bc_registry_no
5049
, demt.email_message_type_nm as last_action_nm
5150
, dem.message_delivery_dtm as last_action_dtm

server/StrDss.Common/Constants.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -234,10 +234,7 @@ public static class FieldTypes
234234

235235
public static class CodeSet
236236
{
237-
public const string Role = "ROLE";
238-
public const string ZoneType = "ZONE_TYPE";
239-
public const string StrAffiliate = "STR_AFFILIATE";
240-
public const string ComplianceStatus = "COMPLIANCE_STATUS";
237+
public const string LicenseStatus = "License Status";
241238
}
242239

243240
public static class StrDssIdProviders

server/StrDss.Data/Repositories/BizLicenseRepository.cs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,13 @@ INSERT INTO biz_lic_table (
9393

9494
var parameters = new List<NpgsqlParameter>
9595
{
96-
new NpgsqlParameter("@businessLicenceNo", row.BusinessLicenceNo),
97-
new NpgsqlParameter("@expiryDt", ConvertToDate(row.ExpiryDt)),
96+
new NpgsqlParameter("@businessLicenceNo", row.BusinessLicenceNo.ToUpper()),
97+
98+
new NpgsqlParameter("@expiryDt", NpgsqlTypes.NpgsqlDbType.Date)
99+
{
100+
Value = ConvertToDate(row.ExpiryDt) ?? (object)DBNull.Value
101+
},
102+
98103
new NpgsqlParameter("@physicalRentalAddressTxt", row.PhysicalRentalAddressTxt ?? (object)DBNull.Value),
99104
new NpgsqlParameter("@licenceTypeTxt", row.LicenceTypeTxt ?? (object)DBNull.Value),
100105
new NpgsqlParameter("@restrictionTxt", row.RestrictionTxt ?? (object)DBNull.Value),
@@ -110,7 +115,12 @@ INSERT INTO biz_lic_table (
110115
new NpgsqlParameter("@businessOperatorPhoneNo", row.BusinessOperatorPhoneNo ?? (object)DBNull.Value),
111116
new NpgsqlParameter("@businessOperatorEmailAddressDsc", row.BusinessOperatorEmailAddressDsc ?? (object)DBNull.Value),
112117
new NpgsqlParameter("@infractionTxt", row.InfractionTxt ?? (object)DBNull.Value),
113-
new NpgsqlParameter("@infractionDt", ConvertToDate(row.InfractionDt) ?? (object)DBNull.Value),
118+
119+
new NpgsqlParameter("@infractionDt", NpgsqlTypes.NpgsqlDbType.Date)
120+
{
121+
Value = ConvertToDate(row.InfractionDt) ?? (object)DBNull.Value
122+
},
123+
114124
new NpgsqlParameter("@propertyZoneTxt", row.PropertyZoneTxt ?? (object)DBNull.Value),
115125
new NpgsqlParameter("@availableBedroomsQty", ConvertToInt2(row.AvailableBedroomsQty) ?? (object)DBNull.Value),
116126
new NpgsqlParameter("@maxGuestsAllowedQty", ConvertToInt2(row.MaxGuestsAllowedQty) ?? (object)DBNull.Value),
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
using AutoMapper;
2+
using Microsoft.EntityFrameworkCore;
3+
using Microsoft.Extensions.Logging;
4+
using StrDss.Common;
5+
using StrDss.Data.Entities;
6+
using StrDss.Model;
7+
using StrDss.Model.CommonCode;
8+
9+
namespace StrDss.Data.Repositories
10+
{
11+
public interface ICodeSetRepository
12+
{
13+
Task<List<CommonCodeDto>> LoadCodeSetAsync();
14+
}
15+
public class CodeSetRepository : RepositoryBase<DssUserIdentity>, ICodeSetRepository
16+
{
17+
public CodeSetRepository(DssDbContext dbContext, IMapper mapper, ICurrentUser currentUser, ILogger<StrDssLogger> logger)
18+
: base(dbContext, mapper, currentUser, logger)
19+
{
20+
}
21+
22+
public async Task<List<CommonCodeDto>> LoadCodeSetAsync()
23+
{
24+
var commonCodes = new List<CommonCodeDto>();
25+
26+
commonCodes.AddRange(await
27+
_dbContext.DssBusinessLicenceStatusTypes
28+
.AsNoTracking()
29+
.Select(x => new CommonCodeDto
30+
{
31+
CodeSet = CodeSet.LicenseStatus,
32+
CodeName = x.LicenceStatusType,
33+
CodeValue = x.LicenceStatusTypeNm
34+
}).ToListAsync()
35+
);
36+
37+
return commonCodes;
38+
}
39+
}
40+
}

server/StrDss.Service/BizLicenseService.cs

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,16 @@ public class BizLicenseService : ServiceBase, IBizLicenseService
2222
private IBizLicenseRepository _bizLicenseRepo;
2323
private IUploadDeliveryRepository _uploadRepo;
2424
private IOrganizationRepository _orgRepo;
25+
private ICodeSetRepository _codeSetRepo;
2526

2627
public BizLicenseService(ICurrentUser currentUser, IFieldValidatorService validator, IUnitOfWork unitOfWork, IMapper mapper, IHttpContextAccessor httpContextAccessor, ILogger<StrDssLogger> logger,
27-
IBizLicenseRepository bizLicenseRepo, IUploadDeliveryRepository uploadRepo, IOrganizationRepository orgRepo)
28+
IBizLicenseRepository bizLicenseRepo, IUploadDeliveryRepository uploadRepo, IOrganizationRepository orgRepo, ICodeSetRepository codeSetRepo)
2829
: base(currentUser, validator, unitOfWork, mapper, httpContextAccessor, logger)
2930
{
3031
_bizLicenseRepo = bizLicenseRepo;
3132
_uploadRepo = uploadRepo;
3233
_orgRepo = orgRepo;
34+
_codeSetRepo = codeSetRepo;
3335
}
3436

3537
public async Task<BizLicenseDto?> GetBizLicense(long businessLicenceId)
@@ -39,6 +41,11 @@ public BizLicenseService(ICurrentUser currentUser, IFieldValidatorService valida
3941

4042
public async Task ProcessBizLicenseUploadAsync()
4143
{
44+
if (!_validator.CommonCodes.Any())
45+
{
46+
_validator.CommonCodes = await _codeSetRepo.LoadCodeSetAsync();
47+
}
48+
4249
var upload = await _uploadRepo.GetUploadToProcessAsync(UploadDeliveryTypes.LicenseData);
4350

4451
if (upload != null)
@@ -49,7 +56,19 @@ public async Task ProcessBizLicenseUploadAsync()
4956

5057
await ProcessBizLicenseUploadAsync(upload);
5158

52-
await _bizLicenseRepo.ProcessBizLicTempTable();
59+
_unitOfWork.Commit();
60+
61+
var errorCount = upload.DssUploadLines.Count(x => x.IsValidationFailure);
62+
63+
if (errorCount == 0)
64+
{
65+
await _bizLicenseRepo.ProcessBizLicTempTable();
66+
_logger.LogInformation($"Success: Finished Business License Upload {upload.UploadDeliveryId} - {upload.ProvidingOrganizationId} - {upload.ProvidingOrganization.OrganizationNm}");
67+
}
68+
else
69+
{
70+
_logger.LogInformation($"Fail: Finished Business License Upload {upload.UploadDeliveryId} - {upload.ProvidingOrganizationId} - {upload.ProvidingOrganization.OrganizationNm}");
71+
}
5372

5473
transaction.Commit();
5574
}
@@ -136,7 +155,7 @@ private void SaveUploadLine(DssUploadLine uploadLine, Dictionary<string, List<st
136155
uploadLine.ErrorTxt = systemError;
137156
}
138157

139-
uploadLine.IsProcessed = false;
158+
uploadLine.IsProcessed = true;
140159
}
141160
}
142161
}

server/StrDss.Service/BizLicenseValidationRule.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public static void LoadBizLicenseValidationRules(List<FieldValidationRule> rules
4848
FieldName = BizLicenseRowFields.LicenceStatusType,
4949
FieldType = FieldTypes.String,
5050
Required = false,
51-
//AllowedValues = new List<string> { "Pending", "Issued", "Suspended", "Revoked", "Cancelled", "Expired" }
51+
CodeSet = CodeSet.LicenseStatus,
5252
});
5353

5454
rules.Add(new FieldValidationRule
@@ -165,6 +165,7 @@ public static void LoadBizLicenseValidationRules(List<FieldValidationRule> rules
165165
EntityName = Entities.BizLicenseRowUntyped,
166166
FieldName = BizLicenseRowFields.AvailableBedroomsQty,
167167
FieldType = FieldTypes.String,
168+
Required = false,
168169
RegexInfo = RegexDefs.GetRegexInfo(RegexDefs.Quantity)
169170
});
170171

server/StrDss.Service/FieldValidatorService.cs

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ public FieldValidatorService()
2020

2121
RentalListingReportValidationRule.LoadReportValidationRules(_rules);
2222
RoleValidationRule.LoadReportValidationRules(_rules);
23+
BizLicenseValidationRule.LoadBizLicenseValidationRules(_rules);
2324
}
2425

2526
public IEnumerable<FieldValidationRule> GetFieldValidationRules(string entityName)
@@ -123,18 +124,33 @@ private List<string> ValidateStringField<T>(FieldValidationRule rule, T val, int
123124

124125
if (rule.CodeSet != null)
125126
{
126-
if (decimal.TryParse(value, out decimal numValue))
127+
//surrogate key
128+
var hasId = CommonCodes.Any(x => x.CodeSet == rule.CodeSet && x.Id != 0);
129+
130+
if (hasId)
127131
{
128-
var exists = CommonCodes.Any(x => x.CodeSet == rule.CodeSet && x.Id == numValue);
132+
if (decimal.TryParse(value, out decimal numValue))
133+
{
134+
var exists = CommonCodes.Any(x => x.CodeSet == rule.CodeSet && x.Id == numValue);
129135

130-
if (!exists)
136+
if (!exists)
137+
{
138+
messages.Add($"{rowNumPrefix}Invalid value. [{value}] doesn't exist in the code set {rule.CodeSet}.");
139+
}
140+
}
141+
else
131142
{
132143
messages.Add($"{rowNumPrefix}Invalid value. [{value}] doesn't exist in the code set {rule.CodeSet}.");
133144
}
134145
}
135146
else
136147
{
137-
messages.Add($"{rowNumPrefix}Invalid value. [{value}] doesn't exist in the code set {rule.CodeSet}.");
148+
var exists = CommonCodes.Any(x => x.CodeSet == rule.CodeSet && x.CodeName == value);
149+
150+
if (!exists)
151+
{
152+
messages.Add($"{rowNumPrefix}Invalid value. [{value}] doesn't exist in the code set {rule.CodeSet}.");
153+
}
138154
}
139155
}
140156

0 commit comments

Comments
 (0)