use of org.hippoecm.hst.content.beans.standard.HippoBeanIterator in project hippo by NHS-digital-website.
the class NewsInternal method getLatestNews.
public List<NewsInternal> getLatestNews() throws QueryException {
HippoBean folder = RequestContextProvider.get().getSiteContentBaseBean();
HippoBeanIterator hippoBeans = HstQueryBuilder.create(folder).ofTypes(NewsInternal.class).where(and(constraint("jcr:uuid").notEqualTo(this.getIdentifier()), or(constraint("intranet:typeofnews").equalTo("permanent"), constraint("intranet:expirydate").greaterOrEqualThan(Calendar.getInstance(), Resolution.HOUR)))).orderByDescending("intranet:publicationdate").limit(5).build().execute().getHippoBeans();
return toList(hippoBeans);
}
use of org.hippoecm.hst.content.beans.standard.HippoBeanIterator in project hippo by NHS-digital-website.
the class CyberAlertComponent method createCyberAlertsList.
private List<CyberAlert> createCyberAlertsList(final int configuredAlertSize, final HstQueryResult alertsQueryResult) {
Calendar twoWeekAgo = Calendar.getInstance();
twoWeekAgo.add(Calendar.WEEK_OF_YEAR, -2);
HippoBeanIterator allAlerts = alertsQueryResult.getHippoBeans();
final List<CyberAlert> severeWithinTwoWeeks = new ArrayList<>();
final List<CyberAlert> allOtherAlerts = new ArrayList<>();
while (allAlerts.hasNext()) {
CyberAlert cyberAlert = (CyberAlert) allAlerts.next();
if (cyberAlert.getSeverity() != null && cyberAlert.getPublishedDate() != null) {
if (cyberAlert.getSeverity().equals("High") && cyberAlert.getPublishedDate().getTimeInMillis() > twoWeekAgo.getTimeInMillis()) {
severeWithinTwoWeeks.add(cyberAlert);
} else {
allOtherAlerts.add(cyberAlert);
}
}
}
List<CyberAlert> cyberAlertsList;
if (severeWithinTwoWeeks.size() > configuredAlertSize) {
cyberAlertsList = severeWithinTwoWeeks.subList(0, configuredAlertSize);
} else {
cyberAlertsList = severeWithinTwoWeeks;
}
if (cyberAlertsList.size() < configuredAlertSize) {
int numberOfAlertsToAdd = configuredAlertSize - cyberAlertsList.size();
for (int i = 0; i < numberOfAlertsToAdd && i < allOtherAlerts.size(); ) {
cyberAlertsList.add(allOtherAlerts.get(i++));
}
}
return cyberAlertsList;
}
use of org.hippoecm.hst.content.beans.standard.HippoBeanIterator in project hippo by NHS-digital-website.
the class ProjectUpdateFeedComponent method addOrganisationFilter.
private void addOrganisationFilter(List<BaseFilter> filters, HstRequest request, HstQuery query) {
String organisationTitle = getSelectedOrganisationTitle(request);
if (StringUtils.isNotBlank(organisationTitle)) {
HippoBeanIterator organisationBeans;
try {
final HstRequestContext requestContext = request.getRequestContext();
HstQuery orgQuery = requestContext.getQueryManager().createQuery(requestContext.getSiteContentBaseBean(), Organisation.class);
Filter orgNameFilter = orgQuery.createFilter();
orgNameFilter.addEqualToCaseInsensitive("website:title", organisationTitle);
orgQuery.setFilter(orgNameFilter);
organisationBeans = orgQuery.execute().getHippoBeans();
} catch (QueryException e) {
log.debug("Error finding organisation with title {}: {}", organisationTitle, e);
return;
}
if (organisationBeans.getSize() == 0) {
return;
}
String jcrQuery;
if (organisationBeans.getSize() > 1) {
StringBuilder jcrQueryBuilder = new StringBuilder(String.format("((website:organisation/@hippo:docbase = '%s')", ((HippoDocument) organisationBeans.nextHippoBean()).getCanonicalHandleUUID()));
while (organisationBeans.hasNext()) {
jcrQueryBuilder.append(String.format(" or (website:organisation/@hippo:docbase = '%s')", ((HippoDocument) organisationBeans.nextHippoBean()).getCanonicalHandleUUID()));
}
jcrQueryBuilder.append(")");
jcrQuery = jcrQueryBuilder.toString();
} else {
jcrQuery = String.format("(website:organisation/@hippo:docbase = '%s')", ((HippoDocument) organisationBeans.nextHippoBean()).getCanonicalHandleUUID());
}
Filter filter = query.createFilter();
filter.addJCRExpression(jcrQuery);
filters.add(filter);
}
}
use of org.hippoecm.hst.content.beans.standard.HippoBeanIterator in project hippo by NHS-digital-website.
the class ApiCatalogueJcrRepository method taxonomyFiltersMapping.
@Override
public Optional<String> taxonomyFiltersMapping() {
try {
final Node mappingDocumentHandle = JcrUtils.getNodeIfExists(TAXONOMY_FILTERS_MAPPING_DOCUMENT_PATH, session);
if (mappingDocumentHandle == null) {
log.warn("API Catalogue's taxonomy-filters mapping document not found at {}", TAXONOMY_FILTERS_MAPPING_DOCUMENT_PATH);
return Optional.empty();
}
final HstQueryResult hstQueryResult = queryForPublishedVariant(mappingDocumentHandle).execute();
return Optional.of(hstQueryResult.getHippoBeans()).filter(Iterator::hasNext).map(HippoBeanIterator::nextHippoBean).map(HippoBean::getProperty).map(properties -> properties.get("website:text")).filter(String.class::isInstance).map(String.class::cast);
} catch (final Exception cause) {
throw new RuntimeException("Failed to retrieve taxonomy-filters mapping YAML for scope node " + TAXONOMY_FILTERS_MAPPING_DOCUMENT_PATH, cause);
}
}
use of org.hippoecm.hst.content.beans.standard.HippoBeanIterator in project hippo by NHS-digital-website.
the class ApiEndpoint method getApiMasterParent.
public ApiMaster getApiMasterParent() {
final HstRequestContext context = RequestContextProvider.get();
try {
HstQuery linkedBeanQuery = ContentBeanUtils.createIncomingBeansQuery(this.getCanonicalBean(), context.getSiteContentBaseBean(), "website:apiendpointgroups/website:apirequest/@hippo:docbase", ApiMaster.class, false);
linkedBeanQuery.setLimit(1);
HstQueryResult hstQueryResult = linkedBeanQuery.execute();
HippoBeanIterator hippoBeanIterator = hstQueryResult.getHippoBeans();
if (hippoBeanIterator.getSize() > 0) {
return (ApiMaster) hippoBeanIterator.nextHippoBean();
} else {
return null;
}
} catch (QueryException queryException) {
log.warn("QueryException ", queryException);
}
return null;
}
Aggregations