Search in sources :

Example 11 with HippoBean

use of org.hippoecm.hst.content.beans.standard.HippoBean in project hippo by NHS-digital-website.

the class FeedHubComponent method getSupInfoFilters.

private void getSupInfoFilters(List<HippoBean> supInfoFeed) throws QueryException {
    Map<String, Long> yearFilters = supInfoFeed.stream().map(e -> (SupplementaryInformation) e).map(SupplementaryInformation::getPublishedDate).map(e -> e != null ? String.valueOf(e.get(Calendar.YEAR)) : "Unknown").collect(Collectors.groupingBy(Function.identity(), Collectors.counting()));
    addFilter("Year", "year", yearFilters);
    if (yearFilters.size() > 0 && filterValues.get("year").length > 0) {
        Map<String, Long> monthFilters = supInfoFeed.stream().map(e -> (SupplementaryInformation) e).map(SupplementaryInformation::getPublishedDate).filter(Objects::nonNull).map(e -> new SimpleDateFormat("MMMMM").format(e.getTime())).collect(Collectors.groupingBy(Function.identity(), Collectors.counting()));
        addFilter("Month", "month", monthFilters);
    }
}
Also used : Pageable(org.onehippo.cms7.essentials.components.paging.Pageable) java.util(java.util) HstRequestContext(org.hippoecm.hst.core.request.HstRequestContext) HippoBeanIterator(org.hippoecm.hst.content.beans.standard.HippoBeanIterator) HstComponentException(org.hippoecm.hst.core.component.HstComponentException) HstRequest(org.hippoecm.hst.core.component.HstRequest) IteratorUtils.toList(org.apache.commons.collections.IteratorUtils.toList) ConstraintBuilder.or(org.hippoecm.hst.content.beans.query.builder.ConstraintBuilder.or) HstResponse(org.hippoecm.hst.core.component.HstResponse) SimpleDateFormat(java.text.SimpleDateFormat) ConstraintBuilder.and(org.hippoecm.hst.content.beans.query.builder.ConstraintBuilder.and) uk.nhs.digital.website.beans(uk.nhs.digital.website.beans) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) HippoBean(org.hippoecm.hst.content.beans.standard.HippoBean) DateTools(org.hippoecm.repository.util.DateTools) Constraint(org.hippoecm.hst.content.beans.query.builder.Constraint) QueryException(org.hippoecm.hst.content.beans.query.exceptions.QueryException) RequestContextProvider(org.hippoecm.hst.container.RequestContextProvider) ParseException(java.text.ParseException) ConstraintBuilder.constraint(org.hippoecm.hst.content.beans.query.builder.ConstraintBuilder.constraint) HstQueryBuilder(org.hippoecm.hst.content.beans.query.builder.HstQueryBuilder) SimpleDateFormat(java.text.SimpleDateFormat)

Example 12 with HippoBean

use of org.hippoecm.hst.content.beans.standard.HippoBean in project hippo by NHS-digital-website.

the class GeneralArticleComponent method doBeforeRender.

