use of org.apereo.portal.portlet.om.IPortletDefinition in project uPortal by Jasig.
the class PortletsRESTController method getManageablePortlets.
/**
* Provides information about all portlets in the portlet registry. NOTE: The response is
* governed by the <code>IPermission.PORTLET_MANAGER_xyz</code> series of permissions. The
* actual level of permission required is based on the current lifecycle state of the portlet.
*/
@RequestMapping(value = "/portlets.json", method = RequestMethod.GET)
public ModelAndView getManageablePortlets(HttpServletRequest request, HttpServletResponse response) throws Exception {
// get a list of all channels
List<IPortletDefinition> allPortlets = portletDefinitionRegistry.getAllPortletDefinitions();
IAuthorizationPrincipal ap = getAuthorizationPrincipal(request);
List<PortletTuple> rslt = new ArrayList<PortletTuple>();
for (IPortletDefinition pdef : allPortlets) {
if (ap.canManage(pdef.getPortletDefinitionId().getStringId())) {
rslt.add(new PortletTuple(pdef));
}
}
return new ModelAndView("json", "portlets", rslt);
}
use of org.apereo.portal.portlet.om.IPortletDefinition in project uPortal by Jasig.
the class PortletsSearchStrategy method search.
@Override
public List<?> search(String query, HttpServletRequest request) {
final List<Object> rslt = new ArrayList<>();
final List<IPortletDefinition> portlets = portletDefinitionRegistry.getAllPortletDefinitions();
for (IPortletDefinition portlet : portlets) {
if (portletRegistryUtil.matches(query, portlet)) {
/* requester permissions checked in buildPortletUrl() */
final String url = portletRegistryUtil.buildPortletUrl(request, portlet);
if (url != null) {
rslt.add(getPortletAttrs(portlet, url));
}
}
}
return rslt;
}
use of org.apereo.portal.portlet.om.IPortletDefinition in project uPortal by Jasig.
the class PortletDefinitionSearcher method searchForEntities.
// Internal search, so shouldn't be called as case insensitive.
@Override
public EntityIdentifier[] searchForEntities(String query, SearchMethod method) throws GroupsException {
boolean allowPartial = true;
switch(method) {
case DISCRETE:
allowPartial = false;
break;
case STARTS_WITH:
query = query + "%";
break;
case ENDS_WITH:
query = "%" + query;
break;
case CONTAINS:
query = "%" + query + "%";
break;
default:
throw new GroupsException("Unknown search type");
}
// get the list of matching portlet definitions
final List<IPortletDefinition> definitions = this.portletDefinitionRegistry.searchForPortlets(query, allowPartial);
if (log.isDebugEnabled()) {
log.debug("Found " + definitions.size() + " matching definitions for query " + query);
}
// initialize an appropriately-sized array of EntityIdentifiers
final EntityIdentifier[] identifiers = new EntityIdentifier[definitions.size()];
// add an identifier for each matching portlet
for (final ListIterator<IPortletDefinition> defIter = definitions.listIterator(); defIter.hasNext(); ) {
final IPortletDefinition definition = defIter.next();
identifiers[defIter.previousIndex()] = new EntityIdentifier(definition.getPortletDefinitionId().getStringId(), this.getType());
}
return identifiers;
}
use of org.apereo.portal.portlet.om.IPortletDefinition in project uPortal by Jasig.
the class GetMemberKeyPhrase method getPhrase.
// Internal search, thus case sensitive.
public static String getPhrase(String name, String memberValue) {
String rslt = null;
// We can cut & run now if the element is a <literal>...
if (name.equals("literal")) {
return memberValue;
}
try {
// Next see if it's a <channel> element...
if (name.equals("channel")) {
IPortletDefinition def = PortletDefinitionRegistryLocator.getPortletDefinitionRegistry().getPortletDefinitionByFname(memberValue);
return String.valueOf(def.getPortletDefinitionId().getStringId());
}
// Must be a group...
Class[] leafTypes = new Class[] { IPerson.class, IPortletDefinition.class };
for (int i = 0; i < leafTypes.length && rslt == null; i++) {
EntityIdentifier[] eis = GroupService.searchForGroups(memberValue, IGroupConstants.SearchMethod.DISCRETE, leafTypes[i]);
if (eis.length == 1) {
// Match!
IEntityGroup g = GroupService.findGroup(eis[0].getKey());
rslt = g.getLocalKey();
break;
} else if (eis.length > 1) {
String msg = "Ambiguous member name: " + memberValue;
throw new RuntimeException(msg);
}
}
} catch (Throwable t) {
String msg = "Error looking up the specified member: " + memberValue;
throw new RuntimeException(msg, t);
}
if (rslt == null) {
String msg = "The specified member was not found: " + memberValue;
throw new RuntimeException(msg);
}
return rslt;
}
use of org.apereo.portal.portlet.om.IPortletDefinition in project uPortal by Jasig.
the class PortletDefinitionImporterExporter method importData.
@Transactional
@Override
public void importData(ExternalPortletDefinition portletRep) {
final IPortletDefinition def = portletDefinitionUnmarshaller.unmarshall(portletRep);
final List<PortletCategory> categories = new ArrayList<>();
for (String categoryName : portletRep.getCategories()) {
// Import/Export function, thus the group search is case sensitive.
EntityIdentifier[] cats = GroupService.searchForGroups(categoryName, IGroupConstants.SearchMethod.DISCRETE, IPortletDefinition.class);
PortletCategory category;
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);
}
}
}
savePortletDefinition(def, categories, permissions);
}
Aggregations