private List<String> buildItineraryPlannerRequest(SingleJourney request) { List<String> reqs = new ArrayList<String>(); for (TType type : request.getTransportTypes()) { int its = 1; if (type.equals(TType.TRANSIT)) { its = 3; } String req = String.format( "from=%s,%s&to=%s,%s&date=%s&departureTime=%s&transportType=%s&routeType=%s&numOfItn=%s", request.getFrom().getLat(), request.getFrom().getLon(), request.getTo().getLat(), request.getTo().getLon(), request.getDate(), request.getDepartureTime(), type, request.getRouteType(), its); reqs.add(req); } return reqs; // String[] resp = new String[request.getTransportTypes().length]; // return reqs.toArray(resp); }
// no crud @RequestMapping(method = RequestMethod.POST, value = "/plansinglejourney") public @ResponseBody void planSingleJourney( HttpServletRequest request, HttpServletResponse response, HttpSession session, @RequestBody SingleJourney journeyRequest) throws InvocationException, AcServiceException { try { User user = getUser(request); String userId = getUserId(user); logger.info("-" + userId + "~AppConsume~plan"); if (userId == null) { response.setStatus(HttpServletResponse.SC_FORBIDDEN); return; } List<String> reqs = buildItineraryPlannerRequest(journeyRequest); ObjectMapper mapper = new ObjectMapper(); List<Itinerary> itineraries = new ArrayList<Itinerary>(); for (String req : reqs) { String plan = HTTPConnector.doGet( otpURL + SMARTPLANNER + PLAN, req, MediaType.APPLICATION_JSON, null, "UTF-8"); List its = mapper.readValue(plan, List.class); for (Object it : its) { Itinerary itinerary = mapper.convertValue(it, Itinerary.class); itineraries.add(itinerary); } } ItinerarySorter.sort(itineraries, journeyRequest.getRouteType()); response.setContentType("application/json; charset=utf-8"); String result = mapper.writeValueAsString(itineraries); ServletOutputStream sos = response.getOutputStream(); sos.write(result.getBytes()); } catch (ConnectorException e0) { response.setStatus(e0.getCode()); } catch (Exception e) { response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); } // return; }