ZUGFERD REST SERVICE: improve logging
This commit is contained in:
parent
873b024f13
commit
f04e1b4c85
@ -9,8 +9,6 @@ using static DigitalData.Modules.Interfaces.Exceptions;
|
|||||||
using static DigitalData.Modules.Interfaces.ZUGFeRDInterface;
|
using static DigitalData.Modules.Interfaces.ZUGFeRDInterface;
|
||||||
using static DigitalData.Modules.Interfaces.PropertyValues;
|
using static DigitalData.Modules.Interfaces.PropertyValues;
|
||||||
using System.Data.SqlClient;
|
using System.Data.SqlClient;
|
||||||
using DigitalData.Modules.Database;
|
|
||||||
using Microsoft.CodeAnalysis.Operations;
|
|
||||||
|
|
||||||
namespace ZUGFeRDRESTService.Controllers
|
namespace ZUGFeRDRESTService.Controllers
|
||||||
{
|
{
|
||||||
@ -55,11 +53,12 @@ namespace ZUGFeRDRESTService.Controllers
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// POST: /api/validation
|
/// POST: /api/validation
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="files">This parameter's name needs to correspond to the html form's file-input name</param>
|
/// <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>
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
public ValidationResponse Post(IFormFile file, string user_id)
|
public ValidationResponse Post(IFormFile file, string user_id)
|
||||||
{
|
{
|
||||||
_logger.Debug("Start processing request to ValidationController");
|
_logger.Info("Start processing request to ValidationController");
|
||||||
|
|
||||||
object oDocument;
|
object oDocument;
|
||||||
PropertyValues.CheckPropertyValuesResult oResult = new PropertyValues.CheckPropertyValuesResult();
|
PropertyValues.CheckPropertyValuesResult oResult = new PropertyValues.CheckPropertyValuesResult();
|
||||||
@ -68,11 +67,11 @@ namespace ZUGFeRDRESTService.Controllers
|
|||||||
{
|
{
|
||||||
using Stream oStream = file.OpenReadStream();
|
using Stream oStream = file.OpenReadStream();
|
||||||
{
|
{
|
||||||
_logger.Debug("Extracting ZUGFeRD Data from file [{0}]", file.FileName);
|
_logger.Info("Extracting ZUGFeRD Data from file [{0}]", file.FileName);
|
||||||
|
|
||||||
oDocument = _zugferd.ExtractZUGFeRDFileWithGDPicture(oStream);
|
oDocument = _zugferd.ExtractZUGFeRDFileWithGDPicture(oStream);
|
||||||
|
|
||||||
_logger.Debug("Checking ZUGFeRD Data against the database");
|
_logger.Info("Starting structural check against the database.");
|
||||||
|
|
||||||
oResult = _props.CheckPropertyValues(oDocument, _propertyMap, "MESSAGEID");
|
oResult = _props.CheckPropertyValues(oDocument, _propertyMap, "MESSAGEID");
|
||||||
|
|
||||||
@ -84,7 +83,7 @@ namespace ZUGFeRDRESTService.Controllers
|
|||||||
_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.Debug("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);
|
oResult.ValidProperties.Count, oResult.MissingProperties.Count);
|
||||||
|
|
||||||
if (oResult.MissingProperties.Count > 0)
|
if (oResult.MissingProperties.Count > 0)
|
||||||
@ -95,16 +94,36 @@ namespace ZUGFeRDRESTService.Controllers
|
|||||||
|
|
||||||
Tuple<bool, string> oValidateResult = ValidateBuyerOrderReference(oResult.ValidProperties);
|
Tuple<bool, string> oValidateResult = ValidateBuyerOrderReference(oResult.ValidProperties);
|
||||||
|
|
||||||
|
if (oValidateResult.Item1 == false)
|
||||||
string oMessage = "Die hochgeladene Datei ist eine gültige-ZUGFeRD Rechnung";
|
|
||||||
|
|
||||||
_logger.Debug($"Replying with: [{oMessage}]");
|
|
||||||
|
|
||||||
return new ValidationResponse()
|
|
||||||
{
|
{
|
||||||
status = RESPONSE_OK,
|
throw new ZUGFeRDExecption(ErrorType.UnknownError, "Die hochgeladene Datei kann nicht validiert werden, weil ein unbekannter Fehler aufgetreten ist.");
|
||||||
message = oMessage
|
}
|
||||||
};
|
|
||||||
|
string oValidateResultString = oValidateResult.Item2;
|
||||||
|
|
||||||
|
if (oValidateResultString == "ALL REFERENCES CHECKED POSITIVE")
|
||||||
|
{
|
||||||
|
string oMessage = "Die hochgeladene Datei ist eine gültige-ZUGFeRD Rechnung";
|
||||||
|
|
||||||
|
_logger.Info($"Responding with message: [{oMessage}]");
|
||||||
|
|
||||||
|
return new ValidationResponse()
|
||||||
|
{
|
||||||
|
status = RESPONSE_OK,
|
||||||
|
message = oMessage
|
||||||
|
};
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
string oMessage = oValidateResultString;
|
||||||
|
|
||||||
|
_logger.Info($"Responding with message: [{oMessage}]");
|
||||||
|
|
||||||
|
return new ValidationResponse()
|
||||||
|
{
|
||||||
|
status = RESPONSE_ERROR,
|
||||||
|
message = oMessage
|
||||||
|
};
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
catch (ZUGFeRDExecption ex)
|
catch (ZUGFeRDExecption ex)
|
||||||
@ -129,7 +148,7 @@ namespace ZUGFeRDRESTService.Controllers
|
|||||||
_ => new List<string>()
|
_ => new List<string>()
|
||||||
};
|
};
|
||||||
|
|
||||||
_logger.Debug($"Replying with: [{oMessage}]");
|
_logger.Info($"Responding with message: [{oMessage}]");
|
||||||
|
|
||||||
return new ValidationResponse()
|
return new ValidationResponse()
|
||||||
{
|
{
|
||||||
@ -144,7 +163,7 @@ namespace ZUGFeRDRESTService.Controllers
|
|||||||
|
|
||||||
string oMessage = "Die hochgeladene Datei kann nicht validiert werden, weil ein unbekannter Fehler aufgetreten ist.";
|
string oMessage = "Die hochgeladene Datei kann nicht validiert werden, weil ein unbekannter Fehler aufgetreten ist.";
|
||||||
|
|
||||||
_logger.Debug($"Replying with: [{oMessage}]");
|
_logger.Info($"Responding with message: [{oMessage}]");
|
||||||
|
|
||||||
return new ValidationResponse()
|
return new ValidationResponse()
|
||||||
{
|
{
|
||||||
@ -156,9 +175,10 @@ namespace ZUGFeRDRESTService.Controllers
|
|||||||
|
|
||||||
private Tuple<bool, string> ValidateBuyerOrderReference(List<ValidProperty> pProperties)
|
private Tuple<bool, string> ValidateBuyerOrderReference(List<ValidProperty> pProperties)
|
||||||
{
|
{
|
||||||
|
|
||||||
var oMessageId = GetMessageId();
|
var oMessageId = GetMessageId();
|
||||||
|
_logger.Debug("Created new MessageId: [{0}]", oMessageId);
|
||||||
|
|
||||||
|
_logger.Debug("Inserting properties into database.");
|
||||||
foreach (var oItem in pProperties)
|
foreach (var oItem in pProperties)
|
||||||
{
|
{
|
||||||
var oResult = InsertPropertyMap(oItem, oMessageId);
|
var oResult = InsertPropertyMap(oItem, oMessageId);
|
||||||
@ -169,17 +189,16 @@ namespace ZUGFeRDRESTService.Controllers
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_logger.Debug("Calling validation prodecure.");
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
using SqlCommand oCommand = new SqlCommand("PRCUST_INV_CHECK_FROM_PORTAL @MESSAGE_ID, @MSG_OUTPUT");
|
using SqlCommand oCommand = new SqlCommand("EXEC PRCUST_INV_CHECK_FROM_PORTAL @REF_GUID, @MSG_OUTPUT");
|
||||||
oCommand.CommandType = System.Data.CommandType.StoredProcedure;
|
oCommand.Parameters.Add("REF_GUID", System.Data.SqlDbType.VarChar, 250).Value = oMessageId;
|
||||||
oCommand.Parameters.Add("MESSAGE_ID", System.Data.SqlDbType.VarChar).Value = oMessageId;
|
oCommand.Parameters.Add("MSG_OUTPUT", System.Data.SqlDbType.VarChar, 500).Direction = System.Data.ParameterDirection.Output;
|
||||||
oCommand.Parameters.Add("MSG_OUTPUT", System.Data.SqlDbType.VarChar).Direction = System.Data.ParameterDirection.Output;
|
|
||||||
|
|
||||||
if (_database.MSSQL.ExecuteNonQuery(oCommand))
|
if (_database.MSSQL.ExecuteNonQuery(oCommand))
|
||||||
{
|
{
|
||||||
string oReturnValue = (string)oCommand.Parameters["MSG_OUTPUT"].Value;
|
string oReturnValue = (string)oCommand.Parameters["MSG_OUTPUT"].Value;
|
||||||
|
|
||||||
return new Tuple<bool, string>(true, oReturnValue);
|
return new Tuple<bool, string>(true, oReturnValue);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user