@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 processPostUpdate(Map<String, Object> requestParams) { int id = Integer.parseInt((String) requestParams.get("id")); 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"); // TODO To remove // System.out.println(String.format("%d - %s:%s", id, email, password)); 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 foundTicket = ticketService.find(id); Ticket ticket = new Ticket(id, exhibition, chairNum, foundUser, purchaseLocation, new Date()); ticket.setToken(foundTicket.getToken()); ticketService.update(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"); } }