Webshops refactoring + checkstyle
This commit is contained in:
@@ -5,7 +5,6 @@ import java.util.List;
|
||||
|
||||
import javax.naming.ConfigurationException;
|
||||
|
||||
import de.rwu.easydrop.exception.InvalidProductException;
|
||||
import de.rwu.easydrop.model.Product;
|
||||
import de.rwu.easydrop.model.ProductCatalogue;
|
||||
import de.rwu.easydrop.util.ProductsConfig;
|
||||
@@ -58,16 +57,9 @@ public class CatalogueRetriever {
|
||||
|
||||
for (Product product : pCat.getProducts()) {
|
||||
Product newProduct = new Product();
|
||||
newProduct.setDataOrigin(product.getDataOrigin());
|
||||
newProduct.setProductId(product.getProductId());
|
||||
|
||||
if (newProduct.getDataOrigin().equals("Amazon")) {
|
||||
newProduct = productRetriever.getProductFromAmazon(product.getProductId());
|
||||
} else if (newProduct.getDataOrigin().equals("eBay")) {
|
||||
newProduct = productRetriever.getProductFromEbay(product.getProductId());
|
||||
} else {
|
||||
throw new InvalidProductException("Product data origin is invalid");
|
||||
}
|
||||
newProduct = productRetriever.getProductFromWebshop(product.getDataOrigin(),
|
||||
product.getProductId());
|
||||
|
||||
newProductCatalogue.addProduct(newProduct);
|
||||
}
|
||||
|
||||
@@ -1,14 +1,5 @@
|
||||
package de.rwu.easydrop.service.retriever;
|
||||
|
||||
import de.rwu.easydrop.model.Offer;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class OfferRetriever {
|
||||
|
||||
public List<Offer> loadOffers() {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import de.rwu.easydrop.api.client.EbayItemDataSource;
|
||||
import de.rwu.easydrop.api.dto.ProductDTO;
|
||||
import de.rwu.easydrop.data.connector.AbstractProductPersistence;
|
||||
import de.rwu.easydrop.model.Product;
|
||||
import de.rwu.easydrop.model.Webshop;
|
||||
import de.rwu.easydrop.service.mapping.ProductMapper;
|
||||
import de.rwu.easydrop.service.validation.ProductValidator;
|
||||
|
||||
@@ -21,9 +22,9 @@ public class ProductRetriever {
|
||||
private DataSourceFactory dataSourceFactory;
|
||||
|
||||
/**
|
||||
* @param newDataSourceFactory the dataSourceFactory to set
|
||||
* @param newDataSourceFactory the WebshopFactory to set
|
||||
*/
|
||||
public void setDataSourceFactory(final DataSourceFactory newDataSourceFactory) {
|
||||
public void setWebshopFactory(final DataSourceFactory newDataSourceFactory) {
|
||||
this.dataSourceFactory = newDataSourceFactory;
|
||||
}
|
||||
|
||||
@@ -31,7 +32,7 @@ public class ProductRetriever {
|
||||
* @param newDataSourceFactory
|
||||
*/
|
||||
public ProductRetriever(final DataSourceFactory newDataSourceFactory) {
|
||||
this.setDataSourceFactory(newDataSourceFactory);
|
||||
this.setWebshopFactory(newDataSourceFactory);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -83,23 +84,23 @@ public class ProductRetriever {
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves a product from an API by name of the API so that high-level components do not need to be extended
|
||||
* Retrieves a product from an API by name of the API so that high-level
|
||||
* components do not need to be extended
|
||||
* with exact function call names if we extend the list of webshops.
|
||||
*
|
||||
* @param dataSourceName Data source name, e.g. amazon
|
||||
* @param productName Product name, translated to the correct product ID for the data source
|
||||
* @param shop Data source name, e.g. Amazon
|
||||
* @param productIdentifier Product name, translated to the correct product ID
|
||||
* for the data source
|
||||
* @return Product from that data source or null if data source not available
|
||||
*/
|
||||
public Product getProductFromDataSource(Product.webshop dataSourceName, final String productName) {
|
||||
switch(dataSourceName) {
|
||||
case AMAZON:
|
||||
// TODO: Translation from productName to productId (Amazon) needed
|
||||
return getProductFromAmazon(productName);
|
||||
case EBAY:
|
||||
// TODO: Translation from productName to productId (eBay) needed
|
||||
return getProductFromEbay(productName);
|
||||
default:
|
||||
return null;
|
||||
public Product getProductFromWebshop(final Webshop shop, final String productIdentifier) {
|
||||
switch (shop) {
|
||||
case Amazon:
|
||||
return getProductFromAmazon(productIdentifier);
|
||||
case eBay:
|
||||
return getProductFromEbay(productIdentifier);
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user