Search in sources :

Example 6 with HstQueryResult

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

the class ApiEndpoint method getApiMasterParent.

public ApiMaster getApiMasterParent() {
    final HstRequestContext context = RequestContextProvider.get();
    try {
        HstQuery linkedBeanQuery = ContentBeanUtils.createIncomingBeansQuery(this.getCanonicalBean(), context.getSiteContentBaseBean(), "website:apiendpointgroups/website:apirequest/@hippo:docbase", ApiMaster.class, false);
        linkedBeanQuery.setLimit(1);
        HstQueryResult hstQueryResult = linkedBeanQuery.execute();
        HippoBeanIterator hippoBeanIterator = hstQueryResult.getHippoBeans();
        if (hippoBeanIterator.getSize() > 0) {
            return (ApiMaster) hippoBeanIterator.nextHippoBean();
        } else {
            return null;
        }
    } catch (QueryException queryException) {
        log.warn("QueryException ", queryException);
    }
    return null;
}
Also used : HstQuery(org.hippoecm.hst.content.beans.query.HstQuery) QueryException(org.hippoecm.hst.content.beans.query.exceptions.QueryException) HippoBeanIterator(org.hippoecm.hst.content.beans.standard.HippoBeanIterator) HstRequestContext(org.hippoecm.hst.core.request.HstRequestContext) HstQueryResult(org.hippoecm.hst.content.beans.query.HstQueryResult)

Example 7 with HstQueryResult

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

the class PolicyPageLinkedBeansComponent method doBeforeRender.

@Override
public void doBeforeRender(final HstRequest request, final HstResponse response) {
    super.doBeforeRender(request, response);
    // linkPath property contains the relative path of the links property in the published workflow document
    String linkPath = getComponentParameter("linkPath");
    final HstRequestContext context = request.getRequestContext();
    // we assume a PublishedWorkChapter as content bean, thus expect a PublishedWork as "parent" document
    PolicyPage policyPage = context.getContentBean(PolicyPage.class);
    try {
        HstQuery linkedBeanQuery = ContentBeanUtils.createIncomingBeansQuery(policyPage, context.getSiteContentBaseBean(), linkPath, Policy.class, false);
        // chapter cannot be re-used across different publishedworkflow
        linkedBeanQuery.setLimit(1);
        // linked documents will contain the publishedworkflow document containing all the chapters
        HstQueryResult linkedDocuments = linkedBeanQuery.execute();
        request.setAttribute("linkeddocuments", linkedDocuments);
    } catch (QueryException queryException) {
        log.warn("QueryException ", queryException);
    }
}
Also used : HstQuery(org.hippoecm.hst.content.beans.query.HstQuery) QueryException(org.hippoecm.hst.content.beans.query.exceptions.QueryException) PolicyPage(uk.nhs.digital.website.beans.PolicyPage) HstRequestContext(org.hippoecm.hst.core.request.HstRequestContext) HstQueryResult(org.hippoecm.hst.content.beans.query.HstQueryResult)

Example 8 with HstQueryResult

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

the class FinancialLinkedBeansComponent method doBeforeRender.

@Override
public void doBeforeRender(final HstRequest request, final HstResponse response) {
    super.doBeforeRender(request, response);
    // linkPath property contains the relative path of the links property in the published workflow document
    String linkPath = getComponentParameter("linkPath");
    final HstRequestContext context = request.getRequestContext();
    // we assume a Financial as content bean, thus expect a PublishedWork as "parent" document
    Financial financial = context.getContentBean(Financial.class);
    try {
        HstQuery linkedBeanQuery = ContentBeanUtils.createIncomingBeansQuery(financial, context.getSiteContentBaseBean(), linkPath, Publishedwork.class, false);
        // chapter cannot be re-used across different publishedworkflow
        linkedBeanQuery.setLimit(1);
        // linked documents will contain the publishedworkflow document containing all the chapters
        HstQueryResult linkedDocuments = linkedBeanQuery.execute();
        request.setAttribute("linkeddocuments", linkedDocuments);
    } catch (QueryException queryException) {
        log.warn("QueryException ", queryException);
    }
}
Also used : HstQuery(org.hippoecm.hst.content.beans.query.HstQuery) QueryException(org.hippoecm.hst.content.beans.query.exceptions.QueryException) Financial(uk.nhs.digital.website.beans.Financial) HstRequestContext(org.hippoecm.hst.core.request.HstRequestContext) HstQueryResult(org.hippoecm.hst.content.beans.query.HstQueryResult)

Example 9 with HstQueryResult

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

the class CyberAlertResource method fetchCyberAlert.

