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!207
  • Loading branch information
DnOberon committed Mar 16, 2022
2 parents 4b0975d + 602d707 commit 6d8a3ec
Show file tree
Hide file tree
Showing 11 changed files with 401 additions and 18 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<v-dialog v-model="dialog" width="60%" @click:outside="clearNew">
<v-dialog v-model="dialog" width="40%" @click:outside="clearNew">
<template v-slot:activator="{ on }">
<v-btn color="primary" dark class="mb-2" v-on="on">{{$t("containers.newContainerButton")}}</v-btn>
</template>
Expand Down
2 changes: 1 addition & 1 deletion AdminWebApp/src/views/MetatypeRelationshipPairs.vue
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ export default class MetatypeRelationshipPairs extends Vue {
})
this.$client.listMetatypeRelationshipPairs(this.containerID, {
ontologyVersion: this.ontologyVersionID,
ontologyVersion: this.$store.getters.selectedOntologyVersionID,
nameIn,
loadRelationships: true
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,21 @@ import MetatypeRelationshipPairRepository from '../../../repositories/data_wareh
import MetatypeRelationshipPair from '../../../../domain_objects/data_warehouse/ontology/metatype_relationship_pair';
import MetatypeKeyRepository from '../../../repositories/data_warehouse/ontology/metatype_key_repository';
import MetatypeKey from '../../../../domain_objects/data_warehouse/ontology/metatype_key';
import {User} from '../../../../domain_objects/access_management/user';
import {SuperUser, User} from '../../../../domain_objects/access_management/user';
import NodeRepository from '../../../repositories/data_warehouse/data/node_repository';
import EdgeRepository from '../../../repositories/data_warehouse/data/edge_repository';
import {stringToValidPropertyName} from "../../../../services/utilities";
import OntologyVersionRepository
from "../../../repositories/data_warehouse/ontology/versioning/ontology_version_repository";
import OntologyVersion from "../../../../domain_objects/data_warehouse/ontology/versioning/ontology_version";
const convert = require('xml-js');

const containerRepo = new ContainerRepository();
const metatypeRelationshipRepo = new MetatypeRelationshipRepository();
const metatypeRepo = new MetatypeRepository();
const metatypeRelationshipPairRepo = new MetatypeRelationshipPairRepository();
const metatypeKeyRepo = new MetatypeKeyRepository();
const ontologyRepo = new OntologyVersionRepository();
const nodeRepo = new NodeRepository();
const edgeRepo = new EdgeRepository();

Expand Down Expand Up @@ -490,7 +494,31 @@ export default class ContainerImport {
}
});

