// Path: src/main/java/io/chucknorris/lib/exception/EntityNotFoundException.java
// @ResponseStatus(value = HttpStatus.NOT_FOUND)
// public class EntityNotFoundException extends RuntimeException {
// 
//   public EntityNotFoundException(String message) {
//     super(message);
//   }
// }


import io.chucknorris.lib.exception.EntityNotFoundException;
import java.util.Arrays;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.Size;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;
   * Returns all joke categories delimited by a new line.
   */
  public @ResponseBody @RequestMapping(
      value = "/categories",
      method = RequestMethod.GET,
      headers = HttpHeaders.ACCEPT + "=" + MediaType.TEXT_PLAIN_VALUE,
      produces = MediaType.TEXT_PLAIN_VALUE
  ) String getCategoryValues() {
    StringBuilder stringBuilder = new StringBuilder();

    for (String category : jokeRepository.findAllCategories()) {
      stringBuilder.append(category + '\n');
    }

    return stringBuilder.toString();
  }

  /**
   * Returns a Joke {@link Joke} by id.
   *
   * @param id The joke id
   * @return joke
   */
  public @ResponseBody @RequestMapping(
      value = "/{id}",
      method = RequestMethod.GET,
      headers = HttpHeaders.ACCEPT + "=" + MediaType.APPLICATION_JSON_VALUE,
      produces = MediaType.APPLICATION_JSON_VALUE
  ) Joke getJoke(@PathVariable String id) {
    return jokeRepository.findById(id).orElseThrow(
// Path: src/main/java/io/chucknorris/lib/exception/EntityNotFoundException.java
// @ResponseStatus(value = HttpStatus.NOT_FOUND)
// public class EntityNotFoundException extends RuntimeException {
// 
//   public EntityNotFoundException(String message) {
//     super(message);
//   }
// }


// Path: src/main/java/io/chucknorris/api/joke/JokeController.java
import io.chucknorris.lib.exception.EntityNotFoundException;
import java.util.Arrays;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.Size;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

   * Returns all joke categories delimited by a new line.
   */
  public @ResponseBody @RequestMapping(
      value = "/categories",
      method = RequestMethod.GET,
      headers = HttpHeaders.ACCEPT + "=" + MediaType.TEXT_PLAIN_VALUE,
      produces = MediaType.TEXT_PLAIN_VALUE
  ) String getCategoryValues() {
    StringBuilder stringBuilder = new StringBuilder();

    for (String category : jokeRepository.findAllCategories()) {
      stringBuilder.append(category + '\n');
    }

    return stringBuilder.toString();
  }

  /**
   * Returns a Joke {@link Joke} by id.
   *
   * @param id The joke id
   * @return joke
   */
  public @ResponseBody @RequestMapping(
      value = "/{id}",
      method = RequestMethod.GET,
      headers = HttpHeaders.ACCEPT + "=" + MediaType.APPLICATION_JSON_VALUE,
      produces = MediaType.APPLICATION_JSON_VALUE
  ) Joke getJoke(@PathVariable String id) {
    return jokeRepository.findById(id).orElseThrow(
        () -> new EntityNotFoundException("Joke with id \"" + id + "\" not found.")