Skip to content

Commit

Permalink
Merge branch 'development' into 'master'
Browse files Browse the repository at this point in the history
Development

See merge request b650/Deep-Lynx!279
  • Loading branch information
DnOberon committed Jun 8, 2022
2 parents d8d7bc4 + 455e9d2 commit 9069d23
Show file tree
Hide file tree
Showing 7 changed files with 89 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,17 @@ export default class TypeMappingRepository extends Repository implements Reposit
typeMapping.transformations[i].metatype_relationship_pair_id = undefined;
}

// need infer type if it isn't present so that older type mappings will still function
if (!typeMapping.transformations[i].type) {
if (typeMapping.transformations[i].metatype_id || typeMapping.transformations[i].metatype_name) {
typeMapping.transformations[i].type = 'node';
} else if (typeMapping.transformations[i].metatype_relationship_pair_id || typeMapping.transformations[i].metatype_relationship_pair_name) {
typeMapping.transformations[i].type = 'edge';
} else {
typeMapping.transformations[i].type = 'timeseries';
}
}

// now clear all the id's
typeMapping.transformations[i].type_mapping_id = undefined;
typeMapping.transformations[i].id = undefined;
Expand Down
37 changes: 37 additions & 0 deletions src/http_server/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,43 @@ export function containerContext(): any {
};
}

// activeOntology will attempt to fetch the currently published ontology for the container specified by the
// id query parameter. If one is fetched it will pass it on in request context.
// route must contain the param labeled "containerID"
export function activeOntologyVersionContext(): any {
return (req: express.Request, resp: express.Response, next: express.NextFunction) => {
// if we don't have an id, don't fail, just pass without action
if (!req.params.containerID) {
next();
return;
}

const repo = new OntologyVersionRepository();

repo.where()
.containerID('eq', req.params.containerID)
.and()
.status('eq', 'published')
.list({sortDesc: true, sortBy: 'id', limit: 1})
.then((result) => {
if (result.isError) {
result.asResponse(resp);
return;
}

if (result.value.length > 0) {
req.activeOntologyVersion = result.value[0];
}

next();
})
.catch((error) => {
resp.status(500).json(error);
return;
});
};
}

// metatypeContext will attempt to fetch a metatype by id specified by the
// id query parameter. If one is fetched it will pass it on in request context.
// route must contain the param labeled "metatypeID"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,11 @@ export default class MetatypeRelationshipPairRoutes {
if (typeof req.query.ontologyVersion !== 'undefined' && (req.query.ontologyVersion as string) !== '') {
repository = repository.and().ontologyVersion('eq', req.query.ontologyVersion);
} else {
repository = repository.and().ontologyVersion('is null')
if (req.activeOntologyVersion) {
repository = repository.and().ontologyVersion('eq', req.activeOntologyVersion.id);
} else {
repository = repository.and().ontologyVersion('is null');
}
}

if (typeof req.query.deleted !== 'undefined' && String(req.query.deleted as string).toLowerCase() === 'false') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,11 @@ export default class MetatypeRelationshipRoutes {
if (typeof req.query.ontologyVersion !== 'undefined' && (req.query.ontologyVersion as string) !== '') {
repository = repository.and().ontologyVersion('eq', req.query.ontologyVersion);
} else {
repository = repository.and().ontologyVersion('is null')
if (req.activeOntologyVersion) {
repository = repository.and().ontologyVersion('eq', req.activeOntologyVersion.id);
} else {
repository = repository.and().ontologyVersion('is null');
}
}

if (typeof req.query.deleted !== 'undefined' && String(req.query.deleted as string).toLowerCase() === 'false') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,11 @@ export default class MetatypeRoutes {
if (typeof req.query.ontologyVersion !== 'undefined' && (req.query.ontologyVersion as string) !== '') {
repository = repository.and().ontologyVersion('eq', req.query.ontologyVersion);
} else {
repository = repository.and().ontologyVersion('is null')
if (req.activeOntologyVersion) {
repository = repository.and().ontologyVersion('eq', req.activeOntologyVersion.id);
} else {
repository = repository.and().ontologyVersion('is null');
}
}

if (typeof req.query.modifiedAfter !== 'undefined' && (req.query.modifiedAfter as string) !== '') {
Expand Down
29 changes: 25 additions & 4 deletions src/http_server/routes/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import {
eventActionStatusContext,
ontologyVersionContext,
serviceUserContext,
activeOntologyVersionContext,
} from '../middleware';
import ContainerRoutes from './data_warehouse/ontology/container_routes';
import MetatypeRoutes from './data_warehouse/ontology/metatype_routes';
Expand Down Expand Up @@ -122,17 +123,37 @@ export class Router {
dataSourceContext(),
currentUser(),
]);
MetatypeRoutes.mount(this.app, [authenticateRoute(), containerContext(), metatypeContext(), currentUser()]);
MetatypeKeyRoutes.mount(this.app, [authenticateRoute(), containerContext(), metatypeContext(), metatypeKeyContext(), currentUser()]);
MetatypeRelationshipRoutes.mount(this.app, [authenticateRoute(), containerContext(), metatypeRelationshipContext(), currentUser()]);
MetatypeRoutes.mount(this.app, [authenticateRoute(), containerContext(), activeOntologyVersionContext(), metatypeContext(), currentUser()]);
MetatypeKeyRoutes.mount(this.app, [
authenticateRoute(),
containerContext(),
activeOntologyVersionContext(),
metatypeContext(),
metatypeKeyContext(),
currentUser(),
]);
MetatypeRelationshipRoutes.mount(this.app, [
authenticateRoute(),
containerContext(),
activeOntologyVersionContext(),
metatypeRelationshipContext(),
currentUser(),
]);
MetatypeRelationshipKeyRoutes.mount(this.app, [
authenticateRoute(),
containerContext(),
activeOntologyVersionContext(),
metatypeRelationshipContext(),
metatypeRelationshipKeyContext(),
currentUser(),
]);
MetatypeRelationshipPairRoutes.mount(this.app, [authenticateRoute(), containerContext(), metatypeRelationshipPairContext(), currentUser()]);
MetatypeRelationshipPairRoutes.mount(this.app, [
authenticateRoute(),
containerContext(),
activeOntologyVersionContext(),
metatypeRelationshipPairContext(),
currentUser(),
]);
/* This query route is considered deprecated */
QueryRoutes.mount(this.app, [authenticateRoute(), containerContext(), currentUser()]);
GraphRoutes.mount(this.app, [authenticateRoute(), containerContext(), nodeContext(), edgeContext(), fileContext(), metatypeContext(), currentUser()]);
Expand Down
1 change: 1 addition & 0 deletions src/typings/express/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ declare global {
file?: File;
task?: TaskRecord;
ontologyVersion?: OntologyVersion;
activeOntologyVersion?: OntologyVersion;
// needed for nth-node request
nodeLeaf?: NodeLeaf;
}
Expand Down

0 comments on commit 9069d23

Please sign in to comment.