@Override public String toSphereQuery() { return leftPredicate.toSphereQuery() + " " + connectorWord + " " + rightPredicate.toSphereQuery(); } }
public QueryDsl<Product> bySku(final String sku, final ProductProjectionType type) { final Predicate<PartialProductVariantQueryModel> skuPredicate = ProductVariantQueryModel.get().sku().is(sku); final ProductDataQueryModel<Product> projection = model().masterData().forProjection(type); final Predicate<Product> masterVariantSkuPredicate = projection.masterVariant().where(skuPredicate); final Predicate<Product> variantsSkuPredicate = projection.variants().where(skuPredicate); return withPredicate(masterVariantSkuPredicate.or(variantsSkuPredicate)); } }
/** * Predicate which matches the country and state of a location. * * For ignoring the state use {@link #byCountry(com.neovisionaries.i18n.CountryCode)}. * @param location the location to query for * @return query with the same values but a predicate searching for a specific location */ public QueryDsl<Zone> byLocation(final Location location) { final Predicate<Zone> predicate = location.getState() .map(state -> model().locations().where(l -> l.country().is(location.getCountry()).and(l.state().is(state)))) .orElseGet(() -> model().locations().where(l -> l.country().is(location.getCountry()).and(l.state().isNotPresent()))); return withPredicate(predicate); } }
public QueryDsl<Product> bySku(final String sku, final ProductProjectionType type) { final Predicate<PartialProductVariantQueryModel> skuPredicate = ProductVariantQueryModel.get().sku().is(sku); final ProductDataQueryModel<Product> projection = model().masterData().forProjection(type); final Predicate<Product> masterVariantSkuPredicate = projection.masterVariant().where(skuPredicate); final Predicate<Product> variantsSkuPredicate = projection.variants().where(skuPredicate); return withPredicate(masterVariantSkuPredicate.or(variantsSkuPredicate)); } }
@Override protected String render() { return "(" + predicate.toSphereQuery() + ")"; } }
@SuppressWarnings("rawtypes") @Override public final boolean equals(final Object o) { return o != null && (o instanceof Predicate) && toSphereQuery().equals(((Predicate)o).toSphereQuery()); }
private String queryParametersToString(final boolean urlEncoded) { final UrlQueryBuilder builder = UrlQueryBuilder.of(); predicate().ifPresent(predicate -> builder.add(WHERE, predicate.toSphereQuery(), urlEncoded)); sort().forEach(sort -> builder.add(SORT, sort.toSphereSort(), urlEncoded)); limit().ifPresent(limit -> builder.add(LIMIT, limit.toString(), urlEncoded)); offset().ifPresent(offset -> builder.add(OFFSET, offset.toString(), urlEncoded)); expansionPaths().forEach(path -> builder.add(EXPAND, path.toSphereExpand(), urlEncoded)); additionalQueryParameters().forEach(parameter -> builder.add(parameter.getKey(), parameter.getValue(), urlEncoded)); return "?" + builder.toString(); }