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(#405): Remove LDname limitation #406

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
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 @@ -66,6 +66,7 @@ public class LDeviceAdapter extends SclElementAdapter<IEDAdapter, TLDevice> {
private static final long INTG_PD_VALUE_FOR_FC_MX = 2000L;

private static final String DA_SETSRCREF = "setSrcRef";
private static final int MAXIMUM_LENGHT_LD_NAME_BY_XSD = 64;

/**
* Constructor
Expand Down Expand Up @@ -169,8 +170,8 @@ public String getXPath() {
*/
public void updateLDName() throws ScdException {
String newLdName = parentAdapter.getCurrentElem().getName() + currentElem.getInst();
if (newLdName.length() > 33) {
throw new ScdException(newLdName + "(IED.name + LDevice.inst) has more than 33 characters");
if (newLdName.length() > MAXIMUM_LENGHT_LD_NAME_BY_XSD) {
Copy link
Contributor

@samirromdhani samirromdhani Jul 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Knowing that the maxLength is an XSD constraint I think we shouldn't even care about verifying this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the problem is this occurs during the SCD creation

log.info(STEP_3);
sclEditor.importSTDElementsInSCD(scd, stds);

and the SCD XSD validation occurs far away, in this method :
com.rte_france.rspace.rconf.service.ScdService#createSCD

So maybe the users would like to be warned as soon as the error occurs ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, In order to maintain traceability I would recommend discussing this with @hkaroun for related issues like #7 and Jira tickets.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After discussing together, I will completely remove the check

throw new ScdException("LDName (IED.name + LDevice.inst) has more than 64 characters ("+newLdName+") wich is not allowed by xsd");
}
// renaming ldName
currentElem.setLdName(newLdName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,55 +39,52 @@

class LDeviceAdapterTest {

private IEDAdapter iAdapter;
private IEDAdapter iedAdapter;

@BeforeEach
public void init() {
SCL scd = SclTestMarshaller.getSCLFromFile("/ied-test-schema-conf/ied_unit_test.xml");
SclRootAdapter sclRootAdapter = new SclRootAdapter(scd);
iAdapter = assertDoesNotThrow(() -> sclRootAdapter.getIEDAdapterByName("IED_NAME"));
iedAdapter = assertDoesNotThrow(() -> sclRootAdapter.getIEDAdapterByName("IED_NAME"));
}

@Test
void updateLDName_when_ldName_pass_33_characters_should_throw_exception() {
void updateLDName_when_ldName_less_than_64_characters_should_not_throw_exception() {
// Given
LDeviceAdapter lDeviceAdapter = assertDoesNotThrow(()-> iAdapter.findLDeviceAdapterByLdInst("LD_INS1").get());
SCL std = SclTestMarshaller.getSCLFromFile("/std/std_sample.std");
TIED tied = std.getIED().getFirst();
TLDevice tlDevice = tied.getAccessPoint().getFirst().getServer().getLDevice().getFirst();
LDeviceAdapter lDeviceAdapter = new LDeviceAdapter(new IEDAdapter(new SclRootAdapter(std), tied), tlDevice);

//When
lDeviceAdapter.updateLDName();
assertThat(lDeviceAdapter.getLdName()).isEqualTo("IED_NAMELD_INS1");
assertThat(lDeviceAdapter.getInst()).isEqualTo("LD_INS1");
String iedName = new Random().ints(97, 122)
.limit(27)
.collect(StringBuilder::new, StringBuilder::appendCodePoint, StringBuilder::append)
.toString();
iAdapter.setIEDName(iedName);
// When Then
assertThatThrownBy(lDeviceAdapter::updateLDName)
.isInstanceOf(ScdException.class)
.hasMessageContaining("has more than 33 characters");

//When
assertThat(lDeviceAdapter.getLdName()).isEqualTo("IED4d4fe1a8cda64cf88a5ee4176a1a0eefLDSUIED");
assertThat(lDeviceAdapter.getInst()).isEqualTo("LDSUIED");
}

@Test
void updateLDName_when_ldName_less_than_33_characters_should_not_throw_exception() {
void updateLDName_when_ldName_pass_64_characters_should_throw_exception() {
// Given
LDeviceAdapter lDeviceAdapter = assertDoesNotThrow(()-> iAdapter.findLDeviceAdapterByLdInst("LD_INS1").get());
lDeviceAdapter.updateLDName();
assertThat(lDeviceAdapter.getLdName()).isEqualTo("IED_NAMELD_INS1");
assertThat(lDeviceAdapter.getInst()).isEqualTo("LD_INS1");
String iedName = new Random().ints(97, 122)
.limit(26)
.collect(StringBuilder::new, StringBuilder::appendCodePoint, StringBuilder::append)
.toString();
iAdapter.setIEDName(iedName);
SCL std = SclTestMarshaller.getSCLFromFile("/std/std_sample.std");
TIED tied = std.getIED().getFirst();
TLDevice tlDevice = tied.getAccessPoint().getFirst().getServer().getLDevice().getFirst();
tlDevice.setInst("LDSUIEDDDDDDDDDDDDDDDDDDDDDDDD");
LDeviceAdapter lDeviceAdapter = new LDeviceAdapter(new IEDAdapter(new SclRootAdapter(std), tied), tlDevice);

// When Then
assertThatCode(lDeviceAdapter::updateLDName).doesNotThrowAnyException();
assertThat(lDeviceAdapter.getLdName()).isEqualTo(iedName+"LD_INS1");
assertThatThrownBy(lDeviceAdapter::updateLDName)
.isInstanceOf(ScdException.class)
.hasMessage("LDName (IED.name + LDevice.inst) has more than 64 characters (IED4d4fe1a8cda64cf88a5ee4176a1a0eefLDSUIEDDDDDDDDDDDDDDDDDDDDDDDD)" +
" wich is not allowed by xsd");
}

@Test
@Tag("issue-321")
void testGetLNAdapters() {
// Given
LDeviceAdapter lDeviceAdapter = assertDoesNotThrow(()-> iAdapter.findLDeviceAdapterByLdInst("LD_INS2").get());
LDeviceAdapter lDeviceAdapter = assertDoesNotThrow(()-> iedAdapter.findLDeviceAdapterByLdInst("LD_INS2").get());
assertThat(lDeviceAdapter.getLNAdapters()).hasSize(1);
// When Then
assertDoesNotThrow(() -> lDeviceAdapter.getLNAdapter("ANCR","1",null));
Expand All @@ -99,7 +96,7 @@ void testGetLNAdapters() {
@Test
void findLnAdapter_shouldReturnAdapter(){
// Given
LDeviceAdapter lDeviceAdapter = iAdapter.findLDeviceAdapterByLdInst("LD_INS2").get();
LDeviceAdapter lDeviceAdapter = iedAdapter.findLDeviceAdapterByLdInst("LD_INS2").get();
// When
Optional<LNAdapter> lnAdapter = lDeviceAdapter.findLnAdapter("ANCR", "1", null);
// Then
Expand All @@ -110,7 +107,7 @@ void findLnAdapter_shouldReturnAdapter(){
@Test
void getExtRefBinders_whenExist_shouldReturnExtRefBindingInfo() {
//Given
LDeviceAdapter lDeviceAdapter = assertDoesNotThrow(()-> iAdapter.findLDeviceAdapterByLdInst("LD_INS2").get());
LDeviceAdapter lDeviceAdapter = assertDoesNotThrow(()-> iedAdapter.findLDeviceAdapterByLdInst("LD_INS2").get());
ExtRefSignalInfo signalInfo = DTO.createExtRefSignalInfo();
signalInfo.setPDO("Do.sdo1");
signalInfo.setPDA("da.bda1.bda2.bda3");
Expand All @@ -122,7 +119,7 @@ void getExtRefBinders_whenExist_shouldReturnExtRefBindingInfo() {
@Test
void getExtRefBinders_when_PLN_NotMatch_shouldReturnEmptyList() {
//Given
LDeviceAdapter lDeviceAdapter = assertDoesNotThrow(()-> iAdapter.getLDeviceAdapterByLdInst("LD_INS2"));
LDeviceAdapter lDeviceAdapter = assertDoesNotThrow(()-> iedAdapter.getLDeviceAdapterByLdInst("LD_INS2"));
ExtRefSignalInfo signalInfo = new ExtRefSignalInfo();
signalInfo.setPLN("CSWI");
//When Then
Expand All @@ -133,7 +130,7 @@ void getExtRefBinders_when_PLN_NotMatch_shouldReturnEmptyList() {
@Test
void getExtRefBinders_when_PLN_NotSet_shouldReturnEmptyList() {
//Given
LDeviceAdapter lDeviceAdapter = assertDoesNotThrow(()-> iAdapter.getLDeviceAdapterByLdInst("LD_INS2"));
LDeviceAdapter lDeviceAdapter = assertDoesNotThrow(()-> iedAdapter.getLDeviceAdapterByLdInst("LD_INS2"));
ExtRefSignalInfo signalInfo = new ExtRefSignalInfo();
//When Then
assertDoesNotThrow(()-> lDeviceAdapter.getExtRefBinders(signalInfo));
Expand All @@ -144,7 +141,7 @@ void getExtRefBinders_when_PLN_NotSet_shouldReturnEmptyList() {
@Tag("issue-321")
void getExtRefInfo_should_return_expected_list_of_ExtRefInfo() {
// Given
LDeviceAdapter lDeviceAdapter = assertDoesNotThrow(()-> iAdapter.getLDeviceAdapterByLdInst("LD_INS2"));
LDeviceAdapter lDeviceAdapter = assertDoesNotThrow(()-> iedAdapter.getLDeviceAdapterByLdInst("LD_INS2"));
// When
List<ExtRefInfo> extRefInfoList = assertDoesNotThrow(lDeviceAdapter::getExtRefInfo);
// Then
Expand All @@ -155,7 +152,7 @@ void getExtRefInfo_should_return_expected_list_of_ExtRefInfo() {
@Tag("issue-321")
void TestGetDAI() {
// Given
LDeviceAdapter lDeviceAdapter = assertDoesNotThrow(()-> iAdapter.getLDeviceAdapterByLdInst("LD_INS1"));
LDeviceAdapter lDeviceAdapter = assertDoesNotThrow(()-> iedAdapter.getLDeviceAdapterByLdInst("LD_INS1"));
// When
var dataAttributeRefs = lDeviceAdapter.getDAI(new DataAttributeRef(),true);
// Then
Expand All @@ -170,7 +167,7 @@ void TestGetDAI() {
assertThat(dataAttributeRefs).hasSize(4);

// Given
lDeviceAdapter = assertDoesNotThrow(()-> iAdapter.findLDeviceAdapterByLdInst("LD_INS2").get());
lDeviceAdapter = assertDoesNotThrow(()-> iedAdapter.findLDeviceAdapterByLdInst("LD_INS2").get());
filter.setLnClass("ANCR");
filter.setLnInst("1");
// When
Expand All @@ -183,7 +180,7 @@ void TestGetDAI() {
@Tag("issue-321")
void addPrivate_with_type_and_source_should_create_Private() {
// Given
LDeviceAdapter lDeviceAdapter = assertDoesNotThrow(()-> iAdapter.getLDeviceAdapterByLdInst("LD_INS2"));
LDeviceAdapter lDeviceAdapter = assertDoesNotThrow(()-> iedAdapter.getLDeviceAdapterByLdInst("LD_INS2"));
TPrivate tPrivate = new TPrivate();
tPrivate.setType("Private Type");
tPrivate.setSource("Private Source");
Expand Down Expand Up @@ -230,7 +227,7 @@ void getLDeviceStatus_should_succeed() {
@Test
void getLNAdaptersIncludingLN0_should_return_expected_list_of_AbstractLNAdapter() {
//Given
LDeviceAdapter lDeviceAdapter = assertDoesNotThrow(()-> iAdapter.getLDeviceAdapterByLdInst("LD_INS2"));
LDeviceAdapter lDeviceAdapter = assertDoesNotThrow(()-> iedAdapter.getLDeviceAdapterByLdInst("LD_INS2"));
//When
List<AbstractLNAdapter<?>> lnAdapters = lDeviceAdapter.getLNAdaptersIncludingLN0();
//Then
Expand Down
Loading