@GET
  // @Path("salesMetrics.xhtml")
  public void getProductByID() {
    HttpServletRequest hsr =
        (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest();
    String pid = hsr.getQueryString();
    pid = pid.replace("[", "");
    pid = pid.replace("]", "");
    pid = pid.replace("sort=", "");

    if (Integer.parseInt(pid) == 1) {
      initialiseData();
      results = totalSalesMetricsManager.findAll();
      for (int i = 0; i < results.size() - 1; i++) {
        for (int j = 0; j < results.size() - 1; j++) {
          if (results.get(j).getProductID() > results.get(j + 1).getProductID()) {
            swap = results.get(j);
            results.set(j, results.get(j + 1));
            results.set(j + 1, swap);
          }
        }
      }
    }
    if (Integer.parseInt(pid) == 0) {
      initialiseData();
    }
    if (Integer.parseInt(pid) == 2) {
      initialiseData();
      results = totalSalesMetricsManager.findAll();
      for (int i = 0; i < results.size() - 1; i++) {
        for (int j = 0; j < results.size() - 1; j++) {
          if (results.get(j).getProductPrice() < results.get(j + 1).getProductPrice()) {
            swap = results.get(j);
            results.set(j, results.get(j + 1));
            results.set(j + 1, swap);
          }
        }
      }
    }
    if (Integer.parseInt(pid) == 3) {
      initialiseData();
      results = totalSalesMetricsManager.findAll();
      for (int i = 0; i < results.size() - 1; i++) {
        for (int j = 0; j < results.size() - 1; j++) {
          if (results.get(j).getTotalSold() < results.get(j + 1).getTotalSold()) {
            swap = results.get(j);
            results.set(j, results.get(j + 1));
            results.set(j + 1, swap);
          }
        }
      }
    }
  }
 public void initialiseData() {
   for (SalesMetricsValue smv : salesMetricsManager.findAll()) {
     itemExists = totalSalesMetricsManager.checkExists(smv.getProductID());
     if (itemExists) {
       totalSalesMetricsManager.addNewSale(smv.getProductID(), smv.getTotalAmountSold());
     } else {
       totalSalesMetricsManager.persistTotalSalesMetricsValue(
           new TotalSalesMetric(
               smv.getProductID(),
               smv.getTotalAmountSold(),
               smv.getProductName(),
               smv.getProductPrice(),
               1));
     }
     itemExists = false;
   }
 }
 public String search() {
   initialiseData();
   results = totalSalesMetricsManager.findAll();
   return "salesMetrics";
 }