use of org.apereo.portal.portlet.om.IPortletEntity in project uPortal by Jasig.
the class JpaPortletEntityDao method getPortletEntity.
@Override
@DialectAwareTransactional(value = PostgreSQL81Dialect.class, exclude = false)
@PortalTransactionalReadOnly
@OpenEntityManager(unitName = PERSISTENCE_UNIT_NAME)
public IPortletEntity getPortletEntity(String layoutNodeId, int userId) {
Validate.notNull(layoutNodeId, "portletEntity can not be null");
/* Since portal entities mostly are retrieved in batches (for each "channel" element in user's layout), it is
* faster to retrieve all portlet entities, so that persistence framework can place them in 2nd level cache, and
* iterate over them manually instead of retrieving single portlet entity one by one. */
Set<IPortletEntity> entities = getPortletEntitiesForUser(userId);
for (IPortletEntity entity : entities) {
if (StringUtils.equals(entity.getLayoutNodeId(), layoutNodeId)) {
return entity;
}
}
return null;
}
use of org.apereo.portal.portlet.om.IPortletEntity in project uPortal by Jasig.
the class JpaPortletEntityDao method createPortletEntity.
@Override
@PortalTransactional
public IPortletEntity createPortletEntity(IPortletDefinitionId portletDefinitionId, String layoutNodeId, int userId) {
Validate.notNull(portletDefinitionId, "portletDefinitionId can not be null");
Validate.notEmpty(layoutNodeId, "layoutNodeId can not be null");
final IPortletDefinition portletDefinition = this.portletDefinitionDao.getPortletDefinition(portletDefinitionId);
if (portletDefinition == null) {
throw new DataRetrievalFailureException("No IPortletDefinition exists for IPortletDefinitionId='" + portletDefinitionId + "'");
}
IPortletEntity portletEntity = new PortletEntityImpl(portletDefinition, layoutNodeId, userId);
this.getEntityManager().persist(portletEntity);
return portletEntity;
}
use of org.apereo.portal.portlet.om.IPortletEntity in project uPortal by Jasig.
the class UserLayoutParameterProcessor method processParameters.
@Override
@SuppressWarnings("FallThrough")
public boolean processParameters(HttpServletRequest request, HttpServletResponse response) {
final IPortalRequestInfo portalRequestInfo = this.urlSyntaxProvider.getPortalRequestInfo(request);
final IUserInstance userInstance = this.userInstanceManager.getUserInstance(request);
final IUserPreferencesManager preferencesManager = userInstance.getPreferencesManager();
final IUserLayoutManager userLayoutManager = preferencesManager.getUserLayoutManager();
final String tabId = portalRequestInfo.getTargetedLayoutNodeId();
if (tabId != null) {
this.stylesheetUserPreferencesService.setStylesheetParameter(request, PreferencesScope.STRUCTURE, "focusedTabID", tabId);
}
// on a portlet, it will get overwritten with the new value below.
if (userLayoutManager instanceof TransientUserLayoutManagerWrapper) {
final TransientUserLayoutManagerWrapper transientUserLayoutManagerWrapper = (TransientUserLayoutManagerWrapper) userLayoutManager;
transientUserLayoutManagerWrapper.setFocusedId(null);
}
final UrlState urlState = portalRequestInfo.getUrlState();
switch(urlState) {
case DETACHED:
this.stylesheetUserPreferencesService.setStylesheetParameter(request, PreferencesScope.STRUCTURE, "detached", Boolean.TRUE.toString());
case MAX:
{
final IPortletRequestInfo portletRequestInfo = portalRequestInfo.getTargetedPortletRequestInfo();
if (portletRequestInfo != null) {
final IPortletWindowId targetWindowId = portletRequestInfo.getPortletWindowId();
final IPortletWindow portletWindow = this.portletWindowRegistry.getPortletWindow(request, targetWindowId);
final IPortletEntity portletEntity = portletWindow.getPortletEntity();
final String channelSubscribeId = portletEntity.getLayoutNodeId();
this.stylesheetUserPreferencesService.setStylesheetParameter(request, PreferencesScope.STRUCTURE, "userLayoutRoot", channelSubscribeId);
if (userLayoutManager instanceof TransientUserLayoutManagerWrapper) {
// get wrapper implementation for focusing
final TransientUserLayoutManagerWrapper transientUserLayoutManagerWrapper = (TransientUserLayoutManagerWrapper) userLayoutManager;
// .. and now set it as the focused id
transientUserLayoutManagerWrapper.setFocusedId(channelSubscribeId);
}
// If portletRequestInfo was null just fall through to NORMAL state
break;
}
}
case NORMAL:
default:
{
this.stylesheetUserPreferencesService.setStylesheetParameter(request, PreferencesScope.STRUCTURE, "userLayoutRoot", IUserLayout.ROOT_NODE_NAME);
break;
}
}
return true;
}
use of org.apereo.portal.portlet.om.IPortletEntity 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);
}
}
use of org.apereo.portal.portlet.om.IPortletEntity in project uPortal by Jasig.
the class SearchPortletController method modifySearchResultLinkTitle.
/**
* Since portlets don't have access to the portlet definition to create a useful search results
* link using something like the portlet definition's title, post-process the link text and for
* those portlets whose type is present in the substitution set, replace the title with the
* portlet definition's title.
*
* @param result Search results object (may be modified)
* @param httpServletRequest HttpServletRequest
* @param portletWindowId Portlet Window ID
*/
protected void modifySearchResultLinkTitle(SearchResult result, final HttpServletRequest httpServletRequest, final IPortletWindowId portletWindowId) {
// evaluation context.
if (result.getType().size() > 0 && result.getTitle().contains("${")) {
final IPortletWindow portletWindow = this.portletWindowRegistry.getPortletWindow(httpServletRequest, portletWindowId);
final IPortletEntity portletEntity = portletWindow.getPortletEntity();
final IPortletDefinition portletDefinition = portletEntity.getPortletDefinition();
final SpELEnvironmentRoot spelEnvironment = new SpELEnvironmentRoot(portletDefinition);
try {
result.setTitle(spELService.getValue(result.getTitle(), spelEnvironment));
} catch (SpelParseException | SpelEvaluationException e) {
result.setTitle("(Invalid portlet title) - see details in log file");
logger.error("Invalid Spring EL expression {} in search result portlet title", result.getTitle(), e);
}
}
}
Aggregations