Skip to content

Commit

Permalink
NRPT-777 Update NRIS-EMLI Importer (#901)
Browse files Browse the repository at this point in the history
* NRPT-777 Update NRIS-EMLI Importer

* Add configurable app urls
  • Loading branch information
BcGovNeal authored Aug 19, 2021
1 parent e003466 commit c2ab63e
Show file tree
Hide file tree
Showing 18 changed files with 387 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ <h4>Import from Source System</h4>
<div>
<button
type="button"
[disabled]="buttonActions['nris-emli']"
[disabled]="buttonActions['nris-emli-importer']"
class="btn btn-primary"
(click)="startJob('nris-emli')"
title="Start EMLI import job">
Expand Down
23 changes: 22 additions & 1 deletion angular/projects/public-nrpti/src/app/app.component.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Component, OnInit, ChangeDetectorRef } from '@angular/core';
import { Router } from '@angular/router';
import { IBreadcrumb, LoadingScreenService } from 'nrpti-angular-components';
import { IBreadcrumb, LoadingScreenService, StoreService } from 'nrpti-angular-components';
import { FactoryService } from './services/factory.service';

@Component({
selector: 'app-root',
Expand All @@ -17,6 +18,8 @@ export class AppComponent implements OnInit {
constructor(
private router: Router,
private loadingScreenService: LoadingScreenService,
private factoryService: FactoryService,
private storeService: StoreService,
private _changeDetectionRef: ChangeDetectorRef
) {
this.breadcrumbs = [];
Expand All @@ -39,6 +42,24 @@ export class AppComponent implements OnInit {
break;
}
this._changeDetectionRef.detectChanges();

this.updateMines();
});
}

private updateMines() {
this.factoryService.getMines().subscribe((mineResults: any[]) => {
this.setStoreServiceItem('mines', mineResults[0].data.searchResults);
});
}

// Sets a store service list item, but unshifts a null-based element first.
private setStoreServiceItem(key, list) {
// First unshift an item into the list.
list.unshift({ _id: null, name: 'None' });

// Set the object in the store service
const newObject = { [key]: list };
this.storeService.setItem(newObject);
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,20 @@
import { TestBed } from '@angular/core/testing';
import { HttpClientTestingModule } from '@angular/common/http/testing';

import { StoreService, ConfigService } from 'nrpti-angular-components';
import { ProjectLinkPipe } from './project-link.pipe';

describe('LinkifyPipe', () => {
describe('ProjectLinkPipe', () => {
beforeEach(() => {
TestBed.configureTestingModule({
imports: [HttpClientTestingModule],
providers: [StoreService, ConfigService, ProjectLinkPipe]
});
});

it('create an instance', () => {
const pipe = new ProjectLinkPipe();
const pipe: ProjectLinkPipe = TestBed.get(ProjectLinkPipe);

expect(pipe).toBeTruthy();
});
});
33 changes: 28 additions & 5 deletions angular/projects/public-nrpti/src/app/pipes/project-link.pipe.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { Pipe, PipeTransform } from '@angular/core';

import { StoreService, ConfigService, LoggerService } from 'nrpti-angular-components';

/**
* Replace project names with links to LNG or CGL sites
*
Expand All @@ -9,17 +11,38 @@ import { Pipe, PipeTransform } from '@angular/core';
*/
@Pipe({ name: 'projectLink' })
export class ProjectLinkPipe implements PipeTransform {
constructor(
private storeService: StoreService,
private configService: ConfigService,
private logger: LoggerService
) {}

transform(str: string): string {
if (!str) {
return '';
}

if (str === 'LNG Canada') {
return `<a href="https://lng.gov.bc.ca/project/1/overview" target="_blank">${str}</a>`;
}
try {
const env = this.configService.config.ENVIRONMENT;
const lngUrl = this.configService.config.APPLICATION_URLS.lng[env];
const bcmiUrl = this.configService.config.APPLICATION_URLS.bcmi[env];

const mines = this.storeService.getItem('mines') || [];
const bcmiMine = mines.find(mine => mine.name === str);

if (str === 'LNG Canada') {
return `<a href="${lngUrl}/project/1/overview" target="_blank">${str}</a>`;
}

if (str === 'Coastal Gaslink') {
return `<a href="${lngUrl}/project/2/overview" target="_blank">${str}</a>`;
}

if (str === 'Coastal Gaslink') {
return `<a href="https://lng.gov.bc.ca/project/2/overview" target="_blank">${str}</a>`;
if (bcmiMine) {
return `<a href="${bcmiUrl}/p/${bcmiMine._id}/overview" target="_blank">${str}</a>`;
}
} catch {
this.logger.error('Error determining application URLs.');
}

return str;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { HttpClientTestingModule } from '@angular/common/http/testing';

import { AdministrativePenaltyDetailComponent } from './administrative-penalty-detail.component';
import { ActivatedRoute, Router } from '@angular/router';
Expand All @@ -16,7 +17,7 @@ describe('AdministrativePenaltyDetailComponent', () => {

beforeEach(() => {
TestBed.configureTestingModule({
imports: [GlobalModule, CommonModule],
imports: [GlobalModule, CommonModule, HttpClientTestingModule],
declarations: [AdministrativePenaltyDetailComponent, ProjectLinkPipe],
providers: [
{ provide: ActivatedRoute, useValue: activedRouteStub },
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { HttpClientTestingModule } from '@angular/common/http/testing';

import { AdministrativeSanctionDetailComponent } from './administrative-sanction-detail.component';
import { ActivatedRoute, Router } from '@angular/router';
Expand All @@ -16,7 +17,7 @@ describe('AdministrativeSanctionDetailComponent', () => {

beforeEach((() => {
TestBed.configureTestingModule({
imports: [GlobalModule, CommonModule],
imports: [GlobalModule, CommonModule, HttpClientTestingModule],
declarations: [AdministrativeSanctionDetailComponent, ProjectLinkPipe],
providers: [
{ provide: ActivatedRoute, useValue: activedRouteStub },
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { HttpClientTestingModule } from '@angular/common/http/testing';

import { CourtConvictionDetailComponent } from './court-conviction-detail.component';
import { ActivatedRoute, Router } from '@angular/router';
Expand All @@ -16,7 +17,7 @@ describe('CourtConvictionDetailComponent', () => {

beforeEach((() => {
TestBed.configureTestingModule({
imports: [GlobalModule, CommonModule],
imports: [GlobalModule, CommonModule, HttpClientTestingModule],
declarations: [CourtConvictionDetailComponent, ProjectLinkPipe],
providers: [
{ provide: ActivatedRoute, useValue: activedRouteStub },
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { HttpClientTestingModule } from '@angular/common/http/testing';

import { InspectionDetailComponent } from './inspection-detail.component';
import { ActivatedRoute, Router } from '@angular/router';
Expand All @@ -18,7 +19,8 @@ describe('InspectionDetailComponent', () => {
TestBed.configureTestingModule({
imports: [
GlobalModule,
CommonModule
CommonModule,
HttpClientTestingModule
],
declarations: [
InspectionDetailComponent,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { HttpClientTestingModule } from '@angular/common/http/testing';

import { OrderDetailComponent } from './order-detail.component';
import { ActivatedRoute, Router } from '@angular/router';
Expand All @@ -18,7 +19,8 @@ describe('OrderDetailComponent', () => {
TestBed.configureTestingModule({
imports: [
GlobalModule,
CommonModule
CommonModule,
HttpClientTestingModule
],
declarations: [OrderDetailComponent, ProjectLinkPipe],
providers: [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { HttpClientTestingModule } from '@angular/common/http/testing';

import { RestorativeJusticeDetailComponent } from './restorative-justice-detail.component';
import { ActivatedRoute, Router } from '@angular/router';
Expand All @@ -16,7 +17,7 @@ describe('RestorativeJusticeDetailComponent', () => {

beforeEach((() => {
TestBed.configureTestingModule({
imports: [GlobalModule, CommonModule],
imports: [GlobalModule, CommonModule, HttpClientTestingModule],
declarations: [RestorativeJusticeDetailComponent, ProjectLinkPipe],
providers: [
{ provide: ActivatedRoute, useValue: activedRouteStub },
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { HttpClientTestingModule } from '@angular/common/http/testing';

import { TicketDetailComponent } from './ticket-detail.component';
import { ActivatedRoute, Router } from '@angular/router';
Expand All @@ -16,7 +17,7 @@ describe('TicketDetailComponent', () => {

beforeEach((() => {
TestBed.configureTestingModule({
imports: [GlobalModule, CommonModule],
imports: [GlobalModule, CommonModule, HttpClientTestingModule],
declarations: [TicketDetailComponent, ProjectLinkPipe],
providers: [
{ provide: ActivatedRoute, useValue: activedRouteStub },
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { HttpClientTestingModule } from '@angular/common/http/testing';

import { WarningDetailComponent } from './warning-detail.component';
import { ActivatedRoute, Router } from '@angular/router';
Expand All @@ -15,7 +16,7 @@ describe('WarningDetailComponent', () => {

beforeEach((() => {
TestBed.configureTestingModule({
imports: [GlobalModule],
imports: [GlobalModule, HttpClientTestingModule],
declarations: [WarningDetailComponent, ProjectLinkPipe],
providers: [
{ provide: ActivatedRoute, useValue: activedRouteStub },
Expand Down
10 changes: 10 additions & 0 deletions angular/projects/public-nrpti/src/app/services/factory.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,16 @@ export class FactoryService {
});
}

/**
* Get list of BCMI Mines
*
* @returns {Observable<any[]>}
* @memberof FactoryService
*/
public getMines(): Observable<any[]> {
return this.getRecords(null, ['MineBCMI'], null, null, 1000, null, null, null, null);
}

// public getFullList(schema: string): Observable<Record[]> {
// return this.searchService.getFullList(schema);
// }
Expand Down
48 changes: 48 additions & 0 deletions api/migrations/20210812165533-removeOldEmliRecords.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
'use strict';

// list all collections that require this migration
const collections = ['nrpti', 'redacted_record_subset'];

/**
* We receive the dbmigrate dependency from dbmigrate initially.
* This enables us to not have to rely on NODE_PATH.
*/
exports.setup = function(options, seedLink) {};

exports.up = async function(db) {
console.log('**** Deleting existing EMLI records ****');

const mClient = await db.connection.connect(db.connectionString, {
native_parser: true
});

try {
for (const collection of collections) {
try {
const dbCollection = await mClient.collection(collection);

const result = await dbCollection.deleteMany({ sourceSystemRef: 'nris-emli' });

console.log(`Deleted ${result.deletedCount} records from ${collection}`);
} catch (err) {
console.log(`Error deleting records (${collection}): ${err}`);
}
}

console.log(`**** Finished deleting existing EMLI records ****`);
} catch (err) {
console.log(`Error deleting records: ${err}`);
} finally {
mClient.close();
}

return null;
};

exports.down = function(db) {
return null;
};

exports._meta = {
version: 1
};
53 changes: 53 additions & 0 deletions api/migrations/20210816170601-addApplicationUrls.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
'use strict';
/**
* We receive the dbmigrate dependency from dbmigrate initially.
* This enables us to not have to rely on NODE_PATH.
*/
exports.setup = function(options, seedLink) {};

exports.up = async function(db) {
console.log('**** Adding app URLs ****');
const mClient = await db.connection.connect(db.connectionString, { native_parser: true });

try {
const nrpti = await mClient.collection('nrpti');
await nrpti.insertOne({
_schemaName: 'ApplicationUrl',
data: {
bcmi: {
dev: 'https://bcmi-f00029-dev.apps.silver.devops.gov.bc.ca',
test: 'https://bcmi-f00029-test.apps.silver.devops.gov.bc.ca',
prod: 'https://mines.nrs.gov.bc.ca'
},
nrced: {
dev: 'https://nrced-f00029-test.apps.silver.devops.gov.bc.ca',
test: 'https://nrced-f00029-test.apps.silver.devops.gov.bc.ca',
prod: 'https://nrced.gov.bc.ca'
},
lng: {
dev: 'https://lng-f00029-test.apps.silver.devops.gov.bc.ca',
test: 'https://lng-f00029-test.apps.silver.devops.gov.bc.ca',
prod: 'https://lng.gov.bc.ca'
},
nrpti: {
dev: 'https://nrpti-f00029-dev.apps.silver.devops.gov.bc.ca',
test: 'https://nrpti-f00029-test.apps.silver.devops.gov.bc.ca',
prod: 'https://nrpti-f00029-prod.apps.silver.devops.gov.bc.ca'
}
}
});
console.log('**** Finished adding app URLs ****');
} catch (error) {
console.error(`Migration did not complete. Error processing records: ${error.message}`);
}

mClient.close();
};

exports.down = function(db) {
return null;
};

exports._meta = {
version: 1
};
5 changes: 5 additions & 0 deletions api/src/controllers/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ exports.publicGetConfig = async function (args, res, next) {
configurationData['FEATURE_FLAG'] = featureFlags.data;
}

const appUrls = await FeatureFlag.findOne({ _schemaName: 'ApplicationUrl' });
if (appUrls && appUrls.data) {
configurationData['APPLICATION_URLS'] = appUrls.data;
}

// get project specific confguration
// fetch the latest business area specific CommunicationPackage
// attach it to the configuration data under "COMMUNICATIONS"
Expand Down
Loading

0 comments on commit c2ab63e

Please sign in to comment.