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

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

Merged
merged 5 commits into from
Nov 29, 2024

Conversation

jadzlnds
Copy link

@jadzlnds jadzlnds commented Nov 26, 2024

🚀 Pull Request Checklist

  • Title:

    • [ ] A brief, descriptive title for the changes.
  • Description:

    • [ ] Provide a clear and concise description of your pull request, including the purpose of the changes and the approach you've taken.
  • Context:

    • [ ] Why are these changes necessary? What problem do they solve? Link any related issues.
  • Changes:

    • [ ] List the major changes you've made, ideally organized by commit or feature.
  • Testing:

    • [ ] Describe how the changes have been tested. Include any relevant details about the testing environment and the test cases.
  • Screenshots (if applicable):

    • [ ] If your changes are visual, include screenshots to help explain your changes.
  • Additional Information:

    • [ ] Add any other information that might be useful for reviewers, such as considerations, discussions, or dependencies.
  • Checklist:

    • [ ] I have checked that my code adheres to the project's style guidelines and that my code is well-commented.
    • [ ] I have performed self-review of my own code and corrected any misspellings.
    • [ ] I have made corresponding changes to the documentation (if applicable).
    • [ ] My changes generate no new warnings or errors.
    • [ ] I have added tests that prove my fix is effective or that my feature works.
    • [ ] New and existing unit tests pass locally with my changes.

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:

  • Refactor the CKAN mapper by introducing a new CkanMapper interface and its implementation, CkanMapperImpl, to improve code modularity and maintainability.

Build:

  • Add MapStruct as a dependency in the pom.xml to facilitate object mapping.

Copy link

sourcery-ai bot commented Nov 26, 2024

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
Loading

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

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @jadzlnds - I've reviewed your changes and they look great!

Here's what I looked at during the review
  • 🟢 General issues: all looks good
  • 🟢 Security: all looks good
  • 🟡 Testing: 1 issue found
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Copy link
Collaborator

@brunopacheco1 brunopacheco1 left a comment

Choose a reason for hiding this comment

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

I remember we have another API call to CKAN, for fetching facet values, perhaps this also have some sort of inner mapper somewhere.

@brunopacheco1 brunopacheco1 merged commit f6fdde9 into main Nov 29, 2024
3 checks passed
@brunopacheco1 brunopacheco1 deleted the chore-(ART-10688)-refactor-ckan-mapper branch November 29, 2024 14:29
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.

3 participants