use of org.hippoecm.hst.content.beans.standard.HippoBean in project hippo by NHS-digital-website.
the class RssModifier method modifyEntry.
@Override
public void modifyEntry(final HstRequestContext context, final Item entry, final HippoBean bean) {
String scope = "";
String requestPath = null;
SimpleDateFormat dateFormat = new SimpleDateFormat("E, dd MMM yyyy HH:mm:ss z");
SimpleDateFormat lastUpdatedDateFormat = new SimpleDateFormat("dd MMM yyyy");
dateFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
if (bean instanceof Blog) {
try {
requestPath = context.getBaseURL().getRequestPath();
final String statement = "/jcr:root/content/documents/corporate-website/feeds//*[@jcr:primaryType='feed:rss20descriptor']";
Session session = context.getSession();
final Query q = session.getWorkspace().getQueryManager().createQuery(statement, Query.XPATH);
final NodeIterator nodes = q.execute().getNodes();
while (nodes.hasNext()) {
Node node = nodes.nextNode();
scope = node.getProperty("feed:scope").getString();
if (requestPath.contains("/" + scope)) {
break;
}
}
} catch (Exception e) {
e.printStackTrace();
}
final Blog blogBean = (Blog) bean;
final Date lastUpdated = blogBean.getLastModified();
if (lastUpdated != null) {
HstLink hstLink = context.getHstLinkCreator().create(bean, context);
String blogPath = bean.getPath();
if (hstLink != null && (StringUtils.isNotBlank(scope) && blogPath.contains("/" + scope)) || requestPath.contains("all-blog")) {
List<Element> foreignMarkup = entry.getForeignMarkup();
foreignMarkup.add(getElement("title", blogBean.getTitle()));
Element lmElement = new Element("author");
String emailAddress = "enquiries@nhsdigital.nhs.uk";
StringBuilder strPerson = new StringBuilder();
if (blogBean.getAuthors() != null && blogBean.getAuthors().size() > 0) {
Person person = (Person) blogBean.getAuthors().get(0);
if (person.getRoles() != null && person.getRoles().getContactdetails() != null) {
final ContactDetail contactdetails = person.getRoles().getContactdetails();
if (StringUtils.isBlank(contactdetails.getEmailaddress())) {
strPerson.append(emailAddress);
} else {
strPerson.append(contactdetails.getEmailaddress());
}
strPerson.append(" (" + contactdetails.getName() + ")");
}
} else {
strPerson.append(emailAddress);
if (StringUtils.isNotBlank(blogBean.getAuthorName())) {
strPerson.append(" (" + blogBean.getAuthorName() + ")");
} else {
strPerson.append("(NHS Digital)");
}
}
lmElement.addContent(StringUtils.isNotBlank(strPerson.toString()) ? strPerson.toString() : "enquiries@nhsdigital.nhs.uk (NHS Digital)");
foreignMarkup.add(lmElement);
String category = blogBean.getCategories();
if (StringUtils.isNotBlank(category)) {
foreignMarkup.add(getElement("category", category));
}
foreignMarkup.add(getElement("description", blogBean.getAllDescription()));
Element guid = getElement("guid", blogBean.getGuid());
guid.setAttribute("isPermaLink", "false");
foreignMarkup.add(guid);
foreignMarkup.add(getElement("pubDate", dateFormat.format(lastUpdated)));
foreignMarkup.add(getElement("link", hstLink.toUrlForm(context, true)));
Element source = getElement("source", "NHS Digital");
source.setAttribute("url", "https://digital.nhs.uk");
foreignMarkup.add(source);
final HippoGalleryImageSetBean image = blogBean.getLeadImage();
if (image != null) {
hstLink = context.getHstLinkCreator().create(image, context);
if (hstLink != null) {
foreignMarkup = entry.getForeignMarkup();
String imageUrl = hstLink.toUrlForm(context, true);
final Element element = getImageElement(imageUrl);
foreignMarkup.add(element);
}
}
}
}
} else if (bean instanceof News) {
final News newsBean = (News) bean;
List<Element> foreignMarkup = entry.getForeignMarkup();
foreignMarkup.add(getElement("title", newsBean.getTitle()));
ContactDetail contactDetail = newsBean.getMediacontact();
String author = "NHS Digital";
String emailAddress = "enquiries@nhsdigital.nhs.uk";
if (contactDetail != null && StringUtils.isNotBlank(contactDetail.getName())) {
author = contactDetail.getName();
emailAddress = contactDetail.getEmailaddress();
}
foreignMarkup.add(getElement("author", (emailAddress + " (" + author + ")")));
StringBuilder content = new StringBuilder();
for (HippoBean sre : newsBean.getSections()) {
String tempContent = new String();
if (sre instanceof Section) {
tempContent = ((Section) sre).getHtmlJson();
} else if (sre instanceof EmphasisBox) {
tempContent = ((EmphasisBox) sre).getBodyJson();
} else if (sre instanceof Expander) {
tempContent = ((Expander) sre).getContent().getContent();
} else if (sre instanceof Quote) {
tempContent = ((Quote) sre).getQuote().getContent();
}
content.append(tempContent);
}
foreignMarkup.add(getElement("description", content.toString()));
String category = getNewsCategory(newsBean);
if (StringUtils.isNotBlank(category)) {
foreignMarkup.add(getElement("category", category));
}
Element guid = getElement("guid", newsBean.getCanonicalUUID());
guid.setAttribute("isPermaLink", "false");
foreignMarkup.add(guid);
String formatted = dateFormat.format(newsBean.getLastModified());
foreignMarkup.add(getElement("pubDate", formatted));
HstLink hstLink = context.getHstLinkCreator().create(bean, context);
String urlNews = hstLink.toUrlForm(context, true);
foreignMarkup.add(getElement("link", urlNews));
String tempUrl = urlNews.substring(0, urlNews.indexOf(context.getBaseURL().getHostName()));
String finalUrl = tempUrl + context.getBaseURL().getHostName() + context.getBaseURL().getContextPath() + context.getHstLinkCreator().getBinariesPrefix();
final LeadImageSection leadimagesection = newsBean.getLeadimagesection();
if (leadimagesection != null && leadimagesection.getLeadImage() != null) {
String imageUrl = finalUrl + leadimagesection.getLeadImage().getCanonicalHandlePath();
Element imageElement = getImageElement(imageUrl);
foreignMarkup.add(imageElement);
}
Element source = getElement("source", "NHS Digital");
source.setAttribute("url", "https://digital.nhs.uk");
foreignMarkup.add(source);
} else if (bean instanceof Publication) {
List<Element> foreignMarkup = entry.getForeignMarkup();
final Publication publicationBean = (Publication) bean;
String docPath = bean.getPath();
if (docPath.contains("/publication-system/")) {
foreignMarkup.add(getElement("title", publicationBean.getTitle()));
foreignMarkup.add(getElement("author", "enquiries@nhsdigital.nhs.uk (NHS Digital)"));
StringBuilder description = new StringBuilder();
for (uk.nhs.digital.ps.beans.structuredText.Element tempDesc : publicationBean.getSummary().getElements()) {
description.append(tempDesc);
}
foreignMarkup.add(getElement("description", description.toString()));
String category = getCategory(publicationBean);
if (StringUtils.isNotBlank(category)) {
foreignMarkup.add(getElement("category", category));
}
Element guid = getElement("guid", publicationBean.getCanonicalUUID());
guid.setAttribute("isPermaLink", "false");
foreignMarkup.add(guid);
String formatted = dateFormat.format(publicationBean.getLastModified());
foreignMarkup.add(getElement("pubDate", formatted));
HstLink hstLink = context.getHstLinkCreator().create(bean, context);
String url = hstLink.toUrlForm(context, true);
foreignMarkup.add(getElement("link", url));
String tempUrl1 = url.substring(0, url.indexOf(context.getBaseURL().getHostName()));
String finalUrl = tempUrl1 + context.getBaseURL().getHostName() + context.getBaseURL().getContextPath() + context.getHstLinkCreator().getBinariesPrefix();
for (Infographic test : publicationBean.getKeyFactInfographics()) {
if (test.getIcon() != null) {
foreignMarkup.add(getImageElement(finalUrl + test.getIcon().getCanonicalHandlePath()));
}
}
Element source = getElement("source", "NHS Digital");
source.setAttribute("url", "https://digital.nhs.uk");
foreignMarkup.add(source);
}
} else if (bean instanceof CyberAlert) {
List<Element> foreignMarkup = entry.getForeignMarkup();
final CyberAlert cyberAlertBean = (CyberAlert) bean;
foreignMarkup.add(getElement("title", cyberAlertBean.getThreatId() + " - " + cyberAlertBean.getTitle()));
foreignMarkup.add(getElement("category", cyberAlertBean.getSeverity()));
foreignMarkup.add(getElement("author", "enquiries@nhsdigital.nhs.uk (NHS Digital)"));
foreignMarkup.add(getElement("description", "<p>Severity: " + cyberAlertBean.getSeverity() + "</p>" + " " + cyberAlertBean.getSummary().getContent() + "<p> " + cyberAlertBean.getShortsummary() + "</p><p> Updated: " + lastUpdatedDateFormat.format(cyberAlertBean.getLastModified()) + "</p>"));
Element guid = getElement("guid", cyberAlertBean.getCanonicalUUID());
guid.setAttribute("isPermaLink", "false");
foreignMarkup.add(guid);
String pubDate = dateFormat.format(cyberAlertBean.getPublishedDate().getTime());
foreignMarkup.add(getElement("pubDate", pubDate));
HstLink hstLink = context.getHstLinkCreator().create(bean, context);
String url = hstLink.toUrlForm(context, true);
foreignMarkup.add(getElement("link", url));
}
}
use of org.hippoecm.hst.content.beans.standard.HippoBean in project hippo by NHS-digital-website.
the class CustomAutoDetectFormComponent method getFormBeanFromSignupDocument.
@Nullable
private FormBean getFormBeanFromSignupDocument(final HstRequest request) {
final HippoBean document = request.getRequestContext().getContentBean();
if (document instanceof Signup) {
final Signup signupDocument = (Signup) document;
return (FormBean) signupDocument.getFormLink().getLink();
}
if (document == null || !document.isHippoDocumentBean() || !(document instanceof FormBean)) {
if (log.isDebugEnabled()) {
log.warn("*** EFORMS ***");
log.warn("Cannot get the form bean, returning null. Reason: the content bean is null or it does not match the FormBean type [eforms:form].");
log.warn("Override the method [BaseEformComponent#getFormBean(HstRequest)] to get the form bean in a different way, e.g. from a linked bean.");
log.warn("Will attempt to get the form bean from the component picker.");
log.warn("*** EFORMS ***");
}
return null;
}
return (FormBean) document;
}
use of org.hippoecm.hst.content.beans.standard.HippoBean in project hippo by NHS-digital-website.
the class MasterComponent method doBeforeRender.
@Override
public void doBeforeRender(HstRequest request, HstResponse response) {
super.doBeforeRender(request, response);
final HstRequestContext context = request.getRequestContext();
final HippoBean document = context.getContentBean();
if (document != null) {
request.setAttribute("document", document);
}
}
use of org.hippoecm.hst.content.beans.standard.HippoBean 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.HippoBean in project hippo by NHS-digital-website.
the class SearchPageComponentTest method blankQueryReturnsDocumentsForAllDocTypes.
@Test
public void blankQueryReturnsDocumentsForAllDocTypes() {
MockHstRequest request = new MockHstRequest();
request.setParameterMap("", Collections.emptyMap());
Pageable<HippoBean> documentResults = new DefaultPagination<>(Collections.singletonList(new Task()));
Mockito.when(bloomreachSearchProvider.getBloomreachResults(Mockito.nullable(String.class), anyInt(), anyInt(), eq(SearchArea.ALL))).thenReturn(documentResults);
underTest.doBeforeRender(request, new MockHstResponse());
assertEquals(documentResults, request.getAttribute(REQUEST_ATTR_PAGEABLE));
}
Aggregations