SonarLint fixes

This commit is contained in:
Marvin Scham
2023-06-27 06:45:00 +02:00
parent d01c4d0b1d
commit 9927b8f959
16 changed files with 59 additions and 42 deletions

View File

@@ -5,10 +5,10 @@
"description": "Very epic GPU", "description": "Very epic GPU",
"identifiers": [ "identifiers": [
{ {
"Amazon": "B096Y2TYKV" "AMAZON": "B096Y2TYKV"
}, },
{ {
"eBay": "Gigabyte GeForce RTX 3060" "EBAY": "Gigabyte GeForce RTX 3060"
} }
] ]
} }

View File

@@ -20,7 +20,7 @@ public final class AmazonProductDataSource extends AbstractDataSource {
/** /**
* Name of this data source. * 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. * Base URL to the Amazon data source.
*/ */

View File

@@ -14,7 +14,7 @@ public final class AmazonPurchaser extends AbstractPurchaser {
/** /**
* Name of this data source. * 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. * Base URL to the Amazon Purchase API.
*/ */

View File

@@ -14,7 +14,7 @@ public final class AmazonSeller extends AbstractSeller {
/** /**
* Name of this data source. * 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. * Base URL to the Amazon Purchase API.
*/ */

View File

@@ -20,7 +20,7 @@ public final class EbayItemDataSource extends AbstractDataSource {
/** /**
* Name of this data source. * 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. * Base URL to the eBay data source.
*/ */

View File

@@ -14,7 +14,7 @@ public final class EbayPurchaser extends AbstractPurchaser {
/** /**
* Name of this data source. * 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. * Base URL to the eBay Purchase API.
*/ */

View File

@@ -14,7 +14,7 @@ public final class EbaySeller extends AbstractSeller {
/** /**
* Name of this data source. * 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. * Base URL to the eBay Purchase API.
*/ */

View File

@@ -69,8 +69,8 @@ public final class Core {
OfferProvisioner provis = new OfferProvisioner(odb); OfferProvisioner provis = new OfferProvisioner(odb);
provis.runProvisioner(identifiedOffers); provis.runProvisioner(identifiedOffers);
// LOGGER.info("Creating transactions"); LOGGER.info("Creating transactions");
// TODO: Transactions // Transaction logic!
LOGGER.info("Done!"); LOGGER.info("Done!");
} }

View File

@@ -1,10 +0,0 @@
package de.rwu.easydrop.data.connector;
/**
* Allows connecting to a SQLite Database.
*
* TODO implement
*/
public class DatabaseConnector {
}

View File

@@ -36,6 +36,10 @@ public final class SQLiteConnector implements
* Path to SQLite db file. * Path to SQLite db file.
*/ */
private static final String PERSISTENCE_PATH = "jdbc:sqlite:persistence.db"; 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. * 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) { public ProductDTO getProductDTOById(final String productId) {
String query = "SELECT * FROM products WHERE productId = ?"; String query = "SELECT * FROM products WHERE productId = ?";
ProductDTO dto = null; ProductDTO dto = null;
try (Connection connection = db.getConnection(); try {
PreparedStatement statement = connection.prepareStatement(query)) { Connection connection = db.getConnection();
PreparedStatement statement = connection.prepareStatement(query);
statement.setString(1, productId); statement.setString(1, productId);
@@ -142,10 +152,11 @@ public final class SQLiteConnector implements
dto.setMerchant(resultSet.getString("merchant")); dto.setMerchant(resultSet.getString("merchant"));
dto.setDeliveryPrice(resultSet.getDouble("deliveryPrice")); dto.setDeliveryPrice(resultSet.getDouble("deliveryPrice"));
dto.setAvailable(resultSet.getBoolean("available")); dto.setAvailable(resultSet.getBoolean("available"));
dto.setLastUpdate(resultSet.getString(LAST_UPDATE_COL_NAME));
} }
} }
} catch (SQLException e) { } 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; return dto;
@@ -153,24 +164,33 @@ public final class SQLiteConnector implements
/** /**
* Deletes all data from persistence. * Deletes all data from persistence.
*
* @throws SQLException
*/ */
public void clearData() { public void clearData() {
try (Connection connection = db.getConnection(); try (Connection connection = db.getConnection();
Statement statement = connection.createStatement()) { 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) { } catch (SQLException e) {
throw new PersistenceException("Something went wrong while clearing the database", 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) { public void writeOffer(final OfferDTO dto) {
String query = "INSERT INTO offers (" String query = "INSERT INTO offers ("
+ "offerId, " + "offerId, "
+ "sourceWebshop, sourceId, sourcePrice, " + "sourceWebshop, sourceId, sourcePrice, "
+ "targetWebshop, targetId, targetPrice, " + "targetWebshop, targetId, targetPrice, "
+ "lastUpdate" + LAST_UPDATE_COL_NAME
+ ") VALUES (" + ") 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) { public OfferDTO getOfferDTOById(final String offerId) {
String query = "SELECT * FROM offers WHERE offerId = ?"; String query = "SELECT * FROM offers WHERE offerId = ?";
OfferDTO dto = null; OfferDTO dto = null;
@@ -220,7 +245,7 @@ public final class SQLiteConnector implements
dto.setOfferId(resultSet.getString("offerId")); dto.setOfferId(resultSet.getString("offerId"));
dto.setSourceProduct(srcProduct); dto.setSourceProduct(srcProduct);
dto.setTargetProduct(targetProduct); dto.setTargetProduct(targetProduct);
dto.setLastUpdate(resultSet.getString("lastUpdate")); dto.setLastUpdate(resultSet.getString(LAST_UPDATE_COL_NAME));
} }
} }
} catch (SQLException e) { } catch (SQLException e) {

View File

@@ -68,11 +68,11 @@ public class ProductCatalogue {
@Override @Override
public String toString() { public String toString() {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
sb.append("Catalogue Name: ").append(productName).append("\n"); sb.append(String.format("Catalogue Name: %s%n", productName));
sb.append("Description: ").append(description).append("\n"); sb.append(String.format("Description: %s%n", description));
sb.append("Products:\n"); sb.append("Products:\n");
for (Product product : products) { for (Product product : products) {
sb.append(product.toString()).append("\n"); sb.append(String.format("%s%n", product.toString()));
} }
return sb.toString(); return sb.toString();
} }

View File

@@ -7,11 +7,11 @@ public enum Webshop {
/** /**
* Amazon Product API. * Amazon Product API.
*/ */
Amazon, AMAZON,
/** /**
* eBay Item API. * eBay Item API.
*/ */
eBay; EBAY;
/** /**
* Attempts to derive a webshop value from a string. * Attempts to derive a webshop value from a string.
@@ -26,6 +26,6 @@ public enum Webshop {
return shop; return shop;
} }
} }
throw new IllegalArgumentException(String.format("No webshop called {} found", str)); throw new IllegalArgumentException(String.format("No webshop called %s found", str));
} }
} }

View File

@@ -32,10 +32,10 @@ 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 {
if (offer.getTargetProduct().getDataOrigin() == Webshop.eBay) { if (offer.getTargetProduct().getDataOrigin() == Webshop.EBAY) {
this.ebaySeller.sellProduct(ProductMapper.mapProductToDTO(offer.getTargetProduct())); 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())); this.amazonSeller.sellProduct(ProductMapper.mapProductToDTO(offer.getTargetProduct()));
} else { } else {
throw new IllegalArgumentException("Unsupported target plattform"); throw new IllegalArgumentException("Unsupported target plattform");

View File

@@ -71,7 +71,9 @@ public class CatalogueRetriever {
} }
productCatalogues.add(newProductCatalogue); productCatalogues.add(newProductCatalogue);
LOGGER.info("\nLoaded Catalogue: \n" + newProductCatalogue.toString()); String catString = String.format(
"%nLoaded Catalogue: %n%s", newProductCatalogue.toString());
LOGGER.info(catString);
} }
} }
} }

View File

@@ -94,9 +94,9 @@ public class ProductRetriever {
*/ */
public Product getProductFromWebshop(final Webshop shop, final String productIdentifier) { public Product getProductFromWebshop(final Webshop shop, final String productIdentifier) {
switch (shop) { switch (shop) {
case Amazon: case AMAZON:
return getProductFromAmazon(productIdentifier); return getProductFromAmazon(productIdentifier);
case eBay: case EBAY:
return getProductFromEbay(productIdentifier); return getProductFromEbay(productIdentifier);
default: default:
return null; return null;

View File

@@ -8,7 +8,7 @@ import java.time.format.DateTimeFormatter;
* *
* @since 0.3.0 * @since 0.3.0
*/ */
public abstract class Timestamp { public final class Timestamp {
/** /**
* Hidden constructor. * Hidden constructor.
*/ */