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

Bugfix/edc policy: Fixed breaking changes in the backend #382

Merged
merged 7 commits into from
Jul 19, 2024
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
63 changes: 36 additions & 27 deletions docs/data-sovereignty/PolicyConfigGuide.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,29 +45,30 @@ When auto-negotiation is enabled for the assets or done for the digital twin reg
## Table of contents

<!-- TOC -->
* [Policy Configuration Guide](#policy-configuration-guide)
* [Introduction](#introduction)
* [Table of contents](#table-of-contents)
* [DPP Backend Configuration](#dpp-backend-configuration)
* [Helm Chart Details](#helm-chart-details)
* [Parameters](#parameters)
* [Main Parameters](#main-parameters)
* [Policy Set Configuration](#policy-set-configuration)
* [Action Configuration](#action-configuration)
* [Logical Constraint Configuration](#logical-constraint-configuration)
* [Constraint Configuration](#constraint-configuration)
* [Comparison Modes](#comparison-modes)
* [DPP Frontend Configuration](#dpp-frontend-configuration)
* [Policy Selection Options](#policy-selection-options)
* [Auto-Negotiation](#auto-negotiation)
* [Manual Negotiation](#manual-negotiation)
* [Agree Contract](#agree-contract)
* [Policy Interpretation](#policy-interpretation)
* [Decline Contract](#decline-contract)
* [Examples](#examples)
* [Logical Constraints](#logical-constraints)
* [Multiple Policies](#multiple-policies)
* [Single Constraint](#single-constraint)
- [Policy Configuration Guide](#policy-configuration-guide)
- [Introduction](#introduction)
- [Table of contents](#table-of-contents)
- [DPP Backend Configuration](#dpp-backend-configuration)
- [Helm Chart Details](#helm-chart-details)
- [Parameters](#parameters)
- [Main Parameters](#main-parameters)
- [Policy Set Configuration](#policy-set-configuration)
- [Action Configuration](#action-configuration)
- [Logical Constraint Configuration](#logical-constraint-configuration)
- [Constraint Configuration](#constraint-configuration)
- [Comparison Modes](#comparison-modes)
- [DPP Frontend Configuration](#dpp-frontend-configuration)
- [Policy Selection Options](#policy-selection-options)
- [Auto-Negotiation](#auto-negotiation)
- [Manual Negotiation](#manual-negotiation)
- [Agree Contract](#agree-contract)
- [Policy Interpretation](#policy-interpretation)
- [Decline Contract](#decline-contract)
- [Examples](#examples)
- [Logical Constraints](#logical-constraints)
- [Multiple Policies](#multiple-policies)
- [Single Constraint](#single-constraint)
- [NOTICE](#notice)
<!-- TOC -->

# DPP Backend Configuration
Expand Down Expand Up @@ -227,23 +228,29 @@ In case the and operator is used here is the way how it would be configured. For
"odrl:and": [
{
"@type": "Constraint",
"odrl:leftOperand": "cx-policy:Membership",
"odrl:leftOperand": {
"@id": "cx-policy:Membership"
},
"odrl:operator": {
"@id": "odrl:eq"
},
"odrl:rightOperand": "active"
},
{
"@type": "Constraint",
"odrl:leftOperand": "cx-policy:FrameworkAgreement",
"odrl:leftOperand": {
"@id": "cx-policy:FrameworkAgreement"
},
"odrl:operator": {
"@id": "odrl:eq"
},
"odrl:rightOperand": "circulareconomy:1.0"
},
{
"@type": "Constraint",
"odrl:leftOperand": "cx-policy:UsagePurpose",
"odrl:leftOperand": {
"@id": "cx-policy:UsagePurpose"
},
"odrl:operator": {
"@id": "odrl:eq"
},
Expand Down Expand Up @@ -396,7 +403,9 @@ The reason behind this is that the policies without logical constraints look lik
{
"odrl:action": "USE",
"odrl:constraint": {
"odrl:leftOperand": "cx-poliy:Membership",
"odrl:leftOperand": {
"@id": "cx-poliy:Membership"
},
"odrl:operator": {
"@id": "odrl:eq"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import org.eclipse.tractusx.digitalproductpass.core.config.PolicyCheckConfig;
import org.eclipse.tractusx.digitalproductpass.core.exceptions.ModelException;
import org.eclipse.tractusx.digitalproductpass.core.models.negotiation.DidDocument;

import java.util.ArrayList;
import java.util.List;
Expand All @@ -52,7 +53,7 @@ public class Action {
**/
@JsonProperty("odrl:action")
@JsonAlias({"action", "odrl:action"})
ActionType action;
DidDocument action;
@JsonProperty("odrl:constraint")
@JsonAlias({"constraint", "odrl:constraint"})
LogicalConstraint constraint;
Expand All @@ -65,7 +66,7 @@ public class Action {
public Action() {
}

public Action(ActionType action, LogicalConstraint constraint) {
public Action(DidDocument action, LogicalConstraint constraint) {
this.action = action;
this.constraint = constraint;
}
Expand All @@ -92,18 +93,18 @@ public String retrieveAction() {
if(this.action == null){
return null;
}
return this.action.getType();
return this.action.getId();
}
public void addAction(String action) {
this.action = new ActionType();
this.action.setType(action);
this.action = new DidDocument();
this.action.setId(action);
}

public ActionType getAction() {
public DidDocument getAction() {
return action;
}

public void setAction(ActionType action) {
public void setAction(DidDocument action) {
this.action = action;
}

Expand Down Expand Up @@ -148,25 +149,4 @@ static public List<Action> build(JsonNode node){
// If node is array parse the action node as a list
return mapper.convertValue(node, new TypeReference<>(){});
}

static class ActionType{
@JsonProperty("odrl:type")
@JsonAlias({"type", "odrl:type", "@type"})
String type;

public ActionType(String type) {
this.type = type;
}

public ActionType() {
}

public String getType() {
return type;
}

public void setType(String type) {
this.type = type;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public class Constraint {
/** ATTRIBUTES **/
@JsonProperty("odrl:leftOperand")
@JsonAlias({"leftOperand","odrl:leftOperand"})
String leftOperand;
DidDocument leftOperand;
@JsonProperty("odrl:operator")
@JsonAlias({"operator","odrl:operator"})
DidDocument operator;
Expand All @@ -56,15 +56,15 @@ public class Constraint {
String rightOperand;

/** CONSTRUCTOR(S) **/
public Constraint(String leftOperand, DidDocument operator, String rightOperand) {
public Constraint(DidDocument leftOperand, DidDocument operator, String rightOperand) {
this.leftOperand = leftOperand;
this.operator = operator;
this.rightOperand = rightOperand;
}

public Constraint() {
}
public Constraint(String leftOperand, String operator, String rightOperand){
public Constraint(DidDocument leftOperand, String operator, String rightOperand){
this.leftOperand = leftOperand;
this.operator = new DidDocument();
this.operator.setId(operator);
Expand All @@ -75,18 +75,19 @@ public Constraint(PolicyCheckConfig.ConstraintConfig constraintConfig) {
}

public void buildConstraint(PolicyCheckConfig.ConstraintConfig constraintConfig){
this.leftOperand = constraintConfig.getLeftOperand();
this.leftOperand = new DidDocument();
this.leftOperand.setId(constraintConfig.getLeftOperand());
this.operator = new DidDocument();
this.operator.setId(constraintConfig.getOperator());
this.rightOperand = constraintConfig.getRightOperand();
}

/** GETTERS AND SETTERS **/
public String getLeftOperand() {
public DidDocument getLeftOperand() {
return leftOperand;
}

public void setLeftOperand(String leftOperand) {
public void setLeftOperand(DidDocument leftOperand) {
this.leftOperand = leftOperand;
}

Expand Down Expand Up @@ -122,7 +123,7 @@ public boolean equals(Object o) {
*/
public Boolean compareConstraint(Constraint constraint){
try{
if(!this.leftOperand.equalsIgnoreCase(constraint.getLeftOperand())){return false;} //If left operand is not the same as the left operand
if(!this.leftOperand.getId().equalsIgnoreCase(constraint.getLeftOperand().getId())){return false;} //If left operand is not the same as the left operand
if(!this.operator.getId().equalsIgnoreCase(constraint.getOperator().getId())){return false;}//If operator id is not the same as the operator id
return this.rightOperand.equalsIgnoreCase(constraint.getRightOperand());//If right operand is not the same as the right operand
}catch (Exception e){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ enum LogicType{


/** CONSTRUCTOR(S) **/
public LogicalConstraint(String leftOperand, DidDocument operator, String rightOperand, List<Constraint> andOperator, List<Constraint> orOperator) {
public LogicalConstraint(DidDocument leftOperand, DidDocument operator, String rightOperand, List<Constraint> andOperator, List<Constraint> orOperator) {
super(leftOperand, operator, rightOperand);
this.andOperator = andOperator;
this.orOperator = orOperator;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ public class TransferRequest extends DidDocument {
/** ATTRIBUTES **/
@JsonProperty("assetId")
String assetId;
@JsonProperty("connectorAddress")
String connectorAddress;
@JsonProperty("counterPartyAddress")
String counterPartyAddress;
@JsonProperty("contractId")
String contractId;
@JsonProperty("dataDestination")
Expand All @@ -66,10 +66,10 @@ public class TransferRequest extends DidDocument {
public TransferRequest() {
}

public TransferRequest(String id, String type, String assetId, String connectorAddress, String contractId, DataDestination dataDestination, Boolean managedResources, String protocol, String transferType, List<CallbackAddress> callbackAddresses) {
public TransferRequest(String id, String type, String assetId, String counterPartyAddress, String contractId, DataDestination dataDestination, Boolean managedResources, String protocol, String transferType, List<CallbackAddress> callbackAddresses) {
super(id, type);
this.assetId = assetId;
this.connectorAddress = connectorAddress;
this.counterPartyAddress = counterPartyAddress;
this.contractId = contractId;
this.dataDestination = dataDestination;
this.managedResources = managedResources;
Expand All @@ -78,9 +78,9 @@ public TransferRequest(String id, String type, String assetId, String connectorA
this.callbackAddresses = callbackAddresses;
}

public TransferRequest(String assetId, String connectorAddress, String contractId, DataDestination dataDestination, Boolean managedResources, String protocol, String transferType, List<CallbackAddress> callbackAddresses) {
public TransferRequest(String assetId, String counterPartyAddress, String contractId, DataDestination dataDestination, Boolean managedResources, String protocol, String transferType, List<CallbackAddress> callbackAddresses) {
this.assetId = assetId;
this.connectorAddress = connectorAddress;
this.counterPartyAddress = counterPartyAddress;
this.contractId = contractId;
this.dataDestination = dataDestination;
this.managedResources = managedResources;
Expand All @@ -89,10 +89,10 @@ public TransferRequest(String assetId, String connectorAddress, String contractI
this.callbackAddresses = callbackAddresses;
}

public TransferRequest(String id, String type, JsonNode context, String assetId, String connectorAddress, String contractId, DataDestination dataDestination, Boolean managedResources, String protocol, String transferType, List<CallbackAddress> callbackAddresses) {
public TransferRequest(String id, String type, JsonNode context, String assetId, String counterPartyAddress, String contractId, DataDestination dataDestination, Boolean managedResources, String protocol, String transferType, List<CallbackAddress> callbackAddresses) {
super(id, type, context);
this.assetId = assetId;
this.connectorAddress = connectorAddress;
this.counterPartyAddress = counterPartyAddress;
this.contractId = contractId;
this.dataDestination = dataDestination;
this.managedResources = managedResources;
Expand All @@ -101,10 +101,10 @@ public TransferRequest(String id, String type, JsonNode context, String assetId,
this.callbackAddresses = callbackAddresses;
}

public TransferRequest(String type, String assetId, String connectorAddress, String contractId, DataDestination dataDestination, Boolean managedResources, String protocol, String transferType, List<CallbackAddress> callbackAddresses) {
public TransferRequest(String type, String assetId, String counterPartyAddress, String contractId, DataDestination dataDestination, Boolean managedResources, String protocol, String transferType, List<CallbackAddress> callbackAddresses) {
super(type);
this.assetId = assetId;
this.connectorAddress = connectorAddress;
this.counterPartyAddress = counterPartyAddress;
this.contractId = contractId;
this.dataDestination = dataDestination;
this.managedResources = managedResources;
Expand All @@ -113,10 +113,10 @@ public TransferRequest(String type, String assetId, String connectorAddress, Str
this.callbackAddresses = callbackAddresses;
}

public TransferRequest(JsonNode context, String assetId, String connectorAddress, String contractId, DataDestination dataDestination, Boolean managedResources, String protocol, String transferType, List<CallbackAddress> callbackAddresses) {
public TransferRequest(JsonNode context, String assetId, String counterPartyAddress, String contractId, DataDestination dataDestination, Boolean managedResources, String protocol, String transferType, List<CallbackAddress> callbackAddresses) {
super(context);
this.assetId = assetId;
this.connectorAddress = connectorAddress;
this.counterPartyAddress = counterPartyAddress;
this.contractId = contractId;
this.dataDestination = dataDestination;
this.managedResources = managedResources;
Expand All @@ -125,10 +125,10 @@ public TransferRequest(JsonNode context, String assetId, String connectorAddress
this.callbackAddresses = callbackAddresses;
}

public TransferRequest(JsonNode context, String type, String assetId, String connectorAddress, String contractId, DataDestination dataDestination, Boolean managedResources, String protocol, String transferType, List<CallbackAddress> callbackAddresses) {
public TransferRequest(JsonNode context, String type, String assetId, String counterPartyAddress, String contractId, DataDestination dataDestination, Boolean managedResources, String protocol, String transferType, List<CallbackAddress> callbackAddresses) {
super(context, type);
this.assetId = assetId;
this.connectorAddress = connectorAddress;
this.counterPartyAddress = counterPartyAddress;
this.contractId = contractId;
this.dataDestination = dataDestination;
this.managedResources = managedResources;
Expand All @@ -145,11 +145,11 @@ public String getAssetId() {
public void setAssetId(String assetId) {
this.assetId = assetId;
}
public String getConnectorAddress() {
return connectorAddress;
public String getCounterPartyAddress() {
return counterPartyAddress;
}
public void setConnectorAddress(String connectorAddress) {
this.connectorAddress = connectorAddress;
public void setCounterPartyAddress(String counterPartyAddress) {
this.counterPartyAddress = counterPartyAddress;
}
public String getContractId() { return contractId; }
public void setContractId(String contractId) { this.contractId = contractId; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ public Dataset getContractOfferByAssetId(String assetId, String counterPartyAddr
*/
public NegotiationRequest buildRequestFirstPolicy(Dataset dataset, String endpoint, String providerBpn) {
return new NegotiationRequest(
jsonUtil.toJsonNode(Map.of("odrl", "http://www.w3.org/ns/odrl/2/")),
jsonUtil.toJsonNode(Map.of("odrl", "http://www.w3.org/ns/odrl/2/", "@vocab", "https://w3id.org/edc/v0.0.1/ns/", "cx-policy", "https://w3id.org/catenax/policy/")),
endpoint,
"dataspace-protocol-http",
this.buildOffer(dataset, 0, providerBpn)
Expand Down Expand Up @@ -391,7 +391,7 @@ public NegotiationRequest buildRequestById(Dataset dataset, String endpoint, Str
*/
public NegotiationRequest buildRequest(String endpoint, Policy policyOffer) {
return new NegotiationRequest(
jsonUtil.toJsonNode(Map.of("odrl", "http://www.w3.org/ns/odrl/2/")),
jsonUtil.toJsonNode(Map.of("odrl", "http://www.w3.org/ns/odrl/2/", "@vocab", "https://w3id.org/edc/v0.0.1/ns/", "cx-policy", "https://w3id.org/catenax/policy/")),
"odrl:ContractRequest",
endpoint,
"dataspace-protocol-http",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ configuration:
# List of allowed permissions policies
policies:
- permission:
- action: "USE"
- action: "odrl:use"
logicalConstraint: "odrl:and"
constraints:
- leftOperand: "cx-policy:Membership"
Expand Down Expand Up @@ -156,7 +156,7 @@ configuration:
strictMode: false
policies:
- permission:
- action: "USE"
- action: "odrl:use"
logicalConstraint: "odrl:and"
constraints:
- leftOperand: "cx-policy:Membership"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,7 @@ void saveTransferRequestAndTransfer() {
transferRequest.setProtocol("HTTP");
transferRequest.setContractId(contractId);
transferRequest.setAssetId(assetId);
transferRequest.setConnectorAddress("connectorAddress");
transferRequest.setCounterPartyAddress("connectorAddress");

String transferId = UUID.randomUUID().toString();
Transfer transfer = new Transfer();
Expand Down
Loading
Loading