Skip to content

Commit a9a33d1

Browse files
feat(tSubstation): update 90-30 SourceRef source also
1 parent 776961c commit a9a33d1

File tree

2 files changed

+65
-1
lines changed

2 files changed

+65
-1
lines changed

tSubstation/updateSubstation.spec.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { updateSubstation } from "./updateSubstation.js";
77

88
const aa1 = findElement(substation, 'Substation[name="AA1"]') as Element;
99
const aa2 = findElement(substation, 'Substation[name="AA2"]') as Element;
10+
const aa3 = findElement(substation, 'Substation[name="AA3"]') as Element;
1011

1112
const e1 = new DOMParser()
1213
.parseFromString('<VoltageLevel name="e1" />', "application/xml")
@@ -163,5 +164,26 @@ describe("update Substation element", () => {
163164
),
164165
).to.exist;
165166
});
167+
168+
it("updates SourceRef source attribute", () => {
169+
const edits = updateSubstation({
170+
element: aa3,
171+
attributes: { name: "AA9" },
172+
});
173+
174+
expect(edits.length).to.equal(5);
175+
expect(edits[1].attributes.source).to.equal(
176+
"AA9/J1/Q01/QA2/CBR/CSWI1/OpCls.general",
177+
);
178+
expect(edits[2].attributes.source).to.equal(
179+
"AA9/J1/Q01/QA2/CBR/CSWI1/OpCls.q",
180+
);
181+
expect(edits[3].attributes.source).to.equal(
182+
"AA9/J1/Q01/QA2/CBR/CSWI1/OpOpn.general",
183+
);
184+
expect(edits[4].attributes.source).to.equal(
185+
"AA9/J1/Q01/QA2/CBR/CSWI1/OpOpn.q",
186+
);
187+
});
166188
});
167189
});

tSubstation/updateSubstation.ts

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,41 @@
11
import { Update } from "../foundation/utils.js";
22

3+
function updateSourceRef(
4+
element: Element,
5+
{
6+
oldSubstation,
7+
newSubstation,
8+
}: {
9+
oldSubstation: string;
10+
newSubstation: string;
11+
},
12+
): Update[] {
13+
const sourceRefs = Array.from(
14+
element.ownerDocument.querySelectorAll(
15+
'Private[type="eIEC61850-6-100"]>LNodeInputs>SourceRef',
16+
),
17+
);
18+
19+
const updates: Update[] = [];
20+
21+
sourceRefs.forEach((srcRef) => {
22+
const source = srcRef.getAttribute("source");
23+
if (!source) return;
24+
25+
const oldPath = `${oldSubstation}`;
26+
27+
if (!source.startsWith(oldPath)) return;
28+
29+
const newPath = `${newSubstation}`;
30+
updates.push({
31+
element: srcRef,
32+
attributes: { source: source.replace(oldPath, newPath) },
33+
});
34+
});
35+
36+
return updates.filter((update) => update) as Update[];
37+
}
38+
339
function updateConnectivityNodes(
440
substation: Element,
541
substationName: string,
@@ -83,5 +119,11 @@ export function updateSubstation(update: Update): Update[] {
83119
const newName = attributes.name;
84120
if (!oldName || oldName === newName) return [update];
85121

86-
return [update].concat(...updateConnectivityNodes(substation, newName));
122+
return [update].concat(
123+
...updateConnectivityNodes(substation, newName),
124+
...updateSourceRef(substation, {
125+
oldSubstation: oldName,
126+
newSubstation: newName,
127+
}),
128+
);
87129
}

0 commit comments

Comments
 (0)