Search in sources :

Example 1 with ContractOfferQuery

use of org.eclipse.dataspaceconnector.spi.contract.offer.ContractOfferQuery in project DataSpaceConnector by eclipse-dataspaceconnector.

the class ResourceDescriptionRequestHandler method retrieveObject.

protected OfferedAsset retrieveObject(@NotNull IdsId idsId, @NotNull Result<ClaimToken> verificationResult) {
    String assetId = idsId.getValue();
    Asset asset = assetIndex.findById(assetId);
    if (asset == null) {
        return null;
    }
    ContractOfferQuery contractOfferQuery = ContractOfferQuery.Builder.newInstance().claimToken(verificationResult.getContent()).criterion(new Criterion(Asset.PROPERTY_ID, "=", assetId)).build();
    List<ContractOffer> targetingContractOffers = contractOfferService.queryContractOffers(contractOfferQuery).collect(toList());
    return new OfferedAsset(asset, targetingContractOffers);
}
Also used : ContractOfferQuery(org.eclipse.dataspaceconnector.spi.contract.offer.ContractOfferQuery) Criterion(org.eclipse.dataspaceconnector.spi.query.Criterion) ContractOffer(org.eclipse.dataspaceconnector.spi.types.domain.contract.offer.ContractOffer) OfferedAsset(org.eclipse.dataspaceconnector.ids.spi.types.container.OfferedAsset) Asset(org.eclipse.dataspaceconnector.spi.types.domain.asset.Asset) OfferedAsset(org.eclipse.dataspaceconnector.ids.spi.types.container.OfferedAsset)

Example 2 with ContractOfferQuery

use of org.eclipse.dataspaceconnector.spi.contract.offer.ContractOfferQuery in project DataSpaceConnector by eclipse-dataspaceconnector.

the class ResourceDescriptionRequestHandler method retrieveObject.

@Override
protected OfferedAsset retrieveObject(@NotNull IdsId idsId, @NotNull ClaimToken claimToken) {
    String assetId = idsId.getValue();
    Asset asset = assetIndex.findById(assetId);
    if (asset == null) {
        return null;
    }
    ContractOfferQuery contractOfferQuery = ContractOfferQuery.Builder.newInstance().claimToken(claimToken).criterion(new Criterion(Asset.PROPERTY_ID, "=", assetId)).build();
    List<ContractOffer> targetingContractOffers = contractOfferService.queryContractOffers(contractOfferQuery).collect(toList());
    return new OfferedAsset(asset, targetingContractOffers);
}
Also used : ContractOfferQuery(org.eclipse.dataspaceconnector.spi.contract.offer.ContractOfferQuery) Criterion(org.eclipse.dataspaceconnector.spi.query.Criterion) ContractOffer(org.eclipse.dataspaceconnector.spi.types.domain.contract.offer.ContractOffer) OfferedAsset(org.eclipse.dataspaceconnector.ids.spi.types.container.OfferedAsset) Asset(org.eclipse.dataspaceconnector.spi.types.domain.asset.Asset) OfferedAsset(org.eclipse.dataspaceconnector.ids.spi.types.container.OfferedAsset)

Example 3 with ContractOfferQuery

use of org.eclipse.dataspaceconnector.spi.contract.offer.ContractOfferQuery in project DataSpaceConnector by eclipse-dataspaceconnector.

the class ContractOfferServiceImplTest method testFullFlow.

@Test
void testFullFlow() {
    var contractDefinition = ContractDefinition.Builder.newInstance().id("1").accessPolicy(Policy.Builder.newInstance().build()).contractPolicy(Policy.Builder.newInstance().build()).selectorExpression(AssetSelectorExpression.SELECT_ALL).build();
    when(agentService.createFor(isA(ClaimToken.class))).thenReturn(new ParticipantAgent(emptyMap(), emptyMap()));
    when(contractDefinitionService.definitionsFor(isA(ParticipantAgent.class))).thenReturn(Stream.of(contractDefinition));
    var assetStream = Stream.of(Asset.Builder.newInstance().build(), Asset.Builder.newInstance().build());
    when(assetIndex.queryAssets(isA(AssetSelectorExpression.class))).thenReturn(assetStream);
    ContractOfferQuery query = ContractOfferQuery.builder().claimToken(ClaimToken.Builder.newInstance().build()).build();
    assertThat(contractOfferService.queryContractOffers(query)).hasSize(2);
    verify(agentService).createFor(isA(ClaimToken.class));
    verify(contractDefinitionService).definitionsFor(isA(ParticipantAgent.class));
    verify(assetIndex).queryAssets(isA(AssetSelectorExpression.class));
}
Also used : ContractOfferQuery(org.eclipse.dataspaceconnector.spi.contract.offer.ContractOfferQuery) ClaimToken(org.eclipse.dataspaceconnector.spi.iam.ClaimToken) ParticipantAgent(org.eclipse.dataspaceconnector.spi.contract.agent.ParticipantAgent) AssetSelectorExpression(org.eclipse.dataspaceconnector.spi.asset.AssetSelectorExpression) Test(org.junit.jupiter.api.Test)

Aggregations

ContractOfferQuery (org.eclipse.dataspaceconnector.spi.contract.offer.ContractOfferQuery)3 OfferedAsset (org.eclipse.dataspaceconnector.ids.spi.types.container.OfferedAsset)2 Criterion (org.eclipse.dataspaceconnector.spi.query.Criterion)2 Asset (org.eclipse.dataspaceconnector.spi.types.domain.asset.Asset)2 ContractOffer (org.eclipse.dataspaceconnector.spi.types.domain.contract.offer.ContractOffer)2 AssetSelectorExpression (org.eclipse.dataspaceconnector.spi.asset.AssetSelectorExpression)1 ParticipantAgent (org.eclipse.dataspaceconnector.spi.contract.agent.ParticipantAgent)1 ClaimToken (org.eclipse.dataspaceconnector.spi.iam.ClaimToken)1 Test (org.junit.jupiter.api.Test)1