use of org.apereo.portal.layout.LayoutPortlet in project uPortal by Jasig.
the class LayoutRESTController method getRESTController.
/**
* A REST call to get a json feed of the current users layout. Intent was to provide a layout
* document without per-tab information for mobile device rendering.
*
* @param request The servlet request. Utilized to get the users instance and eventually there
* layout
* @param tab The tab name of which you would like to filter; optional; if not provided, will
* return entire layout.
* @return json feed of the layout
* @deprecated Use /api/v4-3/dlm/layout.json. It has much more information about portlets and
* includes regions and breakout per tab
*/
@Deprecated
@RequestMapping(value = "/layoutDoc", method = RequestMethod.GET)
public ModelAndView getRESTController(HttpServletRequest request, @RequestParam(value = "tab", required = false) String tab) {
final IPerson person = personManager.getPerson(request);
List<LayoutPortlet> portlets = new ArrayList<LayoutPortlet>();
try {
final IUserInstance ui = userInstanceManager.getUserInstance(request);
final IUserPreferencesManager upm = ui.getPreferencesManager();
final IUserProfile profile = upm.getUserProfile();
final DistributedUserLayout userLayout = userLayoutStore.getUserLayout(person, profile);
Document document = userLayout.getLayout();
NodeList portletNodes = null;
if (tab != null) {
NodeList folders = document.getElementsByTagName("folder");
for (int i = 0; i < folders.getLength(); i++) {
Node node = folders.item(i);
if (tab.equalsIgnoreCase(node.getAttributes().getNamedItem("name").getNodeValue())) {
TabListOfNodes tabNodes = new TabListOfNodes();
tabNodes.addAllChannels(node.getChildNodes());
portletNodes = tabNodes;
break;
}
}
} else {
portletNodes = document.getElementsByTagName("channel");
}
for (int i = 0; i < portletNodes.getLength(); i++) {
try {
NamedNodeMap attributes = portletNodes.item(i).getAttributes();
IPortletDefinition def = portletDao.getPortletDefinitionByFname(attributes.getNamedItem("fname").getNodeValue());
LayoutPortlet portlet = new LayoutPortlet(def);
portlet.setNodeId(attributes.getNamedItem("ID").getNodeValue());
//get alt max URL
String alternativeMaximizedLink = def.getAlternativeMaximizedLink();
if (alternativeMaximizedLink != null) {
portlet.setUrl(alternativeMaximizedLink);
portlet.setAltMaxUrl(true);
} else {
// get the maximized URL for this portlet
final IPortalUrlBuilder portalUrlBuilder = urlProvider.getPortalUrlBuilderByLayoutNode(request, attributes.getNamedItem("ID").getNodeValue(), UrlType.RENDER);
final IPortletWindowId targetPortletWindowId = portalUrlBuilder.getTargetPortletWindowId();
if (targetPortletWindowId != null) {
final IPortletUrlBuilder portletUrlBuilder = portalUrlBuilder.getPortletUrlBuilder(targetPortletWindowId);
portletUrlBuilder.setWindowState(WindowState.MAXIMIZED);
}
portlet.setUrl(portalUrlBuilder.getUrlString());
portlet.setAltMaxUrl(false);
}
portlets.add(portlet);
} catch (Exception e) {
log.warn("Exception construction JSON representation of mobile portlet", e);
}
}
ModelAndView mv = new ModelAndView();
mv.addObject("layout", portlets);
mv.setViewName("json");
return mv;
} catch (Exception e) {
log.error("Error retrieving user layout document", e);
}
return null;
}
use of org.apereo.portal.layout.LayoutPortlet in project uPortal by Jasig.
the class PortletsRESTController method getPortlet.
/**
* Provides information about a single portlet in the registry. NOTE: Access to this API enpoint
* requires only <code>IPermission.PORTAL_SUBSCRIBE</code> permission.
*/
@RequestMapping(value = "/portlet/{fname}.json", method = RequestMethod.GET)
public ModelAndView getPortlet(HttpServletRequest request, HttpServletResponse response, @PathVariable String fname) throws Exception {
IAuthorizationPrincipal ap = getAuthorizationPrincipal(request);
IPortletDefinition portletDef = portletDefinitionRegistry.getPortletDefinitionByFname(fname);
if (portletDef != null && ap.canRender(portletDef.getPortletDefinitionId().getStringId())) {
LayoutPortlet portlet = new LayoutPortlet(portletDef);
return new ModelAndView("json", "portlet", portlet);
} else {
response.setStatus(HttpServletResponse.SC_FORBIDDEN);
return new ModelAndView("json");
}
}
Aggregations