Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(policy-store): [#trace-foss-970] return rightOperand without odrl… #725

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
16 changes: 8 additions & 8 deletions docs/concept/#333-Policy-hub-concept/#333-policy-hub-concept.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions docs/src/api/irs-api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

}
Original file line number Diff line number Diff line change
@@ -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<Permission> 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");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading