Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(dao) : LetterSound #1677 #1725

Merged
merged 25 commits into from
Jul 24, 2024
Merged

Conversation

SnehaHS65
Copy link
Contributor

@SnehaHS65 SnehaHS65 commented Jul 13, 2024

closes #1677

The version of webapp in pom.xml is still 2.4.11 and the db migration script in this name already exists. If you could change the version, I can create db script.

@SnehaHS65 SnehaHS65 requested a review from a team as a code owner July 13, 2024 19:00
Copy link
Contributor

coderabbitai bot commented Jul 13, 2024

Walkthrough

The overall change involves renaming the LetterSoundCorrespondence entity to LetterSound throughout the codebase, updating class names, method signatures, imports, variable names, and references in both Java files and JSP files. Additionally, new classes and methods have been introduced to manage the updated entity effectively, alongside the creation of a scheduled task to track LetterSound usage counts.

Changes

File Path Change Summary
src/main/java/.../LetterSoundContributionEventDao.java, .../LetterSoundPeerReviewEventDao.java Updated import statements and method signatures to use LetterSound instead of LetterSoundCorrespondence.
src/main/java/.../LetterSoundDao.java, .../LetterSoundDaoJpa.java Changed the entity type from LetterSoundCorrespondence to LetterSound and adjusted method implementations accordingly.
src/main/java/.../LetterSoundContributionEventDaoJpa.java, .../LetterSoundDaoJpa.java Changed class imports and method parameter types from LetterSoundCorrespondence to LetterSound.
src/main/java/.../converters/StringToLetterSoundConverter.java New file introducing a converter class to convert String IDs to LetterSound entities using LetterSoundDao.
src/main/java/.../LetterSound.java, src/main/java/.../Word.java Renamed LetterSoundCorrespondence class to LetterSound and updated related fields and methods.
src/main/java/.../LetterSoundContributionEvent.java, .../LetterSoundPeerReviewEvent.java Updated class imports and property types from LetterSoundCorrespondence to LetterSound.
src/main/java/.../JpaToGsonConverter.java, .../LetterSoundsRestController.java Updated method signatures and object references to replace LetterSoundCorrespondence with LetterSound.
src/main/java/.../LetterSoundUsageCountScheduler.java, .../SoundUsageCountScheduler.java Introduced a new scheduled task for LetterSound usage counts and updated references from LetterSoundCorrespondence to LetterSound in the existing scheduler.
src/main/java/.../CsvContentExtractionHelper.java, .../DbContentImportHelper.java Renamed methods and data structures to handle LetterSound instead of LetterSoundCorrespondence.
src/main/java/.../MainContentController.java, .../LetterSoundCreateController.java Changed attribute names and method parameters to use LetterSound instead of LetterSoundCorrespondence.
src/main/java/.../LetterSoundEditController.java, .../LetterSoundListController.java Updated import statements, variable declarations, and method parameters to reference LetterSound.
src/main/webapp/.../create.jsp, .../edit.jsp Updated modelAttribute values and element IDs from letterSoundCorrespondence to letterSound.
src/test/java/.../WordContributionRestControllerTest.java Renamed test method and updated variable names and JSON object references to work with letterSounds instead of letterSoundCorrespondences.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant LetterSoundUsageCountScheduler
    participant WordDao
    participant LetterSoundDao

    User->>LetterSoundUsageCountScheduler: Trigger usage count update
    LetterSoundUsageCountScheduler->>WordDao: Retrieve all Words
    WordDao-->>LetterSoundUsageCountScheduler: Return Word list
    LetterSoundUsageCountScheduler->>LetterSoundDao: Retrieve all LetterSounds
    LetterSoundDao-->>LetterSoundUsageCountScheduler: Return LetterSound list
    LetterSoundUsageCountScheduler->>LetterSoundDao: Update usage counts
    LetterSoundDao-->>LetterSoundUsageCountScheduler: Confirm update
    LetterSoundUsageCountScheduler-->>User: Usage counts updated
