public StringQuerySortingModel<Channel> key() { return new StringQuerySortingModel<>(Optional.of(this), "key"); } }
/** * Escapes Strings like that (Scala notation) """query by name " test name""" * @param s the unescaped String * @return the escaped string */ private static String escape(final String s) { return StringQuerySortingModel.escape(s); }
public final Predicate<T> isIn(final Iterable<? extends Referenceable<R>> references) { final List<String> ids = toStream(references).map(r -> r.toReference().getId()).collect(toList()); return new StringQuerySortingModel<>(Optional.of(this), "id").isOneOf(ids); }
default CustomerQuery byEmail(final String email) { return withPredicates(m -> m.lowercaseEmail().is(email.toLowerCase())); } }
@Test public void queryById() throws Exception { with2products("queryById", (p1, p2) -> { final Query<ProductProjection> query1 = ProductProjectionQuery.of(STAGED).withPredicates(m -> m.id().isIn(asList(p1.getId(), p2.getId()))); assertThat(ids(client().executeBlocking(query1))).containsOnly(p1.getId(), p2.getId()); final Query<ProductProjection> query = ProductProjectionQuery.of(STAGED).withPredicates(m -> m.id().is(p1.getId())); assertThat(ids(client().executeBlocking(query))).containsOnly(p1.getId()); }); }
@Test public void isGreaterThanOrEqualTo() throws Exception { assertThat(model.isGreaterThanOrEqualTo("x").toSphereQuery()).isEqualTo("id>=\"x\""); }
@Test public void isGreaterThan() throws Exception { assertThat(model.isGreaterThan("x").toSphereQuery()).isEqualTo("id>\"x\""); }
default TaxCategoryQuery byKey(final String key) { return withPredicates(m -> m.key().is(key)); } }
@Test public void isGreaterThanOrEqualToComparisonPredicate() throws Exception { final QueryPredicate<Category> predicate = CategoryQueryModel.of().name().lang(Locale.ENGLISH).isGreaterThanOrEqualTo("x10"); final Consumer<List<Category>> assertions = categories -> { final List<String> names = categories.stream().map(c -> c.getName().get(Locale.ENGLISH)).collect(toList()); assertThat(names).contains("x2", "x10"); assertThat(names.contains("x1")).isFalse(); }; predicateTestCase(predicate, assertions); }
private CompletionStage<List<Product>> findNext(final ProductQuery seedQuery, final ProductQuery query, final List<Product> products) { final CompletionStage<PagedQueryResult<Product>> pageResult = sphereClient().execute(query); return pageResult.thenCompose(page -> { final List<Product> results = page.getResults(); products.addAll(results); final boolean isLastQueryPage = results.size() < PAGE_SIZE; if (isLastQueryPage) { return CompletableFuture.completedFuture(products); } else { final String lastId = getIdForNextQuery(page); return findNext(seedQuery, seedQuery .plusPredicates(m -> m.id().isGreaterThan(lastId)), products); } }); }
default ChannelQuery byKey(final String key) { return withPredicates(m -> m.key().is(key)); } }
public StringQuerySortingModel<Category> externalId() { return new StringQuerySortingModel<>(Optional.of(this), "externalId"); } }
/** * Internal method to normalize Strings for queries. * @param s the unescaped String * @return the escaped String */ static String normalize(final String s) { return '"' + escape(s) + '"'; } }
@Override public QueryPredicate<ProductProjection> is(final Referenceable<Product> product) { return id().is(product.toReference().getId()); } }
public StringQuerySortingModel<CustomerGroup> name() { return new StringQuerySortingModel<>(Optional.of(this), "name"); } }
@Override public Predicate<T> is(final String s) { return EqPredicate.of(this, escape(s)); }
@Override public QueryPredicate<ProductProjection> is(final Referenceable<Product> product) { return id().is(product.toReference().getId()); } }
public StringQuerySortingModel<Product> id() { return new StringQuerySortingModel<>(Optional.of(this), "id"); } }
@Override public Predicate<T> isNot(final String s) { return NotEqPredicate.of(this, escape(s)); }
default ShippingMethodQuery byKey(final String key) { return withPredicates(ShippingMethodQueryModel.of().key().is(key)); } }