Skip to content

Commit a2192f3

Browse files
committed
feat(#563): DataTypeTemplatesService - replace getFilteredDoLinkedToDa by getAllDoLinkedToDa
Signed-off-by: massifben <[email protected]>
1 parent 58d0137 commit a2192f3

File tree

13 files changed

+381
-368
lines changed

13 files changed

+381
-368
lines changed

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

Lines changed: 45 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,12 @@
44

55
package org.lfenergy.compas.sct.commons;
66

7-
import org.apache.commons.lang3.StringUtils;
87
import org.lfenergy.compas.scl2007b4.model.*;
98
import org.lfenergy.compas.sct.commons.api.DataTypeTemplateReader;
109
import org.lfenergy.compas.sct.commons.domain.DataAttribute;
1110
import org.lfenergy.compas.sct.commons.domain.DataObject;
11+
import org.lfenergy.compas.sct.commons.domain.DataRef;
1212
import org.lfenergy.compas.sct.commons.domain.DoLinkedToDa;
13-
import org.lfenergy.compas.sct.commons.domain.DoLinkedToDaFilter;
1413

1514
import java.util.ArrayList;
1615
import java.util.List;
@@ -31,58 +30,58 @@ public class DataTypeTemplatesService implements DataTypeTemplateReader {
3130
@Override
3231
public Stream<DoLinkedToDa> getAllDoLinkedToDa(TDataTypeTemplates dtt) {
3332
return lnodeTypeService.getLnodeTypes(dtt)
34-
.flatMap(tlNodeType -> {
35-
DoLinkedToDa doLinkedToDa = new DoLinkedToDa(new DataObject(), new DataAttribute());
36-
return tlNodeType.getDO()
37-
.stream()
38-
.map(tdo -> doTypeService.findDoType(dtt, tdo.getType())
39-
.map(doType -> {
40-
doLinkedToDa.dataObject().setDoName(tdo.getName());
41-
return doTypeService.getAllSDOLinkedToDa(dtt, doType, doLinkedToDa).stream();
42-
}))
43-
.filter(Optional::isPresent)
44-
.flatMap(Optional::orElseThrow);
45-
});
33+
.flatMap(tlNodeType -> tlNodeType.getDO()
34+
.stream()
35+
.flatMap(tdo -> getAllDoLinkedToDa(dtt, tdo)));
4636
}
4737

4838
@Override
49-
public Stream<DoLinkedToDa> getFilteredDoLinkedToDa(TDataTypeTemplates dtt, String lNodeTypeId, DoLinkedToDaFilter doLinkedToDaFilter) {
39+
public Stream<DoLinkedToDa> getAllDoLinkedToDa(TDataTypeTemplates dtt, String lNodeTypeId) {
40+
// Filter on LNodeType.Id
5041
return lnodeTypeService.findLnodeType(dtt, lNodeTypeId)
5142
.stream()
52-
.flatMap(tlNodeType -> doService.getFilteredDos(tlNodeType, tdo -> StringUtils.isBlank(doLinkedToDaFilter.doName())
53-
|| doLinkedToDaFilter.doName().equals(tdo.getName()))
54-
.flatMap(tdo -> {
55-
DataObject dataObject = new DataObject();
56-
dataObject.setDoName(tdo.getName());
57-
DoLinkedToDa doLinkedToDa = new DoLinkedToDa(dataObject, new DataAttribute());
58-
return doTypeService.findDoType(dtt, tdo.getType())
59-
.stream()
60-
.flatMap(tdoType -> {
61-
doLinkedToDa.dataObject().setCdc(tdoType.getCdc());
62-
return doTypeService.getAllSDOLinkedToDa(dtt, tdoType, doLinkedToDa).stream()
63-
.filter(doLinkedToDa1 -> StringUtils.isBlank(doLinkedToDaFilter.doName())
64-
|| (doLinkedToDa1.getDoRef().startsWith(doLinkedToDaFilter.getDoRef()) && StringUtils.isBlank(doLinkedToDaFilter.daName()))
65-
|| doLinkedToDa1.getDaRef().startsWith(doLinkedToDaFilter.getDaRef()));
66-
});
67-
}));
43+
.flatMap(tlNodeType -> doService.getDos(tlNodeType)
44+
.flatMap(tdo -> getAllDoLinkedToDa(dtt, tdo)));
6845
}
6946

7047
@Override
71-
public Optional<DoLinkedToDa> findDoLinkedToDa(TDataTypeTemplates dtt, String lNodeTypeId, DoLinkedToDaFilter doLinkedToDaFilter) {
72-
List<String> dataRefList = new ArrayList<>(doLinkedToDaFilter.sdoNames());
73-
dataRefList.addAll(doLinkedToDaFilter.bdaNames());
48+
public Stream<DoLinkedToDa> getAllDoLinkedToDa(TDataTypeTemplates dtt, String lNodeTypeId, String doName) {
49+
// Filter on LNodeType.Id
50+
return lnodeTypeService.findLnodeType(dtt, lNodeTypeId)
51+
.stream()
52+
// Filter on DO.name
53+
.flatMap(tlNodeType -> doService.getFilteredDos(tlNodeType, tdo -> tdo.getName().equals(doName)))
54+
.flatMap(tdo -> getAllDoLinkedToDa(dtt, tdo));
55+
}
56+
57+
private Stream<DoLinkedToDa> getAllDoLinkedToDa(TDataTypeTemplates dtt, TDO tdo) {
58+
DataObject dataObject = new DataObject();
59+
dataObject.setDoName(tdo.getName());
60+
DoLinkedToDa doLinkedToDa = new DoLinkedToDa(dataObject, new DataAttribute());
61+
return doTypeService.findDoType(dtt, tdo.getType())
62+
.stream()
63+
.flatMap(tdoType -> {
64+
doLinkedToDa.dataObject().setCdc(tdoType.getCdc());
65+
return doTypeService.getAllSDOLinkedToDa(dtt, tdoType, doLinkedToDa).stream();
66+
});
67+
}
68+
69+
@Override
70+
public Optional<DoLinkedToDa> findDoLinkedToDa(TDataTypeTemplates dtt, String lNodeTypeId, DataRef dataRef) {
71+
List<String> dataRefList = new ArrayList<>(dataRef.sdoNames());
72+
dataRefList.addAll(dataRef.bdaNames());
7473

7574
return lnodeTypeService.findLnodeType(dtt, lNodeTypeId)
76-
.flatMap(lNodeType -> doService.findDo(lNodeType, doLinkedToDaFilter.doName())
75+
.flatMap(lNodeType -> doService.findDo(lNodeType, dataRef.doName())
7776
// Search DoType for each DO
7877
.flatMap(tdo -> doTypeService.findDoType(dtt, tdo.getType())
7978
.flatMap(tdoType -> {
8079
// Search last DoType from DOType (SDO) > DOType (SDO)
8180
TDOType lastDoType = findDOTypeBySdoName(dtt, tdoType, dataRefList);
8281
// Prepare DataObject
83-
DataObject dataObject = new DataObject(tdo.getName(), tdoType.getCdc(), doLinkedToDaFilter.sdoNames());
82+
DataObject dataObject = new DataObject(tdo.getName(), tdoType.getCdc(), dataRef.sdoNames());
8483
// Search first DA from last DoType
85-
return daService.findDA(lastDoType, doLinkedToDaFilter.daName())
84+
return daService.findDA(lastDoType, dataRef.daName())
8685
.flatMap(tda -> {
8786
// Prepare DataAttribute
8887
DataAttribute dataAttribute = new DataAttribute();
@@ -102,15 +101,15 @@ public Optional<DoLinkedToDa> findDoLinkedToDa(TDataTypeTemplates dtt, String lN
102101
.flatMap(tdaType -> {
103102
// Search last DAType from first DAType
104103
TDAType lastDAType = findDATypeByBdaName(dtt, tdaType, tbda -> tbda.isSetBType()
105-
&& tbda.getBType().equals(TPredefinedBasicTypeEnum.STRUCT), dataRefList);
104+
&& tbda.getBType().equals(TPredefinedBasicTypeEnum.STRUCT), dataRefList);
106105

107106
// last DAType should contain BDA not STRUCT
108107
if (dataRefList.size() != 1) return Optional.empty();
109108
String lastBdaName = dataRefList.getFirst();
110109
return bdaService.findBDA(lastDAType, tbda -> tbda.getName().equals(lastBdaName)
111-
&& !tbda.getBType().equals(TPredefinedBasicTypeEnum.STRUCT))
110+
&& !tbda.getBType().equals(TPredefinedBasicTypeEnum.STRUCT))
112111
.flatMap(tbda -> {
113-
dataAttribute.getBdaNames().addAll(doLinkedToDaFilter.bdaNames());
112+
dataAttribute.getBdaNames().addAll(dataRef.bdaNames());
114113
dataAttribute.setBType(tbda.getBType());
115114
dataAttribute.setType(tbda.getType());
116115
dataAttribute.setValImport(tbda.isValImport());
@@ -125,18 +124,14 @@ public Optional<DoLinkedToDa> findDoLinkedToDa(TDataTypeTemplates dtt, String lN
125124
}
126125

127126
@Override
128-
public Stream<String> getEnumValues(TDataTypeTemplates dataTypeTemplates, String lnType, DoLinkedToDaFilter doLinkedToDaFilter) {
129-
return findDoLinkedToDa(dataTypeTemplates, lnType, doLinkedToDaFilter)
130-
.map(DoLinkedToDa::dataAttribute)
131-
.filter(dataAttribute -> TPredefinedBasicTypeEnum.ENUM.equals(dataAttribute.getBType()))
132-
.map(DataAttribute::getType)
133-
.flatMap(enumId ->
134-
dataTypeTemplates.getEnumType().stream()
135-
.filter(tEnumType -> tEnumType.getId().equals(enumId))
136-
.findFirst())
127+
public List<String> getEnumValues(TDataTypeTemplates dataTypeTemplates, String enumId) {
128+
return dataTypeTemplates.getEnumType().stream()
129+
.filter(tEnumType -> tEnumType.getId().equals(enumId))
130+
.findFirst()
137131
.stream()
138132
.flatMap(tEnumType -> tEnumType.getEnumVal().stream())
139-
.map(TEnumVal::getValue);
133+
.map(TEnumVal::getValue)
134+
.toList();
140135
}
141136

142137
private Optional<TDAType> getDATypeByDaName(TDataTypeTemplates dtt, TDOType tdoType, String daName) {

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
@Slf4j
2626
public class LnService implements LnEditor {
2727

28-
private static final DoLinkedToDaFilter DAI_FILTER_MOD_STVAL = DoLinkedToDaFilter.from(MOD_DO_NAME, STVAL_DA_NAME);
28+
private static final DataRef DAI_FILTER_MOD_STVAL = DataRef.from(MOD_DO_NAME, STVAL_DA_NAME);
2929
public static final String LNODE_STATUS_PRIVATE_TYPE = "COMPAS-LNodeStatus";
3030

3131
public Stream<TAnyLN> getAnylns(TLDevice tlDevice) {
@@ -100,12 +100,12 @@ public Optional<TDAI> getDaiModStVal(TAnyLN tAnyLN) {
100100
}
101101

102102
@Override
103-
public Optional<TDAI> getDOAndDAInstances(TAnyLN tAnyLN, DoLinkedToDaFilter doLinkedToDaFilter) {
104-
List<String> structNamesList = new ArrayList<>(doLinkedToDaFilter.sdoNames());
105-
structNamesList.add(doLinkedToDaFilter.daName());
106-
structNamesList.addAll(doLinkedToDaFilter.bdaNames());
103+
public Optional<TDAI> getDOAndDAInstances(TAnyLN tAnyLN, DataRef dataRef) {
104+
List<String> structNamesList = new ArrayList<>(dataRef.sdoNames());
105+
structNamesList.add(dataRef.daName());
106+
structNamesList.addAll(dataRef.bdaNames());
107107

108-
return tAnyLN.getDOI().stream().filter(doi -> doi.getName().equals(doLinkedToDaFilter.doName()))
108+
return tAnyLN.getDOI().stream().filter(doi -> doi.getName().equals(dataRef.doName()))
109109
.findFirst()
110110
.flatMap(doi -> {
111111
if (structNamesList.size() > 1) {
@@ -160,7 +160,7 @@ public TDAI updateOrCreateDOAndDAInstances(TAnyLN tAnyLN, DoLinkedToDa doLinkedT
160160
@Override
161161
public DoLinkedToDa getDoLinkedToDaCompletedFromDAI(TIED tied, String ldInst, TAnyLN anyLN, DoLinkedToDa doLinkedToDa) {
162162
DoLinkedToDa result = doLinkedToDa.deepCopy();
163-
getDOAndDAInstances(anyLN, doLinkedToDa.toFilter())
163+
getDOAndDAInstances(anyLN, doLinkedToDa.getDataRef())
164164
.ifPresent(tdai -> {
165165
if (tdai.isSetVal()) {
166166
result.dataAttribute().addDaVal(tdai.getVal());

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import org.lfenergy.compas.sct.commons.api.DataTypeTemplateReader;
1313
import org.lfenergy.compas.sct.commons.api.SclEditor;
1414
import org.lfenergy.compas.sct.commons.domain.DaVal;
15-
import org.lfenergy.compas.sct.commons.domain.DoLinkedToDaFilter;
15+
import org.lfenergy.compas.sct.commons.domain.DataRef;
1616
import org.lfenergy.compas.sct.commons.dto.*;
1717
import org.lfenergy.compas.sct.commons.exception.ScdException;
1818
import org.lfenergy.compas.sct.commons.scl.SclRootAdapter;
@@ -35,7 +35,8 @@
3535
import java.util.*;
3636
import java.util.stream.Collectors;
3737

38-
import static org.lfenergy.compas.sct.commons.util.CommonConstants.*;
38+
import static org.lfenergy.compas.sct.commons.util.CommonConstants.IED_TEST_NAME;
39+
import static org.lfenergy.compas.sct.commons.util.CommonConstants.LDEVICE_LDSUIED;
3940
import static org.lfenergy.compas.sct.commons.util.PrivateEnum.COMPAS_ICDHEADER;
4041
import static org.lfenergy.compas.sct.commons.util.Utils.copyLn;
4142

@@ -259,10 +260,9 @@ private void manageMonitoringLns(List<IedSource> iedSources, SCL scd, TIED tied,
259260
List<TLN> lgosOrLsvsLns = lnService.getFilteredLns(ldsuiedLdevice, tln -> monitoringLnClassEnum.value().equals(tln.getLnClass().getFirst())).toList();
260261
if (lgosOrLsvsLns.isEmpty())
261262
errorHandler.get().add(SclReportItem.warning(tied.getName() + "/" + LDEVICE_LDSUIED + "/" + monitoringLnClassEnum.value(), "There is no LN %s present in LDevice".formatted(monitoringLnClassEnum.value())));
262-
DoLinkedToDaFilter doLinkedToDaFilter = new DoLinkedToDaFilter(doName, List.of(), DA_SETSRCREF, List.of());
263-
lgosOrLsvsLns.forEach(lgosOrLsvs -> dataTypeTemplateService.getFilteredDoLinkedToDa(scd.getDataTypeTemplates(), lgosOrLsvs.getLnType(), doLinkedToDaFilter)
263+
DataRef dataRef = new DataRef(doName, List.of(), DA_SETSRCREF, List.of());
264+
lgosOrLsvsLns.forEach(lgosOrLsvs -> dataTypeTemplateService.findDoLinkedToDa(scd.getDataTypeTemplates(), lgosOrLsvs.getLnType(), dataRef)
264265
.map(doLinkedToDa -> lnService.getDoLinkedToDaCompletedFromDAI(tied, LDEVICE_LDSUIED, lgosOrLsvs, doLinkedToDa))
265-
.findFirst()
266266
.filter(doLinkedToDa -> {
267267
if (!doLinkedToDa.isUpdatable())
268268
errorHandler.get().add(SclReportItem.warning(tied.getName() + "/" + LDEVICE_LDSUIED + "/" + monitoringLnClassEnum.value() + "/DOI@name=\"" + doName + "\"/DAI@name=\"setSrcRef\"/Val", "The DAI cannot be updated"));

sct-commons/src/main/java/org/lfenergy/compas/sct/commons/api/DataTypeTemplateReader.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,22 @@
55
package org.lfenergy.compas.sct.commons.api;
66

77
import org.lfenergy.compas.scl2007b4.model.TDataTypeTemplates;
8+
import org.lfenergy.compas.sct.commons.domain.DataRef;
89
import org.lfenergy.compas.sct.commons.domain.DoLinkedToDa;
9-
import org.lfenergy.compas.sct.commons.domain.DoLinkedToDaFilter;
1010

11+
import java.util.List;
1112
import java.util.Optional;
1213
import java.util.stream.Stream;
1314

1415
public interface DataTypeTemplateReader {
1516

1617
Stream<DoLinkedToDa> getAllDoLinkedToDa(TDataTypeTemplates tDataTypeTemplates);
1718

18-
Stream<DoLinkedToDa> getFilteredDoLinkedToDa(TDataTypeTemplates dtt, String lNodeTypeId, DoLinkedToDaFilter doLinkedToDaFilter);
19+
Stream<DoLinkedToDa> getAllDoLinkedToDa(TDataTypeTemplates dtt, String lNodeTypeId);
1920

20-
Optional<DoLinkedToDa> findDoLinkedToDa(TDataTypeTemplates dtt, String lNodeTypeId, DoLinkedToDaFilter doLinkedToDaFilter);
21+
Stream<DoLinkedToDa> getAllDoLinkedToDa(TDataTypeTemplates dtt, String lNodeTypeId, String doName);
2122

22-
Stream<String> getEnumValues(TDataTypeTemplates dataTypeTemplates, String lnType, DoLinkedToDaFilter doLinkedToDaFilter);
23+
Optional<DoLinkedToDa> findDoLinkedToDa(TDataTypeTemplates dtt, String lNodeTypeId, DataRef dataRef);
24+
25+
List<String> getEnumValues(TDataTypeTemplates dataTypeTemplates, String enumId);
2326
}

sct-commons/src/main/java/org/lfenergy/compas/sct/commons/api/LnEditor.java

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

77
import org.lfenergy.compas.scl2007b4.model.*;
8+
import org.lfenergy.compas.sct.commons.domain.DataRef;
89
import org.lfenergy.compas.sct.commons.domain.DoLinkedToDa;
9-
import org.lfenergy.compas.sct.commons.domain.DoLinkedToDaFilter;
1010
import org.lfenergy.compas.sct.commons.util.ActiveStatus;
1111

1212
import java.util.Optional;
@@ -19,7 +19,7 @@ public interface LnEditor {
1919

2020
Optional<TDAI> getDaiModStVal(TAnyLN tAnyLN);
2121

22-
Optional<TDAI> getDOAndDAInstances(TAnyLN tAnyLN, DoLinkedToDaFilter doLinkedToDaFilter);
22+
Optional<TDAI> getDOAndDAInstances(TAnyLN tAnyLN, DataRef dataRef);
2323

2424
TDAI updateOrCreateDOAndDAInstances(TAnyLN tAnyLN, DoLinkedToDa doLinkedToDa);
2525

sct-commons/src/main/java/org/lfenergy/compas/sct/commons/domain/DaVal.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,7 @@
55
package org.lfenergy.compas.sct.commons.domain;
66

77
public record DaVal(Long settingGroup, String val) {
8+
public DaVal(String val) {
9+
this(null, val);
10+
}
811
}

sct-commons/src/main/java/org/lfenergy/compas/sct/commons/domain/DoLinkedToDaFilter.java renamed to sct-commons/src/main/java/org/lfenergy/compas/sct/commons/domain/DataRef.java

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,32 @@
1111
import java.util.Collections;
1212
import java.util.List;
1313

14-
public record DoLinkedToDaFilter(String doName, List<String> sdoNames, String daName, List<String> bdaNames) {
14+
/**
15+
* DataRef is the reference of data.
16+
* At least doName and daName must be filled.
17+
* It is used to find a DoLinkedToDa.
18+
*
19+
* @param doName
20+
* @param sdoNames
21+
* @param daName
22+
* @param bdaNames
23+
*/
24+
public record DataRef(String doName, List<String> sdoNames, String daName, List<String> bdaNames) {
1525

16-
public DoLinkedToDaFilter(String doName, List<String> sdoNames, String daName, List<String> bdaNames) {
17-
this.doName = StringUtils.isBlank(doName) ? null : doName;
26+
public DataRef(String doName, List<String> sdoNames, String daName, List<String> bdaNames) {
27+
if (StringUtils.isBlank(doName)) {
28+
throw new IllegalArgumentException("doName cannot be blank");
29+
}
30+
if (StringUtils.isBlank(daName)) {
31+
throw new IllegalArgumentException("doName cannot be blank");
32+
}
33+
this.doName = doName;
1834
this.sdoNames = sdoNames == null ? Collections.emptyList() : List.copyOf(sdoNames);
19-
this.daName = StringUtils.isBlank(daName) ? null : daName;
35+
this.daName = daName;
2036
this.bdaNames = bdaNames == null ? Collections.emptyList() : List.copyOf(bdaNames);
2137
}
2238

23-
public static DoLinkedToDaFilter from(String doNames, String daNames) {
39+
public static DataRef from(String doNames, String daNames) {
2440
String doName = null;
2541
List<String> sdoNames = null;
2642
String daName = null;
@@ -33,7 +49,7 @@ public static DoLinkedToDaFilter from(String doNames, String daNames) {
3349
daName = daNames.split("\\.")[0];
3450
bdaNames = Arrays.stream(daNames.split("\\.")).skip(1).toList();
3551
}
36-
return new DoLinkedToDaFilter(doName, sdoNames, daName, bdaNames);
52+
return new DataRef(doName, sdoNames, daName, bdaNames);
3753
}
3854

3955
public String getDoRef() {

sct-commons/src/main/java/org/lfenergy/compas/sct/commons/domain/DoLinkedToDa.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,16 @@ private boolean isDOModDAstVal() {
4444
}
4545

4646
/**
47-
* Create DoLinkedToDaFilter from this
48-
* @return new DoLinkedToDaFilter instance with same data Object and data Attribute Ref
47+
* Create DataRef from this
48+
* @return new DataRef instance with same data Object and data Attribute Ref
4949
*/
50-
public DoLinkedToDaFilter toFilter() {
51-
return DoLinkedToDaFilter.from(getDoRef(), getDaRef());
50+
public DataRef getDataRef() {
51+
return DataRef.from(getDoRef(), getDaRef());
5252
}
53+
54+
@Override
55+
public String toString() {
56+
return getDoRef() + "." + getDaRef();
57+
}
58+
5359
}

0 commit comments

Comments
 (0)