Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename into study-config-server and manage network visualization parameters #15

Merged
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,113 @@
/**
* Copyright (c) 2024, 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.spreadsheetconfig.server.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.gridsuite.spreadsheetconfig.server.SpreadsheetConfigApi;
import org.gridsuite.spreadsheetconfig.server.dto.NetworkVisualizationParamInfos;
import org.gridsuite.spreadsheetconfig.server.service.NetworkVisualizationsParamService;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.UUID;

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

/**
* @author David BRAQUART <david.braquart at rte-france.com>
*/
@RestController
@RequestMapping(value = "/" + SpreadsheetConfigApi.API_VERSION + "/network-visualizations-params")
@RequiredArgsConstructor
@Tag(name = "Network Visualizations Params", description = "Network Visualizations Parameters API")
public class NetworkVisualizationsParamController {

private final NetworkVisualizationsParamService service;

public static final String DUPLICATE_FROM = "duplicateFrom";

@PostMapping(value = "/default")
@Operation(summary = "Create new default parameters",
description = "Creates default network visualizations parameters and returns new ID")
@ApiResponse(responseCode = "201", description = "Default parameters created",
content = @Content(schema = @Schema(implementation = UUID.class)))
public ResponseEntity<UUID> createDefaultParameters() {
UUID id = service.createDefaultParameters();
return ResponseEntity.status(HttpStatus.CREATED).body(id);
}

@PostMapping(consumes = APPLICATION_JSON_VALUE)
@Operation(summary = "Create new parameters",
description = "Creates new network visualizations parameters and returns new ID")
@ApiResponse(responseCode = "201", description = "Parameters created",
content = @Content(schema = @Schema(implementation = UUID.class)))
public ResponseEntity<UUID> createParameters(@Parameter(description = "Parameters to save") @Valid @RequestBody NetworkVisualizationParamInfos dto) {
UUID id = service.createParameters(dto);
return ResponseEntity.status(HttpStatus.CREATED).body(id);
}

@PostMapping(value = "/duplicate", params = { DUPLICATE_FROM })
@Operation(summary = "Duplicate parameters",
description = "Creates a copy of existing network visualizations parameters")
@ApiResponse(responseCode = "201", description = "Parameters duplicated",
content = @Content(schema = @Schema(implementation = UUID.class)))
@ApiResponse(responseCode = "404", description = "Parameters not found")
public ResponseEntity<UUID> duplicateParameters(@Parameter(description = "UUID of the parameters to duplicate") @RequestParam(name = DUPLICATE_FROM) UUID id) {
UUID newId = service.duplicateParameters(id);
return ResponseEntity.status(HttpStatus.CREATED).body(newId);
}

@GetMapping("/{id}")
@Operation(summary = "Get parameters",
description = "Retrieves existing network visualizations parameters by its ID")
@ApiResponse(responseCode = "200", description = "Parameters found",
content = @Content(schema = @Schema(implementation = NetworkVisualizationParamInfos.class)))
@ApiResponse(responseCode = "404", description = "Parameters not found")
public ResponseEntity<NetworkVisualizationParamInfos> getParameters(
@Parameter(description = "ID of parameters to retrieve") @PathVariable UUID id) {
return ResponseEntity.ok(service.getParameters(id));
}

@PutMapping("/{id}")
@Operation(summary = "Update parameters",
description = "Updates existing network visualizations parameters")
@ApiResponse(responseCode = "204", description = "Parameters updated")
@ApiResponse(responseCode = "404", description = "Parameters not found")
public ResponseEntity<Void> updateParameters(
@Parameter(description = "ID of the parameters to update") @PathVariable UUID id,
@Valid @RequestBody NetworkVisualizationParamInfos dto) {
service.updateParameters(id, dto);
return ResponseEntity.noContent().build();
}

@DeleteMapping("/{id}")
@Operation(summary = "Delete parameters",
description = "Deletes existing network visualizations parameters")
@ApiResponse(responseCode = "204", description = "Parameters deleted")
@ApiResponse(responseCode = "404", description = "Parameters not found")
public ResponseEntity<Void> deleteParameters(
@Parameter(description = "ID of the parameters to delete") @PathVariable UUID id) {
service.deleteParameters(id);
return ResponseEntity.noContent().build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/**
* Copyright (c) 2024, 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.spreadsheetconfig.server.dto;

import io.swagger.v3.oas.annotations.media.Schema;

/**
* @author David BRAQUART <david.braquart at rte-france.com>
*/
@Schema(name = "MapParamDto", description = "Map parameters")
public record MapParamInfos(

@Schema(description = "Line full path")
Boolean lineFullPath,

@Schema(description = "Spread overlapping lines")
Boolean lineParallelPath,

@Schema(description = "Line flow mode")
String lineFlowMode,

@Schema(description = "Line color mode")
String lineFlowColorMode,

@Schema(description = "Line overloads warning threshold")
Integer lineFlowAlertThreshold,

@Schema(description = "Manual update of geographical view")
Boolean mapManualRefresh,

@Schema(description = "Basemap")
String mapBaseMap
) { }
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* Copyright (c) 2024, 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.spreadsheetconfig.server.dto;

import io.swagger.v3.oas.annotations.media.Schema;

/**
* @author David BRAQUART <david.braquart at rte-france.com>
*/
@Schema(name = "NetworkAreaDiagramParamDto", description = "Network area diagram parameters")
public record NetworkAreaDiagramParamInfos(

@Schema(description = "Initialize with geographical data")
Boolean initNadWithGeoData
) { }
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/**
* Copyright (c) 2024, 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.spreadsheetconfig.server.dto;

import io.swagger.v3.oas.annotations.media.Schema;

import java.util.UUID;

/**
* @author David BRAQUART <david.braquart at rte-france.com>
*/
@Schema(name = "NetworkVisualizationParamDto", description = "Network visualization parameters")
public record NetworkVisualizationParamInfos(

@Schema(description = "Parameters ID")
UUID id,

@Schema(description = "Map parameters")
MapParamInfos mapParameters,

@Schema(description = "Single line diagram parameters")
SingleLineDiagramParamInfos singleLineDiagramParameters,

@Schema(description = "Network area diagram parameters")
NetworkAreaDiagramParamInfos networkAreaDiagramParameters
) { }
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/**
* Copyright (c) 2024, 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.spreadsheetconfig.server.dto;

import io.swagger.v3.oas.annotations.media.Schema;

/**
* @author David BRAQUART <david.braquart at rte-france.com>
*/
@Schema(name = "SingleLineDiagramParamDto", description = "Single line diagram parameters")
public record SingleLineDiagramParamInfos(

@Schema(description = "Display name diagonally")
Boolean diagonalLabel,

@Schema(description = "Center name")
Boolean centerLabel,

@Schema(description = "Substation diagram layout")
String substationLayout,

@Schema(description = "Component library selection")
String componentLibrary
) { }
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/**
* Copyright (c) 2024, 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.spreadsheetconfig.server.entities;

import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import java.util.UUID;

/**
* @author David BRAQUART <david.braquart at rte-france.com>
*/
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Getter
@Setter
@Entity
@Table(name = "network_visualization_params")
public class NetworkVisualizationParamEntity {

@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "id")
private UUID id;

@Column(name = "line_full_path")
private Boolean lineFullPath = true;

@Column(name = "line_parallel_path")
private Boolean lineParallelPath = true;

@Column(name = "line_flow_mode")
private String lineFlowMode = "feeders";

@Column(name = "line_flow_color_mode")
private String lineFlowColorMode = "nominalVoltage";

@Column(name = "line_flow_alert_threshold")
private Integer lineFlowAlertThreshold = 100;

@Column(name = "map_manual_refresh")
private Boolean mapManualRefresh = false;

@Column(name = "map_basemap")
private String mapBaseMap = "mapbox";

@Column(name = "diagonal_label")
private Boolean diagonalLabel = false;

@Column(name = "center_label")
private Boolean centerLabel = false;

@Column(name = "substation_layout")
private String substationLayout = "horizontal";

@Column(name = "component_library")
private String componentLibrary = "";

@Column(name = "init_nad_with_geo_data")
private Boolean initNadWithGeoData = true;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/**
* Copyright (c) 2024, 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.spreadsheetconfig.server.mapper;

import org.gridsuite.spreadsheetconfig.server.dto.MapParamInfos;
import org.gridsuite.spreadsheetconfig.server.dto.NetworkAreaDiagramParamInfos;
import org.gridsuite.spreadsheetconfig.server.dto.NetworkVisualizationParamInfos;
import org.gridsuite.spreadsheetconfig.server.dto.SingleLineDiagramParamInfos;
import org.gridsuite.spreadsheetconfig.server.entities.NetworkVisualizationParamEntity;

/**
* @author David BRAQUART <david.braquart at rte-france.com>
*/
public final class NetworkVisualizationParamMapper {

private NetworkVisualizationParamMapper() {
}

public static NetworkVisualizationParamInfos toDto(NetworkVisualizationParamEntity entity) {
return new NetworkVisualizationParamInfos(
entity.getId(),
new MapParamInfos(
entity.getLineFullPath(),
entity.getLineParallelPath(),
entity.getLineFlowMode(),
entity.getLineFlowColorMode(),
entity.getLineFlowAlertThreshold(),
entity.getMapManualRefresh(),
entity.getMapBaseMap()),
new SingleLineDiagramParamInfos(
entity.getDiagonalLabel(),
entity.getCenterLabel(),
entity.getSubstationLayout(),
entity.getComponentLibrary()
),
new NetworkAreaDiagramParamInfos(entity.getInitNadWithGeoData())
);
}

public static NetworkVisualizationParamEntity toEntity(NetworkVisualizationParamInfos dto) {
NetworkVisualizationParamEntity entity = new NetworkVisualizationParamEntity();
updateEntity(entity, dto);
return entity;
}

public static void updateEntity(NetworkVisualizationParamEntity entity, NetworkVisualizationParamInfos dto) {
// Map
entity.setLineFullPath(dto.mapParameters().lineFullPath());
entity.setLineParallelPath(dto.mapParameters().lineParallelPath());
entity.setLineFlowMode(dto.mapParameters().lineFlowMode());
entity.setLineFlowColorMode(dto.mapParameters().lineFlowColorMode());
entity.setLineFlowAlertThreshold(dto.mapParameters().lineFlowAlertThreshold());
entity.setMapManualRefresh(dto.mapParameters().mapManualRefresh());
entity.setMapBaseMap(dto.mapParameters().mapBaseMap());
// SLD
entity.setDiagonalLabel(dto.singleLineDiagramParameters().diagonalLabel());
entity.setCenterLabel(dto.singleLineDiagramParameters().centerLabel());
entity.setSubstationLayout(dto.singleLineDiagramParameters().substationLayout());
entity.setComponentLibrary(dto.singleLineDiagramParameters().componentLibrary());
// NAD
entity.setInitNadWithGeoData(dto.networkAreaDiagramParameters().initNadWithGeoData());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/**
* Copyright (c) 2024, 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.spreadsheetconfig.server.repositories;

import org.gridsuite.spreadsheetconfig.server.entities.NetworkVisualizationParamEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

import java.util.UUID;

/**
* @author David BRAQUART <david.braquart at rte-france.com>
*/
@Repository
public interface NetworkVisualizationParamRepository extends JpaRepository<NetworkVisualizationParamEntity, UUID> {
}
Loading
Loading