diff --git a/src/Server/ZB.MOM.WW.OtOpcUa.Runtime/DataConnections/ProjectedConditionAccess.cs b/src/Server/ZB.MOM.WW.OtOpcUa.Runtime/DataConnections/ProjectedConditionAccess.cs
index d28fbdac9..818300708 100644
--- a/src/Server/ZB.MOM.WW.OtOpcUa.Runtime/DataConnections/ProjectedConditionAccess.cs
+++ b/src/Server/ZB.MOM.WW.OtOpcUa.Runtime/DataConnections/ProjectedConditionAccess.cs
@@ -287,8 +287,15 @@ public sealed partial class ProjectedConditionAccess : IProjectedConditionAccess
{
public ProjectedMappingPlacement Placement { get; } = placement;
public string MappingId => Placement.Mapping.RemoteNamespaceMappingId;
- public DataView Root { get; } = new(placement.Anchor.Address, placement.Mapping.Realm, null, 0, placement.Anchor.Address.Identifier);
+ // The origin view of the remote root, built exactly as RemoteNamespaceResolver builds it (subject = the mapping's
+ // RemoteRootEntityId): a UNS root's address identifier is an opaque id, and the origin refuses a root item whose subject
+ // is not its own (live a3b-cond-2: map-uns item Denied).
+ public DataView Root { get; } = new(placement.Anchor.Address, placement.Mapping.Realm, null, 0,
+ string.IsNullOrWhiteSpace(placement.Mapping.RemoteRootEntityId) ? placement.Anchor.Address.Identifier : placement.Mapping.RemoteRootEntityId);
public string? RootSubject { get; set; }
+ /// The origin's canonical view of the remote root (from metadata): the root item must carry the origin's own
+ /// subject — a view built from the address alone (subject = identifier) is refused for an opaque-id UNS root.
+ public DataView? RootView { get; set; }
public ulong? Handle { get; set; }
public ProjectedConditionMappingStatus Status { get; set; } = ProjectedConditionMappingStatus.Pending;
public int Total { get; set; }
@@ -407,7 +414,11 @@ public sealed partial class ProjectedConditionAccess : IProjectedConditionAccess
var metadata = await connection.GetMetadataAsync(new MetadataRequest(states.Select(x => x.Root).ToArray(), budget), token)
.ConfigureAwait(false);
for (var i = 0; i < states.Length && i < metadata.Count; i++)
- if (metadata[i] is { Status: DataItemStatus.Good, Value: { } root }) states[i].RootSubject = root.View.Subject;
+ if (metadata[i] is { Status: DataItemStatus.Good, Value: { } root })
+ {
+ states[i].RootSubject = root.View.Subject;
+ states[i].RootView = root.View;
+ }
}
catch (Exception ex) when (ex is not OperationCanceledException) { }
@@ -417,7 +428,7 @@ public sealed partial class ProjectedConditionAccess : IProjectedConditionAccess
epoch, _connectionId, states.Length, Serving?.NodeId ?? "(no provenance)");
var subscriptionId = "conditions-" + Guid.NewGuid().ToString("N");
var settings = new DataSubscriptionSettings(TimeSpan.Zero, TimeSpan.Zero, DataChangeTrigger.StatusValue, null);
- var items = states.Select(x => new DataSubscriptionItem(x.MappingId, x.Root, settings, new DataConditionScope(IncludeInfo: true))).ToArray();
+ var items = states.Select(x => new DataSubscriptionItem(x.MappingId, x.RootView ?? x.Root, settings, new DataConditionScope(IncludeInfo: true))).ToArray();
await subscription.SendAsync(new OpenSubscription(subscriptionId, epoch, "open", TimeSpan.FromSeconds(30), items, false,
TimeSpan.FromMinutes(60), new DataBudget(TimeSpan.FromSeconds(30), 1000, 4 * 1024 * 1024)), token).ConfigureAwait(false);
diff --git a/tests/Server/ZB.MOM.WW.OtOpcUa.Runtime.Tests/DataConnections/GrpcDataProjectedConditionMethodTests.cs b/tests/Server/ZB.MOM.WW.OtOpcUa.Runtime.Tests/DataConnections/GrpcDataProjectedConditionMethodTests.cs
index 27a474368..b51db1785 100644
--- a/tests/Server/ZB.MOM.WW.OtOpcUa.Runtime.Tests/DataConnections/GrpcDataProjectedConditionMethodTests.cs
+++ b/tests/Server/ZB.MOM.WW.OtOpcUa.Runtime.Tests/DataConnections/GrpcDataProjectedConditionMethodTests.cs
@@ -114,6 +114,18 @@ public sealed class GrpcDataProjectedConditionMethodTests
f.Connections.Sent.Count.ShouldBe(sent);
}
+ [Fact]
+ public async Task The_condition_item_carries_the_origins_canonical_root_view_learned_from_metadata()
+ {
+ // Live a3b-cond-2: a UNS root item built from the address alone (subject = the opaque EquipmentId) was refused Denied.
+ await using var f = new Fixture(uns: true);
+ using var demand = f.Access.AcquireEventDemand(null);
+ var stream = await f.Connections.Streams.Reader.ReadAsync(TestContext.Current.CancellationToken);
+ var open = await stream.Opened.Task.WaitAsync(TimeSpan.FromSeconds(10), TestContext.Current.CancellationToken);
+ f.Connections.MetadataViews.Single().Subject.ShouldBe("EQ-0001", "metadata is asked as the browse resolver asks it (RemoteRootEntityId)");
+ open.Items.Single().View.Subject.ShouldBe("area/line/plc", "the item uses the origin's own view of the root");
+ }
+
// ---------------------------------------------------------------------------------------------------------------------
private sealed class Fixture : IAsyncDisposable
@@ -126,7 +138,7 @@ public sealed class GrpcDataProjectedConditionMethodTests
public ProjectedConditionAccess Access { get; }
public RemoteNamespaceMapping Mapping => _placement.Mapping;
- public Fixture()
+ public Fixture(bool uns = false)
{
Grant(NodePermissions.Browse | NodePermissions.Subscribe);
var mapping = new RemoteNamespaceMapping
@@ -138,9 +150,16 @@ public sealed class GrpcDataProjectedConditionMethodTests
ConditionMethodTimeoutMilliseconds = 4321, BranchName = "map-a", RemoteNamespaceUri = "https://zb.com/otopcua/raw",
RemoteIdentifierKind = "string", RemoteIdentifier = "Plant",
};
+ if (uns)
+ {
+ mapping.Realm = mapping.RemoteRealm = DataRealm.Uns;
+ mapping.RemoteNamespaceUri = "https://zb.com/otopcua/uns";
+ mapping.RemoteIdentifier = "EQ-0001";
+ mapping.RemoteRootEntityId = "EQ-0001";
+ }
var segments = new[] { "Plant", "map-a" };
- var anchor = new DataView(new DataAddress("origin", mapping.RemoteNamespaceUri, "string", "Plant"), DataRealm.Raw, "map-a", 1, "Plant/map-a");
- var scope = new NodeScope { ClusterId = "c1", Kind = NodeHierarchyKind.Raw, Segments = segments };
+ var anchor = new DataView(new DataAddress("origin", mapping.RemoteNamespaceUri, "string", mapping.RemoteIdentifier), mapping.Realm, "map-a", 1, "Plant/map-a");
+ var scope = new NodeScope { ClusterId = "c1", Kind = uns ? NodeHierarchyKind.Uns : NodeHierarchyKind.Raw, Segments = segments };
_placement = new ProjectedMappingPlacement(mapping, anchor, anchor, scope, ["local-parent"], new ActiveAuthority());
var policy = new DataOperationPolicy(_state, new TriePermissionEvaluator(_state.Tries, TimeProvider.System), TimeProvider.System);
Access = new ProjectedConditionAccess(new GrpcDataProjectedConditionAccessTests.FakeMappings([_placement]), Connections, policy,
@@ -189,6 +208,7 @@ public sealed class GrpcDataProjectedConditionMethodTests
private int _acquired;
public Channel Streams { get; } = Channel.CreateUnbounded();
public List Sent { get; } = [];
+ public List MetadataViews { get; } = [];
public DataConditionMethodResult Result { get; set; } = new(DataWriteState.AcceptedUnconfirmed, 0, null);
public bool Refuse { get; set; }
public volatile bool Down;
@@ -215,8 +235,14 @@ public sealed class GrpcDataProjectedConditionMethodTests
public TimeProvider Clock => TimeProvider.System;
public Task GetCapabilitiesAsync(DataBudget budget, CancellationToken cancellationToken) => throw new NotSupportedException();
public Task BrowseAsync(BrowseRequest request, CancellationToken cancellationToken) => throw new NotSupportedException();
- public Task>> GetMetadataAsync(MetadataRequest request, CancellationToken cancellationToken) =>
- Task.FromResult>>([]);
+ public Task>> GetMetadataAsync(MetadataRequest request, CancellationToken cancellationToken)
+ {
+ lock (owner.MetadataViews) owner.MetadataViews.AddRange(request.Views);
+ // The origin answers with ITS canonical view of the root (subject = its browse path, not the opaque id).
+ return Task.FromResult>>(request.Views.Select(v => new DataItemResult("0",
+ DataItemStatus.Good, new DataMetadata(v with { Subject = "area/line/plc" }, "plc", "Folder", DataValueKind.Null, -1, [], false,
+ DataOperations.Browse, 1, null, null, false), null)).ToArray());
+ }
public Task> ReadAsync(ReadRequest request, CancellationToken cancellationToken) => throw new NotSupportedException();
public Task> WriteAsync(WriteBatch request, CancellationToken cancellationToken) => throw new NotSupportedException();
public Task SubscribeAsync(CancellationToken cancellationToken)
@@ -239,7 +265,12 @@ public sealed class GrpcDataProjectedConditionMethodTests
{
private readonly Channel _frames = Channel.CreateUnbounded();
public ServingIdentity Serving => GrpcDataProjectedConditionMethodTests.Serving;
- public Task SendAsync(DataSubscriptionCommand command, CancellationToken cancellationToken) => Task.CompletedTask;
+ public TaskCompletionSource Opened { get; } = new(TaskCreationOptions.RunContinuationsAsynchronously);
+ public Task SendAsync(DataSubscriptionCommand command, CancellationToken cancellationToken)
+ {
+ if (command is OpenSubscription open) Opened.TrySetResult(open);
+ return Task.CompletedTask;
+ }
public IAsyncEnumerable ReadAllAsync(CancellationToken cancellationToken) => _frames.Reader.ReadAllAsync(cancellationToken);
public void End() => _frames.Writer.TryComplete();
public ValueTask DisposeAsync() { _frames.Writer.TryComplete(); return ValueTask.CompletedTask; }