use of org.apereo.portal.portlet.om.IPortletPreference in project uPortal by Jasig.
the class PortletPreferencesImpl method setPortletPreferences.
public boolean setPortletPreferences(List<IPortletPreference> newPreferences) {
if (this.portletPreferences == newPreferences) {
return false;
}
if (newPreferences == null) {
final boolean modified = !this.portletPreferences.isEmpty();
this.portletPreferences = new ArrayList<IPortletPreference>(0);
return modified;
}
boolean modified = false;
// Build map of existing preferences for tracking which preferences have been removed
final Map<String, IPortletPreference> oldPreferences = new LinkedHashMap<String, IPortletPreference>();
for (final IPortletPreference preference : this.portletPreferences) {
oldPreferences.put(preference.getName(), preference);
}
this.portletPreferences.clear();
for (final IPortletPreference preference : newPreferences) {
final String name = preference.getName();
// Remove the existing preference from the map since it is supposed to be persisted
final IPortletPreference existingPreference = oldPreferences.remove(name);
if (existingPreference == null) {
modified = true;
// New preference, add it to the list
this.portletPreferences.add(preference);
} else {
modified = modified || !existingPreference.equals(preference);
// Existing preference, update the fields
existingPreference.setValues(preference.getValues());
existingPreference.setReadOnly(preference.isReadOnly());
this.portletPreferences.add(existingPreference);
}
}
return modified;
}
use of org.apereo.portal.portlet.om.IPortletPreference in project uPortal by Jasig.
the class HtmlPortletPreferenceSearchContentExtractorTest method testAppliesToPreferenceMatch.
@Test
public void testAppliesToPreferenceMatch() {
final IPortletDescriptorKey portletDescriptorKey = mock(IPortletDescriptorKey.class);
when(portletDescriptorKey.getPortletName()).thenAnswer(invocation -> NOT_A_MATCH);
when(portletDescriptorKey.getWebAppName()).thenAnswer(invocation -> NOT_A_MATCH);
final IPortletPreference portletPreference = mock(IPortletPreference.class);
when(portletPreference.getName()).thenAnswer(invocation -> PREFERENCE_NAME);
final IPortletDefinition portletDefinition = mock(IPortletDefinition.class);
when(portletDefinition.getPortletDescriptorKey()).thenAnswer(invocation -> portletDescriptorKey);
when(portletDefinition.getPortletPreferences()).thenAnswer(invocation -> Collections.singletonList(portletPreference));
assertFalse(EXTRACTOR.appliesTo(portletDefinition));
}
use of org.apereo.portal.portlet.om.IPortletPreference in project uPortal by Jasig.
the class RenderOnWebFlagSetPredicate method test.
@Override
public boolean test(final HttpServletRequest request) {
try {
final IPortletDefinition portletDefinition = utils.getPortletDefinitionFromServletRequest(request);
Iterator<IPortletPreference> iterator = portletDefinition.getPortletPreferences().iterator();
while (iterator.hasNext()) {
IPortletPreference cur = iterator.next();
if ("renderOnWeb".equalsIgnoreCase(cur.getName())) {
return cur.getValues() != null && cur.getValues().length == 1 && Boolean.parseBoolean(cur.getValues()[0]);
}
}
} catch (Exception e) {
logger.error("Failed to process renderOnWeb check for redirect during pipeline. Failing gracefully by returning false.", e);
}
return false;
}
use of org.apereo.portal.portlet.om.IPortletPreference in project uPortal by Jasig.
the class AbstractPortletPreferencesImplTest method testNullEntryInValues.
@Test
public void testNullEntryInValues() throws ReadOnlyException, ValidatorException, IOException {
portletPreferences.setValues("key", new String[] { null });
portletPreferences.store();
assertEquals(1, this.storedPrefs.size());
final IPortletPreference pref = this.storedPrefs.get("key");
assertNotNull(pref);
assertEquals("key", pref.getName());
assertArrayEquals(new String[] { null }, pref.getValues());
assertFalse(pref.isReadOnly());
}
use of org.apereo.portal.portlet.om.IPortletPreference in project uPortal by Jasig.
the class AbstractPortletPreferencesImplTest method testSetUpdateExisting.
@Test
public void testSetUpdateExisting() throws ReadOnlyException, ValidatorException, IOException {
addPref(basePrefs, "key", false, new String[] { "default" });
// Set a modified value
portletPreferences.setValues("key", new String[] { "modified" });
// Initial store, check that correct stored map is created
portletPreferences.store();
// Actually "store" the stored prefs
this.targetPrefs = new LinkedHashMap<String, IPortletPreference>(this.storedPrefs);
assertEquals(1, this.storedPrefs.size());
IPortletPreference pref = this.storedPrefs.get("key");
assertNotNull(pref);
assertEquals("key", pref.getName());
assertArrayEquals(new String[] { "modified" }, pref.getValues());
assertFalse(pref.isReadOnly());
// Set a modified value
portletPreferences.setValues("key", null);
// Initial store, check that correct stored map is created
portletPreferences.store();
// Actually "store" the stored prefs
this.targetPrefs = new LinkedHashMap<String, IPortletPreference>(this.storedPrefs);
assertEquals(1, this.storedPrefs.size());
pref = this.storedPrefs.get("key");
assertNotNull(pref);
assertEquals("key", pref.getName());
assertArrayEquals(null, pref.getValues());
assertFalse(pref.isReadOnly());
}
Aggregations