Skip to content

Commit 33211e8

Browse files
authored
feat(85): RSR-434 - Create ControlBlocks (#219)
Signed-off-by: massifben <[email protected]>
1 parent fcc433a commit 33211e8

39 files changed

+2389
-1051
lines changed

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

Lines changed: 67 additions & 112 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,20 @@
77
import lombok.Getter;
88
import lombok.NoArgsConstructor;
99
import lombok.Setter;
10+
import org.apache.commons.lang3.StringUtils;
1011
import org.lfenergy.compas.scl2007b4.model.*;
1112
import org.lfenergy.compas.sct.commons.exception.ScdException;
12-
import org.lfenergy.compas.sct.commons.scl.SclRootAdapter;
1313
import org.lfenergy.compas.sct.commons.scl.ied.IEDAdapter;
14-
import org.lfenergy.compas.sct.commons.scl.ied.LDeviceAdapter;
14+
import org.lfenergy.compas.sct.commons.util.ControlBlockEnum;
1515

1616
import java.util.ArrayList;
1717
import java.util.List;
18-
import java.util.stream.Collectors;
1918

2019
/**
2120
* A representation of the model object <em><b>ControlBlock</b></em>.
22-
* @param <T> input such as {@link org.lfenergy.compas.sct.commons.dto.GooseControlBlock <em>GooseControlBlock</em>},
23-
* {@link org.lfenergy.compas.sct.commons.dto.ReportControlBlock <em>ReportControlBlock</em>},
24-
* {@link org.lfenergy.compas.sct.commons.dto.SMVControlBlock <em>SMVControlBlock</em>},
21+
* - {@link org.lfenergy.compas.sct.commons.dto.GooseControlBlock <em>GooseControlBlock</em>},
22+
* - {@link org.lfenergy.compas.sct.commons.dto.ReportControlBlock <em>ReportControlBlock</em>},
23+
* - {@link org.lfenergy.compas.sct.commons.dto.SMVControlBlock <em>SMVControlBlock</em>},
2524
* <p>
2625
* The following features are supported:
2726
* </p>
@@ -31,54 +30,55 @@
3130
* <li>{@link ControlBlock#getDataSetRef() <em>dataSetRef</em>}</li>
3231
* <li>{@link ControlBlock#getDesc() <em>Desc</em>}</li>
3332
* <li>{@link ControlBlock#getConfRev() <em>Refers To confRev</em>}</li>
34-
* <li>{@link ControlBlock#getIedNames() <em>Refers To IedNames</em>}</li>
35-
* <li>{@link ControlBlock#getSecurityEnable() <em>Refers To security Enable</em>}</li>
33+
* <li>{@link ControlBlock#getTargets() <em>Refers To IedNames</em>}</li>
3634
* </ul>
3735
*
3836
* @see org.lfenergy.compas.scl2007b4.model.TControlBlock
3937
*/
4038
@Getter
4139
@Setter
4240
@NoArgsConstructor
43-
public abstract class ControlBlock<T extends ControlBlock> extends LNodeMetaDataEmbedder {
41+
public abstract class ControlBlock extends LNodeMetaDataEmbedder {
4442

45-
protected String id; /// appID or smvID
43+
protected String id; /// appID or smvID or rptID
4644
protected String name;
4745
protected String dataSetRef;
4846
protected String desc;
49-
protected Long confRev;
50-
protected List<TControlWithIEDName.IEDName> iedNames = new ArrayList<>();
51-
protected TPredefinedTypeOfSecurityEnum securityEnable = TPredefinedTypeOfSecurityEnum.NONE;
52-
53-
/**
54-
* Abstract method for getting classe type
55-
* @return classe type
56-
*/
57-
protected abstract Class<T> getClassType();
47+
protected Long confRev = 10000L;
48+
protected List<ControlBlockTarget> targets = new ArrayList<>();
5849

5950
/**
6051
* Get ServiceType
6152
* @return ServiceType enum object
53+
* @deprecated TServiceType provides REPORT, SMV, GOOSE and POLL. It does not provide "LOG" for LogControl and provides "POLL" which is not a valid
54+
* ControlBlock type. Use getControlBlockEnum() instead.
55+
* @see ControlBlock#getControlBlockEnum()
6256
*/
63-
public abstract TServiceType getServiceType();
57+
@Deprecated(since = "16/01/2023")
58+
public TServiceType getServiceType() {
59+
return switch (getControlBlockEnum()){
60+
case GSE -> TServiceType.GOOSE;
61+
case SAMPLED_VALUE -> TServiceType.SMV;
62+
case REPORT -> TServiceType.REPORT;
63+
default -> throw new IllegalArgumentException("Unsupported ControlBlockEnum : " + getControlBlockEnum());
64+
};
65+
}
6466

65-
public abstract <U extends TControl> U createControlBlock();
67+
/**
68+
* Get ControlBlockEnum
69+
* @return ControlBlockEnum of the instance
70+
*/
71+
public abstract ControlBlockEnum getControlBlockEnum();
6672

6773
/**
68-
* Cast object to specified type
69-
* @param obj object to cast
70-
* @return object casted on specified type
74+
* Map the object to TControl
75+
* @return new instance of TControl element with all the attributes copied from the current object
7176
*/
72-
public T cast(Object obj){
73-
if (!obj.getClass().isAssignableFrom(getClassType())) {
74-
throw new UnsupportedOperationException("Cannot cast object to " + getClassType());
75-
}
76-
return (T) obj;
77-
}
77+
public abstract TControl toTControl();
7878

7979
/**
8080
* Validate Control block structure
81-
* @throws ScdException
81+
* @throws ScdException when ControlBlock structure is not valid
8282
*/
8383
public void validateCB() throws ScdException {
8484

@@ -90,86 +90,42 @@ public void validateCB() throws ScdException {
9090
throw new ScdException("A required field is missing: name");
9191
}
9292

93-
if(iedNames.stream().anyMatch( iedName -> iedName == null ||
94-
iedName.getValue() == null || iedName.getValue().isBlank() ||
95-
iedName.getLdInst() == null || iedName.getLdInst().isBlank())) {
93+
if(targets.stream().anyMatch(
94+
target -> target == null || StringUtils.isBlank(target.iedName()) ||
95+
StringUtils.isBlank(target.ldInst()))) {
9696
throw new ScdException("Control block destination IEDs are not well defined");
9797
}
9898
}
9999

100-
/**
101-
* Check Control block's destination is present in SCD file
102-
* @param sclRootAdapter main adapter containing SCD file
103-
* @throws ScdException
104-
*/
105-
public void validateDestination(SclRootAdapter sclRootAdapter) throws ScdException {
106-
for(TControlWithIEDName.IEDName iedName : iedNames){
107-
IEDAdapter iedAdapter =sclRootAdapter.getIEDAdapterByName(iedName.getValue());
108-
LDeviceAdapter lDeviceAdapter = iedAdapter.findLDeviceAdapterByLdInst(iedName.getLdInst())
109-
.orElseThrow(
110-
() -> new ScdException(
111-
String.format(
112-
"Control block destination: Unknown LDevice [%s] in IED [%s]",
113-
iedName.getLdInst(),iedName.getValue()
114-
)
115-
)
116-
);
117-
if (iedName.isSetLnClass()) {
118-
try {
119-
lDeviceAdapter.getLNAdapter(iedName.getLnClass().get(0), iedName.getLnInst(), iedName.getPrefix());
120-
} catch (ScdException e) {
121-
throw new ScdException("Control block destination: " + e.getMessage());
122-
}
123-
}
124-
}
125-
}
126-
127100
/**
128101
* Check if Security is enabled in IED (Services)
129-
* @param iedAdapter IED adapter containing IED datas
130-
* @throws ScdException
102+
* @param iedAdapter IED adapter containing IED data
103+
* @throws ScdException when ControlBlock Security is not consistent
131104
*/
132105
public final void validateSecurityEnabledValue(IEDAdapter iedAdapter) throws ScdException {
133106
TServices tServices = iedAdapter.getServices();
134107
validateSecurityEnabledValue(tServices);
135108
}
136109

137110
/**
138-
* Get ConfRev value
111+
* Get ConfRev value.
112+
* ConfRev is 0 for newly created control blocks without data set reference
139113
* @return confRev long value
140114
*/
141-
protected Long getConfRev() {
142-
if(dataSetRef == null || dataSetRef.isBlank()){
115+
public Long getConfRev() {
116+
if(StringUtils.isBlank(dataSetRef)){
143117
return 0L;
144118
}
145-
return 10000L ;
119+
return confRev;
146120
}
147121

148122
/**
149123
* Abstract method to check validity of Security Enable state for Control blocks
150124
* @param tServices Service object
151-
* @throws ScdException
125+
* @throws ScdException when ControlBlock Security is not consistent
152126
*/
153127
protected abstract void validateSecurityEnabledValue(TServices tServices) throws ScdException;
154128

155-
/**
156-
* Create Control block iedName element from ClientLN element
157-
* @param clientLN property ClientLN
158-
* @return IEDName of Control
159-
*/
160-
public static TControlWithIEDName.IEDName toIEDName(TClientLN clientLN){
161-
162-
TControlWithIEDName.IEDName iedName = new TControlWithIEDName.IEDName();
163-
iedName.setValue(clientLN.getIedName());
164-
iedName.setApRef(clientLN.getApRef());
165-
iedName.setLdInst(clientLN.getLdInst());
166-
iedName.setPrefix(clientLN.getPrefix());
167-
iedName.setLnInst(clientLN.getLnInst());
168-
iedName.getLnClass().addAll(clientLN.getLnClass());
169-
170-
return iedName;
171-
}
172-
173129
/**
174130
* Get Control block settings from Service
175131
* @param tServices Service object
@@ -179,35 +135,34 @@ public TServiceSettingsNoDynEnum getControlBlockServiceSetting(TServices tServic
179135
if(tServices == null) {
180136
return TServiceSettingsNoDynEnum.FIX;
181137
}
182-
183-
if (getServiceType() == TServiceType.GOOSE && tServices.getGSESettings() != null){
184-
return tServices.getGSESettings().getCbName();
185-
}
186-
if(getServiceType() == TServiceType.SMV && tServices.getSMVSettings() != null){
187-
return tServices.getSMVSettings().getCbName();
188-
}
189-
if(getServiceType() == TServiceType.REPORT && tServices.getReportSettings() != null){
190-
return tServices.getReportSettings().getCbName();
191-
}
192-
return TServiceSettingsNoDynEnum.FIX;
138+
return switch (getControlBlockEnum()){
139+
case GSE -> (tServices.getGSESettings() != null) ? tServices.getGSESettings().getCbName() : TServiceSettingsNoDynEnum.FIX;
140+
case SAMPLED_VALUE -> (tServices.getSMVSettings() != null) ? tServices.getSMVSettings().getCbName() : TServiceSettingsNoDynEnum.FIX;
141+
case REPORT -> (tServices.getReportSettings() != null) ? tServices.getReportSettings().getCbName() : TServiceSettingsNoDynEnum.FIX;
142+
default -> TServiceSettingsNoDynEnum.FIX;
143+
};
193144
}
194145

195146
/**
196-
* Get Control block
197-
* @return Control block's string value from IEDNames
147+
* Add the ControlBlock to an LN or LN0 element
148+
* @param tAnyLN tLN or tLNO element
149+
* @return the added TControl
198150
*/
199-
@Override
200-
public String toString() {
201-
String values = iedNames.stream().map(TControlWithIEDName.IEDName::getValue)
202-
.collect(Collectors.joining(","));
203-
return "ControlBlock{" +
204-
"id='" + id + '\'' +
205-
", name='" + name + '\'' +
206-
", dataSetRef='" + dataSetRef + '\'' +
207-
", desc='" + desc + '\'' +
208-
", confRev=" + confRev +
209-
", iedNames=" + values +
210-
", securityEnable=" + securityEnable +
211-
'}';
151+
public abstract TControl addToLN(TAnyLN tAnyLN);
152+
153+
/**
154+
* Copy a TProtocol object
155+
* @param tProtocol input instance
156+
* @return new instance of tProtocol with the same fields as input
157+
*/
158+
protected static TProtocol copyProtocol(TProtocol tProtocol){
159+
if (tProtocol == null) {
160+
return null;
161+
}
162+
TProtocol newTProtocol = new TProtocol();
163+
newTProtocol.setValue(tProtocol.getValue());
164+
newTProtocol.setMustUnderstand(tProtocol.isMustUnderstand());
165+
return newTProtocol;
212166
}
167+
213168
}

0 commit comments

Comments
 (0)