Skip to content
Open
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
Expand Up @@ -14,6 +14,7 @@
import com.powsybl.network.store.server.dto.OperationalLimitsGroupOwnerInfo;
import com.powsybl.network.store.server.dto.OwnerInfo;
import com.powsybl.network.store.server.exceptions.UncheckedSqlException;
import com.powsybl.network.store.server.json.JsonTemporaryLimitsAttributes;
import com.powsybl.network.store.server.json.OperationalLimitsGroupAttributesSqlData;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;
Expand Down Expand Up @@ -129,29 +130,40 @@
private Map<OperationalLimitsGroupOwnerInfo, OperationalLimitsGroupAttributes> innerGetOperationalLimitsGroups(PreparedStatement preparedStmt, int variantNumOverride) throws SQLException {
try (ResultSet resultSet = preparedStmt.executeQuery()) {
Map<OperationalLimitsGroupOwnerInfo, OperationalLimitsGroupAttributes> map = new HashMap<>();
Map<OperationalLimitsGroupOwnerInfo, OperationalLimitsGroupAttributes> olgToMigrate = new HashMap<>();

Check warning on line 133 in network-store-server/src/main/java/com/powsybl/network/store/server/LimitsHandler.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove this unused "olgToMigrate" local variable.

See more on https://sonarcloud.io/project/issues?id=com.powsybl%3Apowsybl-network-store-server&issues=AZ4_lNHZg3RRVkgnBvCZ&open=AZ4_lNHZg3RRVkgnBvCZ&pullRequest=196
while (resultSet.next()) {
OperationalLimitsGroupOwnerInfo owner = new OperationalLimitsGroupOwnerInfo();
// In order, from the QueryCatalog.buildOperationalLimitsGroupQuery SQL query :
// equipmentId, equipmentType, networkUuid, variantNum, side, operationallimitgroupid,
// current_limits_permanent_limit, current_limits_temporary_limits, current_limits_properties,
// apparent_power_limits_permanent_limit, apparent_power_limits_temporary_limits, apparent_power_limits_properties,
// active_power_limits_permanent_limit, active_power_limits_temporary_limits, active_power_limits_properties,
// properties
// 1 equipmentId, 2 equipmentType, 3 networkUuid, 4 variantNum, 5 side, 6 operationallimitgroupid,
// 7 current_limits_permanent_limit, 8 current_limits_temporary_limits, 9 current_limits_properties,
// 10 apparent_power_limits_permanent_limit, 11 apparent_power_limits_temporary_limits, 12 apparent_power_limits_properties,
// 13 active_power_limits_permanent_limit, 14 active_power_limits_temporary_limits, 15 active_power_limits_properties,
// 16 properties, 17 current_limits_temporary_limits_v2.37
owner.setEquipmentId(resultSet.getString(1));
owner.setEquipmentType(ResourceType.valueOf(resultSet.getString(2)));
owner.setNetworkUuid(UUID.fromString(resultSet.getString(3)));
int variantNum = resultSet.getInt(4);

Check warning on line 145 in network-store-server/src/main/java/com/powsybl/network/store/server/LimitsHandler.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove this unused "variantNum" local variable.

See more on https://sonarcloud.io/project/issues?id=com.powsybl%3Apowsybl-network-store-server&issues=AZ4_lNHZg3RRVkgnBvCa&open=AZ4_lNHZg3RRVkgnBvCa&pullRequest=196
owner.setVariantNum(variantNumOverride);
owner.setSide(resultSet.getInt(5));
String operationalLimitsGroupId = resultSet.getString(6);
owner.setOperationalLimitsGroupId(operationalLimitsGroupId);

OperationalLimitsGroupAttributes operationalLimitsGroupAttributes = new OperationalLimitsGroupAttributes();
operationalLimitsGroupAttributes.setId(operationalLimitsGroupId);
LimitsAttributes currentLimits = createLimitsAttributes(
resultSet.getObject(7, Double.class),
resultSet.getString(8),
resultSet.getString(9)
);
LimitsAttributes currentLimits;
// FIXME : clean when all temporary limits are migrated to new column

Check warning on line 154 in network-store-server/src/main/java/com/powsybl/network/store/server/LimitsHandler.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Take the required action to fix the issue indicated by this comment.

See more on https://sonarcloud.io/project/issues?id=com.powsybl%3Apowsybl-network-store-server&issues=AZ3e5_x6NLg40HRgu0Fk&open=AZ3e5_x6NLg40HRgu0Fk&pullRequest=196
if (resultSet.getString(8) != null) {
currentLimits = createOldLimitsAttributes(
resultSet.getObject(7, Double.class),
resultSet.getString(8),
resultSet.getString(9)
);
} else {
currentLimits = createLimitsAttributes(
resultSet.getObject(7, Double.class),
resultSet.getString(17),
resultSet.getString(9));
}
operationalLimitsGroupAttributes.setCurrentLimits(currentLimits);

LimitsAttributes apparentPowerLimits = createLimitsAttributes(
Expand All @@ -174,7 +186,6 @@
});
operationalLimitsGroupAttributes.setProperties(properties);
}

map.put(owner, operationalLimitsGroupAttributes);
}
return map;
Expand All @@ -192,6 +203,31 @@
return null;
}

