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