Skip to content
This repository has been archived by the owner on Nov 7, 2023. It is now read-only.

Commit

Permalink
Merge pull request #148 from dcsaorg/DT-574-Update-RI-Rename-POST-PUT…
Browse files Browse the repository at this point in the history
…-GET-bookings-endpoints-into-POST-PUT-GET-booking-requests

DT-574 renamed bookings to booking-requests
  • Loading branch information
preetamnpr authored Oct 19, 2023
2 parents c8ac420 + 66e6e1c commit 99a78a5
Show file tree
Hide file tree
Showing 56 changed files with 664 additions and 668 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

import lombok.RequiredArgsConstructor;
import org.dcsa.edocumentation.infra.enums.BookingStatus;
import org.dcsa.edocumentation.service.BookingService;
import org.dcsa.edocumentation.service.BookingRequestService;
import org.dcsa.edocumentation.transferobjects.BookingCancelRequestTO;
import org.dcsa.edocumentation.transferobjects.BookingRefStatusTO;
import org.dcsa.edocumentation.transferobjects.BookingTO;
import org.dcsa.edocumentation.transferobjects.BookingRequestRefStatusTO;
import org.dcsa.edocumentation.transferobjects.BookingRequestTO;
import org.dcsa.skernel.errors.exceptions.ConcreteRequestErrorMessageException;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
Expand All @@ -20,48 +20,48 @@
@Validated
@RestController
@RequiredArgsConstructor
public class BookingController {
private final BookingService bookingService;
public class BookingRequestController {
private final BookingRequestService bookingRequestService;

@GetMapping(
path = "${spring.application.bkg-context-path}/bookings/{carrierBookingRequestReference}",
path = "${spring.application.bkg-context-path}/booking-requests/{carrierBookingRequestReference}",
produces = MediaType.APPLICATION_JSON_VALUE
)
@ResponseStatus(HttpStatus.OK)
public BookingTO getBooking(@PathVariable("carrierBookingRequestReference") @NotBlank @Size(max = 100)
public BookingRequestTO getBookingRequest(@PathVariable("carrierBookingRequestReference") @NotBlank @Size(max = 100)
String carrierBookingRequestReference) {
return bookingService
.getBooking(carrierBookingRequestReference)
return bookingRequestService
.getBookingRequest(carrierBookingRequestReference)
.orElseThrow(
() ->
ConcreteRequestErrorMessageException.notFound(
"No booking found with carrierBookingRequestReference: "
"No booking request found with carrierBookingRequestReference: "
+ carrierBookingRequestReference));
}

@PostMapping(path = "${spring.application.bkg-context-path}/bookings")
@PostMapping(path = "${spring.application.bkg-context-path}/booking-requests")
@ResponseStatus(HttpStatus.CREATED)
public BookingRefStatusTO createBooking(@Valid @RequestBody BookingTO bookingRequest) {
public BookingRequestRefStatusTO createBookingRequest(@Valid @RequestBody BookingRequestTO bookingRequest) {
if (bookingRequest.carrierBookingRequestReference() != null
|| bookingRequest.bookingStatus() != null
|| bookingRequest.bookingRequestCreatedDateTime() != null
|| bookingRequest.bookingRequestUpdatedDateTime() != null) {
throw ConcreteRequestErrorMessageException.invalidInput(
"carrierBookingRequestReference, bookingStatus, bookingRequestCreatedDateTime and"
+ " bookingRequestUpdatedDateTime are not allowed when creating a booking");
+ " bookingRequestUpdatedDateTime are not allowed when creating a booking request");
}
return bookingService.createBooking(bookingRequest);
return bookingRequestService.createBookingRequest(bookingRequest);
}

@PutMapping(path = "${spring.application.bkg-context-path}/bookings/{carrierBookingRequestReference}")
@PutMapping(path = "${spring.application.bkg-context-path}/booking-requests/{carrierBookingRequestReference}")
@ResponseStatus(HttpStatus.OK)
public BookingRefStatusTO updateBooking(
public BookingRequestRefStatusTO updateBookingRequest(
@PathVariable("carrierBookingRequestReference")
@NotBlank @Size(max = 100)
String carrierBookingRequestReference,

@Valid @RequestBody
BookingTO bookingRequest
BookingRequestTO bookingRequest
) {
if (bookingRequest.carrierBookingRequestReference() == null || !carrierBookingRequestReference.equals(bookingRequest.carrierBookingRequestReference())) {
throw ConcreteRequestErrorMessageException.invalidInput(
Expand All @@ -72,32 +72,32 @@ public BookingRefStatusTO updateBooking(
|| bookingRequest.bookingRequestUpdatedDateTime() != null) {
throw ConcreteRequestErrorMessageException.invalidInput(
"bookingStatus, bookingRequestCreatedDateTime and"
+ " bookingRequestUpdatedDateTime are not allowed when updating a booking");
+ " bookingRequestUpdatedDateTime are not allowed when updating a booking request");
}
return bookingService.updateBooking(carrierBookingRequestReference, bookingRequest)
return bookingRequestService.updateBookingRequest(carrierBookingRequestReference, bookingRequest)
.orElseThrow(
() ->
ConcreteRequestErrorMessageException.notFound(
"No booking found with carrierBookingRequestReference: "
"No booking request found with carrierBookingRequestReference: "
+ carrierBookingRequestReference));
}

@PatchMapping(
path = "${spring.application.bkg-context-path}/bookings/{carrierBookingRequestReference}",
path = "${spring.application.bkg-context-path}/booking-requests/{carrierBookingRequestReference}",
produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseStatus(HttpStatus.OK)
public BookingRefStatusTO cancelBooking(
public BookingRequestRefStatusTO cancelBookingRequest(
@Valid @PathVariable("carrierBookingRequestReference") @NotNull @Size(max = 100)
String carrierBookingRequestReference,
@Valid @RequestBody BookingCancelRequestTO bookingCancelRequestTO) {
if (!bookingCancelRequestTO.bookingStatus().equals(BookingStatus.CANCELLED)) {
throw ConcreteRequestErrorMessageException.invalidInput("bookingStatus must be CANCELLED");
}
return bookingService.cancelBooking(carrierBookingRequestReference, bookingCancelRequestTO.reason())
return bookingRequestService.cancelBookingRequest(carrierBookingRequestReference, bookingCancelRequestTO.reason())
.orElseThrow(
() ->
ConcreteRequestErrorMessageException.notFound(
"No booking found with carrierBookingRequestReference: "
"No booking request found with carrierBookingRequestReference: "
+ carrierBookingRequestReference));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
import org.dcsa.edocumentation.service.unofficial.UnofficialBookingService;
import org.dcsa.edocumentation.service.unofficial.UnofficialBookingRequestService;
import org.dcsa.edocumentation.transferobjects.unofficial.BookingCancelRequestTO;
import org.dcsa.edocumentation.transferobjects.BookingRefStatusTO;
import org.dcsa.edocumentation.transferobjects.BookingRequestRefStatusTO;
import org.dcsa.skernel.errors.exceptions.ConcreteRequestErrorMessageException;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
Expand All @@ -21,31 +21,31 @@
@Validated
@RestController
@RequiredArgsConstructor
public class UnofficialBookingController {
private final UnofficialBookingService unofficialBookingService;
public class UnofficialBookingRequestController {
private final UnofficialBookingRequestService unofficialBookingRequestService;

@PostMapping(path = "/unofficial${spring.application.bkg-context-path}/bookings/{carrierBookingRequestReference}/validate")
@PostMapping(path = "/unofficial${spring.application.bkg-context-path}/booking-requests/{carrierBookingRequestReference}/validate")
@ResponseStatus(HttpStatus.OK)
public BookingRefStatusTO validateBooking(
public BookingRequestRefStatusTO validateBooking(
@PathVariable("carrierBookingRequestReference")
@NotBlank @Size(max = 100)
String carrierBookingRequestReference) {
return unofficialBookingService.performBookingValidation(carrierBookingRequestReference);
return unofficialBookingRequestService.performBookingValidation(carrierBookingRequestReference);
}

@PatchMapping(
path = "/unofficial${spring.application.bkg-context-path}/bookings/{carrierBookingRequestReference}",
path = "/unofficial${spring.application.bkg-context-path}/booking-requests/{carrierBookingRequestReference}",
produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseStatus(HttpStatus.OK)
public BookingRefStatusTO cancelBooking(
public BookingRequestRefStatusTO cancelBooking(
@Valid @PathVariable("carrierBookingRequestReference") @NotNull @Size(max = 100)
String carrierBookingRequestReference,
@Valid @RequestBody BookingCancelRequestTO bookingCancelRequestTO) {
return unofficialBookingService.cancelBooking(carrierBookingRequestReference, bookingCancelRequestTO)
return unofficialBookingRequestService.cancelBooking(carrierBookingRequestReference, bookingCancelRequestTO)
.orElseThrow(
() ->
ConcreteRequestErrorMessageException.notFound(
"No booking found with carrierBookingRequestReference: "
"No booking request found with carrierBookingRequestReference: "
+ carrierBookingRequestReference));
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.dcsa.edocumentation.controller;

import org.dcsa.edocumentation.service.BookingService;
import org.dcsa.edocumentation.transferobjects.BookingTO;
import org.dcsa.edocumentation.service.BookingRequestService;
import org.dcsa.edocumentation.transferobjects.BookingRequestTO;
import org.dcsa.skernel.errors.infrastructure.ConcreteRequestErrorMessageExceptionHandler;
import org.dcsa.skernel.errors.infrastructure.FallbackExceptionHandler;
import org.dcsa.skernel.errors.infrastructure.JakartaValidationExceptionHandler;
Expand All @@ -26,23 +26,24 @@
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

@ActiveProfiles("test")
@WebMvcTest(controllers = {BookingController.class})
@WebMvcTest(controllers = {BookingRequestController.class})
@Import({
SpringExceptionHandler.class,
JakartaValidationExceptionHandler.class,
FallbackExceptionHandler.class,
ConcreteRequestErrorMessageExceptionHandler.class,
})
class BookingControllerTest {
class BookingRequestControllerTest {
@Autowired MockMvc mockMvc;
@MockBean BookingService bookingService;
private final String path = "/bkg/v2/bookings";
@MockBean
BookingRequestService bookingRequestService;
private final String path = "/bkg/v2/booking-requests";

@Test
void testBookingController_getBookingSingleResult() throws Exception {

BookingTO mockBookingTO = BookingTO.builder().carrierBookingRequestReference("1234").build();
when(bookingService.getBooking("1234")).thenReturn(Optional.of(mockBookingTO));
BookingRequestTO mockBookingRequestTO = BookingRequestTO.builder().carrierBookingRequestReference("1234").build();
when(bookingRequestService.getBookingRequest("1234")).thenReturn(Optional.of(mockBookingRequestTO));

mockMvc
.perform(get(path + "/1234").accept(MediaType.APPLICATION_JSON))
Expand All @@ -64,12 +65,12 @@ void testBookingController_getBookingInvalidCarrierBookingRequestReference() thr
jsonPath("$.errors[0].message")
.value(
containsString(
"getBooking.carrierBookingRequestReference size must be between 0 and 100")));
"getBookingRequest.carrierBookingRequestReference size must be between 0 and 100")));
}

@Test
void testBookingController_getBookingNotFound() throws Exception {
when(bookingService.getBooking(any())).thenReturn(Optional.empty());
when(bookingRequestService.getBookingRequest(any())).thenReturn(Optional.empty());
mockMvc
.perform(get(path + "/IdoNotExist").accept(MediaType.APPLICATION_JSON))
.andDo(print())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
FallbackExceptionHandler.class,
ConcreteRequestErrorMessageExceptionHandler.class,
})
class BookingSummaryControllerTest {
class BookingRequestSummaryControllerTest {

@Autowired MockMvc mockMvc;
@MockBean BookingSummaryService bookingSummaryService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@
import org.springframework.data.domain.Persistable;

@NamedEntityGraph(
name = "graph.booking-summary",
name = "graph.booking-request-summary",
attributeNodes = {@NamedAttributeNode("vessel")})
@NamedEntityGraph(
name = "graph.booking",
name = "graph.booking-request",
attributeNodes = {
@NamedAttributeNode("vessel"),
@NamedAttributeNode("placeOfIssue"),
Expand All @@ -58,9 +58,9 @@
@AllArgsConstructor
@Setter(AccessLevel.PRIVATE)
@Entity
@Table(name = "booking")
@BookingValidation(groups = AsyncShipperProvidedDataValidation.class)
public class Booking extends AbstractStateMachine<String> implements Persistable<UUID> {
@Table(name = "booking_request")
@BookingRequestValidation(groups = AsyncShipperProvidedDataValidation.class)
public class BookingRequest extends AbstractStateMachine<String> implements Persistable<UUID> {

private static final Set<String> CAN_BE_VALIDATED = Set.of(RECEIVED,
PENDING_UPDATES_CONFIRMATION,
Expand Down Expand Up @@ -100,7 +100,7 @@ public class Booking extends AbstractStateMachine<String> implements Persistable
@ToString.Exclude
@EqualsAndHashCode.Exclude
@OneToMany(cascade = CascadeType.ALL)
@JoinColumn(name = "booking_id", referencedColumnName = "id", nullable = false)
@JoinColumn(name = "booking_request_id", referencedColumnName = "id", nullable = false)
@OrderColumn(name = "element_order")
private List<BookingRequestedChange> requestedChanges;

Expand Down Expand Up @@ -222,23 +222,23 @@ public class Booking extends AbstractStateMachine<String> implements Persistable

@ToString.Exclude
@EqualsAndHashCode.Exclude
@OneToMany(mappedBy = "booking")
@OneToMany(mappedBy = "bookingRequest")
private Set<@Valid Reference> references;

@ToString.Exclude
@EqualsAndHashCode.Exclude
@OneToMany(mappedBy = "booking", cascade = CascadeType.ALL)
@OneToMany(mappedBy = "bookingRequest", cascade = CascadeType.ALL)
@OrderColumn(name = "list_order")
private List<@Valid RequestedEquipmentGroup> requestedEquipments;

@ToString.Exclude
@EqualsAndHashCode.Exclude
@OneToMany(mappedBy = "booking")
@OneToMany(mappedBy = "bookingRequest")
private Set<@Valid DocumentParty> documentParties;

@ToString.Exclude
@EqualsAndHashCode.Exclude
@OneToMany(mappedBy = "booking")
@OneToMany(mappedBy = "bookingRequest")
@Size(min = 2, message = "Must have at least two shipment locations", groups = AsyncShipperProvidedDataValidation.class)
@NotNull(groups = AsyncShipperProvidedDataValidation.class)
private Set<@Valid ShipmentLocation> shipmentLocations;
Expand Down Expand Up @@ -436,7 +436,7 @@ public void assignRequestedEquipment(List<RequestedEquipmentGroup> requestedEqui
this.requestedEquipments = requestedEquipments;
if (requestedEquipments != null) {
for (var re : requestedEquipments) {
re.setBooking(this);
re.setBookingRequest(this);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class BookingRequestedChange {
@Column(name = "message", length = 500)
private String message;

public static BookingRequestedChange fromConstraintViolation(ConstraintViolation<Booking> violation) {
public static BookingRequestedChange fromConstraintViolation(ConstraintViolation<BookingRequest> violation) {
return BookingRequestedChange.builder()
.path(violation.getPropertyPath().toString())
.message(violation.getMessage())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ public class ConfirmedBooking {
@ToString.Exclude
@EqualsAndHashCode.Exclude
@ManyToOne(cascade = CascadeType.ALL)
@JoinColumn(name = "booking_id")
private Booking booking;
@JoinColumn(name = "booking_request_id")
private BookingRequest booking;

@ToString.Exclude
@EqualsAndHashCode.Exclude
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ public class DocumentParty {
@ToString.Exclude
@EqualsAndHashCode.Exclude
@ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
@JoinColumn(name = "booking_id")
private Booking booking;
@JoinColumn(name = "booking_request_id")
private BookingRequest bookingRequest;

@JoinColumn(name = "shipping_instruction_id")
@Column(name = "shipping_instruction_id")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ public class Reference {
@ToString.Exclude
@EqualsAndHashCode.Exclude
@ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
@JoinColumn(name = "booking_id")
private Booking booking;
@JoinColumn(name = "booking_request_id")
private BookingRequest bookingRequest;

@JoinColumn(name = "shipping_instruction_id")
@Column(name = "shipping_instruction_id")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ public class RequestedEquipmentGroup {
@ToString.Exclude
@EqualsAndHashCode.Exclude
@ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
@JoinColumn(name = "booking_id")
@JoinColumn(name = "booking_request_id")
@Setter(AccessLevel.PACKAGE)
private Booking booking;
private BookingRequest bookingRequest;

@Column(name = "iso_equipment_code", nullable = false)
@Size(max = 4)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ public class ShipmentLocation {
@ToString.Exclude
@EqualsAndHashCode.Exclude
@ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
@JoinColumn(name = "booking_id")
private Booking booking;
@JoinColumn(name = "booking_request_id")
private BookingRequest bookingRequest;

@ToString.Exclude
@EqualsAndHashCode.Exclude
Expand Down
Loading

0 comments on commit 99a78a5

Please sign in to comment.