@RequestMapping(value = "/list", method = RequestMethod.GET)
  public String list(Model model) {
    Collection<OrderDTO> orders = orderFacade.getAllOrders();
    List<CustomerDTO> customers = new ArrayList<CustomerDTO>();
    for (OrderDTO order : orders) {
      customers.add(order.getCustomer());
    }

    if (UserLogged.usernameLogged.equals("user")) {
      int i = 0;
      Iterator<OrderDTO> orderIterator = orders.iterator();
      for (Iterator<CustomerDTO> iterator = customers.iterator(); iterator.hasNext(); i++) {
        if (orderIterator.hasNext()) {
          OrderDTO order = orderIterator.next();
        }
        CustomerDTO customer = iterator.next();
        if (!customer.getEmail().equals("*****@*****.**")) {
          orderIterator.remove();
          iterator.remove();
        }
      }
    }

    model.addAttribute("orders", orders);
    model.addAttribute("customers", customers);
    return "order/list";
  }
  @RequestMapping(value = "/submit", method = RequestMethod.POST)
  public String index(
      @Valid @ModelAttribute("orderForm") OrderFormDTO orderForm,
      Model m,
      BindingResult result,
      RedirectAttributes redirectAttributes,
      UriComponentsBuilder uriBuilder) {

    List<Long> serviceIds = orderForm.getServiceIds();
    List<Long> tireIds = orderForm.getTireIds();
    OrderDTO order = new OrderDTO();

    for (Long tireId : tireIds) {
      OrderItemDTO tireItem = new OrderItemDTO();
      tireItem.setItem(tireFacade.getTireById(tireId));
      order.addOrderItem(tireItem);
    }

    for (Long serviceId : serviceIds) {
      OrderItemDTO serviceItem = new OrderItemDTO();
      serviceItem.setItem(serviceFacade.findServiceById(serviceId));
      order.addOrderItem(serviceItem);
    }

    String email = orderForm.getEmail();
    if (email != null) {
      CustomerDTO customer = new CustomerDTO();
      customer.setEmail(email);
      customerFacade.createCustomer(customer);
    }

    redirectAttributes.addFlashAttribute("alert_success", "Order was successfully submitted");
    return "redirect:" + uriBuilder.path("/").toUriString();
  }
  /**
   * Action to process submit order form
   *
   * @param orderForm
   * @param m
   * @param result
   * @param request
   * @param redirectAttributes
   * @return
   */
  @RequestMapping(value = "/submit", method = RequestMethod.POST)
  public String submitOrder(
      @Valid @ModelAttribute("orderForm") OrderFormDTO orderForm,
      Model m,
      BindingResult result,
      HttpServletRequest request,
      RedirectAttributes redirectAttributes,
      UriComponentsBuilder uriBuilder) {

    List<Long> serviceIds = orderForm.getServiceIds();
    List<Long> tireIds = orderForm.getTireIds();
    OrderDTO order = new OrderDTO();

    Collection<OrderItemDTO> orderItemCollection = new ArrayList<OrderItemDTO>();

    for (Long tireId : tireIds) {
      OrderItemDTO tireItem = new OrderItemDTO();
      tireItem.setItem(tireFacade.getTireById(tireId));
      orderItemCollection.add(tireItem);
    }

    for (Long serviceId : serviceIds) {
      OrderItemDTO serviceItem = new OrderItemDTO();
      serviceItem.setItem(serviceFacade.findServiceById(serviceId));
      orderItemCollection.add(serviceItem);
    }

    CustomerDTO customer = (CustomerDTO) request.getSession().getAttribute("auth");
    if (customer != null) {
      order.setCustomer(customer);
    }

    order.setOrderItems(orderItemCollection);

    try {
      orderFacade.createOrder(order);
    } catch (PneuFacadeException ex) {
      Logger.getLogger(OrderController.class.getName()).log(Level.SEVERE, ex.getMessage());
      redirectAttributes.addFlashAttribute(
          "alert_danger", "Error occured " + "while submitting the order. Please, try again.");
      return "redirect:/";
    }

    redirectAttributes.addFlashAttribute("alert_success", "Order was successfully submitted");
    return "redirect:/";
  }