Skip to content

Commit 73af9a2

Browse files
authored
Fix: ensure name field is truncated to 255 characters before DB insert/update (#67)
Signed-off-by: Ayoub LABIDI <[email protected]>
1 parent aabb0a2 commit 73af9a2

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/main/java/org/gridsuite/studyconfig/server/entities/diagramgridlayout/diagramlayout/NetworkAreaDiagramLayoutEntity.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@
2121
@Getter
2222
@PrimaryKeyJoinColumn(foreignKey = @ForeignKey(name = "fk_network_area_diagram_layout_abstract"))
2323
public class NetworkAreaDiagramLayoutEntity extends AbstractDiagramLayoutEntity {
24+
// Maximum length for the name field
25+
private static final int MAX_NAME_LENGTH = 255;
26+
2427
@Column(name = "original_nad_config_uuid")
2528
UUID originalNadConfigUuid;
2629

@@ -32,4 +35,17 @@ public class NetworkAreaDiagramLayoutEntity extends AbstractDiagramLayoutEntity
3235

3336
@Column(name = "name")
3437
String name;
38+
39+
/**
40+
* Ensures that the name does not exceed the maximum length.
41+
* This method is called before persisting or updating the entity.
42+
*/
43+
@PrePersist
44+
@PreUpdate
45+
private void truncateName() {
46+
if (name != null && name.length() > MAX_NAME_LENGTH) {
47+
name = name.substring(0, MAX_NAME_LENGTH);
48+
}
49+
}
50+
3551
}

0 commit comments

Comments
 (0)