diff --git a/CHANGELOG.md b/CHANGELOG.md index ea455af98a..47c1cd3419 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,7 +10,8 @@ _**For better traceability add the corresponding GitHub issue number in each cha ### Fixed -- Fixed ESS Investigation job processing not starting #579 +- Fixed ESS Investigation job processing not starting #579 +- Policy store API returns 'rightOperand' without 'odrl:' prefix now (see traceability-foss/issues/970). ### Changed diff --git a/docs/concept/#333-Policy-hub-concept/#333-policy-hub-concept.md b/docs/concept/#333-Policy-hub-concept/#333-policy-hub-concept.md index 3a93d8e248..2da4e0d945 100644 --- a/docs/concept/#333-Policy-hub-concept/#333-policy-hub-concept.md +++ b/docs/concept/#333-Policy-hub-concept/#333-policy-hub-concept.md @@ -108,14 +108,14 @@ sequenceDiagram ### Policy Validation -| PolicyContentDefinition Request | PolicyTemplate Response | Policy | Description | -|----------------------------------------|--------------------------|---------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------| -| PolicyType (Usage/Access) | action(use, access) | action(use, access) | Mappring of correct type | -| ConstraintOperand (And/Or) | odrl:and/:or |odrl:and/:or| Logical Operand to use AND and OR is supported | -| Constraints.Key | leftOperand | leftOperand | | | -| Constraints.Operator (Equals, In, ...) | operator(eq,in,neq, ...) | operator (eq,in,neq, ...) | | | -| Constraints.Value Static | rightOperand | rightOperand | For static value check right operand for dynamic value check if Policy.rightOperand.value is in PolicyTemplate.rightOperand.atrributes.key.possibleValues | -| Constraints.Value Attributes | rightOperand @attributes | rightOperand | Dynamic value check if Policy.rightOperand.value is in PolicyTemplate.rightOperand.atrributes.key.possibleValues | +| PolicyContentDefinition Request | PolicyTemplate Response | Policy | Description | +|----------------------------------------|--------------------------|----------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------| +| PolicyType (Usage/Access) | action(use, access) | action(use, access) | Mapping of correct type | +| ConstraintOperand (And/Or) | odrl:and/:or | odrl:and/:or | Logical Operand to use AND and OR is supported | +| Constraints.Key | leftOperand | leftOperand | | | +| Constraints.Operator (Equals, In, ...) | operator(eq,in,neq, ...) | operator (eq,in,neq, ...) | | | +| Constraints.Value Static | rightOperand | rightOperand | For static value check right operand for dynamic value check if Policy.rightOperand.value is in PolicyTemplate.rightOperand.atrributes.key.possibleValues | +| Constraints.Value Attributes | rightOperand @attributes | rightOperand | Dynamic value check if Policy.rightOperand.value is in PolicyTemplate.rightOperand.atrributes.key.possibleValues | ### Detailed error message diff --git a/docs/src/api/irs-api.yaml b/docs/src/api/irs-api.yaml index 74eff7359e..8580810ea0 100644 --- a/docs/src/api/irs-api.yaml +++ b/docs/src/api/irs-api.yaml @@ -827,11 +827,11 @@ paths: - leftOperand: Membership operator: '@id': eq - odrl:rightOperand: active + rightOperand: active - leftOperand: PURPOSE operator: '@id': eq - odrl:rightOperand: ID 3.1 Trace + rightOperand: ID 3.1 Trace or: null BPNA1234567890DF: [] schema: diff --git a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/policy/Constraint.java b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/policy/Constraint.java index e9ab239c51..9b2fc01f08 100644 --- a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/policy/Constraint.java +++ b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/policy/Constraint.java @@ -24,7 +24,6 @@ package org.eclipse.tractusx.irs.edc.client.policy; import com.fasterxml.jackson.annotation.JsonAlias; -import com.fasterxml.jackson.annotation.JsonProperty; import io.swagger.v3.oas.annotations.media.Schema; import lombok.AllArgsConstructor; import lombok.Getter; @@ -39,13 +38,13 @@ public class Constraint { @Schema(implementation = String.class, example = "string") - @JsonAlias({"odrl:leftOperand"}) + @JsonAlias("odrl:leftOperand") private String leftOperand; @JsonAlias("odrl:operator") @Schema private Operator operator; @Schema(implementation = String.class, example = "string") - @JsonProperty("odrl:rightOperand") + @JsonAlias("odrl:rightOperand") private String rightOperand; } diff --git a/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/policy/ConstraintTest.java b/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/policy/ConstraintTest.java new file mode 100644 index 0000000000..9ce200afff --- /dev/null +++ b/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/policy/ConstraintTest.java @@ -0,0 +1,80 @@ +/******************************************************************************** + * Copyright (c) 2022,2024 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) + * Copyright (c) 2021,2024 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0 which is available at + * https://www.apache.org/licenses/LICENSE-2.0. + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + * SPDX-License-Identifier: Apache-2.0 + ********************************************************************************/ +package org.eclipse.tractusx.irs.edc.client.policy; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.util.Collection; +import java.util.List; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +class ConstraintTest { + + private ObjectMapper mapper; + + @BeforeEach + void setUp() { + mapper = new ObjectMapper(); + mapper.registerModule(new JavaTimeModule()); + } + + @Test + void canReadPermissionsWithDifferentRightOperandAttributeNames() throws JsonProcessingException { + + final List permissions = mapper.readerForListOf(Permission.class).readValue(""" + [ + { + "action": "use", + "constraint": { + "and": [ + { + "leftOperand": "Membership", + "operator": { + "@id": "eq" + }, + "odrl:rightOperand": "active" + }, + { + "leftOperand": "PURPOSE", + "operator": { + "@id": "eq" + }, + "rightOperand": "ID 3.1 Trace" + } + ], + "or": null + } + } + ] + """); + + assertThat(permissions).isNotEmpty(); + assertThat(permissions.stream() + .map(p -> p.getConstraint().getAnd()) + .flatMap(Collection::stream) + .map(Constraint::getRightOperand)).containsExactlyInAnyOrder("active", "ID 3.1 Trace"); + } + +} \ No newline at end of file diff --git a/irs-policy-store/src/main/java/org/eclipse/tractusx/irs/policystore/models/PolicyResponse.java b/irs-policy-store/src/main/java/org/eclipse/tractusx/irs/policystore/models/PolicyResponse.java index 3ce5a76673..a205b12276 100644 --- a/irs-policy-store/src/main/java/org/eclipse/tractusx/irs/policystore/models/PolicyResponse.java +++ b/irs-policy-store/src/main/java/org/eclipse/tractusx/irs/policystore/models/PolicyResponse.java @@ -56,14 +56,14 @@ public record PolicyResponse(OffsetDateTime validUntil, Payload payload) { "operator": { "@id": "eq" }, - "odrl:rightOperand": "active" + "rightOperand": "active" }, { "leftOperand": "PURPOSE", "operator": { "@id": "eq" }, - "odrl:rightOperand": "ID 3.1 Trace" + "rightOperand": "ID 3.1 Trace" } ], "or": null