Search in sources :

Example 26 with HippoBean

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

the class SearchComponent method deriveScope.

private HippoBean[] deriveScope(HstRequest request) {
    SearchArea areaParam = getAreaOption(request);
    final HippoBean base = RequestContextProvider.get().getSiteContentBaseBean();
    final HippoBean newsAndEventsFolder = base.getBean(FOLDER_NEWS_AND_EVENTS);
    final HippoBean publicationsFolder = base.getBean(FOLDER_PUBLICATIONS);
    final HippoBean servicesFolder = base.getBean(FOLDER_SERVICES);
    final HippoBean dataAndInformationFolder = base.getBean(FOLDER_DATAANDINFORMATION);
    final HippoBean nationalIndicatorLibraryFolder = base.getBean(FOLDER_NIL);
    List<HippoBean> scopeBeans = new ArrayList<HippoBean>();
    switch(areaParam) {
        case NEWS_AND_EVENTS:
            scopeBeans.add(newsAndEventsFolder);
            break;
        case DATA:
            scopeBeans.add(publicationsFolder);
            scopeBeans.add(nationalIndicatorLibraryFolder);
            scopeBeans.add(dataAndInformationFolder);
            break;
        case SERVICES:
            scopeBeans.add(servicesFolder);
            break;
        case ALL:
            scopeBeans.add(request.getRequestContext().getSiteContentBaseBean());
            break;
        default:
            scopeBeans.add(request.getRequestContext().getSiteContentBaseBean());
    }
    return scopeBeans.toArray(new HippoBean[0]);
}
Also used : HippoBean(org.hippoecm.hst.content.beans.standard.HippoBean) SearchArea(uk.nhs.digital.common.enums.SearchArea)

Example 27 with HippoBean

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

the class HeroComponent method doBeforeRender.

@Override
public void doBeforeRender(HstRequest request, HstResponse response) {
    super.doBeforeRender(request, response);
    HeroComponentInfo componentInfo = getComponentParametersInfo(request);
    final String size = componentInfo.getSize();
    final String textAlignment = componentInfo.getTextAlignment();
    final Boolean colourBar = componentInfo.getColourBar();
    HippoBean document = getHippoBeanForPath(componentInfo.getDocument(), HippoBean.class);
    String colour = componentInfo.getColour();
    if ("Dark Blue".equalsIgnoreCase(colour)) {
        request.setAttribute("colour", "Dark Blue Multicolour");
    } else {
        request.setAttribute("colour", colour);
    }
    request.setAttribute("document", document);
    request.setAttribute("size", size);
    request.setAttribute("textAlignment", textAlignment);
    request.setAttribute("displayColourBar", colourBar);
    request.setAttribute("stripTagsContentRewriter", stripTagsContentRewriter);
    request.setAttribute("brContentRewriter", brContentRewriter);
}
Also used : HippoBean(org.hippoecm.hst.content.beans.standard.HippoBean) HeroComponentInfo(uk.nhs.digital.common.components.info.HeroComponentInfo)

Example 28 with HippoBean

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

the class ApiCatalogueComponentTest method internalLinkToDocTaggedWith.

private Internallink internalLinkToDocTaggedWith(final String... taxonomyKeys) {
    final HippoBean bean = mock(HippoBean.class);
    given(bean.getProperties()).willReturn(Collections.singletonMap("hippotaxonomy:keys", taxonomyKeys));
    final Internallink link = mock(Internallink.class);
    given(link.getLinkType()).willReturn("internal");
    given(link.getLink()).willReturn(bean);
    given(link.toString()).willReturn("Internallink of a doc tagged with: " + String.join(", ", taxonomyKeys));
    return link;
}
Also used : HippoBean(org.hippoecm.hst.content.beans.standard.HippoBean) Internallink(uk.nhs.digital.website.beans.Internallink)

Example 29 with HippoBean

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

the class CyberAlertResource method fetchAllThreatIds.

@GET
@Path("/getAllThreatIds/")
public ThreatIds fetchAllThreatIds(@Context HttpServletRequest request, @Context HttpServletResponse servletResponse) {
    ThreatIds threatId = new ThreatIds();
    List<ThreatIdDate> threatIdDateList = new ArrayList<ThreatIdDate>();
    try {
        final HstQuery query = createQuery(new DefaultRestContext(this, request), CyberAlert.class, Subtypes.INCLUDE);
        query.setLimit(100);
        final HstQueryResult result = query.execute();
        HippoBeanIterator iterator = result.getHippoBeans();
        while (iterator.hasNext()) {
            CyberAlert cyberAlert = (CyberAlert) iterator.nextHippoBean();
            List<Calendar> calList = new ArrayList<Calendar>();
            ThreatIdDate threDate = new ThreatIdDate();
            if (cyberAlert != null) {
                List<HippoBean> cyberAcknowledgementList = (List<HippoBean>) cyberAlert.getCyberAcknowledgements();
                for (HippoBean cyberAckn : cyberAcknowledgementList) {
                    if (cyberAckn instanceof CyberAcknowledgement) {
                        CyberAcknowledgement cybAck = (CyberAcknowledgement) cyberAckn;
                        calList.add(cybAck.getResponseDatetime());
                    }
                }
                threDate.setResponsedates(calList);
                threDate.setThreatid(cyberAlert.getThreatId());
            }
            threatIdDateList.add(threDate);
        }
    } catch (Exception e) {
        log.error("Error finding beans", e);
    }
    threatId.setThreatids(threatIdDateList);
    return threatId;
}
Also used : HstQuery(org.hippoecm.hst.content.beans.query.HstQuery) DefaultRestContext(org.onehippo.cms7.essentials.components.rest.ctx.DefaultRestContext) CyberAcknowledgement(uk.nhs.digital.website.beans.CyberAcknowledgement) ThreatIds(uk.nhs.digital.website.beans.ThreatIds) HippoBeanIterator(org.hippoecm.hst.content.beans.standard.HippoBeanIterator) CyberAlert(uk.nhs.digital.website.beans.CyberAlert) HstQueryResult(org.hippoecm.hst.content.beans.query.HstQueryResult) HippoBean(org.hippoecm.hst.content.beans.standard.HippoBean) ThreatIdDate(uk.nhs.digital.website.beans.ThreatIdDate) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 30 with HippoBean

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

the class SvgSection method getSvgXmlFromRepository.

public String getSvgXmlFromRepository() throws RepositoryException, IOException {
    HippoBean imageBean = getLinkedBean("website:link", CorporateWebsiteImageset.class);
    HippoBean imageTypeBean = imageBean.getBean(IMAGE_TYPE_ORIGINAL);
    boolean hasBinaryData = ResourceUtils.hasBinaryProperty(imageTypeBean.getNode(), JcrConstants.JCR_DATA);
    if (hasBinaryData) {
        LOG.debug("Fetching binary data from {}.", this.getParentBean().getParentBean().getName());
        InputStream svgBinaryStream = imageTypeBean.getNode().getProperty(JcrConstants.JCR_DATA).getBinary().getStream();
        return IOUtils.toString(svgBinaryStream, StandardCharsets.UTF_8.name());
    } else {
        LOG.warn("Could not find Binary data from the SVG section of the document.");
        return null;
    }
}
Also used : HippoBean(org.hippoecm.hst.content.beans.standard.HippoBean) InputStream(java.io.InputStream)

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