Skip to content

Commit

Permalink
fix(#470) : completeFromDAInstance should replace dataTypeTemplate Va…
Browse files Browse the repository at this point in the history
…l by DAI Val

Signed-off-by: massifben <[email protected]>
  • Loading branch information
massifben committed Feb 5, 2025
1 parent 19c0efb commit 0942908
Show file tree
Hide file tree
Showing 9 changed files with 177 additions and 75 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public List<DoLinkedToDa> getAllSDOLinkedToDa(TDataTypeTemplates dtt, TDOType td
List<DoLinkedToDa> result = new ArrayList<>();
// DA -> BDA -> BDA..
sdoOrDAService.getDAs(tdoType).forEach(tda -> {
DoLinkedToDa doLinkedToDa = DoLinkedToDa.copyFrom(doLinkedToDaTemplate);
DoLinkedToDa doLinkedToDa = doLinkedToDaTemplate.deepCopy();
doLinkedToDa.dataAttribute().setDaName(tda.getName());
if (tda.isSetFc()) {
doLinkedToDa.dataAttribute().setFc(tda.getFc());
Expand All @@ -57,7 +57,7 @@ public List<DoLinkedToDa> getAllSDOLinkedToDa(TDataTypeTemplates dtt, TDOType td
if (tsdo.isSetType()) {
findDoType(dtt, tdoType1 -> tdoType1.getId().equals(tsdo.getType()))
.ifPresent(nextDoType -> {
DoLinkedToDa newDoLinkedToDa = DoLinkedToDa.copyFrom(doLinkedToDaTemplate);
DoLinkedToDa newDoLinkedToDa = doLinkedToDaTemplate.deepCopy();
newDoLinkedToDa.dataObject().getSdoNames().add(tsdo.getName());
if (nextDoType.isSetCdc()) {
newDoLinkedToDa.dataObject().setCdc(nextDoType.getCdc());
Expand All @@ -73,7 +73,7 @@ private Stream<DoLinkedToDa> getDaLinkedToBDA(TDataTypeTemplates dtt, TDAType td
// BDA -> BDA -> BDA..
return bdaService.getBDAs(tdaType1)
.flatMap(tbda -> {
DoLinkedToDa newDoLinkedToDa = DoLinkedToDa.copyFrom(doLinkedToDaTemplate);
DoLinkedToDa newDoLinkedToDa = doLinkedToDaTemplate.deepCopy();
newDoLinkedToDa.dataAttribute().getBdaNames().add(tbda.getName());

// STRUCT type (BType=STRUCT) refer to complex BDA object, otherwise it is kind of DA object
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,13 +146,14 @@ public void updateOrCreateDOAndDAInstances(TAnyLN tAnyLN, DoLinkedToDa doLinkedT
});
}

public void completeFromDAInstance(TIED tied, String ldInst, TAnyLN anyLN, DoLinkedToDa doLinkedToDa) {
public DoLinkedToDa completeFromDAInstance(TIED tied, String ldInst, TAnyLN anyLN, DoLinkedToDa doLinkedToDa) {
DoLinkedToDa result = doLinkedToDa.deepCopy();
getDOAndDAInstances(anyLN, doLinkedToDa.toFilter())
.ifPresent(tdai -> {
if (tdai.isSetVal()) {
doLinkedToDa.dataAttribute().addDaVal(tdai.getVal());
result.dataAttribute().addDaVal(tdai.getVal());
}
if (doLinkedToDa.dataAttribute().getFc() == TFCEnum.SG || doLinkedToDa.dataAttribute().getFc() == TFCEnum.SE) {
if (result.dataAttribute().getFc() == TFCEnum.SG || result.dataAttribute().getFc() == TFCEnum.SE) {
if (hasSettingGroup(tdai)) {
boolean isIedHasConfSG = tied.isSetAccessPoint() &&
tied.getAccessPoint().stream()
Expand All @@ -163,15 +164,16 @@ public void completeFromDAInstance(TIED tied, String ldInst, TAnyLN anyLN, DoLin
&& tAccessPoint.getServices() != null
&& tAccessPoint.getServices().getSettingGroups() != null
&& tAccessPoint.getServices().getSettingGroups().getConfSG() != null);
doLinkedToDa.dataAttribute().setValImport((!tdai.isSetValImport() || tdai.isValImport()) && isIedHasConfSG);
result.dataAttribute().setValImport((!tdai.isSetValImport() || tdai.isValImport()) && isIedHasConfSG);
} else {
log.warn(String.format("Inconsistency in the SCD file - DAI= %s with fc= %s must have a sGroup attribute", tdai.getName(), doLinkedToDa.dataAttribute().getFc()));
doLinkedToDa.dataAttribute().setValImport(false);
log.warn("Inconsistency in the SCD file - DAI= {} with fc= {} must have a sGroup attribute", tdai.getName(), result.dataAttribute().getFc());
result.dataAttribute().setValImport(false);
}
} else if (tdai.isSetValImport()) {
doLinkedToDa.dataAttribute().setValImport(tdai.isValImport());
result.dataAttribute().setValImport(tdai.isValImport());
}
});
return result;
}

public boolean matchesLn(TAnyLN tAnyLN, String lnClass, String lnInst, String lnPrefix) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

@Getter
@Setter
Expand All @@ -26,19 +27,24 @@ public class DataAttribute {
private List<String> bdaNames = new ArrayList<>();
private List<DaVal> daiValues = new ArrayList<>();

public static DataAttribute copyFrom(DataAttribute dataAttribute) {
DataAttribute dataAttribute1 = new DataAttribute();
dataAttribute1.setDaName(dataAttribute.getDaName());
dataAttribute1.setFc(dataAttribute.getFc());
dataAttribute1.setBType(dataAttribute.getBType());
dataAttribute1.setType(dataAttribute.getType());
dataAttribute1.getBdaNames().addAll(dataAttribute.getBdaNames());
dataAttribute1.setValImport(dataAttribute.isValImport());
return dataAttribute1;
public DataAttribute deepCopy() {
DataAttribute dataAttribute = new DataAttribute();
dataAttribute.setDaName(getDaName());
dataAttribute.setType(getType());
dataAttribute.setBType(getBType());
dataAttribute.setFc(getFc());
dataAttribute.setValImport(isValImport());
dataAttribute.getBdaNames().addAll(getBdaNames());
dataAttribute.getDaiValues().addAll(getDaiValues());
return dataAttribute;
}

public void addDaVal(List<TVal> vals) {
vals.forEach(tVal -> daiValues.add(new DaVal(tVal.isSetSGroup() ? tVal.getSGroup() : null, tVal.getValue())));
vals.forEach(tVal -> {
Long settingGroup = tVal.isSetSGroup() ? tVal.getSGroup() : null;
daiValues.removeIf(daVal -> Objects.equals(daVal.settingGroup(), settingGroup));
daiValues.add(new DaVal(settingGroup, tVal.getValue()));
});
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ public DataObject(String doName, TPredefinedCDCEnum cdc, List<String> sdoNames)
this.sdoNames.addAll(sdoNames);
}

public static DataObject copyFrom(DataObject dataObject) {
return new DataObject(dataObject.getDoName(), dataObject.getCdc(), dataObject.getSdoNames());
public DataObject deepCopy() {
return new DataObject(getDoName(), getCdc(), getSdoNames());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@

public record DoLinkedToDa(DataObject dataObject, DataAttribute dataAttribute) {

public static DoLinkedToDa copyFrom(DoLinkedToDa doLinkedToDa) {
public DoLinkedToDa deepCopy() {
return new DoLinkedToDa(
DataObject.copyFrom(doLinkedToDa.dataObject()),
DataAttribute.copyFrom(doLinkedToDa.dataAttribute()));
dataObject().deepCopy(),
dataAttribute().deepCopy());
}

public String getDoRef() {
Expand Down
Loading

0 comments on commit 0942908

Please sign in to comment.