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

SIMSBIOHUB-426: Calculate Submission Regions #231

Closed
wants to merge 201 commits into from
Closed
Show file tree
Hide file tree
Changes from 197 commits
Commits
Show all changes
201 commits
Select commit Hold shift + click to select a range
311b448
DatasetListPage with download functionality and DatasetSortMenu for s…
MacQSL Dec 5, 2023
53f7b63
Add security_review_timestamp to submission table.
NickPhura Dec 6, 2023
856d070
update spatial validation to Collection
KjartanE Dec 6, 2023
d0ee898
implemented fuzzy search with search selection highlighting
MacQSL Dec 7, 2023
0f5309c
added debounce (input delay) for fuzzy search filtering / highlighting
MacQSL Dec 7, 2023
1668355
rework dataset page, new api endpoint
KjartanE Dec 8, 2023
97ed8ea
stubbing out basic menu
al-rosenthal Dec 8, 2023
b001aef
Merge branch 'SIMSBIOHUB-397' into dataset_security_feature
al-rosenthal Dec 8, 2023
4fc3a1b
added button icons
al-rosenthal Dec 8, 2023
6d3c0ff
WIP
NickPhura Dec 8, 2023
d7c9192
refactored code to be more submission centric
MacQSL Dec 8, 2023
216b747
Merge branch 'SIMSBIOHUB-393' into dataset_security_feature
MacQSL Dec 8, 2023
07cee57
Update migrations/seeds
NickPhura Dec 8, 2023
b8152cc
Merge branch 'dataset_security_feature' into SIMSBIOHUB-382
NickPhura Dec 8, 2023
25f805c
added unsecure dialog
al-rosenthal Dec 8, 2023
0ab7a28
Merge branch 'SIMSBIOHUB-397' into dataset_security_feature
al-rosenthal Dec 8, 2023
e827ac2
Update submission table to add name/description.
NickPhura Dec 8, 2023
b2aa40e
Merge branch 'dataset_security_feature' of https://github.com/bcgov/b…
NickPhura Dec 8, 2023
62154ba
Add SubmissionRecord type.
NickPhura Dec 8, 2023
101b60c
added tests for useDebounce and useFuzzySearch
MacQSL Dec 8, 2023
3182066
Merge branch 'SIMSBIOHUB-393' into dataset_security_feature
MacQSL Dec 8, 2023
6f7943d
Change name of data loader
NickPhura Dec 8, 2023
6bc56b8
stubbing out more of the UI
al-rosenthal Dec 8, 2023
92fec5a
Merge branch 'dataset_security_feature' into SIMSBIOHUB-397
al-rosenthal Dec 8, 2023
b36e332
Add admin reviewed submissions endpoint/service/repo
NickPhura Dec 8, 2023
e00a59e
added path for submission and index endpoint
MacQSL Dec 8, 2023
0e2b034
Update security migration
NickPhura Dec 8, 2023
c8157e0
Merge branch 'dataset_security_feature' of https://github.com/bcgov/b…
NickPhura Dec 8, 2023
ce87803
fixed submission merge conflict
MacQSL Dec 9, 2023
6eae1a2
Merge branch 'dataset_security_feature' into SIMSBIOHUB-397
al-rosenthal Dec 9, 2023
a07f86a
adding basic endpoint for fetching rules
al-rosenthal Dec 9, 2023
ace08d2
add submission context and review page
KjartanE Dec 9, 2023
f6f7964
updated sql for getReviewedSubmissionsWithSecurity to handle security…
MacQSL Dec 9, 2023
6186468
fixed test suite compilation issues
MacQSL Dec 11, 2023
f08a81b
added seed file, stubbed out api changes
al-rosenthal Dec 11, 2023
9961059
Merge branch 'dataset_security_feature' into SIMSBIOHUB-397
al-rosenthal Dec 11, 2023
8e3e2d3
oops
al-rosenthal Dec 11, 2023
5701ad1
added tests for submission /repo/service/endpoint
MacQSL Dec 11, 2023
49636ee
Merge branch 'SIMSBIOHUB-393' into dataset_security_feature
MacQSL Dec 11, 2023
d6f1dab
Fix tests, add message get/create api
NickPhura Dec 11, 2023
816606c
Merge remote-tracking branch 'origin/dataset_security_feature' into S…
NickPhura Dec 11, 2023
3674e83
Update tests
NickPhura Dec 11, 2023
aac0f78
fetching rules
al-rosenthal Dec 11, 2023
51126e8
admin submission preview page, datagrid setup
KjartanE Dec 11, 2023
88c8402
Updates
NickPhura Dec 11, 2023
a63a2f6
objects are selectable
al-rosenthal Dec 11, 2023
36912d4
UI WIP
jeznorth Dec 11, 2023
20d602e
began wrapping autocomplete in field array
al-rosenthal Dec 11, 2023
6a238f3
updated seed for submissions and added trigger to submission_feature_…
MacQSL Dec 11, 2023
a6e1975
Wire up dashboard (submission to review) UI
NickPhura Dec 11, 2023
7d77ca1
Change date format
NickPhura Dec 11, 2023
5f942dd
wrapped autocomplete in field array
al-rosenthal Dec 12, 2023
ebcb1f1
text clean up
al-rosenthal Dec 12, 2023
6b9c797
Merge branch 'SIMSBIOHUB-397' into dataset_security_feature
al-rosenthal Dec 12, 2023
58a8a4e
Remove unique constrain on uuid from submission table
NickPhura Dec 12, 2023
34f4183
stubbing out api
al-rosenthal Dec 12, 2023
7b9e4ce
resolving comments
al-rosenthal Dec 12, 2023
b5ec2b3
Implement Skeleton Loader / Layout Updates
jeznorth Dec 12, 2023
006ec9c
Merge branch 'SIMSBIOHUB-382' of https://github.com/bcgov/biohubbc-pl…
jeznorth Dec 12, 2023
5221ee8
Empty state UI Dev
jeznorth Dec 12, 2023
8c98fe6
Adding subtext to empty state
jeznorth Dec 12, 2023
c64e71f
Add tabs and completed review page
NickPhura Dec 12, 2023
362639a
Merge branch 'SIMSBIOHUB-382' of https://github.com/bcgov/biohubbc-pl…
NickPhura Dec 12, 2023
730e570
Format
NickPhura Dec 12, 2023
e709bb6
Rename file
NickPhura Dec 12, 2023
53ea1bd
clean up
al-rosenthal Dec 12, 2023
fe0bd20
UI Updates
jeznorth Dec 12, 2023
b392e7b
Minor Fix
jeznorth Dec 12, 2023
cc02815
Add submitted_timestamp to submission table
NickPhura Dec 12, 2023
ceda5b2
Merge branch 'SIMSBIOHUB-382' of https://github.com/bcgov/biohubbc-pl…
NickPhura Dec 12, 2023
ac72255
hooking up api for adding security
al-rosenthal Dec 12, 2023
8550e2f
fixed add security
al-rosenthal Dec 12, 2023
d7d6dc2
Updates
NickPhura Dec 12, 2023
d169055
Merge remote-tracking branch 'origin/dataset_security_feature' into S…
NickPhura Dec 12, 2023
8c090ec
added snackbar messages for success/ fails
al-rosenthal Dec 12, 2023
6cbd21d
Run Fix
NickPhura Dec 12, 2023
4c2962e
Merge branch 'dataset_security_feature' into SIMSBIOHUB-397
al-rosenthal Dec 12, 2023
238e1b1
submission datagrids setup
KjartanE Dec 13, 2023
2efceef
Merge remote-tracking branch 'origin/dataset_security_feature' into S…
KjartanE Dec 13, 2023
794ac4b
stubbing out unsecure flow
al-rosenthal Dec 13, 2023
fbe9d91
wired up unsecured and fixed close dialog
al-rosenthal Dec 13, 2023
5fe45f9
add button to admin submission page
KjartanE Dec 13, 2023
100d480
Merge branch 'SIMSBIOHUB-397' into dataset_security_feature
al-rosenthal Dec 13, 2023
e9df0b3
created new action card for security rules
al-rosenthal Dec 13, 2023
fa79a8d
swapped out data loader, got autocomplete working
al-rosenthal Dec 13, 2023
89ee5ab
Merge branch 'dataset_security_feature' into SIMSBIOHUB-397
al-rosenthal Dec 13, 2023
1aeccd4
removed field array
al-rosenthal Dec 13, 2023
f494dba
added clear on select to autocomplete
al-rosenthal Dec 13, 2023
46c405d
clean up
al-rosenthal Dec 13, 2023
aa3fb3d
moved security button to correct page
al-rosenthal Dec 13, 2023
e5bec22
clean up + interfaces
KjartanE Dec 13, 2023
8c590e2
Merge remote-tracking branch 'origin/dataset_security_feature' into S…
KjartanE Dec 13, 2023
40dd165
updated labels and added total features to security dialog
al-rosenthal Dec 13, 2023
c73e4ec
clean up
al-rosenthal Dec 13, 2023
68adef6
clean mock data
KjartanE Dec 13, 2023
557b666
stubbing out more API changes
al-rosenthal Dec 13, 2023
7eef96d
added unique constraint for simpler insert actions
al-rosenthal Dec 14, 2023
358b867
stubbing out last set of changes
al-rosenthal Dec 14, 2023
7d66cc6
moved some security calls into context, added banner for warning of s…
al-rosenthal Dec 14, 2023
e310ec1
Add security review feature
NickPhura Dec 14, 2023
990d05b
Update interfaces
NickPhura Dec 14, 2023
0af3140
Merge branch 'SIMSBIOHUB-383' into dataset_security_feature
NickPhura Dec 14, 2023
18846ad
Publish security review update
NickPhura Dec 14, 2023
fa453ea
Tweak code and fix test.
NickPhura Dec 14, 2023
0d9e4fd
Add more specific openapi spec.
NickPhura Dec 15, 2023
c9751e4
Remove .only
NickPhura Dec 15, 2023
57d6c48
moved call for older securities
al-rosenthal Dec 15, 2023
7909825
Remove package
NickPhura Dec 15, 2023
77d2031
adding tests
al-rosenthal Dec 15, 2023
92502b9
Merge branch 'dataset_security_feature' into SIMSBIOHUB-397
al-rosenthal Dec 15, 2023
16d7402
fixed everything after merge
al-rosenthal Dec 15, 2023
f814c33
Add sort columns
NickPhura Dec 15, 2023
1e134d1
added codeContext and featureTypes
KjartanE Dec 16, 2023
498d287
codes utilization for feature type/properties
KjartanE Dec 18, 2023
634d02f
Biohub UI Updates (#213)
jeznorth Dec 19, 2023
6a6b04b
fixed UX on security management menu
al-rosenthal Dec 19, 2023
0f43510
increase test coverage. Endpoints/service/repo
KjartanE Dec 19, 2023
705a088
Header Improvements (#214)
curtisupshall Dec 19, 2023
73712af
Fixed header bugs
curtisupshall Dec 19, 2023
e390bb4
Resolve react dependency warnings.
NickPhura Dec 20, 2023
74ea7ea
Merge branch 'dataset_security_feature' of https://github.com/bcgov/b…
NickPhura Dec 20, 2023
8e4cef3
Fixed Header.test.tsx
curtisupshall Dec 20, 2023
da0a293
Lint fixes
curtisupshall Dec 20, 2023
d067274
SIMSBIOHUB-379: Parse intake key-value pairs (#211)
curtisupshall Dec 20, 2023
adbe9f8
Added VIEW button link to admin submission list page
curtisupshall Dec 20, 2023
4860383
added new colum and trigger to sql setup
al-rosenthal Dec 20, 2023
400ab9e
Merge branch 'dataset_security_feature' into SIMSBIOHUB-397
al-rosenthal Dec 20, 2023
1b955d1
Show which security rules have been applied
curtisupshall Dec 20, 2023
0cbf52f
Ran linter
curtisupshall Dec 20, 2023
cd0d41b
Update submission PATCH endpoint to accept both security_reviewed and…
NickPhura Dec 20, 2023
e755672
Merge branch 'dataset_security_feature' of https://github.com/bcgov/b…
NickPhura Dec 20, 2023
831e0f0
added security category table
al-rosenthal Dec 20, 2023
3d97f78
updated trigger message
al-rosenthal Dec 20, 2023
daa3b79
stubbed out new record
al-rosenthal Dec 20, 2023
3cfb0e3
stubbed out api changes
al-rosenthal Dec 21, 2023
44aed69
Merge branch 'dataset_security_feature' into SIMSBIOHUB-397
al-rosenthal Dec 21, 2023
d18dc67
Submission Meta Endpoint / Dataloader
KjartanE Dec 21, 2023
33d67d8
Update Security Cards to include Category
jeznorth Dec 21, 2023
0e612d9
wired up new rule category endpoint to
al-rosenthal Dec 21, 2023
202e329
Merge branch 'dataset_security_feature' into SIMSBIOHUB-397
al-rosenthal Dec 21, 2023
ab90ad3
Update reviewed/unreviewed admin endpoints.
NickPhura Dec 21, 2023
9a32c52
Merge branch 'dataset_security_feature' of https://github.com/bcgov/b…
NickPhura Dec 21, 2023
6f3f78e
stubbed out label changes
al-rosenthal Dec 21, 2023
6e438f1
Complete review publish buttons (#217)
KjartanE Dec 21, 2023
842ea2b
TechDebt: Keycloak/Auth Updates From SIMS (#216)
NickPhura Dec 21, 2023
f6eefad
Merge branch 'dataset_security_feature' into SIMSBIOHUB-397
al-rosenthal Dec 21, 2023
c91c351
Security rule contexts refactor (#218)
curtisupshall Dec 21, 2023
d40e794
Merge branch 'dataset_security_feature' into SIMSBIOHUB-397
al-rosenthal Dec 21, 2023
4571f39
Update submissions list page and related components
NickPhura Dec 21, 2023
495ea2d
Fix reference to non-existent function
NickPhura Dec 21, 2023
8e86f7e
fixed issues from merge
al-rosenthal Dec 21, 2023
f767256
Merge branch 'dataset_security_feature' into SIMSBIOHUB-397
al-rosenthal Dec 21, 2023
f772f58
Fix query
NickPhura Dec 22, 2023
219338a
Merge branch 'dataset_security_feature' of https://github.com/bcgov/b…
NickPhura Dec 22, 2023
c6f1c5e
fixed remove endpoint
al-rosenthal Dec 22, 2023
1fac269
Merge branch 'dataset_security_feature' into SIMSBIOHUB-397
al-rosenthal Dec 22, 2023
57e82f0
added label change
al-rosenthal Dec 22, 2023
6995888
Removed Add Security menu
curtisupshall Dec 22, 2023
918ef48
Indicate in snackbar if all security is removed
curtisupshall Dec 22, 2023
038e011
Added deprecation warning
curtisupshall Dec 22, 2023
e61c540
added category to search
al-rosenthal Dec 22, 2023
9144e81
Merge branch 'dataset_security_feature' of https://github.com/bcgov/b…
al-rosenthal Dec 22, 2023
bbb2c88
download submission + features
KjartanE Dec 22, 2023
6719773
added dayjs
al-rosenthal Dec 22, 2023
e975f1f
added date difference
al-rosenthal Dec 22, 2023
971da8d
Merge branch 'dataset_security_feature' into SIMSBIOHUB-397
al-rosenthal Dec 22, 2023
41acc2f
admin/published download endpoints created
KjartanE Dec 22, 2023
b26f0df
updated menus for all submissions pages and added tests for Submissio…
MacQSL Dec 28, 2023
6bf902c
added loading button to security dialog
al-rosenthal Jan 2, 2024
02bd2c3
updated tests and seed for pending review submissions
MacQSL Jan 2, 2024
050be69
updated test for submissionlistpage
MacQSL Jan 2, 2024
3ce7006
Merge branch 'feature_menus' into dataset_security_feature
MacQSL Jan 2, 2024
befe1f3
fixed date tests
al-rosenthal Jan 2, 2024
2ce0c44
Merge branch 'dataset_security_feature' of https://github.com/bcgov/b…
al-rosenthal Jan 2, 2024
8b7265a
added tests for submissionlistpage
MacQSL Jan 2, 2024
3a82a56
Merge branch 'dataset_security_feature' of https://github.com/bcgov/b…
MacQSL Jan 3, 2024
821a86a
stubbing out region table and seeds
al-rosenthal Jan 5, 2024
3ffb342
Merge branch 'dev' into SIMSBIOHUB-426
al-rosenthal Jan 5, 2024
9e9671f
make fix
al-rosenthal Jan 5, 2024
0b26cae
updated seed, got regions code working
al-rosenthal Jan 6, 2024
b109137
added calculated column and references in feature property table
al-rosenthal Jan 8, 2024
438c402
renamed table, added join table
al-rosenthal Jan 9, 2024
94ce265
stubbing out services and repo
al-rosenthal Jan 12, 2024
37e0bb7
got basic regions displaying
al-rosenthal Jan 12, 2024
303b695
added comments
al-rosenthal Jan 12, 2024
efb4e99
Merge branch 'dev' into SIMSBIOHUB-426
al-rosenthal Jan 12, 2024
29b4ce8
clean up
al-rosenthal Jan 12, 2024
88c6aa7
fixed various tests, added region repo test
al-rosenthal Jan 13, 2024
462ce6d
added more tests
al-rosenthal Jan 13, 2024
ac44599
added function for area calculation
al-rosenthal Jan 15, 2024
a690e51
added regions to completed and reviewed submission tabs
al-rosenthal Jan 15, 2024
8443440
clean up
al-rosenthal Jan 15, 2024
31d0383
Merge branch 'dev' into SIMSBIOHUB-426
al-rosenthal Jan 15, 2024
5d5df2d
ran make fix, fixed broken test
al-rosenthal Jan 16, 2024
c15e6b4
clean up
al-rosenthal Jan 16, 2024
f877084
Merge branch 'dev' into SIMSBIOHUB-426
al-rosenthal Jan 16, 2024
a23e458
clean up console logs
al-rosenthal Jan 16, 2024
c9c9dba
cleaned up bcgw code and adding some more comments
al-rosenthal Jan 16, 2024
032c750
updated comments, replaced sql with knex
al-rosenthal Jan 16, 2024
72550fb
added file back
al-rosenthal Jan 16, 2024
ef463ed
fixed bug in function with single point values
al-rosenthal Jan 17, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions api/src/paths/administrative/submission/published.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ describe('getPublishedSubmissionsForAdmins', () => {
revision_count: 0,
security: SECURITY_APPLIED_STATUS.SECURED,
root_feature_type_id: 1,
root_feature_type_name: 'dataset'
root_feature_type_name: 'dataset',
regions: []
},
{
submission_id: 2,
Expand All @@ -82,7 +83,8 @@ describe('getPublishedSubmissionsForAdmins', () => {
revision_count: 1,
security: SECURITY_APPLIED_STATUS.PARTIALLY_SECURED,
root_feature_type_id: 1,
root_feature_type_name: 'dataset'
root_feature_type_name: 'dataset',
regions: []
}
];

Expand Down
6 changes: 4 additions & 2 deletions api/src/paths/administrative/submission/reviewed.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ describe('getReviewedSubmissionsForAdmins', () => {
revision_count: 0,
security: SECURITY_APPLIED_STATUS.SECURED,
root_feature_type_id: 1,
root_feature_type_name: 'dataset'
root_feature_type_name: 'dataset',
regions: []
},
{
submission_id: 2,
Expand All @@ -82,7 +83,8 @@ describe('getReviewedSubmissionsForAdmins', () => {
revision_count: 1,
security: SECURITY_APPLIED_STATUS.PARTIALLY_SECURED,
root_feature_type_id: 1,
root_feature_type_name: 'dataset'
root_feature_type_name: 'dataset',
regions: []
}
];

Expand Down
6 changes: 4 additions & 2 deletions api/src/paths/administrative/submission/unreviewed.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ describe('getUnreviewedSubmissionsForAdmins', () => {
revision_count: 0,
security: SECURITY_APPLIED_STATUS.PENDING,
root_feature_type_id: 1,
root_feature_type_name: 'dataset'
root_feature_type_name: 'dataset',
regions: []
},
{
submission_id: 2,
Expand All @@ -82,7 +83,8 @@ describe('getUnreviewedSubmissionsForAdmins', () => {
revision_count: 1,
security: SECURITY_APPLIED_STATUS.PENDING,
root_feature_type_id: 1,
root_feature_type_name: 'dataset'
root_feature_type_name: 'dataset',
regions: []
}
];

Expand Down
9 changes: 8 additions & 1 deletion api/src/paths/administrative/submission/unreviewed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ GET.apiDoc = {
'revision_count',
'security',
'root_feature_type_id',
'root_feature_type_name'
'root_feature_type_name',
'regions'
],
properties: {
submission_id: {
Expand Down Expand Up @@ -115,6 +116,12 @@ GET.apiDoc = {
},
root_feature_type_name: {
type: 'string'
},
regions: {
type: 'array',
items: {
type: 'string'
}
}
}
}
Expand Down
28 changes: 0 additions & 28 deletions api/src/paths/dwc/submission/{datasetId}/handlebar.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ import { describe } from 'mocha';
import sinon from 'sinon';
import sinonChai from 'sinon-chai';
import * as db from '../../../../database/db';
import { HTTPError } from '../../../../errors/http-error';
import { SubmissionService } from '../../../../services/submission-service';
import { getMockDBConnection, getRequestHandlerMocks } from '../../../../__mocks__/db';
import { getHandleBarsTemplateByDatasetId } from './handlebar';

Expand All @@ -20,10 +18,6 @@ describe('handlebar', () => {
const dbConnectionObj = getMockDBConnection();
sinon.stub(db, 'getDBConnection').returns(dbConnectionObj);

sinon
.stub(SubmissionService.prototype, 'getHandleBarsTemplateByDatasetId')
.resolves({ header: 'hedaer', details: 'details' });

const { mockReq, mockRes, mockNext } = getRequestHandlerMocks();

mockReq.params = {
Expand All @@ -36,27 +30,5 @@ describe('handlebar', () => {

expect(mockRes.statusValue).to.equal(200);
});

it('catches and re-throws an error', async () => {
const dbConnectionObj = getMockDBConnection();
sinon.stub(db, 'getDBConnection').returns(dbConnectionObj);

sinon.stub(SubmissionService.prototype, 'getHandleBarsTemplateByDatasetId').rejects(new Error('a test error'));

const { mockReq, mockRes, mockNext } = getRequestHandlerMocks();

mockReq.params = {
datasetId: 'abcd'
};

try {
const requestHandler = getHandleBarsTemplateByDatasetId();

await requestHandler(mockReq, mockRes, mockNext);
expect.fail();
} catch (actualError) {
expect((actualError as HTTPError).message).to.equal('a test error');
}
});
});
});
9 changes: 4 additions & 5 deletions api/src/paths/dwc/submission/{datasetId}/handlebar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { RequestHandler } from 'express';
import { Operation } from 'express-openapi';
import { getAPIUserDBConnection, getDBConnection } from '../../../../database/db';
import { defaultErrorResponses } from '../../../../openapi/schemas/http-responses';
import { SubmissionService } from '../../../../services/submission-service';
import { getLogger } from '../../../../utils/logger';

const defaultLog = getLogger('paths/dwc/eml/{datasetId}/handlebar');
Expand Down Expand Up @@ -60,18 +59,18 @@ export function getHandleBarsTemplateByDatasetId(): RequestHandler {
return async (req, res) => {
const connection = req['keycloak_token'] ? getDBConnection(req['keycloak_token']) : getAPIUserDBConnection();

const datasetId = String(req.params.datasetId);
// const datasetId = String(req.params.datasetId);

try {
await connection.open();

const submissionService = new SubmissionService(connection);
// const submissionService = new SubmissionService(connection);

const result = await submissionService.getHandleBarsTemplateByDatasetId(datasetId);
// const result = await submissionService.getHandleBarsTemplateByDatasetId(datasetId);

await connection.commit();

res.status(200).json(result);
res.status(200).json('');
} catch (error) {
defaultLog.error({ label: 'getHandleBarsTemplateByDatasetId', message: 'error', error });
await connection.rollback();
Expand Down
6 changes: 6 additions & 0 deletions api/src/paths/submission/intake.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import sinonChai from 'sinon-chai';
import * as db from '../../database/db';
import { HTTPError } from '../../errors/http-error';
import { SystemUser } from '../../repositories/user-repository';
import { RegionService } from '../../services/region-service';
import { SearchIndexService } from '../../services/search-index-service';
import { SubmissionService } from '../../services/submission-service';
import { ValidationService } from '../../services/validation-service';
Expand Down Expand Up @@ -101,6 +102,10 @@ describe('intake', () => {
.stub(SearchIndexService.prototype, 'indexFeaturesBySubmissionId')
.resolves();

const calculateAndAddRegionsForSubmissionStub = sinon
.stub(RegionService.prototype, 'calculateAndAddRegionsForSubmission')
.resolves();

const requestHandler = intake.submissionIntake();

const { mockReq, mockRes, mockNext } = getRequestHandlerMocks();
Expand All @@ -118,6 +123,7 @@ describe('intake', () => {
expect(insertSubmissionRecordWithPotentialConflictStub).to.have.been.calledOnce;
expect(insertSubmissionFeatureRecordsStub).to.have.been.calledOnce;
expect(indexFeaturesBySubmissionIdStub).to.have.been.calledOnce;
expect(calculateAndAddRegionsForSubmissionStub).to.have.been.calledOnce;
expect(mockRes.statusValue).to.eql(200);
expect(mockRes.jsonValue).to.eql({ submission_id: 1 });
});
Expand Down
5 changes: 5 additions & 0 deletions api/src/paths/submission/intake.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { HTTP400 } from '../../errors/http-error';
import { defaultErrorResponses } from '../../openapi/schemas/http-responses';
import { ISubmissionFeature } from '../../repositories/submission-repository';
import { authorizeRequestHandler } from '../../request-handlers/security/authorization';
import { RegionService } from '../../services/region-service';
import { SearchIndexService } from '../../services/search-index-service';
import { SubmissionService } from '../../services/submission-service';
import { ValidationService } from '../../services/validation-service';
Expand Down Expand Up @@ -118,6 +119,7 @@ export function submissionIntake(): RequestHandler {
const submissionService = new SubmissionService(connection);
const validationService = new ValidationService(connection);
const searchIndexService = new SearchIndexService(connection);
const regionService = new RegionService(connection);

// validate the submission
if (!(await validationService.validateSubmissionFeatures(submissionFeatures))) {
Expand All @@ -138,6 +140,9 @@ export function submissionIntake(): RequestHandler {
// Index the submission feature record properties
await searchIndexService.indexFeaturesBySubmissionId(response.submission_id);

// Calculate and add submission regions
await regionService.calculateAndAddRegionsForSubmission(response.submission_id, 0.3);

await connection.commit();

res.status(200).json(response);
Expand Down
43 changes: 43 additions & 0 deletions api/src/repositories/bcgw-repository.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { Geometry } from 'geojson';
import { z } from 'zod';
import { getKnex } from '../database/db';
import { ApiExecuteSQLError } from '../errors/api-error';
import { Srid } from '../services/geo-service';
import { BaseRepository } from './base-repository';

export class BCGWRepository extends BaseRepository {
al-rosenthal marked this conversation as resolved.
Show resolved Hide resolved
/**
* Convert the provided GeoJSON geometry into Well-Known Text (WKT) in the provided Spatial Reference ID (SRID).
*
* @see https://postgis.net/docs/ST_AsText.html
*
* @param {Geometry} geometry
* @param {Srid} srid
* @return {*} {Promise<string>}
* @memberof BCGWRepository
*/
async getGeoJsonGeometryAsWkt(geometry: Geometry, srid: Srid): Promise<string> {
const knex = getKnex();

Check warning on line 20 in api/src/repositories/bcgw-repository.ts

View check run for this annotation

Codecov / codecov/patch

api/src/repositories/bcgw-repository.ts#L20

Added line #L20 was not covered by tests

const queryBuilder = knex

Check warning on line 22 in api/src/repositories/bcgw-repository.ts

View check run for this annotation

Codecov / codecov/patch

api/src/repositories/bcgw-repository.ts#L22

Added line #L22 was not covered by tests
.queryBuilder()
.select(
knex.raw(
`public.ST_AsText(public.ST_TRANSFORM(public.ST_Force2D(public.ST_GeomFromGeoJSON('${JSON.stringify(
geometry
)}')), ${srid})) as geometry`
)
);

const response = await this.connection.knex(queryBuilder, z.object({ geometry: z.string() }));

Check warning on line 32 in api/src/repositories/bcgw-repository.ts

View check run for this annotation

Codecov / codecov/patch

api/src/repositories/bcgw-repository.ts#L32

Added line #L32 was not covered by tests

if (response.rowCount !== 1) {
throw new ApiExecuteSQLError('Failed to convert GeoJSON geometry to WKT', [

Check warning on line 35 in api/src/repositories/bcgw-repository.ts

View check run for this annotation

Codecov / codecov/patch

api/src/repositories/bcgw-repository.ts#L35

Added line #L35 was not covered by tests
'BCGWRepository->getGeoJsonGeometryAsWkt',
'rowCount was null or undefined, expected rowCount = 1'
]);
}

return response.rows[0].geometry;

Check warning on line 41 in api/src/repositories/bcgw-repository.ts

View check run for this annotation

Codecov / codecov/patch

api/src/repositories/bcgw-repository.ts#L41

Added line #L41 was not covered by tests
}
}
56 changes: 56 additions & 0 deletions api/src/repositories/region-repository.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import chai, { expect } from 'chai';
import { describe } from 'mocha';
import { QueryResult } from 'pg';
import sinon from 'sinon';
import sinonChai from 'sinon-chai';
import { getMockDBConnection } from '../__mocks__/db';
import { RegionRepository } from './region-repository';

chai.use(sinonChai);

describe('RegionRepository', () => {
describe('getRegions', () => {
afterEach(() => {
sinon.restore();
});

it('returns an array of region records', async () => {
const mockQueryResponse = { rowCount: 1, rows: [{ region_id: 1 }] } as any as Promise<QueryResult<any>>;
const connection = getMockDBConnection({
sql: () => mockQueryResponse
});

const repo = new RegionRepository(connection);

const regions = await repo.getRegions();
expect(regions.length).to.greaterThanOrEqual(1);
});
});

describe('calculateRegionsForASubmission', () => {
it('should succeed without issue', async () => {
const mockQueryResponse = { rowCount: 1, rows: [{ region_id: 1 }] } as any as Promise<QueryResult<any>>;
const connection = getMockDBConnection({
sql: () => mockQueryResponse
});
const repo = new RegionRepository(connection);

const regions = await repo.calculateRegionsForASubmission(1);

expect(regions).to.be.eql([{ region_id: 1 }]);
});
});

describe('insertSubmissionRegions', () => {
it('should return early with no regions', async () => {
const connection = getMockDBConnection({
sql: sinon.mock()
});

const repo = new RegionRepository(connection);
await repo.insertSubmissionRegions(1, []);

expect(connection.sql).to.not.be.called;
});
});
});
Loading
Loading