Search in sources :

Example 1 with ValueList

use of org.onehippo.forge.selection.hst.contentbean.ValueList in project hippo by NHS-digital-website.

the class EventsComponent method doBeforeRender.

@Override
public void doBeforeRender(HstRequest request, HstResponse response) {
    super.doBeforeRender(request, response);
    // sending the eventstype values
    final ValueList eventsTypeValueList = SelectionUtil.getValueListByIdentifier("eventstype", RequestContextProvider.get());
    if (eventsTypeValueList != null) {
        request.setAttribute("eventstype", SelectionUtil.valueListAsMap(eventsTypeValueList));
    }
    String[] selectedTypes = getPublicRequestParameters(request, "type");
    request.setAttribute("selectedTypes", Arrays.asList(selectedTypes));
    request.setAttribute("selectedYear", DocumentUtils.findYearOrDefault(getSelectedYear(request), Calendar.getInstance().get(Calendar.YEAR)));
    request.setAttribute("years", years());
}
Also used : ValueList(org.onehippo.forge.selection.hst.contentbean.ValueList)

Example 2 with ValueList

use of org.onehippo.forge.selection.hst.contentbean.ValueList in project hippo by NHS-digital-website.

the class NewsArticleComponent method doBeforeRender.

@Override
public void doBeforeRender(HstRequest request, HstResponse response) {
    super.doBeforeRender(request, response);
    final ValueList creditbannerValueList = SelectionUtil.getValueListByIdentifier("creditbanner", RequestContextProvider.get());
    if (creditbannerValueList != null) {
        request.setAttribute("creditbanner", SelectionUtil.valueListAsMap(creditbannerValueList));
    }
    final ValueList newstypesValueList = SelectionUtil.getValueListByIdentifier("newstypes", RequestContextProvider.get());
    if (newstypesValueList != null) {
        request.setAttribute("newstypes", SelectionUtil.valueListAsMap(newstypesValueList));
    }
    request.setAttribute("currentUrl", request.getRequestURL().toString());
}
Also used : ValueList(org.onehippo.forge.selection.hst.contentbean.ValueList)

Example 3 with ValueList

use of org.onehippo.forge.selection.hst.contentbean.ValueList in project hippo by NHS-digital-website.

the class RoadmapItemsComponent method doBeforeRender.

@Override
public void doBeforeRender(final HstRequest request, final HstResponse response) {
    super.doBeforeRender(request, response);
    // sending the roadmapcategories values
    final ValueList roadmapCategoriesValueList = SelectionUtil.getValueListByIdentifier("roadmapcategories", RequestContextProvider.get());
    if (roadmapCategoriesValueList != null) {
        request.setAttribute("roadmapcategories", SelectionUtil.valueListAsMap(roadmapCategoriesValueList));
    }
    // sending the effective date status values
    final ValueList effectiveDateStatusValueList = SelectionUtil.getValueListByIdentifier("effectivedatestatus", RequestContextProvider.get());
    if (effectiveDateStatusValueList != null) {
        request.setAttribute("effectivedatestatus", SelectionUtil.valueListAsMap(effectiveDateStatusValueList));
    }
}
Also used : ValueList(org.onehippo.forge.selection.hst.contentbean.ValueList)

Example 4 with ValueList

use of org.onehippo.forge.selection.hst.contentbean.ValueList 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 5 with ValueList

use of org.onehippo.forge.selection.hst.contentbean.ValueList in project hippo by NHS-digital-website.

the class FeedListComponent method doBeforeRender.

@Override
public void doBeforeRender(HstRequest request, HstResponse response) throws HstComponentException {
    FeedListComponentInfo info = getComponentParametersInfo(request);
    final String documentTypes = info.getDocumentTypes();
    ComponentsUtils.addCurrentDateStrings(request);
    if (Strings.isNullOrEmpty(documentTypes)) {
        setEditMode(request);
        return;
    }
    super.doBeforeRender(request, response);
    if (info.getDocumentTypes().equals("website:event")) {
        // sending the eventstype values
        final ValueList eventsTypeValueList = SelectionUtil.getValueListByIdentifier("eventstype", RequestContextProvider.get());
        if (eventsTypeValueList != null) {
            request.setAttribute("eventstype", SelectionUtil.valueListAsMap(eventsTypeValueList));
        }
        String[] selectedTypes = getSelectedTypes(request);
        request.setAttribute("selectedTypes", Arrays.asList(selectedTypes));
        request.setAttribute("selectedYear", DocumentUtils.findYearOrDefault(getSelectedYear(request), Calendar.getInstance().get(Calendar.YEAR)));
        request.setAttribute("years", years());
    }
    String titleText = info.getTitleText();
    String buttonText = info.getButtonText();
    String buttonDestination = info.getButtonDestination();
    String secondaryButtonText = info.getSecondaryButtonText();
    String secondaryButtonDestination = info.getSecondaryButtonDestination();
    request.setAttribute("titleText", titleText);
    request.setAttribute("buttonText", buttonText);
    request.setAttribute("buttonDestination", buttonDestination);
    request.setAttribute("secondaryButtonText", secondaryButtonText);
    request.setAttribute("secondaryButtonDestination", secondaryButtonDestination);
}
Also used : ValueList(org.onehippo.forge.selection.hst.contentbean.ValueList) FeedListComponentInfo(uk.nhs.digital.common.components.info.FeedListComponentInfo)

Aggregations

ValueList (org.onehippo.forge.selection.hst.contentbean.ValueList)5 IteratorUtils.toList (org.apache.commons.collections.IteratorUtils.toList)1 HstQuery (org.hippoecm.hst.content.beans.query.HstQuery)1 HstQueryResult (org.hippoecm.hst.content.beans.query.HstQueryResult)1 QueryException (org.hippoecm.hst.content.beans.query.exceptions.QueryException)1 HippoBean (org.hippoecm.hst.content.beans.standard.HippoBean)1 HstRequestContext (org.hippoecm.hst.core.request.HstRequestContext)1 FeedListComponentInfo (uk.nhs.digital.common.components.info.FeedListComponentInfo)1