Search in sources :

Example 6 with Booking

use of io.narayana.sra.demo.model.Booking in project narayana by jbosstm.

the class TripService method cancelBooking.

public Booking cancelBooking(Booking booking) {
    System.out.printf("Canceling booking id %s (%s) status: %s%n", booking.getId(), booking.getName(), booking.getStatus());
    if (booking.getStatus() != BookingStatus.CANCEL_REQUESTED && booking.getStatus() != BookingStatus.PROVISIONAL)
        throw new WebApplicationException(Response.status(Response.Status.BAD_REQUEST).entity("To late to requestCancel booking").build());
    Booking prev = add(booking);
    if (prev != null)
        System.out.printf("Seen this booking before%n");
    booking.requestCancel();
    lraClient.cancelSRA(SRAClient.lraToURL(booking.getId(), "Invalid trip booking id format"));
    booking.setCanceled();
    return mergeBookingResponse(booking);
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) Booking(io.narayana.sra.demo.model.Booking)

Aggregations

Booking (io.narayana.sra.demo.model.Booking)6 WebApplicationException (javax.ws.rs.WebApplicationException)3 SRA (io.narayana.sra.annotation.SRA)1 SRAClient (io.narayana.sra.client.SRAClient)1 SRAClientAPI (io.narayana.sra.client.SRAClientAPI)1 BookingStatus (io.narayana.sra.demo.model.BookingStatus)1 URL (java.net.URL)1 Arrays (java.util.Arrays)1 List (java.util.List)1 Map (java.util.Map)1 Function (java.util.function.Function)1 Collectors (java.util.stream.Collectors)1 ApplicationScoped (javax.enterprise.context.ApplicationScoped)1 Inject (javax.inject.Inject)1 POST (javax.ws.rs.POST)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 Response (javax.ws.rs.core.Response)1