From 2fa6d5c47f54d02dffa2273027d783dc33a258d1 Mon Sep 17 00:00:00 2001 From: ds-lcapellino Date: Tue, 21 May 2024 12:28:04 +0200 Subject: [PATCH] bug: #978 fix edc policy creation --- CHANGELOG.md | 1 + pom.xml | 2 +- .../importpoc/mapper/PolicyMapper.java | 18 +++++++---- .../irs/model/response/IrsPolicyResponse.java | 7 +++-- .../base/service/NotificationsEDCFacade.java | 30 ++++++++++++------- ...actagreement_negotiation_response_200.json | 16 +++++----- .../policies/response_200_get_policies.json | 5 +++- 7 files changed, 50 insertions(+), 29 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 62b17f7665..d8dccc9e14 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,6 +26,7 @@ _**For better traceability add the corresponding GitHub issue number in each cha - #994 disable inputs of newly added bpn configurations - #995 disable creation and editof notifications for admin role - #991 make menu table headers unvisible to not block column and filters of tables +- #978 Fixed edc policy creation with edc version 0.7.0 ## [11.0.0 - 08.05.2024] ### Added diff --git a/pom.xml b/pom.xml index 5387a55886..ff15aae464 100644 --- a/pom.xml +++ b/pom.xml @@ -90,7 +90,7 @@ SPDX-License-Identifier: Apache-2.0 5.10.2 4.2.1 - 2.0.4-SNAPSHOT + 2.0.5-SNAPSHOT 5.4.0 jacoco diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/assets/application/importpoc/mapper/PolicyMapper.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/assets/application/importpoc/mapper/PolicyMapper.java index 3931137547..0afee39a89 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/assets/application/importpoc/mapper/PolicyMapper.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/assets/application/importpoc/mapper/PolicyMapper.java @@ -23,7 +23,7 @@ import assets.importpoc.PermissionResponse; import assets.importpoc.PolicyResponse; import lombok.experimental.UtilityClass; -import org.eclipse.tractusx.irs.edc.client.asset.model.OdrlContext; +import org.eclipse.tractusx.irs.edc.client.asset.model.Context; import org.eclipse.tractusx.irs.edc.client.contract.model.EdcOperator; import org.eclipse.tractusx.irs.edc.client.policy.model.EdcCreatePolicyDefinitionRequest; import org.eclipse.tractusx.irs.edc.client.policy.model.EdcPolicy; @@ -38,21 +38,27 @@ @UtilityClass public class PolicyMapper { public static EdcCreatePolicyDefinitionRequest mapToEdcPolicyRequest(PolicyResponse policy) { - // TODO https://github.com/eclipse-tractusx/traceability-foss/issues/978 context needs to be updated with the required ones - OdrlContext odrlContext = OdrlContext.builder().odrl("http://www.w3.org/ns/odrl/2/").build(); + // https://github.com/eclipse-tractusx/traceability-foss/issues/978 context needs to be updated with the required ones + Context odrlContext = Context.builder() + .odrl("http://www.w3.org/ns/odrl/2/") + .edc("https://w3id.org/edc/v0.0.1/ns/") + .vocab("https://w3id.org/edc/v0.0.1/ns/") + .cxPolicy("https://w3id.org/catenax/policy/") + .build(); + EdcPolicy edcPolicy = EdcPolicy.builder().odrlPermissions(mapToPermissions(policy.permissions())).type("odrl:Set").build(); return EdcCreatePolicyDefinitionRequest.builder() .policyDefinitionId(policy.policyId()) .policy(edcPolicy) - .odrlContext(odrlContext) + .context(odrlContext) .type("odrl:Set") .build(); } private static List mapToPermissions(List permissions) { return permissions.stream().map(permission -> EdcPolicyPermission.builder() - // TODO https://github.com/eclipse-tractusx/traceability-foss/issues/978 here we need to make sure that the USE is lowercase in the object. - .action(permission.action().name()) + // https://github.com/eclipse-tractusx/traceability-foss/issues/978 here we need to make sure that the USE is lowercase in the object. + .action(permission.action().name().toLowerCase()) .edcPolicyPermissionConstraints(mapToConstraint(permission.constraints())) .build() ).toList(); diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/assets/infrastructure/base/irs/model/response/IrsPolicyResponse.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/assets/infrastructure/base/irs/model/response/IrsPolicyResponse.java index 398b3f52c8..878ecbc21a 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/assets/infrastructure/base/irs/model/response/IrsPolicyResponse.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/assets/infrastructure/base/irs/model/response/IrsPolicyResponse.java @@ -42,7 +42,7 @@ @Builder @Schema(example = IrsPolicyResponse.EXAMPLE_PAYLOAD) public record IrsPolicyResponse(OffsetDateTime validUntil, Payload payload) { - // TODO https://github.com/eclipse-tractusx/traceability-foss/issues/978 + // https://github.com/eclipse-tractusx/traceability-foss/issues/978 // "odrl:action" USE will be use (lowercase) make sure to migrate @SuppressWarnings({"FileTabCharacter", "java:S2479"}) @@ -53,13 +53,16 @@ public record IrsPolicyResponse(OffsetDateTime validUntil, Payload payload) { "validUntil": "2025-12-12T23:59:59.999Z", "payload": { "@context": { + "@vocab" : "https://w3id.org/edc/v0.0.1/ns/", + "edc": "https://w3id.org/edc/v0.0.1/ns/", + "cx-policy": "https://w3id.org/catenax/policy/", "odrl": "http://www.w3.org/ns/odrl/2/" }, "@id": "policy-id", "policy": { "odrl:permission": [ { - "odrl:action": "USE", + "odrl:action": "use", "odrl:constraint": { "odrl:and": [ { diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/notification/domain/base/service/NotificationsEDCFacade.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/notification/domain/base/service/NotificationsEDCFacade.java index 5881137f20..ef77685fd1 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/notification/domain/base/service/NotificationsEDCFacade.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/notification/domain/base/service/NotificationsEDCFacade.java @@ -61,7 +61,6 @@ import java.util.Optional; import static java.lang.String.format; -import static org.eclipse.tractusx.traceability.common.config.JsonLdConfigurationTraceX.NAMESPACE_EDC; import static org.eclipse.tractusx.traceability.common.config.RestTemplateConfiguration.EDC_NOTIFICATION_TEMPLATE; @Slf4j @@ -85,10 +84,10 @@ public class NotificationsEDCFacade { private final EndpointDataReferenceStorage endpointDataReferenceStorage; private final PolicyCheckerService policyCheckerService; - public static final String ASSET_VALUE_QUALITY_INVESTIGATION = "qualityinvestigation"; - public static final String ASSET_VALUE_QUALITY_ALERT = "qualityalert"; - private static final String ASSET_VALUE_NOTIFICATION_METHOD_UPDATE = "update"; - private static final String ASSET_VALUE_NOTIFICATION_METHOD_RECEIVE = "receive"; + private static final String CX_TAXO_QUALITY_INVESTIGATION_RECEIVE = "cx-taxo:ReceiveQualityInvestigationNotification"; + private static final String CX_TAXO_QUALITY_INVESTIGATION_UPDATE = "cx-taxo:UpdateQualityInvestigationNotification"; + private static final String CX_TAXO_QUALITY_ALERT_RECEIVE = "cx-taxo:ReceiveQualityAlertNotification"; + private static final String CX_TAXO_QUALITY_ALERT_UPDATE = "cx-taxo:UpdateQualityAlertNotification"; public void startEdcTransfer( final NotificationMessage notification, @@ -126,22 +125,31 @@ private String negotiateContractAgreement(final String receiverEdcUrl, final Cat private CatalogItem getCatalogItem(final NotificationMessage notification, final String receiverEdcUrl) { try { - final String propertyNotificationTypeValue = NotificationType.ALERT.equals(notification.getType()) ? ASSET_VALUE_QUALITY_ALERT : ASSET_VALUE_QUALITY_INVESTIGATION; - final String propertyMethodValue = Boolean.TRUE.equals(notification.getNotificationStatus().equals(NotificationStatus.SENT)) ? ASSET_VALUE_NOTIFICATION_METHOD_RECEIVE : ASSET_VALUE_NOTIFICATION_METHOD_UPDATE; + + String taxoValue = ""; + if (NotificationType.ALERT.equals(notification.getType()) && notification.getNotificationStatus().equals(NotificationStatus.SENT)) { + taxoValue = CX_TAXO_QUALITY_ALERT_RECEIVE; + } else if (!NotificationType.ALERT.equals(notification.getType()) && notification.getNotificationStatus().equals(NotificationStatus.SENT)) { + taxoValue = CX_TAXO_QUALITY_INVESTIGATION_RECEIVE; + } else if (NotificationType.ALERT.equals(notification.getType())) { + taxoValue = CX_TAXO_QUALITY_ALERT_UPDATE; + } else { + taxoValue = CX_TAXO_QUALITY_INVESTIGATION_UPDATE; + } + return edcCatalogFacade.fetchCatalogItems( CatalogRequest.Builder.newInstance() .protocol(DEFAULT_PROTOCOL) .counterPartyAddress(receiverEdcUrl + edcProperties.getIdsPath()) .counterPartyId(notification.getSendTo()) .querySpec(QuerySpec.Builder.newInstance() - // TODO https://github.com/eclipse-tractusx/traceability-foss/issues/978 + // https://github.com/eclipse-tractusx/traceability-foss/issues/978 // Probably: - // leftOperand = http://purl.org/dc/terms/type'.'@id' + // leftOperand = 'http://purl.org/dc/terms/type'.'@id' // rightOperand = cx-taxo:ReceiveQualityAlertNotification (make sure to check the input for the correct one Receive/Update and Alert or Investigation // The types are all in the ticket documented .filter( - List.of(new Criterion(NAMESPACE_EDC + "notificationtype", "=", propertyNotificationTypeValue), - new Criterion(NAMESPACE_EDC + "notificationmethod", "=", propertyMethodValue)) + List.of(new Criterion("'http://purl.org/dc/terms/type'.'@id'", "=", taxoValue)) ) .build()) .build() diff --git a/tx-backend/src/test/resources/stubs/edc/post/data/contractagreements/contractagreement_negotiation_response_200.json b/tx-backend/src/test/resources/stubs/edc/post/data/contractagreements/contractagreement_negotiation_response_200.json index e99e592351..8aa4ac952a 100644 --- a/tx-backend/src/test/resources/stubs/edc/post/data/contractagreements/contractagreement_negotiation_response_200.json +++ b/tx-backend/src/test/resources/stubs/edc/post/data/contractagreements/contractagreement_negotiation_response_200.json @@ -1,14 +1,14 @@ { "@type" : "edc:ContractNegotiation", "@id" : "a521a424-a07b-4a08-a845-676f2ddd0e89", - "edc:type" : "CONSUMER", - "edc:protocol" : "dataspace-protocol-http", - "edc:state" : "FINALIZED", - "edc:counterPartyId" : "BPNL00000003CML1", - "edc:counterPartyAddress" : "https://trace-x-edc-e2e-a.dev.demo.catena-x.net/api/v1/dsp", - "edc:callbackAddresses" : [], - "edc:createdAt" : 1708590580001, - "edc:contractAgreementId" : "ODA3MmUyNTQtOGNlZi00YzQ2LTljNGYtNGYzNjE2YjQ5NTZl:cmVnaXN0cnktYXNzZXQ=:MDljNDMzY2EtODI5OS00OGE3LWI0MjYtNzZmZjJmODE1ZWE2", + "type" : "CONSUMER", + "protocol" : "dataspace-protocol-http", + "state" : "FINALIZED", + "counterPartyId" : "BPNL00000003CML1", + "counterPartyAddress" : "https://trace-x-edc-e2e-a.dev.demo.catena-x.net/api/v1/dsp", + "callbackAddresses" : [], + "createdAt" : 1708590580001, + "contractAgreementId" : "ODA3MmUyNTQtOGNlZi00YzQ2LTljNGYtNGYzNjE2YjQ5NTZl:cmVnaXN0cnktYXNzZXQ=:MDljNDMzY2EtODI5OS00OGE3LWI0MjYtNzZmZjJmODE1ZWE2", "@context" : { "dct" : "https://purl.org/dc/terms/", "tx" : "https://w3id.org/tractusx/v0.0.1/ns/", diff --git a/tx-backend/src/test/resources/stubs/irs/policies/response_200_get_policies.json b/tx-backend/src/test/resources/stubs/irs/policies/response_200_get_policies.json index 54a28c980c..9f43921cd3 100644 --- a/tx-backend/src/test/resources/stubs/irs/policies/response_200_get_policies.json +++ b/tx-backend/src/test/resources/stubs/irs/policies/response_200_get_policies.json @@ -4,6 +4,9 @@ "validUntil" : "2029-04-03T13:04:58.000819786Z", "payload" : { "@context" : { + "@vocab" : "https://w3id.org/edc/v0.0.1/ns/", + "edc" : "https://w3id.org/edc/v0.0.1/ns/", + "cx-policy" : "https://w3id.org/catenax/policy/", "odrl" : "http://www.w3.org/ns/odrl/2/" }, "@id" : "default-policy", @@ -13,7 +16,7 @@ "validUntil" : "2029-04-03T13:04:58.000819786Z", "permissions" : [ { - "action" : "USE", + "action" : "use", "constraint" : { "and" : [ {