Search in sources :

Example 1 with Event

use of javax.portlet.Event 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 Event

use of javax.portlet.Event in project uPortal by Jasig.

the class SearchPortletController method handleSearchResult.

/** Handles all the SearchResults events coming back from portlets */
@EventMapping(SearchConstants.SEARCH_RESULTS_QNAME_STRING)
public void handleSearchResult(EventRequest request) {
    // UP-3887 Design flaw.  Both the searchLauncher portlet instance and the search portlet instance receive
    // searchRequest and searchResult events because they are in the same portlet code base (to share
    // autosuggest_handler.jsp and because we have to calculate the search portlet url for the ajax call)
    // and share the portlet.xml which defines the event handling behavior.
    // If this instance is the searchLauncher, ignore the searchResult. The search was submitted to the search
    // portlet instance.
    final String searchLaunchFname = request.getPreferences().getValue(SEARCH_LAUNCH_FNAME, null);
    if (searchLaunchFname != null) {
        // logger.debug("SearchLauncher does not process SearchResponse events so discarding message");
        return;
    }
    final Event event = request.getEvent();
    final SearchResults portletSearchResults = (SearchResults) event.getValue();
    // get the existing portal search result from the session and append
    // the results for this event
    final String queryId = portletSearchResults.getQueryId();
    final PortalSearchResults results = this.getPortalSearchResults(request, queryId);
    if (results == null) {
        this.logger.warn("No PortalSearchResults found for queryId {}, ignoring search results from {}", queryId, getSearchResultsSource(portletSearchResults));
        return;
    }
    if (logger.isDebugEnabled()) {
        logger.debug("For queryId {}, adding {} search results from {}", queryId, portletSearchResults.getSearchResult().size(), getSearchResultsSource(portletSearchResults));
    }
    final String windowId = portletSearchResults.getWindowId();
    final HttpServletRequest httpServletRequest = this.portalRequestUtils.getPortletHttpRequest(request);
    final IPortletWindowId portletWindowId = this.portletWindowRegistry.getPortletWindowId(httpServletRequest, windowId);
    //Add the other portlet's results to the main search results object
    this.addSearchResults(portletSearchResults, results, httpServletRequest, portletWindowId);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) Event(javax.portlet.Event) SearchResults(org.apereo.portal.search.SearchResults) IPortletWindowId(org.apereo.portal.portlet.om.IPortletWindowId) EventMapping(org.springframework.web.portlet.bind.annotation.EventMapping)

Example 3 with Event

use of javax.portlet.Event in project uPortal by Jasig.

the class DirectoryPortletController method search2.

@EventMapping(SearchConstants.SEARCH_REQUEST_QNAME_STRING)
public void search2(EventRequest request, EventResponse response) {
    // get the search query object from the event
    Event event = request.getEvent();
    SearchRequest query = (SearchRequest) event.getValue();
    // search the portal's directory service for people matching the request
    final List<IPersonAttributes> people = searchDirectory(query.getSearchTerms(), request);
    if (people.size() > 0) {
        // transform the list of directory results into our generic search
        // response object
        final SearchResults results = new SearchResults();
        results.setQueryId(query.getQueryId());
        results.setWindowId(request.getWindowID());
        for (IPersonAttributes person : people) {
            final SearchResult result = new SearchResult();
            result.setTitle((String) person.getAttributeValue("displayName"));
            result.getType().add(directorySearchResultType);
            PortletUrl url = new PortletUrl();
            url.setType(PortletUrlType.RENDER);
            url.setPortletMode("VIEW");
            url.setWindowState("maximized");
            PortletUrlParameter actionParam = new PortletUrlParameter();
            actionParam.setName("action");
            actionParam.getValue().add("findByUsername");
            url.getParam().add(actionParam);
            PortletUrlParameter usernameParam = new PortletUrlParameter();
            usernameParam.setName("username");
            usernameParam.getValue().add(person.getName());
            url.getParam().add(usernameParam);
            result.setPortletUrl(url);
            results.getSearchResult().add(result);
        }
        // fire a search response event
        response.setEvent(SearchConstants.SEARCH_RESULTS_QNAME, results);
    }
}
Also used : SearchRequest(org.apereo.portal.search.SearchRequest) IPersonAttributes(org.jasig.services.persondir.IPersonAttributes) Event(javax.portlet.Event) PortletUrlParameter(org.apereo.portal.search.PortletUrlParameter) SearchResult(org.apereo.portal.search.SearchResult) SearchResults(org.apereo.portal.search.SearchResults) PortletUrl(org.apereo.portal.search.PortletUrl) EventMapping(org.springframework.web.portlet.bind.annotation.EventMapping)

Example 4 with Event

