Search in sources :

Example 1 with Trip

use of org.neo4j.ogm.domain.gh817.Trip in project java-on-demand-rides-deliveries-stub-provider by googlemaps.

the class ServletStatePropertyChangeListener method searchAndCancelTrips.

/**
 * Find trips with corresponding vehicleId to set the status to cancel.
 *
 * <p>The sample provider currently manages a singleton Vehicle.
 */
private void searchAndCancelTrips(String vehicleId) {
    logger.info(String.format("Searching for trips with vehicleId: %s", vehicleId));
    SearchTripsRequest searchRequest = SearchTripsRequest.newBuilder().setParent(TripUtils.PROVIDER_NAME).setVehicleId(vehicleId).setActiveTripsOnly(true).build();
    SearchTripsPagedResponse tripResponse = authenticatedServerTripService.searchTrips(searchRequest);
    if (tripResponse.getPage() == null) {
        logger.info(String.format("No trips found with vehicleId: %s", vehicleId));
        return;
    }
    Iterator<Trip> trips = tripResponse.iterateAll().iterator();
    if (!trips.hasNext()) {
        logger.info(String.format("No trips found with vehicleId: %s", vehicleId));
        return;
    }
    while (trips.hasNext()) {
        Trip trip = trips.next();
        String tripName = trip.getName();
        logger.info(String.format("Cancelling Trip: %s", tripName));
        UpdateTripRequest updateReq = UpdateTripRequest.newBuilder().setName(tripName).setTrip(Trip.newBuilder().setTripStatus(TripStatus.CANCELED)).setUpdateMask(FieldMask.newBuilder().addPaths(TRIP_STATUS_PROPERTY).build()).build();
        authenticatedServerTripService.updateTrip(updateReq);
    }
}
Also used : SearchTripsRequest(google.maps.fleetengine.v1.SearchTripsRequest) Trip(google.maps.fleetengine.v1.Trip) UpdateTripRequest(google.maps.fleetengine.v1.UpdateTripRequest) SearchTripsPagedResponse(google.maps.fleetengine.v1.TripServiceClient.SearchTripsPagedResponse)

Example 2 with Trip

use of org.neo4j.ogm.domain.gh817.Trip in project java-on-demand-rides-deliveries-stub-provider by googlemaps.

the class TripMatcher method isVehicleReadyForMatch.

/**
 * Determines if the given vehicle is ready to take a match based on current state.
 */
public boolean isVehicleReadyForMatch() {
    String vehicleId = servletState.getVehicleId();
    if (servletState.hasTripPendingMatch() == false) {
        return false;
    }
    GetVehicleRequest getVehicleRequest = GetVehicleRequest.newBuilder().setName(VehicleUtils.getVehicleName(vehicleId)).build();
    Vehicle vehicle = authenticatedServerVehicleService.getVehicle(getVehicleRequest);
    int numberOfTripsAssigned = vehicle.getCurrentTripsList().size();
    if (numberOfTripsAssigned >= 2) {
        return false;
    }
    if (numberOfTripsAssigned == 0) {
        return true;
    }
    if (vehicle.getBackToBackEnabled() == false) {
        return false;
    }
    Trip currentTrip = servletState.getActiveTripsMap().get(vehicle.getCurrentTripsList().get(0));
    GetTripRequest getTripRequest = GetTripRequest.newBuilder().setName(currentTrip.getName()).build();
    Trip trip = authenticatedServerTripService.getTrip(getTripRequest);
    return trip.getTripStatus() != TripStatus.ENROUTE_TO_PICKUP && trip.getTripStatus() != TripStatus.ARRIVED_AT_PICKUP && trip.getTripStatus() != TripStatus.NEW;
}
Also used : Vehicle(google.maps.fleetengine.v1.Vehicle) Trip(google.maps.fleetengine.v1.Trip) GetTripRequest(google.maps.fleetengine.v1.GetTripRequest) GetVehicleRequest(google.maps.fleetengine.v1.GetVehicleRequest)

Example 3 with Trip

use of org.neo4j.ogm.domain.gh817.Trip in project neo4j-ogm by neo4j.

the class SessionAndMappingContextTest method shouldRefreshUpdatedRelationshipEntities.

// GH-817
@Test
public void shouldRefreshUpdatedRelationshipEntities() {
    sessionFactory.openSession().purgeDatabase();
    Session sessionForCreation = sessionFactory.openSession();
    Rider rider = new Rider("Michael");
    Bike bike1 = new Bike("Bike1");
    Bike bike2 = new Bike("Bike2");
    rider.getTrips().add(new Trip(rider, bike1, "n/a"));
    rider.getTrips().add(new Trip(rider, bike2, "n/a"));
    try (Transaction tx = sessionForCreation.beginTransaction()) {
        sessionForCreation.save(rider);
        tx.commit();
    }
    Session sessionForLoadingAndUpdate = sessionFactory.openSession();
    Iterable<Trip> loadedBikes = sessionForLoadingAndUpdate.loadAll(Trip.class);
    assertThat(loadedBikes).hasSize(2).extracting(Trip::getName).containsOnly("n/a");
    String name = "A nice trip";
    Iterable<Trip> updatedBikes = sessionForLoadingAndUpdate.query(Trip.class, "MATCH (r:Rider) - [t:RODE] -> (c:Bike) SET t.name = $newName RETURN *", Collections.singletonMap("newName", name));
    Rider loadedRider = sessionForLoadingAndUpdate.load(Rider.class, rider.getId());
    assertThat(updatedBikes).hasSize(2).extracting(Trip::getName).containsOnly(name);
    assertThat(loadedRider.getTrips()).hasSize(2).extracting(Trip::getName).containsOnly(name);
}
Also used : Trip(org.neo4j.ogm.domain.gh817.Trip) Transaction(org.neo4j.ogm.transaction.Transaction) Rider(org.neo4j.ogm.domain.gh817.Rider) Bike(org.neo4j.ogm.domain.gh817.Bike) Neo4jSession(org.neo4j.ogm.session.Neo4jSession) Session(org.neo4j.ogm.session.Session) Test(org.junit.Test)

