Skip to content

Commit cabd506

Browse files
feat: Split Jsonld Core Extension
1 parent d2747d5 commit cabd506

File tree

17 files changed

+218
-18
lines changed

17 files changed

+218
-18
lines changed

.github/workflows/publish-context.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ on:
2626
branches: [main]
2727
paths:
2828
- 'core/json-ld-core/src/main/resources/document/**'
29+
- 'core/cx-json-ld/src/main/resources/document/**'
2930

3031
jobs:
3132
build:

core/cx-json-ld/build.gradle.kts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/********************************************************************************
2+
* Copyright (c) 2023 Bayerische Motoren Werke Aktiengesellschaft (BMW AG)
3+
* Copyright (c) 2026 SAP SE
4+
*
5+
* See the NOTICE file(s) distributed with this work for additional
6+
* information regarding copyright ownership.
7+
*
8+
* This program and the accompanying materials are made available under the
9+
* terms of the Apache License, Version 2.0 which is available at
10+
* https://www.apache.org/licenses/LICENSE-2.0.
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15+
* License for the specific language governing permissions and limitations
16+
* under the License.
17+
*
18+
* SPDX-License-Identifier: Apache-2.0
19+
********************************************************************************/
20+
21+
plugins {
22+
`java-library`
23+
}
24+
25+
dependencies {
26+
implementation(project(":spi:core-spi"))
27+
implementation(libs.edc.spi.core)
28+
implementation(libs.edc.spi.jsonld)
29+
implementation(libs.dsp.spi.v2025)
30+
implementation(libs.dsp.spi.v08)
31+
implementation(libs.edc.lib.management.api)
32+
testImplementation(testFixtures(libs.edc.junit))
33+
}
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
/********************************************************************************
2+
* Copyright (c) 2023 Bayerische Motoren Werke Aktiengesellschaft (BMW AG)
3+
* Copyright (c) 2026 SAP SE
4+
*
5+
* See the NOTICE file(s) distributed with this work for additional
6+
* information regarding copyright ownership.
7+
*
8+
* This program and the accompanying materials are made available under the
9+
* terms of the Apache License, Version 2.0 which is available at
10+
* https://www.apache.org/licenses/LICENSE-2.0.
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15+
* License for the specific language governing permissions and limitations
16+
* under the License.
17+
*
18+
* SPDX-License-Identifier: Apache-2.0
19+
********************************************************************************/
20+
21+
package org.eclipse.tractusx.edc.cx;
22+
23+
import org.eclipse.edc.jsonld.spi.JsonLd;
24+
import org.eclipse.edc.runtime.metamodel.annotation.Inject;
25+
import org.eclipse.edc.spi.monitor.Monitor;
26+
import org.eclipse.edc.spi.result.Result;
27+
import org.eclipse.edc.spi.system.ServiceExtension;
28+
import org.eclipse.edc.spi.system.ServiceExtensionContext;
29+
import org.jetbrains.annotations.NotNull;
30+
31+
import java.io.File;
32+
import java.nio.file.Files;
33+
import java.nio.file.Path;
34+
import java.util.Map;
35+
36+
import static java.lang.String.format;
37+
import static java.nio.file.StandardCopyOption.REPLACE_EXISTING;
38+
import static org.eclipse.edc.api.management.ManagementApi.MANAGEMENT_SCOPE;
39+
import static org.eclipse.edc.protocol.dsp.spi.type.Dsp08Constants.DSP_SCOPE_V_08;
40+
import static org.eclipse.edc.protocol.dsp.spi.type.Dsp2025Constants.DSP_SCOPE_V_2025_1;
41+
import static org.eclipse.tractusx.edc.edr.spi.CoreConstants.CX_POLICY_NS;
42+
import static org.eclipse.tractusx.edc.edr.spi.CoreConstants.CX_POLICY_PREFIX;
43+
44+
public class CxJsonLdExtension implements ServiceExtension {
45+
46+
@Deprecated(since = "0.11.0")
47+
public static final String CX_POLICY_CONTEXT = "https://w3id.org/tractusx/policy/v1.0.0";
48+
public static final String CX_ODRL_CONTEXT = "https://w3id.org/catenax/2025/9/policy/odrl.jsonld";
49+
public static final String CX_POLICY_2025_09_CONTEXT = "https://w3id.org/catenax/2025/9/policy/context.jsonld";
50+
51+
private static final String PREFIX = "document" + File.separator;
52+
private static final Map<String, String> FILES = Map.of(
53+
CX_POLICY_2025_09_CONTEXT, PREFIX + "cx-policy-v1.jsonld",
54+
CX_ODRL_CONTEXT, PREFIX + "cx-odrl.jsonld");
55+
@Inject
56+
private JsonLd jsonLdService;
57+
58+
@Inject
59+
private Monitor monitor;
60+
61+
@Override
62+
public void initialize(ServiceExtensionContext context) {
63+
jsonLdService.registerNamespace(CX_POLICY_PREFIX, CX_POLICY_NS, DSP_SCOPE_V_08);
64+
65+
jsonLdService.registerContext(CX_POLICY_2025_09_CONTEXT, DSP_SCOPE_V_2025_1);
66+
jsonLdService.registerContext(CX_ODRL_CONTEXT, DSP_SCOPE_V_2025_1);
67+
68+
jsonLdService.registerContext(CX_POLICY_2025_09_CONTEXT, MANAGEMENT_SCOPE);
69+
70+
FILES.entrySet().stream().map(this::mapToFile)
71+
.forEach(result -> result.onSuccess(entry -> jsonLdService.registerCachedDocument(entry.getKey(), entry.getValue().toURI()))
72+
.onFailure(failure -> monitor.warning("Failed to register cached json-ld document: " + failure.getFailureDetail())));
73+
}
74+
75+
private Result<Map.Entry<String, File>> mapToFile(Map.Entry<String, String> fileEntry) {
76+
return getResourceFile(fileEntry.getValue())
77+
.map(file1 -> Map.entry(fileEntry.getKey(), file1));
78+
}
79+
80+
@NotNull
81+
private Result<File> getResourceFile(String name) {
82+
try (var stream = getClass().getClassLoader().getResourceAsStream(name)) {
83+
if (stream == null) {
84+
return Result.failure(format("Cannot find resource %s", name));
85+
}
86+
87+
var filename = Path.of(name).getFileName().toString();
88+
var parts = filename.split("\\.");
89+
var tempFile = Files.createTempFile(parts[0], "." + parts[1]);
90+
Files.copy(stream, tempFile, REPLACE_EXISTING);
91+
return Result.success(tempFile.toFile());
92+
} catch (Exception e) {
93+
return Result.failure(format("Cannot read resource %s: ", name));
94+
}
95+
}
96+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#################################################################################
2+
# Copyright (c) 2023 Bayerische Motoren Werke Aktiengesellschaft (BMW AG)
3+
# Copyright (c) 2026 SAP SE
4+
#
5+
# See the NOTICE file(s) distributed with this work for additional
6+
# information regarding copyright ownership.
7+
#
8+
# This program and the accompanying materials are made available under the
9+
# terms of the Apache License, Version 2.0 which is available at
10+
# https://www.apache.org/licenses/LICENSE-2.0.
11+
#
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15+
# License for the specific language governing permissions and limitations
16+
# under the License.
17+
#
18+
# SPDX-License-Identifier: Apache-2.0
19+
#################################################################################
20+
21+
org.eclipse.tractusx.edc.cx.CxJsonLdExtension

core/json-ld-core/src/main/resources/document/cx-odrl.jsonld renamed to core/cx-json-ld/src/main/resources/document/cx-odrl.jsonld

File renamed without changes.

core/json-ld-core/src/main/resources/document/cx-policy-v1.jsonld renamed to core/cx-json-ld/src/main/resources/document/cx-policy-v1.jsonld

File renamed without changes.
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/********************************************************************************
2+
* Copyright (c) 2023 Bayerische Motoren Werke Aktiengesellschaft (BMW AG)
3+
* Copyright (c) 2026 SAP SE
4+
*
5+
* See the NOTICE file(s) distributed with this work for additional
6+
* information regarding copyright ownership.
7+
*
8+
* This program and the accompanying materials are made available under the
9+
* terms of the Apache License, Version 2.0 which is available at
10+
* https://www.apache.org/licenses/LICENSE-2.0.
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15+
* License for the specific language governing permissions and limitations
16+
* under the License.
17+
*
18+
* SPDX-License-Identifier: Apache-2.0
19+
********************************************************************************/
20+
21+
package org.eclipse.tractusx.edc.jsonld;
22+
23+
import org.eclipse.edc.jsonld.spi.JsonLd;
24+
import org.eclipse.edc.junit.extensions.DependencyInjectionExtension;
25+
import org.eclipse.edc.spi.system.ServiceExtensionContext;
26+
import org.eclipse.tractusx.edc.cx.CxJsonLdExtension;
27+
import org.junit.jupiter.api.BeforeEach;
28+
import org.junit.jupiter.api.Test;
29+
import org.junit.jupiter.api.extension.ExtendWith;
30+
31+
import java.net.URI;
32+
33+
import static org.eclipse.tractusx.edc.cx.CxJsonLdExtension.CX_ODRL_CONTEXT;
34+
import static org.eclipse.tractusx.edc.cx.CxJsonLdExtension.CX_POLICY_2025_09_CONTEXT;
35+
import static org.mockito.ArgumentMatchers.any;
36+
import static org.mockito.ArgumentMatchers.eq;
37+
import static org.mockito.Mockito.mock;
38+
39+
@ExtendWith(DependencyInjectionExtension.class)
40+
public class CxJsonLdExtensionTest {
41+
42+
JsonLd jsonLdService = mock(JsonLd.class);
43+
44+
@BeforeEach
45+
void setup(ServiceExtensionContext context) {
46+
context.registerService(JsonLd.class, jsonLdService);
47+
}
48+
49+
@Test
50+
void initialize(ServiceExtensionContext context, CxJsonLdExtension extension) {
51+
extension.initialize(context);
52+
jsonLdService.registerCachedDocument(eq(CX_POLICY_2025_09_CONTEXT), any(URI.class));
53+
jsonLdService.registerCachedDocument(eq(CX_ODRL_CONTEXT), any(URI.class));
54+
}
55+
}

core/json-ld-core/src/main/java/org/eclipse/tractusx/edc/jsonld/JsonLdExtension.java

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/********************************************************************************
22
* Copyright (c) 2023 Bayerische Motoren Werke Aktiengesellschaft (BMW AG)
3+
* Copyright (c) 2026 SAP SE
34
*
45
* See the NOTICE file(s) distributed with this work for additional
56
* information regarding copyright ownership.
@@ -37,8 +38,6 @@
3738
import static org.eclipse.edc.api.management.ManagementApi.MANAGEMENT_SCOPE;
3839
import static org.eclipse.edc.protocol.dsp.spi.type.Dsp08Constants.DSP_SCOPE_V_08;
3940
import static org.eclipse.edc.protocol.dsp.spi.type.Dsp2025Constants.DSP_SCOPE_V_2025_1;
40-
import static org.eclipse.tractusx.edc.edr.spi.CoreConstants.CX_POLICY_NS;
41-
import static org.eclipse.tractusx.edc.edr.spi.CoreConstants.CX_POLICY_PREFIX;
4241
import static org.eclipse.tractusx.edc.edr.spi.CoreConstants.EDC_CONTEXT;
4342
import static org.eclipse.tractusx.edc.edr.spi.CoreConstants.TX_AUTH_NS;
4443
import static org.eclipse.tractusx.edc.edr.spi.CoreConstants.TX_AUTH_PREFIX;
@@ -52,21 +51,15 @@ public class JsonLdExtension implements ServiceExtension {
5251
public static final String SECURITY_JWS_V1 = "https://w3id.org/security/suites/jws-2020/v1";
5352
public static final String SECURITY_ED25519_V1 = "https://w3id.org/security/suites/ed25519-2020/v1";
5453

55-
@Deprecated(since = "0.11.0")
56-
public static final String CX_POLICY_CONTEXT = "https://w3id.org/tractusx/policy/v1.0.0";
57-
public static final String CX_ODRL_CONTEXT = "https://w3id.org/catenax/2025/9/policy/odrl.jsonld";
58-
public static final String CX_POLICY_2025_09_CONTEXT = "https://w3id.org/catenax/2025/9/policy/context.jsonld";
5954
public static final String TX_AUTH_CONTEXT = "https://w3id.org/tractusx/auth/v1.0.0";
6055

6156
private static final String PREFIX = "document" + File.separator;
6257
private static final Map<String, String> FILES = Map.of(
6358
CREDENTIALS_V_1, PREFIX + "credential-v1.jsonld",
6459
SECURITY_JWS_V1, PREFIX + "security-jws-2020.jsonld",
6560
SECURITY_ED25519_V1, PREFIX + "security-ed25519-2020.jsonld",
66-
CX_POLICY_2025_09_CONTEXT, PREFIX + "cx-policy-v1.jsonld",
6761
TX_AUTH_CONTEXT, PREFIX + "tx-auth-v1.jsonld",
68-
EDC_CONTEXT, PREFIX + "edc-v1.jsonld",
69-
CX_ODRL_CONTEXT, PREFIX + "cx-odrl.jsonld");
62+
EDC_CONTEXT, PREFIX + "edc-v1.jsonld");
7063
@Inject
7164
private JsonLd jsonLdService;
7265

@@ -77,14 +70,10 @@ public class JsonLdExtension implements ServiceExtension {
7770
public void initialize(ServiceExtensionContext context) {
7871
jsonLdService.registerNamespace(TX_PREFIX, TX_NAMESPACE, DSP_SCOPE_V_08);
7972
jsonLdService.registerNamespace(TX_AUTH_PREFIX, TX_AUTH_NS, DSP_SCOPE_V_08);
80-
jsonLdService.registerNamespace(CX_POLICY_PREFIX, CX_POLICY_NS, DSP_SCOPE_V_08);
8173

8274
jsonLdService.registerContext(TX_AUTH_CONTEXT, DSP_SCOPE_V_2025_1);
83-
jsonLdService.registerContext(CX_POLICY_2025_09_CONTEXT, DSP_SCOPE_V_2025_1);
84-
jsonLdService.registerContext(CX_ODRL_CONTEXT, DSP_SCOPE_V_2025_1);
8575

8676
jsonLdService.registerNamespace(TX_AUTH_PREFIX, TX_AUTH_NS, MANAGEMENT_SCOPE);
87-
jsonLdService.registerContext(CX_POLICY_2025_09_CONTEXT, MANAGEMENT_SCOPE);
8877

8978
FILES.entrySet().stream().map(this::mapToFile)
9079
.forEach(result -> result.onSuccess(entry -> jsonLdService.registerCachedDocument(entry.getKey(), entry.getValue().toURI()))

core/json-ld-core/src/test/java/org/eclipse/tractusx/edc/jsonld/JsonLdExtensionTest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/********************************************************************************
22
* Copyright (c) 2023 Bayerische Motoren Werke Aktiengesellschaft (BMW AG)
3+
* Copyright (c) 2026 SAP SE
34
*
45
* See the NOTICE file(s) distributed with this work for additional
56
* information regarding copyright ownership.
@@ -29,7 +30,6 @@
2930
import java.net.URI;
3031

3132
import static org.eclipse.tractusx.edc.jsonld.JsonLdExtension.CREDENTIALS_V_1;
32-
import static org.eclipse.tractusx.edc.jsonld.JsonLdExtension.CX_POLICY_2025_09_CONTEXT;
3333
import static org.eclipse.tractusx.edc.jsonld.JsonLdExtension.SECURITY_ED25519_V1;
3434
import static org.eclipse.tractusx.edc.jsonld.JsonLdExtension.SECURITY_JWS_V1;
3535
import static org.mockito.ArgumentMatchers.any;
@@ -50,7 +50,6 @@ void setup(ServiceExtensionContext context) {
5050
void initialize(ServiceExtensionContext context, JsonLdExtension extension) {
5151
extension.initialize(context);
5252
jsonLdService.registerCachedDocument(eq(CREDENTIALS_V_1), any(URI.class));
53-
jsonLdService.registerCachedDocument(eq(CX_POLICY_2025_09_CONTEXT), any(URI.class));
5453
jsonLdService.registerCachedDocument(eq(SECURITY_JWS_V1), any(URI.class));
5554
jsonLdService.registerCachedDocument(eq(SECURITY_ED25519_V1), any(URI.class));
5655

edc-controlplane/edc-controlplane-base/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ dependencies {
4242

4343
implementation(project(":core:edr-core"))
4444
implementation(project(":core:json-ld-core"))
45+
implementation(project(":core:cx-json-ld"))
4546
implementation(project(":edc-extensions:log4j2-monitor"))
4647
implementation(project(":edc-extensions:agreements"))
4748
implementation(project(":edc-extensions:agreements-bpns"))

0 commit comments

Comments
 (0)