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-365: SIMS -> BIOHUB Intake Dataset #210

Merged
merged 16 commits into from
Dec 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 5 additions & 0 deletions api/package-lock.json

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

2 changes: 2 additions & 0 deletions api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"@elastic/elasticsearch": "~8.1.0",
"adm-zip": "~0.5.5",
"ajv": "~8.6.3",
"avj": "0.0.0",
"aws-sdk": "^2.1391.0",
"axios": "~0.21.4",
"clamdjs": "~1.0.2",
Expand All @@ -41,6 +42,7 @@
"fast-json-patch": "~3.1.1",
"fast-xml-parser": "~4.1.3",
"fastq": "^1.15.0",
"json-schema-traverse": "^1.0.0",
"jsonpath-plus": "~7.2.0",
"jsonwebtoken": "~8.5.1",
"jwks-rsa": "~2.0.5",
Expand Down
2 changes: 1 addition & 1 deletion api/src/database/db.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ describe('db', () => {
db.getServiceAccountDBConnection(SOURCE_SYSTEM['SIMS-SVC-4464']);

expect(getDBConnectionStub).to.have.been.calledWith({
preferred_username: `service-account-${SOURCE_SYSTEM['SIMS-SVC-4464']}@${SYSTEM_IDENTITY_SOURCE.SYSTEM}`,
preferred_username: `service-account-${SOURCE_SYSTEM['SIMS-SVC-4464']}`,
identity_provider: SYSTEM_IDENTITY_SOURCE.SYSTEM
});

Expand Down
2 changes: 1 addition & 1 deletion api/src/database/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ export const getAPIUserDBConnection = (): IDBConnection => {
*/
export const getServiceAccountDBConnection = (sourceSystem: SOURCE_SYSTEM): IDBConnection => {
return getDBConnection({
preferred_username: `service-account-${sourceSystem}@${SYSTEM_IDENTITY_SOURCE.SYSTEM}`,
preferred_username: `service-account-${sourceSystem}`,
identity_provider: SYSTEM_IDENTITY_SOURCE.SYSTEM
});
};
Expand Down
28 changes: 28 additions & 0 deletions api/src/openapi/root-api-doc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,34 @@ export const rootAPIDoc = {
}
}
}
},
SubmissionFeature: {
title: 'BioHub Data Submission Feature',
type: 'object',
required: ['id', 'type', 'properties', 'features'],
properties: {
id: {
title: 'Unique id of the feature',
type: 'string'
},
type: {
title: 'Feature type',
type: 'string'
},
properties: {
title: 'Feature properties',
type: 'object',
properties: {}
},
features: {
title: 'Feature child features',
type: 'array',
items: {
$ref: '#/components/schemas/SubmissionFeature'
}
}
},
additionalProperties: false
}
}
}
Expand Down
35 changes: 2 additions & 33 deletions api/src/openapi/schemas/biohub-data-submission.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export const BioHubDataSubmission = {
title: 'BioHub Data Submission',
type: 'object',
required: ['id', 'type', 'features'],
required: ['id', 'type', 'properties', 'features'],
properties: {
id: {
title: 'Unique id of the submission',
Expand All @@ -19,40 +19,9 @@ export const BioHubDataSubmission = {
features: {
type: 'array',
items: {
$ref: '#/$defs/Feature'
KjartanE marked this conversation as resolved.
Show resolved Hide resolved
$ref: '#/components/schemas/SubmissionFeature'
}
}
},
$defs: {
Feature: {
title: 'BioHub Data Submission Feature',
type: 'object',
required: ['id', 'type', 'properties', 'features'],
properties: {
id: {
title: 'Unique id of the feature',
type: 'string'
},
type: {
title: 'Feature type',
type: 'string'
},
properties: {
title: 'Feature properties',
type: 'object',
properties: {}
},
features: {
title: 'Feature child features',
type: 'array',
items: {
$ref: '#/$defs/Feature'
}
}
},
additionalProperties: false
},
additionalProperties: false
},
additionalProperties: false
};
137 changes: 137 additions & 0 deletions api/src/paths/dataset/intake.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
import { RequestHandler } from 'express';
import { Operation } from 'express-openapi';
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 { authorizeRequestHandler } from '../../request-handlers/security/authorization';
import { SubmissionService } from '../../services/submission-service';
import { ValidationService } from '../../services/validation-service';
import { getKeycloakSource } from '../../utils/keycloak-utils';
import { getLogger } from '../../utils/logger';

const defaultLog = getLogger('paths/dataset/intake');

Check warning on line 13 in api/src/paths/dataset/intake.ts

View check run for this annotation

Codecov / codecov/patch

api/src/paths/dataset/intake.ts#L13

Added line #L13 was not covered by tests

export const POST: Operation = [

Check warning on line 15 in api/src/paths/dataset/intake.ts

View check run for this annotation

Codecov / codecov/patch

api/src/paths/dataset/intake.ts#L15

Added line #L15 was not covered by tests
authorizeRequestHandler(() => {
return {

Check warning on line 17 in api/src/paths/dataset/intake.ts

View check run for this annotation

Codecov / codecov/patch

api/src/paths/dataset/intake.ts#L17

Added line #L17 was not covered by tests
and: [
{
validServiceClientIDs: [SOURCE_SYSTEM['SIMS-SVC-4464']],
discriminator: 'ServiceClient'
}
]
};
}),
datasetIntake()
];

POST.apiDoc = {

Check warning on line 29 in api/src/paths/dataset/intake.ts

View check run for this annotation

Codecov / codecov/patch

api/src/paths/dataset/intake.ts#L29

Added line #L29 was not covered by tests
description: 'Submit dataset to BioHub',
tags: ['dataset'],
security: [
{
Bearer: []
}
],
requestBody: {
content: {
'application/json': {
schema: {
title: 'BioHub Data Submission',
type: 'object',
required: ['id', 'type', 'properties', 'features'],
properties: {
id: {
title: 'Unique id of the submission',
type: 'string'
},
type: {
type: 'string',
enum: ['dataset']
},
properties: {
title: 'Dataset properties',
type: 'object',
properties: {}
},
features: {
type: 'array',
items: {
$ref: '#/components/schemas/SubmissionFeature'
},
additionalProperties: false
}
},
additionalProperties: false
}
}
}
},
responses: {
200: {
description: 'Submission OK',
content: {
'application/json': {
schema: {
type: 'object',
required: ['submission_id'],
properties: {
submission_id: {
type: 'integer'
}
}
}
}
}
},
...defaultErrorResponses
}
};

export function datasetIntake(): RequestHandler {
return async (req, res) => {
const sourceSystem = getKeycloakSource(req['keycloak_token']);

Check warning on line 94 in api/src/paths/dataset/intake.ts

View check run for this annotation

Codecov / codecov/patch

api/src/paths/dataset/intake.ts#L93-L94

Added lines #L93 - L94 were not covered by tests

if (!sourceSystem) {
throw new HTTP400('Failed to identify known submission source system', [

Check warning on line 97 in api/src/paths/dataset/intake.ts

View check run for this annotation

Codecov / codecov/patch

api/src/paths/dataset/intake.ts#L97

Added line #L97 was not covered by tests
'token did not contain a clientId/azp or clientId/azp value is unknown'
]);
}

const dataset = {

Check warning on line 102 in api/src/paths/dataset/intake.ts

View check run for this annotation

Codecov / codecov/patch

api/src/paths/dataset/intake.ts#L102

Added line #L102 was not covered by tests
...req.body,
properties: { ...req.body.properties, additionalInformation: req.body.properties.additionalInformation }
};
const id = req.body.id;

Check warning on line 106 in api/src/paths/dataset/intake.ts

View check run for this annotation

Codecov / codecov/patch

api/src/paths/dataset/intake.ts#L106

Added line #L106 was not covered by tests

const connection = getServiceAccountDBConnection(sourceSystem);

Check warning on line 108 in api/src/paths/dataset/intake.ts

View check run for this annotation

Codecov / codecov/patch

api/src/paths/dataset/intake.ts#L108

Added line #L108 was not covered by tests

try {
await connection.open();

Check warning on line 111 in api/src/paths/dataset/intake.ts

View check run for this annotation

Codecov / codecov/patch

api/src/paths/dataset/intake.ts#L110-L111

Added lines #L110 - L111 were not covered by tests

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

Check warning on line 114 in api/src/paths/dataset/intake.ts

View check run for this annotation

Codecov / codecov/patch

api/src/paths/dataset/intake.ts#L113-L114

Added lines #L113 - L114 were not covered by tests

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

Check warning on line 118 in api/src/paths/dataset/intake.ts

View check run for this annotation

Codecov / codecov/patch

api/src/paths/dataset/intake.ts#L118

Added line #L118 was not covered by tests
}

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

Check warning on line 122 in api/src/paths/dataset/intake.ts

View check run for this annotation

Codecov / codecov/patch

api/src/paths/dataset/intake.ts#L122

Added line #L122 was not covered by tests

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

Check warning on line 125 in api/src/paths/dataset/intake.ts

View check run for this annotation

Codecov / codecov/patch

api/src/paths/dataset/intake.ts#L125

Added line #L125 was not covered by tests

await connection.commit();
res.status(200).json(response);

Check warning on line 128 in api/src/paths/dataset/intake.ts

View check run for this annotation

Codecov / codecov/patch

api/src/paths/dataset/intake.ts#L127-L128

Added lines #L127 - L128 were not covered by tests
} catch (error) {
defaultLog.error({ label: 'datasetIntake', message: 'error', error });
await connection.rollback();
throw error;

Check warning on line 132 in api/src/paths/dataset/intake.ts

View check run for this annotation

Codecov / codecov/patch

api/src/paths/dataset/intake.ts#L130-L132

Added lines #L130 - L132 were not covered by tests
} finally {
connection.release();

Check warning on line 134 in api/src/paths/dataset/intake.ts

View check run for this annotation

Codecov / codecov/patch

api/src/paths/dataset/intake.ts#L134

Added line #L134 was not covered by tests
}
};
}
10 changes: 2 additions & 8 deletions api/src/repositories/submission-repository.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -490,10 +490,7 @@ describe('SubmissionRepository', () => {

const submissionRepository = new SubmissionRepository(mockDBConnection);

const response = await submissionRepository.insertSubmissionRecordWithPotentialConflict({
uuid: 'aaaa',
source_transform_id: 1
});
const response = await submissionRepository.insertSubmissionRecordWithPotentialConflict('aaaa');

expect(response).to.eql({
uuid: 'aaaa',
Expand All @@ -510,10 +507,7 @@ describe('SubmissionRepository', () => {
const submissionRepository = new SubmissionRepository(mockDBConnection);

try {
await submissionRepository.insertSubmissionRecordWithPotentialConflict({
uuid: 'bbbb',
source_transform_id: 3
});
await submissionRepository.insertSubmissionRecordWithPotentialConflict('aaaa');
expect.fail();
} catch (actualError) {
expect((actualError as ApiExecuteSQLError).message).to.equal('Failed to get or insert submission record');
Expand Down
Loading
Loading