Skip to content

fix: prevent duplicate epub titles#2279

Merged
jo-elimu merged 2 commits intomainfrom
2273-prevent-storage-of-duplicate-epub-titles
Jun 23, 2025
Merged

fix: prevent duplicate epub titles#2279
jo-elimu merged 2 commits intomainfrom
2273-prevent-storage-of-duplicate-epub-titles

Conversation

@jo-elimu
Copy link
Copy Markdown
Member

Screenshot 2025-06-23 233131

Issue Number

Purpose

Technical Details

Testing Instructions

Screenshots


Format Checks

Note

Files in PRs are automatically checked for format violations with mvn spotless:check.

If this PR contains files with format violations, run mvn spotless:apply to fix them.

@jo-elimu jo-elimu self-assigned this Jun 23, 2025
@jo-elimu jo-elimu requested a review from a team as a code owner June 23, 2025 17:01
@jo-elimu jo-elimu removed the request for review from a team June 23, 2025 17:01
@jo-elimu jo-elimu linked an issue Jun 23, 2025 that may be closed by this pull request
@codecov
Copy link
Copy Markdown

codecov Bot commented Jun 23, 2025

Codecov Report

Attention: Patch coverage is 0% with 145 lines in your changes missing coverage. Please review.

Project coverage is 16.49%. Comparing base (993dea8) to head (786a59f).
Report is 5 commits behind head on main.

Files with missing lines Patch % Lines
...t/storybook/StoryBookCreateFromEPubController.java 0.00% 142 Missing ⚠️
...rc/main/java/ai/elimu/dao/jpa/StoryBookDaoJpa.java 0.00% 1 Missing ⚠️
...b/content/storybook/StoryBookCreateController.java 0.00% 1 Missing ⚠️
...web/content/storybook/StoryBookEditController.java 0.00% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               main    #2279      +/-   ##
============================================
- Coverage     16.51%   16.49%   -0.03%     
  Complexity      450      450              
============================================
  Files           254      254              
  Lines          7460     7470      +10     
  Branches        846      849       +3     
============================================
  Hits           1232     1232              
- Misses         6163     6173      +10     
  Partials         65       65              

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jun 23, 2025

Walkthrough

The changes implement a uniqueness check for storybook titles during both manual and ePUB-based creation. If a duplicate title is detected, the process is halted, an error is shown, and a preview of the existing storybook is displayed. Supporting updates were made to the DAO, controllers, JSPs, and error messaging.

Changes

File(s) Change Summary
pom-dependency-tree.txt Updated main project artifact version from 2.6.73-SNAPSHOT to 2.6.76-SNAPSHOT.
src/main/java/ai/elimu/dao/jpa/StoryBookDaoJpa.java Limited readByTitle query to return at most one result.
src/main/java/ai/elimu/web/content/storybook/StoryBookCreateController.java Added existing storybook to model when duplicate title is detected on creation.
src/main/java/ai/elimu/web/content/storybook/StoryBookCreateFromEPubController.java Added uniqueness check for title before processing ePUB; added existing storybook to model on duplicate.
src/main/java/ai/elimu/web/content/storybook/StoryBookEditController.java Added existing storybook to model when duplicate title is detected on edit.
src/main/webapp/WEB-INF/jsp/content/storybook/create-from-epub.jsp Display preview card of existing storybook if a duplicate is detected.
src/main/webapp/WEB-INF/jsp/content/storybook/create.jsp Display preview card of existing storybook if a duplicate is detected.
src/main/webapp/WEB-INF/jsp/content/storybook/edit.jsp Display preview card of existing storybook if a duplicate is detected.
src/main/webapp/WEB-INF/tags/formErrors.tag Added error message for generic NonUnique error code.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant WebController
    participant DAO
    participant View

    User->>WebController: Submit ePUB/storybook creation form
    WebController->>DAO: readByTitle(title)
    DAO-->>WebController: Existing storybook or null
    alt Title exists
        WebController->>View: Render form with error and existingStoryBook preview
    else Title unique
        WebController->>WebController: Proceed with ePUB processing (if applicable)
        WebController->>DAO: Save new storybook
        WebController->>View: Render success/redirect
    end
Loading

Assessment against linked issues