use of javax.portlet.Event in project uPortal by Jasig.

the class SearchPortletController method handleSearchRequest.

/**
     * Performs a search of the explicitly configured {@link IPortalSearchService}s. This is done as
     * an event handler so that it can run concurrently with the other portlets handling the search
     * request
     */
@SuppressWarnings("unchecked")
@EventMapping(SearchConstants.SEARCH_REQUEST_QNAME_STRING)
public void handleSearchRequest(EventRequest request, EventResponse response) {
    // UP-3887 Design flaw.  Both the searchLauncher portlet instance and the search portlet instance receive
    // searchRequest and searchResult events because they are in the same portlet code base (to share
    // autosuggest_handler.jsp and because we have to calculate the search portlet url for the ajax call)
    // and share the portlet.xml which defines the event handling behavior.
    // If this instance is the searchLauncher, ignore the searchResult. The search was submitted to the search
    // portlet instance.
    final String searchLaunchFname = request.getPreferences().getValue(SEARCH_LAUNCH_FNAME, null);
    if (searchLaunchFname != null) {
        // logger.debug("SearchLauncher does not participate in SearchRequest events so discarding message");
        return;
    }
    final Event event = request.getEvent();
    final SearchRequest searchQuery = (SearchRequest) event.getValue();
    //Map used to track searches that have been handled, used so that one search doesn't get duplicate results
    ConcurrentMap<String, Boolean> searchHandledCache;
    final PortletSession session = request.getPortletSession();
    synchronized (org.springframework.web.portlet.util.PortletUtils.getSessionMutex(session)) {
        searchHandledCache = (ConcurrentMap<String, Boolean>) session.getAttribute(SEARCH_HANDLED_CACHE_NAME, PortletSession.APPLICATION_SCOPE);
        if (searchHandledCache == null) {
            searchHandledCache = CacheBuilder.newBuilder().maximumSize(20).expireAfterAccess(5, TimeUnit.MINUTES).<String, Boolean>build().asMap();
            session.setAttribute(SEARCH_HANDLED_CACHE_NAME, searchHandledCache, PortletSession.APPLICATION_SCOPE);
        }
    }
    final String queryId = searchQuery.getQueryId();
    if (searchHandledCache.putIfAbsent(queryId, Boolean.TRUE) != null) {
        //Already handled this search request
        return;
    }
    //Create the results
    final SearchResults results = new SearchResults();
    results.setQueryId(queryId);
    results.setWindowId(request.getWindowID());
    final List<SearchResult> searchResultList = results.getSearchResult();
    //Run the search for each service appending the results
    for (IPortalSearchService searchService : searchServices) {
        try {
            logger.debug("For queryId {}, query '{}', searching search service {}", queryId, searchQuery.getSearchTerms(), searchService.getClass().toString());
            final SearchResults serviceResults = searchService.getSearchResults(request, searchQuery);
            logger.debug("For queryId {}, obtained {} results from search service {}", queryId, serviceResults.getSearchResult().size(), searchService.getClass().toString());
            searchResultList.addAll(serviceResults.getSearchResult());
        } catch (Exception e) {
            logger.warn(searchService.getClass() + " threw an exception when searching, it will be ignored. " + searchQuery, e);
        }
    }
    //Respond with a results event if results were found
    if (!searchResultList.isEmpty()) {
        response.setEvent(SearchConstants.SEARCH_RESULTS_QNAME, results);
    }
}
Also used : SearchRequest(org.apereo.portal.search.SearchRequest) PortletSession(javax.portlet.PortletSession) Event(javax.portlet.Event) SearchResult(org.apereo.portal.search.SearchResult) SearchResults(org.apereo.portal.search.SearchResults) SpelParseException(org.springframework.expression.spel.SpelParseException) SpelEvaluationException(org.springframework.expression.spel.SpelEvaluationException) IOException(java.io.IOException) EventMapping(org.springframework.web.portlet.bind.annotation.EventMapping)

Example 5 with Event

use of javax.portlet.Event in project uPortal by Jasig.

the class PortletExecutionManager method doPortletEvents.

