Exemple #1
0
  public Driver searchDriver(Ride ride) throws SQLException {

    DispatchDAO dispatchDAO = new DispatchDAO();
    ArrayList<Driver> freeDrivers = new ArrayList<Driver>();
    Driver driver = null;

    // select driver whoose availability status is free and driver type is
    // taxi

    freeDrivers = dispatchDAO.getFreeDrivers(ride.getRidetype());
    if (freeDrivers.size() != 0) {
      driver = freeDrivers.get(0);

      // update or insert into dispatch table
      String member_emailId = dispatchDAO.getCustomerByEmail(ride.getRequestid());
      if (driver != null && member_emailId != null) {
        int status =
            dispatchDAO.insertDispatch(
                ride.getRideid(), driver.getMemberid(), driver.getVehicleId(), member_emailId);
        if (status != 0) {
          // notify customer and driver
          System.out.println(
              "Customer-Notification:-----Your ride will reach you at  " + ride.getPickuptime());
          System.out.println(
              "Driver-Notification:-----Your ride is waiting at "
                  + ride.getPickuplocation()
                  + " with Customer email: "
                  + member_emailId);
        }
        // update vehicle and driver status
        dispatchDAO.updateDriverStatus("assigned", driver.getMemberid());
      }
    }
    return driver;
  }
  public String processRequest(String requestType) {
    System.out.println("Request is in processing state");
    RideDAO ridedao = new RideDAO();
    Ride ride;
    DispatchDAO dispatchDAO = new DispatchDAO();
    if (requestType.equalsIgnoreCase("ride")) {
      try {
        int rideid = getMaxRideId();

        ride = ridedao.getRideDetails(rideid);
        // Member myMember = new Member();
        DispatchDAO dispatchdao = new DispatchDAO();
        Dispatch dispatch = new Ride();
        Driver driver = dispatch.searchDriver(ride);
        if (driver != null) {
          dispatch.initiateRide();
          HashMap<String, String> rideDetails = new HashMap<String, String>();
          rideDetails.put("requestId", Integer.toString(ride.getRequestid()));
          rideDetails.put("driverId", driver.getMemberid());
          rideDetails.put("memberId", dispatchdao.getCustomerByEmail(ride.getRequestid()));
          rideDetails.put("requestType", ride.getRidetype());
          dispatch.RideInTransit(rideDetails);
          dispatch.ConcludeRide(rideDetails);
          request.setRequestState(new ConcludeRequest(request));
          dispatchDAO.updateDriverStatus("free", driver.getMemberid());
        } else {
          System.out.println(
              "Sorry, we do not have any drivers available. Please try again after some time");
        }
        // request.setRequestState(new ConcludeRequest(request));
      } catch (SQLException e) {
        e.printStackTrace();
      }
    } else {
      IssuePass issuepass = new IssuePass();
      issuepass.issuePass();
      request.setRequestState(new ConcludeRequest(request));
      return "Request is Served";
    }
    /*System.out.println("                "); */
    return "Request is Served";
  }