Skip to content

Commit

Permalink
feat DTT - SVC WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
romdhanisam committed Feb 27, 2024
1 parent a03d502 commit 908e7dc
Show file tree
Hide file tree
Showing 2 changed files with 114 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,70 @@ public boolean isDoModAndDaStValExist(TDataTypeTemplates dtt, String lNodeTypeId
.orElse(false);
}


private TDOType findDOTypeBySdoName(TDataTypeTemplates dtt, TDOType tdoType, List<String> sdoNames) {
System.out.println(":: recDOTypeBySdoName start with :: "+tdoType.getId());
if(sdoNames.isEmpty()) return tdoType;
return getDOTypeBySdoName(dtt, tdoType, sdoNames.get(0))
.map(tdoType1 -> {
sdoNames.remove(0);
System.out.println(":: DO Type found :: "+tdoType1.getId());
return findDOTypeBySdoName(dtt, tdoType1, sdoNames);
})
.orElse(tdoType);
}

private void findDATypeByBdaName(TDataTypeTemplates dtt, TDAType tdaType, List<String> bdaNames, List<SclReportItem> sclReportItems) {
System.out.println(":: recDATypeByBdaName start with :: "+tdaType.getId());
if(bdaNames.isEmpty()) return ;
getDATypeByBdaName(dtt, tdaType, bdaNames.get(0))
.ifPresentOrElse(tdaType1 -> {
System.out.println(":: DA Type found :: "+tdaType1.getId());
bdaNames.remove(0);
findDATypeByBdaName(dtt, tdaType1, bdaNames, sclReportItems);
}, () -> {
sclReportItems.add(SclReportItem.error(null,String.format("Unknown BDA.name (%s) in DAType.id (%s)",
bdaNames.get(0), tdaType.getId())));
});
}

public List<SclReportItem> isDoObjectsAndDataAttributesExistsV11(TDataTypeTemplates dtt, String lNodeTypeId, String dataRef) {
List<SclReportItem> sclReportItems = new ArrayList<>();
LinkedList<String> dataRefList = new LinkedList<>(Arrays.asList(dataRef.split("\\.")));
if (dataRefList.size() < 2) {
sclReportItems.add(SclReportItem.error(null, "Invalid data reference %s. At least DO name and DA name are required".formatted(dataRef)));
}
String doName = dataRefList.remove();
return lnodeTypeService.findLnodeType(dtt, lNodeType -> lNodeTypeId.equals(lNodeType.getId()))
.map(lNodeType -> doService.findDo(lNodeType, tdo -> tdo.getName().equals(doName))
.map(tdo -> doTypeService.findDoType(dtt, doType -> doType.getId().equals(tdo.getType()))
.map(tdoType -> {
TDOType lastDoType = findDOTypeBySdoName(dtt, tdoType, dataRefList);
Optional<TDAType> tdaType = getDATypeByDaName(dtt, lastDoType, dataRefList.get(0));
tdaType.ifPresentOrElse(tdaType1 -> {
System.out.println(":: DA Type found :: "+tdaType1.getId());
dataRefList.remove();
findDATypeByBdaName(dtt, tdaType1, dataRefList, sclReportItems);
}, ()-> sclReportItems.add(SclReportItem.error(null,
String.format("Unknown Sub Data Object SDO or Data Attribute DA (%s) in DOType.id (%s)",
dataRefList.get(0), lastDoType.getId()))));
return sclReportItems;
})
.orElseGet(() -> {
sclReportItems.add(SclReportItem.error(null, String.format("DOType.id (%s) for DO.name (%s) not found in DataTypeTemplates", tdo.getType(), tdo.getName())));
return sclReportItems;
}))
.orElseGet(() -> {
sclReportItems.add(SclReportItem.error(null, String.format("Unknown DO.name (%s) in DOType.id (%s)", doName, lNodeTypeId)));
return sclReportItems;
}))
.orElseGet(() -> {
sclReportItems.add(SclReportItem.error(null, "No Data Attribute found with this reference %s for LNodeType.id (%s)".formatted(dataRef, lNodeTypeId)));
return sclReportItems;
});
}


