From fbe6acf4f3c78b20c6ddb14482b8d74cb221218e Mon Sep 17 00:00:00 2001 From: Martin Vanbrabant Date: Tue, 30 Jan 2024 15:24:06 +0100 Subject: [PATCH] Made fetch status consistent; added test for it. --- CHANGELOG.md | 1 + cypress/e2e/aggregating-query.cy.js | 2 +- cypress/e2e/sources-info.cy.js | 31 +++++++--- initial-pod-data/boms$.ttl | 58 +++++++++++++++++++ initial-pod-data/boms.acl | 14 +++++ initial-pod-data/components$.ttl | 15 +++++ initial-pod-data/components.acl | 14 +++++ initial-pod-data/materials$.ttl | 33 +++++++++++ initial-pod-data/materials.acl | 14 +++++ public/queries/components-materials.rq | 25 ++++++++ public/queries/components.rq | 19 ++++++ .../SourceFetchStatusIcon.jsx | 6 +- src/config.json | 26 ++++++++- src/dataProvider/SparqlDataProvider.js | 6 +- 14 files changed, 251 insertions(+), 13 deletions(-) create mode 100644 initial-pod-data/boms$.ttl create mode 100644 initial-pod-data/boms.acl create mode 100644 initial-pod-data/components$.ttl create mode 100644 initial-pod-data/components.acl create mode 100644 initial-pod-data/materials$.ttl create mode 100644 initial-pod-data/materials.acl create mode 100644 public/queries/components-materials.rq create mode 100644 public/queries/components.rq diff --git a/CHANGELOG.md b/CHANGELOG.md index dcca0c66..d0862acb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed - Aggregating SPARQL queries work now (#70). +- Sources' fetch status is consistent now (#59). ### Removed diff --git a/cypress/e2e/aggregating-query.cy.js b/cypress/e2e/aggregating-query.cy.js index 1ecbc4d6..12fb7321 100644 --- a/cypress/e2e/aggregating-query.cy.js +++ b/cypress/e2e/aggregating-query.cy.js @@ -1,5 +1,5 @@ describe("Aggregating query", () => { - it("AVG() function", () => { + it("AVG() function - see https://github.com/SolidLabResearch/generic-data-viewer-react-admin/issues/70", () => { cy.visit("/"); cy.contains("Average value").click(); diff --git a/cypress/e2e/sources-info.cy.js b/cypress/e2e/sources-info.cy.js index 2e18079d..40a74557 100644 --- a/cypress/e2e/sources-info.cy.js +++ b/cypress/e2e/sources-info.cy.js @@ -1,25 +1,42 @@ describe("Sources info", () => { - it("Fetch status on query failed", () => { + it("Fetch status on fetch failure", () => { cy.visit("/"); cy.contains("My favourite musicians").click(); cy.contains("Finished in:"); cy.get('[aria-label="Sources info"]').click(); - cy.get('[aria-label="Query failed"]').should("exist"); + cy.get('[aria-label="Fetch failed"]').should("exist"); }); - it("Fetch status on query success", () => { + it("Fetch status on fetch success", () => { cy.visit("/"); cy.contains("My wish list").click(); cy.contains("Finished in:"); cy.get('[aria-label="Sources info"]').click(); - cy.get('[aria-label="Query was succesful"]').should("exist"); + cy.get('[aria-label="Fetch was succesful"]').should("exist"); }); - it("Authentication needed for query on public data", () => { + it("Fetch status on cached source - see https://github.com/SolidLabResearch/generic-data-viewer-react-admin/issues/59", () => { + cy.visit("/"); + + cy.contains("Components").click(); + cy.contains("Finished in:"); + cy.get('[aria-label="Sources info"]').click(); + + cy.get('[aria-label="Fetch was succesful"]').should("exist"); + + cy.contains("Components and their materials").click(); + cy.contains("Finished in:"); + cy.get('[aria-label="Sources info"]').click(); + + cy.get('[aria-label="Fetch was succesful"]').should("exist"); + cy.get('[aria-label="Fetch failed"]').should("not.exist"); + }); + + it("Authentication not required for query on public data", () => { cy.visit("/"); cy.contains("My wish list").click(); @@ -29,7 +46,7 @@ describe("Sources info", () => { cy.get('[aria-label="No authentication required"]').should("exist"); }); - it("Authentication needed for query on private data", () => { + it("Authentication required for query on private data", () => { cy.visit("/"); cy.get('[aria-label="Profile"]').click(); @@ -53,7 +70,7 @@ describe("Sources info", () => { cy.get('[aria-label="Authentication required"]').should("exist"); }); - it("Authentication needed for query on failing query", () => { + it("Authentication uncertain for query on not existing source", () => { cy.visit("/"); cy.contains("My favourite musicians").click(); diff --git a/initial-pod-data/boms$.ttl b/initial-pod-data/boms$.ttl new file mode 100644 index 00000000..1155e2ee --- /dev/null +++ b/initial-pod-data/boms$.ttl @@ -0,0 +1,58 @@ + + a ; + , + , . + + a ; + , + , , + , , + . + + a ; + , + . + + a ; + ; + 60 . + + a ; + ; + 30 . + + a ; + ; + 10 . + + a ; + ; + 40 . + + a ; + ; + 20 . + + a ; + ; + 25 . + + a ; + ; + 7 . + + a ; + ; + 5 . + + a ; + ; + 3 . + + a ; + ; + 85 . + + a ; + ; + 15 . diff --git a/initial-pod-data/boms.acl b/initial-pod-data/boms.acl new file mode 100644 index 00000000..15144c72 --- /dev/null +++ b/initial-pod-data/boms.acl @@ -0,0 +1,14 @@ +@prefix acl: . +@prefix foaf: . + +<#public> + a acl:Authorization; + acl:accessTo <./boms>; + acl:agentClass foaf:Agent; + acl:mode acl:Read. + +<#owner> + a acl:Authorization; + acl:accessTo <./boms>; + acl:agent ; + acl:mode acl:Read, acl:Write, acl:Control. diff --git a/initial-pod-data/components$.ttl b/initial-pod-data/components$.ttl new file mode 100644 index 00000000..c79e9915 --- /dev/null +++ b/initial-pod-data/components$.ttl @@ -0,0 +1,15 @@ + + a ; + ; + "Component 1"; + 80 . + + a ; + ; + "Component 2"; + 20 . + + a ; + ; + "Component 3"; + 0 . diff --git a/initial-pod-data/components.acl b/initial-pod-data/components.acl new file mode 100644 index 00000000..2ecd1685 --- /dev/null +++ b/initial-pod-data/components.acl @@ -0,0 +1,14 @@ +@prefix acl: . +@prefix foaf: . + +<#public> + a acl:Authorization; + acl:accessTo <./components>; + acl:agentClass foaf:Agent; + acl:mode acl:Read. + +<#owner> + a acl:Authorization; + acl:accessTo <./components>; + acl:agent ; + acl:mode acl:Read, acl:Write, acl:Control. diff --git a/initial-pod-data/materials$.ttl b/initial-pod-data/materials$.ttl new file mode 100644 index 00000000..e16e068c --- /dev/null +++ b/initial-pod-data/materials$.ttl @@ -0,0 +1,33 @@ + + a ; + "Material 1" . + + a ; + "Material 2" . + + a ; + "Material 3" . + + a ; + "Material 4" . + + a ; + "Material 5" . + + a ; + "Material 6" . + + a ; + "Material 7" . + + a ; + "Material 8" . + + a ; + "Material 9" . + + a ; + "Material 10" . + + a ; + "Material 11" . diff --git a/initial-pod-data/materials.acl b/initial-pod-data/materials.acl new file mode 100644 index 00000000..e036ca97 --- /dev/null +++ b/initial-pod-data/materials.acl @@ -0,0 +1,14 @@ +@prefix acl: . +@prefix foaf: . + +<#public> + a acl:Authorization; + acl:accessTo <./materials>; + acl:agentClass foaf:Agent; + acl:mode acl:Read. + +<#owner> + a acl:Authorization; + acl:accessTo <./materials>; + acl:agent ; + acl:mode acl:Read, acl:Write, acl:Control. diff --git a/public/queries/components-materials.rq b/public/queries/components-materials.rq new file mode 100644 index 00000000..659a2ade --- /dev/null +++ b/public/queries/components-materials.rq @@ -0,0 +1,25 @@ +# Query Texon's components and their materials +# Datasources: https://css5.onto-deside.ilabt.imec.be/texon/data/dt/out/components.ttl https://css5.onto-deside.ilabt.imec.be/texon/data/dt/out/boms.ttl https://css5.onto-deside.ilabt.imec.be/texon/data/dt/out/materials.ttl + +PREFIX oo: +PREFIX ao: +PREFIX rdf: +PREFIX rdfs: +PREFIX d: +PREFIX o: + +SELECT ?component ?componentName ?material ?materialName ?percentage +WHERE { + ?component + a o:Component ; + o:name ?componentName ; + o:has-component-bom [ + o:has-component-material-assoc [ + o:percentage ?percentage ; + o:has-material ?material ; + ]; + ]; + . + ?material o:name ?materialName ; +} +ORDER BY ?componentName diff --git a/public/queries/components.rq b/public/queries/components.rq new file mode 100644 index 00000000..845c20b6 --- /dev/null +++ b/public/queries/components.rq @@ -0,0 +1,19 @@ +# Query Texon's components +# Datasources: https://css5.onto-deside.ilabt.imec.be/texon/data/dt/out/components.ttl + +PREFIX oo: +PREFIX ao: +PREFIX rdf: +PREFIX rdfs: +PREFIX d: +PREFIX o: + +SELECT ?component ?componentName ?recycledContentPercentage +WHERE { + ?component + a o:Component ; + o:name ?componentName ; + o:recycled-content-percentage ?recycledContentPercentage ; + . +} +ORDER BY ?componentName diff --git a/src/components/ActionBar/SourceFetchStatusIcon/SourceFetchStatusIcon.jsx b/src/components/ActionBar/SourceFetchStatusIcon/SourceFetchStatusIcon.jsx index 9f189756..6dd13906 100644 --- a/src/components/ActionBar/SourceFetchStatusIcon/SourceFetchStatusIcon.jsx +++ b/src/components/ActionBar/SourceFetchStatusIcon/SourceFetchStatusIcon.jsx @@ -19,14 +19,14 @@ function SourceFetchStatusIcon({ context, source, proxyUrl }) { const status = context.fetchSuccess[actualSource]; if (status) { return ( - + ); } else { return ( - - ; + + ); } diff --git a/src/config.json b/src/config.json index 19be71e9..9a3363af 100644 --- a/src/config.json +++ b/src/config.json @@ -88,7 +88,7 @@ "comunicaContext": { "sources": [ "http://localhost:8080/example/favourite-musicians", - "httq://this-runs-on-httq.com/" + "http://www.example.com/fetch-failure-but-query-success" ], "lenient": true } @@ -144,6 +144,30 @@ "http://localhost:8080/example/values" ] } + }, + { + "queryLocation": "components.rq", + "name": "Components", + "description": "Query components (no details about materials)", + "id": "7000", + "comunicaContext": { + "sources": ["http://localhost:8080/example/components"], + "lenient": true + } + }, + { + "queryLocation": "components-materials.rq", + "name": "Components and their materials", + "description": "Query components (including details about materials)", + "id": "7001", + "comunicaContext": { + "sources": [ + "http://localhost:8080/example/components", + "http://localhost:8080/example/boms", + "http://localhost:8080/example/materials" + ], + "lenient": true + } } ] } diff --git a/src/dataProvider/SparqlDataProvider.js b/src/dataProvider/SparqlDataProvider.js index 6374ce88..dd862c28 100644 --- a/src/dataProvider/SparqlDataProvider.js +++ b/src/dataProvider/SparqlDataProvider.js @@ -205,8 +205,12 @@ function generateContext(context) { throw new HttpError("No sources provided", 500); } - if(!context.fetchSuccess){ + if (!context.fetchSuccess) { context.fetchSuccess = {}; + // avoid faulty fetch status for sources cached in Comunica + for (const source of context.sources) { + context.fetchSuccess[source] = true; + } } let fetchFunction = fetch;