Skip to content

Commit

Permalink
[BI-1459] - Adding Job data model
Browse files Browse the repository at this point in the history
  • Loading branch information
timparsons committed May 23, 2022
1 parent b6ec1c1 commit dc6d733
Show file tree
Hide file tree
Showing 10 changed files with 198 additions and 61 deletions.
9 changes: 0 additions & 9 deletions src/breeding-insight/dao/ImportDAO.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,15 +99,6 @@ export class ImportDAO {
return new BiResponse(data);
}

static async getProgramUploads(programId: string, includeMapping: boolean) {
const {data} = await api.call({
url: `${process.env.VUE_APP_BI_API_V1_PATH}/programs/${programId}/import/data?mapping=${includeMapping}`,
method: 'get'
}) as Response;

return new BiResponse(data);
}

static async updateUploadData(programId: string, mappingId: string, uploadId: string, userInput: any, commit: boolean) {
let url = `${process.env.VUE_APP_BI_API_V1_PATH}/programs/${programId}/import/mappings/${mappingId}/data/${uploadId}`;
url += commit ? '/commit' : '/preview';
Expand Down
31 changes: 31 additions & 0 deletions src/breeding-insight/dao/JobDAO.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* 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 * as api from '@/util/api';
import { BiResponse, Response } from '@/breeding-insight/model/BiResponse';

export class JobDAO {

static async getProgramJobs(programId: string) {
const {data} = await api.call({
url: `${process.env.VUE_APP_BI_API_V1_PATH}/programs/${programId}/jobs`,
method: 'get'
}) as Response;

return new BiResponse(data);
}
}
7 changes: 5 additions & 2 deletions src/breeding-insight/model/import/ImportResponse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@
import {ImportProgress} from "@/breeding-insight/model/import/ImportProgress";
import {ImportPreview} from "@/breeding-insight/model/import/ImportPreview";
import { User } from '@/breeding-insight/model/User';
import { JobDetail } from '@/breeding-insight/model/job/JobDetail';

export class ImportResponse {
export class ImportResponse extends JobDetail{
importId?: string;
progress?: ImportProgress;
preview?: ImportPreview;
Expand All @@ -31,7 +32,8 @@ export class ImportResponse {
createdAt?: Date;
updatedAt?: Date;

constructor({importId, progress, preview, uploadFileName, importMappingName, importType, createdByUser, updatedByUser, createdAt, updatedAt}: ImportResponse) {
constructor({importId, progress, preview, uploadFileName, importMappingName, importType, createdByUser, updatedByUser, createdAt, updatedAt, jobType}: ImportResponse) {
super();
this.importId = importId;
this.progress = progress;
this.preview = preview;
Expand All @@ -42,5 +44,6 @@ export class ImportResponse {
this.updatedByUser = updatedByUser;
this.createdAt = createdAt;
this.updatedAt = updatedAt;
this.jobType = jobType;
}
}
39 changes: 39 additions & 0 deletions src/breeding-insight/model/job/Job.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* 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 { User } from '@/breeding-insight/model/User';
import { JobDetail } from '@/breeding-insight/model/job/JobDetail';

export class Job {
statuscode?: number;
statusMessage?: string;
jobType?: string;
createdAt?: Date;
updatedAt?: Date;
createdByUser?: User;
jobDetail?: JobDetail;

constructor ({statuscode, statusMessage, jobType, createdAt, updatedAt, createdByUser, jobDetail}: Job) {
this.statuscode = statuscode;
this.statusMessage = statusMessage;
this.jobType = jobType;
this.createdAt = createdAt;
this.updatedAt = updatedAt;
this.createdByUser = createdByUser;
this.jobDetail = jobDetail;
}
}
20 changes: 20 additions & 0 deletions src/breeding-insight/model/job/JobDetail.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* 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 JobDetail {
jobType?: string;
}
25 changes: 0 additions & 25 deletions src/breeding-insight/service/ImportService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,31 +109,6 @@ export class ImportService {

}

static async getProgramUploads(programId: string, includeMapping: boolean): Promise<ImportResponse[]> {
if (!programId || programId === null) {
throw 'Program ID not provided';
}

try {
const response: BiResponse = await ImportDAO.getProgramUploads(programId, includeMapping);
const data: any = response.result;
if(data) {
const importResponse = data.map((response: ImportResponse) => new ImportResponse(response));
return importResponse;
} else {
return [];
}
} catch (e) {
if (e.response && e.response.statusText) {
e.errorMessage = e.response.statusText;
} else {
e.errorMessage = this.getUploadUnknown;
}
throw e;
}

}

static async updateDataUpload(programId: string, mappingId: string, uploadId: string, userInput: any, commit: boolean) {
if (!programId || programId === null) {
throw 'Program ID not provided';
Expand Down
48 changes: 48 additions & 0 deletions src/breeding-insight/service/JobService.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* 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 } from '@/breeding-insight/model/BiResponse';
import { Job } from '@/breeding-insight/model/job/Job';
import { JobDAO } from '@/breeding-insight/dao/JobDAO';

export class JobService {
static getJobsUnknown: string = 'An unknown error occurred while retrieving job statuses';

static async getProgramJobs(programId: string): Promise<Job[]> {
if (!programId) {
throw 'Program ID not provided';
}

try {
const response: BiResponse = await JobDAO.getProgramJobs(programId);
const data: any = response.result;
if(data) {
return data.map((response: Job) => new Job(response));
} else {
return [];
}
} catch (e) {
if (e.response && e.response.statusText) {
e.errorMessage = e.response.statusText;
} else {
e.errorMessage = this.getJobsUnknown;
}
throw e;
}

}
}
2 changes: 1 addition & 1 deletion src/components/layouts/UserSideBarLayout.vue
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@
v-bind:to="{name: 'job-management', params: {programId: activeProgram.id}}"
:id="jobManagementMenuId"
>
Job Management
Jobs
</router-link>
</li>
<li>
Expand Down
2 changes: 1 addition & 1 deletion src/router/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ const routes = [
path: '/programs/:programId/jobs',
name: 'job-management',
meta: {
title: 'Job Management',
title: 'Jobs',
layout: layouts.userSideBar
},
component: JobManagement,
Expand Down
76 changes: 53 additions & 23 deletions src/views/program/JobManagement.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,46 +18,69 @@
<template>
<div id="program-job-management">
<h1 class="title">
Job Management
Jobs
</h1>

<button
class="button is-primary has-text-weight-bold is-pulled-right"
v-on:click="refresh"
data-testid="refreshJobsBtn"
>
Refresh
</button>

<div class="is-clearfix"></div>

<ExpandableTable
v-bind:records.sync="jobs"
v-bind:loading="loading"
v-bind:pagination="pagination"
v-bind:details="true"
v-bind:default-sort="['data.createdAt', 'asc']"
v-bind:default-sort="['data.createdAt', 'desc']"
>
<b-table-column field="data.progress" label="Status" sortable v-slot="props" :th-attrs="(column) => ({scope:'col'})">
<span class="tag" :class="progressTagType(props.row.data.progress)">
{{ formatProgress(props.row.data.progress) }}
<b-table-column field="data.statuscode" label="Status" sortable v-slot="props" :th-attrs="(column) => ({scope:'col'})">
<span class="tag" :class="progressTagType(props.row.data.statuscode)">
{{ formatProgress(props.row.data.statuscode) }}
</span>
</b-table-column>
<b-table-column field="data.importType" label="Type" sortable v-slot="props" :th-attrs="(column) => ({scope:'col'})">
{{ props.row.data.importType}}
<b-table-column field="data.jobType" label="Type" sortable v-slot="props" :th-attrs="(column) => ({scope:'col'})">
{{ props.row.data.jobType}}
</b-table-column>
<b-table-column field="data.createdByUser.name" label="Submitted By" sortable v-slot="props" :th-attrs="(column) => ({scope:'col'})">
{{ props.row.data.createdByUser.name}}
</b-table-column>
<b-table-column field="data.createdAt" label="Submitted At" sortable v-slot="props" :th-attrs="(column) => ({scope:'col'})">
{{ formatDate(props.row.data.createdAt) }}
</b-table-column>
<b-table-column field="data.createdAt" label="Last Updated" sortable v-slot="props" :th-attrs="(column) => ({scope:'col'})">
<b-table-column field="data.updatedAt" label="Last Updated" sortable v-slot="props" :th-attrs="(column) => ({scope:'col'})">
{{ formatDate(props.row.data.updatedAt) }}
</b-table-column>
<b-table-column field="data.progress.message" label="Status Message" sortable v-slot="props" :th-attrs="(column) => ({scope:'col'})">
{{ props.row.data.progress.message }}
<b-table-column field="data.statusMessage" label="Status Message" sortable v-slot="props" :th-attrs="(column) => ({scope:'col'})">
{{ props.row.data.statusMessage }}
</b-table-column>

<template v-slot:detail="{row}">
<div class="column">
<div class="column" v-if="row.jobDetail.jobType === 'IMPORT'">
<div>
<span class="has-text-weight-bold">Status Message: </span>{{ row.jobDetail.progress.message }}
</div>
<div>
<span class="has-text-weight-bold">Status Message: </span>{{ row.progress.message }}
<span class="has-text-weight-bold">In Progress (count): </span>{{ row.jobDetail.progress.inProgress }}
</div>
<div>
<span class="has-text-weight-bold">Import Template Name: </span>{{ row.importMappingName}}
<span class="has-text-weight-bold">Complete (count): </span>{{ row.jobDetail.progress.finished }}
</div>
<div>
<span class="has-text-weight-bold">Total (count): </span>{{ row.jobDetail.progress.total }}
</div>
<div>
<span class="has-text-weight-bold">Import Template Name: </span>{{ row.jobDetail.importMappingName}}
</div>
<div>
<span class="has-text-weight-bold">Uploaded By: </span>{{ row.createdByUser.name }}
</div>
<div>
<span class="has-text-weight-bold">Uploaded File: </span>{{ row.uploadFileName }}
<span class="has-text-weight-bold">Uploaded File: </span>{{ row.jobDetail.uploadFileName }}
</div>
</div>
</template>
Expand Down Expand Up @@ -86,6 +109,8 @@ import { Pagination } from '@/breeding-insight/model/BiResponse';
import { PaginationController } from '@/breeding-insight/model/view_models/PaginationController';
import { ImportProgress } from '@/breeding-insight/model/import/ImportProgress';
import moment from 'moment';
import { JobService } from '@/breeding-insight/service/JobService';
import { Job } from '@/breeding-insight/model/job/Job';

@Component({
components: {
Expand All @@ -102,7 +127,7 @@ import moment from 'moment';
export default class JobManagement extends Vue {

private activeProgram?: Program;
private jobs?: any[] = [];
private jobs?: Job[] = [];
private pagination: Pagination = new Pagination();
private paginationController: PaginationController = new PaginationController();
private loading = true;
Expand All @@ -115,29 +140,34 @@ export default class JobManagement extends Vue {
return moment(date).format();
}

formatProgress(progress:ImportProgress) {
if(progress.statuscode === 202) {
formatProgress(statuscode:number) {
if(statuscode === 202) {
return "In Progress";
} else if(progress.statuscode === 200) {
} else if(statuscode === 200) {
return "Finished";
} else {
return "Processing Error";
return "Error";
}
}

progressTagType(progress:ImportProgress) {
if(progress.statuscode === 202) {
progressTagType(statuscode:number) {
if(statuscode === 202) {
return "is-warning";
} else if(progress.statuscode === 200) {
} else if(statuscode === 200) {
return "is-success";
} else {
return "is-error";
}
}

refresh() {
this.loading = true;
this.getJobs();
}

async getJobs() {
try {
this.jobs = await ImportService.getProgramUploads(this.activeProgram!.id!, false);
this.jobs = await JobService.getProgramJobs(this.activeProgram!.id!);
this.pagination.totalCount = this.jobs.length;
this.pagination.pageSize = 10;
this.pagination.currentPage = 1;
Expand Down

0 comments on commit dc6d733

Please sign in to comment.