Search in sources :

Example 11 with PortletPublishingDefinition

use of org.apereo.portal.portletpublishing.xml.PortletPublishingDefinition in project uPortal by Jasig.

the class PortletAdministrationHelper method cleanOptions.

public void cleanOptions(PortletDefinitionForm form, PortletRequest request) {
    // Add permission parameters to permissions collection
    form.clearPermissions();
    for (PortletPermissionsOnForm perm : PortletPermissionsOnForm.values()) {
        addPermissionsFromRequestToForm(form, request, perm.getActivity());
    }
    // Names of valid preferences and parameters
    final Set<String> preferenceNames = new HashSet<>();
    final Set<String> parameterNames = new HashSet<>();
    // Read all of the submitted channel parameter and portlet preference names from the request
    for (final Enumeration<String> e = request.getParameterNames(); e.hasMoreElements(); ) {
        final String name = e.nextElement();
        final Matcher nameMatcher = PARAM_PATTERN.matcher(name);
        if (nameMatcher.matches()) {
            final String paramType = nameMatcher.group(1);
            final String paramName = nameMatcher.group(2);
            if ("portletPreferences".equals(paramType)) {
                preferenceNames.add(paramName);
            } else if ("parameters".equals(paramType)) {
                parameterNames.add(paramName);
            }
        }
    }
    // Add all of the parameter and preference names that have default values in the CPD into
    // the valid name sets
    final PortletPublishingDefinition cpd = this.portletPublishingDefinitionDao.getChannelPublishingDefinition(form.getTypeId());
    for (final Step step : cpd.getSteps()) {
        final List<Parameter> parameters = step.getParameters();
        if (parameters != null) {
            for (final Parameter parameter : parameters) {
                final JAXBElement<? extends ParameterInputType> parameterInput = parameter.getParameterInput();
                if (parameterInput != null) {
                    final ParameterInputType parameterInputType = parameterInput.getValue();
                    if (parameterInputType != null && parameterInputType.getDefault() != null) {
                        parameterNames.add(parameter.getName());
                    }
                }
            }
        }
        final List<Preference> preferences = step.getPreferences();
        if (preferences != null) {
            for (final Preference preference : preferences) {
                final JAXBElement<? extends PreferenceInputType> preferenceInput = preference.getPreferenceInput();
                final PreferenceInputType preferenceInputType = preferenceInput.getValue();
                if (preferenceInputType instanceof MultiValuedPreferenceInputType) {
                    final MultiValuedPreferenceInputType multiValuedPreferenceInputType = (MultiValuedPreferenceInputType) preferenceInputType;
                    final List<String> defaultValues = multiValuedPreferenceInputType.getDefaults();
                    if (defaultValues != null && !defaultValues.isEmpty()) {
                        preferenceNames.add(preference.getName());
                    }
                } else if (preferenceInputType instanceof SingleValuedPreferenceInputType) {
                    final SingleValuedPreferenceInputType SingleValuedPreferenceInputType = (SingleValuedPreferenceInputType) preferenceInputType;
                    if (SingleValuedPreferenceInputType.getDefault() != null) {
                        preferenceNames.add(preference.getName());
                    }
                }
            }
        }
    }
    // - do it only if portlet doesn't support configMode
    if (!this.supportsConfigMode(form)) {
        final Map<String, StringListAttribute> portletPreferences = form.getPortletPreferences();
        final Map<String, BooleanAttribute> portletPreferencesOverrides = form.getPortletPreferenceReadOnly();
        for (final Iterator<Entry<String, StringListAttribute>> portletPreferenceEntryItr = portletPreferences.entrySet().iterator(); portletPreferenceEntryItr.hasNext(); ) {
            final Map.Entry<String, StringListAttribute> portletPreferenceEntry = portletPreferenceEntryItr.next();
            final String key = portletPreferenceEntry.getKey();
            final StringListAttribute valueAttr = portletPreferenceEntry.getValue();
            if (!preferenceNames.contains(key) || valueAttr == null) {
                portletPreferenceEntryItr.remove();
                portletPreferencesOverrides.remove(key);
            } else {
                final List<String> values = valueAttr.getValue();
                for (final Iterator<String> iter = values.iterator(); iter.hasNext(); ) {
                    String value = iter.next();
                    if (value == null) {
                        iter.remove();
                    }
                }
                if (values.size() == 0) {
                    portletPreferenceEntryItr.remove();
                    portletPreferencesOverrides.remove(key);
                }
            }
        }
    }
    final Map<String, Attribute> parameters = form.getParameters();
    for (final Iterator<Entry<String, Attribute>> parameterEntryItr = parameters.entrySet().iterator(); parameterEntryItr.hasNext(); ) {
        final Entry<String, Attribute> parameterEntry = parameterEntryItr.next();
        final String key = parameterEntry.getKey();
        final Attribute value = parameterEntry.getValue();
        if (!parameterNames.contains(key) || value == null || StringUtils.isBlank(value.getValue())) {
            parameterEntryItr.remove();
        }
    }
}
Also used : BooleanAttribute(org.apereo.portal.portlets.BooleanAttribute) Matcher(java.util.regex.Matcher) BooleanAttribute(org.apereo.portal.portlets.BooleanAttribute) StringListAttribute(org.apereo.portal.portlets.StringListAttribute) Attribute(org.apereo.portal.portlets.Attribute) PortletPublishingDefinition(org.apereo.portal.portletpublishing.xml.PortletPublishingDefinition) Step(org.apereo.portal.portletpublishing.xml.Step) SingleValuedPreferenceInputType(org.apereo.portal.portletpublishing.xml.SingleValuedPreferenceInputType) ParameterInputType(org.apereo.portal.portletpublishing.xml.ParameterInputType) Entry(java.util.Map.Entry) HashSet(java.util.HashSet) MultiValuedPreferenceInputType(org.apereo.portal.portletpublishing.xml.MultiValuedPreferenceInputType) SingleValuedPreferenceInputType(org.apereo.portal.portletpublishing.xml.SingleValuedPreferenceInputType) PreferenceInputType(org.apereo.portal.portletpublishing.xml.PreferenceInputType) MultiValuedPreferenceInputType(org.apereo.portal.portletpublishing.xml.MultiValuedPreferenceInputType) Preference(org.apereo.portal.portletpublishing.xml.Preference) IPortletPreference(org.apereo.portal.portlet.om.IPortletPreference) Parameter(org.apereo.portal.portletpublishing.xml.Parameter) StringListAttribute(org.apereo.portal.portlets.StringListAttribute) Map(java.util.Map) HashMap(java.util.HashMap)

