Search in sources :

Example 1 with Taxonomy

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));
    }
}
Also used : HippoFacetNavigationBean(org.hippoecm.hst.content.beans.standard.HippoFacetNavigationBean) TaxonomyManager(org.onehippo.taxonomy.api.TaxonomyManager) Taxonomy(org.onehippo.taxonomy.api.Taxonomy)

Example 2 with Taxonomy

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;
}
Also used : ArrayUtils.isEmpty(org.apache.commons.lang3.ArrayUtils.isEmpty) HstServices(org.hippoecm.hst.site.HstServices) java.util(java.util) Collections.emptyList(java.util.Collections.emptyList) TaxonomyManager(org.onehippo.taxonomy.api.TaxonomyManager) HippoFolder(org.hippoecm.hst.content.beans.standard.HippoFolder) Taxonomy(org.onehippo.taxonomy.api.Taxonomy) Category(org.onehippo.taxonomy.api.Category) RequestContextProvider(org.hippoecm.hst.container.RequestContextProvider) Collectors(java.util.stream.Collectors) HippoBean(org.hippoecm.hst.content.beans.standard.HippoBean) Category(org.onehippo.taxonomy.api.Category) TaxonomyManager(org.onehippo.taxonomy.api.TaxonomyManager) Taxonomy(org.onehippo.taxonomy.api.Taxonomy) Collections.emptyList(java.util.Collections.emptyList)

Example 3 with Taxonomy

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());
}
Also used : ArrayUtils.isEmpty(org.apache.commons.lang3.ArrayUtils.isEmpty) HstServices(org.hippoecm.hst.site.HstServices) java.util(java.util) Collections.emptyList(java.util.Collections.emptyList) TaxonomyManager(org.onehippo.taxonomy.api.TaxonomyManager) HippoFolder(org.hippoecm.hst.content.beans.standard.HippoFolder) Taxonomy(org.onehippo.taxonomy.api.Taxonomy) Category(org.onehippo.taxonomy.api.Category) RequestContextProvider(org.hippoecm.hst.container.RequestContextProvider) Collectors(java.util.stream.Collectors) HippoBean(org.hippoecm.hst.content.beans.standard.HippoBean) TaxonomyManager(org.onehippo.taxonomy.api.TaxonomyManager) Taxonomy(org.onehippo.taxonomy.api.Taxonomy)

Example 4 with Taxonomy

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;
}
Also used : HstServices(org.hippoecm.hst.site.HstServices) HstRequestContext(org.hippoecm.hst.core.request.HstRequestContext) HstComponentException(org.hippoecm.hst.core.component.HstComponentException) Category(org.onehippo.taxonomy.api.Category) HashMap(java.util.HashMap) Collectors(java.util.stream.Collectors) HippoBean(org.hippoecm.hst.content.beans.standard.HippoBean) ArrayList(java.util.ArrayList) List(java.util.List) RepositoryException(javax.jcr.RepositoryException) TaxonomyManager(org.onehippo.taxonomy.api.TaxonomyManager) Locale(java.util.Locale) Taxonomy(org.onehippo.taxonomy.api.Taxonomy) Map(java.util.Map) RequestContextProvider(org.hippoecm.hst.container.RequestContextProvider) Category(org.onehippo.taxonomy.api.Category) TaxonomyManager(org.onehippo.taxonomy.api.TaxonomyManager) Taxonomy(org.onehippo.taxonomy.api.Taxonomy) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List)

Example 5 with Taxonomy

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;
    }
}
Also used : Category(org.onehippo.taxonomy.api.Category) TaxonomyManager(org.onehippo.taxonomy.api.TaxonomyManager) Taxonomy(org.onehippo.taxonomy.api.Taxonomy) Constraint(org.hippoecm.hst.content.beans.query.builder.Constraint)

Aggregations

Taxonomy (org.onehippo.taxonomy.api.Taxonomy)6 Category (org.onehippo.taxonomy.api.Category)5 TaxonomyManager (org.onehippo.taxonomy.api.TaxonomyManager)5 java.util (java.util)3 Collections.emptyList (java.util.Collections.emptyList)3 Collectors (java.util.stream.Collectors)3 RequestContextProvider (org.hippoecm.hst.container.RequestContextProvider)3 HippoBean (org.hippoecm.hst.content.beans.standard.HippoBean)3 HstServices (org.hippoecm.hst.site.HstServices)3 ArrayUtils.isEmpty (org.apache.commons.lang3.ArrayUtils.isEmpty)2 HippoFacetNavigationBean (org.hippoecm.hst.content.beans.standard.HippoFacetNavigationBean)2 HippoFolder (org.hippoecm.hst.content.beans.standard.HippoFolder)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Locale (java.util.Locale)1 Map (java.util.Map)1 RepositoryException (javax.jcr.RepositoryException)1 Constraint (org.hippoecm.hst.content.beans.query.builder.Constraint)1 HippoFolderBean (org.hippoecm.hst.content.beans.standard.HippoFolderBean)1