ValidationException - Auswertung der Exception-Items - mehrsprachig
This commit is contained in:
@@ -87,8 +87,6 @@ namespace ZUGFeRDRESTService.Controllers
|
|||||||
{
|
{
|
||||||
_logConfig = logging.LogConfig;
|
_logConfig = logging.LogConfig;
|
||||||
_logger = _logConfig.GetLogger();
|
_logger = _logConfig.GetLogger();
|
||||||
//_file = new DigitalData.Modules.Filesystem.File(_logConfig);
|
|
||||||
|
|
||||||
_logger.Debug("Validation Controller initializing");
|
_logger.Debug("Validation Controller initializing");
|
||||||
|
|
||||||
// Read config file and assign all option flags related to
|
// Read config file and assign all option flags related to
|
||||||
@@ -211,7 +209,6 @@ namespace ZUGFeRDRESTService.Controllers
|
|||||||
/// <param name="user_id">This is the email address which the user supplied</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>
|
/// <param name="language_id">This is language code which the user supplied (en-US, de-DE)</param>
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
//public ValidationResponse Post(IFormFile file, StringContent user_id, StringContent language_id = null)
|
|
||||||
public ValidationResponse Post(IFormCollection collection)
|
public ValidationResponse Post(IFormCollection collection)
|
||||||
{
|
{
|
||||||
_logger.Info("Start processing request to ValidationController");
|
_logger.Info("Start processing request to ValidationController");
|
||||||
@@ -219,8 +216,8 @@ namespace ZUGFeRDRESTService.Controllers
|
|||||||
ZugferdResult oZugferdResult = null;
|
ZugferdResult oZugferdResult = null;
|
||||||
CheckPropertyValuesResult oPropertyResult = new CheckPropertyValuesResult();
|
CheckPropertyValuesResult oPropertyResult = new CheckPropertyValuesResult();
|
||||||
|
|
||||||
var oUserId = string.Empty; // user_id == null ? string.Empty : user_id.ToString();
|
var oUserId = string.Empty;
|
||||||
var oLanguageId = GERMAN; // language_id == null ? GERMAN : language_id.ToString();
|
var oLanguageId = GERMAN;
|
||||||
|
|
||||||
IFormFile file = collection.Files[0];
|
IFormFile file = collection.Files[0];
|
||||||
|
|
||||||
@@ -422,16 +419,54 @@ namespace ZUGFeRDRESTService.Controllers
|
|||||||
// Der gesamte Ausgabetext muss anhand des ErrorCodes ermittelt werden
|
// Der gesamte Ausgabetext muss anhand des ErrorCodes ermittelt werden
|
||||||
string oMessage = this.GetRejectionMessage(rejectionCodeNumber);
|
string oMessage = this.GetRejectionMessage(rejectionCodeNumber);
|
||||||
|
|
||||||
List<string> oErrors = ex.ValidationErrors.Select(e =>
|
// Wenn es ValidationErrors gibt, werden diese nun übersetzt und in eine Liste übertragen werden
|
||||||
{
|
|
||||||
return $"Element '{e.ElementName}' mit Wert '{e.ElementValue}': {e.ErrorMessageDE}";
|
|
||||||
}).ToList();
|
|
||||||
|
|
||||||
|
var mainText = GetTextByToken("ItemValueText");
|
||||||
|
var resultList = new List<string>();
|
||||||
|
foreach (var errorItem in ex.ValidationErrors)
|
||||||
|
{
|
||||||
|
var resultString = mainText;
|
||||||
|
|
||||||
|
if (!string.IsNullOrEmpty(errorItem.ElementName))
|
||||||
|
{
|
||||||
|
// replace @ITEM_NAME => e.ElementName
|
||||||
|
resultString = resultString.Replace("@ITEM_NAME", errorItem.ElementName, StringComparison.OrdinalIgnoreCase);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!string.IsNullOrEmpty(errorItem.ElementValue))
|
||||||
|
{
|
||||||
|
// replace ITEM_VALUE => e.ElementValue
|
||||||
|
resultString = resultString.Replace("@ITEM_VALUE", errorItem.ElementValue, StringComparison.OrdinalIgnoreCase);
|
||||||
|
}
|
||||||
|
|
||||||
|
var itemErrorText = GetTextByToken(errorItem.ErrorMessageToken);
|
||||||
|
if (!string.IsNullOrEmpty(itemErrorText))
|
||||||
|
{
|
||||||
|
// attach itemErrorText
|
||||||
|
resultString += " " + itemErrorText;
|
||||||
|
}
|
||||||
|
|
||||||
|
_logger.Debug($"resultString: [{resultString}]");
|
||||||
|
resultList.Add(resultString);
|
||||||
|
}
|
||||||
|
|
||||||
|
// wenn ergebnisse vorliegen, in html transformieren und anhängen
|
||||||
|
if (resultList.Count > 0)
|
||||||
|
{
|
||||||
|
var htmlResultString = "<ul>";
|
||||||
|
foreach (var resultItem in resultList)
|
||||||
|
{
|
||||||
|
htmlResultString += " <li>" + resultItem + "</li>" + Environment.NewLine;
|
||||||
|
}
|
||||||
|
htmlResultString += " </ul>";
|
||||||
|
|
||||||
|
oMessage += " " + htmlResultString;
|
||||||
|
}
|
||||||
|
|
||||||
return new ValidationResponse()
|
return new ValidationResponse()
|
||||||
{
|
{
|
||||||
status = RESPONSE_ERROR,
|
status = RESPONSE_ERROR,
|
||||||
message = oMessage,
|
message = oMessage
|
||||||
errors = oErrors
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
@@ -450,6 +485,39 @@ namespace ZUGFeRDRESTService.Controllers
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Holt sprachgenauen Text anhand eines Titel-Tokens
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
private string GetTextByToken(string tokenValue)
|
||||||
|
{
|
||||||
|
RejectionStringRow stringRow = null;
|
||||||
|
|
||||||
|
if (!string.IsNullOrEmpty(tokenValue))
|
||||||
|
{
|
||||||
|
stringRow = _RecjectionMessageList.Where(i => i.Title.Equals(tokenValue, StringComparison.OrdinalIgnoreCase) &&
|
||||||
|
i.Language.Equals(_UserLanguageCode, StringComparison.OrdinalIgnoreCase)).FirstOrDefault();
|
||||||
|
|
||||||
|
if (stringRow == null &&
|
||||||
|
!_UserLanguageCode.Equals(GERMAN, StringComparison.OrdinalIgnoreCase))
|
||||||
|
{
|
||||||
|
// Wenn kein sprachgenauer Text vorliegt, hole den deutschen Text.
|
||||||
|
stringRow = _RecjectionMessageList.Where(i => i.Title.Equals(tokenValue, StringComparison.OrdinalIgnoreCase) &&
|
||||||
|
i.Language.Equals(GERMAN, StringComparison.OrdinalIgnoreCase)).FirstOrDefault();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
string retValue = string.Empty;
|
||||||
|
|
||||||
|
if (stringRow != null)
|
||||||
|
{
|
||||||
|
retValue = !string.IsNullOrEmpty(stringRow.String1) ? stringRow.String1.Trim() : string.Empty;
|
||||||
|
}
|
||||||
|
|
||||||
|
_logger.Debug($"Token [{tokenValue}] - String1 [{retValue}]");
|
||||||
|
return retValue;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Hier wird eine externe Prozedur gerufen, PRCUST_INV_CHECK_FROM_PORTAL,
|
/// Hier wird eine externe Prozedur gerufen, PRCUST_INV_CHECK_FROM_PORTAL,
|
||||||
/// die das Ergebnis der Referenzpruefung liefert.
|
/// die das Ergebnis der Referenzpruefung liefert.
|
||||||
@@ -975,16 +1043,5 @@ namespace ZUGFeRDRESTService.Controllers
|
|||||||
return "20010";
|
return "20010";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private string GetRejectionCodeNumber(string rejectionCode)
|
|
||||||
{
|
|
||||||
if (rejectionCode.StartsWith("REFERENCES_Rejection_"))
|
|
||||||
{
|
|
||||||
var retValue = rejectionCode.Replace("REFERENCES_Rejection_", "");
|
|
||||||
return retValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
return rejectionCode;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user