@Nullable @Override public CategoryOrderHints getCategoryOrderHints() { return productData.getCategoryOrderHints(); }
@Nullable @Override public CategoryOrderHints getCategoryOrderHints() { return productData.getCategoryOrderHints(); }
@Nullable @Override public CategoryOrderHints getCategoryOrderHints() { return productData.getCategoryOrderHints(); }
private static Comparator<Product> comparatorOfStagedForCategory(final String categoryId) { final Function<Product, String> orderHintExtractor = p -> Optional.ofNullable(p.getMasterData().getStaged().getCategoryOrderHints()) .map(categoryOrderHints -> categoryOrderHints.get(categoryId)) .orElse(null); return comparing(orderHintExtractor, Comparator.nullsLast(Comparator.<String>naturalOrder())); }
@Test public void setCategoryOrderHint() throws Exception { withProductInCategory(client(), (product, category) -> { final Product updatedProduct = client().executeBlocking(ProductUpdateCommand.of(product, SetCategoryOrderHint.of(category.getId(), "0.1234"))); final CategoryOrderHints actual = updatedProduct.getMasterData().getStaged().getCategoryOrderHints(); assertThat(actual).isEqualTo(CategoryOrderHints.of(category.getId(), "0.1234")); assertThat(actual.getAsMap()).isEqualTo(Collections.singletonMap(category.getId(), "0.1234")); }); }
@Test public void addToCategory() throws Exception { withProductAndUnconnectedCategory(client(), (final Product product, final Category category) -> { assertThat(product.getMasterData().getStaged().getCategories()).isEmpty(); final String orderHint = "0.123"; final Product productWithCategory = client() .executeBlocking(ProductUpdateCommand.of(product, AddToCategory.of(category, orderHint))); final Reference<Category> categoryReference = productWithCategory.getMasterData().getStaged().getCategories().stream().findAny().get(); assertThat(categoryReference.referencesSameResource(category)).isTrue(); assertThat(productWithCategory.getMasterData().getStaged().getCategoryOrderHints().get(category.getId())).isEqualTo(orderHint); final Product productWithoutCategory = client() .executeBlocking(ProductUpdateCommand.of(productWithCategory, RemoveFromCategory.of(category))); assertThat(productWithoutCategory.getMasterData().getStaged().getCategories()).isEmpty(); }); }
public void setCategoryOrderHintWithStaged(final Boolean staged) { withCategory(client(), category -> { withUpdateableProduct(client(), product -> { assertThat(product.getMasterData().getStaged().getCategories()).isEmpty(); final String orderHint = "0.123"; final Product productWithCategory = client() .executeBlocking(ProductUpdateCommand.of(product, AddToCategory.of(category, orderHint, false))); assertThat(productWithCategory.getMasterData().hasStagedChanges()).isFalse(); final Product updatedProduct = client().executeBlocking(ProductUpdateCommand.of(productWithCategory, SetCategoryOrderHint.of(category.getId(), "0.1234", staged))); final CategoryOrderHints actual = updatedProduct.getMasterData().getStaged().getCategoryOrderHints(); assertThat(actual).isEqualTo(CategoryOrderHints.of(category.getId(), "0.1234")); assertThat(actual.getAsMap()).isEqualTo(Collections.singletonMap(category.getId(), "0.1234")); assertThat(updatedProduct.getMasterData().hasStagedChanges()).isEqualTo(staged); return productWithCategory; }); }); }