IFS Smartfreight plugin and dangerous goods  Topic is solved

Discussions relating to plugin development, and the Jiwa API.

Re: IFS Smartfreight plugin and dangerous goods

Postby DannyC » Mon Feb 20, 2023 8:11 am

You'll need to do the same.

I would if I could. Firstly I have no idea of the difference between POCO and non-POCO, in fact I had never heard of that term until I read the comments in the plugin.
My programming nouse is typically gleaned from finding something which is known working, and tweaking it to fit. I.e. I have no formal training in coding (I guess you can tell over the years :lol: not counting 1 semester of COBOL 30 years ago!!).
I know we're all under the pump but I just need a little more guidance, ideally some corrected code.
User avatar
DannyC
Senpai
Senpai
 
Posts: 636
Joined: Fri Mar 22, 2013 12:23 pm
Topics Solved: 30

Re: IFS Smartfreight plugin and dangerous goods

Postby SBarnes » Mon Feb 20, 2023 9:25 am

A POCO stands for Plain Old CLR object, it simply means a class with only public properties and no functionality, for example in Jiwa the Sales Order object is not a POCO as it contains functionality but JiwaFinancials.Jiwa.JiwaSales.SalesOrder.XML.SalesOrder is, as it is the structure onto which the sales order can be mapped and then serialized to XML.

Similarly a DTO, Data Transfer Object is used for a similar purpose in the api and does not contain functionality.

What Mike is saying is the XML does not map correctly for things like lists, so its not actually legitimate XML in the strictest sense.

The Code Mike was referring to is below where he uses the XML document to move the nodes and then removes the unwanted nodes, if you follow the same logic steps for dangerous goods you should get the desired result in adding to this function.


Code: Select all
 Public Function Serialise() As System.Xml.XmlDocument

            ' About the SmartFreight XML Format
            ' =================================
            ' Unfortunately the smartfreight XML format does not map nicely to a POCO's with lists.  An example is the freightlines.
            '
            'Example showing multiple freight lines:
            '<connotes>
            '   <connote>
            '       <freightlinedetails>
            '           <ref>MY REF 1111</ref>
            '           <desc>CARTON</desc>
            '           <amt>6</amt>
            '           <wgt>52.45</wgt>
            '       </freightlinedetails>
            '       <freightlinedetails>
            '           <desc>PALLET</desc>
            '           <amt>1</amt>
            '           <wgt>112</wgt>
            '       </freightlinedetails>
            '   </connote>
            '</connotes>

            'Example showing multiple freight lines if it were mappable directly to a POCO:
            '<connotes>
            '   <connote>
            '       <freightlinedetails>
            '           <freightlinedetail>
            '               <ref>MY REF 1111</ref>
            '               <desc>CARTON</desc>
            '               <amt>6</amt>
            '               <wgt>52.45</wgt>
            '           </freightlinedetail>
            '           <freightlinedetail>
            '               <desc>PALLET</desc>
            '               <amt>1</amt>
            '               <wgt>112</wgt>
            '           <freightlinedetail>
            '       </freightlinedetails>
            '   </connote>
            '</connotes>
            '
            ' So, we can't simply serialise the whole connote - we need to serialise then remove the freightlines node,
            ' then add the each freightline manually.  If we didn't have to do this, serialise would be as simple as:
            'Dim stringWriter As New System.IO.StringWriter
            'Dim xmlSerializer As New System.Xml.Serialization.XmlSerializer(GetType(XML.connote))
            'Dim xmlNamespaces As New System.Xml.Serialization.XmlSerializerNamespaces()
            'xmlNamespaces.Add("", "")

            'xmlSerializer.Serialize(stringWriter, Me, xmlNamespaces)

            'Return stringWriter.ToString
            'stringWriter.Close()
            'stringWriter.Dispose()
         
         If applyleastcost Then
                applyleastcostSpecified = True
            End If

            Dim xmlDocument As New System.Xml.XmlDocument()
            Dim xPathNavigator As System.Xml.XPath.XPathNavigator = xmlDocument.CreateNavigator()
            Using xmlWriter As System.Xml.XmlWriter = xPathNavigator.AppendChild()
                Dim ser As New System.Xml.Serialization.XmlSerializer(GetType(XML.connote), "")
                ser.Serialize(xmlWriter, Me)
            End Using

            Dim conNoteNode As System.Xml.XmlNode = xmlDocument.SelectSingleNode("/connote")

            ' Now find the parent freightlinedetails node
            Dim freightlinedetailscontainerNode As System.Xml.XmlNode = xmlDocument.SelectSingleNode("/connote/freightlinedetails")
            If freightlinedetailscontainerNode IsNot Nothing Then

                'Move all the child nodes to their grandparent (the connote)
                While freightlinedetailscontainerNode.HasChildNodes
                    conNoteNode.InsertBefore(freightlinedetailscontainerNode.ChildNodes(0), freightlinedetailscontainerNode)
                End While

                ' Remove the container node
                conNoteNode.RemoveChild(freightlinedetailscontainerNode)
            End If

            ' Now find the additional references node
            Dim additionalReferencesContainerNode As System.Xml.XmlNode = xmlDocument.SelectSingleNode("/connote/additionalreferences")
            If additionalReferencesContainerNode IsNot Nothing Then

                ' Remove the container node
                conNoteNode.RemoveChild(additionalReferencesContainerNode)

                ' Add a new additionalreferences node
                Dim additionalreferencesElement As System.Xml.XmlElement = xmlDocument.CreateElement("additionalreferences")
                conNoteNode.AppendChild(additionalreferencesElement)

                For Each additionalreference As additionalreference In additionalreferences
                    Dim referenceNoElement As System.Xml.XmlElement = xmlDocument.CreateElement("referenceno")
                    referenceNoElement.InnerText = additionalreference.referenceno
                    additionalreferencesElement.AppendChild(referenceNoElement)
                Next

            End If

            Return xmlDocument

        End Function
