Search in sources :

Example 6 with RSQLFilterDialect

use of com.yahoo.elide.core.filter.dialect.RSQLFilterDialect in project elide by yahoo.

the class VerboseErrorResponsesTestBinder method configure.

@Override
protected void configure() {
    EntityDictionary dictionary = EntityDictionary.builder().injector(injector::inject).checks(TestCheckMappings.MAPPINGS).build();
    bind(dictionary).to(EntityDictionary.class);
    // Elide instance
    bindFactory(new Factory<Elide>() {

        @Override
        public Elide provide() {
            DefaultFilterDialect defaultFilterStrategy = new DefaultFilterDialect(dictionary);
            RSQLFilterDialect rsqlFilterStrategy = RSQLFilterDialect.builder().dictionary(dictionary).build();
            MultipleFilterDialect multipleFilterStrategy = new MultipleFilterDialect(Arrays.asList(rsqlFilterStrategy, defaultFilterStrategy), Arrays.asList(rsqlFilterStrategy, defaultFilterStrategy));
            Elide elide = new Elide(new ElideSettingsBuilder(getDataStore()).withAuditLogger(auditLogger).withJoinFilterDialect(multipleFilterStrategy).withSubqueryFilterDialect(multipleFilterStrategy).withEntityDictionary(dictionary).withVerboseErrors().build());
            elide.doScans();
            return elide;
        }

        @Override
        public void dispose(Elide elide) {
        // do nothing
        }
    }).to(Elide.class).named("elide");
    bind(new BillingService() {

        @Override
        public long purchase(Invoice invoice) {
            return 0;
        }
    }).to(BillingService.class);
}
Also used : ElideSettingsBuilder(com.yahoo.elide.ElideSettingsBuilder) Invoice(example.models.triggers.Invoice) MultipleFilterDialect(com.yahoo.elide.core.filter.dialect.jsonapi.MultipleFilterDialect) DefaultFilterDialect(com.yahoo.elide.core.filter.dialect.jsonapi.DefaultFilterDialect) Elide(com.yahoo.elide.Elide) EntityDictionary(com.yahoo.elide.core.dictionary.EntityDictionary) RSQLFilterDialect(com.yahoo.elide.core.filter.dialect.RSQLFilterDialect) BillingService(example.models.triggers.services.BillingService)

Example 7 with RSQLFilterDialect

use of com.yahoo.elide.core.filter.dialect.RSQLFilterDialect in project elide by yahoo.

the class JpaDataStoreTransactionTest method getTestArguments.

private Stream<Arguments> getTestArguments() throws Exception {
    RSQLFilterDialect parser = RSQLFilterDialect.builder().dictionary(dictionary).build();
    FilterExpression expression = parser.parse(ClassType.of(Book.class), Collections.emptySet(), "title=='foo'", NO_VERSION);
    return Stream.of(arguments(true, 1, null, true), arguments(true, 2, null, true), arguments(false, 1, null, true), arguments(false, 2, null, true), arguments(true, 1, expression, false), arguments(true, 2, expression, true), arguments(false, 1, expression, false), arguments(false, 2, expression, false));
}
Also used : Book(example.Book) FilterExpression(com.yahoo.elide.core.filter.expression.FilterExpression) RSQLFilterDialect(com.yahoo.elide.core.filter.dialect.RSQLFilterDialect)

Example 8 with RSQLFilterDialect

use of com.yahoo.elide.core.filter.dialect.RSQLFilterDialect in project faf-java-api by FAForever.

the class ElideConfig method elide.

@Bean
public Elide elide(SpringHibernateDataStore springHibernateDataStore, ObjectMapper objectMapper, EntityDictionary entityDictionary, ExtendedAuditLogger extendedAuditLogger) {
    RSQLFilterDialect rsqlFilterDialect = new RSQLFilterDialect(entityDictionary);
    registerAdditionalConverters();
    return new Elide(new ElideSettingsBuilder(springHibernateDataStore).withJsonApiMapper(new JsonApiMapper(entityDictionary, objectMapper)).withAuditLogger(extendedAuditLogger).withEntityDictionary(entityDictionary).withJoinFilterDialect(rsqlFilterDialect).withSubqueryFilterDialect(rsqlFilterDialect).build());
}
Also used : ElideSettingsBuilder(com.yahoo.elide.ElideSettingsBuilder) JsonApiMapper(com.yahoo.elide.jsonapi.JsonApiMapper) Elide(com.yahoo.elide.Elide) RSQLFilterDialect(com.yahoo.elide.core.filter.dialect.RSQLFilterDialect) Bean(org.springframework.context.annotation.Bean)