double permanentLimit = hasPermanentLimit ? permanentLimitData : Double.NaN;
TreeMap<Integer, TemporaryLimitAttributes> temporaryLimits = null;
if (hasTemporaryLimits) {
JsonTemporaryLimitsAttributes jsonTemporaryLimitsAttributes = mapper.readValue(temporaryLimitsData, new TypeReference<>() { });
temporaryLimits = jsonTemporaryLimitsAttributes.convertToTemporaryLimitAttributes();
}

Map<String, String> properties = null;
if (!StringUtils.isEmpty(propertiesData)) {
properties = mapper.readValue(propertiesData, new TypeReference<>() { });
}

return new LimitsAttributes(permanentLimit, temporaryLimits, properties);
}

// FIXME : clean when all temporary limits are migrated to new column

Check warning on line 221 in network-store-server/src/main/java/com/powsybl/network/store/server/LimitsHandler.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Take the required action to fix the issue indicated by this comment.

See more on https://sonarcloud.io/project/issues?id=com.powsybl%3Apowsybl-network-store-server&issues=AZ3e5_x6NLg40HRgu0Fn&open=AZ3e5_x6NLg40HRgu0Fn&pullRequest=196
private LimitsAttributes createOldLimitsAttributes(Double permanentLimitData,
String temporaryLimitsData,
String propertiesData) throws JsonProcessingException {
boolean hasPermanentLimit = permanentLimitData != null && !Double.isNaN(permanentLimitData);
boolean hasTemporaryLimits = temporaryLimitsData != null && !temporaryLimitsData.equals("[]");
if (!hasPermanentLimit && !hasTemporaryLimits) {
return null;
}

double permanentLimit = hasPermanentLimit ? permanentLimitData : Double.NaN;
TreeMap<Integer, TemporaryLimitAttributes> temporaryLimits = null;
if (hasTemporaryLimits) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3588,4 +3588,13 @@
public Optional<Resource<NetworkAttributes>> getNetwork(UUID uuid, int variantNum) {
return Utils.getNetwork(uuid, variantNum, dataSource, mappings, mapper);
}

// FIXME : to revert when migration 2.36 is done

Check warning on line 3592 in network-store-server/src/main/java/com/powsybl/network/store/server/NetworkStoreRepository.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Take the required action to fix the issue indicated by this comment.

See more on https://sonarcloud.io/project/issues?id=com.powsybl%3Apowsybl-network-store-server&issues=AZ4_lNHGg3RRVkgnBvCY&open=AZ4_lNHGg3RRVkgnBvCY&pullRequest=196
public void deleteOperationalLimitsGroups(UUID networkUuid, int variantNum, List<String> equipmentIds) {
limitsHandler.deleteOperationalLimitsGroups(networkUuid, variantNum, equipmentIds);
}

public void insertOperationalLimitsGroups(Map<OperationalLimitsGroupOwnerInfo, OperationalLimitsGroupAttributes> operationalLimitsGroups) {
limitsHandler.insertOperationalLimitsGroups(operationalLimitsGroups);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
static final String GROUP_ID_COLUMN = "operationallimitgroupid";
static final String CURRENT_LIMITS_PERMANENT_LIMIT_COLUMN = "current_limits_permanent_limit";
static final String CURRENT_LIMITS_TEMPORARY_LIMITS_COLUMN = "current_limits_temporary_limits";
// FIXME : clean when all temporary limits are migrated to new column

Check warning on line 22 in network-store-server/src/main/java/com/powsybl/network/store/server/QueryLimitsCatalog.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Take the required action to fix the issue indicated by this comment.

See more on https://sonarcloud.io/project/issues?id=com.powsybl%3Apowsybl-network-store-server&issues=AZ3e5_uTNLg40HRgu0Fi&open=AZ3e5_uTNLg40HRgu0Fi&pullRequest=196
static final String NEW_CURRENT_LIMITS_TEMPORARY_LIMITS_COLUMN = "current_limits_temporary_limits_v237";
static final String CURRENT_LIMITS_PROPERTIES_COLUMN = "current_limits_properties";
static final String APPARENT_POWER_LIMITS_PERMANENT_LIMIT_COLUMN = "apparent_power_limits_permanent_limit";
static final String APPARENT_POWER_LIMITS_TEMPORARY_LIMITS_COLUMN = "apparent_power_limits_temporary_limits";
Expand All @@ -40,13 +42,13 @@
CURRENT_LIMITS_PERMANENT_LIMIT_COLUMN + ", " + CURRENT_LIMITS_TEMPORARY_LIMITS_COLUMN + ", " + CURRENT_LIMITS_PROPERTIES_COLUMN + ", " +
APPARENT_POWER_LIMITS_PERMANENT_LIMIT_COLUMN + ", " + APPARENT_POWER_LIMITS_TEMPORARY_LIMITS_COLUMN + ", " + APPARENT_POWER_LIMITS_PROPERTIES_COLUMN + ", " +
ACTIVE_POWER_LIMITS_PERMANENT_LIMIT_COLUMN + ", " + ACTIVE_POWER_LIMITS_TEMPORARY_LIMITS_COLUMN + ", " + ACTIVE_POWER_LIMITS_PROPERTIES_COLUMN + ", " +
PROPERTIES_COLUMN + ") " +
PROPERTIES_COLUMN + ", " + NEW_CURRENT_LIMITS_TEMPORARY_LIMITS_COLUMN + ") " +
"select " + EQUIPMENT_ID_COLUMN + ", " + EQUIPMENT_TYPE_COLUMN + ", ?, ?, " +
GROUP_ID_COLUMN + ", " + SIDE_COLUMN + ", " +
CURRENT_LIMITS_PERMANENT_LIMIT_COLUMN + ", " + CURRENT_LIMITS_TEMPORARY_LIMITS_COLUMN + ", " + CURRENT_LIMITS_PROPERTIES_COLUMN + ", " +
APPARENT_POWER_LIMITS_PERMANENT_LIMIT_COLUMN + ", " + APPARENT_POWER_LIMITS_TEMPORARY_LIMITS_COLUMN + ", " + APPARENT_POWER_LIMITS_PROPERTIES_COLUMN + ", " +
ACTIVE_POWER_LIMITS_PERMANENT_LIMIT_COLUMN + ", " + ACTIVE_POWER_LIMITS_TEMPORARY_LIMITS_COLUMN + ", " + ACTIVE_POWER_LIMITS_PROPERTIES_COLUMN + ", " +
PROPERTIES_COLUMN +
PROPERTIES_COLUMN + ", " + NEW_CURRENT_LIMITS_TEMPORARY_LIMITS_COLUMN +
" from " + OPERATIONAL_LIMITS_GROUP_TABLE + " where " + NETWORK_UUID_COLUMN +
" = ? and " + VARIANT_NUM_COLUMN + " = ?";
}
Expand Down Expand Up @@ -96,7 +98,7 @@
GROUP_ID_COLUMN + ", " +
SIDE_COLUMN + ", " +
CURRENT_LIMITS_PERMANENT_LIMIT_COLUMN + ", " +
CURRENT_LIMITS_TEMPORARY_LIMITS_COLUMN + ", " +
NEW_CURRENT_LIMITS_TEMPORARY_LIMITS_COLUMN + ", " +
CURRENT_LIMITS_PROPERTIES_COLUMN + ", " +
APPARENT_POWER_LIMITS_PERMANENT_LIMIT_COLUMN + ", " +
APPARENT_POWER_LIMITS_TEMPORARY_LIMITS_COLUMN + ", " +
Expand Down Expand Up @@ -124,7 +126,8 @@
ACTIVE_POWER_LIMITS_PERMANENT_LIMIT_COLUMN + ", " +
ACTIVE_POWER_LIMITS_TEMPORARY_LIMITS_COLUMN + ", " +
ACTIVE_POWER_LIMITS_PROPERTIES_COLUMN + ", " +
PROPERTIES_COLUMN +
PROPERTIES_COLUMN + ", " +
NEW_CURRENT_LIMITS_TEMPORARY_LIMITS_COLUMN +
" from " + OPERATIONAL_LIMITS_GROUP_TABLE + " where " +
NETWORK_UUID_COLUMN + " = ? and " +
VARIANT_NUM_COLUMN + " = ? and " +
Expand All @@ -150,7 +153,8 @@
ACTIVE_POWER_LIMITS_PERMANENT_LIMIT_COLUMN + ", " +
ACTIVE_POWER_LIMITS_TEMPORARY_LIMITS_COLUMN + ", " +
ACTIVE_POWER_LIMITS_PROPERTIES_COLUMN + ", " +
PROPERTIES_COLUMN +
PROPERTIES_COLUMN + ", " +
NEW_CURRENT_LIMITS_TEMPORARY_LIMITS_COLUMN +
" from " + OPERATIONAL_LIMITS_GROUP_TABLE + " where " +
NETWORK_UUID_COLUMN + " = ? and " +
VARIANT_NUM_COLUMN + " = ? and " +
Expand All @@ -177,7 +181,8 @@
ACTIVE_POWER_LIMITS_PERMANENT_LIMIT_COLUMN + ", " +
ACTIVE_POWER_LIMITS_TEMPORARY_LIMITS_COLUMN + ", " +
ACTIVE_POWER_LIMITS_PROPERTIES_COLUMN + ", " +
PROPERTIES_COLUMN +
PROPERTIES_COLUMN + ", " +
NEW_CURRENT_LIMITS_TEMPORARY_LIMITS_COLUMN +
" from " + OPERATIONAL_LIMITS_GROUP_TABLE +
" where " + NETWORK_UUID_COLUMN + " = ? and " + VARIANT_NUM_COLUMN + " = ? " +
" and (" + EQUIPMENT_ID_COLUMN + ", " + GROUP_ID_COLUMN + ", " + SIDE_COLUMN + ") " +
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
/**
* 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/.
*/
package com.powsybl.network.store.server.json;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.powsybl.network.store.model.TemporaryLimitAttributes;
import lombok.Getter;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;

/**
* @author Etienne Lesot <etienne.lesot at rte-france.com>
*/
@Getter
public class JsonTemporaryLimitsAttributes {
private final String[] n;
private Object[] d;
private Object[] v;
@JsonInclude(JsonInclude.Include.NON_NULL)
private Integer[] f;
@JsonInclude(JsonInclude.Include.NON_NULL)
private Map<String, String>[] p;

public JsonTemporaryLimitsAttributes(String[] names, List<Integer> acceptableDurations, List<Double> values, List<Boolean> fictitious, List<Map<String, String>> properties) {
this.n = names;
setAcceptableDuration(acceptableDurations);
setValues(values);
setFictitious(fictitious);
setProperties(properties);
}

private void setAcceptableDuration(List<Integer> acceptableDurations) {
if (acceptableDurations == null) {
this.d = null;
return;
}
this.d = acceptableDurations.stream().map(acceptableDuration -> acceptableDuration == Integer.MAX_VALUE ? "MAX" : acceptableDuration).toArray();
}

private void setValues(List<Double> values) {
if (values == null) {
this.v = null;
return;
}
this.v = values.stream().map(val -> {
if (val == Double.MAX_VALUE) {
return "MAXD";
} else if (val == Float.MAX_VALUE) {
return "MAXF";
} else {
return val;
}
}).toArray();
}

private void setFictitious(List<Boolean> fictitious) {
if (fictitious == null) {
this.f = null;
return;
}
boolean areAllFictitiousFalse = fictitious.stream().allMatch(m -> m != null && !m);
this.f = areAllFictitiousFalse ? null : fictitious.stream().map(m -> Boolean.TRUE.equals(m) ? 1 : 0).toArray(Integer[]::new);

Check warning on line 69 in network-store-server/src/main/java/com/powsybl/network/store/server/json/JsonTemporaryLimitsAttributes.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Extract this nested ternary operation into an independent statement.

See more on https://sonarcloud.io/project/issues?id=com.powsybl%3Apowsybl-network-store-server&issues=AZ4_lNEEg3RRVkgnBvCW&open=AZ4_lNEEg3RRVkgnBvCW&pullRequest=196
}

private void setProperties(List<Map<String, String>> properties) {
if (properties == null) {
this.p = null;
return;
}
boolean hasNoProperties = properties.stream().allMatch(m -> m != null && m.isEmpty());
this.p = hasNoProperties ? null : properties.toArray(Map[]::new);
}

public TreeMap<Integer, TemporaryLimitAttributes> convertToTemporaryLimitAttributes() {

Check warning on line 81 in network-store-server/src/main/java/com/powsybl/network/store/server/json/JsonTemporaryLimitsAttributes.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

The return type of this method should be an interface such as "SortedMap" rather than the implementation "TreeMap".

See more on https://sonarcloud.io/project/issues?id=com.powsybl%3Apowsybl-network-store-server&issues=AZ3edWFgPbjRN7U_jmBB&open=AZ3edWFgPbjRN7U_jmBB&pullRequest=196

Check failure on line 81 in network-store-server/src/main/java/com/powsybl/network/store/server/json/JsonTemporaryLimitsAttributes.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Refactor this method to reduce its Cognitive Complexity from 18 to the 15 allowed.

See more on https://sonarcloud.io/project/issues?id=com.powsybl%3Apowsybl-network-store-server&issues=AZ4XJ26CqNj55wWm1U-a&open=AZ4XJ26CqNj55wWm1U-a&pullRequest=196
TreeMap<Integer, TemporaryLimitAttributes> result = new TreeMap<>();
for (int i = 0; i < n.length; i++) {
Double value = Double.NaN;
if (v[i] instanceof String) {
if (v[i].equals("MAXD")) {
value = Double.MAX_VALUE;
} else if (v[i].equals("MAXF")) {
value = (double) Float.MAX_VALUE;
}
} else {
value = (Double) v[i];
}
Integer duration;
if (d[i] instanceof String && d[i].equals("MAX")) {
duration = Integer.MAX_VALUE;
} else {
assert d[i] instanceof Integer;
duration = (Integer) d[i];
}
boolean fictitious = false;
if (f != null && f.length != 0) {
fictitious = f[i] == 1;
}
Map<String, String> properties = new HashMap<>();
if (p != null && p.length != 0) {
properties = p[i];
}
result.put(duration, new TemporaryLimitAttributes(n[i], value, duration, fictitious, properties));
}
return result;
}
}
Loading
Loading