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.exception.DataSourceException;
|
||||
import de.rwu.easydrop.model.Webshop;
|
||||
import de.rwu.easydrop.util.FormattingUtil;
|
||||
|
||||
/**
|
||||
@@ -23,7 +24,7 @@ public abstract class AbstractDataSource implements DataSource {
|
||||
*
|
||||
* @return Data source name
|
||||
*/
|
||||
protected abstract String getDataOrigin();
|
||||
protected abstract Webshop getDataOrigin();
|
||||
|
||||
/**
|
||||
* Returns the data source's API key.
|
||||
@@ -48,7 +49,7 @@ public abstract class AbstractDataSource implements DataSource {
|
||||
public ProductDTO getProductDTOById(final String productIdentifier)
|
||||
throws IllegalArgumentException {
|
||||
StringBuilder response = new StringBuilder();
|
||||
String dataOrigin = getDataOrigin();
|
||||
Webshop dataOrigin = getDataOrigin();
|
||||
String apiKey = getApiKey();
|
||||
ProductDTO product = new ProductDTO(productIdentifier, dataOrigin);
|
||||
|
||||
@@ -72,20 +73,16 @@ public abstract class AbstractDataSource implements DataSource {
|
||||
+ responseCode);
|
||||
}
|
||||
|
||||
|
||||
String line;
|
||||
String line;
|
||||
while ((line = reader.readLine()) != null) {
|
||||
response.append(line);
|
||||
}
|
||||
reader.close();
|
||||
|
||||
// FIXME: Mock not complete. Data is missing
|
||||
// FIXME response can be empty
|
||||
String data;
|
||||
if (response.toString().isEmpty()){
|
||||
data = "{}";
|
||||
}
|
||||
else {
|
||||
if (response.toString().isEmpty()) {
|
||||
data = "{}";
|
||||
} else {
|
||||
data = response.toString();
|
||||
}
|
||||
buildProductDTO(product, data);
|
||||
|
||||
@@ -7,6 +7,7 @@ import java.net.URL;
|
||||
|
||||
import de.rwu.easydrop.api.dto.ProductDTO;
|
||||
import de.rwu.easydrop.exception.DataWriterException;
|
||||
import de.rwu.easydrop.model.Webshop;
|
||||
import de.rwu.easydrop.util.FormattingUtil;
|
||||
|
||||
/**
|
||||
@@ -28,7 +29,7 @@ public abstract class AbstractDataWriter {
|
||||
*
|
||||
* @return Data target API name
|
||||
*/
|
||||
protected abstract String getDataTarget();
|
||||
protected abstract Webshop getDataTarget();
|
||||
|
||||
/**
|
||||
* 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) {
|
||||
String apiKey = getApiKey();
|
||||
String dataTarget = getDataTarget();
|
||||
Webshop dataTarget = getDataTarget();
|
||||
|
||||
if (!dataTarget.equals(dto.getDataOrigin())) {
|
||||
throw new DataWriterException(
|
||||
|
||||
@@ -8,6 +8,7 @@ import com.jayway.jsonpath.PathNotFoundException;
|
||||
import com.jayway.jsonpath.ReadContext;
|
||||
|
||||
import de.rwu.easydrop.api.dto.ProductDTO;
|
||||
import de.rwu.easydrop.model.Webshop;
|
||||
|
||||
/**
|
||||
* Interface to an Amazon data source.
|
||||
@@ -18,7 +19,7 @@ public final class AmazonProductDataSource extends AbstractDataSource {
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
@@ -82,7 +83,7 @@ public final class AmazonProductDataSource extends AbstractDataSource {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getDataOrigin() {
|
||||
protected Webshop getDataOrigin() {
|
||||
return DATA_ORIGIN;
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,8 @@ package de.rwu.easydrop.api.client;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
|
||||
import de.rwu.easydrop.model.Webshop;
|
||||
|
||||
/**
|
||||
* Sends a buy request to the Amazon API.
|
||||
*
|
||||
@@ -12,7 +14,7 @@ public final class AmazonPurchaser extends AbstractPurchaser {
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
@@ -61,7 +63,7 @@ public final class AmazonPurchaser extends AbstractPurchaser {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getDataTarget() {
|
||||
protected Webshop getDataTarget() {
|
||||
return DATA_TARGET;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,8 @@ package de.rwu.easydrop.api.client;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
|
||||
import de.rwu.easydrop.model.Webshop;
|
||||
|
||||
/**
|
||||
* Sends a sell request to the Amazon API.
|
||||
*
|
||||
@@ -12,7 +14,7 @@ public final class AmazonSeller extends AbstractSeller {
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
@@ -61,7 +63,7 @@ public final class AmazonSeller extends AbstractSeller {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getDataTarget() {
|
||||
protected Webshop getDataTarget() {
|
||||
return DATA_TARGET;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import com.jayway.jsonpath.PathNotFoundException;
|
||||
import com.jayway.jsonpath.ReadContext;
|
||||
|
||||
import de.rwu.easydrop.api.dto.ProductDTO;
|
||||
import de.rwu.easydrop.model.Webshop;
|
||||
|
||||
/**
|
||||
* Interface to an eBay data source.
|
||||
@@ -18,7 +19,7 @@ public final class EbayItemDataSource extends AbstractDataSource {
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
@@ -77,7 +78,7 @@ public final class EbayItemDataSource extends AbstractDataSource {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getDataOrigin() {
|
||||
protected Webshop getDataOrigin() {
|
||||
return DATA_ORIGIN;
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,8 @@ package de.rwu.easydrop.api.client;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
|
||||
import de.rwu.easydrop.model.Webshop;
|
||||
|
||||
/**
|
||||
* Sends a buy request to the eBay API.
|
||||
*
|
||||
@@ -12,7 +14,7 @@ public final class EbayPurchaser extends AbstractPurchaser {
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
@@ -46,7 +48,7 @@ public final class EbayPurchaser extends AbstractPurchaser {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getDataTarget() {
|
||||
protected Webshop getDataTarget() {
|
||||
return DATA_TARGET;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,8 @@ package de.rwu.easydrop.api.client;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
|
||||
import de.rwu.easydrop.model.Webshop;
|
||||
|
||||
/**
|
||||
* Sends a sell request to the eBay API.
|
||||
*
|
||||
@@ -12,7 +14,7 @@ public final class EbaySeller extends AbstractSeller {
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
@@ -46,7 +48,7 @@ public final class EbaySeller extends AbstractSeller {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getDataTarget() {
|
||||
protected Webshop getDataTarget() {
|
||||
return DATA_TARGET;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user