// Path: product-catalog-context/src/main/java/se/citerus/cqrs/bookstore/productcatalog/infrastructure/InMemoryProductRepository.java
// public class InMemoryProductRepository implements ProductRepository {
// 
//   private Map<String, Product> products = new HashMap<>();
// 
//   private static final Comparator<Product> PRODUCT_COMPARATOR = new Comparator<Product>() {
//     @Override
//     public int compare(Product o1, Product o2) {
//       return o1.book.title.compareTo(o2.book.title);
//     }
//   };
// 
//   @Override
//   public List<Product> getProducts() {
//     List<Product> values = new ArrayList<>(products.values());
//     Collections.sort(values, PRODUCT_COMPARATOR);
//     return values;
//   }
// 
//   @Override
//   public Product getProduct(String productId) {
//     return products.get(productId);
//   }
// 
//   @Override
//   public void save(Product product) {
//     this.products.put(product.productId, product);
//   }
// 
// }
// 
// Path: product-catalog-context/src/main/java/se/citerus/cqrs/bookstore/productcatalog/resource/ProductResource.java
// @Path("products")
// @Produces(APPLICATION_JSON)
// @Consumes(APPLICATION_JSON)
// public class ProductResource {
// 
//   private final Logger logger = LoggerFactory.getLogger(getClass());
//   private ProductRepository productRepository;
// 
//   public ProductResource(ProductRepository productRepository) {
//     this.productRepository = productRepository;
//   }
// 
//   @GET
//   @Path("{productId}")
//   public ProductDto getProduct(@PathParam("productId") String productId) {
//     Product product = productRepository.getProduct(productId);
//     if (product == null) {
//       throw new IllegalArgumentException("No such product: " + productId);
//     }
//     logger.info("Returning product with id [{}]", product.productId);
//     return ProductDtoFactory.fromProduct(product);
//   }
// 
//   @POST
//   public void createProduct(@Valid ProductDto request) {
//     BookDto bookDto = request.book;
//     Book book = new Book(request.book.bookId, bookDto.isbn, bookDto.title, bookDto.description);
//     Product product = new Product(request.productId, book, request.price, request.publisherContractId);
//     logger.info("Saving product with id [{}]", request.productId);
//     productRepository.save(product);
//   }
// 
//   @GET
//   public Collection<ProductDto> getProducts() {
//     Collection<ProductDto> products = new ArrayList<>();
//     for (Product product : productRepository.getProducts()) {
//       products.add(ProductDtoFactory.fromProduct(product));
//     }
//     logger.info("Returning [{}] products", products.size());
//     return products;
//   }
// 
// }


import com.fasterxml.jackson.databind.ObjectMapper;
import io.dropwizard.Application;
import io.dropwizard.setup.Bootstrap;
import io.dropwizard.setup.Environment;
import org.eclipse.jetty.servlets.CrossOriginFilter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import se.citerus.cqrs.bookstore.productcatalog.infrastructure.InMemoryProductRepository;
import se.citerus.cqrs.bookstore.productcatalog.resource.ProductResource;
import javax.servlet.DispatcherType;
import javax.servlet.FilterRegistration;
import java.util.EnumSet;
import static com.fasterxml.jackson.databind.SerializationFeature.INDENT_OUTPUT;
import static com.fasterxml.jackson.databind.SerializationFeature.WRITE_DATES_AS_TIMESTAMPS;
package se.citerus.cqrs.bookstore.productcatalog.application;




public class ProductCatalogApplication extends Application<ProductCatalogConfig> {

  private final Logger logger = LoggerFactory.getLogger(getClass());

  @Override
  public void initialize(Bootstrap<ProductCatalogConfig> bootstrap) {
  }

