package unal.architecture.service;

import unal.architecture.dao.ProductDAO;
import unal.architecture.entity.Product;

import javax.annotation.security.RolesAllowed;
import javax.ejb.EJB;
import javax.ejb.Stateless;
import javax.jws.WebMethod;
import javax.jws.WebService;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import java.util.List;

@Stateless
@WebService
@RolesAllowed({"CLIENT"})
public class ProductService {
    @PersistenceContext
    private EntityManager em;
    @EJB
    ProductDAO productDAO;

    @WebMethod
    public List<Product> getProducts() {
        return productDAO.findAll();
    }

    @WebMethod
    public Product getProduct(long id) {
        return em.find(Product.class, id);
    }
}

@@ -749,11 +749,395 @@
 );%0A    %7D
+%0A%0A    @WebMethod%0A    public boolean orderProduct(long id, int ammount) %7B%0A        Product product = em.find(Product.class, id);%0A        if (product == null) %7B%0A            return false;%0A        %7D%0A        int inventory = product.getInventory() - ammount;%0A        if (inventory %3C 0) %7B%0A            return false;%0A        %7D%0A        product.setInventory(inventory);%0A        return true;%0A    %7D
 %0A%7D%0A

Order product in ProductWS.