From b4d648ad7511c61fa044fa143adee9c5fa9f759e Mon Sep 17 00:00:00 2001 From: illfixit <66363651+illfixit@users.noreply.github.com> Date: Wed, 3 Jul 2024 12:03:56 +0200 Subject: [PATCH 01/18] feat: base --- .../common/model/UiPolicyCreateRequest.java | 2 +- .../api/common/model/UiPolicyExpression.java | 35 ++++++++ .../common/model/UiPolicyExpressionType.java | 16 ++++ .../api/common/mappers/PolicyMapper.java | 84 +++++++++++-------- .../policy/AtomicConstraintMapper.java | 2 +- 5 files changed, 104 insertions(+), 35 deletions(-) create mode 100644 extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiPolicyExpression.java create mode 100644 extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiPolicyExpressionType.java diff --git a/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiPolicyCreateRequest.java b/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiPolicyCreateRequest.java index b1f18465a..9db57ae2a 100644 --- a/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiPolicyCreateRequest.java +++ b/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiPolicyCreateRequest.java @@ -32,5 +32,5 @@ + " subset of the original EDC Policy Entity.") public class UiPolicyCreateRequest { @Schema(description = "Conjunction of required expressions for the policy to evaluate to TRUE.") - private List constraints; + private List expressions; } diff --git a/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiPolicyExpression.java b/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiPolicyExpression.java new file mode 100644 index 000000000..5c5b4a84c --- /dev/null +++ b/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiPolicyExpression.java @@ -0,0 +1,35 @@ +package de.sovity.edc.ext.wrapper.api.common.model; + +import com.fasterxml.jackson.annotation.JsonInclude; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.RequiredArgsConstructor; + +import java.util.List; + + +@Data +@AllArgsConstructor +@RequiredArgsConstructor +@Builder(toBuilder = true) +@JsonInclude(JsonInclude.Include.NON_NULL) +@Schema(description = + "Represents a single Ui Policy Literal or a List of Ui Policy Expressions. The Literal" + + " will be evaluated if the expressionType is LITERAL.") +public class UiPolicyExpression { + + @Schema(description = "Either LITERAL or one of the constraint types.") + private UiPolicyExpressionType expressionType; + + @Schema(description = + "List of policy elements that are evaluated according the expressionType.") + private List expressions; + + @Schema(description = + "A single literal. Will be evaluated if the expressionType is set to " + + "LITERAL.") + private UiPolicyConstraint constraint; + +} diff --git a/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiPolicyExpressionType.java b/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiPolicyExpressionType.java new file mode 100644 index 000000000..618cc4a28 --- /dev/null +++ b/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiPolicyExpressionType.java @@ -0,0 +1,16 @@ +package de.sovity.edc.ext.wrapper.api.common.model; + +import io.swagger.v3.oas.annotations.media.Schema; + +@Schema(description = """ + Ui Policy Expression types: + * `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 + * `CONSTRAINT` - A single constraint for the policy + """, enumAsRef = true) +public enum UiPolicyExpressionType { + AND, OR, XOR, CONSTRAINT +} + + diff --git a/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/PolicyMapper.java b/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/PolicyMapper.java index 78f4fcb4d..fc4eb281d 100644 --- a/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/PolicyMapper.java +++ b/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/PolicyMapper.java @@ -19,15 +19,14 @@ import de.sovity.edc.ext.wrapper.api.common.mappers.asset.utils.FailedMappingException; import de.sovity.edc.ext.wrapper.api.common.mappers.policy.MappingErrors; import de.sovity.edc.ext.wrapper.api.common.mappers.policy.PolicyValidator; -import de.sovity.edc.ext.wrapper.api.common.model.Expression; -import de.sovity.edc.ext.wrapper.api.common.model.UiPolicy; -import de.sovity.edc.ext.wrapper.api.common.model.UiPolicyCreateRequest; +import de.sovity.edc.ext.wrapper.api.common.model.*; import de.sovity.edc.utils.JsonUtils; import de.sovity.edc.utils.jsonld.vocab.Prop; import jakarta.json.JsonObject; import lombok.RequiredArgsConstructor; import org.eclipse.edc.policy.model.Action; import org.eclipse.edc.policy.model.AndConstraint; +import org.eclipse.edc.policy.model.AtomicConstraint; import org.eclipse.edc.policy.model.Constraint; import org.eclipse.edc.policy.model.OrConstraint; import org.eclipse.edc.policy.model.Permission; @@ -62,10 +61,10 @@ public UiPolicy buildUiPolicy(Policy policy) { var constraints = constraintExtractor.getPermissionConstraints(policy, errors); return UiPolicy.builder() - .policyJsonLd(toJson(buildPolicyJsonLd(policy))) - .constraints(constraints) - .errors(errors.getErrors()) - .build(); + .policyJsonLd(toJson(buildPolicyJsonLd(policy))) + .constraints(constraints) + .errors(errors.getErrors()) + .build(); } /** @@ -77,57 +76,76 @@ public UiPolicy buildUiPolicy(Policy policy) { * @return ODRL policy */ public Policy buildPolicy(UiPolicyCreateRequest policyCreateDto) { - var constraints = new ArrayList(atomicConstraintMapper.buildAtomicConstraints( - policyCreateDto.getConstraints())); + var constraints = convertExpressionsToConstraints(policyCreateDto.getExpressions()); var action = Action.Builder.newInstance().type(PolicyValidator.ALLOWED_ACTION).build(); var permission = Permission.Builder.newInstance() - .action(action) - .constraints(constraints) - .build(); + .action(action) + .constraints(constraints) + .build(); return Policy.Builder.newInstance() - .type(PolicyType.SET) - .permission(permission) - .build(); + .type(PolicyType.SET) + .permission(permission) + .build(); } public Policy buildPolicy(List constraintElements) { var constraints = buildConstraints(constraintElements); var action = Action.Builder.newInstance().type(Prop.Odrl.USE).build(); var permission = Permission.Builder.newInstance() - .action(action) - .constraints(constraints) - .build(); + .action(action) + .constraints(constraints) + .build(); return Policy.Builder.newInstance() - .type(PolicyType.SET) - .permission(permission) - .build(); + .type(PolicyType.SET) + .permission(permission) + .build(); } @NotNull private List buildConstraints(List expressions) { return expressions.stream() - .map(this::buildConstraint) - .toList(); + .map(this::buildConstraint) + .toList(); } private Constraint buildConstraint(Expression expression) { var subExpressions = expression.getExpressions(); return switch (expression.getExpressionType()) { - case ATOMIC_CONSTRAINT -> - atomicConstraintMapper.buildAtomicConstraint(expression.getAtomicConstraint()); + case ATOMIC_CONSTRAINT -> atomicConstraintMapper.buildAtomicConstraint(expression.getAtomicConstraint()); case AND -> AndConstraint.Builder.newInstance() - .constraints(buildConstraints(subExpressions)) - .build(); + .constraints(buildConstraints(subExpressions)) + .build(); case OR -> OrConstraint.Builder.newInstance() - .constraints(buildConstraints(subExpressions)) - .build(); + .constraints(buildConstraints(subExpressions)) + .build(); case XOR -> XoneConstraint.Builder.newInstance() - .constraints(buildConstraints(subExpressions)) - .build(); + .constraints(buildConstraints(subExpressions)) + .build(); + }; + } + + private List convertExpressionsToConstraints(List expressions) { + return expressions.stream() + .map(this::convertExpressionToConstraint) + .toList(); + } + + private Constraint convertExpressionToConstraint(UiPolicyExpression expression) { + return switch (expression.getExpressionType()) { + case CONSTRAINT -> atomicConstraintMapper.buildAtomicConstraint(expression.getConstraint()); + case AND -> AndConstraint.Builder.newInstance() + .constraints(convertExpressionsToConstraints(expression.getExpressions())) + .build(); + case OR -> OrConstraint.Builder.newInstance() + .constraints(convertExpressionsToConstraints(expression.getExpressions())) + .build(); + case XOR -> XoneConstraint.Builder.newInstance() + .constraints(convertExpressionsToConstraints(expression.getExpressions())) + .build(); }; } @@ -141,7 +159,7 @@ private Constraint buildConstraint(Expression expression) { */ public Policy buildPolicy(JsonObject policyJsonLd) { return typeTransformerRegistry.transform(policyJsonLd, Policy.class) - .orElseThrow(FailedMappingException::ofFailure); + .orElseThrow(FailedMappingException::ofFailure); } /** @@ -166,6 +184,6 @@ public Policy buildPolicy(String policyJsonLd) { */ public JsonObject buildPolicyJsonLd(Policy policy) { return typeTransformerRegistry.transform(policy, JsonObject.class) - .orElseThrow(FailedMappingException::ofFailure); + .orElseThrow(FailedMappingException::ofFailure); } } diff --git a/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/policy/AtomicConstraintMapper.java b/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/policy/AtomicConstraintMapper.java index 47c75f218..2899170a9 100644 --- a/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/policy/AtomicConstraintMapper.java +++ b/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/policy/AtomicConstraintMapper.java @@ -93,7 +93,7 @@ private Optional getOperator(AtomicConstraint atomicConstraint, Map return Optional.of(operatorMapper.getOperatorDto(operator)); } - private AtomicConstraint buildAtomicConstraint(UiPolicyConstraint constraint) { + public AtomicConstraint buildAtomicConstraint(UiPolicyConstraint constraint) { var left = constraint.getLeft(); var operator = operatorMapper.getOperator(constraint.getOperator()); var right = literalMapper.getUiLiteralValue(constraint.getRight()); From 4e17b03a01aaca4166d04ae523b063f7e0675b2c Mon Sep 17 00:00:00 2001 From: Richard Treier Date: Wed, 10 Jul 2024 15:21:52 +0300 Subject: [PATCH 02/18] chore: apply new indentation on common-mappers and common-api --- .../api/common/model/AtomicConstraintDto.java | 10 ++--- .../wrapper/api/common/model/Expression.java | 10 ++--- .../api/common/model/ExpressionType.java | 12 +++--- .../api/common/model/PermissionDto.java | 2 +- .../ext/wrapper/api/common/model/UiAsset.java | 16 ++++---- .../api/common/model/UiAssetEditRequest.java | 16 ++++---- .../model/UiDataSourceHttpDataMethod.java | 2 +- .../wrapper/api/common/model/UiPolicy.java | 6 +-- .../common/model/UiPolicyCreateRequest.java | 2 +- .../api/common/model/UiPolicyExpression.java | 4 +- .../common/model/UiPolicyExpressionType.java | 12 +++--- .../api/common/model/UiPolicyLiteral.java | 18 ++++----- .../api/common/mappers/AssetMapper.java | 2 +- .../api/common/mappers/PolicyMapper.java | 9 +++-- .../mappers/asset/AssetEditRequestMapper.java | 2 +- .../mappers/asset/AssetJsonLdParser.java | 2 +- .../mappers/asset/utils/JsonBuilderUtils.java | 4 +- .../dataaddress/http/HttpHeaderMapper.java | 2 +- .../policy/AtomicConstraintMapper.java | 39 +++++++++---------- .../common/mappers/policy/LiteralMapper.java | 17 ++++---- .../mappers/policy/PolicyValidator.java | 1 - 21 files changed, 93 insertions(+), 95 deletions(-) diff --git a/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/AtomicConstraintDto.java b/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/AtomicConstraintDto.java index 560f93ce2..0e8ed7b77 100644 --- a/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/AtomicConstraintDto.java +++ b/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/AtomicConstraintDto.java @@ -27,17 +27,17 @@ @Builder(toBuilder = true) @JsonInclude(JsonInclude.Include.NON_NULL) @Schema(description = - "Type-Safe OpenAPI generator friendly Constraint DTO that supports an opinionated" - + " subset of the original EDC Constraint Entity.") + "Type-Safe OpenAPI generator friendly Constraint DTO that supports an opinionated" + + " subset of the original EDC Constraint Entity.") public class AtomicConstraintDto { @Schema(description = "Left part of the constraint.", - requiredMode = Schema.RequiredMode.REQUIRED) + requiredMode = Schema.RequiredMode.REQUIRED) private String leftExpression; @Schema(description = "Operator to connect both parts of the constraint.", - requiredMode = Schema.RequiredMode.REQUIRED) + requiredMode = Schema.RequiredMode.REQUIRED) private OperatorDto operator; @Schema(description = "Right part of the constraint.", - requiredMode = Schema.RequiredMode.REQUIRED) + requiredMode = Schema.RequiredMode.REQUIRED) private String rightExpression; } diff --git a/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/Expression.java b/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/Expression.java index 9fc30e0de..148f34a4f 100644 --- a/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/Expression.java +++ b/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/Expression.java @@ -29,19 +29,19 @@ @Builder(toBuilder = true) @JsonInclude(JsonInclude.Include.NON_NULL) @Schema(description = - "Represents a single atomic constraint or a multiplicity constraint. The atomicConstraint" + - " will be evaluated if the constraintType is ATOMIC_CONSTRAINT.") + "Represents a single atomic constraint or a multiplicity constraint. The atomicConstraint" + + " will be evaluated if the constraintType is ATOMIC_CONSTRAINT.") public class Expression { @Schema(description = "Either ATOMIC_CONSTRAINT or one of the multiplicity constraint types.") private ExpressionType expressionType; @Schema(description = - "List of policy elements that are evaluated according the expressionType.") + "List of policy elements that are evaluated according the expressionType.") private List expressions; @Schema(description = - "A single atomic constraint. Will be evaluated if the expressionType is set to " + - "ATOMIC_CONSTRAINT.") + "A single atomic constraint. Will be evaluated if the expressionType is set to " + + "ATOMIC_CONSTRAINT.") private AtomicConstraintDto atomicConstraint; } diff --git a/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/ExpressionType.java b/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/ExpressionType.java index 33e21f83f..910c82a88 100644 --- a/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/ExpressionType.java +++ b/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/ExpressionType.java @@ -6,12 +6,12 @@ * Sum type enum. */ @Schema(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 - """, enumAsRef = true) + 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 + """, enumAsRef = true) public enum ExpressionType { ATOMIC_CONSTRAINT, AND, OR, XOR } diff --git a/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/PermissionDto.java b/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/PermissionDto.java index 5c107ab29..93f48747b 100644 --- a/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/PermissionDto.java +++ b/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/PermissionDto.java @@ -30,6 +30,6 @@ public class PermissionDto { @Schema(description = "Possible constraints for the permission", - requiredMode = RequiredMode.REQUIRED) + requiredMode = RequiredMode.REQUIRED) private Expression expression; } diff --git a/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiAsset.java b/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiAsset.java index bf28fc1a9..9cc06b818 100644 --- a/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiAsset.java +++ b/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiAsset.java @@ -170,22 +170,22 @@ public class UiAsset { private String assetJsonLd; @Schema(description = "Contains serialized custom properties in the JSON format.", - requiredMode = Schema.RequiredMode.NOT_REQUIRED) + requiredMode = Schema.RequiredMode.NOT_REQUIRED) private String customJsonAsString; @Schema(description = "Contains serialized custom properties in the JSON LD format. " + - "Contrary to the customJsonAsString field, this string must represent a JSON LD object " + - "and will be affected by JSON LD compaction and expansion. " + - "Due to a technical limitation, the properties can't be booleans.", - requiredMode = Schema.RequiredMode.NOT_REQUIRED) + "Contrary to the customJsonAsString field, this string must represent a JSON LD object " + + "and will be affected by JSON LD compaction and expansion. " + + "Due to a technical limitation, the properties can't be booleans.", + requiredMode = Schema.RequiredMode.NOT_REQUIRED) private String customJsonLdAsString; @Schema(description = "Same as customJsonAsString but the data will be stored in the private properties.", - requiredMode = Schema.RequiredMode.NOT_REQUIRED) + requiredMode = Schema.RequiredMode.NOT_REQUIRED) private String privateCustomJsonAsString; @Schema(description = "Same as customJsonLdAsString but the data will be stored in the private properties. " + - "The same limitations apply.", - requiredMode = Schema.RequiredMode.NOT_REQUIRED) + "The same limitations apply.", + requiredMode = Schema.RequiredMode.NOT_REQUIRED) private String privateCustomJsonLdAsString; } diff --git a/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiAssetEditRequest.java b/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiAssetEditRequest.java index 87257c694..6cee639b3 100644 --- a/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiAssetEditRequest.java +++ b/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiAssetEditRequest.java @@ -107,22 +107,22 @@ public class UiAssetEditRequest { private LocalDate temporalCoverageToInclusive; @Schema(description = "Contains serialized custom properties in the JSON format.", - requiredMode = Schema.RequiredMode.NOT_REQUIRED) + requiredMode = Schema.RequiredMode.NOT_REQUIRED) private String customJsonAsString; @Schema(description = "Contains serialized custom properties in the JSON LD format. " + - "Contrary to the customJsonAsString field, this string must represent a JSON LD object " + - "and will be affected by JSON LD compaction and expansion. " + - "Due to a technical limitation, the properties can't be booleans.", - requiredMode = Schema.RequiredMode.NOT_REQUIRED) + "Contrary to the customJsonAsString field, this string must represent a JSON LD object " + + "and will be affected by JSON LD compaction and expansion. " + + "Due to a technical limitation, the properties can't be booleans.", + requiredMode = Schema.RequiredMode.NOT_REQUIRED) private String customJsonLdAsString; @Schema(description = "Same as customJsonAsString but the data will be stored in the private properties.", - requiredMode = Schema.RequiredMode.NOT_REQUIRED) + requiredMode = Schema.RequiredMode.NOT_REQUIRED) private String privateCustomJsonAsString; @Schema(description = "Same as customJsonLdAsString but the data will be stored in the private properties. " + - "The same limitations apply.", - requiredMode = Schema.RequiredMode.NOT_REQUIRED) + "The same limitations apply.", + requiredMode = Schema.RequiredMode.NOT_REQUIRED) private String privateCustomJsonLdAsString; } diff --git a/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiDataSourceHttpDataMethod.java b/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiDataSourceHttpDataMethod.java index 0244a47ab..013848562 100644 --- a/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiDataSourceHttpDataMethod.java +++ b/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiDataSourceHttpDataMethod.java @@ -11,7 +11,7 @@ * sovity GmbH - initial API and implementation * */ - + package de.sovity.edc.ext.wrapper.api.common.model; import io.swagger.v3.oas.annotations.media.Schema; diff --git a/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiPolicy.java b/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiPolicy.java index 4118c7434..77d018aa0 100644 --- a/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiPolicy.java +++ b/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiPolicy.java @@ -32,14 +32,14 @@ @Schema(description = "Type-Safe OpenAPI generator friendly Policy DTO as needed by our UI") public class UiPolicy { @Schema(description = "EDC Policy JSON-LD. This is required because the EDC requires the " + - "full policy when initiating contract negotiations.", requiredMode = RequiredMode.REQUIRED) + "full policy when initiating contract negotiations.", requiredMode = RequiredMode.REQUIRED) private String policyJsonLd; @Schema(description = "Conjunction of required expressions for the policy to evaluate to TRUE.") private List constraints; @Schema(description = "When trying to reduce the policy JSON-LD to our opinionated subset of functionalities, " + - "many fields and functionalities are unsupported. Should any discrepancies occur during " + - "the mapping process, we'll collect them here.", requiredMode = RequiredMode.REQUIRED) + "many fields and functionalities are unsupported. Should any discrepancies occur during " + + "the mapping process, we'll collect them here.", requiredMode = RequiredMode.REQUIRED) private List errors; } diff --git a/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiPolicyCreateRequest.java b/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiPolicyCreateRequest.java index 9db57ae2a..2e2907884 100644 --- a/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiPolicyCreateRequest.java +++ b/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiPolicyCreateRequest.java @@ -29,7 +29,7 @@ @Builder(toBuilder = true) @JsonInclude(JsonInclude.Include.NON_NULL) @Schema(description = "Type-Safe OpenAPI generator friendly Policy Create DTO that supports an opinionated" - + " subset of the original EDC Policy Entity.") + + " subset of the original EDC Policy Entity.") public class UiPolicyCreateRequest { @Schema(description = "Conjunction of required expressions for the policy to evaluate to TRUE.") private List expressions; diff --git a/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiPolicyExpression.java b/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiPolicyExpression.java index 5c5b4a84c..ea1107f68 100644 --- a/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiPolicyExpression.java +++ b/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiPolicyExpression.java @@ -17,7 +17,7 @@ @JsonInclude(JsonInclude.Include.NON_NULL) @Schema(description = "Represents a single Ui Policy Literal or a List of Ui Policy Expressions. The Literal" + - " will be evaluated if the expressionType is LITERAL.") + " will be evaluated if the expressionType is LITERAL.") public class UiPolicyExpression { @Schema(description = "Either LITERAL or one of the constraint types.") @@ -29,7 +29,7 @@ public class UiPolicyExpression { @Schema(description = "A single literal. Will be evaluated if the expressionType is set to " + - "LITERAL.") + "LITERAL.") private UiPolicyConstraint constraint; } diff --git a/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiPolicyExpressionType.java b/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiPolicyExpressionType.java index 618cc4a28..ae374a8c5 100644 --- a/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiPolicyExpressionType.java +++ b/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiPolicyExpressionType.java @@ -3,12 +3,12 @@ import io.swagger.v3.oas.annotations.media.Schema; @Schema(description = """ - Ui Policy Expression types: - * `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 - * `CONSTRAINT` - A single constraint for the policy - """, enumAsRef = true) + Ui Policy Expression types: + * `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 + * `CONSTRAINT` - A single constraint for the policy + """, enumAsRef = true) public enum UiPolicyExpressionType { AND, OR, XOR, CONSTRAINT } diff --git a/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiPolicyLiteral.java b/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiPolicyLiteral.java index 7cb251703..08176e9ae 100644 --- a/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiPolicyLiteral.java +++ b/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiPolicyLiteral.java @@ -45,22 +45,22 @@ public class UiPolicyLiteral { public static UiPolicyLiteral ofString(String string) { return UiPolicyLiteral.builder() - .type(UiPolicyLiteralType.STRING) - .value(string) - .build(); + .type(UiPolicyLiteralType.STRING) + .value(string) + .build(); } public static UiPolicyLiteral ofJson(String jsonString) { return UiPolicyLiteral.builder() - .type(UiPolicyLiteralType.JSON) - .value(jsonString) - .build(); + .type(UiPolicyLiteralType.JSON) + .value(jsonString) + .build(); } public static UiPolicyLiteral ofStringList(Collection strings) { return UiPolicyLiteral.builder() - .type(UiPolicyLiteralType.STRING_LIST) - .valueList(new ArrayList<>(strings)) - .build(); + .type(UiPolicyLiteralType.STRING_LIST) + .valueList(new ArrayList<>(strings)) + .build(); } } diff --git a/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/AssetMapper.java b/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/AssetMapper.java index 03c45f5af..4ac252075 100644 --- a/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/AssetMapper.java +++ b/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/AssetMapper.java @@ -11,7 +11,7 @@ * sovity GmbH - initial API and implementation * */ - + package de.sovity.edc.ext.wrapper.api.common.mappers; import de.sovity.edc.ext.wrapper.api.common.mappers.asset.AssetJsonLdBuilder; diff --git a/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/PolicyMapper.java b/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/PolicyMapper.java index fc4eb281d..5d303892c 100644 --- a/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/PolicyMapper.java +++ b/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/PolicyMapper.java @@ -14,19 +14,21 @@ package de.sovity.edc.ext.wrapper.api.common.mappers; +import de.sovity.edc.ext.wrapper.api.common.mappers.asset.utils.FailedMappingException; import de.sovity.edc.ext.wrapper.api.common.mappers.policy.AtomicConstraintMapper; import de.sovity.edc.ext.wrapper.api.common.mappers.policy.ConstraintExtractor; -import de.sovity.edc.ext.wrapper.api.common.mappers.asset.utils.FailedMappingException; import de.sovity.edc.ext.wrapper.api.common.mappers.policy.MappingErrors; import de.sovity.edc.ext.wrapper.api.common.mappers.policy.PolicyValidator; -import de.sovity.edc.ext.wrapper.api.common.model.*; +import de.sovity.edc.ext.wrapper.api.common.model.Expression; +import de.sovity.edc.ext.wrapper.api.common.model.UiPolicy; +import de.sovity.edc.ext.wrapper.api.common.model.UiPolicyCreateRequest; +import de.sovity.edc.ext.wrapper.api.common.model.UiPolicyExpression; import de.sovity.edc.utils.JsonUtils; import de.sovity.edc.utils.jsonld.vocab.Prop; import jakarta.json.JsonObject; import lombok.RequiredArgsConstructor; import org.eclipse.edc.policy.model.Action; import org.eclipse.edc.policy.model.AndConstraint; -import org.eclipse.edc.policy.model.AtomicConstraint; import org.eclipse.edc.policy.model.Constraint; import org.eclipse.edc.policy.model.OrConstraint; import org.eclipse.edc.policy.model.Permission; @@ -36,7 +38,6 @@ import org.eclipse.edc.transform.spi.TypeTransformerRegistry; import org.jetbrains.annotations.NotNull; -import java.util.ArrayList; import java.util.List; import static de.sovity.edc.utils.JsonUtils.toJson; diff --git a/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/asset/AssetEditRequestMapper.java b/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/asset/AssetEditRequestMapper.java index 3ad1344e5..c65fe5243 100644 --- a/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/asset/AssetEditRequestMapper.java +++ b/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/asset/AssetEditRequestMapper.java @@ -14,10 +14,10 @@ package de.sovity.edc.ext.wrapper.api.common.mappers.asset; +import de.sovity.edc.ext.wrapper.api.common.model.DataSourceType; import de.sovity.edc.ext.wrapper.api.common.model.UiAssetCreateRequest; import de.sovity.edc.ext.wrapper.api.common.model.UiAssetEditRequest; import de.sovity.edc.ext.wrapper.api.common.model.UiDataSource; -import de.sovity.edc.ext.wrapper.api.common.model.DataSourceType; import lombok.NonNull; import lombok.RequiredArgsConstructor; diff --git a/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/asset/AssetJsonLdParser.java b/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/asset/AssetJsonLdParser.java index 84050b94b..aa74994f2 100644 --- a/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/asset/AssetJsonLdParser.java +++ b/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/asset/AssetJsonLdParser.java @@ -15,8 +15,8 @@ import de.sovity.edc.ext.wrapper.api.common.mappers.asset.utils.AssetJsonLdUtils; import de.sovity.edc.ext.wrapper.api.common.mappers.asset.utils.ShortDescriptionBuilder; -import de.sovity.edc.ext.wrapper.api.common.model.UiAsset; import de.sovity.edc.ext.wrapper.api.common.model.DataSourceAvailability; +import de.sovity.edc.ext.wrapper.api.common.model.UiAsset; import de.sovity.edc.utils.JsonUtils; import de.sovity.edc.utils.jsonld.JsonLdUtils; import de.sovity.edc.utils.jsonld.vocab.Prop; diff --git a/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/asset/utils/JsonBuilderUtils.java b/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/asset/utils/JsonBuilderUtils.java index a2158e37e..bd2dbcf0b 100644 --- a/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/asset/utils/JsonBuilderUtils.java +++ b/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/asset/utils/JsonBuilderUtils.java @@ -51,8 +51,8 @@ public static void addNonNull(JsonObjectBuilder builder, String key, LocalDate v * Adds non-null non-blank trimmed items as a JSON Array * * @param builder target object - * @param key key - * @param values list of values + * @param key key + * @param values list of values */ public static void addNotBlankStringArray(JsonObjectBuilder builder, String key, List values) { var filteredItems = (values == null ? Stream.of() : values.stream()) diff --git a/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/dataaddress/http/HttpHeaderMapper.java b/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/dataaddress/http/HttpHeaderMapper.java index b679687df..cde71667d 100644 --- a/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/dataaddress/http/HttpHeaderMapper.java +++ b/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/dataaddress/http/HttpHeaderMapper.java @@ -11,7 +11,7 @@ * sovity GmbH - initial API and implementation * */ - + package de.sovity.edc.ext.wrapper.api.common.mappers.dataaddress.http; import de.sovity.edc.utils.jsonld.vocab.Prop; diff --git a/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/policy/AtomicConstraintMapper.java b/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/policy/AtomicConstraintMapper.java index 2899170a9..a56ed774b 100644 --- a/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/policy/AtomicConstraintMapper.java +++ b/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/policy/AtomicConstraintMapper.java @@ -19,7 +19,6 @@ import lombok.NonNull; import lombok.RequiredArgsConstructor; import org.eclipse.edc.policy.model.AtomicConstraint; -import org.eclipse.edc.policy.model.Constraint; import org.eclipse.edc.policy.model.LiteralExpression; import java.util.List; @@ -44,8 +43,8 @@ public List buildAtomicConstraints(List co } return constraints.stream() - .map(this::buildAtomicConstraint) - .toList(); + .map(this::buildAtomicConstraint) + .toList(); } /** @@ -54,30 +53,30 @@ public List buildAtomicConstraints(List co * This operation is lossy. * * @param atomicConstraint atomic contraints - * @param errors errors + * @param errors errors * @return ui policy constraint */ public Optional buildUiConstraint( - @NonNull AtomicConstraint atomicConstraint, - MappingErrors errors + @NonNull AtomicConstraint atomicConstraint, + MappingErrors errors ) { var leftValue = literalMapper.getExpressionString(atomicConstraint.getLeftExpression(), - errors.forChildObject("leftExpression")); + errors.forChildObject("leftExpression")); var operator = getOperator(atomicConstraint, errors); var rightValue = literalMapper.getExpressionValue(atomicConstraint.getRightExpression(), - errors.forChildObject("rightExpression")); + errors.forChildObject("rightExpression")); if (leftValue.isEmpty() || rightValue.isEmpty() || operator.isEmpty()) { return Optional.empty(); } UiPolicyConstraint result = UiPolicyConstraint.builder() - .left(leftValue.get()) - .operator(operator.get()) - .right(rightValue.get()) - .build(); + .left(leftValue.get()) + .operator(operator.get()) + .right(rightValue.get()) + .build(); return Optional.of(result); } @@ -99,10 +98,10 @@ public AtomicConstraint buildAtomicConstraint(UiPolicyConstraint constraint) { var right = literalMapper.getUiLiteralValue(constraint.getRight()); return AtomicConstraint.Builder.newInstance() - .leftExpression(new LiteralExpression(left)) - .operator(operator) - .rightExpression(new LiteralExpression(right)) - .build(); + .leftExpression(new LiteralExpression(left)) + .operator(operator) + .rightExpression(new LiteralExpression(right)) + .build(); } public AtomicConstraint buildAtomicConstraint(AtomicConstraintDto atomicConstraint) { @@ -111,9 +110,9 @@ public AtomicConstraint buildAtomicConstraint(AtomicConstraintDto atomicConstrai var right = atomicConstraint.getRightExpression(); return AtomicConstraint.Builder.newInstance() - .leftExpression(new LiteralExpression(left)) - .operator(operator) - .rightExpression(new LiteralExpression(right)) - .build(); + .leftExpression(new LiteralExpression(left)) + .operator(operator) + .rightExpression(new LiteralExpression(right)) + .build(); } } diff --git a/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/policy/LiteralMapper.java b/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/policy/LiteralMapper.java index 92f0194bc..e337231d8 100644 --- a/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/policy/LiteralMapper.java +++ b/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/policy/LiteralMapper.java @@ -14,7 +14,6 @@ package de.sovity.edc.ext.wrapper.api.common.mappers.policy; import com.fasterxml.jackson.databind.ObjectMapper; -import de.sovity.edc.ext.wrapper.api.common.mappers.policy.MappingErrors; import de.sovity.edc.ext.wrapper.api.common.model.UiPolicyLiteral; import lombok.RequiredArgsConstructor; import lombok.SneakyThrows; @@ -42,23 +41,23 @@ public Object getUiLiteralValue(UiPolicyLiteral literal) { } public Optional getExpressionString( - Expression expression, - MappingErrors errors + Expression expression, + MappingErrors errors ) { return getLiteralExpression(expression, errors).flatMap(literalExpression -> - getLiteralExpressionString(literalExpression, errors)); + getLiteralExpressionString(literalExpression, errors)); } public Optional getExpressionValue( - Expression expression, - MappingErrors errors + Expression expression, + MappingErrors errors ) { return getLiteralExpression(expression, errors).flatMap(this::getLiteralExpressionValue); } private Optional getLiteralExpressionString( - LiteralExpression literalExpression, - MappingErrors errors + LiteralExpression literalExpression, + MappingErrors errors ) { var value = literalExpression.getValue(); if (value == null) { @@ -84,7 +83,7 @@ private Optional getLiteralExpressionValue(LiteralExpression li } boolean isStringList = value instanceof Collection && ((Collection) value).stream() - .allMatch(it -> it == null || it instanceof String); + .allMatch(it -> it == null || it instanceof String); if (isStringList) { return Optional.of(UiPolicyLiteral.ofStringList((Collection) value)); } diff --git a/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/policy/PolicyValidator.java b/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/policy/PolicyValidator.java index 7bdc44502..dcaf3ea22 100644 --- a/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/policy/PolicyValidator.java +++ b/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/policy/PolicyValidator.java @@ -13,7 +13,6 @@ package de.sovity.edc.ext.wrapper.api.common.mappers.policy; -import de.sovity.edc.ext.wrapper.api.common.mappers.policy.MappingErrors; import lombok.RequiredArgsConstructor; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.StringUtils; From 6e27fc6464660f98b03865ccb4f2199b5ade7a57 Mon Sep 17 00:00:00 2001 From: Richard Treier Date: Thu, 11 Jul 2024 13:56:32 +0300 Subject: [PATCH 03/18] feat: clean up policy model and test --- CHANGELOG.md | 2 + .../CrawlerExtensionContextBuilder.java | 171 ++++++------ .../edc/ext/wrapper/api/ui/UiResource.java | 2 +- .../model/PolicyDefinitionCreateRequest.java | 3 +- .../api/ui}/model/PolicyDefinitionDto.java | 3 +- .../api/ui/model/PolicyDefinitionPage.java | 1 - .../wrapper/api/usecase/UseCaseResource.java | 7 - .../usecase/model/PolicyCreateRequest.java | 39 --- .../wrapper/api/common/model/AssetDto.java | 42 --- .../api/common/model/AtomicConstraintDto.java | 43 --- .../wrapper/api/common/model/Expression.java | 47 ---- .../api/common/model/ExpressionType.java | 17 -- .../wrapper/api/common/model/OperatorDto.java | 7 +- .../api/common/model/PermissionDto.java | 35 --- .../ext/wrapper/api/common/model/UiAsset.java | 2 +- .../common/model/UiAssetCreateRequest.java | 2 +- .../api/common/model/UiAssetEditRequest.java | 2 +- .../api/common/model/UiDataSource.java | 2 +- .../common/model/UiDataSourceHttpData.java | 1 + .../wrapper/api/common/model/UiPolicy.java | 4 +- .../api/common/model/UiPolicyConstraint.java | 2 +- .../common/model/UiPolicyCreateRequest.java | 3 +- .../api/common/model/UiPolicyExpression.java | 39 ++- .../api/common/mappers/PolicyMapper.java | 75 +----- .../policy/AtomicConstraintMapper.java | 49 +--- .../mappers/policy/ConstraintExtractor.java | 113 -------- .../mappers/policy/ExpressionExtractor.java | 67 +++++ .../mappers/policy/ExpressionMapper.java | 136 ++++++++++ .../api/common/mappers/PolicyMapperTest.java | 109 +++----- .../policy/AtomicConstraintMapperTest.java | 22 +- .../policy/ConstraintExtractorTest.java | 107 -------- .../policy/ExpressionExtractorTest.java | 144 ++++++++++ .../mappers/policy/ExpressionMapperTest.java | 252 +++++++++++++++++ .../WrapperExtensionContextBuilder.java | 255 +++++++++--------- .../ext/wrapper/api/ui/UiResourceImpl.java | 2 +- .../policy/PolicyDefinitionApiService.java | 39 +-- .../api/usecase/UseCaseResourceImpl.java | 9 - 37 files changed, 943 insertions(+), 912 deletions(-) rename extensions/wrapper/{wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common => wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui}/model/PolicyDefinitionCreateRequest.java (89%) rename extensions/wrapper/{wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common => wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui}/model/PolicyDefinitionDto.java (90%) delete mode 100644 extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/usecase/model/PolicyCreateRequest.java delete mode 100644 extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/AssetDto.java delete mode 100644 extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/AtomicConstraintDto.java delete mode 100644 extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/Expression.java delete mode 100644 extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/ExpressionType.java delete mode 100644 extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/PermissionDto.java delete mode 100644 extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/policy/ConstraintExtractor.java create mode 100644 extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/policy/ExpressionExtractor.java create mode 100644 extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/policy/ExpressionMapper.java delete mode 100644 extensions/wrapper/wrapper-common-mappers/src/test/java/de/sovity/edc/ext/wrapper/api/common/mappers/policy/ConstraintExtractorTest.java create mode 100644 extensions/wrapper/wrapper-common-mappers/src/test/java/de/sovity/edc/ext/wrapper/api/common/mappers/policy/ExpressionExtractorTest.java create mode 100644 extensions/wrapper/wrapper-common-mappers/src/test/java/de/sovity/edc/ext/wrapper/api/common/mappers/policy/ExpressionMapperTest.java diff --git a/CHANGELOG.md b/CHANGELOG.md index 06b4f7b35..473ecdb04 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,8 @@ 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 `XOR`. + - Removed the "Policy Definition Create" endpoint from the incomplete Use Case API in favor of the UI Endpoint with the `UiPolicy` model, which is more robust. - The Broker has been removed in favor of the Authority Portal and the new Deployment Unit, the "Data Catalog Crawler": - Each "Data Catalog Crawler" connects to an existing Authority Portal Deployment's DB. - Each "Data Catalog Crawler" is responsible for crawling exactly one environment. diff --git a/extensions/catalog-crawler/catalog-crawler/src/main/java/de/sovity/edc/ext/catalog/crawler/CrawlerExtensionContextBuilder.java b/extensions/catalog-crawler/catalog-crawler/src/main/java/de/sovity/edc/ext/catalog/crawler/CrawlerExtensionContextBuilder.java index 2437dd751..f95463a9f 100644 --- a/extensions/catalog-crawler/catalog-crawler/src/main/java/de/sovity/edc/ext/catalog/crawler/CrawlerExtensionContextBuilder.java +++ b/extensions/catalog-crawler/catalog-crawler/src/main/java/de/sovity/edc/ext/catalog/crawler/CrawlerExtensionContextBuilder.java @@ -63,7 +63,8 @@ import de.sovity.edc.ext.wrapper.api.common.mappers.dataaddress.http.HttpDataSourceMapper; import de.sovity.edc.ext.wrapper.api.common.mappers.dataaddress.http.HttpHeaderMapper; import de.sovity.edc.ext.wrapper.api.common.mappers.policy.AtomicConstraintMapper; -import de.sovity.edc.ext.wrapper.api.common.mappers.policy.ConstraintExtractor; +import de.sovity.edc.ext.wrapper.api.common.mappers.policy.ExpressionExtractor; +import de.sovity.edc.ext.wrapper.api.common.mappers.policy.ExpressionMapper; import de.sovity.edc.ext.wrapper.api.common.mappers.policy.LiteralMapper; import de.sovity.edc.ext.wrapper.api.common.mappers.policy.OperatorMapper; import de.sovity.edc.ext.wrapper.api.common.mappers.policy.PolicyValidator; @@ -95,12 +96,12 @@ public class CrawlerExtensionContextBuilder { public static CrawlerExtensionContext buildContext( - Config config, - Monitor monitor, - TypeManager typeManager, - TypeTransformerRegistry typeTransformerRegistry, - JsonLd jsonLd, - CatalogService catalogService + Config config, + Monitor monitor, + TypeManager typeManager, + TypeTransformerRegistry typeTransformerRegistry, + JsonLd jsonLd, + CatalogService catalogService ) { // Config var crawlerConfigFactory = new CrawlerConfigFactory(config); @@ -124,9 +125,9 @@ public static CrawlerExtensionContext buildContext( var crawlerEventLogger = new CrawlerEventLogger(); var crawlerExecutionTimeLogger = new CrawlerExecutionTimeLogger(); var dataOfferMappingUtils = new FetchedCatalogMappingUtils( - policyMapper, - assetMapper, - objectMapperJsonLd + policyMapper, + assetMapper, + objectMapperJsonLd ); var contractOfferRecordUpdater = new ContractOfferRecordUpdater(); var shortDescriptionBuilder = new ShortDescriptionBuilder(); @@ -134,34 +135,34 @@ public static CrawlerExtensionContext buildContext( var contractOfferQueries = new ContractOfferQueries(); var dataOfferLimitsEnforcer = new DataOfferLimitsEnforcer(crawlerConfig, crawlerEventLogger); var dataOfferPatchBuilder = new CatalogPatchBuilder( - contractOfferQueries, - dataOfferQueries, - dataOfferRecordUpdater, - contractOfferRecordUpdater + contractOfferQueries, + dataOfferQueries, + dataOfferRecordUpdater, + contractOfferRecordUpdater ); var dataOfferPatchApplier = new CatalogPatchApplier(); var dataOfferWriter = new ConnectorUpdateCatalogWriter(dataOfferPatchBuilder, dataOfferPatchApplier); var connectorUpdateSuccessWriter = new ConnectorUpdateSuccessWriter( - crawlerEventLogger, - dataOfferWriter, - dataOfferLimitsEnforcer + crawlerEventLogger, + dataOfferWriter, + dataOfferLimitsEnforcer ); var fetchedDataOfferBuilder = new FetchedCatalogBuilder(dataOfferMappingUtils); var dspDataOfferBuilder = new DspDataOfferBuilder(jsonLd); var dspCatalogService = new DspCatalogService( - catalogService, - dspDataOfferBuilder + catalogService, + dspDataOfferBuilder ); var dataOfferFetcher = new FetchedCatalogService(dspCatalogService, fetchedDataOfferBuilder); var connectorUpdateFailureWriter = new ConnectorUpdateFailureWriter(crawlerEventLogger, monitor); var connectorUpdater = new ConnectorCrawler( - dataOfferFetcher, - connectorUpdateSuccessWriter, - connectorUpdateFailureWriter, - connectorQueries, - dslContextFactory, - monitor, - crawlerExecutionTimeLogger + dataOfferFetcher, + connectorUpdateSuccessWriter, + connectorUpdateFailureWriter, + connectorQueries, + dslContextFactory, + monitor, + crawlerExecutionTimeLogger ); var threadPoolTaskQueue = new ThreadPoolTaskQueue(); @@ -171,19 +172,19 @@ public static CrawlerExtensionContext buildContext( var connectorStatusUpdater = new ConnectorStatusUpdater(); var catalogCleaner = new CatalogCleaner(); var offlineConnectorCleaner = new OfflineConnectorCleaner( - crawlerConfig, - connectorQueries, - crawlerEventLogger, - connectorStatusUpdater, - catalogCleaner + crawlerConfig, + connectorQueries, + crawlerEventLogger, + connectorStatusUpdater, + catalogCleaner ); // Schedules List> jobs = List.of( - getOnlineConnectorRefreshCronJob(dslContextFactory, connectorQueueFiller), - getOfflineConnectorRefreshCronJob(dslContextFactory, connectorQueueFiller), - getDeadConnectorRefreshCronJob(dslContextFactory, connectorQueueFiller), - getOfflineConnectorCleanerCronJob(dslContextFactory, offlineConnectorCleaner) + getOnlineConnectorRefreshCronJob(dslContextFactory, connectorQueueFiller), + getOfflineConnectorRefreshCronJob(dslContextFactory, connectorQueueFiller), + getDeadConnectorRefreshCronJob(dslContextFactory, connectorQueueFiller), + getOfflineConnectorCleanerCronJob(dslContextFactory, offlineConnectorCleaner) ); // Startup @@ -191,68 +192,70 @@ public static CrawlerExtensionContext buildContext( var crawlerInitializer = new CrawlerInitializer(quartzScheduleInitializer); return new CrawlerExtensionContext( - crawlerInitializer, - dataSource, - dslContextFactory, - connectorUpdater, - policyMapper, - fetchedDataOfferBuilder, - dataOfferRecordUpdater + crawlerInitializer, + dataSource, + dslContextFactory, + connectorUpdater, + policyMapper, + fetchedDataOfferBuilder, + dataOfferRecordUpdater ); } @NotNull - private static PolicyMapper newPolicyMapper(TypeTransformerRegistry typeTransformerRegistry, ObjectMapper objectMapperJsonLd) { + private static PolicyMapper newPolicyMapper( + TypeTransformerRegistry typeTransformerRegistry, + ObjectMapper objectMapperJsonLd + ) { var operatorMapper = new OperatorMapper(); - var literalMapper = new LiteralMapper( - objectMapperJsonLd - ); + var literalMapper = new LiteralMapper(objectMapperJsonLd); var atomicConstraintMapper = new AtomicConstraintMapper( - literalMapper, - operatorMapper + literalMapper, + operatorMapper ); var policyValidator = new PolicyValidator(); - var constraintExtractor = new ConstraintExtractor( - policyValidator, - atomicConstraintMapper + var expressionMapper = new ExpressionMapper(atomicConstraintMapper); + var constraintExtractor = new ExpressionExtractor( + policyValidator, + expressionMapper ); return new PolicyMapper( - constraintExtractor, - atomicConstraintMapper, - typeTransformerRegistry + constraintExtractor, + expressionMapper, + typeTransformerRegistry ); } @NotNull private static AssetMapper newAssetMapper( - TypeTransformerRegistry typeTransformerRegistry, - JsonLd jsonLd + TypeTransformerRegistry typeTransformerRegistry, + JsonLd jsonLd ) { var edcPropertyUtils = new EdcPropertyUtils(); var assetJsonLdUtils = new AssetJsonLdUtils(); var assetEditRequestMapper = new AssetEditRequestMapper(); var shortDescriptionBuilder = new ShortDescriptionBuilder(); var assetJsonLdParser = new AssetJsonLdParser( - assetJsonLdUtils, - shortDescriptionBuilder, - endpoint -> false + assetJsonLdUtils, + shortDescriptionBuilder, + endpoint -> false ); var httpHeaderMapper = new HttpHeaderMapper(); var httpDataSourceMapper = new HttpDataSourceMapper(httpHeaderMapper); var dataSourceMapper = new DataSourceMapper( - edcPropertyUtils, - httpDataSourceMapper + edcPropertyUtils, + httpDataSourceMapper ); var assetJsonLdBuilder = new AssetJsonLdBuilder( - dataSourceMapper, - assetJsonLdParser, - assetEditRequestMapper + dataSourceMapper, + assetJsonLdParser, + assetEditRequestMapper ); return new AssetMapper( - typeTransformerRegistry, - assetJsonLdBuilder, - assetJsonLdParser, - jsonLd + typeTransformerRegistry, + assetJsonLdBuilder, + assetJsonLdParser, + jsonLd ); } @@ -260,33 +263,33 @@ private static AssetMapper newAssetMapper( private static CronJobRef getOfflineConnectorCleanerCronJob(DslContextFactory dslContextFactory, OfflineConnectorCleaner offlineConnectorCleaner) { return new CronJobRef<>( - CrawlerExtension.SCHEDULED_KILL_OFFLINE_CONNECTORS, - OfflineConnectorCleanerJob.class, - () -> new OfflineConnectorCleanerJob(dslContextFactory, offlineConnectorCleaner) + CrawlerExtension.SCHEDULED_KILL_OFFLINE_CONNECTORS, + OfflineConnectorCleanerJob.class, + () -> new OfflineConnectorCleanerJob(dslContextFactory, offlineConnectorCleaner) ); } @NotNull private static CronJobRef getOnlineConnectorRefreshCronJob( - DslContextFactory dslContextFactory, - ConnectorQueueFiller connectorQueueFiller + DslContextFactory dslContextFactory, + ConnectorQueueFiller connectorQueueFiller ) { return new CronJobRef<>( - CrawlerExtension.CRON_ONLINE_CONNECTOR_REFRESH, - OnlineConnectorRefreshJob.class, - () -> new OnlineConnectorRefreshJob(dslContextFactory, connectorQueueFiller) + CrawlerExtension.CRON_ONLINE_CONNECTOR_REFRESH, + OnlineConnectorRefreshJob.class, + () -> new OnlineConnectorRefreshJob(dslContextFactory, connectorQueueFiller) ); } @NotNull private static CronJobRef getOfflineConnectorRefreshCronJob( - DslContextFactory dslContextFactory, - ConnectorQueueFiller connectorQueueFiller + DslContextFactory dslContextFactory, + ConnectorQueueFiller connectorQueueFiller ) { return new CronJobRef<>( - CrawlerExtension.CRON_OFFLINE_CONNECTOR_REFRESH, - OfflineConnectorRefreshJob.class, - () -> new OfflineConnectorRefreshJob(dslContextFactory, connectorQueueFiller) + CrawlerExtension.CRON_OFFLINE_CONNECTOR_REFRESH, + OfflineConnectorRefreshJob.class, + () -> new OfflineConnectorRefreshJob(dslContextFactory, connectorQueueFiller) ); } @@ -294,9 +297,9 @@ private static CronJobRef getOfflineConnectorRefresh private static CronJobRef getDeadConnectorRefreshCronJob(DslContextFactory dslContextFactory, ConnectorQueueFiller connectorQueueFiller) { return new CronJobRef<>( - CrawlerExtension.CRON_DEAD_CONNECTOR_REFRESH, - DeadConnectorRefreshJob.class, - () -> new DeadConnectorRefreshJob(dslContextFactory, connectorQueueFiller) + CrawlerExtension.CRON_DEAD_CONNECTOR_REFRESH, + DeadConnectorRefreshJob.class, + () -> new DeadConnectorRefreshJob(dslContextFactory, connectorQueueFiller) ); } diff --git a/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/UiResource.java b/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/UiResource.java index aa12367c2..e81ec0a82 100644 --- a/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/UiResource.java +++ b/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/UiResource.java @@ -14,7 +14,7 @@ package de.sovity.edc.ext.wrapper.api.ui; -import de.sovity.edc.ext.wrapper.api.common.model.PolicyDefinitionCreateRequest; +import de.sovity.edc.ext.wrapper.api.ui.model.PolicyDefinitionCreateRequest; import de.sovity.edc.ext.wrapper.api.common.model.UiAsset; import de.sovity.edc.ext.wrapper.api.common.model.UiAssetCreateRequest; import de.sovity.edc.ext.wrapper.api.common.model.UiAssetEditRequest; diff --git a/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/PolicyDefinitionCreateRequest.java b/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/PolicyDefinitionCreateRequest.java similarity index 89% rename from extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/PolicyDefinitionCreateRequest.java rename to extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/PolicyDefinitionCreateRequest.java index 70392fff6..74795e04f 100644 --- a/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/PolicyDefinitionCreateRequest.java +++ b/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/PolicyDefinitionCreateRequest.java @@ -12,9 +12,10 @@ * */ -package de.sovity.edc.ext.wrapper.api.common.model; +package de.sovity.edc.ext.wrapper.api.ui.model; import com.fasterxml.jackson.annotation.JsonInclude; +import de.sovity.edc.ext.wrapper.api.common.model.UiPolicyCreateRequest; import io.swagger.v3.oas.annotations.media.Schema; import lombok.AllArgsConstructor; import lombok.Builder; diff --git a/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/PolicyDefinitionDto.java b/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/PolicyDefinitionDto.java similarity index 90% rename from extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/PolicyDefinitionDto.java rename to extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/PolicyDefinitionDto.java index a0e917f2d..3c69aca84 100644 --- a/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/PolicyDefinitionDto.java +++ b/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/PolicyDefinitionDto.java @@ -12,9 +12,10 @@ * */ -package de.sovity.edc.ext.wrapper.api.common.model; +package de.sovity.edc.ext.wrapper.api.ui.model; import com.fasterxml.jackson.annotation.JsonInclude; +import de.sovity.edc.ext.wrapper.api.common.model.UiPolicy; import io.swagger.v3.oas.annotations.media.Schema; import lombok.AllArgsConstructor; import lombok.Builder; diff --git a/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/PolicyDefinitionPage.java b/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/PolicyDefinitionPage.java index 285e338b9..9b77b3c36 100644 --- a/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/PolicyDefinitionPage.java +++ b/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/PolicyDefinitionPage.java @@ -15,7 +15,6 @@ package de.sovity.edc.ext.wrapper.api.ui.model; import com.fasterxml.jackson.annotation.JsonInclude; -import de.sovity.edc.ext.wrapper.api.common.model.PolicyDefinitionDto; import io.swagger.v3.oas.annotations.media.Schema; import lombok.AllArgsConstructor; import lombok.Builder; diff --git a/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/usecase/UseCaseResource.java b/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/usecase/UseCaseResource.java index 218b337dd..c8cd2d049 100644 --- a/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/usecase/UseCaseResource.java +++ b/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/usecase/UseCaseResource.java @@ -61,11 +61,4 @@ List queryCatalog( @Valid @NotNull CatalogQuery catalogQuery ); - - @POST - @Path("policy-definition") - @Consumes(MediaType.APPLICATION_JSON) - @Produces(MediaType.APPLICATION_JSON) - @Operation(description = "Create a new Policy Definition") - IdResponseDto createPolicyDefinitionUseCase(PolicyCreateRequest policyCreateRequest); } diff --git a/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/usecase/model/PolicyCreateRequest.java b/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/usecase/model/PolicyCreateRequest.java deleted file mode 100644 index da6b75996..000000000 --- a/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/usecase/model/PolicyCreateRequest.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (c) 2022 sovity GmbH - * - * 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 - * - * SPDX-License-Identifier: Apache-2.0 - * - * Contributors: - * sovity GmbH - initial API and implementation - * - */ - -package de.sovity.edc.ext.wrapper.api.usecase.model; - -import com.fasterxml.jackson.annotation.JsonInclude; -import de.sovity.edc.ext.wrapper.api.common.model.PermissionDto; -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Data; -import lombok.RequiredArgsConstructor; - -@Data -@AllArgsConstructor -@RequiredArgsConstructor -@Builder(toBuilder = true) -@JsonInclude(JsonInclude.Include.NON_NULL) -@Schema(description = "Policy Creation Request Supporting Multiplicity Constraints.") -public class PolicyCreateRequest { - - @Schema(description = "Policy Definition ID", requiredMode = Schema.RequiredMode.REQUIRED) - private String policyDefinitionId; - - @Schema(description = "Permission description for the policy to evaluate to TRUE.") - private PermissionDto permission; - -} diff --git a/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/AssetDto.java b/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/AssetDto.java deleted file mode 100644 index 32b28eafb..000000000 --- a/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/AssetDto.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (c) 2022 sovity GmbH - * - * 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 - * - * SPDX-License-Identifier: Apache-2.0 - * - * Contributors: - * sovity GmbH - initial API and implementation - * - */ - -package de.sovity.edc.ext.wrapper.api.common.model; - -import com.fasterxml.jackson.annotation.JsonInclude; -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Data; -import lombok.RequiredArgsConstructor; - -import java.time.OffsetDateTime; -import java.util.Map; - -@Data -@AllArgsConstructor -@RequiredArgsConstructor -@Builder(toBuilder = true) -@JsonInclude(JsonInclude.Include.NON_NULL) -@Schema(description = "Asset Details") -public class AssetDto { - @Schema(description = "ID of asset", requiredMode = Schema.RequiredMode.REQUIRED) - private String assetId; - - @Schema(description = "Creation Date of asset", requiredMode = Schema.RequiredMode.REQUIRED) - private OffsetDateTime createdAt; - - @Schema(description = "Asset properties", requiredMode = Schema.RequiredMode.REQUIRED) - private Map properties; -} diff --git a/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/AtomicConstraintDto.java b/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/AtomicConstraintDto.java deleted file mode 100644 index 0e8ed7b77..000000000 --- a/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/AtomicConstraintDto.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) 2023 sovity GmbH - * - * 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 - * - * SPDX-License-Identifier: Apache-2.0 - * - * Contributors: - * sovity GmbH - init - */ - -package de.sovity.edc.ext.wrapper.api.common.model; - -import com.fasterxml.jackson.annotation.JsonInclude; -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Data; -import lombok.RequiredArgsConstructor; - - -@Data -@AllArgsConstructor -@RequiredArgsConstructor -@Builder(toBuilder = true) -@JsonInclude(JsonInclude.Include.NON_NULL) -@Schema(description = - "Type-Safe OpenAPI generator friendly Constraint DTO that supports an opinionated" - + " subset of the original EDC Constraint Entity.") -public class AtomicConstraintDto { - - @Schema(description = "Left part of the constraint.", - requiredMode = Schema.RequiredMode.REQUIRED) - private String leftExpression; - @Schema(description = "Operator to connect both parts of the constraint.", - requiredMode = Schema.RequiredMode.REQUIRED) - private OperatorDto operator; - @Schema(description = "Right part of the constraint.", - requiredMode = Schema.RequiredMode.REQUIRED) - private String rightExpression; -} diff --git a/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/Expression.java b/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/Expression.java deleted file mode 100644 index 148f34a4f..000000000 --- a/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/Expression.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright (c) 2022 sovity GmbH - * - * 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 - * - * SPDX-License-Identifier: Apache-2.0 - * - * Contributors: - * sovity GmbH - initial API and implementation - * - */ - -package de.sovity.edc.ext.wrapper.api.common.model; - -import com.fasterxml.jackson.annotation.JsonInclude; -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Data; -import lombok.RequiredArgsConstructor; - -import java.util.List; - -@Data -@AllArgsConstructor -@RequiredArgsConstructor -@Builder(toBuilder = true) -@JsonInclude(JsonInclude.Include.NON_NULL) -@Schema(description = - "Represents a single atomic constraint or a multiplicity constraint. The atomicConstraint" + - " will be evaluated if the constraintType is ATOMIC_CONSTRAINT.") -public class Expression { - - @Schema(description = "Either ATOMIC_CONSTRAINT or one of the multiplicity constraint types.") - private ExpressionType expressionType; - - @Schema(description = - "List of policy elements that are evaluated according the expressionType.") - private List expressions; - - @Schema(description = - "A single atomic constraint. Will be evaluated if the expressionType is set to " + - "ATOMIC_CONSTRAINT.") - private AtomicConstraintDto atomicConstraint; -} diff --git a/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/ExpressionType.java b/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/ExpressionType.java deleted file mode 100644 index 910c82a88..000000000 --- a/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/ExpressionType.java +++ /dev/null @@ -1,17 +0,0 @@ -package de.sovity.edc.ext.wrapper.api.common.model; - -import io.swagger.v3.oas.annotations.media.Schema; - -/** - * Sum type enum. - */ -@Schema(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 - """, enumAsRef = true) -public enum ExpressionType { - ATOMIC_CONSTRAINT, AND, OR, XOR -} diff --git a/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/OperatorDto.java b/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/OperatorDto.java index 34ab6a955..67f1ee851 100644 --- a/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/OperatorDto.java +++ b/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/OperatorDto.java @@ -8,7 +8,8 @@ * SPDX-License-Identifier: Apache-2.0 * * Contributors: - * sovity GmbH - init + * Fraunhofer ISST - initial implementation + * sovity GmbH - documentation changes */ package de.sovity.edc.ext.wrapper.api.common.model; @@ -16,11 +17,9 @@ import io.swagger.v3.oas.annotations.media.Schema; /** - * Equivalent of ODRL Policy Operator for our API Wrapper API. - * * @author tim.dahlmanns@isst.fraunhofer.de */ -@Schema(description = "Operator for policies", enumAsRef = true) +@Schema(description = "Type-Safe ODRL Policy Operator as supported by the sovity product landscape", enumAsRef = true) public enum OperatorDto { EQ, NEQ, diff --git a/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/PermissionDto.java b/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/PermissionDto.java deleted file mode 100644 index 93f48747b..000000000 --- a/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/PermissionDto.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright (c) 2023 sovity GmbH - * - * 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 - * - * SPDX-License-Identifier: Apache-2.0 - * - * Contributors: - * sovity GmbH - init - */ - -package de.sovity.edc.ext.wrapper.api.common.model; - -import com.fasterxml.jackson.annotation.JsonInclude; -import io.swagger.v3.oas.annotations.media.Schema; -import io.swagger.v3.oas.annotations.media.Schema.RequiredMode; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Data; -import lombok.RequiredArgsConstructor; - - -@Data -@AllArgsConstructor -@RequiredArgsConstructor -@Builder(toBuilder = true) -@JsonInclude(JsonInclude.Include.NON_NULL) -public class PermissionDto { - - @Schema(description = "Possible constraints for the permission", - requiredMode = RequiredMode.REQUIRED) - private Expression expression; -} diff --git a/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiAsset.java b/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiAsset.java index 9cc06b818..0ed4590b9 100644 --- a/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiAsset.java +++ b/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiAsset.java @@ -29,7 +29,7 @@ @RequiredArgsConstructor @Builder(toBuilder = true) @JsonInclude(JsonInclude.Include.NON_NULL) -@Schema(description = "Type-Safe Asset Metadata as needed by our UI") +@Schema(description = "Type-safe data offer metadata as supported by the sovity product landscape. Contains extension points.") public class UiAsset { @Schema(description = "'Live' vs 'On Request'", requiredMode = Schema.RequiredMode.REQUIRED) private DataSourceAvailability dataSourceAvailability; diff --git a/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiAssetCreateRequest.java b/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiAssetCreateRequest.java index c49b7af1f..8ee241616 100644 --- a/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiAssetCreateRequest.java +++ b/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiAssetCreateRequest.java @@ -29,7 +29,7 @@ @RequiredArgsConstructor @Builder(toBuilder = true) @JsonInclude(JsonInclude.Include.NON_NULL) -@Schema(description = "Type-Safe OpenAPI generator friendly Asset Create DTO that supports an opinionated subset of the original EDC Asset Entity.") +@Schema(description = "Type-safe data offer metadata for creating an asset as supported by the sovity product landscape. Contains extension points.") public class UiAssetCreateRequest { @Schema(description = "Data Source", requiredMode = Schema.RequiredMode.REQUIRED) private UiDataSource dataSource; diff --git a/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiAssetEditRequest.java b/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiAssetEditRequest.java index 6cee639b3..31fd15d74 100644 --- a/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiAssetEditRequest.java +++ b/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiAssetEditRequest.java @@ -29,7 +29,7 @@ @RequiredArgsConstructor @Builder(toBuilder = true) @JsonInclude(JsonInclude.Include.NON_NULL) -@Schema(description = "Data for editing an asset.") +@Schema(description = "Type-safe data offer metadata for editing an asset as supported by the sovity product landscape. Contains extension points.") public class UiAssetEditRequest { @Schema(description = "Data Source", requiredMode = Schema.RequiredMode.NOT_REQUIRED) private UiDataSource dataSourceOverrideOrNull; diff --git a/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiDataSource.java b/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiDataSource.java index bb57db00c..8feef9ae8 100644 --- a/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiDataSource.java +++ b/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiDataSource.java @@ -28,7 +28,7 @@ @RequiredArgsConstructor @Builder(toBuilder = true) @JsonInclude(JsonInclude.Include.NON_NULL) -@Schema(description = "Data Offer Data Source Model. Supports certain Data Address types but also leaves a backdoor for custom Data Address Properties.") +@Schema(description = "Type-safe data source as supported by the sovity product landscape. Contains extension points for using custom data address properties.") public class UiDataSource { @Schema( description = "Data Address Type.", diff --git a/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiDataSourceHttpData.java b/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiDataSourceHttpData.java index 381dcdb73..c995248d5 100644 --- a/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiDataSourceHttpData.java +++ b/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiDataSourceHttpData.java @@ -28,6 +28,7 @@ @RequiredArgsConstructor @Builder(toBuilder = true) @JsonInclude(JsonInclude.Include.NON_NULL) +@Schema(description = "HTTP_DATA type Data Source.") public class UiDataSourceHttpData { @Schema( description = "HTTP Request Method", diff --git a/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiPolicy.java b/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiPolicy.java index 77d018aa0..ce72b2c40 100644 --- a/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiPolicy.java +++ b/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiPolicy.java @@ -29,14 +29,14 @@ @RequiredArgsConstructor @Builder(toBuilder = true) @JsonInclude(JsonInclude.Include.NON_NULL) -@Schema(description = "Type-Safe OpenAPI generator friendly Policy DTO as needed by our UI") +@Schema(description = "Type-Safe OpenAPI generator friendly ODLR policy subset as endorsed by sovity.") public class UiPolicy { @Schema(description = "EDC Policy JSON-LD. This is required because the EDC requires the " + "full policy when initiating contract negotiations.", requiredMode = RequiredMode.REQUIRED) private String policyJsonLd; @Schema(description = "Conjunction of required expressions for the policy to evaluate to TRUE.") - private List constraints; + private List expressions; @Schema(description = "When trying to reduce the policy JSON-LD to our opinionated subset of functionalities, " + "many fields and functionalities are unsupported. Should any discrepancies occur during " + diff --git a/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiPolicyConstraint.java b/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiPolicyConstraint.java index 1df6cd1dc..a640aae62 100644 --- a/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiPolicyConstraint.java +++ b/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiPolicyConstraint.java @@ -27,7 +27,7 @@ @RequiredArgsConstructor @Builder(toBuilder = true) @JsonInclude(JsonInclude.Include.NON_NULL) -@Schema(description = "ODRL AtomicConstraint as supported by our UI") +@Schema(description = "ODRL AtomicConstraint as supported by the sovity product landscape") public class UiPolicyConstraint { @Schema(description = "Left side of the expression.", requiredMode = RequiredMode.REQUIRED) private String left; diff --git a/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiPolicyCreateRequest.java b/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiPolicyCreateRequest.java index 2e2907884..e135937e2 100644 --- a/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiPolicyCreateRequest.java +++ b/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiPolicyCreateRequest.java @@ -28,8 +28,7 @@ @RequiredArgsConstructor @Builder(toBuilder = true) @JsonInclude(JsonInclude.Include.NON_NULL) -@Schema(description = "Type-Safe OpenAPI generator friendly Policy Create DTO that supports an opinionated" - + " subset of the original EDC Policy Entity.") +@Schema(description = "Type-Safe OpenAPI generator friendly ODLR policy subset as endorsed by sovity.") public class UiPolicyCreateRequest { @Schema(description = "Conjunction of required expressions for the policy to evaluate to TRUE.") private List expressions; diff --git a/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiPolicyExpression.java b/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiPolicyExpression.java index ea1107f68..9a4f0478f 100644 --- a/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiPolicyExpression.java +++ b/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiPolicyExpression.java @@ -15,21 +15,44 @@ @RequiredArgsConstructor @Builder(toBuilder = true) @JsonInclude(JsonInclude.Include.NON_NULL) -@Schema(description = - "Represents a single Ui Policy Literal or a List of Ui Policy Expressions. The Literal" + - " will be evaluated if the expressionType is LITERAL.") +@Schema(description = "ODRL constraint as supported by the sovity product landscape") public class UiPolicyExpression { @Schema(description = "Either LITERAL or one of the constraint types.") private UiPolicyExpressionType expressionType; - @Schema(description = - "List of policy elements that are evaluated according the expressionType.") + @Schema(description = "Only for types AND, OR, XOR. List of sub-expressions " + + "to be evaluated according to the expressionType.") private List expressions; - @Schema(description = - "A single literal. Will be evaluated if the expressionType is set to " + - "LITERAL.") + @Schema(description = "Only for type CONSTRAINT. A single constraint.") private UiPolicyConstraint constraint; + public static UiPolicyExpression and(List expressions) { + return UiPolicyExpression.builder() + .expressionType(UiPolicyExpressionType.AND) + .expressions(expressions) + .build(); + } + + public static UiPolicyExpression or(List expressions) { + return UiPolicyExpression.builder() + .expressionType(UiPolicyExpressionType.OR) + .expressions(expressions) + .build(); + } + + public static UiPolicyExpression xor(List expressions) { + return UiPolicyExpression.builder() + .expressionType(UiPolicyExpressionType.XOR) + .expressions(expressions) + .build(); + } + + public static UiPolicyExpression constraint(UiPolicyConstraint constraint) { + return UiPolicyExpression.builder() + .expressionType(UiPolicyExpressionType.CONSTRAINT) + .constraint(constraint) + .build(); + } } diff --git a/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/PolicyMapper.java b/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/PolicyMapper.java index 5d303892c..7ae93423e 100644 --- a/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/PolicyMapper.java +++ b/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/PolicyMapper.java @@ -16,15 +16,14 @@ import de.sovity.edc.ext.wrapper.api.common.mappers.asset.utils.FailedMappingException; import de.sovity.edc.ext.wrapper.api.common.mappers.policy.AtomicConstraintMapper; -import de.sovity.edc.ext.wrapper.api.common.mappers.policy.ConstraintExtractor; +import de.sovity.edc.ext.wrapper.api.common.mappers.policy.ExpressionExtractor; +import de.sovity.edc.ext.wrapper.api.common.mappers.policy.ExpressionMapper; import de.sovity.edc.ext.wrapper.api.common.mappers.policy.MappingErrors; import de.sovity.edc.ext.wrapper.api.common.mappers.policy.PolicyValidator; -import de.sovity.edc.ext.wrapper.api.common.model.Expression; import de.sovity.edc.ext.wrapper.api.common.model.UiPolicy; import de.sovity.edc.ext.wrapper.api.common.model.UiPolicyCreateRequest; import de.sovity.edc.ext.wrapper.api.common.model.UiPolicyExpression; import de.sovity.edc.utils.JsonUtils; -import de.sovity.edc.utils.jsonld.vocab.Prop; import jakarta.json.JsonObject; import lombok.RequiredArgsConstructor; import org.eclipse.edc.policy.model.Action; @@ -36,7 +35,7 @@ import org.eclipse.edc.policy.model.PolicyType; import org.eclipse.edc.policy.model.XoneConstraint; import org.eclipse.edc.transform.spi.TypeTransformerRegistry; -import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.util.List; @@ -44,8 +43,8 @@ @RequiredArgsConstructor public class PolicyMapper { - private final ConstraintExtractor constraintExtractor; - private final AtomicConstraintMapper atomicConstraintMapper; + private final ExpressionExtractor expressionExtractor; + private final ExpressionMapper expressionMapper; private final TypeTransformerRegistry typeTransformerRegistry; /** @@ -59,11 +58,11 @@ public class PolicyMapper { public UiPolicy buildUiPolicy(Policy policy) { MappingErrors errors = MappingErrors.root(); - var constraints = constraintExtractor.getPermissionConstraints(policy, errors); + var expressions = expressionExtractor.getPermissionExpressions(policy, errors); return UiPolicy.builder() .policyJsonLd(toJson(buildPolicyJsonLd(policy))) - .constraints(constraints) + .expressions(expressions) .errors(errors.getErrors()) .build(); } @@ -77,7 +76,7 @@ public UiPolicy buildUiPolicy(Policy policy) { * @return ODRL policy */ public Policy buildPolicy(UiPolicyCreateRequest policyCreateDto) { - var constraints = convertExpressionsToConstraints(policyCreateDto.getExpressions()); + var constraints = expressionMapper.buildConstraints(policyCreateDto.getExpressions()); var action = Action.Builder.newInstance().type(PolicyValidator.ALLOWED_ACTION).build(); @@ -92,64 +91,6 @@ public Policy buildPolicy(UiPolicyCreateRequest policyCreateDto) { .build(); } - public Policy buildPolicy(List constraintElements) { - var constraints = buildConstraints(constraintElements); - var action = Action.Builder.newInstance().type(Prop.Odrl.USE).build(); - var permission = Permission.Builder.newInstance() - .action(action) - .constraints(constraints) - .build(); - - return Policy.Builder.newInstance() - .type(PolicyType.SET) - .permission(permission) - .build(); - } - - @NotNull - private List buildConstraints(List expressions) { - return expressions.stream() - .map(this::buildConstraint) - .toList(); - } - - private Constraint buildConstraint(Expression expression) { - var subExpressions = expression.getExpressions(); - return switch (expression.getExpressionType()) { - case ATOMIC_CONSTRAINT -> atomicConstraintMapper.buildAtomicConstraint(expression.getAtomicConstraint()); - case AND -> AndConstraint.Builder.newInstance() - .constraints(buildConstraints(subExpressions)) - .build(); - case OR -> OrConstraint.Builder.newInstance() - .constraints(buildConstraints(subExpressions)) - .build(); - case XOR -> XoneConstraint.Builder.newInstance() - .constraints(buildConstraints(subExpressions)) - .build(); - }; - } - - private List convertExpressionsToConstraints(List expressions) { - return expressions.stream() - .map(this::convertExpressionToConstraint) - .toList(); - } - - private Constraint convertExpressionToConstraint(UiPolicyExpression expression) { - return switch (expression.getExpressionType()) { - case CONSTRAINT -> atomicConstraintMapper.buildAtomicConstraint(expression.getConstraint()); - case AND -> AndConstraint.Builder.newInstance() - .constraints(convertExpressionsToConstraints(expression.getExpressions())) - .build(); - case OR -> OrConstraint.Builder.newInstance() - .constraints(convertExpressionsToConstraints(expression.getExpressions())) - .build(); - case XOR -> XoneConstraint.Builder.newInstance() - .constraints(convertExpressionsToConstraints(expression.getExpressions())) - .build(); - }; - } - /** * Maps an ODRL Policy from JSON-LD to the Core EDC Type. *

diff --git a/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/policy/AtomicConstraintMapper.java b/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/policy/AtomicConstraintMapper.java index a56ed774b..c26cab1b9 100644 --- a/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/policy/AtomicConstraintMapper.java +++ b/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/policy/AtomicConstraintMapper.java @@ -13,7 +13,6 @@ package de.sovity.edc.ext.wrapper.api.common.mappers.policy; -import de.sovity.edc.ext.wrapper.api.common.model.AtomicConstraintDto; import de.sovity.edc.ext.wrapper.api.common.model.OperatorDto; import de.sovity.edc.ext.wrapper.api.common.model.UiPolicyConstraint; import lombok.NonNull; @@ -21,7 +20,6 @@ import org.eclipse.edc.policy.model.AtomicConstraint; import org.eclipse.edc.policy.model.LiteralExpression; -import java.util.List; import java.util.Optional; @RequiredArgsConstructor @@ -30,23 +28,26 @@ public class AtomicConstraintMapper { private final OperatorMapper operatorMapper; /** - * Create ODRL {@link AtomicConstraint}s from {@link UiPolicyConstraint}s + * Create ODRL {@link AtomicConstraint} from {@link UiPolicyConstraint} *

* This operation is lossless. * - * @param constraints ui constraints - * @return ODRL constraints + * @param constraint ui constraint + * @return ODRL constraint */ - public List buildAtomicConstraints(List constraints) { - if (constraints == null) { - return List.of(); - } + public AtomicConstraint buildAtomicConstraint(UiPolicyConstraint constraint) { + var left = constraint.getLeft(); + var operator = operatorMapper.getOperator(constraint.getOperator()); + var right = literalMapper.getUiLiteralValue(constraint.getRight()); - return constraints.stream() - .map(this::buildAtomicConstraint) - .toList(); + return AtomicConstraint.Builder.newInstance() + .leftExpression(new LiteralExpression(left)) + .operator(operator) + .rightExpression(new LiteralExpression(right)) + .build(); } + /** * Create {@link UiPolicyConstraint} from ODRL {@link AtomicConstraint} *

@@ -91,28 +92,4 @@ private Optional getOperator(AtomicConstraint atomicConstraint, Map return Optional.of(operatorMapper.getOperatorDto(operator)); } - - public AtomicConstraint buildAtomicConstraint(UiPolicyConstraint constraint) { - var left = constraint.getLeft(); - var operator = operatorMapper.getOperator(constraint.getOperator()); - var right = literalMapper.getUiLiteralValue(constraint.getRight()); - - return AtomicConstraint.Builder.newInstance() - .leftExpression(new LiteralExpression(left)) - .operator(operator) - .rightExpression(new LiteralExpression(right)) - .build(); - } - - public AtomicConstraint buildAtomicConstraint(AtomicConstraintDto atomicConstraint) { - var left = atomicConstraint.getLeftExpression(); - var operator = operatorMapper.getOperator(atomicConstraint.getOperator()); - var right = atomicConstraint.getRightExpression(); - - return AtomicConstraint.Builder.newInstance() - .leftExpression(new LiteralExpression(left)) - .operator(operator) - .rightExpression(new LiteralExpression(right)) - .build(); - } } diff --git a/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/policy/ConstraintExtractor.java b/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/policy/ConstraintExtractor.java deleted file mode 100644 index 1ac5f3ca1..000000000 --- a/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/policy/ConstraintExtractor.java +++ /dev/null @@ -1,113 +0,0 @@ -/* - * Copyright (c) 2023 sovity GmbH - * - * 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 - * - * SPDX-License-Identifier: Apache-2.0 - * - * Contributors: - * sovity GmbH - init - */ - -package de.sovity.edc.ext.wrapper.api.common.mappers.policy; - -import de.sovity.edc.ext.wrapper.api.common.model.UiPolicyConstraint; -import lombok.RequiredArgsConstructor; -import org.eclipse.edc.policy.model.AndConstraint; -import org.eclipse.edc.policy.model.AtomicConstraint; -import org.eclipse.edc.policy.model.Constraint; -import org.eclipse.edc.policy.model.OrConstraint; -import org.eclipse.edc.policy.model.Permission; -import org.eclipse.edc.policy.model.Policy; -import org.eclipse.edc.policy.model.XoneConstraint; - -import java.util.ArrayList; -import java.util.List; -import java.util.Optional; - -@RequiredArgsConstructor -public class ConstraintExtractor { - private final PolicyValidator policyValidator; - private final AtomicConstraintMapper atomicConstraintMapper; - - /** - * Build {@link UiPolicyConstraint}s from an ODRL {@link Policy}. - *

- * This operation is lossy which is why we document warnings / errors in {@link MappingErrors}. - * - * @param policy ODRL policy - * @param errors mapping errors - * @return ui policy constraints - */ - public List getPermissionConstraints(Policy policy, MappingErrors errors) { - policyValidator.validateOtherPolicyFieldsUnset(policy, errors); - - var permissions = policy.getPermissions(); - if (permissions == null) { - return List.of(); - } - - - List constraints = new ArrayList<>(); - for (int iPermission = 0; iPermission < permissions.size(); iPermission++) { - var permissionErrors = errors.forChildObject("permissions").forChildArrayElement(iPermission); - var permission = permissions.get(iPermission); - constraints.addAll(getPermissionConstraints(permission, permissionErrors)); - } - return constraints; - } - - private List getPermissionConstraints(Permission permission, MappingErrors errors) { - policyValidator.validateOtherPermissionFieldsUnset(permission, errors); - - if (permission == null) { - return List.of(); - } - - var constraints = permission.getConstraints(); - if (constraints == null) { - return List.of(); - } - - var constraintsMapped = new ArrayList(); - for (int i = 0; i < constraints.size(); i++) { - var constraintErrors = errors.forChildObject("constraints").forChildArrayElement(i); - var constraint = constraints.get(i); - - var constraintMapped = buildConstraint(constraint, constraintErrors); - constraintMapped.ifPresent(constraintsMapped::add); - } - return constraintsMapped; - } - - private Optional buildConstraint(Constraint constraint, MappingErrors errors) { - if (constraint == null) { - errors.add("Constraint is null."); - return Optional.empty(); - } - - if (constraint instanceof XoneConstraint) { - errors.add("XoneConstraints are currently unsupported."); - return Optional.empty(); - } - - if (constraint instanceof AndConstraint) { - errors.add("AndConstraints are currently unsupported."); - return Optional.empty(); - } - - if (constraint instanceof OrConstraint) { - errors.add("OrConstraints are currently unsupported."); - return Optional.empty(); - } - - if (!(constraint instanceof AtomicConstraint)) { - errors.add("Unknown constraint type %s.".formatted(constraint.getClass().getName())); - return Optional.empty(); - } - - return atomicConstraintMapper.buildUiConstraint((AtomicConstraint) constraint, errors); - } -} diff --git a/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/policy/ExpressionExtractor.java b/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/policy/ExpressionExtractor.java new file mode 100644 index 000000000..010bcec4a --- /dev/null +++ b/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/policy/ExpressionExtractor.java @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2023 sovity GmbH + * + * 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 + * + * SPDX-License-Identifier: Apache-2.0 + * + * Contributors: + * sovity GmbH - init + */ + +package de.sovity.edc.ext.wrapper.api.common.mappers.policy; + +import de.sovity.edc.ext.wrapper.api.common.model.UiPolicyExpression; +import lombok.RequiredArgsConstructor; +import org.eclipse.edc.policy.model.Permission; +import org.eclipse.edc.policy.model.Policy; + +import java.util.ArrayList; +import java.util.List; + +@RequiredArgsConstructor +public class ExpressionExtractor { + private final PolicyValidator policyValidator; + private final ExpressionMapper expressionMapper; + + /** + * Build {@link UiPolicyExpression}s from an ODRL {@link Policy}. + *

+ * This operation is lossy which is why we document warnings / errors in {@link MappingErrors}. + * + * @param policy ODRL policy + * @param errors mapping errors + * @return ui policy expressions + */ + public List getPermissionExpressions(Policy policy, MappingErrors errors) { + policyValidator.validateOtherPolicyFieldsUnset(policy, errors); + + var permissions = policy.getPermissions(); + if (permissions == null) { + return List.of(); + } + + List expressions = new ArrayList<>(); + for (int iPermission = 0; iPermission < permissions.size(); iPermission++) { + var permissionErrors = errors.forChildObject("permissions").forChildArrayElement(iPermission); + var permission = permissions.get(iPermission); + expressions.addAll(getPermissionExpressions(permission, permissionErrors)); + } + return expressions; + } + + private List getPermissionExpressions(Permission permission, MappingErrors errors) { + policyValidator.validateOtherPermissionFieldsUnset(permission, errors); + + if (permission == null) { + return List.of(); + } + + return expressionMapper.buildUiPolicyExpressions( + permission.getConstraints(), + errors.forChildObject("constraints") + ); + } +} diff --git a/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/policy/ExpressionMapper.java b/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/policy/ExpressionMapper.java new file mode 100644 index 000000000..1957ac420 --- /dev/null +++ b/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/policy/ExpressionMapper.java @@ -0,0 +1,136 @@ +/* + * Copyright (c) 2023 sovity GmbH + * + * 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 + * + * SPDX-License-Identifier: Apache-2.0 + * + * Contributors: + * sovity GmbH - init + */ + +package de.sovity.edc.ext.wrapper.api.common.mappers.policy; + +import de.sovity.edc.ext.wrapper.api.common.model.UiPolicyConstraint; +import de.sovity.edc.ext.wrapper.api.common.model.UiPolicyExpression; +import de.sovity.edc.ext.wrapper.api.common.model.UiPolicyExpressionType; +import lombok.NonNull; +import lombok.RequiredArgsConstructor; +import org.eclipse.edc.policy.model.AndConstraint; +import org.eclipse.edc.policy.model.AtomicConstraint; +import org.eclipse.edc.policy.model.Constraint; +import org.eclipse.edc.policy.model.OrConstraint; +import org.eclipse.edc.policy.model.XoneConstraint; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; + +@RequiredArgsConstructor +public class ExpressionMapper { + private final AtomicConstraintMapper atomicConstraintMapper; + + public List buildConstraints( + @Nullable List expressions + ) { + if (expressions == null) { + return List.of(); + } + + return expressions.stream() + .map(this::buildConstraint) + .toList(); + } + + @NotNull + public List buildUiPolicyExpressions( + @Nullable List constraints, + @NonNull MappingErrors errors + ) { + if (constraints == null) { + errors.add("Constraints are null."); + return List.of(); + } + + var expressions = new ArrayList(); + for (int i = 0; i < constraints.size(); i++) { + var constraintErrors = errors.forChildArrayElement(i); + var constraint = constraints.get(i); + + buildUiPolicyExpression(constraint, constraintErrors).ifPresent(expressions::add); + } + return expressions; + } + + private Constraint buildConstraint(UiPolicyExpression expression) { + return switch (expression.getExpressionType()) { + case AND -> AndConstraint.Builder.newInstance() + .constraints(buildConstraints(expression.getExpressions())) + .build(); + case OR -> OrConstraint.Builder.newInstance() + .constraints(buildConstraints(expression.getExpressions())) + .build(); + case XOR -> XoneConstraint.Builder.newInstance() + .constraints(buildConstraints(expression.getExpressions())) + .build(); + case CONSTRAINT -> atomicConstraintMapper.buildAtomicConstraint(expression.getConstraint()); + }; + } + + private Optional buildUiPolicyExpression(Constraint constraint, MappingErrors errors) { + if (constraint == null) { + errors.add("Expression is null."); + return Optional.empty(); + } + + if (constraint instanceof XoneConstraint xone) { + return buildMultiUiPolicyExpression( + UiPolicyExpressionType.XOR, + xone.getConstraints(), + errors.forChildObject("constraints") + ); + } else if (constraint instanceof AndConstraint and) { + return buildMultiUiPolicyExpression( + UiPolicyExpressionType.AND, + and.getConstraints(), + errors.forChildObject("constraints") + ); + } else if (constraint instanceof OrConstraint or) { + return buildMultiUiPolicyExpression( + UiPolicyExpressionType.OR, + or.getConstraints(), + errors.forChildObject("constraints") + ); + } else if (constraint instanceof AtomicConstraint atomic) { + return atomicConstraintMapper.buildUiConstraint(atomic, errors) + .map(this::buildConstraintUiPolicyExpression); + } + + errors.add("Unknown expression type %s.".formatted(constraint.getClass().getName())); + return Optional.empty(); + } + + private Optional buildMultiUiPolicyExpression( + UiPolicyExpressionType type, + List constraints, + MappingErrors errors + ) { + var expressions = buildUiPolicyExpressions(constraints, errors); + var expression = UiPolicyExpression.builder() + .expressionType(type) + .expressions(expressions) + .build(); + return Optional.of(expression); + } + + private UiPolicyExpression buildConstraintUiPolicyExpression(UiPolicyConstraint constraint) { + return UiPolicyExpression.builder() + .expressionType(UiPolicyExpressionType.CONSTRAINT) + .constraint(constraint) + .build(); + } +} diff --git a/extensions/wrapper/wrapper-common-mappers/src/test/java/de/sovity/edc/ext/wrapper/api/common/mappers/PolicyMapperTest.java b/extensions/wrapper/wrapper-common-mappers/src/test/java/de/sovity/edc/ext/wrapper/api/common/mappers/PolicyMapperTest.java index 2d01fe7e7..e1f2e71a0 100644 --- a/extensions/wrapper/wrapper-common-mappers/src/test/java/de/sovity/edc/ext/wrapper/api/common/mappers/PolicyMapperTest.java +++ b/extensions/wrapper/wrapper-common-mappers/src/test/java/de/sovity/edc/ext/wrapper/api/common/mappers/PolicyMapperTest.java @@ -14,90 +14,81 @@ package de.sovity.edc.ext.wrapper.api.common.mappers; -import de.sovity.edc.ext.wrapper.api.common.mappers.policy.AtomicConstraintMapper; -import de.sovity.edc.ext.wrapper.api.common.mappers.policy.ConstraintExtractor; +import de.sovity.edc.ext.wrapper.api.common.mappers.policy.ExpressionExtractor; +import de.sovity.edc.ext.wrapper.api.common.mappers.policy.ExpressionMapper; import de.sovity.edc.ext.wrapper.api.common.mappers.policy.MappingErrors; -import de.sovity.edc.ext.wrapper.api.common.model.AtomicConstraintDto; -import de.sovity.edc.ext.wrapper.api.common.model.Expression; -import de.sovity.edc.ext.wrapper.api.common.model.ExpressionType; import de.sovity.edc.ext.wrapper.api.common.model.UiPolicyConstraint; import de.sovity.edc.ext.wrapper.api.common.model.UiPolicyCreateRequest; +import de.sovity.edc.ext.wrapper.api.common.model.UiPolicyExpression; +import jakarta.json.Json; import jakarta.json.JsonObject; -import lombok.SneakyThrows; +import org.eclipse.edc.policy.model.AndConstraint; import org.eclipse.edc.policy.model.AtomicConstraint; +import org.eclipse.edc.policy.model.Constraint; +import org.eclipse.edc.policy.model.OrConstraint; import org.eclipse.edc.policy.model.Policy; import org.eclipse.edc.policy.model.PolicyType; +import org.eclipse.edc.policy.model.XoneConstraint; import org.eclipse.edc.spi.result.Result; import org.eclipse.edc.transform.spi.TypeTransformerRegistry; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.ValueSource; import org.mockito.InjectMocks; import org.mockito.Mock; -import org.mockito.MockedStatic; import org.mockito.junit.jupiter.MockitoExtension; import java.util.List; -import static de.sovity.edc.ext.wrapper.api.common.model.ExpressionType.ATOMIC_CONSTRAINT; -import static de.sovity.edc.utils.JsonUtils.parseJsonObj; import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.mockStatic; import static org.mockito.Mockito.when; @ExtendWith(MockitoExtension.class) class PolicyMapperTest { @InjectMocks PolicyMapper policyMapper; - @Mock - TypeTransformerRegistry transformerRegistry; - + ExpressionExtractor expressionExtractor; @Mock - ConstraintExtractor constraintExtractor; - + ExpressionMapper expressionMapper; @Mock - AtomicConstraintMapper atomicConstraintMapper; - + TypeTransformerRegistry typeTransformerRegistry; @Test - @SneakyThrows - void test_buildPolicyDto() { - try (MockedStatic mappingErrors = mockStatic(MappingErrors.class)) { - // arrange - var policy = mock(Policy.class); - var errors = mock(MappingErrors.class); - var constraints = List.of(mock(UiPolicyConstraint.class)); + void buildUiPolicy() { + // arrange + var policy = mock(Policy.class); + var expression = mock(UiPolicyExpression.class); - when(errors.getErrors()).thenReturn(List.of("error1")); + when(expressionExtractor.getPermissionExpressions(eq(policy), any())).thenAnswer(i -> { + var errors = i.getArgument(1, MappingErrors.class); + errors.add("test"); + return List.of(expression); + }); - mappingErrors.when(MappingErrors::root).thenReturn(errors); - when(constraintExtractor.getPermissionConstraints(policy, errors)).thenReturn(constraints); - when(transformerRegistry.transform(policy, JsonObject.class)).thenReturn(Result.success(parseJsonObj("{}"))); + when(typeTransformerRegistry.transform(eq(policy), eq(JsonObject.class))) + .thenReturn(Result.success(Json.createObjectBuilder().add("a", "b").build())); - // act - var actual = policyMapper.buildUiPolicy(policy); + // act + var actual = policyMapper.buildUiPolicy(policy); - // assert - assertThat(actual.getPolicyJsonLd()).isEqualTo("{}"); - assertThat(actual.getConstraints()).isEqualTo(constraints); - assertThat(actual.getErrors()).isEqualTo(List.of("error1")); - } + // assert + assertThat(actual.getExpressions()).containsExactly(expression); + assertThat(actual.getErrors()).containsExactly("$: test"); + assertThat(actual.getPolicyJsonLd()).isEqualTo("{\"a\":\"b\"}"); } @Test - void test_buildPolicy() { + void buildPolicy() { // arrange - var constraint = mock(UiPolicyConstraint.class); - var createRequest = new UiPolicyCreateRequest(List.of(constraint)); + var uiExpression = mock(UiPolicyExpression.class); + var constraint = mock(Constraint.class); + when(expressionMapper.buildConstraints(eq(List.of(uiExpression)))) + .thenReturn(List.of(constraint)); - var expected = mock(AtomicConstraint.class); - when(atomicConstraintMapper.buildAtomicConstraints(eq(List.of(constraint)))) - .thenReturn(List.of(expected)); + var createRequest = new UiPolicyCreateRequest(List.of(uiExpression)); // act var actual = policyMapper.buildPolicy(createRequest); @@ -107,34 +98,6 @@ void test_buildPolicy() { assertThat(actual.getPermissions()).hasSize(1); assertThat(actual.getPermissions().get(0).getConstraints()).hasSize(1); assertThat(actual.getPermissions().get(0).getAction().getType()).isEqualTo("USE"); - assertThat(actual.getPermissions().get(0).getConstraints().get(0)).isSameAs(expected); - } - - @ParameterizedTest - @ValueSource(strings = {"AND", "OR", "XOR"}) - void buildGenericPolicy(String constraintTypeString) { - // arrange - var expressionType = ExpressionType.valueOf(constraintTypeString); - var incomingConstraint = mock(AtomicConstraintDto.class); - var mappedAtomicConstraint = mock(AtomicConstraint.class); - var atomicConstraint = new Expression(ATOMIC_CONSTRAINT, List.of(), incomingConstraint); - var atomicConstraints = List.of(atomicConstraint, atomicConstraint); - var baseConstraintElement = new Expression(expressionType, atomicConstraints, null); - - // act - when(atomicConstraintMapper - .buildAtomicConstraint(eq(incomingConstraint))) - .thenReturn(mappedAtomicConstraint); - var policy = policyMapper.buildPolicy(List.of(baseConstraintElement)); - - // assert - assertThat(policy.getType()).isEqualTo(PolicyType.SET); - assertThat(policy.getPermissions()).hasSize(1); - var permission = policy.getPermissions().get(0); - assertThat(permission.getConstraints()).hasSize(1); - assertThat(permission.getAction().getType()).isEqualTo("USE"); - - var constraintObject = permission.getConstraints().get(0); - assertNotNull(constraintObject); + assertThat(actual.getPermissions().get(0).getConstraints()).containsExactly(constraint); } } diff --git a/extensions/wrapper/wrapper-common-mappers/src/test/java/de/sovity/edc/ext/wrapper/api/common/mappers/policy/AtomicConstraintMapperTest.java b/extensions/wrapper/wrapper-common-mappers/src/test/java/de/sovity/edc/ext/wrapper/api/common/mappers/policy/AtomicConstraintMapperTest.java index 0a3b718f4..04eac28c7 100644 --- a/extensions/wrapper/wrapper-common-mappers/src/test/java/de/sovity/edc/ext/wrapper/api/common/mappers/policy/AtomicConstraintMapperTest.java +++ b/extensions/wrapper/wrapper-common-mappers/src/test/java/de/sovity/edc/ext/wrapper/api/common/mappers/policy/AtomicConstraintMapperTest.java @@ -38,18 +38,6 @@ class AtomicConstraintMapperTest { - @Test - void test_buildAtomicConstraint_null() { - // arrange - var atomicConstraintMapper = newAtomicConstraintMapper(); - - // act - var actual = atomicConstraintMapper.buildAtomicConstraints(null); - - // assert - assertThat(actual).isEmpty(); - } - @Test void test_buildAtomicConstraint() { // arrange @@ -62,16 +50,14 @@ void test_buildAtomicConstraint() { when(literalMapper.getUiLiteralValue(right)).thenReturn("right"); // act - var actual = atomicConstraintMapper.buildAtomicConstraints(List.of(constraint)); + var actual = atomicConstraintMapper.buildAtomicConstraint(constraint); // assert - assertThat(actual).hasSize(1); - var atomicConstraint = actual.get(0); - assertThat(atomicConstraint.getLeftExpression()).isInstanceOfSatisfying(LiteralExpression.class, literalExpression -> + assertThat(actual.getLeftExpression()).isInstanceOfSatisfying(LiteralExpression.class, literalExpression -> assertThat(literalExpression.getValue()).isEqualTo("left")); - assertThat(atomicConstraint.getRightExpression()).isInstanceOfSatisfying(LiteralExpression.class, literalExpression -> + assertThat(actual.getRightExpression()).isInstanceOfSatisfying(LiteralExpression.class, literalExpression -> assertThat(literalExpression.getValue()).isEqualTo("right")); - assertThat(atomicConstraint.getOperator()).isEqualTo(Operator.EQ); + assertThat(actual.getOperator()).isEqualTo(Operator.EQ); } @Test diff --git a/extensions/wrapper/wrapper-common-mappers/src/test/java/de/sovity/edc/ext/wrapper/api/common/mappers/policy/ConstraintExtractorTest.java b/extensions/wrapper/wrapper-common-mappers/src/test/java/de/sovity/edc/ext/wrapper/api/common/mappers/policy/ConstraintExtractorTest.java deleted file mode 100644 index 4f7730469..000000000 --- a/extensions/wrapper/wrapper-common-mappers/src/test/java/de/sovity/edc/ext/wrapper/api/common/mappers/policy/ConstraintExtractorTest.java +++ /dev/null @@ -1,107 +0,0 @@ -/* - * Copyright (c) 2022 sovity GmbH - * - * 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 - * - * SPDX-License-Identifier: Apache-2.0 - * - * Contributors: - * sovity GmbH - initial API and implementation - * - */ - -package de.sovity.edc.ext.wrapper.api.common.mappers.policy; - -import de.sovity.edc.ext.wrapper.api.common.mappers.policy.AtomicConstraintMapper; -import de.sovity.edc.ext.wrapper.api.common.mappers.policy.ConstraintExtractor; -import de.sovity.edc.ext.wrapper.api.common.mappers.policy.MappingErrors; -import de.sovity.edc.ext.wrapper.api.common.mappers.policy.PolicyValidator; -import de.sovity.edc.ext.wrapper.api.common.model.UiPolicyConstraint; -import org.eclipse.edc.policy.model.AndConstraint; -import org.eclipse.edc.policy.model.AtomicConstraint; -import org.eclipse.edc.policy.model.OrConstraint; -import org.eclipse.edc.policy.model.Permission; -import org.eclipse.edc.policy.model.Policy; -import org.eclipse.edc.policy.model.XoneConstraint; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.mockito.InjectMocks; -import org.mockito.Mock; -import org.mockito.junit.jupiter.MockitoExtension; - -import java.util.Optional; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.ArgumentMatchers.same; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - -@ExtendWith(MockitoExtension.class) -class ConstraintExtractorTest { - @InjectMocks - ConstraintExtractor constraintExtractor; - - @Mock - PolicyValidator policyValidator; - - @Mock - AtomicConstraintMapper atomicConstraintMapper; - - @Test - void test_getPermissionConstraints_null() { - // arrange - var policy = Policy.Builder.newInstance().build(); - var errors = MappingErrors.root(); - - // act - var actual = constraintExtractor.getPermissionConstraints(policy, errors); - - // assert - assertThat(actual).isEmpty(); - verify(policyValidator).validateOtherPolicyFieldsUnset(policy, errors); - } - - @Test - void test_getPermissionConstraints_many_constraints() { - // arrange - var first = mock(AtomicConstraint.class); - var other = mock(AtomicConstraint.class); - var permission = Permission.Builder.newInstance() - .constraint(null) - .constraint(first) - .constraint(other) - .constraint(mock(AndConstraint.class)) - .constraint(mock(OrConstraint.class)) - .constraint(mock(XoneConstraint.class)) - .build(); - var policy = Policy.Builder.newInstance() - .permission(null) - .permission(permission) - .permission(Permission.Builder.newInstance().build()) - .build(); - var errors = MappingErrors.root(); - - var expected = mock(UiPolicyConstraint.class); - when(atomicConstraintMapper.buildUiConstraint(same(first), any())).thenReturn(Optional.of(expected)); - when(atomicConstraintMapper.buildUiConstraint(same(other), any())).thenReturn(Optional.empty()); - - // act - var actual = constraintExtractor.getPermissionConstraints(policy, errors); - - // assert - verify(policyValidator).validateOtherPermissionFieldsUnset(same(permission), any()); - verify(policyValidator).validateOtherPermissionFieldsUnset(eq(null), any()); - assertThat(actual).containsExactly(expected); - assertThat(errors.getErrors()).containsExactlyInAnyOrder( - "$.permissions[1].constraints[0]: Constraint is null.", - "$.permissions[1].constraints[3]: AndConstraints are currently unsupported.", - "$.permissions[1].constraints[4]: OrConstraints are currently unsupported.", - "$.permissions[1].constraints[5]: XoneConstraints are currently unsupported." - ); - } -} diff --git a/extensions/wrapper/wrapper-common-mappers/src/test/java/de/sovity/edc/ext/wrapper/api/common/mappers/policy/ExpressionExtractorTest.java b/extensions/wrapper/wrapper-common-mappers/src/test/java/de/sovity/edc/ext/wrapper/api/common/mappers/policy/ExpressionExtractorTest.java new file mode 100644 index 000000000..e7a541e46 --- /dev/null +++ b/extensions/wrapper/wrapper-common-mappers/src/test/java/de/sovity/edc/ext/wrapper/api/common/mappers/policy/ExpressionExtractorTest.java @@ -0,0 +1,144 @@ +/* + * Copyright (c) 2022 sovity GmbH + * + * 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 + * + * SPDX-License-Identifier: Apache-2.0 + * + * Contributors: + * sovity GmbH - initial API and implementation + * + */ + +package de.sovity.edc.ext.wrapper.api.common.mappers.policy; + +import de.sovity.edc.ext.wrapper.api.common.model.UiPolicyExpression; +import org.eclipse.edc.policy.model.Constraint; +import org.eclipse.edc.policy.model.Permission; +import org.eclipse.edc.policy.model.Policy; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; + +import java.util.List; +import java.util.Optional; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.ArgumentMatchers.same; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +@ExtendWith(MockitoExtension.class) +class ExpressionExtractorTest { + @InjectMocks + ExpressionExtractor expressionExtractor; + + @Mock + PolicyValidator policyValidator; + + @Mock + ExpressionMapper expressionMapper; + + @Test + void test_getPermissionConstraints_null() { + // arrange + var policy = Policy.Builder.newInstance().build(); + var errors = MappingErrors.root(); + + // act + var actual = expressionExtractor.getPermissionExpressions(policy, errors); + + // assert + assertThat(actual).isEmpty(); + verify(policyValidator).validateOtherPolicyFieldsUnset(policy, errors); + } + + @Test + void test_getPermissionConstraints_no_constraints() { + // arrange + var permission = Permission.Builder.newInstance() + .build(); + var policy = Policy.Builder.newInstance() + .permissions(List.of(permission)) + .build(); + var errors = MappingErrors.root(); + + // act + var actual = expressionExtractor.getPermissionExpressions(policy, errors); + + // assert + assertThat(actual).isEmpty(); + verify(policyValidator).validateOtherPolicyFieldsUnset(policy, errors); + } + + @Test + void test_getPermissionConstraints_merge_constraints() { + // arrange + var first = mock(Constraint.class); + var firstPermission = Permission.Builder.newInstance() + .constraint(first) + .build(); + + var other = mock(Constraint.class); + var otherPermission = Permission.Builder.newInstance() + .constraint(other) + .build(); + + var policy = Policy.Builder.newInstance() + .permission(firstPermission) + .permission(otherPermission) + .build(); + var errors = MappingErrors.root(); + + var firstUiExpression = mock(UiPolicyExpression.class); + var otherUiExpression = mock(UiPolicyExpression.class); + when(expressionMapper.buildUiPolicyExpressions(eq(List.of(first)), any())).thenReturn(List.of(firstUiExpression)); + when(expressionMapper.buildUiPolicyExpressions(eq(List.of(other)), any())).thenReturn(List.of(otherUiExpression)); + + // act + var actual = expressionExtractor.getPermissionExpressions(policy, errors); + + // assert + verify(policyValidator).validateOtherPermissionFieldsUnset(same(firstPermission), any()); + verify(policyValidator).validateOtherPermissionFieldsUnset(same(otherPermission), any()); + assertThat(actual) + .usingRecursiveFieldByFieldElementComparator() + .containsExactly(firstUiExpression, otherUiExpression); + } + + @Test + void test_getPermissionConstraints_error_mapping() { + // arrange + var constraint = mock(Constraint.class); + var permission = Permission.Builder.newInstance() + .constraint(constraint) + .build(); + + var policy = Policy.Builder.newInstance() + .permission(permission) + .build(); + var errors = MappingErrors.root(); + + when(expressionMapper.buildUiPolicyExpressions(eq(List.of(constraint)), any())).thenAnswer(i -> { + i.getArgument(1, MappingErrors.class).add("test"); + return List.of(); + }); + + // act + var actual = expressionExtractor.getPermissionExpressions(policy, errors); + + // assert + verify(policyValidator).validateOtherPermissionFieldsUnset(same(permission), any()); + assertThat(actual).isEmpty(); + assertThat(errors.getErrors()).containsExactlyInAnyOrder( + "$.permissions[0].constraints: test" + ); + } +} diff --git a/extensions/wrapper/wrapper-common-mappers/src/test/java/de/sovity/edc/ext/wrapper/api/common/mappers/policy/ExpressionMapperTest.java b/extensions/wrapper/wrapper-common-mappers/src/test/java/de/sovity/edc/ext/wrapper/api/common/mappers/policy/ExpressionMapperTest.java new file mode 100644 index 000000000..82ae5b7d2 --- /dev/null +++ b/extensions/wrapper/wrapper-common-mappers/src/test/java/de/sovity/edc/ext/wrapper/api/common/mappers/policy/ExpressionMapperTest.java @@ -0,0 +1,252 @@ +/* + * Copyright (c) 2022 sovity GmbH + * + * 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 + * + * SPDX-License-Identifier: Apache-2.0 + * + * Contributors: + * sovity GmbH - initial API and implementation + * + */ + +package de.sovity.edc.ext.wrapper.api.common.mappers.policy; + +import de.sovity.edc.ext.wrapper.api.common.model.UiPolicyConstraint; +import de.sovity.edc.ext.wrapper.api.common.model.UiPolicyExpression; +import org.eclipse.edc.policy.model.AndConstraint; +import org.eclipse.edc.policy.model.AtomicConstraint; +import org.eclipse.edc.policy.model.Constraint; +import org.eclipse.edc.policy.model.OrConstraint; +import org.eclipse.edc.policy.model.XoneConstraint; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; + +import java.util.List; +import java.util.Optional; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.same; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +@ExtendWith(MockitoExtension.class) +class ExpressionMapperTest { + @InjectMocks + ExpressionMapper expressionMapper; + + @Mock + AtomicConstraintMapper atomicConstraintMapper; + + + @Test + void buildUiConstraint_errorPropagation() { + // arrange + var errors = MappingErrors.root(); + var atomicConstraint = mock(AtomicConstraint.class); + when(atomicConstraintMapper.buildUiConstraint(same(atomicConstraint), any())) + .thenAnswer(i -> { + i.getArgument(1, MappingErrors.class).add("test"); + return Optional.empty(); + }); + + var constraints = List.of(atomicConstraint); + + // act + var actual = expressionMapper.buildUiPolicyExpressions(constraints, errors); + + // assert + assertThat(actual).isEmpty(); + assertThat(errors.getErrors()).containsExactly("$[0]: test"); + } + + @Test + void buildUiConstraint_simpleAtomicConstraint() { + // arrange + var atomicConstraint = mock(AtomicConstraint.class); + var uiConstraint = mock(UiPolicyConstraint.class); + when(atomicConstraintMapper.buildUiConstraint(same(atomicConstraint), any())) + .thenReturn(Optional.of(uiConstraint)); + + var constraints = List.of(atomicConstraint); + + // act + var actual = expressionMapper.buildUiPolicyExpressions(constraints, MappingErrors.root()); + + // assert + assertThat(actual).containsExactly( + UiPolicyExpression.constraint(uiConstraint) + ); + } + + @Test + void buildUiConstraint_andConstraint() { + // arrange + var atomicConstraint = mock(AtomicConstraint.class); + var uiConstraint = mock(UiPolicyConstraint.class); + when(atomicConstraintMapper.buildUiConstraint(same(atomicConstraint), any())) + .thenReturn(Optional.of(uiConstraint)); + + var constraints = List.of( + AndConstraint.Builder.newInstance() + .constraint(atomicConstraint) + .build() + ); + + // act + var actual = expressionMapper.buildUiPolicyExpressions(constraints, MappingErrors.root()); + + // assert + assertThat(actual).containsExactly( + UiPolicyExpression.and(List.of( + UiPolicyExpression.constraint(uiConstraint) + )) + ); + } + + @Test + void buildUiConstraint_orConstraint() { + // arrange + var atomicConstraint = mock(AtomicConstraint.class); + var uiConstraint = mock(UiPolicyConstraint.class); + when(atomicConstraintMapper.buildUiConstraint(same(atomicConstraint), any())) + .thenReturn(Optional.of(uiConstraint)); + + var constraints = List.of( + OrConstraint.Builder.newInstance() + .constraint(atomicConstraint) + .build() + ); + + // act + var actual = expressionMapper.buildUiPolicyExpressions(constraints, MappingErrors.root()); + + // assert + assertThat(actual).containsExactly( + UiPolicyExpression.or(List.of( + UiPolicyExpression.constraint(uiConstraint) + )) + ); + } + + @Test + void buildUiConstraint_xoneConstraint() { + // arrange + var atomicConstraint = mock(AtomicConstraint.class); + var uiConstraint = mock(UiPolicyConstraint.class); + when(atomicConstraintMapper.buildUiConstraint(same(atomicConstraint), any())) + .thenReturn(Optional.of(uiConstraint)); + + var constraints = List.of( + OrConstraint.Builder.newInstance() + .constraint(atomicConstraint) + .build() + ); + + // act + var actual = expressionMapper.buildUiPolicyExpressions(constraints, MappingErrors.root()); + + // assert + assertThat(actual).containsExactly( + UiPolicyExpression.or(List.of( + UiPolicyExpression.constraint(uiConstraint) + )) + ); + } + + @Test + void buildConstraint_atomicConstraint() { + // arrange + var uiConstraint = mock(UiPolicyConstraint.class); + var expression = UiPolicyExpression.constraint(uiConstraint); + + var atomicConstraint = mock(AtomicConstraint.class); + when(atomicConstraintMapper.buildAtomicConstraint(uiConstraint)) + .thenReturn(atomicConstraint); + + // act + var actual = expressionMapper.buildConstraints(List.of(expression)); + + // assert + assertThat(actual).hasSize(1); + assertThat(actual.get(0)).isEqualTo(atomicConstraint); + } + + @Test + void buildConstraint_andConstraint() { + // arrange + var uiConstraint = mock(UiPolicyConstraint.class); + var expression = UiPolicyExpression.and(List.of( + UiPolicyExpression.constraint(uiConstraint) + )); + + var atomicConstraint = mock(AtomicConstraint.class); + when(atomicConstraintMapper.buildAtomicConstraint(uiConstraint)) + .thenReturn(atomicConstraint); + + // act + var actual = expressionMapper.buildConstraints(List.of(expression)); + + // assert + assertThat(actual).hasSize(1); + assertThat(actual.get(0)).isInstanceOf(AndConstraint.class); + + var constraints = ((AndConstraint) actual.get(0)).getConstraints(); + assertThat(constraints).hasSize(1); + assertThat(constraints.get(0)).isEqualTo(atomicConstraint); + } + + @Test + void buildConstraint_orConstraint() { + // arrange + var uiConstraint = mock(UiPolicyConstraint.class); + var expression = UiPolicyExpression.or(List.of( + UiPolicyExpression.constraint(uiConstraint) + )); + + var atomicConstraint = mock(AtomicConstraint.class); + when(atomicConstraintMapper.buildAtomicConstraint(uiConstraint)) + .thenReturn(atomicConstraint); + + // act + var actual = expressionMapper.buildConstraints(List.of(expression)); + + // assert + assertThat(actual).hasSize(1); + assertThat(actual.get(0)).isInstanceOf(OrConstraint.class); + + var constraints = ((OrConstraint) actual.get(0)).getConstraints(); + assertThat(constraints).hasSize(1); + assertThat(constraints.get(0)).isEqualTo(atomicConstraint); + } + + @Test + void buildConstraint_xoneConstraint() { + // arrange + var uiConstraint = mock(UiPolicyConstraint.class); + var expression = UiPolicyExpression.xor(List.of( + UiPolicyExpression.constraint(uiConstraint) + )); + + var atomicConstraint = mock(AtomicConstraint.class); + when(atomicConstraintMapper.buildAtomicConstraint(uiConstraint)) + .thenReturn(atomicConstraint); + + // act + var actual = expressionMapper.buildConstraints(List.of(expression)); + + // assert + assertThat(actual).hasSize(1); + assertThat(actual.get(0)).isInstanceOf(XoneConstraint.class); + + var constraints = ((XoneConstraint) actual.get(0)).getConstraints(); + assertThat(constraints).hasSize(1); + assertThat(constraints.get(0)).isEqualTo(atomicConstraint); + } +} diff --git a/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/WrapperExtensionContextBuilder.java b/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/WrapperExtensionContextBuilder.java index 36074d5ed..334e9d6ab 100644 --- a/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/WrapperExtensionContextBuilder.java +++ b/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/WrapperExtensionContextBuilder.java @@ -28,7 +28,8 @@ import de.sovity.edc.ext.wrapper.api.common.mappers.dataaddress.http.HttpDataSourceMapper; import de.sovity.edc.ext.wrapper.api.common.mappers.dataaddress.http.HttpHeaderMapper; import de.sovity.edc.ext.wrapper.api.common.mappers.policy.AtomicConstraintMapper; -import de.sovity.edc.ext.wrapper.api.common.mappers.policy.ConstraintExtractor; +import de.sovity.edc.ext.wrapper.api.common.mappers.policy.ExpressionExtractor; +import de.sovity.edc.ext.wrapper.api.common.mappers.policy.ExpressionMapper; import de.sovity.edc.ext.wrapper.api.common.mappers.policy.LiteralMapper; import de.sovity.edc.ext.wrapper.api.common.mappers.policy.OperatorMapper; import de.sovity.edc.ext.wrapper.api.common.mappers.policy.PolicyValidator; @@ -109,217 +110,227 @@ public class WrapperExtensionContextBuilder { public static WrapperExtensionContext buildContext( - AssetIndex assetIndex, - AssetService assetService, - CatalogService catalogService, - Config config, - ContractAgreementService contractAgreementService, - ContractDefinitionService contractDefinitionService, - ContractDefinitionStore contractDefinitionStore, - ContractNegotiationService contractNegotiationService, - ContractNegotiationStore contractNegotiationStore, - JsonLd jsonLd, - Monitor monitor, - ObjectMapper objectMapper, - PolicyDefinitionService policyDefinitionService, - PolicyDefinitionStore policyDefinitionStore, - PolicyEngine policyEngine, - TransferProcessService transferProcessService, - TransferProcessStore transferProcessStore, - TypeTransformerRegistry typeTransformerRegistry + AssetIndex assetIndex, + AssetService assetService, + CatalogService catalogService, + Config config, + ContractAgreementService contractAgreementService, + ContractDefinitionService contractDefinitionService, + ContractDefinitionStore contractDefinitionStore, + ContractNegotiationService contractNegotiationService, + ContractNegotiationStore contractNegotiationStore, + JsonLd jsonLd, + Monitor monitor, + ObjectMapper objectMapper, + PolicyDefinitionService policyDefinitionService, + PolicyDefinitionStore policyDefinitionStore, + PolicyEngine policyEngine, + TransferProcessService transferProcessService, + TransferProcessStore transferProcessStore, + TypeTransformerRegistry typeTransformerRegistry ) { // UI API var operatorMapper = new OperatorMapper(); var criterionOperatorMapper = new CriterionOperatorMapper(); var criterionLiteralMapper = new CriterionLiteralMapper(); var criterionMapper = new CriterionMapper(criterionOperatorMapper, criterionLiteralMapper); - var literalMapper = new LiteralMapper(objectMapper); - var atomicConstraintMapper = new AtomicConstraintMapper(literalMapper, operatorMapper); - var policyValidator = new PolicyValidator(); - var constraintExtractor = new ConstraintExtractor(policyValidator, atomicConstraintMapper); - var policyMapper = new PolicyMapper( - constraintExtractor, - atomicConstraintMapper, - typeTransformerRegistry); var edcPropertyUtils = new EdcPropertyUtils(); var selfDescriptionService = new SelfDescriptionService(config, monitor); var ownConnectorEndpointService = new OwnConnectorEndpointServiceImpl(selfDescriptionService); var assetMapper = newAssetMapper(typeTransformerRegistry, jsonLd, ownConnectorEndpointService); + var policyMapper = newPolicyMapper(objectMapper, typeTransformerRegistry, operatorMapper); var transferProcessStateService = new TransferProcessStateService(); var contractNegotiationUtils = new ContractNegotiationUtils( - contractNegotiationService, - selfDescriptionService + contractNegotiationService, + selfDescriptionService ); var contractAgreementPageCardBuilder = new ContractAgreementPageCardBuilder( - policyMapper, - transferProcessStateService, - assetMapper, - contractNegotiationUtils + policyMapper, + transferProcessStateService, + assetMapper, + contractNegotiationUtils ); var contractAgreementDataFetcher = new ContractAgreementDataFetcher( - contractAgreementService, - contractNegotiationStore, - transferProcessService, - assetIndex + contractAgreementService, + contractNegotiationStore, + transferProcessService, + assetIndex ); var contractAgreementApiService = new ContractAgreementPageApiService( - contractAgreementDataFetcher, - contractAgreementPageCardBuilder + contractAgreementDataFetcher, + contractAgreementPageCardBuilder ); var contactDefinitionBuilder = new ContractDefinitionBuilder(criterionMapper); var contractDefinitionApiService = new ContractDefinitionApiService( - contractDefinitionService, - criterionMapper, - contactDefinitionBuilder); + contractDefinitionService, + criterionMapper, + contactDefinitionBuilder); var transferHistoryPageApiService = new TransferHistoryPageApiService( - assetService, - contractAgreementService, - contractNegotiationStore, - transferProcessService, - transferProcessStateService + assetService, + contractAgreementService, + contractNegotiationStore, + transferProcessService, + transferProcessStateService ); var transferHistoryPageAssetFetcherService = new TransferHistoryPageAssetFetcherService( - assetService, - transferProcessService, - assetMapper, - contractNegotiationStore, - contractNegotiationUtils + assetService, + transferProcessService, + assetMapper, + contractNegotiationStore, + contractNegotiationUtils ); var contractAgreementUtils = new ContractAgreementUtils(contractAgreementService); var parameterizationCompatibilityUtils = new ParameterizationCompatibilityUtils(); var assetIdValidator = new AssetIdValidator(); var assetApiService = new AssetApiService( - assetService, - assetMapper, - assetIdValidator, - selfDescriptionService + assetService, + assetMapper, + assetIdValidator, + selfDescriptionService ); var transferRequestBuilder = new TransferRequestBuilder( - contractAgreementUtils, - contractNegotiationUtils, - edcPropertyUtils, - typeTransformerRegistry, - parameterizationCompatibilityUtils + contractAgreementUtils, + contractNegotiationUtils, + edcPropertyUtils, + typeTransformerRegistry, + parameterizationCompatibilityUtils ); var contractAgreementTransferApiService = new ContractAgreementTransferApiService( - transferRequestBuilder, - transferProcessService + transferRequestBuilder, + transferProcessService ); var policyDefinitionApiService = new PolicyDefinitionApiService( - policyDefinitionService, - policyMapper + policyDefinitionService, + policyMapper ); var dataOfferBuilder = new DspDataOfferBuilder(jsonLd); var uiDataOfferBuilder = new UiDataOfferBuilder(assetMapper, policyMapper); var dspCatalogService = new DspCatalogService(catalogService, dataOfferBuilder); var catalogApiService = new CatalogApiService( - uiDataOfferBuilder, - dspCatalogService + uiDataOfferBuilder, + dspCatalogService ); var contractOfferMapper = new ContractOfferMapper(policyMapper); var contractNegotiationBuilder = new ContractNegotiationBuilder(contractOfferMapper); var contractNegotiationStateService = new ContractNegotiationStateService(); var contractNegotiationApiService = new ContractNegotiationApiService( - contractNegotiationService, - contractNegotiationBuilder, - contractNegotiationStateService + contractNegotiationService, + contractNegotiationBuilder, + contractNegotiationStateService ); var miwConfigBuilder = new MiwConfigService(config); var dapsConfigBuilder = new DapsConfigService(config); var dashboardDataFetcher = new DashboardDataFetcher( - contractNegotiationStore, - transferProcessService, - assetIndex, - policyDefinitionService, - contractDefinitionService + contractNegotiationStore, + transferProcessService, + assetIndex, + policyDefinitionService, + contractDefinitionService ); var dashboardApiService = new DashboardPageApiService( - dashboardDataFetcher, - transferProcessStateService, - dapsConfigBuilder, - miwConfigBuilder, - selfDescriptionService + dashboardDataFetcher, + transferProcessStateService, + dapsConfigBuilder, + miwConfigBuilder, + selfDescriptionService ); var uiResource = new UiResourceImpl( - contractAgreementApiService, - contractAgreementTransferApiService, - transferHistoryPageApiService, - transferHistoryPageAssetFetcherService, - assetApiService, - policyDefinitionApiService, - catalogApiService, - contractDefinitionApiService, - contractNegotiationApiService, - dashboardApiService + contractAgreementApiService, + contractAgreementTransferApiService, + transferHistoryPageApiService, + transferHistoryPageAssetFetcherService, + assetApiService, + policyDefinitionApiService, + catalogApiService, + contractDefinitionApiService, + contractNegotiationApiService, + dashboardApiService ); // Use Case API var filterExpressionOperatorMapper = new FilterExpressionOperatorMapper(); var filterExpressionLiteralMapper = new FilterExpressionLiteralMapper(); var filterExpressionMapper = new FilterExpressionMapper( - filterExpressionOperatorMapper, - filterExpressionLiteralMapper + filterExpressionOperatorMapper, + filterExpressionLiteralMapper ); var kpiApiService = new KpiApiService( - assetIndex, - policyDefinitionStore, - contractDefinitionStore, - transferProcessStore, - contractAgreementService, - transferProcessStateService + assetIndex, + policyDefinitionStore, + contractDefinitionStore, + transferProcessStore, + contractAgreementService, + transferProcessStateService ); var supportedPolicyApiService = new SupportedPolicyApiService(policyEngine); var useCaseCatalogApiService = new UseCaseCatalogApiService( - uiDataOfferBuilder, - dspCatalogService, - filterExpressionMapper + uiDataOfferBuilder, + dspCatalogService, + filterExpressionMapper ); var useCaseResource = new UseCaseResourceImpl( - kpiApiService, - supportedPolicyApiService, - useCaseCatalogApiService, - policyDefinitionApiService + kpiApiService, + supportedPolicyApiService, + useCaseCatalogApiService ); // Collect all JAX-RS resources return new WrapperExtensionContext(List.of( - uiResource, - useCaseResource + uiResource, + useCaseResource ), selfDescriptionService); } @NotNull private static AssetMapper newAssetMapper( - TypeTransformerRegistry typeTransformerRegistry, - JsonLd jsonLd, - OwnConnectorEndpointService ownConnectorEndpointService + TypeTransformerRegistry typeTransformerRegistry, + JsonLd jsonLd, + OwnConnectorEndpointService ownConnectorEndpointService ) { var edcPropertyUtils = new EdcPropertyUtils(); var assetJsonLdUtils = new AssetJsonLdUtils(); var assetEditRequestMapper = new AssetEditRequestMapper(); var shortDescriptionBuilder = new ShortDescriptionBuilder(); var assetJsonLdParser = new AssetJsonLdParser( - assetJsonLdUtils, - shortDescriptionBuilder, - ownConnectorEndpointService + assetJsonLdUtils, + shortDescriptionBuilder, + ownConnectorEndpointService ); var httpHeaderMapper = new HttpHeaderMapper(); var httpDataSourceMapper = new HttpDataSourceMapper(httpHeaderMapper); var dataSourceMapper = new DataSourceMapper( - edcPropertyUtils, - httpDataSourceMapper + edcPropertyUtils, + httpDataSourceMapper ); var assetJsonLdBuilder = new AssetJsonLdBuilder( - dataSourceMapper, - assetJsonLdParser, - assetEditRequestMapper + dataSourceMapper, + assetJsonLdParser, + assetEditRequestMapper ); return new AssetMapper( - typeTransformerRegistry, - assetJsonLdBuilder, - assetJsonLdParser, - jsonLd + typeTransformerRegistry, + assetJsonLdBuilder, + assetJsonLdParser, + jsonLd + ); + } + + @NotNull + private static PolicyMapper newPolicyMapper( + ObjectMapper objectMapper, + TypeTransformerRegistry typeTransformerRegistry, + OperatorMapper operatorMapper + ) { + var literalMapper = new LiteralMapper(objectMapper); + var atomicConstraintMapper = new AtomicConstraintMapper(literalMapper, operatorMapper); + var policyValidator = new PolicyValidator(); + var expressionMapper = new ExpressionMapper(atomicConstraintMapper); + var constraintExtractor = new ExpressionExtractor(policyValidator, expressionMapper); + return new PolicyMapper( + constraintExtractor, + expressionMapper, + typeTransformerRegistry ); } } diff --git a/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/UiResourceImpl.java b/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/UiResourceImpl.java index 872c4a651..e4189e936 100644 --- a/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/UiResourceImpl.java +++ b/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/UiResourceImpl.java @@ -14,7 +14,7 @@ package de.sovity.edc.ext.wrapper.api.ui; -import de.sovity.edc.ext.wrapper.api.common.model.PolicyDefinitionCreateRequest; +import de.sovity.edc.ext.wrapper.api.ui.model.PolicyDefinitionCreateRequest; import de.sovity.edc.ext.wrapper.api.common.model.UiAsset; import de.sovity.edc.ext.wrapper.api.common.model.UiAssetCreateRequest; import de.sovity.edc.ext.wrapper.api.common.model.UiAssetEditRequest; diff --git a/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/pages/policy/PolicyDefinitionApiService.java b/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/pages/policy/PolicyDefinitionApiService.java index e63b10170..9b97085a1 100644 --- a/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/pages/policy/PolicyDefinitionApiService.java +++ b/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/pages/policy/PolicyDefinitionApiService.java @@ -17,10 +17,9 @@ import de.sovity.edc.ext.wrapper.api.ServiceException; import de.sovity.edc.ext.wrapper.api.common.mappers.PolicyMapper; -import de.sovity.edc.ext.wrapper.api.usecase.model.PolicyCreateRequest; -import de.sovity.edc.ext.wrapper.api.common.model.PolicyDefinitionCreateRequest; -import de.sovity.edc.ext.wrapper.api.common.model.PolicyDefinitionDto; import de.sovity.edc.ext.wrapper.api.ui.model.IdResponseDto; +import de.sovity.edc.ext.wrapper.api.ui.model.PolicyDefinitionCreateRequest; +import de.sovity.edc.ext.wrapper.api.ui.model.PolicyDefinitionDto; import jakarta.validation.constraints.NotNull; import lombok.RequiredArgsConstructor; import org.eclipse.edc.connector.policy.spi.PolicyDefinition; @@ -40,9 +39,9 @@ public class PolicyDefinitionApiService { public List getPolicyDefinitions() { var policyDefinitions = getAllPolicyDefinitions(); return policyDefinitions.stream() - .sorted(Comparator.comparing(PolicyDefinition::getCreatedAt).reversed()) - .map(this::buildPolicyDefinitionDto) - .toList(); + .sorted(Comparator.comparing(PolicyDefinition::getCreatedAt).reversed()) + .map(this::buildPolicyDefinitionDto) + .toList(); } @NotNull @@ -61,34 +60,20 @@ public IdResponseDto deletePolicyDefinition(String policyDefinitionId) { private List getAllPolicyDefinitions() { return policyDefinitionService.query(QuerySpec.max()).orElseThrow(ServiceException::new).toList(); } + public PolicyDefinitionDto buildPolicyDefinitionDto(PolicyDefinition policyDefinition) { var policy = policyMapper.buildUiPolicy(policyDefinition.getPolicy()); return PolicyDefinitionDto.builder() - .policyDefinitionId(policyDefinition.getId()) - .policy(policy) - .build(); + .policyDefinitionId(policyDefinition.getId()) + .policy(policy) + .build(); } public PolicyDefinition buildPolicyDefinition(PolicyDefinitionCreateRequest policyDefinitionDto) { var policy = policyMapper.buildPolicy(policyDefinitionDto.getPolicy()); return PolicyDefinition.Builder.newInstance() - .id(policyDefinitionDto.getPolicyDefinitionId()) - .policy(policy) - .build(); - } - - public IdResponseDto createPolicyDefinition(PolicyCreateRequest policyCreateRequest) { - var policyDefinition = buildPolicyDefinition(policyCreateRequest); - policyDefinition = policyDefinitionService.create(policyDefinition).orElseThrow(ServiceException::new); - return new IdResponseDto(policyDefinition.getId()); - } - - private PolicyDefinition buildPolicyDefinition(PolicyCreateRequest policyCreateRequest) { - var permissionExpression = policyCreateRequest.getPermission().getExpression(); - var policy = policyMapper.buildPolicy(List.of(permissionExpression)); - return PolicyDefinition.Builder.newInstance() - .id(policyCreateRequest.getPolicyDefinitionId()) - .policy(policy) - .build(); + .id(policyDefinitionDto.getPolicyDefinitionId()) + .policy(policy) + .build(); } } diff --git a/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/usecase/UseCaseResourceImpl.java b/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/usecase/UseCaseResourceImpl.java index c743faa64..7f1bf7d74 100644 --- a/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/usecase/UseCaseResourceImpl.java +++ b/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/usecase/UseCaseResourceImpl.java @@ -14,10 +14,7 @@ package de.sovity.edc.ext.wrapper.api.usecase; -import de.sovity.edc.ext.wrapper.api.usecase.model.PolicyCreateRequest; -import de.sovity.edc.ext.wrapper.api.ui.model.IdResponseDto; import de.sovity.edc.ext.wrapper.api.ui.model.UiDataOffer; -import de.sovity.edc.ext.wrapper.api.ui.pages.policy.PolicyDefinitionApiService; import de.sovity.edc.ext.wrapper.api.usecase.model.CatalogQuery; import de.sovity.edc.ext.wrapper.api.usecase.model.KpiResult; import de.sovity.edc.ext.wrapper.api.usecase.pages.catalog.UseCaseCatalogApiService; @@ -36,7 +33,6 @@ public class UseCaseResourceImpl implements UseCaseResource { private final KpiApiService kpiApiService; private final SupportedPolicyApiService supportedPolicyApiService; private final UseCaseCatalogApiService useCaseCatalogApiService; - private final PolicyDefinitionApiService policyDefinitionApiService; @Override public KpiResult getKpis() { @@ -52,9 +48,4 @@ public List getSupportedFunctions() { public List queryCatalog(CatalogQuery catalogQuery) { return useCaseCatalogApiService.fetchDataOffers(catalogQuery); } - - @Override - public IdResponseDto createPolicyDefinitionUseCase(PolicyCreateRequest policyCreateRequest) { - return policyDefinitionApiService.createPolicyDefinition(policyCreateRequest); - } } From 9df37c4e6e52c738534985cc964fadadce689c30 Mon Sep 17 00:00:00 2001 From: Richard Treier Date: Tue, 16 Jul 2024 13:53:48 +0300 Subject: [PATCH 04/18] chore: fix build --- .../de/sovity/edc/ext/wrapper/api/usecase/UseCaseResource.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/usecase/UseCaseResource.java b/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/usecase/UseCaseResource.java index c8cd2d049..988f89bef 100644 --- a/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/usecase/UseCaseResource.java +++ b/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/usecase/UseCaseResource.java @@ -14,11 +14,9 @@ package de.sovity.edc.ext.wrapper.api.usecase; -import de.sovity.edc.ext.wrapper.api.ui.model.IdResponseDto; import de.sovity.edc.ext.wrapper.api.ui.model.UiDataOffer; import de.sovity.edc.ext.wrapper.api.usecase.model.CatalogQuery; import de.sovity.edc.ext.wrapper.api.usecase.model.KpiResult; -import de.sovity.edc.ext.wrapper.api.usecase.model.PolicyCreateRequest; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.validation.Valid; From 463753572749a4c50717913dd5ee6c4b9798eb3f Mon Sep 17 00:00:00 2001 From: Richard Treier Date: Tue, 16 Jul 2024 14:30:58 +0300 Subject: [PATCH 05/18] fix: tests --- docs/api/sovity-edc-api-wrapper.yaml | 145 ++---- .../ext/catalog/crawler/CrawlerE2eTest.java | 13 +- .../PolicyDefinitionApiServiceTest.java | 117 ----- .../de/sovity/edc/e2e/ApiWrapperDemoTest.java | 126 ++--- .../e2e/DataSourceParameterizationTest.java | 304 +++++------ .../edc/e2e/DataSourceQueryParamsTest.java | 76 +-- .../edc/e2e/ManagementApiTransferTest.java | 8 +- .../edc/e2e/Ms8ConnectorMigrationTest.java | 38 +- .../de/sovity/edc/e2e/UiApiWrapperTest.java | 487 +++++++++--------- .../sovity/edc/e2e/UseCaseApiWrapperTest.java | 96 ++-- 10 files changed, 642 insertions(+), 768 deletions(-) delete mode 100644 extensions/wrapper/wrapper/src/test/java/de/sovity/edc/ext/wrapper/api/usecase/PolicyDefinitionApiServiceTest.java diff --git a/docs/api/sovity-edc-api-wrapper.yaml b/docs/api/sovity-edc-api-wrapper.yaml index 13d5135d1..51b2dab1e 100644 --- a/docs/api/sovity-edc-api-wrapper.yaml +++ b/docs/api/sovity-edc-api-wrapper.yaml @@ -437,24 +437,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: @@ -661,8 +643,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 @@ -680,8 +662,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 @@ -732,7 +714,7 @@ 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 @@ -841,7 +823,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 @@ -881,18 +864,45 @@ 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 UiPolicyCreateRequest: type: object properties: - constraints: + expressions: type: array description: Conjunction of required expressions for the policy to evaluate to 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. + $ref: '#/components/schemas/UiPolicyExpression' + description: Type-Safe OpenAPI generator friendly ODLR policy subset as endorsed + by sovity. + UiPolicyExpression: + type: object + properties: + expressionType: + $ref: '#/components/schemas/UiPolicyExpressionType' + expressions: + type: array + description: "Only for types AND, OR, XOR. 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: + * `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 + * `CONSTRAINT` - A single constraint for the policy + enum: + - AND + - OR + - XOR + - CONSTRAINT UiPolicyLiteral: required: - type @@ -1029,7 +1039,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 @@ -1216,7 +1227,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 @@ -1261,12 +1273,12 @@ components: type: string description: EDC Policy JSON-LD. This is required because the EDC requires the full policy when initiating contract negotiations. - constraints: + expressions: type: array description: Conjunction of required expressions for the policy to evaluate to TRUE. items: - $ref: '#/components/schemas/UiPolicyConstraint' + $ref: '#/components/schemas/UiPolicyExpression' errors: type: array description: "When trying to reduce the policy JSON-LD to our opinionated\ @@ -1279,8 +1291,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 @@ -1797,69 +1809,6 @@ components: type: string description: A user explanation to detail why the 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 diff --git a/extensions/catalog-crawler/catalog-crawler-e2e-test/src/test/java/de/sovity/edc/ext/catalog/crawler/CrawlerE2eTest.java b/extensions/catalog-crawler/catalog-crawler-e2e-test/src/test/java/de/sovity/edc/ext/catalog/crawler/CrawlerE2eTest.java index 3fedd0961..87c306cff 100644 --- a/extensions/catalog-crawler/catalog-crawler-e2e-test/src/test/java/de/sovity/edc/ext/catalog/crawler/CrawlerE2eTest.java +++ b/extensions/catalog-crawler/catalog-crawler-e2e-test/src/test/java/de/sovity/edc/ext/catalog/crawler/CrawlerE2eTest.java @@ -27,6 +27,8 @@ 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; @@ -48,6 +50,8 @@ import java.util.List; import java.util.concurrent.TimeUnit; import java.util.function.Consumer; +import java.util.stream.Collectors; +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; @@ -190,10 +194,17 @@ private void createPolicy() { .build()) .build(); + var expressions = Stream.of(afterYesterday, beforeTomorrow) + .map(it -> UiPolicyExpression.builder() + .expressionType(UiPolicyExpressionType.CONSTRAINT) + .constraint(it) + .build()) + .toList(); + var policyDefinition = PolicyDefinitionCreateRequest.builder() .policyDefinitionId(dataOfferId) .policy(UiPolicyCreateRequest.builder() - .constraints(List.of(afterYesterday, beforeTomorrow)) + .expressions(expressions) .build()) .build(); diff --git a/extensions/wrapper/wrapper/src/test/java/de/sovity/edc/ext/wrapper/api/usecase/PolicyDefinitionApiServiceTest.java b/extensions/wrapper/wrapper/src/test/java/de/sovity/edc/ext/wrapper/api/usecase/PolicyDefinitionApiServiceTest.java deleted file mode 100644 index e411e36a2..000000000 --- a/extensions/wrapper/wrapper/src/test/java/de/sovity/edc/ext/wrapper/api/usecase/PolicyDefinitionApiServiceTest.java +++ /dev/null @@ -1,117 +0,0 @@ -package de.sovity.edc.ext.wrapper.api.usecase; - -import de.sovity.edc.client.EdcClient; -import de.sovity.edc.client.gen.model.AtomicConstraintDto; -import de.sovity.edc.client.gen.model.Expression; -import de.sovity.edc.client.gen.model.OperatorDto; -import de.sovity.edc.client.gen.model.PermissionDto; -import de.sovity.edc.client.gen.model.PolicyCreateRequest; -import de.sovity.edc.client.gen.model.PolicyDefinitionDto; -import de.sovity.edc.ext.wrapper.TestUtils; -import de.sovity.edc.utils.jsonld.vocab.Prop; -import jakarta.json.Json; -import jakarta.json.JsonObject; -import org.eclipse.edc.junit.annotations.ApiTest; -import org.eclipse.edc.junit.extensions.EdcExtension; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; - -import java.io.StringReader; -import java.util.List; -import java.util.Optional; -import java.util.UUID; - -import static de.sovity.edc.client.gen.model.ExpressionType.AND; -import static de.sovity.edc.client.gen.model.ExpressionType.ATOMIC_CONSTRAINT; -import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.assertEquals; - - -@ApiTest -@ExtendWith(EdcExtension.class) -public class PolicyDefinitionApiServiceTest { - - private EdcClient client; - - @BeforeEach - void setUp(EdcExtension extension) { - TestUtils.setupExtension(extension); - client = TestUtils.edcClient(); - } - - @Test - void createTraceXPolicy() { - // arrange - var policyId = UUID.randomUUID().toString(); - var membershipElement = buildAtomicElement("Membership", OperatorDto.EQ, "active"); - var purposeElement = buildAtomicElement("PURPOSE", OperatorDto.EQ, "ID 3.1 Trace"); - var andElement = new Expression() - .expressionType(AND) - .expressions(List.of(membershipElement, purposeElement)); - var permissionDto = new PermissionDto(andElement); - var createRequest = new PolicyCreateRequest(policyId, permissionDto); - - // act - var response = client.useCaseApi().createPolicyDefinitionUseCase(createRequest); - - // assert - assertThat(response.getId()).isEqualTo(policyId); - var policyById = getPolicyById(policyId); - assertThat(policyById).isPresent(); - var policyDefinitionDto = policyById.get(); - assertEquals(policyId, policyDefinitionDto.getPolicyDefinitionId()); - assertPolicyJsonLd(policyDefinitionDto); - } - - private void assertPolicyJsonLd(PolicyDefinitionDto policyDefinitionDto) { - var permission = getPermissionJsonObject(policyDefinitionDto.getPolicy().getPolicyJsonLd()); - var action = permission.get(Prop.Odrl.ACTION); - assertEquals(Prop.Odrl.USE, action.asJsonObject().getString(Prop.Odrl.TYPE)); - - var permissionConstraints = permission.get(Prop.Odrl.CONSTRAINT).asJsonArray(); - assertThat(permissionConstraints).hasSize(1); - var andConstraint = permissionConstraints.get(0).asJsonObject(); - var andConstraints = andConstraint.get(Prop.Odrl.AND).asJsonArray(); - assertThat(andConstraints).hasSize(2); - - var membershipConstraint = andConstraints.get(0).asJsonObject(); - var purposeConstraint = andConstraints.get(1).asJsonObject(); - assertAtomicConstraint(membershipConstraint, "Membership", "active"); - assertAtomicConstraint(purposeConstraint, "PURPOSE", "ID 3.1 Trace"); - } - - private static JsonObject getPermissionJsonObject(String policyJsonLdString) { - var jsonReader = Json.createReader(new StringReader(policyJsonLdString)); - var jsonObject = jsonReader.readObject(); - var permissionList = jsonObject.get(Prop.Odrl.PERMISSION); - return permissionList.asJsonArray().get(0).asJsonObject(); - } - - private void assertAtomicConstraint(JsonObject atomicConstraint, String left, String right) { - var leftOperand = atomicConstraint.getJsonObject(Prop.Odrl.LEFT_OPERAND); - assertEquals(left, leftOperand.getString("@value")); - var rightOperand = atomicConstraint.getJsonObject(Prop.Odrl.RIGHT_OPERAND); - assertEquals(right, rightOperand.getString("@value")); - } - - private Expression buildAtomicElement( - String left, - OperatorDto operator, - String right) { - var atomicConstraint = new AtomicConstraintDto() - .leftExpression(left) - .operator(operator) - .rightExpression(right); - return new Expression() - .expressionType(ATOMIC_CONSTRAINT) - .atomicConstraint(atomicConstraint); - } - - private Optional getPolicyById(String policyId) { - var policyDefinitionsResponse = client.uiApi().getPolicyDefinitionPage(); - return policyDefinitionsResponse.getPolicies().stream() - .filter(policy -> policy.getPolicyDefinitionId().equals(policyId)) - .findFirst(); - } -} diff --git a/tests/src/test/java/de/sovity/edc/e2e/ApiWrapperDemoTest.java b/tests/src/test/java/de/sovity/edc/e2e/ApiWrapperDemoTest.java index 1c946456a..04383100b 100644 --- a/tests/src/test/java/de/sovity/edc/e2e/ApiWrapperDemoTest.java +++ b/tests/src/test/java/de/sovity/edc/e2e/ApiWrapperDemoTest.java @@ -33,6 +33,8 @@ 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.extension.e2e.connector.ConnectorRemote; @@ -87,9 +89,9 @@ void setup() { providerConnector = new ConnectorRemote(fromConnectorConfig(providerConfig)); providerClient = EdcClient.builder() - .managementApiUrl(providerConfig.getManagementEndpoint().getUri().toString()) - .managementApiKey(providerConfig.getProperties().get("edc.api.auth.key")) - .build(); + .managementApiUrl(providerConfig.getManagementEndpoint().getUri().toString()) + .managementApiKey(providerConfig.getProperties().get("edc.api.auth.key")) + .build(); // set up consumer EDC + Client var consumerConfig = forTestDatabase(CONSUMER_PARTICIPANT_ID, 23000, CONSUMER_DATABASE); @@ -97,9 +99,9 @@ void setup() { consumerConnector = new ConnectorRemote(fromConnectorConfig(consumerConfig)); consumerClient = EdcClient.builder() - .managementApiUrl(consumerConfig.getManagementEndpoint().getUri().toString()) - .managementApiKey(consumerConfig.getProperties().get("edc.api.auth.key")) - .build(); + .managementApiUrl(consumerConfig.getManagementEndpoint().getUri().toString()) + .managementApiKey(consumerConfig.getProperties().get("edc.api.auth.key")) + .build(); // We use the provider EDC as data sink / data source (it has the test-backend-controller extension) dataAddress = new MockDataAddressRemote(providerConnector.getConfig().getDefaultEndpoint()); @@ -124,89 +126,95 @@ void provide_and_consume() { private void createAsset() { var dataSource = UiDataSource.builder() - .type(DataSourceType.HTTP_DATA) - .httpData(UiDataSourceHttpData.builder() - .baseUrl(dataAddress.getDataSourceUrl(dataOfferData)) - .build()) - .build(); + .type(DataSourceType.HTTP_DATA) + .httpData(UiDataSourceHttpData.builder() + .baseUrl(dataAddress.getDataSourceUrl(dataOfferData)) + .build()) + .build(); var asset = UiAssetCreateRequest.builder() - .id(dataOfferId) - .title("My Data Offer") - .description("Example Data Offer.") - .version("2023-11") - .language("EN") - .publisherHomepage("https://my-department.my-org.com/my-data-offer") - .licenseUrl("https://my-department.my-org.com/my-data-offer#license") - .dataSource(dataSource) - .build(); + .id(dataOfferId) + .title("My Data Offer") + .description("Example Data Offer.") + .version("2023-11") + .language("EN") + .publisherHomepage("https://my-department.my-org.com/my-data-offer") + .licenseUrl("https://my-department.my-org.com/my-data-offer#license") + .dataSource(dataSource) + .build(); providerClient.uiApi().createAsset(asset); } private void createPolicy() { - var afterYesterday = UiPolicyConstraint.builder() + var afterYesterday = UiPolicyExpression.builder() + .expressionType(UiPolicyExpressionType.CONSTRAINT) + .constraint(UiPolicyConstraint.builder() .left("POLICY_EVALUATION_TIME") .operator(OperatorDto.GT) .right(UiPolicyLiteral.builder() - .type(UiPolicyLiteralType.STRING) - .value(OffsetDateTime.now().minusDays(1).toString()) - .build()) - .build(); - - var beforeTomorrow = UiPolicyConstraint.builder() + .type(UiPolicyLiteralType.STRING) + .value(OffsetDateTime.now().minusDays(1).toString()) + .build()) + .build()) + .build(); + + var beforeTomorrow = UiPolicyExpression.builder() + .expressionType(UiPolicyExpressionType.CONSTRAINT) + .constraint(UiPolicyConstraint.builder() .left("POLICY_EVALUATION_TIME") .operator(OperatorDto.LT) .right(UiPolicyLiteral.builder() - .type(UiPolicyLiteralType.STRING) - .value(OffsetDateTime.now().plusDays(1).toString()) - .build()) - .build(); + .type(UiPolicyLiteralType.STRING) + .value(OffsetDateTime.now().plusDays(1).toString()) + .build()) + .build()) + .build(); var policyDefinition = PolicyDefinitionCreateRequest.builder() - .policyDefinitionId(dataOfferId) - .policy(UiPolicyCreateRequest.builder() - .constraints(List.of(afterYesterday, beforeTomorrow)) - .build()) - .build(); + .policyDefinitionId(dataOfferId) + .policy(UiPolicyCreateRequest.builder() + .expressions(List.of(afterYesterday, beforeTomorrow)) + .build()) + .build(); providerClient.uiApi().createPolicyDefinition(policyDefinition); } private void createContractDefinition() { var contractDefinition = ContractDefinitionRequest.builder() - .contractDefinitionId(dataOfferId) - .accessPolicyId(dataOfferId) - .contractPolicyId(dataOfferId) - .assetSelector(List.of(UiCriterion.builder() - .operandLeft(Prop.Edc.ID) - .operator(UiCriterionOperator.EQ) - .operandRight(UiCriterionLiteral.builder() - .type(UiCriterionLiteralType.VALUE) - .value(dataOfferId) - .build()) - .build())) - .build(); + .contractDefinitionId(dataOfferId) + .accessPolicyId(dataOfferId) + .contractPolicyId(dataOfferId) + .assetSelector(List.of(UiCriterion.builder() + .operandLeft(Prop.Edc.ID) + .operator(UiCriterionOperator.EQ) + .operandRight(UiCriterionLiteral.builder() + .type(UiCriterionLiteralType.VALUE) + .value(dataOfferId) + .build()) + .build())) + .build(); providerClient.uiApi().createContractDefinition(contractDefinition); } private UiContractNegotiation initiateNegotiation(UiDataOffer dataOffer, UiContractOffer contractOffer) { var negotiationRequest = ContractNegotiationRequest.builder() - .counterPartyAddress(dataOffer.getEndpoint()) - .counterPartyParticipantId(dataOffer.getParticipantId()) - .assetId(dataOffer.getAsset().getAssetId()) - .contractOfferId(contractOffer.getContractOfferId()) - .policyJsonLd(contractOffer.getPolicy().getPolicyJsonLd()) - .build(); + .counterPartyAddress(dataOffer.getEndpoint()) + .counterPartyParticipantId(dataOffer.getParticipantId()) + .assetId(dataOffer.getAsset().getAssetId()) + .contractOfferId(contractOffer.getContractOfferId()) + .policyJsonLd(contractOffer.getPolicy().getPolicyJsonLd()) + .build(); return consumerClient.uiApi().initiateContractNegotiation(negotiationRequest); } private UiContractNegotiation awaitNegotiationDone(String negotiationId) { var negotiation = Awaitility.await().atMost(consumerConnector.timeout).until( - () -> consumerClient.uiApi().getContractNegotiation(negotiationId), - it -> it.getState().getSimplifiedState() != ContractNegotiationSimplifiedState.IN_PROGRESS + () -> consumerClient.uiApi().getContractNegotiation(negotiationId), + it -> it.getState().getSimplifiedState() != ContractNegotiationSimplifiedState.IN_PROGRESS ); assertThat(negotiation.getState().getSimplifiedState()).isEqualTo(ContractNegotiationSimplifiedState.AGREED); @@ -216,9 +224,9 @@ private UiContractNegotiation awaitNegotiationDone(String negotiationId) { private void initiateTransfer(UiContractNegotiation negotiation) { var contractAgreementId = negotiation.getContractAgreementId(); var transferRequest = InitiateTransferRequest.builder() - .contractAgreementId(contractAgreementId) - .dataSinkProperties(dataAddress.getDataSinkProperties()) - .build(); + .contractAgreementId(contractAgreementId) + .dataSinkProperties(dataAddress.getDataSinkProperties()) + .build(); consumerClient.uiApi().initiateTransfer(transferRequest); } diff --git a/tests/src/test/java/de/sovity/edc/e2e/DataSourceParameterizationTest.java b/tests/src/test/java/de/sovity/edc/e2e/DataSourceParameterizationTest.java index c8c5f453f..8bbb9e437 100644 --- a/tests/src/test/java/de/sovity/edc/e2e/DataSourceParameterizationTest.java +++ b/tests/src/test/java/de/sovity/edc/e2e/DataSourceParameterizationTest.java @@ -118,13 +118,13 @@ class DataSourceParameterizationTest { private static final AtomicInteger DATA_OFFER_INDEX = new AtomicInteger(0); record TestCase( - String name, - String id, - String method, - @Nullable String body, - @Nullable String mediaType, - @Nullable String path, - Map> queryParams + String name, + String id, + String method, + @Nullable String body, + @Nullable String mediaType, + @Nullable String path, + Map> queryParams ) { @Override public String toString() { @@ -150,9 +150,9 @@ void setup() { providerConnector = new ConnectorRemote(fromConnectorConfig(providerConfig)); providerClient = EdcClient.builder() - .managementApiUrl(providerConfig.getManagementEndpoint().getUri().toString()) - .managementApiKey(providerConfig.getProperties().get("edc.api.auth.key")) - .build(); + .managementApiUrl(providerConfig.getManagementEndpoint().getUri().toString()) + .managementApiKey(providerConfig.getProperties().get("edc.api.auth.key")) + .build(); // set up consumer EDC + Client var consumerConfig = forTestDatabase(CONSUMER_PARTICIPANT_ID, 23000, CONSUMER_DATABASE); @@ -160,22 +160,22 @@ void setup() { consumerConnector = new ConnectorRemote(fromConnectorConfig(consumerConfig)); consumerClient = EdcClient.builder() - .managementApiUrl(consumerConfig.getManagementEndpoint().getUri().toString()) - .managementApiKey(consumerConfig.getProperties().get("edc.api.auth.key")) - .build(); + .managementApiUrl(consumerConfig.getManagementEndpoint().getUri().toString()) + .managementApiKey(consumerConfig.getProperties().get("edc.api.auth.key")) + .build(); } @Test void canUseTheWorkaroundInCustomTransferRequest() { // arrange val testCase = new TestCase( - "", - "data-offer-" + DATA_OFFER_INDEX.getAndIncrement(), - HttpMethod.PATCH, - "[]", - "application/json", - "my-endpoint", - Map.of("filter", List.of("a", "b", "c")) + "", + "data-offer-" + DATA_OFFER_INDEX.getAndIncrement(), + HttpMethod.PATCH, + "[]", + "application/json", + "my-endpoint", + Map.of("filter", List.of("a", "b", "c")) ); val received = new AtomicBoolean(false); prepareDataTransferBackends(testCase, () -> received.set(true)); @@ -190,30 +190,30 @@ void canUseTheWorkaroundInCustomTransferRequest() { String standardBase = "https://w3id.org/edc/v0.0.1/ns/"; String workaroundBase = "https://sovity.de/workaround/proxy/param/"; var transferRequestJsonLd = Json.createObjectBuilder() - .add( - Prop.Edc.DATA_DESTINATION, - Json.createObjectBuilder(Map.of( - standardBase + "type", "HttpData", - standardBase + "baseUrl", destinationUrl, - standardBase + "method", "PUT", - workaroundBase + "pathSegments", testCase.path, - workaroundBase + "method", testCase.method, - workaroundBase + "queryParams", "filter=a&filter=b&filter=c", - workaroundBase + "mediaType", testCase.mediaType, - workaroundBase + "body", testCase.body - )).build() - ) - .add(Prop.Edc.CTX + "transferType", Json.createObjectBuilder() - .add(Prop.Edc.CTX + "contentType", "application/octet-stream") - .add(Prop.Edc.CTX + "isFinite", true) - ) - .add(Prop.Edc.CTX + "protocol", HttpMessageProtocol.DATASPACE_PROTOCOL_HTTP) - .add(Prop.Edc.CTX + "managedResources", false) - .build(); + .add( + Prop.Edc.DATA_DESTINATION, + Json.createObjectBuilder(Map.of( + standardBase + "type", "HttpData", + standardBase + "baseUrl", destinationUrl, + standardBase + "method", "PUT", + workaroundBase + "pathSegments", testCase.path, + workaroundBase + "method", testCase.method, + workaroundBase + "queryParams", "filter=a&filter=b&filter=c", + workaroundBase + "mediaType", testCase.mediaType, + workaroundBase + "body", testCase.body + )).build() + ) + .add(Prop.Edc.CTX + "transferType", Json.createObjectBuilder() + .add(Prop.Edc.CTX + "contentType", "application/octet-stream") + .add(Prop.Edc.CTX + "isFinite", true) + ) + .add(Prop.Edc.CTX + "protocol", HttpMessageProtocol.DATASPACE_PROTOCOL_HTTP) + .add(Prop.Edc.CTX + "managedResources", false) + .build(); var transferRequest = InitiateCustomTransferRequest.builder() - .contractAgreementId(negotiation.getContractAgreementId()) - .transferProcessRequestJsonLd(JsonUtils.toJson(transferRequestJsonLd)) - .build(); + .contractAgreementId(negotiation.getContractAgreementId()) + .transferProcessRequestJsonLd(JsonUtils.toJson(transferRequestJsonLd)) + .build(); val transferId = consumerClient.uiApi().initiateCustomTransfer(transferRequest).getId(); @@ -238,13 +238,13 @@ private void createData(TestCase testCase) { void sendWithEdcManagementApi() { // arrange val testCase = new TestCase( - "", - "data-offer-" + DATA_OFFER_INDEX.getAndIncrement(), - HttpMethod.PATCH, - "[]", - "application/json", - "my-endpoint", - Map.of("filter", List.of("a", "b", "c")) + "", + "data-offer-" + DATA_OFFER_INDEX.getAndIncrement(), + HttpMethod.PATCH, + "[]", + "application/json", + "my-endpoint", + Map.of("filter", List.of("a", "b", "c")) ); val received = new AtomicBoolean(false); prepareDataTransferBackends(testCase, () -> received.set(true)); @@ -259,19 +259,19 @@ void sendWithEdcManagementApi() { String workaroundBase = "https://sovity.de/workaround/proxy/param/"; String standardBase = "https://w3id.org/edc/v0.0.1/ns/"; val transferId = consumerConnector.initiateTransfer( - negotiation.getContractAgreementId(), - testCase.id, - URI.create("http://localhost:21003/api/dsp"), - Json.createObjectBuilder(Map.of( - standardBase + "type", "HttpData", - standardBase + "baseUrl", destinationUrl, - standardBase + "method", "PUT", - workaroundBase + "pathSegments", testCase.path, - workaroundBase + "method", testCase.method, - workaroundBase + "queryParams", "filter=a&filter=b&filter=c", - workaroundBase + "mediaType", testCase.mediaType, - workaroundBase + "body", testCase.body - )).build() + negotiation.getContractAgreementId(), + testCase.id, + URI.create("http://localhost:21003/api/dsp"), + Json.createObjectBuilder(Map.of( + standardBase + "type", "HttpData", + standardBase + "baseUrl", destinationUrl, + standardBase + "method", "PUT", + workaroundBase + "pathSegments", testCase.path, + workaroundBase + "method", testCase.method, + workaroundBase + "queryParams", "filter=a&filter=b&filter=c", + workaroundBase + "mediaType", testCase.mediaType, + workaroundBase + "body", testCase.body + )).build() ); awaitTransferCompletion(transferId); @@ -305,12 +305,12 @@ void canTransferParameterizedAsset() { // assert TransferHistoryEntry actual = consumerClient.uiApi() - .getTransferHistoryPage() - .getTransferEntries() - .stream() - .filter(it -> it.getAssetId().equals(testCase.id)) - .findFirst() - .get(); + .getTransferHistoryPage() + .getTransferEntries() + .stream() + .filter(it -> it.getAssetId().equals(testCase.id)) + .findFirst() + .get(); assertThat(actual.getAssetId()).isEqualTo(testCase.id); assertThat(actual.getTransferProcessId()).isEqualTo(transferId); assertThat(actual.getState().getSimplifiedState()).isEqualTo(OK); @@ -321,38 +321,38 @@ void canTransferParameterizedAsset() { private Stream source() { val httpMethods = List.of( - HttpMethod.POST, - // HttpMethod.HEAD, - HttpMethod.GET, - HttpMethod.DELETE, - HttpMethod.PUT, - HttpMethod.PATCH, - HttpMethod.OPTIONS + HttpMethod.POST, + // HttpMethod.HEAD, + HttpMethod.GET, + HttpMethod.DELETE, + HttpMethod.PUT, + HttpMethod.PATCH, + HttpMethod.OPTIONS ); val paths = Arrays.asList(null, "different/path/segment"); val queryParameters = List.of( - Map.>of(), - Map.of( - "limit", List.of("10"), - "filter", List.of("a", "b", "c") - ) + Map.>of(), + Map.of( + "limit", List.of("10"), + "filter", List.of("a", "b", "c") + ) ); return httpMethods.stream().flatMap(method -> - getBodyOptionsFor(method).stream().flatMap(body -> - paths.stream().flatMap(usePath -> - queryParameters.stream().map(params -> - new TestCase( - method + " body:" + body + " path:" + usePath + " params=" + params, - "data-offer-" + DATA_OFFER_INDEX.getAndIncrement(), - method, - body, - body == null ? null : "application/json", - usePath, - params - ))) - )); + getBodyOptionsFor(method).stream().flatMap(body -> + paths.stream().flatMap(usePath -> + queryParameters.stream().map(params -> + new TestCase( + method + " body:" + body + " path:" + usePath + " params=" + params, + "data-offer-" + DATA_OFFER_INDEX.getAndIncrement(), + method, + body, + body == null ? null : "application/json", + usePath, + params + ))) + )); } @NotNull @@ -390,23 +390,23 @@ private void prepareDataTransferBackends(TestCase testCase, Runnable onRequestRe mockServer.when(requestDefinition, once()) - .respond((it) -> new HttpResponse() - .withStatusCode(HttpStatusCode.OK_200.code()) - .withBody(payload, StandardCharsets.UTF_8)); + .respond((it) -> new HttpResponse() + .withStatusCode(HttpStatusCode.OK_200.code()) + .withBody(payload, StandardCharsets.UTF_8)); mockServer.when(request(destinationPath).withMethod(HttpMethod.PUT)) - .respond((HttpRequest httpRequest) -> { - if (new String(httpRequest.getBodyAsRawBytes()).equals(payload)) { - onRequestReceived.run(); - } - return new HttpResponse().withStatusCode(200); - }); + .respond((HttpRequest httpRequest) -> { + if (new String(httpRequest.getBodyAsRawBytes()).equals(payload)) { + onRequestReceived.run(); + } + return new HttpResponse().withStatusCode(200); + }); mockServer.when(request("/.*")) - .respond((HttpRequest httpRequest) -> { - fail("Unexpected network call"); - return new HttpResponse().withStatusCode(HttpStatusCode.GONE_410.code()); - }); + .respond((HttpRequest httpRequest) -> { + fail("Unexpected network call"); + return new HttpResponse().withStatusCode(HttpStatusCode.GONE_410.code()); + }); } private static String generateRandomPayload() { @@ -437,59 +437,59 @@ private String createAssetWithParameterizedMethod(TestCase testCase) { .build(); var asset = UiAssetCreateRequest.builder() - .id(testCase.id) - .title("My Data Offer") - .dataSource(dataSource) - .build(); + .id(testCase.id) + .title("My Data Offer") + .dataSource(dataSource) + .build(); return providerClient.uiApi().createAsset(asset).getId(); } private void createPolicy(TestCase testCase) { var policyDefinition = PolicyDefinitionCreateRequest.builder() - .policyDefinitionId(testCase.id) - .policy(UiPolicyCreateRequest.builder() - .constraints(List.of()) - .build()) - .build(); + .policyDefinitionId(testCase.id) + .policy(UiPolicyCreateRequest.builder() + .expressions(List.of()) + .build()) + .build(); providerClient.uiApi().createPolicyDefinition(policyDefinition); } private String createContractDefinition(TestCase testCase) { var contractDefinition = ContractDefinitionRequest.builder() - .contractDefinitionId(testCase.id) - .accessPolicyId(testCase.id) - .contractPolicyId(testCase.id) - .assetSelector(List.of(UiCriterion.builder() - .operandLeft(Prop.Edc.ID) - .operator(UiCriterionOperator.EQ) - .operandRight(UiCriterionLiteral.builder() - .type(UiCriterionLiteralType.VALUE) - .value(testCase.id) - .build()) - .build())) - .build(); + .contractDefinitionId(testCase.id) + .accessPolicyId(testCase.id) + .contractPolicyId(testCase.id) + .assetSelector(List.of(UiCriterion.builder() + .operandLeft(Prop.Edc.ID) + .operator(UiCriterionOperator.EQ) + .operandRight(UiCriterionLiteral.builder() + .type(UiCriterionLiteralType.VALUE) + .value(testCase.id) + .build()) + .build())) + .build(); return providerClient.uiApi().createContractDefinition(contractDefinition).getId(); } private UiContractNegotiation initiateNegotiation(UiDataOffer dataOffer, UiContractOffer contractOffer) { var negotiationRequest = ContractNegotiationRequest.builder() - .counterPartyAddress(dataOffer.getEndpoint()) - .counterPartyParticipantId(dataOffer.getParticipantId()) - .assetId(dataOffer.getAsset().getAssetId()) - .contractOfferId(contractOffer.getContractOfferId()) - .policyJsonLd(contractOffer.getPolicy().getPolicyJsonLd()) - .build(); + .counterPartyAddress(dataOffer.getEndpoint()) + .counterPartyParticipantId(dataOffer.getParticipantId()) + .assetId(dataOffer.getAsset().getAssetId()) + .contractOfferId(contractOffer.getContractOfferId()) + .policyJsonLd(contractOffer.getPolicy().getPolicyJsonLd()) + .build(); return consumerClient.uiApi().initiateContractNegotiation(negotiationRequest); } private UiContractNegotiation awaitNegotiationDone(String negotiationId) { var negotiation = Awaitility.await().atMost(consumerConnector.timeout).until( - () -> consumerClient.uiApi().getContractNegotiation(negotiationId), - it -> it.getState().getSimplifiedState() != ContractNegotiationSimplifiedState.IN_PROGRESS + () -> consumerClient.uiApi().getContractNegotiation(negotiationId), + it -> it.getState().getSimplifiedState() != ContractNegotiationSimplifiedState.IN_PROGRESS ); assertThat(negotiation.getState().getSimplifiedState()).isEqualTo(ContractNegotiationSimplifiedState.AGREED); @@ -497,8 +497,8 @@ private UiContractNegotiation awaitNegotiationDone(String negotiationId) { } private String initiateTransferWithParameters( - UiContractNegotiation negotiation, - TestCase testCase) { + UiContractNegotiation negotiation, + TestCase testCase) { String rootKey = "https://w3id.org/edc/v0.0.1/ns/"; val transferProcessProperties = new HashMap(); @@ -523,8 +523,8 @@ private String initiateTransferWithParameters( if (!testCase.queryParams.isEmpty()) { HttpUrl.Builder builder = new HttpUrl.Builder() - .scheme("http") - .host("example.com"); + .scheme("http") + .host("example.com"); for (val multiValueParam : testCase.queryParams.entrySet()) { for (val singleValue : multiValueParam.getValue()) { @@ -538,10 +538,10 @@ private String initiateTransferWithParameters( } var transferRequest = InitiateTransferRequest.builder() - .contractAgreementId(contractAgreementId) - .dataSinkProperties(dataSinkProperties) - .transferProcessProperties(transferProcessProperties) - .build(); + .contractAgreementId(contractAgreementId) + .dataSinkProperties(dataSinkProperties) + .transferProcessProperties(transferProcessProperties) + .build(); return consumerClient.uiApi().initiateTransfer(transferRequest).getId(); } @@ -551,14 +551,14 @@ private String getProtocolEndpoint(ConnectorRemote connector) { private void awaitTransferCompletion(String transferId) { Awaitility.await().atMost(consumerConnector.timeout).until( - () -> consumerClient.uiApi() - .getTransferHistoryPage() - .getTransferEntries() - .stream() - .filter(it -> it.getTransferProcessId().equals(transferId)) - .findFirst() - .map(it -> it.getState().getSimplifiedState()), - it -> it.orElse(RUNNING) != RUNNING + () -> consumerClient.uiApi() + .getTransferHistoryPage() + .getTransferEntries() + .stream() + .filter(it -> it.getTransferProcessId().equals(transferId)) + .findFirst() + .map(it -> it.getState().getSimplifiedState()), + it -> it.orElse(RUNNING) != RUNNING ); } diff --git a/tests/src/test/java/de/sovity/edc/e2e/DataSourceQueryParamsTest.java b/tests/src/test/java/de/sovity/edc/e2e/DataSourceQueryParamsTest.java index 3a47e95e6..6a12f1179 100644 --- a/tests/src/test/java/de/sovity/edc/e2e/DataSourceQueryParamsTest.java +++ b/tests/src/test/java/de/sovity/edc/e2e/DataSourceQueryParamsTest.java @@ -83,9 +83,9 @@ void setup() { providerConnector = new ConnectorRemote(fromConnectorConfig(providerConfig)); providerClient = EdcClient.builder() - .managementApiUrl(providerConfig.getManagementEndpoint().getUri().toString()) - .managementApiKey(providerConfig.getProperties().get("edc.api.auth.key")) - .build(); + .managementApiUrl(providerConfig.getManagementEndpoint().getUri().toString()) + .managementApiKey(providerConfig.getProperties().get("edc.api.auth.key")) + .build(); // set up consumer EDC + Client var consumerConfig = forTestDatabase(CONSUMER_PARTICIPANT_ID, 23000, CONSUMER_DATABASE); @@ -93,9 +93,9 @@ void setup() { consumerConnector = new ConnectorRemote(fromConnectorConfig(consumerConfig)); consumerClient = EdcClient.builder() - .managementApiUrl(consumerConfig.getManagementEndpoint().getUri().toString()) - .managementApiKey(consumerConfig.getProperties().get("edc.api.auth.key")) - .build(); + .managementApiUrl(consumerConfig.getManagementEndpoint().getUri().toString()) + .managementApiKey(consumerConfig.getProperties().get("edc.api.auth.key")) + .build(); // We use the provider EDC as data sink / data source (it has the test-backend-controller extension) dataAddress = new MockDataAddressRemote(providerConnector.getConfig().getDefaultEndpoint()); @@ -145,59 +145,59 @@ private void createAsset() { .build(); var asset = UiAssetCreateRequest.builder() - .id(dataOfferId) - .title("My Data Offer") - .dataSource(dataSource) - .build(); + .id(dataOfferId) + .title("My Data Offer") + .dataSource(dataSource) + .build(); providerClient.uiApi().createAsset(asset); } private void createPolicy() { var policyDefinition = PolicyDefinitionCreateRequest.builder() - .policyDefinitionId(dataOfferId) - .policy(UiPolicyCreateRequest.builder() - .constraints(List.of()) - .build()) - .build(); + .policyDefinitionId(dataOfferId) + .policy(UiPolicyCreateRequest.builder() + .expressions(List.of()) + .build()) + .build(); providerClient.uiApi().createPolicyDefinition(policyDefinition); } private void createContractDefinition() { var contractDefinition = ContractDefinitionRequest.builder() - .contractDefinitionId(dataOfferId) - .accessPolicyId(dataOfferId) - .contractPolicyId(dataOfferId) - .assetSelector(List.of(UiCriterion.builder() - .operandLeft(Prop.Edc.ID) - .operator(UiCriterionOperator.EQ) - .operandRight(UiCriterionLiteral.builder() - .type(UiCriterionLiteralType.VALUE) - .value(dataOfferId) - .build()) - .build())) - .build(); + .contractDefinitionId(dataOfferId) + .accessPolicyId(dataOfferId) + .contractPolicyId(dataOfferId) + .assetSelector(List.of(UiCriterion.builder() + .operandLeft(Prop.Edc.ID) + .operator(UiCriterionOperator.EQ) + .operandRight(UiCriterionLiteral.builder() + .type(UiCriterionLiteralType.VALUE) + .value(dataOfferId) + .build()) + .build())) + .build(); providerClient.uiApi().createContractDefinition(contractDefinition); } private UiContractNegotiation initiateNegotiation(UiDataOffer dataOffer, UiContractOffer contractOffer) { var negotiationRequest = ContractNegotiationRequest.builder() - .counterPartyAddress(dataOffer.getEndpoint()) - .counterPartyParticipantId(dataOffer.getParticipantId()) - .assetId(dataOffer.getAsset().getAssetId()) - .contractOfferId(contractOffer.getContractOfferId()) - .policyJsonLd(contractOffer.getPolicy().getPolicyJsonLd()) - .build(); + .counterPartyAddress(dataOffer.getEndpoint()) + .counterPartyParticipantId(dataOffer.getParticipantId()) + .assetId(dataOffer.getAsset().getAssetId()) + .contractOfferId(contractOffer.getContractOfferId()) + .policyJsonLd(contractOffer.getPolicy().getPolicyJsonLd()) + .build(); return consumerClient.uiApi().initiateContractNegotiation(negotiationRequest); } private UiContractNegotiation awaitNegotiationDone(String negotiationId) { var negotiation = Awaitility.await().atMost(consumerConnector.timeout).until( - () -> consumerClient.uiApi().getContractNegotiation(negotiationId), - it -> it.getState().getSimplifiedState() != ContractNegotiationSimplifiedState.IN_PROGRESS + () -> consumerClient.uiApi().getContractNegotiation(negotiationId), + it -> it.getState().getSimplifiedState() != ContractNegotiationSimplifiedState.IN_PROGRESS ); assertThat(negotiation.getState().getSimplifiedState()).isEqualTo(ContractNegotiationSimplifiedState.AGREED); @@ -207,9 +207,9 @@ private UiContractNegotiation awaitNegotiationDone(String negotiationId) { private void initiateTransfer(UiContractNegotiation negotiation) { var contractAgreementId = negotiation.getContractAgreementId(); var transferRequest = InitiateTransferRequest.builder() - .contractAgreementId(contractAgreementId) - .dataSinkProperties(dataAddress.getDataSinkProperties()) - .build(); + .contractAgreementId(contractAgreementId) + .dataSinkProperties(dataAddress.getDataSinkProperties()) + .build(); consumerClient.uiApi().initiateTransfer(transferRequest); } diff --git a/tests/src/test/java/de/sovity/edc/e2e/ManagementApiTransferTest.java b/tests/src/test/java/de/sovity/edc/e2e/ManagementApiTransferTest.java index 169ef34c1..5a00b07f7 100644 --- a/tests/src/test/java/de/sovity/edc/e2e/ManagementApiTransferTest.java +++ b/tests/src/test/java/de/sovity/edc/e2e/ManagementApiTransferTest.java @@ -70,10 +70,10 @@ void testDataTransfer() { // act consumerConnector.consumeOffer( - providerConnector.getParticipantId(), - providerConnector.getConfig().getProtocolEndpoint().getUri(), - assetId, - dataAddress.getDataSinkJsonLd()); + providerConnector.getParticipantId(), + providerConnector.getConfig().getProtocolEndpoint().getUri(), + assetId, + dataAddress.getDataSinkJsonLd()); // assert validateDataTransferred(dataAddress.getDataSinkSpyUrl(), TEST_BACKEND_TEST_DATA); diff --git a/tests/src/test/java/de/sovity/edc/e2e/Ms8ConnectorMigrationTest.java b/tests/src/test/java/de/sovity/edc/e2e/Ms8ConnectorMigrationTest.java index dd6d9e7e1..d28c52543 100644 --- a/tests/src/test/java/de/sovity/edc/e2e/Ms8ConnectorMigrationTest.java +++ b/tests/src/test/java/de/sovity/edc/e2e/Ms8ConnectorMigrationTest.java @@ -69,25 +69,25 @@ class Ms8ConnectorMigrationTest { void setup() { var providerConfig = forTestDatabase(PROVIDER_PARTICIPANT_ID, 21000, PROVIDER_DATABASE); providerConfig.setProperty("edc.flyway.additional.migration.locations", - "filesystem:%s".formatted(getAbsoluteTestResourcePath("db/additional-test-data/provider"))); + "filesystem:%s".formatted(getAbsoluteTestResourcePath("db/additional-test-data/provider"))); providerEdcContext.setConfiguration(providerConfig.getProperties()); providerConnector = new ConnectorRemote(fromConnectorConfig(providerConfig)); providerClient = EdcClient.builder() - .managementApiUrl(providerConfig.getManagementEndpoint().getUri().toString()) - .managementApiKey(providerConfig.getProperties().get("edc.api.auth.key")) - .build(); + .managementApiUrl(providerConfig.getManagementEndpoint().getUri().toString()) + .managementApiKey(providerConfig.getProperties().get("edc.api.auth.key")) + .build(); var consumerConfig = forTestDatabase(CONSUMER_PARTICIPANT_ID, 23000, CONSUMER_DATABASE); consumerConfig.setProperty("edc.flyway.additional.migration.locations", - "filesystem:%s".formatted(getAbsoluteTestResourcePath("db/additional-test-data/consumer"))); + "filesystem:%s".formatted(getAbsoluteTestResourcePath("db/additional-test-data/consumer"))); consumerEdcContext.setConfiguration(consumerConfig.getProperties()); consumerConnector = new ConnectorRemote(fromConnectorConfig(consumerConfig)); consumerClient = EdcClient.builder() - .managementApiUrl(consumerConfig.getManagementEndpoint().getUri().toString()) - .managementApiKey(consumerConfig.getProperties().get("edc.api.auth.key")) - .build(); + .managementApiUrl(consumerConfig.getManagementEndpoint().getUri().toString()) + .managementApiKey(consumerConfig.getProperties().get("edc.api.auth.key")) + .build(); // We use the provider EDC as data sink / data source (it has the test-backend-controller extension) dataAddress = new MockDataAddressRemote(providerConnector.getConfig().getDefaultEndpoint()); @@ -142,7 +142,8 @@ void testMs8ProvidingTransferProcess() { // assert assertThat(providerTransfer.getAssetId()).isEqualTo("first-asset-1.0"); assertThat(providerTransfer.getAssetName()).isEqualTo("First Asset"); - assertThat(providerTransfer.getContractAgreementId()).isEqualTo("Zmlyc3QtY2Q=:Zmlyc3QtYXNzZXQtMS4w:MjgzNTZkMTMtN2ZhYy00NTQwLTgwZjItMjI5NzJjOTc1ZWNi"); + assertThat(providerTransfer.getContractAgreementId()).isEqualTo( + "Zmlyc3QtY2Q=:Zmlyc3QtYXNzZXQtMS4w:MjgzNTZkMTMtN2ZhYy00NTQwLTgwZjItMjI5NzJjOTc1ZWNi"); assertThat(providerTransfer.getCounterPartyConnectorEndpoint()).isEqualTo(endpoint(consumerConnector)); assertThat(providerTransfer.getCounterPartyParticipantId()).isEqualTo(consumerConnector.getParticipantId()); assertIsEqualOffsetDateTime(providerTransfer.getCreatedDate(), EdcDateUtils.utcMillisToOffsetDateTime(1695208010855L)); @@ -170,7 +171,8 @@ void testMs8ConsumingTransferProcess() { // assert assertThat(consumerTransfer.getAssetId()).isEqualTo("first-asset-1.0"); assertThat(consumerTransfer.getAssetName()).isEqualTo("first-asset-1.0"); - assertThat(consumerTransfer.getContractAgreementId()).isEqualTo("Zmlyc3QtY2Q=:Zmlyc3QtYXNzZXQtMS4w:MjgzNTZkMTMtN2ZhYy00NTQwLTgwZjItMjI5NzJjOTc1ZWNi"); + assertThat(consumerTransfer.getContractAgreementId()).isEqualTo( + "Zmlyc3QtY2Q=:Zmlyc3QtYXNzZXQtMS4w:MjgzNTZkMTMtN2ZhYy00NTQwLTgwZjItMjI5NzJjOTc1ZWNi"); assertThat(consumerTransfer.getCounterPartyConnectorEndpoint()).isEqualTo(endpoint(providerConnector)); assertThat(consumerTransfer.getCounterPartyParticipantId()).isEqualTo(providerConnector.getParticipantId()); assertIsEqualOffsetDateTime(consumerTransfer.getCreatedDate(), EdcDateUtils.utcMillisToOffsetDateTime(1695208008652L)); @@ -189,10 +191,10 @@ void testMs8DataOffer_negotiateAndTransferNewContract() { // act consumerConnector.consumeOffer( - providerConnector.getParticipantId(), - providerConnector.getConfig().getProtocolEndpoint().getUri(), - "second-asset", - dataAddress.getDataSinkJsonLd()); + providerConnector.getParticipantId(), + providerConnector.getConfig().getProtocolEndpoint().getUri(), + "second-asset", + dataAddress.getDataSinkJsonLd()); // assert validateDataTransferred(dataAddress.getDataSinkSpyUrl(), "second-asset-data"); @@ -206,10 +208,10 @@ void testMs8Contract_transfer() { // act var transferProcessId = consumerConnector.initiateTransfer( - "Zmlyc3QtY2Q=:Zmlyc3QtYXNzZXQtMS4w:MjgzNTZkMTMtN2ZhYy00NTQwLTgwZjItMjI5NzJjOTc1ZWNi", - "first-asset-1.0", - providerConnector.getConfig().getProtocolEndpoint().getUri(), - dataAddress.getDataSinkJsonLd() + "Zmlyc3QtY2Q=:Zmlyc3QtYXNzZXQtMS4w:MjgzNTZkMTMtN2ZhYy00NTQwLTgwZjItMjI5NzJjOTc1ZWNi", + "first-asset-1.0", + providerConnector.getConfig().getProtocolEndpoint().getUri(), + dataAddress.getDataSinkJsonLd() ); // assert diff --git a/tests/src/test/java/de/sovity/edc/e2e/UiApiWrapperTest.java b/tests/src/test/java/de/sovity/edc/e2e/UiApiWrapperTest.java index 5cad0820f..0668295ab 100644 --- a/tests/src/test/java/de/sovity/edc/e2e/UiApiWrapperTest.java +++ b/tests/src/test/java/de/sovity/edc/e2e/UiApiWrapperTest.java @@ -36,6 +36,8 @@ 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.extension.e2e.connector.ConnectorRemote; @@ -101,18 +103,18 @@ void setup() { providerConnector = new ConnectorRemote(fromConnectorConfig(providerConfig)); providerClient = EdcClient.builder() - .managementApiUrl(providerConfig.getManagementEndpoint().getUri().toString()) - .managementApiKey(providerConfig.getProperties().get("edc.api.auth.key")) - .build(); + .managementApiUrl(providerConfig.getManagementEndpoint().getUri().toString()) + .managementApiKey(providerConfig.getProperties().get("edc.api.auth.key")) + .build(); var consumerConfig = forTestDatabase(CONSUMER_PARTICIPANT_ID, 23000, CONSUMER_DATABASE); consumerEdcContext.setConfiguration(consumerConfig.getProperties()); consumerConnector = new ConnectorRemote(fromConnectorConfig(consumerConfig)); consumerClient = EdcClient.builder() - .managementApiUrl(consumerConfig.getManagementEndpoint().getUri().toString()) - .managementApiKey(consumerConfig.getProperties().get("edc.api.auth.key")) - .build(); + .managementApiUrl(consumerConfig.getManagementEndpoint().getUri().toString()) + .managementApiKey(consumerConfig.getProperties().get("edc.api.auth.key")) + .build(); // We use the provider EDC as data sink / data source (it has the test-backend-controller extension) dataAddress = new MockDataAddressRemote(providerConnector.getConfig().getDefaultEndpoint()); @@ -125,83 +127,86 @@ void provide_consume_assetMapping_policyMapping_agreements() { var data = "expected data 123"; var yesterday = OffsetDateTime.now().minusDays(1); - var constraintRequest = UiPolicyConstraint.builder() + var policyExpression = UiPolicyExpression.builder() + .expressionType(UiPolicyExpressionType.CONSTRAINT) + .constraint(UiPolicyConstraint.builder() .left("POLICY_EVALUATION_TIME") .operator(OperatorDto.GT) .right(UiPolicyLiteral.builder() - .type(UiPolicyLiteralType.STRING) - .value(yesterday.toString()) - .build()) - .build(); + .type(UiPolicyLiteralType.STRING) + .value(yesterday.toString()) + .build()) + .build()) + .build(); var policyId = providerClient.uiApi().createPolicyDefinition(PolicyDefinitionCreateRequest.builder() - .policyDefinitionId("policy-1") - .policy(UiPolicyCreateRequest.builder() - .constraints(List.of(constraintRequest)) - .build()) - .build()).getId(); + .policyDefinitionId("policy-1") + .policy(UiPolicyCreateRequest.builder() + .expressions(List.of(policyExpression)) + .build()) + .build()).getId(); var dataSource = UiDataSource.builder() - .type(DataSourceType.HTTP_DATA) - .httpData(UiDataSourceHttpData.builder() - .baseUrl(dataAddress.getDataSourceUrl(data)) - .build()) - .build(); + .type(DataSourceType.HTTP_DATA) + .httpData(UiDataSourceHttpData.builder() + .baseUrl(dataAddress.getDataSourceUrl(data)) + .build()) + .build(); var assetId = providerClient.uiApi().createAsset(UiAssetCreateRequest.builder() - .id("asset-1") - .title("AssetName") - .description("AssetDescription") - .licenseUrl("https://license-url") - .version("1.0.0") - .language("en") - .mediaType("application/json") - .dataCategory("dataCategory") - .dataSubcategory("dataSubcategory") - .dataModel("dataModel") - .geoReferenceMethod("geoReferenceMethod") - .transportMode("transportMode") - .sovereignLegalName("my-sovereign") - .geoLocation("my-geolocation") - .nutsLocations(Arrays.asList("my-nuts-location1", "my-nuts-location2")) - .dataSampleUrls(Arrays.asList("my-data-sample-urls1", "my-data-sample-urls2")) - .referenceFileUrls(Arrays.asList("my-reference-files1", "my-reference-files2")) - .referenceFilesDescription("my-additional-description") - .conditionsForUse("my-conditions-for-use") - .dataUpdateFrequency("my-data-update-frequency") - .temporalCoverageFrom(LocalDate.parse("2007-12-03")) - .temporalCoverageToInclusive(LocalDate.parse("2024-01-22")) - .keywords(List.of("keyword1", "keyword2")) - .publisherHomepage("publisherHomepage") - .dataSource(dataSource) - .customJsonAsString(""" - {"test": "value"} - """) - .customJsonLdAsString(""" - {"https://public/some#key": "public LD value"} - """) - .privateCustomJsonAsString(""" - {"private_test": "private value"} - """) - .privateCustomJsonLdAsString(""" - {"https://private/some#key": "private LD value"} - """) - .build()).getId(); + .id("asset-1") + .title("AssetName") + .description("AssetDescription") + .licenseUrl("https://license-url") + .version("1.0.0") + .language("en") + .mediaType("application/json") + .dataCategory("dataCategory") + .dataSubcategory("dataSubcategory") + .dataModel("dataModel") + .geoReferenceMethod("geoReferenceMethod") + .transportMode("transportMode") + .sovereignLegalName("my-sovereign") + .geoLocation("my-geolocation") + .nutsLocations(Arrays.asList("my-nuts-location1", "my-nuts-location2")) + .dataSampleUrls(Arrays.asList("my-data-sample-urls1", "my-data-sample-urls2")) + .referenceFileUrls(Arrays.asList("my-reference-files1", "my-reference-files2")) + .referenceFilesDescription("my-additional-description") + .conditionsForUse("my-conditions-for-use") + .dataUpdateFrequency("my-data-update-frequency") + .temporalCoverageFrom(LocalDate.parse("2007-12-03")) + .temporalCoverageToInclusive(LocalDate.parse("2024-01-22")) + .keywords(List.of("keyword1", "keyword2")) + .publisherHomepage("publisherHomepage") + .dataSource(dataSource) + .customJsonAsString(""" + {"test": "value"} + """) + .customJsonLdAsString(""" + {"https://public/some#key": "public LD value"} + """) + .privateCustomJsonAsString(""" + {"private_test": "private value"} + """) + .privateCustomJsonLdAsString(""" + {"https://private/some#key": "private LD value"} + """) + .build()).getId(); assertThat(assetId).isEqualTo("asset-1"); providerClient.uiApi().createContractDefinition(ContractDefinitionRequest.builder() - .contractDefinitionId("cd-1") - .accessPolicyId(policyId) - .contractPolicyId(policyId) - .assetSelector(List.of(UiCriterion.builder() - .operandLeft(Prop.Edc.ID) - .operator(UiCriterionOperator.EQ) - .operandRight(UiCriterionLiteral.builder() - .type(UiCriterionLiteralType.VALUE) - .value(assetId) - .build()) - .build())) - .build()); + .contractDefinitionId("cd-1") + .accessPolicyId(policyId) + .contractPolicyId(policyId) + .assetSelector(List.of(UiCriterion.builder() + .operandLeft(Prop.Edc.ID) + .operator(UiCriterionOperator.EQ) + .operandRight(UiCriterionLiteral.builder() + .type(UiCriterionLiteralType.VALUE) + .value(assetId) + .build()) + .build())) + .build()); var assets = providerClient.uiApi().getAssetPage().getAssets(); assertThat(assets).hasSize(1); @@ -255,11 +260,11 @@ void provide_consume_assetMapping_policyMapping_agreements() { assertThat(dataOffer.getAsset().getHttpDatasourceHintsProxyQueryParams()).isFalse(); assertThat(dataOffer.getAsset().getHttpDatasourceHintsProxyBody()).isFalse(); assertThatJson(dataOffer.getAsset().getCustomJsonAsString()).isEqualTo(""" - {"test": "value"} - """); + {"test": "value"} + """); assertThatJson(dataOffer.getAsset().getCustomJsonLdAsString()).isEqualTo(""" - {"https://public/some#key":"public LD value"} - """); + {"https://public/some#key":"public LD value"} + """); assertThat(dataOffer.getAsset().getPrivateCustomJsonAsString()).isNullOrEmpty(); assertThatJson(dataOffer.getAsset().getPrivateCustomJsonLdAsString()).isObject().isEmpty(); @@ -270,17 +275,17 @@ void provide_consume_assetMapping_policyMapping_agreements() { assertThat(asset.getParticipantId()).isEqualTo(providerConnector.getParticipantId()); assertThatJson(asset.getCustomJsonAsString()).isEqualTo(""" - { "test": "value" } - """); + { "test": "value" } + """); assertThatJson(asset.getCustomJsonLdAsString()).isEqualTo(""" - { "https://public/some#key": "public LD value" } - """); + { "https://public/some#key": "public LD value" } + """); assertThatJson(asset.getPrivateCustomJsonAsString()).isEqualTo(""" - { "private_test": "private value" } - """); + { "private_test": "private value" } + """); assertThatJson(asset.getPrivateCustomJsonLdAsString()).isEqualTo(""" - { "https://private/some#key": "private LD value" } - """); + { "https://private/some#key": "private LD value" } + """); // Contract Agreement assertThat(providerAgreements).hasSize(1); @@ -298,8 +303,8 @@ void provide_consume_assetMapping_policyMapping_agreements() { assertThat(providerAgreement.getCounterPartyId()).isEqualTo(CONSUMER_PARTICIPANT_ID); assertThat(providerAgreement.getAsset().getAssetId()).isEqualTo(assetId); - var providingContractPolicyConstraint = providerAgreement.getContractPolicy().getConstraints().get(0); - assertThat(providingContractPolicyConstraint).usingRecursiveComparison().isEqualTo(providingContractPolicyConstraint); + var providingContractPolicyExpression = providerAgreement.getContractPolicy().getExpressions().get(0); + assertThat(providingContractPolicyExpression).usingRecursiveComparison().isEqualTo(policyExpression); assertThat(providerAgreement.getAsset().getAssetId()).isEqualTo(assetId); assertThat(providerAgreement.getAsset().getKeywords()).isEqualTo(List.of("keyword1", "keyword2")); @@ -313,15 +318,18 @@ void provide_consume_assetMapping_policyMapping_agreements() { assertThat(consumerAgreement.getCounterPartyId()).isEqualTo(PROVIDER_PARTICIPANT_ID); assertThat(consumerAgreement.getAsset().getAssetId()).isEqualTo(assetId); - var consumingContractPolicyConstraint = consumerAgreement.getContractPolicy().getConstraints().get(0); - assertThat(consumingContractPolicyConstraint).usingRecursiveComparison().isEqualTo(consumingContractPolicyConstraint); + var consumingContractPolicyConstraint = consumerAgreement.getContractPolicy().getExpressions().get(0); + assertThat(consumingContractPolicyConstraint).usingRecursiveComparison().isEqualTo(policyExpression); assertThat(consumerAgreement.getAsset().getAssetId()).isEqualTo(assetId); assertThat(consumerAgreement.getAsset().getTitle()).isEqualTo(assetId); // Test Policy - assertThat(contractOffer.getPolicy().getConstraints()).hasSize(1); - var constraint = contractOffer.getPolicy().getConstraints().get(0); + assertThat(contractOffer.getPolicy().getExpressions()).hasSize(1); + var actualExpression = contractOffer.getPolicy().getExpressions().get(0); + assertThat(actualExpression.getExpressionType()).isEqualTo(UiPolicyExpressionType.CONSTRAINT); + + var constraint = actualExpression.getConstraint(); assertThat(constraint.getLeft()).isEqualTo("POLICY_EVALUATION_TIME"); assertThat(constraint.getOperator()).isEqualTo(OperatorDto.GT); assertThat(constraint.getRight().getType()).isEqualTo(UiPolicyLiteralType.STRING); @@ -336,26 +344,26 @@ void provide_consume_assetMapping_policyMapping_agreements() { void canOverrideTheWellKnowPropertiesUsingTheCustomProperties() { // arrange var dataSource = UiDataSource.builder() - .type(DataSourceType.HTTP_DATA) - .httpData(UiDataSourceHttpData.builder() - .baseUrl("http://example.com/base") - .build()) - .build(); + .type(DataSourceType.HTTP_DATA) + .httpData(UiDataSourceHttpData.builder() + .baseUrl("http://example.com/base") + .build()) + .build(); var assetId = providerClient.uiApi().createAsset(UiAssetCreateRequest.builder() - .id("asset-1") - .title("will be overridden") - .dataSource(dataSource) - .customJsonLdAsString(""" - { - "http://purl.org/dc/terms/title": "The real title", - "http://purl.org/dc/terms/spatial": { - "http://purl.org/dc/terms/identifier": ["a", "b", "c"] - }, - "http://example.com/an-actual-custom-property": "custom value" - } - """) - .build()).getId(); + .id("asset-1") + .title("will be overridden") + .dataSource(dataSource) + .customJsonLdAsString(""" + { + "http://purl.org/dc/terms/title": "The real title", + "http://purl.org/dc/terms/spatial": { + "http://purl.org/dc/terms/identifier": ["a", "b", "c"] + }, + "http://example.com/an-actual-custom-property": "custom value" + } + """) + .build()).getId(); assertThat(assetId).isEqualTo("asset-1"); // act @@ -373,10 +381,10 @@ void canOverrideTheWellKnowPropertiesUsingTheCustomProperties() { assertThat(asset.getNutsLocations()).isEqualTo(List.of("a", "b", "c")); // remaining custom property assertThatJson(asset.getCustomJsonLdAsString()).isEqualTo(""" - { - "http://example.com/an-actual-custom-property": "custom value" - } - """); + { + "http://example.com/an-actual-custom-property": "custom value" + } + """); } // TODO throw an error if the id is overridden @@ -388,31 +396,31 @@ void customTransferRequest() { var data = "expected data 123"; var dataSource = UiDataSource.builder() - .type(DataSourceType.HTTP_DATA) - .httpData(UiDataSourceHttpData.builder() - .baseUrl(dataAddress.getDataSourceUrl(data)) - .build()) - .build(); + .type(DataSourceType.HTTP_DATA) + .httpData(UiDataSourceHttpData.builder() + .baseUrl(dataAddress.getDataSourceUrl(data)) + .build()) + .build(); var assetId = providerClient.uiApi().createAsset(UiAssetCreateRequest.builder() - .id("asset-1") - .dataSource(dataSource) - .build()).getId(); + .id("asset-1") + .dataSource(dataSource) + .build()).getId(); assertThat(assetId).isEqualTo("asset-1"); var policyId = providerClient.uiApi().createPolicyDefinition(PolicyDefinitionCreateRequest.builder() - .policyDefinitionId("policy-1") - .policy(UiPolicyCreateRequest.builder() - .constraints(List.of()) - .build()) - .build()).getId(); + .policyDefinitionId("policy-1") + .policy(UiPolicyCreateRequest.builder() + .expressions(List.of()) + .build()) + .build()).getId(); providerClient.uiApi().createContractDefinition(ContractDefinitionRequest.builder() - .contractDefinitionId("cd-1") - .accessPolicyId(policyId) - .contractPolicyId(policyId) - .assetSelector(List.of()) - .build()); + .contractDefinitionId("cd-1") + .accessPolicyId(policyId) + .contractPolicyId(policyId) + .assetSelector(List.of()) + .build()); var dataOffers = consumerClient.uiApi().getCatalogPageDataOffers(getProtocolEndpoint(providerConnector)); assertThat(dataOffers).hasSize(1); @@ -423,21 +431,21 @@ void customTransferRequest() { // act var negotiation = negotiate(dataOffer, contractOffer); var transferRequestJsonLd = Json.createObjectBuilder() - .add( - Prop.Edc.DATA_DESTINATION, - getDatasinkPropertiesJsonObject() - ) - .add(Prop.Edc.CTX + "transferType", Json.createObjectBuilder() - .add(Prop.Edc.CTX + "contentType", "application/octet-stream") - .add(Prop.Edc.CTX + "isFinite", true) - ) - .add(Prop.Edc.CTX + "protocol", HttpMessageProtocol.DATASPACE_PROTOCOL_HTTP) - .add(Prop.Edc.CTX + "managedResources", false) - .build(); + .add( + Prop.Edc.DATA_DESTINATION, + getDatasinkPropertiesJsonObject() + ) + .add(Prop.Edc.CTX + "transferType", Json.createObjectBuilder() + .add(Prop.Edc.CTX + "contentType", "application/octet-stream") + .add(Prop.Edc.CTX + "isFinite", true) + ) + .add(Prop.Edc.CTX + "protocol", HttpMessageProtocol.DATASPACE_PROTOCOL_HTTP) + .add(Prop.Edc.CTX + "managedResources", false) + .build(); var transferRequest = InitiateCustomTransferRequest.builder() - .contractAgreementId(negotiation.getContractAgreementId()) - .transferProcessRequestJsonLd(JsonUtils.toJson(transferRequestJsonLd)) - .build(); + .contractAgreementId(negotiation.getContractAgreementId()) + .transferProcessRequestJsonLd(JsonUtils.toJson(transferRequestJsonLd)) + .build(); consumerClient.uiApi().initiateCustomTransfer(transferRequest); validateDataTransferred(dataAddress.getDataSinkSpyUrl(), data); @@ -457,48 +465,48 @@ void editAssetOnLiveContract() { .build(); var assetId = providerClient.uiApi().createAsset(UiAssetCreateRequest.builder() - .id("asset-1") - .title("Bad Asset Title") - .dataSource(dataSource) - .customJsonAsString(""" - { - "test": "value" - } - """) - .customJsonLdAsString(""" - { - "test": "not a valid key, will be deleted", - "http://example.com/key-to-delete": "with a valida key", - "http://example.com/key-to-edit": "with a valida key" - } - """) - .privateCustomJsonAsString(""" - { - "private-test": "value" - } - """) - .privateCustomJsonLdAsString(""" - { - "private-test": "not a valid key, will be deleted", - "http://example.com/private-key-to-delete": "private with a valid key", - "http://example.com/private-key-to-edit": "private with a valid key" - } - """) - .build()).getId(); + .id("asset-1") + .title("Bad Asset Title") + .dataSource(dataSource) + .customJsonAsString(""" + { + "test": "value" + } + """) + .customJsonLdAsString(""" + { + "test": "not a valid key, will be deleted", + "http://example.com/key-to-delete": "with a valida key", + "http://example.com/key-to-edit": "with a valida key" + } + """) + .privateCustomJsonAsString(""" + { + "private-test": "value" + } + """) + .privateCustomJsonLdAsString(""" + { + "private-test": "not a valid key, will be deleted", + "http://example.com/private-key-to-delete": "private with a valid key", + "http://example.com/private-key-to-edit": "private with a valid key" + } + """) + .build()).getId(); providerClient.uiApi().createContractDefinition(ContractDefinitionRequest.builder() - .contractDefinitionId("cd-1") - .accessPolicyId("always-true") - .contractPolicyId("always-true") - .assetSelector(List.of(UiCriterion.builder() - .operandLeft(Prop.Edc.ID) - .operator(UiCriterionOperator.EQ) - .operandRight(UiCriterionLiteral.builder() - .type(UiCriterionLiteralType.VALUE) - .value(assetId) - .build()) - .build())) - .build()); + .contractDefinitionId("cd-1") + .accessPolicyId("always-true") + .contractPolicyId("always-true") + .assetSelector(List.of(UiCriterion.builder() + .operandLeft(Prop.Edc.ID) + .operator(UiCriterionOperator.EQ) + .operandRight(UiCriterionLiteral.builder() + .type(UiCriterionLiteralType.VALUE) + .value(assetId) + .build()) + .build())) + .build()); var dataOffers = consumerClient.uiApi().getCatalogPageDataOffers(getProtocolEndpoint(providerConnector)); assertThat(dataOffers).hasSize(1); @@ -509,82 +517,85 @@ void editAssetOnLiveContract() { // act providerClient.uiApi().editAsset(assetId, UiAssetEditRequest.builder() - .title("Good Asset Title") - .customJsonAsString(""" - { - "edited": "new value" - } - """) - .customJsonLdAsString(""" - { - "edited": "not a valid key, will be deleted", - "http://example.com/key-to-delete": null, - "http://example.com/key-to-edit": "with a valid key", - "http://example.com/extra": "value to add" - } - """) - .privateCustomJsonAsString(""" - { - "private-edited": "new value" - } - """) - .privateCustomJsonLdAsString(""" - { - "private-edited": "not a valid key, will be deleted", - "http://example.com/private-key-to-delete": null, - "http://example.com/private-key-to-edit": "private with a valid key", - "http://example.com/private-extra": "private value to add" - } - """) - .build()); - initiateTransfer(negotiation); - - // assert - assertThat(consumerClient.uiApi().getCatalogPageDataOffers(getProtocolEndpoint(providerConnector)).get(0).getAsset().getTitle()).isEqualTo("Good Asset Title"); - val firstAsset = providerClient.uiApi().getContractAgreementPage(null).getContractAgreements().get(0).getAsset(); - assertThat(firstAsset.getTitle()).isEqualTo("Good Asset Title"); - assertThat(firstAsset.getCustomJsonAsString()).isEqualTo(""" + .title("Good Asset Title") + .customJsonAsString(""" { "edited": "new value" } - """); - assertThatJson(firstAsset.getCustomJsonLdAsString()).isEqualTo(""" + """) + .customJsonLdAsString(""" { + "edited": "not a valid key, will be deleted", + "http://example.com/key-to-delete": null, "http://example.com/key-to-edit": "with a valid key", "http://example.com/extra": "value to add" } - """); - assertThat(firstAsset.getPrivateCustomJsonAsString()).isEqualTo(""" + """) + .privateCustomJsonAsString(""" { "private-edited": "new value" } - """); - assertThatJson(firstAsset.getPrivateCustomJsonLdAsString()).isEqualTo(""" + """) + .privateCustomJsonLdAsString(""" { + "private-edited": "not a valid key, will be deleted", + "http://example.com/private-key-to-delete": null, "http://example.com/private-key-to-edit": "private with a valid key", "http://example.com/private-extra": "private value to add" } - """); + """) + .build()); + initiateTransfer(negotiation); + + // assert + assertThat( + consumerClient.uiApi().getCatalogPageDataOffers(getProtocolEndpoint(providerConnector)).get(0).getAsset().getTitle()).isEqualTo( + "Good Asset Title"); + val firstAsset = providerClient.uiApi().getContractAgreementPage(null).getContractAgreements().get(0).getAsset(); + assertThat(firstAsset.getTitle()).isEqualTo("Good Asset Title"); + assertThat(firstAsset.getCustomJsonAsString()).isEqualTo(""" + { + "edited": "new value" + } + """); + assertThatJson(firstAsset.getCustomJsonLdAsString()).isEqualTo(""" + { + "http://example.com/key-to-edit": "with a valid key", + "http://example.com/extra": "value to add" + } + """); + assertThat(firstAsset.getPrivateCustomJsonAsString()).isEqualTo(""" + { + "private-edited": "new value" + } + """); + assertThatJson(firstAsset.getPrivateCustomJsonLdAsString()).isEqualTo(""" + { + "http://example.com/private-key-to-edit": "private with a valid key", + "http://example.com/private-extra": "private value to add" + } + """); validateDataTransferred(dataAddress.getDataSinkSpyUrl(), data); validateTransferProcessesOk(); - assertThat(providerClient.uiApi().getTransferHistoryPage().getTransferEntries().get(0).getAssetName()).isEqualTo("Good Asset Title"); + assertThat(providerClient.uiApi().getTransferHistoryPage().getTransferEntries().get(0).getAssetName()).isEqualTo( + "Good Asset Title"); } private UiContractNegotiation negotiate(UiDataOffer dataOffer, UiContractOffer contractOffer) { var negotiationRequest = ContractNegotiationRequest.builder() - .counterPartyAddress(dataOffer.getEndpoint()) - .counterPartyParticipantId(dataOffer.getParticipantId()) - .assetId(dataOffer.getAsset().getAssetId()) - .contractOfferId(contractOffer.getContractOfferId()) - .policyJsonLd(contractOffer.getPolicy().getPolicyJsonLd()) - .build(); + .counterPartyAddress(dataOffer.getEndpoint()) + .counterPartyParticipantId(dataOffer.getParticipantId()) + .assetId(dataOffer.getAsset().getAssetId()) + .contractOfferId(contractOffer.getContractOfferId()) + .policyJsonLd(contractOffer.getPolicy().getPolicyJsonLd()) + .build(); var negotiationId = consumerClient.uiApi().initiateContractNegotiation(negotiationRequest) - .getContractNegotiationId(); + .getContractNegotiationId(); var negotiation = Awaitility.await().atMost(consumerConnector.timeout).until( - () -> consumerClient.uiApi().getContractNegotiation(negotiationId), - it -> it.getState().getSimplifiedState() != ContractNegotiationSimplifiedState.IN_PROGRESS + () -> consumerClient.uiApi().getContractNegotiation(negotiationId), + it -> it.getState().getSimplifiedState() != ContractNegotiationSimplifiedState.IN_PROGRESS ); assertThat(negotiation.getState().getSimplifiedState()).isEqualTo(ContractNegotiationSimplifiedState.AGREED); @@ -594,9 +605,9 @@ private UiContractNegotiation negotiate(UiDataOffer dataOffer, UiContractOffer c private void initiateTransfer(UiContractNegotiation negotiation) { var contractAgreementId = negotiation.getContractAgreementId(); var transferRequest = InitiateTransferRequest.builder() - .contractAgreementId(contractAgreementId) - .dataSinkProperties(dataAddress.getDataSinkProperties()) - .build(); + .contractAgreementId(contractAgreementId) + .dataSinkProperties(dataAddress.getDataSinkProperties()) + .build(); consumerClient.uiApi().initiateTransfer(transferRequest); } diff --git a/tests/src/test/java/de/sovity/edc/e2e/UseCaseApiWrapperTest.java b/tests/src/test/java/de/sovity/edc/e2e/UseCaseApiWrapperTest.java index a32f56217..95d7b79a6 100644 --- a/tests/src/test/java/de/sovity/edc/e2e/UseCaseApiWrapperTest.java +++ b/tests/src/test/java/de/sovity/edc/e2e/UseCaseApiWrapperTest.java @@ -32,6 +32,8 @@ 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.extension.e2e.connector.ConnectorRemote; @@ -85,9 +87,9 @@ void setup() { providerConnector = new ConnectorRemote(fromConnectorConfig(providerConfig)); providerClient = EdcClient.builder() - .managementApiUrl(providerConfig.getManagementEndpoint().getUri().toString()) - .managementApiKey(providerConfig.getProperties().get("edc.api.auth.key")) - .build(); + .managementApiUrl(providerConfig.getManagementEndpoint().getUri().toString()) + .managementApiKey(providerConfig.getProperties().get("edc.api.auth.key")) + .build(); // set up consumer EDC + Client var consumerConfig = forTestDatabase(CONSUMER_PARTICIPANT_ID, 23000, CONSUMER_DATABASE); @@ -95,9 +97,9 @@ void setup() { consumerConnector = new ConnectorRemote(fromConnectorConfig(consumerConfig)); consumerClient = EdcClient.builder() - .managementApiUrl(consumerConfig.getManagementEndpoint().getUri().toString()) - .managementApiKey(consumerConfig.getProperties().get("edc.api.auth.key")) - .build(); + .managementApiUrl(consumerConfig.getManagementEndpoint().getUri().toString()) + .managementApiKey(consumerConfig.getProperties().get("edc.api.auth.key")) + .build(); // We use the provider EDC as data sink / data source (it has the test-backend-controller extension) dataAddress = new MockDataAddressRemote(providerConnector.getConfig().getDefaultEndpoint()); @@ -125,17 +127,19 @@ void catalog_filtering_by_like() { private CatalogQuery criterion(String leftOperand, CatalogFilterExpressionOperator operator, String rightOperand) { return CatalogQuery.builder() - .connectorEndpoint(getProtocolEndpoint(providerConnector)) - .filterExpressions( - List.of( - CatalogFilterExpression.builder() - .operandLeft(leftOperand) - .operator(operator) - .operandRight(CatalogFilterExpressionLiteral.builder().value(rightOperand).type(CatalogFilterExpressionLiteralType.VALUE).build()) - .build() - ) + .connectorEndpoint(getProtocolEndpoint(providerConnector)) + .filterExpressions( + List.of( + CatalogFilterExpression.builder() + .operandLeft(leftOperand) + .operator(operator) + .operandRight( + CatalogFilterExpressionLiteral.builder().value(rightOperand).type(CatalogFilterExpressionLiteralType.VALUE) + .build()) + .build() ) - .build(); + ) + .build(); } private void createAsset() { @@ -161,48 +165,54 @@ private void createAsset() { } private void createPolicy() { - var afterYesterday = UiPolicyConstraint.builder() + var afterYesterday = UiPolicyExpression.builder() + .expressionType(UiPolicyExpressionType.CONSTRAINT) + .constraint(UiPolicyConstraint.builder() .left("POLICY_EVALUATION_TIME") .operator(OperatorDto.GT) .right(UiPolicyLiteral.builder() - .type(UiPolicyLiteralType.STRING) - .value(OffsetDateTime.now().minusDays(1).toString()) - .build()) - .build(); + .type(UiPolicyLiteralType.STRING) + .value(OffsetDateTime.now().minusDays(1).toString()) + .build()) + .build()) + .build(); - var beforeTomorrow = UiPolicyConstraint.builder() + var beforeTomorrow = UiPolicyExpression.builder() + .expressionType(UiPolicyExpressionType.CONSTRAINT) + .constraint(UiPolicyConstraint.builder() .left("POLICY_EVALUATION_TIME") .operator(OperatorDto.LT) .right(UiPolicyLiteral.builder() - .type(UiPolicyLiteralType.STRING) - .value(OffsetDateTime.now().plusDays(1).toString()) - .build()) - .build(); + .type(UiPolicyLiteralType.STRING) + .value(OffsetDateTime.now().plusDays(1).toString()) + .build()) + .build()) + .build(); var policyDefinition = PolicyDefinitionCreateRequest.builder() - .policyDefinitionId(dataOfferId) - .policy(UiPolicyCreateRequest.builder() - .constraints(List.of(afterYesterday, beforeTomorrow)) - .build()) - .build(); + .policyDefinitionId(dataOfferId) + .policy(UiPolicyCreateRequest.builder() + .expressions(List.of(afterYesterday, beforeTomorrow)) + .build()) + .build(); providerClient.uiApi().createPolicyDefinition(policyDefinition); } private void createContractDefinition() { var contractDefinition = ContractDefinitionRequest.builder() - .contractDefinitionId(dataOfferId) - .accessPolicyId(dataOfferId) - .contractPolicyId(dataOfferId) - .assetSelector(List.of(UiCriterion.builder() - .operandLeft(Prop.Edc.ID) - .operator(UiCriterionOperator.EQ) - .operandRight(UiCriterionLiteral.builder() - .type(UiCriterionLiteralType.VALUE) - .value(dataOfferId) - .build()) - .build())) - .build(); + .contractDefinitionId(dataOfferId) + .accessPolicyId(dataOfferId) + .contractPolicyId(dataOfferId) + .assetSelector(List.of(UiCriterion.builder() + .operandLeft(Prop.Edc.ID) + .operator(UiCriterionOperator.EQ) + .operandRight(UiCriterionLiteral.builder() + .type(UiCriterionLiteralType.VALUE) + .value(dataOfferId) + .build()) + .build())) + .build(); providerClient.uiApi().createContractDefinition(contractDefinition); } From 9f6c7eda3690d8585cd03c9053da0dd0693ea543 Mon Sep 17 00:00:00 2001 From: Richard Treier Date: Tue, 16 Jul 2024 14:44:44 +0300 Subject: [PATCH 06/18] chore: try fix ci --- .../wrapper/clients/java-client/README.md | 93 +++++++++++-------- 1 file changed, 55 insertions(+), 38 deletions(-) diff --git a/extensions/wrapper/clients/java-client/README.md b/extensions/wrapper/clients/java-client/README.md index 9eb0cd231..ca638b4ef 100644 --- a/extensions/wrapper/clients/java-client/README.md +++ b/extensions/wrapper/clients/java-client/README.md @@ -49,14 +49,14 @@ import de.sovity.edc.client.gen.model.KpiResult; */ public class WrapperClientExample { - public static final String CONNECTOR_ENDPOINT = "http://localhost:11002/api/management/v2"; - public static final String CONNECTOR_API_KEY = "..."; + public static final String MANAGEMENT_API_URL = "http://localhost:11002/api/management"; + public static final String MANAGEMENT_API_KEY = "..."; public static void main(String[] args) { // Configure Client EdcClient client = EdcClient.builder() - .managementApiUrl(CONNECTOR_ENDPOINT) - .managementApiKey(CONNECTOR_API_KEY) + .managementApiUrl(MANAGEMENT_API_URL) + .managementApiKey(MANAGEMENT_API_KEY) .build(); // EDC API Wrapper APIs are now available for use @@ -80,15 +80,15 @@ import de.sovity.edc.client.oauth2.SovityKeycloakUrl; */ public class WrapperClientExample { - public static final String CONNECTOR_ENDPOINT = - "https://{{your-connector}}.prod-sovity.azure.sovity.io/control/data"; + public static final String MANAGEMENT_API_URL = + "https://{{your-connector}}.prod-sovity.azure.sovity.io/control/api/management"; public static final String CLIENT_ID = "{{your-connector}}-app"; public static final String CLIENT_SECRET = "..."; public static void main(String[] args) { // Configure Client EdcClient client = EdcClient.builder() - .managementApiUrl(CONNECTOR_ENDPOINT) + .managementApiUrl(MANAGEMENT_API_URL) .oauth2ClientCredentials(OAuth2ClientCredentials.builder() .tokenUrl(SovityKeycloakUrl.PRODUCTION) .clientId(CLIENT_ID) @@ -107,15 +107,14 @@ public class WrapperClientExample { Below are the examples of various tasks and the corresponding methods to be used from the Java-client. -| Task | Java-Client method | -|----------------------------------------------------------|-----------------------------------------------------------------------| -| Create Policy - uiAPI | `EdcClient.uiApi().createPolicyDefinition(policyDefinition)` | -| Create Policy - useCaseApi (allows AND/OR/XOR operators) | `EdcClient.useCaseApi().createPolicyDefinitionUseCase(createRequest)` | -| Create asset (Asset Creation after activate) | `EdcClient.uiApi().createAsset(uiAssetRequest)` | -| Create contract definition | `EdcClient.uiApi().createContractDefinition(contractDefinition)` | -| Create Offer on consumer dashboard (Catalog Browser) | `EdcClient.uiApi().getCatalogPageDataOffers(PROTOCOL_ENDPOINT)` | -| Accept contract (Contract Negotiation) | `EdcClient.uiApi().initiateContractNegotiation(negotiationRequest)` | -| Transfer Data (Initiate Transfer) | `EdcClient.uiApi().initiateTransfer(negotiation)` | +| Task | Java-Client method | +|------------------------------------------------------|---------------------------------------------------------------------| +| Create Policy | `EdcClient.uiApi().createPolicyDefinition(policyDefinition)` | +| Create asset (Asset Creation after activate) | `EdcClient.uiApi().createAsset(uiAssetRequest)` | +| Create contract definition | `EdcClient.uiApi().createContractDefinition(contractDefinition)` | +| Create Offer on consumer dashboard (Catalog Browser) | `EdcClient.uiApi().getCatalogPageDataOffers(PROTOCOL_ENDPOINT)` | +| Accept contract (Contract Negotiation) | `EdcClient.uiApi().initiateContractNegotiation(negotiationRequest)` | +| Transfer Data (Initiate Transfer) | `EdcClient.uiApi().initiateTransfer(negotiation)` | These methods facilitate various operations such as creating policies, assets, contract definitions, browsing offers, accepting contracts, and initiating data transfers. @@ -124,33 +123,51 @@ These methods facilitate various operations such as creating policies, assets, c The following example demonstrates how to create a Catena-Policy with linked conditions using the Java-client. ```java -var policyId = UUID.randomUUID().toString(); -var membershipElement = buildAtomicElement("Membership", OperatorDto.EQ, "active"); -var purposeElement = buildAtomicElement("PURPOSE", OperatorDto.EQ, "ID 3.1 Trace"); -var andElement = new Expression() - .expressionType(ExpressionTypeDto.AND) - .expressions(List.of(membershipElement, purposeElement)); -var permissionDto = new PermissionDto(andElement); -var createRequest = new PolicyCreateRequest(policyId, permissionDto); - -var response = client.useCaseApi().createPolicyDefinitionUseCase(createRequest); - -private Expression buildAtomicElement( +public String buildCatenaXPolicy() { + var policyId = UUID.randomUUID().toString(); + + var expression = buildAnd( + buildConstraint("Membership", OperatorDto.EQ, "active"), + buildConstraint("PURPOSE", OperatorDto.EQ, "ID 3.1 Trace") + ); + + var policyCreateRequest = PolicyDefinitionCreateRequest.builder() + .policyDefinitionId(policyId) + .policy(UiPolicyCreateRequest.builder() + .expressions(List.of(expression)) + .build()) + .build(); + + consumerClient.uiApi().createPolicyDefinition(policyCreateRequest); + return policyId; +} + +private UiPolicyExpression buildAnd(UiPolicyExpression... expressions) { + return UiPolicyExpression.builder() + .expressionType(UiPolicyExpressionType.AND) + .expressions(Arrays.asList(expressions)) + .build(); +} + +private UiPolicyExpression buildConstraint( String left, OperatorDto operator, - String right) { - var atomicConstraint = new AtomicConstraintDto() - .leftExpression(left) - .operator(operator) - .rightExpression(right); - return new Expression() - .expressionType(ExpressionTypeDto.ATOMIC_CONSTRAINT) - .atomicConstraint(atomicConstraint); + String right +) { + return UiPolicyExpression.builder() + .expressionType(UiPolicyExpressionType.CONSTRAINT) + .constraint(UiPolicyConstraint.builder() + .left(left) + .operator(operator) + .right(UiPolicyLiteral.builder() + .type(UiPolicyLiteralType.STRING) + .value(right) + .build()) + .build()) + .build(); } ``` -The complete example can be seen in [this test](https://github.com/sovity/edc-ce/blob/main/extensions/wrapper/wrapper/src/test/java/de/sovity/edc/ext/wrapper/api/usecase/PolicyDefinitionApiServiceTest.java). - ## License Apache License 2.0 - see [LICENSE](../../../../LICENSE) From 4e1ac0e1db59a2a0294a29b06bf0c4648a360376 Mon Sep 17 00:00:00 2001 From: Richard Treier Date: Tue, 16 Jul 2024 15:10:00 +0300 Subject: [PATCH 07/18] fix: tests (2) --- .../api/ui/pages/catalog/CatalogApiTest.java | 2 +- .../ContractAgreementPageTest.java | 2 +- .../PolicyDefinitionApiServiceTest.java | 50 ++++++++++--------- .../api/usecase/UseCaseApiWrapperTest.java | 2 +- 4 files changed, 30 insertions(+), 26 deletions(-) diff --git a/extensions/wrapper/wrapper/src/test/java/de/sovity/edc/ext/wrapper/api/ui/pages/catalog/CatalogApiTest.java b/extensions/wrapper/wrapper/src/test/java/de/sovity/edc/ext/wrapper/api/ui/pages/catalog/CatalogApiTest.java index a4a366355..2ec04af14 100644 --- a/extensions/wrapper/wrapper/src/test/java/de/sovity/edc/ext/wrapper/api/ui/pages/catalog/CatalogApiTest.java +++ b/extensions/wrapper/wrapper/src/test/java/de/sovity/edc/ext/wrapper/api/ui/pages/catalog/CatalogApiTest.java @@ -100,7 +100,7 @@ private void createPolicy() { var policyDefinition = PolicyDefinitionCreateRequest.builder() .policyDefinitionId(dataOfferId) .policy(UiPolicyCreateRequest.builder() - .constraints(List.of()) + .expressions(List.of()) .build()) .build(); diff --git a/extensions/wrapper/wrapper/src/test/java/de/sovity/edc/ext/wrapper/api/ui/pages/contract_agreement/ContractAgreementPageTest.java b/extensions/wrapper/wrapper/src/test/java/de/sovity/edc/ext/wrapper/api/ui/pages/contract_agreement/ContractAgreementPageTest.java index 8aca8a06f..4814f1a35 100644 --- a/extensions/wrapper/wrapper/src/test/java/de/sovity/edc/ext/wrapper/api/ui/pages/contract_agreement/ContractAgreementPageTest.java +++ b/extensions/wrapper/wrapper/src/test/java/de/sovity/edc/ext/wrapper/api/ui/pages/contract_agreement/ContractAgreementPageTest.java @@ -108,7 +108,7 @@ void testContractAgreementPage( assertThat(transfer.getState().getSimplifiedState()).isEqualTo(TransferProcessSimplifiedState.OK); assertThat(transfer.getErrorMessage()).isEqualTo("my-error-message-1"); - var constraint = agreement.getContractPolicy().getConstraints().get(0); + var constraint = agreement.getContractPolicy().getExpressions().get(0).getConstraint(); assertThat(constraint.getLeft()).isEqualTo("ALWAYS_TRUE"); assertThat(constraint.getOperator()).isEqualTo(OperatorDto.EQ); assertThat(constraint.getRight().getValue()).isEqualTo("true"); diff --git a/extensions/wrapper/wrapper/src/test/java/de/sovity/edc/ext/wrapper/api/ui/pages/policy/PolicyDefinitionApiServiceTest.java b/extensions/wrapper/wrapper/src/test/java/de/sovity/edc/ext/wrapper/api/ui/pages/policy/PolicyDefinitionApiServiceTest.java index 2156b609a..47a4418d7 100644 --- a/extensions/wrapper/wrapper/src/test/java/de/sovity/edc/ext/wrapper/api/ui/pages/policy/PolicyDefinitionApiServiceTest.java +++ b/extensions/wrapper/wrapper/src/test/java/de/sovity/edc/ext/wrapper/api/ui/pages/policy/PolicyDefinitionApiServiceTest.java @@ -21,6 +21,8 @@ import de.sovity.edc.client.gen.model.PolicyDefinitionDto; 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.wrapper.TestUtils; @@ -28,7 +30,6 @@ import org.eclipse.edc.connector.spi.policydefinition.PolicyDefinitionService; import org.eclipse.edc.junit.annotations.ApiTest; import org.eclipse.edc.junit.extensions.EdcExtension; -import org.eclipse.edc.junit.extensions.EdcRuntimeExtension; import org.eclipse.edc.spi.entity.Entity; import org.eclipse.edc.spi.query.QuerySpec; import org.junit.jupiter.api.BeforeEach; @@ -44,14 +45,17 @@ class PolicyDefinitionApiServiceTest { EdcClient client; - UiPolicyConstraint constraint = UiPolicyConstraint.builder() + UiPolicyExpression expression = UiPolicyExpression.builder() + .expressionType(UiPolicyExpressionType.CONSTRAINT) + .constraint(UiPolicyConstraint.builder() .left("a") .operator(OperatorDto.EQ) .right(UiPolicyLiteral.builder() - .type(UiPolicyLiteralType.STRING) - .value("b") - .build()) - .build(); + .type(UiPolicyLiteralType.STRING) + .value("b") + .build()) + .build()) + .build(); @BeforeEach void setUp(EdcExtension extension) { @@ -71,13 +75,13 @@ void getPolicyList() { var policyDefinitions = response.getPolicies(); assertThat(policyDefinitions).hasSize(2); var policyDefinition = policyDefinitions.stream() - .filter(it -> it.getPolicyDefinitionId().equals("my-policy-def-1")) - .findFirst().get(); + .filter(it -> it.getPolicyDefinitionId().equals("my-policy-def-1")) + .findFirst().get(); assertThat(policyDefinition.getPolicyDefinitionId()).isEqualTo("my-policy-def-1"); - assertThat(policyDefinition.getPolicy().getConstraints()).hasSize(1); + assertThat(policyDefinition.getPolicy().getExpressions()).hasSize(1); - var constraintEntry = policyDefinition.getPolicy().getConstraints().get(0); - assertThat(constraintEntry).usingRecursiveComparison().isEqualTo(constraint); + var constraintEntry = policyDefinition.getPolicy().getExpressions().get(0); + assertThat(constraintEntry).usingRecursiveComparison().isEqualTo(expression); } @Test @@ -92,12 +96,12 @@ void test_sorting(PolicyDefinitionService policyDefinitionService) { // assert assertThat(result.getPolicies()) - .extracting(PolicyDefinitionDto::getPolicyDefinitionId) - .containsExactly( - "always-true", - "my-policy-def-2", - "my-policy-def-1", - "my-policy-def-0"); + .extracting(PolicyDefinitionDto::getPolicyDefinitionId) + .containsExactly( + "always-true", + "my-policy-def-2", + "my-policy-def-1", + "my-policy-def-0"); } @Test @@ -105,7 +109,7 @@ void test_delete(PolicyDefinitionService policyDefinitionService) { // arrange createPolicyDefinition("my-policy-def-1"); assertThat(policyDefinitionService.query(QuerySpec.max()).getContent().toList()) - .extracting(Entity::getId).contains("always-true", "my-policy-def-1"); + .extracting(Entity::getId).contains("always-true", "my-policy-def-1"); // act var response = client.uiApi().deletePolicyDefinition("my-policy-def-1"); @@ -113,20 +117,20 @@ void test_delete(PolicyDefinitionService policyDefinitionService) { // assert assertThat(response.getId()).isEqualTo("my-policy-def-1"); assertThat(policyDefinitionService.query(QuerySpec.max()).getContent()) - .extracting(Entity::getId).containsExactly("always-true"); + .extracting(Entity::getId).containsExactly("always-true"); } private void createPolicyDefinition(String policyDefinitionId) { - var policy = new UiPolicyCreateRequest(List.of(constraint)); + var policy = new UiPolicyCreateRequest(List.of(expression)); var policyDefinition = new PolicyDefinitionCreateRequest(policyDefinitionId, policy); client.uiApi().createPolicyDefinition(policyDefinition); } @SneakyThrows private void createPolicyDefinition( - PolicyDefinitionService policyDefinitionService, - String policyDefinitionId, - long createdAt) { + PolicyDefinitionService policyDefinitionService, + String policyDefinitionId, + long createdAt) { createPolicyDefinition(policyDefinitionId); var policyDefinition = policyDefinitionService.findById(policyDefinitionId); diff --git a/extensions/wrapper/wrapper/src/test/java/de/sovity/edc/ext/wrapper/api/usecase/UseCaseApiWrapperTest.java b/extensions/wrapper/wrapper/src/test/java/de/sovity/edc/ext/wrapper/api/usecase/UseCaseApiWrapperTest.java index fc92c506e..74ee6c156 100644 --- a/extensions/wrapper/wrapper/src/test/java/de/sovity/edc/ext/wrapper/api/usecase/UseCaseApiWrapperTest.java +++ b/extensions/wrapper/wrapper/src/test/java/de/sovity/edc/ext/wrapper/api/usecase/UseCaseApiWrapperTest.java @@ -197,7 +197,7 @@ private void setupAssets() { policyId = client.uiApi().createPolicyDefinition(PolicyDefinitionCreateRequest.builder() .policyDefinitionId("policy-1") .policy(UiPolicyCreateRequest.builder() - .constraints(List.of()) + .expressions(List.of()) .build()) .build()).getId(); } From f1015fc3f498b8b61cf132e6a9e205ac6cdb96eb Mon Sep 17 00:00:00 2001 From: Richard Treier Date: Tue, 16 Jul 2024 15:24:33 +0300 Subject: [PATCH 08/18] chore: try fix ci (3) --- .../java/de/sovity/edc/ext/catalog/crawler/CrawlerE2eTest.java | 1 - 1 file changed, 1 deletion(-) diff --git a/extensions/catalog-crawler/catalog-crawler-e2e-test/src/test/java/de/sovity/edc/ext/catalog/crawler/CrawlerE2eTest.java b/extensions/catalog-crawler/catalog-crawler-e2e-test/src/test/java/de/sovity/edc/ext/catalog/crawler/CrawlerE2eTest.java index 87c306cff..fb79645ed 100644 --- a/extensions/catalog-crawler/catalog-crawler-e2e-test/src/test/java/de/sovity/edc/ext/catalog/crawler/CrawlerE2eTest.java +++ b/extensions/catalog-crawler/catalog-crawler-e2e-test/src/test/java/de/sovity/edc/ext/catalog/crawler/CrawlerE2eTest.java @@ -50,7 +50,6 @@ import java.util.List; import java.util.concurrent.TimeUnit; import java.util.function.Consumer; -import java.util.stream.Collectors; import java.util.stream.Stream; import static de.sovity.edc.extension.e2e.connector.config.ConnectorConfigFactory.forTestDatabase; From b14157c39b05aac6f4c0b49423a579e57ecfc9d7 Mon Sep 17 00:00:00 2001 From: Richard Treier Date: Wed, 17 Jul 2024 12:01:06 +0300 Subject: [PATCH 09/18] feat: preserve old policy create endpoint --- docs/api/sovity-edc-api-wrapper.yaml | 111 +++++++++++------- .../ext/catalog/crawler/CrawlerE2eTest.java | 28 ++--- .../wrapper/clients/java-client/README.md | 4 +- .../edc/ext/wrapper/api/ui/UiResource.java | 11 +- .../ui/model/PolicyDefinitionCreateDto.java | 38 ++++++ .../model/PolicyDefinitionCreateRequest.java | 6 +- .../wrapper/api/common/model/UiPolicy.java | 4 +- .../api/common/model/UiPolicyConstraint.java | 2 +- .../common/model/UiPolicyCreateRequest.java | 8 +- .../api/common/model/UiPolicyExpression.java | 30 +++-- .../common/model/UiPolicyExpressionType.java | 14 ++- .../common/mappers/LegacyPolicyMapper.java | 54 +++++++++ .../api/common/mappers/PolicyMapper.java | 21 +--- .../mappers/policy/ExpressionExtractor.java | 34 +++++- .../mappers/policy/ExpressionMapper.java | 32 +++-- .../mappers/LegacyPolicyMapperTest.java | 105 +++++++++++++++++ .../api/common/mappers/PolicyMapperTest.java | 36 ++++-- .../policy/ExpressionExtractorTest.java | 101 +++++++++++++--- .../mappers/policy/ExpressionMapperTest.java | 7 +- .../WrapperExtensionContextBuilder.java | 5 +- .../ext/wrapper/api/ui/UiResourceImpl.java | 7 ++ .../policy/PolicyDefinitionApiService.java | 21 +++- .../api/ui/pages/catalog/CatalogApiTest.java | 13 +- .../ContractAgreementPageTest.java | 6 +- .../PolicyDefinitionApiServiceTest.java | 17 +-- .../api/usecase/UseCaseApiWrapperTest.java | 14 +-- .../de/sovity/edc/e2e/ApiWrapperDemoTest.java | 20 ++-- .../e2e/DataSourceParameterizationTest.java | 13 +- .../edc/e2e/DataSourceQueryParamsTest.java | 13 +- .../de/sovity/edc/e2e/UiApiWrapperTest.java | 26 ++-- .../sovity/edc/e2e/UseCaseApiWrapperTest.java | 20 ++-- 31 files changed, 601 insertions(+), 220 deletions(-) create mode 100644 extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/PolicyDefinitionCreateDto.java create mode 100644 extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/LegacyPolicyMapper.java create mode 100644 extensions/wrapper/wrapper-common-mappers/src/test/java/de/sovity/edc/ext/wrapper/api/common/mappers/LegacyPolicyMapperTest.java diff --git a/docs/api/sovity-edc-api-wrapper.yaml b/docs/api/sovity-edc-api-wrapper.yaml index 51b2dab1e..549003ba3 100644 --- a/docs/api/sovity-edc-api-wrapper.yaml +++ b/docs/api/sovity-edc-api-wrapper.yaml @@ -121,7 +121,7 @@ paths: post: tags: - UI - description: Create a new Policy Definition + description: "[Deprecated] Create a new Policy Definition from a list of constraints" operationId: createPolicyDefinition requestBody: content: @@ -135,6 +135,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: @@ -849,7 +868,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 @@ -864,45 +884,18 @@ components: $ref: '#/components/schemas/OperatorDto' right: $ref: '#/components/schemas/UiPolicyLiteral' - description: ODRL AtomicConstraint as supported by the sovity product landscape + description: "ODRL AtomicConstraint as supported by the sovity product landscape.\ + \ For example 'a EQ b', 'c IN [d, e, f]'" UiPolicyCreateRequest: type: object properties: expressions: type: array - description: Conjunction of required expressions for the policy to evaluate - to TRUE. - items: - $ref: '#/components/schemas/UiPolicyExpression' - description: Type-Safe OpenAPI generator friendly ODLR policy subset as endorsed - by sovity. - UiPolicyExpression: - type: object - properties: - expressionType: - $ref: '#/components/schemas/UiPolicyExpressionType' - expressions: - type: array - description: "Only for types AND, OR, XOR. List of sub-expressions to be\ - \ evaluated according to the expressionType." + description: Conjunction of required constraints 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: - * `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 - * `CONSTRAINT` - A single constraint for the policy - enum: - - AND - - OR - - XOR - - CONSTRAINT + $ref: '#/components/schemas/UiPolicyConstraint' + description: "[Deprecated] Conjunction of constraints (simplified UiPolicyExpression)" + deprecated: true UiPolicyLiteral: required: - type @@ -927,6 +920,46 @@ components: - STRING - STRING_LIST - JSON + PolicyDefinitionCreateDto: + required: + - policy + - policyDefinitionId + type: object + properties: + policyDefinitionId: + type: string + description: Policy Definition ID + policy: + $ref: '#/components/schemas/UiPolicyExpression' + description: Create a Policy Definition + UiPolicyExpression: + type: object + properties: + type: + $ref: '#/components/schemas/UiPolicyExpressionType' + expressions: + type: array + description: "Only for types AND, OR, XOR. 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. All child expressions must be true. + * `OR` - Disjunction of several expressions. (At least) one child expression must be true. + * `XONE` - XOR operation, exactly one child expression must be true. + enum: + - EMPTY + - CONSTRAINT + - AND + - OR + - XONE UiAssetEditRequest: type: object properties: @@ -1273,12 +1306,8 @@ components: type: string description: EDC Policy JSON-LD. This is required because the EDC requires the full policy when initiating contract negotiations. - expressions: - type: array - description: Conjunction of required expressions for the policy to evaluate - to TRUE. - items: - $ref: '#/components/schemas/UiPolicyExpression' + expression: + $ref: '#/components/schemas/UiPolicyExpression' errors: type: array description: "When trying to reduce the policy JSON-LD to our opinionated\ diff --git a/extensions/catalog-crawler/catalog-crawler-e2e-test/src/test/java/de/sovity/edc/ext/catalog/crawler/CrawlerE2eTest.java b/extensions/catalog-crawler/catalog-crawler-e2e-test/src/test/java/de/sovity/edc/ext/catalog/crawler/CrawlerE2eTest.java index fb79645ed..e4db7fb6f 100644 --- a/extensions/catalog-crawler/catalog-crawler-e2e-test/src/test/java/de/sovity/edc/ext/catalog/crawler/CrawlerE2eTest.java +++ b/extensions/catalog-crawler/catalog-crawler-e2e-test/src/test/java/de/sovity/edc/ext/catalog/crawler/CrawlerE2eTest.java @@ -17,7 +17,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; @@ -26,7 +26,6 @@ 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; @@ -193,21 +192,22 @@ private void createPolicy() { .build()) .build(); - var expressions = Stream.of(afterYesterday, beforeTomorrow) - .map(it -> UiPolicyExpression.builder() - .expressionType(UiPolicyExpressionType.CONSTRAINT) - .constraint(it) - .build()) - .toList(); - - 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() - .expressions(expressions) - .build()) + .policy(expression) .build(); - connectorClient.uiApi().createPolicyDefinition(policyDefinition); + connectorClient.uiApi().createPolicyDefinitionV2(policyDefinition); } private void createContractDefinition() { diff --git a/extensions/wrapper/clients/java-client/README.md b/extensions/wrapper/clients/java-client/README.md index ca638b4ef..86826982a 100644 --- a/extensions/wrapper/clients/java-client/README.md +++ b/extensions/wrapper/clients/java-client/README.md @@ -144,7 +144,7 @@ public String buildCatenaXPolicy() { private UiPolicyExpression buildAnd(UiPolicyExpression... expressions) { return UiPolicyExpression.builder() - .expressionType(UiPolicyExpressionType.AND) + .type(UiPolicyExpressionType.AND) .expressions(Arrays.asList(expressions)) .build(); } @@ -155,7 +155,7 @@ private UiPolicyExpression buildConstraint( String right ) { return UiPolicyExpression.builder() - .expressionType(UiPolicyExpressionType.CONSTRAINT) + .type(UiPolicyExpressionType.CONSTRAINT) .constraint(UiPolicyConstraint.builder() .left(left) .operator(operator) diff --git a/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/UiResource.java b/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/UiResource.java index e81ec0a82..c79eb65ea 100644 --- a/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/UiResource.java +++ b/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/UiResource.java @@ -14,6 +14,7 @@ package de.sovity.edc.ext.wrapper.api.ui; +import de.sovity.edc.ext.wrapper.api.ui.model.PolicyDefinitionCreateDto; import de.sovity.edc.ext.wrapper.api.ui.model.PolicyDefinitionCreateRequest; import de.sovity.edc.ext.wrapper.api.common.model.UiAsset; import de.sovity.edc.ext.wrapper.api.common.model.UiAssetCreateRequest; @@ -95,9 +96,17 @@ interface UiResource { @Path("pages/policy-page/policy-definitions") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) - @Operation(description = "Create a new Policy Definition") + @Deprecated + @Operation(description = "[Deprecated] Create a new Policy Definition from a list of constraints", deprecated = true) IdResponseDto createPolicyDefinition(PolicyDefinitionCreateRequest policyDefinitionDtoDto); + @POST + @Path("v2/pages/policy-page/policy-definitions") + @Consumes(MediaType.APPLICATION_JSON) + @Produces(MediaType.APPLICATION_JSON) + @Operation(description = "Create a new Policy Definition") + IdResponseDto createPolicyDefinitionV2(PolicyDefinitionCreateDto policyDefinitionCreateDto); + @DELETE @Path("pages/policy-page/policy-definitions/{policyId}") @Produces(MediaType.APPLICATION_JSON) diff --git a/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/PolicyDefinitionCreateDto.java b/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/PolicyDefinitionCreateDto.java new file mode 100644 index 000000000..5f723f09c --- /dev/null +++ b/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/PolicyDefinitionCreateDto.java @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2022 sovity GmbH + * + * 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 + * + * SPDX-License-Identifier: Apache-2.0 + * + * Contributors: + * sovity GmbH - initial API and implementation + * + */ + +package de.sovity.edc.ext.wrapper.api.ui.model; + +import com.fasterxml.jackson.annotation.JsonInclude; +import de.sovity.edc.ext.wrapper.api.common.model.UiPolicyExpression; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.RequiredArgsConstructor; + +@Data +@AllArgsConstructor +@RequiredArgsConstructor +@Builder(toBuilder = true) +@JsonInclude(JsonInclude.Include.NON_NULL) +@Schema(description = "Create a Policy Definition") +public class PolicyDefinitionCreateDto { + @Schema(description = "Policy Definition ID", requiredMode = Schema.RequiredMode.REQUIRED) + private String policyDefinitionId; + + @Schema(description = "Policy Expression", requiredMode = Schema.RequiredMode.REQUIRED) + private UiPolicyExpression policy; +} + diff --git a/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/PolicyDefinitionCreateRequest.java b/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/PolicyDefinitionCreateRequest.java index 74795e04f..911d90db6 100644 --- a/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/PolicyDefinitionCreateRequest.java +++ b/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/PolicyDefinitionCreateRequest.java @@ -27,12 +27,14 @@ @RequiredArgsConstructor @Builder(toBuilder = true) @JsonInclude(JsonInclude.Include.NON_NULL) -@Schema(description = "Data for creating a Policy Definition") +@Deprecated +@Schema(description = "[Deprecated] Create a Policy Definition. Use PolicyDefinitionCreateDto", deprecated = true) public class PolicyDefinitionCreateRequest { @Schema(description = "Policy Definition ID", requiredMode = Schema.RequiredMode.REQUIRED) private String policyDefinitionId; - @Schema(description = "Policy Contents", requiredMode = Schema.RequiredMode.REQUIRED) + @Schema(description = "[Deprecated] Conjunction of constraints (simplified UiPolicyExpression)", + requiredMode = Schema.RequiredMode.REQUIRED, deprecated = true) private UiPolicyCreateRequest policy; } diff --git a/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiPolicy.java b/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiPolicy.java index ce72b2c40..2b6317edc 100644 --- a/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiPolicy.java +++ b/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiPolicy.java @@ -35,8 +35,8 @@ public class UiPolicy { "full policy when initiating contract negotiations.", requiredMode = RequiredMode.REQUIRED) private String policyJsonLd; - @Schema(description = "Conjunction of required expressions for the policy to evaluate to TRUE.") - private List expressions; + @Schema(description = "Policy expression") + private UiPolicyExpression expression; @Schema(description = "When trying to reduce the policy JSON-LD to our opinionated subset of functionalities, " + "many fields and functionalities are unsupported. Should any discrepancies occur during " + diff --git a/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiPolicyConstraint.java b/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiPolicyConstraint.java index a640aae62..58fc11f22 100644 --- a/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiPolicyConstraint.java +++ b/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiPolicyConstraint.java @@ -27,7 +27,7 @@ @RequiredArgsConstructor @Builder(toBuilder = true) @JsonInclude(JsonInclude.Include.NON_NULL) -@Schema(description = "ODRL AtomicConstraint as supported by the sovity product landscape") +@Schema(description = "ODRL AtomicConstraint as supported by the sovity product landscape. For example 'a EQ b', 'c IN [d, e, f]'") public class UiPolicyConstraint { @Schema(description = "Left side of the expression.", requiredMode = RequiredMode.REQUIRED) private String left; diff --git a/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiPolicyCreateRequest.java b/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiPolicyCreateRequest.java index e135937e2..91260c37c 100644 --- a/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiPolicyCreateRequest.java +++ b/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiPolicyCreateRequest.java @@ -28,8 +28,10 @@ @RequiredArgsConstructor @Builder(toBuilder = true) @JsonInclude(JsonInclude.Include.NON_NULL) -@Schema(description = "Type-Safe OpenAPI generator friendly ODLR policy subset as endorsed by sovity.") +@Deprecated +@Schema(description = "[Deprecated] Conjunction of constraints (simplified UiPolicyExpression)", + deprecated = true) public class UiPolicyCreateRequest { - @Schema(description = "Conjunction of required expressions for the policy to evaluate to TRUE.") - private List expressions; + @Schema(description = "Conjunction of required constraints") + private List expressions; } diff --git a/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiPolicyExpression.java b/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiPolicyExpression.java index 9a4f0478f..85abb5ff5 100644 --- a/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiPolicyExpression.java +++ b/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiPolicyExpression.java @@ -18,8 +18,8 @@ @Schema(description = "ODRL constraint as supported by the sovity product landscape") public class UiPolicyExpression { - @Schema(description = "Either LITERAL or one of the constraint types.") - private UiPolicyExpressionType expressionType; + @Schema(description = "Expression type") + private UiPolicyExpressionType type; @Schema(description = "Only for types AND, OR, XOR. List of sub-expressions " + "to be evaluated according to the expressionType.") @@ -28,31 +28,37 @@ public class UiPolicyExpression { @Schema(description = "Only for type CONSTRAINT. A single constraint.") private UiPolicyConstraint constraint; - public static UiPolicyExpression and(List expressions) { + public static UiPolicyExpression empty() { return UiPolicyExpression.builder() - .expressionType(UiPolicyExpressionType.AND) - .expressions(expressions) + .type(UiPolicyExpressionType.EMPTY) .build(); } - public static UiPolicyExpression or(List expressions) { + public static UiPolicyExpression constraint(UiPolicyConstraint constraint) { + return UiPolicyExpression.builder() + .type(UiPolicyExpressionType.CONSTRAINT) + .constraint(constraint) + .build(); + } + + public static UiPolicyExpression and(List expressions) { return UiPolicyExpression.builder() - .expressionType(UiPolicyExpressionType.OR) + .type(UiPolicyExpressionType.AND) .expressions(expressions) .build(); } - public static UiPolicyExpression xor(List expressions) { + public static UiPolicyExpression or(List expressions) { return UiPolicyExpression.builder() - .expressionType(UiPolicyExpressionType.XOR) + .type(UiPolicyExpressionType.OR) .expressions(expressions) .build(); } - public static UiPolicyExpression constraint(UiPolicyConstraint constraint) { + public static UiPolicyExpression xone(List expressions) { return UiPolicyExpression.builder() - .expressionType(UiPolicyExpressionType.CONSTRAINT) - .constraint(constraint) + .type(UiPolicyExpressionType.XONE) + .expressions(expressions) .build(); } } diff --git a/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiPolicyExpressionType.java b/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiPolicyExpressionType.java index ae374a8c5..9db06655c 100644 --- a/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiPolicyExpressionType.java +++ b/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiPolicyExpressionType.java @@ -4,13 +4,17 @@ @Schema(description = """ Ui Policy Expression types: - * `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 - * `CONSTRAINT` - A single constraint for the policy + * `CONSTRAINT` - Expression 'a=b' + * `AND` - Conjunction of several expressions. All child expressions must be true. + * `OR` - Disjunction of several expressions. (At least) one child expression must be true. + * `XONE` - XOR operation, exactly one child expression must be true. """, enumAsRef = true) public enum UiPolicyExpressionType { - AND, OR, XOR, CONSTRAINT + EMPTY, + CONSTRAINT, + AND, + OR, + XONE } diff --git a/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/LegacyPolicyMapper.java b/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/LegacyPolicyMapper.java new file mode 100644 index 000000000..ae0f5bb8a --- /dev/null +++ b/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/LegacyPolicyMapper.java @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2022 sovity GmbH + * + * 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 + * + * SPDX-License-Identifier: Apache-2.0 + * + * Contributors: + * sovity GmbH - initial API and implementation + * + */ + +package de.sovity.edc.ext.wrapper.api.common.mappers; + +import de.sovity.edc.ext.wrapper.api.common.model.UiPolicyConstraint; +import de.sovity.edc.ext.wrapper.api.common.model.UiPolicyCreateRequest; +import de.sovity.edc.ext.wrapper.api.common.model.UiPolicyExpression; +import lombok.RequiredArgsConstructor; + +import java.util.List; + +@RequiredArgsConstructor +public class LegacyPolicyMapper { + /** + * Builds a {@link UiPolicyExpression} from the legacy {@link UiPolicyCreateRequest}. + * + * @param createRequest {@link UiPolicyCreateRequest} + * @return {@link UiPolicyExpression} + */ + @Deprecated + public UiPolicyExpression buildUiPolicyExpression(UiPolicyCreateRequest createRequest) { + if (createRequest == null) { + return UiPolicyExpression.empty(); + } + + return buildUiPolicyExpression(createRequest.getExpressions()); + } + + private UiPolicyExpression buildUiPolicyExpression(List expressions) { + UiPolicyExpression expression; + if (expressions == null || expressions.isEmpty()) { + expression = UiPolicyExpression.empty(); + } else if (expressions.size() == 1) { + expression = UiPolicyExpression.constraint(expressions.get(0)); + } else { + expression = UiPolicyExpression.and( + expressions.stream().map(UiPolicyExpression::constraint).toList() + ); + } + return expression; + } +} diff --git a/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/PolicyMapper.java b/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/PolicyMapper.java index 7ae93423e..3b69efa56 100644 --- a/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/PolicyMapper.java +++ b/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/PolicyMapper.java @@ -15,29 +15,20 @@ package de.sovity.edc.ext.wrapper.api.common.mappers; import de.sovity.edc.ext.wrapper.api.common.mappers.asset.utils.FailedMappingException; -import de.sovity.edc.ext.wrapper.api.common.mappers.policy.AtomicConstraintMapper; import de.sovity.edc.ext.wrapper.api.common.mappers.policy.ExpressionExtractor; import de.sovity.edc.ext.wrapper.api.common.mappers.policy.ExpressionMapper; import de.sovity.edc.ext.wrapper.api.common.mappers.policy.MappingErrors; import de.sovity.edc.ext.wrapper.api.common.mappers.policy.PolicyValidator; import de.sovity.edc.ext.wrapper.api.common.model.UiPolicy; -import de.sovity.edc.ext.wrapper.api.common.model.UiPolicyCreateRequest; import de.sovity.edc.ext.wrapper.api.common.model.UiPolicyExpression; import de.sovity.edc.utils.JsonUtils; import jakarta.json.JsonObject; import lombok.RequiredArgsConstructor; import org.eclipse.edc.policy.model.Action; -import org.eclipse.edc.policy.model.AndConstraint; -import org.eclipse.edc.policy.model.Constraint; -import org.eclipse.edc.policy.model.OrConstraint; import org.eclipse.edc.policy.model.Permission; import org.eclipse.edc.policy.model.Policy; import org.eclipse.edc.policy.model.PolicyType; -import org.eclipse.edc.policy.model.XoneConstraint; import org.eclipse.edc.transform.spi.TypeTransformerRegistry; -import org.jetbrains.annotations.Nullable; - -import java.util.List; import static de.sovity.edc.utils.JsonUtils.toJson; @@ -58,11 +49,11 @@ public class PolicyMapper { public UiPolicy buildUiPolicy(Policy policy) { MappingErrors errors = MappingErrors.root(); - var expressions = expressionExtractor.getPermissionExpressions(policy, errors); + var expression = expressionExtractor.getPermissionExpression(policy, errors); return UiPolicy.builder() .policyJsonLd(toJson(buildPolicyJsonLd(policy))) - .expressions(expressions) + .expression(expression) .errors(errors.getErrors()) .build(); } @@ -72,17 +63,17 @@ public UiPolicy buildUiPolicy(Policy policy) { *

* This operation is lossless. * - * @param policyCreateDto policy + * @param expression policy * @return ODRL policy */ - public Policy buildPolicy(UiPolicyCreateRequest policyCreateDto) { - var constraints = expressionMapper.buildConstraints(policyCreateDto.getExpressions()); + public Policy buildPolicy(UiPolicyExpression expression) { + var constraints = expressionMapper.buildConstraint(expression); var action = Action.Builder.newInstance().type(PolicyValidator.ALLOWED_ACTION).build(); var permission = Permission.Builder.newInstance() .action(action) - .constraints(constraints) + .constraints(constraints.stream().toList()) .build(); return Policy.Builder.newInstance() diff --git a/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/policy/ExpressionExtractor.java b/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/policy/ExpressionExtractor.java index 010bcec4a..496659e11 100644 --- a/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/policy/ExpressionExtractor.java +++ b/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/policy/ExpressionExtractor.java @@ -26,6 +26,26 @@ public class ExpressionExtractor { private final PolicyValidator policyValidator; private final ExpressionMapper expressionMapper; + /** + * Build {@link UiPolicyExpression} from an ODRL {@link Policy}. + *

+ * This operation is lossy which is why we document warnings / errors in {@link MappingErrors}. + * + * @param policy ODRL policy + * @param errors mapping errors + * @return ui policy expression + */ + public UiPolicyExpression getPermissionExpression(Policy policy, MappingErrors errors) { + var expressions = getPermissionExpressions(policy, errors); + if (expressions.isEmpty()) { + return UiPolicyExpression.empty(); + } else if (expressions.size() == 1) { + return expressions.get(0); + } else { + return UiPolicyExpression.and(expressions); + } + } + /** * Build {@link UiPolicyExpression}s from an ODRL {@link Policy}. *

@@ -35,7 +55,7 @@ public class ExpressionExtractor { * @param errors mapping errors * @return ui policy expressions */ - public List getPermissionExpressions(Policy policy, MappingErrors errors) { + private List getPermissionExpressions(Policy policy, MappingErrors errors) { policyValidator.validateOtherPolicyFieldsUnset(policy, errors); var permissions = policy.getPermissions(); @@ -43,6 +63,10 @@ public List getPermissionExpressions(Policy policy, MappingE return List.of(); } + if (permissions.size() > 1) { + errors.add("Multiple permissions were present. Prefer using a conjunction using AND."); + } + List expressions = new ArrayList<>(); for (int iPermission = 0; iPermission < permissions.size(); iPermission++) { var permissionErrors = errors.forChildObject("permissions").forChildArrayElement(iPermission); @@ -59,8 +83,14 @@ private List getPermissionExpressions(Permission permission, return List.of(); } + var constraints = permission.getConstraints(); + if (constraints != null && constraints.size() > 1) { + errors.forChildObject("constraints") + .add("Multiple constraints were present. Prefer using a conjunction using AND."); + } + return expressionMapper.buildUiPolicyExpressions( - permission.getConstraints(), + constraints, errors.forChildObject("constraints") ); } diff --git a/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/policy/ExpressionMapper.java b/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/policy/ExpressionMapper.java index 1957ac420..025ce1488 100644 --- a/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/policy/ExpressionMapper.java +++ b/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/policy/ExpressionMapper.java @@ -43,6 +43,8 @@ public List buildConstraints( return expressions.stream() .map(this::buildConstraint) + .filter(Optional::isPresent) + .map(Optional::get) .toList(); } @@ -66,18 +68,24 @@ public List buildUiPolicyExpressions( return expressions; } - private Constraint buildConstraint(UiPolicyExpression expression) { - return switch (expression.getExpressionType()) { - case AND -> AndConstraint.Builder.newInstance() + public Optional buildConstraint(UiPolicyExpression expression) { + if (expression == null || expression.getType() == null) { + return Optional.empty(); + } + + return switch (expression.getType()) { + case EMPTY -> Optional.empty(); + case AND -> Optional.of(AndConstraint.Builder.newInstance() .constraints(buildConstraints(expression.getExpressions())) - .build(); - case OR -> OrConstraint.Builder.newInstance() + .build()); + case OR -> Optional.of(OrConstraint.Builder.newInstance() .constraints(buildConstraints(expression.getExpressions())) - .build(); - case XOR -> XoneConstraint.Builder.newInstance() + .build()); + case XONE -> Optional.of(XoneConstraint.Builder.newInstance() .constraints(buildConstraints(expression.getExpressions())) - .build(); - case CONSTRAINT -> atomicConstraintMapper.buildAtomicConstraint(expression.getConstraint()); + .build()); + case CONSTRAINT -> Optional.of(atomicConstraintMapper + .buildAtomicConstraint(expression.getConstraint())); }; } @@ -89,7 +97,7 @@ private Optional buildUiPolicyExpression(Constraint constrai if (constraint instanceof XoneConstraint xone) { return buildMultiUiPolicyExpression( - UiPolicyExpressionType.XOR, + UiPolicyExpressionType.XONE, xone.getConstraints(), errors.forChildObject("constraints") ); @@ -121,7 +129,7 @@ private Optional buildMultiUiPolicyExpression( ) { var expressions = buildUiPolicyExpressions(constraints, errors); var expression = UiPolicyExpression.builder() - .expressionType(type) + .type(type) .expressions(expressions) .build(); return Optional.of(expression); @@ -129,7 +137,7 @@ private Optional buildMultiUiPolicyExpression( private UiPolicyExpression buildConstraintUiPolicyExpression(UiPolicyConstraint constraint) { return UiPolicyExpression.builder() - .expressionType(UiPolicyExpressionType.CONSTRAINT) + .type(UiPolicyExpressionType.CONSTRAINT) .constraint(constraint) .build(); } diff --git a/extensions/wrapper/wrapper-common-mappers/src/test/java/de/sovity/edc/ext/wrapper/api/common/mappers/LegacyPolicyMapperTest.java b/extensions/wrapper/wrapper-common-mappers/src/test/java/de/sovity/edc/ext/wrapper/api/common/mappers/LegacyPolicyMapperTest.java new file mode 100644 index 000000000..4e9ac911e --- /dev/null +++ b/extensions/wrapper/wrapper-common-mappers/src/test/java/de/sovity/edc/ext/wrapper/api/common/mappers/LegacyPolicyMapperTest.java @@ -0,0 +1,105 @@ +/* + * Copyright (c) 2022 sovity GmbH + * + * 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 + * + * SPDX-License-Identifier: Apache-2.0 + * + * Contributors: + * sovity GmbH - initial API and implementation + * + */ + +package de.sovity.edc.ext.wrapper.api.common.mappers; + +import de.sovity.edc.ext.wrapper.api.common.model.UiPolicyConstraint; +import de.sovity.edc.ext.wrapper.api.common.model.UiPolicyCreateRequest; +import de.sovity.edc.ext.wrapper.api.common.model.UiPolicyExpression; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.junit.jupiter.MockitoExtension; + +import java.util.List; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Mockito.mock; + +@SuppressWarnings("deprecated") +@ExtendWith(MockitoExtension.class) +public class LegacyPolicyMapperTest { + @InjectMocks + LegacyPolicyMapper legacyPolicyMapper; + + @Test + void buildUiPolicyExpression_null() { + // arrange + var request = (UiPolicyCreateRequest) null; + + // act + UiPolicyExpression result = legacyPolicyMapper.buildUiPolicyExpression(request); + + // assert + assertThat(result).isEqualTo(UiPolicyExpression.empty()); + } + + @Test + void buildUiPolicyExpression_expressionsNull() { + // arrange + var request = new UiPolicyCreateRequest(); + request.setExpressions(null); + + // act + UiPolicyExpression result = legacyPolicyMapper.buildUiPolicyExpression(request); + + // assert + assertThat(result).isEqualTo(UiPolicyExpression.empty()); + } + + @Test + void buildUiPolicyExpression_emptyExpressions() { + // arrange + var request = new UiPolicyCreateRequest(); + request.setExpressions(List.of()); + + // act + UiPolicyExpression result = legacyPolicyMapper.buildUiPolicyExpression(request); + + // assert + assertThat(result).isEqualTo(UiPolicyExpression.empty()); + } + + @Test + void buildUiPolicyExpression_singleExpression() { + // arrange + var request = new UiPolicyCreateRequest(); + var expression = new UiPolicyConstraint(); + request.setExpressions(List.of(expression)); + + // act + UiPolicyExpression result = legacyPolicyMapper.buildUiPolicyExpression(request); + + // assert + assertThat(result).isEqualTo(UiPolicyExpression.constraint(expression)); + } + + @Test + void buildUiPolicyExpression_multipleExpressions() { + // arrange + var request = new UiPolicyCreateRequest(); + var constraint1 = mock(UiPolicyConstraint.class); + var constraint2 = mock(UiPolicyConstraint.class); + request.setExpressions(List.of(constraint1, constraint2)); + + // act + UiPolicyExpression result = legacyPolicyMapper.buildUiPolicyExpression(request); + + // assert + assertThat(result).isEqualTo(UiPolicyExpression.and(List.of( + UiPolicyExpression.constraint(constraint1), + UiPolicyExpression.constraint(constraint2) + ))); + } +} diff --git a/extensions/wrapper/wrapper-common-mappers/src/test/java/de/sovity/edc/ext/wrapper/api/common/mappers/PolicyMapperTest.java b/extensions/wrapper/wrapper-common-mappers/src/test/java/de/sovity/edc/ext/wrapper/api/common/mappers/PolicyMapperTest.java index e1f2e71a0..7ef734cfe 100644 --- a/extensions/wrapper/wrapper-common-mappers/src/test/java/de/sovity/edc/ext/wrapper/api/common/mappers/PolicyMapperTest.java +++ b/extensions/wrapper/wrapper-common-mappers/src/test/java/de/sovity/edc/ext/wrapper/api/common/mappers/PolicyMapperTest.java @@ -38,6 +38,7 @@ import org.mockito.junit.jupiter.MockitoExtension; import java.util.List; +import java.util.Optional; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.ArgumentMatchers.any; @@ -62,10 +63,10 @@ void buildUiPolicy() { var policy = mock(Policy.class); var expression = mock(UiPolicyExpression.class); - when(expressionExtractor.getPermissionExpressions(eq(policy), any())).thenAnswer(i -> { + when(expressionExtractor.getPermissionExpression(eq(policy), any())).thenAnswer(i -> { var errors = i.getArgument(1, MappingErrors.class); errors.add("test"); - return List.of(expression); + return expression; }); when(typeTransformerRegistry.transform(eq(policy), eq(JsonObject.class))) @@ -75,29 +76,44 @@ void buildUiPolicy() { var actual = policyMapper.buildUiPolicy(policy); // assert - assertThat(actual.getExpressions()).containsExactly(expression); + assertThat(actual.getExpression()).isEqualTo(expression); assertThat(actual.getErrors()).containsExactly("$: test"); assertThat(actual.getPolicyJsonLd()).isEqualTo("{\"a\":\"b\"}"); } @Test - void buildPolicy() { + void buildPolicy_constraintExtracted() { // arrange var uiExpression = mock(UiPolicyExpression.class); var constraint = mock(Constraint.class); - when(expressionMapper.buildConstraints(eq(List.of(uiExpression)))) - .thenReturn(List.of(constraint)); - - var createRequest = new UiPolicyCreateRequest(List.of(uiExpression)); + when(expressionMapper.buildConstraint(uiExpression)) + .thenReturn(Optional.of(constraint)); // act - var actual = policyMapper.buildPolicy(createRequest); + var actual = policyMapper.buildPolicy(uiExpression); // assert assertThat(actual.getType()).isEqualTo(PolicyType.SET); assertThat(actual.getPermissions()).hasSize(1); - assertThat(actual.getPermissions().get(0).getConstraints()).hasSize(1); assertThat(actual.getPermissions().get(0).getAction().getType()).isEqualTo("USE"); + assertThat(actual.getPermissions().get(0).getConstraints()).hasSize(1); assertThat(actual.getPermissions().get(0).getConstraints()).containsExactly(constraint); } + + @Test + void buildPolicy_noConstraint() { + // arrange + var uiExpression = mock(UiPolicyExpression.class); + when(expressionMapper.buildConstraint(uiExpression)) + .thenReturn(Optional.empty()); + + // act + var actual = policyMapper.buildPolicy(uiExpression); + + // assert + assertThat(actual.getType()).isEqualTo(PolicyType.SET); + assertThat(actual.getPermissions()).hasSize(1); + assertThat(actual.getPermissions().get(0).getConstraints()).isEmpty(); + assertThat(actual.getPermissions().get(0).getAction().getType()).isEqualTo("USE"); + } } diff --git a/extensions/wrapper/wrapper-common-mappers/src/test/java/de/sovity/edc/ext/wrapper/api/common/mappers/policy/ExpressionExtractorTest.java b/extensions/wrapper/wrapper-common-mappers/src/test/java/de/sovity/edc/ext/wrapper/api/common/mappers/policy/ExpressionExtractorTest.java index e7a541e46..b4e96b340 100644 --- a/extensions/wrapper/wrapper-common-mappers/src/test/java/de/sovity/edc/ext/wrapper/api/common/mappers/policy/ExpressionExtractorTest.java +++ b/extensions/wrapper/wrapper-common-mappers/src/test/java/de/sovity/edc/ext/wrapper/api/common/mappers/policy/ExpressionExtractorTest.java @@ -15,6 +15,7 @@ package de.sovity.edc.ext.wrapper.api.common.mappers.policy; import de.sovity.edc.ext.wrapper.api.common.model.UiPolicyExpression; +import de.sovity.edc.ext.wrapper.api.common.model.UiPolicyExpressionType; import org.eclipse.edc.policy.model.Constraint; import org.eclipse.edc.policy.model.Permission; import org.eclipse.edc.policy.model.Policy; @@ -25,7 +26,6 @@ import org.mockito.junit.jupiter.MockitoExtension; import java.util.List; -import java.util.Optional; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.ArgumentMatchers.any; @@ -53,10 +53,10 @@ void test_getPermissionConstraints_null() { var errors = MappingErrors.root(); // act - var actual = expressionExtractor.getPermissionExpressions(policy, errors); + var actual = expressionExtractor.getPermissionExpression(policy, errors); // assert - assertThat(actual).isEmpty(); + assertThat(actual.getType()).isEqualTo(UiPolicyExpressionType.EMPTY); verify(policyValidator).validateOtherPolicyFieldsUnset(policy, errors); } @@ -71,13 +71,40 @@ void test_getPermissionConstraints_no_constraints() { var errors = MappingErrors.root(); // act - var actual = expressionExtractor.getPermissionExpressions(policy, errors); + var actual = expressionExtractor.getPermissionExpression(policy, errors); // assert - assertThat(actual).isEmpty(); + assertThat(actual.getType()).isEqualTo(UiPolicyExpressionType.EMPTY); verify(policyValidator).validateOtherPolicyFieldsUnset(policy, errors); } + @Test + void test_getPermissionConstraints_single_constraint() { + // arrange + var constraint = mock(Constraint.class); + var permission = Permission.Builder.newInstance() + .constraint(constraint) + .build(); + + var policy = Policy.Builder.newInstance() + .permission(permission) + .build(); + var errors = MappingErrors.root(); + + var uiExpression = mock(UiPolicyExpression.class); + when(expressionMapper.buildUiPolicyExpressions(eq(List.of(constraint)), any())).thenReturn(List.of(uiExpression)); + + // act + var actual = expressionExtractor.getPermissionExpression(policy, errors); + + // assert + verify(policyValidator).validateOtherPermissionFieldsUnset(same(permission), any()); + assertThat(actual) + .usingRecursiveComparison() + .isEqualTo(uiExpression); + assertThat(errors.getErrors()).isEmpty(); + } + @Test void test_getPermissionConstraints_merge_constraints() { // arrange @@ -86,31 +113,69 @@ void test_getPermissionConstraints_merge_constraints() { .constraint(first) .build(); - var other = mock(Constraint.class); - var otherPermission = Permission.Builder.newInstance() - .constraint(other) + var second = mock(Constraint.class); + var secondPermission = Permission.Builder.newInstance() + .constraint(second) .build(); var policy = Policy.Builder.newInstance() .permission(firstPermission) - .permission(otherPermission) + .permission(secondPermission) .build(); var errors = MappingErrors.root(); var firstUiExpression = mock(UiPolicyExpression.class); - var otherUiExpression = mock(UiPolicyExpression.class); + var secondUiExpression = mock(UiPolicyExpression.class); when(expressionMapper.buildUiPolicyExpressions(eq(List.of(first)), any())).thenReturn(List.of(firstUiExpression)); - when(expressionMapper.buildUiPolicyExpressions(eq(List.of(other)), any())).thenReturn(List.of(otherUiExpression)); + when(expressionMapper.buildUiPolicyExpressions(eq(List.of(second)), any())).thenReturn(List.of(secondUiExpression)); // act - var actual = expressionExtractor.getPermissionExpressions(policy, errors); + var actual = expressionExtractor.getPermissionExpression(policy, errors); // assert verify(policyValidator).validateOtherPermissionFieldsUnset(same(firstPermission), any()); - verify(policyValidator).validateOtherPermissionFieldsUnset(same(otherPermission), any()); + verify(policyValidator).validateOtherPermissionFieldsUnset(same(secondPermission), any()); + var expected = UiPolicyExpression.and(List.of(firstUiExpression, secondUiExpression)); + assertThat(actual) + .usingRecursiveComparison() + .isEqualTo(expected); + assertThat(errors.getErrors()).containsExactly( + "$: Multiple permissions were present. Prefer using a conjunction using AND." + ); + } + + @Test + void test_getPermissionConstraints_merge_constraints2() { + // arrange + var first = mock(Constraint.class); + var second = mock(Constraint.class); + var permission = Permission.Builder.newInstance() + .constraints(List.of(first, second)) + .build(); + + var policy = Policy.Builder.newInstance() + .permission(permission) + .build(); + + var errors = MappingErrors.root(); + + var firstUiExpression = mock(UiPolicyExpression.class); + var secondUiExpression = mock(UiPolicyExpression.class); + when(expressionMapper.buildUiPolicyExpressions(eq(List.of(first, second)), any())) + .thenReturn(List.of(firstUiExpression, secondUiExpression)); + + // act + var actual = expressionExtractor.getPermissionExpression(policy, errors); + + // assert + verify(policyValidator).validateOtherPermissionFieldsUnset(same(permission), any()); + var expected = UiPolicyExpression.and(List.of(firstUiExpression, secondUiExpression)); assertThat(actual) - .usingRecursiveFieldByFieldElementComparator() - .containsExactly(firstUiExpression, otherUiExpression); + .usingRecursiveComparison() + .isEqualTo(expected); + assertThat(errors.getErrors()).containsExactly( + "$.permissions[0].constraints: Multiple constraints were present. Prefer using a conjunction using AND." + ); } @Test @@ -132,11 +197,13 @@ void test_getPermissionConstraints_error_mapping() { }); // act - var actual = expressionExtractor.getPermissionExpressions(policy, errors); + var actual = expressionExtractor.getPermissionExpression(policy, errors); // assert verify(policyValidator).validateOtherPermissionFieldsUnset(same(permission), any()); - assertThat(actual).isEmpty(); + assertThat(actual) + .usingRecursiveComparison() + .isEqualTo(UiPolicyExpression.empty()); assertThat(errors.getErrors()).containsExactlyInAnyOrder( "$.permissions[0].constraints: test" ); diff --git a/extensions/wrapper/wrapper-common-mappers/src/test/java/de/sovity/edc/ext/wrapper/api/common/mappers/policy/ExpressionMapperTest.java b/extensions/wrapper/wrapper-common-mappers/src/test/java/de/sovity/edc/ext/wrapper/api/common/mappers/policy/ExpressionMapperTest.java index 82ae5b7d2..6a481887c 100644 --- a/extensions/wrapper/wrapper-common-mappers/src/test/java/de/sovity/edc/ext/wrapper/api/common/mappers/policy/ExpressionMapperTest.java +++ b/extensions/wrapper/wrapper-common-mappers/src/test/java/de/sovity/edc/ext/wrapper/api/common/mappers/policy/ExpressionMapperTest.java @@ -44,7 +44,6 @@ class ExpressionMapperTest { @Mock AtomicConstraintMapper atomicConstraintMapper; - @Test void buildUiConstraint_errorPropagation() { // arrange @@ -144,7 +143,7 @@ void buildUiConstraint_xoneConstraint() { .thenReturn(Optional.of(uiConstraint)); var constraints = List.of( - OrConstraint.Builder.newInstance() + XoneConstraint.Builder.newInstance() .constraint(atomicConstraint) .build() ); @@ -154,7 +153,7 @@ void buildUiConstraint_xoneConstraint() { // assert assertThat(actual).containsExactly( - UiPolicyExpression.or(List.of( + UiPolicyExpression.xone(List.of( UiPolicyExpression.constraint(uiConstraint) )) ); @@ -230,7 +229,7 @@ void buildConstraint_orConstraint() { void buildConstraint_xoneConstraint() { // arrange var uiConstraint = mock(UiPolicyConstraint.class); - var expression = UiPolicyExpression.xor(List.of( + var expression = UiPolicyExpression.xone(List.of( UiPolicyExpression.constraint(uiConstraint) )); diff --git a/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/WrapperExtensionContextBuilder.java b/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/WrapperExtensionContextBuilder.java index 334e9d6ab..02d8c8ab0 100644 --- a/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/WrapperExtensionContextBuilder.java +++ b/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/WrapperExtensionContextBuilder.java @@ -16,6 +16,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; import de.sovity.edc.ext.wrapper.api.common.mappers.AssetMapper; +import de.sovity.edc.ext.wrapper.api.common.mappers.LegacyPolicyMapper; import de.sovity.edc.ext.wrapper.api.common.mappers.PolicyMapper; import de.sovity.edc.ext.wrapper.api.common.mappers.asset.AssetEditRequestMapper; import de.sovity.edc.ext.wrapper.api.common.mappers.asset.AssetJsonLdBuilder; @@ -199,9 +200,11 @@ public static WrapperExtensionContext buildContext( transferRequestBuilder, transferProcessService ); + var legacyPolicyMapper = new LegacyPolicyMapper(); var policyDefinitionApiService = new PolicyDefinitionApiService( policyDefinitionService, - policyMapper + policyMapper, + legacyPolicyMapper ); var dataOfferBuilder = new DspDataOfferBuilder(jsonLd); var uiDataOfferBuilder = new UiDataOfferBuilder(assetMapper, policyMapper); diff --git a/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/UiResourceImpl.java b/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/UiResourceImpl.java index e4189e936..89597247d 100644 --- a/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/UiResourceImpl.java +++ b/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/UiResourceImpl.java @@ -14,6 +14,7 @@ package de.sovity.edc.ext.wrapper.api.ui; +import de.sovity.edc.ext.wrapper.api.ui.model.PolicyDefinitionCreateDto; import de.sovity.edc.ext.wrapper.api.ui.model.PolicyDefinitionCreateRequest; import de.sovity.edc.ext.wrapper.api.common.model.UiAsset; import de.sovity.edc.ext.wrapper.api.common.model.UiAssetCreateRequest; @@ -94,10 +95,16 @@ public PolicyDefinitionPage getPolicyDefinitionPage() { } @Override + @Deprecated public IdResponseDto createPolicyDefinition(PolicyDefinitionCreateRequest policyDefinitionDtoDto) { return policyDefinitionApiService.createPolicyDefinition(policyDefinitionDtoDto); } + @Override + public IdResponseDto createPolicyDefinitionV2(PolicyDefinitionCreateDto policyDefinitionCreateDto) { + return policyDefinitionApiService.createPolicyDefinitionV2(policyDefinitionCreateDto); + } + @Override public IdResponseDto deletePolicyDefinition(String policyId) { return policyDefinitionApiService.deletePolicyDefinition(policyId); diff --git a/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/pages/policy/PolicyDefinitionApiService.java b/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/pages/policy/PolicyDefinitionApiService.java index 9b97085a1..cccc365e9 100644 --- a/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/pages/policy/PolicyDefinitionApiService.java +++ b/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/pages/policy/PolicyDefinitionApiService.java @@ -16,8 +16,11 @@ import de.sovity.edc.ext.wrapper.api.ServiceException; +import de.sovity.edc.ext.wrapper.api.common.mappers.LegacyPolicyMapper; import de.sovity.edc.ext.wrapper.api.common.mappers.PolicyMapper; +import de.sovity.edc.ext.wrapper.api.common.model.UiPolicyExpression; import de.sovity.edc.ext.wrapper.api.ui.model.IdResponseDto; +import de.sovity.edc.ext.wrapper.api.ui.model.PolicyDefinitionCreateDto; import de.sovity.edc.ext.wrapper.api.ui.model.PolicyDefinitionCreateRequest; import de.sovity.edc.ext.wrapper.api.ui.model.PolicyDefinitionDto; import jakarta.validation.constraints.NotNull; @@ -35,6 +38,7 @@ public class PolicyDefinitionApiService { private final PolicyDefinitionService policyDefinitionService; private final PolicyMapper policyMapper; + private final LegacyPolicyMapper legacyPolicyMapper; public List getPolicyDefinitions() { var policyDefinitions = getAllPolicyDefinitions(); @@ -45,8 +49,17 @@ public List getPolicyDefinitions() { } @NotNull + @Deprecated public IdResponseDto createPolicyDefinition(PolicyDefinitionCreateRequest request) { - var policyDefinition = buildPolicyDefinition(request); + var uiPolicyExpression = legacyPolicyMapper.buildUiPolicyExpression(request.getPolicy()); + var policyDefinition = buildPolicyDefinition(request.getPolicyDefinitionId(), uiPolicyExpression); + policyDefinition = policyDefinitionService.create(policyDefinition).orElseThrow(ServiceException::new); + return new IdResponseDto(policyDefinition.getId()); + } + + @NotNull + public IdResponseDto createPolicyDefinitionV2(PolicyDefinitionCreateDto request) { + var policyDefinition = buildPolicyDefinition(request.getPolicyDefinitionId(), request.getPolicy()); policyDefinition = policyDefinitionService.create(policyDefinition).orElseThrow(ServiceException::new); return new IdResponseDto(policyDefinition.getId()); } @@ -69,10 +82,10 @@ public PolicyDefinitionDto buildPolicyDefinitionDto(PolicyDefinition policyDefin .build(); } - public PolicyDefinition buildPolicyDefinition(PolicyDefinitionCreateRequest policyDefinitionDto) { - var policy = policyMapper.buildPolicy(policyDefinitionDto.getPolicy()); + public PolicyDefinition buildPolicyDefinition(String id, UiPolicyExpression uiPolicyExpression) { + var policy = policyMapper.buildPolicy(uiPolicyExpression); return PolicyDefinition.Builder.newInstance() - .id(policyDefinitionDto.getPolicyDefinitionId()) + .id(id) .policy(policy) .build(); } diff --git a/extensions/wrapper/wrapper/src/test/java/de/sovity/edc/ext/wrapper/api/ui/pages/catalog/CatalogApiTest.java b/extensions/wrapper/wrapper/src/test/java/de/sovity/edc/ext/wrapper/api/ui/pages/catalog/CatalogApiTest.java index 2ec04af14..219c85d4f 100644 --- a/extensions/wrapper/wrapper/src/test/java/de/sovity/edc/ext/wrapper/api/ui/pages/catalog/CatalogApiTest.java +++ b/extensions/wrapper/wrapper/src/test/java/de/sovity/edc/ext/wrapper/api/ui/pages/catalog/CatalogApiTest.java @@ -17,7 +17,7 @@ import de.sovity.edc.client.EdcClient; import de.sovity.edc.client.gen.model.ContractDefinitionRequest; import de.sovity.edc.client.gen.model.DataSourceType; -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; @@ -25,7 +25,8 @@ import de.sovity.edc.client.gen.model.UiCriterionOperator; import de.sovity.edc.client.gen.model.UiDataSource; import de.sovity.edc.client.gen.model.UiDataSourceHttpData; -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.ext.wrapper.TestUtils; import de.sovity.edc.extension.utils.junit.DisabledOnGithub; import de.sovity.edc.utils.jsonld.vocab.Prop; @@ -97,14 +98,12 @@ private void createAsset() { } private void createPolicy() { - var policyDefinition = PolicyDefinitionCreateRequest.builder() + var policyDefinition = PolicyDefinitionCreateDto.builder() .policyDefinitionId(dataOfferId) - .policy(UiPolicyCreateRequest.builder() - .expressions(List.of()) - .build()) + .policy(UiPolicyExpression.builder().type(UiPolicyExpressionType.EMPTY).build()) .build(); - client.uiApi().createPolicyDefinition(policyDefinition); + client.uiApi().createPolicyDefinitionV2(policyDefinition); } private void createContractDefinition() { diff --git a/extensions/wrapper/wrapper/src/test/java/de/sovity/edc/ext/wrapper/api/ui/pages/contract_agreement/ContractAgreementPageTest.java b/extensions/wrapper/wrapper/src/test/java/de/sovity/edc/ext/wrapper/api/ui/pages/contract_agreement/ContractAgreementPageTest.java index 4814f1a35..99d5bd9f9 100644 --- a/extensions/wrapper/wrapper/src/test/java/de/sovity/edc/ext/wrapper/api/ui/pages/contract_agreement/ContractAgreementPageTest.java +++ b/extensions/wrapper/wrapper/src/test/java/de/sovity/edc/ext/wrapper/api/ui/pages/contract_agreement/ContractAgreementPageTest.java @@ -18,6 +18,7 @@ import de.sovity.edc.client.gen.model.ContractAgreementDirection; import de.sovity.edc.client.gen.model.OperatorDto; import de.sovity.edc.client.gen.model.TransferProcessSimplifiedState; +import de.sovity.edc.client.gen.model.UiPolicyExpressionType; import de.sovity.edc.ext.wrapper.TestUtils; import de.sovity.edc.utils.jsonld.vocab.Prop; import org.eclipse.edc.connector.contract.spi.negotiation.store.ContractNegotiationStore; @@ -108,7 +109,10 @@ void testContractAgreementPage( assertThat(transfer.getState().getSimplifiedState()).isEqualTo(TransferProcessSimplifiedState.OK); assertThat(transfer.getErrorMessage()).isEqualTo("my-error-message-1"); - var constraint = agreement.getContractPolicy().getExpressions().get(0).getConstraint(); + var expression = agreement.getContractPolicy().getExpression(); + assertThat(expression.getType()).isEqualTo(UiPolicyExpressionType.CONSTRAINT); + + var constraint = expression.getConstraint(); assertThat(constraint.getLeft()).isEqualTo("ALWAYS_TRUE"); assertThat(constraint.getOperator()).isEqualTo(OperatorDto.EQ); assertThat(constraint.getRight().getValue()).isEqualTo("true"); diff --git a/extensions/wrapper/wrapper/src/test/java/de/sovity/edc/ext/wrapper/api/ui/pages/policy/PolicyDefinitionApiServiceTest.java b/extensions/wrapper/wrapper/src/test/java/de/sovity/edc/ext/wrapper/api/ui/pages/policy/PolicyDefinitionApiServiceTest.java index 47a4418d7..0e4bd383f 100644 --- a/extensions/wrapper/wrapper/src/test/java/de/sovity/edc/ext/wrapper/api/ui/pages/policy/PolicyDefinitionApiServiceTest.java +++ b/extensions/wrapper/wrapper/src/test/java/de/sovity/edc/ext/wrapper/api/ui/pages/policy/PolicyDefinitionApiServiceTest.java @@ -17,10 +17,9 @@ import de.sovity.edc.client.EdcClient; 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.PolicyDefinitionDto; 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; @@ -36,8 +35,6 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; -import java.util.List; - import static org.assertj.core.api.Assertions.assertThat; @ApiTest @@ -46,7 +43,7 @@ class PolicyDefinitionApiServiceTest { EdcClient client; UiPolicyExpression expression = UiPolicyExpression.builder() - .expressionType(UiPolicyExpressionType.CONSTRAINT) + .type(UiPolicyExpressionType.CONSTRAINT) .constraint(UiPolicyConstraint.builder() .left("a") .operator(OperatorDto.EQ) @@ -78,10 +75,7 @@ void getPolicyList() { .filter(it -> it.getPolicyDefinitionId().equals("my-policy-def-1")) .findFirst().get(); assertThat(policyDefinition.getPolicyDefinitionId()).isEqualTo("my-policy-def-1"); - assertThat(policyDefinition.getPolicy().getExpressions()).hasSize(1); - - var constraintEntry = policyDefinition.getPolicy().getExpressions().get(0); - assertThat(constraintEntry).usingRecursiveComparison().isEqualTo(expression); + assertThat(policyDefinition.getPolicy().getExpression()).usingRecursiveComparison().isEqualTo(expression); } @Test @@ -121,9 +115,8 @@ void test_delete(PolicyDefinitionService policyDefinitionService) { } private void createPolicyDefinition(String policyDefinitionId) { - var policy = new UiPolicyCreateRequest(List.of(expression)); - var policyDefinition = new PolicyDefinitionCreateRequest(policyDefinitionId, policy); - client.uiApi().createPolicyDefinition(policyDefinition); + var policyDefinition = new PolicyDefinitionCreateDto(policyDefinitionId, expression); + client.uiApi().createPolicyDefinitionV2(policyDefinition); } @SneakyThrows diff --git a/extensions/wrapper/wrapper/src/test/java/de/sovity/edc/ext/wrapper/api/usecase/UseCaseApiWrapperTest.java b/extensions/wrapper/wrapper/src/test/java/de/sovity/edc/ext/wrapper/api/usecase/UseCaseApiWrapperTest.java index 74ee6c156..0af6103c2 100644 --- a/extensions/wrapper/wrapper/src/test/java/de/sovity/edc/ext/wrapper/api/usecase/UseCaseApiWrapperTest.java +++ b/extensions/wrapper/wrapper/src/test/java/de/sovity/edc/ext/wrapper/api/usecase/UseCaseApiWrapperTest.java @@ -22,7 +22,7 @@ import de.sovity.edc.client.gen.model.CatalogQuery; import de.sovity.edc.client.gen.model.ContractDefinitionRequest; import de.sovity.edc.client.gen.model.DataSourceType; -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; @@ -30,7 +30,8 @@ import de.sovity.edc.client.gen.model.UiCriterionOperator; import de.sovity.edc.client.gen.model.UiDataSource; import de.sovity.edc.client.gen.model.UiDataSourceHttpData; -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.ext.wrapper.TestUtils; import de.sovity.edc.extension.utils.junit.DisabledOnGithub; import de.sovity.edc.utils.jsonld.vocab.Prop; @@ -41,7 +42,6 @@ import org.junit.jupiter.api.extension.ExtendWith; import java.util.List; -import java.util.Map; import static org.assertj.core.api.Assertions.assertThat; @@ -194,11 +194,11 @@ private void setupAssets() { .mediaType("application/json") .build()).getId(); - policyId = client.uiApi().createPolicyDefinition(PolicyDefinitionCreateRequest.builder() + policyId = client.uiApi().createPolicyDefinitionV2(PolicyDefinitionCreateDto.builder() .policyDefinitionId("policy-1") - .policy(UiPolicyCreateRequest.builder() - .expressions(List.of()) - .build()) + .policy(UiPolicyExpression.builder() + .type(UiPolicyExpressionType.EMPTY) + .build()) .build()).getId(); } } diff --git a/tests/src/test/java/de/sovity/edc/e2e/ApiWrapperDemoTest.java b/tests/src/test/java/de/sovity/edc/e2e/ApiWrapperDemoTest.java index 04383100b..4afaf8b7c 100644 --- a/tests/src/test/java/de/sovity/edc/e2e/ApiWrapperDemoTest.java +++ b/tests/src/test/java/de/sovity/edc/e2e/ApiWrapperDemoTest.java @@ -20,7 +20,7 @@ import de.sovity.edc.client.gen.model.DataSourceType; import de.sovity.edc.client.gen.model.InitiateTransferRequest; 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.UiContractNegotiation; import de.sovity.edc.client.gen.model.UiContractOffer; @@ -32,7 +32,6 @@ 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; @@ -148,7 +147,7 @@ private void createAsset() { private void createPolicy() { var afterYesterday = UiPolicyExpression.builder() - .expressionType(UiPolicyExpressionType.CONSTRAINT) + .type(UiPolicyExpressionType.CONSTRAINT) .constraint(UiPolicyConstraint.builder() .left("POLICY_EVALUATION_TIME") .operator(OperatorDto.GT) @@ -160,7 +159,7 @@ private void createPolicy() { .build(); var beforeTomorrow = UiPolicyExpression.builder() - .expressionType(UiPolicyExpressionType.CONSTRAINT) + .type(UiPolicyExpressionType.CONSTRAINT) .constraint(UiPolicyConstraint.builder() .left("POLICY_EVALUATION_TIME") .operator(OperatorDto.LT) @@ -171,14 +170,17 @@ private void createPolicy() { .build()) .build(); - var policyDefinition = PolicyDefinitionCreateRequest.builder() + var expression = UiPolicyExpression.builder() + .type(UiPolicyExpressionType.AND) + .expressions(List.of(afterYesterday, beforeTomorrow)) + .build(); + + var policyDefinition = PolicyDefinitionCreateDto.builder() .policyDefinitionId(dataOfferId) - .policy(UiPolicyCreateRequest.builder() - .expressions(List.of(afterYesterday, beforeTomorrow)) - .build()) + .policy(expression) .build(); - providerClient.uiApi().createPolicyDefinition(policyDefinition); + providerClient.uiApi().createPolicyDefinitionV2(policyDefinition); } private void createContractDefinition() { diff --git a/tests/src/test/java/de/sovity/edc/e2e/DataSourceParameterizationTest.java b/tests/src/test/java/de/sovity/edc/e2e/DataSourceParameterizationTest.java index 8bbb9e437..77d33cc48 100644 --- a/tests/src/test/java/de/sovity/edc/e2e/DataSourceParameterizationTest.java +++ b/tests/src/test/java/de/sovity/edc/e2e/DataSourceParameterizationTest.java @@ -20,7 +20,7 @@ import de.sovity.edc.client.gen.model.DataSourceType; import de.sovity.edc.client.gen.model.InitiateCustomTransferRequest; import de.sovity.edc.client.gen.model.InitiateTransferRequest; -import de.sovity.edc.client.gen.model.PolicyDefinitionCreateRequest; +import de.sovity.edc.client.gen.model.PolicyDefinitionCreateDto; import de.sovity.edc.client.gen.model.TransferHistoryEntry; import de.sovity.edc.client.gen.model.UiAssetCreateRequest; import de.sovity.edc.client.gen.model.UiContractNegotiation; @@ -32,7 +32,8 @@ import de.sovity.edc.client.gen.model.UiDataOffer; import de.sovity.edc.client.gen.model.UiDataSource; import de.sovity.edc.client.gen.model.UiDataSourceHttpData; -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.extension.e2e.connector.ConnectorRemote; import de.sovity.edc.extension.e2e.db.TestDatabase; import de.sovity.edc.extension.e2e.db.TestDatabaseFactory; @@ -446,14 +447,14 @@ private String createAssetWithParameterizedMethod(TestCase testCase) { } private void createPolicy(TestCase testCase) { - var policyDefinition = PolicyDefinitionCreateRequest.builder() + var policyDefinition = PolicyDefinitionCreateDto.builder() .policyDefinitionId(testCase.id) - .policy(UiPolicyCreateRequest.builder() - .expressions(List.of()) + .policy(UiPolicyExpression.builder() + .type(UiPolicyExpressionType.EMPTY) .build()) .build(); - providerClient.uiApi().createPolicyDefinition(policyDefinition); + providerClient.uiApi().createPolicyDefinitionV2(policyDefinition); } private String createContractDefinition(TestCase testCase) { diff --git a/tests/src/test/java/de/sovity/edc/e2e/DataSourceQueryParamsTest.java b/tests/src/test/java/de/sovity/edc/e2e/DataSourceQueryParamsTest.java index 6a12f1179..d0f77fa8d 100644 --- a/tests/src/test/java/de/sovity/edc/e2e/DataSourceQueryParamsTest.java +++ b/tests/src/test/java/de/sovity/edc/e2e/DataSourceQueryParamsTest.java @@ -19,7 +19,7 @@ import de.sovity.edc.client.gen.model.ContractNegotiationSimplifiedState; import de.sovity.edc.client.gen.model.DataSourceType; import de.sovity.edc.client.gen.model.InitiateTransferRequest; -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.UiContractNegotiation; import de.sovity.edc.client.gen.model.UiContractOffer; @@ -30,7 +30,8 @@ import de.sovity.edc.client.gen.model.UiDataOffer; import de.sovity.edc.client.gen.model.UiDataSource; import de.sovity.edc.client.gen.model.UiDataSourceHttpData; -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.extension.e2e.connector.ConnectorRemote; import de.sovity.edc.extension.e2e.connector.MockDataAddressRemote; import de.sovity.edc.extension.e2e.db.TestDatabase; @@ -154,14 +155,14 @@ private void createAsset() { } private void createPolicy() { - var policyDefinition = PolicyDefinitionCreateRequest.builder() + var policyDefinition = PolicyDefinitionCreateDto.builder() .policyDefinitionId(dataOfferId) - .policy(UiPolicyCreateRequest.builder() - .expressions(List.of()) + .policy(UiPolicyExpression.builder() + .type(UiPolicyExpressionType.EMPTY) .build()) .build(); - providerClient.uiApi().createPolicyDefinition(policyDefinition); + providerClient.uiApi().createPolicyDefinitionV2(policyDefinition); } private void createContractDefinition() { diff --git a/tests/src/test/java/de/sovity/edc/e2e/UiApiWrapperTest.java b/tests/src/test/java/de/sovity/edc/e2e/UiApiWrapperTest.java index 0668295ab..99090b93a 100644 --- a/tests/src/test/java/de/sovity/edc/e2e/UiApiWrapperTest.java +++ b/tests/src/test/java/de/sovity/edc/e2e/UiApiWrapperTest.java @@ -21,7 +21,7 @@ import de.sovity.edc.client.gen.model.InitiateCustomTransferRequest; import de.sovity.edc.client.gen.model.InitiateTransferRequest; 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.TransferProcessSimplifiedState; import de.sovity.edc.client.gen.model.UiAssetCreateRequest; import de.sovity.edc.client.gen.model.UiAssetEditRequest; @@ -35,7 +35,6 @@ 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; @@ -128,7 +127,7 @@ void provide_consume_assetMapping_policyMapping_agreements() { var yesterday = OffsetDateTime.now().minusDays(1); var policyExpression = UiPolicyExpression.builder() - .expressionType(UiPolicyExpressionType.CONSTRAINT) + .type(UiPolicyExpressionType.CONSTRAINT) .constraint(UiPolicyConstraint.builder() .left("POLICY_EVALUATION_TIME") .operator(OperatorDto.GT) @@ -139,11 +138,9 @@ void provide_consume_assetMapping_policyMapping_agreements() { .build()) .build(); - var policyId = providerClient.uiApi().createPolicyDefinition(PolicyDefinitionCreateRequest.builder() + var policyId = providerClient.uiApi().createPolicyDefinitionV2(PolicyDefinitionCreateDto.builder() .policyDefinitionId("policy-1") - .policy(UiPolicyCreateRequest.builder() - .expressions(List.of(policyExpression)) - .build()) + .policy(policyExpression) .build()).getId(); var dataSource = UiDataSource.builder() @@ -303,7 +300,7 @@ void provide_consume_assetMapping_policyMapping_agreements() { assertThat(providerAgreement.getCounterPartyId()).isEqualTo(CONSUMER_PARTICIPANT_ID); assertThat(providerAgreement.getAsset().getAssetId()).isEqualTo(assetId); - var providingContractPolicyExpression = providerAgreement.getContractPolicy().getExpressions().get(0); + var providingContractPolicyExpression = providerAgreement.getContractPolicy().getExpression(); assertThat(providingContractPolicyExpression).usingRecursiveComparison().isEqualTo(policyExpression); assertThat(providerAgreement.getAsset().getAssetId()).isEqualTo(assetId); @@ -318,16 +315,15 @@ void provide_consume_assetMapping_policyMapping_agreements() { assertThat(consumerAgreement.getCounterPartyId()).isEqualTo(PROVIDER_PARTICIPANT_ID); assertThat(consumerAgreement.getAsset().getAssetId()).isEqualTo(assetId); - var consumingContractPolicyConstraint = consumerAgreement.getContractPolicy().getExpressions().get(0); + var consumingContractPolicyConstraint = consumerAgreement.getContractPolicy().getExpression(); assertThat(consumingContractPolicyConstraint).usingRecursiveComparison().isEqualTo(policyExpression); assertThat(consumerAgreement.getAsset().getAssetId()).isEqualTo(assetId); assertThat(consumerAgreement.getAsset().getTitle()).isEqualTo(assetId); // Test Policy - assertThat(contractOffer.getPolicy().getExpressions()).hasSize(1); - var actualExpression = contractOffer.getPolicy().getExpressions().get(0); - assertThat(actualExpression.getExpressionType()).isEqualTo(UiPolicyExpressionType.CONSTRAINT); + var actualExpression = contractOffer.getPolicy().getExpression(); + assertThat(actualExpression.getType()).isEqualTo(UiPolicyExpressionType.CONSTRAINT); var constraint = actualExpression.getConstraint(); assertThat(constraint.getLeft()).isEqualTo("POLICY_EVALUATION_TIME"); @@ -408,10 +404,10 @@ void customTransferRequest() { .build()).getId(); assertThat(assetId).isEqualTo("asset-1"); - var policyId = providerClient.uiApi().createPolicyDefinition(PolicyDefinitionCreateRequest.builder() + var policyId = providerClient.uiApi().createPolicyDefinitionV2(PolicyDefinitionCreateDto.builder() .policyDefinitionId("policy-1") - .policy(UiPolicyCreateRequest.builder() - .expressions(List.of()) + .policy(UiPolicyExpression.builder() + .type(UiPolicyExpressionType.EMPTY) .build()) .build()).getId(); diff --git a/tests/src/test/java/de/sovity/edc/e2e/UseCaseApiWrapperTest.java b/tests/src/test/java/de/sovity/edc/e2e/UseCaseApiWrapperTest.java index 95d7b79a6..9ce948914 100644 --- a/tests/src/test/java/de/sovity/edc/e2e/UseCaseApiWrapperTest.java +++ b/tests/src/test/java/de/sovity/edc/e2e/UseCaseApiWrapperTest.java @@ -22,7 +22,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; @@ -31,7 +31,6 @@ 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; @@ -166,7 +165,7 @@ private void createAsset() { private void createPolicy() { var afterYesterday = UiPolicyExpression.builder() - .expressionType(UiPolicyExpressionType.CONSTRAINT) + .type(UiPolicyExpressionType.CONSTRAINT) .constraint(UiPolicyConstraint.builder() .left("POLICY_EVALUATION_TIME") .operator(OperatorDto.GT) @@ -178,7 +177,7 @@ private void createPolicy() { .build(); var beforeTomorrow = UiPolicyExpression.builder() - .expressionType(UiPolicyExpressionType.CONSTRAINT) + .type(UiPolicyExpressionType.CONSTRAINT) .constraint(UiPolicyConstraint.builder() .left("POLICY_EVALUATION_TIME") .operator(OperatorDto.LT) @@ -189,14 +188,17 @@ private void createPolicy() { .build()) .build(); - var policyDefinition = PolicyDefinitionCreateRequest.builder() + var expression = UiPolicyExpression.builder() + .type(UiPolicyExpressionType.AND) + .expressions(List.of(afterYesterday, beforeTomorrow)) + .build(); + + var policyDefinition = PolicyDefinitionCreateDto.builder() .policyDefinitionId(dataOfferId) - .policy(UiPolicyCreateRequest.builder() - .expressions(List.of(afterYesterday, beforeTomorrow)) - .build()) + .policy(expression) .build(); - providerClient.uiApi().createPolicyDefinition(policyDefinition); + providerClient.uiApi().createPolicyDefinitionV2(policyDefinition); } private void createContractDefinition() { From c4d4efb0d4081278e67ad732ea487700c35ca727 Mon Sep 17 00:00:00 2001 From: Richard Treier Date: Thu, 18 Jul 2024 15:44:02 +0300 Subject: [PATCH 10/18] chore: post-merge fixes --- docs/api/sovity-edc-api-wrapper.yaml | 6 +- .../api/common/model/UiPolicyExpression.java | 8 ++- .../api/usecase/UseCaseResourceImpl.java | 1 - .../ContractAgreementPageTest.java | 4 +- .../PolicyDefinitionApiServiceTest.java | 10 ---- .../de/sovity/edc/e2e/UiApiWrapperTest.java | 60 ++++--------------- .../extension/e2e/extension/E2eScenario.java | 43 +++++++++---- 7 files changed, 54 insertions(+), 78 deletions(-) diff --git a/docs/api/sovity-edc-api-wrapper.yaml b/docs/api/sovity-edc-api-wrapper.yaml index e89510d46..8d7ee5807 100644 --- a/docs/api/sovity-edc-api-wrapper.yaml +++ b/docs/api/sovity-edc-api-wrapper.yaml @@ -526,11 +526,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: @@ -738,6 +738,7 @@ components: UiDataSourceHttpDataMethod: type: string description: Supported HTTP Methods by UiDataSource + default: GET enum: - GET - POST @@ -745,7 +746,6 @@ components: - PATCH - DELETE - OPTIONS - default: GET UiDataSourceOnRequest: required: - contactEmail @@ -934,6 +934,8 @@ components: $ref: '#/components/schemas/UiPolicyExpression' description: Create a Policy Definition UiPolicyExpression: + required: + - type type: object properties: type: diff --git a/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiPolicyExpression.java b/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiPolicyExpression.java index 85abb5ff5..37c116872 100644 --- a/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiPolicyExpression.java +++ b/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiPolicyExpression.java @@ -18,14 +18,16 @@ @Schema(description = "ODRL constraint as supported by the sovity product landscape") public class UiPolicyExpression { - @Schema(description = "Expression type") + @Schema(description = "Expression type", requiredMode = Schema.RequiredMode.REQUIRED) private UiPolicyExpressionType type; @Schema(description = "Only for types AND, OR, XOR. List of sub-expressions " + - "to be evaluated according to the expressionType.") + "to be evaluated according to the expressionType.", + requiredMode = Schema.RequiredMode.NOT_REQUIRED) private List expressions; - @Schema(description = "Only for type CONSTRAINT. A single constraint.") + @Schema(description = "Only for type CONSTRAINT. A single constraint.", + requiredMode = Schema.RequiredMode.NOT_REQUIRED) private UiPolicyConstraint constraint; public static UiPolicyExpression empty() { diff --git a/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/usecase/UseCaseResourceImpl.java b/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/usecase/UseCaseResourceImpl.java index 659c50070..7f1bf7d74 100644 --- a/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/usecase/UseCaseResourceImpl.java +++ b/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/usecase/UseCaseResourceImpl.java @@ -17,7 +17,6 @@ import de.sovity.edc.ext.wrapper.api.ui.model.UiDataOffer; import de.sovity.edc.ext.wrapper.api.usecase.model.CatalogQuery; import de.sovity.edc.ext.wrapper.api.usecase.model.KpiResult; -import de.sovity.edc.ext.wrapper.api.usecase.model.PolicyCreateRequest; import de.sovity.edc.ext.wrapper.api.usecase.pages.catalog.UseCaseCatalogApiService; import de.sovity.edc.ext.wrapper.api.usecase.services.KpiApiService; import de.sovity.edc.ext.wrapper.api.usecase.services.SupportedPolicyApiService; diff --git a/extensions/wrapper/wrapper/src/test/java/de/sovity/edc/ext/wrapper/api/ui/pages/contract_agreement/ContractAgreementPageTest.java b/extensions/wrapper/wrapper/src/test/java/de/sovity/edc/ext/wrapper/api/ui/pages/contract_agreement/ContractAgreementPageTest.java index 7c74ba03d..a69824768 100644 --- a/extensions/wrapper/wrapper/src/test/java/de/sovity/edc/ext/wrapper/api/ui/pages/contract_agreement/ContractAgreementPageTest.java +++ b/extensions/wrapper/wrapper/src/test/java/de/sovity/edc/ext/wrapper/api/ui/pages/contract_agreement/ContractAgreementPageTest.java @@ -18,8 +18,8 @@ import de.sovity.edc.client.gen.model.ContractAgreementDirection; import de.sovity.edc.client.gen.model.OperatorDto; import de.sovity.edc.client.gen.model.TransferProcessSimplifiedState; -import de.sovity.edc.ext.wrapper.TestUtils; -import de.sovity.edc.client.gen.model.UiPolicyExpressionType;import de.sovity.edc.extension.e2e.connector.ConnectorRemote; +import de.sovity.edc.client.gen.model.UiPolicyExpressionType; +import de.sovity.edc.extension.e2e.connector.ConnectorRemote; import de.sovity.edc.extension.e2e.connector.config.ConnectorConfig; import de.sovity.edc.extension.e2e.db.EdcRuntimeExtensionWithTestDatabase; import de.sovity.edc.utils.jsonld.vocab.Prop; diff --git a/extensions/wrapper/wrapper/src/test/java/de/sovity/edc/ext/wrapper/api/ui/pages/policy/PolicyDefinitionApiServiceTest.java b/extensions/wrapper/wrapper/src/test/java/de/sovity/edc/ext/wrapper/api/ui/pages/policy/PolicyDefinitionApiServiceTest.java index a8c650db5..f6e3344df 100644 --- a/extensions/wrapper/wrapper/src/test/java/de/sovity/edc/ext/wrapper/api/ui/pages/policy/PolicyDefinitionApiServiceTest.java +++ b/extensions/wrapper/wrapper/src/test/java/de/sovity/edc/ext/wrapper/api/ui/pages/policy/PolicyDefinitionApiServiceTest.java @@ -28,18 +28,15 @@ import de.sovity.edc.extension.db.directaccess.DslContextFactory; import de.sovity.edc.extension.e2e.connector.config.ConnectorConfig; import de.sovity.edc.extension.e2e.db.EdcRuntimeExtensionWithTestDatabase; -import lombok.SneakyThrows; import lombok.val; import org.eclipse.edc.connector.spi.policydefinition.PolicyDefinitionService; import org.eclipse.edc.junit.annotations.ApiTest; -import org.eclipse.edc.junit.extensions.EdcRuntimeExtension; import org.eclipse.edc.spi.entity.Entity; import org.eclipse.edc.spi.query.QuerySpec; import org.jooq.DSLContext; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; -import java.util.List; import java.util.Map; import static de.sovity.edc.extension.e2e.connector.config.ConnectorConfigFactory.forTestDatabase; @@ -67,13 +64,6 @@ class PolicyDefinitionApiServiceTest { UiPolicyExpression expression = UiPolicyExpression.builder() .type(UiPolicyExpressionType.CONSTRAINT) .constraint(UiPolicyConstraint.builder() - .left("a") - .operator(OperatorDto.EQ) - .right(UiPolicyLiteral.builder() - .type(UiPolicyLiteralType.STRING) - .value("b") - .build()) - .build(); .left("a") .operator(OperatorDto.EQ) .right(UiPolicyLiteral.builder() diff --git a/tests/src/test/java/de/sovity/edc/e2e/UiApiWrapperTest.java b/tests/src/test/java/de/sovity/edc/e2e/UiApiWrapperTest.java index ac3e949d4..6939fbc34 100644 --- a/tests/src/test/java/de/sovity/edc/e2e/UiApiWrapperTest.java +++ b/tests/src/test/java/de/sovity/edc/e2e/UiApiWrapperTest.java @@ -23,6 +23,7 @@ import de.sovity.edc.client.gen.model.InitiateTransferRequest; import de.sovity.edc.client.gen.model.OperatorDto; import de.sovity.edc.client.gen.model.PolicyDefinitionCreateDto; +import de.sovity.edc.client.gen.model.PolicyDefinitionCreateRequest; import de.sovity.edc.client.gen.model.TransferProcessSimplifiedState; import de.sovity.edc.client.gen.model.UiAssetCreateRequest; import de.sovity.edc.client.gen.model.UiAssetEditRequest; @@ -36,6 +37,7 @@ 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; @@ -102,7 +104,7 @@ void provide_consume_assetMapping_policyMapping_agreements( var data = "expected data 123"; var yesterday = OffsetDateTime.now().minusDays(1); - var policyExpression = UiPolicyExpression.builder() + var expression = UiPolicyExpression.builder() .type(UiPolicyExpressionType.CONSTRAINT) .constraint(UiPolicyConstraint.builder() .left("POLICY_EVALUATION_TIME") @@ -116,7 +118,7 @@ void provide_consume_assetMapping_policyMapping_agreements( var policyId = providerClient.uiApi().createPolicyDefinitionV2(PolicyDefinitionCreateDto.builder() .policyDefinitionId("policy-1") - .policy(policyExpression) + .policy(expression) .build()).getId(); var dataSource = UiDataSource.builder() @@ -277,8 +279,8 @@ void provide_consume_assetMapping_policyMapping_agreements( assertThat(providerAgreement.getCounterPartyId()).isEqualTo(CONSUMER_PARTICIPANT_ID); assertThat(providerAgreement.getAsset().getAssetId()).isEqualTo(assetId); - var providingContractPolicyExpression = providerAgreement.getContractPolicy().getExpression(); - assertThat(providingContractPolicyExpression).usingRecursiveComparison().isEqualTo(policyExpression); + var providingContractPolicyConstraint = providerAgreement.getContractPolicy().getExpression(); + assertThat(providingContractPolicyConstraint).usingRecursiveComparison().isEqualTo(expression); assertThat(providerAgreement.getAsset().getAssetId()).isEqualTo(assetId); assertThat(providerAgreement.getAsset().getKeywords()).isEqualTo(List.of("keyword1", "keyword2")); @@ -293,16 +295,14 @@ void provide_consume_assetMapping_policyMapping_agreements( assertThat(consumerAgreement.getAsset().getAssetId()).isEqualTo(assetId); var consumingContractPolicyConstraint = consumerAgreement.getContractPolicy().getExpression(); - assertThat(consumingContractPolicyConstraint).usingRecursiveComparison().isEqualTo(policyExpression); + assertThat(consumingContractPolicyConstraint).usingRecursiveComparison().isEqualTo(expression); assertThat(consumerAgreement.getAsset().getAssetId()).isEqualTo(assetId); assertThat(consumerAgreement.getAsset().getTitle()).isEqualTo(assetId); // Test Policy - var actualExpression = contractOffer.getPolicy().getExpression(); - assertThat(actualExpression.getType()).isEqualTo(UiPolicyExpressionType.CONSTRAINT); - - var constraint = actualExpression.getConstraint(); + assertThat(contractOffer.getPolicy().getExpression().getType()).isEqualTo(UiPolicyExpressionType.CONSTRAINT); + var constraint = contractOffer.getPolicy().getExpression().getConstraint(); assertThat(constraint.getLeft()).isEqualTo("POLICY_EVALUATION_TIME"); assertThat(constraint.getOperator()).isEqualTo(OperatorDto.GT); assertThat(constraint.getRight().getType()).isEqualTo(UiPolicyLiteralType.STRING); @@ -500,41 +500,8 @@ void editAssetOnLiveContract( // act providerClient.uiApi().editAsset(assetId, UiAssetEditRequest.builder() - .title("Good Asset Title") - .customJsonAsString(""" - { - "edited": "new value" - } - """) - .customJsonLdAsString(""" - { - "edited": "not a valid key, will be deleted", - "http://example.com/key-to-delete": null, - "http://example.com/key-to-edit": "with a valid key", - "http://example.com/extra": "value to add" - } - """) - .privateCustomJsonAsString(""" - { - "private-edited": "new value" - } - """) - .privateCustomJsonLdAsString(""" - { - "private-edited": "not a valid key, will be deleted", - "http://example.com/private-key-to-delete": null, - "http://example.com/private-key-to-edit": "private with a valid key", - "http://example.com/private-extra": "private value to add" - } - """) - .build()); - initiateTransfer(consumerClient, negotiation); - - // assert - assertThat(consumerClient.uiApi().getCatalogPageDataOffers(providerProtocolEndpoint).get(0).getAsset().getTitle()).isEqualTo("Good Asset Title"); - val firstAsset = providerClient.uiApi().getContractAgreementPage(null).getContractAgreements().get(0).getAsset(); - assertThat(firstAsset.getTitle()).isEqualTo("Good Asset Title"); - assertThat(firstAsset.getCustomJsonAsString()).isEqualTo(""" + .title("Good Asset Title") + .customJsonAsString(""" { "edited": "new value" } @@ -561,11 +528,10 @@ void editAssetOnLiveContract( } """) .build()); - initiateTransfer(negotiation); + initiateTransfer(consumerClient, negotiation); // assert - assertThat( - consumerClient.uiApi().getCatalogPageDataOffers(getProtocolEndpoint(providerConnector)).get(0).getAsset().getTitle()).isEqualTo( + assertThat(consumerClient.uiApi().getCatalogPageDataOffers(providerProtocolEndpoint).get(0).getAsset().getTitle()).isEqualTo( "Good Asset Title"); val firstAsset = providerClient.uiApi().getContractAgreementPage(null).getContractAgreements().get(0).getAsset(); assertThat(firstAsset.getTitle()).isEqualTo("Good Asset Title"); diff --git a/utils/test-utils/src/main/java/de/sovity/edc/extension/e2e/extension/E2eScenario.java b/utils/test-utils/src/main/java/de/sovity/edc/extension/e2e/extension/E2eScenario.java index a4bc6317d..107d049e4 100644 --- a/utils/test-utils/src/main/java/de/sovity/edc/extension/e2e/extension/E2eScenario.java +++ b/utils/test-utils/src/main/java/de/sovity/edc/extension/e2e/extension/E2eScenario.java @@ -24,7 +24,7 @@ import de.sovity.edc.client.gen.model.InitiateCustomTransferRequest; import de.sovity.edc.client.gen.model.InitiateTransferRequest; 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.UiContractNegotiation; import de.sovity.edc.client.gen.model.UiCriterion; @@ -34,7 +34,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.extension.e2e.connector.config.ConnectorConfig; @@ -51,6 +52,7 @@ import java.util.Arrays; import java.util.List; import java.util.concurrent.atomic.AtomicInteger; +import java.util.stream.Stream; import static de.sovity.edc.client.gen.model.TransferProcessSimplifiedState.RUNNING; import static de.sovity.edc.extension.policy.AlwaysTruePolicyConstants.POLICY_DEFINITION_ID; @@ -144,15 +146,22 @@ public String createPolicyDefinition(String policyId, UiPolicyConstraint... cons } private IdResponseDto createPolicyDefinition(String policyId, List constraints) { - var policyDefinition = PolicyDefinitionCreateRequest.builder() + var expression = UiPolicyExpression.builder() + .type(UiPolicyExpressionType.AND) + .expressions(constraints.stream() + .map(it -> UiPolicyExpression.builder() + .type(UiPolicyExpressionType.CONSTRAINT) + .constraint(it) + .build()) + .toList()) + .build(); + + var policyDefinition = PolicyDefinitionCreateDto.builder() .policyDefinitionId(policyId) - .policy(UiPolicyCreateRequest.builder() - .constraints(constraints) - .build() - ) + .policy(expression) .build(); - return providerClient.uiApi().createPolicyDefinition(policyDefinition); + return providerClient.uiApi().createPolicyDefinitionV2(policyDefinition); } public String createContractDefinition(String assetId) { @@ -226,14 +235,22 @@ public void createPolicy(String id, OffsetDateTime from, OffsetDateTime until) { .build()) .build(); - var policyDefinition = PolicyDefinitionCreateRequest.builder() + val expression = UiPolicyExpression.builder() + .type(UiPolicyExpressionType.AND) + .expressions(Stream.of(startConstraint, endConstraint) + .map(it -> UiPolicyExpression.builder() + .type(UiPolicyExpressionType.CONSTRAINT) + .constraint(it) + .build()) + .toList()) + .build(); + + var policyDefinition = PolicyDefinitionCreateDto.builder() .policyDefinitionId(id) - .policy(UiPolicyCreateRequest.builder() - .constraints(List.of(startConstraint, endConstraint)) - .build()) + .policy(expression) .build(); - providerClient.uiApi().createPolicyDefinition(policyDefinition); + providerClient.uiApi().createPolicyDefinitionV2(policyDefinition); } public String transferAndAwait(InitiateTransferRequest transferRequest) { From e75e6d3bcd80bc1e4bde0950103f0ef3d89541bf Mon Sep 17 00:00:00 2001 From: Richard Treier Date: Thu, 18 Jul 2024 16:42:53 +0300 Subject: [PATCH 11/18] chore: idk --- .../e2e/DataSourceParameterizationTest.java | 18 +++++++++--------- .../de/sovity/edc/e2e/UiApiWrapperTest.java | 2 -- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/tests/src/test/java/de/sovity/edc/e2e/DataSourceParameterizationTest.java b/tests/src/test/java/de/sovity/edc/e2e/DataSourceParameterizationTest.java index 925b4178f..9015e7afd 100644 --- a/tests/src/test/java/de/sovity/edc/e2e/DataSourceParameterizationTest.java +++ b/tests/src/test/java/de/sovity/edc/e2e/DataSourceParameterizationTest.java @@ -179,9 +179,9 @@ void canUseTheWorkaroundInCustomTransferRequest( .add(Prop.Edc.CTX + "managedResources", false) .build(); var transferRequest = InitiateCustomTransferRequest.builder() - .contractAgreementId(negotiation.getContractAgreementId()) - .transferProcessRequestJsonLd(JsonUtils.toJson(transferRequestJsonLd)) - .build(); + .contractAgreementId(negotiation.getContractAgreementId()) + .transferProcessRequestJsonLd(JsonUtils.toJson(transferRequestJsonLd)) + .build(); val transferId = scenario.transferAndAwait(transferRequest); @@ -307,12 +307,12 @@ void canTransferParameterizedAsset( // assert TransferHistoryEntry actual = consumerClient.uiApi() - .getTransferHistoryPage() - .getTransferEntries() - .stream() - .filter(it -> it.getAssetId().equals(testCase.id)) - .findFirst() - .get(); + .getTransferHistoryPage() + .getTransferEntries() + .stream() + .filter(it -> it.getAssetId().equals(testCase.id)) + .findFirst() + .get(); assertThat(actual.getAssetId()).isEqualTo(testCase.id); assertThat(actual.getTransferProcessId()).isEqualTo(transferId); assertThat(actual.getState().getSimplifiedState()).isEqualTo(OK); diff --git a/tests/src/test/java/de/sovity/edc/e2e/UiApiWrapperTest.java b/tests/src/test/java/de/sovity/edc/e2e/UiApiWrapperTest.java index 6939fbc34..235cde517 100644 --- a/tests/src/test/java/de/sovity/edc/e2e/UiApiWrapperTest.java +++ b/tests/src/test/java/de/sovity/edc/e2e/UiApiWrapperTest.java @@ -23,7 +23,6 @@ import de.sovity.edc.client.gen.model.InitiateTransferRequest; import de.sovity.edc.client.gen.model.OperatorDto; import de.sovity.edc.client.gen.model.PolicyDefinitionCreateDto; -import de.sovity.edc.client.gen.model.PolicyDefinitionCreateRequest; import de.sovity.edc.client.gen.model.TransferProcessSimplifiedState; import de.sovity.edc.client.gen.model.UiAssetCreateRequest; import de.sovity.edc.client.gen.model.UiAssetEditRequest; @@ -37,7 +36,6 @@ 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; From c9eafa236b609e93f49506a5c31e84f7661cfd92 Mon Sep 17 00:00:00 2001 From: Richard Treier Date: Thu, 18 Jul 2024 17:05:12 +0300 Subject: [PATCH 12/18] chore: changelog --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0cf70da48..74b267d39 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,7 +12,8 @@ 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 `XOR`. - - Removed the "Policy Definition Create" endpoint from the incomplete Use Case API in favor of the UI Endpoint with the `UiPolicy` model, which is more robust. + - 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 From fb52dbd2151949e02ef578aa6ec1b1753c18f933 Mon Sep 17 00:00:00 2001 From: Richard Treier Date: Thu, 18 Jul 2024 17:05:41 +0300 Subject: [PATCH 13/18] chore: changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 74b267d39..e1f2fa9c2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,7 +11,7 @@ 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 `XOR`. +- 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. From 107797156514cbba9221010a3f44c202125026aa Mon Sep 17 00:00:00 2001 From: Richard Treier Date: Thu, 18 Jul 2024 17:28:43 +0300 Subject: [PATCH 14/18] chore: rename field from policy to expression --- docs/api/sovity-edc-api-wrapper.yaml | 7 ++++--- .../edc/ext/catalog/crawler/CrawlerE2eTest.java | 2 +- extensions/wrapper/clients/java-client/README.md | 13 ++++++------- .../api/ui/model/PolicyDefinitionCreateDto.java | 2 +- .../api/common/model/UiPolicyCreateRequest.java | 4 ++-- .../api/common/mappers/LegacyPolicyMapper.java | 2 +- .../api/common/mappers/LegacyPolicyMapperTest.java | 8 ++++---- .../ui/pages/policy/PolicyDefinitionApiService.java | 2 +- .../api/ui/pages/catalog/CatalogApiTest.java | 2 +- .../wrapper/api/usecase/UseCaseApiWrapperTest.java | 2 +- .../java/de/sovity/edc/e2e/ApiWrapperDemoTest.java | 2 +- .../edc/e2e/DataSourceParameterizationTest.java | 2 +- .../java/de/sovity/edc/e2e/UiApiWrapperTest.java | 4 ++-- .../de/sovity/edc/e2e/UseCaseApiWrapperTest.java | 2 +- .../edc/extension/e2e/extension/E2eScenario.java | 4 ++-- 15 files changed, 29 insertions(+), 29 deletions(-) diff --git a/docs/api/sovity-edc-api-wrapper.yaml b/docs/api/sovity-edc-api-wrapper.yaml index 8d7ee5807..d1b7ccc8d 100644 --- a/docs/api/sovity-edc-api-wrapper.yaml +++ b/docs/api/sovity-edc-api-wrapper.yaml @@ -890,9 +890,10 @@ components: UiPolicyCreateRequest: type: object properties: - expressions: + constraints: type: array description: Conjunction of required constraints + deprecated: true items: $ref: '#/components/schemas/UiPolicyConstraint' description: "[Deprecated] Conjunction of constraints (simplified UiPolicyExpression)" @@ -923,14 +924,14 @@ components: - JSON PolicyDefinitionCreateDto: required: - - policy + - expression - policyDefinitionId type: object properties: policyDefinitionId: type: string description: Policy Definition ID - policy: + expression: $ref: '#/components/schemas/UiPolicyExpression' description: Create a Policy Definition UiPolicyExpression: diff --git a/extensions/catalog-crawler/catalog-crawler-e2e-test/src/test/java/de/sovity/edc/ext/catalog/crawler/CrawlerE2eTest.java b/extensions/catalog-crawler/catalog-crawler-e2e-test/src/test/java/de/sovity/edc/ext/catalog/crawler/CrawlerE2eTest.java index 6508c9908..759f65cf4 100644 --- a/extensions/catalog-crawler/catalog-crawler-e2e-test/src/test/java/de/sovity/edc/ext/catalog/crawler/CrawlerE2eTest.java +++ b/extensions/catalog-crawler/catalog-crawler-e2e-test/src/test/java/de/sovity/edc/ext/catalog/crawler/CrawlerE2eTest.java @@ -205,7 +205,7 @@ private void createPolicy() { var policyDefinition = PolicyDefinitionCreateDto.builder() .policyDefinitionId(dataOfferId) - .policy(expression) + .expression(expression) .build(); connectorClient.uiApi().createPolicyDefinitionV2(policyDefinition); diff --git a/extensions/wrapper/clients/java-client/README.md b/extensions/wrapper/clients/java-client/README.md index 86826982a..0598c4b62 100644 --- a/extensions/wrapper/clients/java-client/README.md +++ b/extensions/wrapper/clients/java-client/README.md @@ -109,7 +109,7 @@ Below are the examples of various tasks and the corresponding methods to be used | Task | Java-Client method | |------------------------------------------------------|---------------------------------------------------------------------| -| Create Policy | `EdcClient.uiApi().createPolicyDefinition(policyDefinition)` | +| Create Policy | `EdcClient.uiApi().createPolicyDefinitionV2(policyDefinition)` | | Create asset (Asset Creation after activate) | `EdcClient.uiApi().createAsset(uiAssetRequest)` | | Create contract definition | `EdcClient.uiApi().createContractDefinition(contractDefinition)` | | Create Offer on consumer dashboard (Catalog Browser) | `EdcClient.uiApi().getCatalogPageDataOffers(PROTOCOL_ENDPOINT)` | @@ -123,7 +123,7 @@ These methods facilitate various operations such as creating policies, assets, c The following example demonstrates how to create a Catena-Policy with linked conditions using the Java-client. ```java -public String buildCatenaXPolicy() { +public String createCatenaXPolicy() { var policyId = UUID.randomUUID().toString(); var expression = buildAnd( @@ -131,14 +131,13 @@ public String buildCatenaXPolicy() { buildConstraint("PURPOSE", OperatorDto.EQ, "ID 3.1 Trace") ); - var policyCreateRequest = PolicyDefinitionCreateRequest.builder() + var policyCreateRequest = PolicyDefinitionCreateDto.builder() .policyDefinitionId(policyId) - .policy(UiPolicyCreateRequest.builder() - .expressions(List.of(expression)) - .build()) + .expression(expression) .build(); - consumerClient.uiApi().createPolicyDefinition(policyCreateRequest); + client.uiApi().createPolicyDefinition(policyCreateRequest); + return policyId; } diff --git a/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/PolicyDefinitionCreateDto.java b/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/PolicyDefinitionCreateDto.java index 5f723f09c..8bc4d076d 100644 --- a/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/PolicyDefinitionCreateDto.java +++ b/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/PolicyDefinitionCreateDto.java @@ -33,6 +33,6 @@ public class PolicyDefinitionCreateDto { private String policyDefinitionId; @Schema(description = "Policy Expression", requiredMode = Schema.RequiredMode.REQUIRED) - private UiPolicyExpression policy; + private UiPolicyExpression expression; } diff --git a/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiPolicyCreateRequest.java b/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiPolicyCreateRequest.java index 91260c37c..e27806608 100644 --- a/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiPolicyCreateRequest.java +++ b/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiPolicyCreateRequest.java @@ -32,6 +32,6 @@ @Schema(description = "[Deprecated] Conjunction of constraints (simplified UiPolicyExpression)", deprecated = true) public class UiPolicyCreateRequest { - @Schema(description = "Conjunction of required constraints") - private List expressions; + @Schema(description = "Conjunction of required constraints", deprecated = true) + private List constraints; } diff --git a/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/LegacyPolicyMapper.java b/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/LegacyPolicyMapper.java index ae0f5bb8a..22d95bf34 100644 --- a/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/LegacyPolicyMapper.java +++ b/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/LegacyPolicyMapper.java @@ -35,7 +35,7 @@ public UiPolicyExpression buildUiPolicyExpression(UiPolicyCreateRequest createRe return UiPolicyExpression.empty(); } - return buildUiPolicyExpression(createRequest.getExpressions()); + return buildUiPolicyExpression(createRequest.getConstraints()); } private UiPolicyExpression buildUiPolicyExpression(List expressions) { diff --git a/extensions/wrapper/wrapper-common-mappers/src/test/java/de/sovity/edc/ext/wrapper/api/common/mappers/LegacyPolicyMapperTest.java b/extensions/wrapper/wrapper-common-mappers/src/test/java/de/sovity/edc/ext/wrapper/api/common/mappers/LegacyPolicyMapperTest.java index 4e9ac911e..84c0896cb 100644 --- a/extensions/wrapper/wrapper-common-mappers/src/test/java/de/sovity/edc/ext/wrapper/api/common/mappers/LegacyPolicyMapperTest.java +++ b/extensions/wrapper/wrapper-common-mappers/src/test/java/de/sovity/edc/ext/wrapper/api/common/mappers/LegacyPolicyMapperTest.java @@ -49,7 +49,7 @@ void buildUiPolicyExpression_null() { void buildUiPolicyExpression_expressionsNull() { // arrange var request = new UiPolicyCreateRequest(); - request.setExpressions(null); + request.setConstraints(null); // act UiPolicyExpression result = legacyPolicyMapper.buildUiPolicyExpression(request); @@ -62,7 +62,7 @@ void buildUiPolicyExpression_expressionsNull() { void buildUiPolicyExpression_emptyExpressions() { // arrange var request = new UiPolicyCreateRequest(); - request.setExpressions(List.of()); + request.setConstraints(List.of()); // act UiPolicyExpression result = legacyPolicyMapper.buildUiPolicyExpression(request); @@ -76,7 +76,7 @@ void buildUiPolicyExpression_singleExpression() { // arrange var request = new UiPolicyCreateRequest(); var expression = new UiPolicyConstraint(); - request.setExpressions(List.of(expression)); + request.setConstraints(List.of(expression)); // act UiPolicyExpression result = legacyPolicyMapper.buildUiPolicyExpression(request); @@ -91,7 +91,7 @@ void buildUiPolicyExpression_multipleExpressions() { var request = new UiPolicyCreateRequest(); var constraint1 = mock(UiPolicyConstraint.class); var constraint2 = mock(UiPolicyConstraint.class); - request.setExpressions(List.of(constraint1, constraint2)); + request.setConstraints(List.of(constraint1, constraint2)); // act UiPolicyExpression result = legacyPolicyMapper.buildUiPolicyExpression(request); diff --git a/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/pages/policy/PolicyDefinitionApiService.java b/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/pages/policy/PolicyDefinitionApiService.java index cccc365e9..87a17cbcb 100644 --- a/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/pages/policy/PolicyDefinitionApiService.java +++ b/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/pages/policy/PolicyDefinitionApiService.java @@ -59,7 +59,7 @@ public IdResponseDto createPolicyDefinition(PolicyDefinitionCreateRequest reques @NotNull public IdResponseDto createPolicyDefinitionV2(PolicyDefinitionCreateDto request) { - var policyDefinition = buildPolicyDefinition(request.getPolicyDefinitionId(), request.getPolicy()); + var policyDefinition = buildPolicyDefinition(request.getPolicyDefinitionId(), request.getExpression()); policyDefinition = policyDefinitionService.create(policyDefinition).orElseThrow(ServiceException::new); return new IdResponseDto(policyDefinition.getId()); } diff --git a/extensions/wrapper/wrapper/src/test/java/de/sovity/edc/ext/wrapper/api/ui/pages/catalog/CatalogApiTest.java b/extensions/wrapper/wrapper/src/test/java/de/sovity/edc/ext/wrapper/api/ui/pages/catalog/CatalogApiTest.java index eec927efc..101a76fdb 100644 --- a/extensions/wrapper/wrapper/src/test/java/de/sovity/edc/ext/wrapper/api/ui/pages/catalog/CatalogApiTest.java +++ b/extensions/wrapper/wrapper/src/test/java/de/sovity/edc/ext/wrapper/api/ui/pages/catalog/CatalogApiTest.java @@ -110,7 +110,7 @@ private void createAsset() { private void createPolicy() { var policyDefinition = PolicyDefinitionCreateDto.builder() .policyDefinitionId(dataOfferId) - .policy(UiPolicyExpression.builder().type(UiPolicyExpressionType.EMPTY).build()) + .expression(UiPolicyExpression.builder().type(UiPolicyExpressionType.EMPTY).build()) .build(); client.uiApi().createPolicyDefinitionV2(policyDefinition); diff --git a/extensions/wrapper/wrapper/src/test/java/de/sovity/edc/ext/wrapper/api/usecase/UseCaseApiWrapperTest.java b/extensions/wrapper/wrapper/src/test/java/de/sovity/edc/ext/wrapper/api/usecase/UseCaseApiWrapperTest.java index 09f637757..4a4dbfd43 100644 --- a/extensions/wrapper/wrapper/src/test/java/de/sovity/edc/ext/wrapper/api/usecase/UseCaseApiWrapperTest.java +++ b/extensions/wrapper/wrapper/src/test/java/de/sovity/edc/ext/wrapper/api/usecase/UseCaseApiWrapperTest.java @@ -204,7 +204,7 @@ private void setupAssets() { policyId = client.uiApi().createPolicyDefinitionV2(PolicyDefinitionCreateDto.builder() .policyDefinitionId("policy-1") - .policy(UiPolicyExpression.builder() + .expression(UiPolicyExpression.builder() .type(UiPolicyExpressionType.EMPTY) .build()) .build()).getId(); diff --git a/tests/src/test/java/de/sovity/edc/e2e/ApiWrapperDemoTest.java b/tests/src/test/java/de/sovity/edc/e2e/ApiWrapperDemoTest.java index 480cc8b7d..71143851d 100644 --- a/tests/src/test/java/de/sovity/edc/e2e/ApiWrapperDemoTest.java +++ b/tests/src/test/java/de/sovity/edc/e2e/ApiWrapperDemoTest.java @@ -178,7 +178,7 @@ private void createPolicy() { var policyDefinition = PolicyDefinitionCreateDto.builder() .policyDefinitionId(dataOfferId) - .policy(expression) + .expression(expression) .build(); providerClient.uiApi().createPolicyDefinitionV2(policyDefinition); diff --git a/tests/src/test/java/de/sovity/edc/e2e/DataSourceParameterizationTest.java b/tests/src/test/java/de/sovity/edc/e2e/DataSourceParameterizationTest.java index 9015e7afd..f0bdd6ea3 100644 --- a/tests/src/test/java/de/sovity/edc/e2e/DataSourceParameterizationTest.java +++ b/tests/src/test/java/de/sovity/edc/e2e/DataSourceParameterizationTest.java @@ -451,7 +451,7 @@ private String createAssetWithParameterizedMethod(EdcClient providerClient, Test private void createPolicy(EdcClient providerClient, TestCase testCase) { var policyDefinition = PolicyDefinitionCreateDto.builder() .policyDefinitionId(testCase.id) - .policy(UiPolicyExpression.builder() + .expression(UiPolicyExpression.builder() .type(UiPolicyExpressionType.EMPTY) .build()) .build(); diff --git a/tests/src/test/java/de/sovity/edc/e2e/UiApiWrapperTest.java b/tests/src/test/java/de/sovity/edc/e2e/UiApiWrapperTest.java index 235cde517..33d90c17b 100644 --- a/tests/src/test/java/de/sovity/edc/e2e/UiApiWrapperTest.java +++ b/tests/src/test/java/de/sovity/edc/e2e/UiApiWrapperTest.java @@ -116,7 +116,7 @@ void provide_consume_assetMapping_policyMapping_agreements( var policyId = providerClient.uiApi().createPolicyDefinitionV2(PolicyDefinitionCreateDto.builder() .policyDefinitionId("policy-1") - .policy(expression) + .expression(expression) .build()).getId(); var dataSource = UiDataSource.builder() @@ -384,7 +384,7 @@ void customTransferRequest( var policyId = providerClient.uiApi().createPolicyDefinitionV2(PolicyDefinitionCreateDto.builder() .policyDefinitionId("policy-1") - .policy(UiPolicyExpression.builder() + .expression(UiPolicyExpression.builder() .type(UiPolicyExpressionType.EMPTY) .build()) .build()).getId(); diff --git a/tests/src/test/java/de/sovity/edc/e2e/UseCaseApiWrapperTest.java b/tests/src/test/java/de/sovity/edc/e2e/UseCaseApiWrapperTest.java index 5c5fad134..3231fda3d 100644 --- a/tests/src/test/java/de/sovity/edc/e2e/UseCaseApiWrapperTest.java +++ b/tests/src/test/java/de/sovity/edc/e2e/UseCaseApiWrapperTest.java @@ -166,7 +166,7 @@ private void createPolicy(EdcClient providerClient) { var policyDefinition = PolicyDefinitionCreateDto.builder() .policyDefinitionId(dataOfferId) - .policy(expression) + .expression(expression) .build(); providerClient.uiApi().createPolicyDefinitionV2(policyDefinition); diff --git a/utils/test-utils/src/main/java/de/sovity/edc/extension/e2e/extension/E2eScenario.java b/utils/test-utils/src/main/java/de/sovity/edc/extension/e2e/extension/E2eScenario.java index 107d049e4..346e256e6 100644 --- a/utils/test-utils/src/main/java/de/sovity/edc/extension/e2e/extension/E2eScenario.java +++ b/utils/test-utils/src/main/java/de/sovity/edc/extension/e2e/extension/E2eScenario.java @@ -158,7 +158,7 @@ private IdResponseDto createPolicyDefinition(String policyId, List Date: Fri, 19 Jul 2024 10:44:47 +0300 Subject: [PATCH 15/18] chore: review remarks --- docs/api/sovity-edc-api-wrapper.yaml | 11 ++++++----- extensions/wrapper/clients/java-client/README.md | 2 +- .../de/sovity/edc/ext/wrapper/api/ui/UiResource.java | 3 ++- .../wrapper/api/common/model/UiPolicyExpression.java | 2 +- .../api/common/model/UiPolicyExpressionType.java | 6 +++--- .../api/common/mappers/LegacyPolicyMapperTest.java | 2 +- 6 files changed, 14 insertions(+), 12 deletions(-) diff --git a/docs/api/sovity-edc-api-wrapper.yaml b/docs/api/sovity-edc-api-wrapper.yaml index d1b7ccc8d..592639484 100644 --- a/docs/api/sovity-edc-api-wrapper.yaml +++ b/docs/api/sovity-edc-api-wrapper.yaml @@ -121,7 +121,8 @@ paths: post: tags: - UI - description: "[Deprecated] Create a new Policy Definition from a list of constraints" + description: "[Deprecated] Create a new Policy Definition from a list of constraints.\ + \ Use createPolicyDefinitionV2 instead." operationId: createPolicyDefinition requestBody: content: @@ -943,7 +944,7 @@ components: $ref: '#/components/schemas/UiPolicyExpressionType' expressions: type: array - description: "Only for types AND, OR, XOR. List of sub-expressions to be\ + description: "Only for types AND, OR, XONE. List of sub-expressions to be\ \ evaluated according to the expressionType." items: $ref: '#/components/schemas/UiPolicyExpression' @@ -955,9 +956,9 @@ components: description: | Ui Policy Expression types: * `CONSTRAINT` - Expression 'a=b' - * `AND` - Conjunction of several expressions. All child expressions must be true. - * `OR` - Disjunction of several expressions. (At least) one child expression must be true. - * `XONE` - XOR operation, exactly one child expression must be true. + * `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 diff --git a/extensions/wrapper/clients/java-client/README.md b/extensions/wrapper/clients/java-client/README.md index 0598c4b62..1c419272a 100644 --- a/extensions/wrapper/clients/java-client/README.md +++ b/extensions/wrapper/clients/java-client/README.md @@ -118,7 +118,7 @@ Below are the examples of various tasks and the corresponding methods to be used These methods facilitate various operations such as creating policies, assets, contract definitions, browsing offers, accepting contracts, and initiating data transfers. -### Example Creating a Catena-Policy using operators (AND/OR/XOR) +### Example Creating a Catena-Policy using operators (AND/OR/XONE) The following example demonstrates how to create a Catena-Policy with linked conditions using the Java-client. diff --git a/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/UiResource.java b/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/UiResource.java index 5bb863ff7..cb408936d 100644 --- a/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/UiResource.java +++ b/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/UiResource.java @@ -100,7 +100,8 @@ interface UiResource { @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) @Deprecated - @Operation(description = "[Deprecated] Create a new Policy Definition from a list of constraints", deprecated = true) + @Operation(description = "[Deprecated] Create a new Policy Definition from a list of constraints. " + + "Use createPolicyDefinitionV2 instead.", deprecated = true) IdResponseDto createPolicyDefinition(PolicyDefinitionCreateRequest policyDefinitionDtoDto); @POST diff --git a/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiPolicyExpression.java b/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiPolicyExpression.java index 37c116872..4d30e337d 100644 --- a/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiPolicyExpression.java +++ b/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiPolicyExpression.java @@ -21,7 +21,7 @@ public class UiPolicyExpression { @Schema(description = "Expression type", requiredMode = Schema.RequiredMode.REQUIRED) private UiPolicyExpressionType type; - @Schema(description = "Only for types AND, OR, XOR. List of sub-expressions " + + @Schema(description = "Only for types AND, OR, XONE. List of sub-expressions " + "to be evaluated according to the expressionType.", requiredMode = Schema.RequiredMode.NOT_REQUIRED) private List expressions; diff --git a/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiPolicyExpressionType.java b/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiPolicyExpressionType.java index 9db06655c..2267a4abc 100644 --- a/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiPolicyExpressionType.java +++ b/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiPolicyExpressionType.java @@ -5,9 +5,9 @@ @Schema(description = """ Ui Policy Expression types: * `CONSTRAINT` - Expression 'a=b' - * `AND` - Conjunction of several expressions. All child expressions must be true. - * `OR` - Disjunction of several expressions. (At least) one child expression must be true. - * `XONE` - XOR operation, exactly one child expression must be true. + * `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. """, enumAsRef = true) public enum UiPolicyExpressionType { EMPTY, diff --git a/extensions/wrapper/wrapper-common-mappers/src/test/java/de/sovity/edc/ext/wrapper/api/common/mappers/LegacyPolicyMapperTest.java b/extensions/wrapper/wrapper-common-mappers/src/test/java/de/sovity/edc/ext/wrapper/api/common/mappers/LegacyPolicyMapperTest.java index 84c0896cb..43f5a883a 100644 --- a/extensions/wrapper/wrapper-common-mappers/src/test/java/de/sovity/edc/ext/wrapper/api/common/mappers/LegacyPolicyMapperTest.java +++ b/extensions/wrapper/wrapper-common-mappers/src/test/java/de/sovity/edc/ext/wrapper/api/common/mappers/LegacyPolicyMapperTest.java @@ -36,7 +36,7 @@ public class LegacyPolicyMapperTest { @Test void buildUiPolicyExpression_null() { // arrange - var request = (UiPolicyCreateRequest) null; + UiPolicyCreateRequest request = null; // act UiPolicyExpression result = legacyPolicyMapper.buildUiPolicyExpression(request); From 8dfacfbb9e2aca1c9831adf417bb835d90cbfe11 Mon Sep 17 00:00:00 2001 From: Richard Treier Date: Fri, 19 Jul 2024 11:43:56 +0300 Subject: [PATCH 16/18] chore: review remarks --- .../java/de/sovity/edc/ext/wrapper/api/ui/UiResource.java | 6 ++---- .../de/sovity/edc/ext/wrapper/api/ui/model/AssetPage.java | 3 +-- .../edc/ext/wrapper/api/ui/model/ContractAgreementCard.java | 2 -- .../edc/ext/wrapper/api/ui/model/ContractAgreementPage.java | 2 -- .../wrapper/api/ui/model/ContractAgreementPageQuery.java | 1 - .../api/ui/model/ContractAgreementTransferProcess.java | 2 -- .../ext/wrapper/api/ui/model/ContractDefinitionEntry.java | 2 -- .../ext/wrapper/api/ui/model/ContractDefinitionPage.java | 2 -- .../ext/wrapper/api/ui/model/ContractDefinitionRequest.java | 2 -- .../wrapper/api/ui/model/ContractNegotiationRequest.java | 2 -- .../ext/wrapper/api/ui/model/ContractNegotiationState.java | 2 -- .../edc/ext/wrapper/api/ui/model/DashboardDapsConfig.java | 2 -- .../sovity/edc/ext/wrapper/api/ui/model/DashboardPage.java | 2 -- .../ext/wrapper/api/ui/model/DashboardTransferAmounts.java | 2 -- .../sovity/edc/ext/wrapper/api/ui/model/IdResponseDto.java | 2 -- .../wrapper/api/ui/model/InitiateCustomTransferRequest.java | 2 -- .../ext/wrapper/api/ui/model/InitiateTransferRequest.java | 2 -- .../ext/wrapper/api/ui/model/PolicyDefinitionCreateDto.java | 2 -- .../wrapper/api/ui/model/PolicyDefinitionCreateRequest.java | 2 -- .../edc/ext/wrapper/api/ui/model/PolicyDefinitionDto.java | 2 -- .../edc/ext/wrapper/api/ui/model/PolicyDefinitionPage.java | 2 -- .../edc/ext/wrapper/api/ui/model/TransferHistoryEntry.java | 2 -- .../edc/ext/wrapper/api/ui/model/TransferHistoryPage.java | 2 -- .../edc/ext/wrapper/api/ui/model/TransferProcessState.java | 2 -- .../edc/ext/wrapper/api/ui/model/UiContractNegotiation.java | 2 -- .../edc/ext/wrapper/api/ui/model/UiContractOffer.java | 2 -- .../de/sovity/edc/ext/wrapper/api/ui/model/UiCriterion.java | 2 -- .../edc/ext/wrapper/api/ui/model/UiCriterionLiteral.java | 2 -- .../de/sovity/edc/ext/wrapper/api/ui/model/UiDataOffer.java | 2 -- .../sovity/edc/ext/wrapper/api/usecase/UseCaseResource.java | 1 - .../wrapper/api/usecase/model/CatalogFilterExpression.java | 2 -- .../api/usecase/model/CatalogFilterExpressionLiteral.java | 2 -- .../edc/ext/wrapper/api/usecase/model/CatalogQuery.java | 2 -- .../sovity/edc/ext/wrapper/api/usecase/model/KpiResult.java | 2 -- .../wrapper/api/usecase/model/TransferProcessStatesDto.java | 2 -- .../edc/ext/wrapper/api/common/model/SecretValue.java | 2 -- .../de/sovity/edc/ext/wrapper/api/common/model/UiAsset.java | 2 -- .../ext/wrapper/api/common/model/UiAssetCreateRequest.java | 2 -- .../ext/wrapper/api/common/model/UiAssetEditRequest.java | 2 -- .../edc/ext/wrapper/api/common/model/UiDataSource.java | 2 -- .../ext/wrapper/api/common/model/UiDataSourceHttpData.java | 2 -- .../ext/wrapper/api/common/model/UiDataSourceOnRequest.java | 2 -- .../sovity/edc/ext/wrapper/api/common/model/UiPolicy.java | 2 -- .../ext/wrapper/api/common/model/UiPolicyConstraint.java | 2 -- .../ext/wrapper/api/common/model/UiPolicyCreateRequest.java | 2 -- .../ext/wrapper/api/common/model/UiPolicyExpression.java | 2 -- .../edc/ext/wrapper/api/common/model/UiPolicyLiteral.java | 2 -- 47 files changed, 3 insertions(+), 94 deletions(-) diff --git a/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/UiResource.java b/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/UiResource.java index cb408936d..6c8c07031 100644 --- a/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/UiResource.java +++ b/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/UiResource.java @@ -14,8 +14,6 @@ package de.sovity.edc.ext.wrapper.api.ui; -import de.sovity.edc.ext.wrapper.api.ui.model.PolicyDefinitionCreateDto; -import de.sovity.edc.ext.wrapper.api.ui.model.PolicyDefinitionCreateRequest; import de.sovity.edc.ext.wrapper.api.common.model.UiAsset; import de.sovity.edc.ext.wrapper.api.common.model.UiAssetCreateRequest; import de.sovity.edc.ext.wrapper.api.common.model.UiAssetEditRequest; @@ -30,15 +28,15 @@ import de.sovity.edc.ext.wrapper.api.ui.model.IdResponseDto; import de.sovity.edc.ext.wrapper.api.ui.model.InitiateCustomTransferRequest; import de.sovity.edc.ext.wrapper.api.ui.model.InitiateTransferRequest; +import de.sovity.edc.ext.wrapper.api.ui.model.PolicyDefinitionCreateDto; +import de.sovity.edc.ext.wrapper.api.ui.model.PolicyDefinitionCreateRequest; import de.sovity.edc.ext.wrapper.api.ui.model.PolicyDefinitionPage; import de.sovity.edc.ext.wrapper.api.ui.model.TransferHistoryPage; import de.sovity.edc.ext.wrapper.api.ui.model.UiContractNegotiation; import de.sovity.edc.ext.wrapper.api.ui.model.UiDataOffer; import io.swagger.v3.oas.annotations.Operation; -import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.parameters.RequestBody; import io.swagger.v3.oas.annotations.tags.Tag; -import jakarta.validation.Valid; import jakarta.ws.rs.Consumes; import jakarta.ws.rs.DELETE; import jakarta.ws.rs.GET; diff --git a/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/AssetPage.java b/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/AssetPage.java index 80afa7fd1..4c39c37d9 100644 --- a/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/AssetPage.java +++ b/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/AssetPage.java @@ -13,19 +13,18 @@ */ package de.sovity.edc.ext.wrapper.api.ui.model; + import com.fasterxml.jackson.annotation.JsonInclude; import de.sovity.edc.ext.wrapper.api.common.model.UiAsset; import io.swagger.v3.oas.annotations.media.Schema; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; -import lombok.RequiredArgsConstructor; import java.util.List; @Data @AllArgsConstructor -@RequiredArgsConstructor @Builder(toBuilder = true) @JsonInclude(JsonInclude.Include.NON_NULL) @Schema(description = "All data for the Asset Page") diff --git a/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/ContractAgreementCard.java b/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/ContractAgreementCard.java index 0f9568f0a..47d1a52ea 100644 --- a/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/ContractAgreementCard.java +++ b/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/ContractAgreementCard.java @@ -21,14 +21,12 @@ import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; -import lombok.RequiredArgsConstructor; import java.time.OffsetDateTime; import java.util.List; @Data @AllArgsConstructor -@RequiredArgsConstructor @Builder(toBuilder = true) @JsonInclude(JsonInclude.Include.NON_NULL) @Schema(description = "Contract Agreement for Contract Agreement Page") diff --git a/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/ContractAgreementPage.java b/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/ContractAgreementPage.java index 4e112e45b..036bf7a95 100644 --- a/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/ContractAgreementPage.java +++ b/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/ContractAgreementPage.java @@ -19,13 +19,11 @@ import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; -import lombok.RequiredArgsConstructor; import java.util.List; @Data @AllArgsConstructor -@RequiredArgsConstructor @Builder(toBuilder = true) @JsonInclude(JsonInclude.Include.NON_NULL) @Schema(description = "Data as required by the UI's Contract Agreement Page") diff --git a/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/ContractAgreementPageQuery.java b/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/ContractAgreementPageQuery.java index f836e5399..d9ef4a47e 100644 --- a/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/ContractAgreementPageQuery.java +++ b/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/ContractAgreementPageQuery.java @@ -14,7 +14,6 @@ package de.sovity.edc.ext.wrapper.api.ui.model; -import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonInclude; import io.swagger.v3.oas.annotations.media.Schema; import lombok.AllArgsConstructor; diff --git a/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/ContractAgreementTransferProcess.java b/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/ContractAgreementTransferProcess.java index 92e9577d6..66368c95a 100644 --- a/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/ContractAgreementTransferProcess.java +++ b/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/ContractAgreementTransferProcess.java @@ -19,13 +19,11 @@ import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; -import lombok.RequiredArgsConstructor; import java.time.OffsetDateTime; @Data @AllArgsConstructor -@RequiredArgsConstructor @Builder(toBuilder = true) @JsonInclude(JsonInclude.Include.NON_NULL) @Schema(description = "A Contract Agreement's Transfer Process") diff --git a/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/ContractDefinitionEntry.java b/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/ContractDefinitionEntry.java index 25986ede7..b79e7a167 100644 --- a/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/ContractDefinitionEntry.java +++ b/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/ContractDefinitionEntry.java @@ -19,13 +19,11 @@ import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; -import lombok.RequiredArgsConstructor; import java.util.List; @Data @AllArgsConstructor -@RequiredArgsConstructor @Builder(toBuilder = true) @JsonInclude(JsonInclude.Include.NON_NULL) @Schema(description = "Contract Definition List Entry for Contract Definition Page") diff --git a/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/ContractDefinitionPage.java b/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/ContractDefinitionPage.java index 1962eae7d..b7bc4a6b5 100644 --- a/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/ContractDefinitionPage.java +++ b/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/ContractDefinitionPage.java @@ -19,13 +19,11 @@ import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; -import lombok.RequiredArgsConstructor; import java.util.List; @Data @AllArgsConstructor -@RequiredArgsConstructor @Builder(toBuilder = true) @JsonInclude(JsonInclude.Include.NON_NULL) public class ContractDefinitionPage { diff --git a/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/ContractDefinitionRequest.java b/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/ContractDefinitionRequest.java index 83afe19d3..0ce7fb58d 100644 --- a/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/ContractDefinitionRequest.java +++ b/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/ContractDefinitionRequest.java @@ -20,13 +20,11 @@ import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; -import lombok.RequiredArgsConstructor; import java.util.List; @Data @AllArgsConstructor -@RequiredArgsConstructor @Builder(toBuilder = true) @JsonInclude(JsonInclude.Include.NON_NULL) @Schema(description = "Data for creating a Contract Definition") diff --git a/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/ContractNegotiationRequest.java b/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/ContractNegotiationRequest.java index fe2279644..5f770acb7 100644 --- a/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/ContractNegotiationRequest.java +++ b/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/ContractNegotiationRequest.java @@ -20,11 +20,9 @@ import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; -import lombok.RequiredArgsConstructor; @Data @AllArgsConstructor -@RequiredArgsConstructor @Builder(toBuilder = true) @JsonInclude(JsonInclude.Include.NON_NULL) @Schema(description = "Data for initiating a Contract Negotiation") diff --git a/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/ContractNegotiationState.java b/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/ContractNegotiationState.java index c5f770b52..b79af9a3d 100644 --- a/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/ContractNegotiationState.java +++ b/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/ContractNegotiationState.java @@ -19,11 +19,9 @@ import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; -import lombok.RequiredArgsConstructor; @Data @AllArgsConstructor -@RequiredArgsConstructor @Builder(toBuilder = true) @JsonInclude(JsonInclude.Include.NON_NULL) @Schema(description = "Contract Negotiation State interpreted") diff --git a/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/DashboardDapsConfig.java b/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/DashboardDapsConfig.java index a4cee19ac..e384a90d5 100644 --- a/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/DashboardDapsConfig.java +++ b/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/DashboardDapsConfig.java @@ -5,12 +5,10 @@ import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; -import lombok.RequiredArgsConstructor; @Data @AllArgsConstructor -@RequiredArgsConstructor @Builder(toBuilder = true) @JsonInclude(JsonInclude.Include.NON_NULL) @Schema(description = "DAPS Config") diff --git a/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/DashboardPage.java b/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/DashboardPage.java index 78056c9a7..073483928 100644 --- a/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/DashboardPage.java +++ b/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/DashboardPage.java @@ -5,12 +5,10 @@ import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; -import lombok.RequiredArgsConstructor; @Data @AllArgsConstructor -@RequiredArgsConstructor @Builder(toBuilder = true) @JsonInclude(JsonInclude.Include.NON_NULL) @Schema(description = "Data as required by the UI's Dashboard Page") diff --git a/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/DashboardTransferAmounts.java b/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/DashboardTransferAmounts.java index bbda22a13..c72cdc423 100644 --- a/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/DashboardTransferAmounts.java +++ b/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/DashboardTransferAmounts.java @@ -5,12 +5,10 @@ import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; -import lombok.RequiredArgsConstructor; @Data @AllArgsConstructor -@RequiredArgsConstructor @Builder(toBuilder = true) @JsonInclude(JsonInclude.Include.NON_NULL) @Schema(description = "Number of Transfer Processes for given direction.") diff --git a/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/IdResponseDto.java b/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/IdResponseDto.java index bf554c87b..338bf0180 100644 --- a/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/IdResponseDto.java +++ b/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/IdResponseDto.java @@ -19,13 +19,11 @@ import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; -import lombok.RequiredArgsConstructor; import java.time.OffsetDateTime; @Data @AllArgsConstructor -@RequiredArgsConstructor @Builder(toBuilder = true) @JsonInclude(JsonInclude.Include.NON_NULL) @Schema(description = "Marks the operation as successful") diff --git a/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/InitiateCustomTransferRequest.java b/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/InitiateCustomTransferRequest.java index 4d596a20a..3a1b9356e 100644 --- a/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/InitiateCustomTransferRequest.java +++ b/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/InitiateCustomTransferRequest.java @@ -19,11 +19,9 @@ import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; -import lombok.RequiredArgsConstructor; @Data @AllArgsConstructor -@RequiredArgsConstructor @Builder(toBuilder = true) @JsonInclude(JsonInclude.Include.NON_NULL) @Schema(description = "Required data for starting a Contract Agreement's Transfer Process") diff --git a/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/InitiateTransferRequest.java b/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/InitiateTransferRequest.java index d6eed17f1..2d65e4444 100644 --- a/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/InitiateTransferRequest.java +++ b/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/InitiateTransferRequest.java @@ -19,13 +19,11 @@ import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; -import lombok.RequiredArgsConstructor; import java.util.Map; @Data @AllArgsConstructor -@RequiredArgsConstructor @Builder(toBuilder = true) @JsonInclude(JsonInclude.Include.NON_NULL) @Schema(description = "For type PARAMS_ONLY: Required data for starting a Transfer Process") diff --git a/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/PolicyDefinitionCreateDto.java b/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/PolicyDefinitionCreateDto.java index 8bc4d076d..f331129b9 100644 --- a/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/PolicyDefinitionCreateDto.java +++ b/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/PolicyDefinitionCreateDto.java @@ -20,11 +20,9 @@ import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; -import lombok.RequiredArgsConstructor; @Data @AllArgsConstructor -@RequiredArgsConstructor @Builder(toBuilder = true) @JsonInclude(JsonInclude.Include.NON_NULL) @Schema(description = "Create a Policy Definition") diff --git a/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/PolicyDefinitionCreateRequest.java b/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/PolicyDefinitionCreateRequest.java index 911d90db6..096b7348f 100644 --- a/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/PolicyDefinitionCreateRequest.java +++ b/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/PolicyDefinitionCreateRequest.java @@ -20,11 +20,9 @@ import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; -import lombok.RequiredArgsConstructor; @Data @AllArgsConstructor -@RequiredArgsConstructor @Builder(toBuilder = true) @JsonInclude(JsonInclude.Include.NON_NULL) @Deprecated diff --git a/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/PolicyDefinitionDto.java b/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/PolicyDefinitionDto.java index 3c69aca84..a4e47a096 100644 --- a/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/PolicyDefinitionDto.java +++ b/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/PolicyDefinitionDto.java @@ -20,11 +20,9 @@ import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; -import lombok.RequiredArgsConstructor; @Data @AllArgsConstructor -@RequiredArgsConstructor @Builder(toBuilder = true) @JsonInclude(JsonInclude.Include.NON_NULL) @Schema(description = "Policy Definition as required for the Policy Definition Page") diff --git a/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/PolicyDefinitionPage.java b/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/PolicyDefinitionPage.java index 9b77b3c36..d015fd35d 100644 --- a/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/PolicyDefinitionPage.java +++ b/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/PolicyDefinitionPage.java @@ -19,13 +19,11 @@ import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; -import lombok.RequiredArgsConstructor; import java.util.List; @Data @AllArgsConstructor -@RequiredArgsConstructor @Builder(toBuilder = true) @JsonInclude(JsonInclude.Include.NON_NULL) @Schema(description = "All data for the policy definition page as required by the UI", requiredMode = Schema.RequiredMode.REQUIRED) diff --git a/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/TransferHistoryEntry.java b/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/TransferHistoryEntry.java index 4e29c6c68..e9c03dcd7 100644 --- a/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/TransferHistoryEntry.java +++ b/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/TransferHistoryEntry.java @@ -19,13 +19,11 @@ import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; -import lombok.RequiredArgsConstructor; import java.time.OffsetDateTime; @Data @AllArgsConstructor -@RequiredArgsConstructor @Builder(toBuilder = true) @JsonInclude(JsonInclude.Include.NON_NULL) @Schema(description = "Transfer History Entry for Transfer History Page") diff --git a/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/TransferHistoryPage.java b/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/TransferHistoryPage.java index e13809da0..0ed9bd08a 100644 --- a/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/TransferHistoryPage.java +++ b/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/TransferHistoryPage.java @@ -19,13 +19,11 @@ import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; -import lombok.RequiredArgsConstructor; import java.util.List; @Data @AllArgsConstructor -@RequiredArgsConstructor @Builder(toBuilder = true) @JsonInclude(JsonInclude.Include.NON_NULL) @Schema(description = "Data as required by the UI's Transfer History Page") diff --git a/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/TransferProcessState.java b/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/TransferProcessState.java index fa87c6f84..587c6f8fe 100644 --- a/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/TransferProcessState.java +++ b/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/TransferProcessState.java @@ -19,11 +19,9 @@ import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; -import lombok.RequiredArgsConstructor; @Data @AllArgsConstructor -@RequiredArgsConstructor @Builder(toBuilder = true) @JsonInclude(JsonInclude.Include.NON_NULL) @Schema(description = "Transfer Process State interpreted") diff --git a/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/UiContractNegotiation.java b/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/UiContractNegotiation.java index 1235af25a..6e0f3bee2 100644 --- a/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/UiContractNegotiation.java +++ b/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/UiContractNegotiation.java @@ -20,13 +20,11 @@ import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; -import lombok.RequiredArgsConstructor; import java.time.OffsetDateTime; @Data @AllArgsConstructor -@RequiredArgsConstructor @Builder(toBuilder = true) @JsonInclude(JsonInclude.Include.NON_NULL) @Schema(description = "Contract Negotiation Information") diff --git a/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/UiContractOffer.java b/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/UiContractOffer.java index 8c7b42881..eace4dc30 100644 --- a/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/UiContractOffer.java +++ b/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/UiContractOffer.java @@ -21,11 +21,9 @@ import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; -import lombok.RequiredArgsConstructor; @Data @AllArgsConstructor -@RequiredArgsConstructor @Builder(toBuilder = true) @JsonInclude(JsonInclude.Include.NON_NULL) @Schema(description = "Catalog Data Offer's Contract Offer as required by the UI") diff --git a/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/UiCriterion.java b/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/UiCriterion.java index 80afa2bc9..a91677ba6 100644 --- a/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/UiCriterion.java +++ b/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/UiCriterion.java @@ -20,11 +20,9 @@ import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; -import lombok.RequiredArgsConstructor; @Data @AllArgsConstructor -@RequiredArgsConstructor @Builder(toBuilder = true) @JsonInclude(JsonInclude.Include.NON_NULL) @Schema(description = "Contract Definition Criterion as supported by the UI") diff --git a/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/UiCriterionLiteral.java b/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/UiCriterionLiteral.java index 760d1ff45..6a8ab9f99 100644 --- a/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/UiCriterionLiteral.java +++ b/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/UiCriterionLiteral.java @@ -6,13 +6,11 @@ import lombok.Builder; import lombok.Data; import lombok.NonNull; -import lombok.RequiredArgsConstructor; import java.util.List; @Data @AllArgsConstructor -@RequiredArgsConstructor @Builder(toBuilder = true) @JsonInclude(JsonInclude.Include.NON_NULL) @Schema(description = "Criterion Literal") diff --git a/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/UiDataOffer.java b/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/UiDataOffer.java index 16a8d6316..9f8327980 100644 --- a/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/UiDataOffer.java +++ b/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/UiDataOffer.java @@ -20,13 +20,11 @@ import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; -import lombok.RequiredArgsConstructor; import java.util.List; @Data @AllArgsConstructor -@RequiredArgsConstructor @Builder(toBuilder = true) @JsonInclude(JsonInclude.Include.NON_NULL) @Schema(description = "Catalog Data Offer as required by the UI") diff --git a/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/usecase/UseCaseResource.java b/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/usecase/UseCaseResource.java index b959ac0ec..e02e50e9c 100644 --- a/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/usecase/UseCaseResource.java +++ b/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/usecase/UseCaseResource.java @@ -19,7 +19,6 @@ import de.sovity.edc.ext.wrapper.api.usecase.model.KpiResult; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; -import jakarta.validation.Valid; import jakarta.validation.constraints.NotNull; import jakarta.ws.rs.Consumes; import jakarta.ws.rs.GET; diff --git a/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/usecase/model/CatalogFilterExpression.java b/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/usecase/model/CatalogFilterExpression.java index 238d06e44..16bf52d72 100644 --- a/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/usecase/model/CatalogFilterExpression.java +++ b/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/usecase/model/CatalogFilterExpression.java @@ -20,11 +20,9 @@ import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; -import lombok.RequiredArgsConstructor; @Data @AllArgsConstructor -@RequiredArgsConstructor @Builder(toBuilder = true) @JsonInclude(JsonInclude.Include.NON_NULL) @Schema(description = "Generic expression for filtering the data offers in the catalog", requiredMode = Schema.RequiredMode.NOT_REQUIRED) diff --git a/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/usecase/model/CatalogFilterExpressionLiteral.java b/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/usecase/model/CatalogFilterExpressionLiteral.java index 8faa1d5d3..0cf00bbfc 100644 --- a/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/usecase/model/CatalogFilterExpressionLiteral.java +++ b/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/usecase/model/CatalogFilterExpressionLiteral.java @@ -20,13 +20,11 @@ import lombok.Builder; import lombok.Data; import lombok.NonNull; -import lombok.RequiredArgsConstructor; import java.util.List; @Data @AllArgsConstructor -@RequiredArgsConstructor @Builder(toBuilder = true) @JsonInclude(JsonInclude.Include.NON_NULL) @Schema(description = "FilterExpression Criterion Literal") diff --git a/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/usecase/model/CatalogQuery.java b/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/usecase/model/CatalogQuery.java index ed11ed655..76d2d2940 100644 --- a/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/usecase/model/CatalogQuery.java +++ b/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/usecase/model/CatalogQuery.java @@ -19,13 +19,11 @@ import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; -import lombok.RequiredArgsConstructor; import java.util.List; @Data @AllArgsConstructor -@RequiredArgsConstructor @Builder(toBuilder = true) @JsonInclude(JsonInclude.Include.NON_NULL) @Schema(description = "Catalog query parameters") diff --git a/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/usecase/model/KpiResult.java b/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/usecase/model/KpiResult.java index 61a9a31f4..cbdc955d5 100644 --- a/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/usecase/model/KpiResult.java +++ b/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/usecase/model/KpiResult.java @@ -19,11 +19,9 @@ import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; -import lombok.RequiredArgsConstructor; @Data @AllArgsConstructor -@RequiredArgsConstructor @Builder(toBuilder = true) @JsonInclude(JsonInclude.Include.NON_NULL) @Schema(description = "EDC-status-defining KPIs") diff --git a/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/usecase/model/TransferProcessStatesDto.java b/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/usecase/model/TransferProcessStatesDto.java index 366fab9ca..a53b4ec83 100644 --- a/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/usecase/model/TransferProcessStatesDto.java +++ b/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/usecase/model/TransferProcessStatesDto.java @@ -20,13 +20,11 @@ import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; -import lombok.RequiredArgsConstructor; import java.util.Map; @Data @AllArgsConstructor -@RequiredArgsConstructor @Builder(toBuilder = true) @JsonInclude(JsonInclude.Include.NON_NULL) public class TransferProcessStatesDto { diff --git a/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/SecretValue.java b/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/SecretValue.java index 519f6f914..e97f81d83 100644 --- a/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/SecretValue.java +++ b/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/SecretValue.java @@ -19,11 +19,9 @@ import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; -import lombok.RequiredArgsConstructor; @Data @AllArgsConstructor -@RequiredArgsConstructor @Builder(toBuilder = true) @JsonInclude(JsonInclude.Include.NON_NULL) @Schema(description = "A value either inlined or to be fetched from the Vault. " + diff --git a/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiAsset.java b/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiAsset.java index 0ed4590b9..1d4deb230 100644 --- a/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiAsset.java +++ b/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiAsset.java @@ -19,14 +19,12 @@ import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; -import lombok.RequiredArgsConstructor; import java.time.LocalDate; import java.util.List; @Data @AllArgsConstructor -@RequiredArgsConstructor @Builder(toBuilder = true) @JsonInclude(JsonInclude.Include.NON_NULL) @Schema(description = "Type-safe data offer metadata as supported by the sovity product landscape. Contains extension points.") diff --git a/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiAssetCreateRequest.java b/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiAssetCreateRequest.java index 8ee241616..0e8cb3913 100644 --- a/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiAssetCreateRequest.java +++ b/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiAssetCreateRequest.java @@ -19,14 +19,12 @@ import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; -import lombok.RequiredArgsConstructor; import java.time.LocalDate; import java.util.List; @Data @AllArgsConstructor -@RequiredArgsConstructor @Builder(toBuilder = true) @JsonInclude(JsonInclude.Include.NON_NULL) @Schema(description = "Type-safe data offer metadata for creating an asset as supported by the sovity product landscape. Contains extension points.") diff --git a/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiAssetEditRequest.java b/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiAssetEditRequest.java index 31fd15d74..bb5ec5fd3 100644 --- a/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiAssetEditRequest.java +++ b/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiAssetEditRequest.java @@ -19,14 +19,12 @@ import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; -import lombok.RequiredArgsConstructor; import java.time.LocalDate; import java.util.List; @Data @AllArgsConstructor -@RequiredArgsConstructor @Builder(toBuilder = true) @JsonInclude(JsonInclude.Include.NON_NULL) @Schema(description = "Type-safe data offer metadata for editing an asset as supported by the sovity product landscape. Contains extension points.") diff --git a/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiDataSource.java b/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiDataSource.java index 8feef9ae8..e10df5018 100644 --- a/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiDataSource.java +++ b/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiDataSource.java @@ -19,13 +19,11 @@ import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; -import lombok.RequiredArgsConstructor; import java.util.Map; @Data @AllArgsConstructor -@RequiredArgsConstructor @Builder(toBuilder = true) @JsonInclude(JsonInclude.Include.NON_NULL) @Schema(description = "Type-safe data source as supported by the sovity product landscape. Contains extension points for using custom data address properties.") diff --git a/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiDataSourceHttpData.java b/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiDataSourceHttpData.java index c995248d5..e1de466b8 100644 --- a/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiDataSourceHttpData.java +++ b/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiDataSourceHttpData.java @@ -19,13 +19,11 @@ import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; -import lombok.RequiredArgsConstructor; import java.util.Map; @Data @AllArgsConstructor -@RequiredArgsConstructor @Builder(toBuilder = true) @JsonInclude(JsonInclude.Include.NON_NULL) @Schema(description = "HTTP_DATA type Data Source.") diff --git a/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiDataSourceOnRequest.java b/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiDataSourceOnRequest.java index ce4402303..d3b1b5f86 100644 --- a/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiDataSourceOnRequest.java +++ b/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiDataSourceOnRequest.java @@ -19,11 +19,9 @@ import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; -import lombok.RequiredArgsConstructor; @Data @AllArgsConstructor -@RequiredArgsConstructor @Builder(toBuilder = true) @JsonInclude(JsonInclude.Include.NON_NULL) @Schema(description = "ON_REQUEST type Data Source.") diff --git a/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiPolicy.java b/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiPolicy.java index 2b6317edc..25b19840e 100644 --- a/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiPolicy.java +++ b/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiPolicy.java @@ -20,13 +20,11 @@ import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; -import lombok.RequiredArgsConstructor; import java.util.List; @Data @AllArgsConstructor -@RequiredArgsConstructor @Builder(toBuilder = true) @JsonInclude(JsonInclude.Include.NON_NULL) @Schema(description = "Type-Safe OpenAPI generator friendly ODLR policy subset as endorsed by sovity.") diff --git a/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiPolicyConstraint.java b/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiPolicyConstraint.java index 58fc11f22..3d6cab2f0 100644 --- a/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiPolicyConstraint.java +++ b/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiPolicyConstraint.java @@ -20,11 +20,9 @@ import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; -import lombok.RequiredArgsConstructor; @Data @AllArgsConstructor -@RequiredArgsConstructor @Builder(toBuilder = true) @JsonInclude(JsonInclude.Include.NON_NULL) @Schema(description = "ODRL AtomicConstraint as supported by the sovity product landscape. For example 'a EQ b', 'c IN [d, e, f]'") diff --git a/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiPolicyCreateRequest.java b/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiPolicyCreateRequest.java index e27806608..5aa3489d2 100644 --- a/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiPolicyCreateRequest.java +++ b/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiPolicyCreateRequest.java @@ -19,13 +19,11 @@ import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; -import lombok.RequiredArgsConstructor; import java.util.List; @Data @AllArgsConstructor -@RequiredArgsConstructor @Builder(toBuilder = true) @JsonInclude(JsonInclude.Include.NON_NULL) @Deprecated diff --git a/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiPolicyExpression.java b/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiPolicyExpression.java index 4d30e337d..3fecc2d38 100644 --- a/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiPolicyExpression.java +++ b/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiPolicyExpression.java @@ -5,14 +5,12 @@ import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; -import lombok.RequiredArgsConstructor; import java.util.List; @Data @AllArgsConstructor -@RequiredArgsConstructor @Builder(toBuilder = true) @JsonInclude(JsonInclude.Include.NON_NULL) @Schema(description = "ODRL constraint as supported by the sovity product landscape") diff --git a/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiPolicyLiteral.java b/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiPolicyLiteral.java index 08176e9ae..c8f1d0423 100644 --- a/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiPolicyLiteral.java +++ b/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiPolicyLiteral.java @@ -20,7 +20,6 @@ import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; -import lombok.RequiredArgsConstructor; import java.util.ArrayList; import java.util.Collection; @@ -29,7 +28,6 @@ @Data @AllArgsConstructor -@RequiredArgsConstructor @Builder(toBuilder = true) @JsonInclude(JsonInclude.Include.NON_NULL) @Schema(description = "Sum type: A String, a list of Strings or a generic JSON value.") From b7d5cb840dcf3469c0cd24b18a01c357c7865246 Mon Sep 17 00:00:00 2001 From: Richard Treier Date: Fri, 19 Jul 2024 12:02:47 +0300 Subject: [PATCH 17/18] chore: fix build --- .../java/de/sovity/edc/ext/wrapper/api/ui/model/AssetPage.java | 3 ++- .../edc/ext/wrapper/api/ui/model/ContractAgreementCard.java | 2 ++ .../edc/ext/wrapper/api/ui/model/ContractAgreementPage.java | 2 ++ .../ext/wrapper/api/ui/model/ContractAgreementPageQuery.java | 1 + .../wrapper/api/ui/model/ContractAgreementTransferProcess.java | 2 ++ .../edc/ext/wrapper/api/ui/model/ContractDefinitionEntry.java | 2 ++ .../edc/ext/wrapper/api/ui/model/ContractDefinitionPage.java | 2 ++ .../ext/wrapper/api/ui/model/ContractDefinitionRequest.java | 2 ++ .../ext/wrapper/api/ui/model/ContractNegotiationRequest.java | 2 ++ .../edc/ext/wrapper/api/ui/model/ContractNegotiationState.java | 2 ++ .../edc/ext/wrapper/api/ui/model/DashboardDapsConfig.java | 2 ++ .../de/sovity/edc/ext/wrapper/api/ui/model/DashboardPage.java | 2 ++ .../edc/ext/wrapper/api/ui/model/DashboardTransferAmounts.java | 2 ++ .../de/sovity/edc/ext/wrapper/api/ui/model/IdResponseDto.java | 2 ++ .../wrapper/api/ui/model/InitiateCustomTransferRequest.java | 2 ++ .../edc/ext/wrapper/api/ui/model/InitiateTransferRequest.java | 2 ++ .../ext/wrapper/api/ui/model/PolicyDefinitionCreateDto.java | 2 ++ .../wrapper/api/ui/model/PolicyDefinitionCreateRequest.java | 2 ++ .../edc/ext/wrapper/api/ui/model/PolicyDefinitionDto.java | 2 ++ .../edc/ext/wrapper/api/ui/model/PolicyDefinitionPage.java | 2 ++ .../edc/ext/wrapper/api/ui/model/TransferHistoryEntry.java | 2 ++ .../edc/ext/wrapper/api/ui/model/TransferHistoryPage.java | 2 ++ .../edc/ext/wrapper/api/ui/model/TransferProcessState.java | 2 ++ .../edc/ext/wrapper/api/ui/model/UiContractNegotiation.java | 2 ++ .../sovity/edc/ext/wrapper/api/ui/model/UiContractOffer.java | 2 ++ .../de/sovity/edc/ext/wrapper/api/ui/model/UiCriterion.java | 2 ++ .../edc/ext/wrapper/api/ui/model/UiCriterionLiteral.java | 2 ++ .../de/sovity/edc/ext/wrapper/api/ui/model/UiDataOffer.java | 2 ++ .../de/sovity/edc/ext/wrapper/api/usecase/UseCaseResource.java | 1 + .../ext/wrapper/api/usecase/model/CatalogFilterExpression.java | 2 ++ .../api/usecase/model/CatalogFilterExpressionLiteral.java | 2 ++ .../sovity/edc/ext/wrapper/api/usecase/model/CatalogQuery.java | 2 ++ .../de/sovity/edc/ext/wrapper/api/usecase/model/KpiResult.java | 2 ++ .../wrapper/api/usecase/model/TransferProcessStatesDto.java | 2 ++ .../sovity/edc/ext/wrapper/api/common/model/SecretValue.java | 2 ++ .../de/sovity/edc/ext/wrapper/api/common/model/UiAsset.java | 2 ++ .../edc/ext/wrapper/api/common/model/UiAssetCreateRequest.java | 2 ++ .../edc/ext/wrapper/api/common/model/UiAssetEditRequest.java | 2 ++ .../sovity/edc/ext/wrapper/api/common/model/UiDataSource.java | 2 ++ .../edc/ext/wrapper/api/common/model/UiDataSourceHttpData.java | 2 ++ .../ext/wrapper/api/common/model/UiDataSourceOnRequest.java | 2 ++ .../de/sovity/edc/ext/wrapper/api/common/model/UiPolicy.java | 2 ++ .../edc/ext/wrapper/api/common/model/UiPolicyConstraint.java | 2 ++ .../ext/wrapper/api/common/model/UiPolicyCreateRequest.java | 2 ++ .../edc/ext/wrapper/api/common/model/UiPolicyExpression.java | 2 ++ .../edc/ext/wrapper/api/common/model/UiPolicyLiteral.java | 2 ++ 46 files changed, 90 insertions(+), 1 deletion(-) diff --git a/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/AssetPage.java b/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/AssetPage.java index 4c39c37d9..80afa7fd1 100644 --- a/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/AssetPage.java +++ b/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/AssetPage.java @@ -13,18 +13,19 @@ */ package de.sovity.edc.ext.wrapper.api.ui.model; - import com.fasterxml.jackson.annotation.JsonInclude; import de.sovity.edc.ext.wrapper.api.common.model.UiAsset; import io.swagger.v3.oas.annotations.media.Schema; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; +import lombok.RequiredArgsConstructor; import java.util.List; @Data @AllArgsConstructor +@RequiredArgsConstructor @Builder(toBuilder = true) @JsonInclude(JsonInclude.Include.NON_NULL) @Schema(description = "All data for the Asset Page") diff --git a/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/ContractAgreementCard.java b/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/ContractAgreementCard.java index 47d1a52ea..0f9568f0a 100644 --- a/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/ContractAgreementCard.java +++ b/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/ContractAgreementCard.java @@ -21,12 +21,14 @@ import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; +import lombok.RequiredArgsConstructor; import java.time.OffsetDateTime; import java.util.List; @Data @AllArgsConstructor +@RequiredArgsConstructor @Builder(toBuilder = true) @JsonInclude(JsonInclude.Include.NON_NULL) @Schema(description = "Contract Agreement for Contract Agreement Page") diff --git a/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/ContractAgreementPage.java b/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/ContractAgreementPage.java index 036bf7a95..4e112e45b 100644 --- a/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/ContractAgreementPage.java +++ b/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/ContractAgreementPage.java @@ -19,11 +19,13 @@ import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; +import lombok.RequiredArgsConstructor; import java.util.List; @Data @AllArgsConstructor +@RequiredArgsConstructor @Builder(toBuilder = true) @JsonInclude(JsonInclude.Include.NON_NULL) @Schema(description = "Data as required by the UI's Contract Agreement Page") diff --git a/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/ContractAgreementPageQuery.java b/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/ContractAgreementPageQuery.java index d9ef4a47e..f836e5399 100644 --- a/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/ContractAgreementPageQuery.java +++ b/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/ContractAgreementPageQuery.java @@ -14,6 +14,7 @@ package de.sovity.edc.ext.wrapper.api.ui.model; +import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonInclude; import io.swagger.v3.oas.annotations.media.Schema; import lombok.AllArgsConstructor; diff --git a/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/ContractAgreementTransferProcess.java b/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/ContractAgreementTransferProcess.java index 66368c95a..92e9577d6 100644 --- a/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/ContractAgreementTransferProcess.java +++ b/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/ContractAgreementTransferProcess.java @@ -19,11 +19,13 @@ import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; +import lombok.RequiredArgsConstructor; import java.time.OffsetDateTime; @Data @AllArgsConstructor +@RequiredArgsConstructor @Builder(toBuilder = true) @JsonInclude(JsonInclude.Include.NON_NULL) @Schema(description = "A Contract Agreement's Transfer Process") diff --git a/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/ContractDefinitionEntry.java b/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/ContractDefinitionEntry.java index b79e7a167..25986ede7 100644 --- a/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/ContractDefinitionEntry.java +++ b/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/ContractDefinitionEntry.java @@ -19,11 +19,13 @@ import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; +import lombok.RequiredArgsConstructor; import java.util.List; @Data @AllArgsConstructor +@RequiredArgsConstructor @Builder(toBuilder = true) @JsonInclude(JsonInclude.Include.NON_NULL) @Schema(description = "Contract Definition List Entry for Contract Definition Page") diff --git a/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/ContractDefinitionPage.java b/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/ContractDefinitionPage.java index b7bc4a6b5..1962eae7d 100644 --- a/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/ContractDefinitionPage.java +++ b/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/ContractDefinitionPage.java @@ -19,11 +19,13 @@ import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; +import lombok.RequiredArgsConstructor; import java.util.List; @Data @AllArgsConstructor +@RequiredArgsConstructor @Builder(toBuilder = true) @JsonInclude(JsonInclude.Include.NON_NULL) public class ContractDefinitionPage { diff --git a/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/ContractDefinitionRequest.java b/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/ContractDefinitionRequest.java index 0ce7fb58d..83afe19d3 100644 --- a/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/ContractDefinitionRequest.java +++ b/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/ContractDefinitionRequest.java @@ -20,11 +20,13 @@ import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; +import lombok.RequiredArgsConstructor; import java.util.List; @Data @AllArgsConstructor +@RequiredArgsConstructor @Builder(toBuilder = true) @JsonInclude(JsonInclude.Include.NON_NULL) @Schema(description = "Data for creating a Contract Definition") diff --git a/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/ContractNegotiationRequest.java b/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/ContractNegotiationRequest.java index 5f770acb7..fe2279644 100644 --- a/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/ContractNegotiationRequest.java +++ b/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/ContractNegotiationRequest.java @@ -20,9 +20,11 @@ import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; +import lombok.RequiredArgsConstructor; @Data @AllArgsConstructor +@RequiredArgsConstructor @Builder(toBuilder = true) @JsonInclude(JsonInclude.Include.NON_NULL) @Schema(description = "Data for initiating a Contract Negotiation") diff --git a/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/ContractNegotiationState.java b/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/ContractNegotiationState.java index b79af9a3d..c5f770b52 100644 --- a/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/ContractNegotiationState.java +++ b/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/ContractNegotiationState.java @@ -19,9 +19,11 @@ import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; +import lombok.RequiredArgsConstructor; @Data @AllArgsConstructor +@RequiredArgsConstructor @Builder(toBuilder = true) @JsonInclude(JsonInclude.Include.NON_NULL) @Schema(description = "Contract Negotiation State interpreted") diff --git a/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/DashboardDapsConfig.java b/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/DashboardDapsConfig.java index e384a90d5..a4cee19ac 100644 --- a/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/DashboardDapsConfig.java +++ b/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/DashboardDapsConfig.java @@ -5,10 +5,12 @@ import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; +import lombok.RequiredArgsConstructor; @Data @AllArgsConstructor +@RequiredArgsConstructor @Builder(toBuilder = true) @JsonInclude(JsonInclude.Include.NON_NULL) @Schema(description = "DAPS Config") diff --git a/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/DashboardPage.java b/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/DashboardPage.java index 073483928..78056c9a7 100644 --- a/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/DashboardPage.java +++ b/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/DashboardPage.java @@ -5,10 +5,12 @@ import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; +import lombok.RequiredArgsConstructor; @Data @AllArgsConstructor +@RequiredArgsConstructor @Builder(toBuilder = true) @JsonInclude(JsonInclude.Include.NON_NULL) @Schema(description = "Data as required by the UI's Dashboard Page") diff --git a/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/DashboardTransferAmounts.java b/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/DashboardTransferAmounts.java index c72cdc423..bbda22a13 100644 --- a/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/DashboardTransferAmounts.java +++ b/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/DashboardTransferAmounts.java @@ -5,10 +5,12 @@ import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; +import lombok.RequiredArgsConstructor; @Data @AllArgsConstructor +@RequiredArgsConstructor @Builder(toBuilder = true) @JsonInclude(JsonInclude.Include.NON_NULL) @Schema(description = "Number of Transfer Processes for given direction.") diff --git a/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/IdResponseDto.java b/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/IdResponseDto.java index 338bf0180..bf554c87b 100644 --- a/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/IdResponseDto.java +++ b/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/IdResponseDto.java @@ -19,11 +19,13 @@ import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; +import lombok.RequiredArgsConstructor; import java.time.OffsetDateTime; @Data @AllArgsConstructor +@RequiredArgsConstructor @Builder(toBuilder = true) @JsonInclude(JsonInclude.Include.NON_NULL) @Schema(description = "Marks the operation as successful") diff --git a/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/InitiateCustomTransferRequest.java b/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/InitiateCustomTransferRequest.java index 3a1b9356e..4d596a20a 100644 --- a/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/InitiateCustomTransferRequest.java +++ b/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/InitiateCustomTransferRequest.java @@ -19,9 +19,11 @@ import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; +import lombok.RequiredArgsConstructor; @Data @AllArgsConstructor +@RequiredArgsConstructor @Builder(toBuilder = true) @JsonInclude(JsonInclude.Include.NON_NULL) @Schema(description = "Required data for starting a Contract Agreement's Transfer Process") diff --git a/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/InitiateTransferRequest.java b/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/InitiateTransferRequest.java index 2d65e4444..d6eed17f1 100644 --- a/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/InitiateTransferRequest.java +++ b/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/InitiateTransferRequest.java @@ -19,11 +19,13 @@ import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; +import lombok.RequiredArgsConstructor; import java.util.Map; @Data @AllArgsConstructor +@RequiredArgsConstructor @Builder(toBuilder = true) @JsonInclude(JsonInclude.Include.NON_NULL) @Schema(description = "For type PARAMS_ONLY: Required data for starting a Transfer Process") diff --git a/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/PolicyDefinitionCreateDto.java b/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/PolicyDefinitionCreateDto.java index f331129b9..8bc4d076d 100644 --- a/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/PolicyDefinitionCreateDto.java +++ b/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/PolicyDefinitionCreateDto.java @@ -20,9 +20,11 @@ import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; +import lombok.RequiredArgsConstructor; @Data @AllArgsConstructor +@RequiredArgsConstructor @Builder(toBuilder = true) @JsonInclude(JsonInclude.Include.NON_NULL) @Schema(description = "Create a Policy Definition") diff --git a/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/PolicyDefinitionCreateRequest.java b/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/PolicyDefinitionCreateRequest.java index 096b7348f..911d90db6 100644 --- a/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/PolicyDefinitionCreateRequest.java +++ b/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/PolicyDefinitionCreateRequest.java @@ -20,9 +20,11 @@ import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; +import lombok.RequiredArgsConstructor; @Data @AllArgsConstructor +@RequiredArgsConstructor @Builder(toBuilder = true) @JsonInclude(JsonInclude.Include.NON_NULL) @Deprecated diff --git a/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/PolicyDefinitionDto.java b/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/PolicyDefinitionDto.java index a4e47a096..3c69aca84 100644 --- a/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/PolicyDefinitionDto.java +++ b/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/PolicyDefinitionDto.java @@ -20,9 +20,11 @@ import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; +import lombok.RequiredArgsConstructor; @Data @AllArgsConstructor +@RequiredArgsConstructor @Builder(toBuilder = true) @JsonInclude(JsonInclude.Include.NON_NULL) @Schema(description = "Policy Definition as required for the Policy Definition Page") diff --git a/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/PolicyDefinitionPage.java b/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/PolicyDefinitionPage.java index d015fd35d..9b77b3c36 100644 --- a/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/PolicyDefinitionPage.java +++ b/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/PolicyDefinitionPage.java @@ -19,11 +19,13 @@ import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; +import lombok.RequiredArgsConstructor; import java.util.List; @Data @AllArgsConstructor +@RequiredArgsConstructor @Builder(toBuilder = true) @JsonInclude(JsonInclude.Include.NON_NULL) @Schema(description = "All data for the policy definition page as required by the UI", requiredMode = Schema.RequiredMode.REQUIRED) diff --git a/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/TransferHistoryEntry.java b/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/TransferHistoryEntry.java index e9c03dcd7..4e29c6c68 100644 --- a/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/TransferHistoryEntry.java +++ b/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/TransferHistoryEntry.java @@ -19,11 +19,13 @@ import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; +import lombok.RequiredArgsConstructor; import java.time.OffsetDateTime; @Data @AllArgsConstructor +@RequiredArgsConstructor @Builder(toBuilder = true) @JsonInclude(JsonInclude.Include.NON_NULL) @Schema(description = "Transfer History Entry for Transfer History Page") diff --git a/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/TransferHistoryPage.java b/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/TransferHistoryPage.java index 0ed9bd08a..e13809da0 100644 --- a/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/TransferHistoryPage.java +++ b/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/TransferHistoryPage.java @@ -19,11 +19,13 @@ import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; +import lombok.RequiredArgsConstructor; import java.util.List; @Data @AllArgsConstructor +@RequiredArgsConstructor @Builder(toBuilder = true) @JsonInclude(JsonInclude.Include.NON_NULL) @Schema(description = "Data as required by the UI's Transfer History Page") diff --git a/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/TransferProcessState.java b/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/TransferProcessState.java index 587c6f8fe..fa87c6f84 100644 --- a/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/TransferProcessState.java +++ b/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/TransferProcessState.java @@ -19,9 +19,11 @@ import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; +import lombok.RequiredArgsConstructor; @Data @AllArgsConstructor +@RequiredArgsConstructor @Builder(toBuilder = true) @JsonInclude(JsonInclude.Include.NON_NULL) @Schema(description = "Transfer Process State interpreted") diff --git a/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/UiContractNegotiation.java b/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/UiContractNegotiation.java index 6e0f3bee2..1235af25a 100644 --- a/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/UiContractNegotiation.java +++ b/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/UiContractNegotiation.java @@ -20,11 +20,13 @@ import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; +import lombok.RequiredArgsConstructor; import java.time.OffsetDateTime; @Data @AllArgsConstructor +@RequiredArgsConstructor @Builder(toBuilder = true) @JsonInclude(JsonInclude.Include.NON_NULL) @Schema(description = "Contract Negotiation Information") diff --git a/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/UiContractOffer.java b/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/UiContractOffer.java index eace4dc30..8c7b42881 100644 --- a/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/UiContractOffer.java +++ b/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/UiContractOffer.java @@ -21,9 +21,11 @@ import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; +import lombok.RequiredArgsConstructor; @Data @AllArgsConstructor +@RequiredArgsConstructor @Builder(toBuilder = true) @JsonInclude(JsonInclude.Include.NON_NULL) @Schema(description = "Catalog Data Offer's Contract Offer as required by the UI") diff --git a/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/UiCriterion.java b/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/UiCriterion.java index a91677ba6..80afa2bc9 100644 --- a/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/UiCriterion.java +++ b/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/UiCriterion.java @@ -20,9 +20,11 @@ import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; +import lombok.RequiredArgsConstructor; @Data @AllArgsConstructor +@RequiredArgsConstructor @Builder(toBuilder = true) @JsonInclude(JsonInclude.Include.NON_NULL) @Schema(description = "Contract Definition Criterion as supported by the UI") diff --git a/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/UiCriterionLiteral.java b/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/UiCriterionLiteral.java index 6a8ab9f99..760d1ff45 100644 --- a/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/UiCriterionLiteral.java +++ b/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/UiCriterionLiteral.java @@ -6,11 +6,13 @@ import lombok.Builder; import lombok.Data; import lombok.NonNull; +import lombok.RequiredArgsConstructor; import java.util.List; @Data @AllArgsConstructor +@RequiredArgsConstructor @Builder(toBuilder = true) @JsonInclude(JsonInclude.Include.NON_NULL) @Schema(description = "Criterion Literal") diff --git a/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/UiDataOffer.java b/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/UiDataOffer.java index 9f8327980..16a8d6316 100644 --- a/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/UiDataOffer.java +++ b/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/UiDataOffer.java @@ -20,11 +20,13 @@ import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; +import lombok.RequiredArgsConstructor; import java.util.List; @Data @AllArgsConstructor +@RequiredArgsConstructor @Builder(toBuilder = true) @JsonInclude(JsonInclude.Include.NON_NULL) @Schema(description = "Catalog Data Offer as required by the UI") diff --git a/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/usecase/UseCaseResource.java b/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/usecase/UseCaseResource.java index e02e50e9c..b959ac0ec 100644 --- a/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/usecase/UseCaseResource.java +++ b/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/usecase/UseCaseResource.java @@ -19,6 +19,7 @@ import de.sovity.edc.ext.wrapper.api.usecase.model.KpiResult; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; +import jakarta.validation.Valid; import jakarta.validation.constraints.NotNull; import jakarta.ws.rs.Consumes; import jakarta.ws.rs.GET; diff --git a/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/usecase/model/CatalogFilterExpression.java b/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/usecase/model/CatalogFilterExpression.java index 16bf52d72..238d06e44 100644 --- a/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/usecase/model/CatalogFilterExpression.java +++ b/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/usecase/model/CatalogFilterExpression.java @@ -20,9 +20,11 @@ import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; +import lombok.RequiredArgsConstructor; @Data @AllArgsConstructor +@RequiredArgsConstructor @Builder(toBuilder = true) @JsonInclude(JsonInclude.Include.NON_NULL) @Schema(description = "Generic expression for filtering the data offers in the catalog", requiredMode = Schema.RequiredMode.NOT_REQUIRED) diff --git a/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/usecase/model/CatalogFilterExpressionLiteral.java b/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/usecase/model/CatalogFilterExpressionLiteral.java index 0cf00bbfc..8faa1d5d3 100644 --- a/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/usecase/model/CatalogFilterExpressionLiteral.java +++ b/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/usecase/model/CatalogFilterExpressionLiteral.java @@ -20,11 +20,13 @@ import lombok.Builder; import lombok.Data; import lombok.NonNull; +import lombok.RequiredArgsConstructor; import java.util.List; @Data @AllArgsConstructor +@RequiredArgsConstructor @Builder(toBuilder = true) @JsonInclude(JsonInclude.Include.NON_NULL) @Schema(description = "FilterExpression Criterion Literal") diff --git a/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/usecase/model/CatalogQuery.java b/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/usecase/model/CatalogQuery.java index 76d2d2940..ed11ed655 100644 --- a/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/usecase/model/CatalogQuery.java +++ b/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/usecase/model/CatalogQuery.java @@ -19,11 +19,13 @@ import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; +import lombok.RequiredArgsConstructor; import java.util.List; @Data @AllArgsConstructor +@RequiredArgsConstructor @Builder(toBuilder = true) @JsonInclude(JsonInclude.Include.NON_NULL) @Schema(description = "Catalog query parameters") diff --git a/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/usecase/model/KpiResult.java b/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/usecase/model/KpiResult.java index cbdc955d5..61a9a31f4 100644 --- a/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/usecase/model/KpiResult.java +++ b/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/usecase/model/KpiResult.java @@ -19,9 +19,11 @@ import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; +import lombok.RequiredArgsConstructor; @Data @AllArgsConstructor +@RequiredArgsConstructor @Builder(toBuilder = true) @JsonInclude(JsonInclude.Include.NON_NULL) @Schema(description = "EDC-status-defining KPIs") diff --git a/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/usecase/model/TransferProcessStatesDto.java b/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/usecase/model/TransferProcessStatesDto.java index a53b4ec83..366fab9ca 100644 --- a/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/usecase/model/TransferProcessStatesDto.java +++ b/extensions/wrapper/wrapper-api/src/main/java/de/sovity/edc/ext/wrapper/api/usecase/model/TransferProcessStatesDto.java @@ -20,11 +20,13 @@ import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; +import lombok.RequiredArgsConstructor; import java.util.Map; @Data @AllArgsConstructor +@RequiredArgsConstructor @Builder(toBuilder = true) @JsonInclude(JsonInclude.Include.NON_NULL) public class TransferProcessStatesDto { diff --git a/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/SecretValue.java b/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/SecretValue.java index e97f81d83..519f6f914 100644 --- a/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/SecretValue.java +++ b/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/SecretValue.java @@ -19,9 +19,11 @@ import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; +import lombok.RequiredArgsConstructor; @Data @AllArgsConstructor +@RequiredArgsConstructor @Builder(toBuilder = true) @JsonInclude(JsonInclude.Include.NON_NULL) @Schema(description = "A value either inlined or to be fetched from the Vault. " + diff --git a/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiAsset.java b/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiAsset.java index 1d4deb230..0ed4590b9 100644 --- a/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiAsset.java +++ b/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiAsset.java @@ -19,12 +19,14 @@ import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; +import lombok.RequiredArgsConstructor; import java.time.LocalDate; import java.util.List; @Data @AllArgsConstructor +@RequiredArgsConstructor @Builder(toBuilder = true) @JsonInclude(JsonInclude.Include.NON_NULL) @Schema(description = "Type-safe data offer metadata as supported by the sovity product landscape. Contains extension points.") diff --git a/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiAssetCreateRequest.java b/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiAssetCreateRequest.java index 0e8cb3913..8ee241616 100644 --- a/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiAssetCreateRequest.java +++ b/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiAssetCreateRequest.java @@ -19,12 +19,14 @@ import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; +import lombok.RequiredArgsConstructor; import java.time.LocalDate; import java.util.List; @Data @AllArgsConstructor +@RequiredArgsConstructor @Builder(toBuilder = true) @JsonInclude(JsonInclude.Include.NON_NULL) @Schema(description = "Type-safe data offer metadata for creating an asset as supported by the sovity product landscape. Contains extension points.") diff --git a/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiAssetEditRequest.java b/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiAssetEditRequest.java index bb5ec5fd3..31fd15d74 100644 --- a/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiAssetEditRequest.java +++ b/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiAssetEditRequest.java @@ -19,12 +19,14 @@ import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; +import lombok.RequiredArgsConstructor; import java.time.LocalDate; import java.util.List; @Data @AllArgsConstructor +@RequiredArgsConstructor @Builder(toBuilder = true) @JsonInclude(JsonInclude.Include.NON_NULL) @Schema(description = "Type-safe data offer metadata for editing an asset as supported by the sovity product landscape. Contains extension points.") diff --git a/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiDataSource.java b/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiDataSource.java index e10df5018..8feef9ae8 100644 --- a/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiDataSource.java +++ b/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiDataSource.java @@ -19,11 +19,13 @@ import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; +import lombok.RequiredArgsConstructor; import java.util.Map; @Data @AllArgsConstructor +@RequiredArgsConstructor @Builder(toBuilder = true) @JsonInclude(JsonInclude.Include.NON_NULL) @Schema(description = "Type-safe data source as supported by the sovity product landscape. Contains extension points for using custom data address properties.") diff --git a/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiDataSourceHttpData.java b/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiDataSourceHttpData.java index e1de466b8..c995248d5 100644 --- a/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiDataSourceHttpData.java +++ b/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiDataSourceHttpData.java @@ -19,11 +19,13 @@ import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; +import lombok.RequiredArgsConstructor; import java.util.Map; @Data @AllArgsConstructor +@RequiredArgsConstructor @Builder(toBuilder = true) @JsonInclude(JsonInclude.Include.NON_NULL) @Schema(description = "HTTP_DATA type Data Source.") diff --git a/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiDataSourceOnRequest.java b/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiDataSourceOnRequest.java index d3b1b5f86..ce4402303 100644 --- a/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiDataSourceOnRequest.java +++ b/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiDataSourceOnRequest.java @@ -19,9 +19,11 @@ import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; +import lombok.RequiredArgsConstructor; @Data @AllArgsConstructor +@RequiredArgsConstructor @Builder(toBuilder = true) @JsonInclude(JsonInclude.Include.NON_NULL) @Schema(description = "ON_REQUEST type Data Source.") diff --git a/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiPolicy.java b/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiPolicy.java index 25b19840e..2b6317edc 100644 --- a/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiPolicy.java +++ b/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiPolicy.java @@ -20,11 +20,13 @@ import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; +import lombok.RequiredArgsConstructor; import java.util.List; @Data @AllArgsConstructor +@RequiredArgsConstructor @Builder(toBuilder = true) @JsonInclude(JsonInclude.Include.NON_NULL) @Schema(description = "Type-Safe OpenAPI generator friendly ODLR policy subset as endorsed by sovity.") diff --git a/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiPolicyConstraint.java b/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiPolicyConstraint.java index 3d6cab2f0..58fc11f22 100644 --- a/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiPolicyConstraint.java +++ b/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiPolicyConstraint.java @@ -20,9 +20,11 @@ import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; +import lombok.RequiredArgsConstructor; @Data @AllArgsConstructor +@RequiredArgsConstructor @Builder(toBuilder = true) @JsonInclude(JsonInclude.Include.NON_NULL) @Schema(description = "ODRL AtomicConstraint as supported by the sovity product landscape. For example 'a EQ b', 'c IN [d, e, f]'") diff --git a/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiPolicyCreateRequest.java b/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiPolicyCreateRequest.java index 5aa3489d2..e27806608 100644 --- a/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiPolicyCreateRequest.java +++ b/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiPolicyCreateRequest.java @@ -19,11 +19,13 @@ import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; +import lombok.RequiredArgsConstructor; import java.util.List; @Data @AllArgsConstructor +@RequiredArgsConstructor @Builder(toBuilder = true) @JsonInclude(JsonInclude.Include.NON_NULL) @Deprecated diff --git a/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiPolicyExpression.java b/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiPolicyExpression.java index 3fecc2d38..4d30e337d 100644 --- a/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiPolicyExpression.java +++ b/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiPolicyExpression.java @@ -5,12 +5,14 @@ import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; +import lombok.RequiredArgsConstructor; import java.util.List; @Data @AllArgsConstructor +@RequiredArgsConstructor @Builder(toBuilder = true) @JsonInclude(JsonInclude.Include.NON_NULL) @Schema(description = "ODRL constraint as supported by the sovity product landscape") diff --git a/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiPolicyLiteral.java b/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiPolicyLiteral.java index c8f1d0423..08176e9ae 100644 --- a/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiPolicyLiteral.java +++ b/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiPolicyLiteral.java @@ -20,6 +20,7 @@ import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; +import lombok.RequiredArgsConstructor; import java.util.ArrayList; import java.util.Collection; @@ -28,6 +29,7 @@ @Data @AllArgsConstructor +@RequiredArgsConstructor @Builder(toBuilder = true) @JsonInclude(JsonInclude.Include.NON_NULL) @Schema(description = "Sum type: A String, a list of Strings or a generic JSON value.") From 04f92c0ba9275f5177c60d0a8a6534beb7599f56 Mon Sep 17 00:00:00 2001 From: Richard Treier Date: Fri, 19 Jul 2024 12:07:03 +0300 Subject: [PATCH 18/18] chore: fix build --- tests/src/test/java/de/sovity/edc/e2e/UiApiWrapperTest.java | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/src/test/java/de/sovity/edc/e2e/UiApiWrapperTest.java b/tests/src/test/java/de/sovity/edc/e2e/UiApiWrapperTest.java index ea8864b1b..790e0c268 100644 --- a/tests/src/test/java/de/sovity/edc/e2e/UiApiWrapperTest.java +++ b/tests/src/test/java/de/sovity/edc/e2e/UiApiWrapperTest.java @@ -558,7 +558,6 @@ void editAssetOnLiveContract( validateDataTransferred(dataAddress.getDataSinkSpyUrl(), data); validateTransferProcessesOk(consumerClient, providerClient); assertThat(providerClient.uiApi().getTransferHistoryPage().getTransferEntries().get(0).getAssetName()).isEqualTo("Good Asset Title"); - "Good Asset Title"); } @Test