Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,8 @@ public record SpreadsheetConfigInfos(
List<ColumnInfos> columns,

@Schema(description = "Global filters")
List<GlobalFilterInfos> globalFilters
List<GlobalFilterInfos> globalFilters,

@Schema(description = "List of node aliases")
List<String> nodeAliases
) { }
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,7 @@ public class SpreadsheetConfigEntity {
@Builder.Default
private List<GlobalFilterEntity> globalFilters = new ArrayList<>();

@ElementCollection(fetch = FetchType.EAGER)
@CollectionTable(name = "config_node_aliases", foreignKey = @ForeignKey(name = "fk_spreadsheet_config_node_aliases"))
private List<String> nodeAliases;
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
import org.gridsuite.studyconfig.server.entities.GlobalFilterEntity;
import org.gridsuite.studyconfig.server.entities.SpreadsheetConfigEntity;

import java.util.ArrayList;

/**
* @author Achour BERRAHMA <achour.berrahma at rte-france.com>
*/
Expand All @@ -32,7 +34,8 @@ public static SpreadsheetConfigInfos toDto(SpreadsheetConfigEntity entity) {
.toList(),
entity.getGlobalFilters().stream()
.map(SpreadsheetConfigMapper::toGlobalFilterDto)
.toList()
.toList(),
entity.getNodeAliases()
);
}

