Search in sources :

Example 31 with HippoBean

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

the class SeriesComponent method doBeforeRender.

@Override
public void doBeforeRender(final HstRequest request, final HstResponse response) throws HstComponentException {
    super.doBeforeRender(request, response);
    final HstRequestContext requestContext = request.getRequestContext();
    final HippoBean contentBean = requestContext.getContentBean();
    final Series seriesIndexDocument;
    if (contentBean.isHippoFolderBean()) {
        final List<Series> seriesIndexDocuments = contentBean.getChildBeans(Series.class);
        if (seriesIndexDocuments.size() != 1) {
            reportInvalidTarget(request, contentBean, seriesIndexDocuments.size());
            return;
        }
        seriesIndexDocument = seriesIndexDocuments.get(0);
    } else if (contentBean instanceof Series) {
        seriesIndexDocument = (Series) contentBean;
    } else {
        reportInvalidInvocation(request, contentBean);
        return;
    }
    /* Setting frequency & date naming map on request  */
    final ValueList frequencyValueList = SelectionUtil.getValueListByIdentifier("frequency", RequestContextProvider.get());
    if (frequencyValueList != null) {
        request.setAttribute("frequencyMap", SelectionUtil.valueListAsMap(frequencyValueList));
    }
    final ValueList dateNamingConvention = SelectionUtil.getValueListByIdentifier("datenamingconvention", RequestContextProvider.get());
    if (dateNamingConvention != null) {
        request.setAttribute("dateNamingMap", SelectionUtil.valueListAsMap(dateNamingConvention));
    }
    request.setAttribute("series", seriesIndexDocument);
    try {
        final HstQuery query = requestContext.getQueryManager().createQuery(seriesIndexDocument.getParentBean(), Publication.class, LegacyPublication.class);
        query.addOrderByDescending("publicationsystem:NominalDate");
        final HstQueryResult hstQueryResult = query.execute();
        List<PublicationBase> allPublications = toList(hstQueryResult.getHippoBeans());
        Map<Boolean, List<PublicationBase>> publicationByStatus = allPublications.stream().collect(Collectors.groupingBy(PublicationBase::isPubliclyAccessible));
        List<PublicationBase> livePublications = publicationByStatus.get(true);
        List<PublicationBase> upcomingPublications = publicationByStatus.get(false);
        // Want upcoming in reverse date order to the closest to now is first
        if (!isEmpty(upcomingPublications)) {
            Collections.reverse(upcomingPublications);
        }
        if (!seriesIndexDocument.getShowLatest() && !isEmpty(livePublications)) {
            livePublications.sort(DateComparator.COMPARATOR);
        }
        if (!isEmpty(livePublications) && seriesIndexDocument.getShowLatest()) {
            // removes first publication as the publication available from Series.latestPublication
            livePublications.remove(0);
        }
        request.setAttribute("upcomingPublications", upcomingPublications);
        List<Pair> pastPublicationsAndSeriesChanges = new ArrayList<>();
        for (PublicationBase publicationBase : livePublications) {
            Pair<String, PublicationBase> pair = new Pair("publication", publicationBase, publicationBase.getNominalPublicationDateCalendar());
            pastPublicationsAndSeriesChanges.add(pair);
        }
        if (seriesIndexDocument.getSeriesReplaces() != null) {
            SeriesReplaces seriesReplaces = seriesIndexDocument.getSeriesReplaces();
            if (seriesReplaces.getChangeDate() != null) {
                Pair<String, Series> pair = new Pair("replacedSeries", seriesReplaces, seriesReplaces.getChangeDate().getTime());
                pastPublicationsAndSeriesChanges.add(pair);
            }
        }
        pastPublicationsAndSeriesChanges.sort(Comparator.comparing(Pair::getDate, Comparator.reverseOrder()));
        request.setAttribute("pastPublicationsAndSeriesChanges", pastPublicationsAndSeriesChanges);
    } catch (QueryException queryException) {
        log.error("Failed to find publications for series " + seriesIndexDocument.getTitle(), queryException);
        reportDisplayError(request, seriesIndexDocument.getTitle());
    }
}
Also used : HstQuery(org.hippoecm.hst.content.beans.query.HstQuery) ValueList(org.onehippo.forge.selection.hst.contentbean.ValueList) HstQueryResult(org.hippoecm.hst.content.beans.query.HstQueryResult) HippoBean(org.hippoecm.hst.content.beans.standard.HippoBean) QueryException(org.hippoecm.hst.content.beans.query.exceptions.QueryException) IteratorUtils.toList(org.apache.commons.collections.IteratorUtils.toList) ValueList(org.onehippo.forge.selection.hst.contentbean.ValueList) HstRequestContext(org.hippoecm.hst.core.request.HstRequestContext)

