Skip to content

Commit 62aeade

Browse files
authored
Merge pull request #250 from com-pas/241-updatedai-val-does-not-produce-subelements-sdi-as-expected
fix(#241): updateDai does not create DOI SDI DAI as expected
2 parents 2258b1a + 94ca16f commit 62aeade

File tree

18 files changed

+890
-576
lines changed

18 files changed

+890
-576
lines changed

sct-commons/src/main/java/org/lfenergy/compas/sct/commons/dto/ResumedDataTemplate.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import com.fasterxml.jackson.annotation.JsonIgnore;
88
import lombok.*;
99
import org.lfenergy.compas.scl2007b4.model.*;
10+
import org.lfenergy.compas.sct.commons.util.SclConstructorHelper;
1011

1112
import java.util.ArrayList;
1213
import java.util.List;
@@ -50,7 +51,7 @@ public class ResumedDataTemplate {
5051
private DaTypeName daName = new DaTypeName("");
5152

5253
/**
53-
* Copies sumarized DataTypeTemplate informations to another one
54+
* Copies summarized DataTypeTemplate information to another one
5455
* @param dtt input
5556
* @return Updated ResumedDataTemplate object
5657
*/
@@ -89,7 +90,7 @@ public String getObjRef(String iedName, String ldInst){
8990
}
9091

9192
/**
92-
* Gets LNode reference informations
93+
* Gets LNode reference information
9394
* @return String LNode information concatenated
9495
*/
9596
@JsonIgnore
@@ -335,10 +336,13 @@ public boolean isValImport(){
335336
return daName.isValImport();
336337
}
337338

339+
/**
340+
* Set Val of DA
341+
* @param daiValue daiValue to set
342+
* @return this
343+
*/
338344
public ResumedDataTemplate setVal(String daiValue) {
339-
TVal newDaiVal = new TVal();
340-
newDaiVal.setValue(daiValue);
341-
this.setDaiValues(List.of(newDaiVal));
345+
this.setDaiValues(List.of(SclConstructorHelper.newVal(daiValue)));
342346
return this;
343347
}
344348

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

Lines changed: 17 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -7,29 +7,23 @@
77
import org.lfenergy.compas.scl2007b4.model.TDAI;
88
import org.lfenergy.compas.scl2007b4.model.TDOI;
99
import org.lfenergy.compas.scl2007b4.model.TPrivate;
10-
import org.lfenergy.compas.scl2007b4.model.TVal;
1110
import org.lfenergy.compas.sct.commons.exception.ScdException;
1211
import org.lfenergy.compas.sct.commons.scl.SclElementAdapter;
1312
import org.lfenergy.compas.sct.commons.util.CommonConstants;
1413

1514
import java.util.Map;
1615

16+
import static org.lfenergy.compas.sct.commons.util.SclConstructorHelper.newVal;
17+
1718
/**
1819
* A representation of the model object
1920
* <em><b>{@link org.lfenergy.compas.sct.commons.scl.ied.AbstractDAIAdapter AbstractDAIAdapter}</b></em>.
2021
* <p>
2122
* The following features are supported:
2223
* </p>
2324
* <ol>
24-
* <li>Adapter</li>
25-
* <ul>
26-
* <li>{@link AbstractDAIAdapter#getStructuredDataAdapterByName(String) <em>Returns the value of the <b>Child Adapter </b>object reference</em>}</li>
27-
* <li>{@link AbstractDAIAdapter#getDataAdapterByName(String) <em>Returns the value of the <b>Child Adapter </b>object reference By Name</em>}</li>
28-
* </ul>
2925
* <li>Principal functions</li>
3026
* <ul>
31-
* <li>{@link AbstractDAIAdapter#addDAI(String) <em>Add <b>TDAI </b> under this object</em>}</li>
32-
* <li>{@link AbstractDAIAdapter#addSDOI(String) <em>Add <b>TSDI </b> under this object</em>}</li>
3327
* <li>{@link AbstractDAIAdapter#update(Long, String) <em>Update <b>TDAI</b> (sGroup, value)</em>}</li>
3428
* <li>{@link AbstractDAIAdapter#update(Map) <em>Update Many <b>TDAI</b> (sGroup, value)</em>}</li>
3529
* <li>{@link AbstractDAIAdapter#addPrivate(TPrivate) <em>Add <b>TPrivate </b> under this object</em>}</li>
@@ -52,30 +46,6 @@ protected AbstractDAIAdapter(P parentAdapter, TDAI currentElem) {
5246
super(parentAdapter, currentElem);
5347
}
5448

55-
/**
56-
* Gets SDI from DAI by name
57-
*
58-
* @param sName SDI name
59-
* @param <S> expected class type
60-
* @return <em>IDataAdapter</em> related object
61-
* @throws ScdException throws when specified SDI not present in DAI
62-
*/
63-
public <S extends IDataAdapter> S getStructuredDataAdapterByName(String sName) throws ScdException {
64-
throw new UnsupportedOperationException("DAI doesn't have any SDI");
65-
}
66-
67-
/**
68-
* Gets DataAdapter by DAI
69-
*
70-
* @param sName DAI name
71-
* @param <S> expected class type
72-
* @return <em>IDataAdapter</em> related object
73-
* @throws ScdException throws when specified DAI unknown
74-
*/
75-
public <S extends IDataAdapter> S getDataAdapterByName(String sName) throws ScdException {
76-
throw new UnsupportedOperationException("DAI doesn't have any DAI");
77-
}
78-
7949
/**
8050
* Sets <em>ValImport</em> value
8151
*
@@ -104,7 +74,7 @@ public AbstractDAIAdapter<? extends SclElementAdapter> update(Map<Long, String>
10474
}
10575

10676
/**
107-
* Updates DAI SGroup value
77+
* Updates DAI SGroup value. This method checks if DAI is updatable.
10878
*
10979
* @param sGroup SGroup to update
11080
* @param val value
@@ -118,42 +88,31 @@ public void update(Long sGroup, String val) throws ScdException {
11888
throw new ScdException(msg);
11989
}
12090
if (sGroup != null && sGroup != 0) {
121-
updateSGroupVal(sGroup, val);
91+
setSGroupVal(sGroup, val);
12292
} else {
123-
updateVal(val);
93+
setVal(val);
12494
}
12595
}
12696

127-
private void updateSGroupVal(Long sGroup, String val) {
97+
private void setSGroupVal(Long sGroup, String value) {
12898
currentElem.getVal().stream()
12999
.filter(tValElem -> tValElem.isSetSGroup() && sGroup.equals(tValElem.getSGroup()))
130100
.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);
101+
.ifPresentOrElse(
102+
tVal -> tVal.setValue(value),
103+
() -> currentElem.getVal().add(newVal(value, sGroup)));
139104
}
140105

141-
public void updateVal(String s) {
106+
/**
107+
* Set Val (without sGroup) for DAI without checking if DAI is updatable
108+
* @param value new value
109+
*/
110+
public void setVal(String value) {
142111
currentElem.getVal().stream().findFirst()
143-
.orElseGet(
144-
() -> {
145-
TVal newTVal = new TVal();
146-
currentElem.getVal().add(newTVal);
147-
return newTVal;
148-
})
149-
.setValue(s);
150-
}
112+
.ifPresentOrElse(
113+
tVal -> tVal.setValue(value),
114+
() -> currentElem.getVal().add(newVal(value)));
151115

152-
public IDataAdapter addDAI(String name) {
153-
throw new UnsupportedOperationException("DAI cannot contain an SDI");
154116
}
155117

156-
public IDataAdapter addSDOI(String sdoName) {
157-
throw new UnsupportedOperationException("DAI cannot contain an DAI");
158-
}
159118
}

0 commit comments

Comments
 (0)