211 lines
8.6 KiB
C#
211 lines
8.6 KiB
C#
// Copyright (c) 2015-2017 schick Informatik
|
|
// Description: Hilfsklasse zur Bearbeitung der Antworten / HIS-Nord
|
|
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Xml.Linq;
|
|
using bsmd.database;
|
|
using log4net;
|
|
|
|
namespace bsmd.hisnord
|
|
{
|
|
|
|
public class NSWResponse
|
|
{
|
|
private string _clientRequestId;
|
|
private DateTime _receiveAt;
|
|
private string _notificationId;
|
|
private string _status;
|
|
private string _visitId;
|
|
private string _transitId;
|
|
private Message.NotificationClass _notificationClass;
|
|
|
|
private List<MessageViolation> _violations = new List<MessageViolation>();
|
|
private List<MessageError> _errors = new List<MessageError>();
|
|
|
|
private Guid? _messageCoreId;
|
|
private ILog _log = LogManager.GetLogger(typeof(NSWResponse));
|
|
|
|
public NSWResponse(XElement xml)
|
|
{
|
|
XNamespace ns1 = "http://api.national-single-window.de/visitIdRequest";
|
|
XNamespace ns6 = "http://api.national-single-window.de/receipt";
|
|
//XNamespace ns15 = "http://api.national-single-window.de/statusForClientRequestId";
|
|
XNamespace soap = "http://schemas.xmlsoap.org/soap/envelope/";
|
|
XNamespace ns15 = "http://api.national-single-window.de/visitIdResponse";
|
|
XNamespace ladgNS = "http://api.national-single-window.de/ladg";
|
|
XNamespace hazaNS = "http://api.national-single-window.de/haza";
|
|
XNamespace hazdNS = "http://api.national-single-window.de/hazd";
|
|
XNamespace mdhNS = "http://api.national-single-window.de/mdh";
|
|
XNamespace agntNS = "http://api.national-single-window.de/agnt";
|
|
XNamespace vioNS = "http://api.national-single-window.de/violation";
|
|
XNamespace errNS = "http://api.national-single-window.de/error";
|
|
|
|
|
|
XName idName = "ConveyanceCode";
|
|
var elem = xml.Descendants(idName);
|
|
if (elem.Count() > 0)
|
|
{
|
|
Guid aGuid;
|
|
if (Guid.TryParse(elem.FirstOrDefault()?.Value, out aGuid))
|
|
_messageCoreId = aGuid;
|
|
else
|
|
_log.WarnFormat("cannot parse ConveyanceCode {0}", elem.FirstOrDefault());
|
|
}else
|
|
{
|
|
_log.Warn("NSWResponse does not contain ConveyanceCode!!");
|
|
}
|
|
|
|
// detect response type
|
|
|
|
foreach (Message.NotificationClass messageClassType in Enum.GetValues(typeof(Message.NotificationClass)))
|
|
{
|
|
XName lookupName;
|
|
|
|
switch (messageClassType)
|
|
{
|
|
// we won't get answers for these message types
|
|
case Message.NotificationClass.STO: continue;
|
|
case Message.NotificationClass.CREWD: continue;
|
|
case Message.NotificationClass.PASD: continue;
|
|
|
|
case Message.NotificationClass.VISIT:
|
|
lookupName = ns15 + "VisitIdResponse";
|
|
break;
|
|
case Message.NotificationClass.TRANSIT:
|
|
lookupName = ns15 + "VisitIdResponse";
|
|
break;
|
|
case Message.NotificationClass.LADG:
|
|
lookupName = ladgNS + "LADGResponse";
|
|
break;
|
|
case Message.NotificationClass.HAZA:
|
|
lookupName = hazaNS + "HAZAResponse";
|
|
break;
|
|
case Message.NotificationClass.HAZD:
|
|
lookupName = hazdNS + "HAZDResponse";
|
|
break;
|
|
case Message.NotificationClass.MDH:
|
|
lookupName = mdhNS + "MDHResponse";
|
|
break;
|
|
case Message.NotificationClass.AGNT:
|
|
lookupName = agntNS + "AGNTResponse";
|
|
break;
|
|
default:
|
|
lookupName = "dontmatchmeplease";
|
|
break;
|
|
}
|
|
|
|
if(xml.Descendants(lookupName).Count() > 0)
|
|
{
|
|
|
|
_notificationClass = messageClassType;
|
|
|
|
// match found
|
|
XName xname = ns6 + "ClientRequestId";
|
|
elem = xml.Descendants(xname);
|
|
if (elem.Count() > 0)
|
|
{
|
|
_clientRequestId = elem.First()?.Value;
|
|
}
|
|
|
|
xname = ns6 + "ReceivedAt";
|
|
elem = xml.Descendants(xname);
|
|
if(elem.Count() > 0)
|
|
{
|
|
DateTime.TryParse(elem.First()?.Value, out _receiveAt);
|
|
}
|
|
|
|
xname = ns6 + "NotificationId";
|
|
elem = xml.Descendants(xname);
|
|
if (elem.Count() > 0)
|
|
_notificationId = elem.First()?.Value;
|
|
|
|
xname = ns6 + "Status";
|
|
elem = xml.Descendants(xname);
|
|
if(elem.Count() > 0)
|
|
{
|
|
_status = elem.First()?.Value;
|
|
}
|
|
|
|
xname = ns6 + "VisitId";
|
|
elem = xml.Descendants(xname);
|
|
if(elem.Count() > 0)
|
|
{
|
|
_visitId = elem.First()?.Value;
|
|
}
|
|
|
|
xname = ns6 + "TransitId";
|
|
elem = xml.Descendants(xname);
|
|
if (elem.Count() > 0)
|
|
{
|
|
_transitId = elem.First()?.Value;
|
|
}
|
|
|
|
|
|
// check for violations -------------------------------------------
|
|
xname = ns6 + "Violation";
|
|
XName vCodeName = vioNS + "ViolationCode";
|
|
XName vTextName = vioNS + "ViolationText";
|
|
elem = xml.Descendants(xname);
|
|
foreach(XElement anElem in elem)
|
|
{
|
|
MessageViolation mv = new MessageViolation();
|
|
int vCode = -1;
|
|
if (!Int32.TryParse(anElem.Element(vCodeName).Value, out vCode))
|
|
_log.WarnFormat("cannot convert violation code to int: {0}", anElem.Element(vCodeName).Value);
|
|
else
|
|
mv.ViolationCode = vCode;
|
|
mv.ViolationText = anElem.Element(vTextName).Value;
|
|
_violations.Add(mv);
|
|
}
|
|
|
|
// check for errors ----------------------------------------------
|
|
xname = ns6 + "Error";
|
|
XName eCodeName = errNS + "ErrorCode";
|
|
XName eTextName = errNS + "ErrorText";
|
|
elem = xml.Descendants(xname);
|
|
foreach (XElement anElem in elem)
|
|
{
|
|
MessageError me = new MessageError();
|
|
int eCode = -1;
|
|
if (!Int32.TryParse(anElem.Element(eCodeName).Value, out eCode))
|
|
_log.WarnFormat("cannot convert error code to int: {0}", anElem.Element(eCodeName).Value);
|
|
else
|
|
me.ErrorCode = eCode;
|
|
me.ErrorText = anElem.Element(eTextName).Value;
|
|
_errors.Add(me);
|
|
}
|
|
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
#region Properties
|
|
|
|
public Guid? MessageCoreId { get { return _messageCoreId; } }
|
|
|
|
public string ClientRequestId { get { return _clientRequestId; } }
|
|
|
|
public DateTime? ReceiveAt { get { return _receiveAt; } }
|
|
|
|
public string NotificationId { get { return _notificationId; } }
|
|
|
|
public string Status { get { return this._status; } }
|
|
|
|
public string VisitId { get { return this._visitId; } }
|
|
|
|
public string TransitId { get { return this._transitId; } }
|
|
|
|
public List<MessageViolation> Violations { get { return _violations; } }
|
|
|
|
public List<MessageError> Errors { get { return _errors; } }
|
|
|
|
public Message.NotificationClass NotificationClass { get { return this._notificationClass; } }
|
|
|
|
#endregion
|
|
|
|
}
|
|
|
|
} |