From a5fcb50e6049a38c7faaa5e00b9f9b88a1c56efc Mon Sep 17 00:00:00 2001 From: jhartmann Date: Thu, 16 May 2024 18:08:27 +0200 Subject: [PATCH] feat(policy-store):[#616] fix action in policy creation --- .../test/resources/templates/policy-for-e2e-tests.json | 2 +- .../__files/edc/responseGetNegotiationConfirmed.json | 2 +- .../__files/edc/responseGetNegotiationState.json | 2 +- .../__files/edc/responseGetTransferConfirmed.json | 2 +- .../__files/edc/responseGetTransferState.json | 2 +- .../__files/edc/responseStartNegotiation.json | 2 +- .../__files/edc/responseStartTransferprocess.json | 2 +- .../policystore/controllers/PolicyStoreController.java | 8 +++++++- .../request-collection/IRS_Request_Collection.json | 10 +++++----- local/testing/testdata/transform-and-upload.py | 2 +- 10 files changed, 20 insertions(+), 14 deletions(-) diff --git a/irs-cucumber-tests/src/test/resources/templates/policy-for-e2e-tests.json b/irs-cucumber-tests/src/test/resources/templates/policy-for-e2e-tests.json index bcfccffc15..854ad8f673 100644 --- a/irs-cucumber-tests/src/test/resources/templates/policy-for-e2e-tests.json +++ b/irs-cucumber-tests/src/test/resources/templates/policy-for-e2e-tests.json @@ -6,7 +6,7 @@ "policy": { "odrl:permission": [ { - "odrl:action": "USE", + "odrl:action": "use", "odrl:constraint": { "odrl:and": [ { diff --git a/irs-edc-client/src/test/resources/__files/edc/responseGetNegotiationConfirmed.json b/irs-edc-client/src/test/resources/__files/edc/responseGetNegotiationConfirmed.json index 7dd7e1ad38..080345bada 100644 --- a/irs-edc-client/src/test/resources/__files/edc/responseGetNegotiationConfirmed.json +++ b/irs-edc-client/src/test/resources/__files/edc/responseGetNegotiationConfirmed.json @@ -8,7 +8,7 @@ "edc:callbackAddresses": [], "edc:contractAgreementId": "7681f966-36ea-4542-b5ea-0d0db81967de:5a7ab616-989f-46ae-bdf2-32027b9f6ee6-31b614f5-ec14-4ed2-a509-e7b7780083e7:a6144a2e-c1b1-4ec6-96e1-a221da134e4f", "@context": { - "dct": "https://purl.org/dc/terms/", + "dct": "http://purl.org/dc/terms/", "tx": "https://w3id.org/tractusx/v0.0.1/ns/", "edc": "https://w3id.org/edc/v0.0.1/ns/", "dcat": "https://www.w3.org/ns/dcat/", diff --git a/irs-edc-client/src/test/resources/__files/edc/responseGetNegotiationState.json b/irs-edc-client/src/test/resources/__files/edc/responseGetNegotiationState.json index ee4e9141e6..17ad6b9987 100644 --- a/irs-edc-client/src/test/resources/__files/edc/responseGetNegotiationState.json +++ b/irs-edc-client/src/test/resources/__files/edc/responseGetNegotiationState.json @@ -2,7 +2,7 @@ "@type": "edc:NegotiationState", "edc:state": "FINALIZED", "@context": { - "dct": "https://purl.org/dc/terms/", + "dct": "http://purl.org/dc/terms/", "tx": "https://w3id.org/tractusx/v0.0.1/ns/", "edc": "https://w3id.org/edc/v0.0.1/ns/", "dcat": "https://www.w3.org/ns/dcat/", diff --git a/irs-edc-client/src/test/resources/__files/edc/responseGetTransferConfirmed.json b/irs-edc-client/src/test/resources/__files/edc/responseGetTransferConfirmed.json index 4e75a141eb..f6e6234dfb 100644 --- a/irs-edc-client/src/test/resources/__files/edc/responseGetTransferConfirmed.json +++ b/irs-edc-client/src/test/resources/__files/edc/responseGetTransferConfirmed.json @@ -17,7 +17,7 @@ }, "edc:receiverHttpEndpoint": "https://irs-submodel-server3.dev.demo.catena-x.net/data/endpoint-data", "@context": { - "dct": "https://purl.org/dc/terms/", + "dct": "http://purl.org/dc/terms/", "tx": "https://w3id.org/tractusx/v0.0.1/ns/", "edc": "https://w3id.org/edc/v0.0.1/ns/", "dcat": "https://www.w3.org/ns/dcat/", diff --git a/irs-edc-client/src/test/resources/__files/edc/responseGetTransferState.json b/irs-edc-client/src/test/resources/__files/edc/responseGetTransferState.json index 7d0b2f267c..22715906e8 100644 --- a/irs-edc-client/src/test/resources/__files/edc/responseGetTransferState.json +++ b/irs-edc-client/src/test/resources/__files/edc/responseGetTransferState.json @@ -2,7 +2,7 @@ "@type": "edc:TransferState", "edc:state": "COMPLETED", "@context": { - "dct": "https://purl.org/dc/terms/", + "dct": "http://purl.org/dc/terms/", "tx": "https://w3id.org/tractusx/v0.0.1/ns/", "edc": "https://w3id.org/edc/v0.0.1/ns/", "dcat": "https://www.w3.org/ns/dcat/", diff --git a/irs-edc-client/src/test/resources/__files/edc/responseStartNegotiation.json b/irs-edc-client/src/test/resources/__files/edc/responseStartNegotiation.json index cb7ca32a7c..75cacfebbc 100644 --- a/irs-edc-client/src/test/resources/__files/edc/responseStartNegotiation.json +++ b/irs-edc-client/src/test/resources/__files/edc/responseStartNegotiation.json @@ -3,7 +3,7 @@ "@id": "1bbaec6e-c316-4e1e-8258-c07a648cc43c", "edc:createdAt": 1686830151573, "@context": { - "dct": "https://purl.org/dc/terms/", + "dct": "http://purl.org/dc/terms/", "tx": "https://w3id.org/tractusx/v0.0.1/ns/", "edc": "https://w3id.org/edc/v0.0.1/ns/", "dcat": "https://www.w3.org/ns/dcat/", diff --git a/irs-edc-client/src/test/resources/__files/edc/responseStartTransferprocess.json b/irs-edc-client/src/test/resources/__files/edc/responseStartTransferprocess.json index f6be3d222e..c4a8edc4a2 100644 --- a/irs-edc-client/src/test/resources/__files/edc/responseStartTransferprocess.json +++ b/irs-edc-client/src/test/resources/__files/edc/responseStartTransferprocess.json @@ -3,7 +3,7 @@ "@id": "1b21e963-0bc5-422a-b30d-fd3511861d88", "edc:createdAt": 1686758532950, "@context": { - "dct": "https://purl.org/dc/terms/", + "dct": "http://purl.org/dc/terms/", "tx": "https://w3id.org/tractusx/v0.0.1/ns/", "edc": "https://w3id.org/edc/v0.0.1/ns/", "dcat": "https://www.w3.org/ns/dcat/", diff --git a/irs-policy-store/src/main/java/org/eclipse/tractusx/irs/policystore/controllers/PolicyStoreController.java b/irs-policy-store/src/main/java/org/eclipse/tractusx/irs/policystore/controllers/PolicyStoreController.java index 470f714830..bd2aa004ca 100644 --- a/irs-policy-store/src/main/java/org/eclipse/tractusx/irs/policystore/controllers/PolicyStoreController.java +++ b/irs-policy-store/src/main/java/org/eclipse/tractusx/irs/policystore/controllers/PolicyStoreController.java @@ -46,6 +46,7 @@ import lombok.extern.slf4j.Slf4j; import org.apache.commons.collections.CollectionUtils; import org.eclipse.tractusx.irs.common.auth.IrsRoles; +import org.eclipse.tractusx.irs.data.JsonParseException; import org.eclipse.tractusx.irs.dtos.ErrorResponse; import org.eclipse.tractusx.irs.edc.client.policy.Policy; import org.eclipse.tractusx.irs.policystore.models.CreatePoliciesResponse; @@ -126,8 +127,13 @@ public class PolicyStoreController { @ResponseStatus(HttpStatus.CREATED) @PreAuthorize("hasAuthority('" + IrsRoles.ADMIN_IRS + "')") public CreatePoliciesResponse registerAllowedPolicy(@Valid @RequestBody final CreatePolicyRequest request) { + final Policy registeredPolicy; - final Policy registeredPolicy = service.registerPolicy(request); + try { + registeredPolicy = service.registerPolicy(request); + } catch (JsonParseException e) { + throw new ResponseStatusException(HttpStatus.BAD_REQUEST, e.getMessage(), e); + } if (registeredPolicy == null) { throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, "Policy was not registered"); diff --git a/local/testing/request-collection/IRS_Request_Collection.json b/local/testing/request-collection/IRS_Request_Collection.json index a1d2156f6d..569d04030d 100644 --- a/local/testing/request-collection/IRS_Request_Collection.json +++ b/local/testing/request-collection/IRS_Request_Collection.json @@ -2651,7 +2651,7 @@ "method": "POST", "body": { "mimeType": "application/json", - "text": "{\n\t\"@context\": {\n\t\t\"dct\": \"https://purl.org/dc/terms/\",\n\t\t\"tx\": \"https://w3id.org/tractusx/v0.0.1/ns/\",\n\t\t\"edc\": \"https://w3id.org/edc/v0.0.1/ns/\",\n\t\t\"odrl\": \"http://www.w3.org/ns/odrl/2/\",\n\t\t\"dcat\": \"https://www.w3.org/ns/dcat/\",\n\t\t\"dspace\": \"https://w3id.org/dspace/v0.8/\"\n\t},\n\t\"edc:protocol\": \"dataspace-protocol-http\",\n\t\"edc:providerUrl\": \"{{ _.PROVIDER_CONTROLPLANE_1 }}/api/v1/dsp\"\n}" + "text": "{\n\t\"@context\": {\n\t\t\"dct\": \"http://purl.org/dc/terms/\",\n\t\t\"tx\": \"https://w3id.org/tractusx/v0.0.1/ns/\",\n\t\t\"edc\": \"https://w3id.org/edc/v0.0.1/ns/\",\n\t\t\"odrl\": \"http://www.w3.org/ns/odrl/2/\",\n\t\t\"dcat\": \"https://www.w3.org/ns/dcat/\",\n\t\t\"dspace\": \"https://w3id.org/dspace/v0.8/\"\n\t},\n\t\"edc:protocol\": \"dataspace-protocol-http\",\n\t\"edc:providerUrl\": \"{{ _.PROVIDER_CONTROLPLANE_1 }}/api/v1/dsp\"\n}" }, "parameters": [], "headers": [ @@ -2712,7 +2712,7 @@ "method": "POST", "body": { "mimeType": "application/json", - "text": "{\n\t\"@context\": {\n\t\t\"dct\": \"https://purl.org/dc/terms/\",\n\t\t\"tx\": \"https://w3id.org/tractusx/v0.0.1/ns/\",\n\t\t\"edc\": \"https://w3id.org/edc/v0.0.1/ns/\",\n\t\t\"odrl\": \"http://www.w3.org/ns/odrl/2/\",\n\t\t\"dcat\": \"https://www.w3.org/ns/dcat/\",\n\t\t\"dspace\": \"https://w3id.org/dspace/v0.8/\"\n\t},\n\t\"edc:providerUrl\": \"{{ _.PROVIDER_CONTROLPLANE_1 }}/api/v1/dsp\",\n\t\"edc:protocol\": \"dataspace-protocol-http\",\n\t\"edc:querySpec\": {\n\t\t\"edc:filterExpression\": {\n\t\t\t\"edc:operandLeft\": \"https://w3id.org/edc/v0.0.1/ns/type\",\n\t\t\t\"edc:operator\": \"=\",\n\t\t\t\"edc:operandRight\": \"data.core.digitalTwinRegistry\"\n\t\t}\n\t}\n}" + "text": "{\n\t\"@context\": {\n\t\t\"dct\": \"http://purl.org/dc/terms/\",\n\t\t\"tx\": \"https://w3id.org/tractusx/v0.0.1/ns/\",\n\t\t\"edc\": \"https://w3id.org/edc/v0.0.1/ns/\",\n\t\t\"odrl\": \"http://www.w3.org/ns/odrl/2/\",\n\t\t\"dcat\": \"https://www.w3.org/ns/dcat/\",\n\t\t\"dspace\": \"https://w3id.org/dspace/v0.8/\"\n\t},\n\t\"edc:providerUrl\": \"{{ _.PROVIDER_CONTROLPLANE_1 }}/api/v1/dsp\",\n\t\"edc:protocol\": \"dataspace-protocol-http\",\n\t\"edc:querySpec\": {\n\t\t\"edc:filterExpression\": {\n\t\t\t\"edc:operandLeft\": \"https://w3id.org/edc/v0.0.1/ns/type\",\n\t\t\t\"edc:operator\": \"=\",\n\t\t\t\"edc:operandRight\": \"data.core.digitalTwinRegistry\"\n\t\t}\n\t}\n}" }, "parameters": [], "headers": [ @@ -2749,7 +2749,7 @@ "method": "POST", "body": { "mimeType": "application/json", - "text": "{\n\t\"@context\": {\n\t\t\"dct\": \"https://purl.org/dc/terms/\",\n\t\t\"tx\": \"https://w3id.org/tractusx/v0.0.1/ns/\",\n\t\t\"edc\": \"https://w3id.org/edc/v0.0.1/ns/\",\n\t\t\"odrl\": \"http://www.w3.org/ns/odrl/2/\",\n\t\t\"dcat\": \"https://www.w3.org/ns/dcat/\",\n\t\t\"dspace\": \"https://w3id.org/dspace/v0.8/\"\n\t},\n\t\"edc:providerUrl\": \"{{ _.PROVIDER_CONTROLPLANE_1 }}/api/v1/dsp\",\n\t\"edc:protocol\": \"dataspace-protocol-http\",\n\t\"edc:querySpec\": {\n\t\t\"edc:filterExpression\": {\n\t\t\t\"edc:operandLeft\": \"https://w3id.org/edc/v0.0.1/ns/id\",\n\t\t\t\"edc:operator\": \"=\",\n\t\t\t\"edc:operandRight\": \"{% prompt 'assetId', '', '', '', false, true %}\"\n\t\t}\n\t}\n}" + "text": "{\n\t\"@context\": {\n\t\t\"dct\": \"http://purl.org/dc/terms/\",\n\t\t\"tx\": \"https://w3id.org/tractusx/v0.0.1/ns/\",\n\t\t\"edc\": \"https://w3id.org/edc/v0.0.1/ns/\",\n\t\t\"odrl\": \"http://www.w3.org/ns/odrl/2/\",\n\t\t\"dcat\": \"https://www.w3.org/ns/dcat/\",\n\t\t\"dspace\": \"https://w3id.org/dspace/v0.8/\"\n\t},\n\t\"edc:providerUrl\": \"{{ _.PROVIDER_CONTROLPLANE_1 }}/api/v1/dsp\",\n\t\"edc:protocol\": \"dataspace-protocol-http\",\n\t\"edc:querySpec\": {\n\t\t\"edc:filterExpression\": {\n\t\t\t\"edc:operandLeft\": \"https://w3id.org/edc/v0.0.1/ns/id\",\n\t\t\t\"edc:operator\": \"=\",\n\t\t\t\"edc:operandRight\": \"{% prompt 'assetId', '', '', '', false, true %}\"\n\t\t}\n\t}\n}" }, "parameters": [], "headers": [ @@ -2786,7 +2786,7 @@ "method": "POST", "body": { "mimeType": "application/json", - "text": "{\n\t\"edc:connectorAddress\": \"{{ _.PROVIDER_CONTROLPLANE_1 }}/api/v1/dsp\",\n\t\"edc:connectorId\": \"BPNL00000001CRHK\",\n\t\"edc:offer\": {\n\t\t\"@type\": \"edc:ContractOfferDescription\",\n\t\t\"edc:offerId\": \"ZGR0ci1jeG1lbWJlcnMtY29udHJhY3Q=:ZGlnaXRhbC10d2luLXJlZ2lzdHJ5:OGQ0ZTNkODYtOTIxOC00MjljLWI1N2EtNWZlZTZkODIzMmEx\",\n\t\t\"edc:assetId\": \"digital-twin-registry\",\n\t\t\"edc:policy\": {\n\t\t\t\"@type\": \"odrl:Set\",\n\t\t\t\"odrl:permission\": {\n\t\t\t\t\"odrl:target\": \"digital-twin-registry\",\n\t\t\t\t\"odrl:action\": {\n\t\t\t\t\t\"odrl:type\": \"USE\"\n\t\t\t\t}\n\t\t\t},\n\t\t\t\"odrl:prohibition\": [],\n\t\t\t\"odrl:obligation\": [],\n\t\t\t\"odrl:target\": \"digital-twin-registry\"\n\t\t}\n\t},\n\t\"edc:protocol\": \"dataspace-protocol-http\",\n\t\"edc:callbackAddresses\": [],\n\t\"@context\": {\n\t\t\"dct\": \"https://purl.org/dc/terms/\",\n\t\t\"tx\": \"https://w3id.org/tractusx/v0.0.1/ns/\",\n\t\t\"edc\": \"https://w3id.org/edc/v0.0.1/ns/\",\n\t\t\"odrl\": \"http://www.w3.org/ns/odrl/2/\",\n\t\t\"dcat\": \"https://www.w3.org/ns/dcat/\",\n\t\t\"dspace\": \"https://w3id.org/dspace/v0.8/\"\n\t}\n}" + "text": "{\n\t\"edc:connectorAddress\": \"{{ _.PROVIDER_CONTROLPLANE_1 }}/api/v1/dsp\",\n\t\"edc:connectorId\": \"BPNL00000001CRHK\",\n\t\"edc:offer\": {\n\t\t\"@type\": \"edc:ContractOfferDescription\",\n\t\t\"edc:offerId\": \"ZGR0ci1jeG1lbWJlcnMtY29udHJhY3Q=:ZGlnaXRhbC10d2luLXJlZ2lzdHJ5:OGQ0ZTNkODYtOTIxOC00MjljLWI1N2EtNWZlZTZkODIzMmEx\",\n\t\t\"edc:assetId\": \"digital-twin-registry\",\n\t\t\"edc:policy\": {\n\t\t\t\"@type\": \"odrl:Set\",\n\t\t\t\"odrl:permission\": {\n\t\t\t\t\"odrl:target\": \"digital-twin-registry\",\n\t\t\t\t\"odrl:action\": {\n\t\t\t\t\t\"odrl:type\": \"USE\"\n\t\t\t\t}\n\t\t\t},\n\t\t\t\"odrl:prohibition\": [],\n\t\t\t\"odrl:obligation\": [],\n\t\t\t\"odrl:target\": \"digital-twin-registry\"\n\t\t}\n\t},\n\t\"edc:protocol\": \"dataspace-protocol-http\",\n\t\"edc:callbackAddresses\": [],\n\t\"@context\": {\n\t\t\"dct\": \"http://purl.org/dc/terms/\",\n\t\t\"tx\": \"https://w3id.org/tractusx/v0.0.1/ns/\",\n\t\t\"edc\": \"https://w3id.org/edc/v0.0.1/ns/\",\n\t\t\"odrl\": \"http://www.w3.org/ns/odrl/2/\",\n\t\t\"dcat\": \"https://www.w3.org/ns/dcat/\",\n\t\t\"dspace\": \"https://w3id.org/dspace/v0.8/\"\n\t}\n}" }, "parameters": [], "headers": [ @@ -2935,7 +2935,7 @@ "method": "POST", "body": { "mimeType": "application/json", - "text": "{\n\t\"edc:assetId\": \"digital-twin-registry\",\n\t\"edc:connectorAddress\": \"{{ _.PROVIDER_CONTROLPLANE_1 }}/api/v1/dsp\",\n\t\"edc:contractId\": \"ZGR0ci1jeG1lbWJlcnMtY29udHJhY3Q=:ZGlnaXRhbC10d2luLXJlZ2lzdHJ5:NGNlMDk0ODgtOTMzYy00ZDk3LThiNTAtNDMyZWRjMzIwM2Fm\",\n\t\"edc:dataDestination\": {\n\t\t\"edc:type\": \"HttpProxy\"\n\t},\n\t\"edc:protocol\": \"dataspace-protocol-http\",\n\t\"edc:managedResources\": false,\n\t\"edc:connectorId\": \"BPNL00000001CRHK\",\n\t\"@context\": {\n\t\t\"dct\": \"https://purl.org/dc/terms/\",\n\t\t\"tx\": \"https://w3id.org/tractusx/v0.0.1/ns/\",\n\t\t\"edc\": \"https://w3id.org/edc/v0.0.1/ns/\",\n\t\t\"odrl\": \"http://www.w3.org/ns/odrl/2/\",\n\t\t\"dcat\": \"https://www.w3.org/ns/dcat/\",\n\t\t\"dspace\": \"https://w3id.org/dspace/v0.8/\"\n\t}\n}" + "text": "{\n\t\"edc:assetId\": \"digital-twin-registry\",\n\t\"edc:connectorAddress\": \"{{ _.PROVIDER_CONTROLPLANE_1 }}/api/v1/dsp\",\n\t\"edc:contractId\": \"ZGR0ci1jeG1lbWJlcnMtY29udHJhY3Q=:ZGlnaXRhbC10d2luLXJlZ2lzdHJ5:NGNlMDk0ODgtOTMzYy00ZDk3LThiNTAtNDMyZWRjMzIwM2Fm\",\n\t\"edc:dataDestination\": {\n\t\t\"edc:type\": \"HttpProxy\"\n\t},\n\t\"edc:protocol\": \"dataspace-protocol-http\",\n\t\"edc:managedResources\": false,\n\t\"edc:connectorId\": \"BPNL00000001CRHK\",\n\t\"@context\": {\n\t\t\"dct\": \"http://purl.org/dc/terms/\",\n\t\t\"tx\": \"https://w3id.org/tractusx/v0.0.1/ns/\",\n\t\t\"edc\": \"https://w3id.org/edc/v0.0.1/ns/\",\n\t\t\"odrl\": \"http://www.w3.org/ns/odrl/2/\",\n\t\t\"dcat\": \"https://www.w3.org/ns/dcat/\",\n\t\t\"dspace\": \"https://w3id.org/dspace/v0.8/\"\n\t}\n}" }, "parameters": [], "headers": [ diff --git a/local/testing/testdata/transform-and-upload.py b/local/testing/testdata/transform-and-upload.py index 0349f15d53..ed81839dc6 100644 --- a/local/testing/testdata/transform-and-upload.py +++ b/local/testing/testdata/transform-and-upload.py @@ -83,7 +83,7 @@ def create_edc_registry_asset_payload(registry_url_, asset_prop_id_): def edc_context(): return { - "dct": "https://purl.org/dc/terms/", + "dct": "http://purl.org/dc/terms/", "tx": "https://w3id.org/tractusx/v0.0.1/ns/", "edc": "https://w3id.org/edc/v0.0.1/ns/", "dcat": "https://www.w3.org/ns/dcat/",