Did Checkstyle improvements on OfferProv + Ident
This commit is contained in:
@@ -20,17 +20,29 @@ public class OfferIdentifier {
|
|||||||
* Logger for main process.
|
* Logger for main process.
|
||||||
*/
|
*/
|
||||||
private static final Logger LOGGER = LoggerFactory.getLogger(OfferIdentifier.class);
|
private static final Logger LOGGER = LoggerFactory.getLogger(OfferIdentifier.class);
|
||||||
|
/**
|
||||||
OfferRetriever offerRetriever;
|
* OfferRetriever gets the offer from persistence.
|
||||||
|
*/
|
||||||
|
private OfferRetriever offerRetriever;
|
||||||
|
/**
|
||||||
|
* OfferIdentifier identifies offers that are
|
||||||
|
* feasible to place on a target platform based on
|
||||||
|
* their margin.
|
||||||
|
* @throws ConfigurationException
|
||||||
|
*/
|
||||||
public OfferIdentifier() throws ConfigurationException{
|
public OfferIdentifier() throws ConfigurationException{
|
||||||
this.offerRetriever = new OfferRetriever();
|
this.offerRetriever = new OfferRetriever();
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Offer> runIdentifier(List<ProductCatalogue> pCats) {
|
/**
|
||||||
|
* runIdentifier calls the price function that decides
|
||||||
|
* if it is feasible to dropship products and if so,
|
||||||
|
* at which margin.
|
||||||
|
* @param pCats
|
||||||
|
* @return newOffers
|
||||||
|
*/
|
||||||
|
public List<Offer> runIdentifier(final List<ProductCatalogue> pCats) {
|
||||||
List<Offer> identifiedOffers = new ArrayList<>();
|
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) {
|
for (ProductCatalogue pCat : pCats) {
|
||||||
try {
|
try {
|
||||||
// Call price finder for all catalogue
|
// Call price finder for all catalogue
|
||||||
@@ -41,14 +53,16 @@ public class OfferIdentifier {
|
|||||||
possibleOffer.setSaleProduct(pair.getProduct2());
|
possibleOffer.setSaleProduct(pair.getProduct2());
|
||||||
identifiedOffers.add(possibleOffer);
|
identifiedOffers.add(possibleOffer);
|
||||||
LOGGER.info(
|
LOGGER.info(
|
||||||
"Identified offer " +
|
"Identified offer "
|
||||||
pair.getProduct1().getProductId() +
|
+
|
||||||
" -> " +
|
pair.getProduct1().getProductId()
|
||||||
|
+
|
||||||
|
" -> "
|
||||||
|
+
|
||||||
pair.getProduct2().getProductId()
|
pair.getProduct2().getProductId()
|
||||||
);
|
);
|
||||||
// Following fields will be set if offer confirmed
|
// Following fields will be set if offer confirmed
|
||||||
// creationDate, offerId
|
// creationDate, offerId
|
||||||
|
|
||||||
// Following fields will be set if offer needs update
|
// Following fields will be set if offer needs update
|
||||||
// upDate
|
// upDate
|
||||||
}
|
}
|
||||||
@@ -57,13 +71,14 @@ public class OfferIdentifier {
|
|||||||
System.out.print("product has no margin");
|
System.out.print("product has no margin");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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) {
|
||||||
boolean isNew = true;
|
boolean isNew = true;
|
||||||
for (Offer existingOffer: existingOffers) {
|
for (Offer existingOffer: existingOffers) {
|
||||||
if(existingOffer.getSourceProduct().getProductId().equals(identifiedOffer.getSourceProduct().getProductId())) {
|
if (
|
||||||
|
existingOffer.getSourceProduct().getProductId().
|
||||||
|
equals(identifiedOffer.getSourceProduct().getProductId())) {
|
||||||
isNew = false;
|
isNew = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
package de.rwu.easydrop.core;
|
package de.rwu.easydrop.core;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import de.rwu.easydrop.util.Config;
|
import de.rwu.easydrop.util.Config;
|
||||||
@@ -14,60 +13,71 @@ import de.rwu.easydrop.api.client.EbaySeller;
|
|||||||
import de.rwu.easydrop.api.dto.ProductDTO;
|
import de.rwu.easydrop.api.dto.ProductDTO;
|
||||||
|
|
||||||
public class OfferProvisioner {
|
public class OfferProvisioner {
|
||||||
|
/**
|
||||||
Config config;
|
* Config.
|
||||||
ProductRetriever productRetriever;
|
*/
|
||||||
|
private Config config;
|
||||||
|
/**
|
||||||
|
* Gets the products from persistence.
|
||||||
|
*/
|
||||||
|
private ProductRetriever productRetriever;
|
||||||
// ProductWriter
|
// ProductWriter
|
||||||
AbstractProductPersistence db;
|
/**
|
||||||
OfferWriter offerWriter;
|
* Is the product databank.
|
||||||
AmazonSeller amazonSeller;
|
*/
|
||||||
EbaySeller ebaySeller;
|
private AbstractProductPersistence db;
|
||||||
|
/**
|
||||||
|
* Writes offers into persistence.
|
||||||
|
*/
|
||||||
|
private OfferWriter offerWriter;
|
||||||
|
|
||||||
private void toSeller(Offer offer) throws IllegalArgumentException {
|
/**
|
||||||
|
* Is the API for selling products on Amazon.
|
||||||
|
*/
|
||||||
|
private AmazonSeller amazonSeller;
|
||||||
|
/**
|
||||||
|
* Is the API for selling products on Ebay.
|
||||||
|
*/
|
||||||
|
private EbaySeller ebaySeller;
|
||||||
|
|
||||||
|
private void toSeller(final Offer offer) throws IllegalArgumentException {
|
||||||
// TODO dataOrigin should use the webshop enum
|
// TODO dataOrigin should use the webshop enum
|
||||||
if (offer.getSaleProduct().getDataOrigin().toLowerCase().equals("ebay")) {
|
if (offer.getSaleProduct().getDataOrigin().toLowerCase().equals("ebay")) {
|
||||||
this.ebaySeller.sellProduct(new ProductDTO(
|
this.ebaySeller.sellProduct(new ProductDTO(
|
||||||
offer.getSaleProduct().getProductId(),
|
offer.getSaleProduct().getProductId(),
|
||||||
"Amazon")
|
"Amazon"));
|
||||||
);
|
|
||||||
|
|
||||||
} else if (offer.getSaleProduct().getDataOrigin().toLowerCase().equals("Amazon")) {
|
} else if (offer.getSaleProduct().getDataOrigin().toLowerCase().equals("Amazon")) {
|
||||||
this.amazonSeller.sellProduct(new ProductDTO(
|
this.amazonSeller.sellProduct(new ProductDTO(
|
||||||
offer.getSaleProduct().getProductId(),
|
offer.getSaleProduct().getProductId(),
|
||||||
"eBay")
|
"eBay"));
|
||||||
);
|
} else {
|
||||||
}
|
|
||||||
else {
|
|
||||||
throw new IllegalArgumentException("Unsupported target plattform");
|
throw new IllegalArgumentException("Unsupported target plattform");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Is the class for placing orders on a target platform.
|
||||||
|
*/
|
||||||
public OfferProvisioner(/* OfferWriter for database? */) {
|
public OfferProvisioner(/* OfferWriter for database? */) {
|
||||||
|
|
||||||
//in die Klasse hardcoden, "webshop" nicht verwenden
|
|
||||||
//oder eine Konstante anlegen die das halten würde (besser skalierbar)
|
|
||||||
//die Konstante in model anlegen (in Product, Konstante valid origins)
|
|
||||||
this.offerWriter = new OfferWriter();
|
this.offerWriter = new OfferWriter();
|
||||||
this.config = Config.getInstance();
|
this.config = Config.getInstance();
|
||||||
this.amazonSeller = new AmazonSeller(
|
this.amazonSeller = new AmazonSeller(
|
||||||
config.getProperty("AMAZON_API_URL"),
|
config.getProperty("AMAZON_API_URL"),
|
||||||
config.getProperty("AMAZON_API_KEY")
|
config.getProperty("AMAZON_API_KEY"));
|
||||||
);
|
|
||||||
this.ebaySeller = new EbaySeller(
|
this.ebaySeller = new EbaySeller(
|
||||||
config.getProperty("EBAY_API_URL"),
|
config.getProperty("EBAY_API_URL"),
|
||||||
config.getProperty("EBAY_API_KEY")
|
config.getProperty("EBAY_API_KEY"));
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void runProvisioner(List<Offer> offersToProvision) {
|
/**
|
||||||
/*
|
* Method for placing orders on a target platform.
|
||||||
* Bekommt vom Identifier eine Liste mit Angeboten, die er einstellen soll auf Zielplattformen
|
* @param offersToProvision
|
||||||
* Stellt Angebote bei der Zielplattform ein
|
|
||||||
* Schreibt eingestellte Angebote in die Datenbank
|
|
||||||
*/
|
*/
|
||||||
|
public final void runProvisioner(final List<Offer> offersToProvision) {
|
||||||
|
|
||||||
for (Offer newOffer: offersToProvision){
|
for (Offer newOffer: offersToProvision){
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -77,8 +87,7 @@ public class OfferProvisioner {
|
|||||||
// "duplicate" the product with dataOrigin new platform and merchant = "me"
|
// "duplicate" the product with dataOrigin new platform and merchant = "me"
|
||||||
try {
|
try {
|
||||||
offerWriter.writeOfferToPersistence(newOffer);
|
offerWriter.writeOfferToPersistence(newOffer);
|
||||||
}
|
} catch (Exception e) {
|
||||||
catch (Exception e){
|
|
||||||
System.out.println("Could not write to persistence");
|
System.out.println("Could not write to persistence");
|
||||||
}
|
}
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
|
|||||||
Reference in New Issue
Block a user