use of org.apereo.portal.portlets.BooleanAttribute in project uPortal by Jasig.
the class PortletAdministrationHelper method savePortletRegistration.
/**
* Persist a new or edited PortletDefinition from a form, replacing existing values.
*
* @param publisher {@code IPerson} that requires permission to save this definition
* @param form form data to persist
* @return new {@code PortletDefinitionForm} for this portlet ID
*/
public PortletDefinitionForm savePortletRegistration(IPerson publisher, PortletDefinitionForm form) throws Exception {
// is made when the user enters the lifecycle-selection step in the wizard.)
if (!hasLifecyclePermission(publisher, form.getLifecycleState(), form.getCategories())) {
logger.warn("User '" + publisher.getUserName() + "' attempted to save the following portlet without the selected MANAGE permission: " + form);
throw new SecurityException("Not Authorized");
}
if (!form.isNew()) {
// User must have the previous lifecycle permission
// in AT LEAST ONE previous category as well
IPortletDefinition def = this.portletDefinitionRegistry.getPortletDefinition(form.getId());
Set<PortletCategory> categories = portletCategoryRegistry.getParentCategories(def);
SortedSet<JsonEntityBean> categoryBeans = new TreeSet<>();
for (PortletCategory cat : categories) {
categoryBeans.add(new JsonEntityBean(cat));
}
if (!hasLifecyclePermission(publisher, def.getLifecycleState(), categoryBeans)) {
logger.warn("User '" + publisher.getUserName() + "' attempted to save the following portlet without the previous MANAGE permission: " + form);
throw new SecurityException("Not Authorized");
}
}
if (form.isNew() || portletDefinitionRegistry.getPortletDefinition(form.getId()).getType().getId() != form.getTypeId()) {
// User must have access to the selected CPD if s/he selected it in this interaction
final int selectedTypeId = form.getTypeId();
final PortletPublishingDefinition cpd = portletPublishingDefinitionDao.getChannelPublishingDefinition(selectedTypeId);
final Map<IPortletType, PortletPublishingDefinition> allowableCpds = this.getAllowableChannelPublishingDefinitions(publisher);
if (!allowableCpds.containsValue(cpd)) {
logger.warn("User '" + publisher.getUserName() + "' attempted to administer the following portlet without the selected " + IPermission.PORTLET_MANAGER_SELECT_PORTLET_TYPE + " permission: " + form);
throw new SecurityException("Not Authorized");
}
}
// create the principal array from the form's principal list -- only principals with permissions
final Set<IGroupMember> subscribePrincipalSet = new HashSet<>(form.getPrincipals().size());
final Set<IGroupMember> browsePrincipalSet = new HashSet<>(form.getPrincipals().size());
for (JsonEntityBean bean : form.getPrincipals()) {
final String subscribePerm = bean.getTypeAndIdHash() + "_" + IPermission.PORTLET_SUBSCRIBER_ACTIVITY;
final String browsePerm = bean.getTypeAndIdHash() + "_" + IPermission.PORTLET_BROWSE_ACTIVITY;
final EntityEnum entityEnum = bean.getEntityType();
final IGroupMember principal = entityEnum.isGroup() ? (GroupService.findGroup(bean.getId())) : (GroupService.getGroupMember(bean.getId(), entityEnum.getClazz()));
if (form.getPermissions().contains(subscribePerm)) {
subscribePrincipalSet.add(principal);
}
if (form.getPermissions().contains(browsePerm)) {
browsePrincipalSet.add(principal);
}
}
// create the category list from the form's category bean list
List<PortletCategory> categories = new ArrayList<>();
for (JsonEntityBean category : form.getCategories()) {
String id = category.getId();
String iCatID = id.startsWith("cat") ? id.substring(3) : id;
categories.add(portletCategoryRegistry.getPortletCategory(iCatID));
}
final IPortletType portletType = portletTypeRegistry.getPortletType(form.getTypeId());
if (portletType == null) {
throw new IllegalArgumentException("No IPortletType exists for ID " + form.getTypeId());
}
IPortletDefinition portletDef;
if (form.getId() == null) {
portletDef = new PortletDefinitionImpl(portletType, form.getFname(), form.getName(), form.getTitle(), form.getApplicationId(), form.getPortletName(), form.isFramework());
} else {
portletDef = portletDefinitionRegistry.getPortletDefinition(form.getId());
portletDef.setType(portletType);
portletDef.setFName(form.getFname());
portletDef.setName(form.getName());
portletDef.setTitle(form.getTitle());
portletDef.getPortletDescriptorKey().setWebAppName(form.getApplicationId());
portletDef.getPortletDescriptorKey().setPortletName(form.getPortletName());
portletDef.getPortletDescriptorKey().setFrameworkPortlet(form.isFramework());
}
portletDef.setDescription(form.getDescription());
portletDef.setTimeout(form.getTimeout());
// portletDef reflect the state of the form, in case any have changed.
for (String key : form.getParameters().keySet()) {
String value = form.getParameters().get(key).getValue();
if (!StringUtils.isBlank(value)) {
portletDef.addParameter(key, value);
}
}
portletDef.addParameter(IPortletDefinition.EDITABLE_PARAM, Boolean.toString(form.isEditable()));
portletDef.addParameter(IPortletDefinition.CONFIGURABLE_PARAM, Boolean.toString(form.isConfigurable()));
portletDef.addParameter(IPortletDefinition.HAS_HELP_PARAM, Boolean.toString(form.isHasHelp()));
portletDef.addParameter(IPortletDefinition.HAS_ABOUT_PARAM, Boolean.toString(form.isHasAbout()));
// Now add portlet preferences
List<IPortletPreference> preferenceList = new ArrayList<>();
for (String key : form.getPortletPreferences().keySet()) {
List<String> prefValues = form.getPortletPreferences().get(key).getValue();
if (prefValues != null && prefValues.size() > 0) {
String[] values = prefValues.toArray(new String[prefValues.size()]);
BooleanAttribute readOnly = form.getPortletPreferenceReadOnly().get(key);
preferenceList.add(new PortletPreferenceImpl(key, readOnly.getValue(), values));
}
}
portletDef.setPortletPreferences(preferenceList);
// Lastly update the PortletDefinition's lifecycle state & lifecycle-related metadata
updateLifecycleState(form, portletDef, publisher);
// The final parameter of IGroupMembers is used to set the initial SUBSCRIBE permission set
portletPublishingService.savePortletDefinition(portletDef, publisher, categories, new ArrayList<>(subscribePrincipalSet));
//updatePermissions(portletDef, subscribePrincipalSet, IPermission.PORTLET_SUBSCRIBER_ACTIVITY);
updatePermissions(portletDef, browsePrincipalSet, IPermission.PORTLET_BROWSE_ACTIVITY);
return this.createPortletDefinitionForm(publisher, portletDef.getPortletDefinitionId().getStringId());
}
use of org.apereo.portal.portlets.BooleanAttribute 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 (String activity : PORTLET_SUBSCRIBE_ACTIVITIES) {
addPermissionsFromRequestToForm(form, request, activity);
}
//Names of valid preferences and parameters
final Set<String> preferenceNames = new HashSet<String>();
final Set<String> parameterNames = new HashSet<String>();
//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