Skip to content

Commit 6cb2401

Browse files
authored
Merge pull request #270 from com-pas/develop
New Release
2 parents 7a7f680 + 7597924 commit 6cb2401

File tree

4 files changed

+31
-31
lines changed

4 files changed

+31
-31
lines changed

sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/ied/DOIAdapter.java

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,7 @@
1212
import org.lfenergy.compas.sct.commons.scl.SclElementAdapter;
1313
import org.lfenergy.compas.sct.commons.util.Utils;
1414

15-
import java.util.Comparator;
16-
import java.util.List;
17-
import java.util.Objects;
18-
import java.util.Optional;
15+
import java.util.*;
1916

2017

2118
/**
@@ -109,33 +106,33 @@ public AbstractDAIAdapter<?> toAdapter(TDAI childTDAI) {
109106
* @param tExtRefs all the ExtRefs contained in the current LDevice/LLN0
110107
* @return a filled SclReportItem if an error occurs, empty SclReportItem otherwise
111108
*/
112-
public Optional<SclReportItem> updateDaiFromExtRef(List<TExtRef> tExtRefs) {
113-
Optional<SclReportItem> optionalSclReportItem;
109+
public List<SclReportItem> updateDaiFromExtRef(List<TExtRef> tExtRefs) {
110+
List<SclReportItem> sclReportItems = new ArrayList<>();
114111
Optional<TExtRef> tExtRefMinOptional = tExtRefs.stream().min(EXTREF_DESC_SUFFIX_COMPARATOR);
115112
if (tExtRefMinOptional.isPresent() && extractDescSuffix(tExtRefMinOptional.get().getDesc()) == 1) {
116113
TExtRef tExtRefMin = tExtRefMinOptional.get();
117114
String valueSrcRef = createInRefValNominalString(tExtRefMin);
118-
optionalSclReportItem = updateDAI(DA_NAME_SET_SRC_REF, valueSrcRef);
115+
updateDAI(DA_NAME_SET_SRC_REF, valueSrcRef).ifPresent(sclReportItems::add);
119116
if (tExtRefMin.isSetSrcCBName()) {
120117
String valueSrcCb = createInRefValTestString(tExtRefMin);
121-
optionalSclReportItem = updateDAI(DA_NAME_SET_SRC_CB, valueSrcCb);
118+
updateDAI(DA_NAME_SET_SRC_CB, valueSrcCb).ifPresent(sclReportItems::add);
122119
}
123120

124121
Optional<TExtRef> tExtRefMaxOptional = tExtRefs.stream().max(EXTREF_DESC_SUFFIX_COMPARATOR);
125122
if (tExtRefMaxOptional.isPresent() && extractDescSuffix(tExtRefMaxOptional.get().getDesc()) > 1) {
126123
TExtRef tExtRefMax = tExtRefMaxOptional.get();
127124
String valueTstRef = createInRefValNominalString(tExtRefMax);
128-
optionalSclReportItem = updateDAI(DA_NAME_SET_TST_REF, valueTstRef);
125+
updateDAI(DA_NAME_SET_TST_REF, valueTstRef).ifPresent(sclReportItems::add);
129126
if (tExtRefMax.isSetSrcCBName()) {
130127
String valueTstCb = createInRefValTestString(tExtRefMax);
131-
optionalSclReportItem = updateDAI(DA_NAME_SET_TST_CB, valueTstCb);
128+
updateDAI(DA_NAME_SET_TST_CB, valueTstCb).ifPresent(sclReportItems::add);
132129
}
133130
}
134131
} else {
135-
optionalSclReportItem = Optional.of(SclReportItem.warning(getXPath(), "The DOI %s can't be bound with an ExtRef".formatted(getXPath())));
132+
sclReportItems.add(SclReportItem.warning(getXPath(), "The DOI %s can't be bound with an ExtRef".formatted(getXPath())));
136133
}
137134

138-
return optionalSclReportItem;
135+
return sclReportItems;
139136
}
140137

141138
private Optional<SclReportItem> updateDAI(String daName, String value) {

sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/ied/LN0Adapter.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import java.util.List;
1616
import java.util.Optional;
1717
import java.util.Set;
18+
import java.util.stream.Collectors;
1819

1920
import static org.lfenergy.compas.sct.commons.util.CommonConstants.*;
2021

@@ -265,9 +266,10 @@ public List<SclReportItem> updateDoInRef() {
265266
.map(doiAdapter -> doiAdapter.getDataAdapterByName(DAI_NAME_PURPOSE).getCurrentElem().getVal().stream()
266267
.findFirst()
267268
.map(tVal -> doiAdapter.updateDaiFromExtRef(getBoundExtRefsByDesc(tVal.getValue())))
268-
.orElse(Optional.of(SclReportItem.warning(getXPath(), "The DOI %s can't be bound with an ExtRef".formatted(getXPath())))))
269-
.flatMap(Optional::stream)
270-
.toList();
269+
.orElse(List.of(SclReportItem.warning(getXPath(), "The DOI %s can't be bound with an ExtRef".formatted(getXPath()))))
270+
)
271+
.flatMap(List::stream)
272+
.collect(Collectors.toList());
271273
}
272274

273275
private List<TExtRef> getBoundExtRefsByDesc(String desc) {

sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/ied/DOIAdapterTest.java

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ void updateDaiFromExtRef_should_update_setSrcXX_values_when_ExtRef_desc_suffix_e
315315
TExtRef extRef1 = givenExtRef(1, true);
316316

317317
// When
318-
Optional<SclReportItem> sclReportItems = doiAdapter.updateDaiFromExtRef(List.of(extRef1));
318+
List<SclReportItem> sclReportItems = doiAdapter.updateDaiFromExtRef(List.of(extRef1));
319319

320320
// Then
321321
assertThat(sclReportItems).isEmpty();
@@ -340,7 +340,7 @@ void updateDaiFromExtRef_should_update_setSrcRef_value_but_not_setSrcCB_when_Ext
340340
TExtRef extRef1 = givenExtRef(1, false);
341341

342342
// When
343-
Optional<SclReportItem> sclReportItems = doiAdapter.updateDaiFromExtRef(List.of(extRef1));
343+
List<SclReportItem> sclReportItems = doiAdapter.updateDaiFromExtRef(List.of(extRef1));
344344

345345
// Then
346346
assertThat(sclReportItems).isEmpty();
@@ -371,7 +371,7 @@ void updateDaiFromExtRef_should_update_setSrcXX_and_setTstXX_values_when_ExtRef_
371371
TExtRef extRef3 = givenExtRef(3, true);
372372

373373
// When
374-
Optional<SclReportItem> sclReportItems = doiAdapter.updateDaiFromExtRef(List.of(extRef1, extRef3));
374+
List<SclReportItem> sclReportItems = doiAdapter.updateDaiFromExtRef(List.of(extRef1, extRef3));
375375

376376
// Then
377377
assertThat(sclReportItems).isEmpty();
@@ -423,7 +423,7 @@ void updateDaiFromExtRef_should_update_only_setSrcRef_and_setTstRef_values_when_
423423
TExtRef extRef3 = givenExtRef(3, false);
424424

425425
// When
426-
Optional<SclReportItem> sclReportItems = doiAdapter.updateDaiFromExtRef(List.of(extRef1, extRef3));
426+
List<SclReportItem> sclReportItems = doiAdapter.updateDaiFromExtRef(List.of(extRef1, extRef3));
427427

428428
// Then
429429
assertThat(sclReportItems).isEmpty();
@@ -451,14 +451,13 @@ void updateDaiFromExtRef_should_return_warning_report_when_none_ExtRef_endin_wit
451451
TExtRef extRef3 = givenExtRef(3, false);
452452

453453
// When
454-
Optional<SclReportItem> sclReportItems = doiAdapter.updateDaiFromExtRef(List.of(extRef3));
454+
List<SclReportItem> sclReportItems = doiAdapter.updateDaiFromExtRef(List.of(extRef3));
455455

456456
// Then
457457
assertThat(sclReportItems)
458-
.isPresent()
459-
.isNotEmpty();
460-
assertThat(sclReportItems.get().getMessage())
461-
.contains("can't be bound with an ExtRef");
458+
.isNotEmpty()
459+
.extracting(SclReportItem::getMessage)
460+
.contains("The DOI /DOI[@name=\"Do\"] can't be bound with an ExtRef");
462461
assertThat(doiAdapter.getDataAdapterByName(DOIAdapter.DA_NAME_SET_SRC_REF)).isNotNull();
463462
assertThat(getDaiValOfDoi(doiAdapter, DOIAdapter.DA_NAME_SET_SRC_REF)).isNotPresent();
464463
}
@@ -471,7 +470,7 @@ void updateDaiFromExtRef_should_create_DAI_when_no_DAI_name_setSrcRef() {
471470
TExtRef extRef1 = givenExtRef(1, false);
472471

473472
// When
474-
Optional<SclReportItem> sclReportItems = doiAdapter.updateDaiFromExtRef(List.of(extRef1));
473+
List<SclReportItem> sclReportItems = doiAdapter.updateDaiFromExtRef(List.of(extRef1));
475474

476475
// Then
477476
assertThat(sclReportItems).isEmpty();
@@ -489,13 +488,14 @@ void updateDaiFromExtRef_should_return_filled_ReportItem_when_no_ExtRef_in_LNode
489488
DOIAdapter doiAdapter = daiAdapter.getParentAdapter();
490489

491490
// When
492-
Optional<SclReportItem> sclReportItems = doiAdapter.updateDaiFromExtRef(List.of());
491+
List<SclReportItem> sclReportItems = doiAdapter.updateDaiFromExtRef(List.of());
493492

494493
// Then
495494
assertThat(sclReportItems)
496-
.isPresent()
497495
.isNotEmpty();
498-
assertThat(sclReportItems.get().getMessage()).contains("can't be bound with an ExtRef");
496+
assertThat(sclReportItems)
497+
.extracting(SclReportItem::getMessage)
498+
.contains("The DOI /DOI[@name=\"Do\"] can't be bound with an ExtRef");
499499
}
500500

501501
@Test
@@ -529,7 +529,7 @@ void updateDaiFromExtRef_should_compose_correct_name_when_optional_ExtRef_attrib
529529
extRef3.setDoName("DO_NAME_3");
530530

531531
// When
532-
Optional<SclReportItem> sclReportItems = doiAdapter.updateDaiFromExtRef(List.of(extRef1, extRef3));
532+
List<SclReportItem> sclReportItems = doiAdapter.updateDaiFromExtRef(List.of(extRef1, extRef3));
533533

534534
// Then
535535
assertThat(sclReportItems).isEmpty();

sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/ied/LN0AdapterTest.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1079,9 +1079,10 @@ void updateDoInRef_should_not_update_setSrcRef_and_setSrcCB_and_setTstRef_and_se
10791079
assertThat(finalSetTstRef).isEqualTo(expectedVal);
10801080
assertThat(finalSetTstCB).isEqualTo(expectedVal);
10811081
assertThat(sclReportItems)
1082-
.hasSize(1)
1082+
.hasSize(4)
10831083
.extracting(SclReportItem::getMessage)
1084-
.containsExactly("The DAI cannot be updated");
1084+
.containsExactly("The DAI cannot be updated", "The DAI cannot be updated", "The DAI cannot be updated",
1085+
"The DAI cannot be updated");
10851086
}
10861087

10871088

0 commit comments

Comments
 (0)