use of org.hippoecm.hst.content.beans.query.filter.BaseFilter in project hippo by NHS-digital-website.
the class CommonFieldsBean method getRelatedEvents.
public List<Event> getRelatedEvents() throws HstComponentException, QueryException {
List<String> linkPaths = new ArrayList<>();
linkPaths.add("website:relatedDocuments/@hippo:docbase");
linkPaths.add("website:peoplementioned/@hippo:docbase");
Filter filter = getInitialQuery(linkPaths, Event.class).createFilter();
Calendar today = Calendar.getInstance();
filter.addGreaterOrEqualThan("website:events/website:enddatetime", today, DateTools.Resolution.DAY);
List<BaseFilter> filters = new ArrayList<BaseFilter>();
filters.add(filter);
return getRelatedDocuments(linkPaths, NO_LIMIT, null, null, Event.class, filters);
}
use of org.hippoecm.hst.content.beans.query.filter.BaseFilter in project hippo by NHS-digital-website.
the class CommonFieldsBean method applyRestrictionsToQuery.
private void applyRestrictionsToQuery(HstQuery query, int limit, String orderBy, String orderDirection, List<BaseFilter> andFilters) {
if (limit > NO_LIMIT) {
query.setLimit(limit);
}
if (orderBy != null) {
if (orderDirection == "ascending") {
query.addOrderByAscending(orderBy);
} else {
query.addOrderByDescending(orderBy);
}
}
// applying AND filters
if (andFilters != null && andFilters.size() > 0) {
Filter initFilter = (Filter) query.getFilter();
Filter mainFilter = query.createFilter();
mainFilter.addAndFilter(initFilter);
for (BaseFilter filter : andFilters) {
mainFilter.addAndFilter(filter);
}
query.setFilter(mainFilter);
}
}
use of org.hippoecm.hst.content.beans.query.filter.BaseFilter 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);
}
}
use of org.hippoecm.hst.content.beans.query.filter.BaseFilter in project hippo by NHS-digital-website.
the class ProjectUpdateFeedComponent method addUpdateTypeFilter.
private void addUpdateTypeFilter(List<BaseFilter> filters, String updateType, HstQuery query) {
if (StringUtils.isNotBlank(updateType)) {
Filter filter = query.createFilter();
try {
filter.addEqualTo("website:typeofupdate", updateType);
filters.add(filter);
} catch (final FilterException exception) {
log.error("Error trying to add type of update filter", exception);
}
}
}
use of org.hippoecm.hst.content.beans.query.filter.BaseFilter in project hippo by NHS-digital-website.
the class SupplementaryInformationHubComponent method contributeAndFilters.
@Override
protected void contributeAndFilters(List<BaseFilter> filters, HstRequest request, HstQuery query) throws FilterException {
super.contributeAndFilters(filters, request, query);
// Add year filter
final String selectedYear = DocumentUtils.findYearOrDefault(getSelectedYear(request), Calendar.getInstance().get(Calendar.YEAR));
final Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.YEAR, Integer.parseInt(selectedYear));
Filter yearFilter = query.createFilter();
try {
yearFilter.addEqualTo("publicationsystem:NominalDate", calendar, DateTools.Resolution.YEAR);
filters.add(yearFilter);
} catch (final FilterException exception) {
log.error("Error trying to add year filter", exception);
}
// Add month filter
final Month selectedMonth = findMonthOrNull(getSelectedMonth(request));
if (Objects.nonNull(selectedMonth)) {
calendar.set(Calendar.MONTH, calenderMonthOrdinate(selectedMonth));
Filter monthFilter = query.createFilter();
try {
monthFilter.addEqualTo("publicationsystem:NominalDate", calendar, DateTools.Resolution.MONTH);
filters.add(monthFilter);
} catch (final FilterException exception) {
log.error("Error trying to add year filter", exception);
}
}
}
Aggregations