zugferdrestapi: Fix missing properties
This commit is contained in:
parent
5ac28e2032
commit
acaa2e7ad6
@ -77,54 +77,47 @@ 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="files">This parameter's name needs to correspond to the html form's file-input name</param>
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
public async Task<ValidationResponse> Post(IFormFile file, string user_id)
|
public async Task<ValidationResponse> Post(IFormFile file, string user_id)
|
||||||
{
|
{
|
||||||
_logger.Debug("Start processing request to ValidationController");
|
_logger.Debug("Start processing request to ValidationController");
|
||||||
|
|
||||||
string oFilePath = Path.Combine(Path.GetTempPath(), file.FileName);
|
|
||||||
|
|
||||||
_logger.Debug("Saving file to temp-path [{0}]", oFilePath);
|
|
||||||
|
|
||||||
using FileStream oStream = new FileStream(oFilePath, FileMode.Create);
|
|
||||||
await file.CopyToAsync(oStream);
|
|
||||||
|
|
||||||
// TODO: Delete temp file / Do we even need the temp file?
|
|
||||||
|
|
||||||
_logger.Debug("File successfully saved!");
|
|
||||||
|
|
||||||
CrossIndustryDocumentType oDocument;
|
CrossIndustryDocumentType oDocument;
|
||||||
PropertyValues.CheckPropertyValuesResult oResult = new PropertyValues.CheckPropertyValuesResult();
|
PropertyValues.CheckPropertyValuesResult oResult = new PropertyValues.CheckPropertyValuesResult();
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
_logger.Debug("Extracting ZUGFeRD Data from file [{0}]", oFilePath);
|
using Stream oStream = file.OpenReadStream();
|
||||||
|
|
||||||
oDocument = _zugferd.ExtractZUGFeRDFileWithGDPicture(oFilePath);
|
|
||||||
|
|
||||||
_logger.Debug("Checking ZUGFeRD Data against the database");
|
|
||||||
|
|
||||||
oResult = _props.CheckPropertyValues(oDocument, _propertyMap, "MESSAGEID");
|
|
||||||
|
|
||||||
_logger.Debug("Result of checking against the database: {0} valid properties, {1} missing properties",
|
|
||||||
oResult.ValidProperties.Count, oResult.MissingProperties.Count);
|
|
||||||
|
|
||||||
if (oResult.MissingProperties.Count > 0) {
|
|
||||||
throw new ZUGFeRDExecption(ZUGFeRDInterface.ErrorType.MissingProperties,
|
|
||||||
"Die hochgeladene Datei ist eine gültige ZUGFeRD-Rechnung, allerdings fehlen benötigte Daten.");
|
|
||||||
}
|
|
||||||
|
|
||||||
string oMessage = "Die hochgeladene Datei ist eine gültige-ZUGFeRD Rechnung";
|
|
||||||
|
|
||||||
_logger.Debug($"Replying with: [{oMessage}]");
|
|
||||||
|
|
||||||
return new ValidationResponse()
|
|
||||||
{
|
{
|
||||||
status = RESPONSE_OK,
|
_logger.Debug("Extracting ZUGFeRD Data from file [{0}]", file.FileName);
|
||||||
message = oMessage
|
|
||||||
|
oDocument = _zugferd.ExtractZUGFeRDFileWithGDPicture(oStream);
|
||||||
|
|
||||||
|
_logger.Debug("Checking ZUGFeRD Data against the database");
|
||||||
|
|
||||||
|
oResult = _props.CheckPropertyValues(oDocument, _propertyMap, "MESSAGEID");
|
||||||
|
|
||||||
|
_logger.Debug("Result of checking against the database: {0} valid properties, {1} missing properties",
|
||||||
|
oResult.ValidProperties.Count, oResult.MissingProperties.Count);
|
||||||
|
|
||||||
|
if (oResult.MissingProperties.Count > 0)
|
||||||
|
{
|
||||||
|
throw new ZUGFeRDExecption(ZUGFeRDInterface.ErrorType.MissingProperties,
|
||||||
|
"Die hochgeladene Datei ist eine gültige ZUGFeRD-Rechnung, allerdings fehlen benötigte Daten.");
|
||||||
|
}
|
||||||
|
|
||||||
|
string oMessage = "Die hochgeladene Datei ist eine gültige-ZUGFeRD Rechnung";
|
||||||
|
|
||||||
|
_logger.Debug($"Replying with: [{oMessage}]");
|
||||||
|
|
||||||
|
return new ValidationResponse()
|
||||||
|
{
|
||||||
|
status = RESPONSE_OK,
|
||||||
|
message = oMessage
|
||||||
|
};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
catch (ZUGFeRDExecption ex)
|
catch (ZUGFeRDExecption ex)
|
||||||
@ -154,14 +147,15 @@ namespace ZUGFeRDRESTService.Controllers
|
|||||||
return new ValidationResponse()
|
return new ValidationResponse()
|
||||||
{
|
{
|
||||||
status = RESPONSE_ERROR,
|
status = RESPONSE_ERROR,
|
||||||
message = oMessage
|
message = oMessage,
|
||||||
|
errors = oErrors
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
_logger.Error(ex);
|
_logger.Error(ex);
|
||||||
|
|
||||||
string oMessage = "Die hochgeladene Datei kann nicht validiert werden!";
|
string oMessage = "Die hochgeladene Datei kann nicht validiert werden, weil ein unbekannter Fehler aufgetreten ist.";
|
||||||
|
|
||||||
_logger.Debug($"Replying with: [{oMessage}]");
|
_logger.Debug($"Replying with: [{oMessage}]");
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user