use of org.hippoecm.hst.core.request.HstRequestContext in project hippo by NHS-digital-website.
the class DatasetComponent method doBeforeRender.
@Override
public void doBeforeRender(final HstRequest request, final HstResponse response) throws HstComponentException {
super.doBeforeRender(request, response);
final HstRequestContext ctx = request.getRequestContext();
Dataset dataset = (Dataset) ctx.getContentBean();
if (!dataset.isPubliclyAccessible()) {
try {
response.forward("/error/404");
} catch (IOException ioException) {
throw new HstComponentException("forward failed", ioException);
}
return;
}
request.setAttribute("dataset", dataset);
}
use of org.hippoecm.hst.core.request.HstRequestContext in project hippo by NHS-digital-website.
the class PublicationComponent method doBeforeRender.
@Override
public void doBeforeRender(final HstRequest request, final HstResponse response) throws HstComponentException {
super.doBeforeRender(request, response);
final HstRequestContext ctx = request.getRequestContext();
Publication publication = (Publication) ctx.getContentBean();
request.setAttribute("publication", publication);
request.setAttribute("index", getIndex(publication));
request.setAttribute("keyFactImageSections", pageSectionGrouper.groupSections(publication.getKeyFactImages()));
}
use of org.hippoecm.hst.core.request.HstRequestContext in project hippo by NHS-digital-website.
the class AccessTokenValve method invoke.
@Override
public void invoke(final ValveContext context) throws ContainerException {
try {
final HstRequestContext requestContext = context.getRequestContext();
final Optional<Cookie> cookieOptional = getCookie(requestContext.getServletRequest(), Constants.ACCESS_TOKEN_COOKIE_NAME);
if (cookieOptional.isPresent()) {
final Cookie cookie = cookieOptional.get();
AccessToken accessToken = encoder.decode(cookie.getValue());
if (accessToken.isExpired()) {
try {
accessToken = getNewAccessToken(requestContext, accessToken);
} catch (final AuthorizationException e) {
LOGGER.warn("Refresh token expired or not existent. User will need to login again.");
removeAccessToken(requestContext);
return;
}
}
requestContext.setAttribute(Constants.ACCESS_TOKEN_PROPERTY_NAME, accessToken.getToken());
}
} finally {
context.invokeNext();
}
}
use of org.hippoecm.hst.core.request.HstRequestContext in project hippo by NHS-digital-website.
the class NiHubComponent method doBeforeRender.
@Override
public void doBeforeRender(final HstRequest request, final HstResponse response) throws HstComponentException {
super.doBeforeRender(request, response);
final HstRequestContext ctx = request.getRequestContext();
request.setAttribute("document", ctx.getContentBean());
}
use of org.hippoecm.hst.core.request.HstRequestContext 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