|
|
|
|
@@ -1,13 +1,16 @@
|
|
|
|
|
using DigitalData.Modules.Interfaces;
|
|
|
|
|
using Microsoft.AspNetCore.Http;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
|
|
|
|
using Microsoft.Extensions.Configuration;
|
|
|
|
|
using Microsoft.VisualStudio.Web.CodeGeneration.Contracts.Messaging;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Data;
|
|
|
|
|
using System.Data.SqlClient;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Net.Http;
|
|
|
|
|
using System.Text.RegularExpressions;
|
|
|
|
|
using System.Xml.Linq;
|
|
|
|
|
using static DigitalData.Modules.Interfaces.Exceptions;
|
|
|
|
|
@@ -29,6 +32,7 @@ namespace ZUGFeRDRESTService.Controllers
|
|
|
|
|
public const string VALIDATION_SUCCESS = "VALIDATION SUCCESS";
|
|
|
|
|
public const string REFERENCES_Rejection_30001 = "REFERENCES_Rejection_30001";
|
|
|
|
|
public const string REFERENCES_Rejection_30002 = "REFERENCES_Rejection_30002";
|
|
|
|
|
public const string REFERENCES_Rejection_30002_1 = "REFERENCES_Rejection_30002_1";
|
|
|
|
|
public const string REFERENCES_Rejection_30003_1 = "REFERENCES_Rejection_30003_1";
|
|
|
|
|
public const string REFERENCES_Rejection_30003_2 = "REFERENCES_Rejection_30003_2";
|
|
|
|
|
public const string REFERENCES_Rejection_30003_3 = "REFERENCES_Rejection_30003_3";
|
|
|
|
|
@@ -47,7 +51,14 @@ namespace ZUGFeRDRESTService.Controllers
|
|
|
|
|
public const string REFERENCES_Rejection_30012 = "REFERENCES_Rejection_30012";
|
|
|
|
|
public const string AMOUNT_CALC_REJECTION = "AMOUNT_CALC_REJECTION";
|
|
|
|
|
|
|
|
|
|
public const string GERMAN = "de-DE";
|
|
|
|
|
public const string ENGLISH = "en-US";
|
|
|
|
|
public const string FRENCH = "fr-FR";
|
|
|
|
|
public const string SPAIN = "es-ES";
|
|
|
|
|
|
|
|
|
|
private List<string> _ValidationErrors;
|
|
|
|
|
private List<string> _AllowedLanguageCodes;
|
|
|
|
|
private string _UserLanguageCode = GERMAN;
|
|
|
|
|
|
|
|
|
|
private const int MAX_FILE_SIZE_DEFAULT = 25;
|
|
|
|
|
|
|
|
|
|
@@ -56,10 +67,9 @@ namespace ZUGFeRDRESTService.Controllers
|
|
|
|
|
|
|
|
|
|
private readonly DigitalData.Modules.Logging.LogConfig _logConfig;
|
|
|
|
|
private readonly DigitalData.Modules.Logging.Logger _logger;
|
|
|
|
|
private readonly DigitalData.Modules.Filesystem.File _file;
|
|
|
|
|
//private readonly DigitalData.Modules.Filesystem.File _file;
|
|
|
|
|
|
|
|
|
|
private readonly PropertyValues _props;
|
|
|
|
|
//private readonly Dictionary<string, XmlItemProperty> _propertyMap = new Dictionary<string, XmlItemProperty>();
|
|
|
|
|
private readonly List<XmlItemProperty> _propertyMapList = new List<XmlItemProperty>();
|
|
|
|
|
private readonly List<RejectionStringRow> _RecjectionMessageList = new List<RejectionStringRow>();
|
|
|
|
|
|
|
|
|
|
@@ -77,7 +87,7 @@ namespace ZUGFeRDRESTService.Controllers
|
|
|
|
|
{
|
|
|
|
|
_logConfig = logging.LogConfig;
|
|
|
|
|
_logger = _logConfig.GetLogger();
|
|
|
|
|
_file = new DigitalData.Modules.Filesystem.File(_logConfig);
|
|
|
|
|
//_file = new DigitalData.Modules.Filesystem.File(_logConfig);
|
|
|
|
|
|
|
|
|
|
_logger.Debug("Validation Controller initializing");
|
|
|
|
|
|
|
|
|
|
@@ -128,6 +138,14 @@ namespace ZUGFeRDRESTService.Controllers
|
|
|
|
|
AMOUNT_CALC_REJECTION
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
_AllowedLanguageCodes = new List<string>()
|
|
|
|
|
{
|
|
|
|
|
GERMAN,
|
|
|
|
|
ENGLISH,
|
|
|
|
|
FRENCH,
|
|
|
|
|
SPAIN,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
_logger.Debug("Validation Controller initialized!");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -191,14 +209,59 @@ namespace ZUGFeRDRESTService.Controllers
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="file">This parameter's name needs to correspond to the html form's file-input name</param>
|
|
|
|
|
/// <param name="user_id">This is the email address which the user supplied</param>
|
|
|
|
|
/// <param name="language_id">This is language code which the user supplied (en-US, de-DE)</param>
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public ValidationResponse Post(IFormFile file, string user_id)
|
|
|
|
|
//public ValidationResponse Post(IFormFile file, StringContent user_id, StringContent language_id = null)
|
|
|
|
|
public ValidationResponse Post(IFormCollection collection)
|
|
|
|
|
{
|
|
|
|
|
_logger.Info("Start processing request to ValidationController");
|
|
|
|
|
|
|
|
|
|
ZugferdResult oZugferdResult = null;
|
|
|
|
|
CheckPropertyValuesResult oPropertyResult = new CheckPropertyValuesResult();
|
|
|
|
|
|
|
|
|
|
var oUserId = string.Empty; // user_id == null ? string.Empty : user_id.ToString();
|
|
|
|
|
var oLanguageId = GERMAN; // language_id == null ? GERMAN : language_id.ToString();
|
|
|
|
|
|
|
|
|
|
IFormFile file = collection.Files[0];
|
|
|
|
|
|
|
|
|
|
foreach (var keyItem in collection.Keys)
|
|
|
|
|
{
|
|
|
|
|
if (keyItem == "user_id")
|
|
|
|
|
{
|
|
|
|
|
oUserId = collection[keyItem];
|
|
|
|
|
}
|
|
|
|
|
else if (keyItem == "language_id")
|
|
|
|
|
{
|
|
|
|
|
oLanguageId = collection[keyItem];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(oUserId))
|
|
|
|
|
{
|
|
|
|
|
_logger.Info("UserID set to [{0}].", oUserId);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
_logger.Info("UserID is empty!");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(oLanguageId))
|
|
|
|
|
{
|
|
|
|
|
_logger.Info("Language code was empty. Set to default 'de-DE'");
|
|
|
|
|
// DEFAULT-Sprache = Deutsch de-DE
|
|
|
|
|
_UserLanguageCode = GERMAN;
|
|
|
|
|
}
|
|
|
|
|
else if (_AllowedLanguageCodes.Contains(oLanguageId))
|
|
|
|
|
{
|
|
|
|
|
_logger.Info("Language code is allowed. Set to [{0}].", oLanguageId);
|
|
|
|
|
_UserLanguageCode = oLanguageId;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
_logger.Info("Language code was unknown: [{0}]. Set to default 'de-DE'", oLanguageId);
|
|
|
|
|
_UserLanguageCode = GERMAN;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
using Stream oStream = file.OpenReadStream();
|
|
|
|
|
@@ -299,7 +362,7 @@ namespace ZUGFeRDRESTService.Controllers
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
catch (ZUGFeRDExecption ex)
|
|
|
|
|
{
|
|
|
|
|
@@ -325,12 +388,6 @@ namespace ZUGFeRDRESTService.Controllers
|
|
|
|
|
oMessage = Regex.Replace(oMessage, "@REPLACE_PARAM2", ex.Param2, RegexOptions.IgnoreCase);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Der REJECTION-Code wird in alle Meldungen eingefügt.
|
|
|
|
|
if (!string.IsNullOrEmpty(rejectionCodeNumber) && oMessage.Contains("@REJECTION_CODE", StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
{
|
|
|
|
|
oMessage = Regex.Replace(oMessage, "@REJECTION_CODE", "Ablehnungscode: " + rejectionCodeNumber, RegexOptions.IgnoreCase);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Determine if any errors should be sent in the response
|
|
|
|
|
switch (ex.ErrorCode)
|
|
|
|
|
{
|
|
|
|
|
@@ -467,13 +524,6 @@ namespace ZUGFeRDRESTService.Controllers
|
|
|
|
|
oReturnValue = oDbMessage;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Der REJECTION-Code wird in alle Meldungen eingefügt.
|
|
|
|
|
if (!string.IsNullOrEmpty(oRejectionItem) && oReturnValue.Contains("@REJECTION_CODE", StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
{
|
|
|
|
|
var rejectionCodeNumber = GetRejectionCodeNumber(oRejectionItem);
|
|
|
|
|
oReturnValue = Regex.Replace(oReturnValue, "@REJECTION_CODE", "Ablehnungscode: " + rejectionCodeNumber, RegexOptions.IgnoreCase);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@@ -611,7 +661,7 @@ namespace ZUGFeRDRESTService.Controllers
|
|
|
|
|
return oReplaceParam1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string GetMessageId()
|
|
|
|
|
private string GetMessageId()
|
|
|
|
|
{
|
|
|
|
|
return $"{Guid.NewGuid()}@{MESSAGEID_DOMAIN}";
|
|
|
|
|
}
|
|
|
|
|
@@ -772,7 +822,7 @@ namespace ZUGFeRDRESTService.Controllers
|
|
|
|
|
return oDataTable;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool DeleteExistingPropertyValues(string pMessageId)
|
|
|
|
|
private bool DeleteExistingPropertyValues(string pMessageId)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
@@ -816,18 +866,15 @@ namespace ZUGFeRDRESTService.Controllers
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Ermittelt die Ausgabe-nachricht für einen Fehlercode
|
|
|
|
|
/// </summary>
|
|
|
|
|
public string GetRejectionMessage(string pErrorCode)
|
|
|
|
|
private string GetRejectionMessage(string pErrorCode)
|
|
|
|
|
{
|
|
|
|
|
_logger.Info("GetRejectionMessage() - errorCode.ToString(): '" + pErrorCode.ToString() + "'");
|
|
|
|
|
|
|
|
|
|
if (_RecjectionMessageList == null) return string.Empty;
|
|
|
|
|
|
|
|
|
|
// Sprache wird man vielleicht mal auswählen können
|
|
|
|
|
var language = "de-DE";
|
|
|
|
|
var searchTitle = string.Empty;
|
|
|
|
|
|
|
|
|
|
if (pErrorCode.Contains("2000"))
|
|
|
|
|
@@ -844,15 +891,43 @@ namespace ZUGFeRDRESTService.Controllers
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// else-Fall muss noch geklärt werden.
|
|
|
|
|
searchTitle = "AMOUNT_CALC_REJECTION_Web";
|
|
|
|
|
searchTitle = "ZUGFERD_Rejection_20006_Web";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var messageItem = _RecjectionMessageList.Where(i => i.Title.Equals(searchTitle, StringComparison.OrdinalIgnoreCase) && i.Language.Equals(language, StringComparison.OrdinalIgnoreCase)).FirstOrDefault();
|
|
|
|
|
if (messageItem != null)
|
|
|
|
|
// Sprachgenauen Text suchen.
|
|
|
|
|
var messageItem = _RecjectionMessageList.Where(i => i.Title.Equals(searchTitle, StringComparison.OrdinalIgnoreCase) &&
|
|
|
|
|
i.Language.Equals(_UserLanguageCode, StringComparison.OrdinalIgnoreCase)).FirstOrDefault();
|
|
|
|
|
|
|
|
|
|
if (messageItem == null &&
|
|
|
|
|
!_UserLanguageCode.Equals(GERMAN, StringComparison.OrdinalIgnoreCase)) {
|
|
|
|
|
|
|
|
|
|
_logger.Info("GetRejectionMessage() - Es wurde kein passender Text für die Sprache [{0}] gefunden.", _UserLanguageCode);
|
|
|
|
|
|
|
|
|
|
// Wenn kein sprachgenauer Text vorliegt, hole den deutschen Text.
|
|
|
|
|
messageItem = _RecjectionMessageList.Where(i => i.Title.Equals(searchTitle, StringComparison.OrdinalIgnoreCase) &&
|
|
|
|
|
i.Language.Equals(GERMAN, StringComparison.OrdinalIgnoreCase)).FirstOrDefault();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (messageItem != null && !string.IsNullOrEmpty(pErrorCode))
|
|
|
|
|
{
|
|
|
|
|
_logger.Info("GetRejectionMessage() - messageItem: '" + messageItem.String1 + "'");
|
|
|
|
|
return messageItem.String1;
|
|
|
|
|
var resultText = string.Empty;
|
|
|
|
|
|
|
|
|
|
// Der REJECTION-Code wird in allen Meldungen ausgetauscht.
|
|
|
|
|
if (messageItem.String1.Contains("@REJECTION_CODE", StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
{
|
|
|
|
|
var substituteText = this.GetLabelText("Ablehnungscode", _UserLanguageCode);
|
|
|
|
|
substituteText = string.IsNullOrEmpty(substituteText) ? "Ablehnungscode" : substituteText;
|
|
|
|
|
substituteText = substituteText + ": " + pErrorCode;
|
|
|
|
|
|
|
|
|
|
resultText = Regex.Replace(messageItem.String1, "@REJECTION_CODE", substituteText, RegexOptions.IgnoreCase);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
resultText = messageItem.String1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_logger.Info("GetRejectionMessage() - messageItem: '" + resultText + "'");
|
|
|
|
|
return resultText;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
@@ -861,6 +936,15 @@ namespace ZUGFeRDRESTService.Controllers
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private string GetLabelText(string pLabel, string pLanguage)
|
|
|
|
|
{
|
|
|
|
|
// Sprachgenauen Text suchen.
|
|
|
|
|
var messageItem = _RecjectionMessageList.Where(i => i.Title.Equals(pLabel, StringComparison.OrdinalIgnoreCase) &&
|
|
|
|
|
i.Language.Equals(pLanguage, StringComparison.OrdinalIgnoreCase)).FirstOrDefault();
|
|
|
|
|
|
|
|
|
|
return messageItem != null ? messageItem.String1 : string.Empty;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private string GetRejectionCodeNumber(ErrorCodes rejectionCode)
|
|
|
|
|
{
|
|
|
|
|
switch (rejectionCode)
|
|
|
|
|
|