Skip to content

feat(core): DELETE entity endpoint#59

Open
RVANDO12 wants to merge 13 commits into
mainfrom
feat/entity/delete
Open

feat(core): DELETE entity endpoint#59
RVANDO12 wants to merge 13 commits into
mainfrom
feat/entity/delete

Conversation

@RVANDO12
Copy link
Copy Markdown
Collaborator

@RVANDO12 RVANDO12 commented May 22, 2026

PR Description

https://decathlon.atlassian.net/browse/CPDE-2935

  • HTTP Method: DELETE
  • Path: /api/v1/entities/{templateIdentifier}/{entityIdentifier}
  • Security: Requires an authenticated user (@WithMockUser) and a valid CSRF token.
  • Expected Responses:
    • 204 No Content: Successful deletion or relation cleanup completed.
    • 401 Unauthorized: Missing or invalid authentication token.
    • 403 Forbidden: Missing CSRF token or insufficient rights.
    • 404 Not Found: Entity or template does not exist.
    • 500 Internal Server Error: Unexpected server failure (e.g., blank path parameters).

image

What this PR Provides

  • new endpoint for DELETE Entity
  • DELETE : Remove an entity from the system using its identifier and template identifier
  • DELETE : Validate remove only if not link to a relation required, and prevent orphan when removed entity
    . Rule 1 (Optional relationship): If the parent entity points to the deleted entity, and this relationship required: false in its Template, the relationship is simply removed from the parent entity in the database.
    . Rule 2 (Mandatory relationship): If the parent entity points to the deleted entity, and the relationship required: true, and it was the only target entity (to_many cardinality: false or array became empty), the deletion prime on relation and the relations was updated after deletion of entity.

Review

The reviewer must double-check these points:

  • The reviewer has tested the feature
  • The reviewer has reviewed the implementation of the feature
  • The documentation has been updated
  • The feature implementation respects the Technical Doc / ADR previously produced

How to Test


2. Test Setup & Prerequisites

To thoroughly validate the deletion workflow and its side effects (cascading relation cleanups), you must establish a multi-entity relational lifecycle model.

Step 1: Ensure an Entity Template Exists

An entity cannot exist without a valid parent schema template.

  • Action: Verify or create an EntityTemplate (e.g., web-service) that defines the necessary schema properties and relation definitions.

Step 2: Create the Target Entity (The Entity to Delete)

This entity will be the target of the DELETE request.

  • Action: Send a POST /api/v1/entities/web-service request.
  • Payload:
    {
      "name": "Relation Target Entity",
      "identifier": "relation-target-entity",
      "properties": {
        "applicationName": "catalog-api",
        "ownerEmail": "owner@example.com",
        "port": "8080",
        "environment": "DEV",
        "version": "1.2.3",
        "teamName": "platform-team",
        "baseUrl": "[https://catalog.example.com](https://catalog.example.com)",
        "protocol": "HTTP",
        "programmingLanguage": "JAVA"
      }
    }
  • Expectation: 201 Created.

Step 3: Create the Source Entity with a Multi-Relation Link

To test the cascading relational cleanup, a second entity must be created that declares a dependency or relation pointing to the target entity created in Step 2.

  • Action: Send a POST /api/v1/entities/web-service request.
  • Payload:
    {
      "name": "Relation Source Entity",
      "identifier": "relation-source-entity",
      "properties": { 
        "applicationName": "source-api",
        "ownerEmail": "source@example.com",
        "port": "9090"
      },
      "relations": [
        {
          "name": "database",
          "target_entity_identifiers": ["relation-target-entity"]
        }
      ]
    }
  • Expectation: 201 Created.

3. Test Execution Workflow

Once the environment state is prepared, execute the deletion process sequentially.

Flow: [Source Entity] --(points to)--> [Target Entity]

  1. Executing DELETE on Target Entity
  2. Target Entity is removed from DB (204)
  3. Source Entity's relations are automatically updated (200 OK)

Step 4: Execute the DELETE Request

Perform the destructive action on the target entity identifier while supplying appropriate mock authentication and CSRF protection headers.

  • Action: Invoke DELETE /api/v1/entities/web-service/relation-target-entity

4. Verification & Assertions

