Skip to content

feat(api): specify delete entity-template behavior and enforce relation-target validation#91

Open
walterspieler-dkt wants to merge 1 commit into
mainfrom
CPDE-2895-idp-core-specify-and-validate-behavior-of-delete-entity-template
Open

feat(api): specify delete entity-template behavior and enforce relation-target validation#91
walterspieler-dkt wants to merge 1 commit into
mainfrom
CPDE-2895-idp-core-specify-and-validate-behavior-of-delete-entity-template

Conversation

@walterspieler-dkt

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 200.
    • 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)

  • API JSON schema modification (existing resource / behavior):
    • DELETE /api/v1/entity-templates/{identifier} success status changed from
      HTTP 204 to HTTP 200.
  • Behavior modification of a component:
    • template deletion now explicitly fails with HTTP 400 when the template is a
      relation target for another template.
  • Others:
    • cascade delete now explicitly removes all entities for the template before
      deleting the template.

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.

@walterspieler-dkt walterspieler-dkt self-assigned this Jul 10, 2026
@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

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