Example 12 with PortletPublishingDefinition

use of org.apereo.portal.portletpublishing.xml.PortletPublishingDefinition in project uPortal by Jasig.

the class PortletAdministrationHelperTest method updateFormForSinglePortletTypeNoOpWhenMultiplePortletTypes.

/**
 * When there are multiple available portlet types, the method
 * updateFormForSinglePortletType(...) is a no-op returning null.
 *
 * <p>This test case verifies that the method returns null in this case.
 */
@Test
public void updateFormForSinglePortletTypeNoOpWhenMultiplePortletTypes() {
    PortletAdministrationHelper helper = new PortletAdministrationHelper();
    Map<IPortletType, PortletPublishingDefinition> portletDefinitions = new HashMap<>();
    IPortletType someType = new PortletTypeImpl("someType", "someUri");
    IPortletType someOtherType = new PortletTypeImpl("someOtherType", "someOtherUri");
    PortletPublishingDefinition someDefinition = new PortletPublishingDefinition();
    PortletPublishingDefinition someOtherDefinition = new PortletPublishingDefinition();
    portletDefinitions.put(someType, someDefinition);
    portletDefinitions.put(someOtherType, someOtherDefinition);
    PortletDefinitionForm form = new PortletDefinitionForm();
    assertNull(helper.updateFormForSinglePortletType(portletDefinitions, form));
}
Also used : PortletTypeImpl(org.apereo.portal.portlet.dao.jpa.PortletTypeImpl) IPortletType(org.apereo.portal.portlet.om.IPortletType) HashMap(java.util.HashMap) PortletPublishingDefinition(org.apereo.portal.portletpublishing.xml.PortletPublishingDefinition) Test(org.junit.Test)

Aggregations

PortletPublishingDefinition (org.apereo.portal.portletpublishing.xml.PortletPublishingDefinition)12 IPortletType (org.apereo.portal.portlet.om.IPortletType)7 Step (org.apereo.portal.portletpublishing.xml.Step)5 HashMap (java.util.HashMap)4 HashSet (java.util.HashSet)3 IPortletPreference (org.apereo.portal.portlet.om.IPortletPreference)3 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 Map (java.util.Map)2 MissingResourceException (java.util.MissingResourceException)2 JAXBException (javax.xml.bind.JAXBException)2 Preference (org.apereo.portal.portletpublishing.xml.Preference)2 BooleanAttribute (org.apereo.portal.portlets.BooleanAttribute)2 PortletDescriptor (org.apereo.portal.xml.PortletDescriptor)2 Test (org.junit.Test)2 Resource (org.springframework.core.io.Resource)2 ArrayList (java.util.ArrayList)1 LinkedHashMap (java.util.LinkedHashMap)1 Entry (java.util.Map.Entry)1 TreeSet (java.util.TreeSet)1