@GET
@Path("/single/")
public CyberAlert fetchCyberAlert(@Context HttpServletRequest servletRequest, @Context HttpServletResponse servletResponse, @Context UriInfo uriInfo, @PathParam("threatid") String threatid) {
    CyberAlert cyberAlert = null;
    try {
        threatid = servletRequest.getParameter("threatid");
        if (threatid != null) {
            HstRequestContext requestContext = RequestContextProvider.get();
            HstQueryManager hstQueryManager = getHstQueryManager(requestContext.getSession(), requestContext);
            String mountContentPath = requestContext.getResolvedMount().getMount().getContentPath();
            Node mountContentNode = requestContext.getSession().getRootNode().getNode(PathUtils.normalizePath(mountContentPath));
            HstQuery hstQuery = hstQueryManager.createQuery(mountContentNode, CyberAlert.class);
            Filter filter = hstQuery.createFilter();
            filter.addEqualTo("website:threatid", threatid);
            hstQuery.setFilter(filter);
            hstQuery.setLimit(1);
            HstQueryResult result = hstQuery.execute();
            HippoBeanIterator iterator = result.getHippoBeans();
            if (iterator.hasNext()) {
                cyberAlert = (CyberAlert) iterator.nextHippoBean();
            } else {
                JSONObject json = new JSONObject();
                json.put("error", "The threatid=" + threatid + " is not found");
                servletResponse.resetBuffer();
                servletResponse.setStatus(HttpServletResponse.SC_FORBIDDEN);
                servletResponse.setHeader("Content-Type", "application/json");
                servletResponse.setCharacterEncoding("UTF-8");
                servletResponse.getWriter().write(json.toString());
                servletResponse.flushBuffer();
            }
        } else {
            JSONObject json = new JSONObject();
            json.put("error", "The URL is not correct. Use /single?threatid=<threatid>");
            servletResponse.resetBuffer();
            servletResponse.setStatus(HttpServletResponse.SC_FORBIDDEN);
            servletResponse.setHeader("Content-Type", "application/json");
            servletResponse.setCharacterEncoding("UTF-8");
            servletResponse.getWriter().write(json.toString());
            servletResponse.flushBuffer();
        }
    } catch (Exception queryException) {
        log.warn("QueryException ", queryException);
    }
    return cyberAlert;
}
Also used : HstQuery(org.hippoecm.hst.content.beans.query.HstQuery) JSONObject(org.json.simple.JSONObject) Filter(org.hippoecm.hst.content.beans.query.filter.Filter) HippoBeanIterator(org.hippoecm.hst.content.beans.standard.HippoBeanIterator) Node(javax.jcr.Node) HstQueryManager(org.hippoecm.hst.content.beans.query.HstQueryManager) CyberAlert(uk.nhs.digital.website.beans.CyberAlert) HstRequestContext(org.hippoecm.hst.core.request.HstRequestContext) HstQueryResult(org.hippoecm.hst.content.beans.query.HstQueryResult) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 10 with HstQueryResult

use of org.hippoecm.hst.content.beans.query.HstQueryResult 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)

Aggregations

HstQueryResult (org.hippoecm.hst.content.beans.query.HstQueryResult)15 HstQuery (org.hippoecm.hst.content.beans.query.HstQuery)12 QueryException (org.hippoecm.hst.content.beans.query.exceptions.QueryException)10 HstRequestContext (org.hippoecm.hst.core.request.HstRequestContext)9 HippoBean (org.hippoecm.hst.content.beans.standard.HippoBean)7 HippoBeanIterator (org.hippoecm.hst.content.beans.standard.HippoBeanIterator)4 CyberAlert (uk.nhs.digital.website.beans.CyberAlert)3 Node (javax.jcr.Node)2 GET (javax.ws.rs.GET)2 Path (javax.ws.rs.Path)2 HstQueryBuilder (org.hippoecm.hst.content.beans.query.builder.HstQueryBuilder)2 HstComponentException (org.hippoecm.hst.core.component.HstComponentException)2 java.util (java.util)1 IteratorUtils.toList (org.apache.commons.collections.IteratorUtils.toList)1 RequestContextProvider (org.hippoecm.hst.container.RequestContextProvider)1 ObjectBeanManagerException (org.hippoecm.hst.content.beans.ObjectBeanManagerException)1 HstQueryManager (org.hippoecm.hst.content.beans.query.HstQueryManager)1 Constraint (org.hippoecm.hst.content.beans.query.builder.Constraint)1 ConstraintBuilder.constraint (org.hippoecm.hst.content.beans.query.builder.ConstraintBuilder.constraint)1 ConstraintBuilder.or (org.hippoecm.hst.content.beans.query.builder.ConstraintBuilder.or)1