Skip to content
Merged
Show file tree
Hide file tree
Changes from 13 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
Expand Up @@ -197,8 +197,18 @@ public ResponseEntity<List<LineTypeInfos>> getLineTypes() {
@GetMapping(value = "/network-modifications/catalog/line_types/{uuid}", produces = MediaType.APPLICATION_JSON_VALUE)
@Operation(summary = "Get a line types catalog")
Comment thread
Mathieu-Deharbe marked this conversation as resolved.
Outdated
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "The line types catalog is returned")})
public ResponseEntity<LineTypeInfos> getOneLineTypeWithLimits(@PathVariable("uuid") UUID uuid) {
return ResponseEntity.ok().body(lineTypesCatalogService.getLineTypesWithLimits(uuid));
public ResponseEntity<LineTypeInfos> getOneLineTypeWithAreaAndTemperature(@PathVariable("uuid") UUID uuid) {
return ResponseEntity.ok().body(lineTypesCatalogService.getLineTypesWithAreaTemperatureShapeFactors(uuid));
}

@GetMapping(value = "/network-modifications/catalog/line_types/{uuid}/withLimits", produces = MediaType.APPLICATION_JSON_VALUE)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From our guidelines :

La typographie des mots, composant un path, doit adopter une convention kebab case plutôt que snake ou camel case : /voltage-levels et non /voltage_levels ou /voltageLevels

Suggested change
@GetMapping(value = "/network-modifications/catalog/line_types/{uuid}/withLimits", produces = MediaType.APPLICATION_JSON_VALUE)
@GetMapping(value = "/network-modifications/catalog/line_types/{uuid}/with-limits", produces = MediaType.APPLICATION_JSON_VALUE)

But there are conflicting data in the examples !

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where do you see conflicts ?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it should be better keep it withLimits without "-"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the guideline page you have the above texte which asks for kebab case and at the end of the page you have that king of example :

/network-modifications/loadModification

Which don't use kebab case at all.

@Operation(summary = "Get a line types catalog")
Comment thread
Mathieu-Deharbe marked this conversation as resolved.
Outdated
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "The line types catalog is returned")})
public ResponseEntity<LineTypeInfos> getOneLineTypeWithLimits(@PathVariable UUID uuid, @RequestParam String area,
@RequestParam(required = false) String temperature,
@RequestParam(required = false) String shapeFactor) {
LineTypeInfos test = lineTypesCatalogService.getLineTypesWithLimits(uuid, area, temperature, shapeFactor);
return ResponseEntity.ok().body(test);
}

