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;
}
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;
}
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.");
}
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;
}
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();
}
}
}
Aggregations