use of org.apereo.portal.portlet.om.IPortletPreference in project uPortal by Jasig.
the class JpaPortletDaoTest method testAllDefinitionDaoMethods.
@Test
public void testAllDefinitionDaoMethods() throws Exception {
final IPortletDefinitionId portletDefinitionId = execute(new Callable<IPortletDefinitionId>() {
@Override
public IPortletDefinitionId call() {
final IPortletType channelType = jpaChannelTypeDao.createPortletType("BaseType", "foobar");
// Create a definition
final IPortletDefinition chanDef1 = new PortletDefinitionImpl(channelType, "fname1", "Test Portlet 1", "Test Portlet 1 Title", "/context1", "portletName1", false);
jpaPortletDefinitionDao.savePortletDefinition(chanDef1);
// Try all of the retrieval options
final IPortletDefinition portDef1a = jpaPortletDefinitionDao.getPortletDefinition(chanDef1.getPortletDefinitionId());
jpaPortletDefinitionDao.savePortletDefinition(chanDef1);
assertEquals(chanDef1, portDef1a);
// Create a second definition with the same app/portlet
final IPortletDefinition chanDef2 = new PortletDefinitionImpl(channelType, "fname2", "Test Portlet 2", "Test Portlet 2 Title", "/uPortal", "portletName2", true);
jpaPortletDefinitionDao.savePortletDefinition(chanDef2);
return chanDef2.getPortletDefinitionId();
}
});
execute(new CallableWithoutResult() {
@Override
protected void callWithoutResult() {
final IPortletDefinition chanDef2 = jpaPortletDefinitionDao.getPortletDefinitionByFname("fname2");
// Add some preferences
final List<IPortletPreference> prefsList2 = chanDef2.getPortletPreferences();
prefsList2.add(new PortletPreferenceImpl("prefName1", false, "val1", "val2"));
prefsList2.add(new PortletPreferenceImpl("prefName2", true, "val3", "val4"));
jpaPortletDefinitionDao.savePortletDefinition(chanDef2);
}
});
execute(new CallableWithoutResult() {
@Override
protected void callWithoutResult() {
final IPortletDefinition chanDef2 = jpaPortletDefinitionDao.getPortletDefinitionByFname("fname2");
// verify preferences
final List<IPortletPreference> prefsList2 = chanDef2.getPortletPreferences();
assertEquals(2, prefsList2.size());
}
});
execute(new CallableWithoutResult() {
@Override
protected void callWithoutResult() {
// Check prefs, remove one and another
final IPortletDefinition portDef3 = jpaPortletDefinitionDao.getPortletDefinitionByName("Test Portlet 2");
final List<IPortletPreference> prefsList3 = portDef3.getPortletPreferences();
final List<IPortletPreference> expectedPrefsList3 = new ArrayList<IPortletPreference>();
expectedPrefsList3.add(new PortletPreferenceImpl("prefName1", false, "val1", "val2"));
expectedPrefsList3.add(new PortletPreferenceImpl("prefName2", true, "val3", "val4"));
assertEquals(expectedPrefsList3, prefsList3);
prefsList3.remove(1);
prefsList3.add(new PortletPreferenceImpl("prefName3", false, "val5", "val6"));
jpaPortletDefinitionDao.savePortletDefinition(portDef3);
}
});
execute(new CallableWithoutResult() {
@Override
protected void callWithoutResult() {
// Check prefs
final IPortletDefinition portDef4 = jpaPortletDefinitionDao.getPortletDefinition(portletDefinitionId);
final List<IPortletPreference> prefsList4 = portDef4.getPortletPreferences();
final List<IPortletPreference> expectedPrefsList4 = new ArrayList<IPortletPreference>();
expectedPrefsList4.add(new PortletPreferenceImpl("prefName1", false, "val1", "val2"));
expectedPrefsList4.add(new PortletPreferenceImpl("prefName3", false, "val5", "val6"));
assertEquals(expectedPrefsList4, prefsList4);
}
});
}
use of org.apereo.portal.portlet.om.IPortletPreference 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.IPortletPreference 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.IPortletPreference in project uPortal by Jasig.
the class PortletDefinitionBeanTest method testFromMarketplacePortletDefinition.
@Test
public void testFromMarketplacePortletDefinition() {
Long id = 345L;
String name = "testName";
String[] keywords = new String[] { "val1", "val2" };
List<IPortletPreference> prefs = new ArrayList<>();
prefs.add(portletPref);
Mockito.when(portletPref.getName()).thenReturn("keywords");
Mockito.when(portletPref.getValues()).thenReturn(keywords);
Map<String, IPortletDefinitionParameter> params = new HashMap<>();
params.put("test1", portletDefParam);
MarketplacePortletDefinition mpd = buildMarketplacePortletDefinition(id, name, prefs, params);
PortletDefinitionBean pdb = PortletDefinitionBean.fromMarketplacePortletDefinition(mpd, Locale.ENGLISH, false);
assertEquals(averageRating, pdb.getAverageRating());
assertEquals(id, (Long) pdb.getId());
assertEquals(fName, pdb.getFname());
assertEquals(title, pdb.getTitle());
assertEquals(name, pdb.getName());
assertEquals(description, pdb.getDescription());
assertEquals(state.toString(), pdb.getState());
assertEquals(typeId, pdb.getTypeId());
assertEquals(usersRated, (Long) pdb.getRatingsCount());
assertEquals(params, pdb.getParameters());
assertEquals(Arrays.asList(keywords), pdb.getKeywords());
}
use of org.apereo.portal.portlet.om.IPortletPreference in project uPortal by Jasig.
the class ExternalPortletDefinitionUnmarshaller method unmarshall.
/* package-private */
IPortletDefinition unmarshall(ExternalPortletDefinition epd) {
final PortletDescriptor portletDescriptor = epd.getPortletDescriptor();
final Boolean isFramework = portletDescriptor.isIsFramework();
if (isFramework != null && isFramework && "UPGRADED_CHANNEL_IS_NOT_A_PORTLET".equals(portletDescriptor.getPortletName())) {
if (errorOnChannel) {
throw new IllegalArgumentException(epd.getFname() + " is not a portlet. It was likely an IChannel from a previous version of uPortal and cannot be imported.");
}
logger.warn(epd.getFname() + " is not a portlet. It was likely an IChannel from a previous version of uPortal and will not be imported.");
return null;
}
// get the portlet type
final IPortletType portletType = portletTypeRegistry.getPortletType(epd.getType());
if (portletType == null) {
throw new IllegalArgumentException("No portlet type registered for: " + epd.getType());
}
final String fname = epd.getFname();
IPortletDefinition rslt = portletDefinitionDao.getPortletDefinitionByFname(fname);
if (rslt == null) {
rslt = new PortletDefinitionImpl(portletType, fname, epd.getName(), epd.getTitle(), portletDescriptor.getWebAppName(), portletDescriptor.getPortletName(), isFramework != null ? isFramework : false);
} else {
final IPortletDescriptorKey portletDescriptorKey = rslt.getPortletDescriptorKey();
portletDescriptorKey.setPortletName(portletDescriptor.getPortletName());
if (isFramework != null && isFramework) {
portletDescriptorKey.setFrameworkPortlet(true);
portletDescriptorKey.setWebAppName(null);
} else {
portletDescriptorKey.setFrameworkPortlet(false);
portletDescriptorKey.setWebAppName(portletDescriptor.getWebAppName());
}
rslt.setName(epd.getName());
rslt.setTitle(epd.getTitle());
rslt.setType(portletType);
}
rslt.setDescription(epd.getDesc());
final BigInteger timeout = epd.getTimeout();
if (timeout != null) {
rslt.setTimeout(timeout.intValue());
}
final BigInteger actionTimeout = epd.getActionTimeout();
if (actionTimeout != null) {
rslt.setActionTimeout(actionTimeout.intValue());
}
final BigInteger eventTimeout = epd.getEventTimeout();
if (eventTimeout != null) {
rslt.setEventTimeout(eventTimeout.intValue());
}
final BigInteger renderTimeout = epd.getRenderTimeout();
if (renderTimeout != null) {
rslt.setRenderTimeout(renderTimeout.intValue());
}
final BigInteger resourceTimeout = epd.getResourceTimeout();
if (resourceTimeout != null) {
rslt.setResourceTimeout(resourceTimeout.intValue());
}
unmarshallLifecycle(epd.getLifecycle(), rslt);
final Set<IPortletDefinitionParameter> parameters = new LinkedHashSet<>();
for (ExternalPortletParameter param : epd.getParameters()) {
parameters.add(new PortletDefinitionParameterImpl(param.getName(), param.getValue()));
}
rslt.setParameters(parameters);
final ArrayList<IPortletPreference> preferenceList = new ArrayList<>();
for (ExternalPortletPreference pref : epd.getPortletPreferences()) {
final List<String> valueList = pref.getValues();
final String[] values = valueList.toArray(new String[valueList.size()]);
final Boolean readOnly = pref.isReadOnly();
preferenceList.add(new PortletPreferenceImpl(pref.getName(), readOnly != null ? readOnly : false, values));
}
rslt.setPortletPreferences(preferenceList);
return rslt;
}
Aggregations