diff --git a/config/demo.config.properties b/config/demo.config.properties index d3e4d63..13b994e 100644 --- a/config/demo.config.properties +++ b/config/demo.config.properties @@ -2,4 +2,5 @@ AMAZON_API_URL= AMAZON_API_KEY= EBAY_API_URL= -EBAY_API_KEY= \ No newline at end of file +EBAY_API_KEY= +WEBSHOPS=amazon,ebay \ No newline at end of file diff --git a/src/main/java/de/rwu/easydrop/core/OfferIdentifier.java b/src/main/java/de/rwu/easydrop/core/OfferIdentifier.java index 1d20353..bfdbd9c 100644 --- a/src/main/java/de/rwu/easydrop/core/OfferIdentifier.java +++ b/src/main/java/de/rwu/easydrop/core/OfferIdentifier.java @@ -1,6 +1,13 @@ package de.rwu.easydrop.core; import de.rwu.easydrop.model.Offer; +import de.rwu.easydrop.model.Product; +import de.rwu.easydrop.model.ProductCatalogue; +import de.rwu.easydrop.service.retriever.OfferRetriever; +import de.rwu.easydrop.service.retriever.ProductRetriever; +import de.rwu.easydrop.util.Config; + +import javax.naming.ConfigurationException; import java.util.List; import java.util.ArrayList; @@ -8,11 +15,14 @@ import java.util.ArrayList; public class OfferIdentifier { + String[] webshops; + OfferRetriever offerRetriever; + ProductRetriever productRetriever; - - public OfferIdentifier() { - + public OfferIdentifier() throws ConfigurationException { + Config config = Config.getInstance(); + this.webshops = config.getProperty("WEBSHOPS").split(","); } public List runIdentifier() { @@ -23,8 +33,43 @@ public class OfferIdentifier { * wenn ja, muss er die Liste um diese Angebote kürzen * */ - return new ArrayList(); + // Just an example here taken from demo.products-config.json; should be generic and configurable either via + // JSON or the database later. + ProductCatalogue catalogue = new ProductCatalogue("Gigabyte GeForce RTX 3060", "Very epic GPU"); + for(String webshop: this.webshops) { + // The product retriever should know what API with which ProductID to query; high-level components should not know about such + // things. + Product product = this.productRetriever.getProductFromDataSource(webshop, catalogue.getProductName()); + if(product != null) { + catalogue.addProduct(product); + } + } + + List identifiedOffers = new ArrayList<>(); + // Here we would call the price function that decides if is feasible to dropship the product and if, at which + // margin + // Offer possibleOffer = GenerateOfferFromCatalogue(catalogue); + // if(possibleOffer != null) { + // identifiedOffers.add(possibleOffer); + // } + + List newOffers = new ArrayList<>(); + List existingOffers = offerRetriever.loadOffers(); + for(Offer identifiedOffer: identifiedOffers) { + boolean isNew = true; + for(Offer existingOffer: existingOffers) { + if(existingOffer.getSourceProduct().getProductId().equals(identifiedOffer.getSourceProduct().getProductId())) { + isNew = false; + break; + } + } + if(isNew) { + newOffers.add(identifiedOffer); + } + } + + return newOffers; } diff --git a/src/main/java/de/rwu/easydrop/model/Offer.java b/src/main/java/de/rwu/easydrop/model/Offer.java index f1772d6..a030146 100644 --- a/src/main/java/de/rwu/easydrop/model/Offer.java +++ b/src/main/java/de/rwu/easydrop/model/Offer.java @@ -23,11 +23,6 @@ public class Offer { */ Product saleProduct; - /* - * Boolean to check if sourceProduct is still available on source website - */ - boolean availability; - /* * Date of the creation of the offer * NOTE: Use Timestamp? https://docs.oracle.com/javase/8/docs/api/java/sql/Timestamp.html @@ -44,9 +39,4 @@ public class Offer { */ Date checkDate; - - - - - } diff --git a/src/main/java/de/rwu/easydrop/service/retriever/OfferRetriever.java b/src/main/java/de/rwu/easydrop/service/retriever/OfferRetriever.java new file mode 100644 index 0000000..3571b7d --- /dev/null +++ b/src/main/java/de/rwu/easydrop/service/retriever/OfferRetriever.java @@ -0,0 +1,14 @@ +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 loadOffers() { + return new ArrayList<>(); + } + +} diff --git a/src/main/java/de/rwu/easydrop/service/retriever/ProductRetriever.java b/src/main/java/de/rwu/easydrop/service/retriever/ProductRetriever.java index da842c3..d4e5950 100644 --- a/src/main/java/de/rwu/easydrop/service/retriever/ProductRetriever.java +++ b/src/main/java/de/rwu/easydrop/service/retriever/ProductRetriever.java @@ -81,4 +81,28 @@ public class ProductRetriever { return product; } + + /** + * 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 + * @return Product from that data source or null if data source not available + */ + public Product getProductFromDataSource(final String dataSourceName, final String productName) { + switch(dataSourceName.toLowerCase()) { + 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); + case "persistence": + // TODO: Translation from productName to productId (persistence layer) needed + return getProductFromPersistence(productName); + default: + return null; + } + } }