Repository navigation
Feature/582 Update reference data upload to support multiple provenances #660
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
4ff5ee4
Update reference data upload to support multiple provenances
KianKwa bd76d70
Add e2e test
KianKwa 0aa9d1f
Update provenance labels
KianKwa 483c321
Fix failing e2e tests
KianKwa d016f3f
Fix failing e2e tests
KianKwa 969dd2c
Merge branch 'master' into feature/582-reference-data-upload
KianKwa 1d21571
Merge remote-tracking branch 'origin/master' into feature/582-referen…
KianKwa 4e7fe64
Fix build issue
KianKwa 923e752
Fix unit test failure
KianKwa File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
19 changes: 19 additions & 0 deletions
19
apps/postgres/prisma/migrations/20260520113517_add_location_reference/migration.sql
This file contains hidden or 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,19 @@ | ||
| -- AlterTable | ||
| ALTER TABLE "list_types" ADD COLUMN "location_type" VARCHAR(50); | ||
|
|
||
| -- CreateTable | ||
| CREATE TABLE "location_reference" ( | ||
| "location_reference_id" TEXT NOT NULL, | ||
| "location_id" INTEGER NOT NULL, | ||
| "provenance" VARCHAR(50) NOT NULL, | ||
| "provenance_location_id" VARCHAR(255) NOT NULL, | ||
| "provenance_location_type" VARCHAR(50) NOT NULL, | ||
|
|
||
| CONSTRAINT "location_reference_pkey" PRIMARY KEY ("location_reference_id") | ||
| ); | ||
|
|
||
| -- CreateIndex | ||
| CREATE UNIQUE INDEX "location_reference_provenance_provenance_location_id_key" ON "location_reference"("provenance", "provenance_location_id"); | ||
|
|
||
| -- AddForeignKey | ||
| ALTER TABLE "location_reference" ADD CONSTRAINT "location_reference_location_id_fkey" FOREIGN KEY ("location_id") REFERENCES "location"("location_id") ON DELETE CASCADE ON UPDATE CASCADE; |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or 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,61 @@ | ||
| # Implementation Tasks | ||
|
|
||
| ## Database Schema | ||
|
|
||
| - [x] Add `LocationReference` model to `libs/location/prisma/schema.prisma` with fields: `location_reference_id`, `location_id`, `provenance`, `provenance_location_id`, `provenance_location_type`; add `@@unique([provenance, provenanceLocationId])` constraint and `onDelete: Cascade` back-relation on `Location` | ||
| - [x] Add `locationType` field (nullable `String`) to `ListType` model in `libs/location/prisma/schema.prisma` | ||
| - [x] Create migration for `location_reference` table (`yarn db:migrate:dev`) | ||
| - [x] Create migration for `location_type` column on `list_types` table (`yarn db:migrate:dev`) | ||
| - [x] Run `yarn db:generate` to regenerate the Prisma client | ||
|
|
||
| ## Location Reference Queries | ||
|
|
||
| - [x] Create `libs/location/src/location-reference/model.ts` with `LOCATION_REFERENCE_PROVENANCES` and `LOCATION_REFERENCE_TYPES` string literal union constants | ||
| - [x] Create `libs/location/src/location-reference/queries.ts` with `getLocationByProvenanceLocationId(provenance, provenanceLocationId, locationType?)` that queries `location_reference` joined to `location`, excluding soft-deleted locations | ||
| - [x] Export `getLocationByProvenanceLocationId` from `libs/location/src/index.ts` | ||
|
|
||
| ## CSV Upload - Model & Parser | ||
|
|
||
| - [x] Add `PROVENANCE`, `PROVENANCE_LOCATION_ID`, `PROVENANCE_LOCATION_TYPE` fields to `CsvRow` interface in `libs/system-admin-pages/src/reference-data-upload/model.ts` | ||
| - [x] Add `provenance`, `provenanceLocationId`, `provenanceLocationType` fields to `ParsedLocationData` interface in the same file | ||
| - [x] Add the three new column names to `REQUIRED_HEADERS` in `libs/system-admin-pages/src/reference-data-upload/parsers/csv-parser.ts` | ||
| - [x] Parse and map the three new fields in the row-level loop in `csv-parser.ts` | ||
| - [x] Update `csv-parser.test.ts` to cover new fields present and new fields missing | ||
|
|
||
| ## CSV Upload - Validation | ||
|
|
||
| - [x] Fix in-file location name duplicate check in `libs/system-admin-pages/src/reference-data-upload/validation/validation.ts` to key on `(locationName, locationId)` so identical names for the same ID are allowed | ||
| - [x] Fix in-file Welsh location name duplicate check with the same `(welshLocationName, locationId)` keying | ||
| - [x] Add validation that `provenance` is non-empty and is one of the allowed values from `LOCATION_REFERENCE_PROVENANCES` | ||
| - [x] Add validation that `provenanceLocationId` is non-empty | ||
| - [x] Add validation that `provenanceLocationType` is non-empty and is one of the allowed values from `LOCATION_REFERENCE_TYPES` | ||
| - [x] Add validation that `(provenance, provenanceLocationId)` is unique within the uploaded CSV | ||
| - [x] Update `validation.test.ts` to cover all new rules and the relaxed name-uniqueness rule | ||
|
|
||
| ## CSV Upload - Repository | ||
|
|
||
| - [x] Update `upsertLocations` in `libs/system-admin-pages/src/reference-data-upload/repository/upload-repository.ts` to upsert a `location_reference` row for each CSV row using the `(provenance, provenanceLocationId)` unique key | ||
| - [x] Update `upload-repository.test.ts` to assert `locationReference` upsert is called with correct data | ||
|
|
||
| ## Provenance Enum Update | ||
|
|
||
| - [x] Add `CP_CATH = "CP_CATH"` and `PDDA = "PDDA"` to the `Provenance` enum in `libs/publication/src/provenance.ts` | ||
| - [x] Add corresponding entries to `PROVENANCE_LABELS` in the same file | ||
|
|
||
| ## Blob Ingestion - Model & Validation | ||
|
|
||
| - [x] Add `resolvedLocationId?: string` to `BlobValidationResult` interface in `libs/api/src/blob-ingestion/repository/model.ts` | ||
| - [x] Add `CP_CATH` and `PDDA` to `ALLOWED_PROVENANCES` in `libs/api/src/blob-ingestion/validation.ts` | ||
| - [x] Define `EXTERNAL_PROVENANCES` constant (`SNL`, `COMMON_PLATFORM`, `CP_CATH`, `PDDA`) in `validation.ts` | ||
| - [x] Update location validation in `validateBlobRequest` to branch on external vs internal provenance: external provenances call `getLocationByProvenanceLocationId(provenance, court_id, listTypeLocationType)`, internal provenances call `getLocationById(parseInt(court_id))` | ||
| - [x] Populate `resolvedLocationId` in the returned `BlobValidationResult` with the looked-up internal location ID | ||
| - [x] Update `validation.test.ts` to cover external provenance resolution and the new allowed provenance values | ||
|
|
||
| ## Blob Ingestion - Service | ||
|
|
||
| - [x] Update `processBlobIngestion` in `libs/api/src/blob-ingestion/repository/service.ts` to use `validation.resolvedLocationId ?? request.court_id` as the `locationId` argument for `createArtefact` and `processPublication` | ||
| - [x] Update `service.test.ts` to assert the resolved location ID is used when provenance is external | ||
|
|
||
| ## Tests | ||
|
|
||
| - [x] Verify all unit tests pass: `yarn test` |
This file contains hidden or 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,51 @@ | ||
| # Issue #582: System admin reference data upload - Backend logic update | ||
|
|
||
| ## Title | ||
| System admin reference data upload - Backend logic update | ||
|
|
||
| ## Body | ||
|
|
||
| *Frontend update is not covered in this ticket.* | ||
|
|
||
| Currently the reference data upload does not have the concept of provenance. To support multiple provenances for a location: | ||
|
|
||
| - The following fields need to be added to the input CSV file format, the relevant model classes and the database: | ||
| - PROVENANCE | ||
| - PROVENANCE LOCATION ID | ||
| - PROVENANCE LOCATION TYPE | ||
| - The above fields should be mandatory and non-empty. | ||
| - A new `location_reference` table with the following fields added to store the location provenance: | ||
| - location_reference_id | ||
| - location_id | ||
| - provenance | ||
| - provenance_location_id | ||
| - provenance_location_type | ||
| - The possible values for provenance should be one of the enum values below: | ||
| - SNL | ||
| - COMMON_PLATFORM | ||
| - CP_CATH | ||
| - PDDA | ||
| - The possible values for provenance_location_type should be one of the enum values below: | ||
| - VENUE | ||
| - REGION | ||
| - OWNING_HEARING_LOCATION | ||
| - NATIONAL | ||
|
|
||
| ### Reference data upload validation update: | ||
| - When the CSV file has multiple records with same location name or welsh location name but different location IDs, we should show the error on frontend. | ||
| - When the CSV file has records with the same location name or Welsh location name but different location IDs as existing records on the database, we should also error on frontend. | ||
| - Location name and Welsh location name on the location table should have unique constraint. | ||
| - The CSV files are allowed to have same location name or Welsh location name for records with the same location ID but different provenances. | ||
|
|
||
| ### Changes required in publication upload processing to support the use of provenance location ID: | ||
| - Frontend manual upload should always use internal location ID to represent the court or tribunal the publication is uploaded to. | ||
| - Publication upload using the API currently only uses internal location ID for the `court_id` header. With the addition of provenance in reference data upload, external systems (SNL, COMMON_PLATFORM, CP_CATH, PDDA) should use their owned provenance location ID in the header when uploading publication. | ||
| - A new field called `location_type` needs to be added to the `list_type` table with one of the possible values below: | ||
| - VENUE | ||
| - REGION | ||
| - OWNING_HEARING_LOCATION | ||
| - NATIONAL | ||
| - When a publication is uploaded by external systems using the API, we should query the `location` table by the provenance location ID, provenance and the list type provenance location type to convert the provenance location ID to internal location ID before storing the publication in the database. | ||
|
|
||
| ## Assignees | ||
| - KianKwa | ||
This file contains hidden or 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,11 +1,11 @@ | ||
| LOCATION_ID,LOCATION_NAME,WELSH_LOCATION_NAME,EMAIL,CONTACT_NO,SUB_JURISDICTION_NAME,REGION_NAME | ||
| 9001,Test Court Alpha,Llys Prawf Alffa,test.alpha@test.hmcts.net,01234567890,Civil Court;Crown Court,South East | ||
| 9002,Test Court Beta,Llys Prawf Beta,test.beta@test.hmcts.net,01234567891,Civil Court;Family Court,Midlands | ||
| 9003,Test Court Gamma,Llys Prawf Gama,test.gamma@test.hmcts.net,01234567892,Civil Court,North | ||
| 9004,Test Court Delta,Llys Prawf Delta,test.delta@test.hmcts.net,01234567893,Civil Court;Crown Court;Court of Appeal,London | ||
| 9005,Test Court Epsilon,Llys Prawf Epsilon,test.epsilon@test.hmcts.net,01234567894,Civil Court;Family Court,Wales | ||
| 9006,Test Court Zeta,Llys Prawf Zeta,test.zeta@test.hmcts.net,01234567895,Civil Court;Crown Court,North | ||
| 9007,Test Court Eta,Llys Prawf Eta,test.eta@test.hmcts.net,01234567896,Civil Court;Family Court,South East | ||
| 9008,Test Court Theta,Llys Prawf Theta,test.theta@test.hmcts.net,01234567897,Civil Court;Family Court,North | ||
| 9,Test SJP Court,Llys Prawf SJP,sjp@test.hmcts.net,01234567898,Magistrates Court,London;Midlands;South East;North;Wales | ||
| 9010,Test Court Iota,Llys Prawf Iota,test.iota@test.hmcts.net,01234567899,Civil Court;Crown Court,North | ||
| LOCATION_ID,LOCATION_NAME,WELSH_LOCATION_NAME,EMAIL,CONTACT_NO,SUB_JURISDICTION_NAME,REGION_NAME,PROVENANCE,PROVENANCE_LOCATION_ID,PROVENANCE_LOCATION_TYPE | ||
| 9001,Test Court Alpha,Llys Prawf Alffa,test.alpha@test.hmcts.net,01234567890,Civil Court;Crown Court,South East,SNL,9001,VENUE | ||
| 9002,Test Court Beta,Llys Prawf Beta,test.beta@test.hmcts.net,01234567891,Civil Court;Family Court,Midlands,SNL,9002,VENUE | ||
| 9003,Test Court Gamma,Llys Prawf Gama,test.gamma@test.hmcts.net,01234567892,Civil Court,North,SNL,9003,VENUE | ||
| 9004,Test Court Delta,Llys Prawf Delta,test.delta@test.hmcts.net,01234567893,Civil Court;Crown Court;Court of Appeal,London,SNL,9004,VENUE | ||
| 9005,Test Court Epsilon,Llys Prawf Epsilon,test.epsilon@test.hmcts.net,01234567894,Civil Court;Family Court,Wales,SNL,9005,VENUE | ||
| 9006,Test Court Zeta,Llys Prawf Zeta,test.zeta@test.hmcts.net,01234567895,Civil Court;Crown Court,North,SNL,9006,VENUE | ||
| 9007,Test Court Eta,Llys Prawf Eta,test.eta@test.hmcts.net,01234567896,Civil Court;Family Court,South East,SNL,9007,VENUE | ||
| 9008,Test Court Theta,Llys Prawf Theta,test.theta@test.hmcts.net,01234567897,Civil Court;Family Court,North,SNL,9008,VENUE | ||
| 9,Test SJP Court,Llys Prawf SJP,sjp@test.hmcts.net,01234567898,Magistrates Court,London;Midlands;South East;North;Wales,SNL,9,VENUE | ||
| 9010,Test Court Iota,Llys Prawf Iota,test.iota@test.hmcts.net,01234567899,Civil Court;Crown Court,North,SNL,9010,VENUE |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use the exact CSV header names consistently across ticket docs.
Lines 13–15 use spaced names (
PROVENANCE LOCATION ID,PROVENANCE LOCATION TYPE), while the plan/tasks and parser changes use underscore headers (PROVENANCE_LOCATION_ID,PROVENANCE_LOCATION_TYPE). Please standardise these to avoid ambiguity in implementation and test data.🧰 Tools
🪛 LanguageTool
[duplication] ~13-~13: Possible typo: you repeated a word.
Context: ...ant model classes and the database: - PROVENANCE - PROVENANCE LOCATION ID - PROVENANCE LOCATION TYP...
(ENGLISH_WORD_REPEAT_RULE)