use of org.onehippo.taxonomy.api.Taxonomy in project hippo by NHS-digital-website.
the class TaxonomyFacetWrapper method createTaxonomyFacets.
private List<TaxonomyFacet> createTaxonomyFacets() {
// get the taxonomy facets
List<HippoFolderBean> taxonomyFacets = facetBean.getFolders().stream().filter((facet) -> facet.getName().equals(TAXONOMY_FACET_NAME)).findAny().map(HippoFolderBean::getFolders).orElseGet(() -> {
log.error("Unable to find taxonomy facet.");
return null;
});
if (isEmpty(taxonomyFacets)) {
return emptyList();
}
// link the taxonomy facets to the taxonomy category
HashMap<String, TaxonomyFacet> keyToTaxonomyFacet = new HashMap<>(taxonomyFacets.size());
for (HippoFolderBean facet : taxonomyFacets) {
String key = facet.getName();
keyToTaxonomyFacet.put(key, new TaxonomyFacet(taxonomy, key, facet));
}
// build the tree structure
List<TaxonomyFacet> rootTaxonomyFacets = new ArrayList<>();
for (TaxonomyFacet taxonomyFacet : keyToTaxonomyFacet.values()) {
Category taxonomyCategory = taxonomyFacet.getTaxonomyCategory();
Category parentTaxonomy = taxonomyCategory == null ? null : taxonomyCategory.getParent();
if (parentTaxonomy == null) {
rootTaxonomyFacets.add(taxonomyFacet);
} else {
String parentKey = parentTaxonomy.getKey();
TaxonomyFacet parent = keyToTaxonomyFacet.get(parentKey);
if (parent == null) {
log.error("No parent facet found for taxonomy key: " + taxonomyCategory.getName());
} else {
parent.addChild(taxonomyFacet);
}
}
}
return rootTaxonomyFacets;
}
Aggregations