Search in sources :

Example 1 with EventDefinition

use of org.apache.pluto.container.om.portlet.EventDefinition 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 2 with EventDefinition

use of org.apache.pluto.container.om.portlet.EventDefinition 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 3 with EventDefinition

use of org.apache.pluto.container.om.portlet.EventDefinition 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 4 with EventDefinition

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

the class PortletEventCoordinatationService method getAllAliases.

protected Set<QName> getAllAliases(QName eventName, PortletApplicationDefinition portletApplicationDefinition) {
    final List<? extends EventDefinition> eventDefinitions = portletApplicationDefinition.getEventDefinitions();
    if (eventDefinitions == null || eventDefinitions.isEmpty()) {
        return Collections.emptySet();
    }
    final String defaultNamespace = portletApplicationDefinition.getDefaultNamespace();
    for (final EventDefinition eventDefinition : eventDefinitions) {
        final QName defQName = eventDefinition.getQualifiedName(defaultNamespace);
        if (defQName != null && defQName.equals(eventName)) {
            final List<QName> aliases = eventDefinition.getAliases();
            if (aliases == null || aliases.isEmpty()) {
                return Collections.emptySet();
            }
            return new LinkedHashSet<QName>(aliases);
        }
    }
    return Collections.emptySet();
}
Also used : LinkedHashSet(java.util.LinkedHashSet) QName(javax.xml.namespace.QName) EventDefinition(org.apache.pluto.container.om.portlet.EventDefinition)

Aggregations

EventDefinition (org.apache.pluto.container.om.portlet.EventDefinition)4 QName (javax.xml.namespace.QName)3 PortletApplicationDefinition (org.apache.pluto.container.om.portlet.PortletApplicationDefinition)3 PortletDefinition (org.apache.pluto.container.om.portlet.PortletDefinition)3 Serializable (java.io.Serializable)1 StringReader (java.io.StringReader)1 LinkedHashSet (java.util.LinkedHashSet)1 Event (javax.portlet.Event)1 JAXBContext (javax.xml.bind.JAXBContext)1 JAXBException (javax.xml.bind.JAXBException)1 Unmarshaller (javax.xml.bind.Unmarshaller)1 XMLInputFactory (javax.xml.stream.XMLInputFactory)1 XMLStreamException (javax.xml.stream.XMLStreamException)1 XMLStreamReader (javax.xml.stream.XMLStreamReader)1 PortletContainerException (org.apache.pluto.container.PortletContainerException)1 EventDefinitionReference (org.apache.pluto.container.om.portlet.EventDefinitionReference)1 MockPortletDefinitionId (org.apereo.portal.mock.portlet.om.MockPortletDefinitionId)1 EventImpl (org.apereo.portal.portlet.container.EventImpl)1 IPortletDefinition (org.apereo.portal.portlet.om.IPortletDefinition)1 Test (org.junit.Test)1