Skip to content

Commit

Permalink
Merge pull request #270 from com-pas/develop
Browse files Browse the repository at this point in the history
New Release
  • Loading branch information
AliouDIAITE authored Apr 5, 2023
2 parents 7a7f680 + 7597924 commit 6cb2401
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@
import org.lfenergy.compas.sct.commons.scl.SclElementAdapter;
import org.lfenergy.compas.sct.commons.util.Utils;

import java.util.Comparator;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.*;


/**
Expand Down Expand Up @@ -109,33 +106,33 @@ public AbstractDAIAdapter<?> toAdapter(TDAI childTDAI) {
* @param tExtRefs all the ExtRefs contained in the current LDevice/LLN0
* @return a filled SclReportItem if an error occurs, empty SclReportItem otherwise
*/
public Optional<SclReportItem> updateDaiFromExtRef(List<TExtRef> tExtRefs) {
Optional<SclReportItem> optionalSclReportItem;
public List<SclReportItem> updateDaiFromExtRef(List<TExtRef> tExtRefs) {
List<SclReportItem> sclReportItems = new ArrayList<>();
Optional<TExtRef> tExtRefMinOptional = tExtRefs.stream().min(EXTREF_DESC_SUFFIX_COMPARATOR);
if (tExtRefMinOptional.isPresent() && extractDescSuffix(tExtRefMinOptional.get().getDesc()) == 1) {
TExtRef tExtRefMin = tExtRefMinOptional.get();
String valueSrcRef = createInRefValNominalString(tExtRefMin);
optionalSclReportItem = updateDAI(DA_NAME_SET_SRC_REF, valueSrcRef);
updateDAI(DA_NAME_SET_SRC_REF, valueSrcRef).ifPresent(sclReportItems::add);
if (tExtRefMin.isSetSrcCBName()) {
String valueSrcCb = createInRefValTestString(tExtRefMin);
optionalSclReportItem = updateDAI(DA_NAME_SET_SRC_CB, valueSrcCb);
updateDAI(DA_NAME_SET_SRC_CB, valueSrcCb).ifPresent(sclReportItems::add);
}

Optional<TExtRef> tExtRefMaxOptional = tExtRefs.stream().max(EXTREF_DESC_SUFFIX_COMPARATOR);
if (tExtRefMaxOptional.isPresent() && extractDescSuffix(tExtRefMaxOptional.get().getDesc()) > 1) {
TExtRef tExtRefMax = tExtRefMaxOptional.get();
String valueTstRef = createInRefValNominalString(tExtRefMax);
optionalSclReportItem = updateDAI(DA_NAME_SET_TST_REF, valueTstRef);
updateDAI(DA_NAME_SET_TST_REF, valueTstRef).ifPresent(sclReportItems::add);
if (tExtRefMax.isSetSrcCBName()) {
String valueTstCb = createInRefValTestString(tExtRefMax);
optionalSclReportItem = updateDAI(DA_NAME_SET_TST_CB, valueTstCb);
updateDAI(DA_NAME_SET_TST_CB, valueTstCb).ifPresent(sclReportItems::add);
}
}
} else {
optionalSclReportItem = Optional.of(SclReportItem.warning(getXPath(), "The DOI %s can't be bound with an ExtRef".formatted(getXPath())));
sclReportItems.add(SclReportItem.warning(getXPath(), "The DOI %s can't be bound with an ExtRef".formatted(getXPath())));
}

return optionalSclReportItem;
return sclReportItems;
}

private Optional<SclReportItem> updateDAI(String daName, String value) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;

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

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

private List<TExtRef> getBoundExtRefsByDesc(String desc) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ void updateDaiFromExtRef_should_update_setSrcXX_values_when_ExtRef_desc_suffix_e
TExtRef extRef1 = givenExtRef(1, true);

// When
Optional<SclReportItem> sclReportItems = doiAdapter.updateDaiFromExtRef(List.of(extRef1));
List<SclReportItem> sclReportItems = doiAdapter.updateDaiFromExtRef(List.of(extRef1));

// Then
assertThat(sclReportItems).isEmpty();
Expand All @@ -340,7 +340,7 @@ void updateDaiFromExtRef_should_update_setSrcRef_value_but_not_setSrcCB_when_Ext
TExtRef extRef1 = givenExtRef(1, false);

// When
Optional<SclReportItem> sclReportItems = doiAdapter.updateDaiFromExtRef(List.of(extRef1));
List<SclReportItem> sclReportItems = doiAdapter.updateDaiFromExtRef(List.of(extRef1));

// Then
assertThat(sclReportItems).isEmpty();
Expand Down Expand Up @@ -371,7 +371,7 @@ void updateDaiFromExtRef_should_update_setSrcXX_and_setTstXX_values_when_ExtRef_
TExtRef extRef3 = givenExtRef(3, true);

// When
Optional<SclReportItem> sclReportItems = doiAdapter.updateDaiFromExtRef(List.of(extRef1, extRef3));
List<SclReportItem> sclReportItems = doiAdapter.updateDaiFromExtRef(List.of(extRef1, extRef3));

// Then
assertThat(sclReportItems).isEmpty();
Expand Down Expand Up @@ -423,7 +423,7 @@ void updateDaiFromExtRef_should_update_only_setSrcRef_and_setTstRef_values_when_
TExtRef extRef3 = givenExtRef(3, false);

// When
Optional<SclReportItem> sclReportItems = doiAdapter.updateDaiFromExtRef(List.of(extRef1, extRef3));
List<SclReportItem> sclReportItems = doiAdapter.updateDaiFromExtRef(List.of(extRef1, extRef3));

// Then
assertThat(sclReportItems).isEmpty();
Expand Down Expand Up @@ -451,14 +451,13 @@ void updateDaiFromExtRef_should_return_warning_report_when_none_ExtRef_endin_wit
TExtRef extRef3 = givenExtRef(3, false);

// When
Optional<SclReportItem> sclReportItems = doiAdapter.updateDaiFromExtRef(List.of(extRef3));
List<SclReportItem> sclReportItems = doiAdapter.updateDaiFromExtRef(List.of(extRef3));

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

// When
Optional<SclReportItem> sclReportItems = doiAdapter.updateDaiFromExtRef(List.of(extRef1));
List<SclReportItem> sclReportItems = doiAdapter.updateDaiFromExtRef(List.of(extRef1));

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

// When
Optional<SclReportItem> sclReportItems = doiAdapter.updateDaiFromExtRef(List.of());
List<SclReportItem> sclReportItems = doiAdapter.updateDaiFromExtRef(List.of());

// Then
assertThat(sclReportItems)
.isPresent()
.isNotEmpty();
assertThat(sclReportItems.get().getMessage()).contains("can't be bound with an ExtRef");
assertThat(sclReportItems)
.extracting(SclReportItem::getMessage)
.contains("The DOI /DOI[@name=\"Do\"] can't be bound with an ExtRef");
}

@Test
Expand Down Expand Up @@ -529,7 +529,7 @@ void updateDaiFromExtRef_should_compose_correct_name_when_optional_ExtRef_attrib
extRef3.setDoName("DO_NAME_3");

// When
Optional<SclReportItem> sclReportItems = doiAdapter.updateDaiFromExtRef(List.of(extRef1, extRef3));
List<SclReportItem> sclReportItems = doiAdapter.updateDaiFromExtRef(List.of(extRef1, extRef3));

// Then
assertThat(sclReportItems).isEmpty();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1079,9 +1079,10 @@ void updateDoInRef_should_not_update_setSrcRef_and_setSrcCB_and_setTstRef_and_se
assertThat(finalSetTstRef).isEqualTo(expectedVal);
assertThat(finalSetTstCB).isEqualTo(expectedVal);
assertThat(sclReportItems)
.hasSize(1)
.hasSize(4)
.extracting(SclReportItem::getMessage)
.containsExactly("The DAI cannot be updated");
.containsExactly("The DAI cannot be updated", "The DAI cannot be updated", "The DAI cannot be updated",
"The DAI cannot be updated");
}


Expand Down

0 comments on commit 6cb2401

Please sign in to comment.