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());
}
}
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;
}
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;
}
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());
}
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());
}
Aggregations