public ProductDraftBuilder categories(final List<Reference<Category>> categories) { return categories(new LinkedHashSet<>(categories)); }
public ProductDraftBuilder categories(final List<Reference<Category>> categories) { return categories(new LinkedHashSet<>(categories)); }
/** * Adds categories to this product draft. Alias for {@link #categories(List)} which takes the category objects as parameter. * * @param categories categories which the product belongs to * @return this builder */ public ProductDraftBuilder categoriesAsObjectList(final List<Category> categories) { final List<Reference<Category>> referenceList = categories.stream() .filter(Objects::nonNull) .map(Category::toReference) .collect(Collectors.toList()); return categories(referenceList); }
/** * Adds categories to this product draft. Alias for {@link #categories(List)} which takes the category objects as parameter. * * @param categories categories which the product belongs to * @return this builder */ public ProductDraftBuilder categoriesAsObjectList(final List<Category> categories) { final List<Reference<Category>> referenceList = categories.stream() .filter(Objects::nonNull) .map(Category::toReference) .collect(Collectors.toList()); return categories(referenceList); }
public ProductDraftDsl withCategories(final Set<ResourceIdentifier<Category>> categories) { return newBuilder().categories(categories).build(); }
private void withProductInCategories(final BlockingSphereClient client, final List<String> ids, final Consumer<Product> consumer) { final List<Reference<Category>> categories = ids.stream() .map(id -> Category.referenceOfId(id)) .collect(Collectors.toList()); ProductFixtures.withProduct(client, builder -> builder.categories(categories), consumer); }
.metaDescription(metaDescription) .metaKeywords(metaKeywords) .categories(categories) .taxCategory(taxCategory) .searchKeywords(searchKeywords)
private static void withProductInCategory(final BlockingSphereClient client, final Referenceable<Category> category, final Consumer<Product> user) { final ProductType productType = client.executeBlocking(ProductTypeCreateCommand.of(ProductTypeDraft.of(randomKey(), CategoryDocumentationIntegrationTest.class.getSimpleName(), "", asList()))); final LocalizedString name = LocalizedString.of(ENGLISH, "foo"); final Product product = client.executeBlocking(ProductCreateCommand.of(ProductDraftBuilder.of(productType, name, name.slugifiedUnique(), ProductVariantDraftBuilder.of().build()).categories(asSet(category.toReference())).build())); user.accept(product); client.executeBlocking(ProductDeleteCommand.of(product)); client.executeBlocking(ProductTypeDeleteCommand.of(productType)); }
final ProductDraft productDraft = ProductDraftBuilder.of(productType, randomSlug(), randomSlug(), masterVariantDraft) .categoryOrderHints(categoryOrderHints) .categories(asList(category1.toReference(), category2.toReference())) .build(); final Product product = client().executeBlocking(ProductCreateCommand.of(productDraft));
@Test public void categoriesMissing() { withCategory(client(), category -> { withProduct(client(), builder -> builder.categories(singleton(category.toReference())), productWithCategories -> { withProduct(client(), productWithoutCategories -> { final List<String> productIds = asList(productWithCategories.getId(), productWithoutCategories.getId()); final ProductProjectionSearch missing = ProductProjectionSearch.ofStaged() .withQueryFilters(m -> m.id().isIn(productIds))//for test isolation .plusQueryFilters(m -> m.categories().missing()); assertEventually(() -> { final List<ProductProjection> results = client().executeBlocking(missing).getResults(); assertThat(results) .hasSize(1) .extracting(s -> s.getId()) .containsExactly(productWithoutCategories.getId()) .doesNotContain(productWithCategories.getId()); }); }); }); }); }
@Test public void categoriesExists() { withCategory(client(), category -> { withProduct(client(), builder -> builder.categories(singleton(category.toReference())), productWithCategories -> { withProduct(client(), productWithoutCategories -> { final List<String> productIds = asList(productWithCategories.getId(), productWithoutCategories.getId()); final ProductProjectionSearch exists = ProductProjectionSearch.ofStaged() .withQueryFilters(m -> m.id().isIn(productIds))//for test isolation .plusQueryFilters(m -> m.categories().exists()); assertEventually(() -> { final List<ProductProjection> results = client().executeBlocking(exists).getResults(); assertThat(results) .hasSize(1) .extracting(s -> s.getId()) .containsExactly(productWithCategories.getId()) .doesNotContain(productWithoutCategories.getId()); }); }); }); }); }