Search in sources :

Example 1 with Step

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

the class XmlChannelPublishingDefinitionDaoTest method getCpdCache.

/**
 * @return
 */
public static Map<Integer, PortletPublishingDefinition> getCpdCache() {
    Map<Integer, PortletPublishingDefinition> cpdCache = new HashMap<>();
    PortletPublishingDefinition portletPublishingDefinition = new PortletPublishingDefinition();
    PortletDescriptor portletDescriptor = new PortletDescriptor();
    portletDescriptor.setWebAppName("/WebProxyPortlet");
    portletDescriptor.setPortletName("WebProxyPortlet");
    portletDescriptor.setIsFramework(false);
    portletPublishingDefinition.setPortletDescriptor(portletDescriptor);
    List<Step> steps = portletPublishingDefinition.getSteps();
    Step step = new Step();
    step.setName("General Configuration");
    step.setDescription("Use the configuration options after reviewing the portlet publishing information to configure the portlet.");
    steps.add(step);
    cpdCache.put(1010, portletPublishingDefinition);
    return cpdCache;
}
Also used : PortletDescriptor(org.apereo.portal.xml.PortletDescriptor) HashMap(java.util.HashMap) PortletPublishingDefinition(org.apereo.portal.portletpublishing.xml.PortletPublishingDefinition) Step(org.apereo.portal.portletpublishing.xml.Step)

Example 2 with Step

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

the class XmlChannelPublishingDefinitionDao method loadChannelPublishingDefinition.

private PortletPublishingDefinition loadChannelPublishingDefinition(int channelTypeId) {
    // if the CPD is not already in the cache, determine the CPD URI
    final String cpdUri;
    if (channelTypeId >= 0) {
        final IPortletType type = this.portletTypeRegistry.getPortletType(channelTypeId);
        if (type == null) {
            throw new IllegalArgumentException("No ChannelType registered with id: " + channelTypeId);
        }
        cpdUri = type.getCpdUri();
    } else {
        throw new IllegalArgumentException("No ChannelType registered with id: " + channelTypeId);
    }
    // read and parse the CPD
    final PortletPublishingDefinition def;
    final Resource cpdResource = this.resourceLoader.getResource("classpath:" + cpdUri);
    if (!cpdResource.exists()) {
        throw new MissingResourceException("Failed to find CPD '" + cpdUri + "' for channel type " + channelTypeId, this.getClass().getName(), cpdUri);
    }
    final InputStream cpdStream;
    try {
        cpdStream = cpdResource.getInputStream();
    } catch (IOException e) {
        throw new MissingResourceException("Failed to load CPD '" + cpdUri + "' for channel type " + channelTypeId, this.getClass().getName(), cpdUri);
    }
    try {
        def = (PortletPublishingDefinition) this.unmarshaller.unmarshal(cpdStream);
        final List<Step> sharedParameters = this.getSharedParameters();
        def.getSteps().addAll(sharedParameters);
        // add the CPD to the cache and return it
        this.cpdCache.put(channelTypeId, def);
        return def;
    } catch (JAXBException e) {
    } finally {
        IOUtils.closeQuietly(cpdStream);
    }
    return null;
}
Also used : IPortletType(org.apereo.portal.portlet.om.IPortletType) InputStream(java.io.InputStream) MissingResourceException(java.util.MissingResourceException) JAXBException(javax.xml.bind.JAXBException) Resource(org.springframework.core.io.Resource) PortletPublishingDefinition(org.apereo.portal.portletpublishing.xml.PortletPublishingDefinition) IOException(java.io.IOException) Step(org.apereo.portal.portletpublishing.xml.Step)

Example 3 with Step

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

the class XmlChannelPublishingDefinitionDaoTest method testGetChannelPublishingDefinition.

@Test
public void testGetChannelPublishingDefinition() {
    PortletPublishingDefinition portletPublishingDefinition = xmlChannelPublishingDefinitionDao.getChannelPublishingDefinition(1010);
    assertEquals(portletPublishingDefinition.getPortletDescriptor().getPortletName(), "WebProxyPortlet");
    assertEquals(portletPublishingDefinition.getPortletDescriptor().getWebAppName(), "/WebProxyPortlet");
    assertEquals(portletPublishingDefinition.getSteps().size(), 1);
    List<Step> steps = portletPublishingDefinition.getSteps();
    Step step = steps.get(0);
    assertEquals(step.getName(), "General Configuration");
    assertEquals(step.getDescription(), "Use the configuration options after reviewing the portlet publishing information to configure the portlet.");
}
Also used : PortletPublishingDefinition(org.apereo.portal.portletpublishing.xml.PortletPublishingDefinition) Step(org.apereo.portal.portletpublishing.xml.Step) Test(org.junit.Test)

Example 4 with Step

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

the class PortletAdministrationHelper method getArbitraryPortletPreferenceNames.

/**
 * Get a list of the key names of the currently-set arbitrary portlet preferences.
 *
 * @param form
 * @return
 */
public Set<String> getArbitraryPortletPreferenceNames(PortletDefinitionForm form) {
    // set default values for all portlet parameters
    PortletPublishingDefinition cpd = this.portletPublishingDefinitionDao.getChannelPublishingDefinition(form.getTypeId());
    Set<String> currentPrefs = new HashSet<>();
    currentPrefs.addAll(form.getPortletPreferences().keySet());
    for (Step step : cpd.getSteps()) {
        if (step.getPreferences() != null) {
            for (Preference pref : step.getPreferences()) {
                currentPrefs.remove(pref.getName());
            }
        }
    }
    return currentPrefs;
}
Also used : Preference(org.apereo.portal.portletpublishing.xml.Preference) IPortletPreference(org.apereo.portal.portlet.om.IPortletPreference) PortletPublishingDefinition(org.apereo.portal.portletpublishing.xml.PortletPublishingDefinition) Step(org.apereo.portal.portletpublishing.xml.Step) HashSet(java.util.HashSet)

Example 5 with Step

use of org.apereo.portal.portletpublishing.xml.Step 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)

Aggregations

Step (org.apereo.portal.portletpublishing.xml.Step)6 PortletPublishingDefinition (org.apereo.portal.portletpublishing.xml.PortletPublishingDefinition)5 IPortletPreference (org.apereo.portal.portlet.om.IPortletPreference)3 Preference (org.apereo.portal.portletpublishing.xml.Preference)3 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 MultiValuedPreferenceInputType (org.apereo.portal.portletpublishing.xml.MultiValuedPreferenceInputType)2 Parameter (org.apereo.portal.portletpublishing.xml.Parameter)2 ParameterInputType (org.apereo.portal.portletpublishing.xml.ParameterInputType)2 PreferenceInputType (org.apereo.portal.portletpublishing.xml.PreferenceInputType)2 SingleValuedPreferenceInputType (org.apereo.portal.portletpublishing.xml.SingleValuedPreferenceInputType)2 Attribute (org.apereo.portal.portlets.Attribute)2 BooleanAttribute (org.apereo.portal.portlets.BooleanAttribute)2 StringListAttribute (org.apereo.portal.portlets.StringListAttribute)2 PortletDescriptor (org.apereo.portal.xml.PortletDescriptor)2 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1 MissingResourceException (java.util.MissingResourceException)1