Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@Paurikova2
Copy link
Collaborator

@Paurikova2 Paurikova2 commented Apr 29, 2025

Phases MP MM MB MR JM Total
ETA 0 0 0 0 0 0
Developing 5 0 0 0 0 0
Review 0 0 0 0 0 0
Total - - - - - 0
ETA est. 0
ETA cust. - - - - - 0

Problem description

The embargo is not recorded to provenance during submission.

Summary by CodeRabbit

  • New Features

    • Provenance information is now automatically recorded when new access conditions are applied to bitstreams.
  • Bug Fixes

    • Ensured provenance metadata is consistently added after updating bitstream access policies.
  • Tests

    • Added integration test to verify embargo access conditions add appropriate provenance metadata.

@coderabbitai
Copy link

coderabbitai bot commented Apr 29, 2025

Walkthrough

A new overloaded method for setting bitstream policies using an access conditions string was introduced in the ProvenanceService interface and implemented in its corresponding class. The implementation separates the logic for handling access conditions as a string from handling them as a bulk input object. Additionally, provenance tracking was integrated into the bitstream resource policy addition process, ensuring that provenance metadata is recorded whenever new resource policies are applied to a bitstream. The relevant service is now autowired into the REST patch operation to facilitate this functionality. A new integration test was added to verify that patching a workflow item with an embargo access condition correctly adds provenance metadata referencing the embargo.

Changes

File(s) Change Summary
dspace-api/src/main/java/org/dspace/core/ProvenanceService.java Added a new overloaded method setBitstreamPolicies accepting an access conditions string to the interface.
dspace-api/src/main/java/org/dspace/core/ProvenanceServiceImpl.java Implemented the new method; refactored existing logic to delegate to the new method for provenance message creation.
dspace-server-webapp/src/main/java/org/dspace/app/rest/submit/factory/impl/BitstreamResourcePolicyAddPatchOperation.java Autowired ProvenanceService; updated the add method to invoke provenance tracking after applying resource policies.
dspace-server-webapp/src/test/java/org/dspace/app/rest/WorkflowItemRestRepositoryIT.java Added integration test patchEmbargoTest to verify provenance metadata is added when patching embargo access conditions.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant BitstreamResourcePolicyAddPatchOperation
    participant ProvenanceService
    participant Item

    Client->>BitstreamResourcePolicyAddPatchOperation: add()
    BitstreamResourcePolicyAddPatchOperation->>BitstreamResourcePolicyAddPatchOperation: Apply resource policies
    loop For each new AccessConditionDTO
        BitstreamResourcePolicyAddPatchOperation->>ProvenanceService: setBitstreamPolicies(context, bitstream, item, accConditionName)
        ProvenanceService->>Item: Add provenance metadata
    end
    BitstreamResourcePolicyAddPatchOperation->>Client: Return result
Loading

Poem

In the warren of code, a new path appears,
Provenance tracked for bitstreams, cheers!
With strings or bulk, the service is wise,
Recording each policy, no need for disguise.
🐇 A hop, a commit, a provenance note—
The history of access, a rabbit's proud quote!


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6ec020d and 2450431.

