Skip to content

Commit 77373ba

Browse files
authored
Store and manage network visualization parameters (#15)
Signed-off-by: David BRAQUART <[email protected]>
1 parent f9b4eab commit 77373ba

14 files changed

+673
-2
lines changed
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
/**
2+
* Copyright (c) 2024, RTE (http://www.rte-france.com)
3+
* This Source Code Form is subject to the terms of the Mozilla Public
4+
* License, v. 2.0. If a copy of the MPL was not distributed with this
5+
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
6+
*/
7+
package org.gridsuite.spreadsheetconfig.server.controller;
8+
9+
import io.swagger.v3.oas.annotations.Operation;
10+
import io.swagger.v3.oas.annotations.Parameter;
11+
import io.swagger.v3.oas.annotations.media.Content;
12+
import io.swagger.v3.oas.annotations.media.Schema;
13+
import io.swagger.v3.oas.annotations.responses.ApiResponse;
14+
import io.swagger.v3.oas.annotations.tags.Tag;
15+
import jakarta.validation.Valid;
16+
import lombok.RequiredArgsConstructor;
17+
import org.gridsuite.spreadsheetconfig.server.SpreadsheetConfigApi;
18+
import org.gridsuite.spreadsheetconfig.server.dto.NetworkVisualizationParamInfos;
19+
import org.gridsuite.spreadsheetconfig.server.service.NetworkVisualizationsParamService;
20+
import org.springframework.http.HttpStatus;
21+
import org.springframework.http.ResponseEntity;
22+
import org.springframework.web.bind.annotation.DeleteMapping;
23+
import org.springframework.web.bind.annotation.GetMapping;
24+
import org.springframework.web.bind.annotation.PathVariable;
25+
import org.springframework.web.bind.annotation.PostMapping;
26+
import org.springframework.web.bind.annotation.PutMapping;
27+
import org.springframework.web.bind.annotation.RequestBody;
28+
import org.springframework.web.bind.annotation.RequestMapping;
29+
import org.springframework.web.bind.annotation.RequestParam;
30+
import org.springframework.web.bind.annotation.RestController;
31+
32+
import java.util.UUID;
33+
34+
import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE;
35+
36+
/**
37+
* @author David BRAQUART <david.braquart at rte-france.com>
38+
*/
39+
@RestController
40+
@RequestMapping(value = "/" + SpreadsheetConfigApi.API_VERSION + "/network-visualizations-params")
41+
@RequiredArgsConstructor
42+
@Tag(name = "Network Visualizations Params", description = "Network Visualizations Parameters API")
43+
public class NetworkVisualizationsParamController {
44+
45+
private final NetworkVisualizationsParamService service;
46+
47+
public static final String DUPLICATE_FROM = "duplicateFrom";
48+
49+
@PostMapping(value = "/default")
50+
@Operation(summary = "Create new default parameters",
51+
description = "Creates default network visualizations parameters and returns new ID")
52+
@ApiResponse(responseCode = "201", description = "Default parameters created",
53+
content = @Content(schema = @Schema(implementation = UUID.class)))
54+
public ResponseEntity<UUID> createDefaultParameters() {
55+
UUID id = service.createDefaultParameters();
56+
return ResponseEntity.status(HttpStatus.CREATED).body(id);
57+
}
58+
59+
@PostMapping(consumes = APPLICATION_JSON_VALUE)
60+
@Operation(summary = "Create new parameters",
61+
description = "Creates new network visualizations parameters and returns new ID")
62+
@ApiResponse(responseCode = "201", description = "Parameters created",
63+
content = @Content(schema = @Schema(implementation = UUID.class)))
64+
public ResponseEntity<UUID> createParameters(@Parameter(description = "Parameters to save") @Valid @RequestBody NetworkVisualizationParamInfos dto) {
65+
UUID id = service.createParameters(dto);
66+
return ResponseEntity.status(HttpStatus.CREATED).body(id);
67+
}
68+
69+
@PostMapping(value = "/duplicate", params = { DUPLICATE_FROM })
70+
@Operation(summary = "Duplicate parameters",
71+
description = "Creates a copy of existing network visualizations parameters")
72+
@ApiResponse(responseCode = "201", description = "Parameters duplicated",
73+
content = @Content(schema = @Schema(implementation = UUID.class)))
74+
@ApiResponse(responseCode = "404", description = "Parameters not found")
75+
public ResponseEntity<UUID> duplicateParameters(@Parameter(description = "UUID of the parameters to duplicate") @RequestParam(name = DUPLICATE_FROM) UUID id) {
76+
UUID newId = service.duplicateParameters(id);
77+
return ResponseEntity.status(HttpStatus.CREATED).body(newId);
78+
}
79+
80+
@GetMapping("/{id}")
81+
@Operation(summary = "Get parameters",
82+
description = "Retrieves existing network visualizations parameters by its ID")
83+
@ApiResponse(responseCode = "200", description = "Parameters found",
84+
content = @Content(schema = @Schema(implementation = NetworkVisualizationParamInfos.class)))
85+
@ApiResponse(responseCode = "404", description = "Parameters not found")
86+
public ResponseEntity<NetworkVisualizationParamInfos> getParameters(
87+
@Parameter(description = "ID of parameters to retrieve") @PathVariable UUID id) {
88+
return ResponseEntity.ok(service.getParameters(id));
89+
}
90+
91+
@PutMapping("/{id}")
92+
@Operation(summary = "Update parameters",
93+
description = "Updates existing network visualizations parameters")
94+
@ApiResponse(responseCode = "204", description = "Parameters updated")
95+
@ApiResponse(responseCode = "404", description = "Parameters not found")
96+
public ResponseEntity<Void> updateParameters(
97+
@Parameter(description = "ID of the parameters to update") @PathVariable UUID id,
98+
@Valid @RequestBody NetworkVisualizationParamInfos dto) {
99+
service.updateParameters(id, dto);
100+
return ResponseEntity.noContent().build();
101+
}
102+
103+
@DeleteMapping("/{id}")
104+
@Operation(summary = "Delete parameters",
105+
description = "Deletes existing network visualizations parameters")
106+
@ApiResponse(responseCode = "204", description = "Parameters deleted")
107+
@ApiResponse(responseCode = "404", description = "Parameters not found")
108+
public ResponseEntity<Void> deleteParameters(
109+
@Parameter(description = "ID of the parameters to delete") @PathVariable UUID id) {
110+
service.deleteParameters(id);
111+
return ResponseEntity.noContent().build();
112+
}
113+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/**
2+
* Copyright (c) 2024, RTE (http://www.rte-france.com)
3+
* This Source Code Form is subject to the terms of the Mozilla Public
4+
* License, v. 2.0. If a copy of the MPL was not distributed with this
5+
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
6+
*/
7+
package org.gridsuite.spreadsheetconfig.server.dto;
8+
9+
import io.swagger.v3.oas.annotations.media.Schema;
10+
11+
/**
12+
* @author David BRAQUART <david.braquart at rte-france.com>
13+
*/
14+
@Schema(name = "MapParamDto", description = "Map parameters")
15+
public record MapParamInfos(
16+
17+
@Schema(description = "Line full path")
18+
Boolean lineFullPath,
19+
20+
@Schema(description = "Spread overlapping lines")
21+
Boolean lineParallelPath,
22+
23+
@Schema(description = "Line flow mode")
24+
String lineFlowMode,
25+
26+
@Schema(description = "Line color mode")
27+
String lineFlowColorMode,
28+
29+
@Schema(description = "Line overloads warning threshold")
30+
Integer lineFlowAlertThreshold,
31+
32+
@Schema(description = "Manual update of geographical view")
33+
Boolean mapManualRefresh,
34+
35+
@Schema(description = "Basemap")
36+
String mapBaseMap
37+
) { }
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/**
2+
* Copyright (c) 2024, RTE (http://www.rte-france.com)
3+
* This Source Code Form is subject to the terms of the Mozilla Public
4+
* License, v. 2.0. If a copy of the MPL was not distributed with this
5+
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
6+
*/
7+
package org.gridsuite.spreadsheetconfig.server.dto;
8+
9+
import io.swagger.v3.oas.annotations.media.Schema;
10+
11+
/**
12+
* @author David BRAQUART <david.braquart at rte-france.com>
13+
*/
14+
@Schema(name = "NetworkAreaDiagramParamDto", description = "Network area diagram parameters")
15+
public record NetworkAreaDiagramParamInfos(
16+
17+
@Schema(description = "Initialize with geographical data")
18+
Boolean initNadWithGeoData
19+
) { }
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/**
2+
* Copyright (c) 2024, RTE (http://www.rte-france.com)
3+
* This Source Code Form is subject to the terms of the Mozilla Public
4+
* License, v. 2.0. If a copy of the MPL was not distributed with this
5+
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
6+
*/
7+
package org.gridsuite.spreadsheetconfig.server.dto;
8+
9+
import io.swagger.v3.oas.annotations.media.Schema;
10+
11+
import java.util.UUID;
12+
13+
/**
14+
* @author David BRAQUART <david.braquart at rte-france.com>
15+
*/
16+
@Schema(name = "NetworkVisualizationParamDto", description = "Network visualization parameters")
17+
public record NetworkVisualizationParamInfos(
18+
19+
@Schema(description = "Parameters ID")
20+
UUID id,
21+
22+
@Schema(description = "Map parameters")
23+
MapParamInfos mapParameters,
24+
25+
@Schema(description = "Single line diagram parameters")
26+
SingleLineDiagramParamInfos singleLineDiagramParameters,
27+
28+
@Schema(description = "Network area diagram parameters")
29+
NetworkAreaDiagramParamInfos networkAreaDiagramParameters
30+
) { }
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/**
2+
* Copyright (c) 2024, RTE (http://www.rte-france.com)
3+
* This Source Code Form is subject to the terms of the Mozilla Public
4+
* License, v. 2.0. If a copy of the MPL was not distributed with this
5+
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
6+
*/
7+
package org.gridsuite.spreadsheetconfig.server.dto;
8+
9+
import io.swagger.v3.oas.annotations.media.Schema;
10+
11+
/**
12+
* @author David BRAQUART <david.braquart at rte-france.com>
13+
*/
14+
@Schema(name = "SingleLineDiagramParamDto", description = "Single line diagram parameters")
15+
public record SingleLineDiagramParamInfos(
16+
17+
@Schema(description = "Display name diagonally")
18+
Boolean diagonalLabel,
19+
20+
@Schema(description = "Center name")
21+
Boolean centerLabel,
22+
23+
@Schema(description = "Substation diagram layout")
24+
String substationLayout,
25+
26+
@Schema(description = "Component library selection")
27+
String componentLibrary
28+
) { }
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/**
2+
* Copyright (c) 2024, RTE (http://www.rte-france.com)
3+
* This Source Code Form is subject to the terms of the Mozilla Public
4+
* License, v. 2.0. If a copy of the MPL was not distributed with this
5+
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
6+
*/
7+
package org.gridsuite.spreadsheetconfig.server.entities;
8+
9+
import jakarta.persistence.*;
10+
import lombok.AllArgsConstructor;
11+
import lombok.Builder;
12+
import lombok.Getter;
13+
import lombok.NoArgsConstructor;
14+
import lombok.Setter;
15+
import java.util.UUID;
16+
17+
/**
18+
* @author David BRAQUART <david.braquart at rte-france.com>
19+
*/
20+
@Builder
21+
@NoArgsConstructor
22+
@AllArgsConstructor
23+
@Getter
24+
@Setter
25+
@Entity
26+
@Table(name = "network_visualization_params")
27+
public class NetworkVisualizationParamEntity {
28+
29+
@Id
30+
@GeneratedValue(strategy = GenerationType.AUTO)
31+
@Column(name = "id")
32+
private UUID id;
33+
34+
@Column(name = "line_full_path")
35+
private Boolean lineFullPath = true;
36+
37+
@Column(name = "line_parallel_path")
38+
private Boolean lineParallelPath = true;
39+
40+
@Column(name = "line_flow_mode")
41+
private String lineFlowMode = "feeders";
42+
43+
@Column(name = "line_flow_color_mode")
44+
private String lineFlowColorMode = "nominalVoltage";
45+
46+
@Column(name = "line_flow_alert_threshold")
47+
private Integer lineFlowAlertThreshold = 100;
48+
49+
@Column(name = "map_manual_refresh")
50+
private Boolean mapManualRefresh = false;
51+
52+
@Column(name = "map_basemap")
53+
private String mapBaseMap = "mapbox";
54+
55+
@Column(name = "diagonal_label")
56+
private Boolean diagonalLabel = false;
57+
58+
@Column(name = "center_label")
59+
private Boolean centerLabel = false;
60+
61+
@Column(name = "substation_layout")
62+
private String substationLayout = "horizontal";
63+
64+
@Column(name = "component_library")
65+
private String componentLibrary = "";
66+
67+
@Column(name = "init_nad_with_geo_data")
68+
private Boolean initNadWithGeoData = true;
69+
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/**
2+
* Copyright (c) 2024, RTE (http://www.rte-france.com)
3+
* This Source Code Form is subject to the terms of the Mozilla Public
4+
* License, v. 2.0. If a copy of the MPL was not distributed with this
5+
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
6+
*/
7+
package org.gridsuite.spreadsheetconfig.server.mapper;
8+
9+
import org.gridsuite.spreadsheetconfig.server.dto.MapParamInfos;
10+
import org.gridsuite.spreadsheetconfig.server.dto.NetworkAreaDiagramParamInfos;
11+
import org.gridsuite.spreadsheetconfig.server.dto.NetworkVisualizationParamInfos;
12+
import org.gridsuite.spreadsheetconfig.server.dto.SingleLineDiagramParamInfos;
13+
import org.gridsuite.spreadsheetconfig.server.entities.NetworkVisualizationParamEntity;
14+
15+
/**
16+
* @author David BRAQUART <david.braquart at rte-france.com>
17+
*/
18+
public final class NetworkVisualizationParamMapper {
19+
20+
private NetworkVisualizationParamMapper() {
21+
}
22+
23+
public static NetworkVisualizationParamInfos toDto(NetworkVisualizationParamEntity entity) {
24+
return new NetworkVisualizationParamInfos(
25+
entity.getId(),
26+
new MapParamInfos(
27+
entity.getLineFullPath(),
28+
entity.getLineParallelPath(),
29+
entity.getLineFlowMode(),
30+
entity.getLineFlowColorMode(),
31+
entity.getLineFlowAlertThreshold(),
32+
entity.getMapManualRefresh(),
33+
entity.getMapBaseMap()),
34+
new SingleLineDiagramParamInfos(
35+
entity.getDiagonalLabel(),
36+
entity.getCenterLabel(),
37+
entity.getSubstationLayout(),
38+
entity.getComponentLibrary()
39+
),
40+
new NetworkAreaDiagramParamInfos(entity.getInitNadWithGeoData())
41+
);
42+
}
43+
44+
public static NetworkVisualizationParamEntity toEntity(NetworkVisualizationParamInfos dto) {
45+
NetworkVisualizationParamEntity entity = new NetworkVisualizationParamEntity();
46+
updateEntity(entity, dto);
47+
return entity;
48+
}
49+
50+
public static void updateEntity(NetworkVisualizationParamEntity entity, NetworkVisualizationParamInfos dto) {
51+
// Map
52+
entity.setLineFullPath(dto.mapParameters().lineFullPath());
53+
entity.setLineParallelPath(dto.mapParameters().lineParallelPath());
54+
entity.setLineFlowMode(dto.mapParameters().lineFlowMode());
55+
entity.setLineFlowColorMode(dto.mapParameters().lineFlowColorMode());
56+
entity.setLineFlowAlertThreshold(dto.mapParameters().lineFlowAlertThreshold());
57+
entity.setMapManualRefresh(dto.mapParameters().mapManualRefresh());
58+
entity.setMapBaseMap(dto.mapParameters().mapBaseMap());
59+
// SLD
60+
entity.setDiagonalLabel(dto.singleLineDiagramParameters().diagonalLabel());
61+
entity.setCenterLabel(dto.singleLineDiagramParameters().centerLabel());
62+
entity.setSubstationLayout(dto.singleLineDiagramParameters().substationLayout());
63+
entity.setComponentLibrary(dto.singleLineDiagramParameters().componentLibrary());
64+
// NAD
65+
entity.setInitNadWithGeoData(dto.networkAreaDiagramParameters().initNadWithGeoData());
66+
}
67+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/**
2+
* Copyright (c) 2024, RTE (http://www.rte-france.com)
3+
* This Source Code Form is subject to the terms of the Mozilla Public
4+
* License, v. 2.0. If a copy of the MPL was not distributed with this
5+
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
6+
*/
7+
package org.gridsuite.spreadsheetconfig.server.repositories;
8+
9+
import org.gridsuite.spreadsheetconfig.server.entities.NetworkVisualizationParamEntity;
10+
import org.springframework.data.jpa.repository.JpaRepository;
11+
import org.springframework.stereotype.Repository;
12+
13+
import java.util.UUID;
14+
15+
/**
16+
* @author David BRAQUART <david.braquart at rte-france.com>
17+
*/
18+
@Repository
19+
public interface NetworkVisualizationParamRepository extends JpaRepository<NetworkVisualizationParamEntity, UUID> {
20+
}

0 commit comments

Comments
 (0)