Exemplo n.º 1
0
 private QueryCommand createQuery(FtsQueryFormBean queryFormBean) {
   QueryCommand query = null;
   OriginalRequest request = new OriginalRequest();
   long logged_time = Calendar.getInstance().getTimeInMillis();
   request.setId("r" + logged_time);
   request.setLoggedTime(logged_time);
   request.setOriginAddress(getOriginAddr(queryFormBean));
   request.setDestnAddress(getDestnAddr(queryFormBean));
   if (queryFormBean.getTime_constraint().equals("depart_at")) {
     request.setDepartureTime(getTime(queryFormBean));
   } else { // arrive_by
     request.setArriveTime(getTime(queryFormBean));
   }
   request.setAgeGroup(getAgeGroup(queryFormBean));
   request.setMobilityStatus(getMobilityStatus(queryFormBean));
   request.setPurpose(getJourneyPurpose(queryFormBean));
   String[] preference = new String[NUM_OF_PREFERED_OPTION];
   PreferedOption[] preference_enum = parsePreferedOptions(queryFormBean);
   for (int i = 0; i < NUM_OF_PREFERED_OPTION; i++) {
     preference[i] = PreferedOption.toString(preference_enum[i]);
     System.out.println(preference[i]);
   }
   request.setPreference(preference);
   query = new QueryCommand(fits_webservice_broker, request);
   return query;
 }
Exemplo n.º 2
0
  public PreferedOption[] parsePreferedOptions(FtsQueryFormBean queryFormBean) {

    String s = queryFormBean.getPrefered_options();
    PreferedOption[] preference = new PreferedOption[NUM_OF_PREFERED_OPTION];
    s = s.replaceAll("ranking\\[\\]=", "");
    StringTokenizer st = new StringTokenizer(s.trim(), "&");
    int value = -1;
    for (int i = 0; i < NUM_OF_PREFERED_OPTION; i++) {
      value = new Integer(st.nextToken().trim());
      preference[i] = PreferedOption.valueOf(value);
    }
    return preference;
  }
Exemplo n.º 3
0
 private PassengerMobilityStatus getMobilityStatus(FtsQueryFormBean queryFormBean) {
   String value = queryFormBean.getMobility_status();
   if (value.equals("Able bodied")) {
     return PassengerMobilityStatus.valueOf(0);
   } else if (value.equals("Disabled - wheelchair user")) {
     return PassengerMobilityStatus.valueOf(1);
   } else if (value.equals("Disabled - other")) {
     return PassengerMobilityStatus.valueOf(2);
   } else if (value.equals("Mobility impaired - unable to use regular PT")) {
     return PassengerMobilityStatus.valueOf(3);
   }
   return null;
 }
Exemplo n.º 4
0
  private int getMin(FtsQueryFormBean queryFormBean) {

    String time = queryFormBean.getTimepicker();
    StringTokenizer st = null;
    if (time.endsWith("pm")) {
      st = new StringTokenizer(time.replaceFirst("pm", ""), ":");
      st.nextToken();
      return new Integer(st.nextToken());
    } else {
      st = new StringTokenizer(time.replaceFirst("am", ""), ":");
      st.nextToken();
      return new Integer(st.nextToken());
    }
  }
Exemplo n.º 5
0
 private PassengerAge getAgeGroup(FtsQueryFormBean queryFormBean) {
   String value = queryFormBean.getAge_group();
   if (value.equals("under 16")) {
     return PassengerAge.valueOf(0);
   } else if (value.equals("16 to 21")) {
     return PassengerAge.valueOf(1);
   } else if (value.equals("22 to 54")) {
     return PassengerAge.valueOf(2);
   } else if (value.equals("55 to 59")) {
     return PassengerAge.valueOf(3);
   } else if (value.equals("60 and above")) {
     return PassengerAge.valueOf(4);
   }
   return null;
 }
Exemplo n.º 6
0
  private String getDestnAddr(FtsQueryFormBean queryFormBean) {

    StringBuilder sb = new StringBuilder();
    if (queryFormBean.getStreet_number_t() != null) {
      sb.append(queryFormBean.getStreet_number_t());
      sb.append("+");
    }
    if (queryFormBean.getRoute_t() != null) {
      sb.append(queryFormBean.getRoute_t());
      sb.append("+");
    }
    if (queryFormBean.getPostal_code_t() != null) {
      sb.append(queryFormBean.getPostal_code_t());
      sb.append("+");
    }
    if (queryFormBean.getLocality_t() != null) {
      sb.append(queryFormBean.getLocality_t());
      sb.append("+");
    }
    if (queryFormBean.getCountry_t() != null) {
      sb.append(queryFormBean.getCountry_t());
    }
    return sb.toString().replaceAll(",", "%2C").replaceAll(" ", "+");
  }
