From e5e7651db9726a219cac677ff8c872f5019a4d3d Mon Sep 17 00:00:00 2001 From: ndr_brt Date: Wed, 27 Mar 2024 10:01:50 +0100 Subject: [PATCH] feat(dsp): cache dspace jsonld context document (#4048) * feat(dsp): cache dspace jsonld context document * pr remark --- .../eclipse/edc/jsonld/JsonLdExtension.java | 12 +++- .../src/main/resources/document/dspace.jsonld | 62 +++++++++++++++++++ 2 files changed, 71 insertions(+), 3 deletions(-) create mode 100644 extensions/common/json-ld/src/main/resources/document/dspace.jsonld diff --git a/extensions/common/json-ld/src/main/java/org/eclipse/edc/jsonld/JsonLdExtension.java b/extensions/common/json-ld/src/main/java/org/eclipse/edc/jsonld/JsonLdExtension.java index 9056f56d97f..72300709772 100644 --- a/extensions/common/json-ld/src/main/java/org/eclipse/edc/jsonld/JsonLdExtension.java +++ b/extensions/common/json-ld/src/main/java/org/eclipse/edc/jsonld/JsonLdExtension.java @@ -33,6 +33,7 @@ import java.io.File; import java.net.URI; import java.net.URISyntaxException; +import java.util.stream.Stream; import static java.lang.String.format; import static org.eclipse.edc.spi.CoreConstants.EDC_NAMESPACE; @@ -89,9 +90,13 @@ public JsonLd createJsonLdService(ServiceExtensionContext context) { } service.registerNamespace(EDC_PREFIX, EDC_NAMESPACE); - getResourceUri("document" + File.separator + "odrl.jsonld") - .onSuccess(uri -> service.registerCachedDocument("http://www.w3.org/ns/odrl.jsonld", uri)) - .onFailure(failure -> monitor.warning("Failed to register cached json-ld document: " + failure.getFailureDetail())); + Stream.of( + new JsonLdContext("odrl.jsonld", "http://www.w3.org/ns/odrl.jsonld"), + new JsonLdContext("dspace.jsonld", "https://w3id.org/dspace/2024/1/context.json") + ).forEach(jsonLdContext -> getResourceUri("document" + File.separator + jsonLdContext.fileName()) + .onSuccess(uri -> service.registerCachedDocument(jsonLdContext.url(), uri)) + .onFailure(failure -> monitor.warning("Failed to register cached json-ld document: " + failure.getFailureDetail())) + ); registerCachedDocumentsFromConfig(context, service); @@ -126,5 +131,6 @@ private Result getResourceUri(String name) { } } + record JsonLdContext(String fileName, String url) { } } diff --git a/extensions/common/json-ld/src/main/resources/document/dspace.jsonld b/extensions/common/json-ld/src/main/resources/document/dspace.jsonld new file mode 100644 index 00000000000..f475b23504f --- /dev/null +++ b/extensions/common/json-ld/src/main/resources/document/dspace.jsonld @@ -0,0 +1,62 @@ +{ + "@context": { + "odrl": "http://www.w3.org/ns/odrl/2/", + "xsd": "http://www.w3.org/2001/XMLSchema#", + "cred": "https://www.w3.org/2018/credentials#", + "sec": "https://w3id.org/security#", + "foaf": "http://xmlns.com/foaf/0.1/", + "cc": "http://creativecommons.org/ns#", + "dct": "http://purl.org/dc/terms/", + "dcat": "http://www.w3.org/ns/dcat#", + "dspace": "https://w3id.org/dspace/2024/1/", + + "dct:title": { "@language": "en" }, + "dct:creator": { "@type": "@id" }, + "dct:description": { "@container": "@set" }, + "dct:issued": { "@type": "xsd:dateTime" }, + "dct:modified": { "@type": "xsd:dateTime" }, + + "dcat:byteSize": { "@type": "xsd:decimal" }, + "dcat:distribution": { "@container": "@set" }, + "dcat:theme": { "@type": "@id" }, + "dcat:conformsTo": { "@type": "@id" }, + "dcat:dataset": { "@container": "@set" }, + "dcat:endpointURL": { "@type": "xsd:anyURI" }, + "dcat:endpointDescription": { "@type": "xsd:anyURI" }, + "dcat:keyword": { "@container": "@set" }, + "dcat:servesDataset": {"@container": "@set" }, + "dcat:service": { "@container": "@set" }, + "dcat:accessService": { "@container": "@set" }, + + "dspace:agreementId": { "@type": "@id" }, + "dspace:dataset": { "@type": "@id" }, + "dspace:transportType": { "@type": "@id" }, + "dspace:state": { "@type": "@id" }, + "dspace:providerId": { "@type": "@id" }, + "dspace:consumerId": { "@type": "@id" }, + "dspace:participantId": { "@type": "@id" }, + "dspace:reason": { "@container": "@set" }, + "dspace:catalog": { "@container": "@set" }, + "dspace:filter": { "@container": "@set" }, + "dspace:timestamp": { "@type": "xsd:dateTime" }, + "dspace:callbackAddress": { "@type": "xsd:anyURI" }, + "dspace:endpointProperties": { "@container": "@set" }, + + "foaf:homepage": { "@type": "xsd:anyURI" }, + + "odrl:hasPolicy": { "@container": "@set" }, + "odrl:permission": { "@container": "@set" }, + "odrl:prohibition": { "@container": "@set" }, + "odrl:obligation": { "@container": "@set" }, + "odrl:duty": { "@container": "@set" }, + "odrl:constraint": { "@container": "@set" }, + "odrl:action": { "@type": "@id" }, + "odrl:target": { "@type": "@id" }, + "odrl:leftOperand": { "@type": "@id" }, + "odrl:operator": { "@type": "@id" }, + "odrl:rightOperandReference": { "@type": "@id" }, + "odrl:profile": { "@container": "@set" } + "odrl:assigner": { "@type": "@id" }, + "odrl:assignee": { "@type": "@id" } + } +}