Wrote Enum for webshops
changed code in respective classes
This commit is contained in:
@@ -15,15 +15,12 @@ import java.util.ArrayList;
|
|||||||
|
|
||||||
public class OfferIdentifier {
|
public class OfferIdentifier {
|
||||||
|
|
||||||
String[] webshops;
|
|
||||||
OfferRetriever offerRetriever;
|
OfferRetriever offerRetriever;
|
||||||
ProductRetriever productRetriever;
|
ProductRetriever productRetriever;
|
||||||
|
|
||||||
|
|
||||||
public OfferIdentifier() {
|
public OfferIdentifier() {}
|
||||||
Config config = Config.getInstance();
|
|
||||||
this.webshops = config.getProperty("WEBSHOPS").split(",");
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<Offer> runIdentifier() {
|
public List<Offer> runIdentifier() {
|
||||||
/* muss die Kataloge durchforsten nach vergleichbaren Produkten auf mehreren Händlerwebseiten (APIs)
|
/* muss die Kataloge durchforsten nach vergleichbaren Produkten auf mehreren Händlerwebseiten (APIs)
|
||||||
@@ -37,7 +34,7 @@ public class OfferIdentifier {
|
|||||||
// Just an example here taken from demo.products-config.json; should be generic and configurable either via
|
// Just an example here taken from demo.products-config.json; should be generic and configurable either via
|
||||||
// JSON or the database later.
|
// JSON or the database later.
|
||||||
ProductCatalogue catalogue = new ProductCatalogue("Gigabyte GeForce RTX 3060", "Very epic GPU");
|
ProductCatalogue catalogue = new ProductCatalogue("Gigabyte GeForce RTX 3060", "Very epic GPU");
|
||||||
for(String webshop: this.webshops) {
|
for(Product.webshop webshop: Product.webshop.values()) {
|
||||||
// The product retriever should know what API with which ProductID to query; high-level components should not know about such
|
// The product retriever should know what API with which ProductID to query; high-level components should not know about such
|
||||||
// things.
|
// things.
|
||||||
Product product = this.productRetriever.getProductFromDataSource(webshop, catalogue.getProductName());
|
Product product = this.productRetriever.getProductFromDataSource(webshop, catalogue.getProductName());
|
||||||
|
|||||||
@@ -10,6 +10,13 @@ import lombok.Data;
|
|||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
public class Product {
|
public class Product {
|
||||||
|
/*
|
||||||
|
* Constants for data source/destination platforms
|
||||||
|
*/
|
||||||
|
public enum webshop{
|
||||||
|
AMAZON, EBAY
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Data source platform, like "Amazon".
|
* Data source platform, like "Amazon".
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -90,17 +90,14 @@ public class ProductRetriever {
|
|||||||
* @param productName Product name, translated to the correct product ID for the data source
|
* @param productName 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
|
* @return Product from that data source or null if data source not available
|
||||||
*/
|
*/
|
||||||
public Product getProductFromDataSource(final String dataSourceName, final String productName) {
|
public Product getProductFromDataSource(Product.webshop dataSourceName, final String productName) {
|
||||||
switch(dataSourceName.toLowerCase()) {
|
switch(dataSourceName) {
|
||||||
case "amazon":
|
case AMAZON:
|
||||||
// TODO: Translation from productName to productId (Amazon) needed
|
// TODO: Translation from productName to productId (Amazon) needed
|
||||||
return getProductFromAmazon(productName);
|
return getProductFromAmazon(productName);
|
||||||
case "ebay":
|
case EBAY:
|
||||||
// TODO: Translation from productName to productId (eBay) needed
|
// TODO: Translation from productName to productId (eBay) needed
|
||||||
return getProductFromEbay(productName);
|
return getProductFromEbay(productName);
|
||||||
case "persistence":
|
|
||||||
// TODO: Translation from productName to productId (persistence layer) needed
|
|
||||||
return getProductFromPersistence(productName);
|
|
||||||
default:
|
default:
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,8 @@ import org.junit.jupiter.api.Test;
|
|||||||
public class CoreTest {
|
public class CoreTest {
|
||||||
@Test
|
@Test
|
||||||
void testRunCore() {
|
void testRunCore() {
|
||||||
|
Core core1=new Core();
|
||||||
|
core1.runCore();
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user