Wrote Enum for webshops

changed code in respective classes
This commit is contained in:
Leonie Eitze
2023-06-15 18:47:10 +02:00
parent 5e6a2541fa
commit 5436118829
4 changed files with 16 additions and 13 deletions

View File

@@ -15,15 +15,12 @@ import java.util.ArrayList;
public class OfferIdentifier {
String[] webshops;
OfferRetriever offerRetriever;
ProductRetriever productRetriever;
public OfferIdentifier() {
Config config = Config.getInstance();
this.webshops = config.getProperty("WEBSHOPS").split(",");
}
public OfferIdentifier() {}
public List<Offer> runIdentifier() {
/* 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
// JSON or the database later.
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
// things.
Product product = this.productRetriever.getProductFromDataSource(webshop, catalogue.getProductName());

View File

@@ -10,6 +10,13 @@ import lombok.Data;
*/
@Data
public class Product {
/*
* Constants for data source/destination platforms
*/
public enum webshop{
AMAZON, EBAY
}
/**
* Data source platform, like "Amazon".
*/

View File

@@ -90,17 +90,14 @@ public class ProductRetriever {
* @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":
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":
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;
}