@Override public boolean test(final Category category){ return category.getParent() != null; } }
@Override public boolean test(final Category category){ return category.getParent() != null; } }
@Override public boolean test(final Category category){ return category.getParent().isPresent(); } }
@Nullable @Override public Reference<Category> getParent() { return delegate.getParent(); }
@Override public boolean test(final Category category){ return category.getParent().isPresent(); } }
@Override public boolean test(final Category category){ return category.getParent().isPresent(); } }
@Nullable @Override public Reference<Category> getParent() { return delegate.getParent(); }
@Nullable @Override public Reference<Category> getParent() { return delegate.getParent(); }
private List<Category> getSiblings(final Category category) { return Optional.ofNullable(category.getParent()) .map(this::findChildren) .orElseGet(this::getRoots); }
private Map<String, List<Category>> getChildrenByParentIdMap(final List<Category> allCategoriesAsFlatList) { final Map<String, List<Category>> childrenByParentId = new HashMap<>(); allCategoriesAsFlatList.forEach(category -> Optional.ofNullable(category.getParent()).ifPresent(parentReference -> { final String parentId = parentReference.getId(); final List<Category> entries = childrenByParentId.getOrDefault(parentId, new LinkedList<>()); entries.add(category); childrenByParentId.put(parentId, entries); }) ); return childrenByParentId; }
private Map<String, List<Category>> getChildrenByParentIdMap(final List<Category> allCategoriesAsFlatList) { final Map<String, List<Category>> childrenByParentId = new HashMap<>(); allCategoriesAsFlatList.forEach(category -> Optional.ofNullable(category.getParent()).ifPresent(parentReference -> { final String parentId = parentReference.getId(); final List<Category> entries = childrenByParentId.getOrDefault(parentId, new LinkedList<>()); entries.add(category); childrenByParentId.put(parentId, entries); }) ); return childrenByParentId; }
private static Multimap<String, Category> buildParentMultiMap(List<Category> categoriesWithParents) { final Multimap<String, Category> categoriesByParentId = new Multimap<>(); for (final Category categoryWithParent : categoriesWithParents) { final String parentId = categoryWithParent.getParent().get().getId(); categoriesByParentId.put(parentId, categoryWithParent); } return categoriesByParentId; }
private static Multimap<String, Category> buildParentMultiMap(List<Category> categoriesWithParents) { final Multimap<String, Category> categoriesByParentId = new Multimap<>(); for (final Category categoryWithParent : categoriesWithParents) { final String parentId = categoryWithParent.getParent().get().getId(); categoriesByParentId.put(parentId, categoryWithParent); } return categoriesByParentId; }
@Test public void fetchRoots_withMapper() throws Exception { final CategoryQuery seedQuery = CategoryQuery.of().withPredicates(m -> m.parent().isNotPresent()); final CompletionStage<List<Category>> rootCategoryStage = QueryExecutionUtils .queryAll(client(), seedQuery, category -> category); final List<Category> rootCategories = SphereClientUtils .blockingWait(rootCategoryStage, Duration.ofMinutes(1)); assertThat(rootCategories.stream().allMatch(cat -> cat.getParent() == null)) .overridingErrorMessage("fetched only root categories") .isTrue(); }
@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)); }); } }
/** * 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 referenceExpansionForDeletionByKey() throws Exception { final String key = randomKey(); final Category parent = client().executeBlocking(CategoryCreateCommand.of(CategoryDraftBuilder.of(randomLocalizedString(), randomSlug()).build())); final Category category = client().executeBlocking(CategoryCreateCommand.of(CategoryDraftBuilder.of(randomLocalizedString(), randomSlug()).key(key).parent(parent).build())); final CategoryDeleteCommand deleteCommand = CategoryDeleteCommand.ofKey(key, category.getVersion()).plusExpansionPaths(m -> m.parent()); final Category deletedCategory = client().executeBlocking(deleteCommand); assertThat(deletedCategory.getParent().getObj()).isNotNull().isEqualTo(parent); client().executeBlocking(CategoryDeleteCommand.of(parent)); } }
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()); }
@Test public void referenceExpansion() throws Exception { final CategoryDraft parentDraft = CategoryDraftBuilder.of(randomSlug(), randomSlug()).build(); final Category parent = client().executeBlocking(CategoryCreateCommand.of(parentDraft)); final CategoryDraft categoryDraft = CategoryDraftBuilder.of(randomSlug(), randomSlug()).parent(parent).build(); final CategoryCreateCommand createCommand = CategoryCreateCommand.of(categoryDraft).withExpansionPaths(m -> m.parent()); final Category category = client().executeBlocking(createCommand); assertThat(category.getParent()).is(expanded()); client().executeBlocking(CategoryDeleteCommand.of(parent)); }
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()); }