Search in sources :

Example 1 with Asset

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);
}
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 Asset

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");
}
Also used : Response(okhttp3.Response) ContractAgreementBuilder(de.fraunhofer.iais.eis.ContractAgreementBuilder) Request(okhttp3.Request) JsonAssertions(net.javacrumbs.jsonunit.assertj.JsonAssertions) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ComponentTest(org.eclipse.dataspaceconnector.common.annotations.ComponentTest) HashMap(java.util.HashMap) UUID(java.util.UUID) ContractRequestBuilder(de.fraunhofer.iais.eis.ContractRequestBuilder) StandardCharsets(java.nio.charset.StandardCharsets) Test(org.junit.jupiter.api.Test) CalendarUtil(org.eclipse.dataspaceconnector.ids.core.util.CalendarUtil) List(java.util.List) OkHttpClient(okhttp3.OkHttpClient) IdsType(org.eclipse.dataspaceconnector.ids.spi.IdsType) BeforeAll(org.junit.jupiter.api.BeforeAll) ContractOfferBuilder(de.fraunhofer.iais.eis.ContractOfferBuilder) Map(java.util.Map) Response(okhttp3.Response) PermissionBuilder(de.fraunhofer.iais.eis.PermissionBuilder) Asset(org.eclipse.dataspaceconnector.spi.types.domain.asset.Asset) IdsId(org.eclipse.dataspaceconnector.ids.spi.IdsId) URI(java.net.URI) TestUtils.testOkHttpClient(org.eclipse.dataspaceconnector.common.testfixtures.TestUtils.testOkHttpClient) Request(okhttp3.Request) Asset(org.eclipse.dataspaceconnector.spi.types.domain.asset.Asset) ComponentTest(org.eclipse.dataspaceconnector.common.annotations.ComponentTest) Test(org.junit.jupiter.api.Test)

Example 3 with Asset

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());
}
Also used : InMemoryNodeDirectory(org.eclipse.dataspaceconnector.catalog.directory.InMemoryNodeDirectory) Asset(org.eclipse.dataspaceconnector.spi.types.domain.asset.Asset)

Example 4 with Asset

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"));
}
Also used : Asset(org.eclipse.dataspaceconnector.spi.types.domain.asset.Asset) AssetDocument(org.eclipse.dataspaceconnector.assetindex.azure.model.AssetDocument) AssetSelectorExpression(org.eclipse.dataspaceconnector.spi.asset.AssetSelectorExpression) AzureCosmosDbIntegrationTest(org.eclipse.dataspaceconnector.azure.testfixtures.annotations.AzureCosmosDbIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 5 with Asset

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");
}
Also used : Asset(org.eclipse.dataspaceconnector.spi.types.domain.asset.Asset) AssetDocument(org.eclipse.dataspaceconnector.assetindex.azure.model.AssetDocument) AzureCosmosDbIntegrationTest(org.eclipse.dataspaceconnector.azure.testfixtures.annotations.AzureCosmosDbIntegrationTest) Test(org.junit.jupiter.api.Test)

Aggregations

Asset (org.eclipse.dataspaceconnector.spi.types.domain.asset.Asset)36 Test (org.junit.jupiter.api.Test)24 AssetDocument (org.eclipse.dataspaceconnector.assetindex.azure.model.AssetDocument)16 AzureCosmosDbIntegrationTest (org.eclipse.dataspaceconnector.azure.testfixtures.annotations.AzureCosmosDbIntegrationTest)9 URI (java.net.URI)8 List (java.util.List)8 IdsId (org.eclipse.dataspaceconnector.ids.spi.IdsId)7 DataAddress (org.eclipse.dataspaceconnector.spi.types.domain.DataAddress)7 HashMap (java.util.HashMap)6 UUID (java.util.UUID)6 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)6 BeforeAll (org.junit.jupiter.api.BeforeAll)6 AssetSelectorExpression (org.eclipse.dataspaceconnector.spi.asset.AssetSelectorExpression)5 SqlQuerySpec (com.azure.cosmos.models.SqlQuerySpec)4 ContractAgreementBuilder (de.fraunhofer.iais.eis.ContractAgreementBuilder)4 ContractOfferBuilder (de.fraunhofer.iais.eis.ContractOfferBuilder)4 ContractRequestBuilder (de.fraunhofer.iais.eis.ContractRequestBuilder)4 PermissionBuilder (de.fraunhofer.iais.eis.PermissionBuilder)4 StandardCharsets (java.nio.charset.StandardCharsets)4 Map (java.util.Map)4