Search in sources :

Example 1 with HippoBeanIterator

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);
}
Also used : HippoBean(org.hippoecm.hst.content.beans.standard.HippoBean) HippoBeanIterator(org.hippoecm.hst.content.beans.standard.HippoBeanIterator)

Example 2 with HippoBeanIterator

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;
}
Also used : HippoBeanIterator(org.hippoecm.hst.content.beans.standard.HippoBeanIterator) Calendar(java.util.Calendar) ArrayList(java.util.ArrayList) CyberAlert(uk.nhs.digital.website.beans.CyberAlert)

Example 3 with HippoBeanIterator

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);
    }
}
Also used : HstQuery(org.hippoecm.hst.content.beans.query.HstQuery) HippoDocument(org.hippoecm.hst.content.beans.standard.HippoDocument) QueryException(org.hippoecm.hst.content.beans.query.exceptions.QueryException) BaseFilter(org.hippoecm.hst.content.beans.query.filter.BaseFilter) Filter(org.hippoecm.hst.content.beans.query.filter.Filter) HippoBeanIterator(org.hippoecm.hst.content.beans.standard.HippoBeanIterator) HstRequestContext(org.hippoecm.hst.core.request.HstRequestContext)

Example 4 with HippoBeanIterator

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);
    }
}
Also used : HippoBeanIterator(org.hippoecm.hst.content.beans.standard.HippoBeanIterator) Node(javax.jcr.Node) HstQueryResult(org.hippoecm.hst.content.beans.query.HstQueryResult)

Example 5 with HippoBeanIterator

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;
}
Also used : HstQuery(org.hippoecm.hst.content.beans.query.HstQuery) QueryException(org.hippoecm.hst.content.beans.query.exceptions.QueryException) HippoBeanIterator(org.hippoecm.hst.content.beans.standard.HippoBeanIterator) HstRequestContext(org.hippoecm.hst.core.request.HstRequestContext) HstQueryResult(org.hippoecm.hst.content.beans.query.HstQueryResult)

Aggregations

HippoBeanIterator (org.hippoecm.hst.content.beans.standard.HippoBeanIterator)9 HstQuery (org.hippoecm.hst.content.beans.query.HstQuery)4 HstQueryResult (org.hippoecm.hst.content.beans.query.HstQueryResult)4 HippoBean (org.hippoecm.hst.content.beans.standard.HippoBean)4 HstRequestContext (org.hippoecm.hst.core.request.HstRequestContext)4 CyberAlert (uk.nhs.digital.website.beans.CyberAlert)3 Node (javax.jcr.Node)2 GET (javax.ws.rs.GET)2 Path (javax.ws.rs.Path)2 QueryException (org.hippoecm.hst.content.beans.query.exceptions.QueryException)2 Filter (org.hippoecm.hst.content.beans.query.filter.Filter)2 ArrayList (java.util.ArrayList)1 Calendar (java.util.Calendar)1 HstQueryManager (org.hippoecm.hst.content.beans.query.HstQueryManager)1 Constraint (org.hippoecm.hst.content.beans.query.builder.Constraint)1 HstQueryBuilder (org.hippoecm.hst.content.beans.query.builder.HstQueryBuilder)1 BaseFilter (org.hippoecm.hst.content.beans.query.filter.BaseFilter)1 HippoDocument (org.hippoecm.hst.content.beans.standard.HippoDocument)1 DateTools (org.hippoecm.repository.util.DateTools)1 JSONObject (org.json.simple.JSONObject)1