Skip to content

Commit

Permalink
Contract Definition Page Api Service implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
SaadEGI committed Jul 26, 2023
1 parent 0823a59 commit f65a7dd
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.eclipse.edc.connector.contract.spi.offer.store.ContractDefinitionStore;
import org.eclipse.edc.connector.policy.spi.store.PolicyDefinitionStore;
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 @@ -81,7 +84,8 @@ public void initialize(ServiceExtensionContext context) {
policyDefinitionStore,
policyEngine,
transferProcessService,
transferProcessStore
transferProcessStore,
(org.eclipse.edc.connector.contract.spi.offer.ContractDefinitionService) contractDefinitionService
);

wrapperExtensionContext.jaxRsResources().forEach(resource ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
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;
Expand Down Expand Up @@ -86,6 +87,7 @@ public static WrapperExtensionContext buildContext(
contractAgreementPageCardBuilder
);
var transferHistoryPageApiService = new TransferHistoryPageApiService();
var contractDefinitionApiService = new ContractDefinitionApiService();
var transformerRegistryUtils = new TransformerRegistryUtils(dtoTransformerRegistry);
var contractNegotiationUtils = new ContractNegotiationUtils(contractNegotiationService);
var contractAgreementUtils = new ContractAgreementUtils(contractAgreementService);
Expand All @@ -103,7 +105,8 @@ public static WrapperExtensionContext buildContext(
var uiResource = new UiResource(
contractAgreementApiService,
transferHistoryPageApiService,
contractAgreementTransferApiService
contractAgreementTransferApiService,
contractDefinitionApiService
);

// Use Case API
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@

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 io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
Expand All @@ -38,7 +40,7 @@ public class UiResource {
private final ContractAgreementPageApiService contractAgreementApiService;
private final TransferHistoryPageApiService transferHistoryPageApiService;
private final ContractAgreementTransferApiService contractAgreementTransferApiService;

private final ContractDefinitionApiService contractDefinitionApiService;
@GET
@Path("pages/contract-agreement-page")
@Produces(MediaType.APPLICATION_JSON)
Expand Down Expand Up @@ -66,4 +68,11 @@ public IdResponseDto initiateTransfer(
public TransferHistoryPage transferHistoryPageEndpoint() {
return transferHistoryPageApiService.transferHistoryPage();
}

@GET
@Path("pages/contract-definition-page")
@Produces(MediaType.APPLICATION_JSON)
public ContractDefinitionPage contractDefinitionPageEndpoint() {
return new ContractDefinitionPage(contractDefinitionApiService.getContractDefinitions());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class ContractDefinitionEntry {
private List<Criterion> criteria;

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


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
* 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.pages.contracts;

import de.sovity.edc.ext.wrapper.api.ui.model.ContractDefinitionEntry;
import de.sovity.edc.ext.wrapper.api.ui.pages.contracts.services.ContractAgreementData;
import lombok.RequiredArgsConstructor;
import org.eclipse.edc.connector.contract.spi.negotiation.store.ContractNegotiationStore;
import org.eclipse.edc.connector.contract.spi.types.agreement.ContractAgreement;
import org.eclipse.edc.connector.contract.spi.types.negotiation.ContractNegotiation;
import org.eclipse.edc.connector.contract.spi.types.offer.ContractDefinition;
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.spi.query.QuerySpec;
import org.eclipse.edc.spi.types.domain.asset.Asset;
import org.jetbrains.annotations.NotNull;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import static java.util.stream.Collectors.groupingBy;
import static java.util.stream.Collectors.toList;


@RequiredArgsConstructor
public class ContractDefinitionApiService {


private final ContractDefinitionService contractDefinitionService;
public List<ContractDefinitionEntry> getContractDefinitions() {
// Obtain all contract definitions
var definitions = getAllContractDefinitons();
return definitions.stream()
.map(definition -> {
var entry = new ContractDefinitionEntry();
entry.setContractDefinitionId(definition.getId());
entry.setAccessPolicyId(definition.getAccessPolicyId());
entry.setContractPolicyId(definition.getContractPolicyId());
entry.setCriteria(definition.getSelectorExpression().getCriteria()); // This depends on how the criteria are stored in your system
return entry;
})
.collect(Collectors.toList());
}
private List<ContractDefinition> getAllContractDefinitons() {
return contractDefinitionService.query(QuerySpec.max()).getContent().toList();
}

}

0 comments on commit f65a7dd

Please sign in to comment.