use of org.apereo.portal.EntityIdentifier in project uPortal by Jasig.
the class GetMemberServicePhrase method getPhrase.
// Internal search, thus case sensitive.
public static String getPhrase(String name, String memberValue) {
String rslt = null;
// We can (and must) cut & run if the element is a <literal> or a <channel>...
if (name.equals("literal") || name.equals("channel")) {
return "local";
}
try {
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!
if (eis[0].getType() == IEntityGroup.class) {
IEntityGroup g = GroupService.findGroup(eis[0].getKey());
rslt = g.getServiceName().toString();
} else {
String msg = "The specified entity is not a group: " + memberValue;
throw new RuntimeException(msg);
}
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.EntityIdentifier in project uPortal by Jasig.
the class GroupKeyOrLiteralPhrase method evaluate.
// Internal search, thus case sensitive.
@Override
public Object evaluate(TaskRequest req, TaskResponse res) {
String rslt = null;
Element e = (Element) element.evaluate(req, res);
if (e.getName().equals("group")) {
// This is a group name, we need to look up the key...
try {
Class[] types = new Class[] { IPerson.class, IPortletDefinition.class };
for (Class c : types) {
EntityIdentifier[] eis = GroupService.searchForGroups(e.getText(), IGroupConstants.SearchMethod.DISCRETE, c);
switch(eis.length) {
case 1:
// This is good -- what we hope for...
rslt = GroupService.findGroup(eis[0].getKey()).getKey();
break;
case 0:
// This is ok -- try the next type...
continue;
default:
String msg2 = "Ambiguous group name: " + e.getText();
throw new RuntimeException(msg2);
}
}
// We better have a match by now...
if (rslt == null) {
String msg = "No group with the specified name was found: " + e.getText();
throw new RuntimeException(msg);
}
} catch (Throwable t) {
String msg = "Error looking up the specified group: " + e.getText();
throw new RuntimeException(msg, t);
}
} else if (e.getName().equals("literal")) {
rslt = e.getText();
} else {
String msg = "Unsupported element type: " + e.getName();
throw new RuntimeException(msg);
}
return rslt;
}
use of org.apereo.portal.EntityIdentifier 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);
}
use of org.apereo.portal.EntityIdentifier in project uPortal by Jasig.
the class GoogleAnalyticsController method isMember.
/**
* Check if the user is a member of the specified group name
*
* <p>Internal search, thus case sensitive.
*/
private boolean isMember(IGroupMember groupMember, String groupName) {
try {
IEntityGroup group = GroupService.findGroup(groupName);
if (group != null) {
return groupMember.isDeepMemberOf(group);
}
final EntityIdentifier[] results = GroupService.searchForGroups(groupName, GroupService.SearchMethod.DISCRETE, IPerson.class);
if (results == null || results.length == 0) {
this.logger.warn("No portal group found for '{}' no users will be placed in that group for analytics", groupName);
return false;
}
if (results.length > 1) {
this.logger.warn("{} groups were found for groupName '{}'. The first result will be used.", results.length, groupName);
}
group = (IEntityGroup) GroupService.getGroupMember(results[0]);
return groupMember.isDeepMemberOf(group);
} catch (Exception e) {
this.logger.warn("Failed to determine if {} is a member of {}, returning false", groupMember, groupName, e);
return false;
}
}
use of org.apereo.portal.EntityIdentifier in project uPortal by Jasig.
the class PopularPortletsController method buildEventCounts.
private List<PortletUsage> buildEventCounts(Integer days, IPerson user, Locale locale) {
final DateTime end = new DateTime();
final DateTime begin = end.minusDays(days);
final IEntityGroup everyone = GroupService.getRootGroup(IPerson.class);
final AggregatedGroupMapping group = aggregatedGroupLookupDao.getGroupMapping(everyone.getKey());
final List<PortletLayoutAggregation> aggregations = portletLayoutDao.getAggregationsForAllPortlets(begin, end, AGGREGATION_INTERVAL, group);
final EntityIdentifier ei = user.getEntityIdentifier();
final AuthorizationServiceFacade authService = AuthorizationServiceFacade.instance();
final IAuthorizationPrincipal ap = authService.newPrincipal(ei.getKey(), ei.getType());
final Map<String, PortletUsage> resultBuilder = new HashMap<String, PortletUsage>();
for (final PortletLayoutAggregation aggregation : aggregations) {
final AggregatedPortletMapping portlet = aggregation.getPortletMapping();
final String fname = portlet.getFname();
PortletUsage portletUsage = resultBuilder.get(fname);
if (portletUsage == null) {
final IPortletDefinition portletDefinition = this.portletDefinitionDao.getPortletDefinitionByFname(fname);
if (portletDefinition == null || !ap.canSubscribe(portletDefinition.getPortletDefinitionId().getStringId())) {
// Skip portlets that no longer exist or cannot be subscribed to
continue;
}
portletUsage = new PortletUsage(portletDefinition.getPortletDefinitionId().getLongId(), fname, portletDefinition.getTitle(locale.toString()), portletDefinition.getDescription(locale.toString()));
resultBuilder.put(fname, portletUsage);
}
portletUsage.incrementCount(aggregation.getAddCount());
}
final ArrayList<PortletUsage> results = new ArrayList<PortletUsage>(resultBuilder.values());
Collections.sort(results);
return results;
}
Aggregations