Skip to content

Commit 105c5d1

Browse files
committed
add alias in spreadsheet config entity
Signed-off-by: David BRAQUART <[email protected]>
1 parent 85e1bd2 commit 105c5d1

File tree

9 files changed

+78
-38
lines changed

9 files changed

+78
-38
lines changed

src/main/java/org/gridsuite/studyconfig/server/dto/SpreadsheetConfigInfos.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,8 @@ public record SpreadsheetConfigInfos(
3333
List<ColumnInfos> columns,
3434

3535
@Schema(description = "Global filters")
36-
List<GlobalFilterInfos> globalFilters
36+
List<GlobalFilterInfos> globalFilters,
37+
38+
@Schema(description = "List of node aliases")
39+
List<String> nodeAliases
3740
) { }

src/main/java/org/gridsuite/studyconfig/server/entities/SpreadsheetConfigEntity.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,7 @@ public class SpreadsheetConfigEntity {
4949
@Builder.Default
5050
private List<GlobalFilterEntity> globalFilters = new ArrayList<>();
5151

52+
@ElementCollection(fetch = FetchType.EAGER)
53+
@CollectionTable(name = "config_node_aliases", foreignKey = @ForeignKey(name = "fk_spreadsheet_config_node_aliases"))
54+
private List<String> nodeAliases;
5255
}

src/main/java/org/gridsuite/studyconfig/server/mapper/SpreadsheetConfigMapper.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
import org.gridsuite.studyconfig.server.entities.GlobalFilterEntity;
1515
import org.gridsuite.studyconfig.server.entities.SpreadsheetConfigEntity;
1616

17+
import java.util.ArrayList;
18+
1719
/**
1820
* @author Achour BERRAHMA <achour.berrahma at rte-france.com>
1921
*/
@@ -32,7 +34,8 @@ public static SpreadsheetConfigInfos toDto(SpreadsheetConfigEntity entity) {
3234
.toList(),
3335
entity.getGlobalFilters().stream()
3436
.map(SpreadsheetConfigMapper::toGlobalFilterDto)
35-
.toList()
37+
.toList(),
38+
entity.getNodeAliases()
3639
);
3740
}
3841

