Connected application components

This commit is contained in:
Marvin Scham
2023-06-27 05:23:43 +02:00
parent b78fb49eb1
commit d01c4d0b1d
31 changed files with 402 additions and 561 deletions

View File

@@ -0,0 +1,81 @@
package de.rwu.easydrop.service.processing;
import java.util.List;
import de.rwu.easydrop.api.client.AmazonSeller;
import de.rwu.easydrop.api.client.EbaySeller;
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;
public class OfferProvisioner {
/**
* Config.
*/
private Config config;
/**
* Writes offers into persistence.
*/
private OfferWriter offerWriter;
/**
* 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 {
if (offer.getTargetProduct().getDataOrigin() == Webshop.eBay) {
this.ebaySeller.sellProduct(ProductMapper.mapProductToDTO(offer.getTargetProduct()));
} else if (offer.getTargetProduct().getDataOrigin().equals(Webshop.Amazon)) {
this.amazonSeller.sellProduct(ProductMapper.mapProductToDTO(offer.getTargetProduct()));
} else {
throw new IllegalArgumentException("Unsupported target plattform");
}
}
/**
* Is the class for placing orders on a target platform.
*
* @param db Persistence Interface
*/
public OfferProvisioner(final OfferPersistenceInterface db) {
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"));
}
/**
* Method for placing orders on a target platform.
*
* @param offersToProvision
*/
public final void runProvisioner(final List<Offer> offersToProvision) {
for (Offer newOffer : offersToProvision) {
String newOfferId = FormattingUtil.removeSpaces(
newOffer.getSourceProduct().getDataOrigin().toString()
+ newOffer.getTargetProduct().getDataOrigin().toString()
+ "_"
+ newOffer.getSourceProduct().getProductId()
+ newOffer.getTargetProduct().getProductId());
this.toSeller(newOffer);
newOffer.setOfferId(newOfferId);
offerWriter.writeOfferToPersistence(newOffer);
}
}
}