use of org.apereo.portal.layout.dlm.FragmentDefinition in project uPortal by Jasig.
the class FragmentAdministrationHelper method getAuthorizedDlmFragments.
/**
* @param remoteUser
* @return
*/
public Map<String, String> getAuthorizedDlmFragments(String remoteUser) {
List<FragmentDefinition> fragments = this.configurationLoader.getFragments();
Map<String, String> results = new TreeMap<String, String>();
for (FragmentDefinition frag : fragments) {
if (this.identitySwapperManager.canImpersonateUser(remoteUser, frag.getOwnerId())) {
results.put(frag.getOwnerId(), frag.getName());
}
}
return results;
}
use of org.apereo.portal.layout.dlm.FragmentDefinition in project uPortal by Jasig.
the class SubscribableTabsRESTController method getSubscriptionList.
@RequestMapping(value = "/subscribableTabs.json", method = RequestMethod.GET)
public ModelAndView getSubscriptionList(HttpServletRequest request) {
Map<String, Object> model = new HashMap<String, Object>();
/** Retrieve the IPerson and IAuthorizationPrincipal for the currently authenticated user */
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();
// 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);
SubscribableFragment jsonFragment = new SubscribableFragment(name, description, owner, subscribed);
jsonFragments.add(jsonFragment);
}
}
}
model.put("fragments", jsonFragments);
return new ModelAndView("json", model);
}
use of org.apereo.portal.layout.dlm.FragmentDefinition in project uPortal by Jasig.
the class FragmentDefinitionImporter method importData.
/* (non-Javadoc)
* @see org.apereo.portal.io.xml.IDataImporter#importData(java.lang.Object)
*/
@Override
@Transactional
public void importData(Tuple<String, Document> data) {
final Document resultDoc = data.second;
final Element fragmentDefElement = this.xPathOperations.evaluate("//*[local-name() = 'fragment']", resultDoc, XPathConstants.NODE);
if (fragmentDefElement == null) {
throw new IllegalArgumentException("Could not find required dlm:fragment element in fragment-definition file");
}
final String fragmentName = fragmentDefElement.getAttribute("name");
FragmentDefinition fragmentDefinition = this.fragmentDefinitionDao.getFragmentDefinition(fragmentName);
if (fragmentDefinition == null) {
fragmentDefinition = new FragmentDefinition(fragmentDefElement);
}
fragmentDefinition.loadFromEelement(fragmentDefElement);
this.fragmentDefinitionDao.updateFragmentDefinition(fragmentDefinition);
}
use of org.apereo.portal.layout.dlm.FragmentDefinition in project uPortal by Jasig.
the class FragmentLayoutsDataFunction method apply.
@Override
public Iterable<? extends IPortalData> apply(IPortalDataType input) {
final List<FragmentDefinition> fragments = this.configurationLoader.getFragments();
final List<IPortalData> portalData = Lists.transform(fragments, new Function<FragmentDefinition, IPortalData>() {
@Override
public IPortalData apply(FragmentDefinition fragmentDefinition) {
return new SimpleStringPortalData(fragmentDefinition.getOwnerId(), fragmentDefinition.getName(), fragmentDefinition.getDescription());
}
});
return portalData;
}
use of org.apereo.portal.layout.dlm.FragmentDefinition in project uPortal by Jasig.
the class FragmentDefinitionDataFunction method apply.
@Override
public Iterable<? extends IPortalData> apply(IPortalDataType input) {
final List<FragmentDefinition> fragmentDefinitions = this.fragmentDefinitionDao.getAllFragments();
final List<IPortalData> portalData = Lists.transform(fragmentDefinitions, new Function<FragmentDefinition, IPortalData>() {
@Override
public IPortalData apply(FragmentDefinition fragmentDefinition) {
return new SimpleStringPortalData(fragmentDefinition.getName(), null, fragmentDefinition.getDescription());
}
});
return portalData;
}
Aggregations