9 Commits

Author SHA1 Message Date
Jonathan Jenne
d8bc87fd24 ZUGFeRDService: Version 2.3.2.0 2023-02-28 14:59:22 +01:00
Jonathan Jenne
ca63a8c47d Fix property map logging 2023-02-28 14:57:25 +01:00
Jonathan Jenne
f6fc6fe7dc ZUGFeRDRESTService: Add specification, add logging 2023-02-28 14:34:46 +01:00
Jonathan Jenne
81eac3043a Improve logging 2023-02-28 14:13:17 +01:00
Jonathan Jenne
22c7fe8fe2 ZUGFeRDRESTService: Use FilterPropertyMap function, fix no type found error 2023-02-28 13:51:40 +01:00
Jonathan Jenne
2f11b7082b ZUGFeRDWebService: Fix config 2023-02-28 13:21:55 +01:00
Jonathan Jenne
1c428b7db6 ZUGFeRDRESTService: Prepare Zugferd 2x 2023-02-28 12:56:43 +01:00
Jonathan Jenne
bd03e5b925 ZUGFeRDTest: fix error when file is zugferd10 2023-02-28 12:55:53 +01:00
Jonathan Jenne
435de76f95 ZUGFeRDService: Version 2.3.1 2023-02-28 11:49:56 +01:00
6 changed files with 140 additions and 36 deletions

View File

@@ -131,8 +131,14 @@ Public Class Form1
Dim oResult = _zugferd.SerializeZUGFeRDDocument(oDoc) Dim oResult = _zugferd.SerializeZUGFeRDDocument(oDoc)
Console.WriteLine() Console.WriteLine()
Dim oSpecification = oResult.Specification
If oSpecification = ZUGFeRDInterface.ZUGFERD_SPEC_10 Then
oSpecification = ZUGFeRDInterface.ZUGFERD_SPEC_DEFAULT
End If
Dim oPropertyMap = oArgs.PropertyMap. Dim oPropertyMap = oArgs.PropertyMap.
Where(Function(kv) kv.Value.Specification = oResult.Specification). Where(Function(kv) kv.Value.Specification = oSpecification).
ToDictionary(Function(kv) kv.Key, Function(kv) kv.Value) ToDictionary(Function(kv) kv.Key, Function(kv) kv.Value)
Dim oResult2 = _zugferd.PropertyValues.CheckPropertyValues(oResult.SchemaObject, oPropertyMap, "test") Dim oResult2 = _zugferd.PropertyValues.CheckPropertyValues(oResult.SchemaObject, oPropertyMap, "test")

View File

@@ -12,8 +12,8 @@ Imports System.Runtime.InteropServices
<Assembly: AssemblyDescription("")> <Assembly: AssemblyDescription("")>
<Assembly: AssemblyCompany("Digital Data")> <Assembly: AssemblyCompany("Digital Data")>
<Assembly: AssemblyProduct("DDZUGFeRDService")> <Assembly: AssemblyProduct("DDZUGFeRDService")>
<Assembly: AssemblyCopyright("Copyright © 2022")> <Assembly: AssemblyCopyright("Copyright © 2023")>
<Assembly: AssemblyTrademark("2.3.0.0")> <Assembly: AssemblyTrademark("2.3.2.0")>
<Assembly: ComVisible(False)> <Assembly: ComVisible(False)>
@@ -31,5 +31,5 @@ Imports System.Runtime.InteropServices
' übernehmen, indem Sie "*" eingeben: ' übernehmen, indem Sie "*" eingeben:
' <Assembly: AssemblyVersion("1.0.*")> ' <Assembly: AssemblyVersion("1.0.*")>
<Assembly: AssemblyVersion("2.3.0.0")> <Assembly: AssemblyVersion("2.3.2.0")>
<Assembly: AssemblyFileVersion("2.3.0.0")> <Assembly: AssemblyFileVersion("2.3.2.0")>

View File

