Skip to content

Commit 42d5f09

Browse files
committed
--Change Specs : No id change for CurrentLimitsData when limits are different
Signed-off-by: basseche <[email protected]>
1 parent 4511d86 commit 42d5f09

File tree

3 files changed

+20
-89
lines changed

3 files changed

+20
-89
lines changed

src/main/java/org/gridsuite/network/map/dto/mapper/LineInfosMapper.java

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -66,18 +66,14 @@ private static LineFormInfos toFormInfos(Identifiable<?> identifiable) {
6666
.b1(line.getB1())
6767
.g2(line.getG2())
6868
.b2(line.getB2())
69-
.properties(getProperties(line));
70-
71-
Pair<String, String> newSelectedOpLimitsGroups = mergeCurrentLimits(line.getOperationalLimitsGroups1(), line.getOperationalLimitsGroups2(),
72-
line.getSelectedOperationalLimitsGroupId1().orElse(null),
73-
line.getSelectedOperationalLimitsGroupId2().orElse(null),
74-
builder::currentLimits);
69+
.properties(getProperties(line))
70+
.selectedOperationalLimitsGroup1(line.getSelectedOperationalLimitsGroupId1().orElse(null))
71+
.selectedOperationalLimitsGroup2(line.getSelectedOperationalLimitsGroupId2().orElse(null));
7572

76-
builder.selectedOperationalLimitsGroup1(!newSelectedOpLimitsGroups.getLeft().isEmpty() ? newSelectedOpLimitsGroups.getLeft() : line.getSelectedOperationalLimitsGroupId1().orElse(null));
77-
builder.selectedOperationalLimitsGroup2(!newSelectedOpLimitsGroups.getRight().isEmpty() ? newSelectedOpLimitsGroups.getRight() : line.getSelectedOperationalLimitsGroupId2().orElse(null));
73+
mergeCurrentLimits(line.getOperationalLimitsGroups1(), line.getOperationalLimitsGroups2(), builder::currentLimits);
7874

79-
buildCurrentLimits(line.getOperationalLimitsGroups1(), line.getSelectedOperationalLimitsGroupId1().orElse(null), newSelectedOpLimitsGroups.getLeft(), builder::currentLimits1);
80-
buildCurrentLimits(line.getOperationalLimitsGroups2(), line.getSelectedOperationalLimitsGroupId2().orElse(null), newSelectedOpLimitsGroups.getRight(), builder::currentLimits2);
75+
buildCurrentLimits(line.getOperationalLimitsGroups1(), builder::currentLimits1);
76+
buildCurrentLimits(line.getOperationalLimitsGroups2(), builder::currentLimits2);
8177

8278
builder.busOrBusbarSectionId1(getBusOrBusbarSection(terminal1))
8379
.busOrBusbarSectionId2(getBusOrBusbarSection(terminal2));

src/main/java/org/gridsuite/network/map/dto/mapper/TwoWindingsTransformerInfosMapper.java

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -78,17 +78,13 @@ private static TwoWindingsTransformerFormInfos toFormInfos(Identifiable<?> ident
7878
builder.q2(nullIfNan(terminal2.getQ()));
7979
builder.i1(nullIfNan(terminal1.getI()));
8080
builder.i2(nullIfNan(terminal2.getI()));
81+
builder.selectedOperationalLimitsGroup1(twoWT.getSelectedOperationalLimitsGroupId1().orElse(null));
82+
builder.selectedOperationalLimitsGroup2(twoWT.getSelectedOperationalLimitsGroupId2().orElse(null));
8183

82-
Pair<String, String> newSelectedOpLimitsGroups = mergeCurrentLimits(twoWT.getOperationalLimitsGroups1(), twoWT.getOperationalLimitsGroups2(),
83-
twoWT.getSelectedOperationalLimitsGroupId1().orElse(null),
84-
twoWT.getSelectedOperationalLimitsGroupId2().orElse(null),
85-
builder::currentLimits);
86-
87-
builder.selectedOperationalLimitsGroup1(!newSelectedOpLimitsGroups.getLeft().isEmpty() ? newSelectedOpLimitsGroups.getLeft() : twoWT.getSelectedOperationalLimitsGroupId1().orElse(null));
88-
builder.selectedOperationalLimitsGroup2(!newSelectedOpLimitsGroups.getRight().isEmpty() ? newSelectedOpLimitsGroups.getRight() : twoWT.getSelectedOperationalLimitsGroupId2().orElse(null));
84+
mergeCurrentLimits(twoWT.getOperationalLimitsGroups1(), twoWT.getOperationalLimitsGroups2(), builder::currentLimits);
8985

90-
buildCurrentLimits(twoWT.getOperationalLimitsGroups1(), twoWT.getSelectedOperationalLimitsGroupId1().orElse(null), newSelectedOpLimitsGroups.getLeft(), builder::currentLimits1);
91-
buildCurrentLimits(twoWT.getOperationalLimitsGroups2(), twoWT.getSelectedOperationalLimitsGroupId2().orElse(null), newSelectedOpLimitsGroups.getRight(), builder::currentLimits2);
86+
buildCurrentLimits(twoWT.getOperationalLimitsGroups1(), builder::currentLimits1);
87+
buildCurrentLimits(twoWT.getOperationalLimitsGroups2(), builder::currentLimits2);
9288

9389
builder.operatingStatus(toOperatingStatus(twoWT));
9490
builder.connectablePosition1(toMapConnectablePosition(twoWT, 1))

src/main/java/org/gridsuite/network/map/dto/utils/ElementUtils.java

Lines changed: 9 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -85,79 +85,31 @@ public static Optional<HvdcOperatorActivePowerRangeInfos> toHvdcOperatorActivePo
8585
.oprFromCS2toCS1(hvdcOperatorActivePowerRange.getOprFromCS2toCS1()).build());
8686
}
8787

