Search in sources :

Example 6 with FragmentDefinition

use of org.apereo.portal.layout.dlm.FragmentDefinition in project uPortal by Jasig.

the class FragmentDefinitionExporter method exportDataElement.

/* (non-Javadoc)
     * @see org.apereo.portal.io.xml.crn.AbstractDom4jExporter#exportDataElement(java.lang.String)
     */
@Override
protected Element exportDataElement(String id) {
    final FragmentDefinition fragmentDefinition = fragmentDefinitionDao.getFragmentDefinition(id);
    if (fragmentDefinition == null) {
        return null;
    }
    final org.dom4j.Document fragmentDefDoc = new org.dom4j.DocumentFactory().createDocument();
    final Element fragmentDefElement = fragmentDefDoc.addElement("fragment-definition");
    fragmentDefElement.addNamespace("dlm", Constants.NS_URI);
    fragmentDefElement.addAttribute("script", "classpath://org/jasig/portal/io/import-fragment-definition_v3-1.crn");
    fragmentDefinition.toElement(fragmentDefElement);
    return fragmentDefElement;
}
Also used : FragmentDefinition(org.apereo.portal.layout.dlm.FragmentDefinition) Element(org.dom4j.Element)

Example 7 with FragmentDefinition

use of org.apereo.portal.layout.dlm.FragmentDefinition in project uPortal by Jasig.

the class LayoutsDataFunction method apply.

@Override
public Iterable<? extends IPortalData> apply(IPortalDataType input) {
    final List<FragmentDefinition> fragments = this.configurationLoader.getFragments();
    final Set<String> fragmentOwners = new LinkedHashSet<String>();
    for (final FragmentDefinition fragmentDefinition : fragments) {
        fragmentOwners.add(fragmentDefinition.getOwnerId());
    }
    final List<String> userList = this.jdbcOperations.queryForList("SELECT USER_NAME FROM UP_USER WHERE USER_NAME NOT IN (:userNames)", Collections.singletonMap("userNames", fragmentOwners), String.class);
    return Lists.transform(userList, new Function<String, IPortalData>() {

        @Override
        public IPortalData apply(final String userName) {
            return new SimpleStringPortalData(userName, null, null);
        }
    });
}
Also used : LinkedHashSet(java.util.LinkedHashSet) FragmentDefinition(org.apereo.portal.layout.dlm.FragmentDefinition) SimpleStringPortalData(org.apereo.portal.io.xml.SimpleStringPortalData) IPortalData(org.apereo.portal.io.xml.IPortalData)

Example 8 with FragmentDefinition

use of org.apereo.portal.layout.dlm.FragmentDefinition in project uPortal by Jasig.

the class FragmentListController method listFragments.

/**
     * Returns a model of fragments --> List<FragmentBean> , sorted by precedence (default) or by
     * fragment name depending on sort parameter, to be rendered by the jsonView.
     *
     * @param req the servlet request, bound via SpringWebMVC to GET method invocations of this
     *     controller.
     * @param sortParam PRECEDENCE, NAME, or null.
     * @return ModelAndView with a List of FragmentBeans to be rendered by the jsonView.
     * @throws ServletException on Exception in underlying attempt to get at the fragments
     * @throws AuthorizationException if request is for any user other than a Portal Administrator.
     * @throws IllegalArgumentException if sort parameter has an unrecognized value
     */
@RequestMapping(method = RequestMethod.GET)
public ModelAndView listFragments(HttpServletRequest req, @RequestParam(value = "sort", required = false) String sortParam) throws ServletException {
    // Verify that the user is allowed to use this service
    IPerson user = personManager.getPerson(req);
    if (!AdminEvaluator.isAdmin(user)) {
        throw new AuthorizationException("User " + user.getUserName() + " not an administrator.");
    }
    Map<String, Document> fragmentLayoutMap = null;
    if (userLayoutStore != null) {
        try {
            fragmentLayoutMap = userLayoutStore.getFragmentLayoutCopies();
        } catch (Exception e) {
            String msg = "Failed to access fragment layouts";
            log.error(msg, e);
            throw new ServletException(msg, e);
        }
    }
    List<FragmentBean> fragments = new ArrayList<FragmentBean>();
    for (FragmentDefinition frag : dlmConfig.getFragments()) {
        Document layout = fragmentLayoutMap != null ? fragmentLayoutMap.get(frag.getOwnerId()) : null;
        List<String> portlets = null;
        if (layout != null) {
            portlets = new ArrayList<String>();
            NodeList channelFNames = this.xpathOperations.evaluate(CHANNEL_FNAME_XPATH, layout, XPathConstants.NODESET);
            for (int i = 0; i < channelFNames.getLength(); i++) {
                String fname = channelFNames.item(i).getTextContent();
                IPortletDefinition pDef = portletRegistry.getPortletDefinitionByFname(fname);
                if (null != pDef) {
                    portlets.add(pDef.getTitle());
                }
            }
        }
        fragments.add(FragmentBean.create(frag, portlets));
    }
    // Determine & follow sorting preference...
    Sort sort = DEFAULT_SORT;
    if (sortParam != null) {
        sort = Sort.valueOf(sortParam);
    }
    Collections.sort(fragments, sort.getComparator());
    return new ModelAndView("jsonView", "fragments", fragments);
}
Also used : FragmentDefinition(org.apereo.portal.layout.dlm.FragmentDefinition) AuthorizationException(org.apereo.portal.AuthorizationException) NodeList(org.w3c.dom.NodeList) ArrayList(java.util.ArrayList) ModelAndView(org.springframework.web.servlet.ModelAndView) Document(org.w3c.dom.Document) ServletException(javax.servlet.ServletException) AuthorizationException(org.apereo.portal.AuthorizationException) ServletException(javax.servlet.ServletException) IPerson(org.apereo.portal.security.IPerson) IPortletDefinition(org.apereo.portal.portlet.om.IPortletDefinition) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 9 with FragmentDefinition

use of org.apereo.portal.layout.dlm.FragmentDefinition in project uPortal by Jasig.

the class FragmentDefinitionUtils method getFragmentDefinitionsApplicableToPerson.

@Override
public List<FragmentDefinition> getFragmentDefinitionsApplicableToPerson(final IPerson person) {
    final List<FragmentDefinition> result = new ArrayList<FragmentDefinition>();
    final List<FragmentDefinition> definitions = this.configurationLoader.getFragments();
    logger.debug("About to check applicability of {} fragments", definitions.size());
    if (definitions != null) {
        for (final FragmentDefinition fragmentDefinition : definitions) {
            logger.debug("Checking applicability of the following fragment: {}", fragmentDefinition.getName());
            if (fragmentDefinition.isApplicable(person)) {
                result.add(fragmentDefinition);
            }
        }
    }
    return result;
}
Also used : FragmentDefinition(org.apereo.portal.layout.dlm.FragmentDefinition) ArrayList(java.util.ArrayList)

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