Search in sources :

Example 21 with IPortletPreference

use of org.apereo.portal.portlet.om.IPortletPreference in project uPortal by Jasig.

the class MarketplacePortletDefinition method initPortletReleaseNotes.

private void initPortletReleaseNotes() {
    PortletReleaseNotes temp = new PortletReleaseNotes();
    for (IPortletPreference portletPreference : this.portletDefinition.getPortletPreferences()) {
        if (MarketplacePortletDefinition.RELEASE_DATE_PREFERENCE_NAME.equalsIgnoreCase(portletPreference.getName())) {
            try {
                DateTime dt = releaseDateFormatter.parseDateTime(portletPreference.getValues()[0]);
                temp.setReleaseDate(dt);
            } catch (Exception e) {
                logger.warn("Issue with parsing " + RELEASE_DATE_PREFERENCE_NAME + ". Should be in format " + RELEASE_DATE_FORMAT, e);
            }
            continue;
        }
        if (MarketplacePortletDefinition.RELEASE_NOTE_PREFERENCE_NAME.equalsIgnoreCase(portletPreference.getName())) {
            temp.setReleaseNotes(Arrays.asList(portletPreference.getValues()));
            continue;
        }
        if (MarketplacePortletDefinition.INITIAL_RELEASE_DATE_PREFERENCE_NAME.equalsIgnoreCase(portletPreference.getName())) {
            try {
                DateTime dt = releaseDateFormatter.parseDateTime(portletPreference.getValues()[0]);
                temp.setInitialReleaseDate(dt);
            } catch (Exception e) {
                logger.warn("Issue with parsing " + INITIAL_RELEASE_DATE_PREFERENCE_NAME + ". Should be in format " + RELEASE_DATE_FORMAT, e);
            }
            continue;
        }
    }
    this.setPortletReleaseNotes(temp);
}
Also used : IPortletPreference(org.apereo.portal.portlet.om.IPortletPreference) DateTime(org.joda.time.DateTime)

Example 22 with IPortletPreference

use of org.apereo.portal.portlet.om.IPortletPreference in project uPortal by Jasig.

the class PortletDefinitionBeanTest method testFromMarketplacePortletDefinitionNoKeywords.

@Test
public void testFromMarketplacePortletDefinitionNoKeywords() {
    Long id = 345L;
    String name = "testName";
    // Create a non-keyword list
    String[] nonKeywords = new String[] { "val1", "val2" };
    List<IPortletPreference> prefs = new ArrayList<>();
    prefs.add(portletPref);
    Mockito.when(portletPref.getName()).thenReturn("non-keywords");
    Mockito.when(portletPref.getValues()).thenReturn(nonKeywords);
    MarketplacePortletDefinition mpd = buildMarketplacePortletDefinition(id, name, prefs, null);
    PortletDefinitionBean pdb = PortletDefinitionBean.fromMarketplacePortletDefinition(mpd, Locale.ENGLISH, false);
    assertEquals(Collections.EMPTY_LIST, pdb.getKeywords());
}
Also used : IPortletPreference(org.apereo.portal.portlet.om.IPortletPreference) MarketplacePortletDefinition(org.apereo.portal.portlet.marketplace.MarketplacePortletDefinition) ArrayList(java.util.ArrayList) PortletDefinitionBean(org.apereo.portal.layout.dlm.remoting.registry.v43.PortletDefinitionBean) Test(org.junit.Test)

Example 23 with IPortletPreference

use of org.apereo.portal.portlet.om.IPortletPreference in project uPortal by Jasig.

the class AbstractPortletPreferencesImpl method setValues.

@Override
public final void setValues(String key, String[] values) throws ReadOnlyException {
    Assert.notNull(key, "Preference Key cannot be null");
    final Map<String, IPortletPreference> targetPortletPreferences = this.getTargetPortletPreferences();
    // Check if there is a base preference for the key
    final Map<String, IPortletPreference> basePortletPreferences = this.getBasePortletPreferences();
    final IPortletPreference basePreference = basePortletPreferences.get(key);
    if (basePreference != null) {
        if (this.isReadOnly(basePreference)) {
            throw new ReadOnlyException("Preference '" + key + "' is read only");
        }
        // if the set value matches base value, delete any target pref
        if (Arrays.equals(values, basePreference.getValues())) {
            this.reset(key);
            return;
        }
    }
    IPortletPreference portletPreference = targetPortletPreferences.get(key);
    // No target preference exists yet, create it and then update the composite map
    if (portletPreference == null) {
        portletPreference = new PortletPreferenceImpl(key, false, values != null ? values.clone() : null);
        targetPortletPreferences.put(key, portletPreference);
        final Map<String, IPortletPreference> compositePortletPreferences = this.getCompositePortletPreferences();
        compositePortletPreferences.put(key, portletPreference);
        this.modified = true;
    } else // Update the existing preference if the values array is different
    if (!Arrays.equals(values, portletPreference.getValues())) {
        portletPreference.setValues(values != null ? values.clone() : null);
        this.modified = true;
    }
}
Also used : IPortletPreference(org.apereo.portal.portlet.om.IPortletPreference) ReadOnlyException(javax.portlet.ReadOnlyException) PortletPreferenceImpl(org.apereo.portal.portlet.dao.jpa.PortletPreferenceImpl)

Example 24 with IPortletPreference

use of org.apereo.portal.portlet.om.IPortletPreference in project uPortal by Jasig.

the class AbstractPortletPreferencesImpl method reset.

@Override
public final void reset(String key) throws ReadOnlyException {
    final Map<String, IPortletPreference> basePortletPreferences = this.getBasePortletPreferences();
    final IPortletPreference basePreference = basePortletPreferences.get(key);
    if (this.isReadOnly(basePreference)) {
        throw new ReadOnlyException("Preference '" + key + "' is read only");
    }
    final Map<String, IPortletPreference> targetPortletPreferences = this.getTargetPortletPreferences();
    final IPortletPreference removed = targetPortletPreferences.remove(key);
    // There was a target preference with that key, update the composite preferences map
    if (removed != null) {
        final Map<String, IPortletPreference> compositePortletPreferences = this.getCompositePortletPreferences();
        if (basePreference != null) {
            compositePortletPreferences.put(key, basePreference);
        } else {
            compositePortletPreferences.remove(key);
        }
        this.modified = true;
    }
}
Also used : IPortletPreference(org.apereo.portal.portlet.om.IPortletPreference) ReadOnlyException(javax.portlet.ReadOnlyException)

Example 25 with IPortletPreference

use of org.apereo.portal.portlet.om.IPortletPreference in project uPortal by Jasig.

the class GuestPortletEntityPreferencesImpl method storeInternal.

@Override
protected boolean storeInternal() throws IOException, ValidatorException {
    final Map<String, IPortletPreference> targetPortletPreferences = this.getTargetPortletPreferences();
    if (targetPortletPreferences.isEmpty()) {
        return false;
    }
    final HttpServletRequest containerRequest = portletRequestContext.getContainerRequest();
    this.storeSessionPreferences(portletEntityId, containerRequest, targetPortletPreferences);
    return true;
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) IPortletPreference(org.apereo.portal.portlet.om.IPortletPreference)

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