88-
public static void buildCurrentLimits(Collection<OperationalLimitsGroup> currentLimits, String oldSelected, String newSelected, Consumer<List<CurrentLimitsData>> build) {
88+
public static void buildCurrentLimits(Collection<OperationalLimitsGroup> currentLimits, Consumer<List<CurrentLimitsData>> build) {
8989

9090
ArrayList<CurrentLimitsData> currentLimitsData = new ArrayList<>(currentLimits.stream()
9191
.map(ElementUtils::operationalLimitsGroupToMapDataCurrentLimits)
9292
.toList());
9393

94-
// if selected operationalLimitsGroups renamed, rename it also here
95-
if (!newSelected.isEmpty()) {
96-
Optional<CurrentLimitsData> limitsGroup = currentLimitsData.stream().filter(l -> l.getId().equals(oldSelected)).findFirst();
97-
if (limitsGroup.isPresent()) {
98-
CurrentLimitsData current = copyCurrentLimitsData(limitsGroup.get(), newSelected);
99-
currentLimitsData.remove(limitsGroup.get());
100-
currentLimitsData.add(current);
101-
}
102-
}
103-
10494
if (!currentLimitsData.isEmpty()) {
10595
build.accept(currentLimitsData);
10696
}
10797
}
10898

109-
private static String generateSetName(String basicName, String suffix, List<CurrentLimitsData> mergedList, List<CurrentLimitsData> otherList) {
110-
111-
boolean nameUsed;
112-
String strIncrement = "";
113-
int increment = 1;
114-
115-
do {
116-
String currentId = basicName + suffix + strIncrement;
117-
if (!mergedList.stream().filter(l -> l.getId().equals(currentId)).toList().isEmpty()
118-
|| !otherList.stream().filter(l -> l.getId().equals(currentId)).toList().isEmpty()) {
119-
nameUsed = true;
120-
increment++;
121-
strIncrement = "(" + increment + ")";
122-
} else {
123-
nameUsed = false;
124-
}
125-
} while (nameUsed);
126-
127-
return basicName + suffix + strIncrement;
128-
}
129-
130-
private static CurrentLimitsData copyCurrentLimitsData(CurrentLimitsData currentLimitsData, CurrentLimitsData.Applicability applicability, String id) {
131-
return CurrentLimitsData.builder()
132-
.id(id.isEmpty() ? currentLimitsData.getId() : id)
133-
.applicability(applicability)
134-
.temporaryLimits(currentLimitsData.getTemporaryLimits())
135-
.permanentLimit(currentLimitsData.getPermanentLimit()).build();
136-
}
137-
13899
private static CurrentLimitsData copyCurrentLimitsData(CurrentLimitsData currentLimitsData, CurrentLimitsData.Applicability applicability) {
139-
return copyCurrentLimitsData(currentLimitsData, applicability, "");
140-
}
141-
142-
private static CurrentLimitsData copyCurrentLimitsData(CurrentLimitsData currentLimitsData, String id) {
143100
return CurrentLimitsData.builder()
144-
.id(id.isEmpty() ? currentLimitsData.getId() : id)
145-
.applicability(currentLimitsData.getApplicability())
101+
.id(currentLimitsData.getId())
102+
.applicability(applicability)
146103
.temporaryLimits(currentLimitsData.getTemporaryLimits())
147104
.permanentLimit(currentLimitsData.getPermanentLimit()).build();
148105
}
149106

150107
/**
151108
* @return id of the selected operation limits group 1 and 2 if they have been renamed
152109
*/
153-
public static Pair<String, String> mergeCurrentLimits(Collection<OperationalLimitsGroup> operationalLimitsGroups1,
110+
public static void mergeCurrentLimits(Collection<OperationalLimitsGroup> operationalLimitsGroups1,
154111
Collection<OperationalLimitsGroup> operationalLimitsGroups2,
155-
String selectedLimitsGroup1, String selectedLimitsGroup2,
156112
Consumer<List<CurrentLimitsData>> build) {
157-
final String orSuffix = "_OR";
158-
final String exSuffix = "_EX";
159-
String changedSelectedLimitsGroup1 = "";
160-
String changedSelectedLimitsGroup2 = "";
161113
List<CurrentLimitsData> mergedLimitsData = new ArrayList<>();
162114

163115
// Build temporary limit from side 1 and 2
@@ -174,13 +126,13 @@ public static Pair<String, String> mergeCurrentLimits(Collection<OperationalLimi
174126
mergedLimitsData.add(copyCurrentLimitsData(currentLimitsData, SIDE1));
175127
}
176128
build.accept(mergedLimitsData);
177-
return Pair.of("", "");
129+
return;
178130
} else if (currentLimitsData1.isEmpty() && !currentLimitsData2.isEmpty()) {
179131
for (CurrentLimitsData currentLimitsData : currentLimitsData2) {
180132
mergedLimitsData.add(copyCurrentLimitsData(currentLimitsData, SIDE2));
181133
}
182134
build.accept(mergedLimitsData);
183-
return Pair.of("", "");
135+
return;
184136
}
185137

186138
// more complex case
@@ -199,23 +151,12 @@ public static Pair<String, String> mergeCurrentLimits(Collection<OperationalLimi
199151
// both sides have limits and limits are equals
200152
if (limitsData.limitsEquals(limitsData2)) {
201153
mergedLimitsData.add(copyCurrentLimitsData(limitsData, EQUIPMENT));
202-
// both side have limits and they are differents : create 2 differents limitset with basename_Or and _Ex
154+
// both side have limits and they are different : create 2 different limit sets with basename_Or and _Ex
203155
} else {
204-
String currentLimitId = limitsData.getId();
205156
// Side 1
206-
String limitId = generateSetName(currentLimitId, orSuffix, mergedLimitsData, currentLimitsData2);
207-
mergedLimitsData.add(copyCurrentLimitsData(limitsData, SIDE1, limitId));
208-
// if name changed and is active limit set change also selected limit set
209-
if (selectedLimitsGroup1.equals(currentLimitId)) {
210-
changedSelectedLimitsGroup1 = limitId;
211-
}
157+
mergedLimitsData.add(copyCurrentLimitsData(limitsData, SIDE1));
212158
// Side 2
213-
limitId = generateSetName(currentLimitId, exSuffix, mergedLimitsData, currentLimitsData2);
214-
mergedLimitsData.add(copyCurrentLimitsData(limitsData2, SIDE2, limitId));
215-
// if name changed and is active limit set change also selected limit set
216-
if (selectedLimitsGroup2.equals(currentLimitId)) {
217-
changedSelectedLimitsGroup2 = limitId;
218-
}
159+
mergedLimitsData.add(copyCurrentLimitsData(limitsData2, SIDE2));
219160
}
220161
}
221162
// remove processed limits from side 2
@@ -233,8 +174,6 @@ public static Pair<String, String> mergeCurrentLimits(Collection<OperationalLimi
233174
if (!mergedLimitsData.isEmpty()) {
234175
build.accept(mergedLimitsData);
235176
}
236-
237-
return Pair.of(changedSelectedLimitsGroup1, changedSelectedLimitsGroup2);
238177
}
239178

240179
public static Optional<StandbyAutomatonInfos> toStandbyAutomaton(StaticVarCompensator staticVarCompensator) {

0 commit comments

Comments
 (0)