Skip to content

Commit

Permalink
[REVIEW] WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
samirromdhani committed Mar 20, 2024
1 parent 538d117 commit 925762a
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public Set<DataAttributeRef> getDAI(SCL scd, String iedName, String ldInst, Data
.map(tied1 -> ldeviceService.findLdevice(tied1, tlDevice -> tlDevice.getInst().equals(ldInst))
.map(tlDevice -> Stream.concat(tlDevice.getLN().stream(), Stream.of(tlDevice.getLN0()))
.filter(anyLN -> tAnyLNPredicate.test(anyLN, dataAttributeRef))
.flatMap(tAnyLN -> dataTypeTemplatesService.getFilteredDOAndDA(scd.getDataTypeTemplates(), tAnyLN, LnKey.updateDataRef(tAnyLN, dataAttributeRef))
.flatMap(tAnyLN -> dataTypeTemplatesService.getFilteredDOAndDA(scd.getDataTypeTemplates(), tAnyLN, DataAttributeRef.updateDataRef(tAnyLN, dataAttributeRef))
.map(dataAttribute -> {
lnService.completeFromDAInstance(tied1, tlDevice.getInst(), tAnyLN, dataAttribute);
return dataAttribute;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,31 @@ public static DataAttributeRef copyFrom(DataAttributeRef source) {
return dataAttributeRef;
}

public static DataAttributeRef updateDataRef(TAnyLN anyLN, DataAttributeRef dataAttributeRef) {
DataAttributeRef filter = copyFrom(dataAttributeRef);
if(anyLN.isSetLnType()) {
filter.setLnType(anyLN.getLnType());
}
switch (anyLN){
case TLN0 tln0 -> {
if(tln0.isSetInst()) filter.setLnInst(tln0.getInst());
if(tln0.isSetLnClass()) filter.setLnClass(tln0.getLnClass().get(0));
filter.setPrefix(StringUtils.EMPTY);
}
case TLN tln -> {
if(tln.isSetInst()) filter.setLnInst(tln.getInst());
if(tln.isSetLnClass()) filter.setLnClass(tln.getLnClass().get(0));
if(tln.isSetPrefix()) {
filter.setPrefix(tln.getPrefix());
} else {
filter.setPrefix(StringUtils.EMPTY);
}
}
default -> throw new RuntimeException("not possible");
}
return filter;
}

/**
* Checks if DA/DO is updatable
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
import lombok.Getter;
import org.apache.commons.lang3.StringUtils;
import org.lfenergy.compas.scl2007b4.model.*;
import org.lfenergy.compas.sct.commons.dto.DataAttributeRef;


@Getter
@EqualsAndHashCode
Expand All @@ -35,30 +33,5 @@ public LnKey(TLN tln) {
this.prefix = tln.getPrefix();
}

public static DataAttributeRef updateDataRef(TAnyLN anyLN, DataAttributeRef dataAttributeRef) {
DataAttributeRef filter = DataAttributeRef.copyFrom(dataAttributeRef);
if(anyLN.isSetLnType()) {
filter.setLnType(anyLN.getLnType());
}
switch (anyLN){
case TLN0 tln0 -> {
if(tln0.isSetInst()) filter.setLnInst(tln0.getInst());
if(tln0.isSetLnClass()) filter.setLnClass(tln0.getLnClass().get(0));
filter.setPrefix(StringUtils.EMPTY);
}
case TLN tln -> {
if(tln.isSetInst()) filter.setLnInst(tln.getInst());
if(tln.isSetLnClass()) filter.setLnClass(tln.getLnClass().get(0));
if(tln.isSetPrefix()) {
filter.setPrefix(tln.getPrefix());
} else {
filter.setPrefix(StringUtils.EMPTY);
}
}
default -> throw new RuntimeException("not possible");
}
return filter;
}

}

Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.junit.jupiter.params.provider.MethodSource;
import org.lfenergy.compas.scl2007b4.model.*;
import org.lfenergy.compas.sct.commons.scl.ln.LNAdapter;
import org.lfenergy.compas.sct.commons.scl.ln.LnKey;

import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -356,4 +357,39 @@ void constructor_from_TFCDA_should_ignore_blank_fc() {
.isEqualTo("prefixlnClasslnInst.DoName.sdo.daName.bda");
assertThat(dataAttributeRef.getFc()).isNull();
}

@Test
void test_updateDataRef_withLN() {
//Given
DataAttributeRef dataAttributeRef = new DataAttributeRef();
TLN ln = new TLN();
ln.setLnType("LnTypeAny");
ln.setInst("1");
ln.getLnClass().add(TSystemLNGroupEnum.LGOS.value());
// When
DataAttributeRef result = DataAttributeRef.updateDataRef(ln, dataAttributeRef);
// Then
assertThat(result).extracting(DataAttributeRef::getLnType,
DataAttributeRef::getPrefix,
DataAttributeRef::getLnClass,
DataAttributeRef::getLnInst)
.containsExactly("LnTypeAny", "", "LGOS", "1");
}

@Test
void test_updateDataRef_withLN0() {
//Given
DataAttributeRef dataAttributeRef = new DataAttributeRef();
LN0 ln0 = new LN0();
ln0.setLnType("LnType0");
ln0.getLnClass().add(TLLN0Enum.LLN_0.value());
// When
DataAttributeRef result = DataAttributeRef.updateDataRef(ln0, dataAttributeRef);
// Then
assertThat(result).extracting(DataAttributeRef::getLnType,
DataAttributeRef::getPrefix,
DataAttributeRef::getLnClass,
DataAttributeRef::getLnInst)
.containsExactly("LnType0", "", "LLN0", null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,50 +5,46 @@

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

import org.apache.commons.lang3.StringUtils;
import org.junit.jupiter.api.Test;
import org.lfenergy.compas.scl2007b4.model.LN0;
import org.lfenergy.compas.scl2007b4.model.TLLN0Enum;
import org.lfenergy.compas.scl2007b4.model.TLN;
import org.lfenergy.compas.scl2007b4.model.TSystemLNGroupEnum;
import org.lfenergy.compas.sct.commons.dto.DataAttributeRef;

import static org.assertj.core.api.Assertions.assertThat;

class LnKeyTest {

@Test
void test_updateDataRef_withLN() {
void test_LnKey_withLN() {
//Given
DataAttributeRef dataAttributeRef = new DataAttributeRef();
TLN ln = new TLN();
ln.setLnType("LnTypeAny");
ln.setInst("1");
ln.getLnClass().add(TSystemLNGroupEnum.LGOS.value());
// When
DataAttributeRef result = LnKey.updateDataRef(ln, dataAttributeRef);
LnKey lnKey = new LnKey(ln);
// Then
assertThat(result).extracting(DataAttributeRef::getLnType,
DataAttributeRef::getPrefix,
DataAttributeRef::getLnClass,
DataAttributeRef::getLnInst)
.containsExactly("LnTypeAny", "", "LGOS", "1");
assertThat(lnKey.getLnType()).isEqualTo("LnTypeAny");
assertThat(lnKey.getLnClass()).isEqualTo("LGOS");
assertThat(lnKey.getInst()).isEqualTo("1");
assertThat(lnKey.getPrefix()).isEqualTo(StringUtils.EMPTY);
}

@Test
void test_updateDataRef_withLN0() {
void test_LnKey_withLN0() {
//Given
DataAttributeRef dataAttributeRef = new DataAttributeRef();
LN0 ln0 = new LN0();
ln0.setLnType("LnType0");
ln0.getLnClass().add(TLLN0Enum.LLN_0.value());
// When
DataAttributeRef result = LnKey.updateDataRef(ln0, dataAttributeRef);
LnKey lnKey = new LnKey(ln0);
// Then
assertThat(result).extracting(DataAttributeRef::getLnType,
DataAttributeRef::getPrefix,
DataAttributeRef::getLnClass,
DataAttributeRef::getLnInst)
.containsExactly("LnType0", "", "LLN0", null);
assertThat(lnKey.getLnType()).isEqualTo("LnType0");
assertThat(lnKey.getLnClass()).isEqualTo("LLN0");
assertThat(lnKey.getInst()).isEqualTo("");
assertThat(lnKey.getPrefix()).isEqualTo(StringUtils.EMPTY);
}

}

0 comments on commit 925762a

Please sign in to comment.