use of org.onehippo.taxonomy.api.Taxonomy in project hippo by NHS-digital-website.
the class FacetComponent method doBeforeRender.
@Override
public void doBeforeRender(HstRequest request, HstResponse response) {
if (request.getRequestContext().getAttribute("isContentSearch") != null) {
request.setAttribute("isContentSearch", request.getRequestContext().getAttribute("isContentSearch"));
if (request.getRequestContext().getAttribute("taxonomyHierarchy") != null && request.getRequestContext().getAttribute("taxonomyTotalDepth") != null) {
request.setAttribute("taxonomyTotalDepth", request.getRequestContext().getAttribute("taxonomyTotalDepth"));
request.setAttribute("taxonomyHierarchy", request.getRequestContext().getAttribute("taxonomyHierarchy"));
}
} else {
TaxonomyManager taxonomyManager = HstServices.getComponentManager().getComponent(TaxonomyManager.class.getName());
Taxonomy taxonomy = taxonomyManager.getTaxonomies().getTaxonomy(HippoBeanHelper.PUBLICATION_TAXONOMY);
HippoFacetNavigationBean facetNavigationBean = getFacetNavigationBean(request);
TaxonomyFacetWrapper taxonomyWrapper = facetNavigationBean == null ? null : new TaxonomyFacetWrapper(taxonomy, facetNavigationBean);
request.setAttribute("taxonomy", taxonomyWrapper);
request.setAttribute("query", getQueryParameter(request));
request.setAttribute("facets", facetNavigationBean);
request.getRequestContext().setAttribute("facets", facetNavigationBean);
request.setAttribute("cparam", getComponentInfo(request));
}
}
use of org.onehippo.taxonomy.api.Taxonomy in project hippo by NHS-digital-website.
the class HippoBeanHelper method getTaxonomyKeysAndNames.
/**
* Return distinct collection of taxonomy in the format of [Key, Name]
*/
public static Map<String, String> getTaxonomyKeysAndNames(String[] keys) {
Map<String, String> keyNamePairs = new HashMap<String, String>();
// For each taxonomy tag key, get the name and also include hierarchy context (ancestors)
if (keys != null) {
// Lookup Taxonomy Tree
TaxonomyManager taxonomyManager = HstServices.getComponentManager().getComponent(TaxonomyManager.class.getName());
Taxonomy taxonomyTree = taxonomyManager.getTaxonomies().getTaxonomy(PUBLICATION_TAXONOMY);
for (String key : keys) {
List<Category> ancestors = (List<Category>) taxonomyTree.getCategoryByKey(key).getAncestors();
// collect the ancestors
Map<String, String> map = ancestors.stream().distinct().collect(Collectors.toMap(Category::getKey, category -> category.getInfo(Locale.UK).getName()));
// add the current node
map.putIfAbsent(key, taxonomyTree.getCategoryByKey(key).getInfo(Locale.UK).getName());
// combine with master collection if haven't been collected already
map.forEach(keyNamePairs::putIfAbsent);
}
}
return keyNamePairs;
}
use of org.onehippo.taxonomy.api.Taxonomy in project hippo by NHS-digital-website.
the class HippoBeanHelper method getFullTaxonomyList.
public static List<String> getFullTaxonomyList(HippoBean bean) {
String[] fullTaxonomy = bean.getMultipleProperty("common:FullTaxonomy");
if (isEmpty(fullTaxonomy)) {
return emptyList();
}
// Lookup Taxonomy Tree
TaxonomyManager taxonomyManager = HstServices.getComponentManager().getComponent(TaxonomyManager.class.getName());
Taxonomy taxonomyTree = taxonomyManager.getTaxonomies().getTaxonomy(PUBLICATION_TAXONOMY);
return Arrays.stream(fullTaxonomy).map(key -> taxonomyTree.getCategoryByKey(key).getInfo(Locale.UK).getName()).collect(Collectors.toList());
}
use of org.onehippo.taxonomy.api.Taxonomy in project hippo by NHS-digital-website.
the class HippoBeanHelper method getTaxonomyList.
public static List<List<String>> getTaxonomyList(String[] keys) {
List<List<String>> taxonomyList = new ArrayList<>();
// For each taxonomy tag key, get the name and also include hierarchy context (ancestors)
if (keys != null) {
// Lookup Taxonomy Tree
TaxonomyManager taxonomyManager = HstServices.getComponentManager().getComponent(TaxonomyManager.class.getName());
Taxonomy taxonomyTree = taxonomyManager.getTaxonomies().getTaxonomy(getTaxonomyName());
for (String key : keys) {
List<Category> ancestors = (List<Category>) taxonomyTree.getCategoryByKey(key).getAncestors();
List<String> list = ancestors.stream().map(category -> category.getInfo(Locale.UK).getName()).collect(Collectors.toList());
list.add(taxonomyTree.getCategoryByKey(key).getInfo(Locale.UK).getName());
taxonomyList.add(list);
}
}
return taxonomyList;
}
use of org.onehippo.taxonomy.api.Taxonomy in project hippo by NHS-digital-website.
the class SearchComponent method calculateTaxonomyLabel.
private String calculateTaxonomyLabel(List<String> taxonomyKeys) {
TaxonomyManager taxonomyManager = HstServices.getComponentManager().getComponent(TaxonomyManager.class.getName());
Taxonomy taxonomy = taxonomyManager.getTaxonomies().getTaxonomy(HippoBeanHelper.PUBLICATION_TAXONOMY);
List<String> pathLabels = new ArrayList<>();
boolean isValid = true;
for (int i = 1; i < taxonomyKeys.size(); i++) {
final Category categoryByKey = taxonomy.getCategoryByKey(taxonomyKeys.get(i));
if (categoryByKey != null && categoryByKey.getInfo(Locale.getDefault()) != null && categoryByKey.getInfo(Locale.getDefault()).getName() != null) {
pathLabels.add(taxonomy.getCategoryByKey(taxonomyKeys.get(i)).getInfo(Locale.getDefault()).getName());
} else {
isValid = false;
}
}
if (pathLabels.size() > 0 && isValid) {
return pathLabels.get(pathLabels.size() - 1);
} else {
return null;
}
}
Aggregations