public Product setProduct(Product product) { Product _product = null; // Retreive product if (product.getIdProduct() != 0) { _product = this.getProduct(product.getIdProduct()); } else { _product = this.getProduct( product.getProductConf(), product.getSerialNumber(), product.getDatecode()); } // Update product components List<Product> _productComponents = this.updateProductComponents(this.getProductComponents(product)); // Update product softwares List<Software> _productSoftwares = this.updateProductSoftwares(product.getProductSoftwares()); // Save product _product = this.setProduct( _product, product.getProductConf(), product.getSerialNumber(), product.getDatecode(), _productComponents, _productSoftwares); return _product; }
/* * Création de la liste des composants du produit à partir d'une liste de * composants. * * @param productComponents Liste des composants. */ private List<Product> updateProductComponents(List<Product> productComponents) { List<Product> _productComponents = new ArrayList<Product>(); if (null != productComponents) { ProductConf _productConf = null; String _datecode; String _serialNumber; String _provider; for (Product _productComponent : productComponents) { _productConf = _productComponent.getProductConf(); _serialNumber = _productComponent.getSerialNumber(); _datecode = _productComponent.getDatecode(); _provider = _productComponent.getProviderCode(); // Retreive component _productComponent = this.getProduct(_productConf, _serialNumber, _datecode); if (null == _productComponent) { // New component _productComponent = this.addProduct(_productConf, _serialNumber, _datecode, _provider); } else { // Exiting component _productComponent.setDatecode(_datecode); _productComponent.setSerialNumber(_serialNumber); _productComponent.setProviderCode(_provider); this.updateProduct(_productComponent); } _productComponents.add(_productComponent); } } return _productComponents; }