Skip to content

Commit 4c3d30f

Browse files
committed
Updated ITopicRepository.Load() to use uniqueKey instead of topicKey
In a previous commit, we created a new function, `GetTopicIDByUniqueKey`, which allows a `TopicID` to be looked up based on its `UniqueKey` instead of its `TopicKey` (ea97f91). This effectively replaces the legacy `GetTopicID`, which would lookup the _first instance_ of a topic which had a given `Key`. Since multiple topics can have the same `Key`, however, this was error prone. As a result, `GetTopicIDByUniqueKey` requires that a fully qualified `UniqueKey` (e.g., from `Topic.GetUniqueKey()`) be passed along, instead of simply a `Topic.Key`. As a result, this was not implemented on `ITopicRepository.Load(topicKey)` as that would be a breaking change; any call passing a single topic key would fail, unless that topic key happened to be in the root. For this major release, we're finally updating this to use `GetTopicIDByUniqueKey`. To avoid confusion, the parameter name is also being updated from `topicKey` to `uniqueKey` to help disambiguate _which_ key is appropriate here.
1 parent 7d887bb commit 4c3d30f

File tree

8 files changed

+18
-18
lines changed

8 files changed

+18
-18
lines changed

OnTopic.AspNetCore.Mvc/Components/MenuViewComponentBase{T}.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ IHierarchicalTopicMappingService<T> hierarchicalTopicMappingService
7979
var configuredRoot = CurrentTopic.Attributes.GetValue("NavigationRoot", true);
8080

