Skip to content

Commit

Permalink
feat: extend UiPolicy from only constraints to expressions (#988)
Browse files Browse the repository at this point in the history
Co-authored-by: Richard Treier <richard.treier@sovity.de>
  • Loading branch information
illfixit and richardtreier authored Jul 19, 2024
1 parent a78b169 commit f62d976
Show file tree
Hide file tree
Showing 59 changed files with 1,624 additions and 1,237 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ please see [changelog_updates.md](docs/dev/changelog_updates.md).

#### Major Changes

- The `UiPolicy` model has been adjusted to support complex expressions including `AND`, `OR` and `XONE`.
- The `createPolicyDefinition` has been marked as deprecated in favor of the new `createPolicyDefinitionV2` endpoint that supports complex policies.
- Removed the recently rushed `createPolicyDefinitionUseCase` endpoint in favor of the new `createPolicyDefinitionV2` endpoint.

#### Minor Changes

- Both providers and consumers can now terminate their contracts.
Expand Down
194 changes: 88 additions & 106 deletions docs/api/sovity-edc-api-wrapper.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,8 @@ paths:
post:
tags:
- UI
description: Create a new Policy Definition
description: "[Deprecated] Create a new Policy Definition from a list of constraints.\
\ Use createPolicyDefinitionV2 instead."
operationId: createPolicyDefinition
requestBody:
content:
Expand All @@ -135,6 +136,25 @@ paths:
application/json:
schema:
$ref: '#/components/schemas/IdResponseDto'
deprecated: true
/wrapper/ui/v2/pages/policy-page/policy-definitions:
post:
tags:
- UI
description: Create a new Policy Definition
operationId: createPolicyDefinitionV2
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/PolicyDefinitionCreateDto'
responses:
default:
description: default response
content:
application/json:
schema:
$ref: '#/components/schemas/IdResponseDto'
/wrapper/ui/pages/asset-page/assets/{assetId}:
put:
tags:
Expand Down Expand Up @@ -495,24 +515,6 @@ paths:
application/json:
schema:
$ref: '#/components/schemas/IdResponseDto'
/wrapper/use-case-api/policy-definition:
post:
tags:
- Use Case
description: Create a new Policy Definition
operationId: createPolicyDefinitionUseCase
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/PolicyCreateRequest'
responses:
default:
description: default response
content:
application/json:
schema:
$ref: '#/components/schemas/IdResponseDto'
/wrapper/use-case-api/kpis:
get:
tags:
Expand Down Expand Up @@ -582,11 +584,11 @@ components:
DataSourceType:
type: string
description: Supported Data Source Types by UiDataSource
default: CUSTOM
enum:
- HTTP_DATA
- ON_REQUEST
- CUSTOM
default: CUSTOM
SecretValue:
type: object
properties:
Expand Down Expand Up @@ -719,8 +721,8 @@ components:
type: string
description: Same as customJsonLdAsString but the data will be stored in
the private properties. The same limitations apply.
description: Type-Safe OpenAPI generator friendly Asset Create DTO that supports
an opinionated subset of the original EDC Asset Entity.
description: Type-safe data offer metadata for creating an asset as supported
by the sovity product landscape. Contains extension points.
UiDataSource:
required:
- type
Expand All @@ -738,8 +740,8 @@ components:
type: string
description: For all types. Custom Data Address Properties.
description: For all types. Custom Data Address Properties.
description: Data Offer Data Source Model. Supports certain Data Address types
but also leaves a backdoor for custom Data Address Properties.
description: Type-safe data source as supported by the sovity product landscape.
Contains extension points for using custom data address properties.
UiDataSourceHttpData:
required:
- baseUrl
Expand Down Expand Up @@ -790,18 +792,18 @@ components:
\ both a request body and a content type. Only Methods POST, PUT and PATCH\
\ allow request bodies."
default: false
description: Only for type HTTP_DATA
description: HTTP_DATA type Data Source.
UiDataSourceHttpDataMethod:
type: string
description: Supported HTTP Methods by UiDataSource
default: GET
enum:
- GET
- POST
- PUT
- PATCH
- DELETE
- OPTIONS
default: GET
UiDataSourceOnRequest:
required:
- contactEmail
Expand Down Expand Up @@ -899,7 +901,8 @@ components:
- LIKE
OperatorDto:
type: string
description: Operator for policies
description: Type-Safe ODRL Policy Operator as supported by the sovity product
landscape
enum:
- EQ
- NEQ
Expand All @@ -924,7 +927,8 @@ components:
description: Policy Definition ID
policy:
$ref: '#/components/schemas/UiPolicyCreateRequest'
description: Data for creating a Policy Definition
description: "[Deprecated] Create a Policy Definition. Use PolicyDefinitionCreateDto"
deprecated: true
UiPolicyConstraint:
required:
- left
Expand All @@ -939,18 +943,19 @@ components:
$ref: '#/components/schemas/OperatorDto'
right:
$ref: '#/components/schemas/UiPolicyLiteral'
description: ODRL AtomicConstraint as supported by our UI
description: "ODRL AtomicConstraint as supported by the sovity product landscape.\
\ For example 'a EQ b', 'c IN [d, e, f]'"
UiPolicyCreateRequest:
type: object
properties:
constraints:
type: array
description: Conjunction of required expressions for the policy to evaluate
to TRUE.
description: Conjunction of required constraints
deprecated: true
items:
$ref: '#/components/schemas/UiPolicyConstraint'
description: Type-Safe OpenAPI generator friendly Policy Create DTO that supports
an opinionated subset of the original EDC Policy Entity.
description: "[Deprecated] Conjunction of constraints (simplified UiPolicyExpression)"
deprecated: true
UiPolicyLiteral:
required:
- type
Expand All @@ -975,6 +980,48 @@ components:
- STRING
- STRING_LIST
- JSON
PolicyDefinitionCreateDto:
required:
- expression
- policyDefinitionId
type: object
properties:
policyDefinitionId:
type: string
description: Policy Definition ID
expression:
$ref: '#/components/schemas/UiPolicyExpression'
description: Create a Policy Definition
UiPolicyExpression:
required:
- type
type: object
properties:
type:
$ref: '#/components/schemas/UiPolicyExpressionType'
expressions:
type: array
description: "Only for types AND, OR, XONE. List of sub-expressions to be\
\ evaluated according to the expressionType."
items:
$ref: '#/components/schemas/UiPolicyExpression'
constraint:
$ref: '#/components/schemas/UiPolicyConstraint'
description: ODRL constraint as supported by the sovity product landscape
UiPolicyExpressionType:
type: string
description: |
Ui Policy Expression types:
* `CONSTRAINT` - Expression 'a=b'
* `AND` - Conjunction of several expressions. Evaluates to true iff all child expressions are true.
* `OR` - Disjunction of several expressions. Evaluates to true iff at least one child expression is true.
* `XONE` - XONE operation. Evaluates to true iff exactly one child expression is true.
enum:
- EMPTY
- CONSTRAINT
- AND
- OR
- XONE
UiAssetEditRequest:
type: object
properties:
Expand Down Expand Up @@ -1087,7 +1134,8 @@ components:
type: string
description: Same as customJsonLdAsString but the data will be stored in
the private properties. The same limitations apply.
description: Data for editing an asset.
description: Type-safe data offer metadata for editing an asset as supported
by the sovity product landscape. Contains extension points.
AssetPage:
required:
- assets
Expand Down Expand Up @@ -1274,7 +1322,8 @@ components:
type: string
description: Same as customJsonLdAsString but the data will be stored in
the private properties. The same limitations apply.
description: Type-Safe Asset Metadata as needed by our UI
description: Type-safe data offer metadata as supported by the sovity product
landscape. Contains extension points.
UiContractOffer:
required:
- contractOfferId
Expand Down Expand Up @@ -1319,12 +1368,8 @@ components:
type: string
description: EDC Policy JSON-LD. This is required because the EDC requires
the full policy when initiating contract negotiations.
constraints:
type: array
description: Conjunction of required expressions for the policy to evaluate
to TRUE.
items:
$ref: '#/components/schemas/UiPolicyConstraint'
expression:
$ref: '#/components/schemas/UiPolicyExpression'
errors:
type: array
description: "When trying to reduce the policy JSON-LD to our opinionated\
Expand All @@ -1337,8 +1382,8 @@ components:
\ subset of functionalities, many fields and functionalities are unsupported.\
\ Should any discrepancies occur during the mapping process, we'll collect\
\ them here."
description: Type-Safe OpenAPI generator friendly Policy DTO as needed by our
UI
description: Type-Safe OpenAPI generator friendly ODLR policy subset as endorsed
by sovity.
ContractAgreementCard:
required:
- asset
Expand Down Expand Up @@ -1872,69 +1917,6 @@ components:
type: string
description: A short reason why this contract was terminated
description: Data for terminating a Contract Agreement
AtomicConstraintDto:
required:
- leftExpression
- operator
- rightExpression
type: object
properties:
leftExpression:
type: string
description: Left part of the constraint.
operator:
$ref: '#/components/schemas/OperatorDto'
rightExpression:
type: string
description: Right part of the constraint.
description: Type-Safe OpenAPI generator friendly Constraint DTO that supports
an opinionated subset of the original EDC Constraint Entity.
Expression:
type: object
properties:
expressionType:
$ref: '#/components/schemas/ExpressionType'
expressions:
type: array
description: List of policy elements that are evaluated according the expressionType.
items:
$ref: '#/components/schemas/Expression'
atomicConstraint:
$ref: '#/components/schemas/AtomicConstraintDto'
description: Represents a single atomic constraint or a multiplicity constraint.
The atomicConstraint will be evaluated if the constraintType is ATOMIC_CONSTRAINT.
ExpressionType:
type: string
description: |
Expression types:
* `ATOMIC_CONSTRAINT` - A single constraint for the policy
* `AND` - Several constraints, all of which must be respected
* `OR` - Several constraints, of which at least one must be respected
* `XOR` - Several constraints, of which exactly one must be respected
enum:
- ATOMIC_CONSTRAINT
- AND
- OR
- XOR
PermissionDto:
required:
- expression
type: object
properties:
expression:
$ref: '#/components/schemas/Expression'
description: Permission description for the policy to evaluate to TRUE.
PolicyCreateRequest:
required:
- policyDefinitionId
type: object
properties:
policyDefinitionId:
type: string
description: Policy Definition ID
permission:
$ref: '#/components/schemas/PermissionDto'
description: Policy Creation Request Supporting Multiplicity Constraints.
KpiResult:
required:
- assetsCount
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import de.sovity.edc.client.gen.model.ContractDefinitionRequest;
import de.sovity.edc.client.gen.model.DataSourceType;
import de.sovity.edc.client.gen.model.OperatorDto;
import de.sovity.edc.client.gen.model.PolicyDefinitionCreateRequest;
import de.sovity.edc.client.gen.model.PolicyDefinitionCreateDto;
import de.sovity.edc.client.gen.model.UiAssetCreateRequest;
import de.sovity.edc.client.gen.model.UiCriterion;
import de.sovity.edc.client.gen.model.UiCriterionLiteral;
Expand All @@ -27,7 +27,8 @@
import de.sovity.edc.client.gen.model.UiDataSource;
import de.sovity.edc.client.gen.model.UiDataSourceHttpData;
import de.sovity.edc.client.gen.model.UiPolicyConstraint;
import de.sovity.edc.client.gen.model.UiPolicyCreateRequest;
import de.sovity.edc.client.gen.model.UiPolicyExpression;
import de.sovity.edc.client.gen.model.UiPolicyExpressionType;
import de.sovity.edc.client.gen.model.UiPolicyLiteral;
import de.sovity.edc.client.gen.model.UiPolicyLiteralType;
import de.sovity.edc.ext.catalog.crawler.dao.connectors.ConnectorRef;
Expand All @@ -49,6 +50,7 @@
import java.util.List;
import java.util.concurrent.TimeUnit;
import java.util.function.Consumer;
import java.util.stream.Stream;

import static de.sovity.edc.extension.e2e.connector.config.ConnectorConfigFactory.forTestDatabase;
import static de.sovity.edc.extension.e2e.connector.config.ConnectorConfigFactory.getFreePortRange;
Expand Down Expand Up @@ -191,14 +193,22 @@ private void createPolicy() {
.build())
.build();

var policyDefinition = PolicyDefinitionCreateRequest.builder()
var expression = UiPolicyExpression.builder()
.type(UiPolicyExpressionType.AND)
.expressions(Stream.of(afterYesterday, beforeTomorrow)
.map(it -> UiPolicyExpression.builder()
.type(UiPolicyExpressionType.CONSTRAINT)
.constraint(it)
.build())
.toList())
.build();

var policyDefinition = PolicyDefinitionCreateDto.builder()
.policyDefinitionId(dataOfferId)
.policy(UiPolicyCreateRequest.builder()
.constraints(List.of(afterYesterday, beforeTomorrow))
.build())
.expression(expression)
.build();

connectorClient.uiApi().createPolicyDefinition(policyDefinition);
connectorClient.uiApi().createPolicyDefinitionV2(policyDefinition);
}

private void createContractDefinition() {
Expand Down
Loading

0 comments on commit f62d976

Please sign in to comment.