Skip to content

Conversation

@JR-1991
Copy link
Member

@JR-1991 JR-1991 commented Sep 2, 2025

As discussed in #46, @qqmyers suggested updating the custom license terms using the semantic API. This PR implements the workflow, which involves fetching the metadata as JSON-LD upon update, adding the corresponding license terms, and then updating the metadata. These changes ensure that license updates are accurately reflected in the dataset metadata. Furthermore, the PR includes thorough testing with new integration tests to verify its functionality. Additionally, several internal improvements were made to enhance consistency and maintainability.

License management and JSON-LD support:

  • Added to_json_ld and json_ld_field_names methods to both License and CustomLicense classes in easyDataverse/license.py, enabling conversion to JSON-LD format and listing JSON-LD field names for metadata updates. [1] [2]
  • Implemented _update_license, _fetch_json_ld_metadata, and _update_json_ld_metadata helper functions in easyDataverse/uploader.py to fetch, update, and synchronize license information in JSON-LD format with the Dataverse API.
  • Modified the update_dataset function to accept a license argument and trigger license updates via the new helpers. [1] [2] [3]

Testing and fixtures:

  • Added new integration tests in tests/integration/test_dataset_update.py to verify license updates for both custom and predefined licenses, ensuring proper round-trip serialization and retrieval.
  • Introduced a new minimal custom license fixture for dataset upload tests in tests/fixtures/minimal_upload_custom_license.json.

Internal consistency and code maintenance:

  • Updated references to model_fields in easyDataverse/base.py to use self.__class__.model_fields for correct class-level access in attribute management and change extraction logic. [1] [2] [3]
  • Improved imports and type hints in easyDataverse/license.py and easyDataverse/uploader.py for clarity and correctness. [1] [2]

These changes collectively provide robust, extensible support for license management in Dataverse datasets, with reliable API integration and thorough test coverage.

Replaces instance-level access to model_fields with class-level access via self.__class__.model_fields in DataverseBase methods. This ensures correct field resolution and avoids potential issues with inheritance or instance-specific modifications.
Introduces logic to update a dataset's license, supporting both predefined and custom licenses via JSON-LD metadata. Adds integration tests for custom and predefined license updates, and a fixture for minimal custom license upload.
Introduces to_json_ld and json_ld_field_names methods to License and CustomLicense classes, enabling conversion of license data to JSON-LD format and retrieval of relevant field names. This facilitates interoperability with systems using JSON-LD for metadata representation.
Eliminated unnecessary imports of the 'rich' module from uploader.py and test_dataset_update.py to clean up the codebase.
@JR-1991 JR-1991 self-assigned this Sep 2, 2025
@JR-1991 JR-1991 added bug Something isn't working enhancement New feature or request labels Sep 2, 2025
@JR-1991 JR-1991 requested a review from Copilot September 2, 2025 09:54
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds comprehensive license management functionality to the easyDataverse package, enabling users to update both custom and predefined licenses through the Dataverse semantic API. The implementation fetches dataset metadata as JSON-LD, applies license updates, and synchronizes changes back to the server.

Key Changes

  • Added JSON-LD conversion methods to License and CustomLicense classes for API compatibility
  • Implemented license update workflow in the uploader module with helper functions for JSON-LD metadata operations
  • Enhanced dataset update functionality to support license modifications

Reviewed Changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
easyDataverse/license.py Added to_json_ld and json_ld_field_names methods to License and CustomLicense classes
easyDataverse/uploader.py Implemented license update functionality with JSON-LD metadata fetch/update helpers
easyDataverse/dataset.py Modified update method to pass license parameter to update_dataset function
easyDataverse/base.py Fixed model_fields references to use class-level access
tests/integration/test_dataset_update.py Added comprehensive integration tests for license update functionality
tests/fixtures/minimal_upload_custom_license.json New test fixture for custom license dataset creation

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Refactored license type assertion to use tuple for isinstance. Changed generic Exception to httpx.HTTPError for failed JSON-LD metadata updates to provide more specific error handling.
Introduces the minimal_upload_custom_license pytest fixture to load data from minimal_upload_custom_license.json for tests requiring custom license uploads.
Changed comments in test_dataset_update.py to correctly indicate that the tests update the dataset license instead of the title, improving code clarity.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working enhancement New feature or request

Projects

Development

Successfully merging this pull request may close these issues.

2 participants