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-379: Parse intake key-value pairs #211

Merged
merged 48 commits into from
Dec 20, 2023
Merged
Show file tree
Hide file tree
Changes from 36 commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
419f672
Squashed SIMSBIOHUB-365
curtisupshall Dec 5, 2023
450f950
SIMSBIOHUB-379: initialize search-index repo
curtisupshall Dec 5, 2023
29dde55
SIMSBIOHUB-379: Finished typedefs for search-index-repo insertion met…
curtisupshall Dec 5, 2023
dbda860
Merge branch 'dev' into SIMSBIOHUB-379
curtisupshall Dec 6, 2023
6f7665e
Merge branch 'SIMSBIOHUB-379' of github.com:bcgov/biohubbc-platform i…
curtisupshall Dec 6, 2023
93115cf
SIMSBIOHUB-379: Create search indexing endpoint
curtisupshall Dec 7, 2023
35a680a
SIMSBIOHUB-379: Parse key-value pairs (WIP)
curtisupshall Dec 7, 2023
85a2aa4
SIMSBIOHUB-379: fix typo
curtisupshall Dec 8, 2023
eb023bd
Merge branch 'dataset_security_feature' into SIMSBIOHUB-379
curtisupshall Dec 8, 2023
b5953dd
SIMSBIOHUB-379: Add records to table
curtisupshall Dec 11, 2023
e607077
Merge branch 'dataset_security_feature' into SIMSBIOHUB-379
curtisupshall Dec 11, 2023
2dec085
SIMSBIOHUB-379: Restore admin submissions folder
curtisupshall Dec 11, 2023
d662267
SIMSBIOHUB-379: some type changes, debugging
curtisupshall Dec 11, 2023
c809a69
SIMSBIOHUB-379: Added timestamp to db seed
curtisupshall Dec 12, 2023
e49d60b
SIMSBIOHUB-379: Added some tests WIP
curtisupshall Dec 12, 2023
7301232
Merge branch 'dataset_security_feature' into SIMSBIOHUB-379
curtisupshall Dec 12, 2023
79b895c
SIMSBIOHUB-379: Tests WIP
curtisupshall Dec 13, 2023
0d3ced3
SIMSBIOHUB-379: Refined types, jsdocs
curtisupshall Dec 13, 2023
619538f
SIMSBIOHUB-379: Added repo tests
curtisupshall Dec 13, 2023
57917bb
SIMSBIOHUB-379: Working tests
curtisupshall Dec 13, 2023
97b20f0
SIMSBIOHUB-379: Code cleanup
curtisupshall Dec 13, 2023
d09a09f
Merge branch 'dataset_security_feature' into SIMSBIOHUB-379
curtisupshall Dec 13, 2023
c455076
Merge branch 'dataset_security_feature' into SIMSBIOHUB-379
curtisupshall Dec 15, 2023
d84e87e
SIMSBIOHUB-379: Fix type error
curtisupshall Dec 15, 2023
98aaff3
Merge branch 'dataset_security_feature' into SIMSBIOHUB-379
al-rosenthal Dec 15, 2023
f9215e3
Update migration
NickPhura Dec 15, 2023
522d91e
Update intake endpoint to work with related changes from SIMS PR #1185
NickPhura Dec 18, 2023
ddec497
Fix unit test
NickPhura Dec 18, 2023
d3c417a
Fix intake validation
NickPhura Dec 18, 2023
0cc8cd2
SIMSBIOHUB-379: Addressed PR feedback
curtisupshall Dec 18, 2023
2bdd82d
SIMSBIOHUB-379: Fix zod schema checking for index table insertion
curtisupshall Dec 18, 2023
ed00e7b
SIMSBIOHUB-379: Promise typing
curtisupshall Dec 18, 2023
534b8ec
Merge branch 'dataset_security_feature' into SIMSBIOHUB-379
curtisupshall Dec 18, 2023
6e90031
SIMSBIOHUB-379: Fixed geometry typing
curtisupshall Dec 19, 2023
c52a14d
Improve JSONPath string in submission validation-service.ts
NickPhura Dec 19, 2023
c9b6674
Merge branch 'SIMSBIOHUB-379' of https://github.com/bcgov/biohubbc-pl…
NickPhura Dec 19, 2023
0e21f94
SISMBIOHUB-379: Filtered out null end_date
curtisupshall Dec 19, 2023
bdf31b5
SIMSBIOHUB-379: Remove console log
curtisupshall Dec 19, 2023
2b18a8c
Merge branch 'dataset_security_feature' into SIMSBIOHUB-379
curtisupshall Dec 19, 2023
0533606
SIMSBIOHUB-379: Lint fixes
curtisupshall Dec 20, 2023
8ea1721
SIMSBIOHUB-379: Added test check
curtisupshall Dec 20, 2023
987c7e9
SIMSBIOHUB-379: Fix compilation errors in tests
curtisupshall Dec 20, 2023
bbedbad
SIMSBIOHUB-379: Fixed test
curtisupshall Dec 20, 2023
5826152
Remove .only
NickPhura Dec 20, 2023
d5fca79
SIMSBIOHUB-379: Fixed typo in test
curtisupshall Dec 20, 2023
4507700
SIMSBIOHUB-379: Added missing stub for intake endpoint test
curtisupshall Dec 20, 2023
45192d9
Merge branch 'dataset_security_feature' into SIMSBIOHUB-379
curtisupshall Dec 20, 2023
03f6705
SIMSBIOHUB-379: Ran linter
curtisupshall Dec 20, 2023
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
2 changes: 1 addition & 1 deletion api/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,10 @@
"@types/mocha": "~9.0.0",
"@types/multer": "~1.4.7",
"@types/node": "~14.14.31",
"@types/object-inspect": "~1.8.1",
"@types/pg": "~8.6.1",
"@types/sinon": "~10.0.4",
"@types/sinon-chai": "~3.2.5",
"@types/object-inspect": "~1.8.1",
"@types/swagger-ui-express": "~4.1.3",
"@types/uuid": "~8.3.1",
"@types/yamljs": "~0.2.31",
Expand Down
45 changes: 30 additions & 15 deletions api/src/paths/submission/intake.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import { SOURCE_SYSTEM } from '../../constants/database';
import { getServiceAccountDBConnection } from '../../database/db';
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 { SearchIndexService } from '../../services/search-index-service';
import { SubmissionService } from '../../services/submission-service';
import { ValidationService } from '../../services/validation-service';
import { getKeycloakSource } from '../../utils/keycloak-utils';
Expand Down Expand Up @@ -40,26 +42,28 @@ POST.apiDoc = {
schema: {
title: 'BioHub Data Submission',
type: 'object',
required: ['id', 'type', 'properties', 'features'],
required: ['id', 'name', 'description', 'features'],
properties: {
id: {
title: 'Unique id of the submission',
type: 'string'
},
type: {
name: {
title: 'The name of the submission. Should not include sensitive information.',
type: 'string',
enum: ['submission']
maxLength: 200
},
properties: {
title: 'Dataset properties',
type: 'object',
properties: {}
description: {
title: 'A description of the submission. Should not include sensitive information.',
type: 'string',
maxLength: 3000
},
features: {
type: 'array',
items: {
$ref: '#/components/schemas/SubmissionFeature'
},
maxItems: 1,
curtisupshall marked this conversation as resolved.
Show resolved Hide resolved
additionalProperties: false
}
},
Expand Down Expand Up @@ -100,10 +104,12 @@ export function submissionIntake(): RequestHandler {
}

const submission = {
...req.body,
properties: { ...req.body.properties, additionalInformation: req.body.properties.additionalInformation }
id: req.body.id,
name: req.body.name,
description: req.body.description
};
const id = req.body.id;

const submissionFeatures: ISubmissionFeature[] = req.body.features;

const connection = getServiceAccountDBConnection(sourceSystem);

Expand All @@ -112,19 +118,28 @@ export function submissionIntake(): RequestHandler {

const submissionService = new SubmissionService(connection);
const validationService = new ValidationService(connection);
const searchIndexService = new SearchIndexService(connection);

// validate the submission submission
if (!(await validationService.validateDatasetSubmission(submission))) {
throw new HTTP400('Invalid submission submission');
// validate the submission
if (!(await validationService.validateSubmissionFeatures(submissionFeatures))) {
throw new HTTP400('Invalid submission');
}

// insert the submission record
const response = await submissionService.insertSubmissionRecordWithPotentialConflict(id);
const response = await submissionService.insertSubmissionRecordWithPotentialConflict(
submission.id,
submission.name,
submission.description
);

// insert each submission feature record
await submissionService.insertSubmissionFeatureRecords(response.submission_id, submission.features);
await submissionService.insertSubmissionFeatureRecords(response.submission_id, submissionFeatures);

// Index the submission feature record properties
await searchIndexService.indexFeaturesBySubmissionId(response.submission_id);

await connection.commit();

res.status(200).json(response);
} catch (error) {
defaultLog.error({ label: 'submissionIntake', message: 'error', error });
Expand Down
85 changes: 85 additions & 0 deletions api/src/paths/submission/search-idx.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import { RequestHandler } from 'express';
import { Operation } from 'express-openapi';
import { SOURCE_SYSTEM } from '../../constants/database';
import { getAPIUserDBConnection, getDBConnection } from '../../database/db';
import { defaultErrorResponses } from '../../openapi/schemas/http-responses';
import { authorizeRequestHandler } from '../../request-handlers/security/authorization';
import { SearchIndexService } from '../../services/search-index-service';
import { getLogger } from '../../utils/logger';

const defaultLog = getLogger('paths/dataset/search-index');

export const POST: Operation = [
authorizeRequestHandler(() => {
return {
and: [
{
validServiceClientIDs: [SOURCE_SYSTEM['SIMS-SVC-4464']],
discriminator: 'ServiceClient'
}
]
};
}),
indexSubmission()
];

POST.apiDoc = {
description: 'Index dataset in BioHub',
tags: ['dataset'],
security: [
{
Bearer: []
}
],
parameters: [
{
description: 'Submission ID',
in: 'query',
name: 'submissionId',
schema: {
type: 'integer',
minimum: 1
},
required: true
}
],
responses: {
200: {
description: 'TODO', // TODO
content: {
'application/json': {
schema: {
Copy link
Contributor

Choose a reason for hiding this comment

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

api doc still required todo

// TODO
}
}
}
},
...defaultErrorResponses
}
};

export function indexSubmission(): RequestHandler {
return async (req, res) => {
const connection = req['keycloak_token'] ? getDBConnection(req['keycloak_token']) : getAPIUserDBConnection();

const submissionId = Number(req.query.submissionId);

try {
await connection.open();

const searchIndexService = new SearchIndexService(connection);

// Index the submission record
const response = await searchIndexService.indexFeaturesBySubmissionId(submissionId);

await connection.commit();
res.status(200).json(response);
} catch (error) {
defaultLog.error({ label: 'datasetIntake', message: 'error', error });
await connection.rollback();
throw error;
} finally {
connection.release();
}
};
}
Loading
Loading