use of org.apereo.portal.layout.node.IUserLayoutChannelDescription in project uPortal by Jasig.
the class UpdatePreferencesServlet method removeFavorite.
/**
* This method removes the channelId specified from favorites. Note that even if you pass in the
* layout channel id, it will always remove from the favorites.
*
* @param channelId The long channel ID that is used to determine which fname to remove from
* favorites
* @param request
* @param response
* @return returns a mav object with a response attribute for noty
* @throws IOException if it has problem reading the layout file.
*/
@RequestMapping(method = RequestMethod.POST, params = "action=removeFavorite")
public ModelAndView removeFavorite(@RequestParam String channelId, HttpServletRequest request, HttpServletResponse response) throws IOException {
UserPreferencesManager upm = (UserPreferencesManager) userInstanceManager.getUserInstance(request).getPreferencesManager();
IUserLayoutManager ulm = upm.getUserLayoutManager();
final Locale locale = RequestContextUtils.getLocale(request);
IPortletDefinition portletDefinition = portletDefinitionRegistry.getPortletDefinition(channelId);
if (portletDefinition != null && StringUtils.isNotBlank(portletDefinition.getFName())) {
String functionalName = portletDefinition.getFName();
List<IUserLayoutNodeDescription> favoritePortlets = favoritesUtils.getFavoritePortletLayoutNodes(ulm.getUserLayout());
// Retrieve favorites matching functional name from list of favorites
List<IUserLayoutChannelDescription> favoritesToDelete = FavoritesUtils.getDuplicateFavoritesByFNameToDelete(favoritePortlets, functionalName);
String resp = new String();
for (IUserLayoutChannelDescription deleteNode : favoritesToDelete) {
if (deleteNode != null && deleteNode instanceof UserLayoutChannelDescription) {
UserLayoutChannelDescription channelDescription = (UserLayoutChannelDescription) deleteNode;
try {
if (!ulm.deleteNode(channelDescription.getChannelSubscribeId())) {
logger.warn("Error deleting the node {} from favorites for user {}", channelId, (upm.getPerson() == null ? "unknown" : upm.getPerson().getID()));
response.setStatus(HttpServletResponse.SC_FORBIDDEN);
// load fail message
resp = getMessage("error.remove.favorite", "Can''t remove favorite", locale);
} else {
// load success message
resp = getMessage("success.remove.portlet", "Removed from Favorites successfully", locale);
}
// save the user's layout
ulm.saveUserLayout();
} catch (PortalException e) {
return handlePersistError(request, response, e);
}
}
}
return new ModelAndView("jsonView", Collections.singletonMap("response", resp));
}
// save the user's layout
ulm.saveUserLayout();
return new ModelAndView("jsonView", Collections.singletonMap("response", getMessage("error.finding.favorite", "Can''t find favorite", locale)));
}
use of org.apereo.portal.layout.node.IUserLayoutChannelDescription in project uPortal by Jasig.
the class TransientPortletEntityDao method determineDatabaseChannelSubscribeId.
protected String determineDatabaseChannelSubscribeId(String layoutNodeId) {
// Find the referenced Node in the user's layout
final IUserLayoutManager userLayoutManager = this.getUserLayoutManager();
final IUserLayoutChannelDescription channelNode = (IUserLayoutChannelDescription) userLayoutManager.getNode(layoutNodeId);
// Lookup the IportletDefinition for the node
final String portletPublishId = channelNode.getChannelPublishId();
final IPortletDefinition portletDefinition = this.portletDefinitionRegistry.getPortletDefinition(portletPublishId);
// Generate the subscribe ID used for the database
return this.getPersistentLayoutNodeId(portletDefinition.getPortletDefinitionId());
}
use of org.apereo.portal.layout.node.IUserLayoutChannelDescription in project uPortal by Jasig.
the class FavoritesUtils method getFavoritePortletDefinitions.
public Set<IPortletDefinition> getFavoritePortletDefinitions(IUserLayout layout) {
final Set<IPortletDefinition> rslt = new HashSet<>();
final List<IUserLayoutNodeDescription> favoriteLayoutNodes = getFavoritePortletLayoutNodes(layout);
favoriteLayoutNodes.stream().forEach(node -> {
if (IUserLayoutChannelDescription.class.isInstance(node)) {
final IUserLayoutChannelDescription chanDef = (IUserLayoutChannelDescription) node;
// Not the most usable API...
final IPortletDefinitionId pId = new IPortletDefinitionId() {
@Override
public long getLongId() {
return Long.valueOf(chanDef.getChannelPublishId());
}
@Override
public String getStringId() {
return chanDef.getChannelPublishId();
}
};
final IPortletDefinition pDef = portletRegistry.getPortletDefinition(pId);
if (pDef != null) {
rslt.add(pDef);
}
}
});
return rslt;
}
use of org.apereo.portal.layout.node.IUserLayoutChannelDescription in project uPortal by Jasig.
the class FavoritesUtils method castListChannelDescriptionToListNodeDescription.
public static List<IUserLayoutNodeDescription> castListChannelDescriptionToListNodeDescription(List<IUserLayoutChannelDescription> nodeList) {
List<IUserLayoutNodeDescription> nodeDescriptionList = new ArrayList<>();
for (IUserLayoutNodeDescription nodeDescription : nodeList) {
if (nodeDescription instanceof IUserLayoutChannelDescription) {
final IUserLayoutChannelDescription channelDescription = (IUserLayoutChannelDescription) nodeDescription;
nodeDescriptionList.add(channelDescription);
}
}
return nodeDescriptionList;
}
Aggregations