Added missing buy logic
This commit is contained in:
@@ -9,6 +9,8 @@ import org.slf4j.LoggerFactory;
|
|||||||
import org.sqlite.SQLiteDataSource;
|
import org.sqlite.SQLiteDataSource;
|
||||||
|
|
||||||
import de.rwu.easydrop.api.client.DataSourceFactory;
|
import de.rwu.easydrop.api.client.DataSourceFactory;
|
||||||
|
import de.rwu.easydrop.api.client.PurchaserFactory;
|
||||||
|
import de.rwu.easydrop.api.client.SellerFactory;
|
||||||
import de.rwu.easydrop.api.dto.OfferDTO;
|
import de.rwu.easydrop.api.dto.OfferDTO;
|
||||||
import de.rwu.easydrop.data.connector.OfferPersistenceInterface;
|
import de.rwu.easydrop.data.connector.OfferPersistenceInterface;
|
||||||
import de.rwu.easydrop.data.connector.ProductPersistenceInterface;
|
import de.rwu.easydrop.data.connector.ProductPersistenceInterface;
|
||||||
@@ -56,12 +58,16 @@ public final class Core {
|
|||||||
|
|
||||||
LOGGER.info("Preparing...");
|
LOGGER.info("Preparing...");
|
||||||
DataSourceFactory dataSourceFactory = new DataSourceFactory(config);
|
DataSourceFactory dataSourceFactory = new DataSourceFactory(config);
|
||||||
ProductPersistenceInterface pdb = new SQLiteConnector(new SQLiteDataSource());
|
SellerFactory sellerFactory = new SellerFactory(config);
|
||||||
OfferPersistenceInterface odb = new SQLiteConnector(new SQLiteDataSource());
|
PurchaserFactory purchaserFactory = new PurchaserFactory(config);
|
||||||
ProductRetriever retriever = new ProductRetriever(dataSourceFactory, pdb);
|
|
||||||
|
ProductPersistenceInterface productDB = new SQLiteConnector(new SQLiteDataSource());
|
||||||
|
OfferPersistenceInterface offerDB = new SQLiteConnector(new SQLiteDataSource());
|
||||||
|
TransactionPersistenceInterface txDB = new SQLiteConnector(new SQLiteDataSource());
|
||||||
|
|
||||||
|
ProductRetriever retriever = new ProductRetriever(dataSourceFactory, productDB);
|
||||||
CatalogueRetriever catRetriever = new CatalogueRetriever(pConfig, retriever);
|
CatalogueRetriever catRetriever = new CatalogueRetriever(pConfig, retriever);
|
||||||
CatalogueWriter catWriter = new CatalogueWriter(pdb);
|
CatalogueWriter catWriter = new CatalogueWriter(productDB);
|
||||||
TransactionPersistenceInterface tpi = new SQLiteConnector(new SQLiteDataSource());
|
|
||||||
|
|
||||||
LOGGER.info("Loading catalogues");
|
LOGGER.info("Loading catalogues");
|
||||||
catRetriever.loadCatalogues();
|
catRetriever.loadCatalogues();
|
||||||
@@ -70,17 +76,17 @@ public final class Core {
|
|||||||
|
|
||||||
LOGGER.info("Creating offers");
|
LOGGER.info("Creating offers");
|
||||||
OfferIdentifier ident = new OfferIdentifier();
|
OfferIdentifier ident = new OfferIdentifier();
|
||||||
|
OfferProvisioner provis = new OfferProvisioner(offerDB, sellerFactory, purchaserFactory);
|
||||||
List<Offer> identifiedOffers = ident.runIdentifier(pCats);
|
List<Offer> identifiedOffers = ident.runIdentifier(pCats);
|
||||||
OfferProvisioner provis = new OfferProvisioner(odb);
|
|
||||||
provis.runProvisioner(identifiedOffers);
|
provis.runProvisioner(identifiedOffers);
|
||||||
|
|
||||||
LOGGER.info("Creating transactions");
|
LOGGER.info("Creating transactions");
|
||||||
TransactionHandler txHandler = new TransactionHandler(tpi);
|
TransactionHandler txHandler = new TransactionHandler(txDB);
|
||||||
for (OfferDTO o : odb.getOffers()) {
|
for (OfferDTO o : offerDB.getOffers()) {
|
||||||
txHandler.turnOfferToTransaction(OfferMapper.mapOfferFromDTO(o));
|
txHandler.turnOfferToTransaction(OfferMapper.mapOfferFromDTO(o));
|
||||||
}
|
}
|
||||||
|
|
||||||
tpi.outputTransactionsToLog();
|
txDB.outputTransactionsToLog();
|
||||||
tpi.outputSummaryToLog();
|
txDB.outputSummaryToLog();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -319,9 +319,12 @@ public final class SQLiteConnector implements
|
|||||||
sb.append("\n");
|
sb.append("\n");
|
||||||
sb.append(String.format("%3d", ++index));
|
sb.append(String.format("%3d", ++index));
|
||||||
sb.append(String.format(" - %s - ", resultSet.getString("transactionTime")));
|
sb.append(String.format(" - %s - ", resultSet.getString("transactionTime")));
|
||||||
sb.append(String.format("+%s (%s) - %s",
|
sb.append(String.format("+%s (%s) - ",
|
||||||
FormattingUtil.formatEuro(resultSet.getDouble("earnings")),
|
FormattingUtil.formatEuro(resultSet.getDouble("earnings")),
|
||||||
FormattingUtil.formatEuro(resultSet.getDouble("volume")),
|
FormattingUtil.formatEuro(resultSet.getDouble("volume"))));
|
||||||
|
sb.append(String.format("[%s to %s] %s",
|
||||||
|
resultSet.getString("sourceWebshop"),
|
||||||
|
resultSet.getString("targetWebshop"),
|
||||||
resultSet.getString(OFFERID_COL_NAME)));
|
resultSet.getString(OFFERID_COL_NAME)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,21 +2,27 @@ package de.rwu.easydrop.service.processing;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import de.rwu.easydrop.api.client.AmazonPurchaser;
|
||||||
import de.rwu.easydrop.api.client.AmazonSeller;
|
import de.rwu.easydrop.api.client.AmazonSeller;
|
||||||
|
import de.rwu.easydrop.api.client.EbayPurchaser;
|
||||||
import de.rwu.easydrop.api.client.EbaySeller;
|
import de.rwu.easydrop.api.client.EbaySeller;
|
||||||
|
import de.rwu.easydrop.api.client.PurchaserFactory;
|
||||||
|
import de.rwu.easydrop.api.client.SellerFactory;
|
||||||
import de.rwu.easydrop.data.connector.OfferPersistenceInterface;
|
import de.rwu.easydrop.data.connector.OfferPersistenceInterface;
|
||||||
import de.rwu.easydrop.model.Offer;
|
import de.rwu.easydrop.model.Offer;
|
||||||
import de.rwu.easydrop.model.Webshop;
|
import de.rwu.easydrop.model.Webshop;
|
||||||
import de.rwu.easydrop.service.mapping.ProductMapper;
|
import de.rwu.easydrop.service.mapping.ProductMapper;
|
||||||
import de.rwu.easydrop.service.writer.OfferWriter;
|
import de.rwu.easydrop.service.writer.OfferWriter;
|
||||||
import de.rwu.easydrop.util.Config;
|
|
||||||
import de.rwu.easydrop.util.FormattingUtil;
|
import de.rwu.easydrop.util.FormattingUtil;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Offer provisioner.
|
||||||
|
*
|
||||||
|
* @since 0.3.0
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
public class OfferProvisioner {
|
public class OfferProvisioner {
|
||||||
/**
|
|
||||||
* Config.
|
|
||||||
*/
|
|
||||||
private Config config;
|
|
||||||
/**
|
/**
|
||||||
* Writes offers into persistence.
|
* Writes offers into persistence.
|
||||||
*/
|
*/
|
||||||
@@ -30,7 +36,20 @@ public class OfferProvisioner {
|
|||||||
* Is the API for selling products on Ebay.
|
* Is the API for selling products on Ebay.
|
||||||
*/
|
*/
|
||||||
private EbaySeller ebaySeller;
|
private EbaySeller ebaySeller;
|
||||||
|
/**
|
||||||
|
* Is the API for buying products on Amazon.
|
||||||
|
*/
|
||||||
|
private AmazonPurchaser amazonPurchaser;
|
||||||
|
/**
|
||||||
|
* Is the API for buying products on Ebay.
|
||||||
|
*/
|
||||||
|
private EbayPurchaser ebayPurchaser;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Puts up the sell order.
|
||||||
|
*
|
||||||
|
* @param offer
|
||||||
|
*/
|
||||||
private void toSeller(final Offer offer) throws IllegalArgumentException {
|
private void toSeller(final Offer offer) throws IllegalArgumentException {
|
||||||
if (offer.getTargetProduct().getDataOrigin() == Webshop.EBAY) {
|
if (offer.getTargetProduct().getDataOrigin() == Webshop.EBAY) {
|
||||||
this.ebaySeller.sellProduct(ProductMapper.mapProductToDTO(offer.getTargetProduct()));
|
this.ebaySeller.sellProduct(ProductMapper.mapProductToDTO(offer.getTargetProduct()));
|
||||||
@@ -43,20 +62,41 @@ public class OfferProvisioner {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Puts up the buy order.
|
||||||
|
*
|
||||||
|
* @param offer
|
||||||
|
*/
|
||||||
|
private void toBuyer(final Offer offer) throws IllegalArgumentException {
|
||||||
|
if (offer.getSourceProduct().getDataOrigin() == Webshop.EBAY) {
|
||||||
|
this.ebayPurchaser.purchaseProduct(
|
||||||
|
ProductMapper.mapProductToDTO(offer.getSourceProduct()));
|
||||||
|
|
||||||
|
} else if (offer.getTargetProduct().getDataOrigin().equals(Webshop.AMAZON)) {
|
||||||
|
this.amazonPurchaser.purchaseProduct(
|
||||||
|
ProductMapper.mapProductToDTO(offer.getSourceProduct()));
|
||||||
|
} else {
|
||||||
|
throw new IllegalArgumentException("Unsupported target plattform");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Is the class for placing orders on a target platform.
|
* Is the class for placing orders on a target platform.
|
||||||
*
|
*
|
||||||
* @param db Persistence Interface
|
* @param db Persistence Interface
|
||||||
|
* @param newSellerFactory Seller Factory
|
||||||
|
* @param newPurchaserFactory Purchaser Factory
|
||||||
*/
|
*/
|
||||||
public OfferProvisioner(final OfferPersistenceInterface db) {
|
public OfferProvisioner(
|
||||||
|
final OfferPersistenceInterface db,
|
||||||
|
final SellerFactory newSellerFactory,
|
||||||
|
final PurchaserFactory newPurchaserFactory) {
|
||||||
this.offerWriter = new OfferWriter(db);
|
this.offerWriter = new OfferWriter(db);
|
||||||
this.config = Config.getInstance();
|
this.ebaySeller = newSellerFactory.createEbaySeller();
|
||||||
this.amazonSeller = new AmazonSeller(
|
this.amazonSeller = newSellerFactory.createAmazonSeller();
|
||||||
config.getProperty("AMAZON_API_URL"),
|
this.ebayPurchaser = newPurchaserFactory.createEbayPurchaser();
|
||||||
config.getProperty("AMAZON_API_KEY"));
|
this.amazonPurchaser = newPurchaserFactory.createAmazonPurchaser();
|
||||||
this.ebaySeller = new EbaySeller(
|
|
||||||
config.getProperty("EBAY_API_URL"),
|
|
||||||
config.getProperty("EBAY_API_KEY"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -74,6 +114,7 @@ public class OfferProvisioner {
|
|||||||
+ newOffer.getTargetProduct().getProductId());
|
+ newOffer.getTargetProduct().getProductId());
|
||||||
|
|
||||||
this.toSeller(newOffer);
|
this.toSeller(newOffer);
|
||||||
|
this.toBuyer(newOffer);
|
||||||
newOffer.setOfferId(newOfferId);
|
newOffer.setOfferId(newOfferId);
|
||||||
offerWriter.writeOfferToPersistence(newOffer);
|
offerWriter.writeOfferToPersistence(newOffer);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user