use of org.apereo.portal.portlet.om.PortletCategory in project uPortal by Jasig.
the class PortletDefinitionImporterExporter method savePortletDefinition.
/**
* Save a portlet definition.
*
* @param definition the portlet definition
* @param publisher the person publishing the portlet
* @param categories the list of categories for the portlet
* @param permissionMap a map of permission name -> list of groups who are granted that
* permission (Note: for now, only grant is supported and only for the FRAMEWORK_OWNER perm
* manager)
*/
private IPortletDefinition savePortletDefinition(IPortletDefinition definition, IPerson publisher, List<PortletCategory> categories, Map<ExternalPermissionDefinition, Set<IGroupMember>> permissionMap) {
boolean newChannel = (definition.getPortletDefinitionId() == null);
// save the channel
definition = portletDefinitionDao.savePortletDefinition(definition);
definition = portletDefinitionDao.getPortletDefinitionByFname(definition.getFName());
final String defId = definition.getPortletDefinitionId().getStringId();
final IEntity portletDefEntity = GroupService.getEntity(defId, IPortletDefinition.class);
//The groups service needs to deal with concurrent modification better.
synchronized (this.groupUpdateLock) {
// Delete existing category memberships for this channel
if (!newChannel) {
for (IEntityGroup group : portletDefEntity.getAncestorGroups()) {
group.removeChild(portletDefEntity);
group.update();
}
}
// For each category ID, add channel to category
for (PortletCategory category : categories) {
final IEntityGroup categoryGroup = GroupService.findGroup(category.getId());
categoryGroup.addChild(portletDefEntity);
categoryGroup.updateMembers();
}
// Set groups
final AuthorizationService authService = AuthorizationService.instance();
final String target = PermissionHelper.permissionTargetIdForPortletDefinition(definition);
// Loop over the affected permission managers...
Map<String, Collection<ExternalPermissionDefinition>> permissionsBySystem = getPermissionsBySystem(permissionMap.keySet());
for (String system : permissionsBySystem.keySet()) {
Collection<ExternalPermissionDefinition> systemPerms = permissionsBySystem.get(system);
// get the permission manager for this system...
final IUpdatingPermissionManager upm = authService.newUpdatingPermissionManager(system);
final List<IPermission> permissions = new ArrayList<>();
// add activity grants for each permission..
for (ExternalPermissionDefinition permissionDef : systemPerms) {
Set<IGroupMember> members = permissionMap.get(permissionDef);
for (final IGroupMember member : members) {
final IAuthorizationPrincipal authPrincipal = authService.newPrincipal(member);
final IPermission permEntity = upm.newPermission(authPrincipal);
permEntity.setType(IPermission.PERMISSION_TYPE_GRANT);
permEntity.setActivity(permissionDef.getActivity());
permEntity.setTarget(target);
permissions.add(permEntity);
}
}
// If modifying the channel, remove the existing permissions before adding the new ones
if (!newChannel) {
for (ExternalPermissionDefinition permissionName : permissionMap.keySet()) {
IPermission[] oldPermissions = upm.getPermissions(permissionName.getActivity(), target);
upm.removePermissions(oldPermissions);
}
}
upm.addPermissions(permissions.toArray(new IPermission[permissions.size()]));
}
}
if (logger.isDebugEnabled()) {
logger.debug("Portlet " + defId + " has been " + (newChannel ? "published" : "modified") + ".");
}
return definition;
}
use of org.apereo.portal.portlet.om.PortletCategory in project uPortal by Jasig.
the class ChannelListController method preparePortletCategoryBean.
private PortletCategoryBean preparePortletCategoryBean(WebRequest req, PortletCategory category, Set<IPortletDefinition> portletsNotYetCategorized, IPerson user, Locale locale) {
/* Prepare child categories. */
Set<PortletCategoryBean> subcategories = new HashSet<>();
for (PortletCategory childCategory : this.portletCategoryRegistry.getChildCategories(category)) {
PortletCategoryBean childBean = preparePortletCategoryBean(req, childCategory, portletsNotYetCategorized, user, locale);
subcategories.add(childBean);
}
// add the direct child channels for this category
Set<IPortletDefinition> portlets = portletCategoryRegistry.getChildPortlets(category);
EntityIdentifier ei = user.getEntityIdentifier();
IAuthorizationPrincipal ap = AuthorizationService.instance().newPrincipal(ei.getKey(), ei.getType());
Set<PortletDefinitionBean> marketplacePortlets = new HashSet<>();
for (IPortletDefinition portlet : portlets) {
if (authorizationService.canPrincipalBrowse(ap, portlet)) {
PortletDefinitionBean pdb = preparePortletDefinitionBean(req, portlet, locale);
marketplacePortlets.add(pdb);
}
/*
* Remove the portlet from the uncategorized collection;
* note -- this approach will not prevent portlets from
* appearing in multiple categories (as appropriate).
*/
portletsNotYetCategorized.remove(portlet);
}
// construct a new portlet category bean for this category
PortletCategoryBean categoryBean = PortletCategoryBean.fromPortletCategory(category, subcategories, marketplacePortlets);
categoryBean.setName(messageSource.getMessage(category.getName(), new Object[] {}, locale));
return categoryBean;
}
use of org.apereo.portal.portlet.om.PortletCategory in project uPortal by Jasig.
the class PortletDefinitionImporterExporter method importData.
@Transactional
@Override
public void importData(ExternalPortletDefinition portletRep) {
final PortletDescriptor portletDescriptor = portletRep.getPortletDescriptor();
final Boolean isFramework = portletDescriptor.isIsFramework();
if (isFramework != null && isFramework && "UPGRADED_CHANNEL_IS_NOT_A_PORTLET".equals(portletDescriptor.getPortletName())) {
if (errorOnChannel) {
throw new IllegalArgumentException(portletRep.getFname() + " is not a portlet. It was likely an IChannel from a previous version of uPortal and cannot be imported.");
}
logger.warn(portletRep.getFname() + " is not a portlet. It was likely an IChannel from a previous version of uPortal and will not be imported.");
return;
}
// get the portlet type
final IPortletType portletType = portletTypeRegistry.getPortletType(portletRep.getType());
if (portletType == null) {
throw new IllegalArgumentException("No portlet type registered for: " + portletRep.getType());
}
final List<PortletCategory> categories = new ArrayList<PortletCategory>();
for (String categoryName : portletRep.getCategories()) {
EntityIdentifier[] cats = GroupService.searchForGroups(categoryName, IGroupConstants.IS, IPortletDefinition.class);
PortletCategory category = null;
if (cats != null && cats.length > 0) {
category = portletCategoryRegistry.getPortletCategory(cats[0].getKey());
} else {
category = portletCategoryRegistry.getPortletCategory(categoryName);
}
if (category == null) {
throw new IllegalArgumentException("No category '" + categoryName + "' found when importing portlet: " + portletRep.getFname());
}
categories.add(category);
}
final String fname = portletRep.getFname();
final Map<ExternalPermissionDefinition, Set<IGroupMember>> permissions = new HashMap<>();
final Set<IGroupMember> subscribeMembers = toGroupMembers(portletRep.getGroups(), fname);
permissions.put(ExternalPermissionDefinition.SUBSCRIBE, subscribeMembers);
if (portletRep.getPermissions() != null && portletRep.getPermissions().getPermissions() != null) {
for (ExternalPermissionMemberList perm : portletRep.getPermissions().getPermissions()) {
Set<IGroupMember> members = toGroupMembers(perm.getGroups(), fname);
ExternalPermissionDefinition permDef = toExternalPermissionDefinition(perm.getSystem(), perm.getActivity());
if (permissions.containsKey(permDef)) {
permissions.get(permDef).addAll(members);
} else {
permissions.put(permDef, members);
}
}
}
IPortletDefinition def = portletDefinitionDao.getPortletDefinitionByFname(fname);
if (def == null) {
def = new PortletDefinitionImpl(portletType, fname, portletRep.getName(), portletRep.getTitle(), portletDescriptor.getWebAppName(), portletDescriptor.getPortletName(), isFramework != null ? isFramework : false);
} else {
final IPortletDescriptorKey portletDescriptorKey = def.getPortletDescriptorKey();
portletDescriptorKey.setPortletName(portletDescriptor.getPortletName());
if (isFramework != null && isFramework) {
portletDescriptorKey.setFrameworkPortlet(true);
portletDescriptorKey.setWebAppName(null);
} else {
portletDescriptorKey.setFrameworkPortlet(false);
portletDescriptorKey.setWebAppName(portletDescriptor.getWebAppName());
}
def.setName(portletRep.getName());
def.setTitle(portletRep.getTitle());
def.setType(portletType);
}
def.setDescription(portletRep.getDesc());
final BigInteger timeout = portletRep.getTimeout();
if (timeout != null) {
def.setTimeout(timeout.intValue());
}
final BigInteger actionTimeout = portletRep.getActionTimeout();
if (actionTimeout != null) {
def.setActionTimeout(actionTimeout.intValue());
}
final BigInteger eventTimeout = portletRep.getEventTimeout();
if (eventTimeout != null) {
def.setEventTimeout(eventTimeout.intValue());
}
final BigInteger renderTimeout = portletRep.getRenderTimeout();
if (renderTimeout != null) {
def.setRenderTimeout(renderTimeout.intValue());
}
final BigInteger resourceTimeout = portletRep.getResourceTimeout();
if (resourceTimeout != null) {
def.setResourceTimeout(resourceTimeout.intValue());
}
handleLifecycleApproval(def, portletRep.getLifecycle());
handleLifecyclePublished(def, portletRep.getLifecycle());
handleLifecycleExpired(def, portletRep.getLifecycle());
final Set<IPortletDefinitionParameter> parameters = new LinkedHashSet<IPortletDefinitionParameter>();
for (ExternalPortletParameter param : portletRep.getParameters()) {
parameters.add(new PortletDefinitionParameterImpl(param.getName(), param.getValue()));
}
def.setParameters(parameters);
final ArrayList<IPortletPreference> preferenceList = new ArrayList<IPortletPreference>();
for (ExternalPortletPreference pref : portletRep.getPortletPreferences()) {
final List<String> valueList = pref.getValues();
final String[] values = valueList.toArray(new String[valueList.size()]);
final Boolean readOnly = pref.isReadOnly();
preferenceList.add(new PortletPreferenceImpl(pref.getName(), readOnly != null ? readOnly : false, values));
}
def.setPortletPreferences(preferenceList);
savePortletDefinition(def, systemUser, categories, permissions);
}
use of org.apereo.portal.portlet.om.PortletCategory in project uPortal by Jasig.
the class PortletCategoryRegistryImpl method getAllChildCategories.
/* (non-Javadoc)
* @see org.apereo.portal.portlet.registry.IPortletCategoryRegistry#getAllChildCategories(org.apereo.portal.portlet.om.PortletCategory)
*/
@Override
public Set<PortletCategory> getAllChildCategories(PortletCategory parent) {
Set<PortletCategory> rslt = new HashSet<PortletCategory>();
for (PortletCategory child : getChildCategories(parent)) {
// recurse
rslt.add(child);
rslt.addAll(getAllChildCategories(child));
}
return rslt;
}
use of org.apereo.portal.portlet.om.PortletCategory in project uPortal by Jasig.
the class PortletCategoryRegistryImpl method getPortletCategory.
/* (non-Javadoc)
* @see org.apereo.portal.portlet.registry.IPortletCategoryRegistry#getPortletCategory(java.lang.String)
*/
@Override
public PortletCategory getPortletCategory(String portletCategoryId) {
IEntityGroup categoryGroup = GroupService.findGroup(portletCategoryId);
if (categoryGroup == null) {
return null;
}
PortletCategory category = new PortletCategory(portletCategoryId);
category.setName(categoryGroup.getName());
category.setDescription(categoryGroup.getDescription());
category.setCreatorId(categoryGroup.getCreatorID());
return category;
}
Aggregations