Properly requeue on exception
This commit is contained in:
parent
6d319cd378
commit
05d4c2ded6
@ -85,36 +85,37 @@ public class TripService implements ITripService {
|
|||||||
public void match(Long tripId, MatchDTO match) throws EntityNotFoundException, DriverNotAvailableException, IllegalStateException {
|
public void match(Long tripId, MatchDTO match) throws EntityNotFoundException, DriverNotAvailableException, IllegalStateException {
|
||||||
ITrip trip;
|
ITrip trip;
|
||||||
IMatch newMatch;
|
IMatch newMatch;
|
||||||
|
IDriver driver;
|
||||||
try {
|
try {
|
||||||
trip = getTrip(tripId);
|
trip = getTrip(tripId);
|
||||||
IDriver driver = getDriver(match.getDriverId());
|
driver = getDriver(match.getDriverId());
|
||||||
IMatchDAO matchDAO = daoFactory.createMatchDAO();
|
List<IMatch> matches = daoFactory.createMatchDAO().findAll();
|
||||||
for (IMatch m : matchDAO.findAll()) {
|
for (IMatch existingMatch : matches) {
|
||||||
if (m.getDriver() != null && m.getDriver().getId().equals(driver.getId()))
|
if (existingMatch.getDriver().getId().equals(match.getDriverId())) {
|
||||||
throw new DriverNotAvailableException("Driver with id " + driver.getId() + " is already busy");
|
throw new DriverNotAvailableException("Driver with id " + driver.getId() + " is already busy");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
IVehicle vehicle = getVehicle(match.getVehicleId());
|
|
||||||
|
|
||||||
newMatch = modelFactory.createMatch();
|
|
||||||
newMatch.setDate(new Date());
|
|
||||||
newMatch.setTrip(trip);
|
|
||||||
newMatch.setDriver(driver);
|
|
||||||
newMatch.setVehicle(vehicle);
|
|
||||||
|
|
||||||
IMoney fare = modelFactory.createMoney();
|
|
||||||
fare.setCurrency(match.getFare().getCurrency());
|
|
||||||
fare.setValue(match.getFare().getValue());
|
|
||||||
newMatch.setFare(fare);
|
|
||||||
|
|
||||||
trip.setMatch(newMatch);
|
|
||||||
trip.setState(TripState.MATCHED);
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
// Requeue match
|
|
||||||
matchingService.queueTripForMatching(tripId);
|
matchingService.queueTripForMatching(tripId);
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
IVehicle vehicle = getVehicle(match.getVehicleId());
|
||||||
|
|
||||||
|
newMatch = modelFactory.createMatch();
|
||||||
|
newMatch.setDate(new Date());
|
||||||
|
newMatch.setTrip(trip);
|
||||||
|
newMatch.setDriver(driver);
|
||||||
|
newMatch.setVehicle(vehicle);
|
||||||
|
|
||||||
|
IMoney fare = modelFactory.createMoney();
|
||||||
|
fare.setCurrency(match.getFare().getCurrency());
|
||||||
|
fare.setValue(match.getFare().getValue());
|
||||||
|
newMatch.setFare(fare);
|
||||||
|
|
||||||
|
trip.setMatch(newMatch);
|
||||||
|
trip.setState(TripState.MATCHED);
|
||||||
|
|
||||||
entityManager.merge(trip);
|
entityManager.merge(trip);
|
||||||
entityManager.persist(newMatch);
|
entityManager.persist(newMatch);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user