private List<RouteInfo> getRouteInfoForDestinations( Map<String, Set<String>> from, Map<String, Set<String>> to, List<String> errors) { List<RouteInfo> routes = new ArrayList<RouteInfo>(); // loop through all destination states and find all hubs that belongs to // the catchment for (String destState : to.keySet()) { List<String> reqTo = new ArrayList<String>(), reqFrom = new ArrayList<String>(); for (String destCity : to.get(destState)) { reqTo.add(destCity + "," + destState); } if (from.get(destState) != null) { for (String hubName : from.get(destState)) { reqFrom.add(hubName + "," + destState); } } for (State hubState : catchment.getDestinations().get(State.valueOf(destState))) { if (from.get(hubState.name()) == null) continue; for (String hubName : from.get(hubState.name())) { reqFrom.add(hubName + "," + hubState); } } try { if (!reqFrom.isEmpty() & !reqTo.isEmpty()) routes.addAll(GoogleHandler.getRouteInfoList(reqFrom, reqTo, errors)); } catch (GoogleServiceParamException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (GoogleServiceException e) { // TODO Auto-generated catch block e.printStackTrace(); } } return routes; }
public void generateReport() { if (destinationsTA.isEmpty()) return; List<String> lines = Parser.getLines(destinationsTA); Map<String, Set<String>> existingRoutesByDestMap = new HashMap<String, Set<String>>(); Map<String, Set<String>> to = new HashMap<String, Set<String>>(); Map<String, Set<String>> from = new HashMap<String, Set<String>>(); Report report = new Report(); List<String> errors = new ArrayList<String>(); String destCity = "", destState = ""; State destStateEnm, hubStateEnm; for (String line : lines) { System.out.println(line); destCity = Parser.getCity(line); destState = Parser.getState(line); try { destStateEnm = State.valueOf(destState); } catch (IllegalArgumentException e) { continue; } for (String hubName : hubsRegistry.getHubsNames()) { String hubCity = Parser.getCity(hubName); String hubState = Parser.getState(hubName); try { hubStateEnm = State.valueOf(hubState); } catch (IllegalArgumentException e) { continue; } if (destStateEnm != hubStateEnm & !catchment.getDestinations().get(destStateEnm).contains(hubStateEnm)) continue; RouteId id = new RouteId(); id.setHubName(hubCity); id.setHubState(hubState); id.setDestName(destCity); id.setDestState(destState); RouteEntity route = repo.findRoute(id); System.out.println("Found route: " + route); // add to request if (route == null) { System.out.println("Adding to request"); if (to.containsKey(destState)) to.get(destState).add(destCity); else { Set<String> dCities = new HashSet<String>(); dCities.add(destCity); to.put(destState, dCities); } if (from.containsKey(hubState)) from.get(hubState).add(hubCity); else { Set<String> hCities = new HashSet<String>(); hCities.add(hubCity); from.put(hubState, hCities); } System.out.println("REquest : " + to + " / " + from); } // add to report else { // for(HubServiceEntity service : // hubsRegistry.getServicesForHub(hub.getShortName())){ try { report.add( route, hubsRegistry.getServicesForHub(hubName), hubsRegistry.getCoefficientsForHub(hubName)); if (existingRoutesByDestMap.containsKey(destCity + "," + destState)) existingRoutesByDestMap.get(destCity + "," + destState).add(hubName); else { Set<String> hubsList = new HashSet<String>(); hubsList.add(hubName); existingRoutesByDestMap.put(destCity + "," + destState, hubsList); } } catch (ReportEntryException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } } List<RouteInfo> routeInfoList = getRouteInfoForDestinations(from, to, errors); List<RouteEntity> savedRoutes = repo.saveRoutes(routeInfoList); for (RouteEntity route : savedRoutes) { try { report.add( route, hubsRegistry.getServicesForHub(route.getHubName() + "," + route.getHubState()), hubsRegistry.getCoefficientsForHub(route.getHubName() + "," + route.getHubState())); } catch (ReportEntryException e) { // TODO Auto-generated catch block e.printStackTrace(); } } System.out.println(routeInfoList); System.out.println(report); ReportRow row; for (Entry<String, ArrayList<ReportEntry>> next : report.entrySet()) { row = new ReportRow(); row.setDestInfo(next.getKey()); ArrayList<ReportEntry> list = next.getValue(); Collections.sort(list); row.setEntries(list); entries.add(row); } // } Messanger.show("Got rate ", report.size() + "/"); }