GenomicDataInfrastructure / gdi-userportal-dataset-discovery-service

0 stars 1 forks source link

chore: (ART-10688) refactor ckan mapper #159

Closed jadzlnds closed 2 days ago

jadzlnds commented 5 days ago

🚀 Pull Request Checklist

Summary by Sourcery

Refactor the CKAN mapper by replacing the existing PackageShowMapper and PackageSearchMapper with a new CkanMapper interface and its implementation. Update the CkanDatasetsRepository to use the new mapper. Add MapStruct as a dependency to support the new mapping functionality. Enhance test coverage by restructuring and adding new test cases for the mapper.

Enhancements:

Build:

sourcery-ai[bot] commented 5 days ago

Reviewer's Guide by Sourcery

This PR refactors the CKAN mapper implementation by introducing MapStruct for object mapping, improving code organization and maintainability. The changes consolidate multiple mapping utility classes into a single MapStruct-based mapper interface, while maintaining the same functionality.

Class diagram for CKAN Mapper Refactor

classDiagram
    class CkanMapper {
        <<interface>>
        +RetrievedDataset map(CkanPackage ckanPackage)
        +ValueLabel map(CkanValueLabel ckanValueLabel)
        +ValueLabel map(CkanTag ckanTag)
        +RetrievedDistribution map(CkanResource ckanResource)
        +List~SearchedDataset~ map(PackagesSearchResult result)
        +SearchedDataset mapToSearchedDataset(CkanPackage ckanPackage)
        +OffsetDateTime map(String date)
    }

    class CkanMapperImpl {
        +map(CkanPackage ckanPackage)
        +map(CkanValueLabel ckanValueLabel)
        +map(CkanTag ckanTag)
        +map(CkanResource ckanResource)
        +map(PackagesSearchResult result)
        +mapToSearchedDataset(CkanPackage ckanPackage)
        +map(String date)
    }

    CkanMapper <|.. CkanMapperImpl

    class CkanPackage
    class RetrievedDataset
    class CkanValueLabel
    class ValueLabel
    class CkanTag
    class CkanResource
    class RetrievedDistribution
    class PackagesSearchResult
    class SearchedDataset
    class OffsetDateTime

    CkanMapper --> CkanPackage
    CkanMapper --> RetrievedDataset
    CkanMapper --> CkanValueLabel
    CkanMapper --> ValueLabel
    CkanMapper --> CkanTag
    CkanMapper --> CkanResource
    CkanMapper --> RetrievedDistribution
    CkanMapper --> PackagesSearchResult
    CkanMapper --> SearchedDataset
    CkanMapper --> OffsetDateTime

File-Level Changes

Change Details Files
Introduced MapStruct for object mapping
  • Added MapStruct dependencies to pom.xml
  • Configured MapStruct compiler arguments for error handling
  • Created CkanMapper interface with MapStruct annotations
pom.xml
src/main/java/io/github/genomicdatainfrastructure/discovery/datasets/infrastructure/ckan/mapper/CkanMapper.java
Consolidated mapping utilities into a single mapper interface
  • Removed individual mapping utility classes
  • Implemented mapping methods in CkanMapper interface
  • Added date parsing logic in the mapper
src/main/java/io/github/genomicdatainfrastructure/discovery/datasets/infrastructure/ckan/utils/CkanAgentParser.java
src/main/java/io/github/genomicdatainfrastructure/discovery/datasets/infrastructure/ckan/utils/CkanDatetimeParser.java
src/main/java/io/github/genomicdatainfrastructure/discovery/datasets/infrastructure/ckan/utils/CkanTagParser.java
src/main/java/io/github/genomicdatainfrastructure/discovery/datasets/infrastructure/ckan/utils/CkanValueLabelParser.java
src/main/java/io/github/genomicdatainfrastructure/discovery/datasets/infrastructure/ckan/utils/PackageSearchMapper.java
src/main/java/io/github/genomicdatainfrastructure/discovery/datasets/infrastructure/ckan/utils/PackageShowMapper.java
Updated test implementation to use new mapper
  • Refactored test class to use CkanMapper
  • Added nested test classes for better organization
  • Introduced parameterized tests for SearchedDataset mapping
  • Extracted helper methods for test data creation
src/test/java/io/github/genomicdatainfrastructure/discovery/services/PackageShowMapperTest.java
Updated repository implementation to use new mapper
  • Injected CkanMapper into CkanDatasetsRepository
  • Updated mapping calls to use the new mapper interface
src/main/java/io/github/genomicdatainfrastructure/discovery/datasets/infrastructure/ckan/persistence/CkanDatasetsRepository.java

Tips and commands #### Interacting with Sourcery - **Trigger a new review:** Comment `@sourcery-ai review` on the pull request. - **Continue discussions:** Reply directly to Sourcery's review comments. - **Generate a GitHub issue from a review comment:** Ask Sourcery to create an issue from a review comment by replying to it. - **Generate a pull request title:** Write `@sourcery-ai` anywhere in the pull request title to generate a title at any time. - **Generate a pull request summary:** Write `@sourcery-ai summary` anywhere in the pull request body to generate a PR summary at any time. You can also use this command to specify where the summary should be inserted. #### Customizing Your Experience Access your [dashboard](https://app.sourcery.ai) to: - Enable or disable review features such as the Sourcery-generated pull request summary, the reviewer's guide, and others. - Change the review language. - Add, remove or edit custom review instructions. - Adjust other review settings. #### Getting Help - [Contact our support team](mailto:support@sourcery.ai) for questions or feedback. - Visit our [documentation](https://docs.sourcery.ai) for detailed guides and information. - Keep in touch with the Sourcery team by following us on [X/Twitter](https://x.com/SourceryAI), [LinkedIn](https://www.linkedin.com/company/sourcery-ai/) or [GitHub](https://github.com/sourcery-ai).