-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added New CriterionDto Mapping method
- Loading branch information
Showing
9 changed files
with
251 additions
and
41 deletions.
There are no files selected for viewing
62 changes: 62 additions & 0 deletions
62
...apper/client/src/test/java/de/sovity/edc/client/ContractDefinitionPageApiServiceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/* | ||
* 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 - initial API and implementation | ||
* | ||
*/ | ||
|
||
package de.sovity.edc.client; | ||
|
||
import org.eclipse.edc.connector.spi.contractdefinition.ContractDefinitionService; | ||
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 static de.sovity.edc.client.ContractDefinitionTestUtils.createContractDefinition; | ||
|
||
import java.text.ParseException; | ||
import java.util.Map; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
@ApiTest | ||
@ExtendWith(EdcExtension.class) | ||
class ContractDefinitionPageApiServiceTest { | ||
|
||
@BeforeEach | ||
void setUp(EdcExtension extension) { | ||
extension.setConfiguration(TestUtils.createConfiguration(Map.of())); | ||
} | ||
|
||
@Test | ||
void startContractDefinition(ContractDefinitionService contractDefinitionService) throws ParseException { | ||
var client = TestUtils.edcClient(); | ||
|
||
// arrange | ||
createContractDefinition(contractDefinitionService); | ||
|
||
|
||
// act | ||
var result = client.uiApi().contractDefinitionPage(); | ||
|
||
// Get the contract definition | ||
var contractDefinitions = result.getContractDefinitions(); | ||
|
||
// assert | ||
var contractDefinition = contractDefinitions.get(0); | ||
assertThat(contractDefinition.getContractDefinitionId()).isEqualTo(ContractDefinitionTestUtils.CONTRACT_DEFINITION_ID); | ||
assertThat(contractDefinition.getContractPolicyId()).isEqualTo(ContractDefinitionTestUtils.CONTRACT_POLICY_ID); | ||
assertThat(contractDefinition.getAccessPolicyId()).isEqualTo(ContractDefinitionTestUtils.ACCESS_POLICY_ID); | ||
} | ||
|
||
|
||
} |
58 changes: 58 additions & 0 deletions
58
...nsions/wrapper/client/src/test/java/de/sovity/edc/client/ContractDefinitionTestUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
* 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.client; | ||
|
||
import org.eclipse.edc.connector.contract.spi.types.offer.ContractDefinition; | ||
import org.eclipse.edc.connector.spi.contractdefinition.ContractDefinitionService; | ||
import org.eclipse.edc.spi.asset.AssetSelectorExpression; | ||
import org.eclipse.edc.spi.query.Criterion; | ||
import org.jetbrains.annotations.NotNull; | ||
import java.text.ParseException; | ||
import java.util.Arrays; | ||
|
||
public class ContractDefinitionTestUtils { | ||
|
||
public static final String CONTRACT_DEFINITION_ID = "contract-definition:eb934d1f-6582-4bab-85e6-af19a76f7e2b"; | ||
|
||
public static final String CONTRACT_POLICY_ID = "contract-policy:f52a5d30-6356-4a55-a75a-3c45d7a88c3e"; | ||
|
||
public static final String ACCESS_POLICY_ID = "access-policy:eb934d1f-6582-4bab-85e6-af19a76f7e2b"; | ||
|
||
@NotNull | ||
public static void createContractDefinition(ContractDefinitionService contractDefinitionService) throws ParseException { | ||
|
||
// Create an AssetSelectorExpression | ||
AssetSelectorExpression selectorExpression = AssetSelectorExpression.Builder.newInstance() | ||
.criteria(Arrays.asList( | ||
new Criterion("criteria1", "=", "value1"), | ||
new Criterion("criteria2", "=", "value2") | ||
)) | ||
.build(); | ||
|
||
var definition = ContractDefinition.Builder.newInstance() | ||
.id(CONTRACT_DEFINITION_ID) | ||
.contractPolicyId(CONTRACT_POLICY_ID) | ||
.accessPolicyId(ACCESS_POLICY_ID) | ||
.validity(10000L) | ||
.selectorExpression(selectorExpression) | ||
.build(); | ||
|
||
contractDefinitionService.create(definition); | ||
|
||
|
||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
...ns/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/CriterionDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* 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 lombok.Getter; | ||
import lombok.Setter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.AllArgsConstructor; | ||
|
||
|
||
@Getter | ||
@Setter | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class CriterionDto { | ||
private String operandLeft; | ||
private String operator; | ||
private String operatorRight; | ||
private String[] operatorRightArray; | ||
private CriterionType type; | ||
|
||
public static CriterionDto forString(String operandLeft, String operator, String operatorRight) { | ||
return new CriterionDto(operandLeft, operator, operatorRight, null, CriterionType.STRING); | ||
} | ||
|
||
public static CriterionDto forStringArray(String operandLeft, String operator, String[] operatorRightArray) { | ||
return new CriterionDto(operandLeft, operator, null, operatorRightArray, CriterionType.STRING_ARRAY); | ||
} | ||
|
||
public static CriterionDto forJson(String operandLeft, String operator, String operatorRight) { | ||
return new CriterionDto(operandLeft, operator, operatorRight, null, CriterionType.JSON); | ||
} | ||
|
||
} | ||
|
||
enum CriterionType { | ||
STRING, STRING_ARRAY, JSON | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
...sovity/edc/ext/wrapper/api/ui/pages/contracts/services/utils/ContractDefinitionUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
* 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 - initial API and implementation | ||
* | ||
*/ | ||
|
||
package de.sovity.edc.ext.wrapper.api.ui.pages.contracts.services.utils; | ||
|
||
|
||
import de.sovity.edc.ext.wrapper.api.ui.model.CriterionDto; | ||
import lombok.RequiredArgsConstructor; | ||
import org.eclipse.edc.spi.query.Criterion; | ||
|
||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
@RequiredArgsConstructor | ||
public class ContractDefinitionUtils { | ||
|
||
public CriterionDto mapToCriterionDto(Criterion criterion) { | ||
if (criterion == null) { | ||
return null; | ||
} | ||
|
||
CriterionDto dto = new CriterionDto(); | ||
dto.setOperandLeft(String.valueOf(criterion.getOperandLeft())); | ||
dto.setOperator(criterion.getOperator()); | ||
dto.setOperatorRight(String.valueOf(criterion.getOperandRight())); | ||
|
||
// Since the operatorRightArray and type fields don't exist in the Criterion object | ||
// they can't be mapped in this function | ||
|
||
return dto; | ||
} | ||
|
||
public List<CriterionDto> mapToCriterionDtos(List<Criterion> criteria) { | ||
if (criteria == null) { | ||
return null; | ||
} | ||
|
||
return criteria.stream().map(this::mapToCriterionDto).collect(Collectors.toList()); | ||
} | ||
|
||
|
||
} |