Search in sources :

Example 41 with HippoBean

use of org.hippoecm.hst.content.beans.standard.HippoBean in project hippo by NHS-digital-website.

the class FeedHubComponent method getEventFilters.

private void getEventFilters(List<HippoBean> eventFeed) throws QueryException {
    Map<String, Long> yearFilters = eventFeed.stream().map(e -> (Event) e).flatMap(e -> e.getEvents().parallelStream().map(Interval::getStartdatetime).map(date -> String.valueOf(date.get(Calendar.YEAR))).distinct()).collect(Collectors.groupingBy(Function.identity(), Collectors.counting()));
    addFilter("Year", "year", yearFilters);
    if (yearFilters.size() > 0 && filterValues.get("year").length > 0) {
        Map<String, Long> monthFilters = eventFeed.stream().map(e -> (Event) e).flatMap(e -> e.getEvents().parallelStream().map(Interval::getStartdatetime).map(date -> new SimpleDateFormat("MMMMM").format(date.getTime())).distinct()).collect(Collectors.groupingBy(Function.identity(), Collectors.counting()));
        addFilter("Month", "month", monthFilters);
    }
    Map<String, Long> typeFilters = eventFeed.stream().map(e -> (Event) e).flatMap(e -> Arrays.stream(e.getType())).collect(Collectors.groupingBy(Function.identity(), Collectors.counting()));
    addFilter("Type", "type[]", typeFilters);
}
Also used : Pageable(org.onehippo.cms7.essentials.components.paging.Pageable) java.util(java.util) HstRequestContext(org.hippoecm.hst.core.request.HstRequestContext) HippoBeanIterator(org.hippoecm.hst.content.beans.standard.HippoBeanIterator) HstComponentException(org.hippoecm.hst.core.component.HstComponentException) HstRequest(org.hippoecm.hst.core.component.HstRequest) IteratorUtils.toList(org.apache.commons.collections.IteratorUtils.toList) ConstraintBuilder.or(org.hippoecm.hst.content.beans.query.builder.ConstraintBuilder.or) HstResponse(org.hippoecm.hst.core.component.HstResponse) SimpleDateFormat(java.text.SimpleDateFormat) ConstraintBuilder.and(org.hippoecm.hst.content.beans.query.builder.ConstraintBuilder.and) uk.nhs.digital.website.beans(uk.nhs.digital.website.beans) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) HippoBean(org.hippoecm.hst.content.beans.standard.HippoBean) DateTools(org.hippoecm.repository.util.DateTools) Constraint(org.hippoecm.hst.content.beans.query.builder.Constraint) QueryException(org.hippoecm.hst.content.beans.query.exceptions.QueryException) RequestContextProvider(org.hippoecm.hst.container.RequestContextProvider) ParseException(java.text.ParseException) ConstraintBuilder.constraint(org.hippoecm.hst.content.beans.query.builder.ConstraintBuilder.constraint) HstQueryBuilder(org.hippoecm.hst.content.beans.query.builder.HstQueryBuilder) SimpleDateFormat(java.text.SimpleDateFormat)

Example 42 with HippoBean

use of org.hippoecm.hst.content.beans.standard.HippoBean in project hippo by NHS-digital-website.

the class FeedHubComponent method getFeed.

