use of org.springframework.web.portlet.bind.annotation.RenderMapping in project uPortal by Jasig.
the class FavoritesController method initializeView.
/**
* Handles all Favorites portlet VIEW mode renders. Populates model with user's favorites and
* selects a view to display those favorites.
*
* <p>View selection:
*
* <p>Returns "jsp/Favorites/view" in the normal case where the user has at least one favorited
* portlet or favorited collection.
*
* <p>Returns "jsp/Favorites/view_zero" in the edge case where the user has zero favorited
* portlets AND zero favorited collections.
*
* <p>Model: marketPlaceFname --> String functional name of Marketplace portlet, or null if not
* available. collections --> List of favorited collections (IUserLayoutNodeDescription s)
* favorites --> List of favorited individual portlets (IUserLayoutNodeDescription s)
*
* @param model . Spring model. This method adds three model attributes.
* @return jsp/Favorites/view[_zero]
*/
@RenderMapping
public String initializeView(Model model) {
IUserInstance ui = userInstanceManager.getUserInstance(portalRequestUtils.getCurrentPortalRequest());
UserPreferencesManager upm = (UserPreferencesManager) ui.getPreferencesManager();
IUserLayoutManager ulm = upm.getUserLayoutManager();
IUserLayout userLayout = ulm.getUserLayout();
// TODO: the portlet could predicate including a non-null marketplace portlet fname
// on the accessing user having permission to render the portlet referenced by that fname
// so that portlet would gracefully degrade when configured with bad marketplace portlet fname
// and also gracefully degrade when the accessing user doesn't have permission to access an otherwise
// viable configured marketplace. This complexity may not be worth it. Anyway it is not yet implemented.
model.addAttribute("marketplaceFname", this.marketplaceFName);
List<IUserLayoutNodeDescription> collections = FavoritesUtils.getFavoriteCollections(userLayout);
model.addAttribute("collections", collections);
List<IUserLayoutNodeDescription> favorites = FavoritesUtils.getFavoritePortlets(userLayout);
model.addAttribute("favorites", favorites);
// default to the regular old view
String viewName = "jsp/Favorites/view";
if (collections.isEmpty() && favorites.isEmpty()) {
// special edge case of zero favorites, switch to special view
viewName = "jsp/Favorites/view_zero";
}
logger.trace("Favorites Portlet VIEW mode render populated model [{}] for render by view {}.", model, viewName);
return viewName;
}
use of org.springframework.web.portlet.bind.annotation.RenderMapping in project SimpleContentPortlet by Jasig.
the class AttachmentsManagerController method main.
@RenderMapping
public ModelAndView main(final PortletRequest request) {
final Map<String, Object> model = new HashMap<String, Object>();
model.put("attachments", attachmentService.findAll(0, 65536));
ModelAndView view = new ModelAndView("view", model);
return view;
}
use of org.springframework.web.portlet.bind.annotation.RenderMapping in project uPortal by Jasig.
the class SoffitConnectorController method invokeService.
@RenderMapping
public void invokeService(final RenderRequest req, final RenderResponse res) {
final PortletPreferences prefs = req.getPreferences();
final String serviceUrl = prefs.getValue(SERVICE_URL_PREFERENCE, null);
if (serviceUrl == null) {
throw new IllegalStateException("Missing portlet prefernce value for " + SERVICE_URL_PREFERENCE);
}
// First look in cache for an existing response that applies to this request
ResponseWrapper responseValue = fetchContentFromCacheIfAvailable(req, serviceUrl);
if (responseValue != null) {
logger.debug("Response value obtained from cache for serviceUrl '{}'", serviceUrl);
} else {
logger.debug("No applicable response in cache; invoking serviceUrl '{}'", serviceUrl);
final HttpGet getMethod = new HttpGet(serviceUrl);
try (final CloseableHttpClient httpClient = httpClientBuilder.build()) {
// Send the data model as encrypted JWT HTTP headers
for (IHeaderProvider headerProvider : headerProviders) {
final Header header = headerProvider.createHeader(req, res);
if (header != null) {
getMethod.addHeader(header);
}
}
// Send the request
final HttpResponse httpResponse = httpClient.execute(getMethod);
try {
final int statusCode = httpResponse.getStatusLine().getStatusCode();
logger.debug("HTTP response code for url '{}' was '{}'", serviceUrl, statusCode);
if (statusCode == HttpStatus.SC_OK) {
responseValue = extractResponseAndCacheIfAppropriate(httpResponse, req, serviceUrl);
} else {
logger.error("Failed to get content from remote service '{}'; HttpStatus={}", serviceUrl, statusCode);
res.getWriter().write("FAILED! statusCode=" + // TODO: Better message
statusCode);
}
} finally {
if (null != httpResponse) {
// Ensures that the entity content is fully consumed and the content stream,
// if exists, is closed.
EntityUtils.consumeQuietly(httpResponse.getEntity());
}
}
} catch (IOException e) {
logger.error("Failed to invoke serviceUrl '{}'", serviceUrl, e);
}
}
if (responseValue != null) {
// Whether by cache or by fresh HTTP request, we have a response we can show...
try {
res.getPortletOutputStream().write(responseValue.getBytes());
} catch (IOException e) {
logger.error("Failed to write the response for serviceUrl '{}'", serviceUrl, e);
}
}
}
use of org.springframework.web.portlet.bind.annotation.RenderMapping in project uPortal by Jasig.
the class ViewBackgroundPreferenceController method getView.
/**
* Display the main user-facing view of the portlet.
*
* @param request
* @return
*/
@RenderMapping
public String getView(RenderRequest req, Model model) {
final String[] images = imageSetSelectionStrategy.getImageSet(req);
model.addAttribute("images", images);
final String[] thumbnailImages = imageSetSelectionStrategy.getImageThumbnailSet(req);
model.addAttribute("thumbnailImages", thumbnailImages);
final String[] imageCaptions = imageSetSelectionStrategy.getImageCaptions(req);
model.addAttribute("imageCaptions", imageCaptions);
final String preferredBackgroundImage = imageSetSelectionStrategy.getSelectedImage(req);
model.addAttribute("backgroundImage", preferredBackgroundImage);
final String backgroundContainerSelector = imageSetSelectionStrategy.getBackgroundContainerSelector(req);
model.addAttribute("backgroundContainerSelector", backgroundContainerSelector);
final PortletPreferences prefs = req.getPreferences();
model.addAttribute("applyOpacityTo", prefs.getValue("applyOpacityTo", null));
model.addAttribute("opacityCssValue", prefs.getValue("opacityCssValue", "1.0"));
return "/jsp/BackgroundPreference/viewBackgroundPreference";
}
use of org.springframework.web.portlet.bind.annotation.RenderMapping in project uPortal by Jasig.
the class DynamicRespondrSkinViewController method displaySkinCssHeader.
/**
* Display Skin CSS include based on skin's configuration values from portlet preferences.<br>
* dynamic=false: load the pre-built css file from the skins directory and default skin name;
* e.g. RELATIVE_ROOT/{defaultSkin}.css dynamic=true: Process the default skin less file if
* needed at RELATIVE_ROOT/{defaultSkin}.less to create a customized skin css file
* (RELATIVE_ROOT/skin-ID#.css to load.
*/
@RenderMapping
public ModelAndView displaySkinCssHeader(RenderRequest request, RenderResponse response, Model model) throws IOException {
if (PortletRequest.RENDER_HEADERS.equals(request.getAttribute(PortletRequest.RENDER_PART))) {
PortletPreferences prefs = request.getPreferences();
Boolean enabled = Boolean.valueOf(prefs.getValue(DynamicRespondrSkinConstants.PREF_DYNAMIC, "false"));
String skinName = prefs.getValue(DynamicRespondrSkinConstants.PREF_SKIN_NAME, DynamicRespondrSkinConstants.DEFAULT_SKIN_NAME);
String cssUrl = enabled ? calculateDynamicSkinUrlPathToUse(request, skinName) : calculateDefaultSkinCssLocationInWebapp(skinName);
model.addAttribute(DynamicRespondrSkinConstants.SKIN_CSS_URL_MODEL_ATTRIBUTE_NAME, cssUrl);
return new ModelAndView("jsp/DynamicRespondrSkin/skinHeader");
} else {
// We need to know if this user can CONFIG this skin
// Default
boolean canAccessSkinConfig = false;
final HttpServletRequest httpr = portalRequestUtils.getCurrentPortalRequest();
final IPerson user = personManager.getPerson(httpr);
final IAuthorizationPrincipal principal = AuthorizationPrincipalHelper.principalFromUser(user);
final IPortletWindowId portletWindowId = portletWindowRegistry.getPortletWindowId(httpr, request.getWindowID());
final IPortletWindow portletWindow = portletWindowRegistry.getPortletWindow(httpr, portletWindowId);
final IPortletEntity portletEntity = portletWindow.getPortletEntity();
if (principal.canConfigure(portletEntity.getPortletDefinitionId().toString())) {
canAccessSkinConfig = true;
}
// RENDER_MARKUP
return new ModelAndView("jsp/DynamicRespondrSkin/skinBody", DynamicRespondrSkinConstants.CAN_ACCESS_SKIN_CONFIG_MODEL_NAME, canAccessSkinConfig);
}
}
Aggregations