@Nullable @Override public String getKey() { return delegate.getKey(); }
@Nullable @Override public String getKey() { return delegate.getKey(); }
public CategoryTree create(final List<Category> allCategoriesAsFlatList, final List<Category> roots, final List<Category> subtreeRoots) { final List<Category> allAsFlatList = allCategoriesAsFlatList; final Map<LocalizedStringEntry, Category> categoriesByLocaleAndSlug = getLocalizedStringEntryCategoryMap(allCategoriesAsFlatList); final Map<String, Category> categoriesById = allCategoriesAsFlatList.stream().collect(toMap(Category::getId, Function.<Category>identity())); final Map<String, Category> categoriesByKey = allCategoriesAsFlatList.stream().filter(category -> category.getKey() != null).collect(toMap(Category::getKey, Function.<Category>identity())); final Map<String, List<Category>> childrenByParentId = getChildrenByParentIdMap(allCategoriesAsFlatList); return new CategoryTreeImpl(roots, allAsFlatList, categoriesByLocaleAndSlug, categoriesById, categoriesByKey ,childrenByParentId, subtreeRoots); }
public CategoryTree create(final List<Category> allCategoriesAsFlatList, final List<Category> roots, final List<Category> subtreeRoots) { final List<Category> allAsFlatList = allCategoriesAsFlatList; final Map<LocalizedStringEntry, Category> categoriesByLocaleAndSlug = getLocalizedStringEntryCategoryMap(allCategoriesAsFlatList); final Map<String, Category> categoriesById = allCategoriesAsFlatList.stream().collect(toMap(Category::getId, Function.<Category>identity())); final Map<String, Category> categoriesByKey = allCategoriesAsFlatList.stream().filter(category -> category.getKey() != null).collect(toMap(Category::getKey, Function.<Category>identity())); final Map<String, List<Category>> childrenByParentId = getChildrenByParentIdMap(allCategoriesAsFlatList); return new CategoryTreeImpl(roots, allAsFlatList, categoriesByLocaleAndSlug, categoriesById, categoriesByKey ,childrenByParentId, subtreeRoots); }
@Test public void execution() throws Exception { CategoryFixtures.withCategoryAndParentCategory(client(), (category, parent) -> { final String key = category.getKey(); final Get<Category> fetch = CategoryByKeyGet.of(key) .withExpansionPaths(m -> m.parent()); final Category loadedCategory = client().executeBlocking(fetch); assertThat(loadedCategory.getKey()).isEqualTo(key); assertThat(loadedCategory.getParent()).is(expanded(parent)); }); } }
@Test public void simpleCategoryTreeOperations() throws Exception { final CategoryTree categoryTree = createCategoryTree(); //find by slug final Optional<Category> jeansWomenOptional = categoryTree.findBySlug(ENGLISH, "jeans-women"); assertThat(jeansWomenOptional).isPresent(); assertThat(categoryTree.findBySlug(ENGLISH, "not-existing-slug")).isEmpty(); //find by Key final Optional<Category> jeansWomenOptionalByKey = categoryTree.findByKey(jeansWomenOptional.get().getKey()); assertThat(jeansWomenOptionalByKey).isPresent(); assertThat(jeansWomenOptionalByKey.get().getSlug().get(ENGLISH)).contains("jeans-women"); //find by ID final Reference<Category> clothingWomenReference = jeansWomenOptional.get().getParent(); final Optional<Category> clothingWomenOptional = categoryTree.findById(clothingWomenReference.getId()); assertThat(clothingWomenOptional).isPresent(); assertThat(clothingWomenOptional.get().getSlug().get(ENGLISH)).contains("womens-clothing"); //find all direct children of one category final Category clothingWomen = clothingWomenOptional.get(); final List<Category> clothingWomenSubcategories = categoryTree.findChildren(clothingWomen); final List<String> names = clothingWomenSubcategories.stream() .map(cat -> cat.getName().get(ENGLISH)) .sorted() .collect(toList()); assertThat(names).contains("jeans", "t-shirts"); }
@Test public void changeKey() throws Exception { withCategory(client(), category -> { final String key = randomKey(); final CategoryUpdateCommand command = CategoryUpdateCommand.of(category, SetKey.of(key)); final Category updatedCategory = client().executeBlocking(command); assertThat(updatedCategory.getKey()).isEqualTo(key); }); }
/** * 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()); } }