Skip to content

Commit 5e9ac6e

Browse files
syllamohSaintierFr
authored andcommitted
update documentation, implement issues #43, #42 and #37
Signed-off-by: Mohamed Sylla <[email protected]>
1 parent 5699cb0 commit 5e9ac6e

23 files changed

+268
-92
lines changed

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

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public abstract class ControlBlock<T extends ControlBlock> extends LNodeMetaData
3434
protected String name;
3535
protected String dataSetRef;
3636
protected String desc;
37-
protected long confRev;
37+
protected Long confRev;
3838
protected List<TControlWithIEDName.IEDName> iedNames = new ArrayList<>();
3939
protected TPredefinedTypeOfSecurityEnum securityEnable = TPredefinedTypeOfSecurityEnum.NONE;
4040

@@ -53,15 +53,11 @@ public T cast(Object obj){
5353
public void validateCB() throws ScdException {
5454

5555
if(id == null || id.isBlank()){
56-
throw new ScdException("Control block ID is missing");
56+
throw new ScdException("A required field is missing: ID ");
5757
}
5858

5959
if(name == null || name.isBlank()){
60-
throw new ScdException("Control block Name is missing");
61-
}
62-
63-
if(dataSetRef != null && dataSetRef.isBlank()){
64-
throw new ScdException("Control block datSet is missing");
60+
throw new ScdException("A required field is missing: name");
6561
}
6662

6763
if(iedNames.stream().anyMatch( iedName -> iedName == null ||
@@ -78,12 +74,17 @@ public void validateDestination(SclRootAdapter sclRootAdapter) throws ScdExcepti
7874
.orElseThrow(
7975
() -> new ScdException(
8076
String.format(
81-
"Unknown LDevice [%s] in IED [%s]", iedName.getLdInst(),iedName.getValue()
77+
"Control block destination: Unknown LDevice [%s] in IED [%s]",
78+
iedName.getLdInst(),iedName.getValue()
8279
)
8380
)
8481
);
8582
if(!iedName.getLnClass().isEmpty()) {
86-
lDeviceAdapter.getLNAdapter(iedName.getLnClass().get(0),iedName.getLnInst(), iedName.getPrefix());
83+
try {
84+
lDeviceAdapter.getLNAdapter(iedName.getLnClass().get(0), iedName.getLnInst(), iedName.getPrefix());
85+
} catch (ScdException e){
86+
throw new ScdException("Control block destination: " + e.getMessage());
87+
}
8788
} else {
8889
Utils.setField(iedName,"lnClass",null);
8990
}

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

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,16 @@ public FCDAInfo(String dataSet, TFCDA tfcda) {
4646
@JsonIgnore
4747
public TFCDA getFCDA(){
4848
TFCDA tfcda = new TFCDA();
49-
tfcda.setFc(fc);
5049
tfcda.setLdInst(ldInst);
51-
tfcda.getLnClass().add(lnClass);
52-
53-
if(!StringUtils.isBlank(lnInst)){
54-
tfcda.setLnInst(lnInst);
50+
tfcda.setFc(fc);
51+
if(!StringUtils.isBlank(lnClass)){
52+
tfcda.getLnClass().add(lnClass);
53+
if(!StringUtils.isBlank(lnInst)){
54+
tfcda.setLnInst(lnInst);
55+
}
56+
if(!StringUtils.isBlank(prefix)){
57+
tfcda.setPrefix(prefix);
58+
}
5559
}
5660

5761
if(doName != null && doName.isDefined()){

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,4 +92,13 @@ public TReportControl createControlBlock() {
9292

9393
return reportControl;
9494
}
95+
96+
@Override
97+
public void validateCB() throws ScdException {
98+
super.validateCB();
99+
100+
if(dataSetRef != null && dataSetRef.isBlank()){
101+
throw new ScdException("A required field is missing: datSet");
102+
}
103+
}
95104
}

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

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ public class SMVControlBlock extends ControlBlock<SMVControlBlock>{
2727
private TSampledValueControl.SmvOpts smvOpts;
2828
private TProtocol protocol;
2929
private boolean multicast = true;
30-
private long smpRate;
31-
private long nofASDU;
30+
private Long smpRate;
31+
private Long nofASDU;
3232
private TSmpMod smpMod = TSmpMod.SMP_PER_PERIOD;
3333

3434

@@ -78,6 +78,22 @@ protected void validateSecurityEnabledValue(TServices tServices) throws ScdExcep
7878
}
7979
}
8080

81+
@Override
82+
public void validateCB() throws ScdException {
83+
super.validateCB();
84+
85+
if(dataSetRef != null && dataSetRef.isBlank()){
86+
throw new ScdException("A required field is missing: datSet");
87+
}
88+
if(smpRate == null){
89+
throw new ScdException("A required field is missing: smpRate");
90+
}
91+
92+
if(nofASDU == null){
93+
throw new ScdException("A required field is missing: nofASDU ");
94+
}
95+
}
96+
8197
@Override
8298
public TSampledValueControl createControlBlock() {
8399

@@ -95,8 +111,13 @@ public TSampledValueControl createControlBlock() {
95111
if(smpMod != null) {
96112
sampledValueControl.setSmpMod(smpMod);
97113
}
98-
sampledValueControl.setSmpRate(smpRate);
99-
sampledValueControl.setNofASDU(nofASDU);
114+
if(smpRate != null) {
115+
sampledValueControl.setSmpRate(smpRate);
116+
}
117+
118+
if(nofASDU != null) {
119+
sampledValueControl.setNofASDU(nofASDU);
120+
}
100121
if(protocol != null) {
101122
sampledValueControl.setProtocol(protocol);
102123
}

sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/dtt/EnumTypeAdapter.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,9 @@
77

88
import org.lfenergy.compas.scl2007b4.model.TEnumType;
99
import org.lfenergy.compas.scl2007b4.model.TEnumVal;
10-
import org.lfenergy.compas.sct.commons.dto.DaTypeName;
11-
import org.lfenergy.compas.sct.commons.dto.ResumedDataTemplate;
12-
import org.lfenergy.compas.sct.commons.scl.SclElementAdapter;
1310

1411
import java.util.List;
15-
import java.util.Objects;
16-
import java.util.Optional;
12+
import java.util.Objects;;
1713

1814
public class EnumTypeAdapter extends AbstractDataTypeAdapter<TEnumType>{
1915

sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/dtt/LNodeTypeAdapter.java

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ public Optional<String> getDOTypeId(String doName){
8888
.findFirst();
8989
}
9090

91-
public List<ResumedDataTemplate> getResumedDTTs(ResumedDataTemplate filter) {
91+
public List<ResumedDataTemplate> getResumedDTTs(@NonNull ResumedDataTemplate filter) {
9292

9393
List<ResumedDataTemplate> resumedDataTemplates = new ArrayList<>();
9494
if(filter.isDaNameDefined()) {
@@ -101,14 +101,12 @@ public List<ResumedDataTemplate> getResumedDTTs(ResumedDataTemplate filter) {
101101
}
102102
ResumedDataTemplate rootResumedRTT = new ResumedDataTemplate();
103103
rootResumedRTT.setLnType(currentElem.getId());
104-
if(filter != null) {
105-
rootResumedRTT.setLnClass(filter.getLnClass());
106-
rootResumedRTT.setLnInst(filter.getLnInst());
107-
rootResumedRTT.setPrefix(filter.getPrefix());
108-
}
104+
rootResumedRTT.setLnClass(filter.getLnClass());
105+
rootResumedRTT.setLnInst(filter.getLnInst());
106+
rootResumedRTT.setPrefix(filter.getPrefix());
109107

110108
for(TDO tdo : currentElem.getDO()){
111-
if(filter != null && filter.isDoNameDefined() &&
109+
if(filter.isDoNameDefined() &&
112110
!filter.getDoName().getName().equals(tdo.getName())){
113111
continue;
114112
}
@@ -173,13 +171,10 @@ public void check(@NonNull DoTypeName doTypeName, @NonNull DaTypeName daTypeName
173171

174172
// check coherence between Data Object and Data Attributes information
175173
DOTypeAdapter lastDoTypeAdapter;
176-
String lastSdo;
177174
if(adapterPair == null){
178175
adapterPair = findPathFromDo2DA(doTypeName.getName(),daTypeName.getName());
179176
lastDoTypeAdapter = adapterPair.getValue();
180-
lastSdo = adapterPair.getKey();
181177
} else {
182-
lastSdo = adapterPair.getKey();
183178
if(adapterPair.getRight().containsDAWithDAName(daTypeName.getName())){
184179
lastDoTypeAdapter = adapterPair.getValue();
185180
} else {
@@ -232,7 +227,7 @@ public List<ResumedDataTemplate> getResumedDTTByDaName(DaTypeName daTypeName) th
232227
return rDtts;
233228
}
234229

235-
public List<ResumedDataTemplate> getResumedDTTByDoName(DoTypeName doTypeName) throws ScdException {
230+
public List<ResumedDataTemplate> getResumedDTTByDoName(DoTypeName doTypeName) {
236231

237232

238233
DOAdapter doAdapter = getDOAdapterByName(doTypeName.getName()).orElseThrow();

sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/header/HeaderAdapter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public String getHeaderVersion() {
5858
return currentElem.getVersion();
5959
}
6060

61-
public List<? extends THitem> getHistoryItems() {
61+
public List<THitem> getHistoryItems() {
6262
if(currentElem.getHistory() == null) return new ArrayList<>();
6363
return currentElem.getHistory().getHitem();
6464
}

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

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import org.lfenergy.compas.sct.commons.scl.ObjectReference;
1111
import org.lfenergy.compas.sct.commons.scl.SclElementAdapter;
1212

13-
import java.util.List;
1413
import java.util.Map;
1514
import java.util.Optional;
1615
import java.util.stream.Stream;
@@ -36,7 +35,7 @@ public Boolean isValImport(){
3635
return currentElem.isValImport();
3736
}
3837

39-
public AbstractDAIAdapter update(Map<Long, String> daiValues) throws ScdException {
38+
public AbstractDAIAdapter<? extends SclElementAdapter> update(Map<Long, String> daiValues) throws ScdException {
4039
if(daiValues.size() > 1 && daiValues.containsKey(0L)){
4140
update(0L, daiValues.get(0L)); // to be refined (with COMPAS TEAMS)
4241
} else {
@@ -47,10 +46,6 @@ public AbstractDAIAdapter update(Map<Long, String> daiValues) throws ScdExceptio
4746
return this;
4847
}
4948

50-
public boolean matches(ObjectReference dataAttributes){
51-
return false;
52-
}
53-
5449
public void update(Long sGroup, String val) throws ScdException {
5550
if(currentElem.isValImport() != null && !currentElem.isValImport().booleanValue()){
5651
String msg = String.format(

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

Lines changed: 53 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import org.lfenergy.compas.sct.commons.dto.ExtRefInfo;
3030
import org.lfenergy.compas.sct.commons.dto.ExtRefSignalInfo;
3131
import org.lfenergy.compas.sct.commons.dto.ExtRefSourceInfo;
32+
import org.lfenergy.compas.sct.commons.dto.FCDAInfo;
3233
import org.lfenergy.compas.sct.commons.dto.GooseControlBlock;
3334
import org.lfenergy.compas.sct.commons.dto.LNodeMetaData;
3435
import org.lfenergy.compas.sct.commons.dto.ReportControlBlock;
@@ -69,8 +70,26 @@ public static LNAdapterBuilder builder(){
6970
public abstract String getLNInst();
7071
public abstract String getPrefix();
7172

72-
protected void addControlBlock(ReportControlBlock controlBlock) {
73-
currentElem.getReportControl().add(controlBlock.createControlBlock());
73+
protected void addControlBlock(ControlBlock<?> controlBlock) throws ScdException {
74+
75+
switch (controlBlock.getServiceType() ) {
76+
case REPORT:
77+
currentElem.getReportControl().add(controlBlock.createControlBlock());
78+
break;
79+
case GOOSE:
80+
if(isLN0()) {
81+
((LN0)currentElem).getGSEControl().add(controlBlock.createControlBlock());
82+
}
83+
break;
84+
case SMV:
85+
if(isLN0()) {
86+
((LN0)currentElem).getSampledValueControl().add(controlBlock.createControlBlock());
87+
}
88+
break;
89+
default:
90+
throw new ScdException("Unknown control block type : " + controlBlock.getServiceType());
91+
92+
}
7493
}
7594

7695
public Optional<TDataSet> findDataSetByRef(String dataSetRef) {
@@ -314,6 +333,23 @@ public static boolean isNull(TFCDA tfcda){
314333

315334
}
316335

336+
public boolean hasControlBlock(ControlBlock<? extends ControlBlock> controlBlock) {
337+
338+
switch (controlBlock.getServiceType()){
339+
case REPORT:
340+
return currentElem.getReportControl().stream()
341+
.anyMatch(control -> control.getName().equals(controlBlock.getName()));
342+
case GOOSE:
343+
return isLN0() && ((LN0)currentElem).getGSEControl().stream()
344+
.anyMatch(control -> control.getName().equals(controlBlock.getName()));
345+
case SMV:
346+
return isLN0() && ((LN0)currentElem).getSampledValueControl().stream()
347+
.anyMatch(reportControl -> reportControl.getName().equals(controlBlock.getName()));
348+
default:
349+
return false;
350+
}
351+
}
352+
317353
public List<TDataSet> getDataSet(ExtRefInfo filter){
318354
if (filter == null || filter.getSignalInfo() == null || filter.getBindingInfo() == null) {
319355
return currentElem.getDataSet();
@@ -497,7 +533,7 @@ protected ResumedDataTemplate completeResumedDTTFromDAI(ResumedDataTemplate rDtt
497533
*/
498534
protected Optional<? extends AbstractDAIAdapter> findMatch(DoTypeName doTypeName, DaTypeName daTypeName){
499535
DAITracker daiTracker = new DAITracker(this,doTypeName,daTypeName);
500-
DAITracker.MatchResult matchResult = daiTracker.Search();
536+
DAITracker.MatchResult matchResult = daiTracker.search();
501537
if(matchResult != DAITracker.MatchResult.FULL_MATCH){
502538
return Optional.empty();
503539
}
@@ -513,7 +549,7 @@ public void updateDAI(@NonNull ResumedDataTemplate rDtt) throws ScdException {
513549
DaTypeName daTypeName = rDtt.getDaName();
514550

515551
DAITracker daiTracker = new DAITracker(this,doTypeName,daTypeName);
516-
DAITracker.MatchResult matchResult = daiTracker.Search();
552+
DAITracker.MatchResult matchResult = daiTracker.search();
517553
AbstractDAIAdapter<?> daiAdapter = null;
518554
IDataParentAdapter doiOrSdoiAdapter;
519555
if(matchResult == DAITracker.MatchResult.FULL_MATCH){
@@ -617,12 +653,22 @@ protected boolean matchesDataAttributes(String dataAttribute){
617653
currentElem.getReportControl().stream().anyMatch(rptCtl -> rptCtl.getName().equals(dataAttribute));
618654
}
619655

620-
public Set<DataSetInfo> getDataSet() {
656+
public Optional<DataSetInfo> getDataSetByRef(String dataSetRef) {
621657
return currentElem.getDataSet()
622-
.stream().map(tDataSet -> DataSetInfo.from(tDataSet)).collect(Collectors.toSet());
658+
.stream()
659+
.filter(tDataSet -> tDataSet.getName().equals(dataSetRef))
660+
.map(DataSetInfo::from)
661+
.findFirst();
623662
}
624663

625664
public void addDataSet(DataSetInfo dataSetInfo) {
665+
TDataSet tDataSet = new TDataSet();
666+
tDataSet.setName(dataSetInfo.getName());
667+
tDataSet.getFCDA().addAll(
668+
dataSetInfo.getFCDAInfos().stream().map(fcdaInfo -> fcdaInfo.getFCDA()).collect(Collectors.toList())
669+
);
670+
currentElem.getDataSet().add(tDataSet);
671+
626672
}
627673

628674
public DataTypeTemplateAdapter getDataTypeTemplateAdapter() {
@@ -631,7 +677,7 @@ public DataTypeTemplateAdapter getDataTypeTemplateAdapter() {
631677

632678
public Map<Long, String> getDAIValues(ResumedDataTemplate rDtt) {
633679
DAITracker daiTracker = new DAITracker(this,rDtt.getDoName(),rDtt.getDaName());
634-
DAITracker.MatchResult matchResult = daiTracker.Search();
680+
DAITracker.MatchResult matchResult = daiTracker.search();
635681
if(matchResult != DAITracker.MatchResult.FULL_MATCH){
636682
return new HashMap<>();
637683
}

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
import org.lfenergy.compas.sct.commons.dto.DoTypeName;
1313
import org.lfenergy.compas.sct.commons.dto.ResumedDataTemplate;
1414
import org.lfenergy.compas.sct.commons.exception.ScdException;
15-
import org.lfenergy.compas.sct.commons.scl.SclService;
1615
import org.lfenergy.compas.sct.commons.scl.dtt.DataTypeTemplateAdapter;
1716
import org.lfenergy.compas.sct.commons.scl.dtt.LNodeTypeAdapter;
1817

@@ -38,7 +37,7 @@ public DAITracker(@NonNull AbstractLNAdapter<?> lnAdapter,
3837
this.daTypeName = daTypeName;
3938
}
4039

41-
public MatchResult Search() {
40+
public MatchResult search() {
4241

4342
Pair<? extends IDataAdapter,Integer> matchResult;
4443
String doiName = doTypeName.getName();

0 commit comments

Comments
 (0)