Skip to content

Commit

Permalink
Merge pull request eclipse-tractusx#416 from FraunhoferISST/feat/json…
Browse files Browse the repository at this point in the history
…ld-catalog

Feat/jsonld contracting
  • Loading branch information
tom-rm-meyer-ISST authored Jul 9, 2024
2 parents f3e0575 + 8dc63aa commit 570d7cb
Show file tree
Hide file tree
Showing 34 changed files with 9,369 additions and 49 deletions.
14 changes: 14 additions & 0 deletions DEPENDENCIES_BACKEND
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
maven/mavencentral/ch.qos.logback/logback-classic/1.4.14, EPL-1.0 OR LGPL-2.1-only, approved, #3435
maven/mavencentral/ch.qos.logback/logback-core/1.4.14, EPL-1.0 OR LGPL-2.1-only, approved, #3373
maven/mavencentral/com.apicatalog/titanium-json-ld/1.4.0, Apache-2.0, approved, #13683
maven/mavencentral/com.fasterxml.jackson.core/jackson-annotations/2.15.4, Apache-2.0, approved, #7947
maven/mavencentral/com.fasterxml.jackson.core/jackson-core/2.15.4, MIT AND Apache-2.0, approved, #7932
maven/mavencentral/com.fasterxml.jackson.core/jackson-databind/2.15.4, Apache-2.0, approved, #7934
maven/mavencentral/com.fasterxml.jackson.dataformat/jackson-dataformat-yaml/2.15.4, Apache-2.0, approved, #8802
maven/mavencentral/com.fasterxml.jackson.datatype/jackson-datatype-jakarta-jsonp/2.15.4, Apache-2.0, approved, #9179
maven/mavencentral/com.fasterxml.jackson.datatype/jackson-datatype-jdk8/2.15.4, Apache-2.0, approved, #8808
maven/mavencentral/com.fasterxml.jackson.datatype/jackson-datatype-jsr310/2.15.4, Apache-2.0, approved, #7930
maven/mavencentral/com.fasterxml.jackson.module/jackson-module-parameter-names/2.15.4, Apache-2.0, approved, #8803
Expand All @@ -16,15 +18,19 @@ maven/mavencentral/com.squareup.okio/okio/3.6.0, Apache-2.0, approved, #11155
maven/mavencentral/com.sun.istack/istack-commons-runtime/4.1.2, BSD-3-Clause, approved, #2590
maven/mavencentral/com.vaadin.external.google/android-json/0.0.20131108.vaadin1, Apache-2.0, approved, CQ21310
maven/mavencentral/com.zaxxer/HikariCP/5.0.1, Apache-2.0, approved, clearlydefined
maven/mavencentral/dev.failsafe/failsafe/3.3.2, Apache-2.0, approved, #9268
maven/mavencentral/io.micrometer/micrometer-commons/1.12.5, Apache-2.0 AND (Apache-2.0 AND MIT), approved, #11679
maven/mavencentral/io.micrometer/micrometer-observation/1.12.5, Apache-2.0, approved, #11680
maven/mavencentral/io.opentelemetry/opentelemetry-api/1.31.0, Apache-2.0, approved, #11087
maven/mavencentral/io.opentelemetry/opentelemetry-context/1.31.0, Apache-2.0, approved, #11088
maven/mavencentral/io.smallrye/jandex/3.1.2, Apache-2.0, approved, clearlydefined
maven/mavencentral/io.swagger.core.v3/swagger-annotations-jakarta/2.2.21, Apache-2.0, approved, #5947
maven/mavencentral/io.swagger.core.v3/swagger-core-jakarta/2.2.21, Apache-2.0, approved, #5929
maven/mavencentral/io.swagger.core.v3/swagger-models-jakarta/2.2.21, Apache-2.0, approved, #5919
maven/mavencentral/jakarta.activation/jakarta.activation-api/2.1.3, EPL-2.0 OR BSD-3-Clause OR GPL-2.0-only with Classpath-exception-2.0, approved, ee4j.jaf
maven/mavencentral/jakarta.annotation/jakarta.annotation-api/2.1.1, EPL-2.0 OR GPL-2.0-only with Classpath-exception-2.0, approved, ee4j.ca
maven/mavencentral/jakarta.inject/jakarta.inject-api/2.0.1, Apache-2.0, approved, ee4j.cdi
maven/mavencentral/jakarta.json/jakarta.json-api/2.1.3, EPL-2.0 OR GPL-2.0-only with Classpath-exception-2.0, approved, ee4j.jsonp
maven/mavencentral/jakarta.persistence/jakarta.persistence-api/3.1.0, EPL-2.0 OR BSD-3-Clause, approved, ee4j.jpa
maven/mavencentral/jakarta.transaction/jakarta.transaction-api/2.0.1, EPL-2.0 OR GPL-2.0-only with Classpath-exception-2.0, approved, ee4j.jta
maven/mavencentral/jakarta.validation/jakarta.validation-api/3.0.2, Apache-2.0, approved, ee4j.validation
Expand All @@ -47,9 +53,17 @@ maven/mavencentral/org.assertj/assertj-core/3.24.2, Apache-2.0, approved, #6161
maven/mavencentral/org.awaitility/awaitility/4.2.1, Apache-2.0, approved, #14178
maven/mavencentral/org.checkerframework/checker-qual/3.42.0, MIT, approved, clearlydefined
maven/mavencentral/org.eclipse.angus/angus-activation/2.0.2, EPL-2.0 OR GPL-2.0-only with Classpath-exception-2.0, approved, ee4j.angus
maven/mavencentral/org.eclipse.edc/boot-spi/0.7.0, Apache-2.0, approved, technology.edc
maven/mavencentral/org.eclipse.edc/core-spi/0.7.0, Apache-2.0, approved, technology.edc
maven/mavencentral/org.eclipse.edc/json-ld-lib/0.7.0, Apache-2.0, approved, technology.edc
maven/mavencentral/org.eclipse.edc/json-ld-spi/0.7.0, Apache-2.0, approved, technology.edc
maven/mavencentral/org.eclipse.edc/policy-model/0.7.0, Apache-2.0, approved, technology.edc
maven/mavencentral/org.eclipse.edc/runtime-metamodel/0.7.0, Apache-2.0, approved, technology.edc
maven/mavencentral/org.eclipse.edc/transform-spi/0.7.0, Apache-2.0, approved, technology.edc
maven/mavencentral/org.glassfish.jaxb/jaxb-core/4.0.5, BSD-3-Clause, approved, ee4j.jaxb-impl
maven/mavencentral/org.glassfish.jaxb/jaxb-runtime/4.0.5, BSD-3-Clause, approved, ee4j.jaxb-impl
maven/mavencentral/org.glassfish.jaxb/txw2/4.0.5, BSD-3-Clause, approved, ee4j.jaxb-impl
maven/mavencentral/org.glassfish/jakarta.json/2.0.1, EPL-2.0 OR GPL-2.0-only with Classpath-exception-2.0, approved, ee4j.jsonp
maven/mavencentral/org.hamcrest/hamcrest-core/2.2, BSD-3-Clause, approved, clearlydefined
maven/mavencentral/org.hamcrest/hamcrest/2.2, BSD-3-Clause, approved, clearlydefined
maven/mavencentral/org.hibernate.common/hibernate-commons-annotations/6.0.6.Final, LGPL-2.1-only, approved, #6962
Expand Down
38 changes: 38 additions & 0 deletions NOTICE.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,44 @@ feather (4.29)
* Project URL: https://feathericons.com/
* Source URL: https://github.com/feathericons/feather