public List<SclReportItem> isDoObjectsAndDataAttributesExists(TDataTypeTemplates dtt, String lNodeTypeId, String dataRef) {
List<SclReportItem> sclReportItems = new ArrayList<>();
LinkedList<String> dataRefList = new LinkedList<>(Arrays.asList(dataRef.split("\\.")));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.assertj.core.api.Assertions;
import org.assertj.core.api.AssertionsForInterfaceTypes;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestClassOrder;
import org.lfenergy.compas.scl2007b4.model.*;
import org.lfenergy.compas.sct.commons.dto.DaTypeName;
import org.lfenergy.compas.sct.commons.dto.DataAttributeRef;
Expand All @@ -15,7 +16,7 @@

import java.util.List;

import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.AssertionsForClassTypes.assertThatCode;
import static org.lfenergy.compas.sct.commons.scl.dtt.DataTypeTemplateTestUtils.SCD_DTT_DO_SDO_DA_BDA;
import static org.lfenergy.compas.sct.commons.scl.dtt.DataTypeTemplateTestUtils.initDttAdapterFromFile;
Expand Down Expand Up @@ -166,10 +167,10 @@ void isDataAttributeExist2_should_find_DO_SDO_DA_and_BDA() {

assertThat(dataAttributeRefs.getDoRef()).isEqualTo("Do1.sdo1.sdo2");
assertThat(dataAttributeRefs.getDaRef()).isEqualTo("da2.bda1.bda2");
Assertions.assertThat(dataAttributeRefs).extracting(DataAttributeRef::getDoRef, DataAttributeRef::getDaRef)
assertThat(dataAttributeRefs).extracting(DataAttributeRef::getDoRef, DataAttributeRef::getDaRef)
.containsExactly("Do1.sdo1.sdo2", "da2.bda1.bda2");
Assertions.assertThat(dataAttributeRefs.getDoName().getCdc()).isEqualTo(TPredefinedCDCEnum.WYE);
Assertions.assertThat(dataAttributeRefs.getDaName()).extracting(DaTypeName::getBType, DaTypeName::getFc)
assertThat(dataAttributeRefs.getDoName().getCdc()).isEqualTo(TPredefinedCDCEnum.WYE);
assertThat(dataAttributeRefs.getDaName()).extracting(DaTypeName::getBType, DaTypeName::getFc)
.containsExactly(TPredefinedBasicTypeEnum.ENUM, TFCEnum.ST);
}

Expand All @@ -183,7 +184,7 @@ void isDoObjectsAndDataAttributesExists_test0() {
List<SclReportItem> sclReportItems = dataTypeTemplatesService.isDoObjectsAndDataAttributesExists(
dttAdapter.getCurrentElem(), "LN1", "Do1.sdo1.sdo2.da2.bda1.bda2");
// Then
AssertionsForInterfaceTypes.assertThat(sclReportItems).isEqualTo(List.of());
assertThat(sclReportItems).isEqualTo(List.of());
}


Expand All @@ -199,7 +200,7 @@ void isDoObjectsAndDataAttributesExists_when_LNodeType_not_exist() {
List<SclReportItem> sclReportItems = dataTypeTemplatesService.isDoObjectsAndDataAttributesExists(dtt,
"lnodeTypeId2", "Do1.sdo1.sdo2.da2.bda1.bda2");
// Then
AssertionsForInterfaceTypes.assertThat(sclReportItems)
assertThat(sclReportItems)
.hasSize(1)
.extracting(SclReportItem::message)
.containsExactly("No Data Attribute found with this reference Do1.sdo1.sdo2.da2.bda1.bda2 for LNodeType.id (lnodeTypeId2)");
Expand All @@ -221,7 +222,7 @@ void isDoObjectsAndDataAttributesExists_when_DO_not_exist() {
List<SclReportItem> sclReportItems = dataTypeTemplatesService.isDoObjectsAndDataAttributesExists(dtt,
"lnodeTypeId", "Mod.stVal");
// Then
AssertionsForInterfaceTypes.assertThat(sclReportItems)
assertThat(sclReportItems)
.hasSize(1)
.extracting(SclReportItem::message)
.containsExactly("Unknown DO.name (Mod) in DOType.id (lnodeTypeId)");
Expand All @@ -244,7 +245,7 @@ void isDoObjectsAndDataAttributesExists_when_DOType_not_exist() {
List<SclReportItem> sclReportItems = dataTypeTemplatesService.isDoObjectsAndDataAttributesExists(dtt,
"lnodeTypeId", "Mod.stVal");
// Then
AssertionsForInterfaceTypes.assertThat(sclReportItems)
assertThat(sclReportItems)
.hasSize(1)
.extracting(SclReportItem::message)
.containsExactly("DOType.id (doTypeId) for DO.name (Mod) not found in DataTypeTemplates");
Expand Down Expand Up @@ -272,7 +273,7 @@ void isDoObjectsAndDataAttributesExists_when_DA_not_exist() {
List<SclReportItem> sclReportItems = dataTypeTemplatesService.isDoObjectsAndDataAttributesExists(dtt,
"lnodeTypeId", "Mod.stVal");
// Then
AssertionsForInterfaceTypes.assertThat(sclReportItems)
assertThat(sclReportItems)
.hasSize(1)
.extracting(SclReportItem::message)
.containsExactly("Unknown Data Attribute DA (stVal) in DOType.id (doTypeId)");
Expand Down Expand Up @@ -301,7 +302,7 @@ void isDoObjectsAndDataAttributesExists_when_DO_DA_exist() {
List<SclReportItem> sclReportItems = dataTypeTemplatesService.isDoObjectsAndDataAttributesExists(dtt,
"lnodeTypeId", "Mod.stVal");
// Then
AssertionsForInterfaceTypes.assertThat(sclReportItems).isEmpty();
assertThat(sclReportItems).isEmpty();
}


Expand All @@ -314,6 +315,43 @@ void isDoObjectsAndDataAttributesExists_test01() {
List<SclReportItem> sclReportItems = dataTypeTemplatesService.isDoObjectsAndDataAttributesExists(
dttAdapter.getCurrentElem(), "LN1", "Do1.sdo1.sdo2.da2.bda1.bda2");
// Then
AssertionsForInterfaceTypes.assertThat(sclReportItems).isEqualTo(List.of());
assertThat(sclReportItems).isEqualTo(List.of());
}
}


@Test
void isDoObjectsAndDataAttributesExistsV11_test01() {
// Given
DataTypeTemplateAdapter dttAdapter = initDttAdapterFromFile(SCD_DTT_DO_SDO_DA_BDA);
// When
DataTypeTemplatesService dataTypeTemplatesService = new DataTypeTemplatesService();
List<SclReportItem> sclReportItems = dataTypeTemplatesService.isDoObjectsAndDataAttributesExistsV11(
dttAdapter.getCurrentElem(), "LN1", "Do1.sdo1.sdo2.da2.bda1.bda2");
// Then
assertThat(sclReportItems).isEqualTo(List.of());
}

@Test
void test() {
TDataTypeTemplates dtt = new TDataTypeTemplates();
TLNodeType tlNodeType = new TLNodeType();
tlNodeType.setId("lnodeTypeId");
TDO tdo = new TDO();
tdo.setType("doTypeId");
tdo.setName("Mod");
tlNodeType.getDO().add(tdo);
dtt.getLNodeType().add(tlNodeType);
TDOType tdoType = new TDOType();
tdoType.setId("doTypeId");
TDA tda = new TDA();
tda.setName("stVal");
tdoType.getSDOOrDA().add(tda);
dtt.getDOType().add(tdoType);
// When
DataTypeTemplatesService dataTypeTemplatesService = new DataTypeTemplatesService();
List<SclReportItem> sclReportItems = dataTypeTemplatesService.isDoObjectsAndDataAttributesExistsV11(
dtt, "lnodeTypeId", "Mod.stVal");
// Then
assertThat(sclReportItems).isEqualTo(List.of());
}
}

0 comments on commit 908e7dc

Please sign in to comment.