fix(uns): #1040 every effective-name computation goes through EquipmentReferenceMap.EffectiveName
The two sites the issue named (DataConnectionValidator, LocalExportCatalog line 56) were already converted by #1002; the remaining inline copies were not. EquipmentReferenceMap.EffectiveNames itself used '??', so an empty override dropped the reference instead of naming it after its tag; the artifact-side ACL resolver used IsNullOrWhiteSpace. Both now agree with the one rule, as do the UnsTreeService rows, the composer and the local-export alarm reservation.
This commit is contained in:
@@ -97,8 +97,7 @@ public static class EquipmentReferenceMap
|
||||
var names = new HashSet<string>(StringComparer.Ordinal);
|
||||
foreach (var r in references)
|
||||
{
|
||||
var effectiveName = r.DisplayNameOverride
|
||||
?? (tagNameById.TryGetValue(r.TagId, out var n) ? n : null);
|
||||
var effectiveName = EffectiveName(r.DisplayNameOverride, tagNameById.TryGetValue(r.TagId, out var n) ? n : null);
|
||||
if (!string.IsNullOrEmpty(effectiveName)) names.Add(effectiveName);
|
||||
}
|
||||
return names;
|
||||
|
||||
@@ -139,13 +139,13 @@ public sealed class UnsTreeService(
|
||||
// Backing tag missing (should not happen — raw-tag delete is reference-blocked); surface a
|
||||
// clearly-degraded row rather than dropping it so the operator can remove the dangling ref.
|
||||
rows.Add(new EquipmentReferenceRow(
|
||||
r.UnsTagReferenceId, r.DisplayNameOverride ?? "(missing tag)", "(missing tag)",
|
||||
r.UnsTagReferenceId, EquipmentReferenceMap.EffectiveName(r.DisplayNameOverride, "(missing tag)")!, "(missing tag)",
|
||||
"", TagAccessLevel.Read, r.DisplayNameOverride, r.SortOrder, r.RowVersion));
|
||||
continue;
|
||||
}
|
||||
|
||||
var rawPath = resolver?.TryBuildTagPath(tag.DeviceId, tag.TagGroupId, tag.Name) ?? tag.Name;
|
||||
var effectiveName = string.IsNullOrEmpty(r.DisplayNameOverride) ? tag.Name : r.DisplayNameOverride;
|
||||
var effectiveName = EquipmentReferenceMap.EffectiveName(r.DisplayNameOverride, tag.Name)!;
|
||||
rows.Add(new EquipmentReferenceRow(
|
||||
r.UnsTagReferenceId, effectiveName, rawPath, tag.DataType, tag.AccessLevel,
|
||||
r.DisplayNameOverride, r.SortOrder, r.RowVersion));
|
||||
@@ -1412,9 +1412,8 @@ public sealed class UnsTreeService(
|
||||
var effectiveNames = new HashSet<string>(StringComparer.Ordinal);
|
||||
foreach (var r in refs)
|
||||
{
|
||||
var eff = string.IsNullOrEmpty(r.DisplayNameOverride)
|
||||
? (tagNameById.TryGetValue(r.TagId, out var n) ? n : null)
|
||||
: r.DisplayNameOverride;
|
||||
var eff = EquipmentReferenceMap.EffectiveName(
|
||||
r.DisplayNameOverride, tagNameById.TryGetValue(r.TagId, out var n) ? n : null);
|
||||
if (!string.IsNullOrEmpty(eff)) effectiveNames.Add(eff!);
|
||||
}
|
||||
return effectiveNames;
|
||||
|
||||
@@ -958,7 +958,7 @@ public static class AddressSpaceComposer
|
||||
if (!equipFolderPath.TryGetValue(r.EquipmentId, out var equipPath)) continue;
|
||||
var rawPath = topology.Resolver.TryBuildTagPath(tag.DeviceId, tag.TagGroupId, tag.Name);
|
||||
if (rawPath is null) continue;
|
||||
var effectiveName = string.IsNullOrEmpty(r.DisplayNameOverride) ? tag.Name : r.DisplayNameOverride!;
|
||||
var effectiveName = EquipmentReferenceMap.EffectiveName(r.DisplayNameOverride, tag.Name)!;
|
||||
|
||||
string nodeId;
|
||||
try
|
||||
|
||||
+1
-2
@@ -217,8 +217,7 @@ public sealed partial class LocalExportCatalog
|
||||
|| !equipmentById.TryGetValue(reference.EquipmentId, out var owner)
|
||||
|| !lineById.TryGetValue(owner.UnsLineId, out var line) || !areaById.TryGetValue(line.UnsAreaId, out var area))
|
||||
continue;
|
||||
var effectiveName = string.IsNullOrEmpty(reference.DisplayNameOverride) ? tagById[reference.TagId].Name
|
||||
: reference.DisplayNameOverride!;
|
||||
var effectiveName = EquipmentReferenceMap.EffectiveName(reference.DisplayNameOverride, tagById[reference.TagId].Name)!;
|
||||
string reserved;
|
||||
try { reserved = V3NodeIds.UnsChild(V3NodeIds.Uns(area.Name, line.Name, owner.Name), effectiveName); }
|
||||
catch (ArgumentException) { continue; } // an invalid name segment: the deploy gate rejects it; never listed
|
||||
|
||||
@@ -1240,9 +1240,8 @@ internal sealed partial class ParsedDeploymentArtifact : IDisposable
|
||||
// Effective name = the override when present, else the backing raw tag's own name. This is the
|
||||
// same rule the address space materializes UNS variables under; a reference whose tag is
|
||||
// missing from the artifact has no resolvable name and is skipped.
|
||||
var effective = ReadNullableString(el, "DisplayNameOverride");
|
||||
if (string.IsNullOrWhiteSpace(effective))
|
||||
effective = tags.TryGetValue(tagId, out var t) ? t.Name : null;
|
||||
var effective = EquipmentReferenceMap.EffectiveName(
|
||||
ReadNullableString(el, "DisplayNameOverride"), tags.TryGetValue(tagId, out var t) ? t.Name : null);
|
||||
if (effective is null) continue;
|
||||
|
||||
references.Add((equipmentId, tagId, effective));
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
using Shouldly;
|
||||
using Xunit;
|
||||
using ZB.MOM.WW.OtOpcUa.Commons.Types;
|
||||
|
||||
namespace ZB.MOM.WW.OtOpcUa.Commons.Tests;
|
||||
|
||||
/// <summary>
|
||||
/// lmxopcua#1040 (#978 follow-up): the effective-name rule is stated once
|
||||
/// (<see cref="EquipmentReferenceMap.EffectiveName"/>) — an EMPTY override means "no override". Every other
|
||||
/// helper on the map must agree with it, including <see cref="EquipmentReferenceMap.EffectiveNames"/>, which
|
||||
/// used <c>??</c> and so dropped an empty-override reference instead of naming it after its tag.
|
||||
/// </summary>
|
||||
public sealed class EquipmentReferenceMapEffectiveNameTests
|
||||
{
|
||||
[Theory]
|
||||
[InlineData(null, "Speed", "Speed")]
|
||||
[InlineData("", "Speed", "Speed")]
|
||||
[InlineData("Rate", "Speed", "Rate")]
|
||||
public void EffectiveName_empty_override_is_no_override(string? displayNameOverride, string tagName, string expected) =>
|
||||
EquipmentReferenceMap.EffectiveName(displayNameOverride, tagName).ShouldBe(expected);
|
||||
|
||||
[Fact]
|
||||
public void EffectiveNames_agrees_with_EffectiveName_for_an_empty_override()
|
||||
{
|
||||
var names = EquipmentReferenceMap.EffectiveNames(
|
||||
[
|
||||
new EquipmentReferenceMap.ReferenceRow("R1", "EQ-1", "T1", ""),
|
||||
new EquipmentReferenceMap.ReferenceRow("R2", "EQ-1", "T2", null),
|
||||
new EquipmentReferenceMap.ReferenceRow("R3", "EQ-1", "T3", "Override"),
|
||||
],
|
||||
new Dictionary<string, string> { ["T1"] = "Speed", ["T2"] = "Temp", ["T3"] = "Level" });
|
||||
|
||||
names.ShouldBe(["Speed", "Temp", "Override"], ignoreOrder: true);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user