  @Override
  public void run(ProductCatalogConfig configuration, Environment environment) {
    ObjectMapper objectMapper = environment.getObjectMapper();
    objectMapper.enable(INDENT_OUTPUT);
    objectMapper.enable(WRITE_DATES_AS_TIMESTAMPS);

// Path: product-catalog-context/src/main/java/se/citerus/cqrs/bookstore/productcatalog/infrastructure/InMemoryProductRepository.java
// public class InMemoryProductRepository implements ProductRepository {
// 
//   private Map<String, Product> products = new HashMap<>();
// 
//   private static final Comparator<Product> PRODUCT_COMPARATOR = new Comparator<Product>() {
//     @Override
//     public int compare(Product o1, Product o2) {
//       return o1.book.title.compareTo(o2.book.title);
//     }
//   };
// 
//   @Override
//   public List<Product> getProducts() {
//     List<Product> values = new ArrayList<>(products.values());
//     Collections.sort(values, PRODUCT_COMPARATOR);
//     return values;
//   }
// 
//   @Override
//   public Product getProduct(String productId) {
//     return products.get(productId);
//   }
// 
//   @Override
//   public void save(Product product) {
//     this.products.put(product.productId, product);
//   }
// 
// }
// 
// Path: product-catalog-context/src/main/java/se/citerus/cqrs/bookstore/productcatalog/resource/ProductResource.java
// @Path("products")
// @Produces(APPLICATION_JSON)
// @Consumes(APPLICATION_JSON)
// public class ProductResource {
// 
//   private final Logger logger = LoggerFactory.getLogger(getClass());
//   private ProductRepository productRepository;
// 
//   public ProductResource(ProductRepository productRepository) {
//     this.productRepository = productRepository;
//   }
// 
//   @GET
//   @Path("{productId}")
//   public ProductDto getProduct(@PathParam("productId") String productId) {
//     Product product = productRepository.getProduct(productId);
//     if (product == null) {
//       throw new IllegalArgumentException("No such product: " + productId);
//     }
//     logger.info("Returning product with id [{}]", product.productId);
//     return ProductDtoFactory.fromProduct(product);
//   }
// 
//   @POST
//   public void createProduct(@Valid ProductDto request) {
//     BookDto bookDto = request.book;
//     Book book = new Book(request.book.bookId, bookDto.isbn, bookDto.title, bookDto.description);
//     Product product = new Product(request.productId, book, request.price, request.publisherContractId);
//     logger.info("Saving product with id [{}]", request.productId);
//     productRepository.save(product);
//   }
// 
//   @GET
//   public Collection<ProductDto> getProducts() {
//     Collection<ProductDto> products = new ArrayList<>();
//     for (Product product : productRepository.getProducts()) {
//       products.add(ProductDtoFactory.fromProduct(product));
//     }
//     logger.info("Returning [{}] products", products.size());
//     return products;
//   }
// 
// }


// Path: product-catalog-context/src/main/java/se/citerus/cqrs/bookstore/productcatalog/application/ProductCatalogApplication.java
import com.fasterxml.jackson.databind.ObjectMapper;
import io.dropwizard.Application;
import io.dropwizard.setup.Bootstrap;
import io.dropwizard.setup.Environment;
import org.eclipse.jetty.servlets.CrossOriginFilter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import se.citerus.cqrs.bookstore.productcatalog.infrastructure.InMemoryProductRepository;
import se.citerus.cqrs.bookstore.productcatalog.resource.ProductResource;
import javax.servlet.DispatcherType;
import javax.servlet.FilterRegistration;
import java.util.EnumSet;
import static com.fasterxml.jackson.databind.SerializationFeature.INDENT_OUTPUT;
import static com.fasterxml.jackson.databind.SerializationFeature.WRITE_DATES_AS_TIMESTAMPS;

package se.citerus.cqrs.bookstore.productcatalog.application;




public class ProductCatalogApplication extends Application<ProductCatalogConfig> {

  private final Logger logger = LoggerFactory.getLogger(getClass());

  @Override
  public void initialize(Bootstrap<ProductCatalogConfig> bootstrap) {
  }

  @Override
  public void run(ProductCatalogConfig configuration, Environment environment) {
    ObjectMapper objectMapper = environment.getObjectMapper();
    objectMapper.enable(INDENT_OUTPUT);
    objectMapper.enable(WRITE_DATES_AS_TIMESTAMPS);

    environment.jersey().register(new ProductResource(new InMemoryProductRepository()));