Search in sources :

Example 16 with PortletDefinition

use of org.apache.pluto.container.om.portlet.PortletDefinition in project uPortal by Jasig.

the class EventProviderImpl method isValueInstanceOfDefinedClass.

private boolean isValueInstanceOfDefinedClass(QName qname, Serializable value) {
    final PortletDefinition portletDefinition = this.portletWindow.getPlutoPortletWindow().getPortletDefinition();
    final PortletApplicationDefinition app = portletDefinition.getApplication();
    final List<? extends EventDefinition> events = app.getEventDefinitions();
    if (events == null) {
        return true;
    }
    final String defaultNamespace = app.getDefaultNamespace();
    for (final EventDefinition eventDefinition : events) {
        if (eventDefinition.getQName() != null) {
            if (eventDefinition.getQName().equals(qname)) {
                final Class<? extends Serializable> valueClass = value.getClass();
                return valueClass.getName().equals(eventDefinition.getValueType());
            }
        } else {
            final QName tmp = new QName(defaultNamespace, eventDefinition.getName());
            if (tmp.equals(qname)) {
                final Class<? extends Serializable> valueClass = value.getClass();
                return valueClass.getName().equals(eventDefinition.getValueType());
            }
        }
    }
    // event not declared
    return true;
}
Also used : PortletApplicationDefinition(org.apache.pluto.container.om.portlet.PortletApplicationDefinition) QName(javax.xml.namespace.QName) EventDefinition(org.apache.pluto.container.om.portlet.EventDefinition) PortletDefinition(org.apache.pluto.container.om.portlet.PortletDefinition)

Example 17 with PortletDefinition

use of org.apache.pluto.container.om.portlet.PortletDefinition in project uPortal by Jasig.

the class PortletAdministrationHelper method loadDefaultsFromPortletDefinitionIfNew.

/**
     * Pre-populate a new {@link PortletDefinitionForm} with information from the {@link
     * PortletDefinition}.
     *
     * @param form
     */
public void loadDefaultsFromPortletDefinitionIfNew(PortletDefinitionForm form) {
    if (!form.isNew()) {
        // Get out;  we only prepopulate new portlets
        return;
    }
    // appName/portletName must be set at this point
    Validate.notBlank(form.getApplicationId(), "ApplicationId not set");
    Validate.notBlank(form.getPortletName(), "PortletName not set");
    final PortletRegistryService portletRegistryService = portalDriverContainerServices.getPortletRegistryService();
    final PortletDefinition portletDef;
    try {
        portletDef = portletRegistryService.getPortlet(form.getApplicationId(), form.getPortletName());
    } catch (PortletContainerException e) {
        this.logger.warn("Failed to load portlet descriptor for appId='" + form.getApplicationId() + "', portletName='" + form.getPortletName() + "'", e);
        return;
    }
    form.setTitle(portletDef.getPortletName());
    form.setName(portletDef.getPortletName());
    for (Supports supports : portletDef.getSupports()) {
        for (String mode : supports.getPortletModes()) {
            if ("edit".equalsIgnoreCase(mode)) {
                form.setEditable(true);
            } else if ("help".equalsIgnoreCase(mode)) {
                form.setHasHelp(true);
            } else if ("config".equalsIgnoreCase(mode)) {
                form.setConfigurable(true);
            }
        }
    }
}
Also used : PortletRegistryService(org.apache.pluto.container.driver.PortletRegistryService) Supports(org.apache.pluto.container.om.portlet.Supports) PortletContainerException(org.apache.pluto.container.PortletContainerException) IPortletDefinition(org.apereo.portal.portlet.om.IPortletDefinition) PortletDefinition(org.apache.pluto.container.om.portlet.PortletDefinition)

Example 18 with PortletDefinition

use of org.apache.pluto.container.om.portlet.PortletDefinition in project uPortal by Jasig.

the class PortletEventCoordinatationService method unmarshall.

