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

[BI-1363] Program Configuration and Share Ontologies #214

Merged
merged 7 commits into from
Apr 5, 2022
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
50 changes: 50 additions & 0 deletions src/breeding-insight/dao/SharedOntologyDAO.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* See the NOTICE file distributed with this work for additional information
* regarding copyright ownership.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import {BiResponse, Metadata, Response} from "@/breeding-insight/model/BiResponse";
import * as api from "@/util/api";
import {SharedProgramRequest} from "@/breeding-insight/model/SharedProgramRequest";

export class SharedOntologyDAO {

static async get(programId: string): Promise<BiResponse> {
const { data } = await api.call({
url: `${process.env.VUE_APP_BI_API_V1_PATH}/programs/${programId}/ontology/shared/programs`,
method: 'get'
}) as Response;

return new BiResponse(data);
}

static async share(programId: string, sharedProgramsRequest: SharedProgramRequest[]): Promise<BiResponse> {
const { data } = await api.call({
url: `${process.env.VUE_APP_BI_API_V1_PATH}/programs/${programId}/ontology/shared/programs`,
method: 'post',
data: sharedProgramsRequest
}) as Response;
return new BiResponse(data);
}

static async revoke(programId: string, sharedProgramId: string) {
const { data } = await api.call({
url: `${process.env.VUE_APP_BI_API_V1_PATH}/programs/${programId}/ontology/shared/programs/${sharedProgramId}`,
method: 'delete'
}) as Response;

return new BiResponse(data);
}
}
32 changes: 32 additions & 0 deletions src/breeding-insight/model/SharedProgram.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* See the NOTICE file distributed with this work for additional information
* regarding copyright ownership.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

export class SharedProgram {
programName: string;
programId: string;
shared: boolean;
accepted: boolean | undefined;
editable: boolean | undefined;

constructor({programName, programId, shared, accepted, editable}: SharedProgram) {
this.programName = programName;
this.programId = programId;
this.shared = shared;
this.accepted = accepted;
this.editable = editable;
}
}
27 changes: 27 additions & 0 deletions src/breeding-insight/model/SharedProgramRequest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* See the NOTICE file distributed with this work for additional information
* regarding copyright ownership.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/


export class SharedProgramRequest {
programName: string;
programId: string;

constructor({programName, programId}: SharedProgramRequest) {
this.programName = programName;
this.programId = programId;
}
}
88 changes: 88 additions & 0 deletions src/breeding-insight/service/SharedOntologyService.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/*
* See the NOTICE file distributed with this work for additional information
* regarding copyright ownership.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import {SharedProgram} from "@/breeding-insight/model/SharedProgram";
import {BiResponse, Metadata} from "@/breeding-insight/model/BiResponse";
import {TraitDAO} from "@/breeding-insight/dao/TraitDAO";
import {ValidationErrorService} from "@/breeding-insight/service/ValidationErrorService";
import {SharedOntologyDAO} from "@/breeding-insight/dao/SharedOntologyDAO";
import {SharedProgramRequest} from "@/breeding-insight/model/SharedProgramRequest";
import {ValidationError} from "@/breeding-insight/model/errors/ValidationError";

export class SharedOntologyService {

static async get(programId: string): Promise<[SharedProgram[], Metadata]> {
if (!programId) throw 'Program ID required';

try {
const { result: { data }, metadata } = await SharedOntologyDAO.get(programId);
const sharedPrograms: SharedProgram[] = [];
for (const datum of data) {
sharedPrograms.push(new SharedProgram(datum));
}
return [sharedPrograms, metadata];
} catch (error) {
if (error.response && error.response.status === 404) {
throw error.response.message;
} else {
throw 'An unknown error has occurred';
}
}

}

static async share(programId: string, shareRequests: SharedProgramRequest[]): Promise<[SharedProgram[], Metadata]> {

try {
const { result: { data }, metadata } = await SharedOntologyDAO.share(programId, shareRequests);
// Parse into SharedPrograms
const sharedPrograms: SharedProgram[] = [];
for (const datum of data) {
sharedPrograms.push(new SharedProgram(datum));
}
return [sharedPrograms, metadata];
} catch (error) {
if (error.response && error.response.status === 404) {
throw error.response.message;
} else if (error.response && error.response.status == 422) {
const parsedErrors: ValidationError | string = ValidationErrorService.parseError(error);
// Stringify and format msg
throw ValidationErrorService.stringify(parsedErrors, {includeRowNum: false, includeField: false}).join(" ");
} else {
throw 'An unknown error has occurred';
}
}
}

static async revokeAll(programId: string, programsToRemove: string[]) {

if (!programId) throw 'Program ID required';

// TODO: Collect errors
for (const programToRemove of programsToRemove) {
try {
await SharedOntologyDAO.revoke(programId, programToRemove);
} catch (error) {
if (error.response && error.response.status === 404) {
throw error.response.message;
} else {
throw 'An unknown error has occurred';
}
}
}
}
}
23 changes: 23 additions & 0 deletions src/breeding-insight/service/ValidationErrorService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,27 @@ export class ValidationErrorService {
}
}
}

static stringify(errors: ValidationError | string, {includeRowNum, includeField}: {includeRowNum: boolean, includeField: boolean}) {

const formattedErrors = [];
const isValidationError = errors instanceof ValidationError;
if (isValidationError){
const validationErrors = errors as ValidationError;
if (validationErrors.rowErrors) {
for (const error of validationErrors.rowErrors){
if (error.errors) {
for (const fieldError of error.errors){
let msg = includeField ? `${fieldError.field}: ${fieldError.errorMessage}` : fieldError.errorMessage;
msg += includeRowNum ? ` in row ${error.rowIndex}` : '';
formattedErrors.push(msg);
}
}
}
}
return formattedErrors;
} else {
return [errors];
}
}
}
47 changes: 47 additions & 0 deletions src/components/modals/GenericModal.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<!--
- See the NOTICE file distributed with this work for additional information
- regarding copyright ownership.
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-->

<template>
<BaseModal
v-bind:active.sync="active"
v-on:deactivate="$emit('deactivate')"
>
<h3 class="is-5 title has-text-info">
{{msgTitle}}
</h3>
<slot></slot>
</BaseModal>
</template>

<script lang="ts">
import { Component, Prop, Vue } from 'vue-property-decorator';
import BaseModal from '@/components/modals/BaseModal.vue';
import { AlertCircleIcon } from 'vue-feather-icons'

@Component({
components: {BaseModal, AlertCircleIcon}
})
export default class GenericModal extends Vue {
@Prop()
active!: boolean;
@Prop()
bodyClass!: Object;
@Prop()
msgTitle!: string;
}

</script>
Loading