-
Notifications
You must be signed in to change notification settings - Fork 1
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
Make catalog harvesting optional #69
Changes from 5 commits
d694918
7972a13
c9b6625
367f562
8e68b25
20f829b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,30 +2,59 @@ | |
# SPDX-FileContributor: 2024 Stichting Health-RI | ||
# | ||
# SPDX-License-Identifier: AGPL-3.0-only | ||
|
||
import logging | ||
|
||
from ckanext.fairdatapoint.harvesters.civity_harvester import CivityHarvester | ||
from ckanext.fairdatapoint.harvesters.domain.fair_data_point_record_provider import FairDataPointRecordProvider | ||
from ckanext.fairdatapoint.harvesters.domain.fair_data_point_record_to_package_converter import \ | ||
FairDataPointRecordToPackageConverter | ||
from ckanext.fairdatapoint.harvesters.domain.fair_data_point_record_provider import ( | ||
FairDataPointRecordProvider, | ||
) | ||
from ckanext.fairdatapoint.harvesters.domain.fair_data_point_record_to_package_converter import ( | ||
FairDataPointRecordToPackageConverter, | ||
) | ||
from ckan.plugins import toolkit | ||
|
||
PROFILE = "profile" | ||
HARVEST_CATALOG = "harvest_catalogs" | ||
HARVEST_CATALOG_CONFIG = "ckanext.fairdatapoint.harvest_catalogs" | ||
|
||
PROFILE = 'profile' | ||
log = logging.getLogger(__name__) | ||
|
||
|
||
class FairDataPointCivityHarvester(CivityHarvester): | ||
|
||
def _get_harvest_catalog_setting(self, harvest_config_dict): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. issue (complexity): Consider simplifying the configuration handling and removing unnecessary logging. The new code introduces additional complexity due to extra logging, a new method for configuration handling, and more verbose import statements. While these changes add functionality, they also make the code harder to read and maintain. Consider simplifying the configuration handling by doing it inline within the from ckanext.fairdatapoint.harvesters.civity_harvester import CivityHarvester
from ckanext.fairdatapoint.harvesters.domain.fair_data_point_record_provider import FairDataPointRecordProvider
from ckanext.fairdatapoint.harvesters.domain.fair_data_point_record_to_package_converter import FairDataPointRecordToPackageConverter
from ckan.plugins import toolkit
PROFILE = "profile"
HARVEST_CATALOG = "harvest_catalogs"
HARVEST_CATALOG_CONFIG = "ckanext.fairdatapoint.harvest_catalogs"
class FairDataPointCivityHarvester(CivityHarvester):
def setup_record_provider(self, harvest_url, harvest_config_dict):
harvest_catalogs = toolkit.asbool(
harvest_config_dict.get(HARVEST_CATALOG, toolkit.config.get(HARVEST_CATALOG_CONFIG, False))
)
self.record_provider = FairDataPointRecordProvider(harvest_url, harvest_catalogs)
def setup_record_to_package_converter(self, harvest_url, harvest_config_dict):
if PROFILE in harvest_config_dict:
self.record_to_package_converter = FairDataPointRecordToPackageConverter(
harvest_config_dict.get(PROFILE)
)
else:
raise Exception(f"[{PROFILE}] not found in harvester config JSON")
def info(self):
return {
"name": "fair_data_point_harvester",
"title": "FAIR data point harvester",
"description": "Harvester for end points implementing the FAIR data point protocol",
} This version reduces complexity while keeping the new features intact. |
||
if HARVEST_CATALOG in harvest_config_dict: | ||
log.debug("Using harvest_catalogs from harvest_config_dict") | ||
harvest_catalog_setting = toolkit.asbool( | ||
harvest_config_dict[HARVEST_CATALOG] | ||
) | ||
else: | ||
log.debug("Using harvest_catalogs from global CKAN config") | ||
harvest_catalog_setting = toolkit.asbool( | ||
toolkit.config.get(HARVEST_CATALOG_CONFIG, False) | ||
) | ||
log.debug("Harvesting catalogs is set to %s", harvest_catalog_setting) | ||
return harvest_catalog_setting | ||
|
||
def setup_record_provider(self, harvest_url, harvest_config_dict): | ||
self.record_provider = FairDataPointRecordProvider(harvest_url) | ||
# Harvest catalog config can be set on global CKAN level, but can be overriden by harvest config | ||
harvest_catalogs = self._get_harvest_catalog_setting(harvest_config_dict) | ||
|
||
self.record_provider = FairDataPointRecordProvider( | ||
harvest_url, harvest_catalogs | ||
) | ||
|
||
def setup_record_to_package_converter(self, harvest_url, harvest_config_dict): | ||
if PROFILE in harvest_config_dict: | ||
self.record_to_package_converter = FairDataPointRecordToPackageConverter(harvest_config_dict.get(PROFILE)) | ||
self.record_to_package_converter = FairDataPointRecordToPackageConverter( | ||
harvest_config_dict.get(PROFILE) | ||
) | ||
else: | ||
raise Exception('[{0}] not found in harvester config JSON'.format(PROFILE)) | ||
raise Exception("[{0}] not found in harvester config JSON".format(PROFILE)) | ||
|
||
def info(self): | ||
return { | ||
'name': 'fair_data_point_harvester', | ||
'title': 'FAIR data point harvester', | ||
'description': 'Harvester for end points implementing the FAIR data point protocol' | ||
"name": "fair_data_point_harvester", | ||
"title": "FAIR data point harvester", | ||
"description": "Harvester for end points implementing the FAIR data point protocol", | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
issue (complexity): Consider simplifying the code while maintaining the new functionality.
The new code introduces useful functionality but also adds complexity. Here are some points to consider:
Increased Complexity: The new code has more lines and nested conditions, making it harder to read and understand at a glance. The original code was more straightforward.
Logging and Configuration Handling: While logging is useful, it adds complexity by introducing more logic and potential points of failure. The original code did not have this additional layer of configuration handling.
Use of
toolkit
: The new code usestoolkit
to fetch configuration values, adding another dependency and layer of abstraction. This makes the code harder to maintain.Conditional Logic: The new code has more conditional logic to handle different sources of configuration (
global CKAN level
vsharvest config
). This increases the cognitive load required to understand the flow of the program.Consider simplifying the code while maintaining the new functionality. Here is a suggestion:
This approach reduces complexity while maintaining the new functionality.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi bot, I wouldn't exactly call nested get statements more readable. The entire plugin is a mess when it comes to the style guide, but to keep the diffs small I'm not running a full linter over it yet.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi Markus92,
I understand your concern about nested
get
statements potentially reducing readability. The goal of my suggestion was to streamline the logic and reduce the cognitive load by consolidating the configuration fetching into a single line. However, I see your point about the overall style and the importance of keeping the diffs small.If running a full linter over the entire plugin isn't feasible right now, perhaps we can find a middle ground. We could refactor the configuration fetching into a separate method to improve readability without introducing too many changes at once. Here's an example:
This way, the main methods remain clean, and the configuration logic is encapsulated in a separate method. Let me know what you think!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But now you removed the logging. How can I see where the configuration came from? That would be extremely useful for debugging issues when the wrong behavior is shown.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi Markus92,
I understand the importance of logging for debugging purposes. Let's incorporate the logging back into the refactored method to ensure we can trace where the configuration values are coming from. Here's an updated version that includes detailed logging:
This way, we maintain the readability improvements while ensuring that the logging provides the necessary information for debugging. Let me know if this approach works for you!