use of org.springframework.web.context.request.WebRequest in project uPortal by Jasig.
the class PortletMarketplaceController method setUpInitialView.
private void setUpInitialView(WebRequest webRequest, PortletRequest portletRequest, Model model, final String initialFilter) {
// We'll track and potentially log the time it takes to perform this initialization
final long timestamp = System.currentTimeMillis();
final HttpServletRequest servletRequest = this.portalRequestUtils.getPortletHttpRequest(portletRequest);
final PortletPreferences preferences = portletRequest.getPreferences();
final boolean isLogLevelDebug = logger.isDebugEnabled();
final IPerson user = personManager.getPerson(servletRequest);
final Map<String, Set<?>> registry = getRegistry(user, portletRequest);
@SuppressWarnings("unchecked") final Set<MarketplaceEntry> marketplaceEntries = (Set<MarketplaceEntry>) registry.get("portlets");
model.addAttribute("marketplaceEntries", marketplaceEntries);
@SuppressWarnings("unchecked") Set<PortletCategory> categoryList = (Set<PortletCategory>) registry.get("categories");
@SuppressWarnings("unchecked") final Set<MarketplaceEntry> featuredPortlets = (Set<MarketplaceEntry>) registry.get("featured");
model.addAttribute("featuredEntries", featuredPortlets);
// Determine if the marketplace is going to show the root category
String showRootCategoryPreferenceValue = preferences.getValue(SHOW_ROOT_CATEGORY_PREFERENCE, "false");
boolean showRootCategory = Boolean.parseBoolean(showRootCategoryPreferenceValue);
if (isLogLevelDebug) {
logger.debug("Going to show Root Category?: {}", Boolean.toString(showRootCategory));
}
if (showRootCategory == false) {
categoryList.remove(this.portletCategoryRegistry.getTopLevelPortletCategory());
}
logger.debug("initialFilter: {}", initialFilter);
String filter = initialFilter == null ? null : categoryList.stream().parallel().map(PortletCategory::getName).filter(cat -> cat.equals(initialFilter)).findAny().orElse("");
logger.debug("filter: {}", filter);
model.addAttribute("categoryList", categoryList);
model.addAttribute("initialFilter", filter);
logger.debug("Marketplace took {}ms in setUpInitialView for user '{}'", System.currentTimeMillis() - timestamp, user.getUserName());
}
use of org.springframework.web.context.request.WebRequest in project spring-boot by spring-projects.
the class ManagementErrorEndpointTests method errorResponseWithDefaultErrorAttributesSubclassWithoutDelegation.
@Test
void errorResponseWithDefaultErrorAttributesSubclassWithoutDelegation() {
ErrorAttributes attributes = new DefaultErrorAttributes() {
@Override
public Map<String, Object> getErrorAttributes(WebRequest webRequest, ErrorAttributeOptions options) {
return Collections.singletonMap("error", "custom error");
}
};
ManagementErrorEndpoint endpoint = new ManagementErrorEndpoint(attributes, this.errorProperties);
Map<String, Object> response = endpoint.invoke(new ServletWebRequest(new MockHttpServletRequest()));
assertThat(response).containsExactly(entry("error", "custom error"));
}
use of org.springframework.web.context.request.WebRequest in project BroadleafCommerce by BroadleafCommerce.
the class CartState method setCart.
/**
* Sets the current cart on the current request
*
* @param cart the new cart to set
*/
public static void setCart(Order cart) {
WebRequest request = BroadleafRequestContext.getBroadleafRequestContext().getWebRequest();
request.setAttribute(CartStateRequestProcessor.getCartRequestAttributeName(), cart, WebRequest.SCOPE_REQUEST);
}
use of org.springframework.web.context.request.WebRequest in project BroadleafCommerce by BroadleafCommerce.
the class CartStateRefresher method onApplicationEvent.
/**
* <p>Resets {@link CartState} with the newly persisted Order. If {@link CartState} was empty, this will only update it if
* the {@link Order} that has been persisted is the {@link OrderStatus#IN_PROCESS} {@link Order} for the active
* {@link Customer} (as determined by {@link CustomerState#getCustomer()}. If {@link CartState} was <b>not</b> empty,
* then it will be replaced only if this newly persisted {@link Order} has the same id.</p>
*
* <p>This ensures that whatever is returned from {@link CartState#getCart()} will always be the most up-to-date
* database version (meaning, safe to write to the DB).</p>
*/
@Override
public void onApplicationEvent(final OrderPersistedEvent event) {
WebRequest request = BroadleafRequestContext.getBroadleafRequestContext().getWebRequest();
if (request != null) {
Order dbOrder = event.getOrder();
// Update the cart state ONLY IF the IDs of the newly persisted order and whatever is already in CartState match
boolean emptyCartState = CartState.getCart() == null || CartState.getCart() instanceof NullOrderImpl;
if (emptyCartState) {
// If cart state is empty, set it to this newly persisted order if it's the active Customer's cart
if (CustomerState.getCustomer() != null && CustomerState.getCustomer().getId().equals(dbOrder.getCustomer().getId()) && OrderStatus.IN_PROCESS.equals(dbOrder.getStatus())) {
CartState.setCart(dbOrder);
}
} else if (CartState.getCart().getId().equals(dbOrder.getId())) {
CartState.setCart(dbOrder);
}
}
}
use of org.springframework.web.context.request.WebRequest in project spring-framework by spring-projects.
the class ServletRequestMethodArgumentResolverTests method setup.
@BeforeEach
public void setup() throws Exception {
resolver = new ServletRequestMethodArgumentResolver();
mavContainer = new ModelAndViewContainer();
servletRequest = new MockHttpServletRequest("GET", "");
webRequest = new ServletWebRequest(servletRequest, new MockHttpServletResponse());
method = getClass().getMethod("supportedParams", ServletRequest.class, MultipartRequest.class, HttpSession.class, Principal.class, Locale.class, InputStream.class, Reader.class, WebRequest.class, TimeZone.class, ZoneId.class, HttpMethod.class, PushBuilder.class);
}
Aggregations