Example 4 with Trip

use of org.neo4j.ogm.domain.gh817.Trip in project java-fleetengine-auth by googlemaps.

the class OdrdSampleCommands method createTrip.

static void createTrip() throws SignerInitializationException, IOException {
    String randomTripId = String.format("trip-%s", UUID.randomUUID());
    Trip trip = Trip.newBuilder().setName(String.format("providers/%s/trips/%s", OdrdConfiguration.PROVIDER_ID, randomTripId)).setTripType(TripType.EXCLUSIVE).setNumberOfPassengers(1).setPickupPoint(TerminalLocation.newBuilder().setPoint(EXAMPLE_LAT_LNG).build()).setDropoffPoint(TerminalLocation.newBuilder().setPoint(DEST_EXAMPLE_LAT_LNG).build()).build();
    CreateTripRequest request = CreateTripRequest.newBuilder().setTripId(randomTripId).setTrip(trip).setParent(String.format("providers/%s", OdrdConfiguration.PROVIDER_ID)).build();
    TripServiceSettings settings = new FleetEngineClientSettingsModifier<TripServiceSettings, TripServiceSettings.Builder>(getMinter()).updateBuilder(TripServiceSettings.newBuilder()).setEndpoint(OdrdConfiguration.FLEET_ENGINE_ADDRESS).build();
    try (TripServiceClient client = TripServiceClient.create(settings)) {
        client.createTrip(request);
    }
    System.out.printf("Trip with id '%s' created\n", randomTripId);
}
Also used : Trip(google.maps.fleetengine.v1.Trip) TripServiceClient(google.maps.fleetengine.v1.TripServiceClient) TripServiceSettings(google.maps.fleetengine.v1.TripServiceSettings) CreateTripRequest(google.maps.fleetengine.v1.CreateTripRequest)

Example 5 with Trip

use of org.neo4j.ogm.domain.gh817.Trip in project java-on-demand-rides-deliveries-stub-provider by googlemaps.

the class TripMatcher method triggerMatching.

/**
 * Assigns a trip ready to match to the given vehicle.
 */
public synchronized void triggerMatching() {
    String vehicleId = servletState.getVehicleId();
    logger.info(String.format("triggerMatching() vehicleId: %s", vehicleId));
    Trip tripToMatch = servletState.getNextTripToMatch();
    UpdateTripRequest updateRequest = UpdateTripRequest.newBuilder().setName(tripToMatch.getName()).setTrip(Trip.newBuilder().setVehicleId(vehicleId).build()).setUpdateMask(FieldMask.newBuilder().addPaths("vehicle_id").build()).build();
    Trip updatedTrip = authenticatedServerTripService.updateTrip(updateRequest);
    servletState.getActiveTripsMap().put(updatedTrip.getName(), updatedTrip);
    logger.info(String.format("triggerMatching() completed vehicleId: %s tripName: %s", vehicleId, tripToMatch.getName()));
}
Also used : Trip(google.maps.fleetengine.v1.Trip) UpdateTripRequest(google.maps.fleetengine.v1.UpdateTripRequest)

Aggregations

Trip (google.maps.fleetengine.v1.Trip)11 TripServiceClient (google.maps.fleetengine.v1.TripServiceClient)5 CreateTripRequest (google.maps.fleetengine.v1.CreateTripRequest)3 UpdateTripRequest (google.maps.fleetengine.v1.UpdateTripRequest)3 Gson (com.google.gson.Gson)2 JsonElement (com.google.gson.JsonElement)2 JsonObject (com.google.gson.JsonObject)2 GetTripRequest (google.maps.fleetengine.v1.GetTripRequest)2 GetVehicleRequest (google.maps.fleetengine.v1.GetVehicleRequest)2 SearchTripsRequest (google.maps.fleetengine.v1.SearchTripsRequest)2 SearchTripsPagedResponse (google.maps.fleetengine.v1.TripServiceClient.SearchTripsPagedResponse)2 TripServiceSettings (google.maps.fleetengine.v1.TripServiceSettings)2 Vehicle (google.maps.fleetengine.v1.Vehicle)2 WaypointType (com.example.provider.json.Waypoint.WaypointType)1 ImmutableList (com.google.common.collect.ImmutableList)1 JsonParseException (com.google.gson.JsonParseException)1 JsonSerializationContext (com.google.gson.JsonSerializationContext)1 JsonSerializer (com.google.gson.JsonSerializer)1 LatLng (com.google.type.LatLng)1 TerminalLocation (google.maps.fleetengine.v1.TerminalLocation)1