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

461 add contract definition page to the api wrapper #462

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
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);
}


}
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);


}


}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,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 @@ -63,6 +64,8 @@ public class WrapperExtension implements ServiceExtension {
private TypeManager typeManager;
@Inject
private WebService webService;
@Inject
private ContractDefinitionService contractDefinitionService;

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

wrapperExtensionContext.jaxRsResources().forEach(resource ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@
import de.sovity.edc.ext.wrapper.api.ui.UiResource;
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.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.contracts.services.utils.TransformerRegistryUtils;
import de.sovity.edc.ext.wrapper.api.ui.pages.transferhistory.TransferHistoryPageApiService;
Expand All @@ -40,6 +42,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 @@ -73,8 +76,8 @@ public static WrapperExtensionContext buildContext(
PolicyDefinitionStore policyDefinitionStore,
PolicyEngine policyEngine,
TransferProcessService transferProcessService,
TransferProcessStore transferProcessStore
) {
TransferProcessStore transferProcessStore,
ContractDefinitionService contractDefinitionService) {
// UI API
var transferProcessStateService = new TransferProcessStateService();
var contractAgreementPageCardBuilder = new ContractAgreementPageCardBuilder(
Expand All @@ -91,6 +94,8 @@ public static WrapperExtensionContext buildContext(
var transferHistoryPageApiService = new TransferHistoryPageApiService(assetService, contractAgreementService, contractNegotiationStore,
transferProcessService, transferProcessStateService);
var transferHistoryPageAssetFetcherService = new TransferHistoryPageAssetFetcherService(assetService, transferProcessService);
var contractDefinitionUtils = new ContractDefinitionUtils();
var contractDefinitionApiService = new ContractDefinitionApiService(contractDefinitionService,contractDefinitionUtils);
var transformerRegistryUtils = new TransformerRegistryUtils(dtoTransformerRegistry);
var contractNegotiationUtils = new ContractNegotiationUtils(contractNegotiationService);
var contractAgreementUtils = new ContractAgreementUtils(contractAgreementService);
Expand All @@ -108,8 +113,10 @@ public static WrapperExtensionContext buildContext(
var uiResource = new UiResource(
contractAgreementApiService,
contractAgreementTransferApiService,
contractDefinitionApiService,
transferHistoryPageApiService,
transferHistoryPageAssetFetcherService

);

// Use Case API
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@
import de.sovity.edc.ext.wrapper.api.common.model.AssetDto;
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.TransferHistoryPage;
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 @@ -36,6 +38,7 @@ public class UiResource {

private final ContractAgreementPageApiService contractAgreementApiService;
private final ContractAgreementTransferApiService contractAgreementTransferApiService;
private final ContractDefinitionApiService contractDefinitionApiService;
private final TransferHistoryPageApiService transferHistoryPageApiService;
private final TransferHistoryPageAssetFetcherService transferHistoryPageAssetFetcherService;

Expand Down Expand Up @@ -73,4 +76,11 @@ public TransferHistoryPage transferHistoryPageEndpoint() {
public AssetDto getTransferProcessAsset(@PathParam("transferProcessId") String transferProcessId) {
return transferHistoryPageAssetFetcherService.getAssetForTransferHistoryPage(transferProcessId);
}

@GET
@Path("pages/contract-definition-page")
@Produces(MediaType.APPLICATION_JSON)
public ContractDefinitionPage contractDefinitionPage() {
return new ContractDefinitionPage(contractDefinitionApiService.getContractDefinitions());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* 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")
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;

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


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* 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
public class ContractDefinitionPage {
@Schema(description = "Contract Definition Entries", requiredMode = Schema.RequiredMode.REQUIRED)
private List<ContractDefinitionEntry> contractDefinitions;
}
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
}
Loading
Loading