@PostMapping(value = "/network-modifications/catalog/line_types", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import lombok.Setter;
import lombok.experimental.SuperBuilder;

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

/**
Expand All @@ -36,14 +37,8 @@ public class LimitsForLineTypeInfos {
@Schema(description = "Permanent limit")
private Double permanentLimit;

@Schema(description = "Temporary limit value")
private Double temporaryLimitValue;

@Schema(description = "Temporary limit acceptable duration")
private Integer temporaryLimitAcceptableDuration;

@Schema(description = "Temporary limit name")
private String temporaryLimitName;
@Schema(description = "temporary limits list")
List<TemporaryLimitInfos> temporaryLimits;

@Schema(description = "Area")
private String area;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/**
* Copyright (c) 2026, 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/.
* SPDX-License-Identifier: MPL-2.0
*/
package org.gridsuite.modification.server.dto.catalog;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.experimental.SuperBuilder;
import org.gridsuite.modification.server.entities.catalog.TemporaryLimitEntity;

import java.util.UUID;

/**
* @author Etienne Lesot <etienne.lesot at rte-france.com>
*/
@SuperBuilder
@NoArgsConstructor
@AllArgsConstructor
@Getter
@Setter
@Schema(description = "Temporary Limits infos")
Comment thread
Mathieu-Deharbe marked this conversation as resolved.
Outdated
public class TemporaryLimitInfos {
@Schema(description = "id")
private UUID id;

@Schema(description = "Temporary limit value")
private Double limitValue;

@Schema(description = "Temporary limit acceptable duration")
private Integer acceptableDuration;

@Schema(description = "Temporary limit name")
private String name;

public TemporaryLimitEntity toTemporaryLimitEntity() {
return TemporaryLimitEntity.builder()
.limitValue(limitValue)
.acceptableDuration(acceptableDuration)
.name(name).build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import jakarta.persistence.*;
import lombok.NoArgsConstructor;
import org.gridsuite.modification.server.dto.catalog.AerialLineTypeInfos;
import org.gridsuite.modification.server.dto.catalog.LineTypeInfos;

/**
* @author Sylvain Bouzols <sylvain.bouzols at rte-france.com>
Expand Down Expand Up @@ -41,17 +42,17 @@ private void assignAttributes(AerialLineTypeInfos aerialLineType) {

AerialLineTypeInfos.AerialLineTypeInfosBuilder<?, ?> toDtoBuilder() {
return AerialLineTypeInfos.builder()
.id(this.getId())
.type(this.getType())
.voltage(this.getVoltage())
.conductorType(this.getConductorType())
.section(this.getSection())
.conductorsNumber(this.conductorsNumber)
.circuitsNumber(this.circuitsNumber)
.groundWiresNumber(this.groundWiresNumber)
.linearResistance(this.getLinearResistance())
.linearReactance(this.getLinearReactance())
.linearCapacity(this.getLinearCapacity());
.id(this.getId())
.type(this.getType())
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

revert

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

.voltage(this.getVoltage())
.conductorType(this.getConductorType())
.section(this.getSection())
.conductorsNumber(this.conductorsNumber)
.circuitsNumber(this.circuitsNumber)
.groundWiresNumber(this.groundWiresNumber)
.linearResistance(this.getLinearResistance())
.linearReactance(this.getLinearReactance())
.linearCapacity(this.getLinearCapacity());
}

@Override
Expand All @@ -60,10 +61,20 @@ public AerialLineTypeInfos toDto() {
}

@Override
public AerialLineTypeInfos toDtoWithLimits() {
public AerialLineTypeInfos toDtoWithLimits(String area, String temperature, String shapeFactor) {
return toDtoBuilder()
.limitsForLineType(this.getLimitsForLineType().stream().map(LimitsForLineTypeEntity::toLineTypeInfos).toList())
.build();
.limitsForLineType(this.getLimitsForLineType().stream()
.filter(limitsForLineTypeEntity -> limitsForLineTypeEntity.getArea().equals(area) &&
limitsForLineTypeEntity.getTemperature().equals(temperature))
.map(LimitsForLineTypeEntity::toLineTypeInfos).toList())
.build();
}

@Override
public LineTypeInfos toDtoWithAreaTemperatureShapeFactors() {
return toDtoBuilder()
.limitsForLineType(this.getLimitsForLineType().stream().map(LimitsForLineTypeEntity::toLineTypeInfosWithoutLimits).toList())
.build();
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,19 @@
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.experimental.SuperBuilder;
import org.gridsuite.modification.server.dto.catalog.LimitsForLineTypeInfos;
import org.gridsuite.modification.server.dto.catalog.TemporaryLimitInfos;

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

/**
* @author Etienne Lesot <etienne.lesot at rte-france.com>
*/
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@SuperBuilder
Expand All @@ -38,29 +42,30 @@ public class LimitsForLineTypeEntity {
@Column
private Double permanentLimit;

@Column
private Double temporaryLimitValue;

@Column
private Integer temporaryLimitAcceptableDuration;

@Column
private String temporaryLimitName;
@OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL, orphanRemoval = true)
@JoinColumn(name = "temporary_limit_id", nullable = false)
Comment thread
Mathieu-Deharbe marked this conversation as resolved.
Outdated
private List<TemporaryLimitEntity> temporaryLimits;

@Column
private String area;

@Column
private String temperature;

public LimitsForLineTypeInfos toLineTypeInfosWithoutLimits() {
return LimitsForLineTypeInfos.builder()
.id(id)
.area(area)
.temperature(temperature)
.build();
}

public LimitsForLineTypeInfos toLineTypeInfos() {
return LimitsForLineTypeInfos.builder()
.id(id)
.limitSetName(limitSetName)
.permanentLimit(permanentLimit)
.temporaryLimitValue(temporaryLimitValue)
.temporaryLimitAcceptableDuration(temporaryLimitAcceptableDuration)
.temporaryLimitName(temporaryLimitName)
.temporaryLimits(temporaryLimits.parallelStream().map(TemporaryLimitEntity::toTemporaryLimitInfos).toList())
Comment thread
Mathieu-Deharbe marked this conversation as resolved.
Outdated
.area(area)
.temperature(temperature)
.build();
Expand All @@ -70,9 +75,7 @@ public LimitsForLineTypeEntity(LimitsForLineTypeInfos limitsForLineTypeInfos) {
this(limitsForLineTypeInfos.getId(),
limitsForLineTypeInfos.getLimitSetName(),
limitsForLineTypeInfos.getPermanentLimit(),
limitsForLineTypeInfos.getTemporaryLimitValue(),
limitsForLineTypeInfos.getTemporaryLimitAcceptableDuration(),
limitsForLineTypeInfos.getTemporaryLimitName(),
limitsForLineTypeInfos.getTemporaryLimits() != null ? limitsForLineTypeInfos.getTemporaryLimits().stream().map(TemporaryLimitInfos::toTemporaryLimitEntity).toList() : null,
limitsForLineTypeInfos.getArea(),
limitsForLineTypeInfos.getTemperature());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,14 @@ public LineTypeInfos toDto() {
return toBuilder().build();
}

public LineTypeInfos toDtoWithLimits() {
public LineTypeInfos toDtoWithAreaTemperatureShapeFactors() {
return toBuilder()
.limitsForLineType(this.limitsForLineType.stream().map(LimitsForLineTypeEntity::toLineTypeInfos).toList())
.build();
.limitsForLineType(this.limitsForLineType.parallelStream().map(LimitsForLineTypeEntity::toLineTypeInfosWithoutLimits).toList())
.build();
}

public LineTypeInfos toDtoWithLimits(String area, String temperature, String shapeFactor) {
throw new UnsupportedOperationException("Not implemented, only implemented for subClasses AerialLineTypeEntity and UndergroundLineTypeEntity");
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/**
* Copyright (c) 2026, 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/.
* SPDX-License-Identifier: MPL-2.0
*/
package org.gridsuite.modification.server.entities.catalog;

import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.experimental.SuperBuilder;
import org.gridsuite.modification.server.dto.catalog.TemporaryLimitInfos;

import java.util.UUID;

/**
* @author Etienne Lesot <etienne.lesot at rte-france.com>
*/
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@SuperBuilder
@Entity
@Table(name = "temporary_limit_for_line_catalog")
public class TemporaryLimitEntity {

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

@Column
private Double limitValue;

@Column
private Integer acceptableDuration;

@Column
private String name;

public TemporaryLimitInfos toTemporaryLimitInfos() {
return TemporaryLimitInfos.builder()
.id(id)
.limitValue(limitValue)
.acceptableDuration(acceptableDuration)
.name(name)
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import jakarta.persistence.*;
import lombok.NoArgsConstructor;
import org.gridsuite.modification.server.dto.catalog.LineTypeInfos;
import org.gridsuite.modification.server.dto.catalog.UndergroundLineTypeInfos;

import java.util.List;
Expand Down Expand Up @@ -59,12 +60,28 @@ public UndergroundLineTypeInfos toDto() {
}

@Override
public UndergroundLineTypeInfos toDtoWithLimits() {
public UndergroundLineTypeInfos toDtoWithLimits(String area, String temperature, String shapeFactor) {
double shapeFactorValue = shapeFactor == null ? 1 : Double.parseDouble(shapeFactor);
return toDtoBuilder()
.shapeFactors(SHAPE_FACTORS)
.limitsForLineType(this.getLimitsForLineType().stream().map(LimitsForLineTypeEntity::toLineTypeInfos).toList())
.limitsForLineType(this.getLimitsForLineType().stream()
.filter(limitsForLineTypeEntity -> limitsForLineTypeEntity.getArea().equals(area))
.peek(limitsForLineTypeEntity -> {
Comment thread
Mathieu-Deharbe marked this conversation as resolved.
Outdated
limitsForLineTypeEntity.setPermanentLimit(shapeFactorValue * limitsForLineTypeEntity.getPermanentLimit());
limitsForLineTypeEntity.getTemporaryLimits().forEach(temporaryLimit ->
temporaryLimit.setLimitValue(shapeFactorValue * temporaryLimit.getLimitValue()));
})
.map(LimitsForLineTypeEntity::toLineTypeInfos)
.toList())
.build();
}

@Override
public LineTypeInfos toDtoWithAreaTemperatureShapeFactors() {
return toDtoBuilder()
.shapeFactors(SHAPE_FACTORS)
.limitsForLineType(this.getLimitsForLineType().stream().map(LimitsForLineTypeEntity::toLineTypeInfosWithoutLimits).toList())
.build();
}
}


Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import org.gridsuite.modification.server.dto.catalog.LineTypeInfos;
import org.gridsuite.modification.server.entities.catalog.LineTypeEntity;
import org.gridsuite.modification.server.repositories.LineTypesCatalogRepository;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;
Expand All @@ -32,6 +34,8 @@ public class LineTypesCatalogService {
private final LineTypesCatalogRepository lineTypesCatalogRepository;
private final ObjectMapper mapper;

private static final Logger LOGGER = LoggerFactory.getLogger(LineTypesCatalogService.class);

public LineTypesCatalogService(LineTypesCatalogRepository lineTypesCatalogRepository, ObjectMapper objectMapper) {
this.lineTypesCatalogRepository = lineTypesCatalogRepository;
this.mapper = objectMapper;
Expand All @@ -45,9 +49,15 @@ public List<LineTypeInfos> getAllLineTypes() {
}

@Transactional(readOnly = true)
public LineTypeInfos getLineTypesWithLimits(UUID id) {
public LineTypeInfos getLineTypesWithLimits(UUID id, String area, String temperature, String shapeFactor) {
Optional<LineTypeEntity> lineTypeEntity = lineTypesCatalogRepository.findById(id);
return lineTypeEntity.map((LineTypeEntity lineType) -> lineType.toDtoWithLimits(area, temperature, shapeFactor)).orElse(null);
}

@Transactional(readOnly = true)
public LineTypeInfos getLineTypesWithAreaTemperatureShapeFactors(UUID id) {
Optional<LineTypeEntity> lineTypeEntity = lineTypesCatalogRepository.findById(id);
return lineTypeEntity.map(LineTypeEntity::toDtoWithLimits).orElse(null);
return lineTypeEntity.map(LineTypeEntity::toDtoWithAreaTemperatureShapeFactors).orElse(null);
}

public void deleteLineTypesCatalog() {
Expand All @@ -56,16 +66,20 @@ public void deleteLineTypesCatalog() {

public void resetLineTypes(MultipartFile file) {
try (GZIPInputStream gzipInputStream = new GZIPInputStream(file.getInputStream())) {
List<LineTypeInfos> lineTypes = mapper.readValue(gzipInputStream, new TypeReference<>() {
List<LineTypeInfos> lineTypes = mapper.readValue(gzipInputStream, new TypeReference<List<LineTypeInfos>>() {
});
LOGGER.info("Starting to delete all line types from the catalog");
deleteLineTypesCatalog();
LOGGER.info("All line types from the catalog deleted");
// remove duplicates in file
Set<LineTypeInfos> lineTypesSet = lineTypes.stream().collect(Collectors.toSet());

List<LineTypeEntity> lineTypesEntities = lineTypesSet.stream()
.map(LineTypeInfos::toEntity)
.collect(Collectors.toList());
LOGGER.info("Starting to save {} line types in the catalog", lineTypesEntities.size());
lineTypesCatalogRepository.saveAll(lineTypesEntities);
LOGGER.info("all line types saved in the catalog");
} catch (IOException e) {
throw new UncheckedIOException(e);
}
Expand Down
Loading