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