예제 #1
0
  @Override
  @Interceptors({CartItemInterceptor.class})
  public CartItemModel addCartItem(String cartUid, String productCode, Integer quantity)
      throws EntityNotFoundException, ModelValidationException {
    LOG.trace("ENTER addCartItem(cartUid, productCode, price, quantity)");
    final CartItemEntity cartItemEntity = new CartItemEntity();
    try {
      // Get Cart Entity
      final TypedQuery<CartModel> cartQuery =
          entityManager.createNamedQuery(CartEntity.QUERY_UUID, CartModel.class);
      cartQuery.setParameter("uuid", UUIDUtils.getIdAsByte(UUIDUtils.fromString(cartUid)));
      final CartModel cart = cartQuery.getSingleResult();

      LOG.debug("cart = {}", cart.toString());

      // Get Product Entity
      final TypedQuery<ProductModel> productQuery =
          entityManager.createNamedQuery(ProductEntity.QUERY_PRODUCT_CODE, ProductModel.class);
      productQuery.setParameter("productCode", productCode);
      final ProductModel productInfo = productQuery.getSingleResult();

      LOG.debug("productInfo = {}", productInfo.toString());

      cartItemEntity.setCart(cart);
      cartItemEntity.setProductInfo(productInfo);
      cartItemEntity.setPrice(productInfo.getProductPrice());
      cartItemEntity.setQuantity(quantity);

      cartItemEJB.persist(cartItemEntity);
      return cartItemEntity;
    } finally {
      LOG.trace("EXIT addCartItem(cartUid, productCode, price, quantity)");
    }
  }
예제 #2
0
 @Override
 @Interceptors({CartInterceptor.class})
 public CartModel findByUUID(String uuid) {
   LOG.trace("ENTER findByUUID(uuid)");
   try {
     final TypedQuery<CartEntity> cartQuery =
         entityManager.createNamedQuery(CartEntity.QUERY_UUID, CartEntity.class);
     cartQuery.setParameter("uuid", UUIDUtils.getIdAsByte(UUIDUtils.fromString(uuid)));
     return cartQuery.getSingleResult();
   } finally {
     LOG.trace("EXIT findByUUID(uuid)");
   }
 }