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