Search in sources :

Example 6 with SearchResult

use of org.eclipse.sw360.datahandler.thrift.search.SearchResult in project sw360portal by sw360.

the class SearchPortlet method doView.

@Override
public void doView(RenderRequest request, RenderResponse response) throws IOException, PortletException {
    final User user = UserCacheHolder.getUserFromRequest(request);
    String searchtext = request.getParameter(KEY_SEARCH_TEXT);
    String[] typeMaskArray = request.getParameterValues(TYPE_MASK);
    List<String> typeMask;
    if (typeMaskArray != null) {
        // premature optimization would add && typeMaskArray.length<6
        typeMask = Arrays.asList(typeMaskArray);
    } else {
        typeMask = Collections.emptyList();
        log.info("typeMask set to emptyList");
    }
    String usedsearchtext;
    if (isNullOrEmpty(searchtext)) {
        usedsearchtext = "";
        searchtext = "";
    } else {
        usedsearchtext = searchtext;
    }
    List<SearchResult> searchResults;
    try {
        SearchService.Iface client = thriftClients.makeSearchClient();
        searchResults = client.searchFiltered(usedsearchtext, user, typeMask);
    } catch (TException e) {
        log.error("Search could not be performed!", e);
        searchResults = Collections.emptyList();
    }
    // Set the results
    request.setAttribute(KEY_SEARCH_TEXT, searchtext);
    request.setAttribute(KEY_SUMMARY, searchResults);
    request.setAttribute(TYPE_MASK, typeMask);
    // Proceed with page rendering
    super.doView(request, response);
}
Also used : TException(org.apache.thrift.TException) User(org.eclipse.sw360.datahandler.thrift.users.User) SearchService(org.eclipse.sw360.datahandler.thrift.search.SearchService) SearchResult(org.eclipse.sw360.datahandler.thrift.search.SearchResult)

Aggregations

TException (org.apache.thrift.TException)4 SearchResult (org.eclipse.sw360.datahandler.thrift.search.SearchResult)4 User (org.eclipse.sw360.datahandler.thrift.users.User)3 WrappedTException (org.eclipse.sw360.datahandler.common.WrappedException.WrappedTException)2 SearchService (org.eclipse.sw360.datahandler.thrift.search.SearchService)2 TCompactProtocol (org.apache.thrift.protocol.TCompactProtocol)1 TProtocol (org.apache.thrift.protocol.TProtocol)1 THttpClient (org.apache.thrift.transport.THttpClient)1 ComponentService (org.eclipse.sw360.datahandler.thrift.components.ComponentService)1 Release (org.eclipse.sw360.datahandler.thrift.components.Release)1