Expand All @@ -45,7 +48,9 @@ public static SpreadsheetConfigEntity toEntity(SpreadsheetConfigInfos dto) {
.name(dto.name())
.sheetType(dto.sheetType())
.build();

if (dto.nodeAliases() != null) {
entity.setNodeAliases(new ArrayList<>(dto.nodeAliases()));
}
if (dto.columns() != null) {
entity.setColumns(dto.columns().stream()
.map(SpreadsheetConfigMapper::toColumnEntity)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ private SpreadsheetConfigEntity duplicateSpreadsheetConfigEntity(UUID id) {
.name(entity.getName())
.sheetType(entity.getSheetType())
.build();
if (entity.getNodeAliases() != null) {
duplicate.setNodeAliases(new ArrayList<>(entity.getNodeAliases()));
}
List<ColumnEntity> columns = entity.getColumns().stream()
.map(column -> ColumnEntity.builder()
.name(column.getName())
Expand Down Expand Up @@ -123,6 +126,9 @@ public void updateSpreadsheetConfig(UUID id, SpreadsheetConfigInfos dto) {

entity.setSheetType(dto.sheetType());
entity.setName(dto.name());
if (dto.nodeAliases() != null) {
entity.setNodeAliases(new ArrayList<>(dto.nodeAliases()));
}
entity.getColumns().clear();
if (dto.columns() != null) {
entity.getColumns().addAll(dto.columns().stream()
Expand Down Expand Up @@ -176,6 +182,8 @@ public UUID createSpreadsheetConfigCollectionFromConfigs(List<UUID> configUuids)
return clone;
})
.toList());
List<String> allConfigsUniqueAliases = entity.getSpreadsheetConfigs().stream().map(SpreadsheetConfigEntity::getNodeAliases).flatMap(Collection::stream).collect(Collectors.toSet()).stream().toList();
entity.setNodeAliases(new ArrayList<>(allConfigsUniqueAliases));
return spreadsheetConfigCollectionRepository.save(entity).getId();
}

Expand Down Expand Up @@ -265,6 +273,9 @@ public UUID duplicateSpreadsheetConfigCollection(UUID id) {
.name(config.getName())
.sheetType(config.getSheetType())
.build();
if (config.getNodeAliases() != null) {
configDuplicate.setNodeAliases(new ArrayList<>(config.getNodeAliases()));
}
configDuplicate.setColumns(config.getColumns().stream()
.map(column -> ColumnEntity.builder()
.name(column.getName())
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.1" encoding="UTF-8" standalone="no"?>
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog" xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext" xmlns:pro="http://www.liquibase.org/xml/ns/pro" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd http://www.liquibase.org/xml/ns/pro http://www.liquibase.org/xml/ns/pro/liquibase-pro-latest.xsd http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-latest.xsd">
<changeSet author="braquartdav (generated)" id="1750350281212-6">
<createTable tableName="config_node_aliases">
<column name="spreadsheet_config_entity_id" type="UUID">
<constraints nullable="false"/>
</column>
<column name="node_aliases" type="VARCHAR(255)"/>
</createTable>
</changeSet>
<changeSet author="braquartdav (generated)" id="1750350281212-7">
<addForeignKeyConstraint baseColumnNames="spreadsheet_config_entity_id" baseTableName="config_node_aliases" constraintName="fk_spreadsheet_config_node_aliases" deferrable="false" initiallyDeferred="false" referencedColumnNames="id" referencedTableName="spreadsheet_config" validate="true"/>
</changeSet>
</databaseChangeLog>
3 changes: 3 additions & 0 deletions src/main/resources/db/changelog/db.changelog-master.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,6 @@ databaseChangeLog:
- include:
file: changesets/changelog_20250616T090000Z.xml
relativeToChangelogFile: true
- include:
file: changesets/changelog_20250619T162423Z.xml
relativeToChangelogFile: true
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@ void testConversionToEntityOfSpreadsheetConfig() {
),
List.of(
GlobalFilterInfos.builder().uuid(filterId).filterType("country").label("GlobalFilter1").recent(false).build()
)
),
List.of()
);

SpreadsheetConfigEntity entity = SpreadsheetConfigMapper.toEntity(dto);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.springframework.test.web.servlet.MvcResult;

import java.util.*;
import java.util.stream.Collectors;

import static org.assertj.core.api.Assertions.assertThat;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
Expand Down Expand Up @@ -233,18 +234,31 @@ void testDuplicateCollection() throws Exception {

@Test
void testMergeModelsIntoNewCollection() throws Exception {
// create a first collection with 2 configs
SpreadsheetConfigCollectionInfos collectionToCreate = new SpreadsheetConfigCollectionInfos(null, createSpreadsheetConfigs(), null);
UUID collectionUuid = postSpreadsheetConfigCollection(collectionToCreate);
List<UUID> configIds = getSpreadsheetConfigCollection(collectionUuid).spreadsheetConfigs().stream().map(SpreadsheetConfigInfos::id).toList();
assertThat(configIds).hasSize(2);
// create a second collection duplicating + merging these existing Configs
UUID mergedCollectionUuid = postMergeSpreadsheetConfigsIntoCollection(configIds);
List<UUID> duplicatedConfigIds = getSpreadsheetConfigCollection(mergedCollectionUuid).spreadsheetConfigs().stream().map(SpreadsheetConfigInfos::id).toList();
// create a source collection to create N configs
SpreadsheetConfigCollectionInfos sourceCollection = new SpreadsheetConfigCollectionInfos(null, createSpreadsheetConfigsWithAliases(), List.of("sourceAlias"));
UUID collectionUuid = postSpreadsheetConfigCollection(sourceCollection);
List<SpreadsheetConfigInfos> sourceConfigs = getSpreadsheetConfigCollection(collectionUuid).spreadsheetConfigs();
List<UUID> configIds = sourceConfigs.stream().map(SpreadsheetConfigInfos::id).toList();

// create a second collection, duplicating and merging these N source Configs
UUID mergedCollectionUuid = postMergeSpreadsheetConfigsIntoCollection(configIds);
assertThat(mergedCollectionUuid).isNotEqualTo(collectionUuid);

SpreadsheetConfigCollectionInfos mergedCollection = getSpreadsheetConfigCollection(mergedCollectionUuid);
List<UUID> duplicatedConfigIds = mergedCollection.spreadsheetConfigs().stream().map(SpreadsheetConfigInfos::id).toList();
assertThat(duplicatedConfigIds).hasSameSizeAs(configIds);
assertThat(duplicatedConfigIds.stream().sorted().toList()).isNotEqualTo(configIds.stream().sorted().toList());

// dont compare aliases, merged collection aliases are computed
assertThat(mergedCollection)
.usingRecursiveComparison()
.ignoringFields("id", "nodeAliases", "spreadsheetConfigs.columns.uuid", "spreadsheetConfigs.id")
.ignoringExpectedNullFields()
.isEqualTo(sourceCollection);

// merged aliases must be unique
List<String> expectedUniqueAliases = sourceConfigs.stream().map(SpreadsheetConfigInfos::nodeAliases).flatMap(Collection::stream).collect(Collectors.toSet()).stream().toList();
assertThat(mergedCollection.nodeAliases()).isEqualTo(expectedUniqueAliases);
}

@Test
Expand All @@ -267,7 +281,7 @@ void testAddSpreadsheetConfigToCollection() throws Exception {
List<ColumnInfos> columnInfos = List.of(
new ColumnInfos(null, "new_col", ColumnType.NUMBER, 1, "formula", "[\"dep\"]", "idNew", null, null, null, null, true)
);
SpreadsheetConfigInfos newConfig = new SpreadsheetConfigInfos(null, "NewSheet", SheetType.BATTERY, columnInfos, null);
SpreadsheetConfigInfos newConfig = new SpreadsheetConfigInfos(null, "NewSheet", SheetType.BATTERY, columnInfos, null, List.of());

String newConfigJson = mapper.writeValueAsString(newConfig);
MvcResult mvcResult = mockMvc.perform(post(URI_SPREADSHEET_CONFIG_COLLECTION_BASE + "/" + collectionUuid + "/spreadsheet-configs")
Expand Down Expand Up @@ -305,7 +319,7 @@ void testRemoveSpreadsheetConfigFromCollection() throws Exception {
@Test
void testAddSpreadsheetConfigToNonExistentCollection() throws Exception {
UUID nonExistentUuid = UUID.randomUUID();
SpreadsheetConfigInfos newConfig = new SpreadsheetConfigInfos(null, "TestSheet", SheetType.GENERATOR, List.of(), null);
SpreadsheetConfigInfos newConfig = new SpreadsheetConfigInfos(null, "TestSheet", SheetType.GENERATOR, List.of(), null, List.of());

String newConfigJson = mapper.writeValueAsString(newConfig);
mockMvc.perform(post(URI_SPREADSHEET_CONFIG_COLLECTION_BASE + "/" + nonExistentUuid + "/spreadsheet-configs")
Expand Down Expand Up @@ -400,15 +414,30 @@ void testReplaceAllSpreadsheetConfigs() throws Exception {
.hasSize(sourceConfigIds.size());
}

private List<SpreadsheetConfigInfos> createSpreadsheetConfigsWithAliases() {
List<ColumnInfos> columnInfos = Arrays.asList(
new ColumnInfos(null, "cust_a", ColumnType.NUMBER, 1, "cust_b + cust_c", "[\"cust_b\", \"cust_c\"]", "idA", null, null, null, null, true),
new ColumnInfos(null, "cust_b", ColumnType.TEXT, null, "var_minP + 1", null, "idB", null, null, null, null, true)
);

return List.of(
new SpreadsheetConfigInfos(null, "TestSheet", SheetType.GENERATOR, columnInfos, null, List.of("a1", "a2")),
new SpreadsheetConfigInfos(null, "TestSheet1", SheetType.GENERATOR, columnInfos, null, List.of("a1", "a2", "a3")),
new SpreadsheetConfigInfos(null, "TestSheet2", SheetType.GENERATOR, columnInfos, null, List.of("a2", "a4")),
new SpreadsheetConfigInfos(null, "TestSheet3", SheetType.GENERATOR, columnInfos, null, List.of()),
new SpreadsheetConfigInfos(null, "TestSheet4", SheetType.GENERATOR, columnInfos, null, List.of("alias"))
);
}

private List<SpreadsheetConfigInfos> createSpreadsheetConfigs() {
List<ColumnInfos> columnInfos = Arrays.asList(
new ColumnInfos(null, "cust_a", ColumnType.NUMBER, 1, "cust_b + cust_c", "[\"cust_b\", \"cust_c\"]", "idA", null, null, null, null, true),
new ColumnInfos(null, "cust_b", ColumnType.TEXT, null, "var_minP + 1", null, "idB", null, null, null, null, true)
);

return List.of(
new SpreadsheetConfigInfos(null, "TestSheet", SheetType.GENERATOR, columnInfos, null),
new SpreadsheetConfigInfos(null, "TestSheet1", SheetType.GENERATOR, columnInfos, null)
new SpreadsheetConfigInfos(null, "TestSheet", SheetType.GENERATOR, columnInfos, null, List.of()),
new SpreadsheetConfigInfos(null, "TestSheet1", SheetType.GENERATOR, columnInfos, null, List.of())
);
}

Expand Down Expand Up @@ -443,8 +472,8 @@ private List<SpreadsheetConfigInfos> createSpreadsheetConfigsWithFilters() {
);

return List.of(
new SpreadsheetConfigInfos(null, "TestSheet", SheetType.GENERATOR, columnsConfig1, globalFiltersConfig1),
new SpreadsheetConfigInfos(null, "TestSheet2", SheetType.LOAD, columnsConfig2, globalFiltersConfig2)
new SpreadsheetConfigInfos(null, "TestSheet", SheetType.GENERATOR, columnsConfig1, globalFiltersConfig1, List.of()),
new SpreadsheetConfigInfos(null, "TestSheet2", SheetType.LOAD, columnsConfig2, globalFiltersConfig2, List.of())
);
}

Expand All @@ -457,9 +486,9 @@ private List<SpreadsheetConfigInfos> createUpdatedSpreadsheetConfigs() {
);

return List.of(
new SpreadsheetConfigInfos(null, "Generator", SheetType.GENERATOR, columnInfos, null),
new SpreadsheetConfigInfos(null, "TestSheet", SheetType.GENERATOR, columnInfos, null),
new SpreadsheetConfigInfos(null, "TestSheet (1)", SheetType.BATTERY, columnInfos, null)
new SpreadsheetConfigInfos(null, "Generator", SheetType.GENERATOR, columnInfos, null, List.of()),
new SpreadsheetConfigInfos(null, "TestSheet", SheetType.GENERATOR, columnInfos, null, List.of()),
new SpreadsheetConfigInfos(null, "TestSheet (1)", SheetType.BATTERY, columnInfos, null, List.of())
);
}

Expand Down Expand Up @@ -500,9 +529,9 @@ private List<SpreadsheetConfigInfos> createUpdatedSpreadsheetConfigsWithFilters(
);

return List.of(
new SpreadsheetConfigInfos(null, "Updated1", SheetType.BATTERY, columnsConfig1, globalFiltersConfig1),
new SpreadsheetConfigInfos(null, "Updated2", SheetType.LINE, columnsConfig2, globalFiltersConfig2),
new SpreadsheetConfigInfos(null, "Added3", SheetType.BUS, columnsConfig3, globalFiltersConfig3)
new SpreadsheetConfigInfos(null, "Updated1", SheetType.BATTERY, columnsConfig1, globalFiltersConfig1, List.of()),
new SpreadsheetConfigInfos(null, "Updated2", SheetType.LINE, columnsConfig2, globalFiltersConfig2, List.of()),
new SpreadsheetConfigInfos(null, "Added3", SheetType.BUS, columnsConfig3, globalFiltersConfig3, List.of())
);
}

Expand Down
Loading