use of org.hippoecm.hst.content.beans.query.exceptions.QueryException 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.exceptions.QueryException 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.exceptions.QueryException 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.exceptions.QueryException in project hippo by NHS-digital-website.
the class PolicyPage method getPolicy.
public Policy getPolicy() {
final HstRequestContext context = RequestContextProvider.get();
try {
HstQuery linkedBeanQuery = ContentBeanUtils.createIncomingBeansQuery(this.getCanonicalBean(), context.getSiteContentBaseBean(), "website:childPage/@hippo:docbase", Policy.class, false);
linkedBeanQuery.setLimit(1);
return (Policy) linkedBeanQuery.execute().getHippoBeans().nextHippoBean();
} catch (QueryException queryException) {
log.warn("QueryException ", queryException);
}
return null;
}
use of org.hippoecm.hst.content.beans.query.exceptions.QueryException in project hippo by NHS-digital-website.
the class FeedHubComponent method doBeforeRender.
@Override
public void doBeforeRender(final HstRequest request, final HstResponse response) throws HstComponentException {
super.doBeforeRender(request, response);
filters = new ArrayList<>();
filterValues = new HashMap<>();
String[] yearParams = getPublicRequestParameters(request, "year");
filterValues.put("year", yearParams);
if (yearParams.length > 0) {
filterValues.put("month", getPublicRequestParameters(request, "month"));
}
filterValues.put("type[]", getPublicRequestParameters(request, "type[]"));
filterValues.put("severity", getPublicRequestParameters(request, "severity"));
request.setAttribute("filterValues", filterValues);
long filterCount = filterValues.values().stream().filter(value -> value.length > 0).count();
request.setAttribute("filterCount", filterCount);
queryText = getPublicRequestParameter(request, "query");
if (queryText == null) {
queryText = "";
}
request.setAttribute("query", queryText);
sort = getPublicRequestParameter(request, "sort");
if (sort == null) {
sort = "date-desc";
}
request.setAttribute("sort", sort);
String activeFiltersString = getPublicRequestParameter(request, "active-filters");
if (activeFiltersString != null) {
String[] activeFilters = activeFiltersString.split(",");
request.setAttribute("activeFilters", activeFilters);
}
try {
List<HippoBean> feed = getFeed(request);
request.setAttribute("feed", feed);
Pageable<HippoBean> pagedFeed = pageResults(feed, request);
request.setAttribute("pageable", pagedFeed);
final HstRequestContext context = request.getRequestContext();
FeedHub feedHub = (FeedHub) context.getContentBean();
switch(feedHub.getFeedType()) {
case "News":
getNewsFilters(feed);
break;
case "Supplementary information":
getSupInfoFilters(feed);
break;
case "Events":
getEventFilters(feed);
break;
case "Cyber Alerts":
getCyberAlertFilters(feed);
break;
default:
}
request.setAttribute("filters", filters);
} catch (QueryException e) {
e.printStackTrace();
}
}
Aggregations