public void doPortletEvents(PortletEventQueue eventQueue, HttpServletRequest request, HttpServletResponse response) {
    if (eventQueue.getUnresolvedEvents().isEmpty()) {
        return;
    }
    final Map<IPortletWindowId, IPortletExecutionWorker<Long>> eventWorkers = new LinkedHashMap<IPortletWindowId, IPortletExecutionWorker<Long>>();
    //TODO what to do if we hit the max iterations?
    int iteration = 0;
    for (; iteration < this.maxEventIterations; iteration++) {
        //Make sure all queued events have been resolved
        this.eventCoordinationService.resolvePortletEvents(request, eventQueue);
        //Create and submit an event worker for each window with a queued event
        for (final IPortletWindowId eventWindowId : eventQueue) {
            if (eventWorkers.containsKey(eventWindowId)) {
                /*
                     * PLT.15.2.5 says that event processing per window must be serialized, if there
                     * is already a working in the map for the window ID skip it for now. we'll get back to it eventually
                     */
                continue;
            }
            final QueuedEvent queuedEvent = eventQueue.pollEvent(eventWindowId);
            if (queuedEvent != null) {
                final Event event = queuedEvent.getEvent();
                final IPortletExecutionWorker<Long> portletEventExecutionWorker = this.portletWorkerFactory.createEventWorker(request, response, eventWindowId, event);
                eventWorkers.put(eventWindowId, portletEventExecutionWorker);
                portletEventExecutionWorker.submit();
            }
        }
        //If no event workers exist we're done with event processing!
        if (eventWorkers.isEmpty()) {
            return;
        }
        //See if any of the events have completed
        int completedEventWorkers = 0;
        final Set<Entry<IPortletWindowId, IPortletExecutionWorker<Long>>> entrySet = eventWorkers.entrySet();
        for (final Iterator<Entry<IPortletWindowId, IPortletExecutionWorker<Long>>> eventWorkerEntryItr = entrySet.iterator(); eventWorkerEntryItr.hasNext(); ) {
            final Entry<IPortletWindowId, IPortletExecutionWorker<Long>> eventWorkerEntry = eventWorkerEntryItr.next();
            final IPortletExecutionWorker<Long> eventWorker = eventWorkerEntry.getValue();
            if (eventWorker.isComplete()) {
                final IPortletWindowId portletWindowId = eventWorkerEntry.getKey();
                //TODO return number of new queued events, use to break the loop earlier
                waitForEventWorker(request, eventQueue, eventWorker, portletWindowId);
                eventWorkerEntryItr.remove();
                completedEventWorkers++;
            }
        }
        /*
             * If no event workers have completed without waiting wait for the first one and then loop again
             * Not waiting for all events since each event may spawn more events and we want to start them
             * processing as soon as possible
             */
        if (completedEventWorkers == 0) {
            final Iterator<Entry<IPortletWindowId, IPortletExecutionWorker<Long>>> eventWorkerEntryItr = entrySet.iterator();
            final Entry<IPortletWindowId, IPortletExecutionWorker<Long>> eventWorkerEntry = eventWorkerEntryItr.next();
            eventWorkerEntryItr.remove();
            final IPortletWindowId portletWindowId = eventWorkerEntry.getKey();
            final IPortletExecutionWorker<Long> eventWorker = eventWorkerEntry.getValue();
            waitForEventWorker(request, eventQueue, eventWorker, portletWindowId);
        }
    }
    if (iteration == this.maxEventIterations) {
        this.logger.error("The Event dispatching iteration maximum of " + this.maxEventIterations + " was hit, consider either raising this limit or reviewing the portlets that use events to reduce the number of events spawned");
    }
}
Also used : IPortletExecutionWorker(org.apereo.portal.portlet.rendering.worker.IPortletExecutionWorker) LinkedHashMap(java.util.LinkedHashMap) Entry(java.util.Map.Entry) Event(javax.portlet.Event) IPortletWindowId(org.apereo.portal.portlet.om.IPortletWindowId)

Aggregations

Event (javax.portlet.Event)7 IPortletWindowId (org.apereo.portal.portlet.om.IPortletWindowId)4 SearchResults (org.apereo.portal.search.SearchResults)3 EventMapping (org.springframework.web.portlet.bind.annotation.EventMapping)3 LinkedHashMap (java.util.LinkedHashMap)2 PortletDefinition (org.apache.pluto.container.om.portlet.PortletDefinition)2 IPortletWindow (org.apereo.portal.portlet.om.IPortletWindow)2 SearchRequest (org.apereo.portal.search.SearchRequest)2 SearchResult (org.apereo.portal.search.SearchResult)2 IOException (java.io.IOException)1 LinkedHashSet (java.util.LinkedHashSet)1 Entry (java.util.Map.Entry)1 PortletSession (javax.portlet.PortletSession)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 QName (javax.xml.namespace.QName)1 EventDefinition (org.apache.pluto.container.om.portlet.EventDefinition)1 EventDefinitionReference (org.apache.pluto.container.om.portlet.EventDefinitionReference)1 PortletApplicationDefinition (org.apache.pluto.container.om.portlet.PortletApplicationDefinition)1 EntityIdentifier (org.apereo.portal.EntityIdentifier)1 IUserPreferencesManager (org.apereo.portal.IUserPreferencesManager)1