Webshops refactoring + checkstyle

This commit is contained in:
Leonie Eitze
2023-06-27 02:56:28 +02:00
parent 22ee3f3d34
commit 463932f8e9
24 changed files with 168 additions and 208 deletions

View File

@@ -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);

View File

@@ -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(

View File

@@ -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;
}

View File

@@ -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;
}
}

View File

@@ -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;
}
}

View File

@@ -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;
}

View File

@@ -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;
}
}

View File

@@ -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;
}
}