From e95730dfffd5ea1f2689eda6a2db0aeb77b57f7e Mon Sep 17 00:00:00 2001 From: Sebastian Date: Mon, 4 Apr 2022 18:33:17 +0200 Subject: [PATCH] Downgrade elastic client. --- .../ElasticSearchActionHandler.cs | 87 ++++++++++--------- .../Squidex.Extensions.csproj | 52 +++++------ 2 files changed, 72 insertions(+), 67 deletions(-) diff --git a/backend/extensions/Squidex.Extensions/Actions/ElasticSearch/ElasticSearchActionHandler.cs b/backend/extensions/Squidex.Extensions/Actions/ElasticSearch/ElasticSearchActionHandler.cs index e07e0900c..7cb25669b 100644 --- a/backend/extensions/Squidex.Extensions/Actions/ElasticSearch/ElasticSearchActionHandler.cs +++ b/backend/extensions/Squidex.Extensions/Actions/ElasticSearch/ElasticSearchActionHandler.cs @@ -10,6 +10,7 @@ using Newtonsoft.Json.Linq; using Squidex.Domain.Apps.Core.HandleRules; using Squidex.Domain.Apps.Core.Rules.EnrichedEvents; using Squidex.Domain.Apps.Core.Scripting; +using Squidex.Infrastructure; #pragma warning disable IDE0059 // Value assigned to symbol is never used #pragma warning disable MA0048 // File name must match type name @@ -41,61 +42,65 @@ namespace Squidex.Extensions.Actions.ElasticSearch protected override async Task<(string Description, ElasticSearchJob Data)> CreateJobAsync(EnrichedEvent @event, ElasticSearchAction action) { - if (@event is IEnrichedEntityEvent entityEvent) + var delete = @event.ShouldDelete(scriptEngine, action.Delete); + + string contentId; + + if (@event is IEnrichedEntityEvent enrichedEntityEvent) { - var delete = @event.ShouldDelete(scriptEngine, action.Delete); + contentId = enrichedEntityEvent.Id.ToString(); + } + else + { + contentId = DomainId.NewGuid().ToString(); + } - var contentId = entityEvent.Id.ToString(); + var ruleDescription = string.Empty; + var ruleJob = new ElasticSearchJob + { + IndexName = await FormatAsync(action.IndexName, @event), + ServerHost = action.Host.ToString(), + ServerUser = action.Username, + ServerPassword = action.Password, + ContentId = contentId + }; + + if (delete) + { + ruleDescription = $"Delete entry index: {action.IndexName}"; + } + else + { + ruleDescription = $"Upsert to index: {action.IndexName}"; - var ruleDescription = string.Empty; - var ruleJob = new ElasticSearchJob + JObject json; + try { - IndexName = await FormatAsync(action.IndexName, @event), - ServerHost = action.Host.ToString(), - ServerUser = action.Username, - ServerPassword = action.Password, - ContentId = contentId - }; - - if (delete) - { - ruleDescription = $"Delete entry index: {action.IndexName}"; - } - else - { - ruleDescription = $"Upsert to index: {action.IndexName}"; + string jsonString; - JObject json; - try + if (!string.IsNullOrEmpty(action.Document)) { - string jsonString; - - if (!string.IsNullOrEmpty(action.Document)) - { - jsonString = await FormatAsync(action.Document, @event); - jsonString = jsonString?.Trim(); - } - else - { - jsonString = ToJson(@event); - } - - json = JObject.Parse(jsonString); + jsonString = await FormatAsync(action.Document, @event); + jsonString = jsonString?.Trim(); } - catch (Exception ex) + else { - json = new JObject(new JProperty("error", $"Invalid JSON: {ex.Message}")); + jsonString = ToJson(@event); } - json.AddFirst(new JProperty("contentId", contentId)); - - ruleJob.Content = json.ToString(); + json = JObject.Parse(jsonString); + } + catch (Exception ex) + { + json = new JObject(new JProperty("error", $"Invalid JSON: {ex.Message}")); } - return (ruleDescription, ruleJob); + json.AddFirst(new JProperty("contentId", contentId)); + + ruleJob.Content = json.ToString(); } - return ("Ignore", new ElasticSearchJob()); + return (ruleDescription, ruleJob); } protected override async Task ExecuteJobAsync(ElasticSearchJob job, diff --git a/backend/extensions/Squidex.Extensions/Squidex.Extensions.csproj b/backend/extensions/Squidex.Extensions/Squidex.Extensions.csproj index 1631c233a..f67f49985 100644 --- a/backend/extensions/Squidex.Extensions/Squidex.Extensions.csproj +++ b/backend/extensions/Squidex.Extensions/Squidex.Extensions.csproj @@ -10,35 +10,35 @@ - - - - - - - - - + + + + + + + + + + all runtime; build; native; contentfiles; analyzers; buildtransitive - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + +