Skip to content

Commit

Permalink
chore: rename field from policy to expression
Browse files Browse the repository at this point in the history
  • Loading branch information
richardtreier committed Jul 18, 2024
1 parent fb52dbd commit 1077971
Show file tree
Hide file tree
Showing 15 changed files with 29 additions and 29 deletions.
7 changes: 4 additions & 3 deletions docs/api/sovity-edc-api-wrapper.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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)"
Expand Down Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ private void createPolicy() {

var policyDefinition = PolicyDefinitionCreateDto.builder()
.policyDefinitionId(dataOfferId)
.policy(expression)
.expression(expression)
.build();

connectorClient.uiApi().createPolicyDefinitionV2(policyDefinition);
Expand Down
13 changes: 6 additions & 7 deletions extensions/wrapper/clients/java-client/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)` |
Expand All @@ -123,22 +123,21 @@ 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(
buildConstraint("Membership", OperatorDto.EQ, "active"),
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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@ public class PolicyDefinitionCreateDto {
private String policyDefinitionId;

@Schema(description = "Policy Expression", requiredMode = Schema.RequiredMode.REQUIRED)
private UiPolicyExpression policy;
private UiPolicyExpression expression;
}

Original file line number Diff line number Diff line change
Expand Up @@ -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<UiPolicyConstraint> expressions;
@Schema(description = "Conjunction of required constraints", deprecated = true)
private List<UiPolicyConstraint> constraints;
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public UiPolicyExpression buildUiPolicyExpression(UiPolicyCreateRequest createRe
return UiPolicyExpression.empty();
}

return buildUiPolicyExpression(createRequest.getExpressions());
return buildUiPolicyExpression(createRequest.getConstraints());
}

private UiPolicyExpression buildUiPolicyExpression(List<UiPolicyConstraint> expressions) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ private void createPolicy() {

var policyDefinition = PolicyDefinitionCreateDto.builder()
.policyDefinitionId(dataOfferId)
.policy(expression)
.expression(expression)
.build();

providerClient.uiApi().createPolicyDefinitionV2(policyDefinition);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions tests/src/test/java/de/sovity/edc/e2e/UiApiWrapperTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ private void createPolicy(EdcClient providerClient) {

var policyDefinition = PolicyDefinitionCreateDto.builder()
.policyDefinitionId(dataOfferId)
.policy(expression)
.expression(expression)
.build();

providerClient.uiApi().createPolicyDefinitionV2(policyDefinition);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ private IdResponseDto createPolicyDefinition(String policyId, List<UiPolicyConst

var policyDefinition = PolicyDefinitionCreateDto.builder()
.policyDefinitionId(policyId)
.policy(expression)
.expression(expression)
.build();

return providerClient.uiApi().createPolicyDefinitionV2(policyDefinition);
Expand Down Expand Up @@ -247,7 +247,7 @@ public void createPolicy(String id, OffsetDateTime from, OffsetDateTime until) {

var policyDefinition = PolicyDefinitionCreateDto.builder()
.policyDefinitionId(id)
.policy(expression)
.expression(expression)
.build();

providerClient.uiApi().createPolicyDefinitionV2(policyDefinition);
Expand Down

0 comments on commit 1077971

Please sign in to comment.