/**
  * Requests a count of all data from car park load
  *
  * <p>Request example: GET http://localhost:8080/carparks/carParkLoadsCount/
  *
  * @return
  */
 @RequestMapping(value = "/carParkLoadsCount", method = RequestMethod.GET)
 public Long getAllCarParkLoadsCount() {
   LOGGER.info("Entering getAllCarParkLoadsCount()");
   final long allCarkParkLoadsCount = carParkLoadRep.count();
   LOGGER.infof("Leaving getAllCarParkLoadsCount(): %s", allCarkParkLoadsCount);
   return allCarkParkLoadsCount;
 }
 /**
  * Requests the latest (the closest before the "now") entry from the carparkload table for given
  * carpark id
  *
  * <p>Request example: GET http://localhost:8080/carparks/latestEntry/1
  *
  * @return
  */
 @RequestMapping(value = "/latestEntry/{idString}", method = RequestMethod.GET)
 public CarParkLoad getLatestEntry(@PathVariable final String idString) {
   LOGGER.infof("Entering getLatestEntry(%s)", idString);
   // TODO: add error handling when car park not found
   CarParkLoad latestEntry =
       carParkLoadRep.getLatestEntry(Long.valueOf(idString), createPageRequest(0, 1)).get(0);
   if (LOGGER.isTraceEnabled()) {
     LOGGER.tracef("Leaving getLatestEntry(): %s", latestEntry);
   } else {
     LOGGER.info("Leaving getLatestEntry()");
   }
   return latestEntry;
 }
 /**
  * Requests a list of all data from car park load
  *
  * <p>Request example: GET http://localhost:8080/carparks/carParkLoads/
  *
  * @return
  */
 @RequestMapping(value = "/carParkLoads", method = RequestMethod.GET)
 public Page<CarParkLoad> getAllCarParkLoads(
     @RequestParam(defaultValue = DEFAULT_PAGE) int page,
     @RequestParam(defaultValue = DEFAULT_SIZE) int size,
     @RequestParam(defaultValue = DEFAULT_SORT_ITEM) String sort,
     @RequestParam(defaultValue = DEFAULT_SORT_ORDER) String sortOrder) {
   LOGGER.info("Entering getAllCarParkLoads()");
   final Page<CarParkLoad> allCarkParkLoads =
       carParkLoadRep.findAll(createPageRequest(page, size, sort, sortOrder));
   if (LOGGER.isTraceEnabled()) {
     LOGGER.tracef("Leaving getAllCarParkLoads(): %s", allCarkParkLoads);
   } else {
     LOGGER.info("Leaving getAllCarParkLoads()");
   }
   return allCarkParkLoads;
 }
 /**
  * Requests a list of all data from given car park
  *
  * <p>Request example: GET http://localhost:8080/carparks/carParkLoads/renoma
  *
  * @return
  */
 @RequestMapping(value = "/carParkLoads/{name}", method = RequestMethod.GET)
 public Page<CarParkLoad> getCarParkLoad(
     @PathVariable final String name,
     @RequestParam(defaultValue = DEFAULT_PAGE) int page,
     @RequestParam(defaultValue = DEFAULT_SIZE) int size,
     @RequestParam(defaultValue = DEFAULT_SORT_ITEM) String sort,
     @RequestParam(defaultValue = DEFAULT_SORT_ORDER) String sortOrder) {
   LOGGER.infof("Entering getCarParkLoad(%s)", name);
   final CarPark carPark = carParkRep.findByName(name);
   final Page<CarParkLoad> carkParkLoad =
       carParkLoadRep.findByCarPark(carPark, createPageRequest(page, size, sort, sortOrder));
   if (LOGGER.isTraceEnabled()) {
     LOGGER.tracef("Leaving getCarParkLoad(): %s", carkParkLoad);
   } else {
     LOGGER.info("Leaving getCarParkLoad()");
   }
   return carkParkLoad;
 }
 /**
  * Requests the latest (the closest before the "now") entries for all carparks from the
  * carparkload table
  *
  * <p>Request example: GET http://localhost:8080/carparks/latestEntries
  *
  * @return
  */
 @RequestMapping(value = "/latestEntries", method = RequestMethod.GET)
 public List<CarParkLoad> getLatestEntries() {
   LOGGER.infof("Entering getLatestEntries()");
   List<CarParkLoad> latestEntries = new LinkedList<CarParkLoad>();
   Iterable<CarPark> carParks = carParkRep.findAll();
   for (CarPark carPark : carParks) {
     final CarParkLoad carParkLoad =
         carParkLoadRep.getLatestEntry(carPark.getCarParkid(), createPageRequest(0, 1)).get(0);
     if (carParkLoad.getTimestamp().getTime() > System.currentTimeMillis() - MILIS_IN_DAY) {
       latestEntries.add(carParkLoad);
     }
   }
   if (LOGGER.isTraceEnabled()) {
     LOGGER.tracef("Leaving getLatestEntries(): %s", latestEntries);
   } else {
     LOGGER.info("Leaving getLatestEntries()");
   }
   return latestEntries;
 }