Examples of Eshop


Examples of cz.cvut.fel.wa2.interior.entity.Eshop

    public Eshop findEagerlyById(Class clazz, Long id) {
        PersistenceManager pm = createPersistenceManager();
        Key key = KeyFactory.createKey(clazz.getSimpleName(), id);

        Eshop eshop = null;
        try {
            eshop = (Eshop) pm.getObjectById(clazz, key);
            for (Product product : eshop.getProducts()) {
                product.getName();
                product.getCategory();
                Set<Product> similarProducts = new HashSet<>();
                for (Key similarProductKey : product.getSimilarProductKeys()) {
                    similarProducts.add((Product) pm.getObjectById(Product.class, similarProductKey));
View Full Code Here

Examples of cz.cvut.fel.wa2.interior.entity.Eshop

    @Autowired
    private EshopDAO eshopDAO;

    @Override
    public ProductDTO create(UriInfo uriInfo, Long eshopId, ProductDTO productDTO) throws NotExistingEntityException {
        Eshop eshop = eshopDAO.findById(Eshop.class, eshopId);
        if (eshop == null) {
            throw new NotExistingEntityException("E-shop with ID " + eshopId + " does not exist.");
        }

        Category category = null;
        if (productDTO.getCategory() != null) {
            category = categoryDAO.findById(Category.class, productDTO.getCategory().getId());
            if (category == null) {
                throw new NotExistingEntityException("Category with ID " + productDTO.getCategory().getId() + " does not exist.");
            }
        }

        Product product = new Product(productDTO.getName(), productDTO.getDescription(), category, eshop, productDTO.getUrl(), productDTO.getPrice(), productDTO.getPriceWithVAT(), productDTO.getImageURL());
        eshop.addProduct(product);

        eshopDAO.persist(eshop);
        return new ProductDTO(product, uriInfo);
    }
View Full Code Here

Examples of cz.cvut.fel.wa2.interior.entity.Eshop

        return new ProductDTO(product, uriInfo);
    }

    @Override
    public void update(Long eshopId, Long productId, ProductDTO productDTO) throws NotExistingEntityException {
        Eshop eshop = eshopDAO.findEagerlyById(Eshop.class, eshopId);
        if (eshop == null) {
            throw new NotExistingEntityException("E-shop with ID " + eshopId + " does not exist.");
        }

        Product product = productDAO.findByComplexId(Product.class, productId, Eshop.class, eshopId);
        if (product == null) {
            throw new NotExistingEntityException("Product with ID " + productId + " does not exist.");
        }

        Category category = null;
        if (productDTO.getCategory() != null) {
            category = categoryDAO.findById(Category.class, productDTO.getCategory().getId());
            if (category == null) {
                throw new NotExistingEntityException("Category with ID " + productDTO.getCategory().getId() + " does not exist.");
            }
        }

        for (Product productItem : eshop.getProducts()) {
            if (productItem.equals(product)) {
                productItem.setName(productDTO.getName());
                productItem.setDescription(productDTO.getDescription());
                productItem.setCategory(category);
                productItem.setEshop(eshop);
View Full Code Here

Examples of cz.cvut.fel.wa2.interior.entity.Eshop

    }

    @Override
    public void linkProduct(Long eshopId, Long productId, Long linkedEshopId, Long linkedProductId) throws NotExistingEntityException {

        Eshop eshop = eshopDAO.findEagerlyById(Eshop.class, eshopId);
        if (eshop == null) {
            throw new NotExistingEntityException("E-shop with ID " + eshopId + " does not exist.");
        }

        Product product = productDAO.findByComplexId(Product.class, productId, Eshop.class, eshopId);
        if (product == null) {
            throw new NotExistingEntityException("Product with ID " + productId + " does not exist.");
        }

        Product linkedProduct = productDAO.findByComplexId(Product.class, linkedProductId, Eshop.class, linkedEshopId);
        if (linkedProduct == null) {
            throw new NotExistingEntityException("Product with ID " + linkedProductId + " does not exist.");
        }

        if (eshopId.equals(linkedEshopId)) {
            for (Product productItem : eshop.getProducts()) {
                if (productItem.equals(product)) {
                    productItem.addSimilarProduct(linkedProduct);
                } else if (productItem.equals(linkedProduct)) {
                    productItem.addSimilarProduct(product);
                }
            }
            eshopDAO.update(eshop);
        } else {
            Eshop linkedEshop = eshopDAO.findEagerlyById(Eshop.class, linkedEshopId);
            if (linkedEshop == null) {
                throw new NotExistingEntityException("E-shop with ID " + linkedEshopId + " does not exist.");
            }

            for (Product productItem : eshop.getProducts()) {
                if (productItem.equals(product)) {
                    productItem.addSimilarProduct(linkedProduct);
                    break;
                }
            }

            for (Product productItem : linkedEshop.getProducts()) {
                if (productItem.equals(linkedProduct)) {
                    productItem.addSimilarProduct(product);
                    break;
                }
            }
View Full Code Here

Examples of cz.cvut.fel.wa2.interior.entity.Eshop

        }
    }

    @Override
    public void unlinkProduct(Long eshopId, Long productId, Long linkedEshopId, Long linkedProductId) throws NotExistingEntityException {
        Eshop eshop = eshopDAO.findEagerlyById(Eshop.class, eshopId);
        if (eshop == null) {
            throw new NotExistingEntityException("E-shop with ID " + eshopId + " does not exist.");
        }

        Product product = productDAO.findByComplexId(Product.class, productId, Eshop.class, eshopId);
        if (product == null) {
            throw new NotExistingEntityException("Product with ID " + productId + " does not exist.");
        }

        Product linkedProduct = productDAO.findByComplexId(Product.class, linkedProductId, Eshop.class, linkedEshopId);
        if (linkedProduct == null) {
            throw new NotExistingEntityException("Product with ID " + linkedProductId + " does not exist.");
        }

        if (eshopId.equals(linkedEshopId)) {
            for (Product productItem : eshop.getProducts()) {
                if (productItem.equals(product)) {
                    productItem.removeSimilarProduct(linkedProduct);
                } else if (productItem.equals(linkedProduct)) {
                    productItem.removeSimilarProduct(product);
                }
            }
            eshopDAO.update(eshop);
        } else {
            Eshop linkedEshop = eshopDAO.findEagerlyById(Eshop.class, linkedEshopId);
            if (linkedEshop == null) {
                throw new NotExistingEntityException("E-shop with ID " + linkedEshopId + " does not exist.");
            }

            for (Product productItem : eshop.getProducts()) {
                if (productItem.equals(product)) {
                    productItem.removeSimilarProduct(linkedProduct);
                    break;
                }
            }

            for (Product productItem : linkedEshop.getProducts()) {
                if (productItem.equals(linkedProduct)) {
                    productItem.removeSimilarProduct(product);
                    break;
                }
            }
View Full Code Here

Examples of cz.cvut.fel.wa2.interior.entity.Eshop

        return new Result<>(productDTOs, count);
    }

    @Override
    public Result<ProductDTO> findByEshop(UriInfo uriInfo, Long eshopId, String order, Integer base, Integer offset) throws NotExistingEntityException {
        Eshop eshop = eshopDAO.findById(Eshop.class, eshopId);
        if (eshop == null) {
            throw new NotExistingEntityException("E-shop with ID " + eshopId + " does not exist.");
        }

        order = order != null ? order : "name";
        List<Product> products = productDAO.findByProperty(Product.class, "eshop", Key.class, eshop.getKey(), order, true, base, offset);
        long count = productDAO.findByPropertyCount(Product.class, "eshop", Key.class, eshop.getKey());

        List<ProductDTO> productDTOs = new ArrayList<>();
        for (Product product : products) {
            productDTOs.add(new ProductDTO(product, uriInfo));
        }
View Full Code Here

Examples of cz.cvut.fel.wa2.interior.entity.Eshop

    @Autowired
    private FeedReader feedReader;

    @Override
    public EshopDTO create(UriInfo uriInfo, EshopDTO eshopDTO) {
        Eshop eshop = new Eshop(eshopDTO.getName(), eshopDTO.getWeb(), eshopDTO.getFeed());

        try {
            if (eshop.getFeed() != null && !eshop.getFeed().trim().isEmpty()) {
                feedReader.parseFeed(eshop);
            }
        } catch (FeedNotFoundException | FeedParsingException ex) {
            Logger.getLogger(EshopServiceImpl.class.getName()).log(Level.SEVERE, null, ex);
        } finally {
View Full Code Here

Examples of cz.cvut.fel.wa2.interior.entity.Eshop

        return new EshopDTO(eshop, uriInfo);
    }

    @Override
    public void update(Long id, EshopDTO eshopDTO) throws NotExistingEntityException {
        Eshop eshop = eshopDAO.findById(Eshop.class, id);
        if (eshop == null) {
            throw new NotExistingEntityException("E-shop with ID " + id + " does not exist.");
        }
        eshop.setName(eshopDTO.getName());
        eshop.setWeb(eshopDTO.getWeb());
        eshop.setFeed(eshopDTO.getFeed());
        eshopDAO.update(eshop);
    }
View Full Code Here

Examples of cz.cvut.fel.wa2.interior.entity.Eshop

        eshopDAO.removeById(Eshop.class, id);
    }

    @Override
    public EshopDTO findById(UriInfo uriInfo, Long id) throws NotExistingEntityException {
        Eshop eshop = eshopDAO.findById(Eshop.class, id);
        if (eshop == null) {
            throw new NotExistingEntityException("E-shop with ID " + id + " does not exist.");
        }

        return new EshopDTO(eshop, uriInfo);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.