8181
if (!String.IsNullOrEmpty(configuredRoot)) {
82-
navigationRootTopic = TopicRepository.Load(configuredRoot);
82+
navigationRootTopic = TopicRepository.Load("Root:" + configuredRoot);
8383
}
8484
if (navigationRootTopic is null) {
8585
navigationRootTopic = HierarchicalTopicMappingService.GetHierarchicalRoot(CurrentTopic, 2, "Web");

OnTopic.Data.Caching/CachedTopicRepository.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,13 +96,13 @@ public CachedTopicRepository(ITopicRepository dataProvider) : base() {
9696
}
9797

9898
/// <inheritdoc />
99-
public override Topic? Load(string? topicKey = null, bool isRecursive = true) {
99+
public override Topic? Load(string? uniqueKey = null, bool isRecursive = true) {
100100

101101
/*------------------------------------------------------------------------------------------------------------------------
102102
| Lookup by TopicKey
103103
\-----------------------------------------------------------------------------------------------------------------------*/
104-
if (topicKey is not null && topicKey.Length is not 0) {
105-
return _cache.GetByUniqueKey(topicKey);
104+
if (uniqueKey is not null && uniqueKey.Length is not 0) {
105+
return _cache.GetByUniqueKey(uniqueKey);
106106
}
107107

108108
/*------------------------------------------------------------------------------------------------------------------------

OnTopic.Data.Sql/SqlTopicRepository.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,23 +64,23 @@ public SqlTopicRepository(string connectionString) : base() {
6464
| METHOD: LOAD
6565
\-------------------------------------------------------------------------------------------------------------------------*/
6666
/// <inheritdoc />
67-
public override Topic Load(string? topicKey = null, bool isRecursive = true) {
67+
public override Topic Load(string? uniqueKey = null, bool isRecursive = true) {
6868

6969
/*------------------------------------------------------------------------------------------------------------------------
7070
| Handle empty topic
7171
>-------------------------------------------------------------------------------------------------------------------------
7272
| If the topicKey is null, or does not contain a topic key, then assume the caller wants to return all data; in that case
7373
| call Load() with the special integer value of -1, which will load all topics from the root.
7474
\-----------------------------------------------------------------------------------------------------------------------*/
75-
if (String.IsNullOrEmpty(topicKey)) {
75+
if (String.IsNullOrEmpty(uniqueKey)) {
7676
return Load(-1, isRecursive);
7777
}
7878

7979
/*------------------------------------------------------------------------------------------------------------------------
8080
| Establish database connection
8181
\-----------------------------------------------------------------------------------------------------------------------*/
8282
using var connection = new SqlConnection(_connectionString);
83-
using var command = new SqlCommand("GetTopicID", connection);
83+
using var command = new SqlCommand("GetTopicIDByUniqueKey", connection);
8484

8585
var topicId = -1;
8686

@@ -89,7 +89,7 @@ public override Topic Load(string? topicKey = null, bool isRecursive = true) {
8989
/*------------------------------------------------------------------------------------------------------------------------
9090
| Establish query parameters
9191
\-----------------------------------------------------------------------------------------------------------------------*/
92-
command.AddParameter("TopicKey", topicKey);
92+
command.AddParameter("UniqueKey", uniqueKey);
9393
command.AddOutputParameter();
9494

9595
/*------------------------------------------------------------------------------------------------------------------------
@@ -115,7 +115,7 @@ public override Topic Load(string? topicKey = null, bool isRecursive = true) {
115115
| Validate results
116116
\-----------------------------------------------------------------------------------------------------------------------*/
117117
if (topicId < 0) {
118-
throw new TopicNotFoundException(topicKey);
118+
throw new TopicNotFoundException(uniqueKey);
119119
}
120120

121121
/*------------------------------------------------------------------------------------------------------------------------

OnTopic.TestDoubles/DummyTopicRepository.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public DummyTopicRepository() : base() { }
3333
public override Topic? Load(int topicId, bool isRecursive = true) => null;
3434

3535
/// <inheritdoc />
36-
public override Topic? Load(string? topicKey = null, bool isRecursive = true) => null;
36+
public override Topic? Load(string? uniqueKey = null, bool isRecursive = true) => null;
3737

3838
/// <inheritdoc />
3939
public override Topic? Load(int topicId, DateTime version) => throw new NotImplementedException();

OnTopic.TestDoubles/StubTopicRepository.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,14 @@ public StubTopicRepository() : base() {
5353
(topicId < 0)? _cache :_cache.FindFirst(t => t.Id.Equals(topicId));
5454

5555
/// <inheritdoc />
56-
public override Topic? Load(string? topicKey = null, bool isRecursive = true) {
56+
public override Topic? Load(string? uniqueKey = null, bool isRecursive = true) {
5757

5858
/*------------------------------------------------------------------------------------------------------------------------
5959
| Lookup by TopicKey
6060
\-----------------------------------------------------------------------------------------------------------------------*/
61-
if (topicKey is not null && topicKey.Length > 0) {
62-
topicKey = topicKey.Contains(":") ? topicKey : "Root:" + topicKey;
63-
return _cache.FindFirst(t => t.GetUniqueKey().Equals(topicKey, StringComparison.OrdinalIgnoreCase));
61+
if (uniqueKey is not null && uniqueKey.Length > 0) {
62+
uniqueKey = uniqueKey.Contains(":") ? uniqueKey : "Root:" + uniqueKey;
63+
return _cache.FindFirst(t => t.GetUniqueKey().Equals(uniqueKey, StringComparison.OrdinalIgnoreCase));
6464
}
6565

6666
/*------------------------------------------------------------------------------------------------------------------------

OnTopic/Mapping/Hierarchical/HierarchicalTopicMappingService{T}.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ ITopicMappingService topicMappingService
7474
| GET HIERARCHICAL ROOT
7575
\-------------------------------------------------------------------------------------------------------------------------*/
7676
/// <inheritdoc />
77-
public Topic? GetHierarchicalRoot(Topic? currentTopic, int fromRoot = 2, string defaultRoot = "Web") {
77+
public Topic? GetHierarchicalRoot(Topic? currentTopic, int fromRoot = 2, string defaultRoot = "Root:Web") {
7878

7979
/*------------------------------------------------------------------------------------------------------------------------
8080
| Establish variables

OnTopic/Repositories/ITopicRepository.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,10 @@ public interface ITopicRepository {
6060
/// <summary>
6161
/// Loads a topic (and, optionally, all of its descendants) based on the specified key name.
6262
/// </summary>
63-
/// <param name="topicKey">The topic key.</param>
63+
/// <param name="uniqueKey">The fully-qualified unique topic key.</param>
6464
/// <param name="isRecursive">Determines whether or not to recurse through and load a topic's children.</param>
6565
/// <returns>A topic object.</returns>
66-
Topic? Load(string? topicKey = null, bool isRecursive = true);
66+
Topic? Load(string? uniqueKey = null, bool isRecursive = true);
6767

6868
/// <summary>
6969
/// Loads a specific version of a topic based on its version.

OnTopic/Repositories/TopicRepositoryBase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ protected virtual ContentTypeDescriptorCollection SetContentTypeDescriptors(Cont
224224
public abstract Topic? Load(int topicId, bool isRecursive = true);
225225

226226
/// <inheritdoc />
227-
public abstract Topic? Load(string? topicKey = null, bool isRecursive = true);
227+
public abstract Topic? Load(string? uniqueKey = null, bool isRecursive = true);
228228

229229
/// <inheritdoc />
230230
public abstract Topic? Load(int topicId, DateTime version);

0 commit comments

Comments
 (0)