use of org.hippoecm.hst.core.request.HstRequestContext 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");
}
}
}
use of org.hippoecm.hst.core.request.HstRequestContext in project hippo by NHS-digital-website.
the class CyberAlert method getBasePath.
@JsonProperty
public String getBasePath() {
if (getPublicallyAccessible() || getLimitedAccess()) {
final HstRequestContext context = RequestContextProvider.get();
if (context != null) {
// DW-1077 - compose this documetn base URL for REST API purposes
HttpServletRequest req = context.getServletRequest();
StringBuffer url = req.getRequestURL();
String base = url.substring(0, url.length() - req.getRequestURI().length() + req.getContextPath().length());
// remove basepath part ('content/documents/corporate-website')
// and compose full path
String pathSuffix = this.getPath().replace("/" + context.getSiteContentBasePath(), "");
// remove '/site/' if exists
return (base + pathSuffix).replace("/site/", "/");
}
}
return null;
}
use of org.hippoecm.hst.core.request.HstRequestContext in project hippo by NHS-digital-website.
the class CyberAlert method getFullAccess.
@JsonIgnore
private Boolean getFullAccess() {
Boolean fullAccess = true;
final HstRequestContext context = RequestContextProvider.get();
if (context != null) {
HttpServletRequest request = context.getServletRequest();
String limitedParam = request.getParameter("_limited");
if (limitedParam != null && limitedParam.equals("true")) {
fullAccess = false;
}
}
return fullAccess;
}
use of org.hippoecm.hst.core.request.HstRequestContext in project hippo by NHS-digital-website.
the class Publishedworkchapter method getPublishedWork.
public Publishedwork getPublishedWork() {
final HstRequestContext context = RequestContextProvider.get();
// Publishedworkchapter publishedWorkChapter = context.getContentBean(Publishedworkchapter.class);
try {
HstQuery linkedBeanQuery = ContentBeanUtils.createIncomingBeansQuery(this.getCanonicalBean(), context.getSiteContentBaseBean(), "website:links/@hippo:docbase", Publishedwork.class, false);
linkedBeanQuery.setLimit(1);
return (Publishedwork) linkedBeanQuery.execute().getHippoBeans().nextHippoBean();
} catch (QueryException queryException) {
log.warn("QueryException ", queryException);
}
return null;
}
use of org.hippoecm.hst.core.request.HstRequestContext in project hippo by NHS-digital-website.
the class ProjectUpdateFeedComponent method addOrganisationFilter.
private void addOrganisationFilter(List<BaseFilter> filters, HstRequest request, HstQuery query) {
String organisationTitle = getSelectedOrganisationTitle(request);
if (StringUtils.isNotBlank(organisationTitle)) {
HippoBeanIterator organisationBeans;
try {
final HstRequestContext requestContext = request.getRequestContext();
HstQuery orgQuery = requestContext.getQueryManager().createQuery(requestContext.getSiteContentBaseBean(), Organisation.class);
Filter orgNameFilter = orgQuery.createFilter();
orgNameFilter.addEqualToCaseInsensitive("website:title", organisationTitle);
orgQuery.setFilter(orgNameFilter);
organisationBeans = orgQuery.execute().getHippoBeans();
} catch (QueryException e) {
log.debug("Error finding organisation with title {}: {}", organisationTitle, e);
return;
}
if (organisationBeans.getSize() == 0) {
return;
}
String jcrQuery;
if (organisationBeans.getSize() > 1) {
StringBuilder jcrQueryBuilder = new StringBuilder(String.format("((website:organisation/@hippo:docbase = '%s')", ((HippoDocument) organisationBeans.nextHippoBean()).getCanonicalHandleUUID()));
while (organisationBeans.hasNext()) {
jcrQueryBuilder.append(String.format(" or (website:organisation/@hippo:docbase = '%s')", ((HippoDocument) organisationBeans.nextHippoBean()).getCanonicalHandleUUID()));
}
jcrQueryBuilder.append(")");
jcrQuery = jcrQueryBuilder.toString();
} else {
jcrQuery = String.format("(website:organisation/@hippo:docbase = '%s')", ((HippoDocument) organisationBeans.nextHippoBean()).getCanonicalHandleUUID());
}
Filter filter = query.createFilter();
filter.addJCRExpression(jcrQuery);
filters.add(filter);
}
}
Aggregations