Search in sources :

Example 1 with EventDefinitionReference

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

the class EventProviderImpl method isDeclaredAsPublishingEvent.

private boolean isDeclaredAsPublishingEvent(QName qname) {
    final PortletDefinition portletDescriptor = this.portletWindow.getPlutoPortletWindow().getPortletDefinition();
    final List<? extends EventDefinitionReference> events = portletDescriptor.getSupportedPublishingEvents();
    if (events == null) {
        return false;
    }
    final PortletApplicationDefinition application = portletDescriptor.getApplication();
    final String defaultNamespace = application.getDefaultNamespace();
    for (final EventDefinitionReference ref : events) {
        final QName name = ref.getQualifiedName(defaultNamespace);
        if (name == null) {
            continue;
        }
        if (qname.equals(name)) {
            return true;
        }
    }
    return false;
}
Also used : EventDefinitionReference(org.apache.pluto.container.om.portlet.EventDefinitionReference) PortletApplicationDefinition(org.apache.pluto.container.om.portlet.PortletApplicationDefinition) QName(javax.xml.namespace.QName) PortletDefinition(org.apache.pluto.container.om.portlet.PortletDefinition)

Example 2 with EventDefinitionReference

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

the class PortletEventCoordinatationServiceTest method testSupportedEventResolution.

@Test
public void testSupportedEventResolution() throws Exception {
    final QName searchRequestName = new QName("https://source.jasig.org/schemas/uportal/search", "SearchRequest");
    final QName searchResultsName = new QName("https://source.jasig.org/schemas/uportal/search", "SearchResults");
    //org.apereo.portal.search.SearchQuery
    final Event event = mock(Event.class);
    final MockPortletDefinitionId portletDefinitionId = new MockPortletDefinitionId(1);
    final PortletApplicationDefinition portletApplicationDefinition = mock(PortletApplicationDefinition.class);
    final PortletDefinition portletDefinition = mock(PortletDefinition.class);
    final EventDefinitionReference searchRequestEventDefinitionReference = mock(EventDefinitionReference.class);
    final EventDefinitionReference searchResultsEventDefinitionReference = mock(EventDefinitionReference.class);
    final EventDefinition searchRequestEventDefinition = mock(EventDefinition.class);
    final EventDefinition searchResultsEventDefinition = mock(EventDefinition.class);
    when(event.getQName()).thenReturn(searchRequestName);
    when(searchRequestEventDefinitionReference.getQualifiedName(anyString())).thenReturn(searchRequestName);
    when(searchRequestEventDefinitionReference.getQName()).thenReturn(searchRequestName);
    when(searchResultsEventDefinitionReference.getQualifiedName(anyString())).thenReturn(searchResultsName);
    when(searchResultsEventDefinitionReference.getQName()).thenReturn(searchResultsName);
    when(searchRequestEventDefinition.getQName()).thenReturn(searchRequestName);
    when(searchRequestEventDefinition.getQualifiedName(anyString())).thenReturn(searchRequestName);
    when(searchResultsEventDefinition.getQName()).thenReturn(searchResultsName);
    when(searchResultsEventDefinition.getQualifiedName(anyString())).thenReturn(searchResultsName);
    when(this.portletDefinitionRegistry.getParentPortletApplicationDescriptor(portletDefinitionId)).thenReturn(portletApplicationDefinition);
    when(this.portletDefinitionRegistry.getParentPortletDescriptor(portletDefinitionId)).thenReturn(portletDefinition);
    final List<? extends EventDefinition> eventDefinitions = Arrays.asList(searchRequestEventDefinition, searchResultsEventDefinition);
    when(portletApplicationDefinition.getEventDefinitions()).thenReturn((List) eventDefinitions);
    final List<? extends EventDefinitionReference> supportedProcessingEvents = Collections.singletonList(searchRequestEventDefinitionReference);
    when(portletDefinition.getSupportedProcessingEvents()).thenReturn((List) supportedProcessingEvents);
    final boolean supportsEvent = portletEventCoordinatationService.supportsEvent(event, portletDefinitionId);
    assertTrue(supportsEvent);
}
Also used : MockPortletDefinitionId(org.apereo.portal.mock.portlet.om.MockPortletDefinitionId) EventDefinitionReference(org.apache.pluto.container.om.portlet.EventDefinitionReference) PortletApplicationDefinition(org.apache.pluto.container.om.portlet.PortletApplicationDefinition) QName(javax.xml.namespace.QName) Event(javax.portlet.Event) EventDefinition(org.apache.pluto.container.om.portlet.EventDefinition) PortletDefinition(org.apache.pluto.container.om.portlet.PortletDefinition) Test(org.junit.Test)

