use of org.hippoecm.hst.content.beans.query.HstQuery 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.HstQuery 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.HstQuery 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;
}
use of org.hippoecm.hst.content.beans.query.HstQuery in project hippo by NHS-digital-website.
the class SeriesComponent 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 Series seriesIndexDocument;
if (contentBean.isHippoFolderBean()) {
final List<Series> seriesIndexDocuments = contentBean.getChildBeans(Series.class);
if (seriesIndexDocuments.size() != 1) {
reportInvalidTarget(request, contentBean, seriesIndexDocuments.size());
return;
}
seriesIndexDocument = seriesIndexDocuments.get(0);
} else if (contentBean instanceof Series) {
seriesIndexDocument = (Series) contentBean;
} else {
reportInvalidInvocation(request, contentBean);
return;
}
/* Setting frequency & date naming map on request */
final ValueList frequencyValueList = SelectionUtil.getValueListByIdentifier("frequency", RequestContextProvider.get());
if (frequencyValueList != null) {
request.setAttribute("frequencyMap", SelectionUtil.valueListAsMap(frequencyValueList));
}
final ValueList dateNamingConvention = SelectionUtil.getValueListByIdentifier("datenamingconvention", RequestContextProvider.get());
if (dateNamingConvention != null) {
request.setAttribute("dateNamingMap", SelectionUtil.valueListAsMap(dateNamingConvention));
}
request.setAttribute("series", seriesIndexDocument);
try {
final HstQuery query = requestContext.getQueryManager().createQuery(seriesIndexDocument.getParentBean(), Publication.class, LegacyPublication.class);
query.addOrderByDescending("publicationsystem:NominalDate");
final HstQueryResult hstQueryResult = query.execute();
List<PublicationBase> allPublications = toList(hstQueryResult.getHippoBeans());
Map<Boolean, List<PublicationBase>> publicationByStatus = allPublications.stream().collect(Collectors.groupingBy(PublicationBase::isPubliclyAccessible));
List<PublicationBase> livePublications = publicationByStatus.get(true);
List<PublicationBase> upcomingPublications = publicationByStatus.get(false);
// Want upcoming in reverse date order to the closest to now is first
if (!isEmpty(upcomingPublications)) {
Collections.reverse(upcomingPublications);
}
if (!seriesIndexDocument.getShowLatest() && !isEmpty(livePublications)) {
livePublications.sort(DateComparator.COMPARATOR);
}
if (!isEmpty(livePublications) && seriesIndexDocument.getShowLatest()) {
// removes first publication as the publication available from Series.latestPublication
livePublications.remove(0);
}
request.setAttribute("upcomingPublications", upcomingPublications);
List<Pair> pastPublicationsAndSeriesChanges = new ArrayList<>();
for (PublicationBase publicationBase : livePublications) {
Pair<String, PublicationBase> pair = new Pair("publication", publicationBase, publicationBase.getNominalPublicationDateCalendar());
pastPublicationsAndSeriesChanges.add(pair);
}
if (seriesIndexDocument.getSeriesReplaces() != null) {
SeriesReplaces seriesReplaces = seriesIndexDocument.getSeriesReplaces();
if (seriesReplaces.getChangeDate() != null) {
Pair<String, Series> pair = new Pair("replacedSeries", seriesReplaces, seriesReplaces.getChangeDate().getTime());
pastPublicationsAndSeriesChanges.add(pair);
}
}
pastPublicationsAndSeriesChanges.sort(Comparator.comparing(Pair::getDate, Comparator.reverseOrder()));
request.setAttribute("pastPublicationsAndSeriesChanges", pastPublicationsAndSeriesChanges);
} catch (QueryException queryException) {
log.error("Failed to find publications for series " + seriesIndexDocument.getTitle(), queryException);
reportDisplayError(request, seriesIndexDocument.getTitle());
}
}
use of org.hippoecm.hst.content.beans.query.HstQuery in project hippo by NHS-digital-website.
the class CommonFieldsBean method getInitialQuery.
protected <T extends HippoBean> HstQuery getInitialQuery(List<String> properties, Class<T> beanClass) throws HstComponentException, QueryException {
final HstRequestContext context = RequestContextProvider.get();
HstQuery query = ContentBeanUtils.createIncomingBeansQuery(this.getCanonicalBean(), context.getSiteContentBaseBean(), properties, beanClass, false);
return query;
}
Aggregations