fix: read ticket history without journal service DI

This commit is contained in:
Meik
2026-06-30 19:13:07 +02:00
parent de9a226272
commit 66f1131863
3 changed files with 25 additions and 66 deletions

View File

@@ -13,7 +13,7 @@
<EnableDefaultCompileItems>false</EnableDefaultCompileItems> <EnableDefaultCompileItems>false</EnableDefaultCompileItems>
<M42ExtensionId>6673a25d-33d6-4072-91d9-abed4be1a966</M42ExtensionId> <M42ExtensionId>6673a25d-33d6-4072-91d9-abed4be1a966</M42ExtensionId>
<M42AssemblyPattern>C4ITF4SD*.*</M42AssemblyPattern> <M42AssemblyPattern>C4ITF4SD*.*</M42AssemblyPattern>
<M42PackageVersion>1.4.0.17</M42PackageVersion> <M42PackageVersion>1.4.0.18</M42PackageVersion>
<M42BuildPackage>true</M42BuildPackage> <M42BuildPackage>true</M42BuildPackage>
</PropertyGroup> </PropertyGroup>
@@ -30,8 +30,8 @@
<HintPath>M42Libraries\26.1\Matrix42.Contracts.Platform.dll</HintPath> <HintPath>M42Libraries\26.1\Matrix42.Contracts.Platform.dll</HintPath>
<Private>false</Private> <Private>false</Private>
</Reference> </Reference>
<Reference Include="Matrix42.Contracts.ServiceManagement"> <Reference Include="Matrix42.BizLogic.Journal">
<HintPath>M42Libraries\26.1\Matrix42.Contracts.ServiceManagement.dll</HintPath> <HintPath>M42Libraries\26.1\Matrix42.BizLogic.Journal.dll</HintPath>
<Private>false</Private> <Private>false</Private>
</Reference> </Reference>
<Reference Include="Matrix42.Hosting.Contracts"> <Reference Include="Matrix42.Hosting.Contracts">

View File

@@ -1,6 +1,7 @@
using C4IT.F4SDM; using C4IT.F4SDM;
using C4IT.FASD.Base; using C4IT.FASD.Base;
using C4IT.Logging; using C4IT.Logging;
using Matrix42.BizLogic.Common.Journal;
using Matrix42.Common; using Matrix42.Common;
using Newtonsoft.Json; using Newtonsoft.Json;
using System; using System;
@@ -1408,29 +1409,34 @@ namespace C4IT.F4SD
{ {
await Task.Delay(0); await Task.Delay(0);
List<cTicketJournalItem> journalEntries = new List<cTicketJournalItem>(); List<cTicketJournalItem> journalEntries = new List<cTicketJournalItem>();
var entries = GetJournalList(activityEOID); var entries = JournalManager.GetObjectEntries(
LogEntry($"{entries.Length} Journal entries found for ObjectID={activityEOID}", LogLevels.Debug); activityEOID,
for (int i = 0; i < entries.Length; i++) false,
{ null,
var item = entries.GetValue(i); 0,
var journalId = GetJournalEntryValue(item, "Id", Guid.Empty); 50,
var createdDate = GetJournalEntryValue(item, "CreatedDate", DateTime.MinValue); false,
var creator = GetJournalEntryValue(item, "Creator", string.Empty); "<a href=\"#\" class=\"mx-object-journal--link {0} {1}\">{2}</a>",
var text = GetJournalEntryValue(item, "Text", string.Empty); 120);
var header = GetJournalEntryValue(item, "Header", string.Empty);
var visibleInPortal = GetJournalEntryValue(item, "VisibleInPortal", false);
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() journalEntries.Add(new cTicketJournalItem()
{ {
JournalId = journalId, JournalId = item.Id,
ActivityObjectId = activityEOID, ActivityObjectId = activityEOID,
CreatedBy = creator, CreatedBy = item.CreatorName,
CreationDate = createdDate, CreationDate = createdDate,
DescriptionHtml = text, DescriptionHtml = text,
Description = string.IsNullOrEmpty(text) ? string.Empty : Matrix42.Common.Html.HtmlConverter.ConvertHtmlToPlainText(text), Description = string.IsNullOrEmpty(text) ? string.Empty : Matrix42.Common.Html.HtmlConverter.ConvertHtmlToPlainText(text),
Header = header, Header = item.Header,
IsVisibleForUser = visibleInPortal IsVisibleForUser = item.VisibleInPortal
}); });
} }
return journalEntries; 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,
"<a href=\"#\" class=\"mx-object-journal--link {0} {1}\">{2}</a>",
120
}) as Array ?? Array.Empty<object>();
}
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<T>(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<bool> updateActivitySolution(Guid objectId, string solutionHtml) internal async Task<bool> updateActivitySolution(Guid objectId, string solutionHtml)
{ {

View File

@@ -10,7 +10,6 @@ using System.Threading.Tasks;
using Matrix42.Common; using Matrix42.Common;
using Matrix42.Contracts.Common.Security; using Matrix42.Contracts.Common.Security;
using Matrix42.Contracts.ServiceManagement.ServiceContracts;
using Matrix42.Hosting.Contracts; using Matrix42.Hosting.Contracts;
using Matrix42.Pandora.Contracts; using Matrix42.Pandora.Contracts;
using Matrix42.Persistence.Contracts; using Matrix42.Persistence.Contracts;
@@ -81,11 +80,6 @@ namespace C4IT.F4SD
catch { }; catch { };
} }
internal IJournalService GetJournalService()
{
return GetRequiredService<IJournalService>();
}
private T GetRequiredService<T>() where T : class private T GetRequiredService<T>() where T : class
{ {
var service = _resolver.TryGet<T>(); var service = _resolver.TryGet<T>();