//© 2019 Dublin City University, Trinity College Dublin. All rights reserved. This material may not be reproduced, displayed, modified or distributed without the express prior written permission of the copyright holder. import React, { Component } from 'react'; import { Modal, ModalHeader, ModalBody, ModalFooter, Button, Row, Col, ListGroup, TabContent, Card, CardBody } from 'reactstrap'; import { connect } from 'react-redux'; import { read } from '../../../services/tripleStoreAPIs/readFromTripleStore'; import { getErrorReportForModelDefault } from '../../../services/tripleStoreAPIs/sparql/problemReport/getErrorReportForModelDefault'; import { getErrorReportForModelProblematicTriple } from '../../../services/tripleStoreAPIs/sparql/problemReport/getErrorReportForModelProblematicTriple'; import { getErrorReportForResource } from '../../../services/tripleStoreAPIs/sparql/problemReport/getErrorReportForResource'; import { getErrorReportForQuad } from '../../../services/tripleStoreAPIs/sparql/problemReport/getErrorReportForQuad'; import ListOfProblems from './ListOfProblems'; import ResourcesFailedForProblem from './ResourcesFailedForProblem'; import LoadingSpinner from '../loading'; import LoadingFailed from '../loadingFailed'; import metricExceptionMapping from '../../../config/metricKnowledgeBaseMapping'; class ErrorReport extends Component { constructor(props) { super(props); this.state = { isloading: false, loadFailed: false, totalNumberOfTriplesWithProblem: 0, listOfExceptionsWithCount: [], listOfProblematicThings: [], listOfRelatedFailedMetrics:[], activeTab: 0 } } toggleActiveTab = (tab) => { if (this.state.activeTab !== tab) { this.setState({ activeTab: tab, listOfRelatedFailedMetrics:[] }); } } componentDidMount() { let indexOfMetric = this.props.datasetDetailsCache[0].lastAssessmentMetrics.findIndex((assessment) => { return assessment.Metric.value === this.props.metricURI }); if (this.props.datasetDetailsCache[0].lastAssessmentMetrics[indexOfMetric].errorReport === undefined) { this.setState({ isloading: true }, () => { this.prepareErrorReportCache(indexOfMetric, this.props.datasetDetailsCache[0].lastAssessmentMetrics[indexOfMetric].ProblemStructure.value.split("#")[1], this.props.datasetDetailsCache[0].lastAssessmentMetrics[indexOfMetric].Metric.value.split("#")[1]).then(() => { this.setState( { isloading: false }, () => { if (this.props.datasetDetailsCache[0].lastAssessmentMetrics[indexOfMetric].errorReport !== undefined) { this.prepareUI(indexOfMetric); } } ); }) }); } else { if (this.props.datasetDetailsCache[0].lastAssessmentMetrics[indexOfMetric].errorReport !== undefined) { this.prepareUI(indexOfMetric); } } } prepareUI = async (indexOfMetric) => { let totalNumberOfTriplesWithProblem = await this.prepareTotalNumberOfTriplesWithProblem(indexOfMetric); let listOfExceptionsWithCount = await this.prepareListOfExceptionsWithCount(indexOfMetric); let listOfProblematicThings = await this.prepareListOfProblematicThings(indexOfMetric); this.setState({ totalNumberOfTriplesWithProblem: totalNumberOfTriplesWithProblem, listOfExceptionsWithCount: listOfExceptionsWithCount, listOfProblematicThings: listOfProblematicThings }); } prepareTotalNumberOfTriplesWithProblem = (indexOfMetric) => { let exceptions = Object.keys(this.props.datasetDetailsCache[0].lastAssessmentMetrics[indexOfMetric].errorReport); let count = 0; for (let exception of exceptions) { count += this.props.datasetDetailsCache[0].lastAssessmentMetrics[indexOfMetric].errorReport[exception].count; } return count; } prepareListOfExceptionsWithCount = (indexOfMetric) => { let exceptions = Object.keys(this.props.datasetDetailsCache[0].lastAssessmentMetrics[indexOfMetric].errorReport); let listOfExceptions = []; for (let exception of exceptions) { listOfExceptions.push({ [exception]: this.props.datasetDetailsCache[0].lastAssessmentMetrics[indexOfMetric].errorReport[exception].count }); } return listOfExceptions; } prepareListOfProblematicThings = (indexOfMetric) => { let exceptions = Object.keys(this.props.datasetDetailsCache[0].lastAssessmentMetrics[indexOfMetric].errorReport); let listOfProblematicThings = []; for (let exception of exceptions) { let problematicThings = Object.keys(this.props.datasetDetailsCache[0].lastAssessmentMetrics[indexOfMetric].errorReport[exception].ProblematicThing); for (let problematicThing of problematicThings) { listOfProblematicThings.push({ [problematicThing]: [(this.props.datasetDetailsCache[0].lastAssessmentMetrics[indexOfMetric].errorReport[exception].ProblematicThing[problematicThing].filter(resource => resource !== "")).length,exception] }); } } return listOfProblematicThings; } prepareErrorReportCache = async (index, problemStrucure, metricURI) => { let errorReport = null; if (problemStrucure === "ModelContainer") { let functionToCall = getErrorReportForModelDefault; let listOfExceptions = ""; let listOfHasExceptions = ""; switch (metricURI) { case "UsageOfIncorrectDomainOrRangeDatatypesMetric": functionToCall = getErrorReportForModelProblematicTriple; break; default: functionToCall = getErrorReportForModelDefault; if(metricExceptionMapping.knowledgeBaseMapping[metricURI]!==undefined) { let exceptions = Object.keys(metricExceptionMapping.knowledgeBaseMapping[metricURI]).map((exception)=> "dqm-prob:"+exception); listOfExceptions = exceptions.join(", ") ; let hasExceptions = Object.keys(metricExceptionMapping.knowledgeBaseMapping[metricURI]).map((exception)=> "dqm-prob:has"+exception); listOfHasExceptions = hasExceptions.join(", "); } } if(listOfExceptions==="") { errorReport = await read(functionToCall(this.props.datasetDetailsCache[0].lastAssessmentMetrics[index].ProblemGraph.value, this.props.datasetDetailsCache[0].lastAssessmentMetrics[index].ObservationURI.value)).then((response) => { if (response) { if (response.results.bindings.length > 0) { return response; } } return null; }); } else { errorReport = await read(functionToCall(this.props.datasetDetailsCache[0].lastAssessmentMetrics[index].ProblemGraph.value, this.props.datasetDetailsCache[0].lastAssessmentMetrics[index].ObservationURI.value, listOfExceptions, listOfHasExceptions)).then((response) => { if (response) { if (response.results.bindings.length > 0) { return response; } } return null; }); } } else if (problemStrucure === "ResourceContainer") { errorReport = await read(getErrorReportForResource(this.props.datasetDetailsCache[0].lastAssessmentMetrics[index].ProblemGraph.value, this.props.datasetDetailsCache[0].lastAssessmentMetrics[index].ObservationURI.value)).then((response) => { if (response) { if (response.results.bindings.length > 0) { return response; } } return null; }); } else if (problemStrucure === "QuadContainer") { errorReport = await read(getErrorReportForQuad(this.props.datasetDetailsCache[0].lastAssessmentMetrics[index].ProblemGraph.value, this.props.datasetDetailsCache[0].lastAssessmentMetrics[index].ObservationURI.value)).then((response) => { if (response) { if (response.results.bindings.length > 0) { return response; } } return null; }); } if (errorReport !== null) { let cache = {}; for (let error of errorReport.results.bindings) { let exception = error.Exception.value; let problematicThing = ""; if (error.ProblematicThing !== undefined) { problematicThing = error.ProblematicThing.value; } let problematicThingResource = ""; if (error.ProblematicThingResource !== undefined) { problematicThingResource = error.ProblematicThingResource.value; } //Exception Key doesn't exists if (!(exception in cache)) { cache[exception] = { count: 1, ProblematicThing: { [problematicThing]: [problematicThingResource] } }; } else { cache[exception].count += 1; //Exception Key exists but problematicThing doesn't exists if (!(problematicThing in cache[exception].ProblematicThing)) { cache[exception].ProblematicThing = { ...cache[exception].ProblematicThing, [problematicThing]: [problematicThingResource] }; } else { cache[exception].ProblematicThing[problematicThing].push(problematicThingResource); } } } await this.props.updateErrorReportCache(cache, Number(this.props.datasetID), index); } return; } listRelatedProblems=(listOfRelatedMetrics)=>{ this.setState({ listOfRelatedFailedMetrics:listOfRelatedMetrics }); } render() { //console.log(this.state); let listOfRelatedFailedMetricsToDisplay=null; if(this.state.listOfRelatedFailedMetrics.length>0) { if(this.state.listOfRelatedFailedMetrics.length===1 & this.state.listOfRelatedFailedMetrics[0]==="") { //Nothing to do } else { listOfRelatedFailedMetricsToDisplay= this.state.listOfRelatedFailedMetrics.map((metric, index) => { if(metric!=="") { return
  • {metric}
  • } }); } } return ( Problem Report

    List of Problematic Instances

    Problematic Instance Details

    All Metric(s) failed for the selected Resource

    {listOfRelatedFailedMetricsToDisplay}
    {this.state.isloading ? : null}
    ); } } const mapStateToProps = (state, ownProps) => { let datasetID = Number(ownProps.datasetID); let datasetDetails = state.datasetDetailsCache.filter((dataset) => { if (dataset.datasetID === datasetID) { return dataset; } return null; }); return ( { datasetDetailsCache: datasetDetails } ); } const mapDispatchToProps = (dispatch) => { return ({ updateErrorReportCache: (errorReport, datasetID, metricIndex) => { return dispatch({ type: 'UPDATE_METRIC_ERROR_REPORT_CACHE', payLoad: { errorReport: errorReport, datasetID: datasetID, metricIndex: metricIndex } }); } } ); } export default connect(mapStateToProps, mapDispatchToProps)(ErrorReport);