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);
}
}
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;
}
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);
}
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);
}
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()));
}
Aggregations