feat(api)!: update entity output for having relations grouped#90
feat(api)!: update entity output for having relations grouped#90brandPittCode wants to merge 17 commits into
Conversation
Code Coverage OverviewLanguages: Java Java / code-coverage/jacocoThe overall coverage in the branch remains at 89%, unchanged from the branch. Show a code coverage summary of the most impacted files.
Updated |
There was a problem hiding this comment.
Pull request overview
This PR updates the Entities API response contract to provide a unified relations structure that combines outbound and inbound relations, and enriches related entity summaries with template_identifier so clients can identify related entity types without additional lookups.
Changes:
- Reworked entity output DTOs (
EntityDtoOut,EntitySummaryDto) to support unified relations and includetemplate_identifierin relation summaries. - Updated relation-summary persistence query and mapping to provide inbound relation source template identifiers.
- Updated OpenAPI (
swagger.yaml) and integration-test JSON fixtures to reflect the new response schema (including removal ofrelations_as_targetfrom responses).
Reviewed changes
Copilot reviewed 14 out of 16 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/main/java/com/decathlon/idp_core/infrastructure/adapters/api/mapper/entity/EntityDtoOutMapper.java | Builds unified relations map and injects template identifiers into relation summaries |
| src/main/java/com/decathlon/idp_core/infrastructure/adapters/api/dto/out/entity/EntityDtoOut.java | Refactors entity response DTO to a unified relations-only shape |
| src/main/java/com/decathlon/idp_core/infrastructure/adapters/api/dto/out/entity/EntitySummaryDto.java | Adds templateIdentifier to related entity summaries and converts to record |
| src/main/java/com/decathlon/idp_core/infrastructure/adapters/persistence/repository/JpaRelationRepository.java | Extends native query projection to include source template identifier for inbound relation summaries |
| src/main/java/com/decathlon/idp_core/domain/model/entity/RelationAsTargetSummary.java | Extends domain summary model to carry sourceTemplateIdentifier |
| docs/src/static/swagger.yaml | Updates OpenAPI schemas to remove relations_as_target from responses and add template_identifier to entity summaries |
| src/test/resources/integration_test/json/entity/v1/searchEntities_200_startsWith.json | Updates expected entity search response fixture for unified relations + template identifiers |
| src/test/resources/integration_test/json/entity/v1/searchEntities_200_orTemplates.json | Updates expected entity search response fixture for unified relations + template identifiers |
| src/test/resources/integration_test/json/entity/v1/searchEntities_200_neq.json | Updates expected entity search response fixture for unified relations |
| src/test/resources/integration_test/json/entity/v1/searchEntities_200_byTemplateAndProperty.json | Updates expected entity search response fixture for unified relations + template identifiers |
| src/test/resources/integration_test/json/entity/v1/searchEntities_200_byRelationsAsTargetPresence.json | Updates expected entity search response fixture reflecting inbound relations now in relations |
| src/test/resources/integration_test/json/entity/v1/searchEntities_200_byRelationsAsTarget.json | Updates expected entity search response fixture reflecting inbound relations now in relations |
| src/test/resources/integration_test/json/entity/v1/searchEntities_200_byRelationNameEq.json | Updates expected entity search response fixture for unified relations + template identifiers |
| src/test/resources/integration_test/json/entity/v1/searchEntities_200_byRelationNameContains.json | Updates expected entity search response fixture for unified relations + template identifiers |
| src/test/resources/integration_test/json/entity/v1/getEntities_200_relationsAsTargetIdentifier.json | Updates expected get-entities response fixture reflecting inbound relations now in relations |
| src/test/resources/integration_test/json/entity/v1/getEntities_200_identifierEquals.json | Updates expected get-entities response fixture for unified relations + template identifiers |
evebrnd
left a comment
There was a problem hiding this comment.
There are many mentions of relations_as_target in tests and the documentation that should be cleaned / updated.
PR title is missing a '!' to declare the breaking change
| private Map<String, List<EntitySummaryDto>> buildUnifiedRelationsMap(Entity entity, | ||
| Map<String, EntitySummaryDto> relatedEntitiesSummaries, | ||
| Map<String, List<RelationAsTargetSummary>> relationTargetOwnershipsMap) { | ||
| List<RelationAsTargetSummary> relationAsTargetSummaries = relationTargetOwnershipsMap |
There was a problem hiding this comment.
RelationAsTargetSummaryDtoOut class can be deleted as well
| /// - Template-aware relation summaries for unified API responses | ||
| public record RelationAsTargetSummary(String targetEntityIdentifier, String relationName, | ||
| String sourceEntityIdentifier, String sourceEntityName) { | ||
| String sourceEntityIdentifier, String sourceEntityName, String sourceTemplateIdentifier) { |
There was a problem hiding this comment.
Considering sourceTemplateIdentifier is never used by the domain, isn't more an infra concern ? And should only be for dto and api responses
There was a problem hiding this comment.
Actually at the end RelationAsTargetSummary object is the metadata for an entity. (identifier, name, template identifier) so it is stil a domain concern. I'l will check for maybe change the name. Or manage this in another way.
There was a problem hiding this comment.
This is still used by the mapper for the search. I propose to treat the mapper update for the search in another pr.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 25 out of 28 changed files in this pull request and generated 10 comments.
Comments suppressed due to low confidence (1)
docs/src/concepts/entities.md:247
- The response example under "Relations in Responses" is now missing
template_identifierin relation summaries, which the PR introduces as part of the unified relations API. This makes the docs inconsistent with the updated contract.
In API responses, relations are grouped by name and include summary information about each target entity:
```json
{
"relations": {
| // Load entity graphs in batch | ||
| Map<UUID, Entity> entityGraphs = entityGraphRepositoryPort.findEntityGraph(entityUuids, 1, true, | ||
| EntityGraphTraversalMode.DIRECT_LINEAGE); | ||
|
|
||
| private static record GraphTraversalContext(Map<UUID, Entity> entityMap, | ||
| Map<EntityCompositeKey, UUID> textToUuidLookup, | ||
| Map<String, Map<String, List<UUID>>> inboundIndex, boolean includeProperties, | ||
| Set<String> propertyFilter, Set<String> relationFilter, Set<String> activeStack, | ||
| Map<String, EntityGraphNode> memoCache, // High-speed in-memory reuse cache | ||
| EntityGraphTraversalMode mode) { | ||
| } | ||
| // Call the helper to build graph nodes | ||
| Map<UUID, EntityGraphNode> graphsByUuid = entityGraphHelper.buildGraphNodesForEntityIds( | ||
| entityGraphs, true, Set.of(), Set.of(), EntityGraphTraversalMode.DIRECT_LINEAGE, 1); |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> Signed-off-by: Andrés Brand <andresbrand@gmail.com>
Unify graph retrieving methods
Unify graph retrieving methods
Unify graph retrieving methods
Unify graph retrieving methods
Unify graph retrieving methods Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> Signed-off-by: Andrés Brand <andresbrand@gmail.com>
Unify graph retrieving methods Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> Signed-off-by: Andrés Brand <andresbrand@gmail.com>
Unify graph retrieving methods
Unify graph retrieving methods
b57855e to
179d70b
Compare
|



PR Description
What this PR Provides
This pull request introduces a unified relations API for entities, combining both outbound and inbound relations into a single
relationsfield in the API response. It also enriches relation summaries with template identifiers, allowing clients to distinguish entity types without extra queries. The changes affect the domain model, persistence, API mapping logic, and integration tests.API & Data Model Improvements:
The
relationsfield in API responses now contains both outbound and inbound relations, with each related entity summary including atemplate_identifier. The previousrelations_as_targetfield is removed from responses.The
RelationAsTargetSummarymodel now includes asourceTemplateIdentifierfield, and the corresponding database query and mapping logic are updated to populate this field.Backend Logic Refactoring:
EntityDtoOutMapper) is refactored to build a unified relations map, merging outbound and inbound relations under the same key and including template identifiers in related entity summaries. Obsolete mapping methods are removedTest and Documentation Updates:
These changes provide a more consistent and informative API for consumers, simplify relation handling, and enhance frontend capabilities.
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
Breaking changes (if any)
API JSON schema modification (existing resource / behavior)
N/A
Context of the Breaking Change
The EntityDtoOut contract has change.
Result of the Breaking Change
The relation_as_target fiel have been removed.
The relations (inbound and outbound) are now grouped in the relations section.
The relation summary have now the template identifer information