Skip to content

feat(core): add check when deleting entity template - #138

Merged
brandPittCode merged 1 commit into
mainfrom
feat/add-checks-before-delete-entity-template
Aug 27, 2026
Merged

feat(core): add check when deleting entity template#138
brandPittCode merged 1 commit into
mainfrom
feat/add-checks-before-delete-entity-template

Conversation

@brandPittCode

@brandPittCode brandPittCode commented Aug 27, 2026

Copy link
Copy Markdown
Collaborator

What this PR Provides

  • Adds a deletion guard for entity templates that are referenced as
    targetTemplateIdentifier by another template relation.
  • Introduces a dedicated domain exception
    EntityTemplateIsRelationTargetException with a clear validation message.
  • Implements cascade delete of all entities for a template before deleting the
    template itself, in the same transactional flow.
  • Extends repository ports/adapters and JPA repositories to support:
    • relation-target usage check before deletion.
    • bulk deletion of entities by template identifier.
  • Updates API behavior for DELETE /api/v1/entity-templates/{identifier}:
    • success response is now HTTP 204.
    • returns HTTP 400 when the template is still used as a relation target.
    • still returns HTTP 404 when template does not exist.
  • Adds/updates tests to validate:
    • service-level cascade deletion call path.
    • controller-level HTTP 200 success behavior.
    • controller-level HTTP 400 when deletion is blocked by relation targeting.

ADR link:

  • N/A

Fixes

  • N/A

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
  • The Pull Request title has a ! after the type/scope to identify the breaking
    change in the release note and ensure we will release a major version.

How to test

Please refer (copy/paste) the test section from the User Story. This should include

  • The initial state: what should be the status of the system before testing
    • A running idp-core API with a seeded database containing:
      • an existing template not referenced as a relation target
        (example: monitoring-service).
      • a template referenced as relation target by at least one other template
        (example from current test data: microservice).
      • a non-existing template identifier for negative tests.
  • What and how to test: steps to perform to test the feature
    • Call DELETE /api/v1/entity-templates/monitoring-service.
    • Verify the endpoint returns HTTP 200.
    • Verify entities belonging to monitoring-service are removed (for example,
      by checking related entity retrieval endpoints or DB content).
    • Call DELETE /api/v1/entity-templates/microservice.
    • Verify the endpoint returns HTTP 400 with an explanatory error message about
      relation-target usage.
    • Call DELETE /api/v1/entity-templates/<non-existent-id>.
    • Verify the endpoint returns HTTP 404.
  • Expected results: what should be observed for success or failure
    • Successful deletion returns HTTP 200 and removes both template and owned
      entities.
    • Deletion is rejected with HTTP 400 when the template is still used as a
      relation target in another template.
    • Unknown template identifiers return HTTP 404.

Breaking changes (if any)

N/A

Context of the Breaking Change

The delete-template endpoint behavior was made explicit and aligned with domain
integrity rules:

  • prevent deletion when it would leave dangling relation definitions.
  • ensure template-owned entities are purged in the same transactional flow.
  • expose clear API outcomes for consumers (200/400/404).

Result of the Breaking Change

  • API consumers that expected HTTP 204 on successful template deletion must
    adapt to HTTP 200.
  • API consumers now receive HTTP 400 for relation-target constraint violations
    and should resolve referencing relations before retrying deletion.

@sonarqubecloud

Copy link
Copy Markdown

@github-code-quality

Copy link
Copy Markdown

Code Coverage Overview

Languages: Java

Java / code-coverage/jacoco

The overall line coverage in commit 08f925d in the feat/add-checks-befo... branch remains at 91%, unchanged from commit f2964c4 in the main branch.

Show a line coverage summary of the most impacted files.
File main f2964c4 feat/add-checks-befo... 08f925d +/-
com/decathlon/i...ionHandler.java 83% 83% 0%
com/decathlon/i...ateAdapter.java 91% 91% 0%
com/decathlon/i...ateService.java 94% 94% 0%
com/decathlon/i...tyTemplate.java 100% 100% 0%
com/decathlon/i...ionService.java 100% 100% 0%
com/decathlon/i...ityAdapter.java 81% 82% +1%
com/decathlon/i...ionService.java 90% 100% +10%
com/decathlon/i...tException.java 0% 75% +75%
com/decathlon/i...eException.java 0% 100% +100%
com/decathlon/i...gException.java 0% 100% +100%

@brandPittCode
brandPittCode requested a review from evebrnd August 27, 2026 10:10
@brandPittCode
brandPittCode merged commit 6976334 into main Aug 27, 2026
21 checks passed
@brandPittCode
brandPittCode deleted the feat/add-checks-before-delete-entity-template branch August 27, 2026 11:42
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.

2 participants