private <T extends HippoBean> List<T> getFeed(HstRequest request) throws QueryException {
    final HstRequestContext context = request.getRequestContext();
    FeedHub feedHub = (FeedHub) context.getContentBean();
    HippoBean folder = feedHub.getParentBean();
    ArrayList<Constraint> constraints = new ArrayList<>();
    if ("Site-wide documents".equalsIgnoreCase(feedHub.getHubType())) {
        folder = RequestContextProvider.get().getSiteContentBaseBean();
        if (feedHub.getFeedType().equals("Cyber Alerts")) {
            constraints.add(constraint("website:publicallyaccessible").equalTo(true));
        } else if (!feedHub.getFeedType().equals("Supplementary information")) {
            constraints.add(constraint("website:display").equalTo(true));
        }
    }
    String dateField = "website:publisheddatetime";
    Class feedClass = null;
    switch(feedHub.getFeedType()) {
        case "News":
            feedClass = News.class;
            if (filterValues.get("year").length > 0) {
                Calendar newsDateFilter = Calendar.getInstance();
                newsDateFilter.set(Calendar.YEAR, Integer.parseInt(filterValues.get("year")[0]));
                newsDateFilter.set(Calendar.DAY_OF_YEAR, 1);
                constraints.add(constraint(dateField).equalTo(newsDateFilter, DateTools.Resolution.YEAR));
            }
            break;
        case "Events":
            feedClass = Event.class;
            dateField = "website:events/@website:startdatetime";
            if (filterValues.get("year").length > 0) {
                Calendar eventsDateFilter = Calendar.getInstance();
                eventsDateFilter.set(Calendar.YEAR, Integer.parseInt(filterValues.get("year")[0]));
                eventsDateFilter.set(Calendar.DAY_OF_YEAR, 1);
                constraints.add(constraint("website:events/website:startdatetime").equalTo(eventsDateFilter, DateTools.Resolution.YEAR));
                if (filterValues.get("month").length > 0) {
                    Integer month = getMonth(filterValues.get("month")[0]);
                    if (month != null) {
                        eventsDateFilter.set(Calendar.MONTH, month);
                        eventsDateFilter.set(Calendar.DAY_OF_MONTH, 1);
                        constraints.add(constraint("website:events/website:startdatetime").equalTo(eventsDateFilter, DateTools.Resolution.MONTH));
                    }
                }
            }
            if (filterValues.get("type[]").length > 0) {
                String[] types = filterValues.get("type[]");
                for (String type : types) {
                    constraints.add(constraint("website:type").equalTo(type));
                }
            }
            break;
        case "Cyber Alerts":
            feedClass = CyberAlert.class;
            dateField = "publicationsystem:NominalDate";
            if (filterValues.get("year").length > 0) {
                Calendar cyberAlertsDateFilter = Calendar.getInstance();
                cyberAlertsDateFilter.set(Calendar.YEAR, Integer.parseInt(filterValues.get("year")[0]));
                cyberAlertsDateFilter.set(Calendar.DAY_OF_YEAR, 1);
                constraints.add(constraint(dateField).equalTo(cyberAlertsDateFilter, DateTools.Resolution.YEAR));
            }
            if (filterValues.get("type[]").length > 0) {
                String[] types = filterValues.get("type[]");
                for (String type : types) {
                    constraints.add(constraint("website:threattype").equalTo(type));
                }
            }
            if (filterValues.get("severity").length > 0) {
                constraints.add(constraint("website:severity").equalTo(filterValues.get("severity")[0]));
            }
            break;
        case "Supplementary information":
            feedClass = SupplementaryInformation.class;
            dateField = "publicationsystem:NominalDate";
            if (filterValues.get("year").length > 0) {
                Calendar supplimentaryInfoDateFilter = Calendar.getInstance();
                String year = filterValues.get("year")[0];
                if (year.equals("Unknown")) {
                    constraints.add(constraint(dateField).notExists());
                } else {
                    supplimentaryInfoDateFilter.set(Calendar.YEAR, Integer.parseInt(year));
                    supplimentaryInfoDateFilter.set(Calendar.DAY_OF_YEAR, 1);
                    DateTools.Resolution dateResolution = DateTools.Resolution.YEAR;
                    if (filterValues.get("month").length > 0) {
                        Integer month = getMonth(filterValues.get("month")[0]);
                        if (month != null) {
                            supplimentaryInfoDateFilter.set(Calendar.MONTH, month);
                            supplimentaryInfoDateFilter.set(Calendar.DAY_OF_MONTH, 1);
                            dateResolution = DateTools.Resolution.MONTH;
                        }
                    }
                    constraints.add(constraint(dateField).equalTo(supplimentaryInfoDateFilter, dateResolution));
                }
            }
            break;
        default:
    }
    if (queryText != null && !queryText.isEmpty()) {
        constraints.add(or(constraint("website:title").contains(queryText), constraint("website:shortsummary").contains(queryText)));
    }
    HstQueryBuilder query = HstQueryBuilder.create(folder);
    query.where(and(constraints.toArray(new Constraint[0]))).ofTypes(feedClass);
    if (sort.equals("date-asc")) {
        query.orderByAscending(dateField);
    } else {
        query.orderByDescending(dateField);
    }
    HippoBeanIterator beanIterator = query.build().execute().getHippoBeans();
    return toList(beanIterator);
}
Also used : Constraint(org.hippoecm.hst.content.beans.query.builder.Constraint) HippoBeanIterator(org.hippoecm.hst.content.beans.standard.HippoBeanIterator) HippoBean(org.hippoecm.hst.content.beans.standard.HippoBean) DateTools(org.hippoecm.repository.util.DateTools) HstQueryBuilder(org.hippoecm.hst.content.beans.query.builder.HstQueryBuilder) HstRequestContext(org.hippoecm.hst.core.request.HstRequestContext)