A successful test must guarantee data consistency across three distinct structural checks:

Step 5: Assert Deletion Success

  • Immediate Response: The HTTP status code returned by the server must be exactly 204 No Content.

Step 6: Verify Target Non-Existence (Read-After-Delete)

  • Action: Perform a GET /api/v1/entities/web-service/relation-target-entity.
  • Assertion: The system must return a 404 Not Found status code, ensuring that the record has been fully removed from active storage.

Step 7: Verify Relationship Cleanup on the Source Entity

This is the critical functional boundary validation. The source entity itself must not be deleted, but its internal metadata array mapping the relation to the target entity must be automatically scrubbed.

  • Action: Perform a GET /api/v1/entities/web-service/relation-source-entity.
  • Assertions:
    1. The response code must be 200 OK (the source entity still safely exists).
    2. The JSON response string under the relations block must not contain the string "identifier":"relation-target-entity". The database layer must cleanly un-link the reference.

Breaking changes

N/A

@RVANDO12 RVANDO12 changed the title Feat/entity/delete feat(core): DELETE entity endpoint May 22, 2026
@RVANDO12 RVANDO12 force-pushed the feat/entity/delete branch 3 times, most recently from 335308c to c45d3c5 Compare May 29, 2026 12:24
@RVANDO12 RVANDO12 force-pushed the feat/entity/delete branch from d94a090 to f065994 Compare June 1, 2026 07:04
@RVANDO12 RVANDO12 marked this pull request as ready for review June 1, 2026 07:38
Copy link
Copy Markdown
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 a new DELETE /api/v1/entities/{templateIdentifier}/{entityIdentifier} endpoint to remove an entity, and introduces relation-cleanup logic intended to remove incoming references from other entities. It also updates OpenAPI/docs and adds both integration and unit tests around the deletion workflow.

Changes:

  • Add a DELETE endpoint in EntityController with Swagger metadata and documentation updates.
  • Implement domain-level deletion orchestration in EntityService, including cleanup of parent-entity relations referencing the deleted entity.
  • Extend the persistence port/adapter and repository with new methods (findEntitiesRelated, deleteByTemplateIdentifierAndIdentifier) and add tests for the new behavior.

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 9 comments.

Show a summary per file
File Description
src/test/java/com/decathlon/idp_core/infrastructure/adapters/api/controller/EntityControllerTest.java Adds integration tests for DELETE endpoint behavior (status codes, relation cleanup, auth/CSRF).
src/test/java/com/decathlon/idp_core/domain/service/entity/EntityServiceTest.java Adds unit tests validating relation-cleanup behavior during deletion.
src/main/java/com/decathlon/idp_core/infrastructure/adapters/persistence/repository/JpaEntityRepository.java Adds JPA query to find entities referencing a target identifier and a delete method by template+identifier.
src/main/java/com/decathlon/idp_core/infrastructure/adapters/persistence/PostgresEntityAdapter.java Implements new persistence port methods by delegating to the JPA repository.
src/main/java/com/decathlon/idp_core/infrastructure/adapters/api/controller/EntityController.java Adds @DeleteMapping endpoint and OpenAPI responses for entity deletion.
src/main/java/com/decathlon/idp_core/infrastructure/adapters/api/configuration/SwaggerDescription.java Adds Swagger description constants for the DELETE endpoint.
src/main/java/com/decathlon/idp_core/domain/service/entity/EntityService.java Adds deleteEntity(...) and relation-cleanup logic prior to repository deletion.
src/main/java/com/decathlon/idp_core/domain/port/EntityRepositoryPort.java Extends the domain persistence port for relation lookup + deletion by template+identifier.
docs/src/static/swagger.yaml Documents the new DELETE operation in the static OpenAPI spec.
docs/src/concepts/entities.md Documents how to delete an entity and describes cascade cleanup behavior.

Comment thread src/test/java/com/decathlon/idp_core/domain/service/entity/EntityServiceTest.java Outdated
Comment thread src/main/java/com/decathlon/idp_core/domain/service/entity/EntityService.java Outdated
@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud Bot commented Jun 4, 2026

Comment thread src/main/java/com/decathlon/idp_core/domain/service/entity/EntityService.java Outdated
Comment thread docs/src/concepts/entities.md
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