### Remote Contexts

#### cx-policy-v1 ([main](./backend/src/main/resources/json-ld/cx-policy-v1.jsonld), [test](./backend/src/test/resources/json-ld/cx-policy-v1.jsonld))

* SPDX-License-Identifier: Apache-2.0
* SPDX-FileCopyrightText: https://github.com/eclipse-tractusx/tractusx-profiles/blob/main/LICENSE
* Source URL: https://github.com/eclipse-tractusx/tractusx-profiles/blob/main/cx/credentials/schema/context/policy.context.json

#### dspace ([main](./backend/src/main/resources/json-ld/dspace.jsonld), [test](./backend/src/test/resources/json-ld/dspace.jsonld))

* SPDX-License-Identifier: Apache-2.0
* SPDX-FileCopyrightText: https://github.com/International-Data-Spaces-Association/ids-specification/blob/main/LICENSE
* Source URL: https://international-data-spaces-association.github.io/ids-specification/2024-1/common/schema/context.json

#### edc-v1 ([main](./backend/src/main/resources/json-ld/edc-v1.jsonld), [test](./backend/src/test/resources/json-ld/edc-v1.jsonld))

* SPDX-License-Identifier: Apache-2.0
* SPDX-FileCopyrightText: https://github.com/eclipse-tractusx/tractusx-edc/blob/d728d8311196572b0d34cef7be788c7ef06f46e5/LICENSE
* Source URL: https://github.com/eclipse-tractusx/tractusx-edc/blob/d728d8311196572b0d34cef7be788c7ef06f46e5/core/json-ld-core/src/main/resources/document/edc-v1.jsonld

