Search in sources :

Example 21 with HippoBean

use of org.hippoecm.hst.content.beans.standard.HippoBean in project hippo by NHS-digital-website.

the class IndicatorComponent method getIndicator.

private Indicator getIndicator(HstRequestContext ctx) throws HstComponentException {
    HippoBean content = ctx.getContentBean();
    if (content instanceof Indicator) {
        return (Indicator) content;
    }
    log.warn("Cannot find Indicator document for: {}", content.getPath());
    throw new HstComponentException("Cannot find Indicator document based on request content");
}
Also used : HippoBean(org.hippoecm.hst.content.beans.standard.HippoBean) HstComponentException(org.hippoecm.hst.core.component.HstComponentException) Indicator(uk.nhs.digital.nil.beans.Indicator)

Example 22 with HippoBean

use of org.hippoecm.hst.content.beans.standard.HippoBean in project hippo by NHS-digital-website.

the class ArchiveComponent method doBeforeRender.

@Override
public void doBeforeRender(final HstRequest request, final HstResponse response) throws HstComponentException {
    super.doBeforeRender(request, response);
    final HstRequestContext requestContext = request.getRequestContext();
    final HippoBean contentBean = requestContext.getContentBean();
    final Archive archiveIndexDocument;
    if (contentBean.isHippoFolderBean()) {
        final List<Archive> archiveIndexDocuments = contentBean.getChildBeans(Archive.class);
        if (archiveIndexDocuments.size() != 1) {
            reportInvalidTarget(request, contentBean, archiveIndexDocuments.size());
            return;
        }
        archiveIndexDocument = archiveIndexDocuments.get(0);
    } else if (contentBean instanceof Archive) {
        archiveIndexDocument = (Archive) contentBean;
    } else {
        reportInvalidInvocation(request, contentBean);
        return;
    }
    request.setAttribute("archive", archiveIndexDocument);
    try {
        final HstQuery query = requestContext.getQueryManager().createQuery(archiveIndexDocument.getParentBean(), Publication.class, LegacyPublication.class);
        query.addOrderByDescending("publicationsystem:NominalDate");
        final HstQueryResult hstQueryResult = query.execute();
        request.setAttribute("publications", hstQueryResult.getHippoBeans());
    } catch (QueryException queryException) {
        log.error("Failed to find publications for archive " + archiveIndexDocument.getTitle(), queryException);
        reportDisplayError(request, archiveIndexDocument.getTitle());
    }
}
Also used : HstQuery(org.hippoecm.hst.content.beans.query.HstQuery) HippoBean(org.hippoecm.hst.content.beans.standard.HippoBean) QueryException(org.hippoecm.hst.content.beans.query.exceptions.QueryException) Archive(uk.nhs.digital.ps.beans.Archive) HstRequestContext(org.hippoecm.hst.core.request.HstRequestContext) HstQueryResult(org.hippoecm.hst.content.beans.query.HstQueryResult)

Example 23 with HippoBean

use of org.hippoecm.hst.content.beans.standard.HippoBean 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 24 with HippoBean

use of org.hippoecm.hst.content.beans.standard.HippoBean in project hippo by NHS-digital-website.

the class PublicationComponent method getPublication.

private Publication getPublication(HstRequestContext ctx) throws HstComponentException {
    HippoBean content = ctx.getContentBean();
    if (content.getClass().equals(Publication.class)) {
        return (Publication) content;
    }
    if (content.getClass().equals(HippoFolder.class)) {
        return Publication.getPublicationInFolder((HippoFolder) content, Publication.class);
    }
    log.warn("Cannot find Publication document for: {}", content.getPath());
    throw new HstComponentException("Cannot find Publication document based on request content");
}
Also used : HippoBean(org.hippoecm.hst.content.beans.standard.HippoBean) Publication(uk.nhs.digital.ps.beans.Publication) HstComponentException(org.hippoecm.hst.core.component.HstComponentException)

Example 25 with HippoBean

use of org.hippoecm.hst.content.beans.standard.HippoBean in project hippo by NHS-digital-website.

the class ProjectUpdateFeedComponent method doBeforeRender.

@Override
public void doBeforeRender(final HstRequest request, final HstResponse response) {
    super.doBeforeRender(request, response);
    final HippoBean document = request.getRequestContext().getContentBean();
    if (document != null) {
        request.setAttribute("document", document);
    }
    try {
        List<ProjectUpdate> unfilteredResults = toList(HstQueryBuilder.create(document.getParentBean()).ofTypes(ProjectUpdate.class).build().execute().getHippoBeans());
        request.setAttribute("organisations", organisations(unfilteredResults));
        request.setAttribute("updateTypes", types(unfilteredResults));
        request.setAttribute("years", years(unfilteredResults));
    } catch (QueryException e) {
        log.error("Query for filter generation failed: {}", e.getMessage());
    }
    request.setAttribute("selectedOrganisation", getSelectedOrganisationTitle(request));
    request.setAttribute("selectedUpdateType", getSelectedUpdateType(request));
    request.setAttribute("selectedYear", getYearToFilter(request));
}
Also used : HippoBean(org.hippoecm.hst.content.beans.standard.HippoBean) QueryException(org.hippoecm.hst.content.beans.query.exceptions.QueryException) ProjectUpdate(uk.nhs.digital.website.beans.ProjectUpdate)

Aggregations

HippoBean (org.hippoecm.hst.content.beans.standard.HippoBean)46 QueryException (org.hippoecm.hst.content.beans.query.exceptions.QueryException)10 HstRequestContext (org.hippoecm.hst.core.request.HstRequestContext)10 ArrayList (java.util.ArrayList)7 HstQuery (org.hippoecm.hst.content.beans.query.HstQuery)7 HippoBeanIterator (org.hippoecm.hst.content.beans.standard.HippoBeanIterator)7 HstQueryResult (org.hippoecm.hst.content.beans.query.HstQueryResult)6 HstQueryBuilder (org.hippoecm.hst.content.beans.query.builder.HstQueryBuilder)5 HstComponentException (org.hippoecm.hst.core.component.HstComponentException)5 SimpleDateFormat (java.text.SimpleDateFormat)4 java.util (java.util)4 Collectors (java.util.stream.Collectors)4 IteratorUtils.toList (org.apache.commons.collections.IteratorUtils.toList)4 RequestContextProvider (org.hippoecm.hst.container.RequestContextProvider)4 Constraint (org.hippoecm.hst.content.beans.query.builder.Constraint)4 DateTools (org.hippoecm.repository.util.DateTools)4 ParseException (java.text.ParseException)3 Function (java.util.function.Function)3 Node (javax.jcr.Node)3 ConstraintBuilder.and (org.hippoecm.hst.content.beans.query.builder.ConstraintBuilder.and)3