// Path: booking-service/src/main/java/de/codecentric/resilient/booking/service/BookingService.java
// @Service
// public class BookingService {
// 
//     private static final Logger LOGGER = LoggerFactory.getLogger(BookingService.class);
// 
//     private final BookingRepository bookingRepository;
// 
//     private final BookingMapper bookingMapper;
// 
//     private final RestTemplate restTemplate;
// 
//     private DynamicBooleanProperty secondServiceCallEnabled =
//         DynamicPropertyFactory.getInstance().getBooleanProperty("second.service.call", false);
// 
//     @Autowired
//     public BookingService(BookingRepository bookingRepository, BookingMapper bookingMapper, RestTemplate restTemplate) {
//         this.bookingRepository = bookingRepository;
//         this.bookingMapper = bookingMapper;
//         this.restTemplate = restTemplate;
//     }
// 
//     public BookingServiceResponseDTO createBooking(BookingServiceRequestDTO bookingRequestDTO) {
// 
//         BookingServiceResponseDTO bookingResponseDTO = new BookingServiceResponseDTO();
// 
//         // 1.) Create connote
//         ConnoteDTO connoteDTO = receiveConnote();
// 
//         if (connoteDTO.isFallback()) {
//             bookingResponseDTO.setErrorMsg("Connote error: " + connoteDTO.getErrorMsg());
//             bookingResponseDTO.setStatus("ERROR");
//             return bookingResponseDTO;
//         }
// 
//         // 2. Save booking request
// 
//         Booking booking = bookingMapper.mapToBookingEntity(bookingRequestDTO, connoteDTO.getConnote());
//         bookingRepository.save(booking);
// 
//         CustomerResponseDTO customerDTO = bookingRequestDTO.getCustomerDTO();
//         bookingResponseDTO.setCustomerDTO(new CustomerDTO(customerDTO.getCustomerId(), customerDTO.getCustomerName()));
//         bookingResponseDTO.setConnoteDTO(connoteDTO);
//         bookingResponseDTO.setStatus("OK");
// 
//         return bookingResponseDTO;
// 
//     }
// 
//     private ConnoteDTO receiveConnote() {
//         LOGGER.debug("Starting getConnote");
// 
//         return new ConnoteCommand(restTemplate, secondServiceCallEnabled.get()).execute();
//     }
// }
// 
// Path: service-library/src/main/java/de/codecentric/resilient/dto/BookingServiceRequestDTO.java
// public class BookingServiceRequestDTO {
// 
//     private CustomerResponseDTO customerDTO;
// 
//     private AddressResponseDTO senderAddress;
// 
//     private AddressResponseDTO receiverAddress;
// 
//     public CustomerResponseDTO getCustomerDTO() {
//         return customerDTO;
//     }
// 
//     public void setCustomerDTO(CustomerResponseDTO customerDTO) {
//         this.customerDTO = customerDTO;
//     }
// 
//     public AddressResponseDTO getSenderAddress() {
//         return senderAddress;
//     }
// 
//     public void setSenderAddress(AddressResponseDTO senderAddress) {
//         this.senderAddress = senderAddress;
//     }
// 
//     public AddressResponseDTO getReceiverAddress() {
//         return receiverAddress;
//     }
// 
//     public void setReceiverAddress(AddressResponseDTO receiverAddress) {
//         this.receiverAddress = receiverAddress;
//     }
// 
//     @Override
//     public String toString() {
//         final StringBuilder sb = new StringBuilder("BookingServiceRequestDTO{");
//         sb.append("customerDTO=").append(customerDTO);
//         sb.append(", senderAddress=").append(senderAddress);
//         sb.append(", receiverAddress=").append(receiverAddress);
//         sb.append('}');
//         return sb.toString();
//     }
// }
// 
// Path: service-library/src/main/java/de/codecentric/resilient/dto/BookingServiceResponseDTO.java
// @JsonInclude(JsonInclude.Include.NON_NULL)
// public class BookingServiceResponseDTO extends FallbackAbstractDTO {
// 
//     @JsonProperty(required = true)
//     private ConnoteDTO connoteDTO;
// 
//     @JsonProperty(required = true)
//     private String status;
// 
//     @JsonProperty(required = true)
//     private CustomerDTO customerDTO;
// 
//     @JsonProperty(required = true, value = "service-response-status")
//     private List<ServiceResponseStatus> serviceResponseStatusList;
// 
//     public List<ServiceResponseStatus> getServiceResponseStatusList() {
//         return serviceResponseStatusList;
//     }
// 
//     public void setServiceResponseStatusList(List<ServiceResponseStatus> serviceResponseStatusList) {
//         this.serviceResponseStatusList = serviceResponseStatusList;
//     }
// 
//     public ConnoteDTO getConnoteDTO() {
//         return connoteDTO;
//     }
// 
//     public void setConnoteDTO(ConnoteDTO connoteDTO) {
//         this.connoteDTO = connoteDTO;
//     }
// 
//     public CustomerDTO getCustomerDTO() {
//         return customerDTO;
//     }
// 
//     public void setCustomerDTO(CustomerDTO customerDTO) {
//         this.customerDTO = customerDTO;
//     }
// 
//     public String getStatus() {
//         return status;
//     }
// 
//     public void setStatus(String status) {
//         this.status = status;
//     }
// }


import javax.servlet.http.HttpServletRequest;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.sleuth.Span;
import org.springframework.cloud.sleuth.Tracer;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import de.codecentric.resilient.booking.service.BookingService;
import de.codecentric.resilient.dto.BookingServiceRequestDTO;
import de.codecentric.resilient.dto.BookingServiceResponseDTO;
package de.codecentric.resilient.booking.rest;



/**
 * @author Benjamin Wilms
 */
@RestController
@RequestMapping("rest/booking")
public class BookingController {

    private static final Logger LOGGER = LoggerFactory.getLogger(BookingController.class);

// Path: booking-service/src/main/java/de/codecentric/resilient/booking/service/BookingService.java
// @Service
// public class BookingService {
// 
//     private static final Logger LOGGER = LoggerFactory.getLogger(BookingService.class);
// 
//     private final BookingRepository bookingRepository;
// 
//     private final BookingMapper bookingMapper;
// 
//     private final RestTemplate restTemplate;
// 
//     private DynamicBooleanProperty secondServiceCallEnabled =
//         DynamicPropertyFactory.getInstance().getBooleanProperty("second.service.call", false);
// 
//     @Autowired
//     public BookingService(BookingRepository bookingRepository, BookingMapper bookingMapper, RestTemplate restTemplate) {
//         this.bookingRepository = bookingRepository;
//         this.bookingMapper = bookingMapper;
//         this.restTemplate = restTemplate;
//     }
// 
//     public BookingServiceResponseDTO createBooking(BookingServiceRequestDTO bookingRequestDTO) {
// 
//         BookingServiceResponseDTO bookingResponseDTO = new BookingServiceResponseDTO();
// 
//         // 1.) Create connote
//         ConnoteDTO connoteDTO = receiveConnote();
// 
//         if (connoteDTO.isFallback()) {
//             bookingResponseDTO.setErrorMsg("Connote error: " + connoteDTO.getErrorMsg());
//             bookingResponseDTO.setStatus("ERROR");
//             return bookingResponseDTO;
//         }
// 
//         // 2. Save booking request
// 
//         Booking booking = bookingMapper.mapToBookingEntity(bookingRequestDTO, connoteDTO.getConnote());
//         bookingRepository.save(booking);
// 
//         CustomerResponseDTO customerDTO = bookingRequestDTO.getCustomerDTO();
//         bookingResponseDTO.setCustomerDTO(new CustomerDTO(customerDTO.getCustomerId(), customerDTO.getCustomerName()));
//         bookingResponseDTO.setConnoteDTO(connoteDTO);
//         bookingResponseDTO.setStatus("OK");
// 
//         return bookingResponseDTO;
// 
//     }
// 
//     private ConnoteDTO receiveConnote() {
//         LOGGER.debug("Starting getConnote");
// 
//         return new ConnoteCommand(restTemplate, secondServiceCallEnabled.get()).execute();
//     }
// }
// 
// Path: service-library/src/main/java/de/codecentric/resilient/dto/BookingServiceRequestDTO.java
// public class BookingServiceRequestDTO {
// 
//     private CustomerResponseDTO customerDTO;
// 
//     private AddressResponseDTO senderAddress;
// 
//     private AddressResponseDTO receiverAddress;
// 
//     public CustomerResponseDTO getCustomerDTO() {
//         return customerDTO;
//     }
// 
//     public void setCustomerDTO(CustomerResponseDTO customerDTO) {
//         this.customerDTO = customerDTO;
//     }
// 
//     public AddressResponseDTO getSenderAddress() {
//         return senderAddress;
//     }
// 
//     public void setSenderAddress(AddressResponseDTO senderAddress) {
//         this.senderAddress = senderAddress;
//     }
// 
//     public AddressResponseDTO getReceiverAddress() {
//         return receiverAddress;
//     }
// 
//     public void setReceiverAddress(AddressResponseDTO receiverAddress) {
//         this.receiverAddress = receiverAddress;
//     }
// 
//     @Override
//     public String toString() {
//         final StringBuilder sb = new StringBuilder("BookingServiceRequestDTO{");
//         sb.append("customerDTO=").append(customerDTO);
//         sb.append(", senderAddress=").append(senderAddress);
//         sb.append(", receiverAddress=").append(receiverAddress);
//         sb.append('}');
//         return sb.toString();
//     }
// }
// 
// Path: service-library/src/main/java/de/codecentric/resilient/dto/BookingServiceResponseDTO.java
// @JsonInclude(JsonInclude.Include.NON_NULL)
// public class BookingServiceResponseDTO extends FallbackAbstractDTO {
// 
//     @JsonProperty(required = true)
//     private ConnoteDTO connoteDTO;
// 
//     @JsonProperty(required = true)
//     private String status;
// 
//     @JsonProperty(required = true)
//     private CustomerDTO customerDTO;
// 
//     @JsonProperty(required = true, value = "service-response-status")
//     private List<ServiceResponseStatus> serviceResponseStatusList;
// 
//     public List<ServiceResponseStatus> getServiceResponseStatusList() {
//         return serviceResponseStatusList;
//     }
// 
//     public void setServiceResponseStatusList(List<ServiceResponseStatus> serviceResponseStatusList) {
//         this.serviceResponseStatusList = serviceResponseStatusList;
//     }
// 
//     public ConnoteDTO getConnoteDTO() {
//         return connoteDTO;
//     }
// 
//     public void setConnoteDTO(ConnoteDTO connoteDTO) {
//         this.connoteDTO = connoteDTO;
//     }
// 
//     public CustomerDTO getCustomerDTO() {
//         return customerDTO;
//     }
// 
//     public void setCustomerDTO(CustomerDTO customerDTO) {
//         this.customerDTO = customerDTO;
//     }
// 
//     public String getStatus() {
//         return status;
//     }
// 
//     public void setStatus(String status) {
//         this.status = status;
//     }
// }


// Path: booking-service/src/main/java/de/codecentric/resilient/booking/rest/BookingController.java
import javax.servlet.http.HttpServletRequest;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.sleuth.Span;
import org.springframework.cloud.sleuth.Tracer;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import de.codecentric.resilient.booking.service.BookingService;
import de.codecentric.resilient.dto.BookingServiceRequestDTO;
import de.codecentric.resilient.dto.BookingServiceResponseDTO;

package de.codecentric.resilient.booking.rest;



/**
 * @author Benjamin Wilms
 */
@RestController
@RequestMapping("rest/booking")
public class BookingController {

    private static final Logger LOGGER = LoggerFactory.getLogger(BookingController.class);

    private final BookingService bookingService;