diff --git a/AICore/Context/Entry/Detail/CustomerDetailContextEntry.cs b/AICore/Context/Entry/Detail/CustomerDetailContextEntry.cs index c5874551c..8d5008b55 100644 --- a/AICore/Context/Entry/Detail/CustomerDetailContextEntry.cs +++ b/AICore/Context/Entry/Detail/CustomerDetailContextEntry.cs @@ -4,7 +4,7 @@ using System.Text.Json.Serialization; namespace AICore.Context.Entry { - internal class CustomerDetailContextEntry : DetailContextEntry + internal class CustomerDetailContextEntry : DetailContextEntry { [JsonPropertyName("Klient-ID")] public long CustomerOid { get; set; } diff --git a/AICore/Context/Entry/Detail/DetailContextEntry.cs b/AICore/Context/Entry/Detail/DetailContextEntry.cs index 7a33f1b93..099b68a38 100644 --- a/AICore/Context/Entry/Detail/DetailContextEntry.cs +++ b/AICore/Context/Entry/Detail/DetailContextEntry.cs @@ -1,6 +1,8 @@ -namespace AICore.Context.Entry +using BS.Shared.DataContracts; + +namespace AICore.Context.Entry { - internal abstract class DetailContextEntry : BaseContextEntry + internal abstract class DetailContextEntry : BaseContextEntry { } diff --git a/AICore/Context/Entry/Detail/EmployeeDetailContextEntry.cs b/AICore/Context/Entry/Detail/EmployeeDetailContextEntry.cs index 85d7abb10..517fa1fda 100644 --- a/AICore/Context/Entry/Detail/EmployeeDetailContextEntry.cs +++ b/AICore/Context/Entry/Detail/EmployeeDetailContextEntry.cs @@ -2,7 +2,7 @@ namespace AICore.Context.Entry { - internal class EmployeeDetailContextEntry : DetailContextEntry + internal class EmployeeDetailContextEntry : DetailContextEntry { } diff --git a/AICore/Context/Entry/Detail/OrganisationDetailContextEntry.cs b/AICore/Context/Entry/Detail/OrganisationDetailContextEntry.cs index 3301fc358..0afda6a67 100644 --- a/AICore/Context/Entry/Detail/OrganisationDetailContextEntry.cs +++ b/AICore/Context/Entry/Detail/OrganisationDetailContextEntry.cs @@ -2,7 +2,7 @@ namespace AICore.Context.Entry { - internal class OrganisationDetailContextEntry : DetailContextEntry + internal class OrganisationDetailContextEntry : DetailContextEntry { } diff --git a/AICore/Context/Entry/Detail/PersonDetailContextEntry.cs b/AICore/Context/Entry/Detail/PersonDetailContextEntry.cs index a15334b01..2df01ad50 100644 --- a/AICore/Context/Entry/Detail/PersonDetailContextEntry.cs +++ b/AICore/Context/Entry/Detail/PersonDetailContextEntry.cs @@ -2,7 +2,7 @@ namespace AICore.Context.Entry { - internal class PersonDetailContextEntry : DetailContextEntry + internal class PersonDetailContextEntry : DetailContextEntry { } diff --git a/AICore/Context/Entry/Detail/SupportConceptDetailContextEntry.cs b/AICore/Context/Entry/Detail/SupportConceptDetailContextEntry.cs index 3a67e918d..ae51e6870 100644 --- a/AICore/Context/Entry/Detail/SupportConceptDetailContextEntry.cs +++ b/AICore/Context/Entry/Detail/SupportConceptDetailContextEntry.cs @@ -2,7 +2,7 @@ namespace AICore.Context.Entry { - internal class SupportConceptDetailContextEntry : DetailContextEntry + internal class SupportConceptDetailContextEntry : DetailContextEntry { } diff --git a/AICore/Context/Entry/Navigation/CustomerNavigationContextEntry.cs b/AICore/Context/Entry/Navigation/CustomerNavigationContextEntry.cs index 43153cf13..96c7da150 100644 --- a/AICore/Context/Entry/Navigation/CustomerNavigationContextEntry.cs +++ b/AICore/Context/Entry/Navigation/CustomerNavigationContextEntry.cs @@ -5,7 +5,7 @@ using System.Text.Json.Serialization; namespace AICore.Context.Entry.Navigation { - internal class CustomerNavigationContextEntry : NavigationContextEntry + internal class CustomerNavigationContextEntry : NavigationContextEntry { [JsonPropertyName("Adresse")] public string AddressString { get; set; } diff --git a/AICore/Context/Entry/Navigation/EmployeeNavigationContextEntry.cs b/AICore/Context/Entry/Navigation/EmployeeNavigationContextEntry.cs index 5c0159422..073e3d223 100644 --- a/AICore/Context/Entry/Navigation/EmployeeNavigationContextEntry.cs +++ b/AICore/Context/Entry/Navigation/EmployeeNavigationContextEntry.cs @@ -3,7 +3,7 @@ using System.Text.Json.Serialization; namespace AICore.Context.Entry.Navigation { - internal class EmployeeNavigationContextEntry : NavigationContextEntry + internal class EmployeeNavigationContextEntry : NavigationContextEntry { [JsonPropertyName("Mitarbeiter-ID")] public long EmployeeOid { get; set; } diff --git a/AICore/Context/Entry/Navigation/NavigationContextEntry.cs b/AICore/Context/Entry/Navigation/NavigationContextEntry.cs index 8c43e2150..0ed3b1981 100644 --- a/AICore/Context/Entry/Navigation/NavigationContextEntry.cs +++ b/AICore/Context/Entry/Navigation/NavigationContextEntry.cs @@ -1,6 +1,8 @@ -namespace AICore.Context.Entry.Navigation +using BS.Shared.DataContracts; + +namespace AICore.Context.Entry.Navigation { - internal abstract class NavigationContextEntry : BaseContextEntry + internal abstract class NavigationContextEntry : BaseContextEntry { } diff --git a/AICore/Context/Entry/Navigation/OrganisationNavigationContextEntry.cs b/AICore/Context/Entry/Navigation/OrganisationNavigationContextEntry.cs index 2fb4d2a94..b8acc39b9 100644 --- a/AICore/Context/Entry/Navigation/OrganisationNavigationContextEntry.cs +++ b/AICore/Context/Entry/Navigation/OrganisationNavigationContextEntry.cs @@ -3,7 +3,7 @@ using System.Text.Json.Serialization; namespace AICore.Context.Entry.Navigation { - internal class OrganisationNavigationContextEntry : NavigationContextEntry + internal class OrganisationNavigationContextEntry : NavigationContextEntry { [JsonPropertyName("Organisation-ID")] public long OrganisationOid { get; set; } diff --git a/AICore/Context/Entry/Navigation/PersonNavigationContextEntry.cs b/AICore/Context/Entry/Navigation/PersonNavigationContextEntry.cs index d678f6220..553bb3c0b 100644 --- a/AICore/Context/Entry/Navigation/PersonNavigationContextEntry.cs +++ b/AICore/Context/Entry/Navigation/PersonNavigationContextEntry.cs @@ -4,7 +4,7 @@ using System.Text.Json.Serialization; namespace AICore.Context.Entry.Navigation { - internal class PersonNavigationContextEntry : NavigationContextEntry + internal class PersonNavigationContextEntry : NavigationContextEntry { [JsonPropertyName("Adresse")] public string AddressString { get; set; } diff --git a/AICore/Context/Entry/Navigation/ServiceRecordContextEntry.cs b/AICore/Context/Entry/Navigation/ServiceRecordContextEntry.cs index f6c233f2e..2e98e845b 100644 --- a/AICore/Context/Entry/Navigation/ServiceRecordContextEntry.cs +++ b/AICore/Context/Entry/Navigation/ServiceRecordContextEntry.cs @@ -4,7 +4,7 @@ using System.Text.Json.Serialization; namespace AICore.Context.Entry.Navigation { - internal class ServiceRecordContextEntry : NavigationContextEntry + internal class ServiceRecordContextEntry : NavigationContextEntry { [JsonPropertyName("Zeiteintrag-ID")] public long ServiceRecordOid { get; set; } diff --git a/AICore/Context/Entry/Navigation/SupportConceptNavigationContextEntry.cs b/AICore/Context/Entry/Navigation/SupportConceptNavigationContextEntry.cs index ab51b346a..80162e5db 100644 --- a/AICore/Context/Entry/Navigation/SupportConceptNavigationContextEntry.cs +++ b/AICore/Context/Entry/Navigation/SupportConceptNavigationContextEntry.cs @@ -5,7 +5,7 @@ using System.Text.Json.Serialization; namespace AICore.Context.Entry.Navigation { - internal class SupportConceptNavigationContextEntry : NavigationContextEntry + internal class SupportConceptNavigationContextEntry : NavigationContextEntry { [JsonPropertyName("Hilfeplan-ID")] public long SupportConceptOid { get; set; } diff --git a/AICore/Context/Summary/CustomerDetailContextSummary.cs b/AICore/Context/Summary/Detail/CustomerDetailContextSummary.cs similarity index 75% rename from AICore/Context/Summary/CustomerDetailContextSummary.cs rename to AICore/Context/Summary/Detail/CustomerDetailContextSummary.cs index fe0c70d98..11addbdd5 100644 --- a/AICore/Context/Summary/CustomerDetailContextSummary.cs +++ b/AICore/Context/Summary/Detail/CustomerDetailContextSummary.cs @@ -1,9 +1,9 @@ using AICore.Context.Entry; using BS.Shared.DataContracts; -namespace AICore.Context.Summary +namespace AICore.Context.Summary.Detail { - internal class CustomerDetailContextSummary : DetailContextSummary + internal class CustomerDetailContextSummary : DetailContextSummary { internal CustomerDetailContextSummary(CustomerDetailContextEntry customer) : base(customer) { } } diff --git a/AICore/Context/Summary/DetailContextSummary.cs b/AICore/Context/Summary/Detail/DetailContextSummary.cs similarity index 53% rename from AICore/Context/Summary/DetailContextSummary.cs rename to AICore/Context/Summary/Detail/DetailContextSummary.cs index 4a5884bab..2ec4caad7 100644 --- a/AICore/Context/Summary/DetailContextSummary.cs +++ b/AICore/Context/Summary/Detail/DetailContextSummary.cs @@ -1,8 +1,9 @@ using AICore.Context.Entry; +using BS.Shared.DataContracts; -namespace AICore.Context.Summary +namespace AICore.Context.Summary.Detail { - internal abstract class DetailContextSummary : BaseContextSummary where TEntry : DetailContextEntry + internal abstract class DetailContextSummary : BaseContextSummary where TEntry : DetailContextEntry { internal TEntry DataContext { get; set; } diff --git a/AICore/Context/Summary/EmployeeDetailContextSummary.cs b/AICore/Context/Summary/Detail/EmployeeDetailContextSummary.cs similarity index 75% rename from AICore/Context/Summary/EmployeeDetailContextSummary.cs rename to AICore/Context/Summary/Detail/EmployeeDetailContextSummary.cs index 1642807f7..09674a866 100644 --- a/AICore/Context/Summary/EmployeeDetailContextSummary.cs +++ b/AICore/Context/Summary/Detail/EmployeeDetailContextSummary.cs @@ -1,9 +1,9 @@ using AICore.Context.Entry; using BS.Shared.DataContracts; -namespace AICore.Context.Summary +namespace AICore.Context.Summary.Detail { - internal class EmployeeDetailContextSummary : DetailContextSummary + internal class EmployeeDetailContextSummary : DetailContextSummary { internal EmployeeDetailContextSummary(EmployeeDetailContextEntry employee) : base(employee) { } } diff --git a/AICore/Context/Summary/OrganisationDetailContextSummary.cs b/AICore/Context/Summary/Detail/OrganisationDetailContextSummary.cs similarity index 73% rename from AICore/Context/Summary/OrganisationDetailContextSummary.cs rename to AICore/Context/Summary/Detail/OrganisationDetailContextSummary.cs index f58fe3009..6144af444 100644 --- a/AICore/Context/Summary/OrganisationDetailContextSummary.cs +++ b/AICore/Context/Summary/Detail/OrganisationDetailContextSummary.cs @@ -1,9 +1,9 @@ using AICore.Context.Entry; using BS.Shared.DataContracts; -namespace AICore.Context.Summary +namespace AICore.Context.Summary.Detail { - internal class OrganisationDetailContextSummary : DetailContextSummary + internal class OrganisationDetailContextSummary : DetailContextSummary { internal OrganisationDetailContextSummary(OrganisationDetailContextEntry organisation) : base(organisation) { } } diff --git a/AICore/Context/Summary/PersonDetailContextSummary.cs b/AICore/Context/Summary/Detail/PersonDetailContextSummary.cs similarity index 76% rename from AICore/Context/Summary/PersonDetailContextSummary.cs rename to AICore/Context/Summary/Detail/PersonDetailContextSummary.cs index 87c06400d..ad844f1f0 100644 --- a/AICore/Context/Summary/PersonDetailContextSummary.cs +++ b/AICore/Context/Summary/Detail/PersonDetailContextSummary.cs @@ -1,9 +1,9 @@ using AICore.Context.Entry; using BS.Shared.DataContracts; -namespace AICore.Context.Summary +namespace AICore.Context.Summary.Detail { - internal class PersonDetailContextSummary : DetailContextSummary + internal class PersonDetailContextSummary : DetailContextSummary { internal PersonDetailContextSummary(PersonDetailContextEntry person) : base(person) { } } diff --git a/AICore/Context/Summary/SupportConceptDetailContextSummary.cs b/AICore/Context/Summary/Detail/SupportConceptDetailContextSummary.cs similarity index 73% rename from AICore/Context/Summary/SupportConceptDetailContextSummary.cs rename to AICore/Context/Summary/Detail/SupportConceptDetailContextSummary.cs index 607d45e09..0e3efef5f 100644 --- a/AICore/Context/Summary/SupportConceptDetailContextSummary.cs +++ b/AICore/Context/Summary/Detail/SupportConceptDetailContextSummary.cs @@ -1,9 +1,9 @@ using AICore.Context.Entry; using BS.Shared.DataContracts; -namespace AICore.Context.Summary +namespace AICore.Context.Summary.Detail { - internal class SupportConceptDetailContextSummary : DetailContextSummary + internal class SupportConceptDetailContextSummary : DetailContextSummary { internal SupportConceptDetailContextSummary(SupportConceptDetailContextEntry supportConcept) : base(supportConcept) { } } diff --git a/AICore/Context/Summary/CustomerNavigationContextSummary.cs b/AICore/Context/Summary/Navigation/CustomerNavigationContextSummary.cs similarity index 76% rename from AICore/Context/Summary/CustomerNavigationContextSummary.cs rename to AICore/Context/Summary/Navigation/CustomerNavigationContextSummary.cs index 8c1a13bfd..743d79518 100644 --- a/AICore/Context/Summary/CustomerNavigationContextSummary.cs +++ b/AICore/Context/Summary/Navigation/CustomerNavigationContextSummary.cs @@ -2,9 +2,9 @@ using AICore.Context.Entry.Navigation; using BS.Shared.DataContracts.Compact; -namespace AICore.Context.Summary +namespace AICore.Context.Summary.Navigation { - internal class CustomerNavigationContextSummary : NavigationContextSummary + internal class CustomerNavigationContextSummary : NavigationContextSummary { internal CustomerNavigationContextSummary(IEnumerable customers) : base(customers) { } } diff --git a/AICore/Context/Summary/EmployeeNavigationContextSummary.cs b/AICore/Context/Summary/Navigation/EmployeeNavigationContextSummary.cs similarity index 76% rename from AICore/Context/Summary/EmployeeNavigationContextSummary.cs rename to AICore/Context/Summary/Navigation/EmployeeNavigationContextSummary.cs index fe29a9655..74e8ad4ff 100644 --- a/AICore/Context/Summary/EmployeeNavigationContextSummary.cs +++ b/AICore/Context/Summary/Navigation/EmployeeNavigationContextSummary.cs @@ -2,9 +2,9 @@ using AICore.Context.Entry.Navigation; using BS.Shared.DataContracts.Compact; -namespace AICore.Context.Summary +namespace AICore.Context.Summary.Navigation { - internal class EmployeeNavigationContextSummary : NavigationContextSummary + internal class EmployeeNavigationContextSummary : NavigationContextSummary { internal EmployeeNavigationContextSummary(IEnumerable employee) : base(employee) { } } diff --git a/AICore/Context/Summary/Navigation/NavigationContextSummary.cs b/AICore/Context/Summary/Navigation/NavigationContextSummary.cs new file mode 100644 index 000000000..362fc28f2 --- /dev/null +++ b/AICore/Context/Summary/Navigation/NavigationContextSummary.cs @@ -0,0 +1,17 @@ +using System.Collections.Generic; +using AICore.Context.Entry.Navigation; +using BS.Shared.DataContracts; + +namespace AICore.Context.Summary.Navigation +{ + internal abstract class NavigationContextSummary : BaseContextSummary where TEntry : NavigationContextEntry + { + internal IEnumerable DataContext { get; set; } + + protected NavigationContextSummary(IEnumerable dataContext) + { + DataContext = dataContext; + Context = dataContext; + } + } +} diff --git a/AICore/Context/Summary/OrganisationNavigationContextSummary.cs b/AICore/Context/Summary/Navigation/OrganisationNavigationContextSummary.cs similarity index 75% rename from AICore/Context/Summary/OrganisationNavigationContextSummary.cs rename to AICore/Context/Summary/Navigation/OrganisationNavigationContextSummary.cs index f990f804e..3011be8df 100644 --- a/AICore/Context/Summary/OrganisationNavigationContextSummary.cs +++ b/AICore/Context/Summary/Navigation/OrganisationNavigationContextSummary.cs @@ -2,9 +2,9 @@ using AICore.Context.Entry.Navigation; using BS.Shared.DataContracts.Compact; -namespace AICore.Context.Summary +namespace AICore.Context.Summary.Navigation { - internal class OrganisationNavigationContextSummary : NavigationContextSummary + internal class OrganisationNavigationContextSummary : NavigationContextSummary { internal OrganisationNavigationContextSummary(IEnumerable organisation) : base(organisation) { } } diff --git a/AICore/Context/Summary/PersonNavigationContextSummary.cs b/AICore/Context/Summary/Navigation/PersonNavigationContextSummary.cs similarity index 76% rename from AICore/Context/Summary/PersonNavigationContextSummary.cs rename to AICore/Context/Summary/Navigation/PersonNavigationContextSummary.cs index 654604d5d..674066151 100644 --- a/AICore/Context/Summary/PersonNavigationContextSummary.cs +++ b/AICore/Context/Summary/Navigation/PersonNavigationContextSummary.cs @@ -2,9 +2,9 @@ using AICore.Context.Entry.Navigation; using BS.Shared.DataContracts.Compact; -namespace AICore.Context.Summary +namespace AICore.Context.Summary.Navigation { - internal class PersonNavigationContextSummary : NavigationContextSummary + internal class PersonNavigationContextSummary : NavigationContextSummary { internal PersonNavigationContextSummary(IEnumerable person) : base(person) { } } diff --git a/AICore/Context/Summary/ServiceRecordNavigationContextSummary.cs b/AICore/Context/Summary/Navigation/ServiceRecordNavigationContextSummary.cs similarity index 87% rename from AICore/Context/Summary/ServiceRecordNavigationContextSummary.cs rename to AICore/Context/Summary/Navigation/ServiceRecordNavigationContextSummary.cs index 22404f841..589d33b79 100644 --- a/AICore/Context/Summary/ServiceRecordNavigationContextSummary.cs +++ b/AICore/Context/Summary/Navigation/ServiceRecordNavigationContextSummary.cs @@ -2,9 +2,9 @@ using BS.Shared.DataContracts; using System.Collections.Generic; -namespace AICore.Context.Summary +namespace AICore.Context.Summary.Navigation { - internal class ServiceRecordNavigationContextSummary : NavigationContextSummary + internal class ServiceRecordNavigationContextSummary : NavigationContextSummary { internal CustomerNavigationContextEntry Customer { get; set; } internal string CostBearer { get; set; } diff --git a/AICore/Context/Summary/SupportConceptNavigationContextSummary.cs b/AICore/Context/Summary/Navigation/SupportConceptNavigationContextSummary.cs similarity index 74% rename from AICore/Context/Summary/SupportConceptNavigationContextSummary.cs rename to AICore/Context/Summary/Navigation/SupportConceptNavigationContextSummary.cs index 534439184..29182c01f 100644 --- a/AICore/Context/Summary/SupportConceptNavigationContextSummary.cs +++ b/AICore/Context/Summary/Navigation/SupportConceptNavigationContextSummary.cs @@ -2,9 +2,9 @@ using AICore.Context.Entry.Navigation; using BS.Shared.DataContracts.Compact; -namespace AICore.Context.Summary +namespace AICore.Context.Summary.Navigation { - internal class SupportConceptNavigationContextSummary : NavigationContextSummary + internal class SupportConceptNavigationContextSummary : NavigationContextSummary { internal SupportConceptNavigationContextSummary(IEnumerable supportConcept) : base(supportConcept) { } } diff --git a/AICore/Context/SummaryParser/CsvContextSummaryParser.cs b/AICore/Context/SummaryParser/CsvContextSummaryParser.cs index 2acd48667..e9a787ffe 100644 --- a/AICore/Context/SummaryParser/CsvContextSummaryParser.cs +++ b/AICore/Context/SummaryParser/CsvContextSummaryParser.cs @@ -1,5 +1,6 @@ using AICore.Context.Entry; using AICore.Context.Summary; +using AICore.Context.Summary.Navigation; using BS.Shared; using BS.Shared.Exceptions; using System; diff --git a/AICore/Prompt/Core/AiPromptBuilder.cs b/AICore/Prompt/Core/AiPromptBuilder.cs new file mode 100644 index 000000000..ce51120b0 --- /dev/null +++ b/AICore/Prompt/Core/AiPromptBuilder.cs @@ -0,0 +1,98 @@ +using AICore.Context.Entry; +using AICore.Context.Entry.Navigation; +using AICore.Context.Summary; +using AICore.Context.SummaryMapper; +using AICore.Context.SummaryParser; +using BeWo.ServiceUtils.Core; +using BS.Shared; +using BS.Shared.Core; +using BS.Shared.DataContracts; +using BS.Shared.DataContracts.Compact; +using BS.Shared.Exceptions; +using BS.Shared.Translation; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Reflection; +using System.Text; +using System.Text.Json; + +namespace AICore.Prompt.Core +{ + public class AiPromptBuilder + { + public string CreateSystemInstructions(AiContextType uicontext, BaseContextSummary context, AiDataContextType aiDataContextType) + { + var sb = new StringBuilder(); + + sb.AppendLine(getCustomSystemPrompt()); + + sb.AppendLine("### **Allgemein**"); + sb.AppendLine($"- Aktuelle Zeit: {DateTime.Now}"); + sb.AppendLine(); + sb.AppendLine("### **Ansicht**"); + sb.AppendLine($"- Ich befinde mich aktuell in der \"{EnumTranslations.Ai2Translation[uicontext]}\" meiner Anwendung."); + sb.AppendLine($"- Es ist kein Filter gesetzt."); + sb.AppendLine(); + sb.AppendLine("### **Daten**"); + + if (context?.Context is null) + { + sb.AppendLine("Dir wurden keine Daten bereitgestellt."); + } + else + { + sb.AppendLine("Du erhälst folgende Daten:"); + + var parser = GetParser(aiDataContextType); + var parsed = parser.Parse(uicontext, context); + + sb.AppendLine(parsed); + } + + return sb.ToString(); + } + + private BaseContextSummaryParser GetParser(AiDataContextType aiDataContextType) + { + switch (aiDataContextType) + { + case AiDataContextType.json: + return new JsonContextSummaryParser(); + case AiDataContextType.csv: + return new CsvContextSummaryParser(); + case AiDataContextType.tsv: + return new CsvContextSummaryParser("\t"); + case AiDataContextType.csv2: + return new CsvContextSummaryParser(";", true); + case AiDataContextType.tsv2: + return new CsvContextSummaryParser("\t", true); + default: + break; + } + + throw BeWoNotImplementedException.CreateFromEnum(aiDataContextType); + } + + private string getSystemPrompt(int i) + { + var assembly = Assembly.GetExecutingAssembly(); + var resourceName = $"AICore.Prompt.SystemPrompts.system_prompt{i}.txt"; + + using (Stream stream = assembly.GetManifestResourceStream(resourceName)) + using (StreamReader reader = new StreamReader(stream)) + { + string result = reader.ReadToEnd(); + return result; + } + } + + private string getCustomSystemPrompt() + { + var path = MergedConfig.GetSetting("AiSystemPromptPath"); + + return File.ReadAllText(path); + } + } +} diff --git a/Service/Service.csproj b/Service/Service.csproj index edbf10bef..fa6bfb4bf 100644 --- a/Service/Service.csproj +++ b/Service/Service.csproj @@ -562,6 +562,7 @@ + diff --git a/Service/ServiceUtils/AiContextLoader.cs b/Service/ServiceUtils/AiContextLoader.cs new file mode 100644 index 000000000..99292497a --- /dev/null +++ b/Service/ServiceUtils/AiContextLoader.cs @@ -0,0 +1,153 @@ +using AICore.Context.Summary; +using AICore.Context.SummaryMapper; +using BeWo.Data.Access; +using BeWo.Data.Entities; +using BeWo.Service.DCEntityMapper; +using BeWo.Service.ServiceImplementations; +using BS.Shared.DataContracts.Compact; +using BS.Shared.DataContracts; +using BS.Shared; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BeWo.Service.ServiceUtils +{ + public static class AiContextLoader + { + public static BaseContextSummary LoadContext(AiContextType uicontext, Dictionary context_reference) + { + switch (uicontext) + { + case AiContextType.SupportConceptNavigation: + case AiContextType.CustomerNavigation: + case AiContextType.PersonNavigation: + case AiContextType.EmployeeNavigation: + case AiContextType.OrganisationNavigation: + return loadNavigationContext(uicontext, context_reference); + case AiContextType.CustomerDetail: + case AiContextType.PersonDetail: + case AiContextType.EmployeeDetail: + case AiContextType.OrganisationDetail: + case AiContextType.SupportConceptDetail: + return loadDetailContext(uicontext, context_reference); + case AiContextType.ServiceRecord: + return loadServiceRecordContext(context_reference); + default: + break; + } + + throw new NotImplementedException(); + } + + private static BaseContextSummary loadNavigationContext(AiContextType uicontext, Dictionary context_reference) + { + switch (uicontext) + { + case AiContextType.SupportConceptNavigation: + var list = new CustomerServiceImp().GetAllAuthorizedCompactSupportConcepts(); + var filter = list.Where(x => oidsContainsOid(context_reference[TableID.SupportConcept], x.SupportConceptOid)); + return AiContextSummaryFactory.CreateSupportConceptNavigationContextSummary(filter); + case AiContextType.CustomerNavigation: + var list2 = new CustomerServiceImp().GetAllAuthorizedCompactCustomers(); + var filter2 = list2.Where(x => oidsContainsOid(context_reference[TableID.Customer], x.CustomerOid)); + return AiContextSummaryFactory.CreateCustomerNavigationContextSummary(filter2); + case AiContextType.PersonNavigation: + var list3 = new CustomerServiceImp().GetAllAuthorizedCompactPersons(); + var filter3 = list3.Where(x => oidsContainsOid(context_reference[TableID.Person], x.PersonOid)); + return AiContextSummaryFactory.CreatePersonNavigationContextSummary(filter3); + case AiContextType.EmployeeNavigation: + var list4 = new EmployeeServiceImp().GetAllCompactEmployees(); + var filter4 = list4.Where(x => oidsContainsOid(context_reference[TableID.Employee], x.EmployeeOid)); + return AiContextSummaryFactory.CreateEmployeeNavigationContextSummary(filter4); + case AiContextType.OrganisationNavigation: + var list5 = new CustomerServiceImp().GetAllOrganisationsCompact(); + var filter5 = list5.Where(x => oidsContainsOid(context_reference[TableID.Organisation], x.OrganisationOid)); + return AiContextSummaryFactory.CreateOrganisationNavigationContextSummary(filter5); + } + + throw new NotImplementedException(); + } + + private static BaseContextSummary loadDetailContext(AiContextType uicontext, Dictionary context_reference) + { + switch (uicontext) + { + case AiContextType.CustomerDetail: + var oids = context_reference[TableID.Customer]; + var dc = new CustomerServiceImp().LoadCustomer(oids[0]); + return AiContextSummaryFactory.CreateCustomerDetailContextSummary(dc); + case AiContextType.PersonDetail: + var oids2 = context_reference[TableID.Person]; + var dc2 = new CustomerServiceImp().LoadPerson(oids2[0]); + return AiContextSummaryFactory.CreatePersonDetailContextSummary(dc2); + case AiContextType.EmployeeDetail: + var oids3 = context_reference[TableID.Employee]; + var dc3 = new EmployeeServiceImp().LoadEmployee(oids3[0]); + return AiContextSummaryFactory.CreateEmployeeDetailContextSummary(dc3); + case AiContextType.OrganisationDetail: + var oids4 = context_reference[TableID.Organisation]; + var dc4 = new CustomerServiceImp().LoadOrganisation(oids4[0]); + return AiContextSummaryFactory.CreateOrganisationDetailContextSummary(dc4); + case AiContextType.SupportConceptDetail: + var oids5 = context_reference[TableID.SupportConcept]; + var dc5 = new CustomerServiceImp().LoadSupportConcept(oids5[0]); + return AiContextSummaryFactory.CreateSupportConceptDetailContextSummary(dc5); + } + + throw new NotImplementedException(); + } + + private static BaseContextSummary loadServiceRecordContext(Dictionary context_reference) + { + var customer = loadCompactCustomerDC(context_reference); + var serviceRecords = loadServiceRecordDCs(context_reference); + var supportConcept = loadSupportConceptDC(context_reference); + + return AiContextSummaryFactory.CreateServiceRecordNavigationContextSummary(serviceRecords, customer, supportConcept); + } + + private static bool oidsContainsOid(long[] oids, long oid) + { + if (oids == null || oids.Length == 0) + return false; + + return oids.Contains(oid); + } + + private static CompactCustomerDC loadCompactCustomerDC(Dictionary context_reference) + => LoadDataContact(MapperFactory.CompactCustomerDC_Customer, context_reference); + private static CompactSupportConceptDC loadSupportConceptDC(Dictionary context_reference) + => LoadDataContact(MapperFactory.CompactSupportConceptDC_SupportConcept, context_reference); + private static IEnumerable loadServiceRecordDCs(Dictionary context_reference) + => LoadDataContacts(MapperFactory.ServiceRecordDC_ServiceRecord, context_reference); + + private static TDC LoadDataContact(TMapper mapper, Dictionary context_reference) + where TMapper : AbstractIDCEntityMapper + where TEntity : BeWoEntityBase, new() + where TDC : class, new() + { + var example = new TEntity(); + var tid = example.Tid; + var oid = context_reference[tid][0]; + var entity = DAOFactory.GenericDAO.LoadByID(oid); + var dc = mapper.MapToNewDC(entity); + return dc; + } + + private static IEnumerable LoadDataContacts(TMapper mapper, Dictionary context_reference) + where TMapper : AbstractIDCEntityMapper + where TEntity : BeWoEntityBase, new() + where TDC : class, new() + { + var example = new TEntity(); + var tid = example.Tid; + var oids = context_reference[tid]; + var entities = DAOFactory.GenericDAO.LoadByIDs(oids); + var dcs = mapper.MapToNewDCs(entities); + return dcs; + } + } +}