use of org.hippoecm.hst.content.beans.query.filter.Filter 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.filter.Filter in project hippo by NHS-digital-website.
the class EventsComponent method addIntervalConstraint.
protected void addIntervalConstraint(final List filters, final HstQuery hstQuery, final String dateField, final HstRequest request) throws FilterException {
Calendar calendar = Calendar.getInstance();
int year = Integer.parseInt(DocumentUtils.findYearOrDefault(getSelectedYear(request), calendar.get(Calendar.YEAR)));
final Filter filter = hstQuery.createFilter();
calendar.set(Calendar.YEAR, year);
filter.addBetween(dateField, calendar, calendar, DateTools.Resolution.YEAR);
filters.add(filter);
}
use of org.hippoecm.hst.content.beans.query.filter.Filter 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.Filter 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.Filter 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