@Override
 public String processGetFindAll() throws DaoException {
   List<Ticket> tickets = ticketService.listAll();
   Gson gson = new Gson();
   String jsonMovie = gson.toJson(tickets); // returns empty string if movie == null
   return jsonMovie;
 }
 @Override
 public String processGetFindOne(Integer id) throws DaoException {
   Ticket ticket = ticketService.find(id);
   Gson gson = new Gson();
   String jsonMovie = gson.toJson(ticket); // returns empty string if ticket == null
   return jsonMovie;
 }
  @Override
  public String processPostCreate(Map<String, Object> requestParams) {
    Integer idExhibition = Integer.parseInt((String) requestParams.get("id_exhibition"));
    String chairNum = (String) requestParams.get("chair_num");
    String email = (String) requestParams.get("email");
    String password = (String) requestParams.get("password");
    String strPurchaseLocation = (String) requestParams.get("purchase_location");

    PurchaseLocation purchaseLocation;
    if (strPurchaseLocation.equals("local")) {
      purchaseLocation = PurchaseLocation.LOCAL;
    } else if (strPurchaseLocation.equals("internet")) {
      purchaseLocation = PurchaseLocation.INTERNET;
    } else {
      LOGGER.warn("Invalid purchase location value '" + strPurchaseLocation + "'");
      return createErrorJSONResponse(
          "Invalid purchase location value '" + strPurchaseLocation + "'");
    }

    String strSendMail = (String) requestParams.get("send_mail");
    boolean sendMail = false;
    if (strSendMail != null
        && strSendMail.equals("true")
        && purchaseLocation == PurchaseLocation.INTERNET) {
      sendMail = true;
    }

    try {
      User user = new User();
      user.setEmail(email);
      user.setPassword(password);

      User foundUser = userService.checkLogin(user);
      if (foundUser != null) {
        Exhibition exhibition = exhibitionService.find(idExhibition);

        Ticket ticket = new Ticket(exhibition, chairNum, foundUser, purchaseLocation, new Date());
        ticketService.create(ticket);

        String objectJSON = new Gson().toJson(ticket);
        JsonObject responseJson = new JsonObject();
        responseJson.addProperty("success", true);
        responseJson.addProperty("ticket", objectJSON);
        return responseJson.toString();
      } else {
        LOGGER.warn("Invalid authentication info");
        return createErrorJSONResponse("Invalid authentication info");
      }
    } catch (ServiceException e) {
      LOGGER.warn(e.getMessage());
      return createErrorJSONResponse(e.getMessage());
    } catch (DaoException e) {
      LOGGER.error(e.getMessage(), e);
      return createErrorJSONResponse(e.getMessage());
    } catch (InterruptedException e) {
      LOGGER.error("Error on saving changes on database", e);
      return createErrorJSONResponse("Error on saving changes on database");
    }
  }
  @Override
  public String processGetOther(
      HttpExchange httpExchange, List<String> urlParams, Map<String, Object> requestParams) {
    String operation = (String) requestParams.get("operation");
    if (operation.equals(RETRIEVE_TOKEN)) {
      String token = (String) requestParams.get("token");
      Ticket ticket = ticketService.getByToken(token);

      Gson gson = new Gson();
      String jsonTicket = gson.toJson(ticket);
      return jsonTicket;
    }

    return "";
  }
  @Override
  public String processPostDelete(Map<String, Object> requestParams) {
    String token = (String) requestParams.get("token");
    User user = new User();
    try {
      user.setEmail((String) requestParams.get("email"));
      user.setPassword((String) requestParams.get("password"));
      ticketService.delete(token, user);

      JsonObject responseJson = new JsonObject();
      responseJson.addProperty("success", true);
      responseJson.addProperty("token", token);
      return responseJson.toString();
    } catch (ServiceException e) {
      LOGGER.warn(e.getMessage());
      return createErrorJSONResponse(e.getMessage());
    } catch (DaoException e) {
      LOGGER.error(e.getMessage(), e);
      return createErrorJSONResponse(e.getMessage());
    }
  }
 public TicketServiceExecutor() {
   ticketService = TicketService.getInstance();
   userService = UserService.getInstance();
   exhibitionService = ExhibitionService.getInstance();
 }