Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/447 rsr 1116 update ln modstval based on compas lnodestatus #448

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
import org.lfenergy.compas.sct.commons.domain.DoLinkedToDa;
import org.lfenergy.compas.sct.commons.domain.DoLinkedToDaFilter;

import java.util.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.function.Predicate;
import java.util.stream.Stream;

Expand All @@ -30,18 +32,19 @@ public class DataTypeTemplatesService implements DataTypeTemplateReader {

/**
* verify if DO(name=Mod)/DA(name=stVal) exists in DataTypeTemplate
* @param dtt TDataTypeTemplates where Data object and Data attribute exists
*
* @param dtt TDataTypeTemplates where Data object and Data attribute exists
* @param lNodeTypeId LNode Type ID where Data object exists
* DataTypeTemplates model :
* <DataTypeTemplates>
* <LNodeType lnClass="LNodeTypeClass" id="LNodeTypeID">
* <DO name="Mod" type="DOModTypeID" ../>
* </LNodeType>
* ...
* <DOType cdc="DOTypeCDC" id="DOModTypeID">
* <DA name="stVal" ../>
* </DOType>
* </DataTypeTemplates>
* DataTypeTemplates model :
* <DataTypeTemplates>
* <LNodeType lnClass="LNodeTypeClass" id="LNodeTypeID">
* <DO name="Mod" type="DOModTypeID" ../>
* </LNodeType>
* ...
* <DOType cdc="DOTypeCDC" id="DOModTypeID">
* <DA name="stVal" ../>
* </DOType>
* </DataTypeTemplates>
* @return true if the Data Object (Mod) and Data attribute (stVal) present, false otherwise
*/
public boolean isDoModAndDaStValExist(TDataTypeTemplates dtt, String lNodeTypeId) {
Expand All @@ -54,16 +57,14 @@ public boolean isDoModAndDaStValExist(TDataTypeTemplates dtt, String lNodeTypeId

@Override
public Stream<DoLinkedToDa> getAllDoLinkedToDa(TDataTypeTemplates dtt) {
return lnodeTypeService.getLnodeTypes(dtt)
return lnodeTypeService.getLnodeTypes(dtt)
.flatMap(tlNodeType -> {
DoLinkedToDa doLinkedToDa = new DoLinkedToDa();
doLinkedToDa.setDataObject(new DataObject());
doLinkedToDa.setDataAttribute(new DataAttribute());
DoLinkedToDa doLinkedToDa = new DoLinkedToDa(new DataObject(), new DataAttribute());
return tlNodeType.getDO()
.stream()
.map(tdo -> doTypeService.findDoType(dtt, tdoType -> tdoType.getId().equals(tdo.getType()))
.map(doType -> {
doLinkedToDa.getDataObject().setDoName(tdo.getName());
doLinkedToDa.dataObject().setDoName(tdo.getName());
return doTypeService.getAllSDOLinkedToDa(dtt, doType, doLinkedToDa).stream();
}))
.filter(Optional::isPresent)
Expand All @@ -78,41 +79,49 @@ public Stream<DoLinkedToDa> getFilteredDoLinkedToDa(TDataTypeTemplates dtt, Stri
.flatMap(tlNodeType -> doService.getFilteredDos(tlNodeType, tdo -> StringUtils.isBlank(doLinkedToDaFilter.doName())
|| doLinkedToDaFilter.doName().equals(tdo.getName()))
.flatMap(tdo -> {
DoLinkedToDa doLinkedToDa = new DoLinkedToDa();
DataObject dataObject = new DataObject();
dataObject.setDoName(tdo.getName());
doLinkedToDa.setDataObject(dataObject);
doLinkedToDa.setDataAttribute(new DataAttribute());
DoLinkedToDa doLinkedToDa = new DoLinkedToDa(dataObject, new DataAttribute());
return doTypeService.findDoType(dtt, tdoType -> tdoType.getId().equals(tdo.getType()))
.stream()
.flatMap(tdoType -> {
doLinkedToDa.getDataObject().setCdc(tdoType.getCdc());
doLinkedToDa.dataObject().setCdc(tdoType.getCdc());
return doTypeService.getAllSDOLinkedToDa(dtt, tdoType, doLinkedToDa).stream()
.filter(doLinkedToDa1 -> StringUtils.isBlank(doLinkedToDaFilter.doName())
|| (doLinkedToDa1.getDoRef().startsWith(doLinkedToDaFilter.getDoRef()) && StringUtils.isBlank(doLinkedToDaFilter.daName()))
|| doLinkedToDa1.getDaRef().startsWith(doLinkedToDaFilter.getDaRef()));
});
}));
}));
}

@Override
public Optional<DoLinkedToDa> findDoLinkedToDa(TDataTypeTemplates dtt, String lNodeTypeId, DoLinkedToDa doLinkedToDa) {
List<String> dataRefList = new ArrayList<>(doLinkedToDa.getDataObject().getSdoNames());
dataRefList.addAll(doLinkedToDa.getDataAttribute().getBdaNames());
public Optional<DoLinkedToDa> findDoLinkedToDa(TDataTypeTemplates dtt, String lNodeTypeId, DoLinkedToDaFilter doLinkedToDaFilter) {
List<String> dataRefList = new ArrayList<>(doLinkedToDaFilter.sdoNames());
dataRefList.addAll(doLinkedToDaFilter.bdaNames());

return lnodeTypeService.findLnodeType(dtt, lNodeType -> lNodeTypeId.equals(lNodeType.getId()))
.flatMap(lNodeType -> doService.findDo(lNodeType, tdo -> tdo.getName().equals(doLinkedToDa.getDataObject().getDoName()))
.flatMap(lNodeType -> doService.findDo(lNodeType, tdo -> tdo.getName().equals(doLinkedToDaFilter.doName()))
// Search DoType for each DO
.flatMap(tdo -> doTypeService.findDoType(dtt, doType -> doType.getId().equals(tdo.getType()))
.flatMap(tdoType -> {
// Search last DoType from DOType (SDO) > DOType (SDO)
TDOType lastDoType = findDOTypeBySdoName(dtt, tdoType, dataRefList);
// Prepare DataObject
DataObject dataObject = new DataObject(tdo.getName(), tdoType.getCdc(), doLinkedToDaFilter.sdoNames());
// Search first DA from last DoType
return sdoOrDAService.findDA(lastDoType, tda1 -> tda1.getName().equals(doLinkedToDa.getDataAttribute().getDaName()))
return sdoOrDAService.findDA(lastDoType, tda -> tda.getName().equals(doLinkedToDaFilter.daName()))
.flatMap(tda -> {
// Prepare DataAttribute
DataAttribute dataAttribute = new DataAttribute();
dataAttribute.setDaName(tda.getName());
dataAttribute.setFc(tda.getFc());
// Check if first DA is STRUCT or not
if(!tda.getBType().equals(TPredefinedBasicTypeEnum.STRUCT)) {
return Optional.of(doLinkedToDa);
if (!tda.getBType().equals(TPredefinedBasicTypeEnum.STRUCT)) {
dataAttribute.addDaVal(tda.getVal());
dataAttribute.setBType(tda.getBType());
dataAttribute.setType(tda.getType());
dataAttribute.setValImport(tda.isValImport());
return Optional.of(new DoLinkedToDa(dataObject, dataAttribute));
}
// Search first DaType from DOType (from last DOType where DA is STRUCT)
return getDATypeByDaName(dtt, lastDoType, tda.getName())
Expand All @@ -122,11 +131,18 @@ public Optional<DoLinkedToDa> findDoLinkedToDa(TDataTypeTemplates dtt, String lN
&& tbda.getBType().equals(TPredefinedBasicTypeEnum.STRUCT), dataRefList);

// last DAType should contain BDA not STRUCT
if(dataRefList.size() != 1) return Optional.empty();
if (dataRefList.size() != 1) return Optional.empty();
String lastBdaName = dataRefList.getFirst();
return bdaService.findBDA(lastDAType, tbda -> tbda.getName().equals(lastBdaName)
&& !tbda.getBType().equals(TPredefinedBasicTypeEnum.STRUCT))
.flatMap(tbda -> Optional.of(doLinkedToDa));
.flatMap(tbda -> {
dataAttribute.getBdaNames().addAll(doLinkedToDaFilter.bdaNames());
dataAttribute.setBType(tbda.getBType());
dataAttribute.setType(tbda.getType());
dataAttribute.setValImport(tbda.isValImport());
dataAttribute.addDaVal(tbda.getVal());
return Optional.of(new DoLinkedToDa(dataObject, dataAttribute));
});
});
});
})
Expand All @@ -139,7 +155,7 @@ private Optional<TDAType> getDATypeByDaName(TDataTypeTemplates dtt, TDOType tdoT
}

private TDOType findDOTypeBySdoName(TDataTypeTemplates dtt, TDOType tdoType, List<String> sdoNames) {
if(sdoNames.isEmpty()) return tdoType;
if (sdoNames.isEmpty()) return tdoType;
return sdoOrDAService.findSDO(tdoType, tsdo -> tsdo.getName().equals(sdoNames.getFirst()))
.flatMap(tsdo -> doTypeService.findDoType(dtt, tdoType2 -> tdoType2.getId().equals(tsdo.getType())))
.map(tdoType2 -> {
Expand All @@ -149,7 +165,7 @@ private TDOType findDOTypeBySdoName(TDataTypeTemplates dtt, TDOType tdoType, Lis
}

private TDAType findDATypeByBdaName(TDataTypeTemplates dtt, TDAType tdaType, Predicate<TBDA> tbdaPredicate, List<String> bdaNames) {
if(bdaNames.isEmpty()) return tdaType;
if (bdaNames.isEmpty()) return tdaType;
return bdaService.getFilteredBDAs(tdaType, tbdaPredicate)
.findFirst()
.flatMap(tbda -> daTypeService.findDaType(dtt, tbda.getType()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@

public class DoTypeService {

final DaTypeService daTypeService = new DaTypeService();
final SDOOrDAService sdoOrDAService = new SDOOrDAService();
final BDAService bdaService = new BDAService();
final DaTypeService daTypeService = new DaTypeService();
final SDOOrDAService sdoOrDAService = new SDOOrDAService();
final BDAService bdaService = new BDAService();

public Stream<TDOType> getDoTypes(TDataTypeTemplates tDataTypeTemplates) {
return tDataTypeTemplates.getDOType().stream();
Expand All @@ -37,53 +37,54 @@ public List<DoLinkedToDa> getAllSDOLinkedToDa(TDataTypeTemplates dtt, TDOType td
// DA -> BDA -> BDA..
sdoOrDAService.getDAs(tdoType).forEach(tda -> {
DoLinkedToDa doLinkedToDa = DoLinkedToDa.copyFrom(doLinkedToDaTemplate);
doLinkedToDa.getDataAttribute().setDaName(tda.getName());
if(tda.isSetFc()) {
doLinkedToDa.getDataAttribute().setFc(tda.getFc());
doLinkedToDa.dataAttribute().setDaName(tda.getName());
if (tda.isSetFc()) {
doLinkedToDa.dataAttribute().setFc(tda.getFc());
}

// STRUCT type (BType=STRUCT) refer to BDA, otherwise it is DA
if(TPredefinedBasicTypeEnum.STRUCT.equals(tda.getBType())) {
if (TPredefinedBasicTypeEnum.STRUCT.equals(tda.getBType())) {
daTypeService.findDaType(dtt, tda.getType())
.ifPresent(nextDaType -> result.addAll(getDaLinkedToBDA(dtt, nextDaType, doLinkedToDa).toList()));
} else {
doLinkedToDa.setDataAttribute(updateDataAttributeFromDaOrBda(tda, doLinkedToDa.getDataAttribute()));
result.add(doLinkedToDa);
DataAttribute dataAttribute = updateDataAttributeFromDaOrBda(tda, doLinkedToDa.dataAttribute());
result.add(new DoLinkedToDa(doLinkedToDa.dataObject(), dataAttribute));
}
});
// SDO -> SDO -> SDO..
sdoOrDAService.getSDOs(tdoType)
.forEach(tsdo -> {
if(tsdo.isSetType()){
findDoType(dtt, tdoType1 -> tdoType1.getId().equals(tsdo.getType()))
.ifPresent(nextDoType -> {
DoLinkedToDa newDoLinkedToDa = DoLinkedToDa.copyFrom(doLinkedToDaTemplate);
newDoLinkedToDa.getDataObject().getSdoNames().add(tsdo.getName());
if(nextDoType.isSetCdc()) {
newDoLinkedToDa.getDataObject().setCdc(nextDoType.getCdc());
}
result.addAll(getAllSDOLinkedToDa(dtt, nextDoType, newDoLinkedToDa));
});
if (tsdo.isSetType()) {
findDoType(dtt, tdoType1 -> tdoType1.getId().equals(tsdo.getType()))
.ifPresent(nextDoType -> {
DoLinkedToDa newDoLinkedToDa = DoLinkedToDa.copyFrom(doLinkedToDaTemplate);
newDoLinkedToDa.dataObject().getSdoNames().add(tsdo.getName());
if (nextDoType.isSetCdc()) {
newDoLinkedToDa.dataObject().setCdc(nextDoType.getCdc());
}
result.addAll(getAllSDOLinkedToDa(dtt, nextDoType, newDoLinkedToDa));
});
}
});
return result;
}

private Stream<DoLinkedToDa> getDaLinkedToBDA(TDataTypeTemplates dtt, TDAType tdaType1, DoLinkedToDa doLinkedToDaTemplate) {
// BDA -> BDA -> BDA..
return bdaService.getBDAs(tdaType1)
.flatMap(tbda -> {
DoLinkedToDa newDoLinkedToDa = DoLinkedToDa.copyFrom(doLinkedToDaTemplate);
newDoLinkedToDa.getDataAttribute().getBdaNames().add(tbda.getName());
newDoLinkedToDa.dataAttribute().getBdaNames().add(tbda.getName());

// STRUCT type (BType=STRUCT) refer to complex BDA object, otherwise it is kind of DA object
if(TPredefinedBasicTypeEnum.STRUCT.equals(tbda.getBType())){
return daTypeService.findDaType(dtt, tbda.getType())
if (TPredefinedBasicTypeEnum.STRUCT.equals(tbda.getBType())) {
return daTypeService.findDaType(dtt, tbda.getType())
.stream().flatMap(nextDaType -> getDaLinkedToBDA(dtt, nextDaType, newDoLinkedToDa));
} else {
newDoLinkedToDa.setDataAttribute(updateDataAttributeFromDaOrBda(tbda, newDoLinkedToDa.getDataAttribute()));
return Stream.of(newDoLinkedToDa);
DataAttribute dataAttribute = updateDataAttributeFromDaOrBda(tbda, newDoLinkedToDa.dataAttribute());
return Stream.of(new DoLinkedToDa(newDoLinkedToDa.dataObject(), dataAttribute));
}
});
});
}

private DataAttribute updateDataAttributeFromDaOrBda(TAbstractDataAttribute daOrBda, DataAttribute dataAttribute) {
Expand All @@ -94,4 +95,4 @@ private DataAttribute updateDataAttributeFromDaOrBda(TAbstractDataAttribute daOr
return dataAttribute;
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -307,15 +307,12 @@ public void epfPostProcessing(SCL scd) {
&& (purPoseDAI.get().getVal().getFirst().getValue().startsWith("DYN_LDEPF_DIGITAL CHANNEL")
|| purPoseDAI.get().getVal().getFirst().getValue().startsWith("DYN_LDEPF_ANALOG CHANNEL"));
if(isSetSrcRefExistAndEmpty && isPurposeExistAndMatchChannel) {

DoLinkedToDa doLinkedToDa = new DoLinkedToDa();
DataObject dataObject = new DataObject();
dataObject.setDoName(tdoi.getName());
doLinkedToDa.setDataObject(dataObject);
DataAttribute dataAttribute = new DataAttribute();
dataAttribute.setDaName(SETSRCREF_DA_NAME);
dataAttribute.setDaiValues(List.of(new DaVal(null, tied.getName()+tlDevice.getInst()+"/LPHD0.Proxy")));
doLinkedToDa.setDataAttribute(dataAttribute);
DoLinkedToDa doLinkedToDa = new DoLinkedToDa(dataObject, dataAttribute);
lnEditor.updateOrCreateDOAndDAInstances(tlDevice.getLN0(), doLinkedToDa);
}
})));
Expand Down
Loading
Loading