protected Event unmarshall(IPortletWindow portletWindow, Event event) {
    //TODO make two types of Event impls, one for marshalled data and one for unmarshalled data
    String value = (String) event.getValue();
    final XMLInputFactory xmlInputFactory = this.xmlUtilities.getXmlInputFactory();
    final XMLStreamReader xml;
    try {
        xml = xmlInputFactory.createXMLStreamReader(new StringReader(value));
    } catch (XMLStreamException e) {
        throw new IllegalStateException("Failed to create XMLStreamReader for portlet event: " + event, e);
    }
    // now test if object is jaxb
    final EventDefinition eventDefinitionDD = getEventDefintion(portletWindow, event.getQName());
    final PortletDefinition portletDefinition = portletWindow.getPlutoPortletWindow().getPortletDefinition();
    final PortletApplicationDefinition application = portletDefinition.getApplication();
    final String portletApplicationName = application.getName();
    final ClassLoader loader;
    try {
        loader = portletContextService.getClassLoader(portletApplicationName);
    } catch (PortletContainerException e) {
        throw new IllegalStateException("Failed to get ClassLoader for portlet application: " + portletApplicationName, e);
    }
    final String eventType = eventDefinitionDD.getValueType();
    final Class<? extends Serializable> clazz;
    try {
        clazz = loader.loadClass(eventType).asSubclass(Serializable.class);
    } catch (ClassNotFoundException e) {
        throw new IllegalArgumentException("Declared event type '" + eventType + "' cannot be found in portlet application: " + portletApplicationName, e);
    }
    //TODO cache JAXBContext in registered portlet application
    final JAXBElement<? extends Serializable> result;
    try {
        final JAXBContext jc = JAXBContext.newInstance(clazz);
        final Unmarshaller unmarshaller = jc.createUnmarshaller();
        result = unmarshaller.unmarshal(xml, clazz);
    } catch (JAXBException e) {
        throw new IllegalArgumentException("Cannot create JAXBContext for event type '" + eventType + "' from portlet application: " + portletApplicationName, e);
    }
    return new EventImpl(event.getQName(), result.getValue());
}
Also used : Serializable(java.io.Serializable) XMLStreamReader(javax.xml.stream.XMLStreamReader) PortletApplicationDefinition(org.apache.pluto.container.om.portlet.PortletApplicationDefinition) JAXBException(javax.xml.bind.JAXBException) JAXBContext(javax.xml.bind.JAXBContext) EventDefinition(org.apache.pluto.container.om.portlet.EventDefinition) PortletContainerException(org.apache.pluto.container.PortletContainerException) IPortletDefinition(org.apereo.portal.portlet.om.IPortletDefinition) PortletDefinition(org.apache.pluto.container.om.portlet.PortletDefinition) XMLStreamException(javax.xml.stream.XMLStreamException) EventImpl(org.apereo.portal.portlet.container.EventImpl) StringReader(java.io.StringReader) Unmarshaller(javax.xml.bind.Unmarshaller) XMLInputFactory(javax.xml.stream.XMLInputFactory)

Example 19 with PortletDefinition

use of org.apache.pluto.container.om.portlet.PortletDefinition in project uPortal by Jasig.

the class PortletEventCoordinatationService method resolvePortletEvents.

