Search in sources :

Example 1 with Criterion

use of org.eclipse.dataspaceconnector.spi.query.Criterion 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 Criterion

use of org.eclipse.dataspaceconnector.spi.query.Criterion in project DataSpaceConnector by eclipse-dataspaceconnector.

the class SqlAssetIndexTest method queryAsset_querySpec_nonExistProperty.

@Test
@DisplayName("Query assets with query spec where the property (=leftOperand) does not exist")
void queryAsset_querySpec_nonExistProperty() {
    var asset = getAsset("id1");
    sqlAssetIndex.accept(asset, getDataAddress());
    var qs = QuerySpec.Builder.newInstance().filter(List.of(new Criterion("noexist", "=", "42"))).build();
    assertThat(sqlAssetIndex.queryAssets(qs)).isEmpty();
}
Also used : Criterion(org.eclipse.dataspaceconnector.spi.query.Criterion) ComponentTest(org.eclipse.dataspaceconnector.common.annotations.ComponentTest) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 3 with Criterion

use of org.eclipse.dataspaceconnector.spi.query.Criterion in project DataSpaceConnector by eclipse-dataspaceconnector.

the class SqlConditionExpressionTest method toValuePlaceholder.

@Test
void toValuePlaceholder() {
    var e = new SqlConditionExpression(new Criterion("key", "=", "value"));
    assertThat(e.toValuePlaceholder()).isEqualTo("?");
    var e2 = new SqlConditionExpression(new Criterion("key", "in", List.of("item1", "item2")));
    assertThat(e2.toValuePlaceholder()).matches("\\(\\?,.*\\?\\)");
}
Also used : Criterion(org.eclipse.dataspaceconnector.spi.query.Criterion) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 4 with Criterion

use of org.eclipse.dataspaceconnector.spi.query.Criterion in project DataSpaceConnector by eclipse-dataspaceconnector.

the class SqlConditionExpressionTest method isValidExpression_whenValid.

@ParameterizedTest
@MethodSource("validArgs")
void isValidExpression_whenValid(String left, String op, Object right) {
    var e = new SqlConditionExpression(new Criterion(left, op, right));
    assertThat(e.isValidExpression().succeeded()).isTrue();
}
Also used : Criterion(org.eclipse.dataspaceconnector.spi.query.Criterion) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 5 with Criterion

use of org.eclipse.dataspaceconnector.spi.query.Criterion in project DataSpaceConnector by eclipse-dataspaceconnector.

the class CosmosContractDefinitionStoreIntegrationTest method update.

@Test
void update() {
    var doc1 = generateDocument(TEST_PARTITION_KEY);
    container.createItem(doc1);
    var definition = doc1.getWrappedInstance();
    // modify the object
    definition.getSelectorExpression().getCriteria().add(new Criterion("anotherKey", "NOT EQUAL", "anotherVal"));
    store.update(definition);
    var updatedDefinition = convert(container.readItem(doc1.getId(), new PartitionKey(doc1.getPartitionKey()), Object.class).getItem());
    assertThat(updatedDefinition.getId()).isEqualTo(definition.getId());
    assertThat(updatedDefinition.getSelectorExpression().getCriteria()).hasSize(2).anySatisfy(criterion -> {
        assertThat(criterion.getOperandLeft()).isNotEqualTo("anotherKey");
        assertThat(criterion.getOperator()).isNotEqualTo("NOT EQUAL");
        assertThat(criterion.getOperandLeft()).isNotEqualTo("anotherValue");
    });
// we modified that earlier
}
Also used : Criterion(org.eclipse.dataspaceconnector.spi.query.Criterion) PartitionKey(com.azure.cosmos.models.PartitionKey) AzureCosmosDbIntegrationTest(org.eclipse.dataspaceconnector.azure.testfixtures.annotations.AzureCosmosDbIntegrationTest) Test(org.junit.jupiter.api.Test)

Aggregations

Criterion (org.eclipse.dataspaceconnector.spi.query.Criterion)26 Test (org.junit.jupiter.api.Test)20 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)5 PartitionKey (com.azure.cosmos.models.PartitionKey)2 List (java.util.List)2 AzureCosmosDbIntegrationTest (org.eclipse.dataspaceconnector.azure.testfixtures.annotations.AzureCosmosDbIntegrationTest)2 ComponentTest (org.eclipse.dataspaceconnector.common.annotations.ComponentTest)2 OfferedAsset (org.eclipse.dataspaceconnector.ids.spi.types.container.OfferedAsset)2 ContractOfferQuery (org.eclipse.dataspaceconnector.spi.contract.offer.ContractOfferQuery)2 Asset (org.eclipse.dataspaceconnector.spi.types.domain.asset.Asset)2 ContractOffer (org.eclipse.dataspaceconnector.spi.types.domain.contract.offer.ContractOffer)2 DisplayName (org.junit.jupiter.api.DisplayName)2 MethodSource (org.junit.jupiter.params.provider.MethodSource)2 SqlParameter (com.azure.cosmos.models.SqlParameter)1 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 TypeReference (com.fasterxml.jackson.core.type.TypeReference)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 String.format (java.lang.String.format)1 Collections (java.util.Collections)1 Collectors (java.util.stream.Collectors)1