📒 Files selected for processing (1)
  • dspace-api/src/main/java/org/dspace/core/ProvenanceService.java (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • dspace-api/src/main/java/org/dspace/core/ProvenanceService.java
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: Run Integration Tests
  • GitHub Check: dspace-dependencies / docker-build (linux/amd64, ubuntu-latest, true)
  • GitHub Check: Run Unit Tests
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
dspace-server-webapp/src/main/java/org/dspace/app/rest/submit/factory/impl/BitstreamResourcePolicyAddPatchOperation.java (1)

80-85: Consider optimizing context commits and adding null checks.

The current implementation iterates through all access conditions and commits after processing them all, which is good. However, consider these improvements:

  1. Add null check for the access condition name to prevent potential NullPointerExceptions
  2. Move the context.commit() outside the bitstream loop for better performance when multiple bitstreams are processed
if (CollectionUtils.isNotEmpty(newAccessConditions)) {
    BitstreamResourcePolicyUtils.findApplyResourcePolicy(context, uploadConfig, bitstream,
                                                         newAccessConditions);
    String name;
    for (AccessConditionDTO newAccessCondition : newAccessConditions) {
        name = newAccessCondition.getName();
+       if (name != null) {
            provenanceService.setBitstreamPolicies(context, bitstream, item, name);
+       } else {
+           log.warn("Null access condition name encountered for bitstream " + bitstream.getID());
+       }
    }
-   context.commit();
}

And after the outer bitstream loop (after line 89):

context.commit();
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8eedba2 and 9f1c025.

📒 Files selected for processing (3)
  • dspace-api/src/main/java/org/dspace/core/ProvenanceService.java (1 hunks)
  • dspace-api/src/main/java/org/dspace/core/ProvenanceServiceImpl.java (1 hunks)
  • dspace-server-webapp/src/main/java/org/dspace/app/rest/submit/factory/impl/BitstreamResourcePolicyAddPatchOperation.java (3 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: dspace-dependencies / docker-build (linux/amd64, ubuntu-latest, true)
  • GitHub Check: Run Integration Tests
  • GitHub Check: Run Unit Tests
🔇 Additional comments (4)
dspace-api/src/main/java/org/dspace/core/ProvenanceService.java (1)

57-66: Good addition of overloaded method for granular provenance tracking.

The new overloaded method provides a more flexible way to record provenance information for bitstream policies by accepting a string parameter instead of requiring a full BulkAccessControlInput object. This aligns well with the PR objective of ensuring embargo information is properly tracked in provenance metadata.

dspace-api/src/main/java/org/dspace/core/ProvenanceServiceImpl.java (2)

97-102: Clean implementation of delegation pattern.

The modification to the existing method properly extracts the access conditions string and delegates to the new overloaded method. This approach follows good design principles by separating the extraction logic from the provenance recording logic.


105-119: Verify null handling for access conditions string.

The implementation correctly handles SQL and authorization exceptions, but consider adding a null check for the access conditions string as an additional safeguard, even though the caller method currently checks for blank strings.

@Override
public void setBitstreamPolicies(Context context, Bitstream bitstream, Item item, String accConditionsStr) {
+   if (accConditionsStr == null) {
+       log.warn("Null access conditions string provided when setting bitstream policies for bitstream " + bitstream.getID());
+       return;
+   }
    String msg = messageProvider.getMessage(
            context,
            ProvenanceMessageTemplates.ACCESS_CONDITION.getTemplate(),
            accConditionsStr,
            "bitstream",
            bitstream.getID()
    );

    try {
        addProvenanceMetadata(context, item, msg);
    } catch (SQLException | AuthorizeException e) {
        log.error("Unable to add new provenance metadata when setting bitstream policies.", e);
    }
}
dspace-server-webapp/src/main/java/org/dspace/app/rest/submit/factory/impl/BitstreamResourcePolicyAddPatchOperation.java (1)

42-43: Good autowiring of the ProvenanceService.

Properly autowired the ProvenanceService to enable recording provenance information for bitstream policies.

@milanmajchrak milanmajchrak requested a review from vidiecan May 7, 2025 13:19
@vidiecan vidiecan requested a review from Copilot May 12, 2025 14:36
Copy link

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 fixes an issue where embargo information was not being recorded in the provenance metadata when access conditions are updated for bitstreams. The changes include adding an integration test for embargo handling, updating the patch operation to record provenance for each access condition, and extending the ProvenanceService API and implementation to support the new behavior.

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
dspace-server-webapp/src/test/java/org/dspace/app/rest/WorkflowItemRestRepositoryIT.java Added a new integration test (patchEmbargoTest) to verify that embargo access conditions add provenance metadata.
dspace-server-webapp/src/main/java/org/dspace/app/rest/submit/factory/impl/BitstreamResourcePolicyAddPatchOperation.java Updated patch operation to iterate through access conditions and record provenance metadata for each.
dspace-api/src/main/java/org/dspace/core/ProvenanceServiceImpl.java Added an overloaded setBitstreamPolicies method and updated the service to use it.
dspace-api/src/main/java/org/dspace/core/ProvenanceService.java Extended the ProvenanceService interface to include the new setBitstreamPolicies signature.
Comments suppressed due to low confidence (1)

dspace-server-webapp/src/main/java/org/dspace/app/rest/submit/factory/impl/BitstreamResourcePolicyAddPatchOperation.java:80

  • [nitpick] Consider renaming the 'name' variable to 'accessConditionName' to improve clarity about its purpose.
String name;

Copy link

@vidiecan vidiecan left a comment

Choose a reason for hiding this comment

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

check copilot

@Paurikova2 Paurikova2 requested a review from vidiecan May 13, 2025 04:40
@milanmajchrak milanmajchrak merged commit 76d2da1 into dtq-dev May 15, 2025
11 checks passed
milanmajchrak added a commit that referenced this pull request May 16, 2025
* Fixed browse - the results are not lowercase (#954)

* S3-CESNET direct downloads (#949)

* Return headers for HEAD request - the bitstream download endpoint (#956)

* The bitstream name is encoded in the URL. (#958)

* SWORDv2 issues: Cannot update bitstream of archived Item. The swordv2 url is not composed correctly. Fixed deleting the workspace item when used org.dspace.sword2.WorkflowManagerDefault (#957)

* The file preview process not required username and password in UI (#960)

* Added translation of distribution license for collection to Czech (#952)

* Added dead and deadSince to handle rest (#948)

* Display community and collection handle (#961)

* Embargo during submission not recorded in provenance (#950)

* Allow to access File Downloader for any authorized user (ufal#1199)

* allow.edit.metadata property should also work for submitters that are members of collection SUBMIT subgroup (ufal#1202)

* Prevent error 500 for non admin user uploading file to bundle (ufal#1205)

* Track downloads as pageviews (ufal#1209)

* Loading the bitstreams - performance issue (ufal#1211)
milanmajchrak pushed a commit that referenced this pull request Nov 11, 2025
* added embargo to provenance

* added IT test
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.

UFAL/Provenance - Embargo during submission not recorded in provenance

5 participants