Search in sources :

Example 81 with IPortletDefinition

use of org.apereo.portal.portlet.om.IPortletDefinition in project uPortal by Jasig.

the class TransientUserLayoutManagerWrapper method getTransientNode.

/**
 * Return an IUserLayoutChannelDescription by way of nodeId
 *
 * @param nodeId the node (subscribe) id to get the channel for.
 * @return a <code>IUserLayoutNodeDescription</code>
 */
private IUserLayoutChannelDescription getTransientNode(String nodeId) throws PortalException {
    // get fname from subscribe id
    final String fname = getFname(nodeId);
    if (null == fname || fname.equals("")) {
        return null;
    }
    try {
        // check cache first
        IPortletDefinition chanDef = mChanMap.get(nodeId);
        if (null == chanDef) {
            chanDef = PortletDefinitionRegistryLocator.getPortletDefinitionRegistry().getPortletDefinitionByFname(fname);
            mChanMap.put(nodeId, chanDef);
        }
        return createUserLayoutChannelDescription(nodeId, chanDef);
    } catch (Exception e) {
        throw new PortalException("Failed to obtain channel definition using fname: " + fname);
    }
}
Also used : PortalException(org.apereo.portal.PortalException) PortalException(org.apereo.portal.PortalException) IPortletDefinition(org.apereo.portal.portlet.om.IPortletDefinition)

Example 82 with IPortletDefinition

use of org.apereo.portal.portlet.om.IPortletDefinition in project uPortal by Jasig.

the class TransientUserLayoutManagerWrapper method getChannelDefinition.

/**
 * Given a subscribe Id, return a ChannelDefinition.
 *
 * @param subId the subscribe id for the ChannelDefinition.
 * @return a <code>ChannelDefinition</code>
 */
protected IPortletDefinition getChannelDefinition(String subId) throws PortalException {
    IPortletDefinition chanDef = mChanMap.get(subId);
    if (null == chanDef) {
        String fname = getFname(subId);
        if (log.isDebugEnabled())
            log.debug("TransientUserLayoutManagerWrapper>>getChannelDefinition, " + "attempting to get a channel definition using functional name: " + fname);
        try {
            chanDef = PortletDefinitionRegistryLocator.getPortletDefinitionRegistry().getPortletDefinitionByFname(fname);
        } catch (Exception e) {
            throw new PortalException("Failed to get channel information " + "for subscribeId: " + subId);
        }
        mChanMap.put(subId, chanDef);
    }
    return chanDef;
}
Also used : PortalException(org.apereo.portal.PortalException) PortalException(org.apereo.portal.PortalException) IPortletDefinition(org.apereo.portal.portlet.om.IPortletDefinition)

Example 83 with IPortletDefinition

use of org.apereo.portal.portlet.om.IPortletDefinition in project uPortal by Jasig.

the class TransientUserLayoutManagerWrapper method getSubscribeId.

/**
 * Given an functional name, return its subscribe id.
 *
 * @param fname the functional name to lookup
 * @return the fname's subscribe id.
 */
public String getSubscribeId(String fname) throws PortalException {
    // see if a given subscribe id is already in the map
    String subId = mFnameMap.get(fname);
    if (subId == null) {
        // see if a given subscribe id is already in the layout
        subId = man.getSubscribeId(fname);
    }
    // assign a new transient channel id
    if (subId == null) {
        try {
            IPortletDefinition chanDef = PortletDefinitionRegistryLocator.getPortletDefinitionRegistry().getPortletDefinitionByFname(fname);
            if (chanDef != null) {
                // assign a new id
                subId = getNextSubscribeId();
                mFnameMap.put(fname, subId);
                mSubIdMap.put(subId, fname);
                mChanMap.put(subId, chanDef);
            }
        } catch (Exception e) {
            log.error("TransientUserLayoutManagerWrapper::getSubscribeId() : " + "an exception encountered while trying to obtain " + "ChannelDefinition for fname \"" + fname + "\" : " + e);
            subId = null;
        }
    }
    return subId;
}
Also used : PortalException(org.apereo.portal.PortalException) IPortletDefinition(org.apereo.portal.portlet.om.IPortletDefinition)

Example 84 with IPortletDefinition

use of org.apereo.portal.portlet.om.IPortletDefinition in project uPortal by Jasig.

the class TransientUserLayoutXMLEventReader method getAdditionalEvents.

/**
 * Examines the current token and when appropriate creates and returns dynamically created
 * content. If dynamic content is not created, return null.
 *
 * @param event The current event
 * @return Dynamic content to inject into document, else null if no additional dynamic content
 *     was created.
 */
@Override
protected Deque<XMLEvent> getAdditionalEvents(XMLEvent event) {
    if (event.isStartElement()) {
        final StartElement startElement = event.asStartElement();
        // All following logic requires an ID attribute, ignore any element without one
        final Attribute idAttribute = startElement.getAttributeByName(IUserLayoutManager.ID_ATTR_NAME);
        if (idAttribute == null) {
            return null;
        }
        // Create and return a transient (dynamically created) folder that includes a transient
        // channel
        // if we are processing the tart element of the root node
        // iff the subscribeId is present and describes a transient channel and not a regular
        // layout channel.
        final String subscribeId = this.userLayoutManager.getFocusedId();
        if (this.rootFolderId.equals(idAttribute.getValue()) && subscribeId != null && !subscribeId.equals("") && this.userLayoutManager.isTransientChannel(subscribeId)) {
            IPortletDefinition chanDef = null;
            try {
                chanDef = this.userLayoutManager.getChannelDefinition(subscribeId);
            } catch (Exception e) {
                logger.error("Could not obtain IChannelDefinition for subscribe id: {}", subscribeId, e);
            }
            if (chanDef != null) {
                final QName name = startElement.getName();
                final String namespaceURI = name.getNamespaceURI();
                final String prefix = name.getPrefix();
                final Deque<XMLEvent> transientEventBuffer = new LinkedList<XMLEvent>();
                final Collection<Attribute> transientFolderAttributes = new LinkedList<Attribute>();
                transientFolderAttributes.add(EVENT_FACTORY.createAttribute("ID", TransientUserLayoutManagerWrapper.TRANSIENT_FOLDER_ID));
                transientFolderAttributes.add(EVENT_FACTORY.createAttribute("name", chanDef != null ? chanDef.getTitle() : "Temporary"));
                transientFolderAttributes.add(EVENT_FACTORY.createAttribute("type", "regular"));
                transientFolderAttributes.add(EVENT_FACTORY.createAttribute("hidden", "false"));
                transientFolderAttributes.add(EVENT_FACTORY.createAttribute("unremovable", "true"));
                transientFolderAttributes.add(EVENT_FACTORY.createAttribute("immutable", "true"));
                transientFolderAttributes.add(EVENT_FACTORY.createAttribute("unremovable", "true"));
                transientFolderAttributes.add(EVENT_FACTORY.createAttribute("dlm:addChildAllowed", "false"));
                transientFolderAttributes.add(EVENT_FACTORY.createAttribute("dlm:deleteAllowed", "false"));
                transientFolderAttributes.add(EVENT_FACTORY.createAttribute("dlm:editAllowed", "false"));
                transientFolderAttributes.add(EVENT_FACTORY.createAttribute("dlm:moveAllowed", "false"));
                transientFolderAttributes.add(EVENT_FACTORY.createAttribute("dlm:precedence", "100.0"));
                transientFolderAttributes.add(EVENT_FACTORY.createAttribute("transient", "true"));
                final StartElement transientFolder = EVENT_FACTORY.createStartElement(prefix, namespaceURI, IUserLayoutManager.FOLDER, transientFolderAttributes.iterator(), null);
                transientEventBuffer.add(transientFolder);
                // TODO Move IChannelDefinition/IPortletDefinition -> StAX events code somewhere
                // reusable
                final Collection<Attribute> channelAttrs = new LinkedList<Attribute>();
                channelAttrs.add(EVENT_FACTORY.createAttribute("ID", subscribeId));
                channelAttrs.add(EVENT_FACTORY.createAttribute("typeID", Integer.toString(chanDef.getType().getId())));
                channelAttrs.add(EVENT_FACTORY.createAttribute("hidden", "false"));
                channelAttrs.add(EVENT_FACTORY.createAttribute("unremovable", "true"));
                channelAttrs.add(EVENT_FACTORY.createAttribute("dlm:deleteAllowed", "false"));
                channelAttrs.add(EVENT_FACTORY.createAttribute("dlm:moveAllowed", "false"));
                channelAttrs.add(EVENT_FACTORY.createAttribute("name", chanDef.getName()));
                channelAttrs.add(EVENT_FACTORY.createAttribute("description", chanDef.getDescription()));
                channelAttrs.add(EVENT_FACTORY.createAttribute("title", chanDef.getTitle()));
                channelAttrs.add(EVENT_FACTORY.createAttribute("chanID", chanDef.getPortletDefinitionId().getStringId()));
                channelAttrs.add(EVENT_FACTORY.createAttribute("fname", chanDef.getFName()));
                channelAttrs.add(EVENT_FACTORY.createAttribute("timeout", Integer.toString(chanDef.getTimeout())));
                channelAttrs.add(EVENT_FACTORY.createAttribute("transient", "true"));
                final StartElement startChannel = EVENT_FACTORY.createStartElement(prefix, namespaceURI, IUserLayoutManager.CHANNEL, channelAttrs.iterator(), null);
                transientEventBuffer.offer(startChannel);
                // add channel parameter elements
                for (final IPortletDefinitionParameter parm : chanDef.getParameters()) {
                    final Collection<Attribute> parameterAttrs = new LinkedList<Attribute>();
                    parameterAttrs.add(EVENT_FACTORY.createAttribute("name", parm.getName()));
                    parameterAttrs.add(EVENT_FACTORY.createAttribute("value", parm.getValue()));
                    final StartElement startParameter = EVENT_FACTORY.createStartElement(prefix, namespaceURI, IUserLayoutManager.PARAMETER, parameterAttrs.iterator(), null);
                    transientEventBuffer.offer(startParameter);
                    final EndElement endParameter = EVENT_FACTORY.createEndElement(prefix, namespaceURI, IUserLayoutManager.PARAMETER, null);
                    transientEventBuffer.offer(endParameter);
                }
                final EndElement endChannel = EVENT_FACTORY.createEndElement(prefix, namespaceURI, IUserLayoutManager.CHANNEL, null);
                transientEventBuffer.offer(endChannel);
                final EndElement endFolder = EVENT_FACTORY.createEndElement(prefix, namespaceURI, IUserLayoutManager.FOLDER, null);
                transientEventBuffer.offer(endFolder);
                return transientEventBuffer;
            } else {
                // I don't think subscribeId could be null, but log warning if so.
                logger.warn("Unable to resolve portlet definition for subscribe ID {}", subscribeId);
            }
        }
    }
    return null;
}
Also used : StartElement(javax.xml.stream.events.StartElement) Attribute(javax.xml.stream.events.Attribute) EndElement(javax.xml.stream.events.EndElement) QName(javax.xml.namespace.QName) IPortletDefinitionParameter(org.apereo.portal.portlet.om.IPortletDefinitionParameter) XMLEvent(javax.xml.stream.events.XMLEvent) LinkedList(java.util.LinkedList) IPortletDefinition(org.apereo.portal.portlet.om.IPortletDefinition)

