From 05afeb4afa2d675ffe6ad759e3f3781865582e92 Mon Sep 17 00:00:00 2001 From: Daniel Mulholland Date: Thu, 10 Nov 2022 18:40:05 +1300 Subject: [PATCH 1/2] Import IEDs with Communication section if IED named TEMPLATECloses #1074 --- src/menu/ImportIEDs.ts | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/src/menu/ImportIEDs.ts b/src/menu/ImportIEDs.ts index f1ec23ae0..ef5b0a1a0 100644 --- a/src/menu/ImportIEDs.ts +++ b/src/menu/ImportIEDs.ts @@ -373,15 +373,22 @@ export async function importIED( doc: XMLDocument, dispatchObject: HTMLElement ): Promise { - if (ied.getAttribute('name') === 'TEMPLATE') - ied.setAttribute( - 'name', + if (ied.getAttribute('name') === 'TEMPLATE') { + const newIedName = 'TEMPLATE_IED' + - (Array.from(doc.querySelectorAll('IED')).filter(ied => - ied.getAttribute('name')?.includes('TEMPLATE') - ).length + - 1) - ); + (Array.from(doc.querySelectorAll('IED')).filter(ied => + ied.getAttribute('name')?.includes('TEMPLATE') + ).length + + 1); + + ied.setAttribute('name', newIedName); + + Array.from( + ied.ownerDocument.querySelectorAll( + ':root > Communication > SubNetwork > ConnectedAP[iedName="TEMPLATE"]' + ) + ).forEach(connectedAp => connectedAp.setAttribute('iedName', newIedName)); + } if (!isIedNameUnique(ied, doc)) { dispatchObject.dispatchEvent( From eabba3ff413b5cac1be5dd03aa150c1877b46d6b Mon Sep 17 00:00:00 2001 From: Daniel Mulholland Date: Thu, 10 Nov 2022 20:58:12 +1300 Subject: [PATCH 2/2] Add test --- .../editors/triggered/ImportIedsPlugin.test.ts | 14 ++++++++++++++ test/testfiles/importieds/template.icd | 16 ++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/test/integration/editors/triggered/ImportIedsPlugin.test.ts b/test/integration/editors/triggered/ImportIedsPlugin.test.ts index a11d00754..ad2c34c71 100644 --- a/test/integration/editors/triggered/ImportIedsPlugin.test.ts +++ b/test/integration/editors/triggered/ImportIedsPlugin.test.ts @@ -86,6 +86,20 @@ describe('ImportIedsPlugin', () => { expect(element.doc.querySelector('IED[name="TEMPLATE_IED2"]')).to.exist; }); + it('imports the ConnectedAPs for a TEMPLATE IED', async () => { + const templateIED1 = await fetch( + '/test/testfiles/importieds/template.icd' + ) + .then(response => response.text()) + .then(str => new DOMParser().parseFromString(str, 'application/xml')); + element.prepareImport(templateIED1, doc); + expect( + element.doc?.querySelectorAll( + ':root > Communication > SubNetwork > ConnectedAP[iedName="TEMPLATE_IED1"]' + ) + ).to.exist; + }); + it('loads unique lnodetypes to the project', () => { expect( element.doc?.querySelectorAll(':root > DataTypeTemplates > LNodeType') diff --git a/test/testfiles/importieds/template.icd b/test/testfiles/importieds/template.icd index f86897e73..8e54e0079 100644 --- a/test/testfiles/importieds/template.icd +++ b/test/testfiles/importieds/template.icd @@ -1,6 +1,22 @@
+ + + +
+

192.168.210.111

+

255.255.255.0

+

192.168.210.1

+

1,3,9999,23

+

23

+

00000001

+

0001

+

0001

+
+
+
+