Skip to content

Commit 497666b

Browse files
committed
Refactor column visibility handling to use primitive boolean type
Signed-off-by: achour94 <[email protected]>
1 parent 524a531 commit 497666b

File tree

6 files changed

+16
-22
lines changed

6 files changed

+16
-22
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,5 +54,5 @@ public record ColumnInfos(
5454
Double filterTolerance,
5555

5656
@Schema(description = "Column visibility", defaultValue = "true")
57-
Boolean visible
57+
boolean visible
5858
) { }

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,5 +63,5 @@ public class ColumnEntity {
6363

6464
@Column(name = "visible", nullable = false)
6565
@Builder.Default
66-
private Boolean visible = true;
66+
private boolean visible = true;
6767
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public static ColumnInfos toColumnDto(ColumnEntity entity) {
7474
entity.getFilterType(),
7575
entity.getFilterValue(),
7676
entity.getFilterTolerance(),
77-
entity.getVisible()
77+
entity.isVisible()
7878
);
7979
}
8080

@@ -90,7 +90,7 @@ public static ColumnEntity toColumnEntity(ColumnInfos dto) {
9090
.filterType(dto.filterType())
9191
.filterValue(dto.filterValue())
9292
.filterTolerance(dto.filterTolerance())
93-
.visible(dto.visible() != null ? dto.visible() : true)
93+
.visible(dto.visible())
9494
.build();
9595
}
9696

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

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ public void updateColumn(UUID id, UUID columnId, ColumnInfos dto) {
333333
columnEntity.setFilterType(dto.filterType());
334334
columnEntity.setFilterValue(dto.filterValue());
335335
columnEntity.setFilterTolerance(dto.filterTolerance());
336-
columnEntity.setVisible(dto.visible() != null ? dto.visible() : true);
336+
columnEntity.setVisible(dto.visible());
337337

338338
spreadsheetConfigRepository.save(entity);
339339
}
@@ -381,11 +381,13 @@ public void updateColumnStates(UUID id, List<ColumnStateUpdateInfos> columnState
381381
}
382382

383383
// Reorder columns based on the provided states
384-
List<UUID> orderedColumnIds = columnStates.stream()
385-
.sorted(Comparator.comparingInt(ColumnStateUpdateInfos::order))
386-
.map(ColumnStateUpdateInfos::columnId)
387-
.toList();
388-
reorderColumns(orderedColumnIds, columns);
384+
columns.sort(Comparator.comparing(column ->
385+
columnStates.stream()
386+
.filter(state -> state.columnId().equals(column.getUuid()))
387+
.findFirst()
388+
.map(ColumnStateUpdateInfos::order)
389+
.orElse(Integer.MAX_VALUE)
390+
));
389391
}
390392

391393
private SpreadsheetConfigCollectionInfos readDefaultSpreadsheetConfigCollection() throws IOException {

src/main/resources/db/changelog/changesets/changelog_20250606T123216Z.xml

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,9 @@
22
<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">
33
<changeSet author="berrahmaach (generated)" id="1749213150568-4">
44
<addColumn tableName="spreadsheet_column">
5-
<column name="visible" type="boolean" defaultValueBoolean="true">
5+
<column name="visible" type="boolean" defaultValueBoolean="true" valueBoolean="true">
66
<constraints nullable="false"/>
77
</column>
88
</addColumn>
99
</changeSet>
10-
11-
<!-- Set default value for existing rows -->
12-
<changeSet author="berrahmaach" id="1749213150568-5">
13-
<update tableName="spreadsheet_column">
14-
<column name="visible" valueBoolean="true"/>
15-
<where>visible IS NULL</where>
16-
</update>
17-
</changeSet>
1810
</databaseChangeLog>

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ void testConversionToEntityOfSpreadsheetConfig() {
133133
assertThat(e.getColumns().get(0).getFilterType()).isEqualTo("greaterThan");
134134
assertThat(e.getColumns().get(0).getFilterValue()).isEqualTo("100");
135135
assertThat(e.getColumns().get(0).getFilterTolerance()).isEqualTo(0.5);
136-
assertThat(e.getColumns().get(0).getVisible()).isTrue();
136+
assertThat(e.getColumns().get(0).isVisible()).isTrue();
137137

138138
assertThat(e.getColumns().get(1).getName()).isEqualTo("Column2");
139139
assertThat(e.getColumns().get(1).getFormula()).isEqualTo("Z*W");
@@ -143,7 +143,7 @@ void testConversionToEntityOfSpreadsheetConfig() {
143143
assertThat(e.getColumns().get(1).getFilterType()).isNull();
144144
assertThat(e.getColumns().get(1).getFilterValue()).isNull();
145145
assertThat(e.getColumns().get(1).getFilterTolerance()).isNull();
146-
assertThat(e.getColumns().get(1).getVisible()).isTrue();
146+
assertThat(e.getColumns().get(1).isVisible()).isTrue();
147147

148148
// Global filter assertions
149149
assertThat(e.getGlobalFilters()).hasSize(1);
@@ -212,7 +212,7 @@ void testConversionToEntityOfColumnWithFilter() {
212212
assertThat(e.getFilterType()).isEqualTo("lessThan");
213213
assertThat(e.getFilterValue()).isEqualTo("50.5");
214214
assertThat(e.getFilterTolerance()).isEqualTo(0.1);
215-
assertThat(e.getVisible()).isTrue();
215+
assertThat(e.isVisible()).isTrue();
216216
});
217217
}
218218

0 commit comments

Comments
 (0)