diff --git a/angular/projects/admin-nrpti/src/app/agencies/agencies.component.ts b/angular/projects/admin-nrpti/src/app/agencies/agencies.component.ts
index e37c3a823..cedcab9ac 100644
--- a/angular/projects/admin-nrpti/src/app/agencies/agencies.component.ts
+++ b/angular/projects/admin-nrpti/src/app/agencies/agencies.component.ts
@@ -41,13 +41,13 @@ export class AgenciesComponent implements OnInit {
this.factoryService.applicationAgencyService.refreshAgencies().subscribe();
}
updateSelectedAgency(): void {
+ const index = this.agencyList.indexOf(this.selectedAgency);
try {
- if (this.newAgency.trim() !== '') {
+ if (this.newAgency.trim() !== '' && index !== -1) {
// Find the agency code that matches the selected agency name
const matchingCode = Object.keys(this.agencies).find(key => this.agencies[key] === this.selectedAgency);
if (matchingCode) {
// Update the agencyList with the new value at the same index
- const index = this.agencyList.indexOf(this.selectedAgency);
if (index !== -1) {
this.agencyList[index] = this.newAgency;
}
@@ -65,9 +65,12 @@ export class AgenciesComponent implements OnInit {
this.updatedData.agencies = [];
}
this.toastService.addMessage('Agency Successfully Updated', 'Success Updated', Constants.ToastTypes.SUCCESS);
+ setTimeout(() => {
+ location.reload();
+ }, 1500);
} else {
this.toastService.addMessage(
- 'Updated Agency Name Cannot be Empty',
+ 'Updating/Updated Agency Name Cannot be Empty',
'Save unsuccessful',
Constants.ToastTypes.ERROR
);
diff --git a/angular/projects/admin-nrpti/src/app/mines/mines-collections-add-edit/mines-collections-add-edit.component.html b/angular/projects/admin-nrpti/src/app/mines/mines-collections-add-edit/mines-collections-add-edit.component.html
index 65159265b..257625151 100644
--- a/angular/projects/admin-nrpti/src/app/mines/mines-collections-add-edit/mines-collections-add-edit.component.html
+++ b/angular/projects/admin-nrpti/src/app/mines/mines-collections-add-edit/mines-collections-add-edit.component.html
@@ -74,7 +74,7 @@
{{ (isEditing && 'Edit') || (!isEditing && 'Add') }} C
@@ -243,4 +243,4 @@ Associated Records
-
\ No newline at end of file
+
diff --git a/angular/projects/admin-nrpti/src/app/mines/mines-collections-add-edit/mines-collections-add-edit.component.ts b/angular/projects/admin-nrpti/src/app/mines/mines-collections-add-edit/mines-collections-add-edit.component.ts
index 9eb45e874..7fc3066ca 100644
--- a/angular/projects/admin-nrpti/src/app/mines/mines-collections-add-edit/mines-collections-add-edit.component.ts
+++ b/angular/projects/admin-nrpti/src/app/mines/mines-collections-add-edit/mines-collections-add-edit.component.ts
@@ -14,6 +14,7 @@ import { ConfirmComponent } from '../../confirm/confirm.component';
import { FactoryService } from '../../services/factory.service';
import { RecordUtils } from '../../records/utils/record-utils';
import { Constants } from '../../utils/constants/misc';
+import { AgencyDataService } from '../../../../../../projects/global/src/lib/utils/agency-data-service';
@Component({
selector: 'app-mines-collections-add-edit',
@@ -39,7 +40,7 @@ export class MinesCollectionsAddEditComponent implements OnInit, OnDestroy {
// Pick lists
public collectionTypes = Picklists.collectionTypePicklist;
- public collectionAgencies = Picklists.collectionAgencyPicklist;
+ public collectionAgencies = Picklists.collectionAgencyCodePicklist;
// collection add edit state
public collectionState = null;
@@ -541,6 +542,11 @@ export class MinesCollectionsAddEditComponent implements OnInit, OnDestroy {
return Utils.convertAcronyms(acronym);
}
+ displayName(agency) {
+ const agencyDataService = new AgencyDataService(this.factoryService);
+ return agencyDataService.displayNameFull(agency);
+ }
+
ngOnDestroy(): void {
// When the component is destroying, if collectionAddEdit state exists, but the user hadn't clicked the
// 'addRecordsToCollection' button, then remove the collection state from the store.
diff --git a/angular/projects/admin-nrpti/src/app/mines/mines-enforcement-actions/mines-administrative-penalty-add-edit/mines-administrative-penalty-add-edit.component.html b/angular/projects/admin-nrpti/src/app/mines/mines-enforcement-actions/mines-administrative-penalty-add-edit/mines-administrative-penalty-add-edit.component.html
index 61bfb06de..7a28b95ec 100644
--- a/angular/projects/admin-nrpti/src/app/mines/mines-enforcement-actions/mines-administrative-penalty-add-edit/mines-administrative-penalty-add-edit.component.html
+++ b/angular/projects/admin-nrpti/src/app/mines/mines-enforcement-actions/mines-administrative-penalty-add-edit/mines-administrative-penalty-add-edit.component.html
@@ -60,7 +60,7 @@ Basic Information
name="issuingAgency"
id="issuingAgency"
type="text"
- value="{{ this.convertAcronyms(defaultAgency) }}"
+ value="{{ this.displayName(defaultAgency) }}"
class="form-control" />
diff --git a/angular/projects/admin-nrpti/src/app/mines/mines-enforcement-actions/mines-administrative-penalty-add-edit/mines-administrative-penalty-add-edit.component.ts b/angular/projects/admin-nrpti/src/app/mines/mines-enforcement-actions/mines-administrative-penalty-add-edit/mines-administrative-penalty-add-edit.component.ts
index 91ace92cd..6f9887507 100644
--- a/angular/projects/admin-nrpti/src/app/mines/mines-enforcement-actions/mines-administrative-penalty-add-edit/mines-administrative-penalty-add-edit.component.ts
+++ b/angular/projects/admin-nrpti/src/app/mines/mines-enforcement-actions/mines-administrative-penalty-add-edit/mines-administrative-penalty-add-edit.component.ts
@@ -7,6 +7,7 @@ import { LoadingScreenService, LoggerService } from 'nrpti-angular-components';
import { Utils, StoreService } from 'nrpti-angular-components';
import { ChangeDetectorRef } from '@angular/core';
import { takeUntil } from 'rxjs/operators';
+import { AgencyDataService } from '../../../../../../global/src/lib/utils/agency-data-service';
@Component({
selector: 'app-mines-administrative-penalty-add-edit',
@@ -16,7 +17,7 @@ import { takeUntil } from 'rxjs/operators';
export class MinesAdministrativePenaltyAddEditComponent extends AdministrativePenaltyAddEditComponent
implements OnInit {
public componentTitle = 'BCMI Administrative Penalty Record';
- public defaultAgency = 'Ministry of Energy Mines and Low Carbon Innovation';
+ public defaultAgency = 'AGENCY_EMLI';
public defaultAuthor = 'BC Government';
public currentRecord = null;
@@ -103,7 +104,8 @@ export class MinesAdministrativePenaltyAddEditComponent extends AdministrativePe
}
displayName(agency) {
- return Utils.displayNameFull(agency);
+ const agencyDataService = new AgencyDataService(this.factoryService);
+ return agencyDataService.displayNameFull(agency);
}
cancel() {
diff --git a/angular/projects/admin-nrpti/src/app/mines/mines-enforcement-actions/mines-administrative-penalty-detail/mines-administrative-penalty-detail.component.ts b/angular/projects/admin-nrpti/src/app/mines/mines-enforcement-actions/mines-administrative-penalty-detail/mines-administrative-penalty-detail.component.ts
index deca7f917..93806e8a8 100644
--- a/angular/projects/admin-nrpti/src/app/mines/mines-enforcement-actions/mines-administrative-penalty-detail/mines-administrative-penalty-detail.component.ts
+++ b/angular/projects/admin-nrpti/src/app/mines/mines-enforcement-actions/mines-administrative-penalty-detail/mines-administrative-penalty-detail.component.ts
@@ -5,7 +5,8 @@ import { takeUntil } from 'rxjs/operators';
import { AdministrativePenaltyDetailComponent } from '../../../records/administrative-penalties/administrative-penalty-detail/administrative-penalty-detail.component';
import { RecordUtils } from '../../../records/utils/record-utils';
import { FactoryService } from '../../../services/factory.service';
-import { StoreService, Utils } from 'nrpti-angular-components';
+import { StoreService } from 'nrpti-angular-components';
+import { AgencyDataService } from '../../../../../../global/src/lib/utils/agency-data-service';
@Component({
selector: 'app-mines-administrative-penalty-detail',
@@ -65,7 +66,8 @@ export class MinesAdministrativePenaltyDetailComponent extends AdministrativePen
}
displayName(agency) {
- return Utils.displayNameFull(agency);
+ const agencyDataService = new AgencyDataService(this.factoryService);
+ return agencyDataService.displayNameFull(agency);
}
navigateToEditPage() {
diff --git a/angular/projects/admin-nrpti/src/app/mines/mines-enforcement-actions/mines-court-convictions/mines-court-convictions-add-edit/mines-court-convictions-add-edit.component.html b/angular/projects/admin-nrpti/src/app/mines/mines-enforcement-actions/mines-court-convictions/mines-court-convictions-add-edit/mines-court-convictions-add-edit.component.html
index 118d99514..e0f9f792e 100644
--- a/angular/projects/admin-nrpti/src/app/mines/mines-enforcement-actions/mines-court-convictions/mines-court-convictions-add-edit/mines-court-convictions-add-edit.component.html
+++ b/angular/projects/admin-nrpti/src/app/mines/mines-enforcement-actions/mines-court-convictions/mines-court-convictions-add-edit/mines-court-convictions-add-edit.component.html
@@ -60,7 +60,7 @@
Basic Information
name="recordType"
id="recordType"
type="text"
- [value]="this.convertAcronyms(this.myForm.get('issuingAgency').value)"
+ [value]="this.displayName(this.myForm.get('issuingAgency').value)"
class="form-control"
/>
diff --git a/angular/projects/admin-nrpti/src/app/mines/mines-enforcement-actions/mines-court-convictions/mines-court-convictions-add-edit/mines-court-convictions-add-edit.component.ts b/angular/projects/admin-nrpti/src/app/mines/mines-enforcement-actions/mines-court-convictions/mines-court-convictions-add-edit/mines-court-convictions-add-edit.component.ts
index 4c9740f28..bafe4f491 100644
--- a/angular/projects/admin-nrpti/src/app/mines/mines-enforcement-actions/mines-court-convictions/mines-court-convictions-add-edit/mines-court-convictions-add-edit.component.ts
+++ b/angular/projects/admin-nrpti/src/app/mines/mines-enforcement-actions/mines-court-convictions/mines-court-convictions-add-edit/mines-court-convictions-add-edit.component.ts
@@ -7,6 +7,7 @@ import { LoadingScreenService, LoggerService } from 'nrpti-angular-components';
import { Utils, StoreService } from 'nrpti-angular-components';
import { ChangeDetectorRef } from '@angular/core';
import { takeUntil } from 'rxjs/operators';
+import { AgencyDataService } from '../../../../../../../global/src/lib/utils/agency-data-service';
@Component({
selector: 'app-mines-court-convictions-add-edit',
@@ -17,7 +18,7 @@ import { takeUntil } from 'rxjs/operators';
})
export class MinesCourtConvictionsAddEditComponent extends CourtConvictionAddEditComponent implements OnInit {
public componentTitle = 'BCMI Administrative Penalty Record';
- public defaultAgency = 'Ministry of Energy Mines and Low Carbon Innovation';
+ public defaultAgency = 'AGENCY_EMLI';
public defaultAuthor = 'BC Government';
public currentRecord = null;
@@ -152,6 +153,11 @@ export class MinesCourtConvictionsAddEditComponent extends CourtConvictionAddEdi
}
}
+ displayName(agency) {
+ const agencyDataService = new AgencyDataService(this.factoryService);
+ return agencyDataService.displayNameFull(agency);
+ }
+
cancel() {
const shouldCancel = confirm(
'Leaving this page will discard unsaved changes. Are you sure you would like to continue?'
diff --git a/angular/projects/admin-nrpti/src/app/mines/mines-enforcement-actions/mines-court-convictions/mines-court-convictions-detail/mines-court-convictions-detail.component.ts b/angular/projects/admin-nrpti/src/app/mines/mines-enforcement-actions/mines-court-convictions/mines-court-convictions-detail/mines-court-convictions-detail.component.ts
index 6af8ec1a3..c2b2016ad 100644
--- a/angular/projects/admin-nrpti/src/app/mines/mines-enforcement-actions/mines-court-convictions/mines-court-convictions-detail/mines-court-convictions-detail.component.ts
+++ b/angular/projects/admin-nrpti/src/app/mines/mines-enforcement-actions/mines-court-convictions/mines-court-convictions-detail/mines-court-convictions-detail.component.ts
@@ -5,7 +5,8 @@ import { takeUntil } from 'rxjs/operators';
import { CourtConvictionDetailComponent } from '../../../../records/court-convictions/court-conviction-detail/court-conviction-detail.component';
import { RecordUtils } from '../../../../records/utils/record-utils';
import { FactoryService } from '../../../../services/factory.service';
-import { StoreService, Utils } from 'nrpti-angular-components';
+import { StoreService } from 'nrpti-angular-components';
+import { AgencyDataService } from '../../../../../../../global/src/lib/utils/agency-data-service';
@Component({
selector: 'app-mines-court-convictions-detail',
@@ -64,7 +65,8 @@ export class MinesCourtConvictionsDetailComponent extends CourtConvictionDetailC
}
displayName(agency) {
- return Utils.displayNameFull(agency);
+ const agencyDataService = new AgencyDataService(this.factoryService);
+ return agencyDataService.displayNameFull(agency);
}
navigateToEditPage() {
diff --git a/angular/projects/admin-nrpti/src/app/mines/mines-record-add/mines-record-add.component.ts b/angular/projects/admin-nrpti/src/app/mines/mines-record-add/mines-record-add.component.ts
index e45791627..296c46cb1 100644
--- a/angular/projects/admin-nrpti/src/app/mines/mines-record-add/mines-record-add.component.ts
+++ b/angular/projects/admin-nrpti/src/app/mines/mines-record-add/mines-record-add.component.ts
@@ -6,6 +6,7 @@ import { Picklists } from '../../../../../common/src/app/utils/record-constants'
import { FactoryService } from '../../services/factory.service';
import { RecordUtils } from '../../records/utils/record-utils';
import { Constants } from '../../utils/constants/misc';
+import { AgencyDataService } from '../../../../../../projects/global/src/lib/utils/agency-data-service';
@Component({
selector: 'app-mines-record-add',
@@ -38,7 +39,7 @@ export class MinesRecordAddComponent implements OnInit, OnDestroy {
);
// Pick lists
- public recordAgencies = Picklists.collectionAgencyPicklist;
+ public recordAgencies = Picklists.collectionAgencyCodePicklist;
public recordTypeNamesBCMI = Object.values(Picklists.bcmiRecordTypePicklist).map(item => {
return item.displayName;
}).sort();
@@ -176,7 +177,8 @@ export class MinesRecordAddComponent implements OnInit, OnDestroy {
}
displayName(agency) {
- return Utils.displayNameFull(agency);
+ const agencyDataService = new AgencyDataService(this.factoryService);
+ return agencyDataService.displayNameFull(agency);
}
ngOnDestroy(): void {
diff --git a/angular/projects/admin-nrpti/src/app/mines/mines-records-detail/mines-records-detail.component.ts b/angular/projects/admin-nrpti/src/app/mines/mines-records-detail/mines-records-detail.component.ts
index 37fc0509b..abfc929fc 100644
--- a/angular/projects/admin-nrpti/src/app/mines/mines-records-detail/mines-records-detail.component.ts
+++ b/angular/projects/admin-nrpti/src/app/mines/mines-records-detail/mines-records-detail.component.ts
@@ -4,8 +4,8 @@ import { Subject } from 'rxjs';
import { ActivatedRoute, Router } from '@angular/router';
import moment from 'moment';
import { CollectionBCMI } from '../../../../../common/src/app/models/bcmi';
-import { Utils } from 'nrpti-angular-components';
-
+import { AgencyDataService } from '../../../../../global/src/lib/utils/agency-data-service';
+import { FactoryService } from '../../services/factory.service';
@Component({
selector: 'app-mines-records-detail',
templateUrl: './mines-records-detail.component.html',
@@ -22,7 +22,8 @@ export class MinesRecordDetailComponent implements OnInit, OnDestroy {
constructor(
public route: ActivatedRoute,
public router: Router,
- public changeDetectionRef: ChangeDetectorRef
+ public changeDetectionRef: ChangeDetectorRef,
+ public factoryService: FactoryService
) { }
isDisableEdit() {
@@ -73,7 +74,8 @@ export class MinesRecordDetailComponent implements OnInit, OnDestroy {
}
displayName(agency) {
- return Utils.displayNameAcronym(agency);
+ const agencyDataService = new AgencyDataService(this.factoryService);
+ return agencyDataService.displayNameFull(agency);
}
ngOnDestroy() {
diff --git a/angular/projects/admin-nrpti/src/app/mines/mines-records-edit/mines-records-edit.component.ts b/angular/projects/admin-nrpti/src/app/mines/mines-records-edit/mines-records-edit.component.ts
index e3b761506..828864b5d 100644
--- a/angular/projects/admin-nrpti/src/app/mines/mines-records-edit/mines-records-edit.component.ts
+++ b/angular/projects/admin-nrpti/src/app/mines/mines-records-edit/mines-records-edit.component.ts
@@ -12,6 +12,7 @@ import { ConfirmComponent } from '../../confirm/confirm.component';
import { takeUntil, catchError } from 'rxjs/operators';
import { Constants } from '../../utils/constants/misc';
import { ToastService } from '../../services/toast.service';
+import { AgencyDataService } from '../../../../../../projects/global/src/lib/utils/agency-data-service';
@Component({
selector: 'app-mines-records-edit',
@@ -49,7 +50,7 @@ export class MinesRecordsEditComponent implements OnInit {
}).sort();
public permitTypes = ['OGP', 'AMD'];
- public recordAgencies = Picklists.collectionAgencyPicklist;
+ public recordAgencies = Picklists.collectionAgencyCodePicklist;;
// record add edit state
public recordState = null;
@@ -286,7 +287,8 @@ export class MinesRecordsEditComponent implements OnInit {
}
displayName(agency) {
- return Utils.displayNameFull(agency);
+ const agencyDataService = new AgencyDataService(this.factoryService);
+ return agencyDataService.displayNameFull(agency);
}
/**
diff --git a/angular/projects/admin-nrpti/src/app/mines/mines-records-list/mines-records-list.component.ts b/angular/projects/admin-nrpti/src/app/mines/mines-records-list/mines-records-list.component.ts
index 2b0e8dab5..fd36e0638 100644
--- a/angular/projects/admin-nrpti/src/app/mines/mines-records-list/mines-records-list.component.ts
+++ b/angular/projects/admin-nrpti/src/app/mines/mines-records-list/mines-records-list.component.ts
@@ -19,6 +19,8 @@ import { FilterObject, FilterType, DateFilterDefinition, CheckOrRadioFilterDefin
import { SubsetsObject, SubsetOption } from '../../../../../common/src/app/search-filter-template/subset-object';
import { Mine } from '../../../../../common/src/app/models/bcmi/mine';
import { MiscUtils } from '../../utils/constants/misc';
+import { FactoryService } from '../../services/factory.service';
+import { AgencyDataService } from '../../../../../global/src/lib/utils/agency-data-service';
/**
* Mine list page component.
@@ -121,7 +123,8 @@ export class MinesRecordsListComponent implements OnInit, OnDestroy {
public storeService: StoreService,
private loadingScreenService: LoadingScreenService,
private tableTemplateUtils: TableTemplateUtils,
- private _changeDetectionRef: ChangeDetectorRef
+ private _changeDetectionRef: ChangeDetectorRef,
+ private factoryService: FactoryService
) {
// setup the subset configuration
const subsetOptions = [
@@ -155,10 +158,16 @@ export class MinesRecordsListComponent implements OnInit, OnDestroy {
'agency',
FilterType.MultiSelect,
'Responsible Agency',
- new MultiSelectDefinition(Picklists.agencyPicklist.map(value => {
- const displayValue = Utils.displayNameFull(value);
- return { value: value, displayValue: displayValue, selected: false, display: true };
- }), 'Begin typing to filter agencies...', '')
+ new MultiSelectDefinition(
+ Picklists.getAgencyNames(this.factoryService).map(value => {
+ const agencyDataService = new AgencyDataService(this.factoryService);
+ const displayValue = agencyDataService.displayNameFull(value);
+ const picklistCodes = Picklists.getAgencyCode(this.factoryService, value)
+ return { value: picklistCodes, displayValue: displayValue, selected: false, display: true };
+ }),
+ 'Begin typing to filter agencies...',
+ ''
+ )
);
const sourceSystemFilter = new FilterObject(
diff --git a/angular/projects/admin-nrpti/src/app/mines/mines-records-rows/mines-records-table-row.component.ts b/angular/projects/admin-nrpti/src/app/mines/mines-records-rows/mines-records-table-row.component.ts
index 868291d08..21a66540b 100644
--- a/angular/projects/admin-nrpti/src/app/mines/mines-records-rows/mines-records-table-row.component.ts
+++ b/angular/projects/admin-nrpti/src/app/mines/mines-records-rows/mines-records-table-row.component.ts
@@ -3,7 +3,7 @@ import { FactoryService } from '../../services/factory.service';
import { TableRowComponent } from 'nrpti-angular-components';
import { Router, ActivatedRoute } from '@angular/router';
import { Entity } from '../../../../../common/src/app/models/master/common-models/entity';
-import { Utils } from 'nrpti-angular-components';
+import { AgencyDataService } from '../../../../../global/src/lib/utils/agency-data-service';
@Component({
selector: 'tr[app-mines-records-table-row]',
@@ -39,7 +39,8 @@ export class MinesRecordsTableRowComponent extends TableRowComponent implements
}
displayName(agency) {
- return Utils.displayNameAcronym(agency);
+ const agencyDataService = new AgencyDataService(this.factoryService);
+ return agencyDataService.displayNameFull(agency);
}
private isDisableEdit() {
diff --git a/angular/projects/admin-nrpti/src/app/records/administrative-sanctions/administrative-sanction-add-edit/administrative-sanction-add-edit.component.ts b/angular/projects/admin-nrpti/src/app/records/administrative-sanctions/administrative-sanction-add-edit/administrative-sanction-add-edit.component.ts
index f6b1b280e..a1b2c74e8 100644
--- a/angular/projects/admin-nrpti/src/app/records/administrative-sanctions/administrative-sanction-add-edit/administrative-sanction-add-edit.component.ts
+++ b/angular/projects/admin-nrpti/src/app/records/administrative-sanctions/administrative-sanction-add-edit/administrative-sanction-add-edit.component.ts
@@ -33,7 +33,7 @@ export class AdministrativeSanctionAddEditComponent implements OnInit, OnDestroy
public nrcedPublishSubtext = 'Not published';
// Pick lists
- public agencies = Picklists.agencyCodePicklist;
+ public agencies = Picklists.getAgencyCodes(this.factoryService);
public authors = Picklists.authorPicklist;
private defaultAgency = '';
diff --git a/angular/projects/admin-nrpti/src/app/records/annual-reports/annual-report-add-edit/annual-report-add-edit.component.ts b/angular/projects/admin-nrpti/src/app/records/annual-reports/annual-report-add-edit/annual-report-add-edit.component.ts
index 0bf7fd1b9..ca976451b 100644
--- a/angular/projects/admin-nrpti/src/app/records/annual-reports/annual-report-add-edit/annual-report-add-edit.component.ts
+++ b/angular/projects/admin-nrpti/src/app/records/annual-reports/annual-report-add-edit/annual-report-add-edit.component.ts
@@ -31,7 +31,7 @@ export class AnnualReportAddEditComponent implements OnInit, OnDestroy {
public bcmiPublishSubtext = 'Not published';
// Pick lists
- public agencies = Picklists.agencyCodePicklist;
+ public agencies = Picklists.getAgencyCodes(this.factoryService);
public datepickerMinDate = Constants.DatepickerMinDate;
public datepickerMaxDate = Constants.DatepickerMaxDate;
diff --git a/angular/projects/admin-nrpti/src/app/records/certificate-amendments/certificate-amendments-add-edit/certificate-amendments-add-edit.component.ts b/angular/projects/admin-nrpti/src/app/records/certificate-amendments/certificate-amendments-add-edit/certificate-amendments-add-edit.component.ts
index 7ca86b85f..6ab29d0a0 100644
--- a/angular/projects/admin-nrpti/src/app/records/certificate-amendments/certificate-amendments-add-edit/certificate-amendments-add-edit.component.ts
+++ b/angular/projects/admin-nrpti/src/app/records/certificate-amendments/certificate-amendments-add-edit/certificate-amendments-add-edit.component.ts
@@ -34,7 +34,7 @@ export class CertificateAmendmentAddEditComponent implements OnInit, OnDestroy {
// Pick lists
public certificateSubtypes = Picklists.certificateSubtypePicklist;
- public agencies = Picklists.agencyCodePicklist;
+ public agencies = Picklists.getAgencyCodes(this.factoryService);
public datepickerMinDate = Constants.DatepickerMinDate;
public datepickerMaxDate = Constants.DatepickerMaxDate;
diff --git a/angular/projects/admin-nrpti/src/app/records/certificates/certificate-add-edit/certificate-add-edit.component.ts b/angular/projects/admin-nrpti/src/app/records/certificates/certificate-add-edit/certificate-add-edit.component.ts
index 70ea1dc4d..2c29f39f0 100644
--- a/angular/projects/admin-nrpti/src/app/records/certificates/certificate-add-edit/certificate-add-edit.component.ts
+++ b/angular/projects/admin-nrpti/src/app/records/certificates/certificate-add-edit/certificate-add-edit.component.ts
@@ -32,7 +32,7 @@ export class CertificateAddEditComponent implements OnInit, OnDestroy {
// Pick lists
public certificateSubtypes = Picklists.certificateSubtypePicklist;
- public agencies = Picklists.agencyCodePicklist;
+ public agencies = Picklists.getAgencyCodes(this.factoryService);
public datepickerMinDate = Constants.DatepickerMinDate;
public datepickerMaxDate = Constants.DatepickerMaxDate;
diff --git a/angular/projects/admin-nrpti/src/app/records/construction-plans/construction-plan-add-edit/construction-plan-add-edit.component.ts b/angular/projects/admin-nrpti/src/app/records/construction-plans/construction-plan-add-edit/construction-plan-add-edit.component.ts
index 23b1814ef..332e998a1 100644
--- a/angular/projects/admin-nrpti/src/app/records/construction-plans/construction-plan-add-edit/construction-plan-add-edit.component.ts
+++ b/angular/projects/admin-nrpti/src/app/records/construction-plans/construction-plan-add-edit/construction-plan-add-edit.component.ts
@@ -31,7 +31,7 @@ export class ConstructionPlanAddEditComponent implements OnInit, OnDestroy {
public lngPublishSubtext = 'Not published';
// Pick lists
- public agencies = Picklists.agencyCodePicklist;
+ public agencies = Picklists.getAgencyCodes(this.factoryService);
// Documents
public documents = [];
diff --git a/angular/projects/admin-nrpti/src/app/records/correspondences/correspondence-add-edit/correspondence-add-edit.component.ts b/angular/projects/admin-nrpti/src/app/records/correspondences/correspondence-add-edit/correspondence-add-edit.component.ts
index 3de9d0edc..27397817e 100644
--- a/angular/projects/admin-nrpti/src/app/records/correspondences/correspondence-add-edit/correspondence-add-edit.component.ts
+++ b/angular/projects/admin-nrpti/src/app/records/correspondences/correspondence-add-edit/correspondence-add-edit.component.ts
@@ -33,7 +33,7 @@ export class CorrespondenceAddEditComponent implements OnInit, OnDestroy {
public bcmiPublishSubtext = 'Not published';
// Pick lists
- public agencies = Picklists.agencyCodePicklist;
+ public agencies = Picklists.getAgencyCodes(this.factoryService);
// Documents
public documents = [];
diff --git a/angular/projects/admin-nrpti/src/app/records/court-convictions/court-conviction-add-edit/court-conviction-add-edit.component.ts b/angular/projects/admin-nrpti/src/app/records/court-convictions/court-conviction-add-edit/court-conviction-add-edit.component.ts
index 72b417415..07dadaa66 100644
--- a/angular/projects/admin-nrpti/src/app/records/court-convictions/court-conviction-add-edit/court-conviction-add-edit.component.ts
+++ b/angular/projects/admin-nrpti/src/app/records/court-convictions/court-conviction-add-edit/court-conviction-add-edit.component.ts
@@ -34,7 +34,7 @@ export class CourtConvictionAddEditComponent implements OnInit, OnDestroy {
public bcmiPublishSubtext = 'Not published';
// Pick lists
- public agencies = Picklists.agencyCodePicklist;
+ public agencies = Picklists.getAgencyCodes(this.factoryService);
public authors = Picklists.authorPicklist;
public courtConvictionSubtypes = Picklists.courtConvictionSubtypePicklist;
protected defaultAgency = '';
diff --git a/angular/projects/admin-nrpti/src/app/records/dam-safety-inspections/dam-safety-inspection-add-edit/dam-safety-inspection-add-edit.component.ts b/angular/projects/admin-nrpti/src/app/records/dam-safety-inspections/dam-safety-inspection-add-edit/dam-safety-inspection-add-edit.component.ts
index 5ebee5cd2..afa95a927 100644
--- a/angular/projects/admin-nrpti/src/app/records/dam-safety-inspections/dam-safety-inspection-add-edit/dam-safety-inspection-add-edit.component.ts
+++ b/angular/projects/admin-nrpti/src/app/records/dam-safety-inspections/dam-safety-inspection-add-edit/dam-safety-inspection-add-edit.component.ts
@@ -33,7 +33,7 @@ export class DamSafetyInspectionAddEditComponent implements OnInit, OnDestroy {
public bcmiPublishSubtext = 'Not published';
// Pick lists
- public agencies = Picklists.agencyCodePicklist;
+ public agencies = Picklists.getAgencyCodes(this.factoryService);
// Documents
public documents = [];
diff --git a/angular/projects/admin-nrpti/src/app/records/inspections/inspection-add-edit/inspection-add-edit.component.ts b/angular/projects/admin-nrpti/src/app/records/inspections/inspection-add-edit/inspection-add-edit.component.ts
index 07a6cfd0f..f9d1d0329 100644
--- a/angular/projects/admin-nrpti/src/app/records/inspections/inspection-add-edit/inspection-add-edit.component.ts
+++ b/angular/projects/admin-nrpti/src/app/records/inspections/inspection-add-edit/inspection-add-edit.component.ts
@@ -33,7 +33,7 @@ export class InspectionAddEditComponent implements OnInit, OnDestroy {
public nrcedPublishSubtext = 'Not published';
// Pick lists
- public agencies = Picklists.agencyCodePicklist;
+ public agencies = Picklists.getAgencyCodes(this.factoryService);
public authors = Picklists.authorPicklist;
public outcomeStatuses = Picklists.outcomeStatusPicklist;
private defaultAgency = '';
diff --git a/angular/projects/admin-nrpti/src/app/records/management-plans/management-plan-add-edit/management-plan-add-edit.component.ts b/angular/projects/admin-nrpti/src/app/records/management-plans/management-plan-add-edit/management-plan-add-edit.component.ts
index 1ccb362fb..bfbca43d2 100644
--- a/angular/projects/admin-nrpti/src/app/records/management-plans/management-plan-add-edit/management-plan-add-edit.component.ts
+++ b/angular/projects/admin-nrpti/src/app/records/management-plans/management-plan-add-edit/management-plan-add-edit.component.ts
@@ -31,7 +31,7 @@ export class ManagementPlanAddEditComponent implements OnInit, OnDestroy {
public lngPublishSubtext = 'Not published';
// Pick lists
- public agencies = Picklists.agencyCodePicklist;
+ public agencies = Picklists.getAgencyCodes(this.factoryService);
// Documents
public documents = [];
diff --git a/angular/projects/admin-nrpti/src/app/records/orders/order-add-edit/order-add-edit.component.ts b/angular/projects/admin-nrpti/src/app/records/orders/order-add-edit/order-add-edit.component.ts
index c0d4511a9..554ab8a3b 100644
--- a/angular/projects/admin-nrpti/src/app/records/orders/order-add-edit/order-add-edit.component.ts
+++ b/angular/projects/admin-nrpti/src/app/records/orders/order-add-edit/order-add-edit.component.ts
@@ -34,7 +34,7 @@ export class OrderAddEditComponent implements OnInit, OnDestroy {
// Pick lists
public orderSubtypePicklist = Picklists.orderSubtypePicklist;
- public agencies = Picklists.agencyCodePicklist;
+ public agencies = Picklists.getAgencyCodes(this.factoryService);
public authors = Picklists.authorPicklist;
public outcomeStatuses = Picklists.outcomeStatusPicklist;
private defaultAgency = '';
diff --git a/angular/projects/admin-nrpti/src/app/records/permits/permit-add-edit/permit-add-edit.component.ts b/angular/projects/admin-nrpti/src/app/records/permits/permit-add-edit/permit-add-edit.component.ts
index 924a48bf6..34151a10b 100644
--- a/angular/projects/admin-nrpti/src/app/records/permits/permit-add-edit/permit-add-edit.component.ts
+++ b/angular/projects/admin-nrpti/src/app/records/permits/permit-add-edit/permit-add-edit.component.ts
@@ -32,7 +32,7 @@ export class PermitAddEditComponent implements OnInit, OnDestroy {
// Pick lists
public permitSubtypes = Picklists.permitSubtypePicklist;
- public agencies = Picklists.agencyCodePicklist;
+ public agencies = Picklists.getAgencyCodes(this.factoryService);
private defaultAgency = '';
// Documents
diff --git a/angular/projects/admin-nrpti/src/app/records/records-list/records-list.component.ts b/angular/projects/admin-nrpti/src/app/records/records-list/records-list.component.ts
index f505ca74e..30dee78d4 100644
--- a/angular/projects/admin-nrpti/src/app/records/records-list/records-list.component.ts
+++ b/angular/projects/admin-nrpti/src/app/records/records-list/records-list.component.ts
@@ -28,6 +28,7 @@ import {
RadioOptionItem
} from '../../../../../common/src/app/search-filter-template/filter-object';
import { FactoryService } from '../../services/factory.service';
+import { AgencyDataService } from '../../../../../global/src/lib/utils/agency-data-service';
/**
* List page component.
@@ -113,7 +114,7 @@ export class RecordsListComponent implements OnInit, OnDestroy {
private loadingScreenService: LoadingScreenService,
private tableTemplateUtils: TableTemplateUtils,
private _changeDetectionRef: ChangeDetectorRef,
- public factoryService: FactoryService
+ private factoryService: FactoryService,
) {
// setup the subset configuration
const subsetOptions = [
@@ -195,9 +196,11 @@ export class RecordsListComponent implements OnInit, OnDestroy {
FilterType.MultiSelect,
'Responsible Agency',
new MultiSelectDefinition(
- Picklists.agencyPicklist.map(value => {
- const displayValue = Utils.displayNameFull(value);
- return { value: value, displayValue: displayValue, selected: false, display: true };
+ Picklists.getAgencyNames(this.factoryService).map(value => {
+ const agencyDataService = new AgencyDataService(this.factoryService);
+ const displayValue = agencyDataService.displayNameFull(value);
+ const picklistCodes = Picklists.getAgencyCode(this.factoryService, value)
+ return { value: picklistCodes, displayValue: displayValue, selected: false, display: true };
}),
'Begin typing to filter agencies...',
''
diff --git a/angular/projects/admin-nrpti/src/app/records/reports/report-add-edit/report-add-edit.component.ts b/angular/projects/admin-nrpti/src/app/records/reports/report-add-edit/report-add-edit.component.ts
index 2921e8483..65783fc04 100644
--- a/angular/projects/admin-nrpti/src/app/records/reports/report-add-edit/report-add-edit.component.ts
+++ b/angular/projects/admin-nrpti/src/app/records/reports/report-add-edit/report-add-edit.component.ts
@@ -33,7 +33,7 @@ export class ReportAddEditComponent implements OnInit, OnDestroy {
public bcmiPublishSubtext = 'Not published';
// Pick lists
- public agencies = Picklists.agencyCodePicklist;
+ public agencies = Picklists.getAgencyCodes(this.factoryService);
// Documents
public documents = [];
diff --git a/angular/projects/admin-nrpti/src/app/records/restorative-justices/restorative-justice-add-edit/restorative-justice-add-edit.component.ts b/angular/projects/admin-nrpti/src/app/records/restorative-justices/restorative-justice-add-edit/restorative-justice-add-edit.component.ts
index efb52c90e..77e95537b 100644
--- a/angular/projects/admin-nrpti/src/app/records/restorative-justices/restorative-justice-add-edit/restorative-justice-add-edit.component.ts
+++ b/angular/projects/admin-nrpti/src/app/records/restorative-justices/restorative-justice-add-edit/restorative-justice-add-edit.component.ts
@@ -33,7 +33,7 @@ export class RestorativeJusticeAddEditComponent implements OnInit, OnDestroy {
public nrcedPublishSubtext = 'Not published';
// Pick lists
- public agencies = Picklists.agencyCodePicklist;
+ public agencies = Picklists.getAgencyCodes(this.factoryService);
public authors = Picklists.authorPicklist;
private defaultAgency = '';
diff --git a/angular/projects/admin-nrpti/src/app/records/self-reports/self-report-add-edit/self-report-add-edit.component.ts b/angular/projects/admin-nrpti/src/app/records/self-reports/self-report-add-edit/self-report-add-edit.component.ts
index dbd2c7449..b14af9795 100644
--- a/angular/projects/admin-nrpti/src/app/records/self-reports/self-report-add-edit/self-report-add-edit.component.ts
+++ b/angular/projects/admin-nrpti/src/app/records/self-reports/self-report-add-edit/self-report-add-edit.component.ts
@@ -31,7 +31,7 @@ export class SelfReportAddEditComponent implements OnInit, OnDestroy {
public lngPublishSubtext = 'Not published';
// Pick lists
- public agencies = Picklists.agencyCodePicklist;
+ public agencies = Picklists.getAgencyCodes(this.factoryService);
public authors = Picklists.authorPicklist;
// Documents
diff --git a/angular/projects/admin-nrpti/src/app/records/tickets/ticket-add-edit/ticket-add-edit.component.ts b/angular/projects/admin-nrpti/src/app/records/tickets/ticket-add-edit/ticket-add-edit.component.ts
index a8cbfd0af..b03fd01e4 100644
--- a/angular/projects/admin-nrpti/src/app/records/tickets/ticket-add-edit/ticket-add-edit.component.ts
+++ b/angular/projects/admin-nrpti/src/app/records/tickets/ticket-add-edit/ticket-add-edit.component.ts
@@ -33,7 +33,7 @@ export class TicketAddEditComponent implements OnInit, OnDestroy {
public nrcedPublishSubtext = 'Not published';
// Pick lists
- public agencies = Picklists.agencyCodePicklist;
+ public agencies = Picklists.getAgencyCodes(this.factoryService);
public authors = Picklists.authorPicklist;
private defaultAgency = '';
diff --git a/angular/projects/admin-nrpti/src/app/records/warnings/warning-add-edit/warning-add-edit.component.ts b/angular/projects/admin-nrpti/src/app/records/warnings/warning-add-edit/warning-add-edit.component.ts
index ed6a1ea2a..68608dd87 100644
--- a/angular/projects/admin-nrpti/src/app/records/warnings/warning-add-edit/warning-add-edit.component.ts
+++ b/angular/projects/admin-nrpti/src/app/records/warnings/warning-add-edit/warning-add-edit.component.ts
@@ -33,7 +33,7 @@ export class WarningAddEditComponent implements OnInit, OnDestroy {
public nrcedPublishSubtext = 'Not published';
// Pick lists
- public agencies = Picklists.agencyCodePicklist;
+ public agencies = Picklists.getAgencyCodes(this.factoryService);
public authors = Picklists.authorPicklist;
public outcomeStatuses = Picklists.outcomeStatusPicklist;
private defaultAgency = '';
diff --git a/angular/projects/admin-nrpti/src/app/services/application-agency.service.ts b/angular/projects/admin-nrpti/src/app/services/application-agency.service.ts
index b172cd75d..e40a8b303 100644
--- a/angular/projects/admin-nrpti/src/app/services/application-agency.service.ts
+++ b/angular/projects/admin-nrpti/src/app/services/application-agency.service.ts
@@ -1,24 +1,42 @@
+/**
+ * @description This service provides methods to fetch and store issuing agencies.
+ * @class ApplicationAgencyService
+ */
+
import { Injectable } from '@angular/core';
import { ConfigService } from 'nrpti-angular-components';
import { Observable } from 'rxjs';
import { HttpClient } from '@angular/common/http';
-/*
-Service Layer for fetching issuing agencies and storing them in app_initializer
-*/
-
+/**
+ * @class
+ * @description Service for managing issuing agencies.
+ */
@Injectable()
export class ApplicationAgencyService {
private api: string;
private agencies: { [key: string]: string } = {};
+ /**
+ * @constructor
+ * @param {ConfigService} configService - The configuration service.
+ * @param {HttpClient} http - The HTTP client for making API requests.
+ */
constructor(private configService: ConfigService, public http: HttpClient) {}
+ /**
+ * Initialize the service by setting the API endpoint and refreshing agencies.
+ * @async
+ */
async init() {
this.api = `${this.configService.config['API_LOCATION']}${this.configService.config['API_PATH']}`;
await this.refreshAgencies().toPromise();
}
+ /**
+ * Refresh the list of agencies from the API.
+ * @returns {Observable} An observable that completes when agencies are refreshed.
+ */
refreshAgencies(): Observable {
return new Observable(observer => {
const apiEndpoint = `${this.api}/list-agencies`;
@@ -45,6 +63,10 @@ export class ApplicationAgencyService {
});
}
+ /**
+ * Get the list of agencies.
+ * @returns {Object} A dictionary of agency codes and names.
+ */
getAgencies(): { [key: string]: string } {
return this.agencies;
}
diff --git a/angular/projects/admin-nrpti/src/app/services/factory.service.ts b/angular/projects/admin-nrpti/src/app/services/factory.service.ts
index 1c87a3759..e5d14e518 100644
--- a/angular/projects/admin-nrpti/src/app/services/factory.service.ts
+++ b/angular/projects/admin-nrpti/src/app/services/factory.service.ts
@@ -643,9 +643,7 @@ export class FactoryService {
/**
* Get agency data. If data is not cached, fetch it from the ApplicationAgencyService.
- *
- * @readonly
- * @type {{ [key: string]: string }}
+ * @returns {Observable} An observable that resolves when agency data is fetched.
* @memberof FactoryService
*/
public getApplicationAgencyService(): Observable {
diff --git a/angular/projects/admin-nrpti/src/app/services/issuingagency.service.ts b/angular/projects/admin-nrpti/src/app/services/issuingagency.service.ts
index f2d810894..6758fe54b 100644
--- a/angular/projects/admin-nrpti/src/app/services/issuingagency.service.ts
+++ b/angular/projects/admin-nrpti/src/app/services/issuingagency.service.ts
@@ -1,24 +1,46 @@
+/**
+ * @description This service is used for fetching issuing agencies and storing them in the database.
+ * @class IssuingAgencyService
+ */
+
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { ApiService } from './api.service';
-/*
-Service Layer for agencies component. Used for fetching issuing agencies and storing them in database
-*/
+
+/**
+ * @class
+ * @description Service for managing issuing agencies.
+ */
@Injectable({ providedIn: 'root' })
export class IssuingAgencyService {
+ /**
+ * @constructor
+ * @param {ApiService} apiService - The API service for handling API requests.
+ * @param {HttpClient} http - The HTTP client for making API requests.
+ */
constructor(public apiService: ApiService, public http: HttpClient) {}
+ /**
+ * Get the list of issuing agencies from the API.
+ * @returns {Promise} A promise that resolves with the list of issuing agencies.
+ */
public getIssuingAgencies(): Promise {
return this.http
.get(`${this.apiService.pathAPI}/list-agencies`)
.toPromise()
.catch(error => {
console.error('API call error:', error);
- throw error; // Rethrow the error to propagate it further
+ throw error;
});
}
+ /**
+ * Update an agency's information in the database.
+ * @param {string} agencyCode - The code of the agency to update.
+ * @param {any} agencyName - The updated agency name.
+ * @returns {Promise} A promise that resolves with the result of the update operation.
+ */
public updateAgency(agencyCode: string, agencyName: any): Promise {
const apiUrl = `${this.apiService.pathAPI}/update-agencies`;
const updatedAgency = { agencies: [{ agencyCode: agencyCode, agencyName: agencyName }] }; // Wrap the array in an object
@@ -28,7 +50,7 @@ export class IssuingAgencyService {
.toPromise()
.catch(error => {
console.error('API call error:', error);
- throw error; // Rethrow the error to propagate it further
+ throw error;
});
}
}
diff --git a/angular/projects/common/src/app/utils/record-constants.ts b/angular/projects/common/src/app/utils/record-constants.ts
index 35c791f68..45b2679fa 100644
--- a/angular/projects/common/src/app/utils/record-constants.ts
+++ b/angular/projects/common/src/app/utils/record-constants.ts
@@ -188,6 +188,11 @@ export class Picklists {
return agencyDataService.getAgencyCode(agencyName);
}
+ public static getAgencyCodes(factoryService: FactoryService) {
+ const agencyDataService = new AgencyDataService(factoryService);
+ return agencyDataService.getAgencyCodes();
+ }
+
public static readonly agencyCodePicklist = [
'AGENCY_ALC',
'AGENCY_OGC',
@@ -295,9 +300,15 @@ export class Picklists {
];
public static readonly collectionAgencyPicklist = [
- 'Environmental Assessment Office',
- 'Ministry of Energy Mines and Low Carbon Innovation',
- 'Ministry of Environment and Climate Change Strategy'
+ 'Environmental Assessment Office 2',
+ 'Ministry of Energy Mines and Low Carbon Innovation 2',
+ 'Ministry of Environment and Climate Change Strategy 2'
+ ];
+
+ public static readonly collectionAgencyCodePicklist = [
+ 'AGENCY_EAO',
+ 'AGENCY_EMLI',
+ 'AGENCY_ENV'
];
/**
diff --git a/angular/projects/global/src/lib/utils/agency-data-service-nrced.ts b/angular/projects/global/src/lib/utils/agency-data-service-nrced.ts
new file mode 100644
index 000000000..8ce70a8ac
--- /dev/null
+++ b/angular/projects/global/src/lib/utils/agency-data-service-nrced.ts
@@ -0,0 +1,77 @@
+/**
+ * @summary service for accessing issuing agencies.
+ * @description the service provides methods for getting agency codes and names from ApplicationAgencyService.
+ * @class AgencyDataService
+ */
+
+import { FactoryService } from '../../../../public-nrpti/src/app/services/factory.service';
+
+/**
+ * @class
+ * @description Service for accessing issuing agencies from ApplicationAgencyService.
+ */
+export class AgencyDataService {
+ /**
+ * @constructor
+ * @param {FactoryService} factoryService - the factory service for accessing application agency data.
+ */
+ constructor(
+ private factoryService: FactoryService,
+ ) {}
+
+ /**
+ * Get the full name of the agency based on the agency's code
+ * retrieved from the agency data using the FactoryService.
+ * @param {string} agencyCode - an agency's code
+ * @returns {string} - the agency's full name
+ */
+ displayNameFull(agencyCode): string {
+ // Access cached agency data from FactoryService
+ const agencyService = this.factoryService.applicationAgencyService;
+ const agencyList = agencyService ? agencyService.getAgencies() : null;
+ return agencyList && agencyList[agencyCode] ? agencyList[agencyCode] : agencyCode;
+ }
+
+ /**
+ * Get an array of agency codes.
+ * @returns {string[]} - an array of agency codes
+ */
+ getAgencyCodes(): string[] {
+ const agencyService = this.factoryService.applicationAgencyService;
+ const agencyList = agencyService ? agencyService.getAgencies() : null;
+
+ return agencyList ? Object.keys(agencyList) : [];
+ }
+
+ /**
+ * Get an array of agency names.
+ * @returns {string[]} - an array of agency names
+ */
+ getAgencyNames(): string[] {
+ const agencyService = this.factoryService.applicationAgencyService;
+ const agencyList = agencyService ? agencyService.getAgencies() : null;
+
+ return agencyList ? Object.values(agencyList) : [];
+ }
+
+ /**
+ * Get the agency code based on the agency's name
+ * @param {string} agencyName - the name of an agency
+ * @returns {string} - the agency's code
+ */
+ getAgencyCode(agencyName: string): string {
+ const agencyService = this.factoryService.applicationAgencyService;
+ const agencyList = agencyService ? agencyService.getAgencies() : null;
+
+ if (agencyList) {
+ for (const key in agencyList) {
+ if (agencyList.hasOwnProperty(key) && agencyList[key] === agencyName) {
+ return key; // Return the key if the value matches
+ }
+ }
+ }
+ // Return a default value or handle the case where agencyList is undefined or empty
+ return '';
+ }
+
+}
diff --git a/angular/projects/global/src/lib/utils/agency-data-service.ts b/angular/projects/global/src/lib/utils/agency-data-service.ts
index 777690e9d..93d4ece40 100644
--- a/angular/projects/global/src/lib/utils/agency-data-service.ts
+++ b/angular/projects/global/src/lib/utils/agency-data-service.ts
@@ -1,10 +1,30 @@
+/**
+ * @summary service for accessing issuing agencies.
+ * @description the service provides methods for getting agency codes and names from ApplicationAgencyService.
+ * @class AgencyDataService
+ */
+
import { FactoryService } from '../../../../admin-nrpti/src/app/services/factory.service';
+/**
+ * @class
+ * @description Service for accessing issuing agencies from ApplicationAgencyService.
+ */
export class AgencyDataService {
+ /**
+ * @constructor
+ * @param {FactoryService} factoryService - the factory service for accessing application agency data.
+ */
constructor(
private factoryService: FactoryService,
) {}
+ /**
+ * Get the full name of the agency based on the agency's code
+ * retrieved from the agency data using the FactoryService.
+ * @param {string} agencyCode - an agency's code
+ * @returns {string} - the agency's full name
+ */
displayNameFull(agencyCode): string {
// Access cached agency data from FactoryService
const agencyService = this.factoryService.applicationAgencyService;
@@ -13,6 +33,10 @@ export class AgencyDataService {
return agencyList && agencyList[agencyCode] ? agencyList[agencyCode] : agencyCode;
}
+ /**
+ * Get an array of agency codes.
+ * @returns {string[]} - an array of agency codes
+ */
getAgencyCodes(): string[] {
const agencyService = this.factoryService.applicationAgencyService;
const agencyList = agencyService ? agencyService.getAgencies() : null;
@@ -20,6 +44,10 @@ export class AgencyDataService {
return agencyList ? Object.keys(agencyList) : [];
}
+ /**
+ * Get an array of agency names.
+ * @returns {string[]} - an array of agency names
+ */
getAgencyNames(): string[] {
const agencyService = this.factoryService.applicationAgencyService;
const agencyList = agencyService ? agencyService.getAgencies() : null;
@@ -27,6 +55,11 @@ export class AgencyDataService {
return agencyList ? Object.values(agencyList) : [];
}
+ /**
+ * Get the agency code based on the agency's name
+ * @param {string} agencyName - the name of an agency
+ * @returns {string} - the agency's code
+ */
getAgencyCode(agencyName: string): string {
const agencyService = this.factoryService.applicationAgencyService;
const agencyList = agencyService ? agencyService.getAgencies() : null;
diff --git a/angular/projects/public-nrpti/src/app/app.module.ts b/angular/projects/public-nrpti/src/app/app.module.ts
index 1b8bd45c4..5667e21af 100644
--- a/angular/projects/public-nrpti/src/app/app.module.ts
+++ b/angular/projects/public-nrpti/src/app/app.module.ts
@@ -29,13 +29,20 @@ import { ApiService } from './services/api.service';
import { DocumentService } from './services/document.service';
import { FactoryService } from './services/factory.service';
import { ConfigService, LoggerService } from 'nrpti-angular-components';
+import { ApplicationAgencyService } from './services/application-agency.service';
export function overlayScrollFactory(overlay: Overlay): () => CloseScrollStrategy {
return () => overlay.scrollStrategies.close();
}
-export function initConfig(configService: ConfigService) {
- return () => configService.init();
+export function initConfig(
+ configService: ConfigService,
+ applicationAgency: ApplicationAgencyService
+) {
+ return async () => {
+ await configService.init();
+ await applicationAgency.init();
+ };
}
@NgModule({
@@ -60,7 +67,7 @@ export function initConfig(configService: ConfigService) {
{
provide: APP_INITIALIZER,
useFactory: initConfig,
- deps: [ConfigService],
+ deps: [ConfigService, ApplicationAgencyService],
multi: true
},
{
@@ -72,7 +79,8 @@ export function initConfig(configService: ConfigService) {
ApiService,
DocumentService,
FactoryService,
- LoggerService
+ LoggerService,
+ ApplicationAgencyService
],
entryComponents: [ConfirmComponent, HomeComponent],
bootstrap: [AppComponent]
diff --git a/angular/projects/public-nrpti/src/app/records/administrative-penalties/administrative-penalty-detail/administrative-penalty-detail.component.ts b/angular/projects/public-nrpti/src/app/records/administrative-penalties/administrative-penalty-detail/administrative-penalty-detail.component.ts
index 154a738b4..346866527 100644
--- a/angular/projects/public-nrpti/src/app/records/administrative-penalties/administrative-penalty-detail/administrative-penalty-detail.component.ts
+++ b/angular/projects/public-nrpti/src/app/records/administrative-penalties/administrative-penalty-detail/administrative-penalty-detail.component.ts
@@ -6,6 +6,7 @@ import { AdministrativePenaltyNRCED, Document } from '../../../../../../common/s
import { FactoryService } from '../../../services/factory.service';
import { Utils as CommonUtils } from '../../../../../../common/src/app/utils/utils';
import { Utils as GlobalUtils } from 'nrpti-angular-components';
+import { AgencyDataService } from '../../../../../../../projects/global/src/lib/utils/agency-data-service-nrced';
@Component({
selector: 'app-administrative-penalty-detail',
@@ -104,7 +105,8 @@ export class AdministrativePenaltyDetailComponent implements OnInit, OnChanges,
}
displayName(agency) {
- return GlobalUtils.displayNameFull(agency);
+ const agencyDataService = new AgencyDataService(this.factoryService);
+ return agencyDataService.displayNameFull(agency);
}
ngOnDestroy() {
diff --git a/angular/projects/public-nrpti/src/app/records/administrative-sanctions/administrative-sanction-detail/administrative-sanction-detail.component.ts b/angular/projects/public-nrpti/src/app/records/administrative-sanctions/administrative-sanction-detail/administrative-sanction-detail.component.ts
index ee06cbe26..2b6c78f20 100644
--- a/angular/projects/public-nrpti/src/app/records/administrative-sanctions/administrative-sanction-detail/administrative-sanction-detail.component.ts
+++ b/angular/projects/public-nrpti/src/app/records/administrative-sanctions/administrative-sanction-detail/administrative-sanction-detail.component.ts
@@ -6,6 +6,7 @@ import { AdministrativeSanctionNRCED, Document } from '../../../../../../common/
import { FactoryService } from '../../../services/factory.service';
import { Utils as CommonUtils } from '../../../../../../common/src/app/utils/utils';
import { Utils as GlobalUtils } from 'nrpti-angular-components';
+import { AgencyDataService } from '../../../../../../../projects/global/src/lib/utils/agency-data-service-nrced';
@Component({
selector: 'app-administrative-sanction-detail',
@@ -90,7 +91,8 @@ export class AdministrativeSanctionDetailComponent implements OnInit, OnChanges,
}
displayName(agency) {
- return GlobalUtils.displayNameFull(agency);
+ const agencyDataService = new AgencyDataService(this.factoryService);
+ return agencyDataService.displayNameFull(agency);
}
ngOnDestroy() {
diff --git a/angular/projects/public-nrpti/src/app/records/court-convictions/court-conviction-detail/court-conviction-detail.component.ts b/angular/projects/public-nrpti/src/app/records/court-convictions/court-conviction-detail/court-conviction-detail.component.ts
index 6ffabc480..8d39ff805 100644
--- a/angular/projects/public-nrpti/src/app/records/court-convictions/court-conviction-detail/court-conviction-detail.component.ts
+++ b/angular/projects/public-nrpti/src/app/records/court-convictions/court-conviction-detail/court-conviction-detail.component.ts
@@ -6,6 +6,7 @@ import { CourtConvictionNRCED, Document } from '../../../../../../common/src/app
import { FactoryService } from '../../../services/factory.service';
import { Utils as CommonUtils } from '../../../../../../common/src/app/utils/utils';
import { Utils as GlobalUtils } from 'nrpti-angular-components';
+import { AgencyDataService } from '../../../../../../../projects/global/src/lib/utils/agency-data-service-nrced';
@Component({
selector: 'app-court-conviction-detail',
@@ -107,7 +108,8 @@ export class CourtConvictionDetailComponent implements OnInit, OnDestroy {
}
displayName(agency) {
- return GlobalUtils.displayNameFull(agency);
+ const agencyDataService = new AgencyDataService(this.factoryService);
+ return agencyDataService.displayNameFull(agency);
}
ngOnDestroy() {
diff --git a/angular/projects/public-nrpti/src/app/records/inspections/inspection-detail/inspection-detail.component.ts b/angular/projects/public-nrpti/src/app/records/inspections/inspection-detail/inspection-detail.component.ts
index b71f1bb32..6cfe065e7 100644
--- a/angular/projects/public-nrpti/src/app/records/inspections/inspection-detail/inspection-detail.component.ts
+++ b/angular/projects/public-nrpti/src/app/records/inspections/inspection-detail/inspection-detail.component.ts
@@ -6,7 +6,7 @@ import { InspectionNRCED, Document } from '../../../../../../common/src/app/mode
import { FactoryService } from '../../../services/factory.service';
import { Utils as CommonUtils } from '../../../../../../common/src/app/utils/utils';
import { Utils as GlobalUtils } from 'nrpti-angular-components';
-
+import { AgencyDataService } from '../../../../../../../projects/global/src/lib/utils/agency-data-service-nrced';
@Component({
selector: 'app-inspection-detail',
templateUrl: './inspection-detail.component.html',
@@ -90,7 +90,8 @@ export class InspectionDetailComponent implements OnInit, OnChanges, OnDestroy {
}
displayName(agency) {
- return GlobalUtils.displayNameFull(agency);
+ const agencyDataService = new AgencyDataService(this.factoryService);
+ return agencyDataService.displayNameFull(agency);
}
ngOnDestroy() {
diff --git a/angular/projects/public-nrpti/src/app/records/orders/order-detail/order-detail.component.ts b/angular/projects/public-nrpti/src/app/records/orders/order-detail/order-detail.component.ts
index d9ab42ca5..33cebc594 100644
--- a/angular/projects/public-nrpti/src/app/records/orders/order-detail/order-detail.component.ts
+++ b/angular/projects/public-nrpti/src/app/records/orders/order-detail/order-detail.component.ts
@@ -6,6 +6,7 @@ import { OrderNRCED, Document } from '../../../../../../common/src/app/models';
import { FactoryService } from '../../../services/factory.service';
import { Utils as CommonUtils } from '../../../../../../common/src/app/utils/utils';
import { Utils as GlobalUtils } from 'nrpti-angular-components';
+import { AgencyDataService } from '../../../../../../../projects/global/src/lib/utils/agency-data-service-nrced';
@Component({
selector: 'app-order-detail',
@@ -96,7 +97,8 @@ export class OrderDetailComponent implements OnInit, OnChanges, OnDestroy {
}
displayName(agency) {
- return GlobalUtils.displayNameFull(agency);
+ const agencyDataService = new AgencyDataService(this.factoryService);
+ return agencyDataService.displayNameFull(agency);
}
ngOnDestroy() {
diff --git a/angular/projects/public-nrpti/src/app/records/restorative-justices/restorative-justice-detail/restorative-justice-detail.component.ts b/angular/projects/public-nrpti/src/app/records/restorative-justices/restorative-justice-detail/restorative-justice-detail.component.ts
index a7d95ef01..e13d7251d 100644
--- a/angular/projects/public-nrpti/src/app/records/restorative-justices/restorative-justice-detail/restorative-justice-detail.component.ts
+++ b/angular/projects/public-nrpti/src/app/records/restorative-justices/restorative-justice-detail/restorative-justice-detail.component.ts
@@ -6,6 +6,7 @@ import { RestorativeJusticeNRCED, Document } from '../../../../../../common/src/
import { FactoryService } from '../../../services/factory.service';
import { Utils as CommonUtils } from '../../../../../../common/src/app/utils/utils';
import { Utils as GlobalUtils } from 'nrpti-angular-components';
+import { AgencyDataService } from '../../../../../../../projects/global/src/lib/utils/agency-data-service-nrced';
@Component({
selector: 'app-restorative-justice-detail',
@@ -90,7 +91,8 @@ export class RestorativeJusticeDetailComponent implements OnInit, OnChanges, OnD
}
displayName(agency) {
- return GlobalUtils.displayNameFull(agency);
+ const agencyDataService = new AgencyDataService(this.factoryService);
+ return agencyDataService.displayNameFull(agency);
}
ngOnDestroy() {
diff --git a/angular/projects/public-nrpti/src/app/records/tickets/ticket-detail/ticket-detail.component.ts b/angular/projects/public-nrpti/src/app/records/tickets/ticket-detail/ticket-detail.component.ts
index f112bdb04..f7d89a7b7 100644
--- a/angular/projects/public-nrpti/src/app/records/tickets/ticket-detail/ticket-detail.component.ts
+++ b/angular/projects/public-nrpti/src/app/records/tickets/ticket-detail/ticket-detail.component.ts
@@ -6,6 +6,7 @@ import { TicketNRCED, Document } from '../../../../../../common/src/app/models';
import { FactoryService } from '../../../services/factory.service';
import { Utils as CommonUtils } from '../../../../../../common/src/app/utils/utils';
import { Utils as GlobalUtils } from 'nrpti-angular-components';
+import { AgencyDataService } from '../../../../../../../projects/global/src/lib/utils/agency-data-service-nrced';
@Component({
selector: 'app-ticket-detail',
@@ -90,7 +91,8 @@ export class TicketDetailComponent implements OnInit, OnChanges, OnDestroy {
}
displayName(agency) {
- return GlobalUtils.displayNameFull(agency);
+ const agencyDataService = new AgencyDataService(this.factoryService);
+ return agencyDataService.displayNameFull(agency);
}
ngOnDestroy() {
diff --git a/angular/projects/public-nrpti/src/app/records/warnings/warning-detail/warning-detail.component.ts b/angular/projects/public-nrpti/src/app/records/warnings/warning-detail/warning-detail.component.ts
index fe093a1b6..adefd8e1c 100644
--- a/angular/projects/public-nrpti/src/app/records/warnings/warning-detail/warning-detail.component.ts
+++ b/angular/projects/public-nrpti/src/app/records/warnings/warning-detail/warning-detail.component.ts
@@ -6,6 +6,7 @@ import { WarningNRCED, Document } from '../../../../../../common/src/app/models'
import { FactoryService } from '../../../services/factory.service';
import { Utils as CommonUtils } from '../../../../../../common/src/app/utils/utils';
import { Utils as GlobalUtils } from 'nrpti-angular-components';
+import { AgencyDataService } from '../../../../../../../projects/global/src/lib/utils/agency-data-service-nrced';
@Component({
selector: 'app-warning-detail',
@@ -95,9 +96,11 @@ export class WarningDetailComponent implements OnInit, OnChanges, OnDestroy {
}
displayName(agency) {
- return GlobalUtils.displayNameFull(agency);
+ const agencyDataService = new AgencyDataService(this.factoryService);
+ return agencyDataService.displayNameFull(agency);
}
+
convertAcronyms(acronym) {
return GlobalUtils.convertAcronyms(acronym);
}
diff --git a/angular/projects/public-nrpti/src/app/services/application-agency.service.ts b/angular/projects/public-nrpti/src/app/services/application-agency.service.ts
new file mode 100644
index 000000000..e40a8b303
--- /dev/null
+++ b/angular/projects/public-nrpti/src/app/services/application-agency.service.ts
@@ -0,0 +1,73 @@
+/**
+ * @description This service provides methods to fetch and store issuing agencies.
+ * @class ApplicationAgencyService
+ */
+
+import { Injectable } from '@angular/core';
+import { ConfigService } from 'nrpti-angular-components';
+import { Observable } from 'rxjs';
+import { HttpClient } from '@angular/common/http';
+
+/**
+ * @class
+ * @description Service for managing issuing agencies.
+ */
+@Injectable()
+export class ApplicationAgencyService {
+ private api: string;
+ private agencies: { [key: string]: string } = {};
+
+ /**
+ * @constructor
+ * @param {ConfigService} configService - The configuration service.
+ * @param {HttpClient} http - The HTTP client for making API requests.
+ */
+ constructor(private configService: ConfigService, public http: HttpClient) {}
+
+ /**
+ * Initialize the service by setting the API endpoint and refreshing agencies.
+ * @async
+ */
+ async init() {
+ this.api = `${this.configService.config['API_LOCATION']}${this.configService.config['API_PATH']}`;
+ await this.refreshAgencies().toPromise();
+ }
+
+ /**
+ * Refresh the list of agencies from the API.
+ * @returns {Observable} An observable that completes when agencies are refreshed.
+ */
+ refreshAgencies(): Observable {
+ return new Observable(observer => {
+ const apiEndpoint = `${this.api}/list-agencies`;
+ const getAgencies = this.http.get<{ [key: string]: string }>(apiEndpoint);
+
+ getAgencies.subscribe(
+ response => {
+ // Data transformation to make the data easier to work with
+ const agencyList = {};
+ for (const record in response) {
+ if (response.hasOwnProperty(record)) {
+ agencyList[response[record]['agencyCode']] = response[record]['agencyName'];
+ }
+ }
+ this.agencies = agencyList;
+ observer.next();
+ observer.complete();
+ },
+ error => {
+ console.error('HTTP Request Error: ', error);
+ observer.error(error);
+ }
+ );
+ });
+ }
+
+ /**
+ * Get the list of agencies.
+ * @returns {Object} A dictionary of agency codes and names.
+ */
+ getAgencies(): { [key: string]: string } {
+ return this.agencies;
+ }
+}
diff --git a/angular/projects/public-nrpti/src/app/services/factory.service.ts b/angular/projects/public-nrpti/src/app/services/factory.service.ts
index 1c526fc4d..eb8a20c1a 100644
--- a/angular/projects/public-nrpti/src/app/services/factory.service.ts
+++ b/angular/projects/public-nrpti/src/app/services/factory.service.ts
@@ -2,7 +2,7 @@ import { Injectable, Injector, ViewContainerRef, Type, ComponentRef } from '@ang
import { Observable, of } from 'rxjs';
import { ApiService } from './api.service';
import { SearchService, SearchResults, InjectComponentService } from 'nrpti-angular-components';
-
+import { ApplicationAgencyService } from './application-agency.service';
/**
* Facade service for all public-nrced services.
*
@@ -16,6 +16,7 @@ export class FactoryService {
private _apiService: ApiService;
private _searchService: SearchService;
private _injectComponentService: InjectComponentService;
+ private _applicationAgencyService: ApplicationAgencyService;
constructor(private injector: Injector) {
// The following items are loaded by a file that is only present on cluster builds.
@@ -68,6 +69,20 @@ export class FactoryService {
return this._injectComponentService;
}
+ /**
+ * Inject agency service if it hasn't already been injected.
+ *
+ * @readonly
+ * @type {ApiService}
+ * @memberof FactoryService
+ */
+ public get applicationAgencyService(): ApplicationAgencyService {
+ if (!this._applicationAgencyService) {
+ this._applicationAgencyService = this.injector.get(ApplicationAgencyService);
+ }
+ return this._applicationAgencyService;
+ }
+
/**
* Return the record for the given _id.
*
@@ -204,4 +219,18 @@ export class FactoryService {
public injectComponentIntoView(viewContainerRef: ViewContainerRef, comonentToInject: Type): ComponentRef {
return this.injectComponentService.injectComponentIntoView(viewContainerRef, comonentToInject);
}
+
+ /**
+ * Get agency data. If data is not cached, fetch it from the ApplicationAgencyService.
+ * @returns {Observable} An observable that resolves when agency data is fetched.
+ * @memberof FactoryService
+ */
+ public getApplicationAgencyService(): Observable {
+ if (Object.keys(this.applicationAgencyService.getAgencies).length === 0) {
+ this.applicationAgencyService.refreshAgencies().subscribe(() => {
+ this.applicationAgencyService.getAgencies();
+ });
+ }
+ return this.applicationAgencyService.refreshAgencies();
+ }
}
diff --git a/api/materialized_views/search/redactedRecordSubset.test.js b/api/materialized_views/search/redactedRecordSubset.test.js
index 35d0af33a..8bae9a36b 100644
--- a/api/materialized_views/search/redactedRecordSubset.test.js
+++ b/api/materialized_views/search/redactedRecordSubset.test.js
@@ -44,7 +44,7 @@ describe('Record Individual issuedTo redaction test', () => {
const testRecord = new TestModel({
issuedTo: generateIssuedTo( false, true, false ),
_schemaName: 'Schema',
- issuingAgency: 'BC Parks'
+ issuingAgency: 'AGENCY_ENV_BCPARKS'
});
await nrptiCollection.insertOne(testRecord);
@@ -62,7 +62,7 @@ describe('Record Individual issuedTo redaction test', () => {
const testRecord = new TestModel({
issuedTo: generateIssuedTo( true, false, false ),
_schemaName: 'Schema',
- issuingAgency: 'BC Parks'
+ issuingAgency: 'AGENCY_ENV_BCPARKS'
});
await nrptiCollection.insertOne(testRecord);
@@ -120,4 +120,4 @@ describe('Record Individual issuedTo redaction test', () => {
const redacted = await redacted_record_subset.findOne();
expect(redacted.issuedTo.companyName).toEqual(testRecord.issuedTo.companyName);
});
-});
\ No newline at end of file
+});
diff --git a/api/migrations/20230911220312-addApplicationAgenciesModel.js b/api/migrations/20230911220312-addApplicationAgenciesModel.js
index b0d048a25..65c19af47 100644
--- a/api/migrations/20230911220312-addApplicationAgenciesModel.js
+++ b/api/migrations/20230911220312-addApplicationAgenciesModel.js
@@ -1,21 +1,20 @@
-'use strict';
-const ApplicationAgency = require('../src/models/master/applicationAgency');
-const mongoose = require('mongoose');
-
-var dbm;
-var type;
-var seed;
-
-/*
-Migration file for adding agency codes and agency values to the nrpti collection
-*/
+/**
+ * @summary Adds agency/ministry codes and names as ApplicationAgency constants to the nrpti collection in the database.
+ */
+/**
+ * @param {Object} options - Migration options.
+ * @param {string} seedLink - Seed link.
+ * @description Sets up the migration by initializing variables.
+ */
exports.setup = function(options, seedLink) {
- dbm = options.dbmigrate;
- type = dbm.dataType;
- seed = seedLink;
+ let dbm = options.dbmigrate;
};
+/**
+ * @param {Object} db - Database connection object.
+ * @description Adds _schemaName:ApplicationAgency constants to the nrpti collection in the database.
+ */
exports.up = async function (db) {
console.log('**** Adding ApplicationAgencies constants to nrpti collection ****');
@@ -33,7 +32,6 @@ exports.up = async function (db) {
{ agencyCode: "AGENCY_ENV", agencyName: 'Ministry of Environment and Climate Change Strategy' },
{ agencyCode: "AGENCY_ENV_BCPARKS", agencyName: 'BC Parks' },
{ agencyCode: "AGENCY_OGC", agencyName: 'BC Energy Regulator' },
- { agencyCode: "AGENCY_ENV_EPD", agencyName: 'Ministry of Environment and Climate Change Strategy' },
{ agencyCode: "AGENCY_LNG", agencyName: 'LNG Secretariat' },
{ agencyCode: "AGENCY_AGRI", agencyName: 'Ministry of Agriculture and Food' },
{ agencyCode: "AGENCY_FLNRO", agencyName: 'Ministry of Forests' },
@@ -79,10 +77,18 @@ exports.up = async function (db) {
return null;
};
+/**
+ * @param {Object} db - Database connection object.
+ * @description Performs the reverse migration (not implemented in this script).
+ */
exports.down = function(db) {
return null;
};
+/**
+ * @property {Object} _meta
+ * @property {number} _meta.version - The version of the migration script.
+ */
exports._meta = {
"version": 1
};
diff --git a/api/migrations/20230912181649-updateIssuingAgencyToCode.js b/api/migrations/20230912181649-updateIssuingAgencyToCode.js
index b2a35065a..3c3d3a4a2 100644
--- a/api/migrations/20230912181649-updateIssuingAgencyToCode.js
+++ b/api/migrations/20230912181649-updateIssuingAgencyToCode.js
@@ -1,26 +1,16 @@
-'use strict';
-
-var dbm;
-var seed;
-
/**
- * Migration file for updating all existing records to use agency code instead of agency value
+ * @summary Updates existing records in nrpti and redacted_record_subset to use agency/ministry codes instead of names.
*/
-exports.setup = function (options, seedLink) {
- dbm = options.dbmigrate;
- seed = seedLink;
-};
+/**
+ * @param {Object} db - Database connection object.
+ * @description Updates records in specified collections to use agency codes instead of agency values.
+ */
exports.up = async function (db) {
const mClient = await db.connection.connect(db.connectionString, {
native_parser: true,
});
- const LegislationActs = {
- ACT_Env_Management: 'Environmental Management Act',
- ACT_Int_Pest_Management: 'Integrated Pest Management Act',
- };
-
const agencies = [
{ agencyCode: 'AGENCY_ALC', agencyName: 'Agricultural Land Commission' },
{ agencyCode: 'AGENCY_WF', agencyName: 'BC Wildfire Service' },
@@ -30,7 +20,6 @@ exports.up = async function (db) {
{ agencyCode: "AGENCY_ENV", agencyName: 'Ministry of Environment and Climate Change Strategy' },
{ agencyCode: "AGENCY_ENV_BCPARKS", agencyName: 'BC Parks' },
{ agencyCode: "AGENCY_OGC", agencyName: 'BC Energy Regulator' },
- { agencyCode: "AGENCY_ENV_EPD", agencyName: 'Ministry of Environment and Climate Change Strategy' },
{ agencyCode: "AGENCY_LNG", agencyName: 'LNG Secretariat' },
{ agencyCode: "AGENCY_AGRI", agencyName: 'Ministry of Agriculture and Food' },
{ agencyCode: "AGENCY_FLNRO", agencyName: 'Ministry of Forests' },
@@ -44,42 +33,14 @@ exports.up = async function (db) {
try {
for (let collection of collections) {
console.log(`***** Collection: ${collection} *****`);
- console.log(`***** Updating ocers-csv records *****`);
-
- try {
- let currentCollection = await mClient.collection(collection);
-
- // Update issuingAgency to 'AGENCY_ENV_EPD' for specific records
- await currentCollection.updateMany(
- {
- $and: [
- { issuingAgency: 'Ministry of Environment and Climate Change Strategy' },
- { author: 'Ministry of Environment and Climate Change Strategy' },
- { 'legislation.act': { $in: [LegislationActs.ACT_Env_Management, LegislationActs.ACT_Int_Pest_Management] } }
- ]
- },
- { $set: { issuingAgency: 'AGENCY_ENV_EPD', author: 'AGENCY_ENV_EPD' } }
- );
-
- console.log(` ***** Updated records in collection: ${collection} *****`);
- } catch (err) {
- console.error(` ***** Error updating collection: ${collection} *****`, err);
- }
-
- console.log(`***** Updating all other records records *****`);
try {
let currentCollection = await mClient.collection(collection);
for (const agency of agencies) {
// Update issuingAgency and author fields for the agency
await currentCollection.updateMany(
- {
- $and: [
- { issuingAgency: agency['agencyName'] },
- { author: agency['agencyName'] }
- ]
- },
- { $set: { issuingAgency: agency['agencyCode'], author: agency['agencyCode'] } }
+ { issuingAgency: agency['agencyName'] },
+ { $set: { issuingAgency: agency['agencyCode'] } }
);
console.log(` ***** Updated collection: ${collection} for agency: ${agency['agencyName']} *****`);
@@ -99,23 +60,18 @@ exports.up = async function (db) {
return null;
};
+/**
+ * @param {Object} db - Database connection object.
+ * @description Performs the reverse migration (not implemented in this script).
+ */
exports.down = function (db) {
return null;
};
+/**
+ * @property {Object} _meta
+ * @property {number} _meta.version - The version of the migration script.
+ */
exports._meta = {
version: 1
};
-
-/**
- * Update a record in the collection with a new agency code.
- * @param {Collection} collection - MongoDB collection.
- * @param {string} recordId - The ID of the record to update.
- * @param {string} newAgencyCode - The new agency code.
- */
-async function updateRecord(collection, recordId, newAgencyCode) {
- await collection.updateOne(
- { _id: recordId },
- { $set: { 'legislation.act': newAgencyCode } }
- );
-}
diff --git a/api/migrations/20231005223753-updateBCMIIssuingAgencyToCode.js b/api/migrations/20231005223753-updateBCMIIssuingAgencyToCode.js
new file mode 100644
index 000000000..e8d8bcc00
--- /dev/null
+++ b/api/migrations/20231005223753-updateBCMIIssuingAgencyToCode.js
@@ -0,0 +1,77 @@
+/**
+ * @summary Updates existing records in nrpti and redacted_record_subset to use agency/ministry codes instead of names.
+ */
+
+/**
+ * @param {Object} db - Database connection object.
+ * @description Updates records in specified collections to use agency codes instead of agency values.
+ */
+exports.up = async function (db) {
+ const mClient = await db.connection.connect(db.connectionString, {
+ native_parser: true,
+ });
+
+ const agencies = [
+ { agencyCode: 'AGENCY_ALC', agencyName: 'Agricultural Land Commission' },
+ { agencyCode: 'AGENCY_WF', agencyName: 'BC Wildfire Service' },
+ { agencyCode: "AGENCY_ENV_COS", agencyName: 'Conservation Officer Service' },
+ { agencyCode: "AGENCY_EAO", agencyName: 'Environmental Assessment Office' },
+ { agencyCode: "AGENCY_EMLI", agencyName: 'Ministry of Energy Mines and Low Carbon Innovation' },
+ { agencyCode: "AGENCY_ENV", agencyName: 'Ministry of Environment and Climate Change Strategy' },
+ { agencyCode: "AGENCY_ENV_BCPARKS", agencyName: 'BC Parks' },
+ { agencyCode: "AGENCY_OGC", agencyName: 'BC Energy Regulator' },
+ { agencyCode: "AGENCY_LNG", agencyName: 'LNG Secretariat' },
+ { agencyCode: "AGENCY_AGRI", agencyName: 'Ministry of Agriculture and Food' },
+ { agencyCode: "AGENCY_FLNRO", agencyName: 'Ministry of Forests' },
+ { agencyCode: "AGENCY_FLNR_NRO", agencyName: 'Natural Resource Officers' },
+ { agencyCode: "AGENCY_WLRS", agencyName: 'Ministry of Water, Land and Resource Stewardship' },
+ { agencyCode: "AGENCY_CAS", agencyName: 'Climate Action Secretariat' }
+ ];
+
+ const collections = ['nrpti', 'redacted_record_subset'];
+
+ try {
+ for (let collection of collections) {
+ console.log(`***** Collection: ${collection} *****`);
+ try {
+ let currentCollection = await mClient.collection(collection);
+
+ for (const agency of agencies) {
+ // Update issuingAgency and author fields for the agency
+ await currentCollection.updateMany(
+ { agency: agency['agencyName'] },
+ { $set: { agency: agency['agencyCode'] } }
+ );
+
+ console.log(` ***** Updated collection: ${collection} for agency: ${agency['agencyName']} *****`);
+ }
+ } catch (err) {
+ console.error(` ***** Error updating collection: ${collection} for agency: ${agency['agencyName']} *****`, err);
+ }
+ }
+ } catch (err) {
+ console.error('Error connecting to the database:', err);
+ } finally {
+ if (mClient) {
+ await mClient.close();
+ }
+ }
+
+ return null;
+};
+
+/**
+ * @param {Object} db - Database connection object.
+ * @description Performs the reverse migration (not implemented in this script).
+ */
+exports.down = function (db) {
+ return null;
+};
+
+/**
+ * @property {Object} _meta
+ * @property {number} _meta.version - The version of the migration script.
+ */
+exports._meta = {
+ version: 1
+};
diff --git a/api/src/controllers/agencies.js b/api/src/controllers/agencies.js
index dc224cfbe..a6a5140ae 100644
--- a/api/src/controllers/agencies.js
+++ b/api/src/controllers/agencies.js
@@ -1,13 +1,20 @@
+/**
+ * @summary APIs for the Update Issuing Agency page.
+ * @description This file contains API endpoints for loading and updating agency names from the database.
+ */
+
const queryActions = require('../utils/query-actions');
const mongodb = require('../utils/mongodb');
const RECORD_TYPE = require('../utils/constants/record-type-enum');
const defaultLog = require('../utils/logger')('record');
-/*
-APIs for Update Issuing Agency page
-Includes Get and Put apis to load and update agency names from the database
-*/
-
+/**
+ * @async
+ * @param {Object} args - Request arguments.
+ * @param {Object} res - Response object.
+ * @param {Function} next - Next function in the middleware chain.
+ * @description Get API for retrieving agency code and names from the database.
+ */
exports.publicGet = async function(args, res, next) {
const db = mongodb.connection.db(process.env.MONGODB_DATABASE || 'nrpti-dev');
const collectionDB = db.collection('nrpti');
@@ -15,9 +22,10 @@ exports.publicGet = async function(args, res, next) {
let agencyList;
try {
- //Obtain documents with Application Agency Schema
+ // Obtain documents with Application Agency Schema
let agencyDocuments = await collectionDB.find({ _schemaName: RECORD_TYPE.ApplicationAgency._schemaName }).toArray();
- //Using map function to iterate through the original array and creates a new array with objects containing only the _id, agencyCode, and agencyName properties.
+ // Using map function to iterate through the original array and creates
+ // a new array with objects containing only the _id, agencyCode, and agencyName properties.
agencyList = agencyDocuments.map(item => ({
_id: item._id,
agencyCode: item.agencyCode,
@@ -30,24 +38,27 @@ exports.publicGet = async function(args, res, next) {
queryActions.sendResponse(res, 200, agencyList);
};
-/**
-* @param {*} args
-* @param {*} res
-* @param {*} next
-* @param {*} incomingObj see example
-* @returns edited lng order record
-* Example of args.swagger.params.data.value
- {
- "agencies":
- [
- {
- "agencyCode": "AGENCY_ALC",
- "agencyName": "Agricultural Land Commission_1"
- }
- ]
- }
-*/
+/**
+ * @async
+ * @param {Object} args - Request arguments.
+ * @param {Object} res - Response object.
+ * @param {Function} next - Next function in the middleware chain.
+ * @description Put API for updating agency names in the database.
+ * @param {Object} incomingObj - Incoming object with agency code and the new name to update.
+ * @returns {string} - Result message ('Success' or 'Error').
+ * @example
+ * // Example of args.swagger.params.data.value
+ * {
+ * "agencies":
+ * [
+ * {
+ * "agencyCode": "AGENCY_ALC",
+ * "agencyName": "Agricultural Land Commission_1"
+ * }
+ * ]
+ * }
+ */
exports.protectedPut = async function(args, res, next) {
const db = mongodb.connection.db(process.env.MONGODB_DATABASE || 'nrpti-dev');
let promises = [];
diff --git a/api/src/importers/alc/inspections-utils.js b/api/src/importers/alc/inspections-utils.js
index 68ed1943d..0a2b74d67 100644
--- a/api/src/importers/alc/inspections-utils.js
+++ b/api/src/importers/alc/inspections-utils.js
@@ -38,8 +38,8 @@ class Inspections extends BaseRecordUtils {
inspection['recordType'] = 'Inspection';
inspection['dateIssued'] = csvRow['date'] || null;
- inspection['issuingAgency'] = 'Agricultural Land Commission';
- inspection['author'] = 'Agricultural Land Commission';
+ inspection['issuingAgency'] = 'AGENCY_ALC';
+ inspection['author'] = 'AGENCY_ALC';
inspection['recordName'] = (csvRow['record id'] && `ALC Inspection - Record ${csvRow['record id']}`) || '-';
inspection['description'] = (csvRow['reason'] && `Activity Inspected: ${csvRow['reason']}`) || '-';
diff --git a/api/src/importers/alc/inspections-utils.test.js b/api/src/importers/alc/inspections-utils.test.js
index 955cb2382..c2a05b62d 100644
--- a/api/src/importers/alc/inspections-utils.test.js
+++ b/api/src/importers/alc/inspections-utils.test.js
@@ -17,12 +17,12 @@ describe('transformRecord', () => {
_sourceRefStringId: '',
recordType: 'Inspection',
- author: 'Agricultural Land Commission',
+ author: 'AGENCY_ALC',
dateIssued: null,
issuedTo: { dateOfBirth: null, firstName: '', lastName: '', middleName: '', type: 'Individual' },
description: '-',
sourceSystemRef: 'alc-csv',
- issuingAgency: 'Agricultural Land Commission',
+ issuingAgency: 'AGENCY_ALC',
legislation: [
{
act: 'Agricultural Land Commission Act',
@@ -55,7 +55,7 @@ describe('transformRecord', () => {
recordType: 'Inspection',
recordName: 'ALC Inspection - Record 123',
- author: 'Agricultural Land Commission',
+ author: 'AGENCY_ALC',
description: 'Activity Inspected: reason',
summary: 'Activity Inspected: reason',
dateIssued: expect.any(String),
@@ -66,7 +66,7 @@ describe('transformRecord', () => {
middleName: '',
type: MiscConstants.IssuedToEntityTypes.Individual
},
- issuingAgency: 'Agricultural Land Commission',
+ issuingAgency: 'AGENCY_ALC',
legislation: [
{
act: 'Agricultural Land Commission Act',
diff --git a/api/src/importers/ams/orders-utils.js b/api/src/importers/ams/orders-utils.js
index 5e08b46a0..320c4b72c 100644
--- a/api/src/importers/ams/orders-utils.js
+++ b/api/src/importers/ams/orders-utils.js
@@ -38,8 +38,8 @@ class Orders extends BaseRecordUtils {
order['recordType'] = 'Order';
order['dateIssued'] = csvRow['issuedate'] || null;
- order['issuingAgency'] = 'Ministry of Environment and Climate Change Strategy';
- order['author'] = 'Ministry of Environment and Climate Change Strategy';
+ order['issuingAgency'] = 'AGENCY_ENV';
+ order['author'] = 'AGENCY_ENV';
order['recordName'] = (csvRow['authnumber'] && `AMS Authorization # ${csvRow['authnumber']}`) || '-';
diff --git a/api/src/importers/ams/orders-utils.test.js b/api/src/importers/ams/orders-utils.test.js
index afc82be35..9da29d2f3 100644
--- a/api/src/importers/ams/orders-utils.test.js
+++ b/api/src/importers/ams/orders-utils.test.js
@@ -17,11 +17,11 @@ describe('transformRecord', () => {
_sourceRefStringId: '',
recordType: 'Order',
- author: 'Ministry of Environment and Climate Change Strategy',
+ author: 'AGENCY_ENV',
dateIssued: null,
issuedTo: { type: MiscConstants.IssuedToEntityTypes.Company, companyName: '' },
sourceSystemRef: 'ams-csv',
- issuingAgency: 'Ministry of Environment and Climate Change Strategy',
+ issuingAgency: 'AGENCY_ENV',
legislation: [{ act: 'Environmental Management Act' }],
location: 'British Columbia',
recordName: '-',
@@ -47,14 +47,14 @@ describe('transformRecord', () => {
recordType: 'Order',
recordName: 'AMS Authorization # 123',
- author: 'Ministry of Environment and Climate Change Strategy',
+ author: 'AGENCY_ENV',
summary: 'Authorization Number: 123',
dateIssued: expect.any(String),
issuedTo: {
companyName: 'ABC Company',
type: MiscConstants.IssuedToEntityTypes.Company
},
- issuingAgency: 'Ministry of Environment and Climate Change Strategy',
+ issuingAgency: 'AGENCY_ENV',
legislation: [
{
act: 'Environmental Management Act',
diff --git a/api/src/importers/cmdb/inspection-utils.js b/api/src/importers/cmdb/inspection-utils.js
index f5ce8afd1..ef87221a5 100644
--- a/api/src/importers/cmdb/inspection-utils.js
+++ b/api/src/importers/cmdb/inspection-utils.js
@@ -39,8 +39,8 @@ class Inspections extends BaseRecordUtils {
inspection['recordType'] = 'Inspection';
inspection['dateIssued'] = csvRow['date issued'] || null;
- inspection['issuingAgency'] = 'Ministry of Agriculture and Food';
- inspection['author'] = 'Ministry of Agriculture';
+ inspection['issuingAgency'] = 'AGENCY_AGRI';
+ inspection['author'] = 'AGENCY_AGRI';
inspection['recordName'] = csvRow['inspection type'] || '';
diff --git a/api/src/importers/cmdb/inspection-utils.test.js b/api/src/importers/cmdb/inspection-utils.test.js
index ae844a32d..05db504af 100644
--- a/api/src/importers/cmdb/inspection-utils.test.js
+++ b/api/src/importers/cmdb/inspection-utils.test.js
@@ -19,7 +19,7 @@ describe('transformRecord', () => {
_sourceRefAgriCmdbId: '',
recordType: 'Inspection',
- author: 'Ministry of Agriculture',
+ author: 'AGENCY_AGRI',
dateIssued: null,
issuedTo: {
type: MiscConstants.IssuedToEntityTypes.Company,
@@ -28,7 +28,7 @@ describe('transformRecord', () => {
description: descriptionString,
outcomeDescription: '',
sourceSystemRef: 'agri-cmdb-csv',
- issuingAgency: 'Ministry of Agriculture and Food',
+ issuingAgency: 'AGENCY_AGRI',
legislation: [
{
act: 'Fish and Seafood Act',
@@ -60,14 +60,14 @@ describe('transformRecord', () => {
recordType: 'Inspection',
recordName: 'Higher Risk Inspection',
- author: 'Ministry of Agriculture',
+ author: 'AGENCY_AGRI',
description: descriptionString,
dateIssued: expect.any(String),
issuedTo: {
companyName: 'Company 5',
type: MiscConstants.IssuedToEntityTypes.Company
},
- issuingAgency: 'Ministry of Agriculture and Food',
+ issuingAgency: 'AGENCY_AGRI',
legislation: [
{
act: 'Fish and Seafood Act',
diff --git a/api/src/importers/coors/admin-sanction-utils.js b/api/src/importers/coors/admin-sanction-utils.js
index 37514c827..bb717b719 100644
--- a/api/src/importers/coors/admin-sanction-utils.js
+++ b/api/src/importers/coors/admin-sanction-utils.js
@@ -42,7 +42,7 @@ class AdminSanctions extends BaseRecordUtils {
adminSanction['recordType'] = 'Administrative Sanction';
adminSanction['recordName'] = (csvRow['case_no'] && `Case No. ${csvRow['case_no']}`) || '';
- const ministry = 'Ministry of Forests';
+ const ministry = 'AGENCY_FLNRO';
adminSanction['issuingAgency'] = ministry;
adminSanction['author'] = ministry;
adminSanction['dateIssued'] = csvRow['effective_date'] || null;
diff --git a/api/src/importers/coors/admin-sanction-utils.test.js b/api/src/importers/coors/admin-sanction-utils.test.js
index 713815706..c42e9c31e 100644
--- a/api/src/importers/coors/admin-sanction-utils.test.js
+++ b/api/src/importers/coors/admin-sanction-utils.test.js
@@ -46,8 +46,8 @@ describe('transformRecord', () => {
companyName: 'businessName123',
type: 'Company'
},
- issuingAgency: 'Ministry of Forests',
- author: 'Ministry of Forests',
+ issuingAgency: 'AGENCY_FLNRO',
+ author: 'AGENCY_FLNRO',
legislation: [
{
act: 'Wildlife Act',
@@ -108,8 +108,8 @@ describe('transformRecord', () => {
companyName: 'businessName123',
type: 'Company'
},
- issuingAgency: 'Ministry of Forests',
- author: 'Ministry of Forests',
+ issuingAgency: 'AGENCY_FLNRO',
+ author: 'AGENCY_FLNRO',
legislation: [
{
act: 'Wildlife Act',
diff --git a/api/src/importers/coors/court-conviction-utils.test.js b/api/src/importers/coors/court-conviction-utils.test.js
index 1de7c77bb..b4f80e278 100644
--- a/api/src/importers/coors/court-conviction-utils.test.js
+++ b/api/src/importers/coors/court-conviction-utils.test.js
@@ -57,8 +57,8 @@ describe('transformRecord', () => {
companyName: mockRecord.business_name,
type: 'Company'
},
- issuingAgency: 'BC Parks',
- author: 'BC Parks',
+ issuingAgency: 'AGENCY_ENV_BCPARKS',
+ author: 'AGENCY_ENV_BCPARKS',
legislation: [
{
act: mockRecord.act,
diff --git a/api/src/importers/coors/tickets-utils.test.js b/api/src/importers/coors/tickets-utils.test.js
index a92dab6cd..bf064afaa 100644
--- a/api/src/importers/coors/tickets-utils.test.js
+++ b/api/src/importers/coors/tickets-utils.test.js
@@ -56,8 +56,8 @@ describe('transformRecord', () => {
companyName: 'businessName123',
type: 'Company'
},
- issuingAgency: 'BC Parks',
- author: 'BC Parks',
+ issuingAgency: 'AGENCY_ENV_BCPARKS',
+ author: 'AGENCY_ENV_BCPARKS',
legislation: [
{
act: 'Fisheries Canada',
diff --git a/api/src/importers/coors/utils/csv-utils.js b/api/src/importers/coors/utils/csv-utils.js
index 23384d686..afd745a47 100644
--- a/api/src/importers/coors/utils/csv-utils.js
+++ b/api/src/importers/coors/utils/csv-utils.js
@@ -53,7 +53,7 @@ exports.getIssuingAgency = function(csvRow) {
return MiscConstants.CoorsCsvIssuingAgencies.Water_Sustainability_Act;
}
- // Otherwise the issuing agency defaults to Conservation Officer Service
+ // Otherwise, the issuing agency defaults to Conservation Officer Service
return MiscConstants.CoorsCsvIssuingAgencies.Conservation_Officer_Service;
};
diff --git a/api/src/importers/coors/utils/csv-utils.test.js b/api/src/importers/coors/utils/csv-utils.test.js
index 0d5547ecb..f0743557b 100644
--- a/api/src/importers/coors/utils/csv-utils.test.js
+++ b/api/src/importers/coors/utils/csv-utils.test.js
@@ -40,13 +40,13 @@ describe('getIssuingAgency', () => {
expect(result).toBe(null);
});
- it('returns "BC Parks" if csvRow "case_number" starts with a "P-"', async () => {
+ it('returns "AGENCY_ENV_BCPARKS" if csvRow "case_number" starts with a "P-"', async () => {
const result = await CsvUtils.getIssuingAgency({ case_number: 'P-123123' });
expect(result).toEqual(MiscConstants.CoorsCsvIssuingAgencies.BC_Parks);
});
- it('returns "Conservation Officer Service" if csvRow "case_number" does not start with a "P-"', async () => {
+ it('returns "AGENCY_ENV_COS" if csvRow "case_number" does not start with a "P-"', async () => {
const result = await CsvUtils.getIssuingAgency({ case_number: '123123' });
expect(result).toEqual(MiscConstants.CoorsCsvIssuingAgencies.Conservation_Officer_Service);
diff --git a/api/src/importers/era/tickets-utils.js b/api/src/importers/era/tickets-utils.js
index 8486c68ef..93676f538 100644
--- a/api/src/importers/era/tickets-utils.js
+++ b/api/src/importers/era/tickets-utils.js
@@ -40,8 +40,8 @@ class tickets extends BaseRecordUtils {
}
ticket['recordName'] = csvRow['article_description'] || '';
- ticket['issuingAgency'] = 'Natural Resource Officers';
- ticket['author'] = 'Natural Resource Officers';
+ ticket['issuingAgency'] = 'AGENCY_FLNR_NRO';
+ ticket['author'] = 'AGENCY_FLNR_NRO';
ticket['recordType'] = 'Ticket';
ticket['dateIssued'] = csvRow['service_date'] || null;
diff --git a/api/src/importers/era/tickets-utils.test.js b/api/src/importers/era/tickets-utils.test.js
index 97b5de411..dc7f07799 100644
--- a/api/src/importers/era/tickets-utils.test.js
+++ b/api/src/importers/era/tickets-utils.test.js
@@ -18,8 +18,8 @@ describe('transformRecord', () => {
recordName: '',
recordType: 'Ticket',
- issuingAgency: 'Natural Resource Officers',
- author: 'Natural Resource Officers',
+ issuingAgency: 'AGENCY_FLNR_NRO',
+ author: 'AGENCY_FLNR_NRO',
location: '',
dateIssued: null,
@@ -55,8 +55,8 @@ describe('transformRecord', () => {
recordName: 'bad manners',
location: 'somewhere',
recordType: 'Ticket',
- issuingAgency: 'Natural Resource Officers',
- author: 'Natural Resource Officers',
+ issuingAgency: 'AGENCY_FLNR_NRO',
+ author: 'AGENCY_FLNR_NRO',
dateIssued: '02/24/2021',
penalties: [
diff --git a/api/src/importers/flnr/inspections-utils.js b/api/src/importers/flnr/inspections-utils.js
index cafb046ef..3e3e51744 100644
--- a/api/src/importers/flnr/inspections-utils.js
+++ b/api/src/importers/flnr/inspections-utils.js
@@ -40,8 +40,8 @@ class Inspections extends BaseRecordUtils {
inspection['recordType'] = 'Inspection';
inspection['dateIssued'] = csvRow['date'] || null;
- inspection['issuingAgency'] = 'Natural Resource Officers';
- inspection['author'] = 'Natural Resource Officers';
+ inspection['issuingAgency'] = 'AGENCY_FLNR_NRO';
+ inspection['author'] = 'AGENCY_FLNR_NRO';
inspection['recordName'] = (csvRow['record id'] && `NRO Inspection - Record ${csvRow['record id']}`) || '-';
inspection['description'] = (csvRow['activity'] && `Activity Inspected: ${csvRow['activity']}`) || '-';
diff --git a/api/src/importers/flnr/inspections-utils.test.js b/api/src/importers/flnr/inspections-utils.test.js
index 709576f22..cd0ae4ba1 100644
--- a/api/src/importers/flnr/inspections-utils.test.js
+++ b/api/src/importers/flnr/inspections-utils.test.js
@@ -19,12 +19,12 @@ describe('transformRecord', () => {
_sourceRefNrisId: '',
recordType: 'Inspection',
- author: 'Natural Resource Officers',
+ author: 'AGENCY_FLNR_NRO',
dateIssued: null,
issuedTo: { dateOfBirth: null, firstName: '', lastName: '', middleName: '', type: 'Individual', companyName: '' },
description: '-',
sourceSystemRef: 'nris-flnr-csv',
- issuingAgency: 'Natural Resource Officers',
+ issuingAgency: 'AGENCY_FLNR_NRO',
legislation: [{ legislationDescription: 'Inspection to verify compliance with regulatory requirement' }],
location: null,
outcomeDescription: 'undefined - undefined',
@@ -53,7 +53,7 @@ describe('transformRecord', () => {
recordType: 'Inspection',
recordName: 'NRO Inspection - Record 123',
- author: 'Natural Resource Officers',
+ author: 'AGENCY_FLNR_NRO',
description: 'Activity Inspected: Road - Maintenance',
summary: 'Activity Inspected: Road - Maintenance',
dateIssued: expect.any(String),
@@ -61,7 +61,7 @@ describe('transformRecord', () => {
companyName: 'LNG Canada Development Inc.',
type: MiscConstants.IssuedToEntityTypes.Company
},
- issuingAgency: 'Natural Resource Officers',
+ issuingAgency: 'AGENCY_FLNR_NRO',
legislation: [
{
legislationDescription: 'Inspection to verify compliance with regulatory requirement'
diff --git a/api/src/importers/mis/inspection-utils.js b/api/src/importers/mis/inspection-utils.js
index 8c6f147b0..2c57ac8b6 100644
--- a/api/src/importers/mis/inspection-utils.js
+++ b/api/src/importers/mis/inspection-utils.js
@@ -39,8 +39,8 @@ class Inspections extends BaseRecordUtils {
inspection['recordType'] = 'Inspection';
inspection['dateIssued'] = csvRow['created '] || null;
- inspection['issuingAgency'] = 'Ministry of Agriculture and Food';
- inspection['author'] = 'Ministry of Agriculture';
+ inspection['issuingAgency'] = 'AGENCY_AGRI';
+ inspection['author'] = 'AGENCY_AGRI';
inspection['recordName'] = (csvRow['issue no.'] && `Compliance issue ${csvRow['issue no.']}`) || '';
inspection['description'] = 'Inspection to verify compliance with regulatory requirement';
diff --git a/api/src/importers/mis/inspection-utils.test.js b/api/src/importers/mis/inspection-utils.test.js
index 6554f7aef..0dc4f1e7a 100644
--- a/api/src/importers/mis/inspection-utils.test.js
+++ b/api/src/importers/mis/inspection-utils.test.js
@@ -19,7 +19,7 @@ describe('transformRecord', () => {
_sourceRefAgriMisId: '',
recordType: 'Inspection',
- author: 'Ministry of Agriculture',
+ author: 'AGENCY_AGRI',
dateIssued: null,
issuedTo: {
type: MiscConstants.IssuedToEntityTypes.Company,
@@ -28,7 +28,7 @@ describe('transformRecord', () => {
description: descriptionString,
outcomeDescription: '',
sourceSystemRef: 'agri-mis-csv',
- issuingAgency: 'Ministry of Agriculture and Food',
+ issuingAgency: 'AGENCY_AGRI',
legislation: [
{
act: 'Food Safety Act',
@@ -59,14 +59,14 @@ describe('transformRecord', () => {
recordType: 'Inspection',
recordName: 'Compliance issue 123.4',
- author: 'Ministry of Agriculture',
+ author: 'AGENCY_AGRI',
description: descriptionString,
dateIssued: expect.any(String),
issuedTo: {
companyName: 'ACME Meat',
type: MiscConstants.IssuedToEntityTypes.Company
},
- issuingAgency: 'Ministry of Agriculture and Food',
+ issuingAgency: 'AGENCY_AGRI',
legislation: [
{
act: 'Food Safety Act',
diff --git a/api/src/integrations/bcogc/administrative-penalties-utils.js b/api/src/integrations/bcogc/administrative-penalties-utils.js
index cbd466da4..727800d79 100644
--- a/api/src/integrations/bcogc/administrative-penalties-utils.js
+++ b/api/src/integrations/bcogc/administrative-penalties-utils.js
@@ -39,8 +39,8 @@ class AdministrativePenalty extends BaseRecordUtils {
penalty['recordType'] = RECORD_TYPE.AdministrativePenalty.displayName;
penalty['_sourceRefOgcPenaltyId'] = csvRow['Title'];
- penalty['author'] = 'BC Energy Regulator';
- penalty['issuingAgency'] = 'BC Energy Regulator';
+ penalty['author'] = 'AGENCY_OGC';
+ penalty['issuingAgency'] = 'AGENCY_OGC';
penalty['recordName'] = csvRow['Title'];
penalty['dateIssued'] = new Date(csvRow['Date Issued']);
penalty['location'] = 'British Columbia';
diff --git a/api/src/integrations/bcogc/inspections-utils.js b/api/src/integrations/bcogc/inspections-utils.js
index b91406199..a3341368e 100644
--- a/api/src/integrations/bcogc/inspections-utils.js
+++ b/api/src/integrations/bcogc/inspections-utils.js
@@ -51,8 +51,8 @@ class Inspections extends BaseRecordUtils {
defaultLog.debug(error);
inspection['dateIssued'] = null;
}
- inspection['issuingAgency'] = 'BC Energy Regulator';
- inspection['author'] = 'BC Energy Regulator';
+ inspection['issuingAgency'] = 'AGENCY_OGC';
+ inspection['author'] = 'AGENCY_OGC';
inspection['recordName'] =
(csvRow['inspection number'] && `Inspection Number ${csvRow['inspection number']}`) || '-';
diff --git a/api/src/integrations/bcogc/inspections-utils.test.js b/api/src/integrations/bcogc/inspections-utils.test.js
index a8e459a21..614a8b437 100644
--- a/api/src/integrations/bcogc/inspections-utils.test.js
+++ b/api/src/integrations/bcogc/inspections-utils.test.js
@@ -20,8 +20,8 @@ describe('transformRecord', () => {
recordType: 'Inspection',
dateIssued: null,
issuedTo: { companyName: '', type: 'Company' },
- issuingAgency: 'BC Energy Regulator',
- author: 'BC Energy Regulator',
+ issuingAgency: 'AGENCY_OGC',
+ author: 'AGENCY_OGC',
recordName: '-',
legislation: [{ act: 'Oil and Gas Activities Act', section: '57', subSection: '4', legislationDescription: 'Inspection to verify compliance with regulatory requirement' }],
location: 'British Columbia',
@@ -56,8 +56,8 @@ describe('transformRecord', () => {
recordType: 'Inspection',
dateIssued: expect.any(Date),
issuedTo: { companyName: 'Coastal GasLink Pipeline Ltd.', type: 'Company' },
- issuingAgency: 'BC Energy Regulator',
- author: 'BC Energy Regulator',
+ issuingAgency: 'AGENCY_OGC',
+ author: 'AGENCY_OGC',
recordName: 'Inspection Number 123456',
legislation: [
{
diff --git a/api/src/integrations/bcogc/orders-utils.js b/api/src/integrations/bcogc/orders-utils.js
index 93f2f1d71..a51bcc531 100644
--- a/api/src/integrations/bcogc/orders-utils.js
+++ b/api/src/integrations/bcogc/orders-utils.js
@@ -40,8 +40,8 @@ class Orders extends BaseRecordUtils {
order['recordType'] = RECORD_TYPE.Order.displayName;
order['_sourceRefOgcOrderId'] = csvRow['Title'];
- order['author'] = 'BC Energy Regulator';
- order['issuingAgency'] = 'BC Energy Regulator';
+ order['author'] = 'AGENCY_OGC';
+ order['issuingAgency'] = 'AGENCY_OGC';
order['recordName'] = csvRow['Title'];
try {
diff --git a/api/src/integrations/bcogc/warnings-utils.js b/api/src/integrations/bcogc/warnings-utils.js
index 7085368af..0a777efa2 100644
--- a/api/src/integrations/bcogc/warnings-utils.js
+++ b/api/src/integrations/bcogc/warnings-utils.js
@@ -40,8 +40,8 @@ class Warning extends BaseRecordUtils {
warning['recordType'] = RECORD_TYPE.Warning.displayName;
warning['_sourceRefOgcWarningId'] = csvRow['Title'];
- warning['author'] = 'BC Energy Regulator';
- warning['issuingAgency'] = 'BC Energy Regulator';
+ warning['author'] = 'AGENCY_OGC';
+ warning['issuingAgency'] = 'AGENCY_OGC';
warning['recordName'] = csvRow['Filename'];
try {
warning['dateIssued'] = csvRow['Date Issued'] ? moment.tz(csvRow['Date Issued'], "MM/DD/YYYY", "America/Vancouver").toDate() : null;
diff --git a/api/src/integrations/bcogc/warnings-utils.test.js b/api/src/integrations/bcogc/warnings-utils.test.js
index 470284c14..e71ffd8e1 100644
--- a/api/src/integrations/bcogc/warnings-utils.test.js
+++ b/api/src/integrations/bcogc/warnings-utils.test.js
@@ -23,8 +23,8 @@ describe('transformRecord', () => {
url: undefined
},
issuedTo: { companyName: '', type: 'Company' },
- issuingAgency: 'BC Energy Regulator',
- author: 'BC Energy Regulator',
+ issuingAgency: 'AGENCY_OGC',
+ author: 'AGENCY_OGC',
location: 'British Columbia',
recordName: undefined,
sourceSystemRef: 'bcogc'
@@ -52,8 +52,8 @@ describe('transformRecord', () => {
url: 'https://www.bc-er.ca/some/file/Warning-letter-sample.pdf'
},
issuedTo: { companyName: 'Coastal GasLink Pipeline Ltd.', type: 'Company' },
- issuingAgency: 'BC Energy Regulator',
- author: 'BC Energy Regulator',
+ issuingAgency: 'AGENCY_OGC',
+ author: 'AGENCY_OGC',
location: 'British Columbia',
recordName: 'Warning-letter-sample.pdf',
projectName: 'Coastal Gaslink',
diff --git a/api/src/integrations/core/datasource.js b/api/src/integrations/core/datasource.js
index 40dcd9086..55ec9dbc6 100644
--- a/api/src/integrations/core/datasource.js
+++ b/api/src/integrations/core/datasource.js
@@ -541,7 +541,7 @@ class CoreDataSource {
name: amendment.description !== null ? amendment.description : 'Permit Documents',
date: amendment.issue_date ? new Date(amendment.issue_date) : null,
type: amendment.permit_amendment_type_code === 'OGP' ? 'Permit' : 'Permit Amendment',
- agency: 'Ministry of Energy Mines and Low Carbon Innovation',
+ agency: 'AGENCY_EMLI',
records: (existingPermits && existingPermits.map(permit => permit._id)) || []
};
diff --git a/api/src/integrations/core/permit-utils.js b/api/src/integrations/core/permit-utils.js
index 30c98ed20..928d6ceb5 100644
--- a/api/src/integrations/core/permit-utils.js
+++ b/api/src/integrations/core/permit-utils.js
@@ -76,7 +76,7 @@ class Permits extends BaseRecordUtils {
projectName: mineRecord.name || '',
centroid: (mineRecord.location && mineRecord.location.coordinates) || [],
- issuingAgency: 'Ministry of Energy Mines and Low Carbon Innovation'
+ issuingAgency: 'AGENCY_EMLI'
});
}
}
diff --git a/api/src/integrations/epic/base-record-utils.js b/api/src/integrations/epic/base-record-utils.js
index 80270501d..dbf5500b0 100644
--- a/api/src/integrations/epic/base-record-utils.js
+++ b/api/src/integrations/epic/base-record-utils.js
@@ -130,6 +130,7 @@ class BaseRecordUtils {
_sourceRefId: new ObjectID(epicRecord._id) || '',
_epicMilestoneId: epicRecord.milestone || '',
mineGuid: (mineRecord && mineRecord._sourceRefId) || null,
+ issuingAgency: 'AGENCY_EAO',
recordName: epicRecord.displayName || '',
recordType: this.recordType.displayName,
diff --git a/api/src/integrations/epic/base-record-utils.test.js b/api/src/integrations/epic/base-record-utils.test.js
index a54b679b7..adf4e5476 100644
--- a/api/src/integrations/epic/base-record-utils.test.js
+++ b/api/src/integrations/epic/base-record-utils.test.js
@@ -36,6 +36,7 @@ describe('BaseRecordUtils', () => {
_epicProjectId: '',
_sourceRefId: expect.any(Object),
_epicMilestoneId: '',
+ issuingAgency: 'AGENCY_EAO',
recordName: '',
recordType: RECORD_TYPE.Order.displayName,
diff --git a/api/src/integrations/epic/certificates-amendment-utils.js b/api/src/integrations/epic/certificates-amendment-utils.js
index 78f9f195a..aa91543c2 100644
--- a/api/src/integrations/epic/certificates-amendment-utils.js
+++ b/api/src/integrations/epic/certificates-amendment-utils.js
@@ -34,7 +34,7 @@ class CertificatesAmendment extends BaseRecordUtils {
return {
...(await super.transformRecord(epicRecord)),
- issuingAgency: 'Environmental Assessment Office',
+ issuingAgency: 'AGENCY_EAO',
legislation: [
{
act: (epicRecord.project && epicRecord.project.legislation) || ''
diff --git a/api/src/integrations/epic/certificates-utils.js b/api/src/integrations/epic/certificates-utils.js
index 66aa0abb4..fc0985a5b 100644
--- a/api/src/integrations/epic/certificates-utils.js
+++ b/api/src/integrations/epic/certificates-utils.js
@@ -34,7 +34,7 @@ class Certificates extends BaseRecordUtils {
return {
...(await super.transformRecord(epicRecord)),
- issuingAgency: 'Environmental Assessment Office',
+ issuingAgency: 'AGENCY_EAO',
legislation: [{
act: (epicRecord.project && epicRecord.project.legislation) || ''
}]
diff --git a/api/src/integrations/epic/inspections-utils.js b/api/src/integrations/epic/inspections-utils.js
index 6d673ab6c..696dd06cb 100644
--- a/api/src/integrations/epic/inspections-utils.js
+++ b/api/src/integrations/epic/inspections-utils.js
@@ -53,7 +53,7 @@ class Inspections extends BaseRecordUtils {
return {
...(await super.transformRecord(epicRecord)),
- issuingAgency: 'Environmental Assessment Office',
+ issuingAgency: 'AGENCY_EAO',
author: epicRecord.documentAuthor || '',
legislation: [legislation],
issuedTo: {
diff --git a/api/src/integrations/epic/management-plans-utils.js b/api/src/integrations/epic/management-plans-utils.js
index b0e07a98f..fb43f19d9 100644
--- a/api/src/integrations/epic/management-plans-utils.js
+++ b/api/src/integrations/epic/management-plans-utils.js
@@ -35,7 +35,6 @@ class ManagementPlans extends BaseRecordUtils {
return {
...(await super.transformRecord(epicRecord)),
- issuingAgency: 'Environmental Assessment Office',
author: epicRecord.documentAuthor || ''
};
}
diff --git a/api/src/integrations/epic/management-plans-utils.test.js b/api/src/integrations/epic/management-plans-utils.test.js
new file mode 100644
index 000000000..ced2f67a2
--- /dev/null
+++ b/api/src/integrations/epic/management-plans-utils.test.js
@@ -0,0 +1,19 @@
+const ManagementPlans = require('./management-plans-utils');
+const RECORD_TYPE = require('../../utils/constants/record-type-enum');
+
+describe('ManagementPlans', () => {
+ describe('transformRecord', () => {
+ it('transforms an epic management plan record correctly', async () => {
+ const epicRecord = {'recordName': 'test abc'}
+ const managementPlans = new ManagementPlans({}, RECORD_TYPE.ManagementPlan);
+ const transformedRecord = await managementPlans.transformRecord(epicRecord);
+
+ expect(transformedRecord.issuingAgency).toEqual('AGENCY_EAO');
+ });
+
+ it('throws an error if epic record is not provided', async () => {
+ const managementPlans = new ManagementPlans({}, RECORD_TYPE.ManagementPlan);
+ await expect(managementPlans.transformRecord(null)).rejects.toThrow('transformRecord - required record must be non-null.');
+ });
+ });
+});
diff --git a/api/src/integrations/epic/orders-utils.js b/api/src/integrations/epic/orders-utils.js
index f673875c5..1939538b7 100644
--- a/api/src/integrations/epic/orders-utils.js
+++ b/api/src/integrations/epic/orders-utils.js
@@ -51,7 +51,7 @@ class Orders extends BaseRecordUtils {
return {
...(await super.transformRecord(epicRecord)),
- issuingAgency: 'Environmental Assessment Office',
+ issuingAgency: 'AGENCY_EAO',
author: epicRecord.documentAuthor || '',
legislation: [legislation],
issuedTo: {
diff --git a/api/src/integrations/nris-emli/datasource.js b/api/src/integrations/nris-emli/datasource.js
index 1bc78903d..ebecd0f10 100644
--- a/api/src/integrations/nris-emli/datasource.js
+++ b/api/src/integrations/nris-emli/datasource.js
@@ -239,7 +239,7 @@ class NrisDataSource {
defaultLog.debug(error);
newRecord.dateIssued = null;
}
- newRecord.issuingAgency = 'Ministry of Energy Mines and Low Carbon Innovation';
+ newRecord.issuingAgency = 'AGENCY_EMLI';
newRecord.author = 'EMLI';
newRecord.legislation = [{ ...legislation }];
newRecord.dateAdded = new Date();
diff --git a/api/src/integrations/nris-epd/datasource.js b/api/src/integrations/nris-epd/datasource.js
index 96fb14b78..80dcd5833 100644
--- a/api/src/integrations/nris-epd/datasource.js
+++ b/api/src/integrations/nris-epd/datasource.js
@@ -201,7 +201,7 @@ class NrisDataSource {
// Re-write the issuing agency from Environmental Protection Office => Ministry of Environment and Climate Change Strategy
stringTransformEPOtoEPD(agency) {
- return agency === 'Environmental Protection Office' ? 'Ministry of Environment and Climate Change Strategy' : agency;
+ return agency === 'Environmental Protection Office' ? 'AGENCY_ENV' : agency;
}
stringTransformExpandAMP(inspctResponse) {
@@ -312,7 +312,7 @@ class NrisDataSource {
];
if (record.requirementSource === 'Greenhouse Gas Industrial Reporting and Control Act') {
- newRecord.issuingAgency = 'Climate Action Secretariat';
+ newRecord.issuingAgency = 'AGENCY_CAS';
} else {
if (record.authorization && record.authorization.sourceId) {
descriptions.splice(1, 0, `Authorization Number: ${record.authorization.sourceId}`);
@@ -322,9 +322,22 @@ class NrisDataSource {
descriptions.push(`Waste Discharge Type: ${record.wasteType.join(', ')}`);
}
}
-
+
newRecord.description = descriptions.join('; ');
+
+ // Catch any other issuing agencies that haven't been transformed.
+ // Update the issuing agency based on the mapping.
+ const agencyMapping = {
+ 'FLNRO': 'AGENCY_FLNRO',
+ 'Environmental Assessment Office': 'AGENCY_EAO'
+ };
+ if (newRecord.issuingAgency in agencyMapping) {
+ newRecord.issuingAgency = agencyMapping[newRecord.issuingAgency];
+ } else if (record.issuingAgency in agencyMapping) {
+ newRecord.issuingAgency = agencyMapping[record.issuingAgency];
+ }
+
defaultLog.info('Processed:', record.assessmentId);
return newRecord;
}
diff --git a/api/src/integrations/nris-epd/datasource.test.js b/api/src/integrations/nris-epd/datasource.test.js
index a1d853ff0..3adbeb40a 100644
--- a/api/src/integrations/nris-epd/datasource.test.js
+++ b/api/src/integrations/nris-epd/datasource.test.js
@@ -1,4 +1,62 @@
const NrisDataSource = require('./datasource');
+const mockingoose = require('mockingoose');
+
+const _nrisInspectionDocument = {
+ _id: '507f191e810c19729de860ea',
+ attachment: [],
+ assessmentId: 1234,
+ requirementSource: 'Greenhouse Gas Industrial Reporting and Control Act',
+ authorization: {
+ sourceId: 1234
+ },
+ inspection: {
+ inspctReportSentDate: new Date(),
+ inspectionType: ['Electrical']
+ },
+ location: {
+ locationName: 'My location',
+ latitude: 48.407326,
+ longitude: -123.329773
+ }
+};
+
+const _nrisInspectionDocument_FLNRO = {
+ _id: '507f191e810c19729de860ea',
+ attachment: [],
+ assessmentId: 1234,
+ issuingAgency: 'FLNRO',
+ authorization: {
+ sourceId: 1234
+ },
+ inspection: {
+ inspctReportSentDate: new Date(),
+ inspectionType: ['Electrical']
+ },
+ location: {
+ locationName: 'My location',
+ latitude: 48.407326,
+ longitude: -123.329773
+ }
+};
+
+const _nrisInspectionDocument_EAO = {
+ _id: '507f191e810c19729de860ea',
+ attachment: [],
+ assessmentId: 1234,
+ issuingAgency: 'Environmental Assessment Office',
+ authorization: {
+ sourceId: 1234
+ },
+ inspection: {
+ inspctReportSentDate: new Date(),
+ inspectionType: ['Electrical']
+ },
+ location: {
+ locationName: 'My location',
+ latitude: 48.407326,
+ longitude: -123.329773
+ }
+};
describe('NrisDataSource', () => {
describe('constructor', () => {
@@ -22,4 +80,22 @@ describe('NrisDataSource', () => {
expect(dataSource).toEqual({ auth_payload: undefined, params: {} });
});
});
+
+ describe('transformRecord', () => {
+ it.each([
+ [_nrisInspectionDocument, 'AGENCY_CAS'],
+ [_nrisInspectionDocument_FLNRO, 'AGENCY_FLNRO'],
+ [_nrisInspectionDocument_EAO, 'AGENCY_EAO']
+ ])('should return the appropriate agency code', async (record, expectedAgency) => {
+ const dataSource = new NrisDataSource();
+ // eslint-disable-next-line no-unused-vars
+ const Inspection = require('../../models/master/inspection');
+
+ mockingoose('Inspection').toReturn(record, 'findOne');
+ const doc = await dataSource.transformRecord(record);
+ expect(doc.fileName).toEqual(record.fileName);
+ expect(doc.issuingAgency).toEqual(expectedAgency);
+ });
+ });
+
});
diff --git a/api/src/utils/constants/misc.js b/api/src/utils/constants/misc.js
index 57465b82a..e64a617f5 100644
--- a/api/src/utils/constants/misc.js
+++ b/api/src/utils/constants/misc.js
@@ -69,9 +69,9 @@ exports.IssuedToEntityTypes = {
};
exports.CoorsCsvIssuingAgencies = {
- BC_Parks: 'BC Parks',
- Conservation_Officer_Service: 'Conservation Officer Service',
- Water_Sustainability_Act: 'BC Energy Regulator'
+ BC_Parks: 'AGENCY_ENV_BCPARKS',
+ Conservation_Officer_Service: 'AGENCY_ENV_COS',
+ Water_Sustainability_Act: 'AGENCY_OGC'
};
exports.EpicProjectIds = {