Search in sources :

Example 26 with IPortletPreference

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;
}
Also used : IPortletPreference(org.apereo.portal.portlet.om.IPortletPreference) LinkedHashMap(java.util.LinkedHashMap)

Example 27 with IPortletPreference

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));
}
Also used : IPortletPreference(org.apereo.portal.portlet.om.IPortletPreference) IPortletDescriptorKey(org.apereo.portal.portlet.om.IPortletDescriptorKey) IPortletDefinition(org.apereo.portal.portlet.om.IPortletDefinition) Test(org.junit.Test)

Example 28 with IPortletPreference

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;
}
Also used : IPortletPreference(org.apereo.portal.portlet.om.IPortletPreference) IPortletDefinition(org.apereo.portal.portlet.om.IPortletDefinition)

Example 29 with IPortletPreference

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());
}
Also used : IPortletPreference(org.apereo.portal.portlet.om.IPortletPreference) Test(org.junit.Test)

Example 30 with IPortletPreference

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());
}
Also used : IPortletPreference(org.apereo.portal.portlet.om.IPortletPreference) Test(org.junit.Test)

Aggregations

IPortletPreference (org.apereo.portal.portlet.om.IPortletPreference)37 Test (org.junit.Test)18 PortletPreferenceImpl (org.apereo.portal.portlet.dao.jpa.PortletPreferenceImpl)15 IPortletDefinitionId (org.apereo.portal.portlet.om.IPortletDefinitionId)12 IPortletDefinition (org.apereo.portal.portlet.om.IPortletDefinition)11 IPortletEntity (org.apereo.portal.portlet.om.IPortletEntity)10 List (java.util.List)8 BasePortalJpaDaoTest (org.apereo.portal.test.BasePortalJpaDaoTest)8 IPortletEntityId (org.apereo.portal.portlet.om.IPortletEntityId)7 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)7 ArrayList (java.util.ArrayList)6 Callable (java.util.concurrent.Callable)4 IPortletDescriptorKey (org.apereo.portal.portlet.om.IPortletDescriptorKey)4 PortletDefinition (org.apache.pluto.container.om.portlet.PortletDefinition)3 Preference (org.apache.pluto.container.om.portlet.Preference)3 Preferences (org.apache.pluto.container.om.portlet.Preferences)3 IPortletDefinitionParameter (org.apereo.portal.portlet.om.IPortletDefinitionParameter)3 IPortletType (org.apereo.portal.portlet.om.IPortletType)3 LinkedHashSet (java.util.LinkedHashSet)2 ReadOnlyException (javax.portlet.ReadOnlyException)2