Provided descriptions + todo for empty classes
This commit is contained in:
@@ -50,8 +50,8 @@ public final class AmazonProductDataSource implements DataSource {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProductDTO getProductDTOById(final String productId) {
|
||||
JSONObject offer = null;
|
||||
public ProductDTO getProductDTOById(final String productId) throws IllegalArgumentException {
|
||||
StringBuilder response = new StringBuilder();
|
||||
ProductDTO product = new ProductDTO(productId, DATA_ORIGIN);
|
||||
|
||||
try {
|
||||
@@ -73,27 +73,21 @@ public final class AmazonProductDataSource implements DataSource {
|
||||
if (responseCode == HttpURLConnection.HTTP_OK) {
|
||||
reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
|
||||
} else {
|
||||
return product;
|
||||
throw new IllegalArgumentException(
|
||||
"Amazon API responded with error code " + responseCode);
|
||||
}
|
||||
|
||||
String line;
|
||||
StringBuilder response = new StringBuilder();
|
||||
while ((line = reader.readLine()) != null) {
|
||||
response.append(line);
|
||||
}
|
||||
reader.close();
|
||||
|
||||
offer = new JSONObject(response.toString());
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
if (offer == null) {
|
||||
return product;
|
||||
throw new IllegalArgumentException("Couldn't fulfill Amazon API request");
|
||||
}
|
||||
|
||||
try {
|
||||
offer = offer.getJSONObject("featuredOffer");
|
||||
JSONObject offer = new JSONObject(response.toString()).getJSONObject("featuredOffer");
|
||||
|
||||
product.setDataOrigin(DATA_ORIGIN);
|
||||
product.setAvailable(offer
|
||||
@@ -113,7 +107,7 @@ public final class AmazonProductDataSource implements DataSource {
|
||||
.getJSONObject("merchant")
|
||||
.getString("name"));
|
||||
} catch (JSONException e) {
|
||||
return product;
|
||||
// Pass, allow incomplete ProductDTO to pass for later validation
|
||||
}
|
||||
|
||||
return product;
|
||||
|
||||
Reference in New Issue
Block a user