Example 3 with EventDefinitionReference

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

the class PortletEventCoordinatationService method supportsEvent.

protected boolean supportsEvent(Event event, IPortletDefinitionId portletDefinitionId) {
    final QName eventName = event.getQName();
    //The cache key to use
    final Tuple<IPortletDefinitionId, QName> key = new Tuple<IPortletDefinitionId, QName>(portletDefinitionId, eventName);
    //Check in the cache if the portlet definition supports this event
    final Element element = this.supportedEventCache.get(key);
    if (element != null) {
        final Boolean supported = (Boolean) element.getObjectValue();
        if (supported != null) {
            return supported;
        }
    }
    final PortletApplicationDefinition portletApplicationDescriptor = this.portletDefinitionRegistry.getParentPortletApplicationDescriptor(portletDefinitionId);
    if (portletApplicationDescriptor == null) {
        return false;
    }
    final Set<QName> aliases = this.getAllAliases(eventName, portletApplicationDescriptor);
    final String defaultNamespace = portletApplicationDescriptor.getDefaultNamespace();
    //No support found so far, do more complex namespace matching
    final PortletDefinition portletDescriptor = this.portletDefinitionRegistry.getParentPortletDescriptor(portletDefinitionId);
    if (portletDescriptor == null) {
        return false;
    }
    final List<? extends EventDefinitionReference> supportedProcessingEvents = portletDescriptor.getSupportedProcessingEvents();
    for (final EventDefinitionReference eventDefinitionReference : supportedProcessingEvents) {
        final QName qualifiedName = eventDefinitionReference.getQualifiedName(defaultNamespace);
        if (qualifiedName == null) {
            continue;
        }
        //Look for alias names
        if (qualifiedName.equals(eventName) || aliases.contains(qualifiedName)) {
            this.supportedEventCache.put(new Element(key, Boolean.TRUE));
            return true;
        }
        //Look for namespaced events
        if (StringUtils.isEmpty(qualifiedName.getNamespaceURI())) {
            final QName namespacedName = new QName(defaultNamespace, qualifiedName.getLocalPart());
            if (eventName.equals(namespacedName)) {
                this.supportedEventCache.put(new Element(key, Boolean.TRUE));
                return true;
            }
        }
    }
    this.supportedEventCache.put(new Element(key, Boolean.FALSE));
    return false;
}
Also used : IPortletDefinitionId(org.apereo.portal.portlet.om.IPortletDefinitionId) EventDefinitionReference(org.apache.pluto.container.om.portlet.EventDefinitionReference) PortletApplicationDefinition(org.apache.pluto.container.om.portlet.PortletApplicationDefinition) QName(javax.xml.namespace.QName) Element(net.sf.ehcache.Element) JAXBElement(javax.xml.bind.JAXBElement) Tuple(org.apereo.portal.utils.Tuple) IPortletDefinition(org.apereo.portal.portlet.om.IPortletDefinition) PortletDefinition(org.apache.pluto.container.om.portlet.PortletDefinition)

Aggregations

QName (javax.xml.namespace.QName)3 EventDefinitionReference (org.apache.pluto.container.om.portlet.EventDefinitionReference)3 PortletApplicationDefinition (org.apache.pluto.container.om.portlet.PortletApplicationDefinition)3 PortletDefinition (org.apache.pluto.container.om.portlet.PortletDefinition)3 Event (javax.portlet.Event)1 JAXBElement (javax.xml.bind.JAXBElement)1 Element (net.sf.ehcache.Element)1 EventDefinition (org.apache.pluto.container.om.portlet.EventDefinition)1 MockPortletDefinitionId (org.apereo.portal.mock.portlet.om.MockPortletDefinitionId)1 IPortletDefinition (org.apereo.portal.portlet.om.IPortletDefinition)1 IPortletDefinitionId (org.apereo.portal.portlet.om.IPortletDefinitionId)1 Tuple (org.apereo.portal.utils.Tuple)1 Test (org.junit.Test)1