Search in sources :

Example 1 with PortletUrlParameter

use of org.apereo.portal.search.PortletUrlParameter in project uPortal by Jasig.

the class PortletUtils method getStringFromPortletUrl.

/**
     * A static EL function that is defined in portletUrl.tld Takes a portletUrl object and coverts
     * it into an actual Url Example is in search, returns a marketplace entry Url
     *
     * @param portletUrl
     * @param request
     * @return the Url represented by portletUrl
     */
public static String getStringFromPortletUrl(PortletUrl portletUrl, HttpServletRequest request) {
    if (portletUrl == null) {
        return null;
    }
    //Default urlType
    UrlType urlType = UrlType.RENDER;
    final PortletUrlType type = portletUrl.getType();
    switch(type) {
        case ACTION:
            urlType = UrlType.ACTION;
            break;
        case RESOURCE:
            urlType = UrlType.RESOURCE;
            break;
        default:
            urlType = UrlType.RENDER;
            break;
    }
    IPortletWindow marketplaceWindow = portletWindowRegistry.getOrCreateDefaultPortletWindowByFname(request, MarketplacePortletDefinition.MARKETPLACE_FNAME);
    IPortalUrlBuilder portalUrlBuilder = portalUrlProvider.getPortalUrlBuilderByPortletWindow(request, marketplaceWindow.getPortletWindowId(), urlType);
    IPortletUrlBuilder portletUrlBuilder = portalUrlBuilder.getTargetedPortletUrlBuilder();
    final String portletMode = portletUrl.getPortletMode();
    if (portletMode != null) {
        portletUrlBuilder.setPortletMode(PortletUtils.getPortletMode(portletMode));
    }
    final String windowState = portletUrl.getWindowState();
    if (windowState != null) {
        portletUrlBuilder.setWindowState(PortletUtils.getWindowState(windowState));
    }
    for (final PortletUrlParameter param : portletUrl.getParam()) {
        final String name = param.getName();
        final List<String> values = param.getValue();
        portletUrlBuilder.addParameter(name, values.toArray(new String[values.size()]));
    }
    return portalUrlBuilder.getUrlString();
}
Also used : IPortletUrlBuilder(org.apereo.portal.url.IPortletUrlBuilder) PortletUrlParameter(org.apereo.portal.search.PortletUrlParameter) PortletUrlType(org.apereo.portal.search.PortletUrlType) IPortalUrlBuilder(org.apereo.portal.url.IPortalUrlBuilder) PortletUrlType(org.apereo.portal.search.PortletUrlType) UrlType(org.apereo.portal.url.UrlType) IPortletWindow(org.apereo.portal.portlet.om.IPortletWindow)

Example 2 with PortletUrlParameter

use of org.apereo.portal.search.PortletUrlParameter 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 3 with PortletUrlParameter

use of org.apereo.portal.search.PortletUrlParameter in project uPortal by Jasig.

the class SearchPortletController method getResultUrl.

/** Determine the url for the search result */
protected String getResultUrl(HttpServletRequest httpServletRequest, SearchResult result, IPortletWindowId portletWindowId) {
    final String externalUrl = result.getExternalUrl();
    if (externalUrl != null) {
        return externalUrl;
    }
    UrlType urlType = UrlType.RENDER;
    final PortletUrl portletUrl = result.getPortletUrl();
    if (portletUrl != null) {
        final PortletUrlType type = portletUrl.getType();
        if (type != null) {
            switch(type) {
                case ACTION:
                    {
                        urlType = UrlType.ACTION;
                        break;
                    }
                default:
                case RENDER:
                    {
                        urlType = UrlType.RENDER;
                        break;
                    }
                case RESOURCE:
                    {
                        urlType = UrlType.RESOURCE;
                        break;
                    }
            }
        }
    }
    final IPortalUrlBuilder portalUrlBuilder = this.portalUrlProvider.getPortalUrlBuilderByPortletWindow(httpServletRequest, portletWindowId, urlType);
    final IPortletUrlBuilder portletUrlBuilder = portalUrlBuilder.getTargetedPortletUrlBuilder();
    if (portletUrl != null) {
        final String portletMode = portletUrl.getPortletMode();
        if (portletMode != null) {
            portletUrlBuilder.setPortletMode(PortletUtils.getPortletMode(portletMode));
        }
        final String windowState = portletUrl.getWindowState();
        if (windowState != null) {
            portletUrlBuilder.setWindowState(PortletUtils.getWindowState(windowState));
        }
        for (final PortletUrlParameter param : portletUrl.getParam()) {
            final String name = param.getName();
            final List<String> values = param.getValue();
            portletUrlBuilder.addParameter(name, values.toArray(new String[values.size()]));
        }
    }
    return portalUrlBuilder.getUrlString();
}
Also used : IPortletUrlBuilder(org.apereo.portal.url.IPortletUrlBuilder) PortletUrlParameter(org.apereo.portal.search.PortletUrlParameter) PortletUrl(org.apereo.portal.search.PortletUrl) PortletUrlType(org.apereo.portal.search.PortletUrlType) IPortalUrlBuilder(org.apereo.portal.url.IPortalUrlBuilder) UrlType(org.apereo.portal.url.UrlType) PortletUrlType(org.apereo.portal.search.PortletUrlType)