Loading

Assessment against linked issues

Objective Addressed Explanation
Rename LetterSoundCorrespondence to LetterSound (1677)
Update references in LetterSoundPeerReviewEvent (1677)
Update references in LetterSoundContributionEvent (1677)
Update Word to use LetterSound instead of LetterSoundCorrespondence (1677)
Ensure all usages reflect new class naming (1677) Some references may still exist in tests.

Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 9130589 and cc010be.

Files selected for processing (1)
  • src/main/resources/db/migration/2004022.sql (1 hunks)
Additional context used
Learnings (1)
Common learnings
Learnt from: venkatesh2k3
PR: elimu-ai/webapp#1682
File: src/main/java/ai/elimu/dao/LetterSoundContributionEventDao.java:13-13
Timestamp: 2024-07-06T17:37:44.413Z
Learning: In the `LetterSoundContributionEventDao.java` file, the method signatures should use `LetterSoundContributionEvent` instead of `LetterSoundCorrespondenceContributionEvent` to maintain consistency with the renaming of entities.
Additional comments not posted (6)
src/main/resources/db/migration/2004022.sql (6)

7-8: Ensure the table renaming is correct for LetterSound_Letter.

The command drops the LetterSound_Letter table if it exists and then renames LetterSoundCorrespondence_Letter to LetterSound_Letter. Ensure that this operation does not lead to data loss and that it is executed in the correct order.


19-20: Ensure column renaming is correct for LetterSound_Sound.

The command drops the LetterSound_id column and renames LetterSoundCorrespondence_id to LetterSound_id in the LetterSound_Sound table. Ensure that this operation does not lead to data loss and that it is executed in the correct order.


4-5: Ensure the table renaming is correct.

The command drops the LetterSound table if it exists and then renames LetterSoundCorrespondence to LetterSound. Ensure that this operation does not lead to data loss and that it is executed in the correct order.

Verification successful

Renaming of LetterSoundCorrespondence table is correct

The sequence of operations involving the LetterSoundCorrespondence table confirms that the table exists and is being manipulated correctly. The renaming operation to LetterSound is executed in the correct order and does not lead to data loss.

  • src/main/resources/db/migration/2004022.sql: ALTER TABLE LetterSoundCorrespondence RENAME TO LetterSound;
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the existence of the `LetterSoundCorrespondence` table before renaming.

# Test: Search for the `LetterSoundCorrespondence` table. Expect: The table should exist before renaming.
rg --type sql -A 5 $'CREATE TABLE `LetterSoundCorrespondence`'

Length of output: 63


Script:

#!/bin/bash
# Description: Verify the existence of the `LetterSoundCorrespondence` table before renaming by searching for any references to it.

# Test: Search for any references to the `LetterSoundCorrespondence` table in SQL files.
rg --type sql 'LetterSoundCorrespondence'

Length of output: 5786


Script:

#!/bin/bash
# Description: List all SQL migration files and their contents to verify the sequence of operations involving `LetterSoundCorrespondence`.

# Test: List the contents of all SQL migration files.
fd -e sql -x cat

Length of output: 63280


10-11: Ensure the table renaming is correct for LetterSound_Sound.

The command drops the LetterSound_Sound table if it exists and then renames LetterSoundCorrespondence_Sound to LetterSound_Sound. Ensure that this operation does not lead to data loss and that it is executed in the correct order.


13-14: Ensure the table renaming is correct for Word_LetterSound.

The command drops the Word_LetterSound table if it exists and then renames Word_LetterSoundCorrespondence to Word_LetterSound. Ensure that this operation does not lead to data loss and that it is executed in the correct order.


16-17: Ensure column renaming is correct for LetterSound_Letter.

The command drops the LetterSound_id column and renames LetterSoundCorrespondence_id to LetterSound_id in the LetterSound_Letter table. Ensure that this operation does not lead to data loss and that it is executed in the correct order.


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