#### odrl ([main](./backend/src/main/resources/json-ld/odrl.jsonld), [test](./backend/src/test/resources/json-ld/odrl.jsonld))

* SPDX-License-Identifier: Apache-2.0
* SPDX-FileCopyrightText: https://www.w3.org/copyright/software-license-2015/
* Source URL: https://www.w3.org/ns/odrl.jsonld

#### tx-auth-v1 ([main](./backend/src/main/resources/json-ld/tx-auth-v1.jsonld), [test](./backend/src/test/resources/json-ld/tx-auth-v1.jsonld))

* SPDX-License-Identifier: Apache-2.0
* SPDX-FileCopyrightText: https://github.com/eclipse-tractusx/tractusx-edc/blob/d728d8311196572b0d34cef7be788c7ef06f46e5/LICENSE
* Source URL: https://github.com/eclipse-tractusx/tractusx-edc/blob/d728d8311196572b0d34cef7be788c7ef06f46e5/core/json-ld-core/src/main/resources/document/tx-auth-v1.jsonld

#### tx-v1 ([main](./backend/src/main/resources/json-ld/tx-v1.jsonld), [test](./backend/src/test/resources/json-ld/tx-v1.jsonld))

* SPDX-License-Identifier: Apache-2.0
* SPDX-FileCopyrightText: https://github.com/eclipse-tractusx/tractusx-edc/blob/d728d8311196572b0d34cef7be788c7ef06f46e5/LICENSE
* Source URL: https://github.com/eclipse-tractusx/tractusx-edc/blob/d728d8311196572b0d34cef7be788c7ef06f46e5/core/json-ld-core/src/main/resources/document/tx-v1.jsonld

## Cryptography

Content may contain encryption software. The country in which you are currently
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Beside the dependencies provided in the Helm Chart, the following dependencies h

