use of org.eclipse.dataspaceconnector.spi.types.domain.asset.Asset 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.spi.types.domain.asset.Asset in project DataSpaceConnector by eclipse-dataspaceconnector.
the class MultipartControllerIntegrationTest method testRequestResource.
@Test
void testRequestResource() throws Exception {
// prepare
String assetId = UUID.randomUUID().toString();
Asset asset = Asset.Builder.newInstance().id(assetId).property("ids:fileName", "test.txt").property("ids:byteSize", 10).property("ids:fileExtension", "txt").build();
addAsset(asset);
Request request = createRequest(getDescriptionRequestMessage(IdsId.Builder.newInstance().value(assetId).type(IdsType.RESOURCE).build()));
// invoke
Response response = httpClient.newCall(request).execute();
// verify
assertThat(response).isNotNull().extracting(Response::code).isEqualTo(200);
List<NamedMultipartContent> content = extractNamedMultipartContent(response);
assertThat(content).hasSize(2).extracting(NamedMultipartContent::getName).containsExactly("header", "payload");
var header = content.stream().filter(n -> "header".equalsIgnoreCase(n.getName())).map(NamedMultipartContent::getContent).findFirst().orElseThrow();
var jsonHeader = JsonAssertions.assertThatJson(new String(header, StandardCharsets.UTF_8));
jsonHeader.inPath("$.@type").isString().isEqualTo("ids:DescriptionResponseMessage");
jsonHeader.inPath("$.@id").isString().matches("urn:message:.*");
jsonHeader.inPath("$.ids:modelVersion").isString().isEqualTo("4.2.7");
jsonHeader.inPath("$.ids:contentVersion").isString().isEqualTo("4.2.7");
// jsonHeader.inPath("$.ids:issued").isString().matches("^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}.[0-9]{3}UTC$");
jsonHeader.inPath("$.ids:issuerConnector").isString().isEqualTo("urn:connector:" + CONNECTOR_ID);
jsonHeader.inPath("$.ids:senderAgent").isString().isEqualTo("urn:connector:" + CONNECTOR_ID);
var payload = content.stream().filter(n -> "payload".equalsIgnoreCase(n.getName())).map(NamedMultipartContent::getContent).findFirst().orElseThrow();
var jsonPayload = JsonAssertions.assertThatJson(new String(payload, StandardCharsets.UTF_8));
jsonPayload.inPath("$.@type").isString().isEqualTo("ids:Resource");
jsonPayload.inPath("$.@id").isString().matches("urn:resource:" + assetId);
jsonPayload.inPath("$.ids:contractOffer[0].@type").isString().isEqualTo("ids:ContractOffer");
jsonPayload.inPath("$.ids:contractOffer[0].@id").isString().matches("urn:contractoffer:.*");
jsonPayload.inPath("$.ids:contractOffer[0].ids:permission[0].@type").isString().isEqualTo("ids:Permission");
jsonPayload.inPath("$.ids:contractOffer[0].ids:permission[0].@id").isString().matches("urn:permission:.*");
jsonPayload.inPath("$.ids:contractOffer[0].ids:permission[0].ids:action[0].@id").isString().matches("https://w3id.org/idsa/code/USE");
jsonPayload.inPath("$.ids:representation[0].@type").isString().isEqualTo("ids:Representation");
jsonPayload.inPath("$.ids:representation[0].@id").isString().matches("urn:representation:" + assetId);
jsonPayload.inPath("$.ids:representation[0].ids:instance[0].@type").isString().isEqualTo("ids:Artifact");
jsonPayload.inPath("$.ids:representation[0].ids:instance[0].@id").isString().matches("urn:artifact:" + assetId);
jsonPayload.inPath("$.ids:representation[0].ids:instance[0].ids:fileName").isString().isEqualTo("test.txt");
jsonPayload.inPath("$.ids:representation[0].ids:mediaType.@type").isString().isEqualTo("ids:CustomMediaType");
jsonPayload.inPath("$.ids:representation[0].ids:mediaType.ids:filenameExtension").isString().matches("txt");
}
use of org.eclipse.dataspaceconnector.spi.types.domain.asset.Asset in project DataSpaceConnector by eclipse-dataspaceconnector.
the class FccTestExtension method initialize.
@Override
public void initialize(ServiceExtensionContext context) {
List<Asset> assets = Collections.emptyList();
context.registerService(TransferProcessStore.class, new FakeTransferProcessStore());
context.registerService(RemoteMessageDispatcherRegistry.class, new FakeRemoteMessageDispatcherRegistry());
context.registerService(AssetIndex.class, new FakeAssetIndex(assets));
context.registerService(ContractOfferService.class, new FakeContractOfferService(assets));
context.registerService(ContractDefinitionStore.class, new FakeContractDefinitionStore());
context.registerService(FederatedCacheNodeDirectory.class, new InMemoryNodeDirectory());
}
use of org.eclipse.dataspaceconnector.spi.types.domain.asset.Asset in project DataSpaceConnector by eclipse-dataspaceconnector.
the class CosmosAssetIndexIntegrationTest method queryAssets_filterOnProperty.
@Test
void queryAssets_filterOnProperty() {
Asset asset1 = createAsset("123", "test", "world");
Asset asset2 = createAsset("456", "test", "bar");
container.createItem(new AssetDocument(asset1, TEST_PARTITION_KEY, dataAddress));
container.createItem(new AssetDocument(asset2, TEST_PARTITION_KEY, dataAddress));
AssetSelectorExpression expression = AssetSelectorExpression.Builder.newInstance().whenEquals(Asset.PROPERTY_ID, "456").build();
List<Asset> assets = assetIndex.queryAssets(expression).collect(Collectors.toList());
assertThat(assets).hasSize(1).allSatisfy(asset -> assertThat(asset.getId()).isEqualTo("456"));
}
use of org.eclipse.dataspaceconnector.spi.types.domain.asset.Asset in project DataSpaceConnector by eclipse-dataspaceconnector.
the class CosmosAssetIndexIntegrationTest method queryAssets_operatorIn_syntaxError_throwsException.
@Test
void queryAssets_operatorIn_syntaxError_throwsException() {
Asset asset1 = createAsset("123", "hello", "world");
Asset asset2 = createAsset("456", "foo", "bar");
container.createItem(new AssetDocument(asset1, TEST_PARTITION_KEY, dataAddress));
container.createItem(new AssetDocument(asset2, TEST_PARTITION_KEY, dataAddress));
var inExpr = format("('%s' ; '%s')", asset1.getId(), asset2.getId());
var selector = AssetSelectorExpression.Builder.newInstance().constraint(Asset.PROPERTY_ID, "IN foobar", List.of(asset1.getId(), asset2.getId())).build();
// collecting is necessary, otherwise the cosmos query is not executed
assertThatThrownBy(() -> assetIndex.queryAssets(selector).collect(Collectors.toList())).isInstanceOf(IllegalArgumentException.class).hasMessage("Cannot build WHERE clause, reason: unsupported operator IN foobar");
}
Aggregations