// Path: product-catalog-context/src/main/java/se/citerus/cqrs/bookstore/productcatalog/api/BookDto.java
// public class BookDto extends TransportObject {
// 
//   @NotEmpty
//   @Pattern(regexp = ID_PATTERN)
//   public String bookId;
// 
//   @NotEmpty
//   public String isbn;
// 
//   @NotEmpty
//   public String title;
// 
//   @NotNull
//   public String description;
// 
// }
// 
// Path: product-catalog-context/src/main/java/se/citerus/cqrs/bookstore/productcatalog/api/ProductDto.java
// public class ProductDto extends TransportObject {
// 
//   @NotEmpty
//   @Pattern(regexp = ID_PATTERN)
//   public String productId;
// 
//   @Valid
//   public BookDto book;
// 
//   @Min(0)
//   public long price;
// 
//   @NotEmpty
//   @Pattern(regexp = ID_PATTERN)
//   public String publisherContractId;
// 
// }
// 
// Path: product-catalog-context/src/main/java/se/citerus/cqrs/bookstore/productcatalog/api/ProductDtoFactory.java
// public class ProductDtoFactory {
// 
//   public static ProductDto fromProduct(Product product) {
//     return toProduct(product, toBook(product.book));
//   }
// 
//   private static ProductDto toProduct(Product product, BookDto bookDto) {
//     ProductDto productDto = new ProductDto();
//     productDto.productId = product.productId;
//     productDto.price = product.price;
//     productDto.publisherContractId = product.publisherContractId;
//     productDto.book = bookDto;
//     return productDto;
//   }
// 
//   private static BookDto toBook(Book book) {
//     BookDto bookDto = new BookDto();
//     bookDto.bookId = book.bookId;
//     bookDto.isbn = book.isbn;
//     bookDto.title = book.title;
//     bookDto.description = book.description;
//     return bookDto;
//   }
// 
// }
// 
// Path: product-catalog-context/src/main/java/se/citerus/cqrs/bookstore/productcatalog/domain/Book.java
// public class Book extends ValueObject {
// 
//   public final String bookId;
//   public final String isbn;
//   public final String title;
//   public final String description;
// 
//   public Book(String bookId, String isbn, String title, String description) {
//     this.bookId = bookId;
//     this.isbn = isbn;
//     this.title = title;
//     this.description = description;
//   }
// 
// }
// 
// Path: product-catalog-context/src/main/java/se/citerus/cqrs/bookstore/productcatalog/domain/Product.java
// public class Product extends ValueObject {
// 
//   public final String productId;
//   public final Book book;
//   public final long price;
//   public final String publisherContractId;
// 
//   public Product(String productId, Book book, long price, String publisherContractId) {
//     this.productId = productId;
//     this.book = book;
//     this.price = price;
//     this.publisherContractId = publisherContractId;
//   }
// 
// }
// 
// Path: product-catalog-context/src/main/java/se/citerus/cqrs/bookstore/productcatalog/domain/ProductRepository.java
// public interface ProductRepository {
// 
//   Collection<Product> getProducts();
// 
//   Product getProduct(String productId);
// 
//   void save(Product product);
// 
// }


import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import se.citerus.cqrs.bookstore.productcatalog.api.BookDto;
import se.citerus.cqrs.bookstore.productcatalog.api.ProductDto;
import se.citerus.cqrs.bookstore.productcatalog.api.ProductDtoFactory;
import se.citerus.cqrs.bookstore.productcatalog.domain.Book;
import se.citerus.cqrs.bookstore.productcatalog.domain.Product;
import se.citerus.cqrs.bookstore.productcatalog.domain.ProductRepository;
import javax.validation.Valid;
import javax.ws.rs.*;
import java.util.ArrayList;
import java.util.Collection;
import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
package se.citerus.cqrs.bookstore.productcatalog.resource;




