Skip to content

Commit

Permalink
update documentation, implement issues #43, #42 and #37
Browse files Browse the repository at this point in the history
Signed-off-by: Mohamed Sylla <mohamed.sylla@rte-france.com>
  • Loading branch information
syllamoh authored and SaintierFr committed Feb 17, 2022
1 parent 5699cb0 commit 5e9ac6e
Show file tree
Hide file tree
Showing 23 changed files with 268 additions and 92 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public abstract class ControlBlock<T extends ControlBlock> extends LNodeMetaData
protected String name;
protected String dataSetRef;
protected String desc;
protected long confRev;
protected Long confRev;
protected List<TControlWithIEDName.IEDName> iedNames = new ArrayList<>();
protected TPredefinedTypeOfSecurityEnum securityEnable = TPredefinedTypeOfSecurityEnum.NONE;

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

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

if(name == null || name.isBlank()){
throw new ScdException("Control block Name is missing");
}

if(dataSetRef != null && dataSetRef.isBlank()){
throw new ScdException("Control block datSet is missing");
throw new ScdException("A required field is missing: name");
}

if(iedNames.stream().anyMatch( iedName -> iedName == null ||
Expand All @@ -78,12 +74,17 @@ public void validateDestination(SclRootAdapter sclRootAdapter) throws ScdExcepti
.orElseThrow(
() -> new ScdException(
String.format(
"Unknown LDevice [%s] in IED [%s]", iedName.getLdInst(),iedName.getValue()
"Control block destination: Unknown LDevice [%s] in IED [%s]",
iedName.getLdInst(),iedName.getValue()
)
)
);
if(!iedName.getLnClass().isEmpty()) {
lDeviceAdapter.getLNAdapter(iedName.getLnClass().get(0),iedName.getLnInst(), iedName.getPrefix());
try {
lDeviceAdapter.getLNAdapter(iedName.getLnClass().get(0), iedName.getLnInst(), iedName.getPrefix());
} catch (ScdException e){
throw new ScdException("Control block destination: " + e.getMessage());
}
} else {
Utils.setField(iedName,"lnClass",null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,16 @@ public FCDAInfo(String dataSet, TFCDA tfcda) {
@JsonIgnore
public TFCDA getFCDA(){
TFCDA tfcda = new TFCDA();
tfcda.setFc(fc);
tfcda.setLdInst(ldInst);
tfcda.getLnClass().add(lnClass);

if(!StringUtils.isBlank(lnInst)){
tfcda.setLnInst(lnInst);
tfcda.setFc(fc);
if(!StringUtils.isBlank(lnClass)){
tfcda.getLnClass().add(lnClass);
if(!StringUtils.isBlank(lnInst)){
tfcda.setLnInst(lnInst);
}
if(!StringUtils.isBlank(prefix)){
tfcda.setPrefix(prefix);
}
}

if(doName != null && doName.isDefined()){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,13 @@ public TReportControl createControlBlock() {

return reportControl;
}

@Override
public void validateCB() throws ScdException {
super.validateCB();

if(dataSetRef != null && dataSetRef.isBlank()){
throw new ScdException("A required field is missing: datSet");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ public class SMVControlBlock extends ControlBlock<SMVControlBlock>{
private TSampledValueControl.SmvOpts smvOpts;
private TProtocol protocol;
private boolean multicast = true;
private long smpRate;
private long nofASDU;
private Long smpRate;
private Long nofASDU;
private TSmpMod smpMod = TSmpMod.SMP_PER_PERIOD;


Expand Down Expand Up @@ -78,6 +78,22 @@ protected void validateSecurityEnabledValue(TServices tServices) throws ScdExcep
}
}

@Override
public void validateCB() throws ScdException {
super.validateCB();

if(dataSetRef != null && dataSetRef.isBlank()){
throw new ScdException("A required field is missing: datSet");
}
if(smpRate == null){
throw new ScdException("A required field is missing: smpRate");
}

if(nofASDU == null){
throw new ScdException("A required field is missing: nofASDU ");
}
}

@Override
public TSampledValueControl createControlBlock() {

Expand All @@ -95,8 +111,13 @@ public TSampledValueControl createControlBlock() {
if(smpMod != null) {
sampledValueControl.setSmpMod(smpMod);
}
sampledValueControl.setSmpRate(smpRate);
sampledValueControl.setNofASDU(nofASDU);
if(smpRate != null) {
sampledValueControl.setSmpRate(smpRate);
}

if(nofASDU != null) {
sampledValueControl.setNofASDU(nofASDU);
}
if(protocol != null) {
sampledValueControl.setProtocol(protocol);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,9 @@

import org.lfenergy.compas.scl2007b4.model.TEnumType;
import org.lfenergy.compas.scl2007b4.model.TEnumVal;
import org.lfenergy.compas.sct.commons.dto.DaTypeName;
import org.lfenergy.compas.sct.commons.dto.ResumedDataTemplate;
import org.lfenergy.compas.sct.commons.scl.SclElementAdapter;

import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.Objects;;

public class EnumTypeAdapter extends AbstractDataTypeAdapter<TEnumType>{

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public Optional<String> getDOTypeId(String doName){
.findFirst();
}

public List<ResumedDataTemplate> getResumedDTTs(ResumedDataTemplate filter) {
public List<ResumedDataTemplate> getResumedDTTs(@NonNull ResumedDataTemplate filter) {

List<ResumedDataTemplate> resumedDataTemplates = new ArrayList<>();
if(filter.isDaNameDefined()) {
Expand All @@ -101,14 +101,12 @@ public List<ResumedDataTemplate> getResumedDTTs(ResumedDataTemplate filter) {
}
ResumedDataTemplate rootResumedRTT = new ResumedDataTemplate();
rootResumedRTT.setLnType(currentElem.getId());
if(filter != null) {
rootResumedRTT.setLnClass(filter.getLnClass());
rootResumedRTT.setLnInst(filter.getLnInst());
rootResumedRTT.setPrefix(filter.getPrefix());
}
rootResumedRTT.setLnClass(filter.getLnClass());
rootResumedRTT.setLnInst(filter.getLnInst());
rootResumedRTT.setPrefix(filter.getPrefix());

for(TDO tdo : currentElem.getDO()){
if(filter != null && filter.isDoNameDefined() &&
if(filter.isDoNameDefined() &&
!filter.getDoName().getName().equals(tdo.getName())){
continue;
}
Expand Down Expand Up @@ -173,13 +171,10 @@ public void check(@NonNull DoTypeName doTypeName, @NonNull DaTypeName daTypeName

// check coherence between Data Object and Data Attributes information
DOTypeAdapter lastDoTypeAdapter;
String lastSdo;
if(adapterPair == null){
adapterPair = findPathFromDo2DA(doTypeName.getName(),daTypeName.getName());
lastDoTypeAdapter = adapterPair.getValue();
lastSdo = adapterPair.getKey();
} else {
lastSdo = adapterPair.getKey();
if(adapterPair.getRight().containsDAWithDAName(daTypeName.getName())){
lastDoTypeAdapter = adapterPair.getValue();
} else {
Expand Down Expand Up @@ -232,7 +227,7 @@ public List<ResumedDataTemplate> getResumedDTTByDaName(DaTypeName daTypeName) th
return rDtts;
}

public List<ResumedDataTemplate> getResumedDTTByDoName(DoTypeName doTypeName) throws ScdException {
public List<ResumedDataTemplate> getResumedDTTByDoName(DoTypeName doTypeName) {


DOAdapter doAdapter = getDOAdapterByName(doTypeName.getName()).orElseThrow();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public String getHeaderVersion() {
return currentElem.getVersion();
}

public List<? extends THitem> getHistoryItems() {
public List<THitem> getHistoryItems() {
if(currentElem.getHistory() == null) return new ArrayList<>();
return currentElem.getHistory().getHitem();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import org.lfenergy.compas.sct.commons.scl.ObjectReference;
import org.lfenergy.compas.sct.commons.scl.SclElementAdapter;

import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Stream;
Expand All @@ -36,7 +35,7 @@ public Boolean isValImport(){
return currentElem.isValImport();
}

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

public boolean matches(ObjectReference dataAttributes){
return false;
}

public void update(Long sGroup, String val) throws ScdException {
if(currentElem.isValImport() != null && !currentElem.isValImport().booleanValue()){
String msg = String.format(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.lfenergy.compas.sct.commons.dto.ExtRefInfo;
import org.lfenergy.compas.sct.commons.dto.ExtRefSignalInfo;
import org.lfenergy.compas.sct.commons.dto.ExtRefSourceInfo;
import org.lfenergy.compas.sct.commons.dto.FCDAInfo;
import org.lfenergy.compas.sct.commons.dto.GooseControlBlock;
import org.lfenergy.compas.sct.commons.dto.LNodeMetaData;
import org.lfenergy.compas.sct.commons.dto.ReportControlBlock;
Expand Down Expand Up @@ -69,8 +70,26 @@ public static LNAdapterBuilder builder(){
public abstract String getLNInst();
public abstract String getPrefix();

protected void addControlBlock(ReportControlBlock controlBlock) {
currentElem.getReportControl().add(controlBlock.createControlBlock());
protected void addControlBlock(ControlBlock<?> controlBlock) throws ScdException {

switch (controlBlock.getServiceType() ) {
case REPORT:
currentElem.getReportControl().add(controlBlock.createControlBlock());
break;
case GOOSE:
if(isLN0()) {
((LN0)currentElem).getGSEControl().add(controlBlock.createControlBlock());
}
break;
case SMV:
if(isLN0()) {
((LN0)currentElem).getSampledValueControl().add(controlBlock.createControlBlock());
}
break;
default:
throw new ScdException("Unknown control block type : " + controlBlock.getServiceType());

}
}

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

}

public boolean hasControlBlock(ControlBlock<? extends ControlBlock> controlBlock) {

switch (controlBlock.getServiceType()){
case REPORT:
return currentElem.getReportControl().stream()
.anyMatch(control -> control.getName().equals(controlBlock.getName()));
case GOOSE:
return isLN0() && ((LN0)currentElem).getGSEControl().stream()
.anyMatch(control -> control.getName().equals(controlBlock.getName()));
case SMV:
return isLN0() && ((LN0)currentElem).getSampledValueControl().stream()
.anyMatch(reportControl -> reportControl.getName().equals(controlBlock.getName()));
default:
return false;
}
}

public List<TDataSet> getDataSet(ExtRefInfo filter){
if (filter == null || filter.getSignalInfo() == null || filter.getBindingInfo() == null) {
return currentElem.getDataSet();
Expand Down Expand Up @@ -497,7 +533,7 @@ protected ResumedDataTemplate completeResumedDTTFromDAI(ResumedDataTemplate rDtt
*/
protected Optional<? extends AbstractDAIAdapter> findMatch(DoTypeName doTypeName, DaTypeName daTypeName){
DAITracker daiTracker = new DAITracker(this,doTypeName,daTypeName);
DAITracker.MatchResult matchResult = daiTracker.Search();
DAITracker.MatchResult matchResult = daiTracker.search();
if(matchResult != DAITracker.MatchResult.FULL_MATCH){
return Optional.empty();
}
Expand All @@ -513,7 +549,7 @@ public void updateDAI(@NonNull ResumedDataTemplate rDtt) throws ScdException {
DaTypeName daTypeName = rDtt.getDaName();

DAITracker daiTracker = new DAITracker(this,doTypeName,daTypeName);
DAITracker.MatchResult matchResult = daiTracker.Search();
DAITracker.MatchResult matchResult = daiTracker.search();
AbstractDAIAdapter<?> daiAdapter = null;
IDataParentAdapter doiOrSdoiAdapter;
if(matchResult == DAITracker.MatchResult.FULL_MATCH){
Expand Down Expand Up @@ -617,12 +653,22 @@ protected boolean matchesDataAttributes(String dataAttribute){
currentElem.getReportControl().stream().anyMatch(rptCtl -> rptCtl.getName().equals(dataAttribute));
}

public Set<DataSetInfo> getDataSet() {
public Optional<DataSetInfo> getDataSetByRef(String dataSetRef) {
return currentElem.getDataSet()
.stream().map(tDataSet -> DataSetInfo.from(tDataSet)).collect(Collectors.toSet());
.stream()
.filter(tDataSet -> tDataSet.getName().equals(dataSetRef))
.map(DataSetInfo::from)
.findFirst();
}

public void addDataSet(DataSetInfo dataSetInfo) {
TDataSet tDataSet = new TDataSet();
tDataSet.setName(dataSetInfo.getName());
tDataSet.getFCDA().addAll(
dataSetInfo.getFCDAInfos().stream().map(fcdaInfo -> fcdaInfo.getFCDA()).collect(Collectors.toList())
);
currentElem.getDataSet().add(tDataSet);

}

public DataTypeTemplateAdapter getDataTypeTemplateAdapter() {
Expand All @@ -631,7 +677,7 @@ public DataTypeTemplateAdapter getDataTypeTemplateAdapter() {

public Map<Long, String> getDAIValues(ResumedDataTemplate rDtt) {
DAITracker daiTracker = new DAITracker(this,rDtt.getDoName(),rDtt.getDaName());
DAITracker.MatchResult matchResult = daiTracker.Search();
DAITracker.MatchResult matchResult = daiTracker.search();
if(matchResult != DAITracker.MatchResult.FULL_MATCH){
return new HashMap<>();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import org.lfenergy.compas.sct.commons.dto.DoTypeName;
import org.lfenergy.compas.sct.commons.dto.ResumedDataTemplate;
import org.lfenergy.compas.sct.commons.exception.ScdException;
import org.lfenergy.compas.sct.commons.scl.SclService;
import org.lfenergy.compas.sct.commons.scl.dtt.DataTypeTemplateAdapter;
import org.lfenergy.compas.sct.commons.scl.dtt.LNodeTypeAdapter;

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

public MatchResult Search() {
public MatchResult search() {

Pair<? extends IDataAdapter,Integer> matchResult;
String doiName = doTypeName.getName();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,13 @@

package org.lfenergy.compas.sct.commons.scl.ied;

import lombok.NonNull;
import org.apache.commons.lang3.tuple.Pair;
import org.lfenergy.compas.scl2007b4.model.TAnyLN;
import org.lfenergy.compas.scl2007b4.model.TDAI;
import org.lfenergy.compas.scl2007b4.model.TDOI;
import org.lfenergy.compas.scl2007b4.model.TSDI;
import org.lfenergy.compas.sct.commons.dto.DoTypeName;
import org.lfenergy.compas.sct.commons.exception.ScdException;
import org.lfenergy.compas.sct.commons.scl.SclElementAdapter;
import org.yaml.snakeyaml.events.Event;

import java.util.List;
import java.util.Optional;

public class DOIAdapter extends SclElementAdapter<AbstractLNAdapter<? extends TAnyLN>, TDOI> implements IDataParentAdapter {

Expand Down Expand Up @@ -78,7 +72,7 @@ public RootSDIAdapter addSDOI(String sdoName) {
return new RootSDIAdapter(this,tsdi);
}

static public class DAIAdapter extends AbstractDAIAdapter<DOIAdapter> {
public static class DAIAdapter extends AbstractDAIAdapter<DOIAdapter> {

protected DAIAdapter(DOIAdapter parentAdapter, TDAI currentElem) {
super(parentAdapter, currentElem);
Expand Down
Loading

0 comments on commit 5e9ac6e

Please sign in to comment.