Added utility structures + tests
This commit is contained in:
@@ -0,0 +1,75 @@
|
||||
package de.rwu.easydrop.service.retriever;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.naming.ConfigurationException;
|
||||
|
||||
import de.rwu.easydrop.model.Product;
|
||||
import de.rwu.easydrop.model.ProductCatalogue;
|
||||
import de.rwu.easydrop.util.ProductsConfig;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* Retrieves data for all products of multiple catalogues.
|
||||
*
|
||||
* @since 0.2.0
|
||||
*/
|
||||
@Data
|
||||
public class CatalogueRetriever {
|
||||
/**
|
||||
* User-configured products.
|
||||
*/
|
||||
private ProductsConfig productsConfig;
|
||||
/**
|
||||
* Product Retriever.
|
||||
*/
|
||||
private ProductRetriever productRetriever;
|
||||
/**
|
||||
* Product catalogue.
|
||||
*/
|
||||
private List<ProductCatalogue> productCatalogues;
|
||||
|
||||
/**
|
||||
* Creates a new instance.
|
||||
*
|
||||
* @param newProductsConfig
|
||||
* @param newProductRetriever
|
||||
*/
|
||||
public CatalogueRetriever(
|
||||
final ProductsConfig newProductsConfig, final ProductRetriever newProductRetriever) {
|
||||
productRetriever = newProductRetriever;
|
||||
productsConfig = newProductsConfig;
|
||||
productCatalogues = new ArrayList<>();
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads catalogues as configured by the user.
|
||||
*
|
||||
* @throws ConfigurationException
|
||||
*/
|
||||
public void loadCatalogues() throws ConfigurationException {
|
||||
productsConfig.loadConfig();
|
||||
|
||||
for (ProductCatalogue pCat : productsConfig.getProductCatalogues()) {
|
||||
ProductCatalogue newProductCatalogue = new ProductCatalogue(
|
||||
pCat.getProductName(), pCat.getDescription());
|
||||
|
||||
for (Product product : pCat.getProducts()) {
|
||||
Product newProduct = new Product();
|
||||
newProduct.setDataOrigin(product.getDataOrigin());
|
||||
newProduct.setProductId(product.getProductId());
|
||||
|
||||
if (product.getDataOrigin().equals("Amazon")) {
|
||||
newProduct = productRetriever.getProductFromAmazon(product.getProductId());
|
||||
} else if (product.getDataOrigin().equals("eBay")) {
|
||||
newProduct = productRetriever.getProductFromEbay(product.getProductId());
|
||||
}
|
||||
|
||||
newProductCatalogue.addProduct(newProduct);
|
||||
}
|
||||
|
||||
productCatalogues.add(newProductCatalogue);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user