feat: Add migration utility for book state management models #3
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
feat: Add migration utility for book state management models
Summary
This PR introduces a
BookMigrationUtilityclass that enables conversion from the old book model (separate classes:AvailableBook,BookOnHold,CheckedOutBook) to the new State pattern implementation (Bookclass withBookStateinterface). The utility preserves all book properties including ID, type, version numbers, patron information, branch details, and timestamps during migration.Key changes:
BookMigrationUtility.javawith three overloadedmigrate()methods for each old model typeBookconstructor defaults toAvailableStateReview & Testing Checklist for Human
BookMigrationUtilityTestpasses and migration actually works end-to-endRecommended test plan: Create sample instances of each old model type, migrate them, and verify both data preservation and that business operations (place hold, checkout, return) work correctly on the migrated objects.
Diagram
%%{ init : { "theme" : "default" }}%% graph TD subgraph "Old Model Package" AvailableBook["model/AvailableBook.java"]:::context BookOnHold["model/BookOnHold.java"]:::context CheckedOutBook["model/CheckedOutBook.java"]:::context end subgraph "New Model Package" Book["new_model/Book.java"]:::context BookState["new_model/BookState.java"]:::context AvailableState["new_model/AvailableState.java"]:::context OnHoldState["new_model/OnHoldState.java"]:::context CheckedOutState["new_model/CheckedOutState.java"]:::context MigrationUtility["new_model/BookMigrationUtility.java"]:::major-edit end subgraph "Tests" MigrationTest["test/.../BookMigrationUtilityTest.groovy"]:::major-edit end subgraph "Documentation" README["README.md"]:::minor-edit end AvailableBook -->|"migrate()"| MigrationUtility BookOnHold -->|"migrate()"| MigrationUtility CheckedOutBook -->|"migrate()"| MigrationUtility MigrationUtility -->|"creates"| Book MigrationUtility -.->|"uses reflection"| Book Book -->|"contains"| BookState subgraph Legend L1[Major Edit]:::major-edit L2[Minor Edit]:::minor-edit L3[Context/No Edit]:::context end classDef major-edit fill:#90EE90 classDef minor-edit fill:#87CEEB classDef context fill:#FFFFFFNotes
statefield ofBookobjects since the constructor always createsAvailableStateinitially