Esempio n. 1
0
  @Override
  public ArrayList<ProductDTO> getProducts() throws NotLoggedInException {
    List<Product> products = new ArrayList<Product>();
    ArrayList<ProductDTO> productsDTO = new ArrayList<ProductDTO>();

    PersistenceManager pm = getPersistenceManager();
    try {
      Query q = pm.newQuery(Product.class);
      products = (List<Product>) q.execute();
      for (Product productItem : products) {

        CategoryDTO categoryDTO = getCategoryForCombo(productItem.getCategoryid());

        ProductDTO productDTO =
            new ProductDTO(
                productItem.getId(),
                productItem.getName(),
                productItem.getPrice(),
                productItem.getDescription(),
                productItem.getDetalle(),
                productItem.getImage(),
                productItem.getImageCarrito(),
                categoryDTO);
        productsDTO.add(productDTO);
      }
    } finally {
      pm.close();
    }
    return productsDTO;
  }
Esempio n. 2
0
  private ArrayList<ProductDTO> executeQuery(Query query) throws NotLoggedInException {
    List<Product> products = (List<Product>) query.execute();
    ArrayList<ProductDTO> productsDTO = new ArrayList<ProductDTO>();

    for (Product productItem : products) {
      CategoryDTO categoryDTO = getCategoryForCombo(productItem.getCategoryid());
      ProductDTO productDTO =
          new ProductDTO(
              productItem.getId(),
              productItem.getName(),
              productItem.getPrice(),
              productItem.getDescription(),
              productItem.getDetalle(),
              productItem.getImage().toString(),
              productItem.getImageCarrito(),
              categoryDTO);

      productsDTO.add(productDTO);
    }
    return productsDTO;
  }
Esempio n. 3
0
  public ProductDTO getProduct(Long productId) throws NotLoggedInException {
    ProductDTO productDTO = null;
    PersistenceManager pm = getPersistenceManager();
    try {
      Product productItem = pm.getObjectById(Product.class, productId);

      CategoryDTO categoryDTO = getCategoryForCombo(productItem.getCategoryid());

      productDTO =
          new ProductDTO(
              productItem.getId(),
              productItem.getName(),
              productItem.getPrice(),
              productItem.getDescription(),
              productItem.getDetalle(),
              productItem.getImage().toString(),
              productItem.getImageCarrito(),
              categoryDTO);

    } finally {
      pm.close();
    }
    return productDTO;
  }