Skip to content

feat(api): update entity output for having relations grouped#90

Open
brandPittCode wants to merge 10 commits into
mainfrom
feat/update-entity-output-for-having-relations-grouped
Open

feat(api): update entity output for having relations grouped#90
brandPittCode wants to merge 10 commits into
mainfrom
feat/update-entity-output-for-having-relations-grouped

Conversation

@brandPittCode

@brandPittCode brandPittCode commented Jul 8, 2026

Copy link
Copy Markdown
Collaborator

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 relations field 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 relations field in API responses now contains both outbound and inbound relations, with each related entity summary including a template_identifier. The previous relations_as_target field is removed from responses.

  • The RelationAsTargetSummary model now includes a sourceTemplateIdentifier field, and the corresponding database query and mapping logic are updated to populate this field.

Backend Logic Refactoring:

  • The API mapping layer (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 removed

Test and Documentation Updates:

  • Integration test fixtures are updated to reflect the new unified relations structure and the inclusion of template identifiers.

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:

  • 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: Have an initial test set with entities that have outboud and inbound relations.
  • What and how to test: Make call to the /entities/template_identifier, /entities/template_identifier/entity_identifier and /entities/search endpoints.
  • Expected results: When calling any of the enpoints that output entities information in a EntityDtout contract, the relations (inbound and outbound) should be now grouped in the relations section. The relations_as_target field shoud not exists.

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

@github-code-quality

github-code-quality Bot commented Jul 8, 2026

Copy link
Copy Markdown

Code Coverage Overview

Languages: Java

Java / code-coverage/jacoco

The overall coverage in the branch remains at 90%, unchanged from the branch.

Show a code coverage summary of the most impacted files.
File 5339ad0 a8f6881 +/-
com/decathlon/i...oOutMapper.java 87% 87% 0%
com/decathlon/i...maryDtoOut.java 0% 0% 0%
com/decathlon/i...tityDtoOut.java 0% 100% +100%
com/decathlon/i...SummaryDto.java 0% 100% +100%

Updated July 09, 2026 16:01 UTC
Code Coverage is in Public Preview. Learn more and provide us with your feedback.

@brandPittCode brandPittCode changed the title Feat(entity): update entity output for having relations grouped feat(entity): update entity output for having relations grouped Jul 8, 2026
@brandPittCode brandPittCode changed the title feat(entity): update entity output for having relations grouped feat(api): update entity output for having relations grouped Jul 8, 2026
@brandPittCode brandPittCode requested a review from Copilot July 8, 2026 12:28

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 include template_identifier in 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 of relations_as_target from 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

brandPittCode and others added 2 commits July 8, 2026 14:47
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Signed-off-by: Andrés Brand <andresbrand@gmail.com>

@evebrnd evebrnd left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

RelationAsTargetSummaryDtoOut class can be deleted as well

Map<String, List<RelationAsTargetSummary>> relationTargetOwnershipsMap) {
List<RelationAsTargetSummary> relationAsTargetSummaries = relationTargetOwnershipsMap

java.util.HashMap<String, List<EntitySummaryDto>> unifiedRelations = new java.util.HashMap<>();

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Maybe use HashMap directly and add import at the top

/// - 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) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Considering sourceTemplateIdentifier is never used by the domain, isn't more an infra concern ? And should only be for dto and api responses

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

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.

@sonarqubecloud

sonarqubecloud Bot commented Jul 9, 2026

Copy link
Copy Markdown

/// @param mode traversal direction (OUTBOUND_ONLY, BIDIRECTIONAL, etc.)
/// @return map of entity identifier to its fully resolved EntityGraphNode
@SuppressWarnings("null")
public Map<UUID, EntityGraphNode> buildGraphNodesForEntityIds(Map<UUID, Entity> entityGraphs, int depth,
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