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

Skip to content

Conversation

@milanmajchrak
Copy link
Collaborator

@milanmajchrak milanmajchrak commented May 7, 2025

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

Problem description

Reported issues

Not-reported issues

Analysis

(Write here, if there is needed describe some specific problem. Erase it, when it is not needed.)

Problems

(Write here, if some unexpected problems occur during solving issues. Erase it, when it is not needed.)

Summary by CodeRabbit

  • Bug Fixes

    • Resolved an issue that could cause errors when deleting items multiple times, ensuring items are only deleted once per transaction.
    • Fixed a potential error when removing bundles from items, preventing concurrent modification problems.
  • Tests

    • Added new integration tests for SWORDv2 endpoints, covering URL fallback, item deletion in different workflow states, and file updates via the API.

milanmajchrak and others added 3 commits May 7, 2025 09:49
* Removed `swordv2` duplicities from the `edit-media` request

* Compose correctly the swordBaseUrl when the `path` is empty

* Added better doc
* Using for instead of Iterator in removeBundle

* Added a test to test file change in the Item

* Use a default value for the plugin.single.org.dspace.sword2.WorkflowManager

* Added a doc why we did that change

---------

Co-authored-by: Matus Kasak <[email protected]>
Co-authored-by: milanmajchrak <[email protected]>
@milanmajchrak milanmajchrak self-assigned this May 7, 2025
@coderabbitai
Copy link

coderabbitai bot commented May 7, 2025

Walkthrough

This update introduces new integration tests for the SWORDv2 API in DSpace, enhances the deletion logic to prevent redundant item deletions, adjusts URL construction to avoid extra path segments, and refactors bundle removal to prevent concurrent modification errors.

Changes

File(s) Change Summary
dspace-server-webapp/src/test/java/org/dspace/app/sword2/Swordv2IT.java Added integration tests for SWORDv2: verifying server URL fallback, workspace/workflow item deletion under different managers, and file update operations.
dspace-swordv2/src/main/java/org/dspace/sword2/ContainerManagerDSpace.java Updated doContainerDelete to check for prior deletion using a new helper method, preventing double deletion of items.
dspace-swordv2/src/main/java/org/dspace/sword2/SwordUrlManager.java Modified URL construction to avoid adding an extra "swordv2" path segment or trailing slash when the server URL config is unset; used StringUtils.isNotBlank for conditional path appending.
dspace-swordv2/src/main/java/org/dspace/sword2/VersionManager.java Refactored bundle removal to collect bundles to remove in a separate list before deletion, preventing ConcurrentModificationException during iteration.

Sequence Diagram(s)

sequenceDiagram
    participant Test as Swordv2IT Test
    participant API as SWORDv2 API
    participant Config as Configuration
    participant Item as DSpace Item
    participant Workflow as WorkflowManager

    Test->>API: Send deposit or edit request (URL config null)
    API->>Config: Get swordv2-server.url
    Config-->>API: Return null
    API->>API: Construct default base URL
    API->>Item: Create or update item
    Test->>API: Retrieve item, check headers/content

    Test->>API: DELETE workspace/workflow item
    API->>Workflow: Use specific WorkflowManager
    API->>Item: Delete item (check for prior deletion)
    API-->>Test: Return 204 No Content
    Test->>API: Retrieve deleted item
    API-->>Test: Return 404 Not Found

    Test->>API: PUT updated file to media resource
    API->>Item: Update file content
    API-->>Test: Return 204 No Content
Loading

Poem

In the warren of code, new tests now appear,
Ensuring SWORDv2’s endpoints stay clear.
Deletions are careful, no double distress,
URLs are tidy, with less trailing mess.
Bundles removed with a gentle, safe sweep—
These changes, dear rabbit, make DSpace leap!
🐇✨

✨ 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: 1

🧹 Nitpick comments (3)
dspace-swordv2/src/main/java/org/dspace/sword2/SwordUrlManager.java (1)

497-499: Guard against double slashes & blank swordPath in buildSWORDUrl()