if (update) {
// if it's an update we need to set the ontology version manually so that we're not actually updating
// the ontology if versioning is enabled
let ontologyVersionID: string | undefined
if(container.config!.ontology_versioning_enabled && update) {
if(container.config!.ontology_versioning_enabled) {
const ontologyVersion = new OntologyVersion({
container_id: containerID,
name: `Update from OWL File`,
description: 'Updates created from uploading an .OWL file',
status: 'ready'
})

const saved = await ontologyRepo.save(ontologyVersion, user)

if(saved.isError) {
Logger.error(`unable to create ontology version for update from .OWL file ${saved.error?.error}`)
} else {
ontologyVersionID = ontologyVersion.id
}
}
}

// only pull and map the old data if we're updating an ontology in place, in a container where versioning
// isn't enabled
if (update && !container.config!.ontology_versioning_enabled) {
let oldMetatypeRelationships: MetatypeRelationship[] = [];
let oldMetatypes: Metatype[] = [];
let oldMetatypeRelationshipPairs: MetatypeRelationshipPair[] = [];
Expand Down Expand Up @@ -609,6 +637,7 @@ export default class ContainerImport {
container_id: containerID,
name: relationship.name,
description: relationship.description,
ontology_version: ontologyVersionID
});

// if marked for update, assign relationship id
Expand All @@ -622,7 +651,7 @@ export default class ContainerImport {

const relationshipPromise = await metatypeRelationshipRepo.bulkSave(user, metatypeRelationships);
// check for an error and rollback if necessary
if (relationshipPromise.isError) {
if (relationshipPromise.isError && !update) {
const rollback = await this.rollbackOntology(container)
.then((result) => {
return result + ' ' + relationshipPromise.error?.error;
Expand All @@ -632,6 +661,8 @@ export default class ContainerImport {
});
resolve(Result.SilentFailure(rollback));
return;
} else if (relationshipPromise.isError) {
resolve(Result.Pass(relationshipPromise))
}

// loop through relationships (with new IDs if created)
Expand All @@ -650,6 +681,7 @@ export default class ContainerImport {
container_id: containerID,
name: thisClass.name,
description: thisClass.description,
ontology_version: ontologyVersionID,
});

// if marked for update, assign metatype id
Expand All @@ -663,7 +695,7 @@ export default class ContainerImport {

const metatypePromise = await metatypeRepo.bulkSave(user, metatypes);
// check for an error and rollback if necessary
if (metatypePromise.isError) {
if (metatypePromise.isError && !update) {
const rollback = await this.rollbackOntology(container)
.then((result) => {
return result + ' ' + metatypePromise.error?.error;
Expand All @@ -673,6 +705,8 @@ export default class ContainerImport {
});
resolve(Result.SilentFailure(rollback));
return;
} else if (metatypePromise.isError) {
resolve(Result.Pass(metatypePromise))
}

// loop through metatypes adding new database IDs
Expand Down Expand Up @@ -705,6 +739,7 @@ export default class ContainerImport {
relationship: relationship.db_id,
relationship_type: 'many:one',
container_id: containerID,
ontology_version: ontologyVersionID
});

if (thisClass.updateKeyNames.includes(relationshipName)) {
Expand Down Expand Up @@ -764,6 +799,7 @@ export default class ContainerImport {
max,
},
options: propertyOptions.length > 0 ? propertyOptions : undefined,
ontology_version: ontologyVersionID
});

if (thisClass.updateKeyNames.includes(dataProp.name)) {
Expand All @@ -786,6 +822,7 @@ export default class ContainerImport {
relationship: relationshipID,
relationship_type: 'many:many',
container_id: containerID,
ontology_version: ontologyVersionID
});

if (thisClass.updateKeyNames.includes(relationshipName)) {
Expand All @@ -808,7 +845,7 @@ export default class ContainerImport {
});
const propertyResults: Result<boolean>[] = await Promise.all(propertyPromises);
for (const propResult of propertyResults) {
if (propResult.isError) {
if (propResult.isError && !update) {
const rollback = await this.rollbackOntology(container)
.then((result) => {
return result + ' ' + propResult.error?.error;
Expand All @@ -818,6 +855,8 @@ export default class ContainerImport {
});
resolve(Result.SilentFailure(rollback));
return;
} else if (propResult.isError) {
resolve(Result.Pass(propResult))
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,14 @@ export default class OntologyVersionMapper extends Mapper {
return super.runStatement(this.setStatusStatement(id, status, statusMessage));
}

public async CloneOntology(userID: string, baseVersionID: string | undefined, targetVersionID: string, transaction?: PoolClient): Promise<Result<boolean>> {
return super.runStatement(this.cloneOntologyStatement(userID, baseVersionID, targetVersionID), {transaction});
public async CloneOntology(
userID: string,
baseVersionID: string | undefined,
targetVersionID: string,
containerID: string,
transaction?: PoolClient,
): Promise<Result<boolean>> {
return super.runStatement(this.cloneOntologyStatement(userID, baseVersionID, targetVersionID, containerID), {transaction});
}

public async Delete(id: string): Promise<Result<boolean>> {
Expand Down Expand Up @@ -109,7 +115,7 @@ export default class OntologyVersionMapper extends Mapper {

private deleteStatement(id: string): QueryConfig {
return {
text: `DELETE FROM ontology_versions WHERE id = $1 AND status <> 'applied'`,
text: `DELETE FROM ontology_versions WHERE id = $1 AND status <> 'published'`,
values: [id],
};
}
Expand Down Expand Up @@ -152,10 +158,10 @@ export default class OntologyVersionMapper extends Mapper {

// this statement runs the function for cloning the ontology, requires at least a target ontology version but
// base version could be null
private cloneOntologyStatement(userID: string, baseOntology: string | undefined, targetOntology: string): QueryConfig {
private cloneOntologyStatement(userID: string, baseOntology: string | undefined, targetOntology: string, containerID: string): QueryConfig {
return {
text: `SELECT clone_ontology($1::bigint, $2::bigint, $3::bigint);`,
values: [userID, baseOntology, targetOntology],
text: `SELECT clone_ontology($1::bigint, $2::bigint, $3::bigint, $4::bigint);`,
values: [userID, baseOntology, targetOntology, containerID],
};
}
}
Loading

0 comments on commit 6d8a3ec

Please sign in to comment.