@Override public Optional<String> getExternalId() { return delegate.getExternalId(); }
@Override public Optional<String> getExternalId() { return delegate.getExternalId(); }
@Nullable @Override public String getExternalId() { return delegate.getExternalId(); }
@Nullable @Override public String getExternalId() { return delegate.getExternalId(); }
@Nullable @Override public String getExternalId() { return delegate.getExternalId(); }
@Override public Optional<Category> findByExternalId(final String externalId) { return getAllAsFlatList().parallelStream() .filter(cat -> Optional.ofNullable(cat.getExternalId()).map(extIdElement -> extIdElement.equals(externalId)).orElse(false)) .findAny();//should be okay, since the externalId should be unique }
@Override public Optional<Category> findByExternalId(final String externalId) { return getAllAsFlatList().parallelStream() .filter(cat -> Optional.ofNullable(cat.getExternalId()).map(extIdElement -> extIdElement.equals(externalId)).orElse(false)) .findAny();//should be okay, since the externalId should be unique }
@Override public Optional<Category> findByExternalId(final String externalId) { return getAllAsFlatList().parallelStream() .filter(cat -> Optional.ofNullable(cat.getExternalId()).map(extIdElement -> extIdElement.equals(externalId)).orElse(false)) .findAny();//should be okay, since the externalId should be unique }
private static CategoryBean createCategoryData(final Category category, final CategoryTree categoryTree, final UserContext userContext, final ProductReverseRouter productReverseRouter, @Nullable final String saleCategoryExtId) { final CategoryBean categoryData = new CategoryBean(); categoryData.setText(category.getName().find(userContext.locales()).orElse("")); categoryData.setUrl(productReverseRouter.productOverviewPageUrlOrEmpty(userContext.locale(), category)); categoryData.setSale(Optional.ofNullable(category.getExternalId()) .map(id -> id.equals(saleCategoryExtId)) .orElse(false)); categoryData.setChildren(categoryTree.findChildren(category).stream() .map(child -> createCategoryData(child, categoryTree, userContext, productReverseRouter, saleCategoryExtId)) .collect(toList())); return categoryData; } }
private static void appendToBuilder(final Category category, final StringBuilder stringBuilder, final CategoryTree categoryTree, final int level) { final String name = category.getName().get(ENGLISH); final String externalId = category.getExternalId(); final String offset = StringUtils.repeat(' ', level * 4); stringBuilder.append(offset).append(externalId).append(" ").append(name).append("\n"); final List<Category> children = categoryTree.findChildren(category); children.stream() .sorted(EXTERNALID_COMPARATOR) .forEach(child -> appendToBuilder(child, stringBuilder, categoryTree, level + 1)); } }
@Test public void collectAllExternalIds() throws Exception { final List<String> externalIds = new ArrayList<>(); final Consumer<Category> categoryConsumer = category -> externalIds.add(category.getExternalId()); final CompletionStage<Void> categoriesStage = QueryExecutionUtils .queryAll(client(), CategoryQuery.of(), categoryConsumer, 500); SphereClientUtils.blockingWait(categoriesStage, Duration.ofMinutes(1)); assertThat(externalIds).hasSize(15); IntStream.range(0, externalIds.size()).forEach(index -> assertThat(externalIds).contains(index + "")); }
@Test public void createAViewForACategoryBreadCrumb() throws Exception { final CategoryTree categoryTree = createCategoryTree(); final Category currentCategory = categoryTree.findBySlug(ENGLISH, "tshirts-men").get(); final List<Reference<Category>> ancestorReferences = currentCategory.getAncestors().stream() .skip(1)//remove top level category .collect(toList()); final Function<Category, String> formatCategory = cat -> defaultString(cat.getExternalId()) + " " + cat.getName().find(ENGLISH).orElse(""); final String ancestorCategoriesString = ancestorReferences.stream() .map(ref -> categoryTree.findById(ref.getId()).get()) .map(formatCategory) .collect(joining(" > ")); final String actual = ancestorCategoriesString + " > " + formatCategory.apply(currentCategory); assertThat(actual).isEqualTo("1 men > 3 clothing > 7 t-shirts"); }
@Test public void findByExternalId() { final CategoryTree tree = createAbcCategoryTree(); final Category category = tree.findById("B-2-3").get(); final String externalId = "external-id-B-2-3"; assertThat(category.getExternalId()).isEqualTo(externalId); final Optional<Category> optional = tree.findByExternalId(externalId); assertThat(optional).isPresent().contains(category); }
@Test public void queryByExternalId() throws Exception { withCategory(client(), category -> { final String externalId = category.getExternalId(); final Query<Category> query = CategoryQuery.of().byExternalId(externalId); final Category actual = client().executeBlocking(query).head().get(); assertThat(actual).isEqualTo(category); }); }
@Test public void setExternalId() throws Exception { withCategory(client(), category -> { final String newExternalId = randomKey(); final CategoryUpdateCommand command = CategoryUpdateCommand.of(category, SetExternalId.of(newExternalId)); final Category updatedCategory = client().executeBlocking(command); assertThat(updatedCategory.getExternalId()).isEqualTo(newExternalId); }); }
/** * Creates a new object initialized with the fields of the template parameter. * * @param template the template * @return a new object initialized from the template */ public static CategoryDraftBuilder of(final Category template) { return new CategoryDraftBuilder(copyAssets(template.getAssets()), copyCustom(template.getCustom()), template.getDescription(), template.getExternalId(), template.getKey(), template.getMetaDescription(), template.getMetaKeywords(), template.getMetaTitle(), template.getName(), template.getOrderHint(), template.getParent(), template.getSlug()); } }
@Test public void copyFromCategory() { final Category parent = CategoryBuilder.of(randomString(), LocalizedString.ofEnglish(randomString()), LocalizedString.ofEnglish(randomString())) .build(); final Category category = CategoryBuilder.of(randomString(), LocalizedString.ofEnglish(randomString()), LocalizedString.ofEnglish(randomString())) .externalId(randomString()) .key(randomKey()) .parent(parent) .assets(null) .build(); final CategoryDraft categoryDraft = CategoryDraftBuilder.of(category).build(); assertThat(category.getName()).isEqualTo(categoryDraft.getName()); assertThat(category.getSlug()).isEqualTo(categoryDraft.getSlug()); assertThat(category.getExternalId()).isEqualTo(categoryDraft.getExternalId()); assertThat(category.getParent()).isEqualTo(categoryDraft.getParent()); assertThat(category.getAssets()).isEqualTo(categoryDraft.getAssets()); assertThat(category.getKey()).isEqualTo(categoryDraft.getKey()); } }
public static CategoryBuilder of(final Category category) { return new CategoryBuilder(category.getId(), category.getName(), category.getSlug()). version(category.getVersion()).createdAt(category.getCreatedAt()). lastModifiedAt(category.getLastModifiedAt()). name(category.getName()).slug(category.getSlug()).description(category.getDescription()). ancestors(category.getAncestors()).parent(category.getParent()). orderHint(category.getOrderHint()).externalId(category.getExternalId()).children(category.getChildren()). pathInTree(category.getPathInTree()); }
public static CategoryBuilder of(final Category category) { return new CategoryBuilder(category.getId(), category.getName(), category.getSlug()). version(category.getVersion()).createdAt(category.getCreatedAt()). lastModifiedAt(category.getLastModifiedAt()). name(category.getName()).slug(category.getSlug()).description(category.getDescription()). ancestors(category.getAncestors()).parent(category.getParent()). orderHint(category.getOrderHint()).externalId(category.getExternalId()).children(category.getChildren()). pathInTree(category.getPathInTree()); }
public static CategoryBuilder of(final Category category) { return new CategoryBuilder(category.getId(), category.getName(), category.getSlug()). version(category.getVersion()).createdAt(category.getCreatedAt()). lastModifiedAt(category.getLastModifiedAt()). name(category.getName()).slug(category.getSlug()).description(category.getDescription()). ancestors(category.getAncestors()).parent(category.getParent()).assets(category.getAssets()). orderHint(category.getOrderHint()).externalId(category.getExternalId()); }