Skip to content

Commit

Permalink
Merge pull request #1259 from catenax-ng/bug/978-fix-edc-policy-funct…
Browse files Browse the repository at this point in the history
…ionality

Bug/978 fix edc policy functionality
  • Loading branch information
ds-lcapellino authored May 21, 2024
2 parents ce06e62 + 2fa6d5c commit 89c20f3
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 29 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,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
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ SPDX-License-Identifier: Apache-2.0
<junit-bom.version>5.10.2</junit-bom.version>
<awaitility.version>4.2.1</awaitility.version>
<!-- TODO https://github.com/eclipse-tractusx/traceability-foss/issues/978 update to the cx release version of irs lib IMPORTANT NO SNAPSHOT-->
<irs-client-lib.version>2.0.4-SNAPSHOT</irs-client-lib.version>
<irs-client-lib.version>2.0.5-SNAPSHOT</irs-client-lib.version>
<json-schema-validator.version>5.4.0</json-schema-validator.version>
<!-- Sonar related properties -->
<sonar.java.coveragePlugin>jacoco</sonar.java.coveragePlugin>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<EdcPolicyPermission> mapToPermissions(List<PermissionResponse> 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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"})
Expand All @@ -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": [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand Down Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
@@ -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/",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -13,7 +16,7 @@
"validUntil" : "2029-04-03T13:04:58.000819786Z",
"permissions" : [
{
"action" : "USE",
"action" : "use",
"constraint" : {
"and" : [
{
Expand Down

0 comments on commit 89c20f3

Please sign in to comment.