Skip to content

Commit cc725a3

Browse files
authored
Merge pull request #523 from com-pas/develop
Release 0.2.44
2 parents f919a91 + bd5eeee commit cc725a3

File tree

11 files changed

+196
-108
lines changed

11 files changed

+196
-108
lines changed

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

Lines changed: 56 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -40,32 +40,73 @@
4040
@Getter
4141
@Setter
4242
public class ReportControlBlock extends ControlBlock {
43+
public static final long RPT_ENABLED_MAX_DEFAULT = 4L;
44+
4345
//TODO this is a DTO object; it's meant to be used for carry information; he must be created be the one responsible for carying the info
44-
private TReportControl.OptFields optFields = newDefaultOptFields();
45-
protected TTrgOps trgOps = newDefaultTrgOps();
46-
protected long intgPd = 60000L;
47-
private Long rptEnabledMax = 1L;
46+
private TReportControl.OptFields optFields;
47+
protected TTrgOps trgOps;
48+
protected long intgPd;
49+
private Long rptEnabledMax;
4850
private String rptEnabledDesc;
49-
private boolean buffered = true;
50-
private long bufTime = 0;
51-
private boolean indexed = true;
51+
private boolean buffered;
52+
private long bufTime;
53+
private boolean indexed;
5254

5355
/**
56+
* Constructor.
5457
* Create ReportControlBlock with default values
5558
*
5659
* @param name name of the ReportControlBlock
5760
* @param id rptId of the ReportControlBlock
5861
* @param dataSetRef datSet of the ReportControlBlock
5962
*/
6063
public ReportControlBlock(String name, String id, String dataSetRef) {
61-
confRev = 1L;
6264
this.name = name;
6365
this.dataSetRef = dataSetRef;
6466
this.id = id;
67+
68+
// Default value
69+
this.confRev = 1L;
70+
this.optFields = newDefaultOptFields();
71+
this.trgOps = newDefaultTrgOps();
72+
this.intgPd = 60000L;
73+
this.rptEnabledMax = RPT_ENABLED_MAX_DEFAULT;
74+
this.buffered = true;
75+
this.bufTime = 0;
76+
this.indexed = true;
77+
}
78+
79+
/**
80+
* Constructor.
81+
* Create ReportControlBlock from TReportControl
82+
*
83+
* @param reportControl input
84+
*/
85+
public ReportControlBlock(TReportControl reportControl) {
86+
super();
87+
id = reportControl.getRptID();
88+
desc = reportControl.getDesc();
89+
name = reportControl.getName();
90+
if (reportControl.isSetConfRev()) {
91+
confRev = reportControl.getConfRev();
92+
}
93+
dataSetRef = reportControl.getDatSet();
94+
indexed = reportControl.isIndexed();
95+
intgPd = reportControl.getIntgPd();
96+
buffered = reportControl.isBuffered();
97+
bufTime = reportControl.getBufTime();
98+
optFields = copyOptFields(reportControl.getOptFields());
99+
trgOps = copyTTrgOps(reportControl.getTrgOps());
100+
if (reportControl.isSetRptEnabled()) {
101+
rptEnabledMax = reportControl.getRptEnabled().getMax();
102+
rptEnabledDesc = reportControl.getRptEnabled().getDesc();
103+
targets = reportControl.getRptEnabled().getClientLN().stream().map(ControlBlockTarget::from).collect(Collectors.toCollection(ArrayList::new));
104+
}
65105
}
66106

67107
/**
68108
* Create a new TTrgOps with default values
109+
*
69110
* @return new instance of TTrgOps
70111
*/
71112
private static TTrgOps newDefaultTrgOps() {
@@ -80,6 +121,7 @@ private static TTrgOps newDefaultTrgOps() {
80121

81122
/**
82123
* Create a new TReportControl.OptFields with default values
124+
*
83125
* @return new instance of TReportControl.OptFields
84126
*/
85127
private static TReportControl.OptFields newDefaultOptFields() {
@@ -95,32 +137,6 @@ private static TReportControl.OptFields newDefaultOptFields() {
95137
return newDefaultOptFields;
96138
}
97139

98-
/**
99-
* Constructor
100-
* @param reportControl input
101-
*/
102-
public ReportControlBlock(TReportControl reportControl) {
103-
super();
104-
id = reportControl.getRptID();
105-
desc = reportControl.getDesc();
106-
name = reportControl.getName();
107-
if(reportControl.isSetConfRev()) {
108-
confRev = reportControl.getConfRev();
109-
}
110-
dataSetRef = reportControl.getDatSet();
111-
indexed = reportControl.isIndexed();
112-
intgPd = reportControl.getIntgPd();
113-
buffered = reportControl.isBuffered();
114-
bufTime = reportControl.getBufTime();
115-
optFields = copyOptFields(reportControl.getOptFields());
116-
trgOps = copyTTrgOps(reportControl.getTrgOps());
117-
if (reportControl.isSetRptEnabled()){
118-
rptEnabledMax = reportControl.getRptEnabled().getMax();
119-
rptEnabledDesc = reportControl.getRptEnabled().getDesc();
120-
targets = reportControl.getRptEnabled().getClientLN().stream().map(ControlBlockTarget::from).collect(Collectors.toCollection(ArrayList::new));
121-
}
122-
}
123-
124140
@Override
125141
public ControlBlockEnum getControlBlockEnum() {
126142
return ControlBlockEnum.REPORT;
@@ -129,6 +145,7 @@ public ControlBlockEnum getControlBlockEnum() {
129145
/**
130146
* Implementation is required by superclass but ReportControl blocks has no SecurityEnabled attributes.
131147
* This implementation does nothing.
148+
*
132149
* @param tServices Service object
133150
* @throws ScdException never (this is just to comply with superclass)
134151
*/
@@ -139,6 +156,7 @@ protected void validateSecurityEnabledValue(TServices tServices) throws ScdExcep
139156

140157
/**
141158
* Creates Report Control Block
159+
*
142160
* @return TReportControl object
143161
*/
144162
@Override
@@ -168,13 +186,14 @@ public TReportControl toTControl() {
168186

169187
/**
170188
* Validates Report Control Block
189+
*
171190
* @throws ScdException when required fields are missing
172191
*/
173192
@Override
174193
public void validateCB() throws ScdException {
175194
super.validateCB();
176195

177-
if(dataSetRef != null && dataSetRef.isBlank()){
196+
if (dataSetRef != null && dataSetRef.isBlank()) {
178197
throw new ScdException("A required field is missing: datSet");
179198
}
180199
}
@@ -187,7 +206,7 @@ public TReportControl addToLN(TAnyLN tAnyLN) {
187206
}
188207

189208
private static TReportControl.OptFields copyOptFields(TReportControl.OptFields optFields) {
190-
if (optFields == null){
209+
if (optFields == null) {
191210
return null;
192211
}
193212
TReportControl.OptFields newOptFields = new TReportControl.OptFields();
@@ -203,7 +222,7 @@ private static TReportControl.OptFields copyOptFields(TReportControl.OptFields o
203222
}
204223

205224
private static TTrgOps copyTTrgOps(TTrgOps tTrgOps) {
206-
if (tTrgOps == null){
225+
if (tTrgOps == null) {
207226
return null;
208227
}
209228
TTrgOps newTTrgOps = new TTrgOps();

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import org.lfenergy.compas.scl2007b4.model.*;
99
import org.lfenergy.compas.sct.commons.dto.ControlBlockTarget;
10+
import org.lfenergy.compas.sct.commons.dto.ReportControlBlock;
1011
import org.lfenergy.compas.sct.commons.scl.SclElementAdapter;
1112
import org.lfenergy.compas.sct.commons.scl.ln.AbstractLNAdapter;
1213
import org.lfenergy.compas.sct.commons.util.ControlBlockEnum;
@@ -40,8 +41,6 @@
4041
*/
4142
public class ControlBlockAdapter extends SclElementAdapter<AbstractLNAdapter<? extends TAnyLN>, TControl> {
4243

43-
private static final long RPT_ENABLED_MAX_DEFAULT = 1L;
44-
4544
public ControlBlockAdapter(AbstractLNAdapter<? extends TAnyLN> parentAdapter, TControl tControl) {
4645
super(parentAdapter, tControl);
4746
}
@@ -103,7 +102,7 @@ public void addTargetIfNotExists(AbstractLNAdapter<?> targetLn) {
103102
} else if (currentElem instanceof TReportControl tReportControl) {
104103
if (!tReportControl.isSetRptEnabled()) {
105104
tReportControl.setRptEnabled(new TRptEnabled());
106-
tReportControl.getRptEnabled().setMax(RPT_ENABLED_MAX_DEFAULT);
105+
tReportControl.getRptEnabled().setMax(ReportControlBlock.RPT_ENABLED_MAX_DEFAULT);
107106
}
108107
if (tReportControl.getRptEnabled().getClientLN().stream().noneMatch(controlBlockTarget::equalsTClientLn)) {
109108
tReportControl.getRptEnabled().getClientLN().add(controlBlockTarget.toTClientLn());

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

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@
2121
import org.lfenergy.compas.sct.commons.util.ControlBlockEnum;
2222
import org.lfenergy.compas.sct.commons.util.Utils;
2323

24-
import java.util.*;
24+
import java.util.List;
25+
import java.util.Locale;
26+
import java.util.Optional;
27+
import java.util.Set;
2528
import java.util.function.Predicate;
2629

2730
import static org.lfenergy.compas.sct.commons.util.CommonConstants.*;
@@ -39,9 +42,9 @@
3942
public class InputsAdapter extends SclElementAdapter<LN0Adapter, TInputs> {
4043

4144
private static final String MESSAGE_SOURCE_LDEVICE_NOT_FOUND = "The signal ExtRef ExtRefldinst does not match any " +
42-
"LDevice with same inst attribute in source IED %s";
45+
"LDevice with same inst attribute in source IED %s";
4346
private static final String MESSAGE_SOURCE_LN_NOT_FOUND = "The signal ExtRef lninst, doName or daName does not match any " +
44-
"source in LDevice %s";
47+
"source in LDevice %s";
4548
private static final String MESSAGE_SERVICE_TYPE_MISSING = "The signal ExtRef is missing ServiceType attribute";
4649
private static final String MESSAGE_INVALID_SERVICE_TYPE = "The signal ExtRef ServiceType attribute is unexpected : %s";
4750
private static final String MESSAGE_IED_MISSING_COMPAS_BAY_UUID = "IED is missing Private/compas:Bay@UUID attribute";
@@ -118,10 +121,10 @@ private boolean isExternalBound(TExtRef tExtRef) {
118121

119122
private boolean areBindingAttributesPresent(TExtRef tExtRef) {
120123
return StringUtils.isNotBlank(tExtRef.getIedName())
121-
&& StringUtils.isNotBlank(tExtRef.getDesc())
122-
&& StringUtils.isNotBlank(tExtRef.getLdInst())
123-
&& tExtRef.getLnClass().stream().findFirst().filter(StringUtils::isNotBlank).isPresent()
124-
&& StringUtils.isNotBlank(tExtRef.getDoName());
124+
&& StringUtils.isNotBlank(tExtRef.getDesc())
125+
&& StringUtils.isNotBlank(tExtRef.getLdInst())
126+
&& tExtRef.getLnClass().stream().findFirst().filter(StringUtils::isNotBlank).isPresent()
127+
&& StringUtils.isNotBlank(tExtRef.getDoName());
125128
}
126129

127130
private Optional<SclReportItem> updateSourceDataSetsAndControlBlocks(TExtRef extRef, String targetBayUuid, List<TFCDA> allowedFcdas) {
@@ -186,8 +189,8 @@ private void createDataSetWithFCDA(TExtRef extRef, LDeviceAdapter sourceLDevice,
186189

187190
private void createControlBlockWithTarget(TExtRef extRef, LDeviceAdapter sourceLDevice, DataAttributeRef sourceDa, String cbName, String datSet) {
188191
String sourceLDName = sourceLDevice.getLdName();
189-
String cbId = getParentAdapter().generateControlBlockId(sourceLDName, cbName);
190-
ControlBlockAdapter controlBlockAdapter = sourceLDevice.getLN0Adapter().createControlBlockIfNotExists(cbName, cbId, datSet, ControlBlockEnum.from(extRef.getServiceType()));
192+
String idSeed = "%s/%s.%s".formatted(StringUtils.trimToEmpty(sourceLDName), TLLN0Enum.LLN_0.value(), cbName);
193+
ControlBlockAdapter controlBlockAdapter = sourceLDevice.getLN0Adapter().createControlBlockIfNotExists(cbName, idSeed, datSet, ControlBlockEnum.from(extRef.getServiceType()));
191194
if (sourceDa.getFc() != TFCEnum.ST && controlBlockAdapter.getCurrentElem() instanceof TReportControl tReportControl) {
192195
tReportControl.getTrgOps().setDchg(false);
193196
tReportControl.getTrgOps().setQchg(false);
@@ -206,13 +209,13 @@ private void setExtRefSrcAttributes(TExtRef extRef, String cbName) {
206209

207210
private static String generateDataSetSuffix(TExtRef extRef, DataAttributeRef sourceDa, boolean isBayInternal) {
208211
return extRef.getLdInst().toUpperCase(Locale.ENGLISH) + ATTRIBUTE_VALUE_SEPARATOR
209-
+ switch (extRef.getServiceType()) {
212+
+ switch (extRef.getServiceType()) {
210213
case GOOSE -> "G" + ((sourceDa.getFc() == TFCEnum.ST) ? "S" : "M");
211214
case SMV -> "SV";
212215
case REPORT -> (sourceDa.getFc() == TFCEnum.ST) ? "DQC" : "CYC";
213216
case POLL -> throw new IllegalArgumentException(MESSAGE_POLL_SERVICE_TYPE_NOT_SUPPORTED);
214217
}
215-
+ (isBayInternal ? "I" : "E");
218+
+ (isBayInternal ? "I" : "E");
216219
}
217220

218221
private Optional<SclReportItem> removeFilteredSourceDas(TExtRef extRef, final Set<DataAttributeRef> sourceDas, List<TFCDA> allowedFcdas) {
@@ -236,9 +239,9 @@ private boolean isFcdaAllowed(DataAttributeRef dataAttributeRef, List<TFCDA> all
236239
throw new IllegalArgumentException("parameters must not be blank");
237240
}
238241
return allowedFcdas.stream().anyMatch(tfcda -> tfcda.getDoName().equals(doName)
239-
&& tfcda.getDaName().equals(daName)
240-
&& tfcda.getLnClass().equals(lnClass)
241-
&& tfcda.getFc().value().equals(fc));
242+
&& tfcda.getDaName().equals(daName)
243+
&& tfcda.getLnClass().equals(lnClass)
244+
&& tfcda.getFc().value().equals(fc));
242245
}
243246

244247
private Optional<SclReportItem> removeFilterSourceDaForReport(TExtRef extRef, Set<DataAttributeRef> sourceDas) {
@@ -264,7 +267,7 @@ private SclRootAdapter getSclRootAdapter() {
264267
* @return list ExtRefs without duplication
265268
*/
266269
public List<TExtRef> filterDuplicatedExtRefs() {
267-
return new ExtRefService().filterDuplicatedExtRefs(currentElem.getExtRef());
270+
return new ExtRefService().filterDuplicatedExtRefs(currentElem.getExtRef());
268271
}
269272

270273
}

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

Lines changed: 11 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import org.lfenergy.compas.sct.commons.scl.ied.*;
2121
import org.lfenergy.compas.sct.commons.scl.ldevice.LDeviceAdapter;
2222
import org.lfenergy.compas.sct.commons.util.ControlBlockEnum;
23+
import org.lfenergy.compas.sct.commons.util.Utils;
2324

2425
import java.util.*;
2526
import java.util.stream.Collectors;
@@ -53,9 +54,6 @@
5354
* <li>{@link AbstractLNAdapter#getDAI <em>Returns the value of the <b>DataAttributeRef </b> containment reference By filter</em>}</li>
5455
* <li>{@link AbstractLNAdapter#getDAIValues(DataAttributeRef) <em>Returns <b>DAI (sGroup, value) </b> containment reference list By <b>DataAttributeRef </b> filter</em>}</li>
5556
*
56-
* <li>{@link AbstractLNAdapter#getDataSetByName(String) <em>Returns the value of the <b>TDataSet </b>object reference By the value of the <b>name </b>attribute </em>}</li>
57-
*
58-
* <li>{@link AbstractLNAdapter#getControlBlocks(List, TServiceType) <em>Returns the value of the <b>ControlBlock </b>containment reference list that match <b>datSet </b> value of given <b>TDataSet</b> </em>}</li>
5957
* <li>{@link AbstractLNAdapter#addPrivate <em>Add <b>TPrivate </b>under this object</em>}</li>
6058
* <li>{@link AbstractLNAdapter#removeAllControlBlocksAndDatasets() <em>Remove all <b>ControlBlock</b></em>}</li>
6159
* </ul>
@@ -81,7 +79,7 @@ public abstract class AbstractLNAdapter<T extends TAnyLN> extends SclElementAdap
8179

8280
public static final DoTypeName MOD_DO_TYPE_NAME = new DoTypeName(MOD_DO_NAME);
8381
public static final DaTypeName STVAL_DA_TYPE_NAME = new DaTypeName(STVAL_DA_NAME);
84-
private static final String DAI_MOD_STVAL_VALUE_ON = "on";
82+
private static final int CONTROLBLOCK_ID_MAX_LENGTH = 14;
8583

8684
/**
8785
* Constructor
@@ -264,7 +262,7 @@ public void updateExtRefBinders(ExtRefInfo extRefInfo) throws ScdException {
264262
log.warn("More the one desc for ExtRef [pDO({}),intAddr({})] in {}{}/{}",
265263
signalInfo.getPDO(), signalInfo.getIntAddr(), iedName, ldInst, getLNClass());
266264
}
267-
TExtRef extRef = tExtRefs.get(0);
265+
TExtRef extRef = tExtRefs.getFirst();
268266
// update ExtRef with binding info
269267
updateExtRefBindingInfo(extRef, extRefInfo);
270268
}
@@ -555,7 +553,7 @@ public TExtRef extractExtRefFromExtRefInfo(@NonNull ExtRefInfo extRefInfo) {
555553
log.error(msg);
556554
throw new ScdException(msg);
557555
}
558-
TExtRef extRef = extRefs.get(0);// to be refined : what's the criteria for ExtRef's uniqueness
556+
TExtRef extRef = extRefs.getFirst();// to be refined : what's the criteria for ExtRef's uniqueness
559557
ExtRefBindingInfo bindingInfo = extRefInfo.getBindingInfo();
560558
if (!bindingInfo.isWrappedIn(extRef)) {
561559
String msg = "No relation between binding info and the matched TExtRef";
@@ -952,46 +950,29 @@ public Stream<ControlBlockAdapter> streamControlBlocks(ControlBlockEnum controlB
952950

953951
/**
954952
* Create ControlBlock if there is no ControlBlock of the same type (controlBlockEnum) and with the same cbName in this LN/LN0.
955-
* When the controlBlock already exists, the id and datSet attributes are NOT updated with the given values.
953+
* When the controlBlock already exists, the idSeed and datSet attributes are NOT updated with the given values.
956954
*
957955
* @param cbName cbName of the controlBlock to look for. When not found, the cbName of the controlBlock to create.
958-
* @param id When controlBlock not found, the id of the controlBlock to create
956+
* @param idSeed When controlBlock not found, the text that will be used to compute the controlBlock Id (appId, smvId, rptId)
959957
* @param datSet the datSet of the controlBlock to create
960958
* @param controlBlockEnum the type of ControlBlock to create
961959
* @return existing controlBlock if a controlBlock of the same type and with same cbName was found in this LN/LN0, otherwise the created ControlBlock.
962960
* The returned ControlBlock is always a child of this LN/LN0.
963961
*/
964-
public ControlBlockAdapter createControlBlockIfNotExists(String cbName, String id, String datSet, ControlBlockEnum controlBlockEnum) {
962+
public ControlBlockAdapter createControlBlockIfNotExists(String cbName, String idSeed, String datSet, ControlBlockEnum controlBlockEnum) {
963+
String computedId = Utils.sha256(idSeed).substring(0, CONTROLBLOCK_ID_MAX_LENGTH);
965964
return findControlBlock(cbName, controlBlockEnum)
966965
.orElseGet(() -> addControlBlock(
967966
switch (controlBlockEnum) {
968-
case GSE -> new GooseControlBlock(cbName, id, datSet);
969-
case SAMPLED_VALUE -> new SMVControlBlock(cbName, id, datSet);
970-
case REPORT -> new ReportControlBlock(cbName, id, datSet);
967+
case GSE -> new GooseControlBlock(cbName, computedId, datSet);
968+
case SAMPLED_VALUE -> new SMVControlBlock(cbName, computedId, datSet);
969+
case REPORT -> new ReportControlBlock(cbName, computedId, datSet);
971970
default -> throw new IllegalArgumentException("Unsupported ControlBlock Type " + controlBlockEnum);
972971
}
973972
)
974973
);
975974
}
976975

977-
/**
978-
* Generate a ControlBlock Id based on the current LN and the given ldName (ldName can be different from the parent LD.name)
979-
*
980-
* @param ldName LD name to use for generating the id
981-
* @param cbName name of the ControlBlock
982-
* @return "ldName/LnPrefixLnClassLnInst.cbName". Blank values are omitted (e.g "IEDNAME1LD1/LLN0.CBNAME1")
983-
*/
984-
public String generateControlBlockId(String ldName, String cbName) {
985-
String s = getLNInst();
986-
String s1 = getPrefix();
987-
return StringUtils.trimToEmpty(ldName)
988-
+ "/"
989-
+ StringUtils.trimToEmpty(s1)
990-
+ StringUtils.defaultString(getLNClass(), "")
991-
+ StringUtils.trimToEmpty(s)
992-
+ "."
993-
+ StringUtils.trimToEmpty(cbName);
994-
}
995976

996977
/**
997978
* Finds all FCDAs in DataSet of Control Block feeding ExtRef

0 commit comments

Comments
 (0)