Codota Logo
ProductQueryModel
Code IndexAdd Codota to your IDE (free)

How to use
ProductQueryModel
in
io.sphere.sdk.products.queries

Best Java code snippets using io.sphere.sdk.products.queries.ProductQueryModel (Showing top 20 results out of 315)

  • Add the Codota plugin to your IDE and get smart completions
private void myMethod () {
List l =
  • Codota Iconnew LinkedList()
  • Codota IconCollections.emptyList()
  • Codota Iconnew ArrayList()
  • Smart code suggestions by Codota
}
origin: com.commercetools.sdk.jvm.core/commercetools-models

default ProductQuery byProductType(final Referenceable<ProductType> productType) {
  return withPredicates(m -> m.productType().is(productType));
}
origin: io.sphere.sdk.jvm/sphere-models

public static ProductQueryModel of() {
  return new ProductQueryModel(null, null);
}
origin: com.commercetools.sdk.jvm.core/commercetools-models

ProductQueryImpl(){
  super(ProductEndpoint.ENDPOINT.endpoint(), ProductQuery.resultTypeReference(), ProductQueryModel.of(), ProductExpansionModel.of(), ProductQueryImpl::new);
}
origin: io.sphere.sdk.jvm/sphere-models

  default ProductQuery bySku(final String sku, final ProductProjectionType type) {
    final QueryPredicate<PartialProductVariantQueryModel> skuPredicate = PartialProductVariantQueryModel.of().sku().is(sku);
    final ProductDataQueryModel<Product> projection = ProductQueryModel.of().masterData().forProjection(type);
    final QueryPredicate<Product> masterVariantSkuPredicate = projection.masterVariant().where(skuPredicate);
    final QueryPredicate<Product> variantsSkuPredicate = projection.variants().where(skuPredicate);
    return withPredicates(masterVariantSkuPredicate.or(variantsSkuPredicate));
  }
}
origin: com.commercetools.sdk.jvm.core/commercetools-models

default ProductQuery bySlug(final ProductProjectionType type, final Locale locale, final String slug) {
  return withPredicates(m -> m.masterData().forProjection(type).slug().lang(locale).is(slug));
}
origin: commercetools/commercetools-jvm-sdk

public static void deleteProductsProductTypeAndProductDiscounts(final BlockingSphereClient client, final ProductType productType) {
  client.executeBlocking(ProductDiscountQuery.of().withLimit(500L)).getResults()
      .forEach(discount -> client.executeBlocking(ProductDiscountDeleteCommand.of(discount)));
  if (productType != null) {
    QueryPredicate<Product> ofProductType = ProductQueryModel.of().productType().is(productType);
    ProductQuery productsOfProductTypeQuery = ProductQuery.of().withPredicates(ofProductType).withLimit(500L);
    do {
      final List<Product> products = client.executeBlocking(productsOfProductTypeQuery).getResults();
      final List<Product> unpublishedProducts = products.stream().map(
          product -> {
            if (product.getMasterData().isPublished()) {
              return client.executeBlocking(ProductUpdateCommand.of(product, Unpublish.of()));
            } else {
              return product;
            }
          }
      ).collect(toList());
      final List<CompletionStage<Product>> stages = new LinkedList<>();
      unpublishedProducts.forEach(
          product -> {
            final CompletionStage<Product> completionStage = client.execute(ProductDeleteCommand.of(product));
            stages.add(completionStage);
          }
      );
      stages.forEach(stage -> SphereClientUtils.blockingWait(stage, 30, TimeUnit.SECONDS));
      deleteProductType(client, productType);
    } while (client.executeBlocking(productsOfProductTypeQuery).getCount() > 0);
  }
}
origin: commercetools/commercetools-jvm-sdk

private void checkIsFoundByPublishedFlag(final Product product, final boolean value) {
  final Optional<Product> productFromQuery = client().executeBlocking(ProductQuery.of()
      .withPredicates(m -> {
        return m.masterData().isPublished().is(value);
      })
      .plusPredicates(m -> m.id().is(product.getId()))).head();
  assertThat(productFromQuery.get().getId()).isEqualTo(product.getId());
}
origin: commercetools/commercetools-jvm-sdk

