Cleanup
This commit is contained in:
@@ -33,21 +33,25 @@ public class OfferIdentifier {
|
|||||||
for (ProductCatalogue pCat : pCats) {
|
for (ProductCatalogue pCat : pCats) {
|
||||||
|
|
||||||
// Call price finder for all catalogue
|
// Call price finder for all catalogue
|
||||||
ProductPair pair = getHighestMarginProducts(pCat);
|
try {
|
||||||
Offer possibleOffer = new Offer();
|
ProductPair pair = getHighestMarginProducts(pCat);
|
||||||
possibleOffer.setLastUpdate(Timestamp.now());
|
Offer possibleOffer = new Offer();
|
||||||
possibleOffer.setSourceProduct(pair.getProduct1());
|
possibleOffer.setLastUpdate(Timestamp.now());
|
||||||
possibleOffer.setTargetProduct(pair.getProduct2());
|
possibleOffer.setSourceProduct(pair.getProduct1());
|
||||||
identifiedOffers.add(possibleOffer);
|
possibleOffer.setTargetProduct(pair.getProduct2());
|
||||||
|
identifiedOffers.add(possibleOffer);
|
||||||
|
|
||||||
double margin = pair.getProduct2().getCurrentPrice()
|
double margin = pair.getProduct2().getCurrentPrice()
|
||||||
- pair.getProduct1().getCurrentPrice();
|
- pair.getProduct1().getCurrentPrice();
|
||||||
String marginFormatted = FormattingUtil.formatEuro(margin);
|
String marginFormatted = FormattingUtil.formatEuro(margin);
|
||||||
LOGGER.info("\n Identified Offer: {} ({} to {}) with margin {} ",
|
LOGGER.info("\n Identified Offer: {} ({} to {}) with margin {} ",
|
||||||
pCat.getProductName(),
|
pCat.getProductName(),
|
||||||
pair.getProduct1().getDataOrigin(),
|
pair.getProduct1().getDataOrigin(),
|
||||||
pair.getProduct2().getDataOrigin(),
|
pair.getProduct2().getDataOrigin(),
|
||||||
marginFormatted);
|
marginFormatted);
|
||||||
|
} catch (InvalidOfferException e) {
|
||||||
|
// Don't include offer if deemed invalid
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return identifiedOffers;
|
return identifiedOffers;
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ import de.rwu.easydrop.api.client.PurchaserFactory;
|
|||||||
import de.rwu.easydrop.api.client.SellerFactory;
|
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.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.FormattingUtil;
|
import de.rwu.easydrop.util.FormattingUtil;
|
||||||
@@ -51,15 +50,13 @@ public class OfferProvisioner {
|
|||||||
* @param offer
|
* @param offer
|
||||||
*/
|
*/
|
||||||
private void toSeller(final Offer offer) throws IllegalArgumentException {
|
private void toSeller(final Offer offer) throws IllegalArgumentException {
|
||||||
if (offer.getTargetProduct().getDataOrigin() == Webshop.EBAY) {
|
switch (offer.getTargetProduct().getDataOrigin()) {
|
||||||
this.ebaySeller.sellProduct(ProductMapper.mapProductToDTO(offer.getTargetProduct()));
|
case EBAY -> this.ebaySeller.sellProduct(
|
||||||
|
ProductMapper.mapProductToDTO(offer.getTargetProduct()));
|
||||||
} else if (offer.getTargetProduct().getDataOrigin().equals(Webshop.AMAZON)) {
|
case AMAZON -> this.amazonSeller.sellProduct(
|
||||||
this.amazonSeller.sellProduct(ProductMapper.mapProductToDTO(offer.getTargetProduct()));
|
ProductMapper.mapProductToDTO(offer.getTargetProduct()));
|
||||||
} else {
|
default -> throw new IllegalArgumentException("Unsupported source plattform");
|
||||||
throw new IllegalArgumentException("Unsupported target plattform");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -68,17 +65,13 @@ public class OfferProvisioner {
|
|||||||
* @param offer
|
* @param offer
|
||||||
*/
|
*/
|
||||||
private void toBuyer(final Offer offer) throws IllegalArgumentException {
|
private void toBuyer(final Offer offer) throws IllegalArgumentException {
|
||||||
if (offer.getSourceProduct().getDataOrigin() == Webshop.EBAY) {
|
switch (offer.getSourceProduct().getDataOrigin()) {
|
||||||
this.ebayPurchaser.purchaseProduct(
|
case EBAY -> ebayPurchaser.purchaseProduct(
|
||||||
ProductMapper.mapProductToDTO(offer.getSourceProduct()));
|
ProductMapper.mapProductToDTO(offer.getSourceProduct()));
|
||||||
|
case AMAZON -> amazonPurchaser.purchaseProduct(
|
||||||
} else if (offer.getTargetProduct().getDataOrigin().equals(Webshop.AMAZON)) {
|
|
||||||
this.amazonPurchaser.purchaseProduct(
|
|
||||||
ProductMapper.mapProductToDTO(offer.getSourceProduct()));
|
ProductMapper.mapProductToDTO(offer.getSourceProduct()));
|
||||||
} else {
|
default -> throw new IllegalArgumentException("Unsupported target plattform");
|
||||||
throw new IllegalArgumentException("Unsupported target plattform");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -93,13 +93,9 @@ public class ProductRetriever {
|
|||||||
* @return Product from that data source or null if data source not available
|
* @return Product from that data source or null if data source not available
|
||||||
*/
|
*/
|
||||||
public Product getProductFromWebshop(final Webshop shop, final String productIdentifier) {
|
public Product getProductFromWebshop(final Webshop shop, final String productIdentifier) {
|
||||||
switch (shop) {
|
return switch (shop) {
|
||||||
case AMAZON:
|
case AMAZON -> getProductFromAmazon(productIdentifier);
|
||||||
return getProductFromAmazon(productIdentifier);
|
case EBAY -> getProductFromEbay(productIdentifier);
|
||||||
case EBAY:
|
};
|
||||||
return getProductFromEbay(productIdentifier);
|
|
||||||
default:
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user