// create a JsonEntityBean for each current category and add it
// to our form bean's category list
Set<PortletCategory> categories = portletCategoryRegistry.getParentCategories(def);
for (PortletCategory cat : categories) {
form.addCategory(new JsonEntityBean(cat));
}
try {
IPermissionManager pm = AuthorizationService.instance().newPermissionManager(IPortletPublishingService.FRAMEWORK_OWNER);
IAuthorizationPrincipal[] prins =
pm.getAuthorizedPrincipals(IPortletPublishingService.SUBSCRIBER_ACTIVITY,
PermissionHelper.permissionTargetIdForPortletDefinition(def));
for (int mp = 0; mp < prins.length; mp++) {
JsonEntityBean bean;
// first assume this is a group
IEntityGroup group = GroupService.findGroup(prins[mp].getKey());
if (group != null) {
bean = new JsonEntityBean(group, EntityEnum.GROUP);
}
// if a matching group can't be found, try to find a matching
// non-group entity
else {
IGroupMember member = AuthorizationService.instance().getGroupMember(prins[mp]);
bean = new JsonEntityBean(member, EntityEnum.PERSON);
String name = groupListHelper.lookupEntityName(bean);
bean.setName(name);
}
form.addGroup(bean);
}
} catch (GroupsException e) {
e.printStackTrace();
}
}
// otherwise, if this is a new portlet, pre-populate the categories
// and groups with some reasonable defaults
else {
// pre-populate with top-level category
IEntityGroup portletCategoriesGroup = GroupService.getDistinguishedGroup(GroupService.PORTLET_CATEGORIES);
form.addCategory(new JsonEntityBean(portletCategoriesGroup, groupListHelper.getEntityType(portletCategoriesGroup)));
// pre-populate with top-level group
IEntityGroup everyoneGroup = GroupService.getDistinguishedGroup(GroupService.EVERYONE);
form.addGroup(new JsonEntityBean(everyoneGroup, groupListHelper.getEntityType(everyoneGroup)));
}
/* TODO: Service-Layer Security Reboot (great need of refactoring with a community-approved plan in place) */
// User must have SOME FORM of lifecycle permission over AT LEAST ONE