Example 4 with PortletUrlParameter

use of org.apereo.portal.search.PortletUrlParameter in project uPortal by Jasig.

the class MarketplaceSearchService method getSearchResults.

/**
     * Returns a list of search results that pertain to the marketplace query is the query to search
     * will search name, title, description, fname, and captions
     */
@Override
public SearchResults getSearchResults(PortletRequest request, SearchRequest query) {
    final String queryString = query.getSearchTerms().toLowerCase();
    final List<IPortletDefinition> portlets = portletDefinitionRegistry.getAllPortletDefinitions();
    final HttpServletRequest httpServletRequest = this.portalRequestUtils.getPortletHttpRequest(request);
    final SearchResults results = new SearchResults();
    for (IPortletDefinition portlet : portlets) {
        if (this.matches(queryString, new MarketplacePortletDefinition(portlet, this.marketplaceService, this.portletCategoryRegistry))) {
            final SearchResult result = new SearchResult();
            result.setTitle(portlet.getTitle());
            result.setSummary(portlet.getDescription());
            result.getType().add("marketplace");
            final IPortletWindow portletWindow = this.portletWindowRegistry.getOrCreateDefaultPortletWindowByFname(httpServletRequest, portlet.getFName());
            // If user does not have browse permission, exclude the portlet.
            if (portletWindow != null && authorizationService.canPrincipalBrowse(authorizationService.newPrincipal(request.getRemoteUser(), EntityEnum.PERSON.getClazz()), portlet)) {
                final IPortletWindowId portletWindowId = portletWindow.getPortletWindowId();
                final IPortalUrlBuilder portalUrlBuilder = this.portalUrlProvider.getPortalUrlBuilderByPortletFName(httpServletRequest, portlet.getFName(), UrlType.RENDER);
                final IPortletUrlBuilder portletUrlBuilder = portalUrlBuilder.getPortletUrlBuilder(portletWindowId);
                portletUrlBuilder.setWindowState(PortletUtils.getWindowState("maximized"));
                result.setExternalUrl(portalUrlBuilder.getUrlString());
                PortletUrl url = new PortletUrl();
                url.setType(PortletUrlType.RENDER);
                url.setPortletMode("VIEW");
                url.setWindowState("maximized");
                PortletUrlParameter actionParam = new PortletUrlParameter();
                actionParam.setName("action");
                actionParam.getValue().add("view");
                url.getParam().add(actionParam);
                PortletUrlParameter fNameParam = new PortletUrlParameter();
                fNameParam.setName("fName");
                fNameParam.getValue().add(portlet.getFName());
                url.getParam().add(fNameParam);
                result.setPortletUrl(url);
                //Add the result to list to return
                results.getSearchResult().add(result);
            }
        }
    }
    return results;
}
Also used : IPortletUrlBuilder(org.apereo.portal.url.IPortletUrlBuilder) SearchResult(org.apereo.portal.search.SearchResult) SearchResults(org.apereo.portal.search.SearchResults) IPortalUrlBuilder(org.apereo.portal.url.IPortalUrlBuilder) IPortletWindow(org.apereo.portal.portlet.om.IPortletWindow) HttpServletRequest(javax.servlet.http.HttpServletRequest) PortletUrlParameter(org.apereo.portal.search.PortletUrlParameter) PortletUrl(org.apereo.portal.search.PortletUrl) IPortletWindowId(org.apereo.portal.portlet.om.IPortletWindowId) IPortletDefinition(org.apereo.portal.portlet.om.IPortletDefinition)

Aggregations

PortletUrlParameter (org.apereo.portal.search.PortletUrlParameter)4 PortletUrl (org.apereo.portal.search.PortletUrl)3 IPortalUrlBuilder (org.apereo.portal.url.IPortalUrlBuilder)3 IPortletUrlBuilder (org.apereo.portal.url.IPortletUrlBuilder)3 IPortletWindow (org.apereo.portal.portlet.om.IPortletWindow)2 PortletUrlType (org.apereo.portal.search.PortletUrlType)2 SearchResult (org.apereo.portal.search.SearchResult)2 SearchResults (org.apereo.portal.search.SearchResults)2 UrlType (org.apereo.portal.url.UrlType)2 Event (javax.portlet.Event)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 IPortletDefinition (org.apereo.portal.portlet.om.IPortletDefinition)1 IPortletWindowId (org.apereo.portal.portlet.om.IPortletWindowId)1 SearchRequest (org.apereo.portal.search.SearchRequest)1 IPersonAttributes (org.jasig.services.persondir.IPersonAttributes)1 EventMapping (org.springframework.web.portlet.bind.annotation.EventMapping)1