Integrated price function into offer identifier
This commit is contained in:
@@ -5,6 +5,7 @@ import java.util.List;
|
||||
import javax.naming.ConfigurationException;
|
||||
|
||||
import de.rwu.easydrop.model.Offer;
|
||||
import de.rwu.easydrop.model.ProductCatalogue;
|
||||
|
||||
public class Core {
|
||||
|
||||
@@ -23,8 +24,8 @@ public class Core {
|
||||
}
|
||||
|
||||
|
||||
public void runCore(){
|
||||
List<Offer> identifiedOffers = ident.runIdentifier();
|
||||
public void runCore(List<ProductCatalogue> pCats){
|
||||
List<Offer> identifiedOffers = ident.runIdentifier(pCats);
|
||||
provis.runProvisioner(identifiedOffers);
|
||||
List<Offer> updatingOffers = review.runReviewer();
|
||||
update.runUpdater(updatingOffers);
|
||||
|
||||
@@ -1,61 +1,63 @@
|
||||
package de.rwu.easydrop.core;
|
||||
|
||||
import de.rwu.easydrop.api.client.DataSourceFactory;
|
||||
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;
|
||||
import java.util.Date;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import de.rwu.easydrop.model.Offer;
|
||||
import de.rwu.easydrop.model.ProductCatalogue;
|
||||
import de.rwu.easydrop.model.ProductPair;
|
||||
import de.rwu.easydrop.service.retriever.OfferRetriever;
|
||||
import de.rwu.easydrop.service.processing.OrderManager;
|
||||
import de.rwu.easydrop.exception.InvalidCatalogueException;
|
||||
|
||||
|
||||
public class OfferIdentifier {
|
||||
|
||||
/**
|
||||
* Logger for main process.
|
||||
*/
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(OfferIdentifier.class);
|
||||
|
||||
OfferRetriever offerRetriever;
|
||||
ProductRetriever productRetriever;
|
||||
|
||||
|
||||
public OfferIdentifier() throws ConfigurationException{
|
||||
this.offerRetriever = new OfferRetriever();
|
||||
DataSourceFactory dataSourceFactory = new DataSourceFactory(Config.getInstance());
|
||||
this.productRetriever= new ProductRetriever(dataSourceFactory);
|
||||
}
|
||||
|
||||
public List<Offer> runIdentifier() {
|
||||
/* muss die Kataloge durchforsten nach vergleichbaren Produkten auf mehreren Händlerwebseiten (APIs)
|
||||
* muss Preisermittler als Abhängigkeit für jeden Katalog aufrufen
|
||||
* erhält dadurch Liste von Produkten, die auf verschiedenen Plattformen eingestellt werden können, gibt diese Liste zurück
|
||||
* muss Datenbank nach Produktangeboten durchforsten, ob diese Produkte schon eingestellt wurden vom OfferProvisioner
|
||||
* wenn ja, muss er die Liste um diese Angebote kürzen
|
||||
*
|
||||
*/
|
||||
public List<Offer> runIdentifier(List<ProductCatalogue> pCats) {
|
||||
List<Offer> identifiedOffers = new ArrayList<>();
|
||||
// Here we call the price function that decides if is feasible to dropship the product and if, at which
|
||||
// margin
|
||||
for (ProductCatalogue pCat : pCats) {
|
||||
try{
|
||||
// Call price finder for all catalogue
|
||||
ProductPair pair = OrderManager.getHighestMarginProducts(pCat);
|
||||
Offer possibleOffer = new Offer();
|
||||
possibleOffer.setCheckDate(new Date());
|
||||
possibleOffer.setSourceProduct(pair.getProduct1());
|
||||
possibleOffer.setSaleProduct(pair.getProduct2());
|
||||
identifiedOffers.add(possibleOffer);
|
||||
LOGGER.info(
|
||||
"Identified offer " +
|
||||
pair.getProduct1().getProductId() +
|
||||
" -> " +
|
||||
pair.getProduct2().getProductId()
|
||||
);
|
||||
// Following fields will be set if offer confirmed
|
||||
// creationDate, offerId
|
||||
|
||||
// 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(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());
|
||||
if(product != null) {
|
||||
catalogue.addProduct(product);
|
||||
// Following fields will be set if offer needs update
|
||||
// upDate
|
||||
}
|
||||
catch(InvalidCatalogueException e) {
|
||||
// if no margin, getHighestMarginProducts will throw
|
||||
System.out.print("product has no margin");
|
||||
}
|
||||
}
|
||||
|
||||
List<Offer> 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<Offer> newOffers = new ArrayList<>();
|
||||
List<Offer> existingOffers = offerRetriever.loadOffers();
|
||||
for(Offer identifiedOffer: identifiedOffers) {
|
||||
@@ -70,9 +72,6 @@ public class OfferIdentifier {
|
||||
newOffers.add(identifiedOffer);
|
||||
}
|
||||
}
|
||||
|
||||
return newOffers;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,14 +1,31 @@
|
||||
package de.rwu.easydrop.core;
|
||||
|
||||
import java.util.List;
|
||||
import javax.naming.ConfigurationException;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import de.rwu.easydrop.api.client.DataSourceFactory;
|
||||
|
||||
import de.rwu.easydrop.model.ProductCatalogue;
|
||||
import de.rwu.easydrop.service.retriever.CatalogueRetriever;
|
||||
import de.rwu.easydrop.service.retriever.ProductRetriever;
|
||||
import de.rwu.easydrop.util.Config;
|
||||
import de.rwu.easydrop.util.ProductsConfig;
|
||||
|
||||
public class CoreTest {
|
||||
@Test
|
||||
void testRunCore() throws ConfigurationException{
|
||||
Config config = Config.getInstance();
|
||||
ProductsConfig pConfig = ProductsConfig.getInstance();
|
||||
DataSourceFactory dataSourceFactory = new DataSourceFactory(config);
|
||||
ProductRetriever retriever = new ProductRetriever(dataSourceFactory);
|
||||
CatalogueRetriever catRetriever = new CatalogueRetriever(pConfig, retriever);
|
||||
|
||||
catRetriever.loadCatalogues();
|
||||
List<ProductCatalogue> pCats = catRetriever.getProductCatalogues();
|
||||
Core core1=new Core();
|
||||
core1.runCore();
|
||||
core1.runCore(pCats);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user