SonarLint fixes
This commit is contained in:
@@ -20,7 +20,7 @@ public final class AmazonProductDataSource extends AbstractDataSource {
|
||||
/**
|
||||
* Name of this data source.
|
||||
*/
|
||||
private static final Webshop DATA_ORIGIN = Webshop.Amazon;
|
||||
private static final Webshop DATA_ORIGIN = Webshop.AMAZON;
|
||||
/**
|
||||
* Base URL to the Amazon data source.
|
||||
*/
|
||||
|
||||
@@ -14,7 +14,7 @@ public final class AmazonPurchaser extends AbstractPurchaser {
|
||||
/**
|
||||
* Name of this data source.
|
||||
*/
|
||||
private static final Webshop DATA_TARGET = Webshop.Amazon;
|
||||
private static final Webshop DATA_TARGET = Webshop.AMAZON;
|
||||
/**
|
||||
* Base URL to the Amazon Purchase API.
|
||||
*/
|
||||
|
||||
@@ -14,7 +14,7 @@ public final class AmazonSeller extends AbstractSeller {
|
||||
/**
|
||||
* Name of this data source.
|
||||
*/
|
||||
private static final Webshop DATA_TARGET = Webshop.Amazon;
|
||||
private static final Webshop DATA_TARGET = Webshop.AMAZON;
|
||||
/**
|
||||
* Base URL to the Amazon Purchase API.
|
||||
*/
|
||||
|
||||
@@ -20,7 +20,7 @@ public final class EbayItemDataSource extends AbstractDataSource {
|
||||
/**
|
||||
* Name of this data source.
|
||||
*/
|
||||
private static final Webshop DATA_ORIGIN = Webshop.eBay;
|
||||
private static final Webshop DATA_ORIGIN = Webshop.EBAY;
|
||||
/**
|
||||
* Base URL to the eBay data source.
|
||||
*/
|
||||
|
||||
@@ -14,7 +14,7 @@ public final class EbayPurchaser extends AbstractPurchaser {
|
||||
/**
|
||||
* Name of this data source.
|
||||
*/
|
||||
private static final Webshop DATA_TARGET = Webshop.eBay;
|
||||
private static final Webshop DATA_TARGET = Webshop.EBAY;
|
||||
/**
|
||||
* Base URL to the eBay Purchase API.
|
||||
*/
|
||||
|
||||
@@ -14,7 +14,7 @@ public final class EbaySeller extends AbstractSeller {
|
||||
/**
|
||||
* Name of this data source.
|
||||
*/
|
||||
private static final Webshop DATA_TARGET = Webshop.eBay;
|
||||
private static final Webshop DATA_TARGET = Webshop.EBAY;
|
||||
/**
|
||||
* Base URL to the eBay Purchase API.
|
||||
*/
|
||||
|
||||
@@ -69,8 +69,8 @@ public final class Core {
|
||||
OfferProvisioner provis = new OfferProvisioner(odb);
|
||||
provis.runProvisioner(identifiedOffers);
|
||||
|
||||
// LOGGER.info("Creating transactions");
|
||||
// TODO: Transactions
|
||||
LOGGER.info("Creating transactions");
|
||||
// Transaction logic!
|
||||
|
||||
LOGGER.info("Done!");
|
||||
}
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
package de.rwu.easydrop.data.connector;
|
||||
|
||||
/**
|
||||
* Allows connecting to a SQLite Database.
|
||||
*
|
||||
* TODO implement
|
||||
*/
|
||||
public class DatabaseConnector {
|
||||
|
||||
}
|
||||
@@ -36,6 +36,10 @@ public final class SQLiteConnector implements
|
||||
* Path to SQLite db file.
|
||||
*/
|
||||
private static final String PERSISTENCE_PATH = "jdbc:sqlite:persistence.db";
|
||||
/**
|
||||
* Name of 'lastUpdate' column.
|
||||
*/
|
||||
private static final String LAST_UPDATE_COL_NAME = "lastUpdate";
|
||||
|
||||
/**
|
||||
* Creates instance.
|
||||
@@ -123,13 +127,19 @@ public final class SQLiteConnector implements
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
/**
|
||||
* Gets a ProductDTO by identifier.
|
||||
*
|
||||
* @param productId
|
||||
* @return DTO
|
||||
*/
|
||||
public ProductDTO getProductDTOById(final String productId) {
|
||||
String query = "SELECT * FROM products WHERE productId = ?";
|
||||
ProductDTO dto = null;
|
||||
|
||||
try (Connection connection = db.getConnection();
|
||||
PreparedStatement statement = connection.prepareStatement(query)) {
|
||||
try {
|
||||
Connection connection = db.getConnection();
|
||||
PreparedStatement statement = connection.prepareStatement(query);
|
||||
|
||||
statement.setString(1, productId);
|
||||
|
||||
@@ -142,10 +152,11 @@ public final class SQLiteConnector implements
|
||||
dto.setMerchant(resultSet.getString("merchant"));
|
||||
dto.setDeliveryPrice(resultSet.getDouble("deliveryPrice"));
|
||||
dto.setAvailable(resultSet.getBoolean("available"));
|
||||
dto.setLastUpdate(resultSet.getString(LAST_UPDATE_COL_NAME));
|
||||
}
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
throw new PersistenceException("Something went wrong while reading from SQLite", e);
|
||||
throw new PersistenceException("Something went wrong while reading from SQLite");
|
||||
}
|
||||
|
||||
return dto;
|
||||
@@ -153,24 +164,33 @@ public final class SQLiteConnector implements
|
||||
|
||||
/**
|
||||
* Deletes all data from persistence.
|
||||
*
|
||||
* @throws SQLException
|
||||
*/
|
||||
public void clearData() {
|
||||
try (Connection connection = db.getConnection();
|
||||
Statement statement = connection.createStatement()) {
|
||||
String query = "DELETE FROM products; DELETE FROM offers;";
|
||||
statement.executeUpdate(query);
|
||||
|
||||
String productsQuery = "DELETE FROM products;";
|
||||
String offersQuery = "DELETE FROM offers;";
|
||||
statement.executeUpdate(productsQuery);
|
||||
statement.executeUpdate(offersQuery);
|
||||
} catch (SQLException e) {
|
||||
throw new PersistenceException("Something went wrong while clearing the database", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
/**
|
||||
* Writes an offer to persistence.
|
||||
*
|
||||
* @param dto OfferDTO
|
||||
*/
|
||||
public void writeOffer(final OfferDTO dto) {
|
||||
String query = "INSERT INTO offers ("
|
||||
+ "offerId, "
|
||||
+ "sourceWebshop, sourceId, sourcePrice, "
|
||||
+ "targetWebshop, targetId, targetPrice, "
|
||||
+ "lastUpdate"
|
||||
+ LAST_UPDATE_COL_NAME
|
||||
+ ") VALUES ("
|
||||
+ "?, ?, ?, ?, ?, ?, ?, ?"
|
||||
+ ")";
|
||||
@@ -196,7 +216,12 @@ public final class SQLiteConnector implements
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
/**
|
||||
* Gets an OfferDTO by identifier.
|
||||
*
|
||||
* @param offerId
|
||||
* @return OfferDTO
|
||||
*/
|
||||
public OfferDTO getOfferDTOById(final String offerId) {
|
||||
String query = "SELECT * FROM offers WHERE offerId = ?";
|
||||
OfferDTO dto = null;
|
||||
@@ -220,7 +245,7 @@ public final class SQLiteConnector implements
|
||||
dto.setOfferId(resultSet.getString("offerId"));
|
||||
dto.setSourceProduct(srcProduct);
|
||||
dto.setTargetProduct(targetProduct);
|
||||
dto.setLastUpdate(resultSet.getString("lastUpdate"));
|
||||
dto.setLastUpdate(resultSet.getString(LAST_UPDATE_COL_NAME));
|
||||
}
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
|
||||
@@ -68,11 +68,11 @@ public class ProductCatalogue {
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("Catalogue Name: ").append(productName).append("\n");
|
||||
sb.append("Description: ").append(description).append("\n");
|
||||
sb.append(String.format("Catalogue Name: %s%n", productName));
|
||||
sb.append(String.format("Description: %s%n", description));
|
||||
sb.append("Products:\n");
|
||||
for (Product product : products) {
|
||||
sb.append(product.toString()).append("\n");
|
||||
sb.append(String.format("%s%n", product.toString()));
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
@@ -7,11 +7,11 @@ public enum Webshop {
|
||||
/**
|
||||
* Amazon Product API.
|
||||
*/
|
||||
Amazon,
|
||||
AMAZON,
|
||||
/**
|
||||
* eBay Item API.
|
||||
*/
|
||||
eBay;
|
||||
EBAY;
|
||||
|
||||
/**
|
||||
* Attempts to derive a webshop value from a string.
|
||||
@@ -26,6 +26,6 @@ public enum Webshop {
|
||||
return shop;
|
||||
}
|
||||
}
|
||||
throw new IllegalArgumentException(String.format("No webshop called {} found", str));
|
||||
throw new IllegalArgumentException(String.format("No webshop called %s found", str));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,10 +32,10 @@ public class OfferProvisioner {
|
||||
private EbaySeller ebaySeller;
|
||||
|
||||
private void toSeller(final Offer offer) throws IllegalArgumentException {
|
||||
if (offer.getTargetProduct().getDataOrigin() == Webshop.eBay) {
|
||||
if (offer.getTargetProduct().getDataOrigin() == Webshop.EBAY) {
|
||||
this.ebaySeller.sellProduct(ProductMapper.mapProductToDTO(offer.getTargetProduct()));
|
||||
|
||||
} else if (offer.getTargetProduct().getDataOrigin().equals(Webshop.Amazon)) {
|
||||
} else if (offer.getTargetProduct().getDataOrigin().equals(Webshop.AMAZON)) {
|
||||
this.amazonSeller.sellProduct(ProductMapper.mapProductToDTO(offer.getTargetProduct()));
|
||||
} else {
|
||||
throw new IllegalArgumentException("Unsupported target plattform");
|
||||
|
||||
@@ -71,7 +71,9 @@ public class CatalogueRetriever {
|
||||
}
|
||||
|
||||
productCatalogues.add(newProductCatalogue);
|
||||
LOGGER.info("\nLoaded Catalogue: \n" + newProductCatalogue.toString());
|
||||
String catString = String.format(
|
||||
"%nLoaded Catalogue: %n%s", newProductCatalogue.toString());
|
||||
LOGGER.info(catString);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -94,9 +94,9 @@ public class ProductRetriever {
|
||||
*/
|
||||
public Product getProductFromWebshop(final Webshop shop, final String productIdentifier) {
|
||||
switch (shop) {
|
||||
case Amazon:
|
||||
case AMAZON:
|
||||
return getProductFromAmazon(productIdentifier);
|
||||
case eBay:
|
||||
case EBAY:
|
||||
return getProductFromEbay(productIdentifier);
|
||||
default:
|
||||
return null;
|
||||
|
||||
@@ -8,7 +8,7 @@ import java.time.format.DateTimeFormatter;
|
||||
*
|
||||
* @since 0.3.0
|
||||
*/
|
||||
public abstract class Timestamp {
|
||||
public final class Timestamp {
|
||||
/**
|
||||
* Hidden constructor.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user