@RequestMapping(value = "/api/route/{ownerId}", method = RequestMethod.POST) public @ResponseBody Route addRoute( @RequestBody Route route, @PathVariable String ownerId, HttpServletRequest request, HttpServletResponse response) throws Exception { if (!Utils.validateAPIRequest(request, dataSetSetup, storage)) { throw new UnauthorizedException("Unauthorized Exception: token not valid"); } route.setOwnerId(ownerId); route.setObjectId(Utils.getUUID()); storage.addRoute(route); if (logger.isInfoEnabled()) { logger.info(String.format("addRoute[%s]:%s", ownerId, route.getName())); } return route; }
@SuppressWarnings("unchecked") @RequestMapping(value = "/api/anchor/{ownerId}", method = RequestMethod.GET) public @ResponseBody List<Anchor> searchAnchor( @PathVariable String ownerId, HttpServletRequest request, HttpServletResponse response) throws Exception { if (!Utils.validateAPIRequest(request, dataSetSetup, storage)) { throw new UnauthorizedException("Unauthorized Exception: token not valid"); } List<Anchor> result = (List<Anchor>) storage.findData(Anchor.class, null, null, ownerId); if (logger.isInfoEnabled()) { logger.info(String.format("searchAnchor[%s]:%d", ownerId, result.size())); } return result; }
@SuppressWarnings("unchecked") @RequestMapping(value = "/api/route/{ownerId}/school/{schoolId}", method = RequestMethod.GET) public @ResponseBody List<Route> searchRoute( @PathVariable String ownerId, @PathVariable String schoolId, HttpServletRequest request, HttpServletResponse response) throws Exception { if (!Utils.validateAPIRequest(request, dataSetSetup, storage)) { throw new UnauthorizedException("Unauthorized Exception: token not valid"); } Criteria criteria = Criteria.where("schoolId").is(schoolId); String dateString = request.getParameter("date"); if (Utils.isNotEmpty(dateString)) { Date date = sdf.parse(dateString); criteria = criteria.andOperator(Criteria.where("from").lte(date), Criteria.where("to").gte(date)); } List<Route> result = (List<Route>) storage.findData(Route.class, criteria, null, ownerId); if (logger.isInfoEnabled()) { logger.info(String.format("searchRoute[%s]:%d", ownerId, result.size())); } return result; }
@RequestMapping(value = "/api/route/{ownerId}/{objectId}", method = RequestMethod.DELETE) public @ResponseBody String deleteRoute( @PathVariable String ownerId, @PathVariable String objectId, HttpServletRequest request, HttpServletResponse response) throws Exception { if (!Utils.validateAPIRequest(request, dataSetSetup, storage)) { throw new UnauthorizedException("Unauthorized Exception: token not valid"); } storage.removeRoute(ownerId, objectId); if (logger.isInfoEnabled()) { logger.info(String.format("deleteRoute[%s]:%s", ownerId, objectId)); } return "{\"status\":\"OK\"}"; }
@RequestMapping(value = "/api/route/{ownerId}/{routeId}", method = RequestMethod.GET) public @ResponseBody Route searchRouteById( @PathVariable String ownerId, @PathVariable String routeId, HttpServletRequest request, HttpServletResponse response) throws Exception { if (!Utils.validateAPIRequest(request, dataSetSetup, storage)) { throw new UnauthorizedException("Unauthorized Exception: token not valid"); } Criteria criteria = Criteria.where("objectId").is(routeId); Route result = storage.findOneData(Route.class, criteria, ownerId); if (logger.isInfoEnabled()) { logger.info(String.format("searchRouteById[%s]:%s", ownerId, routeId)); } return result; }
@RequestMapping(value = "/api/anchor/{ownerId}/{objectId}", method = RequestMethod.PUT) public @ResponseBody Anchor updateAnchor( @RequestBody Anchor anchor, @PathVariable String ownerId, @PathVariable String objectId, HttpServletRequest request, HttpServletResponse response) throws Exception { if (!Utils.validateAPIRequest(request, dataSetSetup, storage)) { throw new UnauthorizedException("Unauthorized Exception: token not valid"); } anchor.setOwnerId(ownerId); anchor.setObjectId(objectId); storage.updateAnchor(anchor); if (logger.isInfoEnabled()) { logger.info(String.format("updateAnchor[%s]:%s", ownerId, anchor.getName())); } return anchor; }
@ExceptionHandler(Exception.class) @ResponseStatus(value = HttpStatus.INTERNAL_SERVER_ERROR) @ResponseBody public Map<String, String> handleError(HttpServletRequest request, Exception exception) { return Utils.handleError(exception); }