*/
IUserInstance userInstance = userInstanceManager.getUserInstance(request);
IPerson person = userInstance.getPerson();
AuthorizationService authService = AuthorizationService.instance();
IAuthorizationPrincipal principal = authService.newPrincipal(person.getUserName(), IPerson.class);
/**
* Build a collection of owner IDs for the fragments to which the
* authenticated user is subscribed
*/
// get the list of current subscriptions for this user
List<IUserFragmentSubscription> subscriptions = userFragmentSubscriptionDao
.getUserFragmentInfo(person);
// transform it into the set of owners
Set<String> subscribedOwners = new HashSet<String>();
for (IUserFragmentSubscription subscription : subscriptions){
if (subscription.isActive()) {
subscribedOwners.add(subscription.getFragmentOwner());
}
}
/**
* Iterate through the list of all currently defined DLM fragments and
* determine if the current user has permissions to subscribe to each.
* Any subscribable fragments will be transformed into a JSON-friendly
* bean and added to the model.
*/
final List<SubscribableFragment> jsonFragments = new ArrayList<SubscribableFragment>();
// get the list of fragment definitions from DLM
final List<FragmentDefinition> fragmentDefinitions = configurationLoader.getFragments();
final Locale locale = RequestContextUtils.getLocale(request);
// iterate through the list
for (FragmentDefinition fragmentDefinition : fragmentDefinitions) {
if (isSubscribable(fragmentDefinition, principal)) {
String owner = fragmentDefinition.getOwnerId();
// check to see if the current user has permission to subscribe to
// this fragment
if (principal.hasPermission("UP_FRAGMENT", "FRAGMENT_SUBSCRIBE", owner)) {
// create a JSON fragment bean and add it to our list
boolean subscribed = subscribedOwners.contains(owner);
final String name = getMessage("fragment." + owner + ".name", fragmentDefinition.getName(), locale);
final String description = getMessage("fragment." + owner + ".description", fragmentDefinition.getDescription(), locale);