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;
}
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);
}
}
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);
}
}
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;
}
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;
}
Aggregations