use of org.hippoecm.hst.content.beans.query.HstQueryResult 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.HstQueryResult in project hippo by NHS-digital-website.
the class HubNewsAndEvents method getLatestBlog.
public List<HippoBean> getLatestBlog() throws QueryException {
HstRequestContext requestContext = RequestContextProvider.get();
HippoBean scope = requestContext.getSiteContentBaseBean();
HstQuery hstBlogQuery = HstQueryBuilder.create(scope).ofTypes(Blog.class).orderByDescending("website:dateofpublication").build();
HstQueryResult blogResult = hstBlogQuery.execute();
return toList(blogResult.getHippoBeans());
}
use of org.hippoecm.hst.content.beans.query.HstQueryResult in project hippo by NHS-digital-website.
the class HubNewsAndEvents method getLatestNewsArticles.
public List<HippoBean> getLatestNewsArticles() throws QueryException {
HstRequestContext requestContext = RequestContextProvider.get();
HippoBean scope = requestContext.getSiteContentBaseBean().getBean("news/latest-news");
HstQuery hstNewsQuery = HstQueryBuilder.create(scope).ofTypes(News.class).orderByDescending("website:publisheddatetime").build();
HstQueryResult newsResult = hstNewsQuery.execute();
return toList(newsResult.getHippoBeans());
}
use of org.hippoecm.hst.content.beans.query.HstQueryResult in project hippo by NHS-digital-website.
the class BloomreachSearchProvider method getBloomreachResults.
public Pageable<HippoBean> getBloomreachResults(String queryString, int pageSize, int currentPage, SearchArea searchArea) {
HstQuery query = getQuery(queryString, searchArea);
query.setLimit(pageSize);
query.setOffset((currentPage - 1) * pageSize);
if (queryString == null) {
query.addOrderByDescending("hippostdpubwf:lastModificationDate");
}
try {
final HstQueryResult execute = query.execute();
return pageableFactory.createPageable(execute.getHippoBeans(), execute.getTotalSize(), pageSize, currentPage);
} catch (QueryException e) {
LOG.error("Error running query: {}", e.getMessage());
LOG.debug("Query exception: ", e);
return null;
}
}
use of org.hippoecm.hst.content.beans.query.HstQueryResult in project hippo by NHS-digital-website.
the class PublicationBase method getDatasets.
public List<Dataset> getDatasets() throws HstComponentException {
assertPropertyPermitted(PropertyKeys.DATASETS);
HstQueryResult hstQueryResult;
try {
hstQueryResult = HstQueryBuilder.create(getParentBean()).ofTypes(Dataset.class).build().execute();
} catch (QueryException queryException) {
log.error("Failed to find datasets for publication " + getCanonicalPath(), queryException);
throw new HstComponentException("Failed to find datasets for publication " + getCanonicalPath(), queryException);
}
ArrayList<Dataset> hippoBeans = Lists.newArrayList((Iterator) hstQueryResult.getHippoBeans());
hippoBeans.sort(DocumentTitleComparator.COMPARATOR);
return hippoBeans;
}
Aggregations