From 66f1131863cc924d1f7607a18661c3ea39ccdd73 Mon Sep 17 00:00:00 2001 From: Meik Date: Tue, 30 Jun 2026 19:13:07 +0200 Subject: [PATCH] fix: read ticket history without journal service DI --- F4SDM42WebApi/F4SD - M42WebApi.csproj | 6 +- F4SDM42WebApi/F4SDHelperService.cs | 79 +++++++----------------- F4SDM42WebApi/F4SDM42WebApiController.cs | 6 -- 3 files changed, 25 insertions(+), 66 deletions(-) diff --git a/F4SDM42WebApi/F4SD - M42WebApi.csproj b/F4SDM42WebApi/F4SD - M42WebApi.csproj index 8afd52b..56f7fba 100644 --- a/F4SDM42WebApi/F4SD - M42WebApi.csproj +++ b/F4SDM42WebApi/F4SD - M42WebApi.csproj @@ -13,7 +13,7 @@ false 6673a25d-33d6-4072-91d9-abed4be1a966 C4ITF4SD*.* - 1.4.0.17 + 1.4.0.18 true @@ -30,8 +30,8 @@ M42Libraries\26.1\Matrix42.Contracts.Platform.dll false - - M42Libraries\26.1\Matrix42.Contracts.ServiceManagement.dll + + M42Libraries\26.1\Matrix42.BizLogic.Journal.dll false diff --git a/F4SDM42WebApi/F4SDHelperService.cs b/F4SDM42WebApi/F4SDHelperService.cs index 69ad613..acc6928 100644 --- a/F4SDM42WebApi/F4SDHelperService.cs +++ b/F4SDM42WebApi/F4SDHelperService.cs @@ -1,6 +1,7 @@ using C4IT.F4SDM; using C4IT.FASD.Base; using C4IT.Logging; +using Matrix42.BizLogic.Common.Journal; using Matrix42.Common; using Newtonsoft.Json; using System; @@ -1408,29 +1409,34 @@ namespace C4IT.F4SD { await Task.Delay(0); List journalEntries = new List(); - var entries = GetJournalList(activityEOID); - LogEntry($"{entries.Length} Journal entries found for ObjectID={activityEOID}", LogLevels.Debug); - for (int i = 0; i < entries.Length; i++) - { - var item = entries.GetValue(i); - var journalId = GetJournalEntryValue(item, "Id", Guid.Empty); - var createdDate = GetJournalEntryValue(item, "CreatedDate", DateTime.MinValue); - var creator = GetJournalEntryValue(item, "Creator", string.Empty); - var text = GetJournalEntryValue(item, "Text", string.Empty); - var header = GetJournalEntryValue(item, "Header", string.Empty); - var visibleInPortal = GetJournalEntryValue(item, "VisibleInPortal", false); + var entries = JournalManager.GetObjectEntries( + activityEOID, + false, + null, + 0, + 50, + false, + "{2}", + 120); - LogEntry($"Journal entry {i + 1}/{entries.Length}: ID={journalId}, CreatedDate={createdDate}, CreatedBy={creator}, Header={header}", LogLevels.Debug); + LogEntry($"{entries.Count} Journal entries found for ObjectID={activityEOID}", LogLevels.Debug); + for (int i = 0; i < entries.Count; i++) + { + var item = entries[i]; + var text = item.Body ?? string.Empty; + var createdDate = item.CreatedDate ?? DateTime.MinValue; + + LogEntry($"Journal entry {i + 1}/{entries.Count}: ID={item.Id}, CreatedDate={createdDate}, CreatedBy={item.CreatorName}, Header={item.Header}", LogLevels.Debug); journalEntries.Add(new cTicketJournalItem() { - JournalId = journalId, + JournalId = item.Id, ActivityObjectId = activityEOID, - CreatedBy = creator, + CreatedBy = item.CreatorName, CreationDate = createdDate, DescriptionHtml = text, Description = string.IsNullOrEmpty(text) ? string.Empty : Matrix42.Common.Html.HtmlConverter.ConvertHtmlToPlainText(text), - Header = header, - IsVisibleForUser = visibleInPortal + Header = item.Header, + IsVisibleForUser = item.VisibleInPortal }); } return journalEntries; @@ -1446,47 +1452,6 @@ namespace C4IT.F4SD } } - private static Array GetJournalList(Guid activityEOID) - { - var journalService = F4SDM42WebApiController.defaultInstance.GetJournalService(); - var method = FindJournalListMethod(journalService.GetType()); - if (method == null) - throw new MissingMethodException(journalService.GetType().FullName, "GetJournalList(Guid, Boolean, Int32, Int32, String, Int32)"); - - return method.Invoke(journalService, new object[] - { - activityEOID, - false, - 0, - 50, - "{2}", - 120 - }) as Array ?? Array.Empty(); - } - - private static MethodInfo FindJournalListMethod(Type serviceType) - { - var parameterTypes = new[] { typeof(Guid), typeof(bool), typeof(int), typeof(int), typeof(string), typeof(int) }; - return new[] { serviceType } - .Concat(serviceType.GetInterfaces()) - .Select(type => type.GetMethod("GetJournalList", parameterTypes)) - .FirstOrDefault(method => method != null); - } - - private static T GetJournalEntryValue(object entry, string propertyName, T defaultValue) - { - var property = entry?.GetType().GetProperty(propertyName); - var value = property?.GetValue(entry); - if (value == null || value == DBNull.Value) - return defaultValue; - - if (value is T typedValue) - return typedValue; - - var targetType = Nullable.GetUnderlyingType(typeof(T)) ?? typeof(T); - return (T)Convert.ChangeType(value, targetType, CultureInfo.InvariantCulture); - } - internal async Task updateActivitySolution(Guid objectId, string solutionHtml) { diff --git a/F4SDM42WebApi/F4SDM42WebApiController.cs b/F4SDM42WebApi/F4SDM42WebApiController.cs index 60d68d1..279b24a 100644 --- a/F4SDM42WebApi/F4SDM42WebApiController.cs +++ b/F4SDM42WebApi/F4SDM42WebApiController.cs @@ -10,7 +10,6 @@ using System.Threading.Tasks; using Matrix42.Common; using Matrix42.Contracts.Common.Security; -using Matrix42.Contracts.ServiceManagement.ServiceContracts; using Matrix42.Hosting.Contracts; using Matrix42.Pandora.Contracts; using Matrix42.Persistence.Contracts; @@ -81,11 +80,6 @@ namespace C4IT.F4SD catch { }; } - internal IJournalService GetJournalService() - { - return GetRequiredService(); - } - private T GetRequiredService() where T : class { var service = _resolver.TryGet();