Exemplo n.º 1
0
  public static void show(Long id) {
    notFoundIfNull(id);
    Order order = Order.findById(id);
    notFoundIfNull(order);

    if (order.orderStatus == OrderStatus.NEW) {
      renderArgs.put("rootReportTypes", ReportType.find("rootReportType=true").fetch());
    }
    render(order);
  }
Exemplo n.º 2
0
  public static void index(String filter, int page, String orderBy, String order, String search) {
    if (page < 1) {
      page = 1;
    }

    BoolQueryBuilder qb = QueryBuilders.boolQuery();
    if (Strings.isNullOrEmpty(search)) {
      qb.must(QueryBuilders.matchAllQuery());
    } else {
      for (String searchPart : search.split("\\s+")) {
        qb.must(QueryBuilders.queryString(String.format("*%s*", searchPart)).defaultField("_all"));
      }
    }

    boolean filterApplied = false;
    for (ReportType reportType : ReportType.<ReportType>findAll()) {
      if (reportType.name.equals(filter)) {
        qb.must(QueryBuilders.fieldQuery("currentReport.reportType.id", reportType.id));
        qb.must(QueryBuilders.fieldQuery("orderStatus", OrderStatus.IN_PROGRESS.toString()));
        filterApplied = true;
      }
    }

    if (filter != null) {
      try {
        OrderStatus orderStatus = OrderStatus.valueOf(filter);
        qb.must(QueryBuilders.fieldQuery("orderStatus", orderStatus.toString()));
        filterApplied = true;
      } catch (IllegalArgumentException e) {
        // do nothing
      }
    }

    if (!filterApplied) {
      // exclude all deleted orders
      qb.mustNot(QueryBuilders.fieldQuery("orderStatus", OrderStatus.DELETED.toString()));
    }

    Query<Order> query = ElasticSearch.query(qb, Order.class);

    query.from((page - 1) * getPageSize()).size(getPageSize());

    if (!Strings.isNullOrEmpty(orderBy)) {
      SortOrder sortOrder = SortOrder.ASC;
      if (!Strings.isNullOrEmpty(order)) {
        if (order.toLowerCase().equals("desc")) {
          sortOrder = SortOrder.DESC;
        }
      }

      query.addSort(orderBy, sortOrder);
    }

    List<Order> orders;
    Long count;

    try {
      SearchResults<Order> results = query.fetch();
      orders = results.objects;
      count = results.totalCount;
    } catch (SearchPhaseExecutionException e) {
      Logger.warn(String.format("Error in search query: %s", search), e);
      flash.now("warning", Messages.get("errorInSearchQuery"));

      orders = new ArrayList<Order>();
      count = 0l;
    }

    List<String> reportTypes = new ArrayList<String>();
    for (ReportType reportType : ReportType.<ReportType>findAll()) {
      reportTypes.add(reportType.name);
    }

    renderArgs.put("pageSize", getPageSize());
    render(orders, count, reportTypes, filter);
  }