use of org.apereo.portal.layout.dlm.DistributedUserLayout in project uPortal by Jasig.
the class PortletMarketplaceController method getLayoutInfo.
@ResourceMapping("layoutInfo")
public String getLayoutInfo(ResourceRequest request, @RequestParam String portletFName, Model model) throws TransformerException {
Validate.notNull(portletFName, "Please supply a portlet fname");
final HttpServletRequest servletRequest = this.portalRequestUtils.getPortletHttpRequest(request);
IUserInstance ui = userInstanceManager.getUserInstance(servletRequest);
UserPreferencesManager upm = (UserPreferencesManager) ui.getPreferencesManager();
IUserLayoutManager ulm = upm.getUserLayoutManager();
IPerson person = ui.getPerson();
DistributedUserLayout userLayout = userLayoutStore.getUserLayout(person, upm.getUserProfile());
List<PortletTab> tabs = getPortletTabInfo(userLayout, portletFName);
boolean isFavorite = isPortletFavorited(ulm.getUserLayout(), portletFName);
model.addAttribute("favorite", isFavorite);
model.addAttribute("tabs", tabs);
return "json";
}
use of org.apereo.portal.layout.dlm.DistributedUserLayout 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.dlm.DistributedUserLayout in project uPortal by Jasig.
the class UpdatePreferencesServlet method subscribeToTab.
/**
* Subscribe a user to a pre-formatted tab (pulled DLM fragment).
*
* @param request
* @param response
* @return
* @throws IOException
*/
@RequestMapping(method = RequestMethod.POST, params = "action=subscribeToTab")
public ModelAndView subscribeToTab(HttpServletRequest request, HttpServletResponse response) throws IOException {
IUserInstance ui = userInstanceManager.getUserInstance(request);
IPerson per = getPerson(ui, response);
UserPreferencesManager upm = (UserPreferencesManager) ui.getPreferencesManager();
IUserLayoutManager ulm = upm.getUserLayoutManager();
// Get the fragment owner's name from the request and construct
// an IPerson object representing that user
String fragmentOwnerName = request.getParameter("sourceID");
if (StringUtils.isBlank(fragmentOwnerName)) {
logger.warn("Attempted to subscribe to tab with null owner ID");
response.sendError(HttpServletResponse.SC_BAD_REQUEST);
return new ModelAndView("jsonView", Collections.singletonMap("error", "Attempted to subscribe to tab with null owner ID"));
}
RestrictedPerson fragmentOwner = PersonFactory.createRestrictedPerson();
fragmentOwner.setUserName(fragmentOwnerName);
// Mark the currently-authenticated user as subscribed to this fragment.
// If an inactivated fragment registration already exists, update it
// as an active subscription. Otherwise, create a new fragment
// subscription.
IUserFragmentSubscription userFragmentInfo = userFragmentInfoDao.getUserFragmentInfo(per, fragmentOwner);
if (userFragmentInfo == null) {
userFragmentInfo = userFragmentInfoDao.createUserFragmentInfo(per, fragmentOwner);
} else {
userFragmentInfo.setActive(true);
userFragmentInfoDao.updateUserFragmentInfo(userFragmentInfo);
}
try {
// reload user layout and stylesheet to incorporate new DLM fragment
ulm.loadUserLayout(true);
// get the target node this new tab should be moved after
String destinationId = request.getParameter("elementID");
// get the user layout for the currently-authenticated user
int uid = userIdentityStore.getPortalUID(fragmentOwner, false);
final DistributedUserLayout userLayout = userLayoutStore.getUserLayout(per, upm.getUserProfile());
Document layoutDocument = userLayout.getLayout();
// attempt to find the new subscribed tab in the layout so we can
// move it
StringBuilder expression = new StringBuilder("//folder[@type='root']/folder[starts-with(@ID,'").append(Constants.FRAGMENT_ID_USER_PREFIX).append(uid).append("')]");
XPathFactory fac = XPathFactory.newInstance();
XPath xpath = fac.newXPath();
NodeList nodes = (NodeList) xpath.evaluate(expression.toString(), layoutDocument, XPathConstants.NODESET);
String sourceId = nodes.item(0).getAttributes().getNamedItem("ID").getTextContent();
ulm.moveNode(sourceId, ulm.getParentId(destinationId), destinationId);
ulm.saveUserLayout();
return new ModelAndView("jsonView", Collections.singletonMap("tabId", sourceId));
} catch (XPathExpressionException e) {
response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
return new ModelAndView("jsonView", Collections.singletonMap("error", "Xpath error"));
} catch (PortalException e) {
return handlePersistError(request, response, e);
}
}
Aggregations