Click here to Skip to main content
15,888,600 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I would like to check to see if the po number the user submitted is the same as the one in the case using if statement. If the po number is not the same, I want to throw an exception "PO Number does not match the one in the case"

The case is an xml document saved in objXmlCaseDoc.

My vb code
VB
Option Strict On
Option Explicit On
Imports System.Xml

Public Class BcaPoRequests

    Shared Sub Main()
        Dim objMessageProcessor As New MessageProcessor
        Dim objSchemasCollection As New Msc.Integration.MessageBroker.Library.v4.SchemasCollection
        Dim objTransformsCollection As New Msc.Integration.MessageBroker.Library.v4.TransformsCollection

        objMessageProcessor.ProcessInputQueue(False, False, objSchemasCollection, objTransformsCollection)

    End Sub

    Private Class MessageProcessor
        Inherits Msc.Integration.ServiceCatalog.Library.v4.SoapMessageProcessor

        Protected Overrides Sub ProcessMessage(ByRef aobjBroker As ServiceCatalog.Library.v4.Broker, ByRef aobjXMLInputSoapEnvelopeDoc As System.Xml.XmlDocument, ByRef aobjInstantiatedObjectsCollection As Microsoft.VisualBasic.Collection, ByRef aobjConsumer As ServiceCatalog.Library.v4.Consumer)
            MyBase.ProcessMessage(aobjBroker, aobjXMLInputSoapEnvelopeDoc, aobjInstantiatedObjectsCollection, aobjConsumer)

            Dim objXmlMessageDoc As XmlDocument
            Dim objXmlMessageNode As XmlNode
            Dim objNameTable As NameTable
            Dim objXMLNameSpaceManager As XmlNamespaceManager
            Dim objXMLSchemaException As Xml.Schema.XmlSchemaException
            Dim strCaseNumber As String
            Dim strPoNumber As String
            Dim objXmlCaseDoc As XmlDocument
            Dim objXmlResponseDoc As XmlDocument
            Dim mobjSchemasLock As New Object
            Dim objXMLOutputSoapEnvelopeDoc As XmlDocument

            'create a namespace manager used for queries into inputmessage (because of namespace)
            objNameTable = New NameTable
            objXMLNameSpaceManager = New XmlNamespaceManager(objNameTable)
            objXMLNameSpaceManager.AddNamespace("ext", "http://www.courts.state.mn.us/ProtectionOrderExtension/1.0")
            objXMLNameSpaceManager.AddNamespace("exc", "http://www.courts.state.mn.us/ProtectionOrderQuery/1.0")
            objXMLNameSpaceManager.AddNamespace("soap", "http://www.w3.org/2003/05/soap-envelope")
            objXMLNameSpaceManager.AddNamespace("wsa", "http://schemas.xmlsoap.org/ws/2004/08/addressing")

            objXmlMessageNode = aobjXMLInputSoapEnvelopeDoc.DocumentElement.SelectSingleNode("soap:Body/exc:ProtectionOrderQueryRequest", objXMLNameSpaceManager)
            objXmlMessageDoc = New XmlDocument

            objXmlMessageDoc.LoadXml(objXmlMessageNode.OuterXml)

            'Check authorization

            'Validate the input message
            objXMLSchemaException = aobjBroker.ValidateXmlDocument(objXmlMessageDoc, "ProtectionOrderQuery_1_0.xsd", "NiemExchanges\ProtectionOrders\Exchange", , False)

            If Not objXMLSchemaException Is Nothing Then
                'return fault if invalid
                aobjBroker.Reply(aobjBroker.CreateSoapFault(Msc.Integration.Utility.Library.v4.Soap.udtSoapCodes.Sender, Msc.Integration.Utility.Library.v4.Xml.FormatXmlSchemaValidationErrorText(objXMLSchemaException), Msc.Integration.Utility.Library.v4.Soap.udtSoapRoles.RoleUltimateReceiver, aobjXMLInputSoapEnvelopeDoc, "soap:InvalidMessage", "soap:Body", Msc.Integration.Utility.Library.v4.Soap.GetReplyEndpointReference(aobjXMLInputSoapEnvelopeDoc), aobjXMLInputSoapEnvelopeDoc.DocumentElement.SelectSingleNode("soap:Header/wsa:MessageID", objXMLNameSpaceManager).InnerText, aobjConsumer))
                Exit Sub
            End If

            'Get the case number and the PO number from the input message
            strCaseNumber = objXmlMessageDoc.DocumentElement.SelectSingleNode("ext:CourtFileNumber", objXMLNameSpaceManager).InnerText
            strPoNumber = objXmlMessageDoc.DocumentElement.SelectSingleNode("ext:ProtectionOrderID", objXMLNameSpaceManager).InnerText


            'Get the case information from Mncis

            'Code for calling the case
            'Catch the error if there is no case number on this case
            Try
                objXmlCaseDoc = Msc.Integration.Mncis.Library.v4.Case.GetIxmlForCaseNumber(strCaseNumber, "CourtCaseHeader,ProtectionOrder,SubjectParties,HearingTrialSetting", False)
            Catch ex As Exception
                aobjBroker.Reply(aobjBroker.CreateSoapFault(Msc.Integration.Utility.Library.v4.Soap.udtSoapCodes.Sender, ex.Message, Msc.Integration.Utility.Library.v4.Soap.udtSoapRoles.RoleUltimateReceiver, aobjXMLInputSoapEnvelopeDoc, "soap:InvalidMessage", "soap:Body", Msc.Integration.Utility.Library.v4.Soap.GetReplyEndpointReference(aobjXMLInputSoapEnvelopeDoc), aobjXMLInputSoapEnvelopeDoc.DocumentElement.SelectSingleNode("soap:Header/wsa:MessageID", objXMLNameSpaceManager).InnerText, aobjConsumer))
                Exit Sub
            End Try

            'Check if the PO on this case is the same as the one user submitted
            'How do I use a if statement to see if the PO submitted is the same as the one in the case?


            aobjBroker.Reply(aobjBroker.CreateSoapFault(Msc.Integration.Utility.Library.v4.Soap.udtSoapCodes.Sender, "Po does not exist", Msc.Integration.Utility.Library.v4.Soap.udtSoapRoles.RoleUltimateReceiver, aobjXMLInputSoapEnvelopeDoc, "soap:InvalidMessage", "soap:Body", Msc.Integration.Utility.Library.v4.Soap.GetReplyEndpointReference(aobjXMLInputSoapEnvelopeDoc), aobjXMLInputSoapEnvelopeDoc.DocumentElement.SelectSingleNode("soap:Header/wsa:MessageID", objXMLNameSpaceManager).InnerText, aobjConsumer))
            'Exit Sub
            'End Try
            End If

            'Tranform case information into the output format
            'set the protectionOrderNumber
            objXmlCaseDoc.DocumentElement.SetAttribute("protectionOrderNumber", strPoNumber)

            'Run stylesheet
            objXmlResponseDoc = aobjBroker.TransformXmlDocument(objXmlCaseDoc, "MNCIS_PO_BCA_Requests_1_0.xsl", "BCA")

            'Validate the xml. validate the reply message
            SyncLock mobjSchemasLock
                objXMLSchemaException = aobjBroker.ValidateXmlDocument(objXmlCaseDoc, "ProtectionOrderQuery_1_0.xsd", "NiemExchanges\ProtectionOrders\Exchange", , False)
            End SyncLock
            If Not objXMLSchemaException Is Nothing Then
                'for now only log a warning if invalid
                aobjBroker.LogApplicationEvent("Invalid Reply Generated: " + objXMLSchemaException.Message, EventLogEntryType.Warning)

            End If

            'Create the SOAP envelope to return the reply to the submitter
            objXMLOutputSoapEnvelopeDoc = aobjBroker.CreateSoapEnvelope("http://www.courts.state.mn.us/ProtectionOrderQuery/1.0", _
              Msc.Integration.Utility.Library.v4.Soap.GetReplyEndpointReference(aobjXMLInputSoapEnvelopeDoc), _
              objXmlResponseDoc.DocumentElement, , aobjConsumer, _
              aobjXMLInputSoapEnvelopeDoc.DocumentElement.SelectSingleNode("soap:Header/wsa:MessageID", objXMLNameSpaceManager).InnerText)


            'Return the response to the requester
            aobjBroker.Reply(objXMLOutputSoapEnvelopeDoc)

        End Sub

    End Class

End Class
Posted

1 solution

This is how I resolved this issue

VB
If objXmlCaseDoc.DocumentElement.SelectSingleNode("ProtectionOrder[ProtectionOrderNumber='" + strPoNumber + "']", objXMLNameSpaceManager) Is Nothing Then

aobjBroker.Reply(aobjBroker.CreateSoapFault(Msc.Integration.Utility.Library.v4.Soap.udtSoapCodes.Sender, "Protection Order " + strPoNumber + " for case " + strCaseNumber + " not found.", Msc.Integration.Utility.Library.v4.Soap.udtSoapRoles.RoleUltimateReceiver, aobjXMLInputSoapEnvelopeDoc, "soap:InvalidMessage", "soap:Body", Msc.Integration.Utility.Library.v4.Soap.GetReplyEndpointReference(aobjXMLInputSoapEnvelopeDoc), aobjXMLInputSoapEnvelopeDoc.DocumentElement.SelectSingleNode("soap:Header/wsa:MessageID", objXMLNameSpaceManager).InnerText, aobjConsumer))
    Exit Sub
 End If
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900