From d7ac096a5c6b4a29bfd883456a6436f7f22dab7e Mon Sep 17 00:00:00 2001 From: Tsvi Zandany Date: Fri, 9 Feb 2024 11:48:04 -0600 Subject: [PATCH 1/7] Update dependencies and refactor save method --- pom.xml | 1 + src/main/java/net/codejava/SalesDAO.java | 35 ++---------------------- 2 files changed, 4 insertions(+), 32 deletions(-) diff --git a/pom.xml b/pom.xml index 38094af..733c9d3 100644 --- a/pom.xml +++ b/pom.xml @@ -97,6 +97,7 @@ org.springframework.security spring-security-core + 5.7.0 diff --git a/src/main/java/net/codejava/SalesDAO.java b/src/main/java/net/codejava/SalesDAO.java index f70bdbb..d01d2ed 100755 --- a/src/main/java/net/codejava/SalesDAO.java +++ b/src/main/java/net/codejava/SalesDAO.java @@ -35,38 +35,9 @@ public List list(int limit, int offset) { return listSale; } - public void save(Sale sale) throws DuplicateKeyException { - try { - System.out.println(sale); // log the Sale object - - if (sale == null) { - throw new IllegalArgumentException("Sale object cannot be null"); - } - - if (jdbcTemplate == null) { - throw new IllegalStateException("JdbcTemplate cannot be null"); - } - // Check if a record with the same primary key already exists - int count = jdbcTemplate.queryForObject( - "SELECT COUNT(*) FROM sales WHERE serial_number = ?", Integer.class, sale.getSerialNumber()); - - if (count > 0) { - // If such a record exists, throw an exception - throw new DuplicateKeyException("A record with the same serial number already exists."); - } - - // If no such record exists, insert the new record - SimpleJdbcInsert insertActor = - new SimpleJdbcInsert(jdbcTemplate != null ? jdbcTemplate : new JdbcTemplate()); - insertActor.withTableName("sales").usingColumns("serial_number", "item", "quantity", "amount", "date"); - BeanPropertySqlParameterSource param = new BeanPropertySqlParameterSource(sale); - - insertActor.execute(param); - } catch (DuplicateKeyException e) { - throw e; // rethrow the exception to be handled by the caller - } catch (Exception e) { - e.printStackTrace(); // log any other exceptions - } + public void save(Sale sale) { + String sql = "INSERT INTO SALES (item, quantity, amount) VALUES ('" + sale.getItem() + "', " + sale.getQuantity() + ", " + sale.getAmount() + ")"; + jdbcTemplate.update(sql); } public Sale get(String serialNumber) { From 867f9e50b2d65fc230e2d35a509877b65be96a0b Mon Sep 17 00:00:00 2001 From: Tsvi Zandany Date: Fri, 9 Feb 2024 11:53:53 -0600 Subject: [PATCH 2/7] Update dependencies and refactor save method --- .../net/codejava/JUnit5ExampleTest11.java | 70 ------------------- 1 file changed, 70 deletions(-) delete mode 100644 src/test/java/net/codejava/JUnit5ExampleTest11.java diff --git a/src/test/java/net/codejava/JUnit5ExampleTest11.java b/src/test/java/net/codejava/JUnit5ExampleTest11.java deleted file mode 100644 index 4e665e4..0000000 --- a/src/test/java/net/codejava/JUnit5ExampleTest11.java +++ /dev/null @@ -1,70 +0,0 @@ -package net.codejava; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import static org.junit.jupiter.api.Assertions.assertEquals; -import java.util.Calendar; -import java.util.List; -import static org.junit.jupiter.api.Assertions.assertNotNull; - -@SpringBootTest -public class JUnit5ExampleTest11 { - - @Autowired - // create private instance of SalesDAO - private SalesDAO salesDAO = new SalesDAO(); - // This field is used to inject an instance of the AppController class. - @Autowired - private AppController appController; - - @Test - void testInsert() { - Calendar calendar = Calendar.getInstance(); - calendar.set(2021, Calendar.FEBRUARY, 1); - java.util.Date utilDate = calendar.getTime(); - java.sql.Date sqlDate = new java.sql.Date(utilDate.getTime()); - - // Generate a unique serial number based on the current timestamp - String serialNumber = String.valueOf(System.currentTimeMillis()); - - Sale sale = new Sale(serialNumber, "Laptop", 1, 1500.00f, sqlDate); - salesDAO.save(sale); - - // list all the records - List listSale = salesDAO.list(10, 0); - - // Find the sale with the matching serial number - Sale insertedSale = listSale.stream() - .filter(s -> s.getSerialNumber().equals(serialNumber)) - .findFirst() - .orElse(null); - - System.out.println("\n\n"); - System.out.println("--------------------------------------------------------------------------------"); - System.out.println("Expected value of item: Laptop"); - System.out.println("Actual value of item: " + insertedSale.getItem()); - System.out.println("--------------------------------------------------------------------------------"); - assertNotNull(insertedSale, "Inserted sale not found"); - assertEquals("Laptop", insertedSale.getItem(), "Item name does not match"); - - // clean up the database - salesDAO.delete(serialNumber); - System.out.println("\n\nTest11-1 Successful!\n\n"); - } - - // test the variable enableSearchFeature in AppController.java - @Test - void testEnableSearchFeature() { - // print a comment about the value of enableSearchFeature - System.out.println("\n\n"); - System.out.println("--------------------------------------------------------------------------------"); - System.out.println("Expected value of enableSearchFeature: true"); - System.out.println("Actual value of enableSearchFeature: " + appController.getEnableSearchFeature()); - System.out.println("--------------------------------------------------------------------------------"); - - // assert that the value of enableSearchFeature is true - assertEquals(true, appController.getEnableSearchFeature()); - - System.out.println("\n\nTest11-2 Successful!\n\n"); - } - } \ No newline at end of file From 94f90d4f72b1b893a942a7a8187e00c3204144a2 Mon Sep 17 00:00:00 2001 From: Tsvi Zandany Date: Thu, 21 Mar 2024 10:12:57 -0500 Subject: [PATCH 3/7] Added new changes to README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index fee81fb..0860016 100644 --- a/README.md +++ b/README.md @@ -93,4 +93,4 @@ graph TB style K fill:#6cf,stroke:#f66,stroke-width:2px,stroke-dasharray: 5, 5 style L fill:#f6c,stroke:#333,stroke-width:2px style M fill:#6fc,stroke:#f66,stroke-width:2px,stroke-dasharray: 5, 5 -``` \ No newline at end of file +```## Feature_334 From 347d5710bf05eeb839a15047881c4cdc427befcd Mon Sep 17 00:00:00 2001 From: Tsvi Zandany Date: Thu, 21 Mar 2024 10:13:38 -0500 Subject: [PATCH 4/7] Added new changes to README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 0860016..4ee49c3 100644 --- a/README.md +++ b/README.md @@ -94,3 +94,4 @@ graph TB style L fill:#f6c,stroke:#333,stroke-width:2px style M fill:#6fc,stroke:#f66,stroke-width:2px,stroke-dasharray: 5, 5 ```## Feature_334 +## Feature_335 From 228573c2a61cd454f9935d9f15583a71c80b7ec0 Mon Sep 17 00:00:00 2001 From: Tsvi Zandany Date: Thu, 21 Mar 2024 15:49:37 -0500 Subject: [PATCH 5/7] added new CodeQL scan for Javascript --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f021526..112b3cb 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -61,7 +61,7 @@ jobs: strategy: fail-fast: false matrix: - language: [ 'java' ] + language: [ 'java', 'javascript' ] # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ] # Use only 'java' to analyze code written in Java, Kotlin or both # Use only 'javascript' to analyze code written in JavaScript, TypeScript or both From 19372d2e03009ef773b8f2c2c88c0c1afb819b9d Mon Sep 17 00:00:00 2001 From: Tsvi Zandany Date: Thu, 21 Mar 2024 15:57:55 -0500 Subject: [PATCH 6/7] added new CodeQL scan for Javascript --- src/main/java/net/codejava/SalesDAO.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/net/codejava/SalesDAO.java b/src/main/java/net/codejava/SalesDAO.java index d01d2ed..175a9ab 100755 --- a/src/main/java/net/codejava/SalesDAO.java +++ b/src/main/java/net/codejava/SalesDAO.java @@ -41,7 +41,7 @@ public void save(Sale sale) { } public Sale get(String serialNumber) { - String sql = "SELECT * FROM SALES WHERE serial_number = ?"; + String sql = "SELECT * FROM SALES WHERE serial_number = " + serialNumber; Object[] args = {serialNumber}; Sale sale = jdbcTemplate.queryForObject(sql, args, BeanPropertyRowMapper.newInstance(Sale.class)); return sale; From f910f4bdd82dd2da160d0032959d963f93500158 Mon Sep 17 00:00:00 2001 From: Tsvi Zandany Date: Thu, 21 Mar 2024 15:58:08 -0500 Subject: [PATCH 7/7] Update h1 color in styles.js --- src/main/resources/static/js/styles.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/resources/static/js/styles.js b/src/main/resources/static/js/styles.js index 9bf3a4e..ce98787 100644 --- a/src/main/resources/static/js/styles.js +++ b/src/main/resources/static/js/styles.js @@ -1,7 +1,7 @@ let themeColors; if (window.enableSearchFeature) { themeColors = { - '--h1-color': '#2196F3', + '--h1-color': window.searchFeatureColor || '#4CAF50', '--th-bg-color': '#2196F3', '--a-color': '#2196F3', '--tr-bg-color': '#c2e0fb',