Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EdiSegmentGroup not parsing the whole Segment #36

Closed
Nekeniehl opened this issue Apr 5, 2017 · 5 comments
Closed

EdiSegmentGroup not parsing the whole Segment #36

Nekeniehl opened this issue Apr 5, 2017 · 5 comments
Assignees
Labels

Comments

@Nekeniehl
Copy link
Contributor

Nekeniehl commented Apr 5, 2017

Hi there, I'm not sure if this is a bug or a bad using of EdiAttributes from my side. I have created a EdiSegmentGroup to parse to a complex type, the segment is called "SG1" which basically contains a RFF (code and qualifier) and a optional DTM(code, date, format). I have made almost the same structure with the NAD segment which is actually working fine, but not for the SG1. Here the structure I want to follow

2017-04-04_15-09-21

Here a Test Message:

UNA:+.? 'UNB+UNOC:3+9900080000007:500+990000000000X:500+160321:1425+DAREFNR0000001'UNH+9IMX20YSP0009+ORDRSP:D:10A:UN:1.1e'BGM+Z12+IM20U000000000CNF'DTM+137:201603211421:203'IMD++Z14+Z07'DTM+203:20151023:102'DTM+Z02:20110408:102'IMD++Z01'IMD++Z10'IMD++Z14+Z06'RFF+ON:00001672'DTM+171:201510231149:203'RFF+Z13:19101'AJT+Z15'NAD+MS+9900080000007::293'CTA+IC+:Spiderman, Clark'COM+?+49 123 456 8652:TE'COM+marktpartner@something.de:EM'NAD+MR+990000000000X::293'NAD+DP'LOC+172+DE12345610243DE0000000000000XXXXX'CUX+2:EUR:9'LIN+1++9900010000649:Z01'QTY+145:1:PCS'MOA+203:825'FTX+ACB+++Text1:Text2:Text3:Text4:Text5'PRI+CAL:50.5'RFF+Z09:8465929523'RFF+Z06:7'UNS+S'MOA+24:9'UNT+17+9IM20YSP9'UNZ+1+DAREFNR00001'

And here the POCO Class (Not completed)

public class ORDRSP : FormatBase
    {
        private List<Nachricht> _listnachricht;

        #region Properties

        public List<Nachricht> ListNachricht
        {
            get { return _listnachricht; }
            set { _listnachricht = value; }
        }

        #endregion

        #region Nested type: CTA

        [EdiPath("CTA[0][0]")]
        [EdiSegment]
        public class CTA
        {
            private string _funktion;

            private string _kontakt;

            private string _kontaktnummer;

            #region Properties

            [EdiValue("X(3)", "CTA/0/0")]
            public string Funktion
            {
                get { return _funktion; }
                set { _funktion = value; }
            }

            [EdiValue("X(17)", "CTA/1/0")]
            public string Kontaktnummer
            {
                get { return _kontaktnummer; }
                set { _kontaktnummer = value; }
            }

            [EdiValue("X(0)", "CTA/1/1")]
            public string Kontakt
            {
                get { return _kontakt; }
                set { _kontakt = value; }
            }

            #endregion
        }

        #endregion

        #region Nested type: DTM

        [EdiSegment]
        [EdiPath("DTM[0][0]")]
        public class DTM
        {
            private string _code;

            private string _datum;

            private string _format;

            #region Properties

            [EdiValue("X(3)", "DTM/0/0")]
            public string Code
            {
                get { return _code; }
                set { _code = value; }
            }

            [EdiValue("X(35)", "DTM/0/1")]
            public string Datum
            {
                get { return _datum; }
                set { _datum = value; }
            }

            [EdiValue("X(3)", "DTM/0/2")]
            public string Format
            {
                get { return _format; }
                set { _format = value; }
            }

            #endregion
        }

        #endregion

        #region Nested type: Nachricht

        [EdiMessage]
        public class Nachricht
        {
            private NAD _absender;
            private NAD _empfaenger;

            #region Properties

            [EdiCondition("MR", "NAD[0][0]")]
            public NAD Empfaenger
            {
                get { return _empfaenger; }
                set { _empfaenger = value; }
            }

            [EdiCondition("MS", "NAD[0][0]")]
            public NAD Absender
            {
                get { return _absender; }
                set { _absender = value; }
            }

            [EdiCondition("ON", "RFF[0][0]")]
            public SG1 Referenz_der_Anfrage { get; set; }
            #endregion
        }

        #endregion

        #region Nested type: NAD

        [EdiSegmentGroup("NAD[0][0]")]
        public class NAD
        {
            private string _code;

            private CTA _cta;

            private string _id;
            private string _qualifier;

            #region Properties

            [EdiValue("X(3)", "NAD/0/0")]
            public string Qualifier
            {
                get { return _qualifier; }
                set { _qualifier = value; }
            }

            [EdiValue("X(35)", "NAD/1/0")]
            public string ID
            {
                get { return _id; }
                set { _id = value; }
            }

            [EdiValue("X(3)", "NAD/1/2")]
            public string Code
            {
                get { return _code; }
                set { _code = value; }
            }

            public CTA CTA
            {
                get { return _cta; }
                set { _cta = value; }
            }

            #endregion
        }

        #endregion

        #region Nested type: SG1

        [EdiSegmentGroup("RFF")]
        public class SG1
        {
            private RFF _referenz;

            private DTM _referenzDatum;

            #region Properties

            //[EdiCondition("ON", "RFF[0][0]")]
            public RFF ReferenzderAnfrage
            {
                get { return _referenz; }
                set { _referenz = value; }
            }

            //[EdiCondition("171", "DTM[0][0]")]
            public DTM Referenz_der_Anfragedatum
            {
                get { return _referenzDatum; }
                set { _referenzDatum = value; }
            }

            #endregion
        }

        #endregion

        #region Nested type: RFF

        [EdiSegment]
        [EdiPath("RFF[0][0]")]
        public class RFF
        {
            private string _code;

            private string _qualifier;

            #region Properties

            [EdiValue("X(70)", "RFF/0/0")]
            public string Code
            {
                get { return _code; }
                set { _code = value; }
            }

            [EdiValue("X(3)", "RFF/0/1")]
            public string Qualifier
            {
                get { return _qualifier; }
                set { _qualifier = value; }
            }

            #endregion
        }

        #endregion
    }

