Webshops refactoring + checkstyle
This commit is contained in:
@@ -9,6 +9,7 @@ import java.net.URL;
|
|||||||
|
|
||||||
import de.rwu.easydrop.api.dto.ProductDTO;
|
import de.rwu.easydrop.api.dto.ProductDTO;
|
||||||
import de.rwu.easydrop.exception.DataSourceException;
|
import de.rwu.easydrop.exception.DataSourceException;
|
||||||
|
import de.rwu.easydrop.model.Webshop;
|
||||||
import de.rwu.easydrop.util.FormattingUtil;
|
import de.rwu.easydrop.util.FormattingUtil;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -23,7 +24,7 @@ public abstract class AbstractDataSource implements DataSource {
|
|||||||
*
|
*
|
||||||
* @return Data source name
|
* @return Data source name
|
||||||
*/
|
*/
|
||||||
protected abstract String getDataOrigin();
|
protected abstract Webshop getDataOrigin();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the data source's API key.
|
* Returns the data source's API key.
|
||||||
@@ -48,7 +49,7 @@ public abstract class AbstractDataSource implements DataSource {
|
|||||||
public ProductDTO getProductDTOById(final String productIdentifier)
|
public ProductDTO getProductDTOById(final String productIdentifier)
|
||||||
throws IllegalArgumentException {
|
throws IllegalArgumentException {
|
||||||
StringBuilder response = new StringBuilder();
|
StringBuilder response = new StringBuilder();
|
||||||
String dataOrigin = getDataOrigin();
|
Webshop dataOrigin = getDataOrigin();
|
||||||
String apiKey = getApiKey();
|
String apiKey = getApiKey();
|
||||||
ProductDTO product = new ProductDTO(productIdentifier, dataOrigin);
|
ProductDTO product = new ProductDTO(productIdentifier, dataOrigin);
|
||||||
|
|
||||||
@@ -72,20 +73,16 @@ public abstract class AbstractDataSource implements DataSource {
|
|||||||
+ responseCode);
|
+ responseCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
String line;
|
String line;
|
||||||
while ((line = reader.readLine()) != null) {
|
while ((line = reader.readLine()) != null) {
|
||||||
response.append(line);
|
response.append(line);
|
||||||
}
|
}
|
||||||
reader.close();
|
reader.close();
|
||||||
|
|
||||||
// FIXME: Mock not complete. Data is missing
|
|
||||||
// FIXME response can be empty
|
|
||||||
String data;
|
String data;
|
||||||
if (response.toString().isEmpty()){
|
if (response.toString().isEmpty()) {
|
||||||
data = "{}";
|
data = "{}";
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
data = response.toString();
|
data = response.toString();
|
||||||
}
|
}
|
||||||
buildProductDTO(product, data);
|
buildProductDTO(product, data);
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import java.net.URL;
|
|||||||
|
|
||||||
import de.rwu.easydrop.api.dto.ProductDTO;
|
import de.rwu.easydrop.api.dto.ProductDTO;
|
||||||
import de.rwu.easydrop.exception.DataWriterException;
|
import de.rwu.easydrop.exception.DataWriterException;
|
||||||
|
import de.rwu.easydrop.model.Webshop;
|
||||||
import de.rwu.easydrop.util.FormattingUtil;
|
import de.rwu.easydrop.util.FormattingUtil;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -28,7 +29,7 @@ public abstract class AbstractDataWriter {
|
|||||||
*
|
*
|
||||||
* @return Data target API name
|
* @return Data target API name
|
||||||
*/
|
*/
|
||||||
protected abstract String getDataTarget();
|
protected abstract Webshop getDataTarget();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates an URL object to connect to the API with.
|
* Creates an URL object to connect to the API with.
|
||||||
@@ -47,7 +48,7 @@ public abstract class AbstractDataWriter {
|
|||||||
*/
|
*/
|
||||||
protected void sendPutRequest(final ProductDTO dto, final String apiType) {
|
protected void sendPutRequest(final ProductDTO dto, final String apiType) {
|
||||||
String apiKey = getApiKey();
|
String apiKey = getApiKey();
|
||||||
String dataTarget = getDataTarget();
|
Webshop dataTarget = getDataTarget();
|
||||||
|
|
||||||
if (!dataTarget.equals(dto.getDataOrigin())) {
|
if (!dataTarget.equals(dto.getDataOrigin())) {
|
||||||
throw new DataWriterException(
|
throw new DataWriterException(
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import com.jayway.jsonpath.PathNotFoundException;
|
|||||||
import com.jayway.jsonpath.ReadContext;
|
import com.jayway.jsonpath.ReadContext;
|
||||||
|
|
||||||
import de.rwu.easydrop.api.dto.ProductDTO;
|
import de.rwu.easydrop.api.dto.ProductDTO;
|
||||||
|
import de.rwu.easydrop.model.Webshop;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Interface to an Amazon data source.
|
* Interface to an Amazon data source.
|
||||||
@@ -18,7 +19,7 @@ public final class AmazonProductDataSource extends AbstractDataSource {
|
|||||||
/**
|
/**
|
||||||
* Name of this data source.
|
* Name of this data source.
|
||||||
*/
|
*/
|
||||||
private static final String DATA_ORIGIN = "Amazon";
|
private static final Webshop DATA_ORIGIN = Webshop.Amazon;
|
||||||
/**
|
/**
|
||||||
* Base URL to the Amazon data source.
|
* Base URL to the Amazon data source.
|
||||||
*/
|
*/
|
||||||
@@ -82,7 +83,7 @@ public final class AmazonProductDataSource extends AbstractDataSource {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected String getDataOrigin() {
|
protected Webshop getDataOrigin() {
|
||||||
return DATA_ORIGIN;
|
return DATA_ORIGIN;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,8 @@ package de.rwu.easydrop.api.client;
|
|||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
|
||||||
|
import de.rwu.easydrop.model.Webshop;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sends a buy request to the Amazon API.
|
* Sends a buy request to the Amazon API.
|
||||||
*
|
*
|
||||||
@@ -12,7 +14,7 @@ public final class AmazonPurchaser extends AbstractPurchaser {
|
|||||||
/**
|
/**
|
||||||
* Name of this data source.
|
* Name of this data source.
|
||||||
*/
|
*/
|
||||||
private static final String DATA_TARGET = "Amazon";
|
private static final Webshop DATA_TARGET = Webshop.Amazon;
|
||||||
/**
|
/**
|
||||||
* Base URL to the Amazon Purchase API.
|
* Base URL to the Amazon Purchase API.
|
||||||
*/
|
*/
|
||||||
@@ -61,7 +63,7 @@ public final class AmazonPurchaser extends AbstractPurchaser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected String getDataTarget() {
|
protected Webshop getDataTarget() {
|
||||||
return DATA_TARGET;
|
return DATA_TARGET;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,8 @@ package de.rwu.easydrop.api.client;
|
|||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
|
||||||
|
import de.rwu.easydrop.model.Webshop;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sends a sell request to the Amazon API.
|
* Sends a sell request to the Amazon API.
|
||||||
*
|
*
|
||||||
@@ -12,7 +14,7 @@ public final class AmazonSeller extends AbstractSeller {
|
|||||||
/**
|
/**
|
||||||
* Name of this data source.
|
* Name of this data source.
|
||||||
*/
|
*/
|
||||||
private static final String DATA_TARGET = "Amazon";
|
private static final Webshop DATA_TARGET = Webshop.Amazon;
|
||||||
/**
|
/**
|
||||||
* Base URL to the Amazon Purchase API.
|
* Base URL to the Amazon Purchase API.
|
||||||
*/
|
*/
|
||||||
@@ -61,7 +63,7 @@ public final class AmazonSeller extends AbstractSeller {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected String getDataTarget() {
|
protected Webshop getDataTarget() {
|
||||||
return DATA_TARGET;
|
return DATA_TARGET;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import com.jayway.jsonpath.PathNotFoundException;
|
|||||||
import com.jayway.jsonpath.ReadContext;
|
import com.jayway.jsonpath.ReadContext;
|
||||||
|
|
||||||
import de.rwu.easydrop.api.dto.ProductDTO;
|
import de.rwu.easydrop.api.dto.ProductDTO;
|
||||||
|
import de.rwu.easydrop.model.Webshop;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Interface to an eBay data source.
|
* Interface to an eBay data source.
|
||||||
@@ -18,7 +19,7 @@ public final class EbayItemDataSource extends AbstractDataSource {
|
|||||||
/**
|
/**
|
||||||
* Name of this data source.
|
* Name of this data source.
|
||||||
*/
|
*/
|
||||||
private static final String DATA_ORIGIN = "eBay";
|
private static final Webshop DATA_ORIGIN = Webshop.eBay;
|
||||||
/**
|
/**
|
||||||
* Base URL to the eBay data source.
|
* Base URL to the eBay data source.
|
||||||
*/
|
*/
|
||||||
@@ -77,7 +78,7 @@ public final class EbayItemDataSource extends AbstractDataSource {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected String getDataOrigin() {
|
protected Webshop getDataOrigin() {
|
||||||
return DATA_ORIGIN;
|
return DATA_ORIGIN;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,8 @@ package de.rwu.easydrop.api.client;
|
|||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
|
||||||
|
import de.rwu.easydrop.model.Webshop;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sends a buy request to the eBay API.
|
* Sends a buy request to the eBay API.
|
||||||
*
|
*
|
||||||
@@ -12,7 +14,7 @@ public final class EbayPurchaser extends AbstractPurchaser {
|
|||||||
/**
|
/**
|
||||||
* Name of this data source.
|
* Name of this data source.
|
||||||
*/
|
*/
|
||||||
private static final String DATA_TARGET = "eBay";
|
private static final Webshop DATA_TARGET = Webshop.eBay;
|
||||||
/**
|
/**
|
||||||
* Base URL to the eBay Purchase API.
|
* Base URL to the eBay Purchase API.
|
||||||
*/
|
*/
|
||||||
@@ -46,7 +48,7 @@ public final class EbayPurchaser extends AbstractPurchaser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected String getDataTarget() {
|
protected Webshop getDataTarget() {
|
||||||
return DATA_TARGET;
|
return DATA_TARGET;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,8 @@ package de.rwu.easydrop.api.client;
|
|||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
|
||||||
|
import de.rwu.easydrop.model.Webshop;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sends a sell request to the eBay API.
|
* Sends a sell request to the eBay API.
|
||||||
*
|
*
|
||||||
@@ -12,7 +14,7 @@ public final class EbaySeller extends AbstractSeller {
|
|||||||
/**
|
/**
|
||||||
* Name of this data source.
|
* Name of this data source.
|
||||||
*/
|
*/
|
||||||
private static final String DATA_TARGET = "eBay";
|
private static final Webshop DATA_TARGET = Webshop.eBay;
|
||||||
/**
|
/**
|
||||||
* Base URL to the eBay Purchase API.
|
* Base URL to the eBay Purchase API.
|
||||||
*/
|
*/
|
||||||
@@ -46,7 +48,7 @@ public final class EbaySeller extends AbstractSeller {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected String getDataTarget() {
|
protected Webshop getDataTarget() {
|
||||||
return DATA_TARGET;
|
return DATA_TARGET;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,36 +14,37 @@ public class OfferDTO {
|
|||||||
*/
|
*/
|
||||||
private String offerId;
|
private String offerId;
|
||||||
|
|
||||||
/*
|
/**
|
||||||
* The product that our software buys
|
* The product that our software buys.
|
||||||
*/
|
*/
|
||||||
Product sourceProduct;
|
private Product sourceProduct;
|
||||||
|
|
||||||
/*
|
/**
|
||||||
* The product that our software sells
|
* The product that our software sells.
|
||||||
*/
|
*/
|
||||||
Product saleProduct;
|
private Product saleProduct;
|
||||||
|
|
||||||
/*
|
/**
|
||||||
* Date of the creation of the offer
|
* Date of the creation of the offer
|
||||||
* NOTE: Use Timestamp? https://docs.oracle.com/javase/8/docs/api/java/sql/Timestamp.html
|
* NOTE: Use Timestamp?
|
||||||
|
* https://docs.oracle.com/javase/8/docs/api/java/sql/Timestamp.html
|
||||||
*/
|
*/
|
||||||
Date creationDate;
|
private Date creationDate;
|
||||||
|
|
||||||
/*
|
/**
|
||||||
* Date of last update of the offer on the destination website (API)
|
* Date of last update of the offer on the destination website (API).
|
||||||
*/
|
*/
|
||||||
Date upDate;
|
private Date upDate;
|
||||||
|
|
||||||
/*
|
/**
|
||||||
* Date of last check if offer is still valid
|
* Date of last check if offer is still valid.
|
||||||
*/
|
*/
|
||||||
Date checkDate;
|
private Date checkDate;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates OfferDTO instance.
|
* Creates OfferDTO instance.
|
||||||
*
|
*
|
||||||
* @param newOfferId Internal Offer identifier
|
* @param newOfferId Internal Offer identifier
|
||||||
*/
|
*/
|
||||||
public OfferDTO(final String newOfferId) {
|
public OfferDTO(final String newOfferId) {
|
||||||
this.offerId = newOfferId;
|
this.offerId = newOfferId;
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package de.rwu.easydrop.api.dto;
|
package de.rwu.easydrop.api.dto;
|
||||||
|
|
||||||
|
import de.rwu.easydrop.model.Webshop;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -10,9 +11,9 @@ import lombok.Data;
|
|||||||
@Data
|
@Data
|
||||||
public class ProductDTO {
|
public class ProductDTO {
|
||||||
/**
|
/**
|
||||||
* Data source platform, like "Amazon".
|
* Data source platform, like Amazon.
|
||||||
*/
|
*/
|
||||||
private String dataOrigin;
|
private Webshop dataOrigin;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Platform internal product identifier.
|
* Platform internal product identifier.
|
||||||
@@ -45,7 +46,7 @@ public class ProductDTO {
|
|||||||
* @param newProductId Internal Product indetifier
|
* @param newProductId Internal Product indetifier
|
||||||
* @param newDataOrigin Data Origin
|
* @param newDataOrigin Data Origin
|
||||||
*/
|
*/
|
||||||
public ProductDTO(final String newProductId, final String newDataOrigin) {
|
public ProductDTO(final String newProductId, final Webshop newDataOrigin) {
|
||||||
this.productId = newProductId;
|
this.productId = newProductId;
|
||||||
this.dataOrigin = newDataOrigin;
|
this.dataOrigin = newDataOrigin;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,32 +7,39 @@ import javax.naming.ConfigurationException;
|
|||||||
import de.rwu.easydrop.model.Offer;
|
import de.rwu.easydrop.model.Offer;
|
||||||
import de.rwu.easydrop.model.ProductCatalogue;
|
import de.rwu.easydrop.model.ProductCatalogue;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The application core.
|
||||||
|
*
|
||||||
|
* @since 0.3.0
|
||||||
|
*/
|
||||||
public class Core {
|
public class Core {
|
||||||
|
/**
|
||||||
|
* Offer identifier.
|
||||||
|
*/
|
||||||
private OfferIdentifier ident;
|
private OfferIdentifier ident;
|
||||||
|
/**
|
||||||
|
* Offer provisioner.
|
||||||
|
*/
|
||||||
private OfferProvisioner provis;
|
private OfferProvisioner provis;
|
||||||
private OfferReviewer review;
|
|
||||||
private OfferUpdater update;
|
|
||||||
|
|
||||||
|
/**
|
||||||
public Core() throws ConfigurationException{
|
* Constructor.
|
||||||
|
*
|
||||||
|
* @throws ConfigurationException
|
||||||
|
*/
|
||||||
|
public Core() throws ConfigurationException {
|
||||||
this.ident = new OfferIdentifier();
|
this.ident = new OfferIdentifier();
|
||||||
this.provis = new OfferProvisioner();
|
this.provis = new OfferProvisioner();
|
||||||
this.review = new OfferReviewer();
|
|
||||||
this.update = new OfferUpdater();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
public void runCore(List<ProductCatalogue> pCats){
|
* Runs the core.
|
||||||
|
*
|
||||||
|
* @param pCats
|
||||||
|
*/
|
||||||
|
public void runCore(final List<ProductCatalogue> pCats) {
|
||||||
List<Offer> identifiedOffers = ident.runIdentifier(pCats);
|
List<Offer> identifiedOffers = ident.runIdentifier(pCats);
|
||||||
provis.runProvisioner(identifiedOffers);
|
provis.runProvisioner(identifiedOffers);
|
||||||
List<Offer> updatingOffers = review.runReviewer();
|
|
||||||
update.runUpdater(updatingOffers);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,7 +14,6 @@ import de.rwu.easydrop.service.retriever.OfferRetriever;
|
|||||||
import de.rwu.easydrop.service.processing.OrderManager;
|
import de.rwu.easydrop.service.processing.OrderManager;
|
||||||
import de.rwu.easydrop.exception.InvalidCatalogueException;
|
import de.rwu.easydrop.exception.InvalidCatalogueException;
|
||||||
|
|
||||||
|
|
||||||
public class OfferIdentifier {
|
public class OfferIdentifier {
|
||||||
/**
|
/**
|
||||||
* Logger for main process.
|
* Logger for main process.
|
||||||
@@ -24,13 +23,15 @@ public class OfferIdentifier {
|
|||||||
* OfferRetriever gets the offer from persistence.
|
* OfferRetriever gets the offer from persistence.
|
||||||
*/
|
*/
|
||||||
private OfferRetriever offerRetriever;
|
private OfferRetriever offerRetriever;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* OfferIdentifier identifies offers that are
|
* OfferIdentifier identifies offers that are
|
||||||
* feasible to place on a target platform based on
|
* feasible to place on a target platform based on
|
||||||
* their margin.
|
* their margin.
|
||||||
|
*
|
||||||
* @throws ConfigurationException
|
* @throws ConfigurationException
|
||||||
*/
|
*/
|
||||||
public OfferIdentifier() throws ConfigurationException{
|
public OfferIdentifier() throws ConfigurationException {
|
||||||
this.offerRetriever = new OfferRetriever();
|
this.offerRetriever = new OfferRetriever();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -38,6 +39,7 @@ public class OfferIdentifier {
|
|||||||
* runIdentifier calls the price function that decides
|
* runIdentifier calls the price function that decides
|
||||||
* if it is feasible to dropship products and if so,
|
* if it is feasible to dropship products and if so,
|
||||||
* at which margin.
|
* at which margin.
|
||||||
|
*
|
||||||
* @param pCats
|
* @param pCats
|
||||||
* @return newOffers
|
* @return newOffers
|
||||||
*/
|
*/
|
||||||
@@ -53,36 +55,25 @@ 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
|
||||||
}
|
} catch (InvalidCatalogueException e) {
|
||||||
catch (InvalidCatalogueException e) {
|
|
||||||
// if no margin, getHighestMarginProducts will throw
|
// if no margin, getHighestMarginProducts will throw
|
||||||
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();
|
for (Offer identifiedOffer : identifiedOffers) {
|
||||||
for (Offer identifiedOffer: identifiedOffers) {
|
|
||||||
boolean isNew = true;
|
boolean isNew = true;
|
||||||
for (Offer existingOffer: existingOffers) {
|
|
||||||
if (
|
|
||||||
existingOffer.getSourceProduct().getProductId().
|
|
||||||
equals(identifiedOffer.getSourceProduct().getProductId())) {
|
|
||||||
isNew = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (isNew) {
|
if (isNew) {
|
||||||
newOffers.add(identifiedOffer);
|
newOffers.add(identifiedOffer);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,33 +2,23 @@ package de.rwu.easydrop.core;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import de.rwu.easydrop.util.Config;
|
|
||||||
import de.rwu.easydrop.data.connector.AbstractProductPersistence;
|
|
||||||
import de.rwu.easydrop.exception.DataWriterException;
|
|
||||||
import de.rwu.easydrop.model.Offer;
|
|
||||||
import de.rwu.easydrop.service.retriever.ProductRetriever;
|
|
||||||
import de.rwu.easydrop.service.writer.OfferWriter;
|
|
||||||
import de.rwu.easydrop.api.client.AmazonSeller;
|
import de.rwu.easydrop.api.client.AmazonSeller;
|
||||||
import de.rwu.easydrop.api.client.EbaySeller;
|
import de.rwu.easydrop.api.client.EbaySeller;
|
||||||
import de.rwu.easydrop.api.dto.ProductDTO;
|
import de.rwu.easydrop.exception.DataWriterException;
|
||||||
|
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;
|
||||||
|
|
||||||
public class OfferProvisioner {
|
public class OfferProvisioner {
|
||||||
/**
|
/**
|
||||||
* Config.
|
* Config.
|
||||||
*/
|
*/
|
||||||
private Config config;
|
private Config config;
|
||||||
/**
|
|
||||||
* Gets the products from persistence.
|
|
||||||
*/
|
|
||||||
private ProductRetriever productRetriever;
|
|
||||||
// ProductWriter
|
|
||||||
/**
|
|
||||||
* Is the product databank.
|
|
||||||
*/
|
|
||||||
private AbstractProductPersistence db;
|
|
||||||
/**
|
/**
|
||||||
* Writes offers into persistence.
|
* Writes offers into persistence.
|
||||||
*/
|
*/
|
||||||
private OfferWriter offerWriter;
|
private OfferWriter offerWriter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -41,16 +31,11 @@ public class OfferProvisioner {
|
|||||||
private EbaySeller ebaySeller;
|
private EbaySeller ebaySeller;
|
||||||
|
|
||||||
private void toSeller(final Offer offer) throws IllegalArgumentException {
|
private void toSeller(final Offer offer) throws IllegalArgumentException {
|
||||||
// TODO dataOrigin should use the webshop enum
|
if (offer.getSaleProduct().getDataOrigin() == Webshop.eBay) {
|
||||||
if (offer.getSaleProduct().getDataOrigin().toLowerCase().equals("ebay")) {
|
this.ebaySeller.sellProduct(ProductMapper.mapProductToDTO(offer.getSaleProduct()));
|
||||||
this.ebaySeller.sellProduct(new ProductDTO(
|
|
||||||
offer.getSaleProduct().getProductId(),
|
|
||||||
"Amazon"));
|
|
||||||
|
|
||||||
} else if (offer.getSaleProduct().getDataOrigin().toLowerCase().equals("amazon")) {
|
} else if (offer.getSaleProduct().getDataOrigin().equals(Webshop.Amazon)) {
|
||||||
this.amazonSeller.sellProduct(new ProductDTO(
|
this.amazonSeller.sellProduct(ProductMapper.mapProductToDTO(offer.getSaleProduct()));
|
||||||
offer.getSaleProduct().getProductId(),
|
|
||||||
"eBay"));
|
|
||||||
} else {
|
} else {
|
||||||
throw new IllegalArgumentException("Unsupported target plattform");
|
throw new IllegalArgumentException("Unsupported target plattform");
|
||||||
}
|
}
|
||||||
@@ -74,11 +59,12 @@ public class OfferProvisioner {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Method for placing orders on a target platform.
|
* Method for placing orders on a target platform.
|
||||||
|
*
|
||||||
* @param offersToProvision
|
* @param offersToProvision
|
||||||
*/
|
*/
|
||||||
public final void runProvisioner(final List<Offer> offersToProvision) {
|
public final void runProvisioner(final List<Offer> offersToProvision) {
|
||||||
|
|
||||||
for (Offer newOffer: offersToProvision){
|
for (Offer newOffer : offersToProvision) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
this.toSeller(newOffer);
|
this.toSeller(newOffer);
|
||||||
@@ -92,10 +78,9 @@ public class OfferProvisioner {
|
|||||||
}
|
}
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
System.out.println(
|
System.out.println(
|
||||||
"Offer could not be placed, " +
|
"Offer could not be placed, "
|
||||||
newOffer.getSaleProduct().getDataOrigin() +
|
+ newOffer.getSaleProduct().getDataOrigin()
|
||||||
" is not supported"
|
+ " is not supported");
|
||||||
);
|
|
||||||
} catch (DataWriterException e) {
|
} catch (DataWriterException e) {
|
||||||
System.out.println("could not transmit offer");
|
System.out.println("could not transmit offer");
|
||||||
}
|
}
|
||||||
|
|||||||
6
src/main/java/de/rwu/easydrop/core/package-info.java
Normal file
6
src/main/java/de/rwu/easydrop/core/package-info.java
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
/**
|
||||||
|
* EasyDrop's core.
|
||||||
|
*
|
||||||
|
* @since 0.3.0
|
||||||
|
*/
|
||||||
|
package de.rwu.easydrop.core;
|
||||||
@@ -2,12 +2,7 @@ package de.rwu.easydrop.data.connector;
|
|||||||
|
|
||||||
import de.rwu.easydrop.api.dto.OfferDTO;
|
import de.rwu.easydrop.api.dto.OfferDTO;
|
||||||
|
|
||||||
public abstract class AbstractOfferPersistence {
|
public abstract class AbstractOfferPersistence {
|
||||||
/**
|
|
||||||
* Data origin.
|
|
||||||
*/
|
|
||||||
public static final String DATA_ORIGIN = "Persistence";
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Writes a ProductDTO to persistence.
|
* Writes a ProductDTO to persistence.
|
||||||
*
|
*
|
||||||
@@ -17,9 +12,11 @@ public abstract class AbstractOfferPersistence {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets a OfferDTO from persistence.
|
* Gets a OfferDTO from persistence.
|
||||||
|
*
|
||||||
|
* @param offerId
|
||||||
|
* @return Offer data transfer object
|
||||||
*/
|
*/
|
||||||
//@Override
|
public abstract OfferDTO getOfferDTOById(String offerId);
|
||||||
public abstract OfferDTO getOfferDTOById(String OfferId);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Deletes all data from persistence.
|
* Deletes all data from persistence.
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import org.sqlite.SQLiteDataSource;
|
|||||||
|
|
||||||
import de.rwu.easydrop.api.dto.ProductDTO;
|
import de.rwu.easydrop.api.dto.ProductDTO;
|
||||||
import de.rwu.easydrop.exception.PersistenceException;
|
import de.rwu.easydrop.exception.PersistenceException;
|
||||||
|
import de.rwu.easydrop.model.Webshop;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Allows connecting to a SQLite Database.
|
* Allows connecting to a SQLite Database.
|
||||||
@@ -18,11 +19,6 @@ import de.rwu.easydrop.exception.PersistenceException;
|
|||||||
* @since 0.2.0
|
* @since 0.2.0
|
||||||
*/
|
*/
|
||||||
public final class SQLiteConnector extends AbstractProductPersistence {
|
public final class SQLiteConnector extends AbstractProductPersistence {
|
||||||
/**
|
|
||||||
* Data origin.
|
|
||||||
*/
|
|
||||||
private static final String DATA_ORIGIN = "SQLite";
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* SQLite Database.
|
* SQLite Database.
|
||||||
*/
|
*/
|
||||||
@@ -95,7 +91,7 @@ public final class SQLiteConnector extends AbstractProductPersistence {
|
|||||||
PreparedStatement statement = connection.prepareStatement(query)) {
|
PreparedStatement statement = connection.prepareStatement(query)) {
|
||||||
int index = 0;
|
int index = 0;
|
||||||
|
|
||||||
statement.setString(++index, dto.getDataOrigin());
|
statement.setString(++index, dto.getDataOrigin().toString());
|
||||||
statement.setString(++index, dto.getProductId());
|
statement.setString(++index, dto.getProductId());
|
||||||
statement.setDouble(++index, dto.getCurrentPrice());
|
statement.setDouble(++index, dto.getCurrentPrice());
|
||||||
statement.setString(++index, dto.getMerchant());
|
statement.setString(++index, dto.getMerchant());
|
||||||
@@ -120,8 +116,9 @@ public final class SQLiteConnector extends AbstractProductPersistence {
|
|||||||
|
|
||||||
try (ResultSet resultSet = statement.executeQuery()) {
|
try (ResultSet resultSet = statement.executeQuery()) {
|
||||||
if (resultSet.next()) {
|
if (resultSet.next()) {
|
||||||
dto = new ProductDTO(resultSet.getString("productId"),
|
Webshop newShop = Webshop.fromString(resultSet.getString("dataOrigin"));
|
||||||
resultSet.getString("dataOrigin"));
|
|
||||||
|
dto = new ProductDTO(resultSet.getString("productId"), newShop);
|
||||||
dto.setCurrentPrice(resultSet.getDouble("currentPrice"));
|
dto.setCurrentPrice(resultSet.getDouble("currentPrice"));
|
||||||
dto.setMerchant(resultSet.getString("merchant"));
|
dto.setMerchant(resultSet.getString("merchant"));
|
||||||
dto.setDeliveryPrice(resultSet.getDouble("deliveryPrice"));
|
dto.setDeliveryPrice(resultSet.getDouble("deliveryPrice"));
|
||||||
@@ -149,8 +146,9 @@ public final class SQLiteConnector extends AbstractProductPersistence {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected String getDataOrigin() {
|
protected Webshop getDataOrigin() {
|
||||||
return DATA_ORIGIN;
|
throw new UnsupportedOperationException(
|
||||||
|
this.getClass().getName() + " doesn't support getDataOrigin");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -10,23 +10,10 @@ import lombok.Data;
|
|||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
public class Product {
|
public class Product {
|
||||||
/**
|
|
||||||
* Constants for data source/destination platforms.
|
|
||||||
*/
|
|
||||||
public enum Webshop {
|
|
||||||
/**
|
|
||||||
* Amazon.
|
|
||||||
*/
|
|
||||||
AMAZON,
|
|
||||||
/**Ebay.
|
|
||||||
*/
|
|
||||||
EBAY
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Data source platform, like "Amazon".
|
* Data source platform, like "Amazon".
|
||||||
*/
|
*/
|
||||||
private String dataOrigin;
|
private Webshop dataOrigin;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Platform internal product identifier.
|
* Platform internal product identifier.
|
||||||
|
|||||||
@@ -5,11 +5,27 @@ package de.rwu.easydrop.model;
|
|||||||
*/
|
*/
|
||||||
public enum Webshop {
|
public enum Webshop {
|
||||||
/**
|
/**
|
||||||
* Amazon.
|
* Amazon Product API.
|
||||||
*/
|
*/
|
||||||
Amazon,
|
Amazon,
|
||||||
/**
|
/**
|
||||||
* eBay.
|
* eBay Item API.
|
||||||
*/
|
*/
|
||||||
eBay
|
eBay;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Attempts to derive a webshop value from a string.
|
||||||
|
*
|
||||||
|
* @param str String
|
||||||
|
* @return webshop
|
||||||
|
* @throws IllegalArgumentException
|
||||||
|
*/
|
||||||
|
public static Webshop fromString(final String str) {
|
||||||
|
for (Webshop shop : Webshop.values()) {
|
||||||
|
if (shop.toString().equalsIgnoreCase(str)) {
|
||||||
|
return shop;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw new IllegalArgumentException(String.format("No webshop called {} found", str));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,7 +11,6 @@ import de.rwu.easydrop.model.Offer;
|
|||||||
*
|
*
|
||||||
* @see Offer
|
* @see Offer
|
||||||
* @see OfferDTO
|
* @see OfferDTO
|
||||||
* @see OfferDTO
|
|
||||||
*/
|
*/
|
||||||
public final class OfferMapper {
|
public final class OfferMapper {
|
||||||
|
|
||||||
@@ -39,7 +38,7 @@ public final class OfferMapper {
|
|||||||
/**
|
/**
|
||||||
* Creates an OfferDTO object from a corresponding offer.
|
* Creates an OfferDTO object from a corresponding offer.
|
||||||
*
|
*
|
||||||
* @param Offer offer
|
* @param offer
|
||||||
* @return OfferDTO
|
* @return OfferDTO
|
||||||
*/
|
*/
|
||||||
public static OfferDTO mapOfferToDTO(final Offer offer) {
|
public static OfferDTO mapOfferToDTO(final Offer offer) {
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ import java.util.List;
|
|||||||
|
|
||||||
import javax.naming.ConfigurationException;
|
import javax.naming.ConfigurationException;
|
||||||
|
|
||||||
import de.rwu.easydrop.exception.InvalidProductException;
|
|
||||||
import de.rwu.easydrop.model.Product;
|
import de.rwu.easydrop.model.Product;
|
||||||
import de.rwu.easydrop.model.ProductCatalogue;
|
import de.rwu.easydrop.model.ProductCatalogue;
|
||||||
import de.rwu.easydrop.util.ProductsConfig;
|
import de.rwu.easydrop.util.ProductsConfig;
|
||||||
@@ -58,16 +57,9 @@ public class CatalogueRetriever {
|
|||||||
|
|
||||||
for (Product product : pCat.getProducts()) {
|
for (Product product : pCat.getProducts()) {
|
||||||
Product newProduct = new Product();
|
Product newProduct = new Product();
|
||||||
newProduct.setDataOrigin(product.getDataOrigin());
|
|
||||||
newProduct.setProductId(product.getProductId());
|
|
||||||
|
|
||||||
if (newProduct.getDataOrigin().equals("Amazon")) {
|
newProduct = productRetriever.getProductFromWebshop(product.getDataOrigin(),
|
||||||
newProduct = productRetriever.getProductFromAmazon(product.getProductId());
|
product.getProductId());
|
||||||
} else if (newProduct.getDataOrigin().equals("eBay")) {
|
|
||||||
newProduct = productRetriever.getProductFromEbay(product.getProductId());
|
|
||||||
} else {
|
|
||||||
throw new InvalidProductException("Product data origin is invalid");
|
|
||||||
}
|
|
||||||
|
|
||||||
newProductCatalogue.addProduct(newProduct);
|
newProductCatalogue.addProduct(newProduct);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,14 +1,5 @@
|
|||||||
package de.rwu.easydrop.service.retriever;
|
package de.rwu.easydrop.service.retriever;
|
||||||
|
|
||||||
import de.rwu.easydrop.model.Offer;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class OfferRetriever {
|
public class OfferRetriever {
|
||||||
|
|
||||||
public List<Offer> loadOffers() {
|
|
||||||
return new ArrayList<>();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import de.rwu.easydrop.api.client.EbayItemDataSource;
|
|||||||
import de.rwu.easydrop.api.dto.ProductDTO;
|
import de.rwu.easydrop.api.dto.ProductDTO;
|
||||||
import de.rwu.easydrop.data.connector.AbstractProductPersistence;
|
import de.rwu.easydrop.data.connector.AbstractProductPersistence;
|
||||||
import de.rwu.easydrop.model.Product;
|
import de.rwu.easydrop.model.Product;
|
||||||
|
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.validation.ProductValidator;
|
import de.rwu.easydrop.service.validation.ProductValidator;
|
||||||
|
|
||||||
@@ -21,9 +22,9 @@ public class ProductRetriever {
|
|||||||
private DataSourceFactory dataSourceFactory;
|
private DataSourceFactory dataSourceFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param newDataSourceFactory the dataSourceFactory to set
|
* @param newDataSourceFactory the WebshopFactory to set
|
||||||
*/
|
*/
|
||||||
public void setDataSourceFactory(final DataSourceFactory newDataSourceFactory) {
|
public void setWebshopFactory(final DataSourceFactory newDataSourceFactory) {
|
||||||
this.dataSourceFactory = newDataSourceFactory;
|
this.dataSourceFactory = newDataSourceFactory;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -31,7 +32,7 @@ public class ProductRetriever {
|
|||||||
* @param newDataSourceFactory
|
* @param newDataSourceFactory
|
||||||
*/
|
*/
|
||||||
public ProductRetriever(final DataSourceFactory newDataSourceFactory) {
|
public ProductRetriever(final DataSourceFactory newDataSourceFactory) {
|
||||||
this.setDataSourceFactory(newDataSourceFactory);
|
this.setWebshopFactory(newDataSourceFactory);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -83,23 +84,23 @@ public class ProductRetriever {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves a product from an API by name of the API so that high-level components do not need to be extended
|
* Retrieves a product from an API by name of the API so that high-level
|
||||||
|
* components do not need to be extended
|
||||||
* with exact function call names if we extend the list of webshops.
|
* with exact function call names if we extend the list of webshops.
|
||||||
*
|
*
|
||||||
* @param dataSourceName Data source name, e.g. amazon
|
* @param shop Data source name, e.g. Amazon
|
||||||
* @param productName Product name, translated to the correct product ID for the data source
|
* @param productIdentifier Product name, translated to the correct product ID
|
||||||
|
* for the data source
|
||||||
* @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 getProductFromDataSource(Product.webshop dataSourceName, final String productName) {
|
public Product getProductFromWebshop(final Webshop shop, final String productIdentifier) {
|
||||||
switch(dataSourceName) {
|
switch (shop) {
|
||||||
case AMAZON:
|
case Amazon:
|
||||||
// TODO: Translation from productName to productId (Amazon) needed
|
return getProductFromAmazon(productIdentifier);
|
||||||
return getProductFromAmazon(productName);
|
case eBay:
|
||||||
case EBAY:
|
return getProductFromEbay(productIdentifier);
|
||||||
// TODO: Translation from productName to productId (eBay) needed
|
default:
|
||||||
return getProductFromEbay(productName);
|
return null;
|
||||||
default:
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,5 @@
|
|||||||
package de.rwu.easydrop.service.validation;
|
package de.rwu.easydrop.service.validation;
|
||||||
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import de.rwu.easydrop.exception.InvalidProductException;
|
import de.rwu.easydrop.exception.InvalidProductException;
|
||||||
import de.rwu.easydrop.model.Product;
|
import de.rwu.easydrop.model.Product;
|
||||||
|
|
||||||
@@ -31,26 +28,8 @@ public final class ProductValidator {
|
|||||||
if (product.getCurrentPrice() == 0.00) {
|
if (product.getCurrentPrice() == 0.00) {
|
||||||
throw new InvalidProductException("Current price cannot be 0.00");
|
throw new InvalidProductException("Current price cannot be 0.00");
|
||||||
}
|
}
|
||||||
if (!isInValidDataOrigins(product.getDataOrigin())) {
|
|
||||||
throw new InvalidProductException("Unknown data source");
|
|
||||||
}
|
|
||||||
if (product.getProductId().equals("")) {
|
if (product.getProductId().equals("")) {
|
||||||
throw new InvalidProductException("Product ID cannot be empty");
|
throw new InvalidProductException("Product ID cannot be empty");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks whether a dataOrigin is within the set of valid ones.
|
|
||||||
*
|
|
||||||
* @param dataOrigin like "Amazon"
|
|
||||||
* @return true if valid
|
|
||||||
*/
|
|
||||||
public static boolean isInValidDataOrigins(final String dataOrigin) {
|
|
||||||
Set<String> validOrigins = new HashSet<>();
|
|
||||||
|
|
||||||
validOrigins.add("Amazon");
|
|
||||||
validOrigins.add("eBay");
|
|
||||||
|
|
||||||
return validOrigins.contains(dataOrigin);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import com.jayway.jsonpath.JsonPathException;
|
|||||||
|
|
||||||
import de.rwu.easydrop.model.Product;
|
import de.rwu.easydrop.model.Product;
|
||||||
import de.rwu.easydrop.model.ProductCatalogue;
|
import de.rwu.easydrop.model.ProductCatalogue;
|
||||||
|
import de.rwu.easydrop.model.Webshop;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reads the user-specified catalogue of products.
|
* Reads the user-specified catalogue of products.
|
||||||
@@ -122,8 +123,8 @@ public final class ProductsConfig {
|
|||||||
ArrayList<HashMap<String, Object>> identifiers = JsonPath.read(jsonIdentifiers, "$");
|
ArrayList<HashMap<String, Object>> identifiers = JsonPath.read(jsonIdentifiers, "$");
|
||||||
|
|
||||||
for (HashMap<String, Object> product : identifiers) {
|
for (HashMap<String, Object> product : identifiers) {
|
||||||
String dataOrigin = product.keySet().iterator().next();
|
Webshop dataOrigin = Webshop.fromString(product.keySet().iterator().next());
|
||||||
String identifier = product.get(dataOrigin).toString();
|
String identifier = product.get(dataOrigin.toString()).toString();
|
||||||
|
|
||||||
Product newProduct = new Product();
|
Product newProduct = new Product();
|
||||||
newProduct.setDataOrigin(dataOrigin);
|
newProduct.setDataOrigin(dataOrigin);
|
||||||
|
|||||||
Reference in New Issue
Block a user