Search in sources :

Example 1 with OfferedAsset

use of org.eclipse.dataspaceconnector.ids.spi.types.container.OfferedAsset 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 OfferedAsset

use of org.eclipse.dataspaceconnector.ids.spi.types.container.OfferedAsset in project DataSpaceConnector by eclipse-dataspaceconnector.

the class CatalogToIdsResourceCatalogTransformer method transform.

@Override
@Nullable
public ResourceCatalog transform(Catalog object, @NotNull TransformerContext context) {
    Objects.requireNonNull(context);
    if (object == null) {
        return null;
    }
    ResourceCatalogBuilder builder;
    String catalogId = object.getId();
    if (catalogId != null) {
        URI catalogIdUri = URI.create(String.join(IdsIdParser.DELIMITER, IdsIdParser.SCHEME, IdsType.CATALOG.getValue(), catalogId));
        builder = new ResourceCatalogBuilder(catalogIdUri);
    } else {
        builder = new ResourceCatalogBuilder();
    }
    List<Resource> resources = new LinkedList<>();
    List<ContractOffer> contractOffers = object.getContractOffers();
    List<Asset> distinctAssets = contractOffers.stream().map(ContractOffer::getAsset).distinct().collect(Collectors.toList());
    for (Asset distinctAsset : distinctAssets) {
        List<ContractOffer> targetingOffers = contractOffers.stream().filter(c -> c.getAsset().getId().equals(distinctAsset.getId())).collect(Collectors.toList());
        OfferedAsset assetAndContractOffers = new OfferedAsset(distinctAsset, targetingOffers);
        Resource resource = context.transform(assetAndContractOffers, Resource.class);
        if (resource != null) {
            resources.add(resource);
        }
    }
    builder._offeredResource_(new ArrayList<>(resources));
    return builder.build();
}
Also used : Resource(de.fraunhofer.iais.eis.Resource) ContractOffer(org.eclipse.dataspaceconnector.spi.types.domain.contract.offer.ContractOffer) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) Objects(java.util.Objects) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) ResourceCatalogBuilder(de.fraunhofer.iais.eis.ResourceCatalogBuilder) IdsType(org.eclipse.dataspaceconnector.ids.spi.IdsType) OfferedAsset(org.eclipse.dataspaceconnector.ids.spi.types.container.OfferedAsset) TransformerContext(org.eclipse.dataspaceconnector.spi.transformer.TransformerContext) IdsIdParser(org.eclipse.dataspaceconnector.ids.spi.IdsIdParser) Asset(org.eclipse.dataspaceconnector.spi.types.domain.asset.Asset) URI(java.net.URI) NotNull(org.jetbrains.annotations.NotNull) LinkedList(java.util.LinkedList) ResourceCatalog(de.fraunhofer.iais.eis.ResourceCatalog) IdsTypeTransformer(org.eclipse.dataspaceconnector.ids.spi.transform.IdsTypeTransformer) Catalog(org.eclipse.dataspaceconnector.spi.types.domain.catalog.Catalog) ContractOffer(org.eclipse.dataspaceconnector.spi.types.domain.contract.offer.ContractOffer) Resource(de.fraunhofer.iais.eis.Resource) OfferedAsset(org.eclipse.dataspaceconnector.ids.spi.types.container.OfferedAsset) URI(java.net.URI) LinkedList(java.util.LinkedList) ResourceCatalogBuilder(de.fraunhofer.iais.eis.ResourceCatalogBuilder) OfferedAsset(org.eclipse.dataspaceconnector.ids.spi.types.container.OfferedAsset) Asset(org.eclipse.dataspaceconnector.spi.types.domain.asset.Asset) Nullable(org.jetbrains.annotations.Nullable)

Example 3 with OfferedAsset

use of org.eclipse.dataspaceconnector.ids.spi.types.container.OfferedAsset 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)

Aggregations

OfferedAsset (org.eclipse.dataspaceconnector.ids.spi.types.container.OfferedAsset)3 Asset (org.eclipse.dataspaceconnector.spi.types.domain.asset.Asset)3 ContractOffer (org.eclipse.dataspaceconnector.spi.types.domain.contract.offer.ContractOffer)3 ContractOfferQuery (org.eclipse.dataspaceconnector.spi.contract.offer.ContractOfferQuery)2 Criterion (org.eclipse.dataspaceconnector.spi.query.Criterion)2 Resource (de.fraunhofer.iais.eis.Resource)1 ResourceCatalog (de.fraunhofer.iais.eis.ResourceCatalog)1 ResourceCatalogBuilder (de.fraunhofer.iais.eis.ResourceCatalogBuilder)1 URI (java.net.URI)1 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Objects (java.util.Objects)1 Collectors (java.util.stream.Collectors)1 IdsIdParser (org.eclipse.dataspaceconnector.ids.spi.IdsIdParser)1 IdsType (org.eclipse.dataspaceconnector.ids.spi.IdsType)1 IdsTypeTransformer (org.eclipse.dataspaceconnector.ids.spi.transform.IdsTypeTransformer)1 TransformerContext (org.eclipse.dataspaceconnector.spi.transformer.TransformerContext)1 Catalog (org.eclipse.dataspaceconnector.spi.types.domain.catalog.Catalog)1 NotNull (org.jetbrains.annotations.NotNull)1