@Override
public void doBeforeRender(final HstRequest hstRequest, final HstResponse hstResponse) {
    super.doBeforeRender(hstRequest, hstResponse);
    final HstRequestContext context = RequestContextProvider.get();
    HttpServletRequest request = context.getServletRequest();
    Object bean = hstRequest.getAttribute(REQUEST_ATTR_DOCUMENT);
    if (bean != null && bean instanceof HippoBean) {
        General generalDocument = (General) bean;
        if (StringUtils.isNotBlank(generalDocument.getEarlyAccessKey()) && !generalDocument.getEarlyAccessKey().equals(request.getParameter("key"))) {
            LOGGER.debug("Early access key is set and no or wrong key is being used. Redirecting to 404 error code");
            hstResponse.setStatus(HttpServletResponse.SC_NOT_FOUND);
            HstResponseUtils.sendRedirect(hstRequest, hstResponse, "/error/404");
        }
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) HippoBean(org.hippoecm.hst.content.beans.standard.HippoBean) General(uk.nhs.digital.website.beans.General) HstRequestContext(org.hippoecm.hst.core.request.HstRequestContext)

Example 13 with HippoBean

use of org.hippoecm.hst.content.beans.standard.HippoBean in project hippo by NHS-digital-website.

the class CaseStudyAndBlogBase method getCategories.

public String getCategories() {
    List<String> strList = new ArrayList<>();
    List<HippoBean> relatedSubjectDoc = getLinkedBeans("website:relatedsubjects", HippoBean.class);
    for (HippoBean bean : relatedSubjectDoc) {
        String title = bean.getSingleProperty("website:title");
        strList.add(title);
    }
    String[] topics = getMultipleProperty("hippotaxonomy:keys");
    if (topics != null && topics.length > 0) {
        strList.addAll(Arrays.asList(topics));
    }
    return strList.size() > 0 ? strList.toString() : null;
}
Also used : HippoBean(org.hippoecm.hst.content.beans.standard.HippoBean) ArrayList(java.util.ArrayList)

Example 14 with HippoBean

use of org.hippoecm.hst.content.beans.standard.HippoBean in project hippo by NHS-digital-website.

the class Role method getPrimaryroles.

@HippoEssentialsGenerated(internalName = "website:primaryrole", allowModifications = false)
public List<String> getPrimaryroles() {
    List<String> roles = new ArrayList<String>();
    List<HippoBean> rolepickers = this.getRolepicker();
    for (HippoBean picker : rolepickers) {
        JobRolePicker rolepicker = (JobRolePicker) picker;
        if (rolepicker != null && rolepicker.getPrimaryrolepicker() != null) {
            JobRole jobrole = rolepicker.getPrimaryrolepicker();
            if (jobrole != null) {
                roles.add(jobrole.getTitle());
            }
        }
    }
    if (roles.size() == 0) {
        roles.add(getSingleProperty("website:primaryrole"));
    }
    return roles;
}
Also used : HippoBean(org.hippoecm.hst.content.beans.standard.HippoBean) ArrayList(java.util.ArrayList) HippoEssentialsGenerated(org.onehippo.cms7.essentials.dashboard.annotations.HippoEssentialsGenerated)

Example 15 with HippoBean

use of org.hippoecm.hst.content.beans.standard.HippoBean in project hippo by NHS-digital-website.

the class ProjectUpdate method getParentFeed.

public ProjectFeed getParentFeed() {
    ProjectFeed parentBean = null;
    HippoBean folder = getParentBean();
    while (!HippoBeanHelper.isRootFolder(folder)) {
        Iterator<ProjectFeed> iterator = folder.getChildBeans(ProjectFeed.class).iterator();
        if (iterator.hasNext()) {
            parentBean = iterator.next();
            break;
        } else {
            folder = folder.getParentBean();
        }
    }
    return parentBean;
}
Also used : HippoBean(org.hippoecm.hst.content.beans.standard.HippoBean)

Aggregations

HippoBean (org.hippoecm.hst.content.beans.standard.HippoBean)46 QueryException (org.hippoecm.hst.content.beans.query.exceptions.QueryException)10 HstRequestContext (org.hippoecm.hst.core.request.HstRequestContext)10 ArrayList (java.util.ArrayList)7 HstQuery (org.hippoecm.hst.content.beans.query.HstQuery)7 HippoBeanIterator (org.hippoecm.hst.content.beans.standard.HippoBeanIterator)7 HstQueryResult (org.hippoecm.hst.content.beans.query.HstQueryResult)6 HstQueryBuilder (org.hippoecm.hst.content.beans.query.builder.HstQueryBuilder)5 HstComponentException (org.hippoecm.hst.core.component.HstComponentException)5 SimpleDateFormat (java.text.SimpleDateFormat)4 java.util (java.util)4 Collectors (java.util.stream.Collectors)4 IteratorUtils.toList (org.apache.commons.collections.IteratorUtils.toList)4 RequestContextProvider (org.hippoecm.hst.container.RequestContextProvider)4 Constraint (org.hippoecm.hst.content.beans.query.builder.Constraint)4 DateTools (org.hippoecm.repository.util.DateTools)4 ParseException (java.text.ParseException)3 Function (java.util.function.Function)3 Node (javax.jcr.Node)3 ConstraintBuilder.and (org.hippoecm.hst.content.beans.query.builder.ConstraintBuilder.and)3