Search in sources :

Example 36 with HippoBean

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

the class DocumentUtils method setMetaTags.

/**
 * Sets the meta tags
 *
 * @param request         HttpRequest
 * @param commonComponent CommonComponent
 */
public static void setMetaTags(HstRequest request, CommonComponent commonComponent) {
    log.debug("Request Path info " + request.getPathInfo());
    String seoSummary = null;
    String title = null;
    try {
        String path = request.getPathInfo().replaceAll("/", "") + "/content/";
        HippoBean bean = commonComponent.getHippoBeanForPath(path, HippoBean.class);
        Node node = null;
        if (bean != null) {
            node = bean.getNode();
        } else {
            log.info("No Bean found for path " + path);
            return;
        }
        log.debug("Value of node is " + node);
        if (node.hasProperty("website:seosummarytext")) {
            seoSummary = node.getProperty("website:seosummarytext").getValue().getString();
        } else {
            seoSummary = node.getProperty("website:shortsummary").getValue().getString();
        }
        title = node.getProperty("website:title").getValue().getString();
        log.debug("Value of title is " + title);
        log.debug("Value of summary  is " + seoSummary);
        request.setAttribute("title", title);
        request.setAttribute("summary", seoSummary);
    } catch (Exception ex) {
        log.error("Exception reading values ", ex);
    }
}
Also used : HippoBean(org.hippoecm.hst.content.beans.standard.HippoBean) Node(javax.jcr.Node) QueryException(org.hippoecm.hst.content.beans.query.exceptions.QueryException)

Example 37 with HippoBean

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

the class SearchPageComponent method searchContent.

private void searchContent(HstRequest request, List<SearchResultTab> searchResultTabs) {
    final SearchArea searchArea = getAreaOption(request);
    final String searchQuery = getSearchQuery(request, true);
    if (searchArea != SearchArea.PEOPLE) {
        final Pageable<HippoBean> bloomreachResults = bloomreachSearchProvider.getBloomreachResults(searchQuery, getComponentInfo(request).getPageSize(), getCurrentPage(request), searchArea);
        request.setAttribute(REQUEST_ATTR_PAGEABLE, bloomreachResults);
        if (searchArea != SearchArea.ALL) {
            searchResultTabs.add(new SearchResultTab(searchArea, Math.toIntExact(bloomreachResults.getTotal())));
        }
    }
    SearchArea.getDocumentSearchAreasWithout(searchArea).forEach(unselectedSearchArea -> searchResultTabs.add(new SearchResultTab(unselectedSearchArea, bloomreachSearchProvider.getBloomreachResultsCount(searchQuery, unselectedSearchArea))));
}
Also used : HippoBean(org.hippoecm.hst.content.beans.standard.HippoBean) SearchArea(uk.nhs.digital.intranet.enums.SearchArea) SearchResultTab(uk.nhs.digital.intranet.model.SearchResultTab)

Example 38 with HippoBean

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

the class RssModifier method getCategory.

private String getCategory(Publication publicationBean) {
    HippoBean parentDocument = publicationBean.getParentDocument();
    if (parentDocument instanceof Series) {
        Series series = (Series) parentDocument;
        StringBuilder category = new StringBuilder();
        try {
            if (series.getFullTaxonomyList() != null && series.getFullTaxonomyList().size() > 0) {
                category.append(Arrays.toString(series.getFullTaxonomyList().toArray()));
            }
        } catch (Exception ex) {
            LOGGER.warn(" Failed to get the Full Taxonomy.", ex.getMessage());
        }
        if (series.getInformationType() != null && series.getInformationType().length > 0) {
            category.append(Arrays.toString(series.getInformationType()));
        }
        if (series.getGranularity() != null && series.getGranularity().length > 0) {
            category.append(Arrays.toString(series.getGranularity()));
        }
        if (series.getGeographicCoverage() != null && series.getGeographicCoverage().length > 0) {
            category.append(Arrays.toString(Arrays.stream(series.getGeographicCoverage()).toArray()));
        }
        return category.toString();
    } else {
        return "";
    }
}
Also used : HippoBean(org.hippoecm.hst.content.beans.standard.HippoBean) Series(uk.nhs.digital.ps.beans.Series) FilterException(org.hippoecm.hst.content.beans.query.exceptions.FilterException) QueryException(org.hippoecm.hst.content.beans.query.exceptions.QueryException)