@@ -45,7 +48,9 @@ public static SpreadsheetConfigEntity toEntity(SpreadsheetConfigInfos dto) {
4548
.name(dto.name())
4649
.sheetType(dto.sheetType())
4750
.build();
48-
51+
if (dto.nodeAliases() != null) {
52+
entity.setNodeAliases(new ArrayList<>(dto.nodeAliases()));
53+
}
4954
if (dto.columns() != null) {
5055
entity.setColumns(dto.columns().stream()
5156
.map(SpreadsheetConfigMapper::toColumnEntity)

src/main/java/org/gridsuite/studyconfig/server/service/SpreadsheetConfigService.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ private SpreadsheetConfigEntity duplicateSpreadsheetConfigEntity(UUID id) {
6363
.name(entity.getName())
6464
.sheetType(entity.getSheetType())
6565
.build();
66+
if (entity.getNodeAliases() != null) {
67+
duplicate.setNodeAliases(new ArrayList<>(entity.getNodeAliases()));
68+
}
6669
List<ColumnEntity> columns = entity.getColumns().stream()
6770
.map(column -> ColumnEntity.builder()
6871
.name(column.getName())
@@ -123,6 +126,9 @@ public void updateSpreadsheetConfig(UUID id, SpreadsheetConfigInfos dto) {
123126

124127
entity.setSheetType(dto.sheetType());
125128
entity.setName(dto.name());
129+
if (dto.nodeAliases() != null) {
130+
entity.setNodeAliases(new ArrayList<>(dto.nodeAliases()));
131+
}
126132
entity.getColumns().clear();
127133
if (dto.columns() != null) {
128134
entity.getColumns().addAll(dto.columns().stream()
@@ -176,6 +182,8 @@ public UUID createSpreadsheetConfigCollectionFromConfigs(List<UUID> configUuids)
176182
return clone;
177183
})
178184
.toList());
185+
List<String> allConfigsUniqueAliases = entity.getSpreadsheetConfigs().stream().map(SpreadsheetConfigEntity::getNodeAliases).flatMap(Collection::stream).collect(Collectors.toSet()).stream().toList();
186+
entity.setNodeAliases(new ArrayList<>(allConfigsUniqueAliases));
179187
return spreadsheetConfigCollectionRepository.save(entity).getId();
180188
}
181189

@@ -265,6 +273,9 @@ public UUID duplicateSpreadsheetConfigCollection(UUID id) {
265273
.name(config.getName())
266274
.sheetType(config.getSheetType())
267275
.build();
276+
if (config.getNodeAliases() != null) {
277+
configDuplicate.setNodeAliases(new ArrayList<>(config.getNodeAliases()));
278+
}
268279
configDuplicate.setColumns(config.getColumns().stream()
269280
.map(column -> ColumnEntity.builder()
270281
.name(column.getName())
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.1" encoding="UTF-8" standalone="no"?>
2+
<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">
3+
<changeSet author="braquartdav (generated)" id="1750350281212-6">
4+
<createTable tableName="config_node_aliases">
5+
<column name="spreadsheet_config_entity_id" type="UUID">
6+
<constraints nullable="false"/>
7+
</column>
8+
<column name="node_aliases" type="VARCHAR(255)"/>
9+
</createTable>
10+
</changeSet>
11+
<changeSet author="braquartdav (generated)" id="1750350281212-7">
12+
<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"/>
13+
</changeSet>
14+
</databaseChangeLog>

src/main/resources/db/changelog/db.changelog-master.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,6 @@ databaseChangeLog:
5959
- include:
6060
file: changesets/changelog_20250616T090000Z.xml
6161
relativeToChangelogFile: true
62+
- include:
63+
file: changesets/changelog_20250619T162423Z.xml
64+
relativeToChangelogFile: true

src/test/java/org/gridsuite/studyconfig/server/DtoConverterTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,8 @@ void testConversionToEntityOfSpreadsheetConfig() {
109109
),
110110
List.of(
111111
GlobalFilterInfos.builder().uuid(filterId).filterType("country").label("GlobalFilter1").recent(false).build()
112-
)
112+
),
113+
List.of()
113114
);
114115

115116
SpreadsheetConfigEntity entity = SpreadsheetConfigMapper.toEntity(dto);

src/test/java/org/gridsuite/studyconfig/server/SpreadsheetConfigCollectionIntegrationTest.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ void testAddSpreadsheetConfigToCollection() throws Exception {
267267
List<ColumnInfos> columnInfos = List.of(
268268
new ColumnInfos(null, "new_col", ColumnType.NUMBER, 1, "formula", "[\"dep\"]", "idNew", null, null, null, null, true)
269269
);
270-
SpreadsheetConfigInfos newConfig = new SpreadsheetConfigInfos(null, "NewSheet", SheetType.BATTERY, columnInfos, null);
270+
SpreadsheetConfigInfos newConfig = new SpreadsheetConfigInfos(null, "NewSheet", SheetType.BATTERY, columnInfos, null, List.of());
271271

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

310310
String newConfigJson = mapper.writeValueAsString(newConfig);
311311
mockMvc.perform(post(URI_SPREADSHEET_CONFIG_COLLECTION_BASE + "/" + nonExistentUuid + "/spreadsheet-configs")
@@ -407,8 +407,8 @@ private List<SpreadsheetConfigInfos> createSpreadsheetConfigs() {
407407
);
408408

409409
return List.of(
410-
new SpreadsheetConfigInfos(null, "TestSheet", SheetType.GENERATOR, columnInfos, null),
411-
new SpreadsheetConfigInfos(null, "TestSheet1", SheetType.GENERATOR, columnInfos, null)
410+
new SpreadsheetConfigInfos(null, "TestSheet", SheetType.GENERATOR, columnInfos, null, List.of()),
411+
new SpreadsheetConfigInfos(null, "TestSheet1", SheetType.GENERATOR, columnInfos, null, List.of())
412412
);
413413
}
414414

@@ -443,8 +443,8 @@ private List<SpreadsheetConfigInfos> createSpreadsheetConfigsWithFilters() {
443443
);
444444

445445
return List.of(
446-
new SpreadsheetConfigInfos(null, "TestSheet", SheetType.GENERATOR, columnsConfig1, globalFiltersConfig1),
447-
new SpreadsheetConfigInfos(null, "TestSheet2", SheetType.LOAD, columnsConfig2, globalFiltersConfig2)
446+
new SpreadsheetConfigInfos(null, "TestSheet", SheetType.GENERATOR, columnsConfig1, globalFiltersConfig1, List.of()),
447+
new SpreadsheetConfigInfos(null, "TestSheet2", SheetType.LOAD, columnsConfig2, globalFiltersConfig2, List.of())
448448
);
449449
}
450450

@@ -457,9 +457,9 @@ private List<SpreadsheetConfigInfos> createUpdatedSpreadsheetConfigs() {
457457
);
458458

459459
return List.of(
460-
new SpreadsheetConfigInfos(null, "Generator", SheetType.GENERATOR, columnInfos, null),
461-
new SpreadsheetConfigInfos(null, "TestSheet", SheetType.GENERATOR, columnInfos, null),
462-
new SpreadsheetConfigInfos(null, "TestSheet (1)", SheetType.BATTERY, columnInfos, null)
460+
new SpreadsheetConfigInfos(null, "Generator", SheetType.GENERATOR, columnInfos, null, List.of()),
461+
new SpreadsheetConfigInfos(null, "TestSheet", SheetType.GENERATOR, columnInfos, null, List.of()),
462+
new SpreadsheetConfigInfos(null, "TestSheet (1)", SheetType.BATTERY, columnInfos, null, List.of())
463463
);
464464
}
465465

@@ -500,9 +500,9 @@ private List<SpreadsheetConfigInfos> createUpdatedSpreadsheetConfigsWithFilters(
500500
);
501501

502502
return List.of(
503-
new SpreadsheetConfigInfos(null, "Updated1", SheetType.BATTERY, columnsConfig1, globalFiltersConfig1),
504-
new SpreadsheetConfigInfos(null, "Updated2", SheetType.LINE, columnsConfig2, globalFiltersConfig2),
505-
new SpreadsheetConfigInfos(null, "Added3", SheetType.BUS, columnsConfig3, globalFiltersConfig3)
503+
new SpreadsheetConfigInfos(null, "Updated1", SheetType.BATTERY, columnsConfig1, globalFiltersConfig1, List.of()),
504+
new SpreadsheetConfigInfos(null, "Updated2", SheetType.LINE, columnsConfig2, globalFiltersConfig2, List.of()),
505+
new SpreadsheetConfigInfos(null, "Added3", SheetType.BUS, columnsConfig3, globalFiltersConfig3, List.of())
506506
);
507507
}
508508

0 commit comments

Comments
 (0)