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

fix(menu/importieds) Import IEDs with Communication section if IED named TEMPLATE #1075

Merged
merged 2 commits into from
Nov 22, 2022
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
23 changes: 15 additions & 8 deletions src/menu/ImportIEDs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -373,15 +373,22 @@ export async function importIED(
doc: XMLDocument,
dispatchObject: HTMLElement
): Promise<void> {
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(
Expand Down
14 changes: 14 additions & 0 deletions test/integration/editors/triggered/ImportIedsPlugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
16 changes: 16 additions & 0 deletions test/testfiles/importieds/template.icd
Original file line number Diff line number Diff line change
@@ -1,6 +1,22 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<SCL xmlns="http://www.iec.ch/61850/2003/SCL" version="2007" revision="B" release="4">
<Header id="TestIID"/>
<Communication>
<SubNetwork type="8-MMS" name="NewSubNetwork">
<ConnectedAP iedName="TEMPLATE" apName="E">
<Address>
<P type="IP">192.168.210.111</P>
<P type="IP-SUBNET">255.255.255.0</P>
<P type="IP-GATEWAY">192.168.210.1</P>
<P type="OSI-AP-Title">1,3,9999,23</P>
<P type="OSI-AE-Qualifier">23</P>
<P type="OSI-PSEL">00000001</P>
<P type="OSI-SSEL">0001</P>
<P type="OSI-TSEL">0001</P>
</Address>
</ConnectedAP>
</SubNetwork>
</Communication>
<IED name="TEMPLATE" type="DummyIED" manufacturer="DummyManufactorer" configVersion="1" originalSclVersion="2007" originalSclRevision="B" owner="DummyOwner">
<Services>
<DynAssociation />
Expand Down