class EventHistoryRequestQueryConverter extends AbstractConverterAware<EventHistoryRequest, SolrQuery> {

  @Override
  public SolrQuery convert(EventHistoryRequest eventHistoryRequest) {
    SolrQuery eventHistoryQuery = new SolrQuery();
    eventHistoryQuery.setQuery("*:*");

    int startIndex = StringUtils.isNotEmpty(eventHistoryRequest.getStartIndex()) && StringUtils.isNumeric(eventHistoryRequest.getStartIndex())
      ? Integer.parseInt(eventHistoryRequest.getStartIndex()) : 0;
    int maxRows = StringUtils.isNotEmpty(eventHistoryRequest.getPageSize()) && StringUtils.isNumeric(eventHistoryRequest.getPageSize())
      ? Integer.parseInt(eventHistoryRequest.getPageSize()) : 10;

    SolrQuery.ORDER order = eventHistoryRequest.getSortType() != null && SolrQuery.ORDER.desc.equals(SolrQuery.ORDER.valueOf(eventHistoryRequest.getSortType()))
      ? SolrQuery.ORDER.desc : SolrQuery.ORDER.asc;
    String sortBy = StringUtils.isNotEmpty(eventHistoryRequest.getSortBy()) ? eventHistoryRequest.getSortBy() : FILTER_NAME;
    String filterName = StringUtils.isBlank(eventHistoryRequest.getFilterName()) ? "*" : "*" + eventHistoryRequest.getFilterName() + "*";

    eventHistoryQuery.addFilterQuery(String.format("%s:%s", ROW_TYPE, eventHistoryRequest.getRowType()));
    eventHistoryQuery.addFilterQuery(String.format("%s:%s", FILTER_NAME, SolrUtil.makeSearcableString(filterName)));
    eventHistoryQuery.setStart(startIndex);
    eventHistoryQuery.setRows(maxRows);

    SolrQuery.SortClause sortOrder = SolrQuery.SortClause.create(sortBy, order);
    List<SolrQuery.SortClause> sort = new ArrayList<>();
    sort.add(sortOrder);
    eventHistoryQuery.setSorts(sort);

    SolrUtil.addListFilterToSolrQuery(eventHistoryQuery, CLUSTER, eventHistoryRequest.getClusters());

    return eventHistoryQuery;
  }

}