@Override
public void resolvePortletEvents(HttpServletRequest request, PortletEventQueue portletEventQueue) {
    final Queue<QueuedEvent> events = portletEventQueue.getUnresolvedEvents();
    //Skip all processing if there are no new events.
    if (events.isEmpty()) {
        return;
    }
    //Get all the portlets the user is subscribed to
    final IUserInstance userInstance = this.userInstanceManager.getUserInstance(request);
    final IUserPreferencesManager preferencesManager = userInstance.getPreferencesManager();
    final IUserLayoutManager userLayoutManager = preferencesManager.getUserLayoutManager();
    //Make a local copy so we can remove data from it
    final Set<String> allLayoutNodeIds = new LinkedHashSet<String>(userLayoutManager.getAllSubscribedChannels());
    final Map<String, IPortletEntity> portletEntityCache = new LinkedHashMap<String, IPortletEntity>();
    while (!events.isEmpty()) {
        final QueuedEvent queuedEvent = events.poll();
        if (queuedEvent == null) {
            //no more queued events, done resolving
            return;
        }
        final IPortletWindowId sourceWindowId = queuedEvent.getPortletWindowId();
        final Event event = queuedEvent.getEvent();
        final boolean globalEvent = isGlobalEvent(request, sourceWindowId, event);
        final Set<IPortletDefinition> portletDefinitions = new LinkedHashSet<IPortletDefinition>();
        if (globalEvent) {
            portletDefinitions.addAll(this.portletDefinitionRegistry.getAllPortletDefinitions());
        }
        //Check each subscription to see what events it is registered to see
        for (final Iterator<String> layoutNodeIdItr = allLayoutNodeIds.iterator(); layoutNodeIdItr.hasNext(); ) {
            final String layoutNodeId = layoutNodeIdItr.next();
            IPortletEntity portletEntity = portletEntityCache.get(layoutNodeId);
            if (portletEntity == null) {
                portletEntity = this.portletEntityRegistry.getOrCreatePortletEntity(request, userInstance, layoutNodeId);
                // if portlet entity registry returned null, then portlet has been deleted - remove it (see UP-3378)
                if (portletEntity == null) {
                    layoutNodeIdItr.remove();
                    continue;
                }
                final IPortletDefinitionId portletDefinitionId = portletEntity.getPortletDefinitionId();
                final PortletDefinition portletDescriptor = this.portletDefinitionRegistry.getParentPortletDescriptor(portletDefinitionId);
                if (portletDescriptor == null) {
                    //Missconfigured portlet, remove it from the list so we don't check again and ignore it
                    layoutNodeIdItr.remove();
                    continue;
                }
                final List<? extends EventDefinitionReference> supportedProcessingEvents = portletDescriptor.getSupportedProcessingEvents();
                //Skip portlets that don't handle any events and remove them from the set so they are not checked again
                if (supportedProcessingEvents == null || supportedProcessingEvents.size() == 0) {
                    layoutNodeIdItr.remove();
                    continue;
                }
                portletEntityCache.put(layoutNodeId, portletEntity);
            }
            final IPortletDefinition portletDefinition = portletEntity.getPortletDefinition();
            final IPortletDefinitionId portletDefinitionId = portletDefinition.getPortletDefinitionId();
            if (this.supportsEvent(event, portletDefinitionId)) {
                this.logger.debug("{} supports event {}", portletDefinition, event);
                //If this is the default portlet entity remove the definition from the all defs set to avoid duplicate processing
                final IPortletEntity defaultPortletEntity = this.portletEntityRegistry.getOrCreateDefaultPortletEntity(request, portletDefinitionId);
                if (defaultPortletEntity.equals(portletEntity)) {
                    portletDefinitions.remove(portletDefinition);
                }
                // Is this portlet permitted to receive events?  (Or is it disablePortletEvents=true?)
                IPortletDefinitionParameter disablePortletEvents = portletDefinition.getParameter(PortletExecutionManager.DISABLE_PORTLET_EVENTS_PARAMETER);
                if (disablePortletEvents != null && Boolean.parseBoolean(disablePortletEvents.getValue())) {
                    logger.info("Ignoring portlet events for portlet '{}' because they have been disabled.", portletDefinition.getFName());
                    continue;
                }
                final IPortletEntityId portletEntityId = portletEntity.getPortletEntityId();
                final Set<IPortletWindow> portletWindows = this.portletWindowRegistry.getAllPortletWindowsForEntity(request, portletEntityId);
                for (final IPortletWindow portletWindow : portletWindows) {
                    this.logger.debug("{} resolved target {}", event, portletWindow);
                    final IPortletWindowId portletWindowId = portletWindow.getPortletWindowId();
                    final Event unmarshalledEvent = this.unmarshall(portletWindow, event);
                    portletEventQueue.offerEvent(portletWindowId, new QueuedEvent(sourceWindowId, unmarshalledEvent));
                }
            } else {
                portletDefinitions.remove(portletDefinition);
            }
        }
        if (!portletDefinitions.isEmpty()) {
            final IPerson user = userInstance.getPerson();
            final EntityIdentifier ei = user.getEntityIdentifier();
            final IAuthorizationPrincipal ap = AuthorizationService.instance().newPrincipal(ei.getKey(), ei.getType());
            //If the event is global there might still be portlet definitions that need targeting
            for (final IPortletDefinition portletDefinition : portletDefinitions) {
                // Is this portlet permitted to receive events?  (Or is it disablePortletEvents=true?)
                IPortletDefinitionParameter disablePortletEvents = portletDefinition.getParameter(PortletExecutionManager.DISABLE_PORTLET_EVENTS_PARAMETER);
                if (disablePortletEvents != null && Boolean.parseBoolean(disablePortletEvents.getValue())) {
                    logger.info("Ignoring portlet events for portlet '{}' because they have been disabled.", portletDefinition.getFName());
                    continue;
                }
                final IPortletDefinitionId portletDefinitionId = portletDefinition.getPortletDefinitionId();
                //Check if the user can render the portlet definition before doing event tests
                if (ap.canRender(portletDefinitionId.getStringId())) {
                    if (this.supportsEvent(event, portletDefinitionId)) {
                        this.logger.debug("{} supports event {}", portletDefinition, event);
                        final IPortletEntity portletEntity = this.portletEntityRegistry.getOrCreateDefaultPortletEntity(request, portletDefinitionId);
                        final IPortletEntityId portletEntityId = portletEntity.getPortletEntityId();
                        final Set<IPortletWindow> portletWindows = this.portletWindowRegistry.getAllPortletWindowsForEntity(request, portletEntityId);
                        for (final IPortletWindow portletWindow : portletWindows) {
                            this.logger.debug("{} resolved target {}", event, portletWindow);
                            final IPortletWindowId portletWindowId = portletWindow.getPortletWindowId();
                            final Event unmarshalledEvent = this.unmarshall(portletWindow, event);
                            portletEventQueue.offerEvent(portletWindowId, new QueuedEvent(sourceWindowId, unmarshalledEvent));
                        }
                    }
                }
            }
        }
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) EntityIdentifier(org.apereo.portal.EntityIdentifier) IPortletWindow(org.apereo.portal.portlet.om.IPortletWindow) LinkedHashMap(java.util.LinkedHashMap) IUserInstance(org.apereo.portal.user.IUserInstance) IPerson(org.apereo.portal.security.IPerson) IPortletEntity(org.apereo.portal.portlet.om.IPortletEntity) IPortletDefinitionParameter(org.apereo.portal.portlet.om.IPortletDefinitionParameter) IAuthorizationPrincipal(org.apereo.portal.security.IAuthorizationPrincipal) IUserPreferencesManager(org.apereo.portal.IUserPreferencesManager) IUserLayoutManager(org.apereo.portal.layout.IUserLayoutManager) IPortletEntityId(org.apereo.portal.portlet.om.IPortletEntityId) IPortletDefinition(org.apereo.portal.portlet.om.IPortletDefinition) IPortletDefinition(org.apereo.portal.portlet.om.IPortletDefinition) PortletDefinition(org.apache.pluto.container.om.portlet.PortletDefinition) IPortletDefinitionId(org.apereo.portal.portlet.om.IPortletDefinitionId) Event(javax.portlet.Event) IPortletWindowId(org.apereo.portal.portlet.om.IPortletWindowId)

Aggregations

PortletDefinition (org.apache.pluto.container.om.portlet.PortletDefinition)19 IPortletDefinition (org.apereo.portal.portlet.om.IPortletDefinition)13 PortletApplicationDefinition (org.apache.pluto.container.om.portlet.PortletApplicationDefinition)7 IPortletDefinitionId (org.apereo.portal.portlet.om.IPortletDefinitionId)7 PortletContainerException (org.apache.pluto.container.PortletContainerException)6 QName (javax.xml.namespace.QName)4 PortletRegistryService (org.apache.pluto.container.driver.PortletRegistryService)4 IPortletEntity (org.apereo.portal.portlet.om.IPortletEntity)4 IPortletWindow (org.apereo.portal.portlet.om.IPortletWindow)4 EventDefinition (org.apache.pluto.container.om.portlet.EventDefinition)3 EventDefinitionReference (org.apache.pluto.container.om.portlet.EventDefinitionReference)3 Preference (org.apache.pluto.container.om.portlet.Preference)3 Preferences (org.apache.pluto.container.om.portlet.Preferences)3 PortletPreferenceImpl (org.apereo.portal.portlet.dao.jpa.PortletPreferenceImpl)3 IPortletEntityId (org.apereo.portal.portlet.om.IPortletEntityId)3 IPortletPreference (org.apereo.portal.portlet.om.IPortletPreference)3 CacheControl (javax.portlet.CacheControl)2 Event (javax.portlet.Event)2 Supports (org.apache.pluto.container.om.portlet.Supports)2 MockPortletDefinitionId (org.apereo.portal.mock.portlet.om.MockPortletDefinitionId)2