Ejemplo n.º 1
0
  public void doSubmitEvent() {
    System.out.println("In submit event");
    events.clear();
    CallSeatwaveService service = new CallSeatwaveService();
    Event[] eventList = null;
    try {
      // formato date: yyyy-MM-dd
      eventList =
          service.call(
              what,
              where,
              sdfDashReverse.format(whenFrom),
              sdfDashReverse.format(whenTo),
              eventWithoutTix);
    } catch (RemoteException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
    if (eventList != null) {
      // fare un oggetto per l'output: il popolamento degli oggetti per il display andrà fatto nella
      // logica poi, non qui
      // o forse usare già i bean jaxb, ma se cambiano la specifica poi siamo fregati, forse è
      // meglio un mapping nostro
      int limit = 0;
      for (Event e : eventList) {
        if (limit > 5) break;
        EventDisplayBean ev = new EventDisplayBean();
        ev.setEventId("" + e.getId());
        SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
        ev.setDate(sdf.format(e.getDate().getTime()));
        SimpleDateFormat sdf2 = new SimpleDateFormat("HH:mm");
        ev.setTime(sdf2.format(e.getDate().getTime()));
        ev.setWhat(e.getEventGroupName());
        ev.setWhere(e.getVenueName());
        ev.setTown(e.getTown());
        ev.setCountry(e.getCountry());
        ev.setTicketCount("" + e.getTicketCount());
        ev.setMinPrice(e.getMinPrice().toString());
        ev.setCurrency(e.getCurrency());
        ev.setUrl(e.getSwURL());
        ev.setImageUrl(e.getEventGroupImageURL());

        events.add(ev);
        limit++;
      }
    }
    firstPageVisit = false;
  }
Ejemplo n.º 2
0
  public void doSubmitAllInOne() {
    System.out.println("In submit all-in-one");

    try {
      boolean proceed =
          true; // se lo valuto, posso stoppare la ricerca successiva in caso non ci sia un volo o
                // un hotel per il periodo
      flights.clear();
      flights2.clear();
      flights3.clear();
      hotels.clear();
      events.clear();
      // get cambio valuta
      CallCurrencyService currencySrv = new CallCurrencyService();
      Double cambio = new Double(1);
      try {
        cambio = currencySrv.call();
      } catch (RemoteException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
      }
      CallCleartripService service = new CallCleartripService();
      // codifico i parametri:
      String fromCode = "", fromCode2 = "", fromCode3 = "", toCode = "";
      System.out.println("DECODED: " + from);
      fromCode = AirCodeUtils.airportToCode.get(from);
      if (from2 != null && !from2.equals("")) fromCode2 = AirCodeUtils.airportToCode.get(from2);
      if (from3 != null && !from3.equals("")) fromCode3 = AirCodeUtils.airportToCode.get(from3);
      toCode = AirCodeUtils.airportToCode.get(to);
      System.out.println("CODED: " + fromCode);
      //			try{
      //				flights = service.call(fromCode, toCode, flightDepDate, flightReturnDate, numberPeople,
      // cabinType, cambio, 3);
      //			}catch(SAXParseException e){
      //				e.printStackTrace();
      //				//non trovati voli
      //				proceed = false;
      //			}

      // gestione con thread, pessima
      FlightDataContainer fdt = FlightDataContainer.getInstance();
      fdt.setTo(toCode);
      fdt.setDepartureDate(sdfDashReverse.format(flightDepDate));
      fdt.setReturnDate(sdfDashReverse.format(flightReturnDate));
      fdt.setCabinType(cabinType);
      fdt.setCambio(cambio);
      fdt.setLimitResults(3);
      FlightThread ft1 = new FlightThread();
      FlightThread ft2 = new FlightThread();
      FlightThread ft3 = new FlightThread();
      Thread t1 = new Thread(ft1);
      Thread t2 = new Thread(ft2);
      Thread t3 = new Thread(ft3);
      fdt.lockSemaphore(); // qui è per forza libero
      fdt.setFrom(
          fromCode); // FIXME: controllare che non si sovrascrivano la variabie mentre la usano:
                     // SEMAFORO?
      fdt.setNumAdults(numberPeople);
      t1.start();
      if (from2 != null && !from2.equals("")) {
        while (!fdt.lockSemaphore()) {
          // aspetto
        }
        fdt.setFrom(fromCode2);
        fdt.setNumAdults(numberPeople2);
        t2.start();
      }
      if (from3 != null && !from3.equals("")) {
        while (!fdt.lockSemaphore()) {
          // aspetto
        }
        fdt.setFrom(fromCode3);
        fdt.setNumAdults(numberPeople3);
        t3.start();
      }

      try {
        t1.join();
        if (from2 != null && !from2.equals("")) t2.join();
        if (from3 != null && !from3.equals("")) t3.join();
      } catch (InterruptedException e) {
        e.printStackTrace();
      }
      HashMap<String, FlightDisplayBeanList> resList = fdt.getAllFlights();
      if (resList.get(fromCode) != null) flights = resList.get(fromCode).getFlightList();
      if (from2 != null && !from2.equals("") && resList.get(fromCode2) != null)
        flights2 = resList.get(fromCode2).getFlightList();
      if (from3 != null && !from3.equals("") && resList.get(fromCode3) != null)
        flights3 = resList.get(fromCode3).getFlightList();

      // hotels
      String destination = to.substring(0, to.indexOf("[") - 1);
      if (destination.indexOf("-") != -1)
        destination = destination.substring(0, destination.indexOf("-") - 1);
      System.out.println("Hotel destination: " + destination);
      String hotelArrivalDate = "", hotelDepartureDate = "";
      /*Gestione inutile, ora uso simpledateformat
      String[] tmpFlightDepDate, tmpFlightRetDate;
      tmpFlightDepDate = flightDepDate.split("-");
      tmpFlightRetDate = flightReturnDate.split("-");
      hotelArrivalDate = tmpFlightDepDate[1]+"/"+tmpFlightDepDate[2]+"/"+tmpFlightDepDate[0];
      hotelDepartureDate = tmpFlightRetDate[1]+"/"+tmpFlightRetDate[2]+"/"+tmpFlightRetDate[0];
      */
      hotelArrivalDate = sdfAmerican.format(flightDepDate);
      hotelDepartureDate = sdfAmerican.format(flightReturnDate);

      Integer totalPeople =
          Integer.parseInt(numberPeople)
              + (from2 != null && !from2.equals("") ? Integer.parseInt(numberPeople2) : 0)
              + (from3 != null && !from3.equals("") ? Integer.parseInt(numberPeople3) : 0);
      System.out.println("Total people toString: " + totalPeople.toString());
      CallExpediaService hotelService = new CallExpediaService();
      HotelList hotelList = null;
      try {
        hotelList =
            hotelService.callGeneral(
                destination,
                hotelDepartureDate,
                hotelArrivalDate,
                totalPeople); // departure e arival date invertite risp al volo: la departure del
                              // volo è l'andata, la departure dall'hotel è il ritorno
      } catch (RemoteException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
      if (hotelList != null) {
        // fare un oggetto per l'output: il popolamento degli oggetti per il display andrà fatto
        // nella logica poi, non qui
        // o forse usare già i bean jaxb, ma se cambiano la specifica poi siamo fregati, forse è
        // meglio un mapping nostro
        int limit = 0;
        for (HotelSummary h : hotelList.getHotelSummary()) {
          if (limit > 3) break;
          HotelDisplayBean hotel = new HotelDisplayBean();
          hotel.setHotelId("" + h.getHotelId());
          hotel.setName(h.getName());
          hotel.setAddress(h.getAddress1());
          hotel.setCity(h.getCity());
          hotel.setCountry(h.getCountryCode());
          hotel.setPostalCode(h.getPostalCode());
          hotel.setHotelRating("" + h.getHotelRating());
          hotel.setLocationDescription(h.getLocationDescription());
          hotel.setShortDescription(
              h.getShortDescription()
                  .replaceAll("&lt;p&gt;&lt;b&gt;", "")
                  .replaceAll("&lt;/b&gt; &lt;br /&gt;", ""));
          hotel.setImageUrl("http://images.travelnow.com" + h.getThumbNailUrl());
          hotel.setUrl(h.getDeepLink());

          // MODIFICA: chiamo anche la getAvailability per ottenere più stanze
          HashMap<Integer, Integer> roomAssoc = new HashMap<Integer, Integer>();
          if (totalPeople > 4) {
            int numRoom = totalPeople / 4 + (totalPeople % 4 == 0 ? 0 : 1);
            for (int i = 0; i < numRoom; i++) {
              int numPerRoom = i == numRoom - 1 ? totalPeople % 4 : 4;
              if (totalPeople % 4 == 1 && i == numRoom - 2)
                numPerRoom -= 1; // tolgo uno dalla penultima stanza
              if (totalPeople % 4 == 1 && i == numRoom - 1)
                numPerRoom += 1; // e lo metto nell'ultima, così non lascio nessuno da solo
              roomAssoc.put(i, numPerRoom);
            }

          } else {
            roomAssoc.put(0, totalPeople);
          }
          HotelRoomAvailabilityResponse roomHotelList = null;
          try {
            roomHotelList =
                hotelService.callGetAvailability(
                    h.getHotelId(), hotelDepartureDate, hotelArrivalDate, roomAssoc);
          } catch (RemoteException e) {
            e.printStackTrace();
          }

          List<Room> rooms = new ArrayList<Room>();

          if (roomHotelList != null) {
            for (HotelRoomResponse r : roomHotelList.getHotelRoomResponse()) {
              Room room = new Room();
              room.setRoomDescription(r.getRoomTypeDescription());
              room.setMaxOccupants("" + r.getRateOccupancyPerRoom());
              room.setTotalCharge(
                  new BigDecimal(r.getRateInfo().getChargeableRateInfo().getTotal()));
              room.setRemainingRooms("" + r.getCurrentAllotment());
              room.setUrl(r.getDeepLink());
              List<String> valueAdds = new ArrayList<String>();
              if (r.getValueAdds() != null) {
                for (ValueAdd v : r.getValueAdds().getValueAdd()) {
                  valueAdds.add(v.getDescription());
                }
              }
              room.setValueAdds(valueAdds);

              rooms.add(room);
            }
          } else {
            for (RoomRateDetails r : h.getRoomRateDetailsList().getRoomRateDetails()) {
              Room room = new Room();
              room.setRoomDescription(r.getRoomDescription());
              room.setMaxOccupants("" + r.getMaxRoomOccupancy());
              room.setTotalCharge(
                  new BigDecimal(r.getRateInfo().getChargeableRateInfo().getTotal()));
              room.setRemainingRooms("" + r.getCurrentAllotment());
              //							room.setUrl("");
              List<String> valueAdds = new ArrayList<String>();
              if (r.getValueAdds() != null) {
                for (ValueAdd v : r.getValueAdds().getValueAdd()) {
                  valueAdds.add(v.getDescription());
                }
              }
              room.setValueAdds(valueAdds);

              rooms.add(room);
            }
          }

          hotel.setRooms(rooms);
          hotels.add(hotel);
          limit++;
        }
      }

      // events
      System.out.println("Finding events.....");
      CallSeatwaveService eventService = new CallSeatwaveService();
      Event[] eventList = null;
      try {
        eventList =
            eventService.call(
                what,
                destination,
                sdfDashReverse.format(flightDepDate),
                sdfDashReverse.format(flightReturnDate),
                eventWithoutTix);
      } catch (RemoteException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
      if (eventList != null) {
        // fare un oggetto per l'output: il popolamento degli oggetti per il display andrà fatto
        // nella logica poi, non qui
        // o forse usare già i bean jaxb, ma se cambiano la specifica poi siamo fregati, forse è
        // meglio un mapping nostro
        int limit = 0;
        for (Event e : eventList) {
          if (limit > 3) break;
          EventDisplayBean ev = new EventDisplayBean();
          ev.setEventId("" + e.getId());
          SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
          ev.setDate(sdf.format(e.getDate().getTime()));
          SimpleDateFormat sdf2 = new SimpleDateFormat("HH:mm");
          ev.setTime(sdf2.format(e.getDate().getTime()));
          ev.setWhat(e.getEventGroupName());
          ev.setWhere(e.getVenueName());
          ev.setTown(e.getTown());
          ev.setCountry(e.getCountry());
          ev.setTicketCount("" + e.getTicketCount());
          ev.setMinPrice(e.getMinPrice().toString());
          ev.setCurrency(e.getCurrency());
          ev.setUrl(e.getSwURL());
          ev.setImageUrl(e.getEventGroupImageURL());

          events.add(ev);
          limit++;
        }
      }

      firstPageVisit = false;
      System.out.println("FIRST_PAGE_END visit?: " + firstPageVisit);
    } catch (Exception e) {
      System.out.println("GENERIC ERROR: " + e.getMessage());
      e.printStackTrace();
    }
  }