use of org.apereo.portal.portlet.om.IPortletEntityId in project uPortal by Jasig.
the class PortletEntityRegistryImplTest method testInterimNoPrefsAlreadyPersistent.
// interim with no prefs & in db - delete db version
@Test
public void testInterimNoPrefsAlreadyPersistent() 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());
// T2 - get the entity and add preferences
final IPortletEntityId portletEntityId = executeInThread("T2.1", new Callable<IPortletEntityId>() {
@Override
public IPortletEntityId call() throws Exception {
// T2 - Get entity
final IPortletEntity localPortletEntity = portletEntityRegistry.getPortletEntity(request, portletEntity.getPortletEntityId().getStringId());
assertEquals(portletEntity, localPortletEntity);
// T2 - Add a preference
final List<IPortletPreference> preferences = localPortletEntity.getPortletPreferences();
final IPortletPreference portletPreference = new PortletPreferenceImpl("pref2", false, "value");
preferences.add(portletPreference);
// T2 - Store the entity
portletEntityRegistry.storePortletEntity(request, localPortletEntity);
return localPortletEntity.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 interim to
// persistent
IPortletEntity portletEntity = portletEntityRegistry.getPortletEntity(request, portletEntityId);
assertEquals(PersistentPortletEntityWrapper.class, portletEntity.getClass());
List<IPortletPreference> preferences = portletEntity.getPortletPreferences();
assertEquals(1, preferences.size());
return null;
}
});
// T1 - clear preferences
final List<IPortletPreference> preferences = portletEntity.getPortletPreferences();
preferences.clear();
// T1 - Store the entity
portletEntityRegistry.storePortletEntity(request, portletEntity);
return portletEntity.getPortletEntityId();
}
});
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(SessionPortletEntityImpl.class, portletEntity.getClass());
final List<IPortletPreference> preferences = portletEntity.getPortletPreferences();
assertEquals(0, preferences.size());
return null;
}
});
}
use of org.apereo.portal.portlet.om.IPortletEntityId in project uPortal by Jasig.
the class PortletEntityRegistryImplTest method testInterimNoPrefs.
// interim with no prefs & not in db - noop
@Test
public void testInterimNoPrefs() 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);
// Store the entity
portletEntityRegistry.storePortletEntity(request, portletEntity);
return null;
}
});
this.execute(new Callable<Object>() {
@Override
public Object call() throws Exception {
final IPortletEntity portletEntity = portletEntityRegistry.getPortletEntity(request, portletEntityId);
// Verify it is still interim
assertEquals(SessionPortletEntityImpl.class, portletEntity.getClass());
return null;
}
});
}
use of org.apereo.portal.portlet.om.IPortletEntityId in project uPortal by Jasig.
the class PortletEntityRegistryImplTest method testPersistentRemovePrefs.
// persistent with no prefs & in db - delete & create interim
@Test
public void testPersistentRemovePrefs() 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());
// remove all preferences
preferences.clear();
// Store the entity
portletEntityRegistry.storePortletEntity(request, portletEntity);
return null;
}
});
this.execute(new Callable<Object>() {
@Override
public Object call() throws Exception {
// Verify it switched from persistent to interim
final IPortletEntity portletEntity = portletEntityRegistry.getPortletEntity(request, portletEntityId);
assertEquals(SessionPortletEntityImpl.class, portletEntity.getClass());
final List<IPortletPreference> preferences = portletEntity.getPortletPreferences();
assertEquals(0, preferences.size());
return null;
}
});
}
use of org.apereo.portal.portlet.om.IPortletEntityId in project uPortal by Jasig.
the class GuestPortletEntityPreferencesImpl method getSessionPreferences.
/**
* Gets the session-stored list of IPortletPreferences for the specified request and
* IPortletEntityId.
*
* @return List of IPortletPreferences for the entity and session, may be null if no preferences
* have been set.
*/
@SuppressWarnings("unchecked")
protected Map<String, IPortletPreference> getSessionPreferences(IPortletEntityId portletEntityId, HttpServletRequest httpServletRequest) {
final HttpSession session = httpServletRequest.getSession();
final Map<IPortletEntityId, Map<String, IPortletPreference>> portletPreferences;
// Sync on the session to ensure the Map isn't in the process of being created
synchronized (session) {
portletPreferences = (Map<IPortletEntityId, Map<String, IPortletPreference>>) session.getAttribute(PORTLET_PREFERENCES_MAP_ATTRIBUTE);
}
if (portletPreferences == null) {
return null;
}
return portletPreferences.get(portletEntityId);
}
use of org.apereo.portal.portlet.om.IPortletEntityId in project uPortal by Jasig.
the class PortletCacheControlServiceImpl method cachePortletOutput.
private <D extends CachedPortletResultHolder<T>, T extends Serializable> void cachePortletOutput(IPortletWindowId portletWindowId, HttpServletRequest httpRequest, CacheState<D, T> cacheState, D cachedPortletData, Ehcache publicOutputCache, Ehcache privateOutputCache) {
final IPortletWindow portletWindow = this.portletWindowRegistry.getPortletWindow(httpRequest, portletWindowId);
final CacheControl cacheControl = cacheState.getCacheControl();
if (cacheControl.isPublicScope()) {
final PublicPortletCacheKey publicCacheKey = cacheState.getPublicPortletCacheKey();
this.cacheElement(publicOutputCache, publicCacheKey, cachedPortletData, cacheControl);
logger.debug("Cached public data under key {} for {}", publicCacheKey, portletWindow);
} else {
PrivatePortletCacheKey privateCacheKey = cacheState.getPrivatePortletCacheKey();
// portlet's response is now privately scoped
if (privateCacheKey == null) {
final HttpSession session = httpRequest.getSession();
final String sessionId = session.getId();
final IPortletEntityId entityId = portletWindow.getPortletEntityId();
final PublicPortletCacheKey publicCacheKey = cacheState.getPublicPortletCacheKey();
privateCacheKey = new PrivatePortletCacheKey(sessionId, portletWindowId, entityId, publicCacheKey);
}
this.cacheElement(privateOutputCache, privateCacheKey, cachedPortletData, cacheControl);
logger.debug("Cached private data under key {} for {}", privateCacheKey, portletWindow);
}
}
Aggregations