Example 39 with HippoBean

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

the class JcrTestUtilsHst method mockJcrRepo.

public static MockSession mockJcrRepo(final String repositoryYaml, final Map<String, Class<? extends HippoBean>> jcrPrimaryNodeTypeBeanPairs, final MockHstRequestContext hstRequestContext, final String expectedQuery, final String... expectedNodesAbsolutePaths) throws IOException, RepositoryException {
    final NhsdMockQueryManager jcrQueryManager = new NhsdMockQueryManager();
    final MockNode root = MockNode.root(jcrQueryManager);
    MockNodeFactory.importYaml(repositoryYaml, root);
    final HstQueryManagerImpl hstQueryManager = new HstQueryManagerImpl(null, new ObjectConverterImpl(Optional.ofNullable(jcrPrimaryNodeTypeBeanPairs).orElse(emptyMap()), new String[0]), DateTools.Resolution.MILLISECOND);
    final List<Node> expectedNodes = Optional.ofNullable(expectedNodesAbsolutePaths).map(Arrays::stream).orElse(Stream.empty()).map(path -> wrapCheckedException(() -> root.getNode(path))).collect(toList());
    jcrQueryManager.registerResultHandler(query -> {
        if (query.getStatement().equals(expectedQuery)) {
            return new MockQueryResult(expectedNodes);
        }
        return new MockQueryResult(emptyList());
    });
    final MockSession session = root.getSession();
    ReflectionTestUtils.setField(hstQueryManager, "session", session);
    final Mount mount = mock(Mount.class);
    final ResolvedMount resolvedMount = mock(ResolvedMount.class);
    given(resolvedMount.getMount()).willReturn(mount);
    given(mount.isPreview()).willReturn(false);
    MockHstRequestContext requestContext = hstRequestContext;
    if (requestContext == null) {
        requestContext = new MockHstRequestContext();
        ModifiableRequestContextProvider.set(requestContext);
    }
    requestContext.setDefaultHstQueryManager(hstQueryManager);
    requestContext.setResolvedMount(resolvedMount);
    requestContext.setSession(session);
    return session;
}
Also used : Arrays(java.util.Arrays) MockHstRequestContext(org.hippoecm.hst.mock.core.request.MockHstRequestContext) MockNodeFactory(org.onehippo.repository.mock.MockNodeFactory) ResolvedMount(org.hippoecm.hst.core.request.ResolvedMount) RepositoryException(javax.jcr.RepositoryException) BDDMockito.given(org.mockito.BDDMockito.given) Node(javax.jcr.Node) MockQueryResult(org.apache.sling.testing.mock.jcr.MockQueryResult) Map(java.util.Map) ObjectConverterImpl(org.hippoecm.hst.content.beans.manager.ObjectConverterImpl) Mount(org.hippoecm.hst.configuration.hosting.Mount) Collections.emptyMap(java.util.Collections.emptyMap) MockNode(org.onehippo.repository.mock.MockNode) ModifiableRequestContextProvider(org.hippoecm.hst.container.ModifiableRequestContextProvider) MockSession(org.onehippo.repository.mock.MockSession) Collections.emptyList(java.util.Collections.emptyList) IOException(java.io.IOException) HstQueryManagerImpl(org.hippoecm.hst.content.beans.query.HstQueryManagerImpl) HippoBean(org.hippoecm.hst.content.beans.standard.HippoBean) Collectors.toList(java.util.stream.Collectors.toList) List(java.util.List) NhsdMockQueryManager(org.apache.sling.testing.mock.jcr.NhsdMockQueryManager) Stream(java.util.stream.Stream) DateTools(org.hippoecm.repository.util.DateTools) Optional(java.util.Optional) ExceptionTestUtils.wrapCheckedException(uk.nhs.digital.test.util.ExceptionTestUtils.wrapCheckedException) Mockito.mock(org.mockito.Mockito.mock) MockHstRequestContext(org.hippoecm.hst.mock.core.request.MockHstRequestContext) Node(javax.jcr.Node) MockNode(org.onehippo.repository.mock.MockNode) ResolvedMount(org.hippoecm.hst.core.request.ResolvedMount) Mount(org.hippoecm.hst.configuration.hosting.Mount) NhsdMockQueryManager(org.apache.sling.testing.mock.jcr.NhsdMockQueryManager) HstQueryManagerImpl(org.hippoecm.hst.content.beans.query.HstQueryManagerImpl) MockNode(org.onehippo.repository.mock.MockNode) MockSession(org.onehippo.repository.mock.MockSession) ObjectConverterImpl(org.hippoecm.hst.content.beans.manager.ObjectConverterImpl) ResolvedMount(org.hippoecm.hst.core.request.ResolvedMount) MockQueryResult(org.apache.sling.testing.mock.jcr.MockQueryResult)