Regards
Stuart Barnes
SBarnes
Shihan
Shihan
 
Posts: 1619
Joined: Fri Aug 15, 2008 3:27 pm
Topics Solved: 175

Re: IFS Smartfreight plugin and dangerous goods

Postby pricerc » Mon Feb 20, 2023 10:08 am

Mike.Sheen wrote:obviously didn't use industry accepted serialiser/deserialisers


It has always amazed me how much software seems to get something as simple as XML wrong.

I think JSON is marginly better because people aren't as spooked by the formality of XML, XSL, and XSD, but even JSON has a few interesting interpretations and implementations.
/Ryan

ERP Consultant,
Advanced ERP Limited, NZ
https://aerp.co.nz
User avatar
pricerc
Senpai
Senpai
 
Posts: 504
Joined: Mon Aug 10, 2009 12:22 pm
Location: Auckland, NZ
Topics Solved: 20

Re: IFS Smartfreight plugin and dangerous goods

Postby Mike.Sheen » Mon Feb 20, 2023 11:39 am

pricerc wrote:
Mike.Sheen wrote:but even JSON has a few interesting interpretations and implementations.


Oh, yes.

I came across one API which returned JSON for a list of countries and their response came back as:

Code: Select all
{
    { "Australia" : "AU" },
    { "Brazil" : "BR" },
    ...
}


It might seem readable to a human, but for the least amount of friction to try and deserialise that I'd need a poco that looked like:

Code: Select all
public class Countries
{
   public string Australia { get; set; }
   public string Brazil { get; set; }
   ...
}


I guess they never experienced or anticipated a period of time where countries changed names or anything, so a class of static property names would be fine, right?
Mike Sheen
Chief Software Engineer
Jiwa Financials

If I do answer your question to your satisfaction, please mark it as the post solving the topic so others with the same issue can readily identify the solution
User avatar
Mike.Sheen
Overflow Error
Overflow Error
 