Example 43 with HippoBean

use of org.hippoecm.hst.content.beans.standard.HippoBean in project hippo by NHS-digital-website.

the class BannerComponent method doBeforeRender.

@Override
public void doBeforeRender(HstRequest request, HstResponse response) {
    super.doBeforeRender(request, response);
    EssentialsBannerComponentInfo componentInfo = getComponentParametersInfo(request);
    HippoBean document = getHippoBeanForPath(componentInfo.getDocument(), HippoBean.class);
    request.setAttribute("document", document);
    request.setAttribute("cparam", componentInfo);
    DocumentUtils.setMetaTags(request, this);
}
Also used : HippoBean(org.hippoecm.hst.content.beans.standard.HippoBean) EssentialsBannerComponentInfo(org.onehippo.cms7.essentials.components.info.EssentialsBannerComponentInfo)

Example 44 with HippoBean

use of org.hippoecm.hst.content.beans.standard.HippoBean in project hippo by NHS-digital-website.

the class Series method getLatestPublication.

public Publication getLatestPublication() throws HstComponentException, QueryException {
    if (!getShowLatest()) {
        return null;
    }
    HippoBean folder = getCanonicalBean().getParentBean();
    HippoBeanIterator hippoBeans = HstQueryBuilder.create(folder).ofTypes(Publication.class).orderByDescending("publicationsystem:NominalDate").build().execute().getHippoBeans();
    boolean found = false;
    Publication publication = null;
    while (!found && hippoBeans.hasNext()) {
        HippoBean hippoBean = hippoBeans.nextHippoBean();
        publication = (Publication) hippoBean;
        found = publication.isPubliclyAccessible();
    }
    if (found) {
        return publication;
    }
    return null;
}
Also used : HippoBean(org.hippoecm.hst.content.beans.standard.HippoBean) HippoBeanIterator(org.hippoecm.hst.content.beans.standard.HippoBeanIterator)

Example 45 with HippoBean

use of org.hippoecm.hst.content.beans.standard.HippoBean in project hippo by NHS-digital-website.

the class CiBreadcrumbProvider method addDatasetBreadcrumbItem.

private void addDatasetBreadcrumbItem(List<BreadcrumbItem> ciBreadcrumbItems) {
    // get Dataset's parent publication
    HippoBean datasetParent = ((Dataset) currentDocumentBean).getParentPublication();
    if (datasetParent != null) {
        Publication publication = (Publication) datasetParent;
        // Is publication part of archive/series?
        HippoBean publicationParent = publication.getParentDocument();
        if (publicationParent != null) {
            // Create Archive/Series navigation
            BaseDocument seriesOrArchiveDocument = (BaseDocument) publicationParent;
            ciBreadcrumbItems.add(createBreadcrumbItem(ctx, seriesOrArchiveDocument));
        }
        // Create Publication navigation
        ciBreadcrumbItems.add(createBreadcrumbItem(ctx, publication));
    }
}
Also used : HippoBean(org.hippoecm.hst.content.beans.standard.HippoBean)

Aggregations

HippoBean (org.hippoecm.hst.content.beans.standard.HippoBean)46 QueryException (org.hippoecm.hst.content.beans.query.exceptions.QueryException)10 HstRequestContext (org.hippoecm.hst.core.request.HstRequestContext)10 ArrayList (java.util.ArrayList)7 HstQuery (org.hippoecm.hst.content.beans.query.HstQuery)7 HippoBeanIterator (org.hippoecm.hst.content.beans.standard.HippoBeanIterator)7 HstQueryResult (org.hippoecm.hst.content.beans.query.HstQueryResult)6 HstQueryBuilder (org.hippoecm.hst.content.beans.query.builder.HstQueryBuilder)5 HstComponentException (org.hippoecm.hst.core.component.HstComponentException)5 SimpleDateFormat (java.text.SimpleDateFormat)4 java.util (java.util)4 Collectors (java.util.stream.Collectors)4 IteratorUtils.toList (org.apache.commons.collections.IteratorUtils.toList)4 RequestContextProvider (org.hippoecm.hst.container.RequestContextProvider)4 Constraint (org.hippoecm.hst.content.beans.query.builder.Constraint)4 DateTools (org.hippoecm.repository.util.DateTools)4 ParseException (java.text.ParseException)3 Function (java.util.function.Function)3 Node (javax.jcr.Node)3 ConstraintBuilder.and (org.hippoecm.hst.content.beans.query.builder.ConstraintBuilder.and)3