Example 32 with HippoBean

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

the class Person method getBusinessUnits.

public List<BusinessUnit> getBusinessUnits() throws HstComponentException, QueryException {
    Role role = this.getRoles();
    if (role != null) {
        HstQuery query = HstQueryBuilder.create(RequestContextProvider.get().getSiteContentBaseBean()).where(constraint("website:responsiblerole").notEqualTo(null)).ofTypes(BusinessUnit.class).orderByAscending("website:order").build();
        List<BusinessUnit> businessUnits = toList(query.execute().getHippoBeans());
        if (businessUnits.size() > 0) {
            List<BusinessUnit> filteredUnits = new ArrayList<BusinessUnit>();
            for (BusinessUnit unit : businessUnits) {
                List<HippoBean> rolepickers = role.getRolepicker();
                for (HippoBean picker : rolepickers) {
                    if (picker != null) {
                        JobRolePicker rolepicker = (JobRolePicker) picker;
                        CommonFieldsBean jobrole = (CommonFieldsBean) rolepicker.getPrimaryrolepicker();
                        JobRole unitrole = (JobRole) unit.getResponsiblerole();
                        if (jobrole != null && unitrole != null && unitrole.getSingleProperty("jcr:uuid").toString().equals(jobrole.getSingleProperty("jcr:uuid").toString())) {
                            filteredUnits.add(unit);
                        }
                    }
                }
            }
            return filteredUnits;
        }
    }
    return null;
}
Also used : HstQuery(org.hippoecm.hst.content.beans.query.HstQuery) HippoBean(org.hippoecm.hst.content.beans.standard.HippoBean) ArrayList(java.util.ArrayList)

Example 33 with HippoBean

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

the class NotesForEditors method getHtmlnotes.

public List<HippoHtml> getHtmlnotes() {
    List<HippoHtml> notes = new ArrayList<>();
    for (HippoBean bean : getPreparednotes()) {
        EditorsNotes note = (EditorsNotes) bean;
        notes.add(note.getEditorsnote());
    }
    notes.addAll(this.getCustomnotes());
    return notes;
}
Also used : HippoBean(org.hippoecm.hst.content.beans.standard.HippoBean) HippoHtml(org.hippoecm.hst.content.beans.standard.HippoHtml) ArrayList(java.util.ArrayList)

Example 34 with HippoBean

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

the class HubNewsAndEvents method getLatestBlog.

public List<HippoBean> getLatestBlog() throws QueryException {
    HstRequestContext requestContext = RequestContextProvider.get();
    HippoBean scope = requestContext.getSiteContentBaseBean();
    HstQuery hstBlogQuery = HstQueryBuilder.create(scope).ofTypes(Blog.class).orderByDescending("website:dateofpublication").build();
    HstQueryResult blogResult = hstBlogQuery.execute();
    return toList(blogResult.getHippoBeans());
}
Also used : HstQuery(org.hippoecm.hst.content.beans.query.HstQuery) HippoBean(org.hippoecm.hst.content.beans.standard.HippoBean) HstRequestContext(org.hippoecm.hst.core.request.HstRequestContext) HstQueryResult(org.hippoecm.hst.content.beans.query.HstQueryResult)

Example 35 with HippoBean

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

the class HubNewsAndEvents method getLatestNewsArticles.

public List<HippoBean> getLatestNewsArticles() throws QueryException {
    HstRequestContext requestContext = RequestContextProvider.get();
    HippoBean scope = requestContext.getSiteContentBaseBean().getBean("news/latest-news");
    HstQuery hstNewsQuery = HstQueryBuilder.create(scope).ofTypes(News.class).orderByDescending("website:publisheddatetime").build();
    HstQueryResult newsResult = hstNewsQuery.execute();
    return toList(newsResult.getHippoBeans());
}
Also used : HstQuery(org.hippoecm.hst.content.beans.query.HstQuery) HippoBean(org.hippoecm.hst.content.beans.standard.HippoBean) HstRequestContext(org.hippoecm.hst.core.request.HstRequestContext) HstQueryResult(org.hippoecm.hst.content.beans.query.HstQueryResult)

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