-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Import Licence versions We need to replace the import service logic to import a licence from NALD. We will leave the import service running to add the NALD data in the import tables, but we will slowly replace the import-licence functionality and move this into the system repo. https://eaflood.atlassian.net/browse/WATER-4575 This change will add the licence versions to the import logic. The licence versions rely on the created / existing licence id. This work needs to be done first to allow us to remove the licence and licence versions from the old import logic. https://eaflood.atlassian.net/browse/WATER-4575 In this instance, we felt it was more constructive to provide the feedback for the original [Import Licence versions](#1195) proposed PR as a series of commits from where the code has been left. This can be used to guide suggested changes, hopefully with better context than just PR comments. --- As I went through making these changes, I realised I was aiming for three outcomes; - simplify the work of the mappers by moving casting and some data generation into the fetch service queries - separate as much as possible the process for importing each entity (licence, licence version etc) - persist as one using a DB transaction to avoid risk of partial licences The commits themselves go into more details but very happy and glad to walk through the changes I'm suggesting. --------- Co-authored-by: Robert Parkinson <robertparkinson@users.noreply.github.com> Co-authored-by: Alan Cruikshanks <alan.cruikshanks@gmail.com>
- Loading branch information
1 parent
23271ac
commit f9b36c3
Showing
48 changed files
with
3,089 additions
and
1,110 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,27 @@ | ||
'use strict' | ||
|
||
const FeatureFlags = require('../../config/feature-flags.config.js') | ||
const ImportLegacyProcessLicenceService = require('../services/import/legacy/process-licence.service.js') | ||
|
||
/** | ||
* Controller for /import | ||
* @param request - the hapi request object | ||
* @param h - the hapi response object | ||
* | ||
* @returns {object} | ||
* | ||
* @module ImportController | ||
*/ | ||
async function licenceLegacy (request, h) { | ||
const { licenceRef } = request.payload | ||
|
||
const Boom = require('@hapi/boom') | ||
|
||
const FeatureFlags = require('../../config/feature-flags.config.js') | ||
const LegacyImportLicenceService = require('../services/import/legacy-licence.service.js') | ||
|
||
async function licence (request, h) { | ||
try { | ||
const { licenceRef } = request.payload | ||
|
||
if (FeatureFlags.enableSystemImportLegacyLicence) { | ||
await LegacyImportLicenceService.go(licenceRef) | ||
} | ||
|
||
return h.response().code(204) | ||
} catch (error) { | ||
return Boom.badImplementation(error.message) | ||
if (FeatureFlags.enableSystemImportLegacyLicence) { | ||
ImportLegacyProcessLicenceService.go(licenceRef) | ||
} | ||
|
||
return h.response().code(204) | ||
} | ||
|
||
module.exports = { | ||
licence | ||
licenceLegacy | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
app/presenters/import/legacy/licence-version-purpose.presenter.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
'use strict' | ||
|
||
/** | ||
* Maps the legacy NALD licence version purpose data to the WRLS format | ||
* @module LicenceVersionPurposePresenter | ||
*/ | ||
|
||
/** | ||
* Maps the legacy NALD licence version purpose data to the WRLS format | ||
* | ||
* @param {ImportLegacyLicenceVersionPurposeType} licenceVersionPurpose - the legacy NALD licence version purpose | ||
* | ||
* @returns {object} the NALD licence version purpose data transformed into the WRLS format ready for validation and | ||
* persisting | ||
*/ | ||
function go (licenceVersionPurpose) { | ||
return { | ||
abstractionPeriodEndDay: licenceVersionPurpose.abstraction_period_end_day, | ||
abstractionPeriodEndMonth: licenceVersionPurpose.abstraction_period_end_month, | ||
abstractionPeriodStartDay: licenceVersionPurpose.abstraction_period_start_day, | ||
abstractionPeriodStartMonth: licenceVersionPurpose.abstraction_period_start_month, | ||
annualQuantity: licenceVersionPurpose.annual_quantity, | ||
dailyQuantity: licenceVersionPurpose.daily_quantity, | ||
externalId: licenceVersionPurpose.external_id, | ||
hourlyQuantity: licenceVersionPurpose.hourly_quantity, | ||
instantQuantity: licenceVersionPurpose.instant_quantity, | ||
notes: licenceVersionPurpose.notes, | ||
primaryPurposeId: licenceVersionPurpose.primary_purpose_id, | ||
purposeId: licenceVersionPurpose.purpose_id, | ||
secondaryPurposeId: licenceVersionPurpose.secondary_purpose_id, | ||
timeLimitedEndDate: licenceVersionPurpose.time_limited_end_date, | ||
timeLimitedStartDate: licenceVersionPurpose.time_limited_start_date | ||
} | ||
} | ||
|
||
module.exports = { | ||
go | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
'use strict' | ||
|
||
/** | ||
* Maps legacy NALD licence version data to the WRLS format | ||
* @module LicenceVersionPresenter | ||
*/ | ||
|
||
const NALD_STATUSES = { | ||
CURR: 'current', | ||
SUPER: 'superseded' | ||
} | ||
|
||
/** | ||
* Maps legacy NALD licence version data to the WRLS format | ||
* | ||
* @param {ImportLegacyLicenceVersionTyp} licenceVersion - the legacy NALD licence version | ||
* | ||
* @returns {object} the NALD licence version data transformed into the WRLS format ready for validation and persisting | ||
*/ | ||
function go (licenceVersion) { | ||
return { | ||
endDate: licenceVersion.effective_end_date, | ||
externalId: licenceVersion.external_id, | ||
increment: licenceVersion.increment_number, | ||
issue: licenceVersion.issue_no, | ||
// Add an empty array property ready for when transforming and attaching licence version purposes | ||
licenceVersionPurposes: [], | ||
startDate: licenceVersion.effective_start_date, | ||
status: NALD_STATUSES[licenceVersion.status] | ||
} | ||
} | ||
|
||
module.exports = { | ||
go | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
'use strict' | ||
|
||
/** | ||
* Maps the legacy NALD licence data to the WRLS format | ||
* @module LicencePresenter | ||
*/ | ||
|
||
const { naldRegions } = require('../../../lib/static-lookups.lib.js') | ||
|
||
/** | ||
* Maps the legacy NALD licence data to the WRLS format | ||
* | ||
* @param {ImportLegacyLicenceType} licence - the legacy NALD licence | ||
* | ||
* @returns {object} the NALD licence data transformed into the WRLS format ready for validation and persisting | ||
*/ | ||
function go (licence) { | ||
return { | ||
expiredDate: licence.expiry_date, | ||
lapsedDate: licence.lapsed_date, | ||
licenceRef: licence.licence_ref, | ||
// Add an empty array property ready for when transforming and attaching licence versions | ||
licenceVersions: [], | ||
regionId: licence.region_id, | ||
regions: _regions(licence), | ||
revokedDate: licence.revoked_date, | ||
startDate: _startDate(licence), | ||
waterUndertaker: licence.environmental_improvement_unit_charge_code.endsWith('SWC') | ||
} | ||
} | ||
|
||
/** | ||
* Creates a JSON object of the region data. This is stored as a JSON object in the licence.regions column. | ||
* | ||
* @private | ||
*/ | ||
const _regions = (licence) => { | ||
const historicalAreaCode = licence.historical_area_code | ||
const regionPrefix = licence.environmental_improvement_unit_charge_code.substr(0, 2) | ||
const regionalChargeArea = naldRegions[regionPrefix] | ||
const standardUnitChargeCode = licence.standard_unit_charge_code | ||
const localEnvironmentAgencyPlanCode = licence.local_environment_agency_plan_code | ||
|
||
return { historicalAreaCode, regionalChargeArea, standardUnitChargeCode, localEnvironmentAgencyPlanCode } | ||
} | ||
|
||
function _startDate (licence) { | ||
if (licence.original_effective_date) { | ||
return licence.original_effective_date | ||
} | ||
|
||
return licence.earliest_version_start_date | ||
} | ||
|
||
module.exports = { | ||
go | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
58 changes: 0 additions & 58 deletions
58
app/services/import/legacy-import/fetch-licence-versions.service.js
This file was deleted.
Oops, something went wrong.
76 changes: 0 additions & 76 deletions
76
app/services/import/legacy-import/fetch-licence.service.js
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.