Added missing buy logic
This commit is contained in:
@@ -2,21 +2,27 @@ package de.rwu.easydrop.service.processing;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import de.rwu.easydrop.api.client.AmazonPurchaser;
|
||||
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.PurchaserFactory;
|
||||
import de.rwu.easydrop.api.client.SellerFactory;
|
||||
import de.rwu.easydrop.data.connector.OfferPersistenceInterface;
|
||||
import de.rwu.easydrop.model.Offer;
|
||||
import de.rwu.easydrop.model.Webshop;
|
||||
import de.rwu.easydrop.service.mapping.ProductMapper;
|
||||
import de.rwu.easydrop.service.writer.OfferWriter;
|
||||
import de.rwu.easydrop.util.Config;
|
||||
import de.rwu.easydrop.util.FormattingUtil;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* Offer provisioner.
|
||||
*
|
||||
* @since 0.3.0
|
||||
*/
|
||||
@Data
|
||||
public class OfferProvisioner {
|
||||
/**
|
||||
* Config.
|
||||
*/
|
||||
private Config config;
|
||||
/**
|
||||
* Writes offers into persistence.
|
||||
*/
|
||||
@@ -30,7 +36,20 @@ public class OfferProvisioner {
|
||||
* Is the API for selling products on Ebay.
|
||||
*/
|
||||
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 {
|
||||
if (offer.getTargetProduct().getDataOrigin() == Webshop.EBAY) {
|
||||
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.
|
||||
*
|
||||
* @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.config = Config.getInstance();
|
||||
this.amazonSeller = new AmazonSeller(
|
||||
config.getProperty("AMAZON_API_URL"),
|
||||
config.getProperty("AMAZON_API_KEY"));
|
||||
this.ebaySeller = new EbaySeller(
|
||||
config.getProperty("EBAY_API_URL"),
|
||||
config.getProperty("EBAY_API_KEY"));
|
||||
this.ebaySeller = newSellerFactory.createEbaySeller();
|
||||
this.amazonSeller = newSellerFactory.createAmazonSeller();
|
||||
this.ebayPurchaser = newPurchaserFactory.createEbayPurchaser();
|
||||
this.amazonPurchaser = newPurchaserFactory.createAmazonPurchaser();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -74,6 +114,7 @@ public class OfferProvisioner {
|
||||
+ newOffer.getTargetProduct().getProductId());
|
||||
|
||||
this.toSeller(newOffer);
|
||||
this.toBuyer(newOffer);
|
||||
newOffer.setOfferId(newOfferId);
|
||||
offerWriter.writeOfferToPersistence(newOffer);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user