Example 85 with IPortletDefinition

use of org.apereo.portal.portlet.om.IPortletDefinition in project uPortal by Jasig.

the class PopularPortletsController method buildEventCounts.

private List<PortletUsage> buildEventCounts(Integer days, IPerson user, Locale locale) {
    final DateTime end = new DateTime();
    final DateTime begin = end.minusDays(days);
    final IEntityGroup everyone = GroupService.getRootGroup(IPerson.class);
    final AggregatedGroupMapping group = aggregatedGroupLookupDao.getGroupMapping(everyone.getKey());
    final List<PortletLayoutAggregation> aggregations = portletLayoutDao.getAggregationsForAllPortlets(begin, end, AGGREGATION_INTERVAL, group);
    final EntityIdentifier ei = user.getEntityIdentifier();
    final AuthorizationServiceFacade authService = AuthorizationServiceFacade.instance();
    final IAuthorizationPrincipal ap = authService.newPrincipal(ei.getKey(), ei.getType());
    final Map<String, PortletUsage> resultBuilder = new HashMap<String, PortletUsage>();
    for (final PortletLayoutAggregation aggregation : aggregations) {
        final AggregatedPortletMapping portlet = aggregation.getPortletMapping();
        final String fname = portlet.getFname();
        PortletUsage portletUsage = resultBuilder.get(fname);
        if (portletUsage == null) {
            final IPortletDefinition portletDefinition = this.portletDefinitionDao.getPortletDefinitionByFname(fname);
            if (portletDefinition == null || !ap.canSubscribe(portletDefinition.getPortletDefinitionId().getStringId())) {
                // Skip portlets that no longer exist or cannot be subscribed to
                continue;
            }
            portletUsage = new PortletUsage(portletDefinition.getPortletDefinitionId().getLongId(), fname, portletDefinition.getTitle(locale.toString()), portletDefinition.getDescription(locale.toString()));
            resultBuilder.put(fname, portletUsage);
        }
        portletUsage.incrementCount(aggregation.getAddCount());
    }
    final ArrayList<PortletUsage> results = new ArrayList<PortletUsage>(resultBuilder.values());
    Collections.sort(results);
    return results;
}
Also used : HashMap(java.util.HashMap) PortletLayoutAggregation(org.apereo.portal.events.aggr.portletlayout.PortletLayoutAggregation) AggregatedPortletMapping(org.apereo.portal.events.aggr.portlets.AggregatedPortletMapping) ArrayList(java.util.ArrayList) EntityIdentifier(org.apereo.portal.EntityIdentifier) DateTime(org.joda.time.DateTime) IEntityGroup(org.apereo.portal.groups.IEntityGroup) AggregatedGroupMapping(org.apereo.portal.events.aggr.groups.AggregatedGroupMapping) AuthorizationServiceFacade(org.apereo.portal.services.AuthorizationServiceFacade) IAuthorizationPrincipal(org.apereo.portal.security.IAuthorizationPrincipal) IPortletDefinition(org.apereo.portal.portlet.om.IPortletDefinition)