codecov bot commented Jul 13, 2024

Codecov Report

Attention: Patch coverage is 5.26316% with 108 lines in your changes missing coverage. Please review.

Project coverage is 15.19%. Comparing base (eb26209) to head (cc010be).

Files Patch % Lines
...ai/elimu/tasks/LetterSoundUsageCountScheduler.java 6.89% 27 Missing ⚠️
.../ai/elimu/util/csv/CsvContentExtractionHelper.java 0.00% 19 Missing ⚠️
...i/elimu/web/content/word/WordCreateController.java 7.69% 12 Missing ⚠️
.../ai/elimu/web/content/word/WordEditController.java 0.00% 12 Missing ⚠️
...limu/web/content/word/WordCsvExportController.java 0.00% 8 Missing ⚠️
.../main/java/ai/elimu/dao/jpa/LetterSoundDaoJpa.java 12.50% 7 Missing ⚠️
...logic/converters/StringToLetterSoundConverter.java 16.66% 5 Missing ⚠️
...n/java/ai/elimu/util/db/DbContentImportHelper.java 0.00% 2 Missing ⚠️
...tent/letter_sound/LetterSoundCreateController.java 0.00% 2 Missing ⚠️
...t/letter_sound/LetterSoundCsvExportController.java 0.00% 2 Missing ⚠️
... and 8 more
Additional details and impacted files
@@            Coverage Diff            @@
##               main    #1725   +/-   ##
=========================================
  Coverage     15.19%   15.19%           
  Complexity      450      450           
=========================================
  Files           249      249           
  Lines          7630     7630           
  Branches        801      801           
=========================================
  Hits           1159     1159           
  Misses         6421     6421           
  Partials         50       50           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 6

Outside diff range, codebase verification and nitpick comments (2)
src/main/java/ai/elimu/tasks/LetterSoundUsageCountScheduler.java (1)

19-22: Use a more specific logger name.

Using a more specific logger name can help in identifying logs from this class.

- private Logger logger = LogManager.getLogger();
+ private Logger logger = LogManager.getLogger(LetterSoundUsageCountScheduler.class);
src/main/java/ai/elimu/web/content/letter_sound/LetterSoundCsvExportController.java (1)

Line range hint 55-79: Optimize JSON array creation.

Consider using Java streams to simplify the creation of JSON arrays.

JSONArray letterIdsJsonArray = new JSONArray();
letterSound.getLetters().forEach(letter -> letterIdsJsonArray.put(letter.getId()));

JSONArray letterTextsJsonArray = new JSONArray();
letterSound.getLetters().forEach(letter -> letterTextsJsonArray.put(letter.getText()));

JSONArray soundIdsJsonArray = new JSONArray();
letterSound.getSounds().forEach(sound -> soundIdsJsonArray.put(sound.getId()));

JSONArray soundValuesIpaJsonArray = new JSONArray();
letterSound.getSounds().forEach(sound -> soundValuesIpaJsonArray.put(sound.getValueIpa()));

@jo-elimu
Copy link
Member

The version of webapp in pom.xml is still 2.4.11 and the db migration script in this name already exists. If you could change the version, I can create db script.

@Sneha65 Done: https://github.com/elimu-ai/webapp/releases

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 4

src/main/resources/db/migration/2004012.sql Outdated Show resolved Hide resolved
src/main/resources/db/migration/2004012.sql Outdated Show resolved Hide resolved
src/main/resources/db/migration/2004012.sql Outdated Show resolved Hide resolved
src/main/resources/db/migration/2004012.sql Outdated Show resolved Hide resolved
@SnehaHS65 SnehaHS65 requested a review from jo-elimu July 14, 2024 14:43
@SnehaHS65 SnehaHS65 self-assigned this Jul 15, 2024
@SnehaHS65
Copy link
Contributor Author

@jo-elimu , can you please review and approve my PR

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
@jo-elimu
Copy link
Member

