Closed MaximilianAnzinger closed 5 days ago
The recent updates streamline error handling in the CompetencyRepository
and LearningPathRepository
by consolidating numerous custom query methods into unified access methods using getValueElseThrow
. This refactoring improves code maintainability and readability, centralizing the handling of entity retrieval and associated exceptions.
File | Change Summary |
---|---|
CompetencyRepository.java |
Removed several custom query methods and replaced them with a generic getValueElseThrow method, simplifying the repository interface. |
LearningPathRepository.java |
Refactored error handling within default methods to use getValueElseThrow , enhancing code readability and maintainability. |
src/main/java/de/tum/in/www1/artemis/repository/LearningPathRepository.java (1)
Pattern `src/main/java/**/*.java`: naming:CamelCase; principles:{single_responsibility,small_methods,no_duplication}; db:{perf_queries,datetime_not_timestamp}; rest:{stateless,singleton,delegate_logic,http_only,minimal_dtos}; dtos:{java_records,no_entities,min_data,single_resp}; di:constructor_injection; kiss:simple_code; file_handling:os_indep_paths; practices:{least_access,avoid_transactions,code_reuse,static_member_ref,prefer_primitives}; sql:{param_annotation,uppercase,avoid_subqueries};java:avoid_star_imports
src/main/java/de/tum/in/www1/artemis/repository/LearningPathRepository.java (5)
`74-74`: **Centralized exception handling approved.** The consistent application of `getValueElseThrow` across various methods ensures a uniform approach to error handling. Verify that it is used appropriately in all relevant scenarios.Verification successful
--- **Centralized exception handling approved.** The consistent application of `getValueElseThrow` across various methods ensures a uniform approach to error handling. The method is appropriately used in all relevant scenarios. - **Locations of `getValueElseThrow` usage:** - `CompetencyRepository.java` - `RepositoryImpl.java` - `ArtemisJpaRepository.java` - `LearningPathRepository.java` - `ProgrammingExerciseRepository.java` - `ComplaintRepository.java`--- `26-26`: **Centralized exception handling approved.** This change enhances maintainability by centralizing error handling. Ensure that `getValueElseThrow` is implemented correctly and efficiently handles all potential exceptions.Scripts executed
The following scripts were executed for the analysis: --- Script: ```shell #!/bin/bash # Description: Verify the appropriate usage of `getValueElseThrow` in all relevant scenarios. # Test: Search for the function usage. Expect: Appropriate usage across the repository. rg --type java $'getValueElseThrow' ``` Length of output: 2759Verification successful
--- **Centralized exception handling approved.** The implementations of `getValueElseThrow` in `RepositoryImpl` correctly handle exceptions by throwing `EntityNotFoundException` when the optional value is not present. This ensures efficient and consistent error handling across the repository methods. - `getValueElseThrow(Optionaloptional)`: ```java @NotNull public T getValueElseThrow(Optional optional) { return optional.orElseThrow(() -> new EntityNotFoundException(entityInformation.getEntityName())); } ``` - `getValueElseThrow(Optional optional, ID id)`: ```java @NotNull public T getValueElseThrow(Optional optional, ID id) { return optional.orElseThrow(() -> new EntityNotFoundException(entityInformation.getEntityName(), String.valueOf(id))); } ``` These methods effectively centralize the exception handling logic, enhancing maintainability and readability. --- `47-47`: **Centralized exception handling approved.** Using `getValueElseThrow` consistently across different methods aids in maintainability. Verify the performance implications of this method, especially in complex queries. --- `40-40`: **Centralized exception handling approved.** Continued use of `getValueElseThrow` promotes consistency and maintainability. Verify that it handles all edge cases correctly. --- `33-33`: **Centralized exception handling approved.** Consistent use of `getValueElseThrow` across methods enhances maintainability. Ensure that this method is used correctly in all scenarios where it's applied.Scripts executed
The following scripts were executed for the analysis: --- Script: ```shell #!/bin/bash # Description: Verify the implementation of `getValueElseThrow`. # Test: Search for the function implementation. Expect: Efficient and correct handling of exceptions. rg --type java $'getValueElseThrow' ``` Length of output: 2759 --- --- Script: ```shell #!/bin/bash # Extract the implementation details of `getValueElseThrow` methods from `RepositoryImpl.java`. # Retrieve the methods from the file ast-grep --lang java --pattern $'public T getValueElseThrow(Optionaloptional) { $$$ }' src/main/java/de/tum/in/www1/artemis/repository/base/RepositoryImpl.java ast-grep --lang java --pattern $'public T getValueElseThrow(Optional optional, ID id) { $$$ }' src/main/java/de/tum/in/www1/artemis/repository/base/RepositoryImpl.java ``` Length of output: 340 --- --- Script: ```shell #!/bin/bash # Locate the method signatures of `getValueElseThrow` and extract the surrounding lines to reveal the full implementations. # Search for the method signature with one parameter rg --context 10 'public T getValueElseThrow\(Optional optional\)' src/main/java/de/tum/in/www1/artemis/repository/base/RepositoryImpl.java # Search for the method signature with two parameters rg --context 10 'public T getValueElseThrow\(Optional optional, ID id\)' src/main/java/de/tum/in/www1/artemis/repository/base/RepositoryImpl.java ``` Length of output: 1752
Checklist
General
Server
Description
Utilizes functions from
ArtemisJpaRepository
and removes unused codeReview Progress
Performance Review
Code Review
Summary by CodeRabbit