@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) {
// Path: product-catalog-context/src/main/java/se/citerus/cqrs/bookstore/productcatalog/api/BookDto.java
// public class BookDto extends TransportObject {
// 
//   @NotEmpty
//   @Pattern(regexp = ID_PATTERN)
//   public String bookId;
// 
//   @NotEmpty
//   public String isbn;
// 
//   @NotEmpty
//   public String title;
// 
//   @NotNull
//   public String description;
// 
// }
// 
// Path: product-catalog-context/src/main/java/se/citerus/cqrs/bookstore/productcatalog/api/ProductDto.java
// public class ProductDto extends TransportObject {
// 
//   @NotEmpty
//   @Pattern(regexp = ID_PATTERN)
//   public String productId;
// 
//   @Valid
//   public BookDto book;
// 
//   @Min(0)
//   public long price;
// 
//   @NotEmpty
//   @Pattern(regexp = ID_PATTERN)
//   public String publisherContractId;
// 
// }
// 
// Path: product-catalog-context/src/main/java/se/citerus/cqrs/bookstore/productcatalog/api/ProductDtoFactory.java
// public class ProductDtoFactory {
// 
//   public static ProductDto fromProduct(Product product) {
//     return toProduct(product, toBook(product.book));
//   }
// 
//   private static ProductDto toProduct(Product product, BookDto bookDto) {
//     ProductDto productDto = new ProductDto();
//     productDto.productId = product.productId;
//     productDto.price = product.price;
//     productDto.publisherContractId = product.publisherContractId;
//     productDto.book = bookDto;
//     return productDto;
//   }
// 
//   private static BookDto toBook(Book book) {
//     BookDto bookDto = new BookDto();
//     bookDto.bookId = book.bookId;
//     bookDto.isbn = book.isbn;
//     bookDto.title = book.title;
//     bookDto.description = book.description;
//     return bookDto;
//   }
// 
// }
// 
// Path: product-catalog-context/src/main/java/se/citerus/cqrs/bookstore/productcatalog/domain/Book.java
// public class Book extends ValueObject {
// 
//   public final String bookId;
//   public final String isbn;
//   public final String title;
//   public final String description;
// 
//   public Book(String bookId, String isbn, String title, String description) {
//     this.bookId = bookId;
//     this.isbn = isbn;
//     this.title = title;
//     this.description = description;
//   }
// 
// }
// 
// Path: product-catalog-context/src/main/java/se/citerus/cqrs/bookstore/productcatalog/domain/Product.java
// public class Product extends ValueObject {
// 
//   public final String productId;
//   public final Book book;
//   public final long price;
//   public final String publisherContractId;
// 
//   public Product(String productId, Book book, long price, String publisherContractId) {
//     this.productId = productId;
//     this.book = book;
//     this.price = price;
//     this.publisherContractId = publisherContractId;
//   }
// 
// }
// 
// Path: product-catalog-context/src/main/java/se/citerus/cqrs/bookstore/productcatalog/domain/ProductRepository.java
// public interface ProductRepository {
// 
//   Collection<Product> getProducts();
// 
//   Product getProduct(String productId);
// 
//   void save(Product product);
// 
// }


// Path: product-catalog-context/src/main/java/se/citerus/cqrs/bookstore/productcatalog/resource/ProductResource.java
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import se.citerus.cqrs.bookstore.productcatalog.api.BookDto;
import se.citerus.cqrs.bookstore.productcatalog.api.ProductDto;
import se.citerus.cqrs.bookstore.productcatalog.api.ProductDtoFactory;
import se.citerus.cqrs.bookstore.productcatalog.domain.Book;
import se.citerus.cqrs.bookstore.productcatalog.domain.Product;
import se.citerus.cqrs.bookstore.productcatalog.domain.ProductRepository;
import javax.validation.Valid;
import javax.ws.rs.*;
import java.util.ArrayList;
import java.util.Collection;
import static javax.ws.rs.core.MediaType.APPLICATION_JSON;

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




@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;