@Test
public void queryByTiersWithMinimumQuantity() {
  withProduct(client(), product -> {
    final ProductQuery productQuery = ProductQuery.of()
        .withPredicates(m -> m.masterData().current().variants().prices().tiers().minimumQuantity().isGreaterThan(5))
        .plusPredicates(m -> m.is(product));
    final List<Product> results = client().executeBlocking(productQuery).getResults();
    assertThat(results).hasSize(0);
  });
}
origin: commercetools/commercetools-jvm-sdk

@Test
public void useIdPredicateInsteadOfOffset() throws Exception {
  final ProductQuery seedQuery = ProductQuery.of()
      //the original predicate, which queries products for a certain product type
      //the idea works also for no predicate to get all products
      .withPredicates(m -> m.productType().is(productType))
      //important, we sort by id, otherwise id > $lastId would not make sense
      .withSort(m -> m.id().sort().asc())
      .withLimit(PAGE_SIZE)
      .withFetchTotal(false);//saves also resources and time
  final CompletionStage<List<Product>> resultStage = findNext(seedQuery, seedQuery, new LinkedList<>());
  final List<Product> actualProducts = resultStage.toCompletableFuture().join();
  assertThat(actualProducts).hasSize(createdProducts.size());
  //!!! the underlying database has a different algorithm to sort by ID, it is a UUID, which differs from String sorting
  final List<Product> javaSortedActual = actualProducts.stream().sorted(BY_ID_COMPARATOR).collect(toList());
  assertThat(javaSortedActual).isEqualTo(createdProducts);
}
origin: io.sphere.sdk.jvm/models

public static ProductQueryModel model() {
  return ProductQueryModel.get();
}
origin: commercetools/commercetools-jvm-sdk

@Test
public void transitionState() {
  withStateByBuilder(client(), builder -> builder.type(PRODUCT_STATE), state -> {
    withUpdateableProduct(client(), product -> {
      assertThat(product.getState()).isNull();
      final Product updatedProduct = client().executeBlocking(ProductUpdateCommand.of(product, asList(TransitionState.of(state))));
      assertThat(updatedProduct.getState()).isEqualTo(state.toReference());
      assertEventually(() -> {
        final PagedQueryResult<ProductStateTransitionMessage> messageQueryResult =
            client().executeBlocking(MessageQuery.of()
                .withPredicates(m -> m.resource().is(product))
                .forMessageType(ProductStateTransitionMessage.MESSAGE_HINT));
        assertThat(messageQueryResult.getResults()).isNotEmpty();
        final ProductStateTransitionMessage message = messageQueryResult.head().get();
        assertThat(message.getState()).isEqualTo(state.toReference());
      });
      //check query model
      final ProductQuery query = ProductQuery.of()
          .withPredicates(m -> m.id().is(product.getId()).and(m.state().is(state)));
      final Product productByState = client().executeBlocking(query)
          .head().get();
      assertThat(productByState).isEqualTo(updatedProduct);
      return updatedProduct;
    });
  });
}
origin: commercetools/commercetools-jvm-sdk

  private ProductQuery query(final Product product) {
    return ProductQuery.of().withPredicates(m -> m.id().is(product.getId()));
  }
}
origin: commercetools/commercetools-jvm-sdk

  default ProductQuery bySku(final String sku, final ProductProjectionType type) {
    final QueryPredicate<EmbeddedProductVariantQueryModel> skuPredicate = EmbeddedProductVariantQueryModel.of().sku().is(sku);
    final ProductDataQueryModel<Product> projection = ProductQueryModel.of().masterData().forProjection(type);
    final QueryPredicate<Product> masterVariantSkuPredicate = projection.masterVariant().where(skuPredicate);
    final QueryPredicate<Product> variantsSkuPredicate = projection.variants().where(skuPredicate);
    return withPredicates(masterVariantSkuPredicate.or(variantsSkuPredicate));
  }
}
origin: io.sphere.sdk.jvm/sphere-models

default ProductQuery bySlug(final ProductProjectionType type, final Locale locale, final String slug) {
  return withPredicates(m -> m.masterData().forProjection(type).slug().lang(locale).is(slug));
}
origin: commercetools/commercetools-jvm-sdk

