use of org.apereo.portal.portlet.om.IPortletEntity in project uPortal by Jasig.
the class MobileUrlNodeSyntaxHelper method getFolderNameForPortlet.
/* (non-Javadoc)
* @see org.apereo.portal.url.IUrlNodeSyntaxHelper#getFolderNameForPortlet(javax.servlet.http.HttpServletRequest, org.apereo.portal.portlet.om.IPortletWindowId)
*/
@RequestCache(keyMask = { false, true })
@Override
public String getFolderNameForPortlet(HttpServletRequest request, IPortletWindowId portletWindowId) {
final IPortletWindow portletWindow = this.portletWindowRegistry.getPortletWindow(request, portletWindowId);
final IPortletEntity portletEntity = portletWindow.getPortletEntity();
final IPortletDefinition portletDefinition = portletEntity.getPortletDefinition();
final String fname = portletDefinition.getFName();
final String channelSubscribeId = portletEntity.getLayoutNodeId();
// Build the targeted portlet string (fname + subscribeId)
return fname + PORTLET_PATH_ELEMENT_SEPERATOR + channelSubscribeId;
}
use of org.apereo.portal.portlet.om.IPortletEntity in project uPortal by Jasig.
the class PortletEventCoordinatationService method resolvePortletEvents.
@Override
public void resolvePortletEvents(HttpServletRequest request, PortletEventQueue portletEventQueue) {
final Queue<QueuedEvent> events = portletEventQueue.getUnresolvedEvents();
// Skip all processing if there are no new events.
if (events.isEmpty()) {
return;
}
// Get all the portlets the user is subscribed to
final IUserInstance userInstance = this.userInstanceManager.getUserInstance(request);
final IUserPreferencesManager preferencesManager = userInstance.getPreferencesManager();
final IUserLayoutManager userLayoutManager = preferencesManager.getUserLayoutManager();
// Make a local copy so we can remove data from it
final Set<String> allLayoutNodeIds = new LinkedHashSet<String>(userLayoutManager.getAllSubscribedChannels());
final Map<String, IPortletEntity> portletEntityCache = new LinkedHashMap<String, IPortletEntity>();
while (!events.isEmpty()) {
final QueuedEvent queuedEvent = events.poll();
if (queuedEvent == null) {
// no more queued events, done resolving
return;
}
final IPortletWindowId sourceWindowId = queuedEvent.getPortletWindowId();
final Event event = queuedEvent.getEvent();
final boolean globalEvent = isGlobalEvent(request, sourceWindowId, event);
final Set<IPortletDefinition> portletDefinitions = new LinkedHashSet<IPortletDefinition>();
if (globalEvent) {
portletDefinitions.addAll(this.portletDefinitionRegistry.getAllPortletDefinitions());
}
// Check each subscription to see what events it is registered to see
for (final Iterator<String> layoutNodeIdItr = allLayoutNodeIds.iterator(); layoutNodeIdItr.hasNext(); ) {
final String layoutNodeId = layoutNodeIdItr.next();
IPortletEntity portletEntity = portletEntityCache.get(layoutNodeId);
if (portletEntity == null) {
portletEntity = this.portletEntityRegistry.getOrCreatePortletEntity(request, userInstance, layoutNodeId);
// remove it (see UP-3378)
if (portletEntity == null) {
layoutNodeIdItr.remove();
continue;
}
final IPortletDefinitionId portletDefinitionId = portletEntity.getPortletDefinitionId();
final PortletDefinition portletDescriptor = this.portletDefinitionRegistry.getParentPortletDescriptor(portletDefinitionId);
if (portletDescriptor == null) {
// Missconfigured portlet, remove it from the list so we don't check again
// and ignore it
layoutNodeIdItr.remove();
continue;
}
final List<? extends EventDefinitionReference> supportedProcessingEvents = portletDescriptor.getSupportedProcessingEvents();
// they are not checked again
if (supportedProcessingEvents == null || supportedProcessingEvents.size() == 0) {
layoutNodeIdItr.remove();
continue;
}
portletEntityCache.put(layoutNodeId, portletEntity);
}
final IPortletDefinition portletDefinition = portletEntity.getPortletDefinition();
final IPortletDefinitionId portletDefinitionId = portletDefinition.getPortletDefinitionId();
if (this.supportsEvent(event, portletDefinitionId)) {
this.logger.debug("{} supports event {}", portletDefinition, event);
// If this is the default portlet entity remove the definition from the all defs
// set to avoid duplicate processing
final IPortletEntity defaultPortletEntity = this.portletEntityRegistry.getOrCreateDefaultPortletEntity(request, portletDefinitionId);
if (defaultPortletEntity.equals(portletEntity)) {
portletDefinitions.remove(portletDefinition);
}
// Is this portlet permitted to receive events? (Or is it
// disablePortletEvents=true?)
IPortletDefinitionParameter disablePortletEvents = portletDefinition.getParameter(PortletExecutionManager.DISABLE_PORTLET_EVENTS_PARAMETER);
if (disablePortletEvents != null && Boolean.parseBoolean(disablePortletEvents.getValue())) {
logger.info("Ignoring portlet events for portlet '{}' because they have been disabled.", portletDefinition.getFName());
continue;
}
final IPortletEntityId portletEntityId = portletEntity.getPortletEntityId();
final Set<IPortletWindow> portletWindows = this.portletWindowRegistry.getAllPortletWindowsForEntity(request, portletEntityId);
for (final IPortletWindow portletWindow : portletWindows) {
this.logger.debug("{} resolved target {}", event, portletWindow);
final IPortletWindowId portletWindowId = portletWindow.getPortletWindowId();
final Event unmarshalledEvent = this.unmarshall(portletWindow, event);
portletEventQueue.offerEvent(portletWindowId, new QueuedEvent(sourceWindowId, unmarshalledEvent));
}
} else {
portletDefinitions.remove(portletDefinition);
}
}
if (!portletDefinitions.isEmpty()) {
final IPerson user = userInstance.getPerson();
final EntityIdentifier ei = user.getEntityIdentifier();
final IAuthorizationPrincipal ap = AuthorizationServiceFacade.instance().newPrincipal(ei.getKey(), ei.getType());
// targeting
for (final IPortletDefinition portletDefinition : portletDefinitions) {
// Is this portlet permitted to receive events? (Or is it
// disablePortletEvents=true?)
IPortletDefinitionParameter disablePortletEvents = portletDefinition.getParameter(PortletExecutionManager.DISABLE_PORTLET_EVENTS_PARAMETER);
if (disablePortletEvents != null && Boolean.parseBoolean(disablePortletEvents.getValue())) {
logger.info("Ignoring portlet events for portlet '{}' because they have been disabled.", portletDefinition.getFName());
continue;
}
final IPortletDefinitionId portletDefinitionId = portletDefinition.getPortletDefinitionId();
// Check if the user can render the portlet definition before doing event tests
if (ap.canRender(portletDefinitionId.getStringId())) {
if (this.supportsEvent(event, portletDefinitionId)) {
this.logger.debug("{} supports event {}", portletDefinition, event);
final IPortletEntity portletEntity = this.portletEntityRegistry.getOrCreateDefaultPortletEntity(request, portletDefinitionId);
final IPortletEntityId portletEntityId = portletEntity.getPortletEntityId();
final Set<IPortletWindow> portletWindows = this.portletWindowRegistry.getAllPortletWindowsForEntity(request, portletEntityId);
for (final IPortletWindow portletWindow : portletWindows) {
this.logger.debug("{} resolved target {}", event, portletWindow);
final IPortletWindowId portletWindowId = portletWindow.getPortletWindowId();
final Event unmarshalledEvent = this.unmarshall(portletWindow, event);
portletEventQueue.offerEvent(portletWindowId, new QueuedEvent(sourceWindowId, unmarshalledEvent));
}
}
}
}
}
}
}
use of org.apereo.portal.portlet.om.IPortletEntity in project uPortal by Jasig.
the class PortletErrorController method renderError.
/**
* Render the error portlet view.
*
* @param request
* @param response
* @param model
* @return the name of the view to display
* @throws Exception
*/
@RequestMapping("VIEW")
public String renderError(RenderRequest request, RenderResponse response, ModelMap model) throws Exception {
HttpServletRequest httpRequest = this.portalRequestUtils.getPortletHttpRequest(request);
IPortletWindowId currentFailedPortletWindowId = (IPortletWindowId) request.getAttribute(REQUEST_ATTRIBUTE__CURRENT_FAILED_PORTLET_WINDOW_ID);
model.addAttribute("portletWindowId", currentFailedPortletWindowId);
Exception cause = (Exception) request.getAttribute(REQUEST_ATTRIBUTE__CURRENT_EXCEPTION_CAUSE);
model.addAttribute("exception", cause);
final String rootCauseMessage = ExceptionUtils.getRootCauseMessage(cause);
model.addAttribute("rootCauseMessage", rootCauseMessage);
// Maintenance Mode?
if (cause != null && cause instanceof MaintenanceModeException) {
return "/jsp/PortletError/maintenance";
}
IUserInstance userInstance = this.userInstanceManager.getUserInstance(httpRequest);
if (hasAdminPrivileges(userInstance)) {
IPortletWindow window = this.portletWindowRegistry.getPortletWindow(httpRequest, currentFailedPortletWindowId);
window.setRenderParameters(new ParameterMap());
IPortalUrlBuilder adminRetryUrl = this.portalUrlProvider.getPortalUrlBuilderByPortletWindow(httpRequest, currentFailedPortletWindowId, UrlType.RENDER);
model.addAttribute("adminRetryUrl", adminRetryUrl.getUrlString());
final IPortletWindow portletWindow = portletWindowRegistry.getPortletWindow(httpRequest, currentFailedPortletWindowId);
final IPortletEntity parentPortletEntity = portletWindow.getPortletEntity();
final IPortletDefinition parentPortletDefinition = parentPortletEntity.getPortletDefinition();
model.addAttribute("channelDefinition", parentPortletDefinition);
StringWriter stackTraceWriter = new StringWriter();
cause.printStackTrace(new PrintWriter(stackTraceWriter));
model.addAttribute("stackTrace", stackTraceWriter.toString());
return "/jsp/PortletError/detailed";
}
// no admin privileges, return generic view
return "/jsp/PortletError/generic";
}
use of org.apereo.portal.portlet.om.IPortletEntity in project uPortal by Jasig.
the class PortletEntityRegistryImplTest method testPersistentUpdatingPrefs.
// persistent with prefs & in db - update
@Test
public void testPersistentUpdatingPrefs() throws Exception {
final IPortletDefinitionId portletDefId = this.createDefaultPorltetDefinition();
final String nodeId = "u1l1n1";
// Mock setup
final MockHttpServletRequest request = new MockHttpServletRequest();
when(portalRequestUtils.getOriginalPortalRequest(request)).thenReturn(request);
when(portalRequestUtils.getOriginalPortletOrPortalRequest(request)).thenReturn(request);
when(userInstanceManager.getUserInstance(request)).thenReturn(userInstance);
when(userInstance.getPreferencesManager()).thenReturn(preferencesManager);
when(userInstance.getPerson()).thenReturn(person);
when(preferencesManager.getUserLayoutManager()).thenReturn(userLayoutManager);
when(userLayoutManager.getNode(nodeId)).thenReturn(node);
when(node.getType()).thenReturn(LayoutNodeType.PORTLET);
when(node.getChannelPublishId()).thenReturn(portletDefId.getStringId());
final IPortletEntityId portletEntityId = this.execute(new Callable<IPortletEntityId>() {
@Override
public IPortletEntityId call() throws Exception {
// Create the entity
IPortletEntity portletEntity = portletEntityRegistry.getOrCreatePortletEntity(request, portletDefId, nodeId, 12);
assertEquals(SessionPortletEntityImpl.class, portletEntity.getClass());
return portletEntity.getPortletEntityId();
}
});
this.execute(new Callable<Object>() {
@Override
public Object call() throws Exception {
final IPortletEntity portletEntity = portletEntityRegistry.getPortletEntity(request, portletEntityId);
// Add a preference
final List<IPortletPreference> preferences = portletEntity.getPortletPreferences();
final IPortletPreference portletPreference = new PortletPreferenceImpl("pref", false, "value");
preferences.add(portletPreference);
// Store the entity
portletEntityRegistry.storePortletEntity(request, portletEntity);
return null;
}
});
this.execute(new Callable<Object>() {
@Override
public Object call() throws Exception {
// Verify it was converted from interim to persistent
final IPortletEntity portletEntity = portletEntityRegistry.getPortletEntity(request, portletEntityId);
assertEquals(PersistentPortletEntityWrapper.class, portletEntity.getClass());
final List<IPortletPreference> preferences = portletEntity.getPortletPreferences();
assertEquals(1, preferences.size());
// add another preference
final PortletPreferenceImpl portletPreference = new PortletPreferenceImpl("pref2", false, "valuea");
preferences.add(portletPreference);
// Store the entity
portletEntityRegistry.storePortletEntity(request, portletEntity);
return null;
}
});
this.execute(new Callable<Object>() {
@Override
public Object call() throws Exception {
// Verify it was converted from interim to persistent
final IPortletEntity portletEntity = portletEntityRegistry.getPortletEntity(request, portletEntityId);
assertEquals(PersistentPortletEntityWrapper.class, portletEntity.getClass());
final List<IPortletPreference> preferences = portletEntity.getPortletPreferences();
assertEquals(2, preferences.size());
return null;
}
});
}
use of org.apereo.portal.portlet.om.IPortletEntity in project uPortal by Jasig.
the class PortletEntityRegistryImplTest method testPersistentWithPrefsNotInDb.
// persistent with prefs & not in db - create new & update
@Test
// Hopelessly arcane issues troubleshooting org.hibernate.StaleObjectStateException
@Ignore
public void testPersistentWithPrefsNotInDb() throws Throwable {
final IPortletDefinitionId portDefId1 = this.createDefaultPorltetDefinition();
final String nodeId = "u1l1n1";
// Mock setup
final MockHttpServletRequest request = new MockHttpServletRequest();
when(portalRequestUtils.getOriginalPortalRequest(request)).thenReturn(request);
when(portalRequestUtils.getOriginalPortletOrPortalRequest(request)).thenReturn(request);
when(userInstanceManager.getUserInstance(request)).thenReturn(userInstance);
when(userInstance.getPreferencesManager()).thenReturn(preferencesManager);
when(userInstance.getPerson()).thenReturn(person);
when(preferencesManager.getUserLayoutManager()).thenReturn(userLayoutManager);
when(userLayoutManager.getNode(nodeId)).thenReturn(node);
when(node.getType()).thenReturn(LayoutNodeType.PORTLET);
when(node.getChannelPublishId()).thenReturn(portDefId1.getStringId());
final IPortletEntityId portletEntityId = this.execute(new Callable<IPortletEntityId>() {
@Override
public IPortletEntityId call() throws Exception {
// T1 - Create the entity
final IPortletEntity portletEntity = portletEntityRegistry.getOrCreatePortletEntity(request, portDefId1, nodeId, 12);
assertEquals(SessionPortletEntityImpl.class, portletEntity.getClass());
return portletEntity.getPortletEntityId();
}
});
/*
* T1 create entity
* T1 add preference, making persistent
* T2 delete preference, making interim
* T1 add preference 2 to persistent, stays persistent
*/
this.execute(new Callable<Object>() {
@Override
public Object call() throws Exception {
final IPortletEntity portletEntity = portletEntityRegistry.getPortletEntity(request, portletEntityId);
// Add a preference
final List<IPortletPreference> preferences = portletEntity.getPortletPreferences();
final IPortletPreference portletPreference = new PortletPreferenceImpl("pref", false, "value");
preferences.add(portletPreference);
// Store the entity
portletEntityRegistry.storePortletEntity(request, portletEntity);
return null;
}
});
this.execute(new Callable<Object>() {
@Override
public Object call() throws Exception {
// T1 - Verify it was converted from interim to persistent
final IPortletEntity portletEntity = portletEntityRegistry.getPortletEntity(request, portletEntityId);
assertEquals(PersistentPortletEntityWrapper.class, portletEntity.getClass());
final List<IPortletPreference> preferences = portletEntity.getPortletPreferences();
assertEquals(1, preferences.size());
// T2 - get the entity and add preferences
final IPortletEntityId localPortletEntityId = executeInThread("T2.1", new Callable<IPortletEntityId>() {
@Override
public IPortletEntityId call() throws Exception {
// T2 - Get entity
final IPortletEntity portletEntity = portletEntityRegistry.getPortletEntity(request, portletEntityId.getStringId());
assertEquals(portletEntity, portletEntity);
// T2 - add preference
final List<IPortletPreference> preferences = portletEntity.getPortletPreferences();
preferences.clear();
// T2 - Store the entity
portletEntityRegistry.storePortletEntity(request, portletEntity);
return portletEntity.getPortletEntityId();
}
});
// T2 - verify entity was made persistent
executeInThread("T2.2", new Callable<Object>() {
@Override
public Object call() throws Exception {
// T2 - Verify it was converted from persistent to interim
final IPortletEntity portletEntity = portletEntityRegistry.getPortletEntity(request, localPortletEntityId);
assertNotNull(portletEntity);
assertEquals(SessionPortletEntityImpl.class, portletEntity.getClass());
final List<IPortletPreference> preferences = portletEntity.getPortletPreferences();
assertEquals(0, preferences.size());
return null;
}
});
// T1 - add preference 2
final IPortletPreference portletPreference = new PortletPreferenceImpl("pref2", false, "value");
preferences.add(portletPreference);
// T1 - Store the entity
portletEntityRegistry.storePortletEntity(request, portletEntity);
return null;
}
});
this.execute(new Callable<Object>() {
@Override
public Object call() throws Exception {
// T1 - Verify it was converted from interim to persistent
final IPortletEntity portletEntity = portletEntityRegistry.getPortletEntity(request, portletEntityId);
assertEquals(PersistentPortletEntityWrapper.class, portletEntity.getClass());
final List<IPortletPreference> preferences = portletEntity.getPortletPreferences();
assertEquals(2, preferences.size());
return null;
}
});
}
Aggregations