use of org.apereo.portal.portlet.om.IPortletEntityId in project uPortal by Jasig.
the class PortletWindowRegistryImpl method initializePortletWindowData.
/**
* Initializes a newly created {@link PortletWindow}, the default implementation sets up the
* appropriate {@link WindowState} and {@link javax.portlet.PortletMode}
*/
protected void initializePortletWindowData(HttpServletRequest request, PortletWindowData portletWindowData) {
final IStylesheetDescriptor stylesheetDescriptor = getThemeStylesheetDescriptor(request);
final IPortletEntityId portletEntityId = portletWindowData.getPortletEntityId();
final IPortletEntity portletEntity = this.portletEntityRegistry.getPortletEntity(request, portletEntityId);
final WindowState entityWindowState = portletEntity.getWindowState(stylesheetDescriptor);
if (persistentWindowStates.contains(entityWindowState)) {
portletWindowData.setWindowState(entityWindowState);
} else if (entityWindowState != null) {
// Set of persistent window states must have changed, nuke the old value
this.logger.warn("PortletEntity.windowState=" + entityWindowState + " but that state is not in the set of persistent WindowStates. PortletEntity.windowState will be set to null");
portletEntity.setWindowState(stylesheetDescriptor, null);
this.portletEntityRegistry.storePortletEntity(request, portletEntity);
}
}
use of org.apereo.portal.portlet.om.IPortletEntityId in project uPortal by Jasig.
the class PortletWindowRegistryImpl method wrapPortletWindowData.
protected IPortletWindow wrapPortletWindowData(HttpServletRequest request, PortletWindowData portletWindowData) {
final IPortletEntityId portletEntityId = portletWindowData.getPortletEntityId();
final IPortletEntity portletEntity = this.portletEntityRegistry.getPortletEntity(request, portletEntityId);
if (portletEntity == null) {
return null;
}
final IPortletDefinition portletDefinition = portletEntity.getPortletDefinition();
final PortletDefinition portletDescriptor = this.portletDefinitionRegistry.getParentPortletDescriptor(portletDefinition.getPortletDefinitionId());
if (portletDescriptor == null) {
return null;
}
final IPortletWindow portletWindow = new PortletWindowImpl(portletDescriptor, portletEntity, portletWindowData);
logger.trace("Wrapping PortletWindowData {} as IPortletWindow", portletWindow.getPortletWindowId());
return portletWindow;
}
use of org.apereo.portal.portlet.om.IPortletEntityId in project uPortal by Jasig.
the class PortletWindowRegistryImpl method getOrCreateDefaultPortletWindow.
@Override
public IPortletWindow getOrCreateDefaultPortletWindow(HttpServletRequest request, IPortletDefinitionId portletDefinitionId) {
Validate.notNull(request, "HttpServletRequest cannot be null");
Validate.notNull(portletDefinitionId, "portletDefinition cannot be null");
final IPortletEntity portletEntity = this.portletEntityRegistry.getOrCreateDefaultPortletEntity(request, portletDefinitionId);
final IPortletEntityId portletEntityId = portletEntity.getPortletEntityId();
return this.getOrCreateDefaultPortletWindow(request, portletEntityId);
}
use of org.apereo.portal.portlet.om.IPortletEntityId in project uPortal by Jasig.
the class PortletEntityRegistryImplTest method testInterimAddingPrefsAlreadyPersistent.
// interim with prefs & in db - get db version & update
@Test
public void testInterimAddingPrefsAlreadyPersistent() 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());
/*
* T1 - create ientity
* T2 - get ientity
* T2 - add pref and store ientity converting it to pentity
* T1 - add pref to ientity and store
*/
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 - Add a preference
final List<IPortletPreference> preferences = portletEntity.getPortletPreferences();
final IPortletPreference portletPreference = new PortletPreferenceImpl("pref1", false, "value");
preferences.add(portletPreference);
// 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(PersistentPortletEntityWrapper.class, portletEntity.getClass());
final List<IPortletPreference> preferences = portletEntity.getPortletPreferences();
assertEquals(1, preferences.size());
return null;
}
});
}
use of org.apereo.portal.portlet.om.IPortletEntityId in project uPortal by Jasig.
the class PortletEntityRegistryImplTest method testInterimAddingPrefs.
// interim with prefs & not in db - create new & update, delete interim
@Test
public void testInterimAddingPrefs() 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());
return null;
}
});
}
Aggregations