Search in sources :

Example 1 with FragmentDefinition

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;
}
Also used : FragmentDefinition(org.apereo.portal.layout.dlm.FragmentDefinition) TreeMap(java.util.TreeMap)

Example 2 with FragmentDefinition

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);
}
Also used : Locale(java.util.Locale) FragmentDefinition(org.apereo.portal.layout.dlm.FragmentDefinition) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ModelAndView(org.springframework.web.servlet.ModelAndView) IUserFragmentSubscription(org.apereo.portal.fragment.subscribe.IUserFragmentSubscription) IUserInstance(org.apereo.portal.user.IUserInstance) IPerson(org.apereo.portal.security.IPerson) AuthorizationService(org.apereo.portal.services.AuthorizationService) IAuthorizationPrincipal(org.apereo.portal.security.IAuthorizationPrincipal) HashSet(java.util.HashSet) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 3 with FragmentDefinition

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);
}
Also used : FragmentDefinition(org.apereo.portal.layout.dlm.FragmentDefinition) Element(org.w3c.dom.Element) Document(org.w3c.dom.Document) Transactional(org.springframework.transaction.annotation.Transactional)

Example 4 with 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;
}
Also used : FragmentDefinition(org.apereo.portal.layout.dlm.FragmentDefinition) SimpleStringPortalData(org.apereo.portal.io.xml.SimpleStringPortalData) IPortalData(org.apereo.portal.io.xml.IPortalData)

Example 5 with FragmentDefinition

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;
}
Also used : FragmentDefinition(org.apereo.portal.layout.dlm.FragmentDefinition) SimpleStringPortalData(org.apereo.portal.io.xml.SimpleStringPortalData) IPortalData(org.apereo.portal.io.xml.IPortalData)

Aggregations

FragmentDefinition (org.apereo.portal.layout.dlm.FragmentDefinition)9 ArrayList (java.util.ArrayList)3 IPortalData (org.apereo.portal.io.xml.IPortalData)3 SimpleStringPortalData (org.apereo.portal.io.xml.SimpleStringPortalData)3 IPerson (org.apereo.portal.security.IPerson)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 ModelAndView (org.springframework.web.servlet.ModelAndView)2 Document (org.w3c.dom.Document)2 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 LinkedHashSet (java.util.LinkedHashSet)1 Locale (java.util.Locale)1 TreeMap (java.util.TreeMap)1 ServletException (javax.servlet.ServletException)1 AuthorizationException (org.apereo.portal.AuthorizationException)1 IUserFragmentSubscription (org.apereo.portal.fragment.subscribe.IUserFragmentSubscription)1 IPortletDefinition (org.apereo.portal.portlet.om.IPortletDefinition)1 IAuthorizationPrincipal (org.apereo.portal.security.IAuthorizationPrincipal)1 AuthorizationService (org.apereo.portal.services.AuthorizationService)1 IUserInstance (org.apereo.portal.user.IUserInstance)1