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

feat(rest): create new endpoint for bulk delete function #2416

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

shi9qiu
Copy link
Contributor

@shi9qiu shi9qiu commented Apr 17, 2024

Please provide a summary of your changes here.

  • Which issue is this pull request belonging to and how is it solving it? (Refer to issue here)
  • Did you add or update any new dependencies that are required for your change?

Issue: #2415, #1649

Create new endpoint for bulk delete function (#1468).

How To Test?

  • Preparations

    • Before starting the system, add the following options to sw360.properties.
      bulk.release.deleting.enabled=true  
      admin.private.project.access.enabled=true  
      
    • Obtain an API token with Admin privileges.
    • Obtain an API token with User (or non-Admin) privileges.
  • Exclusion Behavior Confirmation

    1. After starting the system, sign in as an Admin user and register a Release with the following structure.
      basic_links

    2. Open the detail screen of each Release in a web browser and confirm the ID of the Release.

    3. Use any RestAPI client tool to execute the RestAPI.
      HTTP Method: DELETE
      URL:http://{your-host}/resource/api/releases/{release-id}/bulkDelete

      • Specify the ID of “DeleteLibrary001 1.00” confirmed in the web browser for {release-id}.
      • Specify a token that can be accessed with Admin privileges as authentication information.
    4. Response Confirmation

      • Confirm that the response is a success status.
      • Confirm that the response body contains JSON data in the following format.
        {
            "id": "0cc9b2190acc4a9684220c5fae3bb8d1",
            "name": "DeleteLibrary001",
            "version": "",
            "type": "COMPONENT",
            "childList": [
                {
                    "id": "7ba3519c75a44dbb8001b9abf204aabe",
                    "name": "DeleteLibrary001",
                    "version": "1.00",
                    "type": "RELEASE",
                    "parentId": "0cc9b2190acc4a9684220c5fae3bb8d1",
                    "childList": [
                        {
                            "id": "f44b32501fce45cf83210eb87e1a0f38",
                            "name": "DeleteLibrary002",
                            "version": "",
                            "type": "COMPONENT",
                            "parentId": "7ba3519c75a44dbb8001b9abf204aabe",
                            "childList": [
                                {
                                    "id": "81e2a98043754c16ae0e1f0b813f12e8",
                                    "name": "DeleteLibrary002",
                                    "version": "1.00",
                                    "type": "RELEASE",
                                    "parentId": "f44b32501fce45cf83210eb87e1a0f38",
                                    "childList": [
                                        {
                                            "id": "559eef9ea058403bb573bf1d9877e578",
                                            "name": "DeleteLibrary003",
                                            "version": "",
                                            "type": "COMPONENT",
                                            "parentId": "81e2a98043754c16ae0e1f0b813f12e8",
                                            "childList": [
                                                {
                                                    "id": "aac86784f95146929646009a6ee6a6f9",
                                                    "name": "DeleteLibrary003",
                                                    "version": "1.00",
                                                    "type": "RELEASE",
                                                    "parentId": "559eef9ea058403bb573bf1d9877e578",
                                                    "childList": [],
                                                    "state": "EXCLUDED"
                                                }
                                            ],
                                            "state": "EXCLUDED"
                                        }
                                    ],
                                    "state": "EXCLUDED"
                                }
                            ],
                            "state": "EXCLUDED"
                        }
                    ],
                    "state": "EXCLUDED"
                }
            ],
            "state": "EXCLUDED"
        }
        Replace the ID of the release according to the test data.
    5. Confirm that the following records have not been deleted.
      [Release]
      DeleteLibrary001 1.00
      DeleteLibrary002 1.00
      DeleteLibrary003 1.00

      [Component]
      DeleteLibrary001
      DeleteLibrary002
      DeleteLibrary003

  • Confirmation of Preview Mode Operation

    1. After starting the system, sign in as an Admin user and register a Release with the following structure.
      test data1

    2. Open the detail screen of each Release in a web browser and confirm the ID of the Release.

    3. Use any RestAPI client tool to execute the RestAPI.
      HTTP Method: DELETE
      URL: http://{your-host}/resource/api/releases/{release-id}/bulkDelete?isPreview=true

      • Specify the ID of “DeleteLibrary004 1.00” confirmed in the web browser for {release-id}.
      • Specify isPreview=true as a parameter.
      • Specify a token that can be accessed with Admin privileges as authentication information.
    4. Response Confirmation

      • Confirm that the response is a success status.
      • Confirm that the response body contains JSON data in the following format.
        {
            "id": "8bfed94283b044eea64d26ba3ddc82ad",
            "name": "DeleteLibrary004",
            "version": "",
            "type": "COMPONENT",
            "childList": [
                {
                    "id": "24db41e44aa64090a6fdad642d7d94b1",
                    "name": "DeleteLibrary004",
                    "version": "1.00",
                    "type": "RELEASE",
                    "parentId": "8bfed94283b044eea64d26ba3ddc82ad",
                    "childList": [
                        {
                            "id": "056543ab37dc404f8b322409d7697bc4",
                            "name": "RemainLibrary001",
                            "version": "",
                            "type": "COMPONENT",
                            "parentId": "24db41e44aa64090a6fdad642d7d94b1",
                            "childList": [
                                {
                                    "id": "dbd29dbba48e4c0f809897a4695d0248",
                                    "name": "RemainLibrary001",
                                    "version": "1.00",
                                    "type": "RELEASE",
                                    "parentId": "056543ab37dc404f8b322409d7697bc4",
                                    "childList": [],
                                    "state": "EXCLUDED"
                                }
                            ],
                            "state": "EXCLUDED"
                        },
                        {
                            "id": "44b339a428b1470a8232944a0efa012e",
                            "name": "DeleteLibrary005",
                            "version": "",
                            "type": "COMPONENT",
                            "parentId": "24db41e44aa64090a6fdad642d7d94b1",
                            "childList": [
                                {
                                    "id": "8a12abad6bfe4d63b3cf2738f6d87f37",
                                    "name": "DeleteLibrary005",
                                    "version": "1.00",
                                    "type": "RELEASE",
                                    "parentId": "44b339a428b1470a8232944a0efa012e",
                                    "childList": [
                                        {
                                            "id": "1c14c0b323754a98835ef8f06ef05ce9",
                                            "name": "DeleteLibrary006",
                                            "version": "",
                                            "type": "COMPONENT",
                                            "parentId": "8a12abad6bfe4d63b3cf2738f6d87f37",
                                            "childList": [
                                                {
                                                    "id": "6ff70c8569c541adbc04667624d9a2f1",
                                                    "name": "DeleteLibrary006",
                                                    "version": "1.00",
                                                    "type": "RELEASE",
                                                    "parentId": "1c14c0b323754a98835ef8f06ef05ce9",
                                                    "childList": [],
                                                    "state": "SUCCEEDED"
                                                }
                                            ],
                                            "state": "SUCCEEDED"
                                        }
                                    ],
                                    "state": "SUCCEEDED"
                                }
                            ],
                            "state": "SUCCEEDED"
                        }
                    ],
                    "state": "SUCCEEDED"
                }
            ],
            "state": "SUCCEEDED"
        }
        Replace the ID of the release according to the test data.
    5. Confirm that the following records have not been deleted.
      [Release]
      ExcludeLibrary001 1.00
      RemainLibrary001 1.00
      DeleteLibrary004 1.00
      DeleteLibrary005 1.00
      DeleteLibrary006 1.00

      [Component]
      ExcludeLibrary001
      RemainLibrary001
      DeleteLibrary004
      DeleteLibrary005
      DeleteLibrary006

  • Bulk Deletion Confirmation

    1. After starting the system, sign in as an Admin user and register a Release with the following structure.
      test data2

    2. Open the detail screen of each Release in a web browser and confirm the ID of the Release.

    3. Use any RestAPI client tool to execute the RestAPI.
      HTTP Method: DELETE
      URL: http://{your-host}/resource/api/releases/{release-id}/bulkDelete

      • Specify the ID of “DeleteLibrary004 1.00” confirmed in the web browser for {release-id}.
      • Specify a token that can be accessed with Admin privileges as authentication information.
    4. Response Confirmation

      • Confirm that the response is a success status.
      • Confirm that the response body contains JSON data in the following format.
        {
            "id": "8bfed94283b044eea64d26ba3ddc82ad",
            "name": "DeleteLibrary004",
            "version": "",
            "type": "COMPONENT",
            "childList": [
                {
                    "id": "24db41e44aa64090a6fdad642d7d94b1",
                    "name": "DeleteLibrary004",
                    "version": "1.00",
                    "type": "RELEASE",
                    "parentId": "8bfed94283b044eea64d26ba3ddc82ad",
                    "childList": [
                        {
                            "id": "056543ab37dc404f8b322409d7697bc4",
                            "name": "RemainLibrary001",
                            "version": "",
                            "type": "COMPONENT",
                            "parentId": "24db41e44aa64090a6fdad642d7d94b1",
                            "childList": [
                                {
                                    "id": "dbd29dbba48e4c0f809897a4695d0248",
                                    "name": "RemainLibrary001",
                                    "version": "1.00",
                                    "type": "RELEASE",
                                    "parentId": "056543ab37dc404f8b322409d7697bc4",
                                    "childList": [],
                                    "state": "EXCLUDED"
                                }
                            ],
                            "state": "EXCLUDED"
                        },
                        {
                            "id": "44b339a428b1470a8232944a0efa012e",
                            "name": "DeleteLibrary005",
                            "version": "",
                            "type": "COMPONENT",
                            "parentId": "24db41e44aa64090a6fdad642d7d94b1",
                            "childList": [
                                {
                                    "id": "8a12abad6bfe4d63b3cf2738f6d87f37",
                                    "name": "DeleteLibrary005",
                                    "version": "1.00",
                                    "type": "RELEASE",
                                    "parentId": "44b339a428b1470a8232944a0efa012e",
                                    "childList": [
                                        {
                                            "id": "1c14c0b323754a98835ef8f06ef05ce9",
                                            "name": "DeleteLibrary006",
                                            "version": "",
                                            "type": "COMPONENT",
                                            "parentId": "8a12abad6bfe4d63b3cf2738f6d87f37",
                                            "childList": [
                                                {
                                                    "id": "6ff70c8569c541adbc04667624d9a2f1",
                                                    "name": "DeleteLibrary006",
                                                    "version": "1.00",
                                                    "type": "RELEASE",
                                                    "parentId": "1c14c0b323754a98835ef8f06ef05ce9",
                                                    "childList": [],
                                                    "state": "SUCCEEDED"
                                                }
                                            ],
                                            "state": "SUCCEEDED"
                                        }
                                    ],
                                    "state": "SUCCEEDED"
                                }
                            ],
                            "state": "SUCCEEDED"
                        }
                    ],
                    "state": "SUCCEEDED"
                }
            ],
            "state": "SUCCEEDED"
        }

      Replace the ID of the release according to the test data.

    5. Confirm that the following records have not been deleted.
      [Release]
      ExcludeLibrary001 1.00
      RemainLibrary001 1.00

      [Component]
      ExcludeLibrary001
      RemainLibrary001

    6. Confirm that the following records have been deleted.
      [Release]
      DeleteLibrary004 1.00
      DeleteLibrary005 1.00
      DeleteLibrary006 1.00

      [Component]
      DeleteLibrary004
      DeleteLibrary005
      DeleteLibrary006

  • Operation by a User without Admin Privileges

    1. Open the detail screen of any Release in a web browser and confirm the ID of the Release.

    2. Use any RestAPI client tool to execute the RestAPI.
      HTTP method: DELETE
      URL: http://{your-host}/resource/api/releases/{release-id}/bulkDelete

      • Specify the ID of the Release confirmed in the web browser for {release-id}.
      • Specify a token with User (or non-Admin) privileges as authentication information.
    3. Response Confirmation

      • Confirm that the response is an error status.
      • Confirm that the Release specified for deletion has not been deleted.

Checklist

Must:

  • All related issues are referenced in commit messages and in PR

Overview of improvements

Purpose

  • The bulk delete function is a feature that allows for the deletion of a group of Releases and unused Components that are linked together, starting from a specified Release.

  • The purpose of this change is to enable the execution of the bulk delete function from the RestAPI, in anticipation of transitioning the frontend to Next.js.

  • The operating conditions and limitations are the same as the UI version of the bulk delete function.

    To enable the bulk delete function, it is necessary to enable the Admin’s Private access function.

    Add the following entries to sw360.properties:

    bulk.release.deleting.enabled=true  
    admin.private.project.access.enabled=true  
    

Summary of Function Changes

  • Addition of Endpoint
    The following endpoint has been added to the SW360 RestAPI.

    Endpoint HTTP method Description
    /releases/{id}/bulkDelete DELETE Bulk deletes the Release specified by {id}, its subordinate resources, and unused Components.
    Query parameter Value Description
    isPreview Boolean Flag for the preview mode of the bulk delete function. It’s an optional parameter and the default value is false.
    true: Only perform operation check without deleting data on the DB. (For preview screen)
    false: Delete data on the DB.

    Sample URL:

    http://127.0.0.1:8080/resource/api/releases/{id}/bulkDelete?isPreview=true
    

Key Points of Code Changes

  1. RestAPI
    • Addition of endpoint for bulk delete function

      • ReleaseController
        rest/resource-server/src/main/java/org/eclipse/sw360/rest/resourceserver/release/ReleaseController.java
        bulkDeleteReleases method
        Added a Java method corresponding to the endpoint “/{id}/bulkDelete” for the bulk delete function.

      • Sw360ReleaseService
        rest/resource-server/src/main/java/org/eclipse/sw360/rest/resourceserver/release/Sw360ReleaseService.java
        deleteBulkRelease method
        Added common RestAPI processing to call the backend processing of the bulk delete function.

      • JacksonCustomizations
        rest/resource-server/src/main/java/org/eclipse/sw360/rest/resourceserver/core/JacksonCustomizations.java
        BulkOperationNodeMixin class
        Added a Mixin class containing instructions to the serializer during response JSON generation.

    • Bug fixes
      Modified backend logic to fix bugs discovered in testing.

      • BulkDeleteUtil
        backend/src-common/src/main/java/org/eclipse/sw360/datahandler/db/BulkDeleteUtil.java
        deleteBulkRelease method

        Fixed a bug where the links of subordinate Releases were deleted when a Release referenced from an external project was bulk deleted.

      • BulkDeleteUtilTest
        backend/src/src-components/src/test/java/org/eclipse/sw360/components/db/BulkDeleteUtilTest.java

        Added Maven tests to address the aforementioned bug.

Data Structure

  • DB Records
    The bulk delete function analyzes the dependency tree of existing data each time and deletes the data. Therefore, the bulk delete function does not hold any tree information in the database.

  • Response JSON
    The API of the bulk delete function returns JSON data in the following format after execution. The structure of the JSON data is based on the assumption that it will be displayed on the bulk delete screen of the UI, and the format is such that Components and Releases appear alternately.

    {
        "id": "8bfed94283b044eea64d26ba3ddc82ad",
        "name": "DeleteLibrary004",
        "version": "",
        "type": "COMPONENT",
        "childList": [
            {
                "id": "24db41e44aa64090a6fdad642d7d94b1",
                "name": "DeleteLibrary004",
                "version": "1.00",
                "type": "RELEASE",
                "parentId": "8bfed94283b044eea64d26ba3ddc82ad",
                "childList": [
                    {
                        "id": "056543ab37dc404f8b322409d7697bc4",
                        "name": "RemainLibrary001",
                        "version": "",
                        "type": "COMPONENT",
                        "parentId": "24db41e44aa64090a6fdad642d7d94b1",
                        "childList": [
                            {
                                "id": "dbd29dbba48e4c0f809897a4695d0248",
                                "name": "RemainLibrary001",
                                "version": "1.00",
                                "type": "RELEASE",
                                "parentId": "056543ab37dc404f8b322409d7697bc4",
                                "childList": [],
                                "state": "EXCLUDED"
                            }
                        ],
                        "state": "EXCLUDED"
                    },
                    {
                        "id": "44b339a428b1470a8232944a0efa012e",
                        "name": "DeleteLibrary005",
                        "version": "",
                        "type": "COMPONENT",
                        "parentId": "24db41e44aa64090a6fdad642d7d94b1",
                        "childList": [
                            {
                                "id": "8a12abad6bfe4d63b3cf2738f6d87f37",
                                "name": "DeleteLibrary005",
                                "version": "1.00",
                                "type": "RELEASE",
                                "parentId": "44b339a428b1470a8232944a0efa012e",
                                "childList": [
                                    {
                                        "id": "1c14c0b323754a98835ef8f06ef05ce9",
                                        "name": "DeleteLibrary006",
                                        "version": "",
                                        "type": "COMPONENT",
                                        "parentId": "8a12abad6bfe4d63b3cf2738f6d87f37",
                                        "childList": [
                                            {
                                                "id": "6ff70c8569c541adbc04667624d9a2f1",
                                                "name": "DeleteLibrary006",
                                                "version": "1.00",
                                                "type": "RELEASE",
                                                "parentId": "1c14c0b323754a98835ef8f06ef05ce9",
                                                "childList": [],
                                                "state": "SUCCEEDED"
                                            }
                                        ],
                                        "state": "SUCCEEDED"
                                    }
                                ],
                                "state": "SUCCEEDED"
                            }
                        ],
                        "state": "SUCCEEDED"
                    }
                ],
                "state": "SUCCEEDED"
            }
        ],
        "state": "SUCCEEDED"
    }

    Data class corresponding to the response data:
    org.eclipse.sw360.datahandler.thrift.components.BulkOperationNode

DB Migration

There are no changes to the DB structure due to this modification.

Limitations

  • None in particular.

@KoukiHama KoukiHama added needs code review needs general test This is general testing, meaning that there is no org specific issue to check for REST New-UI Level for the API and UI level changes for the new-ui labels Apr 18, 2024
@ag4ums ag4ums self-assigned this Apr 22, 2024
@GMishx GMishx assigned smrutis1 and unassigned ag4ums Oct 17, 2024
@shi9qiu
Copy link
Contributor Author

shi9qiu commented Nov 11, 2024

Dear all, @GMishx @KoukiHama @heliocastro @arunazhakesan @smrutis1
I have resolved the conflicts and rebased the code. Could you help to review this again?
Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs code review needs general test This is general testing, meaning that there is no org specific issue to check for New-UI Level for the API and UI level changes for the new-ui REST
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants