Integrated price function into offer identifier
This commit is contained in:
@@ -5,6 +5,7 @@ import java.util.List;
|
|||||||
import javax.naming.ConfigurationException;
|
import javax.naming.ConfigurationException;
|
||||||
|
|
||||||
import de.rwu.easydrop.model.Offer;
|
import de.rwu.easydrop.model.Offer;
|
||||||
|
import de.rwu.easydrop.model.ProductCatalogue;
|
||||||
|
|
||||||
public class Core {
|
public class Core {
|
||||||
|
|
||||||
@@ -23,8 +24,8 @@ public class Core {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void runCore(){
|
public void runCore(List<ProductCatalogue> pCats){
|
||||||
List<Offer> identifiedOffers = ident.runIdentifier();
|
List<Offer> identifiedOffers = ident.runIdentifier(pCats);
|
||||||
provis.runProvisioner(identifiedOffers);
|
provis.runProvisioner(identifiedOffers);
|
||||||
List<Offer> updatingOffers = review.runReviewer();
|
List<Offer> updatingOffers = review.runReviewer();
|
||||||
update.runUpdater(updatingOffers);
|
update.runUpdater(updatingOffers);
|
||||||
|
|||||||
@@ -1,61 +1,63 @@
|
|||||||
package de.rwu.easydrop.core;
|
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 javax.naming.ConfigurationException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.ArrayList;
|
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 {
|
public class OfferIdentifier {
|
||||||
|
/**
|
||||||
|
* Logger for main process.
|
||||||
|
*/
|
||||||
|
private static final Logger LOGGER = LoggerFactory.getLogger(OfferIdentifier.class);
|
||||||
|
|
||||||
OfferRetriever offerRetriever;
|
OfferRetriever offerRetriever;
|
||||||
ProductRetriever productRetriever;
|
|
||||||
|
|
||||||
|
|
||||||
public OfferIdentifier() throws ConfigurationException{
|
public OfferIdentifier() throws ConfigurationException{
|
||||||
this.offerRetriever = new OfferRetriever();
|
this.offerRetriever = new OfferRetriever();
|
||||||
DataSourceFactory dataSourceFactory = new DataSourceFactory(Config.getInstance());
|
|
||||||
this.productRetriever= new ProductRetriever(dataSourceFactory);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Offer> runIdentifier() {
|
public List<Offer> runIdentifier(List<ProductCatalogue> pCats) {
|
||||||
/* muss die Kataloge durchforsten nach vergleichbaren Produkten auf mehreren Händlerwebseiten (APIs)
|
List<Offer> identifiedOffers = new ArrayList<>();
|
||||||
* muss Preisermittler als Abhängigkeit für jeden Katalog aufrufen
|
// Here we call the price function that decides if is feasible to dropship the product and if, at which
|
||||||
* erhält dadurch Liste von Produkten, die auf verschiedenen Plattformen eingestellt werden können, gibt diese Liste zurück
|
// margin
|
||||||
* muss Datenbank nach Produktangeboten durchforsten, ob diese Produkte schon eingestellt wurden vom OfferProvisioner
|
for (ProductCatalogue pCat : pCats) {
|
||||||
* wenn ja, muss er die Liste um diese Angebote kürzen
|
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
|
// Following fields will be set if offer needs update
|
||||||
// JSON or the database later.
|
// upDate
|
||||||
ProductCatalogue catalogue = new ProductCatalogue("Gigabyte GeForce RTX 3060", "Very epic GPU");
|
}
|
||||||
for(Product.webshop webshop: Product.webshop.values()) {
|
catch(InvalidCatalogueException e) {
|
||||||
// The product retriever should know what API with which ProductID to query; high-level components should not know about such
|
// if no margin, getHighestMarginProducts will throw
|
||||||
// things.
|
System.out.print("product has no margin");
|
||||||
Product product = this.productRetriever.getProductFromDataSource(webshop, catalogue.getProductName());
|
|
||||||
if(product != null) {
|
|
||||||
catalogue.addProduct(product);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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> newOffers = new ArrayList<>();
|
||||||
List<Offer> existingOffers = offerRetriever.loadOffers();
|
List<Offer> existingOffers = offerRetriever.loadOffers();
|
||||||
for(Offer identifiedOffer: identifiedOffers) {
|
for(Offer identifiedOffer: identifiedOffers) {
|
||||||
@@ -70,9 +72,6 @@ public class OfferIdentifier {
|
|||||||
newOffers.add(identifiedOffer);
|
newOffers.add(identifiedOffer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return newOffers;
|
return newOffers;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,14 +1,31 @@
|
|||||||
package de.rwu.easydrop.core;
|
package de.rwu.easydrop.core;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
import javax.naming.ConfigurationException;
|
import javax.naming.ConfigurationException;
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
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 {
|
public class CoreTest {
|
||||||
@Test
|
@Test
|
||||||
void testRunCore() throws ConfigurationException{
|
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();
|
Core core1=new Core();
|
||||||
core1.runCore();
|
core1.runCore(pCats);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user