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
@@ -0,0 +1,35 @@
/**
* Copyright (c) 2025, RTE (http://www.rte-france.com)
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
package org.gridsuite.studyconfig.server.configuration;

import com.fasterxml.jackson.databind.ObjectMapper;

import org.gridsuite.studyconfig.server.dto.diagramgridlayout.diagramlayout.AbstractDiagramLayout;
import org.gridsuite.studyconfig.server.dto.diagramgridlayout.diagramlayout.AbstractDiagramLayoutJsonMapper;
import org.springframework.context.annotation.Configuration;

import jakarta.annotation.PostConstruct;

/**
* Jackson configuration for diagram layout polymorphic serialization.
* This external configuration avoids circular dependencies between the abstract base class
* and its subtypes by using a mixin approach with type mappings.
*/
@Configuration
public class DiagramLayoutJacksonConfiguration {

private final ObjectMapper objectMapper;

public DiagramLayoutJacksonConfiguration(ObjectMapper objectMapper) {
this.objectMapper = objectMapper;
}

@PostConstruct
public void configureDiagramLayoutMixIn() {
objectMapper.addMixIn(AbstractDiagramLayout.class, AbstractDiagramLayoutJsonMapper.class);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/**
* Copyright (c) 2025, RTE (http://www.rte-france.com)
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
package org.gridsuite.studyconfig.server.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.gridsuite.studyconfig.server.StudyConfigApi;
import org.gridsuite.studyconfig.server.dto.diagramgridlayout.DiagramGridLayout;
import org.gridsuite.studyconfig.server.service.DiagramGridLayoutService;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.UUID;

import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE;

@RestController
@RequestMapping(value = "/" + StudyConfigApi.API_VERSION + "/diagram-grid-layout")
@RequiredArgsConstructor
@Tag(name = "Diagram Grid Layout Config", description = "Diagram Grid Layout Configuration API")
public class DiagramGridLayoutController {
private final DiagramGridLayoutService diagramGridLayoutService;

@PostMapping(consumes = APPLICATION_JSON_VALUE)
@Operation(summary = "Save diagram grid layout")
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "The newly created diagram grid layout UUID returned")})
public ResponseEntity<UUID> saveDiagramGridLayout(@RequestBody DiagramGridLayout diagramGridLayout) {
return ResponseEntity.ok().body(diagramGridLayoutService.saveDiagramGridLayout(diagramGridLayout));
}

@PutMapping(value = "/{id}", consumes = APPLICATION_JSON_VALUE)
@Operation(summary = "Update diagram grid layout")
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "The diagram grid layout has been updated")})
public ResponseEntity<Void> updateDiagramGridLayout(@PathVariable("id") UUID diagramGridLayoutUuid,
@RequestBody DiagramGridLayout diagramGridLayout) {
diagramGridLayoutService.updateDiagramGridLayout(diagramGridLayoutUuid, diagramGridLayout);
return ResponseEntity.ok().build();
}

@GetMapping(value = "/{id}", produces = APPLICATION_JSON_VALUE)
@Operation(summary = "Get diagram grid layout")
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "The diagram grid layout is returned")})
public ResponseEntity<DiagramGridLayout> getDiagramGridLayout(
@PathVariable("id") UUID diagramGridLayoutUuid) {
return ResponseEntity.ok().contentType(MediaType.APPLICATION_JSON).body(diagramGridLayoutService.getByDiagramGridLayoutUuid(diagramGridLayoutUuid));
}

@DeleteMapping(value = "/{id}")
@Operation(summary = "Delete diagram grid layout")
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "The diagram grid layout is deleted")})
public ResponseEntity<DiagramGridLayout> deleteDiagramGridLayout(
@PathVariable("id") UUID diagramGridLayoutUuid) {
diagramGridLayoutService.deleteDiagramGridLayout(diagramGridLayoutUuid);
return ResponseEntity.ok().build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/**
* Copyright (c) 2025, RTE (http://www.rte-france.com)
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
package org.gridsuite.studyconfig.server.dto.diagramgridlayout;

import lombok.*;

import java.util.List;

import org.gridsuite.studyconfig.server.dto.diagramgridlayout.diagramlayout.AbstractDiagramLayout;

@Builder
@AllArgsConstructor
@NoArgsConstructor
@Setter
@Getter
public class DiagramGridLayout {
List<AbstractDiagramLayout> diagramLayouts;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/**
* Copyright (c) 2025, RTE (http://www.rte-france.com)
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
package org.gridsuite.studyconfig.server.dto.diagramgridlayout.diagramlayout;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.experimental.SuperBuilder;

import java.util.Map;
import java.util.UUID;

@SuperBuilder
@AllArgsConstructor
@NoArgsConstructor
@Setter
@Getter
public abstract class AbstractDiagramLayout {
UUID diagramUuid;

Map<String, DiagramPosition> diagramPositions;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/**
* Copyright (c) 2025, RTE (http://www.rte-france.com)
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
package org.gridsuite.studyconfig.server.dto.diagramgridlayout.diagramlayout;

import com.fasterxml.jackson.annotation.JsonSubTypes;
import com.fasterxml.jackson.annotation.JsonTypeInfo;

/**
* MixIn interface for AbstractDiagramLayout to define polymorphic serialization
* without creating circular dependencies in the class hierarchy.
* This approach avoids circular dependencies that would occur with @JsonSubTypes
* directly on the abstract class.
*/
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type", visible = true)
@JsonSubTypes({
@JsonSubTypes.Type(value = SubstationDiagramLayout.class, name = "substation"),
@JsonSubTypes.Type(value = VoltageLevelDiagramLayout.class, name = "voltage-level"),
@JsonSubTypes.Type(value = NetworkAreaDiagramLayout.class, name = "network-area-diagram")
})
public interface AbstractDiagramLayoutJsonMapper {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/**
* Copyright (c) 2025, RTE (http://www.rte-france.com)
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
package org.gridsuite.studyconfig.server.dto.diagramgridlayout.diagramlayout;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;

@Builder
@AllArgsConstructor
@Getter
public class DiagramPosition {
Integer w;
Integer h;
Integer x;
Integer y;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/**
* Copyright (c) 2025, RTE (http://www.rte-france.com)
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
package org.gridsuite.studyconfig.server.dto.diagramgridlayout.diagramlayout;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.experimental.SuperBuilder;

import java.util.UUID;

@SuperBuilder
@AllArgsConstructor
@NoArgsConstructor
@Setter
@Getter
public class NetworkAreaDiagramLayout extends AbstractDiagramLayout {
UUID originalNadConfigUuid;
UUID currentNadConfigUuid;
UUID filterUuid;
String name;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/**
* Copyright (c) 2025, RTE (http://www.rte-france.com)
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
package org.gridsuite.studyconfig.server.dto.diagramgridlayout.diagramlayout;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.experimental.SuperBuilder;

@SuperBuilder
@AllArgsConstructor
@NoArgsConstructor
@Setter
@Getter
public class SubstationDiagramLayout extends AbstractDiagramLayout {
String substationId;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/**
* Copyright (c) 2025, RTE (http://www.rte-france.com)
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
package org.gridsuite.studyconfig.server.dto.diagramgridlayout.diagramlayout;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.experimental.SuperBuilder;

@SuperBuilder
@AllArgsConstructor
@NoArgsConstructor
@Setter
@Getter
public class VoltageLevelDiagramLayout extends AbstractDiagramLayout {
String voltageLevelId;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/**
* Copyright (c) 2025, RTE (http://www.rte-france.com)
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
package org.gridsuite.studyconfig.server.entities.diagramgridlayout;

import jakarta.persistence.*;
import lombok.*;

import java.util.List;
import java.util.UUID;

import org.gridsuite.studyconfig.server.entities.diagramgridlayout.diagramlayout.AbstractDiagramLayoutEntity;

@Builder
@AllArgsConstructor
@NoArgsConstructor
@Entity
@Getter
@Setter
public class DiagramGridLayoutEntity {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
UUID uuid;

@OneToMany(cascade = CascadeType.ALL, orphanRemoval = true)
@JoinColumn(name = "diagram_grid_layout_id", foreignKey = @ForeignKey(name = "fk_diagram_layout_grid_layout"))
List<AbstractDiagramLayoutEntity> diagramLayouts;

public void replaceAllDiagramLayouts(List<AbstractDiagramLayoutEntity> diagramLayouts) {
this.diagramLayouts.clear();
this.diagramLayouts.addAll(diagramLayouts);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/**
* Copyright (c) 2025, RTE (http://www.rte-france.com)
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
package org.gridsuite.studyconfig.server.entities.diagramgridlayout;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

import java.util.UUID;

@Repository
public interface DiagramGridLayoutRepository extends JpaRepository<DiagramGridLayoutEntity, UUID> {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/**
* Copyright (c) 2025, RTE (http://www.rte-france.com)
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
package org.gridsuite.studyconfig.server.entities.diagramgridlayout.diagramlayout;

import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;

import java.util.Map;
import java.util.UUID;

@Entity
@Inheritance(strategy = InheritanceType.JOINED)
@SuperBuilder
@NoArgsConstructor
@AllArgsConstructor
@Getter
public abstract class AbstractDiagramLayoutEntity {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private UUID id;

UUID diagramUuid;

@ElementCollection
@CollectionTable(foreignKey = @ForeignKey(name = "fk_diagram_positions_abstract_diagram"))
@MapKeyColumn(name = "grid_layout_key")
Map<String, DiagramPositionEntity> diagramPositions;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/**
* Copyright (c) 2025, RTE (http://www.rte-france.com)
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
package org.gridsuite.studyconfig.server.entities.diagramgridlayout.diagramlayout;

import jakarta.persistence.Embeddable;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Builder
@AllArgsConstructor
@NoArgsConstructor
@Embeddable
@Getter
public class DiagramPositionEntity {
Integer width;
Integer height;
Integer xPosition;
Integer yPosition;
}
Loading