search.put("leaving", (String)cache.get("leavingFrom"));
search.put("going", (String)cache.get("goingTo"));
search.put("time", new SimpleDateFormat("HH:mm").format((Date)cache.get("departure")));
search.put("date", new SimpleDateFormat("yyyy-MM-dd").format((Date)cache.get("departure")));
cache.clear();
JSONArray volHistoricList = new JSONArray();
volHistoricList.put(search);
for(Entity result : preparedHistoricQuery.asIterable())
{
JSONObject vol = new JSONObject();
vol.put("id", KeyFactory.keyToString(result.getKey()));
vol.put("departureDate", result.getProperty("departureDate"));
vol.put("departureTime", result.getProperty("departureTime"));
vol.put("arrivalDate", result.getProperty("arrivalDate"));
vol.put("arrivalTime", result.getProperty("arrivalTime"));
vol.put("duration", result.getProperty("duration"));
vol.put("price", result.getProperty("price"));
vol.put("availableSeats", result.getProperty("availableSeats"));
volHistoricList.put(vol);
}
response.getWriter().print(volHistoricList);
} catch (CacheException | NullPointerException e) {
response.getWriter().print("{\"message\":\"No Cache\"}");