-
Notifications
You must be signed in to change notification settings - Fork 244
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: first JSON-LD context for management api (#4256)
* feat: first JSON-LD context for management api * pr remarks * chore: deps file * chore: pr suggestions
- Loading branch information
Showing
10 changed files
with
993 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
extensions/common/api/management-api-json-ld-context/build.gradle.kts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* Copyright (c) 2024 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Apache License, Version 2.0 which is available at | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* Contributors: | ||
* Bayerische Motoren Werke Aktiengesellschaft (BMW AG) - initial API and implementation | ||
* | ||
*/ | ||
|
||
plugins { | ||
`java-library` | ||
} | ||
|
||
dependencies { | ||
api(project(":spi:common:json-ld-spi")) | ||
|
||
implementation(project(":core:common:lib:transform-lib")) | ||
implementation(project(":core:control-plane:control-plane-transform")) | ||
|
||
testImplementation(project(":spi:common:edr-store-spi")) | ||
testImplementation(project(":core:common:connector-core")) | ||
testImplementation(project(":core:control-plane:control-plane-transform")) | ||
testImplementation(project(":core:common:junit")) | ||
testImplementation(project(":core:common:lib:json-ld-lib")) | ||
testImplementation(project(":extensions:common:json-ld")) | ||
testImplementation(project(":extensions:common:http:jetty-core")) | ||
testImplementation(project(":extensions:common:http:jersey-core")) | ||
testImplementation(project(":extensions:common:api:management-api-configuration")) | ||
testImplementation(project(":extensions:control-plane:api:management-api:contract-definition-api")) | ||
testImplementation(project(":extensions:control-plane:api:management-api:contract-negotiation-api")) | ||
testImplementation(project(":extensions:control-plane:api:management-api:policy-definition-api")) | ||
testImplementation(project(":extensions:control-plane:api:management-api:transfer-process-api")) | ||
testImplementation(project(":extensions:control-plane:api:management-api:secrets-api")) | ||
testImplementation(project(":extensions:control-plane:api:management-api:edr-cache-api")) | ||
} | ||
|
||
edcBuild { | ||
swagger { | ||
apiGroup.set("management-api") | ||
} | ||
} | ||
|
||
|
72 changes: 72 additions & 0 deletions
72
.../org/eclipse/edc/connector/api/management/jsonld/ManagementApiJsonLdContextExtension.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/* | ||
* Copyright (c) 2024 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Apache License, Version 2.0 which is available at | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* Contributors: | ||
* Bayerische Motoren Werke Aktiengesellschaft (BMW AG) - initial API and implementation | ||
* | ||
*/ | ||
|
||
package org.eclipse.edc.connector.api.management.jsonld; | ||
|
||
import org.eclipse.edc.jsonld.spi.JsonLd; | ||
import org.eclipse.edc.runtime.metamodel.annotation.Inject; | ||
import org.eclipse.edc.spi.monitor.Monitor; | ||
import org.eclipse.edc.spi.result.Result; | ||
import org.eclipse.edc.spi.system.ServiceExtension; | ||
import org.eclipse.edc.spi.system.ServiceExtensionContext; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.net.URI; | ||
import java.net.URISyntaxException; | ||
import java.util.Map; | ||
|
||
import static java.lang.String.format; | ||
|
||
public class ManagementApiJsonLdContextExtension implements ServiceExtension { | ||
|
||
public static final String EDC_CONNECTOR_MANAGEMENT_CONTEXT = "https://w3id.org/edc/connector/management/v0.0.1"; | ||
public static final String EDC_CONNECTOR_MANAGEMENT_SCOPE = "MANAGEMENT_API"; | ||
|
||
private static final String PREFIX = "document/"; | ||
private static final Map<String, String> FILES = Map.of( | ||
EDC_CONNECTOR_MANAGEMENT_CONTEXT, PREFIX + "management-context-v1.jsonld"); | ||
|
||
@Inject | ||
private JsonLd jsonLdService; | ||
|
||
@Inject | ||
private Monitor monitor; | ||
|
||
@Override | ||
public void initialize(ServiceExtensionContext context) { | ||
jsonLdService.registerContext(EDC_CONNECTOR_MANAGEMENT_CONTEXT, EDC_CONNECTOR_MANAGEMENT_SCOPE); | ||
FILES.entrySet().stream().map(this::mapToUri) | ||
.forEach(result -> result.onSuccess(entry -> jsonLdService.registerCachedDocument(entry.getKey(), entry.getValue())) | ||
.onFailure(failure -> monitor.warning("Failed to register cached json-ld document: " + failure.getFailureDetail()))); | ||
} | ||
|
||
private Result<Map.Entry<String, URI>> mapToUri(Map.Entry<String, String> fileEntry) { | ||
return getResourceUri(fileEntry.getValue()) | ||
.map(file1 -> Map.entry(fileEntry.getKey(), file1)); | ||
} | ||
|
||
@NotNull | ||
private Result<URI> getResourceUri(String name) { | ||
var uri = getClass().getClassLoader().getResource(name); | ||
if (uri == null) { | ||
return Result.failure(format("Cannot find resource %s", name)); | ||
} | ||
|
||
try { | ||
return Result.success(uri.toURI()); | ||
} catch (URISyntaxException e) { | ||
return Result.failure(format("Cannot read resource %s: %s", name, e.getMessage())); | ||
} | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
...-context/src/main/resources/META-INF/services/org.eclipse.edc.spi.system.ServiceExtension
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# | ||
# Copyright (c) 2024 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) | ||
# | ||
# This program and the accompanying materials are made available under the | ||
# terms of the Apache License, Version 2.0 which is available at | ||
# https://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# | ||
# Contributors: | ||
# Bayerische Motoren Werke Aktiengesellschaft (BMW AG) - initial API and implementation | ||
# | ||
# | ||
|
||
org.eclipse.edc.connector.api.management.jsonld.ManagementApiJsonLdContextExtension |
116 changes: 116 additions & 0 deletions
116
...i/management-api-json-ld-context/src/main/resources/document/management-context-v1.jsonld
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
{ | ||
"@context": { | ||
"@version": 1.1, | ||
"edc": "https://w3id.org/edc/v0.0.1/ns/", | ||
"Asset": "edc:Asset", | ||
"PolicyDefinition": "edc:PolicyDefinition", | ||
"DataAddress": { | ||
"@id": "edc:DataAddress", | ||
"@context": { | ||
"type": "edc:type" | ||
} | ||
}, | ||
"ContractDefinition": "edc:ContractDefinition", | ||
"Criterion": "edc:Criterion", | ||
"ContractRequest": "edc:ContractRequest", | ||
"QuerySpec": "edc:QuerySpec", | ||
"ContractNegotiation": { | ||
"@id": "edc:ContractNegotiation", | ||
"@context": { | ||
"type": "edc:type" | ||
} | ||
}, | ||
"CallbackAddress": "edc:CallbackAddress", | ||
"NegotiationState": "edc:NegotiationState", | ||
"TerminateNegotiation": "edc:TerminateNegotiation", | ||
"ContractAgreement": "edc:ContractAgreement", | ||
"TransferRequest": "edc:TransferRequest", | ||
"TransferState": "edc:TransferState", | ||
"TransferProcess": { | ||
"@id": "edc:TransferProcess", | ||
"@context": { | ||
"type": "edc:type" | ||
} | ||
}, | ||
"TerminateTransfer": "edc:TerminateTransfer", | ||
"SuspendTransfer": "edc:SuspendTransfer", | ||
"Secret": "edc:Secret", | ||
"EndpointDataReferenceEntry": "edc:EndpointDataReferenceEntry", | ||
"properties": { | ||
"@id": "edc:properties", | ||
"@context": { | ||
"@vocab": "https://w3id.org/edc/v0.0.1/ns/" | ||
} | ||
}, | ||
"privateProperties": { | ||
"@id": "edc:privateProperties", | ||
"@context": { | ||
"@vocab": "https://w3id.org/edc/v0.0.1/ns/" | ||
} | ||
}, | ||
"dataAddress": { | ||
"@id": "edc:dataAddress", | ||
"@context": { | ||
"@vocab": "https://w3id.org/edc/v0.0.1/ns/" | ||
} | ||
}, | ||
"createdAt": "edc:createdAt", | ||
"accessPolicyId": "edc:accessPolicyId", | ||
"contractPolicyId": "edc:contractPolicyId", | ||
"assetsSelector": { | ||
"@id": "edc:assetsSelector", | ||
"@container": "@set" | ||
}, | ||
"operandLeft": "edc:operandLeft", | ||
"operator": "edc:operator", | ||
"operandRight": "edc:operandRight", | ||
"limit": "edc:limit", | ||
"offset": "edc:offset", | ||
"filterExpression": { | ||
"@id": "edc:filterExpression", | ||
"@container": "@set" | ||
}, | ||
"sortOrder": "edc:sortOrder", | ||
"sortField": "edc:sortField", | ||
"counterPartyAddress": "edc:counterPartyAddress", | ||
"protocol": "edc:protocol", | ||
"callbackAddresses": { | ||
"@id": "edc:callbackAddresses", | ||
"@container": "@set" | ||
}, | ||
"providerId": "edc:providerId", | ||
"policy": { | ||
"@id": "edc:policy", | ||
"@context": [ | ||
"http://www.w3.org/ns/odrl.jsonld", | ||
{ | ||
"uid": null, | ||
"type": null | ||
} | ||
] | ||
}, | ||
"counterPartyId": "edc:counterPartyId", | ||
"state": "edc:state", | ||
"errorDetail": "edc:errorDetail", | ||
"contractAgreementId": "edc:contractAgreementId", | ||
"uri": "edc:uri", | ||
"transactional": "edc:transactional", | ||
"events": { | ||
"@id": "edc:events", | ||
"@container": "@set" | ||
}, | ||
"reason": "edc:reason", | ||
"assetId": "edc:assetId", | ||
"consumerId": "edc:consumerId", | ||
"contractSigningDate": "edc:contractSigningDate", | ||
"contractId": "edc:contractId", | ||
"dataDestination": "edc:dataDestination", | ||
"correlationId": "edc:correlationId", | ||
"stateTimestamp": "edc:stateTimestamp", | ||
"value": "edc:value", | ||
"transferProcessId": "edc:transferProcessId", | ||
"contractNegotiationId": "edc:contractNegotiationId", | ||
"agreementId": "edc:agreementId", | ||
"inForceDate": "edc:inForceDate" | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
...se/edc/connector/api/management/jsonld/serde/ManagementApiJsonLdContextExtensionTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* Copyright (c) 2024 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Apache License, Version 2.0 which is available at | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* Contributors: | ||
* Bayerische Motoren Werke Aktiengesellschaft (BMW AG) - initial API and implementation | ||
* | ||
*/ | ||
|
||
package org.eclipse.edc.connector.api.management.jsonld.serde; | ||
|
||
import org.eclipse.edc.connector.api.management.jsonld.ManagementApiJsonLdContextExtension; | ||
import org.eclipse.edc.jsonld.spi.JsonLd; | ||
import org.eclipse.edc.junit.extensions.DependencyInjectionExtension; | ||
import org.eclipse.edc.spi.system.ServiceExtensionContext; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
|
||
import static org.eclipse.edc.connector.api.management.jsonld.ManagementApiJsonLdContextExtension.EDC_CONNECTOR_MANAGEMENT_CONTEXT; | ||
import static org.eclipse.edc.connector.api.management.jsonld.ManagementApiJsonLdContextExtension.EDC_CONNECTOR_MANAGEMENT_SCOPE; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.verify; | ||
|
||
@ExtendWith(DependencyInjectionExtension.class) | ||
class ManagementApiJsonLdContextExtensionTest { | ||
|
||
private final JsonLd jsonLd = mock(); | ||
private ManagementApiJsonLdContextExtension extension; | ||
|
||
@BeforeEach | ||
void setup(ServiceExtensionContext context) { | ||
context.registerService(JsonLd.class, jsonLd); | ||
} | ||
|
||
@Test | ||
void initialize(ManagementApiJsonLdContextExtension extension, ServiceExtensionContext context) { | ||
extension.initialize(context); | ||
verify(jsonLd).registerContext(EDC_CONNECTOR_MANAGEMENT_CONTEXT, EDC_CONNECTOR_MANAGEMENT_SCOPE); | ||
} | ||
} |
Oops, something went wrong.