Compare commits
2 Commits
4cfc8cd46b
...
b4eecbdb86
| Author | SHA1 | Date | |
|---|---|---|---|
| b4eecbdb86 | |||
| 3f58acea7a |
@@ -87,8 +87,6 @@ namespace ZUGFeRDRESTService.Controllers
|
||||
{
|
||||
_logConfig = logging.LogConfig;
|
||||
_logger = _logConfig.GetLogger();
|
||||
//_file = new DigitalData.Modules.Filesystem.File(_logConfig);
|
||||
|
||||
_logger.Debug("Validation Controller initializing");
|
||||
|
||||
// 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="language_id">This is language code which the user supplied (en-US, de-DE)</param>
|
||||
[HttpPost]
|
||||
//public ValidationResponse Post(IFormFile file, StringContent user_id, StringContent language_id = null)
|
||||
public ValidationResponse Post(IFormCollection collection)
|
||||
{
|
||||
_logger.Info("Start processing request to ValidationController");
|
||||
@@ -219,8 +216,8 @@ namespace ZUGFeRDRESTService.Controllers
|
||||
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();
|
||||
var oUserId = string.Empty;
|
||||
var oLanguageId = GERMAN;
|
||||
|
||||
IFormFile file = collection.Files[0];
|
||||
|
||||
@@ -251,7 +248,7 @@ namespace ZUGFeRDRESTService.Controllers
|
||||
// DEFAULT-Sprache = Deutsch de-DE
|
||||
_UserLanguageCode = GERMAN;
|
||||
}
|
||||
else if (_AllowedLanguageCodes.Contains(oLanguageId))
|
||||
else if (_AllowedLanguageCodes.Where(i => i.Equals(oLanguageId, StringComparison.OrdinalIgnoreCase)).FirstOrDefault() != null)
|
||||
{
|
||||
_logger.Info("Language code is allowed. Set to [{0}].", oLanguageId);
|
||||
_UserLanguageCode = oLanguageId;
|
||||
@@ -392,8 +389,12 @@ namespace ZUGFeRDRESTService.Controllers
|
||||
switch (ex.ErrorCode)
|
||||
{
|
||||
case ErrorCodes.MissingValueException:
|
||||
oErrors.AddRange(from item in oPropertyResult.MissingProperties
|
||||
select (item.EN16931_ID + " (" + item.Description + ")"));
|
||||
|
||||
var oErrorsText = GetMissingValuesListString(oPropertyResult.MissingProperties);
|
||||
if (!string.IsNullOrEmpty(oErrorsText) && oMessage.Contains("@REPLACE_PARAM3", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
oMessage = Regex.Replace(oMessage, "@REPLACE_PARAM3", oErrorsText, RegexOptions.IgnoreCase);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@@ -422,16 +423,54 @@ namespace ZUGFeRDRESTService.Controllers
|
||||
// Der gesamte Ausgabetext muss anhand des ErrorCodes ermittelt werden
|
||||
string oMessage = this.GetRejectionMessage(rejectionCodeNumber);
|
||||
|
||||
List<string> oErrors = ex.ValidationErrors.Select(e =>
|
||||
{
|
||||
return $"Element '{e.ElementName}' mit Wert '{e.ElementValue}': {e.ErrorMessageDE}";
|
||||
}).ToList();
|
||||
// Wenn es ValidationErrors gibt, werden diese nun übersetzt und in eine Liste übertragen werden
|
||||
|
||||
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()
|
||||
{
|
||||
status = RESPONSE_ERROR,
|
||||
message = oMessage,
|
||||
errors = oErrors
|
||||
message = oMessage
|
||||
};
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -450,6 +489,59 @@ namespace ZUGFeRDRESTService.Controllers
|
||||
}
|
||||
}
|
||||
|
||||
private string GetMissingValuesListString(List<MissingProperty> missingProperties)
|
||||
{
|
||||
if (missingProperties == null || missingProperties.Count == 0)
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
string retValue = "<ul>";
|
||||
foreach (var missingProperty in missingProperties)
|
||||
{
|
||||
var searchToken = missingProperty.EN16931_ID + "_Description";
|
||||
var descriptionTranslated = GetTextByToken(searchToken);
|
||||
var rowString = "<li>" + missingProperty.EN16931_ID + " (" + descriptionTranslated + ")</li>";
|
||||
retValue += rowString;
|
||||
}
|
||||
retValue += "</ul>";
|
||||
|
||||
return retValue;
|
||||
}
|
||||
|
||||
/// <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>
|
||||
/// Hier wird eine externe Prozedur gerufen, PRCUST_INV_CHECK_FROM_PORTAL,
|
||||
/// die das Ergebnis der Referenzpruefung liefert.
|
||||
@@ -975,16 +1067,5 @@ namespace ZUGFeRDRESTService.Controllers
|
||||
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