@Test
public void queryProductsWithAnyDiscount() throws Exception {
  withUpdateableProductDiscount(client(), (ProductDiscount productDiscount, Product product) -> {
    final ProductQuery query = ProductQuery.of()
        .withPredicates(m -> m.id().is(product.getId())
            .and(m.masterData().staged().masterVariant().prices().discounted().isPresent()));
    final Duration maxWaitTime = Duration.ofMinutes(2);
    final Duration waitBeforeRetry = Duration.ofMillis(500);
    assertEventually(maxWaitTime, waitBeforeRetry, () -> {
      final Optional<Product> loadedProduct = client().executeBlocking(query).head();
      assertThat(loadedProduct.isPresent()).isTrue();
      assertThat(loadedProduct.get().getId()).isEqualTo(product.getId());
    });
    return productDiscount;
  });
}
origin: commercetools/commercetools-jvm-sdk

@Test
public void queryByTiersWithValue() {
  withProduct(client(), product -> {
    final ProductQuery productQuery = ProductQuery.of()
        .withPredicates(m -> m.masterData().current().variants().prices().tiers().value().currencyCode().is("EUR"))
        .plusPredicates(m -> m.is(product));
    final List<Product> results = client().executeBlocking(productQuery).getResults();
    assertThat(results).hasSize(0);
  });
}
origin: io.sphere.sdk.jvm/products

public static ProductQueryModel model() {
  return ProductQueryModel.get();
}
origin: commercetools/commercetools-jvm-sdk

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);
    }
  });
}
origin: com.commercetools.sdk.jvm.core/commercetools-models

  default ProductQuery bySku(final String sku, final ProductProjectionType type) {
    final QueryPredicate<EmbeddedProductVariantQueryModel> skuPredicate = EmbeddedProductVariantQueryModel.of().sku().is(sku);
    final ProductDataQueryModel<Product> projection = ProductQueryModel.of().masterData().forProjection(type);
    final QueryPredicate<Product> masterVariantSkuPredicate = projection.masterVariant().where(skuPredicate);
    final QueryPredicate<Product> variantsSkuPredicate = projection.variants().where(skuPredicate);
    return withPredicates(masterVariantSkuPredicate.or(variantsSkuPredicate));
  }
}
origin: commercetools/commercetools-jvm-sdk

default ProductQuery bySlug(final ProductProjectionType type, final Locale locale, final String slug) {
  return withPredicates(m -> m.masterData().forProjection(type).slug().lang(locale).is(slug));
}
io.sphere.sdk.products.queriesProductQueryModel

Most used methods

  • masterData
  • productType
  • <init>
  • of
  • get
  • id
  • is
  • referenceModel
  • referenceOptionalModel
  • reviewRatingStatistics
  • state
  • state

Popular in Java

  • Reactive rest calls using spring rest template
  • getSupportFragmentManager (FragmentActivity)
  • scheduleAtFixedRate (Timer)
    Schedules the specified task for repeated fixed-rate execution, beginning after the specified delay.
  • getSharedPreferences (Context)
  • Rectangle (java.awt)
    A Rectangle specifies an area in a coordinate space that is enclosed by the Rectangle object's top-
  • Calendar (java.util)
    Calendar is an abstract base class for converting between a Date object and a set of integer fields
  • Enumeration (java.util)
    A legacy iteration interface.New code should use Iterator instead. Iterator replaces the enumeration
  • LinkedHashMap (java.util)
    Hash table and linked list implementation of the Map interface, with predictable iteration order. Th
  • Set (java.util)
    A collection that contains no duplicate elements. More formally, sets contain no pair of elements e1
  • Options (org.apache.commons.cli)
    Main entry-point into the library. Options represents a collection of Option objects, which describ
Codota Logo
  • Products

    Search for Java codeSearch for JavaScript codeEnterprise
  • IDE Plugins

    IntelliJ IDEAWebStormAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogCodota Academy Plugin user guide Terms of usePrivacy policyJava Code IndexJavascript Code Index
Get Codota for your IDE now