Example 9 with RSQLFilterDialect

use of com.yahoo.elide.core.filter.dialect.RSQLFilterDialect in project elide by yahoo.

the class FilteredIteratorTest method testEmptyResult.

@Test
public void testEmptyResult() throws Exception {
    EntityDictionary dictionary = EntityDictionary.builder().build();
    dictionary.bindEntity(Book.class);
    List<Book> books = List.of();
    RSQLFilterDialect filterDialect = RSQLFilterDialect.builder().dictionary(dictionary).build();
    FilterExpression expression = filterDialect.parse(ClassType.of(Book.class), new HashSet<>(), "title==*bar", NO_VERSION);
    RequestScope scope = new TestRequestScope(null, null, dictionary);
    Iterator<Book> bookIterator = new FilteredIterator<>(expression, scope, books.iterator());
    assertFalse(bookIterator.hasNext());
    assertThrows(NoSuchElementException.class, () -> bookIterator.next());
}
Also used : TestRequestScope(com.yahoo.elide.core.TestRequestScope) Book(example.Book) FilterExpression(com.yahoo.elide.core.filter.expression.FilterExpression) EntityDictionary(com.yahoo.elide.core.dictionary.EntityDictionary) RSQLFilterDialect(com.yahoo.elide.core.filter.dialect.RSQLFilterDialect) RequestScope(com.yahoo.elide.core.RequestScope) TestRequestScope(com.yahoo.elide.core.TestRequestScope) Test(org.junit.jupiter.api.Test)

Example 10 with RSQLFilterDialect

use of com.yahoo.elide.core.filter.dialect.RSQLFilterDialect in project elide by yahoo.

the class RequiresFilter method getRequiredFilter.

default FilterExpression getRequiredFilter(EntityDictionary dictionary) {
    Type<?> cls = dictionary.getEntityClass(getTable().getName(), getTable().getVersion());
    RSQLFilterDialect filterDialect = RSQLFilterDialect.builder().dictionary(dictionary).addDefaultArguments(false).build();
    if (StringUtils.isNotEmpty(getRequiredFilter())) {
        try {
            return filterDialect.parseFilterExpression(getRequiredFilter(), cls, false, true);
        } catch (ParseException e) {
            throw new IllegalStateException(e);
        }
    }
    return null;
}
Also used : ParseException(com.yahoo.elide.core.filter.dialect.ParseException) RSQLFilterDialect(com.yahoo.elide.core.filter.dialect.RSQLFilterDialect)

Aggregations

RSQLFilterDialect (com.yahoo.elide.core.filter.dialect.RSQLFilterDialect)19 FilterExpression (com.yahoo.elide.core.filter.expression.FilterExpression)12 Test (org.junit.jupiter.api.Test)12 Book (example.Book)10 PersistentResource (com.yahoo.elide.core.PersistentResource)7 AndFilterExpression (com.yahoo.elide.core.filter.expression.AndFilterExpression)7 NotFilterExpression (com.yahoo.elide.core.filter.expression.NotFilterExpression)7 OrFilterExpression (com.yahoo.elide.core.filter.expression.OrFilterExpression)7 PermissionExecutor (com.yahoo.elide.core.security.PermissionExecutor)7 EntityDictionary (com.yahoo.elide.core.dictionary.EntityDictionary)6 Elide (com.yahoo.elide.Elide)5 ElideSettingsBuilder (com.yahoo.elide.ElideSettingsBuilder)5 DataStoreTransaction (com.yahoo.elide.core.datastore.DataStoreTransaction)5 SQLUnitTest (com.yahoo.elide.datastores.aggregation.framework.SQLUnitTest)3 Query (com.yahoo.elide.datastores.aggregation.query.Query)3 Author (example.Author)3 RequestScope (com.yahoo.elide.core.RequestScope)2 TestRequestScope (com.yahoo.elide.core.TestRequestScope)2 DefaultFilterDialect (com.yahoo.elide.core.filter.dialect.jsonapi.DefaultFilterDialect)2 MultipleFilterDialect (com.yahoo.elide.core.filter.dialect.jsonapi.MultipleFilterDialect)2