Search in sources :

Example 1 with HippoBean

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));
    }
}
Also used : HstQuery(org.hippoecm.hst.content.beans.query.HstQuery) Query(javax.jcr.query.Query) Node(javax.jcr.Node) HstLink(org.hippoecm.hst.core.linking.HstLink) Element(org.jdom2.Element) HippoBean(org.hippoecm.hst.content.beans.standard.HippoBean) NodeIterator(javax.jcr.NodeIterator) HippoGalleryImageSetBean(org.hippoecm.hst.content.beans.standard.HippoGalleryImageSetBean) Publication(uk.nhs.digital.ps.beans.Publication) FilterException(org.hippoecm.hst.content.beans.query.exceptions.FilterException) QueryException(org.hippoecm.hst.content.beans.query.exceptions.QueryException) SimpleDateFormat(java.text.SimpleDateFormat) Session(javax.jcr.Session)

Example 2 with HippoBean

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;
}
Also used : HippoBean(org.hippoecm.hst.content.beans.standard.HippoBean) Signup(uk.nhs.digital.website.beans.Signup) FormBean(com.onehippo.cms7.eforms.hst.beans.FormBean) Nullable(org.jetbrains.annotations.Nullable)

Example 3 with HippoBean

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

Example 4 with HippoBean

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

Example 5 with HippoBean

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));
}
Also used : HippoBean(org.hippoecm.hst.content.beans.standard.HippoBean) Task(uk.nhs.digital.intranet.beans.Task) MockHstRequest(org.hippoecm.hst.mock.core.component.MockHstRequest) MockHstResponse(org.hippoecm.hst.mock.core.component.MockHstResponse) DefaultPagination(org.onehippo.cms7.essentials.components.paging.DefaultPagination) Test(org.junit.Test)

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