Search in sources :

Example 1 with BaseFilter

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);
}
Also used : Filter(org.hippoecm.hst.content.beans.query.filter.Filter) BaseFilter(org.hippoecm.hst.content.beans.query.filter.BaseFilter) Calendar(java.util.Calendar) ArrayList(java.util.ArrayList) BaseFilter(org.hippoecm.hst.content.beans.query.filter.BaseFilter)

Example 2 with BaseFilter

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);
    }
}
Also used : Filter(org.hippoecm.hst.content.beans.query.filter.Filter) BaseFilter(org.hippoecm.hst.content.beans.query.filter.BaseFilter) BaseFilter(org.hippoecm.hst.content.beans.query.filter.BaseFilter)

Example 3 with BaseFilter

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);
    }
}
Also used : HstQuery(org.hippoecm.hst.content.beans.query.HstQuery) HippoDocument(org.hippoecm.hst.content.beans.standard.HippoDocument) QueryException(org.hippoecm.hst.content.beans.query.exceptions.QueryException) BaseFilter(org.hippoecm.hst.content.beans.query.filter.BaseFilter) Filter(org.hippoecm.hst.content.beans.query.filter.Filter) HippoBeanIterator(org.hippoecm.hst.content.beans.standard.HippoBeanIterator) HstRequestContext(org.hippoecm.hst.core.request.HstRequestContext)

Example 4 with BaseFilter

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);
        }
    }
}
Also used : BaseFilter(org.hippoecm.hst.content.beans.query.filter.BaseFilter) Filter(org.hippoecm.hst.content.beans.query.filter.Filter) FilterException(org.hippoecm.hst.content.beans.query.exceptions.FilterException)

Example 5 with BaseFilter

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);
        }
    }
}
Also used : Month(java.time.Month) Filter(org.hippoecm.hst.content.beans.query.filter.Filter) BaseFilter(org.hippoecm.hst.content.beans.query.filter.BaseFilter) FilterException(org.hippoecm.hst.content.beans.query.exceptions.FilterException)

Aggregations

BaseFilter (org.hippoecm.hst.content.beans.query.filter.BaseFilter)11 Filter (org.hippoecm.hst.content.beans.query.filter.Filter)11 FilterException (org.hippoecm.hst.content.beans.query.exceptions.FilterException)7 HstQuery (org.hippoecm.hst.content.beans.query.HstQuery)3 QueryException (org.hippoecm.hst.content.beans.query.exceptions.QueryException)3 ArrayList (java.util.ArrayList)2 Calendar (java.util.Calendar)2 HstQueryBuilder (org.hippoecm.hst.content.beans.query.builder.HstQueryBuilder)2 FeedListComponentInfo (uk.nhs.digital.common.components.info.FeedListComponentInfo)2 Month (java.time.Month)1 HippoBeanIterator (org.hippoecm.hst.content.beans.standard.HippoBeanIterator)1 HippoDocument (org.hippoecm.hst.content.beans.standard.HippoDocument)1 HstRequestContext (org.hippoecm.hst.core.request.HstRequestContext)1 EssentialsEventsComponentInfo (org.onehippo.cms7.essentials.components.info.EssentialsEventsComponentInfo)1