@@ -6,10 +6,19 @@
public string LogPath { get; set; } public string LogPath { get; set; }
public string MSSQLConnectionString { get; set; } public string MSSQLConnectionString { get; set; }
public string MaxFileSizeInMegabytes { get; set; } public string MaxFileSizeInMegabytes { get; set; }
public ZugferdConfig Zugferd { get; set; }
public FirebirdConfig Firebird { get; set; } public FirebirdConfig Firebird { 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 class FirebirdConfig public class FirebirdConfig
{ {
public string Datasource { get; set; } public string Datasource { get; set; }

View File

@@ -33,9 +33,13 @@ namespace ZUGFeRDRESTService.Controllers
private readonly DigitalData.Modules.Filesystem.File _file; private readonly DigitalData.Modules.Filesystem.File _file;
private readonly PropertyValues _props; private readonly PropertyValues _props;
private readonly Dictionary<string, XmlItemProperty> _propertyMap; private readonly Dictionary<string, XmlItemProperty> _propertyMap = new Dictionary<string, XmlItemProperty>();
private readonly int _MaxFileSizeInMegabytes; private int _MaxFileSizeInMegabytes;
private bool _AllowFacturX;
private bool _AllowXRechnung;
private bool _AllowZugferd2x;
private bool _AllowZugferd10;
public ValidationController(ILogging logging, IDatabase database, IConfiguration Config) public ValidationController(ILogging logging, IDatabase database, IConfiguration Config)
{ {
@@ -49,20 +53,73 @@ namespace ZUGFeRDRESTService.Controllers
var oGDPictureKey = database.GetGDPictureKey(); var oGDPictureKey = database.GetGDPictureKey();
var oPropertyMap = database.GetPropertyMap(); var oPropertyMap = database.GetPropertyMap();
_propertyMap = oPropertyMap; // Read config file and assign all option flags related to
// - Zugferd files
// - Filesizes
ParseConfig(Config);
_zugferd = new ZUGFeRDInterface(_logConfig, oGDPictureKey); _zugferd = new ZUGFeRDInterface(_logConfig, oGDPictureKey, new ZugferdOptions()
{
AllowFacturX_Filename = _AllowFacturX,
AllowXRechnung_Filename = _AllowXRechnung,
AllowZugferd_1_0_Schema = _AllowZugferd10,
AllowZugferd_2_x_Schema = _AllowZugferd2x
});
_props = new PropertyValues(_logConfig); _props = new PropertyValues(_logConfig);
var oAppConfig = Config.GetSection("Config"); _logger.Debug("Property Map initial: [{0}] entries found.", oPropertyMap.Count);
if (int.TryParse(oAppConfig["MaxFileSizeInMegabytes"], out _MaxFileSizeInMegabytes)) if (_AllowZugferd10 == true)
_propertyMap = oPropertyMap.
Where(kv => kv.Value.Specification == ZUGFERD_SPEC_10 || kv.Value.Specification == ZUGFERD_SPEC_DEFAULT).
Concat(_propertyMap).
ToDictionary(kv => kv.Key, kv => kv.Value);
if (_AllowZugferd2x == true)
_propertyMap = oPropertyMap.
Where(kv => kv.Value.Specification == ZUGFERD_SPEC_2x).
Concat(_propertyMap).
ToDictionary(kv => kv.Key, kv => kv.Value);
_logger.Debug("Property Map filtered: [{0}] entries found.", _propertyMap.Count);
_logger.Debug("Validation Controller initialized!");
}
private void ParseConfig(IConfiguration Config)
{
var oAppConfig = Config.GetSection("Config");
var oZugferdConfig = oAppConfig.GetSection("Zugferd");
if (!bool.TryParse(oZugferdConfig["AllowFacturX"], out _AllowFacturX))
{
_logger.Info("Configuration AllowFacturX was not set. Using default value [{0}]", false);
_AllowFacturX = false;
}
if (!bool.TryParse(oZugferdConfig["AllowXRechnung"], out _AllowXRechnung))
{
_logger.Info("Configuration AllowXRechnung was not set. Using default value [{0}]", false);
_AllowXRechnung = false;
}
if (!bool.TryParse(oZugferdConfig["AllowZugferd2x"], out _AllowZugferd2x))
{
_logger.Info("Configuration Zugferd2x was not set. Using default value [{0}]", false);
_AllowZugferd2x = false;
}
if (!bool.TryParse(oZugferdConfig["AllowZugferd10"], out _AllowZugferd10))
{
_logger.Info("Configuration Zugferd10 was not set. Using default value [{0}]", true);
_AllowZugferd10 = true;
}
if (!int.TryParse(oAppConfig["MaxFileSizeInMegabytes"], out _MaxFileSizeInMegabytes))
{ {
_logger.Info("Configuration MaxFileSizeInMegabytes was not set. Using default value [{0}]", MAX_FILE_SIZE_DEFAULT); _logger.Info("Configuration MaxFileSizeInMegabytes was not set. Using default value [{0}]", MAX_FILE_SIZE_DEFAULT);
_MaxFileSizeInMegabytes = MAX_FILE_SIZE_DEFAULT; _MaxFileSizeInMegabytes = MAX_FILE_SIZE_DEFAULT;
} }
_logger.Debug("Validation Controller initialized!");
} }
/// <summary> /// <summary>
@@ -75,8 +132,8 @@ namespace ZUGFeRDRESTService.Controllers
{ {
_logger.Info("Start processing request to ValidationController"); _logger.Info("Start processing request to ValidationController");
object oDocument; ZugferdResult oZugferdResult;
CheckPropertyValuesResult oResult = new CheckPropertyValuesResult(); CheckPropertyValuesResult oPropertyResult = new CheckPropertyValuesResult();
try try
{ {
@@ -89,40 +146,52 @@ namespace ZUGFeRDRESTService.Controllers
if (oFileSizeIsOK == false) if (oFileSizeIsOK == false)
{ {
throw new ZUGFeRDExecption(ErrorType.FileTooBig, throw new ZUGFeRDExecption(ErrorType.FileTooBig, "FileTooBig");
string.Format("Die hochgeladene Datei überschreitet die zulässige Dateigröße [{0}].", _MaxFileSizeInMegabytes));
} }
_logger.Info("Extracting ZUGFeRD Data from file [{0}]", file.FileName); _logger.Info("Extracting ZUGFeRD Data from file [{0}]", file.FileName);
oDocument = _zugferd.ExtractZUGFeRDFileWithGDPicture(oStream); oZugferdResult = _zugferd.ExtractZUGFeRDFileWithGDPicture(oStream);
_logger.Info("Detected Specification was: [{0}]", oZugferdResult.Specification);
var oFilteredPropertyMap = _zugferd.FilterPropertyMap(_propertyMap, oZugferdResult.Specification);
if (oFilteredPropertyMap.Count == 0)
{
_logger.Warn("No properties found in property map for specification [{0}]", oZugferdResult.Specification);
throw new ZUGFeRDExecption(ErrorType.UnsupportedFormat, "Unsupported Format");
}
else
{
_logger.Debug("Property map contains [{0}] entries for specification [{1}]", oFilteredPropertyMap.Count, oZugferdResult.Specification);
}
_logger.Info("Starting structural check against the database."); _logger.Info("Starting structural check against the database.");
oResult = _props.CheckPropertyValues(oDocument, _propertyMap, "MESSAGEID"); oPropertyResult = _props.CheckPropertyValues(oZugferdResult.SchemaObject, oFilteredPropertyMap, "MESSAGEID");
var oRequiredProperties = _propertyMap. var oRequiredProperties = oFilteredPropertyMap.
Where(prop => { return prop.Value.IsRequired == true; }). Where(prop => { return prop.Value.IsRequired == true; }).
Select(prop => { return prop.Value.Description; }) Select(prop => { return prop.Value.Description; }).
.ToList(); ToList();
_logger.Debug("Found [{0}] required properties", oRequiredProperties.Count); _logger.Debug("Found [{0}] required properties", oRequiredProperties.Count);
_logger.Debug(string.Join(",", oRequiredProperties.ToArray())); _logger.Debug(string.Join(",", oRequiredProperties.ToArray()));
_logger.Info("Result of checking against the database: {0} valid properties, {1} missing properties", _logger.Info("Result of checking against the database: {0} valid properties, {1} missing properties",
oResult.ValidProperties.Count, oResult.MissingProperties.Count); oPropertyResult.ValidProperties.Count, oPropertyResult.MissingProperties.Count);
if (oResult.MissingProperties.Count > 0) if (oPropertyResult.MissingProperties.Count > 0)
{ {
throw new ZUGFeRDExecption(ErrorType.MissingProperties, throw new ZUGFeRDExecption(ErrorType.MissingProperties, "Missing Properties");
"Die hochgeladene Datei ist eine gültige ZUGFeRD-Rechnung, allerdings fehlen benötigte Daten.");
} }
Tuple<bool, string> oValidateResult = ValidateBuyerOrderReference(oResult.ValidProperties); Tuple<bool, string> oValidateResult = ValidateBuyerOrderReference(oPropertyResult.ValidProperties);
if (oValidateResult.Item1 == false) if (oValidateResult.Item1 == false)
{ {
throw new ZUGFeRDExecption(ErrorType.UnknownError, "Die hochgeladene Datei kann nicht validiert werden, weil ein unbekannter Fehler aufgetreten ist."); throw new ZUGFeRDExecption(ErrorType.UnknownError, "Unknown Error");
} }
string oValidateResultString = oValidateResult.Item2; string oValidateResultString = oValidateResult.Item2;
@@ -162,8 +231,9 @@ namespace ZUGFeRDRESTService.Controllers
ErrorType.NoValidFile => "Die hochgeladene Datei ist keine gültige Datei.", ErrorType.NoValidFile => "Die hochgeladene Datei ist keine gültige Datei.",
ErrorType.NoZugferd => "Die hochgeladene Datei ist keine ZUGFeRD-Rechnung.", ErrorType.NoZugferd => "Die hochgeladene Datei ist keine ZUGFeRD-Rechnung.",
ErrorType.NoValidZugferd => "Die hochgeladene Datei ist keine gültige ZUGFeRD-Rechnung.", ErrorType.NoValidZugferd => "Die hochgeladene Datei ist keine gültige ZUGFeRD-Rechnung.",
ErrorType.MissingProperties => "Die hochgeladene Datei ist keine gültige ZUGFeRD-Rechnung, es fehlen einige Metadaten", ErrorType.MissingProperties => "Die hochgeladene Datei ist keine gültige ZUGFeRD-Rechnung, es fehlen einige Metadaten.",
ErrorType.FileTooBig => string.Format("Die hochgeladene Datei überschreitet die zulässige Dateigröße [{0}].", _MaxFileSizeInMegabytes), ErrorType.FileTooBig => string.Format("Die hochgeladene Datei überschreitet die zulässige Dateigröße [{0}].", _MaxFileSizeInMegabytes),
ErrorType.UnsupportedFormat => "Die hochgeladene Datei enthält ein falsches oder nicht unterstütztes ZUGFeRD Format.",
_ => "Die hochgeladene Datei kann nicht validiert werden.", _ => "Die hochgeladene Datei kann nicht validiert werden.",
}; };
@@ -171,7 +241,7 @@ namespace ZUGFeRDRESTService.Controllers
List<string> oErrors = ex.ErrorType switch List<string> oErrors = ex.ErrorType switch
{ {
// Errors contains the list of missing fields // Errors contains the list of missing fields
ErrorType.MissingProperties => oResult.MissingProperties, ErrorType.MissingProperties => oPropertyResult.MissingProperties,
_ => new List<string>() _ => new List<string>()
}; };

View File

@@ -14,11 +14,12 @@ namespace ZUGFeRDRESTService
{ {
public class Database: IDatabase public class Database: IDatabase
{ {
private DigitalData.Modules.Logging.Logger _Logger = null;
private string _gdPictureKey = null; private string _gdPictureKey = null;
private Dictionary<string, XmlItemProperty> _propertyMap = null; private Dictionary<string, XmlItemProperty> _propertyMap = null;
private const string QUERY_GET_GDPICTURE_KEY = "SELECT LICENSE FROM TBDD_3RD_PARTY_MODULES WHERE NAME = 'GDPICTURE'"; 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 TBEDM_XML_ITEMS WHERE SPECIFICATION = '{0}' AND ACTIVE = True ORDER BY XML_PATH"; private const string QUERY_GET_PROPERTY_MAP = "SELECT * FROM TBEDM_XML_ITEMS WHERE ACTIVE = True ORDER BY XML_PATH";
public MSSQLServer MSSQL { get; set; } public MSSQLServer MSSQL { get; set; }
public Firebird Firebird { get; set; } public Firebird Firebird { get; set; }
@@ -42,6 +43,8 @@ namespace ZUGFeRDRESTService
oLogger.Debug("MSSQL Connection: [{0}]", MSSQL.CurrentConnectionString); oLogger.Debug("MSSQL Connection: [{0}]", MSSQL.CurrentConnectionString);
oLogger.Debug("Firebird Connection: [{0}]", Firebird.ConnectionString); oLogger.Debug("Firebird Connection: [{0}]", Firebird.ConnectionString);
_Logger = oLogger;
} }
public string GetGDPictureKey() public string GetGDPictureKey()
@@ -52,12 +55,16 @@ namespace ZUGFeRDRESTService
return _gdPictureKey; return _gdPictureKey;
} }
public Dictionary<String, XmlItemProperty> GetPropertyMap() public Dictionary<string, XmlItemProperty> GetPropertyMap()
{ {
if (_propertyMap == null) if (_propertyMap == null)
{ {
_Logger.Debug("Property map does not exist, creating.");
_propertyMap = new Dictionary<string, XmlItemProperty>(); _propertyMap = new Dictionary<string, XmlItemProperty>();
var oDatatable = Firebird.GetDatatable(string.Format(QUERY_GET_PROPERTY_MAP, "DEFAULT")); var oDatatable = Firebird.GetDatatable(QUERY_GET_PROPERTY_MAP);
_Logger.Debug("Datatable Rows: [{0}]", oDatatable.Rows);
foreach (DataRow oRow in oDatatable.Rows) foreach (DataRow oRow in oDatatable.Rows)
{ {
@@ -68,11 +75,17 @@ namespace ZUGFeRDRESTService
TableColumn = oRow["TABLE_COLUMN"].ToString(), TableColumn = oRow["TABLE_COLUMN"].ToString(),
GroupScope = oRow["GROUP_SCOPE"].ToString(), GroupScope = oRow["GROUP_SCOPE"].ToString(),
IsRequired = (bool)oRow["IS_REQUIRED"], IsRequired = (bool)oRow["IS_REQUIRED"],
IsGrouped = (bool)oRow["IS_GROUPED"] IsGrouped = (bool)oRow["IS_GROUPED"],
Specification = oRow["SPECIFICATION"].ToString()
}); });
} }
} else
{
_Logger.Debug("Property map already exists, returning.");
} }
_Logger.Debug("Returning Property Map with [{0}] entries.", _propertyMap.Count);
return _propertyMap; return _propertyMap;
} }
} }

View File

@@ -18,6 +18,12 @@
"Username": "<FIREBIRDSERVER-USERNAME>", "Username": "<FIREBIRDSERVER-USERNAME>",
"Password": "<FIREBIRDSERVER-PASSWORD>" "Password": "<FIREBIRDSERVER-PASSWORD>"
}, },
"Zugferd": {
"AllowZugferd10": true,
"AllowZugferd2x": false,
"AllowFacturX": false,
"AllowXRechnung": false
},
"MaxFileSizeInMegabytes": 25 "MaxFileSizeInMegabytes": 25
} }
} }