Objective Addressed Explanation
Prevent storage of duplicate ePUB titles and show warning (#2273)

Assessment against linked issues: Out-of-scope changes

No out-of-scope changes found.

Suggested reviewers

  • nya-elimu
  • AshishBagdane
  • tomaszsmy

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ab26e7b and 786a59f.

📒 Files selected for processing (3)
  • src/main/webapp/WEB-INF/jsp/content/storybook/create-from-epub.jsp (1 hunks)
  • src/main/webapp/WEB-INF/jsp/content/storybook/create.jsp (1 hunks)
  • src/main/webapp/WEB-INF/jsp/content/storybook/edit.jsp (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
  • src/main/webapp/WEB-INF/jsp/content/storybook/create.jsp
  • src/main/webapp/WEB-INF/jsp/content/storybook/create-from-epub.jsp
  • src/main/webapp/WEB-INF/jsp/content/storybook/edit.jsp
⏰ Context from checks skipped due to timeout of 90000ms (7)
  • GitHub Check: test_rest
  • GitHub Check: test_rest
  • GitHub Check: build (ubuntu-latest, 21)
  • GitHub Check: build (windows-latest, 17)
  • GitHub Check: build (ubuntu-latest, 17)
  • GitHub Check: build (windows-latest, 21)
  • GitHub Check: test_rest

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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>, please review it.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 using 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 generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this 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.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

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
Copy Markdown
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

♻️ Duplicate comments (2)
src/main/webapp/WEB-INF/jsp/content/storybook/create-from-epub.jsp (1)

10-30: Fix potential null pointer exception in CSS class construction.

Same issue as in create.jsp - the code references existingStoryBook.coverImage.checksumGitHub on line 20 outside the conditional check that verifies the cover image exists.

Apply the same fix as suggested for the create.jsp file.

src/main/webapp/WEB-INF/jsp/content/storybook/edit.jsp (1)

24-44: Fix potential null pointer exception in CSS class construction.

Same issue as in the other JSP files - line 34 references existingStoryBook.coverImage.checksumGitHub outside the conditional check that verifies the cover image exists.

Apply the same fix pattern as suggested for the other JSP files.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 158e670 and ab26e7b.

📒 Files selected for processing (9)
  • pom-dependency-tree.txt (1 hunks)
  • src/main/java/ai/elimu/dao/jpa/StoryBookDaoJpa.java (1 hunks)
  • src/main/java/ai/elimu/web/content/storybook/StoryBookCreateController.java (1 hunks)
  • src/main/java/ai/elimu/web/content/storybook/StoryBookCreateFromEPubController.java (1 hunks)
  • src/main/java/ai/elimu/web/content/storybook/StoryBookEditController.java (1 hunks)
  • src/main/webapp/WEB-INF/jsp/content/storybook/create-from-epub.jsp (1 hunks)
  • src/main/webapp/WEB-INF/jsp/content/storybook/create.jsp (1 hunks)
  • src/main/webapp/WEB-INF/jsp/content/storybook/edit.jsp (1 hunks)
  • src/main/webapp/WEB-INF/tags/formErrors.tag (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (12)
  • GitHub Check: build (ubuntu-latest, 21)
  • GitHub Check: test_rest
  • GitHub Check: build (macos-latest, 21)
  • GitHub Check: build (ubuntu-latest, 17)
  • GitHub Check: test_rest
  • GitHub Check: test_rest
  • GitHub Check: build (windows-latest, 21)
  • GitHub Check: build (windows-latest, 17)
  • GitHub Check: build (macos-latest, 17)
  • GitHub Check: test_rest
  • GitHub Check: test_rest
  • GitHub Check: test_rest
🔇 Additional comments (8)
pom-dependency-tree.txt (1)

1-1: Version bump looks good.

The project version update to 2.6.76-SNAPSHOT is consistent with the feature changes being implemented across the codebase.

src/main/java/ai/elimu/dao/jpa/StoryBookDaoJpa.java (1)

22-22: ```shell
#!/bin/bash

Locate the StoryBook entity and check for uniqueness on the title field

echo "Locating StoryBook entity..."
entity_file=$(fd -t f StoryBook.java)

if [[ -z "$entity_file" ]]; then
echo "⚠️ StoryBook.java not found in the repository."
exit 1
fi

echo "Found: $entity_file"
echo "Inspecting @column annotations for 'title'..."
rg -n "@column.*title" "$entity_file"


</details>
<details>
<summary>src/main/webapp/WEB-INF/tags/formErrors.tag (1)</summary>

`51-51`: **Good addition of generic NonUnique error handling.**

The generic `'NonUnique'` error case provides appropriate fallback messaging for title uniqueness validation, consistent with the existing error message patterns.

</details>
<details>
<summary>src/main/java/ai/elimu/web/content/storybook/StoryBookCreateController.java (1)</summary>

`71-71`: **Excellent enhancement for user experience.**

Adding the existing storybook to the model when a duplicate is detected allows the UI to display helpful information about the conflicting entry, making it easier for users to understand and resolve the validation error.

</details>
<details>
<summary>src/main/java/ai/elimu/web/content/storybook/StoryBookEditController.java (1)</summary>

`152-152`: **Consistent implementation matching the create controller.**

The addition of the existing storybook to the model follows the same pattern as the create controller, providing consistent user experience across both creation and editing workflows.

</details>
<details>
<summary>src/main/java/ai/elimu/web/content/storybook/StoryBookCreateFromEPubController.java (3)</summary>

`153-158`: **LGTM: Well-positioned uniqueness check with proper error handling.**

The uniqueness check is correctly placed immediately after title extraction and before expensive processing operations. The error handling properly rejects the field and adds the existing storybook to the model for UI display.

---

`160-221`: **LGTM: Smart optimization to prevent expensive operations on validation errors.**

Wrapping the description extraction, cover image processing, and file operations in the error check prevents unnecessary processing when title uniqueness validation has already failed. This improves performance and user experience.

---

`223-349`: **LGTM: Consistent error handling for chapter processing.**

The second conditional check ensures that chapter extraction and processing only occur when there are no validation errors, maintaining consistency with the earlier processing logic.

</details>

</blockquote></details>

</details>

<!-- This is an auto-generated comment by CodeRabbit for review status -->

Comment thread src/main/webapp/WEB-INF/jsp/content/storybook/create.jsp
@jo-elimu jo-elimu merged commit edf84ee into main Jun 23, 2025
19 of 20 checks passed
@jo-elimu jo-elimu deleted the 2273-prevent-storage-of-duplicate-epub-titles branch June 23, 2025 17:11
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.

Prevent storage of duplicate ePUB titles

1 participant