Exemplo n.º 7
0
 private PassengerJourneyPurpose getJourneyPurpose(FtsQueryFormBean queryFormBean) {
   String value = queryFormBean.getJourney_purpose();
   if (value.equals("Health Appointment")) {
     return PassengerJourneyPurpose.valueOf(0);
   } else if (value.equals("Shopping")) {
     return PassengerJourneyPurpose.valueOf(1);
   } else if (value.equals("Social/Leisure")) {
     return PassengerJourneyPurpose.valueOf(2);
   } else if (value.equals("School/Education")) {
     return PassengerJourneyPurpose.valueOf(3);
   } else if (value.equals("Work/Commuting")) {
     return PassengerJourneyPurpose.valueOf(3);
   } else if (value.equals("Other")) {
     return PassengerJourneyPurpose.valueOf(3);
   }
   return null;
 }
Exemplo n.º 8
0
  private int getHour(FtsQueryFormBean queryFormBean) {

    String time = queryFormBean.getTimepicker();
    StringTokenizer st = null;
    String nextToken = null;
    if (time.endsWith("pm")) {
      st = new StringTokenizer(time.replaceFirst("pm", ""), ":");
      nextToken = st.nextToken();
      if (nextToken.equals("12")) {
        return new Integer(nextToken);
      } else {
        return 12 + new Integer(nextToken);
      }
    } else {
      st = new StringTokenizer(time.replaceFirst("am", ""), ":");
      return new Integer(st.nextToken());
    }
  }
Exemplo n.º 9
0
  private Calendar getTime(FtsQueryFormBean queryFormBean) {

    Calendar c = Calendar.getInstance();
    String year, month, day;
    StringTokenizer st = new StringTokenizer(queryFormBean.getDatepicker(), "/");
    month = st.nextToken();
    day = st.nextToken();
    year = st.nextToken();
    c.set(Calendar.YEAR, new Integer(year));
    c.set(Calendar.MONTH, new Integer(month) - 1);
    c.set(Calendar.DAY_OF_MONTH, new Integer(day));
    c.set(Calendar.HOUR_OF_DAY, getHour(queryFormBean));
    c.set(Calendar.MINUTE, getMin(queryFormBean));
    c.set(Calendar.SECOND, 0);
    c.set(Calendar.MILLISECOND, 0);
    System.out.println("retrieve calendar " + c.getTime().toGMTString());
    return c;
  }
Exemplo n.º 10
0
 @RequestMapping(method = RequestMethod.POST)
 public String processSubmit(
     @Valid FtsQueryFormBean queryFormBean,
     BindingResult result,
     @ModelAttribute("ajaxRequest") boolean ajaxRequest,
     Model model,
     RedirectAttributes redirectAttrs) {
   /* validate the query form*/
   if (result.hasErrors()) {
     System.err.println(result.getFieldError());
     return "query-fts";
   }
   // Typically you would save to a db and clear the "form" attribute from the session
   // via SessionStatus.setCompleted(). For the demo we leave it in the session.
   //		String message = "Form submitted successfully.  Bound " + queryFormBean;
   QueryCommand query = createQuery(queryFormBean);
   List<TOption> options = fits_webservice_broker.query(query);
   Calendar travel_of_day = null;
   if (query.getOriginalRequest().getDepartureTime() != null) {
     travel_of_day = query.getOriginalRequest().getDepartureTime();
   } else {
     travel_of_day = query.getOriginalRequest().getArriveTime();
   }
   model.addAttribute("caption", "Transport options ranked using preferences");
   DateFormat df = new SimpleDateFormat("MMM dd, yyyy");
   String formattedDate = df.format(travel_of_day.getTime());
   model.addAttribute("date_of_travel", formattedDate);
   model.addAttribute("origin_postcode", queryFormBean.getPostal_code_f());
   List<TOption> relaxed_options = new ArrayList<TOption>();
   List<TOption> not_relaxed = new ArrayList<TOption>();
   for (TOption option : options) {
     if (option.isRelaxed()) {
       relaxed_options.add(option);
       continue;
     }
     not_relaxed.add(option);
   }
   model.addAttribute("options", not_relaxed);
   System.out.println("relaxed option size " + relaxed_options.size());
   model.addAttribute("relaxed_options", relaxed_options);
   System.out.println("query count:" + count);
   count++;
   return "matching";
 }