From c0c372ab57d3391f76838a7063f93793a3fafd39 Mon Sep 17 00:00:00 2001
From: Binon
Date: Tue, 14 Apr 2026 11:24:19 +0100
Subject: [PATCH 1/2] removed the findwise references in WebAPI
---
.../Controllers/HierarchyController.cs | 6 -
.../Controllers/ResourceSyncController.cs | 4 +-
.../Startup/ServiceMappings.cs | 3 -
.../Configuration/MigrationToolSettings.cs | 2 +-
.../IFindWiseHttpClient.cs | 18 -
.../IFindwiseApiFacade.cs | 37 --
.../IResourceService.cs | 2 +-
.../CatalogueServiceTests.cs | 3 -
.../LearningHub.Nhs.Services/BaseService.cs | 18 +-
.../CatalogueService.cs | 76 +---
.../FindWiseHttpClient.cs | 60 ---
.../Findwise/FindwiseApiFacade.cs | 131 -------
.../HierarchyService.cs | 2 +-
.../Messaging/MessageService.cs | 5 +-
.../NotificationTemplateService.cs | 4 +-
.../LearningHub.Nhs.Services/RatingService.cs | 2 -
.../ResourceService.cs | 4 +-
.../ResourceSyncService.cs | 61 +--
.../LearningHub.Nhs.Services/SearchService.cs | 352 +-----------------
19 files changed, 23 insertions(+), 767 deletions(-)
delete mode 100644 WebAPI/LearningHub.Nhs.Services.Interface/IFindWiseHttpClient.cs
delete mode 100644 WebAPI/LearningHub.Nhs.Services.Interface/IFindwiseApiFacade.cs
delete mode 100644 WebAPI/LearningHub.Nhs.Services/FindWiseHttpClient.cs
delete mode 100644 WebAPI/LearningHub.Nhs.Services/Findwise/FindwiseApiFacade.cs
diff --git a/WebAPI/LearningHub.Nhs.API/Controllers/HierarchyController.cs b/WebAPI/LearningHub.Nhs.API/Controllers/HierarchyController.cs
index ff6d5d560..3af6c645e 100644
--- a/WebAPI/LearningHub.Nhs.API/Controllers/HierarchyController.cs
+++ b/WebAPI/LearningHub.Nhs.API/Controllers/HierarchyController.cs
@@ -473,12 +473,6 @@ public async Task PublishHierarchyEdit(PublishHierarchyEditViewMo
try
{
int publicationId = await this.hierarchyService.PublishHierarchyEditAsync(publishViewModel);
-
- /* TODO - IT2 - confirm submission to Findwise (why here rather than in service method just called?)
- if (publicationId > 0)
- {
- this.hierarchyService.ConfirmSubmissionToSearch(publicationId, publishViewModel.UserId);
- } */
}
catch (Exception ex)
{
diff --git a/WebAPI/LearningHub.Nhs.API/Controllers/ResourceSyncController.cs b/WebAPI/LearningHub.Nhs.API/Controllers/ResourceSyncController.cs
index 0228c54b2..8846029e1 100644
--- a/WebAPI/LearningHub.Nhs.API/Controllers/ResourceSyncController.cs
+++ b/WebAPI/LearningHub.Nhs.API/Controllers/ResourceSyncController.cs
@@ -67,11 +67,11 @@ public async Task RemoveFromSyncList(List resourceIds)
}
///
- /// The SyncWithFindwise.
+ /// The Sync.
///
/// The action result.
[HttpPost("Sync")]
- public async Task SyncWithFindwise()
+ public async Task Sync()
{
var vr = await this.resourceSyncService.SyncForUserAsync(this.CurrentUserId);
return this.Ok(new ApiResponse(vr.IsValid, vr));
diff --git a/WebAPI/LearningHub.Nhs.API/Startup/ServiceMappings.cs b/WebAPI/LearningHub.Nhs.API/Startup/ServiceMappings.cs
index a9f0988ce..108504bc2 100644
--- a/WebAPI/LearningHub.Nhs.API/Startup/ServiceMappings.cs
+++ b/WebAPI/LearningHub.Nhs.API/Startup/ServiceMappings.cs
@@ -39,7 +39,6 @@ namespace LearningHub.Nhs.Api
using LearningHub.Nhs.Repository.Report;
using LearningHub.Nhs.Repository.Resources;
using LearningHub.Nhs.Services;
- using LearningHub.Nhs.Services.Findwise;
using LearningHub.Nhs.Services.Interface;
using LearningHub.Nhs.Services.Interface.Messaging;
using LearningHub.Nhs.Services.Interface.Report;
@@ -218,7 +217,6 @@ public static void AddLearningHubMappings(this IServiceCollection services, ICon
services.AddScoped();
services.AddScoped();
services.AddScoped();
- services.AddScoped();
services.AddScoped();
services.AddScoped();
services.AddScoped();
@@ -235,7 +233,6 @@ public static void AddLearningHubMappings(this IServiceCollection services, ICon
services.AddTransient();
services.AddTransient();
services.AddScoped();
- services.AddScoped();
services.AddScoped();
services.AddScoped();
services.AddScoped();
diff --git a/WebAPI/LearningHub.Nhs.Api.Shared/Configuration/MigrationToolSettings.cs b/WebAPI/LearningHub.Nhs.Api.Shared/Configuration/MigrationToolSettings.cs
index bcfa50e66..76e66990c 100644
--- a/WebAPI/LearningHub.Nhs.Api.Shared/Configuration/MigrationToolSettings.cs
+++ b/WebAPI/LearningHub.Nhs.Api.Shared/Configuration/MigrationToolSettings.cs
@@ -1,7 +1,7 @@
namespace LearningHub.Nhs.Api.Shared.Configuration
{
///
- /// The FindwiseSettings.
+ /// The MigrationToolSettings.
///
public class MigrationToolSettings
{
diff --git a/WebAPI/LearningHub.Nhs.Services.Interface/IFindWiseHttpClient.cs b/WebAPI/LearningHub.Nhs.Services.Interface/IFindWiseHttpClient.cs
deleted file mode 100644
index 74cc6f31f..000000000
--- a/WebAPI/LearningHub.Nhs.Services.Interface/IFindWiseHttpClient.cs
+++ /dev/null
@@ -1,18 +0,0 @@
-namespace LearningHub.Nhs.Services.Interface
-{
- using System.Net.Http;
- using System.Threading.Tasks;
-
- ///
- /// The FindWise Http Client interface.
- ///
- public interface IFindWiseHttpClient
- {
- ///
- /// The get cient async.
- ///
- /// The url of the client.
- /// The .
- Task GetClient(string httpClientUrl);
- }
-}
\ No newline at end of file
diff --git a/WebAPI/LearningHub.Nhs.Services.Interface/IFindwiseApiFacade.cs b/WebAPI/LearningHub.Nhs.Services.Interface/IFindwiseApiFacade.cs
deleted file mode 100644
index 4e50ff92b..000000000
--- a/WebAPI/LearningHub.Nhs.Services.Interface/IFindwiseApiFacade.cs
+++ /dev/null
@@ -1,37 +0,0 @@
-namespace LearningHub.Nhs.Services.Interface
-{
- using System.Collections.Generic;
- using System.Threading.Tasks;
- using LearningHub.Nhs.Models.Search;
-
- ///
- /// The IFindwiseApiFacade.
- ///
- public interface IFindwiseApiFacade
- {
- ///
- /// Modifies the information Findwise has for the catalogues provided.
- /// Documents not in Findwise will be added.
- /// Documents that already exist in Findwise will be replaced.
- ///
- /// The catalogues to add/replace in the index.
- /// The task.
- Task AddOrReplaceAsync(List catalogues);
-
- ///
- /// Modifies the information Findwise has for the resources provided.
- /// Documents not in Findwise will be added.
- /// Documents that already exist in Findwise will be replaced.
- ///
- /// The resources to add/replace in the index.
- /// The task.
- Task AddOrReplaceAsync(List resources);
-
- ///
- /// Removes the documents from Findwise.
- ///
- /// The resources to remove from Findwise.
- /// The task.
- Task RemoveAsync(List resources);
- }
-}
diff --git a/WebAPI/LearningHub.Nhs.Services.Interface/IResourceService.cs b/WebAPI/LearningHub.Nhs.Services.Interface/IResourceService.cs
index 9b2e8e9d4..b31374b16 100644
--- a/WebAPI/LearningHub.Nhs.Services.Interface/IResourceService.cs
+++ b/WebAPI/LearningHub.Nhs.Services.Interface/IResourceService.cs
@@ -165,7 +165,7 @@ public interface IResourceService
Task PublishResourceVersionAsync(PublishViewModel publishViewModel);
///
- /// Submits a published resource version to the Findwise search.
+ /// Submits a published resource version to search.
///
/// The resourceVersionId.
/// The userId.
diff --git a/WebAPI/LearningHub.Nhs.Services.UnitTests/CatalogueServiceTests.cs b/WebAPI/LearningHub.Nhs.Services.UnitTests/CatalogueServiceTests.cs
index 4157f98cb..f7f49ec59 100644
--- a/WebAPI/LearningHub.Nhs.Services.UnitTests/CatalogueServiceTests.cs
+++ b/WebAPI/LearningHub.Nhs.Services.UnitTests/CatalogueServiceTests.cs
@@ -28,7 +28,6 @@ public class CatalogueServiceTests : TestBase
{
private readonly Mock mockUserRepository;
private readonly Mock mockResourceVersionRepository;
- private readonly Mock mockFindwiseApiFacade;
private Mock mockRoleUserGroupRepository;
private Mock mockUserUserGroupRepository;
private MockRepository mockRepository;
@@ -62,7 +61,6 @@ public CatalogueServiceTests()
this.mockRoleUserGroupRepository = this.mockRepository.Create();
this.mockUserRepository = this.mockRepository.Create();
this.mockResourceVersionRepository = this.mockRepository.Create();
- this.mockFindwiseApiFacade = this.mockRepository.Create();
this.mockRoleUserGroupRepository = this.mockRepository.Create();
this.mockUserUserGroupRepository = this.mockRepository.Create();
this.mockEmailSenderService = this.mockRepository.Create();
@@ -142,7 +140,6 @@ private CatalogueService CreateService()
this.mockUserRepository.Object,
this.mockRoleUserGroupRepository.Object,
this.mockResourceVersionRepository.Object,
- this.mockFindwiseApiFacade.Object,
this.mockUserUserGroupRepository.Object,
this.mockEmailSenderService.Object,
////this.mockUserService.Object,
diff --git a/WebAPI/LearningHub.Nhs.Services/BaseService.cs b/WebAPI/LearningHub.Nhs.Services/BaseService.cs
index 2d9ae36dc..6dc0b1779 100644
--- a/WebAPI/LearningHub.Nhs.Services/BaseService.cs
+++ b/WebAPI/LearningHub.Nhs.Services/BaseService.cs
@@ -1,6 +1,5 @@
namespace LearningHub.Nhs.Services
{
- using LearningHub.Nhs.Services.Interface;
using Microsoft.Extensions.Logging;
///
@@ -16,20 +15,13 @@ public abstract class BaseService
///
private readonly ILogger logger;
- ///
- /// The Find Wise HTTP Client.
- ///
- private IFindWiseHttpClient findWiseHttpClient;
-
///
/// Initializes a new instance of the class.
/// The base service.
///
- /// The Find Wise http client.
/// The logger.
- protected BaseService(IFindWiseHttpClient findWiseHttpClient, ILogger logger)
+ protected BaseService(ILogger logger)
{
- this.findWiseHttpClient = findWiseHttpClient;
this.logger = logger;
}
@@ -40,13 +32,5 @@ protected ILogger Logger
{
get { return this.logger; }
}
-
- ///
- /// Gets the Find Wise HTTP Client.
- ///
- protected IFindWiseHttpClient FindWiseHttpClient
- {
- get { return this.findWiseHttpClient; }
- }
}
}
diff --git a/WebAPI/LearningHub.Nhs.Services/CatalogueService.cs b/WebAPI/LearningHub.Nhs.Services/CatalogueService.cs
index c9906b62f..370c876c7 100644
--- a/WebAPI/LearningHub.Nhs.Services/CatalogueService.cs
+++ b/WebAPI/LearningHub.Nhs.Services/CatalogueService.cs
@@ -40,7 +40,6 @@ public class CatalogueService : ICatalogueService
private readonly IUserRepository userRepository;
private readonly IRoleUserGroupRepository roleUserGroupRepository;
private readonly IResourceVersionRepository resourceVersionRepository;
- private readonly IFindwiseApiFacade findwiseApiFacade;
private readonly IUserUserGroupRepository userUserGroupRepository;
private readonly IEmailSenderService emailSenderService;
private readonly Settings settings;
@@ -90,7 +89,6 @@ public CatalogueService(
IUserRepository userRepository,
IRoleUserGroupRepository roleUserGroupRepository,
IResourceVersionRepository resourceVersionRepository,
- IFindwiseApiFacade findwiseApiFacade,
IUserUserGroupRepository userUserGroupRepository,
IEmailSenderService emailSenderService,
////elfhHub.Nhs.Services.Interface.IUserService userService,
@@ -108,7 +106,6 @@ public CatalogueService(
this.catalogueNodeVersionRepository = catalogueNodeVersionRepository;
this.nodeResourceRepository = nodeResourceRepository;
this.resourceVersionRepository = resourceVersionRepository;
- this.findwiseApiFacade = findwiseApiFacade;
this.roleUserGroupRepository = roleUserGroupRepository;
this.userUserGroupRepository = userUserGroupRepository;
this.nodeActivityRepository = nodeActivityRepository;
@@ -250,24 +247,6 @@ public async Task CreateCatalogueAsync(int userId,
var catalogueNodeVersionId = await this.catalogueNodeVersionRepository.CreateCatalogueAsync(userId, catalogue);
- // Catalogue is in database, push to findwise
- var cnv = this.catalogueNodeVersionRepository.GetAll()
- .Include(x => x.NodeVersion).ThenInclude(x => x.Node)
- .Include(x => x.Keywords)
- .Include(x => x.CatalogueNodeVersionProvider)
- .SingleOrDefault(x => x.Id == catalogueNodeVersionId);
-
- if (cnv != null)
- {
- var searchModel = this.mapper.Map(cnv);
- if (searchModel.Description.Length > this.settings.Findwise.DescriptionLengthLimit)
- {
- searchModel.Description = searchModel.Description.Substring(0, this.settings.Findwise.DescriptionLengthLimit - 4) + "
";
- }
-
- await this.findwiseApiFacade.AddOrReplaceAsync(new List { searchModel });
- }
-
return new LearningHubValidationResult(true)
{
CreatedId = catalogueNodeVersionId,
@@ -486,24 +465,6 @@ public async Task UpdateCatalogueAsync(int userId,
await this.catalogueNodeVersionRepository.UpdateCatalogueAsync(userId, catalogue);
- // Update catalogue in findwise
- var cnv = this.catalogueNodeVersionRepository.GetAll()
- .Include(x => x.NodeVersion).ThenInclude(x => x.Node)
- .Include(x => x.Keywords)
- .Include(x => x.CatalogueNodeVersionProvider)
- .SingleOrDefault(x => x.Id == catalogue.CatalogueNodeVersionId);
-
- if (cnv != null)
- {
- var searchModel = this.mapper.Map(cnv);
- if (searchModel.Description.Length > this.settings.Findwise.DescriptionLengthLimit)
- {
- searchModel.Description = searchModel.Description.Substring(0, this.settings.Findwise.DescriptionLengthLimit - 4) + "";
- }
-
- await this.findwiseApiFacade.AddOrReplaceAsync(new List { searchModel });
- }
-
return new LearningHubValidationResult(true);
}
@@ -579,24 +540,6 @@ public async Task ShowCatalogueAsync(int userId, in
await this.catalogueNodeVersionRepository.ShowCatalogue(userId, nodeId);
- var cnv = this.catalogueNodeVersionRepository.GetAll()
- .Include(x => x.NodeVersion).ThenInclude(x => x.Node)
- .Include(x => x.Keywords)
- .Include(x => x.CatalogueNodeVersionProvider)
- .SingleOrDefault(x => x.NodeVersion.NodeId == nodeId);
-
- // update findwise
- if (cnv != null)
- {
- var searchModel = this.mapper.Map(cnv);
- if (searchModel.Description.Length > this.settings.Findwise.DescriptionLengthLimit)
- {
- searchModel.Description = searchModel.Description.Substring(0, this.settings.Findwise.DescriptionLengthLimit - 4) + "";
- }
-
- await this.findwiseApiFacade.AddOrReplaceAsync(new List { searchModel });
- }
-
return new LearningHubValidationResult(true);
}
@@ -615,24 +558,7 @@ public async Task HideCatalogueAsync(int userId, int nodeId)
}
node.Hidden = true;
- await this.nodeRepository.UpdateAsync(userId, node);
-
- // update findwise
- var cnv = this.catalogueNodeVersionRepository.GetAll()
- .Include(x => x.NodeVersion).ThenInclude(x => x.Node)
- .Include(x => x.Keywords)
- .Include(x => x.CatalogueNodeVersionProvider)
- .SingleOrDefault(x => x.NodeVersion.NodeId == nodeId);
- if (cnv != null)
- {
- var searchModel = this.mapper.Map(cnv);
- if (searchModel.Description.Length > this.settings.Findwise.DescriptionLengthLimit)
- {
- searchModel.Description = searchModel.Description.Substring(0, this.settings.Findwise.DescriptionLengthLimit - 4) + "";
- }
-
- await this.findwiseApiFacade.AddOrReplaceAsync(new List { searchModel });
- }
+ await this.nodeRepository.UpdateAsync(userId, node);
}
///
diff --git a/WebAPI/LearningHub.Nhs.Services/FindWiseHttpClient.cs b/WebAPI/LearningHub.Nhs.Services/FindWiseHttpClient.cs
deleted file mode 100644
index 51a2fa0cb..000000000
--- a/WebAPI/LearningHub.Nhs.Services/FindWiseHttpClient.cs
+++ /dev/null
@@ -1,60 +0,0 @@
-namespace LearningHub.Nhs.Services
-{
- using System;
- using System.Net.Http;
- using System.Net.Http.Headers;
- using System.Threading.Tasks;
- using LearningHub.Nhs.Services.Interface;
-
- ///
- /// The FindWise Http Client.
- ///
- public class FindWiseHttpClient : IFindWiseHttpClient, IDisposable
- {
- private readonly HttpClient httpClient = new ();
- //// private readonly LearningHubAuthServiceConfig authConfig;
- private bool initialised = false;
-
- ///
- /// The Get Client method.
- ///
- /// The url of the client.
- /// The .
- public async Task GetClient(string httpClientUrl)
- {
- this.Initialise(httpClientUrl);
- return this.httpClient;
- }
-
- ///
- public void Dispose()
- {
- this.Dispose(true);
- GC.SuppressFinalize(this);
- }
-
- ///
- /// The dispoase.
- ///
- /// disposing.
- protected virtual void Dispose(bool disposing)
- {
- if (disposing)
- {
- this.httpClient.Dispose();
- }
- }
-
- private void Initialise(string httpClientUrl)
- {
- if (this.initialised == false)
- {
- this.httpClient.BaseAddress = new Uri(httpClientUrl);
- this.httpClient.DefaultRequestHeaders.Accept.Clear();
- this.httpClient.DefaultRequestHeaders.Accept.Add(
- new MediaTypeWithQualityHeaderValue("application/json"));
- this.initialised = true;
- }
- }
- }
-}
diff --git a/WebAPI/LearningHub.Nhs.Services/Findwise/FindwiseApiFacade.cs b/WebAPI/LearningHub.Nhs.Services/Findwise/FindwiseApiFacade.cs
deleted file mode 100644
index 06911ba10..000000000
--- a/WebAPI/LearningHub.Nhs.Services/Findwise/FindwiseApiFacade.cs
+++ /dev/null
@@ -1,131 +0,0 @@
-namespace LearningHub.Nhs.Services.Findwise
-{
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Net.Http;
- using System.Text;
- using System.Threading.Tasks;
- using LearningHub.Nhs.Api.Shared.Configuration;
- using LearningHub.Nhs.Models.Search;
- using LearningHub.Nhs.Services.Interface;
- using Microsoft.Extensions.Logging;
- using Microsoft.Extensions.Options;
- using Newtonsoft.Json;
-
- ///
- /// The FindwiseApiFacade.
- ///
- public class FindwiseApiFacade : IFindwiseApiFacade
- {
- private readonly IFindWiseHttpClient findWiseHttpClient;
- private readonly Settings settings;
- private readonly ILogger logger;
-
- ///
- /// Initializes a new instance of the class.
- ///
- /// The findWiseHttpClient.
- /// The options.
- /// The logger.
- public FindwiseApiFacade(
- IFindWiseHttpClient findWiseHttpClient,
- IOptions options,
- ILogger logger)
- {
- this.findWiseHttpClient = findWiseHttpClient;
- this.settings = options.Value;
- this.logger = logger;
- }
-
- ///
- /// Modifies the information Findwise has for the catalogues provided.
- /// Documents not in Findwise will be added.
- /// Documents that already exist in Findwise will be replaced.
- ///
- /// The catalogues to add/replace in the index.
- /// The task.
- public async Task AddOrReplaceAsync(List catalogues)
- {
- var request = string.Format(this.settings.Findwise.IndexMethod, this.settings.Findwise.CollectionIds.Catalogue)
- + $"?token={this.settings.Findwise.Token}";
- var response = await this.PostAsync(request, catalogues);
- this.ValidateResponse(response, $"catalogues: {string.Join(',', catalogues.Select(x => x.Id))}");
- }
-
- ///
- /// Modifies the information Findwise has for the resources provided.
- /// Documents not in Findwise will be added.
- /// Documents that already exist in Findwise will be replaced.
- ///
- /// The resources to add/replace in the index.
- /// The task.
- public async Task AddOrReplaceAsync(List resources)
- {
- var request = string.Format(this.settings.Findwise.IndexMethod, this.settings.Findwise.CollectionIds.Resource)
- + $"?token={this.settings.Findwise.Token}";
- var response = await this.PostAsync(request, resources);
- this.ValidateResponse(response, $"resources: {string.Join(',', resources.Select(x => x.Id))}");
- }
-
- ///
- /// Removes the documents from Findwise.
- ///
- /// The resources to remove from Findwise.
- /// The task.
- public async Task RemoveAsync(List resources)
- {
- var resourceIds = resources.Select(x => x.Id);
- var idQueryString = string.Join(
- '&',
- resourceIds.Select(x => $"id={x}"));
- var request = string.Format(
- this.settings.Findwise.IndexMethod,
- this.settings.Findwise.CollectionIds.Resource)
- + $"?{idQueryString}&token={this.settings.Findwise.Token}";
- var response = await this.DeleteAsync(request);
- this.ValidateResponse(response, $"resources: {string.Join(',', resourceIds)}");
- }
-
- private void ValidateResponse(HttpResponseMessage response, string dataForError)
- {
- if (response.StatusCode == System.Net.HttpStatusCode.Unauthorized || response.StatusCode == System.Net.HttpStatusCode.Forbidden)
- {
- this.logger.LogError($"Updating FindWise failed for {dataForError} HTTP Status Code:" + response.StatusCode.ToString());
- throw new Exception("AccessDenied");
- }
- else if (!response.IsSuccessStatusCode)
- {
- this.logger.LogError($"Updating FindWise failed for {dataForError} HTTP Status Code:" + response.StatusCode.ToString());
- throw new Exception("Posting of resource to search failed: " + dataForError);
- }
- }
-
- private async Task PostAsync(string request, T obj)
- where T : class, new()
- {
- var content = this.GetContent(obj);
- var client = await this.GetClientAsync();
- return await client.PostAsync(request, content).ConfigureAwait(false);
- }
-
- private async Task DeleteAsync(string request)
- {
- var client = await this.GetClientAsync();
- return await client.DeleteAsync(request).ConfigureAwait(false);
- }
-
- private async Task GetClientAsync()
- {
- return await this.findWiseHttpClient.GetClient(this.settings.Findwise.IndexUrl);
- }
-
- private StringContent GetContent(T obj)
- where T : class, new()
- {
- var json = JsonConvert.SerializeObject(obj, new JsonSerializerSettings() { DateFormatString = "yyyy-MM-dd" });
-
- return new StringContent(json, UnicodeEncoding.UTF8, "application/json");
- }
- }
-}
diff --git a/WebAPI/LearningHub.Nhs.Services/HierarchyService.cs b/WebAPI/LearningHub.Nhs.Services/HierarchyService.cs
index 5a2d6734d..4df4915a2 100644
--- a/WebAPI/LearningHub.Nhs.Services/HierarchyService.cs
+++ b/WebAPI/LearningHub.Nhs.Services/HierarchyService.cs
@@ -651,7 +651,7 @@ public async Task PublishHierarchyEditAsync(PublishHierarchyEditViewModel p
var currentUserId = publishViewModel.UserId;
var publicationId = this.hierarchyEditRepository.Publish(publishViewModel.HierarchyEditId, publishViewModel.IsMajorRevision, publishViewModel.Notes, currentUserId);
- bool success = true; // From Findwise in IT2
+ bool success = true;
if (success)
{
diff --git a/WebAPI/LearningHub.Nhs.Services/Messaging/MessageService.cs b/WebAPI/LearningHub.Nhs.Services/Messaging/MessageService.cs
index fa28f33b1..98a8d2610 100644
--- a/WebAPI/LearningHub.Nhs.Services/Messaging/MessageService.cs
+++ b/WebAPI/LearningHub.Nhs.Services/Messaging/MessageService.cs
@@ -9,7 +9,6 @@
using LearningHub.Nhs.Models.Messaging;
using LearningHub.Nhs.Models.Validation;
using LearningHub.Nhs.Repository.Interface.Messaging;
- using LearningHub.Nhs.Services.Interface;
using LearningHub.Nhs.Services.Interface.Messaging;
using Microsoft.Extensions.Logging;
@@ -23,14 +22,12 @@ public class MessageService : BaseService, IMessageService
///
/// Initializes a new instance of the class.
///
- /// The findwiseHttpClient.
/// The logger.
/// The message repository.
public MessageService(
- IFindWiseHttpClient findwiseHttpClient,
ILogger logger,
IMessageRepository messageRepository)
- : base(findwiseHttpClient, logger)
+ : base(logger)
{
this.messageRepository = messageRepository;
}
diff --git a/WebAPI/LearningHub.Nhs.Services/NotificationTemplateService.cs b/WebAPI/LearningHub.Nhs.Services/NotificationTemplateService.cs
index 8452f03b5..d1934b338 100644
--- a/WebAPI/LearningHub.Nhs.Services/NotificationTemplateService.cs
+++ b/WebAPI/LearningHub.Nhs.Services/NotificationTemplateService.cs
@@ -20,14 +20,12 @@ public class NotificationTemplateService : BaseService, IN
///
/// Initializes a new instance of the class.
///
- /// The findwise client.
/// The logger.
/// The notification template repository.
public NotificationTemplateService(
- IFindWiseHttpClient fwClient,
ILogger logger,
INotificationTemplateRepository notificationTemplateRepository)
- : base(fwClient, logger)
+ : base(logger)
{
this.notificationTemplateRepository = notificationTemplateRepository;
}
diff --git a/WebAPI/LearningHub.Nhs.Services/RatingService.cs b/WebAPI/LearningHub.Nhs.Services/RatingService.cs
index ead13ade2..23c96c4fa 100644
--- a/WebAPI/LearningHub.Nhs.Services/RatingService.cs
+++ b/WebAPI/LearningHub.Nhs.Services/RatingService.cs
@@ -232,7 +232,6 @@ public async Task CreateRating(int userId, RatingVi
await this.GetRatingSummaryBasic(ratingViewModel.EntityVersionId);
- // TODO: Submit new resource record to findwise.
return retVal;
}
@@ -333,7 +332,6 @@ private async Task CreateNewRatingAndRecalcAverageAsync(int userId, RatingViewMo
await this.resourceVersionRatingSummaryRepository.UpdateAsync(userId, ratingSummary);
- // Submit updated rating to Findwise.
await this.resourceService.SubmitResourceVersionToSearchAsync(ratingViewModel.EntityVersionId, userId);
}
diff --git a/WebAPI/LearningHub.Nhs.Services/ResourceService.cs b/WebAPI/LearningHub.Nhs.Services/ResourceService.cs
index 6d71a5194..30278bad6 100644
--- a/WebAPI/LearningHub.Nhs.Services/ResourceService.cs
+++ b/WebAPI/LearningHub.Nhs.Services/ResourceService.cs
@@ -984,7 +984,7 @@ public async Task PublishResourceVersionAsync(PublishViewModel publishViewM
}
///
- /// Submits a published resource version to the Findwise search.
+ /// Submits a published resource version to search.
///
/// The resourceVersionId.
/// The userId.
@@ -1236,7 +1236,7 @@ public async Task UnpublishResourceVersion(Unpublis
this.resourceVersionRepository.Unpublish(unpublishViewModel.ResourceVersionId, unpublishViewModel.Details, userId);
- // Remove from Findwise Search Index
+ // Remove from Search Index
var r = await this.resourceVersionRepository.GetBasicByIdAsync(unpublishViewModel.ResourceVersionId);
await this.searchService.RemoveResourceFromSearchAsync(r.ResourceId);
diff --git a/WebAPI/LearningHub.Nhs.Services/ResourceSyncService.cs b/WebAPI/LearningHub.Nhs.Services/ResourceSyncService.cs
index 9c24ff569..9373ad6c8 100644
--- a/WebAPI/LearningHub.Nhs.Services/ResourceSyncService.cs
+++ b/WebAPI/LearningHub.Nhs.Services/ResourceSyncService.cs
@@ -24,7 +24,6 @@ public class ResourceSyncService : IResourceSyncService
private readonly IResourceVersionRepository resourceVersionRepository;
private readonly ICatalogueNodeVersionRepository catalogueNodeVersionRepository;
private readonly IGenericFileResourceVersionRepository genericFileResourceVersionRepository;
- private readonly IFindwiseApiFacade findwiseApiFacade;
private readonly IMapper mapper;
///
@@ -34,21 +33,18 @@ public class ResourceSyncService : IResourceSyncService
/// The resourceVersionRepository.
/// The catalogueNodeVersionRepository.
/// The genericFileResourceVersionRepository.
- /// The findwiseApiFacade.
/// The mapper.
public ResourceSyncService(
IResourceSyncRepository resourceSyncRepository,
IResourceVersionRepository resourceVersionRepository,
ICatalogueNodeVersionRepository catalogueNodeVersionRepository,
IGenericFileResourceVersionRepository genericFileResourceVersionRepository,
- IFindwiseApiFacade findwiseApiFacade,
IMapper mapper)
{
this.resourceSyncRepository = resourceSyncRepository;
this.resourceVersionRepository = resourceVersionRepository;
this.catalogueNodeVersionRepository = catalogueNodeVersionRepository;
this.genericFileResourceVersionRepository = genericFileResourceVersionRepository;
- this.findwiseApiFacade = findwiseApiFacade;
this.mapper = mapper;
}
@@ -104,46 +100,6 @@ public List GetSyncListResourcesForUser(int
/// The task.
public async Task SyncForUserAsync(int userId)
{
- // Obtain Resource Version dataset related to the sync list for the supplied User Id.
- var syncList = this.resourceSyncRepository.GetSyncListForUser(userId, true).ToList();
-
- var resources = syncList.Select(x => x.Resource).ToList();
-
- // Sync Updates
- var resourcesToUpdate = resources.Where(x => !this.ResourceIsUnpublished(x)).ToList();
- var resourceVersionIdList = resourcesToUpdate.Select(x => x.Id).ToList();
- var mappedResourcesToUpdate = await this.BuildSearchResourceRequestModelList(resourceVersionIdList);
-
- // Validate Findwise submission
- var invalidResourceDetails = new List();
- foreach (var r in mappedResourcesToUpdate)
- {
- if (!r.IsValidForSubmission())
- {
- invalidResourceDetails.Add(r.Title);
- }
- }
-
- if (invalidResourceDetails.Count > 0)
- {
- return new LearningHubValidationResult(false, $"The following Resources are not valid for submission: {string.Join(", ", invalidResourceDetails)}");
- }
-
- // Send update to Findwise
- if (mappedResourcesToUpdate.Any())
- {
- await this.findwiseApiFacade.AddOrReplaceAsync(mappedResourcesToUpdate.ToList());
- }
-
- // Synce Deletes
- var resourcesToDelete = resources.Where(x => this.ResourceIsUnpublished(x)).ToList();
- var mappedResourcesToDelete = resourcesToDelete.Select(x => this.mapper.Map(x)).ToList();
-
- if (mappedResourcesToDelete.Any())
- {
- await this.findwiseApiFacade.RemoveAsync(mappedResourcesToDelete.ToList());
- }
-
await this.resourceSyncRepository.SetSyncedForUserAsync(userId);
return new LearningHubValidationResult(true);
@@ -247,22 +203,7 @@ public async Task SyncSingleAsync(int resourceVersi
if (resourceVersion == null)
{
throw new Exception($"No resource version found for id '{resourceVersionId}'");
- }
-
- var searchResourceRequestModel = await this.BuildSearchResourceRequestModel(resourceVersionId);
- if (this.ResourceIsUnpublished(resourceVersion))
- {
- await this.findwiseApiFacade.RemoveAsync(new List { searchResourceRequestModel });
- }
- else
- {
- if (!searchResourceRequestModel.IsValidForSubmission())
- {
- return new LearningHubValidationResult(false, $"Resource '{resourceVersion.Title}' is not valid for submission to Findwise");
- }
-
- await this.findwiseApiFacade.AddOrReplaceAsync(new List { searchResourceRequestModel });
- }
+ }
return new LearningHubValidationResult(true);
}
diff --git a/WebAPI/LearningHub.Nhs.Services/SearchService.cs b/WebAPI/LearningHub.Nhs.Services/SearchService.cs
index d05c73cb5..be5cc8d98 100644
--- a/WebAPI/LearningHub.Nhs.Services/SearchService.cs
+++ b/WebAPI/LearningHub.Nhs.Services/SearchService.cs
@@ -42,18 +42,16 @@ public class SearchService : BaseService, ISearchService
/// Initializes a new instance of the class.
/// The search service.
///
- /// The FindWise Http Client.
/// The event service.
/// The logger.
/// The settings.
/// The mapper.
public SearchService(
- IFindWiseHttpClient findWiseHttpClient,
IEventService eventService,
ILogger logger,
IOptions settings,
IMapper mapper)
- : base(findWiseHttpClient, logger)
+ : base(logger)
{
this.eventService = eventService;
this.settings = settings.Value;
@@ -68,69 +66,8 @@ public SearchService(
/// The .
public async Task GetSearchResultAsync(SearchRequestModel searchRequestModel, int userId)
{
- SearchResultModel viewmodel = new SearchResultModel();
-
- try
- {
- // e.g. if pagesize is 10, then offset would be 0,10,20,30
- var pageSize = searchRequestModel.PageSize;
- var offset = searchRequestModel.PageIndex * pageSize;
-
- var client = await this.FindWiseHttpClient.GetClient(this.settings.Findwise.SearchUrl);
- var request = string.Format(
- this.settings.Findwise.UrlSearchComponent + "?offset={1}&hits={2}&q={3}&token={4}",
- this.settings.Findwise.CollectionIds.Resource,
- offset,
- pageSize,
- this.EncodeSearchText(searchRequestModel.SearchText) + searchRequestModel.FilterText + searchRequestModel.ResourceAccessLevelFilterText + searchRequestModel.ProviderFilterText,
- this.settings.Findwise.Token);
-
- if (searchRequestModel.CatalogueId.HasValue)
- {
- request += $"&catalogue_ids={searchRequestModel.CatalogueId}";
- }
-
- // if sort column is requested
- if (!string.IsNullOrEmpty(searchRequestModel.SortColumn))
- {
- var sortquery = $"&sort={searchRequestModel.SortColumn}";
-
- // if sort direction option is requested
- if (!string.IsNullOrEmpty(searchRequestModel.SortDirection))
- {
- var sortdirection = searchRequestModel.SortDirection.StartsWith("asc") ? "asc" : "desc";
- sortquery = $"{sortquery}_{sortdirection}";
- }
-
- request = $"{request}{sortquery}";
- }
-
- var response = await client.GetAsync(request).ConfigureAwait(false);
-
- if (response.IsSuccessStatusCode)
- {
- var result = response.Content.ReadAsStringAsync().Result;
- viewmodel = JsonConvert.DeserializeObject(result);
- searchRequestModel.TotalNumberOfHits = viewmodel.Stats.TotalHits;
- }
- else if (response.StatusCode == System.Net.HttpStatusCode.Unauthorized || response.StatusCode == System.Net.HttpStatusCode.Forbidden)
- {
- this.Logger.LogError($"Get Search Result failed in FindWise, HTTP Status Code:{response.StatusCode}");
- throw new Exception("AccessDenied to FindWise Server");
- }
- else
- {
- var error = response.Content.ReadAsStringAsync().Result.ToString();
- this.Logger.LogError($"Get Search Result failed in FindWise, HTTP Status Code:{response.StatusCode}, Error Message:{error}");
- throw new Exception("Error with FindWise Server");
- }
-
- return viewmodel;
- }
- catch (Exception)
- {
- throw;
- }
+ this.Logger.LogWarning("Search is not currently configured. Returning empty results.");
+ return await Task.FromResult(new SearchResultModel());
}
///
@@ -147,53 +84,7 @@ public async Task GetSearchResultAsync(SearchRequestModel sea
///
public async Task GetCatalogueSearchResultAsync(CatalogueSearchRequestModel catalogSearchRequestModel, int userId)
{
- var viewmodel = new SearchCatalogueResultModel();
-
- try
- {
- // e.g. if pagesize is 3, then offset would be 0,3,6,9
- var offset = catalogSearchRequestModel.PageIndex * catalogSearchRequestModel.PageSize;
- var client = await this.FindWiseHttpClient.GetClient(this.settings.Findwise.SearchUrl);
- var request = string.Format(
- this.settings.Findwise.UrlSearchComponent + "?offset={1}&hits={2}&q={3}&token={4}",
- this.settings.Findwise.CollectionIds.Catalogue,
- offset,
- catalogSearchRequestModel.PageSize,
- this.EncodeSearchText(catalogSearchRequestModel.SearchText),
- this.settings.Findwise.Token);
-
- var response = await client.GetAsync(request).ConfigureAwait(false);
-
- if (response.IsSuccessStatusCode)
- {
- var result = response.Content.ReadAsStringAsync().Result;
- viewmodel = JsonConvert.DeserializeObject(result);
- catalogSearchRequestModel.TotalNumberOfHits = viewmodel.Stats.TotalHits;
- }
- else if (response.StatusCode == System.Net.HttpStatusCode.Unauthorized || response.StatusCode == System.Net.HttpStatusCode.Forbidden)
- {
- this.Logger.LogError($"Get Catalogue Search Result failed in FindWise, HTTP Status Code:{response.StatusCode}");
- throw new Exception("AccessDenied to FindWise Server");
- }
- else
- {
- var error = response.Content.ReadAsStringAsync().Result.ToString();
- this.Logger.LogError($"Get Catalogue Search Result failed in FindWise, HTTP Status Code:{response.StatusCode}, Error Message:{error}");
- throw new Exception("Error with FindWise Server");
- }
-
- var remainingItems = catalogSearchRequestModel.TotalNumberOfHits - offset;
- var resultsPerPage = remainingItems >= catalogSearchRequestModel.PageSize ? catalogSearchRequestModel.PageSize : remainingItems;
- LearningHubValidationResult validationResult = await this.CreateCatalogueSearchTerm(catalogSearchRequestModel, resultsPerPage, userId);
-
- viewmodel.SearchId = validationResult.CreatedId ?? 0;
-
- return viewmodel;
- }
- catch (Exception)
- {
- throw;
- }
+ return await Task.FromResult(new SearchCatalogueResultModel());
}
///
@@ -205,53 +96,7 @@ public async Task GetCatalogueSearchResultAsync(Cata
/// The .
public async Task SendResourceForSearchAsync(SearchResourceRequestModel searchResourceRequestModel, int userId, int? iterations)
{
- try
- {
- if (string.IsNullOrEmpty(this.settings.Findwise.IndexMethod))
- {
- this.Logger.LogWarning("The FindWiseIndexMethod is not configured. Resource not added to search results");
- }
- else
- {
- List resourceList = new List();
- resourceList.Add(searchResourceRequestModel);
-
- var json = JsonConvert.SerializeObject(resourceList, new JsonSerializerSettings() { DateFormatString = "yyyy-MM-dd" });
-
- var stringContent = new StringContent(json, UnicodeEncoding.UTF8, "application/json");
-
- var client = await this.FindWiseHttpClient.GetClient(this.settings.Findwise.IndexUrl);
-
- var request = string.Format(this.settings.Findwise.IndexMethod, this.settings.Findwise.CollectionIds.Resource) + $"?token={this.settings.Findwise.Token}";
- var response = await client.PostAsync(request, stringContent).ConfigureAwait(false);
- iterations--;
- if (response.StatusCode == System.Net.HttpStatusCode.Unauthorized || response.StatusCode == System.Net.HttpStatusCode.Forbidden)
- {
- this.Logger.LogError("Save to FindWise failed for resourceId:" + searchResourceRequestModel.Id.ToString() + "HTTP Status Code:" + response.StatusCode.ToString());
- throw new Exception("AccessDenied");
- }
- else if (!response.IsSuccessStatusCode)
- {
- if (iterations < 0)
- {
- this.Logger.LogError("Save to FindWise failed for resourceId:" + searchResourceRequestModel.Id.ToString() + "HTTP Status Code:" + response.StatusCode.ToString());
- throw new Exception("Posting of resource to search failed: " + stringContent);
- }
-
- await this.SendResourceForSearchAsync(searchResourceRequestModel, userId, iterations);
- }
- else
- {
- return true;
- }
- }
-
- return false;
- }
- catch (Exception ex)
- {
- throw new Exception("Posting of resource to search failed: " + searchResourceRequestModel.Id + " : " + ex.Message);
- }
+ return await Task.FromResult(true);
}
///
@@ -443,36 +288,9 @@ public async Task CreateCatalogueResourceSearchActi
///
/// The resource to be removed from search.
/// The .
- public async Task RemoveResourceFromSearchAsync(int resourceId)
+ public Task RemoveResourceFromSearchAsync(int resourceId)
{
- try
- {
- if (string.IsNullOrEmpty(this.settings.Findwise.IndexMethod))
- {
- this.Logger.LogWarning("The FindWiseIndexMethod is not configured. Resource not removed from search.");
- }
- else
- {
- var client = await this.FindWiseHttpClient.GetClient(this.settings.Findwise.IndexUrl);
-
- var request = string.Format(this.settings.Findwise.IndexMethod, this.settings.Findwise.CollectionIds.Resource) + $"?id={resourceId.ToString()}&token={this.settings.Findwise.Token}";
-
- var response = await client.DeleteAsync(request).ConfigureAwait(false);
-
- if (response.StatusCode == System.Net.HttpStatusCode.Unauthorized || response.StatusCode == System.Net.HttpStatusCode.Forbidden)
- {
- throw new Exception("AccessDenied");
- }
- else if (!response.IsSuccessStatusCode)
- {
- throw new Exception("Removal of resource to search failed: " + resourceId.ToString());
- }
- }
- }
- catch (Exception ex)
- {
- throw new Exception("Removal of resource from search failed: " + resourceId.ToString() + " : " + ex.Message);
- }
+ return Task.CompletedTask;
}
///
@@ -548,44 +366,7 @@ public async Task SendCatalogueSearchEventAsync(SearchActionCatalogueModel
/// The .
public async Task GetAllCatalogueSearchResultsAsync(AllCatalogueSearchRequestModel catalogSearchRequestModel)
{
- var viewmodel = new SearchAllCatalogueResultModel();
- try
- {
- var offset = catalogSearchRequestModel.PageIndex * catalogSearchRequestModel.PageSize;
- var client = await this.FindWiseHttpClient.GetClient(this.settings.Findwise.SearchUrl);
- var request = string.Format(
- this.settings.Findwise.UrlSearchComponent + "?offset={1}&hits={2}&q={3}&token={4}",
- this.settings.Findwise.CollectionIds.Catalogue,
- offset,
- catalogSearchRequestModel.PageSize,
- this.EncodeSearchText(catalogSearchRequestModel.SearchText),
- this.settings.Findwise.Token);
-
- var response = await client.GetAsync(request).ConfigureAwait(false);
-
- if (response.IsSuccessStatusCode)
- {
- var result = response.Content.ReadAsStringAsync().Result;
- viewmodel = JsonConvert.DeserializeObject(result);
- }
- else if (response.StatusCode == System.Net.HttpStatusCode.Unauthorized || response.StatusCode == System.Net.HttpStatusCode.Forbidden)
- {
- this.Logger.LogError($"Get AllCatalogue Search Result failed in FindWise, HTTP Status Code:{response.StatusCode}");
- throw new Exception("AccessDenied to FindWise Server");
- }
- else
- {
- var error = response.Content.ReadAsStringAsync().Result.ToString();
- this.Logger.LogError($"Get AllCatalogue Search Result failed in FindWise, HTTP Status Code:{response.StatusCode}, Error Message:{error}");
- throw new Exception("Error with FindWise Server");
- }
-
- return viewmodel;
- }
- catch (Exception)
- {
- throw;
- }
+ return await Task.FromResult(new SearchAllCatalogueResultModel());
}
///
@@ -595,42 +376,7 @@ public async Task GetAllCatalogueSearchResultsAsy
/// The .
public async Task GetAutoSuggestionResultsAsync(string term)
{
- var viewmodel = new AutoSuggestionModel();
-
- try
- {
- var client = await this.FindWiseHttpClient.GetClient(this.settings.Findwise.SearchUrl);
- var request = string.Format(
- this.settings.Findwise.UrlSearchComponent + "?q={1}&token={2}",
- this.settings.Findwise.CollectionIds.AutoSuggestion,
- this.EncodeSearchText(term),
- this.settings.Findwise.Token);
-
- var response = await client.GetAsync(request).ConfigureAwait(false);
-
- if (response.IsSuccessStatusCode)
- {
- var result = response.Content.ReadAsStringAsync().Result;
- viewmodel = JsonConvert.DeserializeObject(result);
- }
- else if (response.StatusCode == System.Net.HttpStatusCode.Unauthorized || response.StatusCode == System.Net.HttpStatusCode.Forbidden)
- {
- this.Logger.LogError($"Get Auto Suggetion Result failed in FindWise, HTTP Status Code:{response.StatusCode}");
- throw new Exception("AccessDenied to FindWise Server");
- }
- else
- {
- var error = response.Content.ReadAsStringAsync().Result.ToString();
- this.Logger.LogError($"Get Auto Suggetion Result failed in FindWise, HTTP Status Code:{response.StatusCode}, Error Message:{error}");
- throw new Exception("Error with FindWise Server");
- }
-
- return viewmodel;
- }
- catch (Exception)
- {
- throw;
- }
+ return await Task.FromResult(new AutoSuggestionModel());
}
///
@@ -662,46 +408,7 @@ public async Task SendAutoSuggestionEventAsync(AutoSuggestionClickPayloadM
///
private async Task SendSearchEventClickAsync(SearchClickPayloadModel searchClickPayloadModel, bool isResource)
{
- var eventType = isResource ? "resource" : "catalog";
-
- try
- {
- if (string.IsNullOrEmpty(this.settings.Findwise.UrlClickComponent))
- {
- this.Logger.LogWarning($"The UrlClickComponent is not configured. {eventType} click event not send to FindWise.");
- }
- else
- {
- var json = JsonConvert.SerializeObject(searchClickPayloadModel);
- var base64EncodedString = BinaryFormatterHelper.Base64EncodeObject(json);
-
- var request = $"{this.settings.Findwise.UrlClickComponent}?payload={base64EncodedString}";
-
- var client = await this.FindWiseHttpClient.GetClient(this.settings.Findwise.SearchUrl);
- var response = await client.PostAsync(request, null).ConfigureAwait(false);
-
- if (response.StatusCode == System.Net.HttpStatusCode.Unauthorized || response.StatusCode == System.Net.HttpStatusCode.Forbidden)
- {
- this.Logger.LogError($"Click event save to FindWise failed for {eventType}: {searchClickPayloadModel.ClickTargetUrl} HTTP Status Code: {response.StatusCode}");
- throw new Exception("AccessDenied");
- }
- else if (!response.IsSuccessStatusCode)
- {
- this.Logger.LogError($"Click event save to FindWise failed for {eventType}: {searchClickPayloadModel.ClickTargetUrl} HTTP Status Code: {response.StatusCode}");
- throw new Exception($"Click event save to FindWise failed for {eventType}: {json}");
- }
- else
- {
- return true;
- }
- }
-
- return false;
- }
- catch (Exception ex)
- {
- throw new Exception($"Click event save to FindWise failed for {eventType}: {searchClickPayloadModel.ClickTargetUrl} : {ex.Message}");
- }
+ return await Task.FromResult(false);
}
///
@@ -713,44 +420,7 @@ private async Task SendSearchEventClickAsync(SearchClickPayloadModel searc
///
private async Task SendAutoSuggestionEventClickAsync(AutoSuggestionClickPayloadModel clickPayloadModel)
{
- try
- {
- if (string.IsNullOrEmpty(this.settings.Findwise.UrlAutoSuggestionClickComponent))
- {
- this.Logger.LogWarning($"The UrlClickComponent is not configured. Auto suggestion click event not send to FindWise.");
- }
- else
- {
- var json = JsonConvert.SerializeObject(clickPayloadModel);
- var base64EncodedString = BinaryFormatterHelper.Base64EncodeObject(json);
-
- var request = $"{this.settings.Findwise.UrlAutoSuggestionClickComponent}?payload={base64EncodedString}";
-
- var client = await this.FindWiseHttpClient.GetClient(this.settings.Findwise.SearchUrl);
- var response = await client.PostAsync(request, null).ConfigureAwait(false);
-
- if (response.StatusCode == System.Net.HttpStatusCode.Unauthorized || response.StatusCode == System.Net.HttpStatusCode.Forbidden)
- {
- this.Logger.LogError($"Click event save to FindWise failed for Auto suggestion: {clickPayloadModel.ClickTargetUrl} HTTP Status Code: {response.StatusCode}");
- throw new Exception("AccessDenied");
- }
- else if (!response.IsSuccessStatusCode)
- {
- this.Logger.LogError($"Click event save to FindWise failed for Auto suggestion: {clickPayloadModel.ClickTargetUrl} HTTP Status Code: {response.StatusCode}");
- throw new Exception($"Click event save to FindWise failed for Auto suggestion: {json}");
- }
- else
- {
- return true;
- }
- }
-
- return false;
- }
- catch (Exception ex)
- {
- throw new Exception($"Click event save to FindWise failed for Auto suggestion: {clickPayloadModel.ClickTargetUrl} : {ex.Message}");
- }
+ return await Task.FromResult(false);
}
private string EncodeSearchText(string searchText)
From c55e1a17f231cb03a0c32827c9e7e74b15c19638 Mon Sep 17 00:00:00 2001
From: Binon
Date: Tue, 14 Apr 2026 17:27:59 +0100
Subject: [PATCH 2/2] removed the remaining findwise references in webapi
---
.../Controllers/SearchController.cs | 6 +-
WebAPI/LearningHub.Nhs.API/appsettings.json | 17 +-----
.../Configuration/AzureSearchSettings.cs | 19 ++++++
.../FindwiseCollectionIdSettings.cs | 28 ---------
.../Configuration/FindwiseSettings.cs | 58 -------------------
.../Configuration/Settings.cs | 4 +-
.../LearningHub.Nhs.Services/SearchService.cs | 6 +-
7 files changed, 29 insertions(+), 109 deletions(-)
create mode 100644 WebAPI/LearningHub.Nhs.Api.Shared/Configuration/AzureSearchSettings.cs
delete mode 100644 WebAPI/LearningHub.Nhs.Api.Shared/Configuration/FindwiseCollectionIdSettings.cs
delete mode 100644 WebAPI/LearningHub.Nhs.Api.Shared/Configuration/FindwiseSettings.cs
diff --git a/WebAPI/LearningHub.Nhs.API/Controllers/SearchController.cs b/WebAPI/LearningHub.Nhs.API/Controllers/SearchController.cs
index ea4d10d04..1e6f72e35 100644
--- a/WebAPI/LearningHub.Nhs.API/Controllers/SearchController.cs
+++ b/WebAPI/LearningHub.Nhs.API/Controllers/SearchController.cs
@@ -312,7 +312,7 @@ private async Task GetSearchResults(SearchRequestModel searchRe
searchViewModel.DocumentModel = results.DocumentList.Documents.ToList();
searchViewModel.SearchString = searchRequestModel.SearchText;
searchViewModel.Hits = results.DocumentList.Documents.Count();
- searchViewModel.DescriptionMaximumLength = this.settings.Findwise.MaximumDescriptionLength;
+ searchViewModel.DescriptionMaximumLength = this.settings.AzureSearch.MaximumDescriptionLength;
searchViewModel.ErrorOnAPI = results.ErrorsOnAPICall;
searchViewModel.Facets = results.Facets;
@@ -418,7 +418,7 @@ private async Task GetCatalogueSearchResults(Catalogue
DocumentModel = documents,
SearchString = catalogueSearchRequestModel.SearchText,
Hits = results.DocumentList.Documents.Count(),
- DescriptionMaximumLength = this.settings.Findwise.MaximumDescriptionLength,
+ DescriptionMaximumLength = this.settings.AzureSearch.MaximumDescriptionLength,
ErrorOnAPI = results.ErrorsOnAPICall,
Facets = results.Facets,
};
@@ -491,7 +491,7 @@ private async Task GetAllCatalogueResults(AllCatalo
DocumentModel = documents,
SearchString = catalogueSearchRequestModel.SearchText,
Hits = results.DocumentList.Documents.Count(),
- DescriptionMaximumLength = this.settings.Findwise.MaximumDescriptionLength,
+ DescriptionMaximumLength = this.settings.AzureSearch.MaximumDescriptionLength,
ErrorOnAPI = results.ErrorsOnAPICall,
Facets = results.Facets,
};
diff --git a/WebAPI/LearningHub.Nhs.API/appsettings.json b/WebAPI/LearningHub.Nhs.API/appsettings.json
index b35cc9fe6..5498a983a 100644
--- a/WebAPI/LearningHub.Nhs.API/appsettings.json
+++ b/WebAPI/LearningHub.Nhs.API/appsettings.json
@@ -83,21 +83,8 @@
}
},
- "FindWise": {
- "IndexUrl": "",
- "SearchUrl": "",
- "CollectionIds": {
- "Resource": "",
- "Catalogue": "",
- "AutoSuggestion": ""
- },
- "UrlSearchComponent": "rest/apps/HEE/searchers/{0}",
- "UrlClickComponent": "rest/apps/HEE/searchers/hee/signals/hee/signal/click",
- "UrlAutoSuggestionClickComponent": "rest/apps/HEE/searchers/hee/signals/hee/signal/click-hee",
- "Token": "",
- "MaximumDescriptionLength": 150,
- "IndexMethod": "/rest/v2/collections/{0}/documents",
- "DescriptionLengthLimit": 3000
+ "AzureSearch": {
+ "MaximumDescriptionLength": 150
},
"Notifications": {
"PublishResourceTimeToProcessInSec": 30,
diff --git a/WebAPI/LearningHub.Nhs.Api.Shared/Configuration/AzureSearchSettings.cs b/WebAPI/LearningHub.Nhs.Api.Shared/Configuration/AzureSearchSettings.cs
new file mode 100644
index 000000000..796306ac7
--- /dev/null
+++ b/WebAPI/LearningHub.Nhs.Api.Shared/Configuration/AzureSearchSettings.cs
@@ -0,0 +1,19 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace LearningHub.Nhs.Api.Shared.Configuration
+{
+ ///
+ /// The Azure AI Search configuration settings.
+ ///
+ public class AzureSearchSettings
+ {
+ ///
+ /// Gets or sets the maximum description length.
+ ///
+ public int MaximumDescriptionLength { get; set; } = 150;
+ }
+}
diff --git a/WebAPI/LearningHub.Nhs.Api.Shared/Configuration/FindwiseCollectionIdSettings.cs b/WebAPI/LearningHub.Nhs.Api.Shared/Configuration/FindwiseCollectionIdSettings.cs
deleted file mode 100644
index b83dc6805..000000000
--- a/WebAPI/LearningHub.Nhs.Api.Shared/Configuration/FindwiseCollectionIdSettings.cs
+++ /dev/null
@@ -1,28 +0,0 @@
-namespace LearningHub.Nhs.Api.Shared.Configuration
-{
- ///
- /// The FindwiseCollectionIdSettings.
- ///
- public class FindwiseCollectionIdSettings
- {
- ///
- /// Gets or sets the resource collection id.
- ///
- public string Resource { get; set; }
-
- ///
- /// Gets or sets the catalogue collection id.
- ///
- public string Catalogue { get; set; }
-
- ///
- /// Gets or sets the AutoSuggestion collection id.
- ///
- public string AutoSuggestion { get; set; }
-
- ///
- /// Gets or sets the moodle collection id.
- ///
- public string Moodle { get; set; }
- }
-}
diff --git a/WebAPI/LearningHub.Nhs.Api.Shared/Configuration/FindwiseSettings.cs b/WebAPI/LearningHub.Nhs.Api.Shared/Configuration/FindwiseSettings.cs
deleted file mode 100644
index aa3802eee..000000000
--- a/WebAPI/LearningHub.Nhs.Api.Shared/Configuration/FindwiseSettings.cs
+++ /dev/null
@@ -1,58 +0,0 @@
-namespace LearningHub.Nhs.Api.Shared.Configuration
-{
- ///
- /// The FindwiseSettings.
- ///
- public class FindwiseSettings
- {
- ///
- /// Gets or sets the index url.
- ///
- public string IndexUrl { get; set; }
-
- ///
- /// Gets or sets the search url.
- ///
- public string SearchUrl { get; set; }
-
- ///
- /// Gets or sets the url search component.
- ///
- public string UrlSearchComponent { get; set; }
-
- ///
- /// Gets or sets the url click component.
- ///
- public string UrlClickComponent { get; set; }
-
- ///
- /// Gets or sets the url AutoSuggestion click component.
- ///
- public string UrlAutoSuggestionClickComponent { get; set; }
-
- ///
- /// Gets or sets the token.
- ///
- public string Token { get; set; }
-
- ///
- /// Gets or sets the maximum description length.
- ///
- public int MaximumDescriptionLength { get; set; }
-
- ///
- /// Gets or sets the index method.
- ///
- public string IndexMethod { get; set; }
-
- ///
- /// Gets or sets the collection ids.
- ///
- public FindwiseCollectionIdSettings CollectionIds { get; set; }
-
- ///
- /// Gets or sets the Description length limit.
- ///
- public int DescriptionLengthLimit { get; set; }
- }
-}
diff --git a/WebAPI/LearningHub.Nhs.Api.Shared/Configuration/Settings.cs b/WebAPI/LearningHub.Nhs.Api.Shared/Configuration/Settings.cs
index 13b2b0654..544e9a0f0 100644
--- a/WebAPI/LearningHub.Nhs.Api.Shared/Configuration/Settings.cs
+++ b/WebAPI/LearningHub.Nhs.Api.Shared/Configuration/Settings.cs
@@ -133,9 +133,9 @@ public class Settings
public MigrationToolSettings MigrationTool { get; set; }
///
- /// Gets or sets the findwise settings.
+ /// Gets or sets the Azure Search settings.
///
- public FindwiseSettings Findwise { get; set; }
+ public AzureSearchSettings AzureSearch { get; set; }
///
/// Gets or sets the azure storage account connectionstring for queue.
diff --git a/WebAPI/LearningHub.Nhs.Services/SearchService.cs b/WebAPI/LearningHub.Nhs.Services/SearchService.cs
index be5cc8d98..3680f28c0 100644
--- a/WebAPI/LearningHub.Nhs.Services/SearchService.cs
+++ b/WebAPI/LearningHub.Nhs.Services/SearchService.cs
@@ -334,7 +334,7 @@ public async Task SendResourceSearchEventClickAsync(SearchActionResourceMo
searchClickPayloadModel.TimeOfClick = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
searchClickPayloadModel.SearchSignal.ProfileSignature.ApplicationId = ApplicationId;
searchClickPayloadModel.SearchSignal.ProfileSignature.ProfileType = ProfileType;
- searchClickPayloadModel.SearchSignal.ProfileSignature.ProfileId = this.settings.Findwise.CollectionIds.Resource;
+ searchClickPayloadModel.SearchSignal.ProfileSignature.ProfileId = "Resource";
return await this.SendSearchEventClickAsync(searchClickPayloadModel, true);
}
@@ -354,7 +354,7 @@ public async Task SendCatalogueSearchEventAsync(SearchActionCatalogueModel
searchClickPayloadModel.TimeOfClick = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
searchClickPayloadModel.SearchSignal.ProfileSignature.ApplicationId = ApplicationId;
searchClickPayloadModel.SearchSignal.ProfileSignature.ProfileType = ProfileType;
- searchClickPayloadModel.SearchSignal.ProfileSignature.ProfileId = this.settings.Findwise.CollectionIds.Catalogue;
+ searchClickPayloadModel.SearchSignal.ProfileSignature.ProfileId = "Catalogue";
return await this.SendSearchEventClickAsync(searchClickPayloadModel, false);
}
@@ -393,7 +393,7 @@ public async Task SendAutoSuggestionEventAsync(AutoSuggestionClickPayloadM
clickPayloadModel.TimeOfClick = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
clickPayloadModel.SearchSignal.ProfileSignature.ApplicationId = ApplicationId;
clickPayloadModel.SearchSignal.ProfileSignature.ProfileType = ProfileType;
- clickPayloadModel.SearchSignal.ProfileSignature.ProfileId = this.settings.Findwise.CollectionIds.AutoSuggestion;
+ clickPayloadModel.SearchSignal.ProfileSignature.ProfileId = "AutoSuggestion";
return await this.SendAutoSuggestionEventClickAsync(clickPayloadModel);
}