| Application | App Version | Chart Version |
|-------------------------------------------------------------------------------------------------------------------|-------------|---------------|
| [Tractus-X Connector](https://github.com/eclipse-tractusx/tractusx-edc/tree/main/charts/tractusx-connector) | 0.7.1 | 0.7.1 |
| [Tractus-X Connector](https://github.com/eclipse-tractusx/tractusx-edc/tree/main/charts/tractusx-connector) | 0.7.2 | 0.7.2 |
| [Digital Twin Registry](https://github.com/eclipse-tractusx/sldt-digital-twin-registry/tree/main/charts/registry) | 0.4.3 | 0.4.11 |

## Known Knows
Expand Down
16 changes: 15 additions & 1 deletion backend/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
<postgresql.version>42.7.3</postgresql.version>
<snakeyaml.version>2.2</snakeyaml.version>
<springdoc.version>2.5.0</springdoc.version>
<edc-connector-version>0.7.0</edc-connector-version>
</properties>
<dependencies>
<dependency>
Expand Down Expand Up @@ -125,8 +126,19 @@
<artifactId>modelmapper</artifactId>
<version>${modelmapper.version}</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.eclipse.edc/json-ld-lib -->
<dependency>
<groupId>org.eclipse.edc</groupId>
<artifactId>json-ld-lib</artifactId>
<version>${edc-connector-version}</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.eclipse.edc/json-ld-spi -->
<dependency>
<groupId>org.eclipse.edc</groupId>
<artifactId>json-ld-spi</artifactId>
<version>${edc-connector-version}</version>
</dependency>
</dependencies>

<pluginRepositories>
<pluginRepository>
<id>dash-licenses</id>
Expand Down Expand Up @@ -197,6 +209,8 @@
<directory>${project.basedir}/src/main/resources</directory>
<includes>
<include>application.properties</include>
<!-- add json-ld data-->
<include>json-ld/*</include>
</includes>
<targetPath>BOOT-INF/classes/</targetPath>
</resource>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import okhttp3.*;
import org.eclipse.tractusx.puris.backend.common.edc.domain.model.AssetType;
import org.eclipse.tractusx.puris.backend.common.edc.logic.util.EdcRequestBodyBuilder;
import org.eclipse.tractusx.puris.backend.common.edc.logic.util.JsonLdUtils;
import org.eclipse.tractusx.puris.backend.common.util.PatternStore;
import org.eclipse.tractusx.puris.backend.common.util.VariablesService;
import org.eclipse.tractusx.puris.backend.masterdata.domain.model.MaterialPartnerRelation;
Expand Down Expand Up @@ -59,6 +60,9 @@ public class EdcAdapterService {
@Autowired
private EdcContractMappingService edcContractMappingService;

@Autowired
private JsonLdUtils jsonLdUtils;

private final Pattern urlPattern = PatternStore.URL_PATTERN;

public EdcAdapterService(ObjectMapper objectMapper) {
Expand Down Expand Up @@ -707,7 +711,9 @@ private boolean negotiateForPartnerDtr(Partner partner) {
EdcRequestBodyBuilder.CX_TAXO_NAMESPACE + "DigitalTwinRegistry"
);
var responseNode = getCatalog(partner.getEdcUrl(), partner.getBpnl(), equalFilters);
var catalogArray = responseNode.get("dcat:dataset");
responseNode = jsonLdUtils.expand(responseNode);

var catalogArray = responseNode.get(EdcRequestBodyBuilder.DCAT_NAMESPACE + "dataset");
// If there is exactly one asset, the catalogContent will be a JSON object.
// In all other cases catalogContent will be a JSON array.
// For the sake of uniformity we will embed a single object in an array.
Expand Down Expand Up @@ -1046,7 +1052,8 @@ public boolean negotiateContractForNotification(Partner partner, AssetType type)
public boolean negotiateContract(Partner partner, String assetId, AssetType type, String dspUrl, Map<String, String> equalFilters) {
try {
var responseNode = getCatalog(dspUrl, partner.getBpnl(), equalFilters);
var catalogArray = responseNode.get("dcat:dataset");
responseNode = jsonLdUtils.expand(responseNode);
var catalogArray = responseNode.get(EdcRequestBodyBuilder.DCAT_NAMESPACE + "dataset");
// If there is exactly one asset, the catalogContent will be a JSON object.
// In all other cases catalogContent will be a JSON array.
// For the sake of uniformity we will embed a single object in an array.
Expand Down Expand Up @@ -1125,17 +1132,23 @@ public String getCxIdFromPartTypeInformation(MaterialPartnerRelation mpr) {

/**
* Helper method to check whether you and the contract offer from the other party have the
* same framework agreement policy.
* same framework agreement policy. The given catalogEntry must be expanded!
*
* @param catalogEntry the catalog item containing the desired api asset
* @param catalogEntry the catalog item containing the desired api asset in expanded form
* @return true, if the policy matches yours, otherwise false
*/
public boolean testContractPolicyConstraints(JsonNode catalogEntry) {
log.debug("Testing constraints in the following catalogEntry: {}", catalogEntry.toPrettyString());
var constraint = Optional.ofNullable(catalogEntry.get("odrl:hasPolicy"))
.map(policy -> policy.get("odrl:permission"))
.map(permission -> permission.get("odrl:constraint"))
.map(con -> con.get("odrl:and"));
log.debug("Testing constraints in the following catalogEntry: \n{}", catalogEntry.toPrettyString());
var constraint = Optional.ofNullable(catalogEntry.get(EdcRequestBodyBuilder.ODRL_NAMESPACE + "hasPolicy"))
.filter(policy -> policy.isArray() && policy.size() == 1)
.map(policy -> policy.get(0))
.map(policy -> policy.get(EdcRequestBodyBuilder.ODRL_NAMESPACE + "permission"))
.filter(permission -> permission.isArray() && permission.size() == 1)
.map(permission -> permission.get(0))
.map(permission -> permission.get(EdcRequestBodyBuilder.ODRL_NAMESPACE + "constraint"))
.filter(constr -> constr.isArray() && constr.size() == 1)
.map(constr -> constr.get(0))
.map(con -> con.get(EdcRequestBodyBuilder.ODRL_NAMESPACE + "and"));
if (constraint.isEmpty()) {
log.debug("Constraint mismatch: we expect to have a constraint in permission node.");
return false;
Expand All @@ -1147,7 +1160,9 @@ public boolean testContractPolicyConstraints(JsonNode catalogEntry) {
Optional<JsonNode> purposeConstraint = Optional.empty();

for (JsonNode con : constraint.get()) { // Iterate over array elements and find the nodes
JsonNode leftOperandNode = con.get("odrl:leftOperand");
JsonNode leftOperandNode = con.get(EdcRequestBodyBuilder.ODRL_NAMESPACE + "leftOperand");
leftOperandNode = leftOperandNode.get(0);
leftOperandNode = leftOperandNode.get("@id");
if (leftOperandNode != null && (EdcRequestBodyBuilder.CX_POLICY_NAMESPACE + "FrameworkAgreement").equals(leftOperandNode.asText())) {
frameworkAgreementConstraint = Optional.of(con);
}
Expand All @@ -1169,19 +1184,24 @@ public boolean testContractPolicyConstraints(JsonNode catalogEntry) {
result = result && testSingleConstraint(
frameworkAgreementConstraint,
EdcRequestBodyBuilder.CX_POLICY_NAMESPACE + "FrameworkAgreement",
"odrl:eq",
EdcRequestBodyBuilder.ODRL_NAMESPACE + "eq",
variablesService.getPurisFrameworkAgreementWithVersion()
);

result = result && testSingleConstraint(
purposeConstraint,
EdcRequestBodyBuilder.CX_POLICY_NAMESPACE + "UsagePurpose",
"odrl:eq",
EdcRequestBodyBuilder.ODRL_NAMESPACE + "eq",
variablesService.getPurisPurposeWithVersion()
);

JsonNode policy = catalogEntry.get(EdcRequestBodyBuilder.ODRL_NAMESPACE + "hasPolicy");
JsonNode prohibition = policy.get(EdcRequestBodyBuilder.ODRL_NAMESPACE + "prohibition");
JsonNode obligation = policy.get(EdcRequestBodyBuilder.ODRL_NAMESPACE + "obligation");
result = result && (prohibition == null || (prohibition.isArray() && prohibition.isEmpty()));
result = result && (obligation == null || (obligation.isArray() && obligation.isEmpty()));

} else {
System.out.println("Only one constraint ");
log.info(
"2 Constraints (Framework Agreement, Purpose) are expected but got {} constraints.",
constraint.get().size()
Expand All @@ -1198,25 +1218,30 @@ private boolean testSingleConstraint(Optional<JsonNode> constraintToTest, String

JsonNode con = constraintToTest.get();

JsonNode leftOperandNode = con.get("odrl:leftOperand");
JsonNode leftOperandNode = con.get(EdcRequestBodyBuilder.ODRL_NAMESPACE + "leftOperand");
leftOperandNode = leftOperandNode == null ? null : leftOperandNode.get(0);
leftOperandNode = leftOperandNode == null ? null : leftOperandNode.get("@id");
if (leftOperandNode == null || !targetLeftOperand.equals(leftOperandNode.asText())) {
String leftOperand = leftOperandNode == null ? "null" : leftOperandNode.asText();
log.debug("Left operand '{}' does not equal expected value '{}'.", leftOperand, targetLeftOperand);
log.info("Left operand '{}' does not equal expected value '{}'.", leftOperand, targetLeftOperand);
return false;
}

JsonNode operatorNode = con.get("odrl:operator");
JsonNode operatorNode = con.get(EdcRequestBodyBuilder.ODRL_NAMESPACE + "operator");
operatorNode = operatorNode == null ? null : operatorNode.get(0);
operatorNode = operatorNode == null ? null : operatorNode.get("@id");
if (operatorNode == null || !targetOperator.equals(operatorNode.asText())) {
String operator = operatorNode == null ? "null" : operatorNode.asText();
log.debug("Operator '{}' does not equal expected value '{}'.", operator, targetOperator);
log.info("Operator '{}' does not equal expected value '{}'.", operator, targetOperator);
return false;
}

JsonNode rightOperandNode = con.get("odrl:rightOperand");
JsonNode rightOperandNode = con.get(EdcRequestBodyBuilder.ODRL_NAMESPACE + "rightOperand");
rightOperandNode = rightOperandNode == null ? null : rightOperandNode.get(0);
rightOperandNode = rightOperandNode == null ? null : rightOperandNode.get("@value");
if (rightOperandNode == null || !targetRightOperand.equals(rightOperandNode.asText())) {
String rightOperand = rightOperandNode == null ? "null" : rightOperandNode.asText();
log.debug("Right operand '{}' odes not equal expected value '{}'.", rightOperand, targetRightOperand);
log.info("Right operand '{}' does not equal expected value '{}'.", rightOperand, targetRightOperand);
return false;
}

Expand Down
Loading

0 comments on commit 570d7cb

Please sign in to comment.