I have try with several different configurations without success, like it is now, you will get parsed the both NAD's and SG1 date but not the reference.

I also tried to add the following lines in the Nachricht class and is working fine everything, but I think is not the correct structure since the DTM is dependent (or child) for the RFF

[EdiCondition("ON", "RFF[0][0]")]
public RFF ReferenzderAnfrage { get; set; }

[EdiCondition("171", "DTM[0][0]")]
public DTM Referenz_der_Anfragedatum { get; set; }

Hope you can help me out, thanks in advance!

@cleftheris
Copy link
Contributor

Hi @Nekeniehl would it be possible to add a failing unit test with your sample and classes? The current solution needs VS2017 to work. Just fork the code, add your test models + sample transmission + failing unit test and make a pull request.

Will look into this ASAP.

On another note I think I stumbled upon a bug with the condition issue #35 and have not found the time to overcome this.

@Nekeniehl
Copy link
Contributor Author

I'm having some troubles to install the DotNetCore for VS 2015 to run the project, I will install then the community vs 2017 tomorrow and make the pull request. Thanks again!

@Nekeniehl
Copy link
Contributor Author

I might found the problem, maybe you can verified it:
If I decorate the classes as follows:

[EdiMessage]
public class Nachricht
{
    [EdiCondition("ON", Path = "RFF/0/0")]
    public SG1 Referenz_der_Anfrage { get; set; }

    [EdiCondition("Z13", Path = "RFF/0/0")]
    public SG1 Prüfindikator{ get; set; }
}

[EdiSegment]
[EdiPath("RFF/0/0")]
public class RFF
{
    [EdiValue("X(70)", Path = "RFF/0/0")]
    public string Code { get; set; }

    [EdiValue("X(3)", Path = "RFF/0/1")]
    public string Qualifier { get; set; }
}

[EdiSegment]
[EdiPath("DTM/0/0")]
public class DTM
{
    #region Properties

    [EdiValue("X(3)", Path = "DTM/0/0")]
    public string Code { get; set; }

    [EdiValue("X(35)", Path = "DTM/0/1")]
    public string Datum { get; set; }

    [EdiValue("X(3)", Path = "DTM/0/2")]
    public string Format { get; set; }

    #endregion
}

[EdiSegmentGroup("RFF")]
public class SG1
{
    public RFF Referenz { get; set; }

    public DTM Referenz_Datum { get; set; }
}

The serialization serializes just the DTM for the conditional RFF named as Referenz_der_Anfrage, but if I modified the SG1 class like the following:

[EdiSegmentGroup("RFF")]
public class SG1
{
    [EdiValue("X(70)", Path = "RFF/0/0")]
    public string Code { get; set; }

    [EdiValue("X(3)", Path = "RFF/0/1")]
    public string Qualifier { get; set; }

    public DTM Referenz_Datum { get; set; }
}

Both RFF are working fine. So I guess it was my bad in the using of the EdiSegmentGroupAttribute, please confirm this.

@cleftheris
Copy link
Contributor

Yes you are correct 👍

as stated on this similar issue #32 comment

Classes that are decorated with Segment, SegmentGroup, Message, Group or Interchange consume the segment that defines the contrainer and cannot be reused inside them. If that makes sense you cannot have a Segment loop class RffLoop and an otherone inside Rff mapped to the same segment. The inner one will not map. The solution is simple: just map the properties of the segment to the container class (RffLoop in the example above).

Glad you managed to overcome this. Should I close the issue?

@Nekeniehl
Copy link
Contributor Author

Nekeniehl commented Apr 6, 2017

Understood, thanks again!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants