// Path: customer-service/src/main/java/de/codecentric/resilient/customer/entity/Customer.java
// @Entity
// public class Customer {
// 
//     @Id
//     @GeneratedValue
//     private Long id;
// 
//     private String name;
// 
//     public Customer(String name) {
//         this.name = name;
//     }
// 
//     public Customer() {
//     }
// 
//     public Long getId() {
//         return id;
//     }
// 
//     public void setId(Long id) {
//         this.id = id;
//     }
// 
//     public String getName() {
//         return name;
//     }
// 
//     public void setName(String name) {
//         this.name = name;
//     }
// }
// 
// Path: customer-service/src/main/java/de/codecentric/resilient/customer/exception/CustomerNotFoundException.java
// public class CustomerNotFoundException extends RuntimeException {
//     public CustomerNotFoundException(String message) {
//         super(message);
//     }
// 
//     public CustomerNotFoundException(String message, Throwable cause) {
//         super(message, cause);
//     }
// }
// 
// Path: customer-service/src/main/java/de/codecentric/resilient/customer/service/CustomerService.java
// @Service
// public class CustomerService {
// 
//     private final CustomerRepository customerRepository;
// 
//     @Autowired
//     public CustomerService(CustomerRepository customerRepository) {
// 
//         this.customerRepository = customerRepository;
//     }
// 
//     public Customer findCustomerById(Long customerId) throws CustomerNotFoundException {
// 
//         Customer customer = null;
//         try {
//             customer = customerRepository.findOne(customerId);
// 
//         } catch (Exception e) {
//             throw new CustomerNotFoundException("Error by finding customer by id: " + customerId, e);
//         }
// 
//         if (customer == null) {
//             throw new CustomerNotFoundException("Customer not found by id: " + customerId);
//         }
// 
//         return customer;
// 
//     }
// 
//     public Customer findByName(String name) {
//         Customer customer;
//         try {
//             customer = customerRepository.findByName(name);
// 
//         } catch (Exception e) {
//             throw new CustomerNotFoundException("Error by finding customer by name: " + name, e);
//         }
// 
//         if (customer == null) {
//             throw new CustomerNotFoundException("Customer not found by name: " + name);
//         }
// 
//         return customer;
//     }
// }
// 
// Path: service-library/src/main/java/de/codecentric/resilient/dto/CustomerDTO.java
// @JsonInclude(JsonInclude.Include.NON_NULL)
// public class CustomerDTO {
// 
//     @JsonProperty(required = true)
//     private Long customerId;
// 
//     @JsonProperty(required = true)
//     private String customerName;
// 
//     public CustomerDTO(Long customerId, String customerName) {
//         this.customerId = customerId;
//         this.customerName = customerName;
//     }
// 
//     public CustomerDTO() {
// 
//     }
// 
//     public Long getCustomerId() {
//         return customerId;
//     }
// 
//     public void setCustomerId(Long customerId) {
//         this.customerId = customerId;
//     }
// 
//     public String getCustomerName() {
//         return customerName;
//     }
// 
//     public void setCustomerName(String customerName) {
//         this.customerName = customerName;
//     }
// 
//     @Override
//     public String toString() {
//         final StringBuilder sb = new StringBuilder("CustomerDTO{");
//         sb.append("customerId=").append(customerId);
//         sb.append(", customerName='").append(customerName).append('\'');
//         sb.append('}');
//         return sb.toString();
//     }
// }


