From c6756e13aa9f057e12e3d702dd3ee447080085ad Mon Sep 17 00:00:00 2001 From: pitzm Date: Fri, 10 Jan 2025 10:50:35 +0100 Subject: [PATCH] ZUGFeRD Service/WebService: Lesen/Auswertung neue Config-Schalter. GDPicture-Lizenz-Abfrage --- GUIs.Test.ZUGFeRDTest/Form1.vb | 8 +++- GUIs.Test.ZUGFeRDTest/ZUGFeRDTest.vbproj | 4 ++ Services.ZUGFeRDService/Config.vb | 21 +++++++++- Services.ZUGFeRDService/ThreadRunner.vb | 5 ++- WEBSERVICES/ZUGFeRDRESTService/Config.cs | 11 +++++ .../Controllers/ValidationController.cs | 42 ++++++++++++++----- WEBSERVICES/ZUGFeRDRESTService/Database.cs | 28 +++++++------ WEBSERVICES/ZUGFeRDRESTService/Logger.cs | 3 -- WEBSERVICES/ZUGFeRDRESTService/Program.cs | 9 ---- WEBSERVICES/ZUGFeRDRESTService/Startup.cs | 8 +--- .../ZUGFeRDRESTService/appsettings.json | 6 ++- 11 files changed, 98 insertions(+), 47 deletions(-) diff --git a/GUIs.Test.ZUGFeRDTest/Form1.vb b/GUIs.Test.ZUGFeRDTest/Form1.vb index 3733e2e3..978ee04d 100644 --- a/GUIs.Test.ZUGFeRDTest/Form1.vb +++ b/GUIs.Test.ZUGFeRDTest/Form1.vb @@ -5,6 +5,7 @@ Imports DigitalData.Modules.Database Imports DigitalData.Modules.Interfaces Imports DigitalData.Modules.Jobs Imports DigitalData.Modules.Logging +Imports DigitalData.Modules.Config Public Class Form1 Private _logConfig As LogConfig @@ -12,6 +13,8 @@ Public Class Form1 Private _firebird As Firebird Private _mssql As MSSQLServer Private _zugferd As ZUGFeRDInterface + Private _GDPictureVersion As String + Private _GDPictureLizenz As String Private PropertyMap As New Dictionary(Of String, XmlItemProperty) @@ -23,7 +26,10 @@ Public Class Form1 _logger = _logConfig.GetLogger() _mssql = New MSSQLServer(_logConfig, My.Settings.MSSQL_CONNECTIONSTRING) - _zugferd = New ZUGFeRDInterface(_logConfig, "kG1Qf9PwmqgR8aDmIW2zI_ebj48RzqAJegRxcystEmkbTGQqfkNBdFOXIb6C_A00Ra8zZkrHdfjqzOPXK7kgkF2YDhvrqKfqh4WDug2vOt0qO31IommzkANSuLjZ4zmraoubyEVd25rE3veQ2h_j7tGIoH_LyIHmy24GaXsxdG0yCzIBMdiLbMMMDwcPY-809KeZ83Grv76OVhFvcbBWyYc251vou1N-kGg5_ZlHDgfWoY85gTLRxafjD3KS_i9ARW4BMiy36y8n7UP2jN8kGRnW_04ubpFtfjJqvtsrP_J9D0x7bqV8xtVtT5JI6dpKsVTiMgDCrIcoFSo5gCC1fw9oUopX4TDCkBQttO4-WHBlOeq9dG5Yb0otonVmJKaQA2tP6sMR-lZDs3ql_WI9t91yPWgpssrJUxSHDd27_LMTH_owJIqkF3NOJd9mYQuAv22oNKFYbH8e41pVKb8cT33Y9CgcQ_sy6YDA5PTuIRi67mjKge_nD9rd0IN213Ir9M_EFWqg9e4haWzIdHXQUo0md70kVhPX4UIH_BKJnxEEnFfoFRNMh77bB0N4jkcBEHPl-ghOERv8dOztf4vCnNpzzWvcLD2cqWIm6THy8XGGq9h4hp8aEreRleSMwv9QQAC7mjLwhQ1rBYkpUHlpTjhTLnMwHknl6HH0Z6zzmsgkRKVyfquv94Pd7QbQfZrRka0ss_48pf9p8hAywEn81Q==", New ZUGFeRDInterface.ZugferdOptions) + _GDPictureVersion = "11.2024" + _GDPictureLizenz = ConfigDbFunct.GetProductLicense("GDPICTURE", _GDPictureVersion, _logConfig, My.Settings.MSSQL_CONNECTIONSTRING) + + _zugferd = New ZUGFeRDInterface(_logConfig, _GDPictureLizenz, New ZUGFeRDInterface.ZugferdOptions) End Sub Private Function LoadPropertyMapFor(Args As WorkerArgs) diff --git a/GUIs.Test.ZUGFeRDTest/ZUGFeRDTest.vbproj b/GUIs.Test.ZUGFeRDTest/ZUGFeRDTest.vbproj index ce8ff9a7..81dd5825 100644 --- a/GUIs.Test.ZUGFeRDTest/ZUGFeRDTest.vbproj +++ b/GUIs.Test.ZUGFeRDTest/ZUGFeRDTest.vbproj @@ -48,6 +48,10 @@ On + + False + ..\..\DDModules\Config\bin\Debug\DigitalData.Modules.Config.dll + False ..\..\DDModules\Database\bin\Debug\DigitalData.Modules.Database.dll diff --git a/Services.ZUGFeRDService/Config.vb b/Services.ZUGFeRDService/Config.vb index ae3f1000..e2701325 100644 --- a/Services.ZUGFeRDService/Config.vb +++ b/Services.ZUGFeRDService/Config.vb @@ -2,23 +2,30 @@ Public Property Custom As New CustomConfig Public Property MSSQLConnectionString As String = "" + Public Property MSSQLEmailOutAccountID As String = 1 Public Property PORTAL_NAME As String = "WISAG-Portal" Public Property JobInterval As Integer = 10 + Public Property ExceptionEmailAddress As String = "wisag-flow@digitaldata.works" Public Property Debug As Boolean = False Public Property WatchDirectory As String = String.Empty + Public Property SuccessDirectory As String = String.Empty + Public Property ErrorDirectory As String = String.Empty + Public Property OriginalEmailDirectory As String = String.Empty + Public Property RejectedEmailDirectory As String = String.Empty + Public Property AttachmentsSubDirectory As String = String.Empty - Public Property NonZugferdDirectory As String = String.Empty + Public Property NonZugferdDirectory As String = String.Empty Public Class CustomConfig ''' @@ -49,9 +56,21 @@ ''' Public Property RejectionTemplateId As Integer = 0 + ''' + ''' Enthält die Version des GDPicture Modules, + ''' für das der Lizenzschlüssel aus TBDD_3RD_PARTY_MODULES + ''' gelesen werden soll. + ''' + Public Property GDPictureVersion As String = "" + Public Property AllowFacturX As Boolean = False + Public Property AllowXRechnung As Boolean = False + Public Property AllowZugferd10 As Boolean = True + Public Property AllowZugferd2x As Boolean = True + + Public Property AllowPeppolBISBill3x As Boolean = False End Class End Class diff --git a/Services.ZUGFeRDService/ThreadRunner.vb b/Services.ZUGFeRDService/ThreadRunner.vb index 721b1f7e..fa680865 100644 --- a/Services.ZUGFeRDService/ThreadRunner.vb +++ b/Services.ZUGFeRDService/ThreadRunner.vb @@ -52,7 +52,9 @@ Public Class ThreadRunner .AllowXRechnung = _config.Config.Custom.AllowXRechnung, .AllowZugferd10 = _config.Config.Custom.AllowZugferd10, .AllowZugferd2x = _config.Config.Custom.AllowZugferd2x, - .RejectionTemplateId = _config.Config.Custom.RejectionTemplateId + .AllowPeppolBISBill3x = _config.Config.Custom.AllowPeppolBISBill3x, + .RejectionTemplateId = _config.Config.Custom.RejectionTemplateId, + .GDPictureVersion = _config.Config.Custom.GDPictureVersion } oArgs = LoadFolderConfig(oArgs) @@ -64,6 +66,7 @@ Public Class ThreadRunner _logger.Debug("MaxAttachmentSizeInMegaBytes: [{0}]", oArgs.MaxAttachmentSizeInMegaBytes) _logger.Debug("MinFileAgeInMinutes: [{0}]", oArgs.MinFileAgeInMinutes) _logger.Debug("RejectionTemplateId: [{0}]", oArgs.RejectionTemplateId) + _logger.Debug("GDPictureVersion: [{0}]", oArgs.GDPictureVersion) _jobArguments = oArgs diff --git a/WEBSERVICES/ZUGFeRDRESTService/Config.cs b/WEBSERVICES/ZUGFeRDRESTService/Config.cs index a0d1b5e3..29c24e35 100644 --- a/WEBSERVICES/ZUGFeRDRESTService/Config.cs +++ b/WEBSERVICES/ZUGFeRDRESTService/Config.cs @@ -3,19 +3,30 @@ public class Config { public string Name { get; set; } + public string LogPath { get; set; } + public string MSSQLConnectionString { get; set; } + public string MaxFileSizeInMegabytes { get; set; } + + public string GDPictureVersion { get; set; } + public ZugferdConfig Zugferd { get; set; } } public class ZugferdConfig { public bool AllowFacturX { get; set; } = false; + public bool AllowXRechnung { get; set; } = false; + public bool AllowZugferd10 { get; set; } = true; + public bool AllowZugferd2x { get; set; } = true; + public bool AllowPeppolBISBill3x { get; set; } = false; + } } diff --git a/WEBSERVICES/ZUGFeRDRESTService/Controllers/ValidationController.cs b/WEBSERVICES/ZUGFeRDRESTService/Controllers/ValidationController.cs index fb9e90bc..86f9e6fd 100644 --- a/WEBSERVICES/ZUGFeRDRESTService/Controllers/ValidationController.cs +++ b/WEBSERVICES/ZUGFeRDRESTService/Controllers/ValidationController.cs @@ -40,6 +40,9 @@ namespace ZUGFeRDRESTService.Controllers private bool _AllowXRechnung; private bool _AllowZugferd2x; private bool _AllowZugferd10; + private bool _AllowPeppolBISBill3x; + + private string _GDPictureVersion; public ValidationController(ILogging logging, IDatabase database, IConfiguration Config) { @@ -49,21 +52,22 @@ namespace ZUGFeRDRESTService.Controllers _logger.Debug("Validation Controller initializing"); - _database = database; - var oGDPictureKey = database.GetGDPictureKey(); - var oPropertyMap = database.GetPropertyMap(); - // Read config file and assign all option flags related to // - Zugferd files // - Filesizes ParseConfig(Config); + _database = database; + var oGDPictureKey = database.GetGDPictureKey(); + var oPropertyMap = database.GetPropertyMap(); + _zugferd = new ZUGFeRDInterface(_logConfig, oGDPictureKey, new ZugferdOptions() { AllowFacturX_Filename = _AllowFacturX, AllowXRechnung_Filename = _AllowXRechnung, AllowZugferd_1_0_Schema = _AllowZugferd10, - AllowZugferd_2_x_Schema = _AllowZugferd2x + AllowZugferd_2_x_Schema = _AllowZugferd2x, + AllowPeppol_3017_Schema = _AllowPeppolBISBill3x }); _props = new PropertyValues(_logConfig); @@ -115,6 +119,19 @@ namespace ZUGFeRDRESTService.Controllers _AllowZugferd10 = true; } + if (!bool.TryParse(oZugferdConfig["AllowPeppolBISBill3x"], out _AllowPeppolBISBill3x)) + { + _logger.Info("Configuration AllowPeppolBISBill3x was not set. Using default value [{0}]", false); + _AllowPeppolBISBill3x = false; + } + + _GDPictureVersion = oAppConfig["GDPictureVersion"]; + if (string.IsNullOrEmpty(_GDPictureVersion)) + { + _logger.Info("Configuration GDPictureVersion was not set. Using default value [string.Empty]"); + _GDPictureVersion = string.Empty; + } + if (!int.TryParse(oAppConfig["MaxFileSizeInMegabytes"], out _MaxFileSizeInMegabytes)) { _logger.Info("Configuration MaxFileSizeInMegabytes was not set. Using default value [{0}]", MAX_FILE_SIZE_DEFAULT); @@ -238,12 +255,17 @@ namespace ZUGFeRDRESTService.Controllers }; // Determine if any errors should be sent in the response - List oErrors = ex.ErrorType switch + var oErrors = new List(); + switch (ex.ErrorType) { - // Errors contains the list of missing fields - ErrorType.MissingProperties => oPropertyResult.MissingProperties, - _ => new List() - }; + case ErrorType.MissingProperties: + oErrors.AddRange(from item in oPropertyResult.MissingProperties + select item.Description); + break; + default: + break; + } + _logger.Info($"Responding with message: [{oMessage}]"); return new ValidationResponse() diff --git a/WEBSERVICES/ZUGFeRDRESTService/Database.cs b/WEBSERVICES/ZUGFeRDRESTService/Database.cs index 2a9bc898..0cc2246c 100644 --- a/WEBSERVICES/ZUGFeRDRESTService/Database.cs +++ b/WEBSERVICES/ZUGFeRDRESTService/Database.cs @@ -1,14 +1,10 @@ -using System; -using System.Collections.Generic; -using System.Data; -using System.Data.SqlClient; -using System.Linq; -using System.Threading.Tasks; -using DigitalData.Modules.Database; +using DigitalData.Modules.Database; using DigitalData.Modules.Interfaces; -using Microsoft.AspNetCore.Mvc.Formatters; +using DigitalData.Modules.Config; using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.Options; +using System.Collections.Generic; +using System.Data; +using DigitalData.Modules.Logging; namespace ZUGFeRDRESTService { @@ -18,6 +14,11 @@ namespace ZUGFeRDRESTService private string _gdPictureKey = null; private Dictionary _propertyMap = null; + private LogConfig _logConfig = null; + private string _connString; + private string _GDPictureVersion; + + private const string QUERY_GET_GDPICTURE_KEY = "SELECT LICENSE FROM TBDD_3RD_PARTY_MODULES WHERE NAME = 'GDPICTURE'"; private const string QUERY_GET_PROPERTY_MAP = "SELECT * FROM TBDD_ZUGFERD_XML_ITEMS WHERE ACTIVE = 1 ORDER BY XML_PATH"; @@ -25,12 +26,14 @@ namespace ZUGFeRDRESTService public Database(ILogging Logging, IConfiguration Config) { - var oLogConfig = Logging.LogConfig; + _logConfig = Logging.LogConfig; var oLogger = Logging.LogConfig.GetLogger(); var oAppConfig = Config.GetSection("Config"); + _connString = oAppConfig["MSSQLConnectionString"]; + _GDPictureVersion = oAppConfig["GDPictureVersion"]; oLogger.Debug("Establishing MSSQL Database connection.."); - MSSQL = new MSSQLServer(oLogConfig, oAppConfig["MSSQLConnectionString"]); + MSSQL = new MSSQLServer(_logConfig, _connString); oLogger.Debug("MSSQL Connection: [{0}]", MSSQL.CurrentConnectionString); @@ -39,8 +42,7 @@ namespace ZUGFeRDRESTService public string GetGDPictureKey() { - if (_gdPictureKey == null) - _gdPictureKey = MSSQL.GetScalarValue(QUERY_GET_GDPICTURE_KEY).ToString(); + _gdPictureKey = ConfigDbFunct.GetProductLicense("GDPICTURE", _GDPictureVersion, _logConfig, _connString); return _gdPictureKey; } diff --git a/WEBSERVICES/ZUGFeRDRESTService/Logger.cs b/WEBSERVICES/ZUGFeRDRESTService/Logger.cs index 0f42a78f..f6b02358 100644 --- a/WEBSERVICES/ZUGFeRDRESTService/Logger.cs +++ b/WEBSERVICES/ZUGFeRDRESTService/Logger.cs @@ -1,7 +1,4 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; namespace ZUGFeRDRESTService { diff --git a/WEBSERVICES/ZUGFeRDRESTService/Program.cs b/WEBSERVICES/ZUGFeRDRESTService/Program.cs index 007ffa36..6866dcb4 100644 --- a/WEBSERVICES/ZUGFeRDRESTService/Program.cs +++ b/WEBSERVICES/ZUGFeRDRESTService/Program.cs @@ -1,14 +1,5 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; using Microsoft.AspNetCore.Hosting; -using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Hosting; -using Microsoft.Extensions.Logging; -using NLog.Web; -using DigitalData.Modules.Logging; -using System.Reflection; namespace ZUGFeRDRESTService { diff --git a/WEBSERVICES/ZUGFeRDRESTService/Startup.cs b/WEBSERVICES/ZUGFeRDRESTService/Startup.cs index 0a880841..0a426995 100644 --- a/WEBSERVICES/ZUGFeRDRESTService/Startup.cs +++ b/WEBSERVICES/ZUGFeRDRESTService/Startup.cs @@ -1,15 +1,9 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; -using Microsoft.AspNetCore.HttpsPolicy; -using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; -using Microsoft.Extensions.Logging; +using System; namespace ZUGFeRDRESTService { diff --git a/WEBSERVICES/ZUGFeRDRESTService/appsettings.json b/WEBSERVICES/ZUGFeRDRESTService/appsettings.json index bff970a1..ba548124 100644 --- a/WEBSERVICES/ZUGFeRDRESTService/appsettings.json +++ b/WEBSERVICES/ZUGFeRDRESTService/appsettings.json @@ -22,8 +22,10 @@ "AllowZugferd10": true, "AllowZugferd2x": false, "AllowFacturX": false, - "AllowXRechnung": false + "AllowXRechnung": false, + "AllowPeppolBISBill3x": false }, - "MaxFileSizeInMegabytes": 25 + "GDPictureVersion": "", + "MaxFileSizeInMegabytes": 25 } }