Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NRPT-117: Adds Permit and Amendment import with flavours #467

Merged
merged 6 commits into from
Jul 3, 2020

Conversation

KitArmstrong
Copy link
Contributor

Ticket: https://bcmines.atlassian.net/browse/NRPT-117

This updates the Core importer to create Permits and PermitAmendments for all Mine records. Mines are only created as a BCMI flavour (previous change, not this ticket), but the Permits and PermitAmendments have both master and BCMI flavours. This is because it might be required to share this data in the future, especially the permit as it does exist for LNG.

If running the importer against the Core Prod API (recommended) there will be about 15 records that it errors on. This is expected and should be logged to the console.


dateAdded: { type: Date, default: Date.now() },
dateUpdated: { type: Date, default: null },
datePublished: { type: Date, default: null },
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can remove the datePublished and publishedBy from the master record, as they should never themselves get published.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed from master.


addedBy: { type: String, default: '' },
updatedBy: { type: String, default: '' },
publishedBy: { type: String, default: '' },
Copy link
Contributor

@NickPhura NickPhura Jul 3, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could add sourceDateAdded and sourceDateUpdated to be consistent with the other types. Same goes for the bcmi flavour version of the models, though I'm not sure if we use them ever, so maybe there is an argument for leaving them out of the flavour models.

Also, probably need to add isBcmiPublished ? This would be in alignment with the other types, though I'm not sure how collections influences this, if it does.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added isBcmiPublished to permit and permit amendments. I don't capture the source date information as none of that is returned by the Core API.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't capture the source date information as none of that is returned by the Core API.

Yeah, fair enough then

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you add it here, isBcmiPublished needs to be done for all other master records in order to facilitate search on the admin page.

permitNumber: { type: String, default: '' },
status: { type: String, default: '' },
permitAmendments: [{ type: 'ObjectId', default: [], index: true }],

Copy link
Contributor

@NickPhura NickPhura Jul 3, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For line 48, though apparently I cant add a comment there, not sure why: Similar to my below comment, could add isBcmiPublished to align with the other models, though not sure how collections impacts this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added.

read: [{ type: String, trim: true, default: 'sysadmin' }],
write: [{ type: String, trim: true, default: 'sysadmin' }],

mineGuid: { type: String, default: '' },
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Open question: do we need to include all of the other Permit fields here as well? Our other records always copy all of the master fields, regardless of whether or not they get shown on the frontends. But maybe that isn't necessary? Not sure

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was talking to @marklise about this and opted to follow what the others have done. However, I would think they should just live on the flavour.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I understand what you said correctly (possibly I don't), then we DO want to add all of the other permit fields here? recordName, dateIssued, legislation, etc.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh sorry, I thought this was on the master. Umm, to me it seems unnecessary on the flavour, but maybe there was a reason it was done before. Do you think they should be? Would they be used for anything?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think they should be? Would they be used for anything?

Not sure. Trying to think if there is a good reason to include them, other than just because that is what was done in past.

The only thing that comes to mind, is if we wanted to use those other values for filtering/searching.
On LNG, we don't show that many fields, but some of them get used for searching/filtering. BCMI in theory might be similar, though with collections, its harder to say, since now we aren't directly querying for bcmi records from the public site.

So not sure :/

I guess given that we have no current reason to change it, we can just leave it as is, and always migrate it over in future if it becomes necessary for w/e reason

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, that sounds good.

Comment on lines 48 to 50
receivedDate: (amendment.received_date && new Date(amendment.received_date)) || null,
issueDate: (amendment.issue_date && new Date(amendment.issue_date)) || null,
authorizedEndDate: (amendment.authorized_end_date && new Date(amendment.authorized_end_date)) || null,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably a nit: Assuming the dateString is in a valid form, we could probably just set it directly without calling new Date()?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updating.

Comment on lines 421 to 425
// Update the amendments and permit.
const transformedAmendments = await permitAmendmentUtils.transformRecords(permit);
// To trigger flavour for this import.
const preparedAmendments = transformedAmendments.map(amendment => ({ ...amendment, PermitAmendmentBCMI: {} }))
const updatedAmendments = await permitAmendmentUtils.updateRecord(preparedAmendments);
Copy link
Contributor

@NickPhura NickPhura Jul 3, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to be performing an update to an existing Permit, but have new amendments that need to get created?
If it is, then would probably need to do the findExisting check here first, and then call either permitAmendmentUtils update/create.

And then related, are we missing a put controller for permit-amendments?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call. Updated to handle an update and create.

@@ -0,0 +1,74 @@
const mongoose = require('mongoose');
Copy link
Contributor

@NickPhura NickPhura Jul 3, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we still have the concept of a mine-permit, or is this replaced by permit and permit-amendment?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do not. Removed.

@KitArmstrong
Copy link
Contributor Author

KitArmstrong commented Jul 3, 2020

@NickPhura Addressed your comments.

@NickPhura
Copy link
Contributor

@NickPhura Addressed your comments.

Sweet, will give it another look over in a bit here

Copy link
Contributor

@dhlevi dhlevi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 That was a lot of work! Tests are passing, looks like enums are updated with the new flavour info, consistent naming with the *BCMI postfix. Looks good!

@NickPhura
Copy link
Contributor

@KitArmstrong I tried running the core importer, but got a 503 error. It looks like I did successfully got an api token (says it expires in 16 hours), but then the subsequent calls to get verified mines, etc, returned 503.

I've got all of the env vars set up for Core Test. Maybe it is down? Or is there possibly some other config I am missing?

Ill mess with it a bit more though and see what I come up with

@NickPhura
Copy link
Contributor

NickPhura commented Jul 3, 2020

I know this is a known side effect of Core not supplying any of the 'normal' Permit values, but we'll probably want to put some kind of canned data into some of these fields, so it doesn't render empty like this (see screenshot).

Probably this is something that UX/PO folks need to think about, so maybe can be its own ticket. Assuming they feel the same way of course.

image

Copy link
Contributor

@marklise marklise left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. We got a few tickets to make for other things that weren't caught during refinement.

Copy link
Contributor

@NickPhura NickPhura left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ran the importer a couple of times, appears to work as expected.
Tests all pass.

Nice one!
👍

Editing my Edit: never mind what I had previously. It is correct!

@KitArmstrong KitArmstrong merged commit 3ea4972 into bcgov:master Jul 3, 2020
@KitArmstrong KitArmstrong deleted the permitImport branch July 3, 2020 22:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants