Skip to content

Commit c51ab57

Browse files
committed
finalize DAI updating
Signed-off-by: Mohamed Sylla <[email protected]>
1 parent 54798d7 commit c51ab57

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+1560
-343
lines changed

sct-commons/src/main/java/org/lfenergy/compas/sct/commons/Utils.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
import lombok.extern.slf4j.Slf4j;
88

99
import java.lang.reflect.Field;
10+
import java.util.Locale;
11+
import java.util.ResourceBundle;
1012

1113
@Slf4j
1214
public class Utils {
@@ -43,9 +45,8 @@ public static String getMethodName() {
4345
try {
4446
return (new Throwable()).getStackTrace()[2].getMethodName();
4547
} catch (Exception e){
46-
// do nothing
48+
return "-";
4749
}
48-
return "-";
4950
}
5051

5152
public static String leaving(){

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public void validateCB() throws ScdException {
7373

7474
public void validateDestination(SclRootAdapter sclRootAdapter) throws ScdException {
7575
for(TControlWithIEDName.IEDName iedName : iedNames){
76-
IEDAdapter iedAdapter =sclRootAdapter.getIEDAdapter(iedName.getValue());
76+
IEDAdapter iedAdapter =sclRootAdapter.getIEDAdapterByName(iedName.getValue());
7777
LDeviceAdapter lDeviceAdapter = iedAdapter.getLDeviceAdapterByLdInst(iedName.getLdInst())
7878
.orElseThrow(
7979
() -> new ScdException(

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

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
package org.lfenergy.compas.sct.commons.dto;
66

77
import com.fasterxml.jackson.annotation.JsonIgnore;
8+
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
9+
import com.fasterxml.jackson.annotation.JsonProperty;
10+
import com.fasterxml.jackson.annotation.JsonPropertyDescription;
811
import lombok.Getter;
912
import lombok.NoArgsConstructor;
1013
import lombok.Setter;
@@ -28,7 +31,6 @@ public class DaTypeName extends DataTypeName{
2831
private String type;
2932
private TPredefinedBasicTypeEnum bType;
3033
private boolean valImport;
31-
private boolean initValImport; // valImport from DataTypeTemplate
3234
private Map<Long,String> daiValues = new HashMap<>();
3335

3436
public DaTypeName(String daName) {
@@ -54,10 +56,7 @@ public DaTypeName(String name, String names) {
5456
}
5557

5658
public boolean isValImport(){
57-
if(!valImport){
58-
return initValImport;
59-
}
60-
return true;
59+
return valImport;
6160
}
6261

6362
public boolean isUpdatable(){
@@ -71,12 +70,28 @@ public boolean isUpdatable(){
7170
);
7271
}
7372

74-
@JsonIgnore
75-
public void setDaiValues(List<TVal> vals) {
73+
public void addDaiValues(List<TVal> vals) {
7674
if(vals.size() == 1){
7775
daiValues.put(0L,vals.get(0).getValue());
76+
} else {
77+
vals.forEach(tVal -> daiValues.put(tVal.getSGroup(), tVal.getValue()));
78+
}
79+
}
80+
81+
public void addDaiValue(TVal val) {
82+
if(val.getSGroup() == null){
83+
daiValues.put(0L,val.getValue());
84+
} else {
85+
daiValues.put(val.getSGroup(), val.getValue());
86+
}
87+
}
88+
89+
public void addDaiValue(Long sg, String val) {
90+
if(sg == null){
91+
daiValues.put(0L,val);
92+
} else {
93+
daiValues.put(sg, val);
7894
}
79-
vals.forEach(tVal -> daiValues.put(tVal.getSGroup(),tVal.getValue()));
8095
}
8196

8297
@Override

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,15 @@
66

77
import lombok.Getter;
88
import lombok.NoArgsConstructor;
9+
import org.lfenergy.compas.scl2007b4.model.TAnyLN;
910
import org.lfenergy.compas.scl2007b4.model.TDataSet;
11+
import org.lfenergy.compas.sct.commons.scl.ied.AbstractLNAdapter;
1012

1113
import java.util.ArrayList;
14+
import java.util.Collection;
1215
import java.util.Collections;
1316
import java.util.List;
17+
import java.util.Set;
1418
import java.util.stream.Collectors;
1519

1620
@Getter
@@ -35,6 +39,11 @@ public static DataSetInfo from(TDataSet tDataSet) {
3539
return dataSetInfo;
3640
}
3741

42+
public static Set<DataSetInfo> getDataSets(AbstractLNAdapter<? extends TAnyLN> lnAdapter){
43+
return lnAdapter.getDataSet(null)
44+
.stream().map(tDataSet -> DataSetInfo.from(tDataSet)).collect(Collectors.toSet());
45+
}
46+
3847
public void addFCDAInfo(FCDAInfo fcdaInfo){
3948
fcdaInfos.add(fcdaInfo);
4049
}
@@ -46,4 +55,11 @@ public List<FCDAInfo> getFCDAInfos(){
4655
public void setName(String name){
4756
this.name = name;
4857
}
58+
59+
public boolean isValid(){
60+
if(name.length() > 32 || fcdaInfos.isEmpty()){
61+
return false;
62+
}
63+
return fcdaInfos.stream().allMatch(fcdaInfo -> fcdaInfo.isValid());
64+
}
4965
}

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,4 +86,18 @@ public int hashCode() {
8686
public void addStructName(String structName) {
8787
structNames.add(structName);
8888
}
89+
90+
@JsonIgnore
91+
public String getLast(){
92+
int sz = structNames.size();
93+
return sz == 0 ? name : structNames.get(sz -1);
94+
}
95+
96+
public void addName(String name) {
97+
if(isDefined()){
98+
structNames.add(name);
99+
} else {
100+
this.name = name;
101+
}
102+
}
89103
}

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ public class DoTypeName extends DataTypeName {
2323
public DoTypeName(String doName) {
2424
super(doName);
2525
}
26-
2726
public DoTypeName(String ppDoName, String sdoNames) {
2827
super(ppDoName, sdoNames);
2928
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public boolean isWrappedIn(TExtRef tExtRef){
9898
Objects.equals(prefix, tExtRef.getPrefix()) &&
9999
Objects.equals(lnInst, tExtRef.getLnInst()) &&
100100
tExtRef.getLnClass().contains(lnClass) &&
101-
Objects.equals(serviceType, tExtRef.getServiceType());
101+
(tExtRef.getServiceType() == null || Objects.equals(serviceType, tExtRef.getServiceType()));
102102
}
103103

104104
public boolean isNull(){

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

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ public class FCDAInfo {
2424
private String prefix;
2525
private String lnClass;
2626
private String lnInst;
27-
private DataTypeName doName; //doName.[...sdoNames]
28-
private DataTypeName daName; //daName.[...bdaNames]
27+
private DoTypeName doName; //doName.[...sdoNames]
28+
private DaTypeName daName; //daName.[...bdaNames]
2929
private Long ix;
3030

3131
public FCDAInfo(String dataSet, TFCDA tfcda) {
@@ -37,8 +37,8 @@ public FCDAInfo(String dataSet, TFCDA tfcda) {
3737
this.lnClass = tfcda.getLnClass().get(0);
3838
}
3939
lnInst = tfcda.getLnInst();
40-
doName = new DataTypeName(tfcda.getDoName());
41-
daName = new DataTypeName(tfcda.getDaName());
40+
doName = new DoTypeName(tfcda.getDoName());
41+
daName = new DaTypeName(tfcda.getDaName());
4242
ix = tfcda.getIx();
4343
}
4444

@@ -49,21 +49,26 @@ public TFCDA getFCDA(){
4949
tfcda.setFc(fc);
5050
tfcda.setLdInst(ldInst);
5151
tfcda.getLnClass().add(lnClass);
52+
5253
if(!StringUtils.isBlank(lnInst)){
5354
tfcda.setLnInst(lnInst);
5455
}
55-
tfcda.setDoName(doName.toString());
56-
if(daName != null){
56+
57+
if(doName != null && doName.isDefined()){
58+
tfcda.setDaName(doName.toString());
59+
}
60+
61+
if(daName != null && daName.isDefined()){
5762
tfcda.setDaName(daName.toString());
5863
}
64+
5965
if(ix != null){
6066
tfcda.setIx(ix);
6167
}
62-
6368
return tfcda;
6469
}
6570

6671
public boolean isValid() {
67-
return doName != null && !StringUtils.isBlank(doName.toString());
72+
return doName != null && doName.isDefined();
6873
}
6974
}

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

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,14 @@
1010
import org.lfenergy.compas.scl2007b4.model.TAnyLN;
1111
import org.lfenergy.compas.scl2007b4.model.TExtRef;
1212
import org.lfenergy.compas.sct.commons.Utils;
13+
import org.lfenergy.compas.sct.commons.exception.ScdException;
14+
import org.lfenergy.compas.sct.commons.scl.SclRootAdapter;
15+
import org.lfenergy.compas.sct.commons.scl.dtt.DataTypeTemplateAdapter;
16+
import org.lfenergy.compas.sct.commons.scl.dtt.LNodeTypeAdapter;
1317
import org.lfenergy.compas.sct.commons.scl.ied.AbstractLNAdapter;
1418
import org.lfenergy.compas.sct.commons.scl.ied.LDeviceAdapter;
1519
import org.lfenergy.compas.sct.commons.scl.ied.LNAdapter;
1620

17-
import java.util.ArrayList;
1821
import java.util.HashSet;
1922
import java.util.List;
2023
import java.util.Set;
@@ -75,7 +78,27 @@ public static <T extends TAnyLN> LNodeDTO from(AbstractLNAdapter<T> nodeAdapter,
7578
}
7679

7780
if(options.isWithDatSet()) {
78-
lNodeDTO.datSets = nodeAdapter.getDataSet();
81+
lNodeDTO.datSets = DataSetInfo.getDataSets(nodeAdapter);
82+
}
83+
84+
if(options.isWithResumedDtt()) {
85+
DataTypeTemplateAdapter dttAdapter = nodeAdapter.getDataTypeTemplateAdapter();
86+
LNodeTypeAdapter lNodeTypeAdapter = dttAdapter.getLNodeTypeAdapterById(nodeAdapter.getLnType())
87+
.orElseThrow(
88+
() -> new IllegalArgumentException(
89+
String.format(
90+
"Corrupted SCD file: reference to unknown lnType(%s)",
91+
nodeAdapter.getLnType()
92+
)
93+
)
94+
);
95+
ResumedDataTemplate filter = new ResumedDataTemplate();
96+
filter.setLnInst(nodeAdapter.getLNInst());
97+
filter.setLnClass(nodeAdapter.getLNClass());
98+
filter.setPrefix(nodeAdapter.getPrefix());
99+
filter.setLnType(nodeAdapter.getLnType());
100+
List<ResumedDataTemplate> resumedDataTemplateList = lNodeTypeAdapter.getResumedDTTs(filter);
101+
lNodeDTO.addAllResumedDataTemplate(resumedDataTemplateList);
79102
}
80103

81104
if(options.isWithCB()) {

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@
1616
@NoArgsConstructor
1717
public class LogicalNodeOptions {
1818
private boolean withExtRef = false;
19-
//private boolean withResumedDtt = false;
19+
private boolean withResumedDtt = false;
2020
private boolean withCB = false;
2121
private boolean withDatSet = false;
2222

23-
public LogicalNodeOptions(boolean withExtRef/*, boolean withResumedDtt*/, boolean withCB, boolean withDatSet) {
23+
public LogicalNodeOptions(boolean withExtRef, boolean withResumedDtt, boolean withCB, boolean withDatSet) {
2424
this.withExtRef = withExtRef;
25-
//this.withResumedDtt = withResumedDtt;
25+
this.withResumedDtt = withResumedDtt;
2626
this.withCB = withCB;
2727
this.withDatSet = withDatSet;
2828
}

0 commit comments

Comments
 (0)