@SnehaHS65 I applied some suggestions: 40cf0e1

So please fetch the latest changes before you continue working on the branch.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 4

src/main/resources/db/migration/2004014.sql Outdated Show resolved Hide resolved
src/main/resources/db/migration/2004014.sql Outdated Show resolved Hide resolved
src/main/resources/db/migration/2004014.sql Outdated Show resolved Hide resolved
src/main/resources/db/migration/2004014.sql Outdated Show resolved Hide resolved
@SnehaHS65
Copy link
Contributor Author

@SnehaHS65 I applied some suggestions: 40cf0e1

So please fetch the latest changes before you continue working on the branch.

@jo-elimu , Can you please check now?

@SnehaHS65
Copy link
Contributor Author

@jo-elimu , now all the files should be in sync with the Main branch, can you please review

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Outside diff range, codebase verification and nitpick comments (1)
src/main/java/ai/elimu/tasks/LetterSoundUsageCountScheduler.java (1)

41-46: Optimize logging within loops.

Logging within loops can be expensive. Consider reducing the log level or aggregating logs.

- logger.debug("word.getText(): " + word.getText());
+ logger.trace("word.getText(): " + word.getText());

@jo-elimu
Copy link
Member

@jo-elimu , now all the files should be in sync with the Main branch, can you please review

Thank you, @SnehaHS65. I will test your code changes later today.

Copy link
Member

@jo-elimu jo-elimu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested webapp on localhost, and this seems to be running well 👍

The jpa-schema-export.sql has not been updated to reflect the changes. Needs to be re-generated by running mvn jetty:run.

@SnehaHS65 SnehaHS65 requested a review from jo-elimu July 24, 2024 02:38
Copy link
Member

@jo-elimu jo-elimu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SnehaHS65 The DB migration script also needs to include renaming of the LetterSoundCorrespondence_id column, because I don't think that's handled automatically by Hibernate.

Other than that, all your changes look very good to me 🙂

coderabbitai[bot]
coderabbitai bot previously approved these changes Jul 24, 2024
@SnehaHS65 SnehaHS65 requested a review from jo-elimu July 24, 2024 13:24
Copy link
Member

@jo-elimu jo-elimu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, @SnehaHS65. I think these changes look good. Please merge, so that we can create a release and try out the migration script on the databases in production (Hindi + Tagalog).

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Outside diff range, codebase verification and nitpick comments (1)
src/main/resources/db/migration/2004022.sql (1)

1-2: Clarify the version number.

The version number in the SQL file should be updated to 2.4.22-SNAPSHOT to align with the versioning strategy in the pom.xml file.

  • File: src/main/resources/db/migration/2004022.sql
  • Line: 1

Update:

# 2.4.22-SNAPSHOT
Analysis chain

Clarify the version number.

The comment indicates the version as 2.4.22. Ensure that this version number aligns with the versioning strategy and the pom.xml file.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the version number in the `pom.xml` file.

# Test: Search for the version number. Expect: The version number should be `2.4.22`.
rg --type xml -A 5 $'<version>2.4.22</version>'

Length of output: 48


Script:

#!/bin/bash
# Description: List all version tags in the `pom.xml` file to understand the versioning strategy.

# Test: Search for all version tags in the `pom.xml` file.
rg --type xml '<version>' -A 1

Length of output: 4922

@SnehaHS65 SnehaHS65 merged commit 749ced9 into elimu-ai:main Jul 24, 2024
10 checks passed
@SnehaHS65
Copy link
Contributor Author

Thank you, @SnehaHS65. I think these changes look good. Please merge, so that we can create a release and try out the migration script on the databases in production (Hindi + Tagalog).

@jo-elimu , Merged!!

@SnehaHS65 SnehaHS65 deleted the 1677-LetterSound branch July 24, 2024 23:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Rename LetterSoundCorrespondence to LetterSound
3 participants