Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

391 backend UI api wrapper GET & POST & DELETE contract definition endpoint with 02x #466

Merged
Show file tree
Hide file tree
Changes from 32 commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
23b7f40
del: ids-clearinghouse-client-Extension
efiege Jun 6, 2023
e4eb869
del: ids-broker-client-Extension
efiege Jun 6, 2023
c0a5df5
feat: upgrade to core-edc-version 0.1.0
efiege Jun 6, 2023
e98ff36
fix: wrapper-Extension
efiege Jun 6, 2023
2e61c92
fix: tests and transfer process state mapping
efiege Jun 6, 2023
35e8347
test: e2e test for a http-push transfer
efiege Jun 15, 2023
9fc4940
chore: integrate lombok version into gradle submodules
efiege Jun 15, 2023
41d8e9e
feat: Add db-migration script for EDC-MS8 to 0.1.0
efiege Jun 19, 2023
b9cbef4
chore: Adapt dev-docker-compose to build images from scratch
efiege Jun 22, 2023
7334850
feat: Upgrade to version 0.1.2
efiege Jun 23, 2023
4fe6182
feat: enhance script to migrate old m8-data to version 0.1.2
efiege Jun 26, 2023
6f0ef3c
feat: update postman collection for version 0.1.2
efiege Jun 26, 2023
671a1ab
feat: update health endpoint in dockerfile for version 0.1.2
efiege Jun 27, 2023
f9d9527
feat: move ms8-to-0.1.0 migration script such that it will be execute…
efiege Jun 28, 2023
ca6c5a6
feat: rename ids endpoints and variables to protocol
efiege Jun 28, 2023
ee255f0
chore: update openapi.yaml to represent version 0.1.2 endpoints
efiege Jun 28, 2023
e55a7b3
chore: adapt changelog for 0.1.2 changes
efiege Jun 30, 2023
f7c170c
feat: upgrade to core edc version 0.1.3
efiege Jul 10, 2023
af33440
feat: upgrade to core edc version 0.2.0
efiege Jul 28, 2023
6619cff
feat(wrapper): create offer merge chnages from main and upgrade to ed…
timdah Jun 26, 2023
8b7596a
feat: migrate initiateTransfer endpoint to edc version 0.2.0
efiege Aug 1, 2023
021b2d0
feat: migrate transferHistory and contractAgreement endpoints to edc …
efiege Aug 1, 2023
f2fdfcb
chore: drop removed columns for edc schema version 0.2.0
efiege Aug 1, 2023
f74b4b9
Added GET Contract Definitions
SaadEGI Aug 3, 2023
5084136
GET and POST Contract Definition Calls
SaadEGI Aug 3, 2023
a26c7b1
DELETE Contract Definition Calls
SaadEGI Aug 3, 2023
d72d511
PR Revision I: Format + assert Functions
SaadEGI Aug 3, 2023
57d3941
Contract Definition Delete Test + PR Revision II
SaadEGI Aug 9, 2023
6081bd8
Merge branch 'main' of https://github.com/sovity/edc-extensions into …
SaadEGI Aug 10, 2023
e124589
test: Contract Definition Api
SaadEGI Aug 10, 2023
d0c3654
Merge branch 'main' of https://github.com/sovity/edc-extensions into …
SaadEGI Aug 10, 2023
dbe2572
fix: Code Style & Struct
SaadEGI Aug 10, 2023
77f916b
chore: CriterionLiteral + operatorDto
SaadEGI Aug 10, 2023
0c506d3
fix: typos and Style
SaadEGI Aug 10, 2023
fb21224
chore: Operator Refactoring+Mapper
SaadEGI Aug 11, 2023
b1b72c4
fix: tests, Criterion SumType
SaadEGI Aug 14, 2023
f8cca5f
fix: Pipeline
SaadEGI Aug 14, 2023
959b1af
chore: CriterionMapper test
SaadEGI Aug 15, 2023
a53052e
fix: remove obsolete wait statements
SaadEGI Aug 15, 2023
bbb34fa
fix: Pipeline
SaadEGI Aug 15, 2023
9ce4c1c
fix: Pipeline
SaadEGI Aug 15, 2023
8da0c04
fix: Timewrapper instead of wait statements
SaadEGI Aug 15, 2023
e901ac0
chore: simplify timewrapper
richardtreier Aug 15, 2023
cbae989
fix: Operator test
SaadEGI Aug 15, 2023
44b8e35
fix: Operator test Naming
SaadEGI Aug 15, 2023
ceb8edf
fix: False Changing
SaadEGI Aug 15, 2023
30729dd
fix: use of static
SaadEGI Aug 15, 2023
ce78b61
fix: Removed dead Code
SaadEGI Aug 15, 2023
9e1cc10
fix: Operator test case
SaadEGI Aug 15, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
SaadEGI marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
/*
* 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 de.sovity.edc.client.gen.model.ContractDefinitionRequest;
import de.sovity.edc.client.gen.model.CriterionDto;
import org.eclipse.edc.connector.contract.spi.types.offer.ContractDefinition;
import org.eclipse.edc.connector.spi.contractdefinition.ContractDefinitionService;
import org.eclipse.edc.junit.annotations.ApiTest;
import org.eclipse.edc.junit.extensions.EdcExtension;
import org.eclipse.edc.spi.query.Criterion;
import org.eclipse.edc.spi.query.QuerySpec;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;


import java.util.Arrays;
import java.util.List;

import static org.assertj.core.api.Assertions.assertThat;

@ApiTest
@ExtendWith(EdcExtension.class)
class ContractDefinitionPageApiServiceTest {

@BeforeEach
void setUp(EdcExtension extension) {
TestUtils.setupExtension(extension);
}

@Test
void contractDefinitionPage(ContractDefinitionService contractDefinitionService) {
//arrange
var client = TestUtils.edcClient();
var criteria = Arrays.asList(
SaadEGI marked this conversation as resolved.
Show resolved Hide resolved
new Criterion(
"exampleLeft1",
"operator1",
"exampleRight1")
);
createContractDefinition(contractDefinitionService, "contractPolicy-id-1", "accessPolicy-id-1", criteria);

// act
var result = client.uiApi().contractDefinitionPage();

//assert
var contractDefinitions = result.getContractDefinitions();
SaadEGI marked this conversation as resolved.
Show resolved Hide resolved
assertThat(contractDefinitions).hasSize(1);
var contractDefinition = contractDefinitions.get(0);
assertThat(contractDefinition.getContractPolicyId()).isEqualTo("contractPolicy-id-1");
assertThat(contractDefinition.getAccessPolicyId()).isEqualTo("accessPolicy-id-1");
assertThat(contractDefinition.getCriteria().get(0).getOperandLeft()).isEqualTo(criteria.get(0).getOperandLeft());
assertThat(contractDefinition.getCriteria().get(0).getOperator()).isEqualTo(criteria.get(0).getOperator());
assertThat(contractDefinition.getCriteria().get(0).getOperandRight()).isEqualTo(criteria.get(0).getOperandRight());
}

@Test
void contractDefinitionPageSorting(ContractDefinitionService contractDefinitionService) {
//arrange
var client = TestUtils.edcClient();
createContractDefinition(contractDefinitionService, "contractPolicy-id-1", "accessPolicy-id-1", Arrays.asList());
TestUtils.wait(1);
createContractDefinition(contractDefinitionService, "contractPolicy-id-2", "accessPolicy-id-2", Arrays.asList());
TestUtils.wait(1);
SaadEGI marked this conversation as resolved.
Show resolved Hide resolved
createContractDefinition(contractDefinitionService, "contractPolicy-id-3", "accessPolicy-id-3", Arrays.asList());

// act
var result = client.uiApi().contractDefinitionPage();

//assert
assertThat(result.getContractDefinitions())
.extracting(contractDefinition -> contractDefinition.getContractPolicyId())
.containsExactly("contractPolicy-id-3", "contractPolicy-id-2", "contractPolicy-id-1");

}

@Test
void testContractDefinitionCreation(ContractDefinitionService contractDefinitionService) {
// arrange
var client = TestUtils.edcClient();
var criteria = Arrays.asList(
new CriterionDto(
"exampleLeft1",
"operator1",
"exampleRight1")
);
var contractDefinition = ContractDefinitionRequest.builder()
.contractPolicyId("contractPolicy-id-1")
.accessPolicyId("accessPolicy-id-1")
.assetsSelector(criteria)
.build();

// act
var response = client.uiApi().createContractDefinition(contractDefinition);

//assert
assertThat(response).isNotNull();
var contractDefinitions = contractDefinitionService.query(QuerySpec.max()).getContent().toList();
assertThat(contractDefinitions).hasSize(1);
var contractDefinitionEntry = contractDefinitions.get(0);
assertThat(contractDefinitionEntry.getContractPolicyId()).isEqualTo("contractPolicy-id-1");
assertThat(contractDefinitionEntry.getAccessPolicyId()).isEqualTo("accessPolicy-id-1");
assertThat(contractDefinitionEntry.getAssetsSelector().get(0).getOperandLeft()).isEqualTo(criteria.get(0).getOperandLeft());
assertThat(contractDefinitionEntry.getAssetsSelector().get(0).getOperator()).isEqualTo(criteria.get(0).getOperator());
assertThat(contractDefinitionEntry.getAssetsSelector().get(0).getOperandRight()).isEqualTo(criteria.get(0).getOperandRight());
}

@Test
void testDeleteContractDefinition(ContractDefinitionService contractDefinitionService) {
// arrange
var client = TestUtils.edcClient();
var criteria = Arrays.asList(
new Criterion(
"exampleLeft1",
"operator1",
"exampleRight1")
);
createContractDefinition(contractDefinitionService, "contractPolicy-id-1", "accessPolicy-id-1", criteria);
assertThat(contractDefinitionService.query(QuerySpec.max()).getContent().toList()).hasSize(1);
var contractDefinition = contractDefinitionService.query(QuerySpec.max()).getContent().toList().get(0);

// act
var response = client.uiApi().deleteContractDefinition(contractDefinition.getId());

// assert
assertThat(response.getId()).isEqualTo(contractDefinition.getId());
assertThat(contractDefinitionService.query(QuerySpec.max()).getContent()).isEmpty();
}

private void createContractDefinition(
ContractDefinitionService contractDefinitionService,
String contractPolicyId,
String accessPolicyId,
List<Criterion> criteria
) {
var contractDefinition = ContractDefinition.Builder.newInstance()
.contractPolicyId(contractPolicyId)
.accessPolicyId(accessPolicyId)
.assetsSelector(criteria)
.build();
contractDefinitionService.create(contractDefinition);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,12 @@ public static EdcClient edcClient() {
.managementApiKey(TestUtils.MANAGEMENT_API_KEY)
.build();
}

public static void wait(int seconds) {
try {
Thread.sleep(seconds * 1000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.eclipse.edc.connector.policy.spi.store.PolicyDefinitionStore;
import org.eclipse.edc.connector.spi.asset.AssetService;
import org.eclipse.edc.connector.spi.contractagreement.ContractAgreementService;
import org.eclipse.edc.connector.spi.contractdefinition.ContractDefinitionService;
import org.eclipse.edc.connector.spi.contractnegotiation.ContractNegotiationService;
import org.eclipse.edc.connector.spi.transferprocess.TransferProcessService;
import org.eclipse.edc.connector.transfer.spi.store.TransferProcessStore;
Expand Down Expand Up @@ -60,6 +61,8 @@ public class WrapperExtension implements ServiceExtension {
private TypeManager typeManager;
@Inject
private WebService webService;
@Inject
private ContractDefinitionService contractDefinitionService;

@Override
public String name() {
Expand All @@ -82,7 +85,8 @@ public void initialize(ServiceExtensionContext context) {
policyDefinitionStore,
policyEngine,
transferProcessStore,
transferProcessService
transferProcessService,
contractDefinitionService
);

wrapperExtensionContext.jaxRsResources().forEach(resource ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,14 @@
import de.sovity.edc.ext.wrapper.api.ui.pages.asset.services.utils.AssetPropertyMapper;
import de.sovity.edc.ext.wrapper.api.ui.pages.contracts.ContractAgreementPageApiService;
import de.sovity.edc.ext.wrapper.api.ui.pages.contracts.ContractAgreementTransferApiService;
import de.sovity.edc.ext.wrapper.api.ui.pages.contracts.ContractDefinitionApiService;
import de.sovity.edc.ext.wrapper.api.ui.pages.contracts.services.ContractAgreementDataFetcher;
import de.sovity.edc.ext.wrapper.api.ui.pages.contracts.services.ContractAgreementPageCardBuilder;
import de.sovity.edc.ext.wrapper.api.ui.pages.contracts.services.ContractDefinitionBuilder;
import de.sovity.edc.ext.wrapper.api.ui.pages.contracts.services.TransferProcessStateService;
import de.sovity.edc.ext.wrapper.api.ui.pages.contracts.services.TransferRequestBuilder;
import de.sovity.edc.ext.wrapper.api.ui.pages.contracts.services.utils.ContractAgreementUtils;
import de.sovity.edc.ext.wrapper.api.ui.pages.contracts.services.utils.ContractDefinitionUtils;
import de.sovity.edc.ext.wrapper.api.ui.pages.contracts.services.utils.ContractNegotiationUtils;
import de.sovity.edc.ext.wrapper.api.ui.pages.transferhistory.TransferHistoryPageApiService;
import de.sovity.edc.ext.wrapper.api.ui.pages.transferhistory.TransferHistoryPageAssetFetcherService;
Expand All @@ -41,6 +44,7 @@
import org.eclipse.edc.connector.policy.spi.store.PolicyDefinitionStore;
import org.eclipse.edc.connector.spi.asset.AssetService;
import org.eclipse.edc.connector.spi.contractagreement.ContractAgreementService;
import org.eclipse.edc.connector.spi.contractdefinition.ContractDefinitionService;
import org.eclipse.edc.connector.spi.contractnegotiation.ContractNegotiationService;
import org.eclipse.edc.connector.spi.transferprocess.TransferProcessService;
import org.eclipse.edc.connector.transfer.spi.store.TransferProcessStore;
Expand Down Expand Up @@ -75,7 +79,8 @@ public static WrapperExtensionContext buildContext(
PolicyDefinitionStore policyDefinitionStore,
PolicyEngine policyEngine,
TransferProcessStore transferProcessStore,
TransferProcessService transferProcessService
TransferProcessService transferProcessService,
ContractDefinitionService contractDefinitionService
) {
// UI API
var transferProcessStateService = new TransferProcessStateService();
Expand All @@ -92,6 +97,9 @@ public static WrapperExtensionContext buildContext(
contractAgreementDataFetcher,
contractAgreementPageCardBuilder
);
var contractDefinitionUtils = new ContractDefinitionUtils();
var contactDefinitionBuilder = new ContractDefinitionBuilder(contractDefinitionUtils);
var contractDefinitionApiService = new ContractDefinitionApiService(contractDefinitionService, contractDefinitionUtils, contactDefinitionBuilder);
var transferHistoryPageApiService = new TransferHistoryPageApiService(
assetService,
contractAgreementService,
Expand Down Expand Up @@ -121,7 +129,8 @@ public static WrapperExtensionContext buildContext(
contractAgreementTransferApiService,
transferHistoryPageApiService,
transferHistoryPageAssetFetcherService,
assetApiService
assetApiService,
contractDefinitionApiService
);

// Use Case API
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,14 @@
import de.sovity.edc.ext.wrapper.api.ui.model.AssetCreateRequest;
import de.sovity.edc.ext.wrapper.api.ui.model.ContractAgreementPage;
import de.sovity.edc.ext.wrapper.api.ui.model.ContractAgreementTransferRequest;
import de.sovity.edc.ext.wrapper.api.ui.model.ContractDefinitionPage;
import de.sovity.edc.ext.wrapper.api.ui.model.ContractDefinitionRequest;
import de.sovity.edc.ext.wrapper.api.ui.model.IdResponseDto;
import de.sovity.edc.ext.wrapper.api.ui.model.TransferHistoryPage;
import de.sovity.edc.ext.wrapper.api.ui.pages.asset.AssetApiService;
import de.sovity.edc.ext.wrapper.api.ui.pages.contracts.ContractAgreementPageApiService;
import de.sovity.edc.ext.wrapper.api.ui.pages.contracts.ContractAgreementTransferApiService;
import de.sovity.edc.ext.wrapper.api.ui.pages.contracts.ContractDefinitionApiService;
import de.sovity.edc.ext.wrapper.api.ui.pages.transferhistory.TransferHistoryPageApiService;
import de.sovity.edc.ext.wrapper.api.ui.pages.transferhistory.TransferHistoryPageAssetFetcherService;
import io.swagger.v3.oas.annotations.Operation;
Expand All @@ -49,6 +52,7 @@ public class UiResource {
private final TransferHistoryPageApiService transferHistoryPageApiService;
private final TransferHistoryPageAssetFetcherService transferHistoryPageAssetFetcherService;
private final AssetApiService assetApiService;
private final ContractDefinitionApiService contractDefinitionApiService;

@GET
@Path("pages/contract-agreement-page")
Expand Down Expand Up @@ -110,4 +114,27 @@ public IdResponseDto deleteAsset(@PathParam("assetId") String assetId) {
return assetApiService.deleteAsset(assetId);
}

@GET
@Path("pages/contract-definition-page")
@Produces(MediaType.APPLICATION_JSON)
public ContractDefinitionPage contractDefinitionPage() {
return new ContractDefinitionPage(contractDefinitionApiService.getContractDefinitions());
}

@POST
@Path("pages/contract-definition-page/contractDefinitions")
SaadEGI marked this conversation as resolved.
Show resolved Hide resolved
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@Operation(description = "Create a new Contract Definition")
public IdResponseDto createContractDefinition(ContractDefinitionRequest contractDefinitionRequest) {
return contractDefinitionApiService.createContractDefinition(contractDefinitionRequest);
}

@DELETE
@Path("pages/contract-definition-page/contractDefinitions/{contractDefinitionId}")
SaadEGI marked this conversation as resolved.
Show resolved Hide resolved
@Produces(MediaType.APPLICATION_JSON)
@Operation(description = "Delete a Contract Definition")
public IdResponseDto deleteContractDefinition(@PathParam("contractDefinitionId") String contractDefinitionId) {
return contractDefinitionApiService.deleteContractDefinition(contractDefinitionId);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* 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 io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

import java.util.List;

@Data
@Schema(description = "Contract Definition Entry for Contract Definition Page")
SaadEGI marked this conversation as resolved.
Show resolved Hide resolved
public class ContractDefinitionEntry {

@Schema(description = "Access Policy ID", requiredMode = Schema.RequiredMode.REQUIRED)
private String accessPolicyId;

@Schema(description = "Contract Policy ID", requiredMode = Schema.RequiredMode.REQUIRED)
private String contractPolicyId;

@Schema(description = "Criteria for the contract", requiredMode = Schema.RequiredMode.REQUIRED)
private List<CriterionDto> criteria;
SaadEGI marked this conversation as resolved.
Show resolved Hide resolved
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* 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 io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Data;

import java.util.List;

@Data
@AllArgsConstructor
@Schema(description = "All data for the Contract Definition Page")
public class ContractDefinitionPage {

@Schema(description = "Contract Definition Entries", requiredMode = Schema.RequiredMode.REQUIRED)
private List<ContractDefinitionEntry> contractDefinitions;
}
Loading
Loading