Posts: 2444
Joined: Tue Feb 12, 2008 11:12 am
Location: Perth, Republic of Western Australia
Topics Solved: 756

Re: IFS Smartfreight plugin and dangerous goods

Postby SBarnes » Mon Feb 20, 2023 11:45 am

Unfortunately I've seen the same thing elsewhere and recently I don't know if this would work in ServiceStack but the answer in NewtonSoft was Dictionary<string, string>
Regards
Stuart Barnes
SBarnes
Shihan
Shihan
 
Posts: 1619
Joined: Fri Aug 15, 2008 3:27 pm
Topics Solved: 175

Re: IFS Smartfreight plugin and dangerous goods

Postby pricerc » Mon Feb 20, 2023 5:06 pm

SBarnes wrote:Unfortunately I've seen the same thing elsewhere and recently I don't know if this would work in ServiceStack but the answer in NewtonSoft was Dictionary<string, string>


NewtonSoft has some cool features - like a functional XML/JSON converter.

And it will deserialize "0" into an integer or float property where the new System.Text.Json spits the dummy because its a "string".
/Ryan

ERP Consultant,
Advanced ERP Limited, NZ
https://aerp.co.nz
User avatar
pricerc
Senpai
Senpai
 
Posts: 504
Joined: Mon Aug 10, 2009 12:22 pm
Location: Auckland, NZ
Topics Solved: 20

Re: IFS Smartfreight plugin and dangerous goods

Postby DannyC » Tue Feb 28, 2023 4:19 pm

Once again I got sidetracked for a few days so looking to get back onto this.

Unfortunately the posts from Mike & Stuart have given me no assistance. Whilst they may suggest reasons why it is hard (in language I don't really comprehend) I really need some actual code I can utilize.
Sorry to be a bit dumb but I am just not familiar enough to go beyond what I've already provided in the attached plugin.
User avatar
DannyC
Senpai
Senpai
 
Posts: 636
Joined: Fri Mar 22, 2013 12:23 pm
Topics Solved: 30

Re: IFS Smartfreight plugin and dangerous goods

Postby Mike.Sheen » Tue Feb 28, 2023 4:28 pm

DannyC wrote:Once again I got sidetracked for a few days so looking to get back onto this.

Unfortunately the posts from Mike & Stuart have given me no assistance. Whilst they may suggest reasons why it is hard (in language I don't really comprehend) I really need some actual code I can utilize.
Sorry to be a bit dumb but I am just not familiar enough to go beyond what I've already provided in the attached plugin.


You could ask the Smartfreight people to give you some code in VB or C# which serialises and deserialises their XML format to and from poco's - they may even have a library you can reference.

You could also just do a plugin in your preferred language which acts as your library to serialise and deserialise - and then in your IFS plugin which is in C#, make it call your library.

Usually when faced with such challenges I write a simple console app in Visual Studio to read / write the file - get the bare minimum working, then slowly adapt it to be more library-like and then migrate it to a plugin.
Mike Sheen
Chief Software Engineer
Jiwa Financials

If I do answer your question to your satisfaction, please mark it as the post solving the topic so others with the same issue can readily identify the solution
User avatar
Mike.Sheen
Overflow Error
Overflow Error
 
Posts: 2444
Joined: Tue Feb 12, 2008 11:12 am
Location: Perth, Republic of Western Australia
Topics Solved: 756

Re: IFS Smartfreight plugin and dangerous goods  Topic is solved

Postby SBarnes » Tue Feb 28, 2023 5:51 pm

If it is beyond what you can do you could always get a quote here
Regards
Stuart Barnes
SBarnes
Shihan
Shihan
 
Posts: 1619
Joined: Fri Aug 15, 2008 3:27 pm
Topics Solved: 175

Previous

Return to Technical and or Programming

Who is online

Users browsing this forum: No registered users and 37 guests