metadata-validator-ui/src/app/pages/oaipmh-validator/validation-analysis/oaipmh-analysis.component.ts

187 lines
6.6 KiB
TypeScript

import {Component, OnInit, ViewChild} from '@angular/core';
import {UntypedFormGroup} from "@angular/forms";
import {OaipmhValidatorService} from "../../../services/oaipmh-validator.service";
import {Subscriber} from "rxjs";
import {ActivatedRoute} from "@angular/router";
import {RulePerJob, Status} from "../../entities/RulePerJob";
import {Issue} from "../../entities/Issue";
import {JobResult} from "../../entities/JobResult";
import {Breadcrumb} from "../../../openaire-library/utils/breadcrumbs/breadcrumbs.component";
export class Duration {
years: number;
months: number;
days: number;
hours: number;
minutes: number;
seconds: number;
}
@Component({
selector: 'app-oaipmh-analysis',
templateUrl: './oaipmh-analysis.component.html',
styleUrls: ['./oaipmh-analysis.component.less']
})
export class OaipmhAnalysisComponent implements OnInit {
public form: UntypedFormGroup;
public jobResult: JobResult = null;
public jobDuration: Duration = null;
public validationResult: Map<string, { "analysisResult": RulePerJob[], "successfulAnalysisResult": RulePerJob[], "warningAnalysisResult": RulePerJob[], "failedAnalysisResult": RulePerJob[] }>;
// public analysisResult: RulePerJob[] = [];
// public successfulAnalysisResult: RulePerJob[] = [];
// public warningAnalysisResult: RulePerJob[] = [];
// public failedAnalysisResult: RulePerJob[] = [];
public warningsModalOpen: boolean = false;
public errorsModalOpen: boolean = false;
public warnings: Issue[];
public errors: Issue[];
public internal_error: string;
@ViewChild('warningsModal') warningsModal;
@ViewChild('errorsModal') errorsModal;
public offset: number;
public jobId: string = "";
public breadcrumbs: Breadcrumb[] = [{name: 'home', route: '/'}, {name: 'Validator\'s History', route: '/oaipmh-history'}, {name: 'Result for ...'}];
subscriptions = [];
public guidelinesLabelToPrefix: Map<string, string> = new Map([
['OpenAIRE Guidelines for Literature Repositories Profile v4', 'oai_openaire'],
['OpenAIRE Guidelines for Literature Repositories Profile v3', 'oai_dc'],
['OpenAIRE Guidelines for Data Archives Profile v2', 'oai_datacite'],
['OpenAIRE FAIR Guidelines for Data Repositories Profile', 'oai_datacite']
]);
constructor(private route: ActivatedRoute, private validator: OaipmhValidatorService) {
}
ngOnInit(): void {
this.subscriptions.push(this.route.queryParams.subscribe(params => {
this.jobId = params['jobId'];
this.validationResult = new Map<string, {"analysisResult": RulePerJob[], "successfulAnalysisResult": RulePerJob[], "warningAnalysisResult": RulePerJob[], "failedAnalysisResult": RulePerJob[] }>;
// this.analysisResult = [];
// this.successfulAnalysisResult = [];
// this.warningAnalysisResult = [];
// this.failedAnalysisResult = [];
this.jobResult = null;
if(this.jobId) {
this.getAnalysis();
this.getJobResult();
}
}));
}
ngAfterViewInit() {
if (typeof document !== 'undefined') {
if (document.getElementById("main-menu")) {
this.offset = Number.parseInt(getComputedStyle(document.documentElement).getPropertyValue('--header-height'));
} else {
this.offset = 0;
}
}
}
ngOnDestroy() {
this.subscriptions.forEach(subscription => {
if (subscription instanceof Subscriber) {
subscription.unsubscribe();
}
});
}
public getAnalysis() {
this.validator.getAnalysis(this.jobId).subscribe(
(result: RulePerJob[]) => {
console.log(result);
// this.analysisResult = result;
for(let rulePerJob of result) {
if(!this.validationResult.has(rulePerJob.guidelines)) {
this.validationResult.set(rulePerJob.guidelines, {analysisResult: [], successfulAnalysisResult: [], warningAnalysisResult: [], failedAnalysisResult: []});
}
this.validationResult.get(rulePerJob.guidelines).analysisResult.push(rulePerJob);
if(rulePerJob.rule_status == Status.FAILURE || rulePerJob.rule_status == Status.ERROR) {
this.validationResult.get(rulePerJob.guidelines).failedAnalysisResult.push(rulePerJob);
} else {
if(rulePerJob.has_warnings || rulePerJob.has_errors || rulePerJob.internal_error) {
this.validationResult.get(rulePerJob.guidelines).warningAnalysisResult.push(rulePerJob);
} else {
this.validationResult.get(rulePerJob.guidelines).successfulAnalysisResult.push(rulePerJob);
}
}
}
}
);
}
public openWarningsModal(rule: RulePerJob) {
this.warningsModalOpen = true;
this.warningsModal.cancelButton = false;
this.warningsModal.okButton = false;
this.warningsModal.alertTitle = rule.rule_name;
this.warningsModal.open();
}
public openErrorsModal(rule: RulePerJob) {
this.errorsModalOpen = true;
this.errorsModal.cancelButton = false;
this.errorsModal.okButton = false;
this.errorsModal.alertTitle = rule.rule_name;
this.errorsModal.open();
}
getWarnings(rule: RulePerJob) {
this.warnings = [];
this.openWarningsModal(rule);
this.warningsModalOpen = true;
this.validator.getWarnings(this.jobId, rule.rule_name).subscribe(
result => {
this.warnings = result;
console.log(result);
// this.result = result;
}
);
}
getErrors(rule: RulePerJob) {
this.internal_error = rule.internal_error;
this.errors = [];
this.openErrorsModal(rule);
this.errorsModalOpen = true;
if(rule.has_errors) {
this.validator.getErrors(this.jobId, rule.rule_name).subscribe(
result => {
this.errors = result;
console.log(result);
}
);
}
}
public getJobResult() {
this.validator.getJobResult(this.jobId).subscribe(
(result: JobResult) => {
this.jobResult = result;
let startDate = new Date(this.jobResult.startDate);
let endDate = this.jobResult.endDate ? new Date(this.jobResult.endDate) : new Date();
this.jobDuration = new Duration();
const msBetweenDates = endDate.getTime() - startDate.getTime();
this.jobDuration.seconds = Math.ceil(msBetweenDates / 1000 % 60);
this.jobDuration.minutes = Math.floor(msBetweenDates / 1000 / 60 % 60);
this.jobDuration.hours = Math.floor(msBetweenDates / 1000 / 60 / 60 % 24);
this.jobDuration.days = Math.floor(msBetweenDates / 1000 / 60 / 60 / 24);
this.jobDuration.months = Math.floor(this.jobDuration.days / 31);
this.jobDuration.years = Math.floor(this.jobDuration.months / 12);
}
);
}
protected readonly Status = Status;
}