feat(api): specify delete entity-template behavior and enforce relation-target validation - #91
Conversation
… validation for relation targets
|
@copilot resolve the merge conflicts in this pull request |
Co-authored-by: walterspieler-dkt <167087950+walterspieler-dkt@users.noreply.github.com>
Merge conflicts resolved in commit 5 files had conflicts — all resolved by keeping additions from both sides:
All 91 unit tests pass, build compiles cleanly, and CodeQL finds no issues. |
…vior-of-delete-entity-template
…vior-of-delete-entity-template
…vior-of-delete-entity-template
Code Coverage OverviewLanguages: Java Java / code-coverage/jacocoThe overall line coverage in commit a910924 in the Show a line coverage summary of the most impacted files.
Updated |
…vior-of-delete-entity-template
There was a problem hiding this comment.
Pull request overview
This PR makes entity-template deletion behavior explicit across Domain, Persistence, and API layers by preventing deletion when a template is still referenced as a relation target, and by cascading deletion of template-owned entities in the same transactional flow.
Changes:
- Added a relation-target deletion guard via a new domain exception and a persistence-side existence check.
- Implemented cascade deletion of all entities for a template before deleting the template itself (single transaction).
- Updated API contract and tests for
DELETE /api/v1/entity-templates/{identifier}to return200on success and400on relation-target constraint violations.
Reviewed changes
Copilot reviewed 15 out of 15 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| src/test/java/com/decathlon/idp_core/infrastructure/adapters/api/controller/EntityTemplateControllerTest.java | Updates DELETE endpoint test to expect 200 and adds a 400 relation-target scenario. |
| src/test/java/com/decathlon/idp_core/domain/service/entity_template/EntityTemplateServiceTest.java | Adds service-level tests for cascade delete flow and validation failure behavior. |
| src/main/java/com/decathlon/idp_core/infrastructure/adapters/persistence/repository/JpaEntityTemplateRepository.java | Adds JPQL count query to detect relation-target usage before deletion. |
| src/main/java/com/decathlon/idp_core/infrastructure/adapters/persistence/repository/JpaEntityRepository.java | Adds derived delete for bulk removal of entities by template identifier (and documents intent). |
| src/main/java/com/decathlon/idp_core/infrastructure/adapters/persistence/PostgresEntityTemplateAdapter.java | Implements new relation-target existence check via JPA repository. |
| src/main/java/com/decathlon/idp_core/infrastructure/adapters/persistence/PostgresEntityAdapter.java | Implements new port method for deleting entities by template identifier. |
| src/main/java/com/decathlon/idp_core/infrastructure/adapters/api/handler/ApiExceptionHandler.java | Maps the new domain exception to HTTP 400 Bad Request. |
| src/main/java/com/decathlon/idp_core/infrastructure/adapters/api/controller/EntityTemplateController.java | Updates DELETE endpoint contract/annotations to return 200 and document 400/404. |
| src/main/java/com/decathlon/idp_core/domain/service/entity_template/EntityTemplateValidationService.java | Adds relation-target validation to the deletion preconditions. |
| src/main/java/com/decathlon/idp_core/domain/service/entity_template/EntityTemplateService.java | Adds cascade purge call before template deletion inside a transaction. |
| src/main/java/com/decathlon/idp_core/domain/port/EntityTemplateRepositoryPort.java | Extends port contract with relation-target existence check. |
| src/main/java/com/decathlon/idp_core/domain/port/EntityRepositoryPort.java | Extends port contract with bulk entity deletion by template identifier. |
| src/main/java/com/decathlon/idp_core/domain/exception/entity_template/EntityTemplateIsRelationTargetException.java | Introduces a domain-specific exception for relation-target deletion constraint. |
| src/main/java/com/decathlon/idp_core/domain/constant/ValidationMessages.java | Adds a new validation message for the relation-target deletion constraint. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> Signed-off-by: Andrés Brand <andresbrand@gmail.com>
|



What this PR Provides
targetTemplateIdentifierby another template relation.EntityTemplateIsRelationTargetExceptionwith a clear validation message.template itself, in the same transactional flow.
DELETE /api/v1/entity-templates/{identifier}:ADR link:
Fixes
Review
The reviewer must double-check these points:
!after the type/scope to identify the breakingchange 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
(example:
monitoring-service).(example from current test data:
microservice).DELETE /api/v1/entity-templates/monitoring-service.monitoring-serviceare removed (for example,by checking related entity retrieval endpoints or DB content).
DELETE /api/v1/entity-templates/microservice.relation-target usage.
DELETE /api/v1/entity-templates/<non-existent-id>.entities.
relation target in another template.
Breaking changes (if any)
DELETE /api/v1/entity-templates/{identifier}success status changed fromHTTP 204 to HTTP 200.
relation target for another template.
deleting the template.
Context of the Breaking Change
The delete-template endpoint behavior was made explicit and aligned with domain
integrity rules:
Result of the Breaking Change
adapt to HTTP 200.
and should resolve referencing relations before retrying deletion.