import javax.servlet.http.HttpServletRequest;
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.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import de.codecentric.resilient.customer.entity.Customer;
import de.codecentric.resilient.customer.exception.CustomerNotFoundException;
import de.codecentric.resilient.customer.service.CustomerService;
import de.codecentric.resilient.dto.CustomerDTO;

    }

    @RequestMapping(value = "search/name")
    @ResponseBody
    public ResponseEntity<CustomerDTO> searchByName(@RequestParam("name") String name, HttpServletRequest request) {

        Customer customer;
        try {
            customer = customerService.findByName(name);

        } catch (CustomerNotFoundException e) {
            return new ResponseEntity<>(HttpStatus.NOT_FOUND);
        }

        CustomerDTO customerDTO = mapToCustomerDTO(customer);

        appendSpan(customerDTO.getCustomerName(), "customer-name");
        appendSpan(String.valueOf(customerDTO.getCustomerId()), "customer-id");

        return new ResponseEntity<>(customerDTO, HttpStatus.FOUND);

    }

    private CustomerDTO mapToCustomerDTO(Customer customer) {
        return new CustomerDTO(customer.getId(), customer.getName());
    }

    private void appendSpan(String value, String key) {
        Span span = tracer.getCurrentSpan();
// Path: customer-service/src/main/java/de/codecentric/resilient/customer/entity/Customer.java
// @Entity
// public class Customer {
// 
//     @Id
//     @GeneratedValue
//     private Long id;
// 
//     private String name;
// 
//     public Customer(String name) {
//         this.name = name;
//     }
// 
//     public Customer() {
//     }
// 
//     public Long getId() {
//         return id;
//     }
// 
//     public void setId(Long id) {
//         this.id = id;
//     }
// 
//     public String getName() {
//         return name;
//     }
// 
//     public void setName(String name) {
//         this.name = name;
//     }
// }
// 
// Path: customer-service/src/main/java/de/codecentric/resilient/customer/exception/CustomerNotFoundException.java
// public class CustomerNotFoundException extends RuntimeException {
//     public CustomerNotFoundException(String message) {
//         super(message);
//     }
// 
//     public CustomerNotFoundException(String message, Throwable cause) {
//         super(message, cause);
//     }
// }
// 
// Path: customer-service/src/main/java/de/codecentric/resilient/customer/service/CustomerService.java
// @Service
// public class CustomerService {
// 
//     private final CustomerRepository customerRepository;
// 
//     @Autowired
//     public CustomerService(CustomerRepository customerRepository) {
// 
//         this.customerRepository = customerRepository;
//     }
// 
//     public Customer findCustomerById(Long customerId) throws CustomerNotFoundException {
// 
//         Customer customer = null;
//         try {
//             customer = customerRepository.findOne(customerId);
// 
//         } catch (Exception e) {
//             throw new CustomerNotFoundException("Error by finding customer by id: " + customerId, e);
//         }
// 
//         if (customer == null) {
//             throw new CustomerNotFoundException("Customer not found by id: " + customerId);
//         }
// 
//         return customer;
// 
//     }
// 
//     public Customer findByName(String name) {
//         Customer customer;
//         try {
//             customer = customerRepository.findByName(name);
// 
//         } catch (Exception e) {
//             throw new CustomerNotFoundException("Error by finding customer by name: " + name, e);
//         }
// 
//         if (customer == null) {
//             throw new CustomerNotFoundException("Customer not found by name: " + name);
//         }
// 
//         return customer;
//     }
// }
// 
// Path: service-library/src/main/java/de/codecentric/resilient/dto/CustomerDTO.java
// @JsonInclude(JsonInclude.Include.NON_NULL)
// public class CustomerDTO {
// 
//     @JsonProperty(required = true)
//     private Long customerId;
// 
//     @JsonProperty(required = true)
//     private String customerName;
// 
//     public CustomerDTO(Long customerId, String customerName) {
//         this.customerId = customerId;
//         this.customerName = customerName;
//     }
// 
//     public CustomerDTO() {
// 
//     }
// 
//     public Long getCustomerId() {
//         return customerId;
//     }
// 
//     public void setCustomerId(Long customerId) {
//         this.customerId = customerId;
//     }
// 
//     public String getCustomerName() {
//         return customerName;
//     }
// 
//     public void setCustomerName(String customerName) {
//         this.customerName = customerName;
//     }
// 
//     @Override
//     public String toString() {
//         final StringBuilder sb = new StringBuilder("CustomerDTO{");
//         sb.append("customerId=").append(customerId);
//         sb.append(", customerName='").append(customerName).append('\'');
//         sb.append('}');
//         return sb.toString();
//     }
// }


// Path: customer-service/src/main/java/de/codecentric/resilient/customer/rest/CustomerController.java
import javax.servlet.http.HttpServletRequest;
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.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import de.codecentric.resilient.customer.entity.Customer;
import de.codecentric.resilient.customer.exception.CustomerNotFoundException;
import de.codecentric.resilient.customer.service.CustomerService;
import de.codecentric.resilient.dto.CustomerDTO;


    }

    @RequestMapping(value = "search/name")
    @ResponseBody
    public ResponseEntity<CustomerDTO> searchByName(@RequestParam("name") String name, HttpServletRequest request) {

        Customer customer;
        try {
            customer = customerService.findByName(name);

        } catch (CustomerNotFoundException e) {
            return new ResponseEntity<>(HttpStatus.NOT_FOUND);
        }

        CustomerDTO customerDTO = mapToCustomerDTO(customer);

        appendSpan(customerDTO.getCustomerName(), "customer-name");
        appendSpan(String.valueOf(customerDTO.getCustomerId()), "customer-id");

        return new ResponseEntity<>(customerDTO, HttpStatus.FOUND);

    }

    private CustomerDTO mapToCustomerDTO(Customer customer) {
        return new CustomerDTO(customer.getId(), customer.getName());
    }

    private void appendSpan(String value, String key) {
        Span span = tracer.getCurrentSpan();
        String baggageKey = key;