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;
}
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);
}
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;
}
Aggregations