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

Migrating transfer history page to api wrapper #421

Merged
merged 33 commits into from
Jul 25, 2023
Merged
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
6805dd0
feat: Updating the data fetcher of new TransferHistoryEntry Model (WIP)
AnurosePrakash Jul 3, 2023
b8a0446
chore: added the TransferHistoryPageApiService
AnurosePrakash Jul 4, 2023
37d180b
chore: building tests for new transfer history page api wrapper
AnurosePrakash Jul 5, 2023
e380f07
chore: building tests for new transfer history page api wrapper (WIP)
AnurosePrakash Jul 7, 2023
9208e11
chore: tests updated for new transfer history page api wrapper
AnurosePrakash Jul 10, 2023
2e7a76b
Merge branch 'main' into Migrating_transfer_history_page_to_API_wrapper
AnurosePrakash Jul 10, 2023
aed81ee
chore: implemented GetTransferProcessAssetApiServiceTest
AnurosePrakash Jul 11, 2023
702d012
chore: reformatting - removing unwanted blank lines
AnurosePrakash Jul 11, 2023
7fdd65f
chore: prepare release (#414)
richardtreier Jul 7, 2023
33c26c9
build(deps): bump io.swagger.core.v3:swagger-annotations-jakarta (#417)
dependabot[bot] Jul 10, 2023
afe9e32
build(deps): bump io.swagger.core.v3:swagger-jaxrs2-jakarta (#416)
dependabot[bot] Jul 10, 2023
85ee014
build(deps): bump gradle/gradle-build-action from 2.5.1 to 2.6.0 (#419)
dependabot[bot] Jul 11, 2023
6dc65df
Merge remote-tracking branch 'origin/main'
AnurosePrakash Jul 11, 2023
f94a84d
Merge branch 'main' into Migrating_transfer_history_page_to_API_wrapper
AnurosePrakash Jul 11, 2023
1018a85
chore: reformatting - refactoring method calls
AnurosePrakash Jul 12, 2023
2f3544b
Merge remote-tracking branch 'origin/Migrating_transfer_history_page_…
AnurosePrakash Jul 12, 2023
56b53f7
chore: reformatting - minor refactoring in function calls
AnurosePrakash Jul 12, 2023
64cde01
chore: reformatting - minor refactoring with variable namings
AnurosePrakash Jul 12, 2023
d3e0da7
Update README.md (#424)
SebastianOpriel Jul 14, 2023
97e76a9
Merge remote-tracking branch 'origin/main'
AnurosePrakash Jul 18, 2023
36eab98
Merge branch 'main' into Migrating_transfer_history_page_to_API_wrapper
AnurosePrakash Jul 18, 2023
2b20022
Merge remote-tracking branch 'origin/main'
AnurosePrakash Jul 19, 2023
a6620ec
chore: reformatting - minor refactoring with removing blank lines
AnurosePrakash Jul 19, 2023
2e68336
Merge remote-tracking branch 'origin/Migrating_transfer_history_page_…
AnurosePrakash Jul 19, 2023
6472648
Update TransferHistoryPageApiService.java
AnurosePrakash Jul 19, 2023
6a20b89
chore: minor refactorings - removing blank lines
AnurosePrakash Jul 20, 2023
45ac335
Merge remote-tracking branch 'origin/Migrating_transfer_history_page_…
AnurosePrakash Jul 20, 2023
291af0d
Merge remote-tracking branch 'origin/main'
AnurosePrakash Jul 24, 2023
1652ef1
Merge branch 'main' into Migrating_transfer_history_page_to_API_wrapper
AnurosePrakash Jul 24, 2023
cb41ff0
chore: fix checkstyle warning
AnurosePrakash Jul 24, 2023
ecf2c7d
Merge branch 'main' into Migrating_transfer_history_page_to_API_wrapper
AnurosePrakash Jul 25, 2023
a509111
chore: fix reformatting errors
AnurosePrakash Jul 25, 2023
d690a31
chore: updated the tests
AnurosePrakash Jul 25, 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*
* 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.contract.spi.negotiation.store.ContractNegotiationStore;
import org.eclipse.edc.connector.spi.asset.AssetService;
import org.eclipse.edc.connector.transfer.spi.store.TransferProcessStore;
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 java.text.ParseException;
import java.util.Map;

import static de.sovity.edc.client.TransferProcessTestUtils.*;
AnurosePrakash marked this conversation as resolved.
Show resolved Hide resolved
import static org.assertj.core.api.Assertions.assertThat;

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

@BeforeEach
void setUp(EdcExtension extension) {
extension.setConfiguration(TestUtils.createConfiguration(Map.of()));
}

@Test
void testProviderTransferProcess(ContractNegotiationStore negotiationStore,
TransferProcessStore transferProcessStore,
AssetService assetStore) throws ParseException {

var client = TestUtils.edcClient();

//arrange data
createProvidingTransferProcesses(negotiationStore, transferProcessStore, assetStore);

//act
var providerAssetResult = client.uiApi().getTransferProcessAsset(PROVIDING_TRANSFER_PROCESS_ID);

AnurosePrakash marked this conversation as resolved.
Show resolved Hide resolved
//assert
assertThat(providerAssetResult.getAssetId()).isEqualTo(VALID_ASSET_ID);
assertThat(providerAssetResult.getProperties().get("asset:prop:name")).isEqualTo(ASSET_NAME);
}

@Test
void testConsumerTransferProcess(ContractNegotiationStore negotiationStore,
TransferProcessStore transferProcessStore) throws ParseException {

var client = TestUtils.edcClient();

//arrange data
createConsumingTransferProcesses(negotiationStore, transferProcessStore);

//act
var consumerAssetResult = client.uiApi().getTransferProcessAsset(CONSUMING_TRANSFER_PROCESS_ID);

//assert
assertThat(consumerAssetResult.getAssetId()).isEqualTo(UNKNOWN_ASSET_ID);
assertThat(consumerAssetResult.getProperties().get("asset:prop:name")).isNull();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/*
* 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.contract.spi.negotiation.store.ContractNegotiationStore;
import org.eclipse.edc.connector.spi.asset.AssetService;
import org.eclipse.edc.connector.transfer.spi.store.TransferProcessStore;
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 java.text.ParseException;
import java.util.Map;

import static de.sovity.edc.client.TransferProcessTestUtils.*;
import static de.sovity.edc.client.gen.model.TransferHistoryEntry.DirectionEnum.CONSUMING;
import static de.sovity.edc.client.gen.model.TransferHistoryEntry.DirectionEnum.PROVIDING;
import static org.assertj.core.api.Assertions.assertThat;

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

@BeforeEach
void setUp(EdcExtension extension) {
extension.setConfiguration(TestUtils.createConfiguration(Map.of()));
}

@Test
void startTransferProcessForAgreement(
ContractNegotiationStore negotiationStore,
TransferProcessStore transferProcessStore,
AssetService assetStore
) throws ParseException {
var client = TestUtils.edcClient();

// arrange
createProvidingTransferProcesses(negotiationStore, transferProcessStore, assetStore);
createConsumingTransferProcesses(negotiationStore, transferProcessStore);

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

// get
var transferProcess = result.getTransferEntries();

// assert for the order of entries
assertThat(transferProcess.get(1).getTransferProcessId()).isEqualTo(TransferProcessTestUtils.PROVIDING_TRANSFER_PROCESS_ID);

// assert for consuming request entry
assertThat(transferProcess.get(0).getTransferProcessId()).isEqualTo(TransferProcessTestUtils.CONSUMING_TRANSFER_PROCESS_ID);
AnurosePrakash marked this conversation as resolved.
Show resolved Hide resolved
assertThat(transferProcess.get(0).getAssetId()).isEqualTo(UNKNOWN_ASSET_ID);
assertThat(transferProcess.get(0).getCounterPartyConnectorEndpoint()).isEqualTo(COUNTER_PARTY_ADDRESS);
assertThat(transferProcess.get(0).getContractAgreementId()).isEqualTo(CONSUMING_CONTRACT_ID);
assertThat(transferProcess.get(0).getDirection()).isEqualTo(CONSUMING);
assertThat(transferProcess.get(0).getState().getCode()).isEqualTo(800);
assertThat(transferProcess.get(0).getAssetName()).isEqualTo(UNKNOWN_ASSET_ID);
assertThat(transferProcess.get(0).getErrorMessage()).isEqualTo("");

// assert for providing request entry
assertThat(transferProcess.get(1).getTransferProcessId()).isEqualTo(TransferProcessTestUtils.PROVIDING_TRANSFER_PROCESS_ID);
assertThat(transferProcess.get(1).getAssetId()).isEqualTo(VALID_ASSET_ID);
assertThat(transferProcess.get(1).getCounterPartyConnectorEndpoint()).isEqualTo(COUNTER_PARTY_ADDRESS);
assertThat(transferProcess.get(1).getContractAgreementId()).isEqualTo(PROVIDING_CONTRACT_ID);
assertThat(transferProcess.get(1).getDirection()).isEqualTo(PROVIDING);
assertThat(transferProcess.get(1).getState().getCode()).isEqualTo(800);
assertThat(transferProcess.get(1).getAssetName()).isEqualTo(ASSET_NAME);
assertThat(transferProcess.get(1).getErrorMessage()).isEqualTo("TransferProcessManager: attempt #8 failed to send transfer");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
package de.sovity.edc.client;

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.spi.asset.AssetService;
import org.eclipse.edc.connector.transfer.spi.store.TransferProcessStore;
import org.eclipse.edc.connector.transfer.spi.types.DataRequest;
import org.eclipse.edc.connector.transfer.spi.types.TransferProcess;
import org.eclipse.edc.policy.model.Policy;
import org.eclipse.edc.spi.types.domain.DataAddress;
import org.eclipse.edc.spi.types.domain.asset.Asset;
import org.jetbrains.annotations.NotNull;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Locale;
import java.util.UUID;

public class TransferProcessTestUtils {
public static final String DATA_SINK = "http://my-data-sink/api/stuff";
public static final String COUNTER_PARTY_ADDRESS = "http://some-other-connector/api/v1/ids/data";
public static final String PROVIDING_CONTRACT_ID = "provider-contract:eb934d1f-6582-4bab-85e6-af19a76f7e2b";
public static final String CONSUMING_CONTRACT_ID = "consumer-contract:f52a5d30-6356-4a55-a75a-3c45d7a88c3e";
public static final String VALID_ASSET_ID = "urn:artifact:asset";
public static final String UNKNOWN_ASSET_ID = "urn:junk";
public static final String ASSET_NAME = "Test asset";
public static final String PROVIDING_TRANSFER_PROCESS_ID = "81cdf4cf-8427-480f-9662-8a29d66ddd3b";
AnurosePrakash marked this conversation as resolved.
Show resolved Hide resolved
public static final String CONSUMING_TRANSFER_PROCESS_ID = "be0cac12-bb43-420e-aa29-d66bb3d0e0ac";

@NotNull
public static void createProvidingTransferProcesses(ContractNegotiationStore store, TransferProcessStore transferProcessStore, AssetService assetStore) throws ParseException {
DataAddress dataAddress = getDataAddress();
createAsset(assetStore, dataAddress, VALID_ASSET_ID, ASSET_NAME);

// preparing providing transfer process
var providerAgreement = createContractAgreement(PROVIDING_CONTRACT_ID, VALID_ASSET_ID);
createContractNegotiation(store, COUNTER_PARTY_ADDRESS, providerAgreement, ContractNegotiation.Type.PROVIDER);
var lastUpdateDateForProvidingTransferProcess = "2023-07-08";
var errorMessageForProvidingTransferProcess = "TransferProcessManager: attempt #8 failed to send transfer";
createTransferProcess(VALID_ASSET_ID,
PROVIDING_CONTRACT_ID,
dataAddress,
TransferProcess.Type.PROVIDER,
PROVIDING_TRANSFER_PROCESS_ID,
lastUpdateDateForProvidingTransferProcess,
errorMessageForProvidingTransferProcess,
transferProcessStore);

}

@NotNull
public static void createConsumingTransferProcesses(ContractNegotiationStore store, TransferProcessStore transferProcessStore) throws ParseException {
DataAddress dataAddress = getDataAddress();

// preparing consuming transfer process
var consumerAgreement = createContractAgreement(CONSUMING_CONTRACT_ID, UNKNOWN_ASSET_ID);
createContractNegotiation(store, COUNTER_PARTY_ADDRESS, consumerAgreement, ContractNegotiation.Type.CONSUMER);
var lastUpdateDateForConsumingTransferProcess = "2023-07-10";
var errorMessageForConsumingTransferProcess = "";
createTransferProcess(UNKNOWN_ASSET_ID,
CONSUMING_CONTRACT_ID,
dataAddress,
TransferProcess.Type.CONSUMER,
CONSUMING_TRANSFER_PROCESS_ID,
lastUpdateDateForConsumingTransferProcess,
errorMessageForConsumingTransferProcess,
transferProcessStore);
}

AnurosePrakash marked this conversation as resolved.
Show resolved Hide resolved
private static DataAddress getDataAddress() {
var dataAddress = DataAddress.Builder.newInstance()
.type("HttpData")
.property("baseUrl", DATA_SINK)
.build();
return dataAddress;
}

private static void createAsset(AssetService assetStore, DataAddress dataAddress, String assetId, String assetName) throws ParseException {
var asset = Asset.Builder.newInstance()
.id(assetId)
.property("asset:prop:name", assetName)
.createdAt(dateFormatterToLong("2023-06-01"))
.build();
assetStore.create(asset, dataAddress);

}

private static ContractAgreement createContractAgreement(
String agreementId,
String assetId
) {
var agreement = ContractAgreement.Builder.newInstance()
.id(agreementId)
.providerAgentId(UUID.randomUUID().toString())
.consumerAgentId(UUID.randomUUID().toString())
.assetId(assetId)
.policy(Policy.Builder.newInstance().build())
.build();

return agreement;
}

private static void createContractNegotiation(
ContractNegotiationStore store,
String counterPartyAddress,
ContractAgreement agreement,
ContractNegotiation.Type type
) {
var negotiation = ContractNegotiation.Builder.newInstance()
.id(UUID.randomUUID().toString())
.counterPartyId(UUID.randomUUID().toString())
.counterPartyAddress(counterPartyAddress)
.protocol("protocol")
.contractAgreement(agreement)
.type(type)
.correlationId(UUID.randomUUID().toString())
.build();

store.save(negotiation);
}

private static void createTransferProcess(String assetId, String contractId, DataAddress dataAddress, TransferProcess.Type type, String transferProcessId, String lastUpdateDateForTransferProcess, String errorMessage, TransferProcessStore transferProcessStore) throws ParseException {


var dataRequestForTransfer = DataRequest.Builder.newInstance()
.assetId(assetId)
.contractId(contractId)
.dataDestination(dataAddress)
.build();

var transferProcess = TransferProcess.Builder.newInstance()
.id(transferProcessId)
.type(type)
.dataRequest(dataRequestForTransfer)
.createdAt(dateFormatterToLong("2023-07-08"))
.updatedAt(dateFormatterToLong(lastUpdateDateForTransferProcess))
.state(800)
.errorDetail(errorMessage)
.build();

transferProcessStore.save(transferProcess);
}

private static long dateFormatterToLong(String date) throws ParseException {
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
return formatter.parse(date).getTime();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.eclipse.edc.connector.contract.spi.negotiation.store.ContractNegotiationStore;
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.asset.AssetService;
import org.eclipse.edc.connector.spi.contractagreement.ContractAgreementService;
import org.eclipse.edc.connector.spi.contractnegotiation.ContractNegotiationService;
import org.eclipse.edc.connector.spi.transferprocess.TransferProcessService;
Expand All @@ -37,6 +38,8 @@ public class WrapperExtension implements ServiceExtension {
@Inject
private AssetIndex assetIndex;
@Inject
private AssetService assetService;
@Inject
private ContractAgreementService contractAgreementService;
@Inject
private ContractDefinitionStore contractDefinitionStore;
Expand Down Expand Up @@ -72,6 +75,7 @@ public void initialize(ServiceExtensionContext context) {

var wrapperExtensionContext = WrapperExtensionContextBuilder.buildContext(
assetIndex,
assetService,
contractAgreementService,
contractDefinitionStore,
contractNegotiationService,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
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;
import de.sovity.edc.ext.wrapper.api.ui.pages.transferhistory.TransferHistoryPageAssetFetcherService;
import de.sovity.edc.ext.wrapper.api.usecase.UseCaseResource;
import de.sovity.edc.ext.wrapper.api.usecase.services.KpiApiService;
import de.sovity.edc.ext.wrapper.api.usecase.services.OfferingService;
Expand All @@ -36,14 +37,14 @@
import org.eclipse.edc.connector.contract.spi.negotiation.store.ContractNegotiationStore;
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.asset.AssetService;
import org.eclipse.edc.connector.spi.contractagreement.ContractAgreementService;
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;
import org.eclipse.edc.policy.engine.spi.PolicyEngine;
import org.eclipse.edc.runtime.metamodel.annotation.Inject;
import org.eclipse.edc.spi.asset.AssetIndex;

import java.util.List;


Expand All @@ -60,6 +61,7 @@ public class WrapperExtensionContextBuilder {

public static WrapperExtensionContext buildContext(
AssetIndex assetIndex,
AssetService assetService,
ContractAgreementService contractAgreementService,
ContractDefinitionStore contractDefinitionStore,
ContractNegotiationService contractNegotiationService,
Expand All @@ -84,7 +86,9 @@ public static WrapperExtensionContext buildContext(
contractAgreementDataFetcher,
contractAgreementPageCardBuilder
);
var transferHistoryPageApiService = new TransferHistoryPageApiService();
var transferHistoryPageApiService = new TransferHistoryPageApiService(assetService, contractAgreementService, contractNegotiationStore,
transferProcessService, transferProcessStateService);
var transferHistoryPageAssetFetcherService = new TransferHistoryPageAssetFetcherService(assetService, transferProcessService);
var transformerRegistryUtils = new TransformerRegistryUtils(dtoTransformerRegistry);
var contractNegotiationUtils = new ContractNegotiationUtils(contractNegotiationService);
var contractAgreementUtils = new ContractAgreementUtils(contractAgreementService);
Expand All @@ -101,8 +105,9 @@ public static WrapperExtensionContext buildContext(
);
var uiResource = new UiResource(
contractAgreementApiService,
contractAgreementTransferApiService,
transferHistoryPageApiService,
contractAgreementTransferApiService
transferHistoryPageAssetFetcherService
);

// Use Case API
Expand Down
Loading
Loading