Skip to content

feat(core): add guardrails to update template endpoint#51

Merged
evebrnd merged 10 commits into
mainfrom
feat/add-guardrails-on-update-template-endpoint
May 12, 2026
Merged

feat(core): add guardrails to update template endpoint#51
evebrnd merged 10 commits into
mainfrom
feat/add-guardrails-on-update-template-endpoint

Conversation

@evebrnd
Copy link
Copy Markdown
Collaborator

@evebrnd evebrnd commented May 7, 2026

PR Description

What this PR Provides

Enforce the following business rules:

  • All PropertyDefinition names within a single template must be unique
  • All RelationDefinition names within a single template must be unique
  • The targetTemplateIdentifier of a RelationDefinition must reference an existing EntityTemplate and cannot reference the template itself
  • All type changes of PropertyDefinition are blocked. Once a property is created, the type cannot be changed
  • All target template changes of RelationDefinition are blocked. Once a relation is created, the target template cannot be changed
  • When a PropertyDefinition is removed from an EntityTemplate via PUT, the system auto-purges all matching property rows from every entity instance of that template.
  • When a RelationDefinition is removed from an EntityTemplate via PUT, the system auto-purges all matching relation rows from every entity instance of that template.

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

Happy Path

  • Removing a property or renaming it (delete and create) must return a 200 OK. The system must purge associated property values in the database for existing entities (no orphan data).
  • Database integrity - Upon a successful remove operation (property or relation), a GET on the entity property/relation tables must not return any rows for the old identifiers

Error Path

  • Duplicate properties: A PUT request with two properties with the same name must return 400 Bad Request.
  • Duplicate relations: A PUT request with two relations with the same name must return 400 Bad Request.
  • Wrong Relations: If targetTemplateIdentifier references a template that does not exist in the entity_templates table, the request must return 400 Bad Request. If targetTemplateIdentifier references the template itself, the request must return 400 Bad Request.
  • Type change: If the type of a property is changed, PUT request must return 400 Bad Request.
  • Target template change: If the target template of a relation is changed, PUT request must return 400 Bad Request.

Breaking changes

N/A

@evebrnd evebrnd marked this pull request as ready for review May 7, 2026 15:40
@evebrnd evebrnd requested review from Copilot May 11, 2026 08:36
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

Adds domain-level validation guardrails around entity-template creation/update to enforce uniqueness and referential integrity, and introduces API-layer exception mappings and test coverage for the new rules.

Changes:

  • Enforce case-insensitive uniqueness for property/relation names and validate relation target templates exist.
  • Block property type changes on template updates and map new domain exceptions to HTTP 400.
  • Add/adjust integration + unit tests and supporting test fixtures/config.

Reviewed changes

Copilot reviewed 22 out of 22 changed files in this pull request and generated 14 comments.

Show a summary per file
File Description
src/test/resources/integration_test/json/entity-template/v1/putTemplate_400_unsafe_type_conversion.json Adds PUT payload fixture to exercise blocked property type changes
src/test/resources/integration_test/json/entity-template/v1/putEntityTemplate_400_identifier_in_body.json Adds PUT payload fixture containing forbidden/unknown identifier field
src/test/resources/integration_test/json/entity-template/v1/postEntityTemplate_400_target_template_not_found.json Adds POST payload fixture for invalid relation target template
src/test/resources/integration_test/json/entity-template/v1/postEntityTemplate_400_duplicate_relation_names.json Adds POST payload fixture for duplicate relation names (case-insensitive)
src/test/resources/integration_test/json/entity-template/v1/postEntityTemplate_400_duplicate_property_names.json Adds POST payload fixture for duplicate property names (case-insensitive)
src/test/resources/application-test.yml Tightens Jackson test deserialization settings (fail on unknown properties)
src/test/java/com/decathlon/idp_core/infrastructure/adapters/api/controller/EntityTemplateControllerTest.java Adds integration tests for new 400 cases; refactors some endpoint path usages
src/test/java/com/decathlon/idp_core/domain/service/entity_template/RelationDefinitionValidationServiceTest.java Introduces unit tests for relation name uniqueness validation
src/test/java/com/decathlon/idp_core/domain/service/entity_template/PropertyDefinitionValidationServiceTest.java Extends unit tests for property uniqueness and blocked type changes
src/main/java/com/decathlon/idp_core/infrastructure/adapters/persistence/repository/JpaEntityRepository.java Adds existsByTemplateIdentifier query method
src/main/java/com/decathlon/idp_core/infrastructure/adapters/persistence/PostgresEntityAdapter.java Implements existsByTemplateIdentifier in persistence adapter
src/main/java/com/decathlon/idp_core/infrastructure/adapters/api/handler/ApiExceptionHandler.java Maps new domain exceptions to HTTP 400 responses
src/main/java/com/decathlon/idp_core/domain/service/entity_template/RelationDefinitionValidationService.java Adds domain service validations for relation uniqueness + target existence
src/main/java/com/decathlon/idp_core/domain/service/entity_template/PropertyDefinitionValidationService.java Adds property name uniqueness + property type immutability validation
src/main/java/com/decathlon/idp_core/domain/service/entity_template/EntityTemplateValidationService.java Orchestrates new property/relation validations on create/update
src/main/java/com/decathlon/idp_core/domain/service/entity_template/EntityTemplateService.java Updates update-flow to pass existing template into validation
src/main/java/com/decathlon/idp_core/domain/port/EntityRepositoryPort.java Extends entity persistence port with existsByTemplateIdentifier
src/main/java/com/decathlon/idp_core/domain/exception/entity_template/UnsafeTypeConversionException.java Introduces domain exception for blocked property type changes
src/main/java/com/decathlon/idp_core/domain/exception/entity_template/TargetTemplateNotFoundException.java Introduces domain exception for missing relation targets
src/main/java/com/decathlon/idp_core/domain/exception/entity_template/RelationNameAlreadyExistsException.java Introduces domain exception for duplicate relation names
src/main/java/com/decathlon/idp_core/domain/exception/entity_template/PropertyNameAlreadyExistsException.java Introduces domain exception for duplicate property names
src/main/java/com/decathlon/idp_core/domain/constant/ValidationMessages.java Adds new validation message constants for the new rule violations

Copy link
Copy Markdown
Collaborator

@brandPittCode brandPittCode left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add flywway sctipt for indexes

-- Optimize property deletion by template identifier and property name
CREATE INDEX idx_entity_template_identifier
ON entity (template_identifier);

CREATE INDEX idx_property_name
ON property (name);

@sonarqubecloud
Copy link
Copy Markdown

@evebrnd evebrnd merged commit c1e1728 into main May 12, 2026
32 of 34 checks passed
@evebrnd evebrnd deleted the feat/add-guardrails-on-update-template-endpoint branch May 12, 2026 15:06
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