Example 40 with HippoBean

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

the class FeedHubComponent method doBeforeRender.

@Override
public void doBeforeRender(final HstRequest request, final HstResponse response) throws HstComponentException {
    super.doBeforeRender(request, response);
    filters = new ArrayList<>();
    filterValues = new HashMap<>();
    String[] yearParams = getPublicRequestParameters(request, "year");
    filterValues.put("year", yearParams);
    if (yearParams.length > 0) {
        filterValues.put("month", getPublicRequestParameters(request, "month"));
    }
    filterValues.put("type[]", getPublicRequestParameters(request, "type[]"));
    filterValues.put("severity", getPublicRequestParameters(request, "severity"));
    request.setAttribute("filterValues", filterValues);
    long filterCount = filterValues.values().stream().filter(value -> value.length > 0).count();
    request.setAttribute("filterCount", filterCount);
    queryText = getPublicRequestParameter(request, "query");
    if (queryText == null) {
        queryText = "";
    }
    request.setAttribute("query", queryText);
    sort = getPublicRequestParameter(request, "sort");
    if (sort == null) {
        sort = "date-desc";
    }
    request.setAttribute("sort", sort);
    String activeFiltersString = getPublicRequestParameter(request, "active-filters");
    if (activeFiltersString != null) {
        String[] activeFilters = activeFiltersString.split(",");
        request.setAttribute("activeFilters", activeFilters);
    }
    try {
        List<HippoBean> feed = getFeed(request);
        request.setAttribute("feed", feed);
        Pageable<HippoBean> pagedFeed = pageResults(feed, request);
        request.setAttribute("pageable", pagedFeed);
        final HstRequestContext context = request.getRequestContext();
        FeedHub feedHub = (FeedHub) context.getContentBean();
        switch(feedHub.getFeedType()) {
            case "News":
                getNewsFilters(feed);
                break;
            case "Supplementary information":
                getSupInfoFilters(feed);
                break;
            case "Events":
                getEventFilters(feed);
                break;
            case "Cyber Alerts":
                getCyberAlertFilters(feed);
                break;
            default:
        }
        request.setAttribute("filters", filters);
    } catch (QueryException e) {
        e.printStackTrace();
    }
}
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) HippoBean(org.hippoecm.hst.content.beans.standard.HippoBean) QueryException(org.hippoecm.hst.content.beans.query.exceptions.QueryException) HstRequestContext(org.hippoecm.hst.core.request.HstRequestContext)

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