use of org.hippoecm.hst.content.beans.query.exceptions.QueryException in project hippo by NHS-digital-website.
the class RssModifier method modifyHstQuery.
@Override
public void modifyHstQuery(final HstRequestContext context, final HstQuery query, final RSS20FeedDescriptor descriptor) {
try {
String strQuery = query.getQueryAsString(true);
if (strQuery.contains("jcr:primaryType=\'website:news\'")) {
Calendar calendar = Calendar.getInstance();
calendar.add(Calendar.MONTH, -3);
Filter filter = query.createFilter();
try {
filter.addGreaterOrEqualThan("website:publisheddatetime", calendar, DateTools.Resolution.DAY);
query.setFilter(filter);
} catch (final FilterException exception) {
exception.printStackTrace();
}
} else if (strQuery.contains("jcr:primaryType=\'publicationsystem:publication\'")) {
Calendar calendar = Calendar.getInstance();
calendar.add(Calendar.MONTH, -1);
Filter filter = query.createFilter();
try {
filter.addGreaterOrEqualThan("publicationsystem:NominalDate", calendar, DateTools.Resolution.DAY);
filter.addEqualTo("publicationsystem:PubliclyAccessible", true);
query.setFilter(filter);
} catch (final FilterException exception) {
exception.printStackTrace();
}
}
} catch (QueryException e) {
e.printStackTrace();
}
}
use of org.hippoecm.hst.content.beans.query.exceptions.QueryException in project hippo by NHS-digital-website.
the class CyberAlertComponent method doBeforeRender.
@Override
public void doBeforeRender(HstRequest request, HstResponse response) {
super.doBeforeRender(request, response);
final CyberAlertComponentInfo componentParametersInfo = getComponentParametersInfo(request);
final int configuredAlertSize = componentParametersInfo.getNumberOfAlertsToDisplay();
request.setAttribute("title", componentParametersInfo.getTitle());
try {
final HippoBean baseContentBean = request.getRequestContext().getSiteContentBaseBean();
final HippoBean cyberAlertScope = (HippoBean) request.getRequestContext().getObjectBeanManager().getObject(baseContentBean.getPath() + "/cyber-alerts");
HstQueryBuilder builder = HstQueryBuilder.create(cyberAlertScope);
HstQueryResult alertsQueryResult = builder.ofTypes(CyberAlert.class).orderByDescending("publicationsystem:NominalDate").build().execute();
List<CyberAlert> alertsListToDisplay;
if (alertsQueryResult != null && configuredAlertSize > 0) {
alertsListToDisplay = createCyberAlertsList(configuredAlertSize, alertsQueryResult);
request.setAttribute("cyberAlertList", alertsListToDisplay);
}
} catch (QueryException | ObjectBeanManagerException e) {
LOGGER.error("Failed to execute Cyber Alerts Query ", e);
}
}
use of org.hippoecm.hst.content.beans.query.exceptions.QueryException in project hippo by NHS-digital-website.
the class FeedHubComponent method getSupInfoFilters.
private void getSupInfoFilters(List<HippoBean> supInfoFeed) throws QueryException {
Map<String, Long> yearFilters = supInfoFeed.stream().map(e -> (SupplementaryInformation) e).map(SupplementaryInformation::getPublishedDate).map(e -> e != null ? String.valueOf(e.get(Calendar.YEAR)) : "Unknown").collect(Collectors.groupingBy(Function.identity(), Collectors.counting()));
addFilter("Year", "year", yearFilters);
if (yearFilters.size() > 0 && filterValues.get("year").length > 0) {
Map<String, Long> monthFilters = supInfoFeed.stream().map(e -> (SupplementaryInformation) e).map(SupplementaryInformation::getPublishedDate).filter(Objects::nonNull).map(e -> new SimpleDateFormat("MMMMM").format(e.getTime())).collect(Collectors.groupingBy(Function.identity(), Collectors.counting()));
addFilter("Month", "month", monthFilters);
}
}
use of org.hippoecm.hst.content.beans.query.exceptions.QueryException in project hippo by NHS-digital-website.
the class Publishedworkchapter method getPublishedWork.
public Publishedwork getPublishedWork() {
final HstRequestContext context = RequestContextProvider.get();
// Publishedworkchapter publishedWorkChapter = context.getContentBean(Publishedworkchapter.class);
try {
HstQuery linkedBeanQuery = ContentBeanUtils.createIncomingBeansQuery(this.getCanonicalBean(), context.getSiteContentBaseBean(), "website:links/@hippo:docbase", Publishedwork.class, false);
linkedBeanQuery.setLimit(1);
return (Publishedwork) 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 ProjectUpdateFeedComponent method addOrganisationFilter.
private void addOrganisationFilter(List<BaseFilter> filters, HstRequest request, HstQuery query) {
String organisationTitle = getSelectedOrganisationTitle(request);
if (StringUtils.isNotBlank(organisationTitle)) {
HippoBeanIterator organisationBeans;
try {
final HstRequestContext requestContext = request.getRequestContext();
HstQuery orgQuery = requestContext.getQueryManager().createQuery(requestContext.getSiteContentBaseBean(), Organisation.class);
Filter orgNameFilter = orgQuery.createFilter();
orgNameFilter.addEqualToCaseInsensitive("website:title", organisationTitle);
orgQuery.setFilter(orgNameFilter);
organisationBeans = orgQuery.execute().getHippoBeans();
} catch (QueryException e) {
log.debug("Error finding organisation with title {}: {}", organisationTitle, e);
return;
}
if (organisationBeans.getSize() == 0) {
return;
}
String jcrQuery;
if (organisationBeans.getSize() > 1) {
StringBuilder jcrQueryBuilder = new StringBuilder(String.format("((website:organisation/@hippo:docbase = '%s')", ((HippoDocument) organisationBeans.nextHippoBean()).getCanonicalHandleUUID()));
while (organisationBeans.hasNext()) {
jcrQueryBuilder.append(String.format(" or (website:organisation/@hippo:docbase = '%s')", ((HippoDocument) organisationBeans.nextHippoBean()).getCanonicalHandleUUID()));
}
jcrQueryBuilder.append(")");
jcrQuery = jcrQueryBuilder.toString();
} else {
jcrQuery = String.format("(website:organisation/@hippo:docbase = '%s')", ((HippoDocument) organisationBeans.nextHippoBean()).getCanonicalHandleUUID());
}
Filter filter = query.createFilter();
filter.addJCRExpression(jcrQuery);
filters.add(filter);
}
}
Aggregations