dspaceUrl may already end with “/”, and swordPath can be configured as empty or start/end with slashes.
The current concatenation can therefore yield URLs like https://dspace.org//swordv2 or just https://dspace.org/ (trailing slash but no path). A small normalisation makes this helper more robust for all call-sites.

-        return dspaceUrl + "/" + swordPath + (StringUtils.isNotBlank(path) ? "/" + path : "");
+        StringBuilder url = new StringBuilder(dspaceUrl);
+        if (!dspaceUrl.endsWith("/")) {
+            url.append('/');
+        }
+        if (StringUtils.isNotBlank(swordPath)) {
+            url.append(StringUtils.stripStart(swordPath, "/"));
+        }
+        if (StringUtils.isNotBlank(path)) {
+            url.append('/').append(StringUtils.stripStart(path, "/"));
+        }
+        return url.toString();

This keeps behaviour identical for standard values, but prevents double-slashes and works even if swordv2-server.path is set to “” (allowed by the config defaults).

dspace-swordv2/src/main/java/org/dspace/sword2/ContainerManagerDSpace.java (1)

800-814: Minor: linear scan over event list can be expensive in large batches

context.getEvents() may contain hundreds of entries during bulk operations. Consider short-circuiting once a match is found or holding a HashSet<UUID> of deleted IDs if this check is performed frequently.

dspace-server-webapp/src/test/java/org/dspace/app/sword2/Swordv2IT.java (1)

639-645: Ensure test stream is closed to avoid file-handle leaks on Windows

getResourceAsStream("simple-article.pdf") is never closed. While short-lived in tests, Windows locks the file until GC closes the stream, potentially causing flaky behaviour.

-        InputStream pdf = getClass().getResourceAsStream("simple-article.pdf");
-        WorkspaceItem witem = WorkspaceItemBuilder.createWorkspaceItem(context, collection)
+        try (InputStream pdf = getClass().getResourceAsStream("simple-article.pdf")) {
+            WorkspaceItem witem = WorkspaceItemBuilder.createWorkspaceItem(context, collection)
                 .withTitle("Test WorkspaceItem")
                 .withIssueDate("2017-10-17")
                 .withFulltext("simple-article.pdf", "/local/path/simple-article.pdf", pdf)
                 .build();
+            item = witem.getItem();
+        }

(This requires moving the item variable outside the try block).

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 9d7f646 and b98342c.

📒 Files selected for processing (4)
  • dspace-server-webapp/src/test/java/org/dspace/app/sword2/Swordv2IT.java (4 hunks)
  • dspace-swordv2/src/main/java/org/dspace/sword2/ContainerManagerDSpace.java (4 hunks)
  • dspace-swordv2/src/main/java/org/dspace/sword2/SwordUrlManager.java (3 hunks)
  • dspace-swordv2/src/main/java/org/dspace/sword2/VersionManager.java (2 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 (2)
dspace-swordv2/src/main/java/org/dspace/sword2/ContainerManagerDSpace.java (1)

767-773: Type consistency check when skipping second delete

isItemAlreadyDeleted(context, item.getID()) compares the UUID of the Item to event.getSubjectID().
Please confirm that Event#getSubjectID() also returns a java.util.UUID. In some older DSpace versions this method returned an int, in which case the equality check will always be false and the duplicate‐delete protection won’t work.

If the types can differ, convert both sides to String/UUID before comparing, or use event.getSubject().

Example (only if required):

-            if (event.getEventType() == Event.DELETE && event.getSubjectID().equals(itemUUID)) {
+            if (event.getEventType() == Event.DELETE
+                && itemUUID.toString().equals(event.getSubjectID().toString())) {
                 return true;
             }
dspace-swordv2/src/main/java/org/dspace/sword2/VersionManager.java (1)

47-58: Good fix – removes risk of ConcurrentModificationException

Collecting bundles into a separate list before removal is the safest approach here. The change keeps behavioural parity while hardening against runtime crashes.

@milanmajchrak milanmajchrak merged commit f79e704 into dtq-dev May 7, 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)
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