Aggregations

IPortletDefinition (org.apereo.portal.portlet.om.IPortletDefinition)109 IPortletEntity (org.apereo.portal.portlet.om.IPortletEntity)24 IPortletWindow (org.apereo.portal.portlet.om.IPortletWindow)22 IAuthorizationPrincipal (org.apereo.portal.security.IAuthorizationPrincipal)17 ArrayList (java.util.ArrayList)16 IPortletDefinitionId (org.apereo.portal.portlet.om.IPortletDefinitionId)14 HashSet (java.util.HashSet)13 IPerson (org.apereo.portal.security.IPerson)13 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)13 PortletCategory (org.apereo.portal.portlet.om.PortletCategory)12 EntityIdentifier (org.apereo.portal.EntityIdentifier)11 IUserLayoutManager (org.apereo.portal.layout.IUserLayoutManager)9 HashMap (java.util.HashMap)8 IPortletWindowId (org.apereo.portal.portlet.om.IPortletWindowId)8 IPortletDefinitionParameter (org.apereo.portal.portlet.om.IPortletDefinitionParameter)7 IPortletPreference (org.apereo.portal.portlet.om.IPortletPreference)7 IUserInstance (org.apereo.portal.user.IUserInstance)7 Locale (java.util.Locale)6 HttpServletRequest (javax.servlet.http.HttpServletRequest)6 PortletDefinition (org.apache.pluto.container.om.portlet.PortletDefinition)6