From ff245410d26af9ea0392a9f9a25ee9296531d8e2 Mon Sep 17 00:00:00 2001 From: Tsvi Zandany Date: Thu, 21 Mar 2024 20:30:47 -0500 Subject: [PATCH 1/4] Add spring-security-core dependency and update save method in SalesDAO --- pom.xml | 6 ++++ src/main/java/net/codejava/SalesDAO.java | 35 ++---------------------- 2 files changed, 9 insertions(+), 32 deletions(-) diff --git a/pom.xml b/pom.xml index 59384d5..875022b 100644 --- a/pom.xml +++ b/pom.xml @@ -136,6 +136,12 @@ spring-data-commons + + 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 24e1541..8ca4ff3 100755 --- a/src/main/java/net/codejava/SalesDAO.java +++ b/src/main/java/net/codejava/SalesDAO.java @@ -30,38 +30,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 474448294be1411b34e82755dc966719fcc1836c Mon Sep 17 00:00:00 2001 From: Tsvi Zandany Date: Thu, 21 Mar 2024 20:31:56 -0500 Subject: [PATCH 2/4] Update CI workflow and CodeQL actions --- .github/workflows/ci.yml | 43 ++++++++-------------------------------- PD-462.txt | 1 + 2 files changed, 9 insertions(+), 35 deletions(-) create mode 100644 PD-462.txt diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index fbb647b..112b3cb 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -5,14 +5,9 @@ on: # manual trigger workflow_dispatch: inputs: - ssh_debug_enabled: + debug_enabled: type: boolean - description: 'Run the build/test with ssh debugging enabled (https://github.com/marketplace/actions/debugging-with-tmate)' - required: false - default: false - debug_deployment: - type: boolean - description: 'Run the pipeline with debug deployment enabled' + description: 'Run the build with tmate debugging enabled (https://github.com/marketplace/actions/debugging-with-tmate)' required: false default: false @@ -66,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 @@ -92,7 +87,7 @@ jobs: # runnning code scanning with CodeQL. Link to the documentation - https://docs.github.com/en/code-security/secure-coding/automatically-scanning-your-code-for-vulnerabilities-and-errors/about-code-scanning # first step is to initialize CodeQL - name: Initialize CodeQL - uses: github/codeql-action/init@v3 + uses: github/codeql-action/init@v2 with: languages: ${{ matrix.language }} # defining the language for the CodeQL analysis # debug: true # uncomment this line to enable debugging for CodeQL analysis step @@ -107,11 +102,11 @@ jobs: # Autobuild attempts to build any compiled languages (C/C++, C#, Go, or Java). # If this step fails, then you should remove it and run the build manually (see below) - name: Autobuild - uses: github/codeql-action/autobuild@v3 + uses: github/codeql-action/autobuild@v2 # performing Code Quality Analysis with CodeQL. Link to the documentation - https://docs.github.com/en/code-security/secure-coding/automatically-scanning-your-code-for-vulnerabilities-and-errors/about-code-scanning - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@v3 + uses: github/codeql-action/analyze@v2 with: category: "/language:${{matrix.language}}" # defining the language for the CodeQL analysis - uses: actions/upload-artifact@v3 # uploading the artifact to the GitHub Artifacts. Link to the documentation - https://docs.github.com/en/actions/guides/storing-workflow-data-as-artifacts @@ -186,7 +181,7 @@ jobs: - name: Setup tmate session uses: mxschmitt/action-tmate@v3 - if: ${{ github.event_name == 'workflow_dispatch' && inputs.ssh_debug_enabled }} + if: ${{ github.event_name == 'workflow_dispatch' && inputs.debug_enabled }} # split-tests action - splits the tests into x number of groups # based on the total number of github-hosted runners and junit previous test results by time and line count. @@ -195,7 +190,7 @@ jobs: id: split-tests name: Split tests with: - glob: src/test/**/**/*.java # glob pattern to match the test files + glob: src/test/**/**/**.java # glob pattern to match the test files split-total: ${{ env.total-runners }} # total number of github-hosted runners split-index: ${{ matrix.runner-index }} # current runner index junit-path: test_results/*xml # path to the junit test results with wildcards to match all the files @@ -216,27 +211,6 @@ jobs: name: Test Results path: ./target/surefire-reports # path to the test results retention-days: 90 # retention period for the artifact in days. Link to the documentation - https://docs.github.com/en/actions/guides/storing-workflow-data-as-artifacts#about-workflow-artifact-retention - - publish-test-results: - needs: unit-parallel-tests - runs-on: ubuntu-latest - steps: - - name: Checkout repository - uses: actions/checkout@v3 - - - name: Download test results - uses: actions/download-artifact@v2 - with: - name: Test Results - path: test_results - - - name: Publish Test Results - uses: dorny/test-reporter@v1.8.0 - if: success() || failure() - with: - reporter: java-junit - name: JUnit Test Results - path: test_results/*.xml build-and-publish-docker-image: # job to build the docker image and publish it to the GitHub Container Registry runs-on: ubuntu-latest # using the latest ubuntu runner @@ -305,5 +279,4 @@ jobs: with: # with tag from the build-and-publish-docker-image job in the output_tags step image_tag: "${{ needs.build-and-publish-docker-image.outputs.image_tag }}" - debug: "${{ github.event.inputs.debug_deployment }}" secrets: inherit \ No newline at end of file diff --git a/PD-462.txt b/PD-462.txt new file mode 100644 index 0000000..557db03 --- /dev/null +++ b/PD-462.txt @@ -0,0 +1 @@ +Hello World From 258833fc6ccbe1435805bee40a9c33993ed9f307 Mon Sep 17 00:00:00 2001 From: Tsvi Zandany Date: Thu, 21 Mar 2024 20:52:59 -0500 Subject: [PATCH 3/4] updated styles.js --- PD-462.txt | 1 - src/main/resources/static/js/styles.js | 6 +----- 2 files changed, 1 insertion(+), 6 deletions(-) delete mode 100644 PD-462.txt diff --git a/PD-462.txt b/PD-462.txt deleted file mode 100644 index 557db03..0000000 --- a/PD-462.txt +++ /dev/null @@ -1 +0,0 @@ -Hello World diff --git a/src/main/resources/static/js/styles.js b/src/main/resources/static/js/styles.js index a0b3a4b..ce98787 100644 --- a/src/main/resources/static/js/styles.js +++ b/src/main/resources/static/js/styles.js @@ -1,11 +1,10 @@ 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', - '--a-color': '#2196F3', }; } else { themeColors = { @@ -13,9 +12,6 @@ if (window.enableSearchFeature) { '--th-bg-color': '#4CAF50', '--a-color': '#4CAF50', '--tr-bg-color': '#fbfde3', - '--button-color': '#4CAF50', - '--button-hover-color': '#388E3C', - '--a-color': '#4CAF50', }; } From 5d6b789e65a969c04500cbdb1e862e5cf69f1c77 Mon Sep 17 00:00:00 2001 From: Tsvi Zandany <121246525+tsviz@users.noreply.github.com> Date: Thu, 14 Nov 2024 09:45:30 -0700 Subject: [PATCH 4/4] Update SalesDAO.java --- 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 8ca4ff3..c82fb28 100755 --- a/src/main/java/net/codejava/SalesDAO.java +++ b/src/main/java/net/codejava/SalesDAO.java @@ -89,7 +89,7 @@ public Page findAll(Pageable pageable) { return new PageImpl<>(sales, pageable, total); } - // a method to returns a list of all sales in a jdbctemplate query to use as a csv output + // a method to returns a list of all sales in a jdbctemplate query to use as a csv output public List listAll() { String sql = "SELECT * FROM sales ORDER BY serial_number ASC"; List listSale = jdbcTemplate.query(sql, BeanPropertyRowMapper.newInstance(Sale.class));