Skip to content

Commit e8c5680

Browse files
authored
fix(#239): Exclude DOI Mod-stVal in DAI updatability check (#240)
* fix(#239): Exclude DOI Mod-stVal in DAI updatability check * fix(#239): Comment unit test in error while bug #241 is not fixed Signed-off-by: SaintierFr <[email protected]>
1 parent bf6dddc commit e8c5680

File tree

6 files changed

+289
-67
lines changed

6 files changed

+289
-67
lines changed

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

Lines changed: 24 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@
55
package org.lfenergy.compas.sct.commons.scl.ied;
66

77
import org.lfenergy.compas.scl2007b4.model.TDAI;
8+
import org.lfenergy.compas.scl2007b4.model.TDOI;
89
import org.lfenergy.compas.scl2007b4.model.TPrivate;
910
import org.lfenergy.compas.scl2007b4.model.TVal;
1011
import org.lfenergy.compas.sct.commons.exception.ScdException;
1112
import org.lfenergy.compas.sct.commons.scl.SclElementAdapter;
13+
import org.lfenergy.compas.sct.commons.util.CommonConstants;
1214

1315
import java.util.Map;
14-
import java.util.Optional;
15-
import java.util.stream.Stream;
1616

1717
/**
1818
* A representation of the model object
@@ -35,9 +35,6 @@
3535
* <li>{@link AbstractDAIAdapter#addPrivate(TPrivate) <em>Add <b>TPrivate </b> under this object</em>}</li>
3636
* </ul>
3737
* <li>Checklist functions</li>
38-
* <ul>
39-
* <li>{@link AbstractDAIAdapter#isValImport <em>Check value Of <b>valImport </b> attribute</em>}</li>
40-
* </ul>
4138
* </ol>
4239
*
4340
* @see org.lfenergy.compas.scl2007b4.model.TDAI
@@ -88,13 +85,11 @@ public void setValImport(boolean b) {
8885
currentElem.setValImport(b);
8986
}
9087

91-
/**
92-
* Cheks <em>ValImport</em> boolean value
93-
*
94-
* @return <em>Boolean</em> value of <em>ValImport</em> if define or <em>null</em>
95-
*/
96-
public Boolean isValImport() {
97-
return currentElem.isSetValImport() ? currentElem.isValImport() : null;
88+
private boolean isDOModDAstVal() {
89+
if (parentAdapter.getCurrentElem() instanceof final TDOI tdoi) {
90+
return currentElem.getName().equals(CommonConstants.STVAL) && tdoi.getName().equals(CommonConstants.MOD_DO_NAME);
91+
}
92+
return false;
9893
}
9994

10095
public AbstractDAIAdapter<? extends SclElementAdapter> update(Map<Long, String> daiValues) throws ScdException {
@@ -116,30 +111,33 @@ public AbstractDAIAdapter<? extends SclElementAdapter> update(Map<Long, String>
116111
* @throws ScdException throws when DAI for which SGroup should be updated is not updatable
117112
*/
118113
public void update(Long sGroup, String val) throws ScdException {
119-
if (currentElem.isSetValImport() && !currentElem.isValImport()) {
114+
if (!isDOModDAstVal() && currentElem.isSetValImport() && !currentElem.isValImport()) {
120115
String msg = String.format(
121-
"DAI(%s) cannot be updated : valImport(false)", currentElem.getName()
116+
"DAI(%s) cannot be updated : valImport(false) %s", currentElem.getName(), getXPath()
122117
);
123118
throw new ScdException(msg);
124119
}
125-
Stream<TVal> tValStream = currentElem.getVal().stream();
126120
if (sGroup != null && sGroup != 0) {
127-
Optional<TVal> tVal = tValStream.filter(tValElem -> tValElem.isSetSGroup() &&
128-
sGroup.equals(tValElem.getSGroup()))
129-
.findFirst();
130-
if (tVal.isPresent()) {
131-
tVal.get().setValue(val);
132-
} else {
133-
TVal newTVal = new TVal();
134-
newTVal.setValue(val);
135-
newTVal.setSGroup(sGroup);
136-
currentElem.getVal().add(newTVal);
137-
}
121+
updateSGroupVal(sGroup, val);
138122
} else {
139123
updateVal(val);
140124
}
141125
}
142126

127+
private void updateSGroupVal(Long sGroup, String val) {
128+
currentElem.getVal().stream()
129+
.filter(tValElem -> tValElem.isSetSGroup() && sGroup.equals(tValElem.getSGroup()))
130+
.findFirst()
131+
.orElseGet(
132+
() -> {
133+
TVal newTVal = new TVal();
134+
newTVal.setSGroup(sGroup);
135+
currentElem.getVal().add(newTVal);
136+
return newTVal;
137+
})
138+
.setValue(val);
139+
}
140+
143141
public void updateVal(String s) {
144142
currentElem.getVal().stream().findFirst()
145143
.orElseGet(

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

Lines changed: 21 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -705,46 +705,40 @@ public void updateDAI(@NonNull ResumedDataTemplate rDtt) throws ScdException {
705705
DAITracker.MatchResult matchResult = daiTracker.search();
706706
AbstractDAIAdapter<?> daiAdapter = null;
707707
IDataParentAdapter doiOrSdoiAdapter;
708-
if (matchResult == DAITracker.MatchResult.FULL_MATCH) {
709-
// update
710-
daiAdapter = (AbstractDAIAdapter) daiTracker.getBdaiOrDaiAdapter();
711-
if ((daiAdapter.isValImport() != null && daiAdapter.isValImport()) ||
712-
(daiAdapter.isValImport() == null && rDtt.isUpdatable())) {
713-
daiAdapter.update(daTypeName.getDaiValues());
714-
return;
715-
} else {
716-
throw new ScdException(String.format("DAI (%s -%s) cannot be updated", doTypeName, daTypeName));
717-
}
718-
}
719708

720-
if (rDtt.isUpdatable()) {
709+
if (!rDtt.isUpdatable())
710+
return;
711+
712+
if (rDtt.isUpdatable() && matchResult == DAITracker.MatchResult.FULL_MATCH) {
713+
daiAdapter = (AbstractDAIAdapter) daiTracker.getBdaiOrDaiAdapter();
714+
} else {
721715
doiOrSdoiAdapter = daiTracker.getDoiOrSdoiAdapter();
722-
int idx = daiTracker.getIndexDoType();
716+
int indexDoType = daiTracker.getIndexDoType();
723717
int doSz = doTypeName.getStructNames().size();
724718
if (matchResult == DAITracker.MatchResult.FAILED) {
725719
doiOrSdoiAdapter = addDOI(doTypeName.getName());
726-
idx = 0;
727-
} else if (idx == -1) {
728-
idx = 0;
729-
} else if (idx == doSz - 1) {
730-
idx = doSz;
720+
indexDoType = 0;
721+
} else if (indexDoType == -1) {
722+
indexDoType = 0;
723+
} else if (indexDoType == doSz - 1) {
724+
indexDoType = doSz;
731725
}
732-
for (int i = idx; i < doSz; ++i) {
726+
for (int i = indexDoType; i < doSz; ++i) {
733727
String sdoName = doTypeName.getStructNames().get(i);
734728
doiOrSdoiAdapter = doiOrSdoiAdapter.addSDOI(sdoName);
735729
}
736730

737731
IDataParentAdapter daiOrBdaiAdapter = daiTracker.getDoiOrSdoiAdapter();
738-
idx = daiTracker.getIndexDaType();
732+
int indexDaType = daiTracker.getIndexDaType();
739733
int daSz = daTypeName.getStructNames().size();
740-
if (idx <= -1) {
741-
idx = 0;
742-
} else if (idx == daSz - 1) {
743-
idx = daSz;
734+
if (indexDaType <= -1) {
735+
indexDaType = 0;
736+
} else if (indexDaType == daSz - 1) {
737+
indexDaType = daSz;
744738
}
745-
for (int i = idx; i < daSz; ++i) {
739+
for (int i = indexDaType; i < daSz; ++i) {
746740
String bdaName = daTypeName.getStructNames().get(i);
747-
if (idx == 0) {
741+
if (indexDaType == 0) {
748742
daiOrBdaiAdapter = doiOrSdoiAdapter.addSDOI(daTypeName.getName());
749743
} else if (i == daSz - 1) {
750744
daiAdapter = daiOrBdaiAdapter.addDAI(bdaName, rDtt.isUpdatable());
@@ -755,9 +749,8 @@ public void updateDAI(@NonNull ResumedDataTemplate rDtt) throws ScdException {
755749
if (daiAdapter == null) {
756750
daiAdapter = doiOrSdoiAdapter.addDAI(daTypeName.getName(), rDtt.isUpdatable());
757751
}
758-
759-
daiAdapter.update(daTypeName.getDaiValues());
760752
}
753+
daiAdapter.update(daTypeName.getDaiValues());
761754
}
762755

763756
/**

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

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1037,6 +1037,52 @@ void updateLDeviceStatus_shouldReturnUpdatedFile() {
10371037
assertEquals("off", getLDeviceStatusValue(sclReport.getSclRootAdapter().getCurrentElem(), "IedName3", "LDSUIED").get().getValue());
10381038
}
10391039

1040+
@Test
1041+
void updateLDeviceStatus_shouldReturnUpdatedFile_when_DAI_Mod_DO_stVal_whatever_it_is_updatable_or_not() {
1042+
// Given
1043+
SCL givenScl = SclTestMarshaller.getSCLFromFile("/scd-refresh-lnode/issue_165_enhance_68_Test_Dai_Updatable.scd");
1044+
assertThat(getLDeviceStatusValue(givenScl, "IedName1", "LDSUIED"))
1045+
.map(TVal::getValue)
1046+
.hasValue("off");
1047+
assertThat(getLDeviceStatusValue(givenScl, "IedName2", "LDSUIED"))
1048+
.map(TVal::getValue)
1049+
.hasValue("on");
1050+
assertThat(getLDeviceStatusValue(givenScl, "IedName3", "LDSUIED"))
1051+
.map(TVal::getValue)
1052+
.isNotPresent();
1053+
assertThat(getLDeviceStatusValue(givenScl, "IedName4", "LDSUIED"))
1054+
.map(TVal::getValue)
1055+
.hasValue("on");
1056+
assertThat(getLDeviceStatusValue(givenScl, "IedName5", "LDSUIED"))
1057+
.map(TVal::getValue)
1058+
.hasValue("on");
1059+
1060+
// When
1061+
SclReport sclReport = SclService.updateLDeviceStatus(givenScl);
1062+
1063+
// Then
1064+
assertThat(sclReport.isSuccess()).isTrue();
1065+
assertThat(getLDeviceStatusValue(sclReport.getSclRootAdapter().getCurrentElem(), "IedName1", "LDSUIED"))
1066+
.map(TVal::getValue)
1067+
.hasValue("on");
1068+
1069+
assertThat(getLDeviceStatusValue(sclReport.getSclRootAdapter().getCurrentElem(), "IedName2", "LDSUIED"))
1070+
.map(TVal::getValue)
1071+
.hasValue("off");
1072+
1073+
assertThat(getLDeviceStatusValue(sclReport.getSclRootAdapter().getCurrentElem(), "IedName3", "LDSUIED"))
1074+
.map(TVal::getValue)
1075+
.hasValue("off");
1076+
1077+
assertThat(getLDeviceStatusValue(sclReport.getSclRootAdapter().getCurrentElem(), "IedName4", "LDSUIED"))
1078+
.map(TVal::getValue)
1079+
.hasValue("off");
1080+
1081+
assertThat(getLDeviceStatusValue(sclReport.getSclRootAdapter().getCurrentElem(), "IedName5", "LDSUIED"))
1082+
.map(TVal::getValue)
1083+
.hasValue("off");
1084+
}
1085+
10401086
private Optional<TVal> getLDeviceStatusValue(SCL scl, String iedName, String ldInst) {
10411087
return getValFromDaiName(scl, iedName, ldInst, "Mod", "stVal");
10421088
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,9 @@ void testInnerDAIAdapter() {
5555
DOIAdapter.DAIAdapter daiAdapter = initInnerDAIAdapter("Do", "angRef");
5656

5757
// Then
58-
assertNull(daiAdapter.isValImport());
58+
assertThat(daiAdapter.getCurrentElem().isSetValImport()).isFalse();
5959
daiAdapter.setValImport(true);
60-
assertTrue(daiAdapter.isValImport());
60+
assertThat(daiAdapter.getCurrentElem().isSetValImport()).isTrue();
6161

6262
// test tree map
6363
assertThatThrownBy(() -> daiAdapter.getDataAdapterByName(TOTO)).isInstanceOf(UnsupportedOperationException.class);

0 commit comments

Comments
 (0)