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

Multiple repeated elements within a single segment #272

Open
nochancenine opened this issue Nov 14, 2024 · 4 comments
Open

Multiple repeated elements within a single segment #272

nochancenine opened this issue Nov 14, 2024 · 4 comments

Comments

@nochancenine
Copy link

nochancenine commented Nov 14, 2024

I'm working with a segment PFD that has multiple repeated elements within the segment and also repeated elements within repeated elements.

All the examples I have found seem to only have a single repeated element within a segment. I have other segments like that and they work.

The issue is specifically with multiple repeated elements in the same segment.

image

I have been trying many combinations trying to get these to serialize onto a single PFD segment, but it always seems to split them off into separate PFD segments.

Even if I need to do the Seat Characteristics as 5 individual EdiValue each (not repeated), there are still multiple repeated elements that I haven't been able to get to serialize into a single PFD segment

Is there a way to accomplish this or any workaround method to achieve it?

What I thought I should do is like this:

        [EdiPath("PFD/1/8..*")]
        public PFD_SeatCharacteristic[] SeatCharacteristics { get; set; }

...

Then this:

        [EdiPath("PFD/6..*")]
        public PFD_SeatDetail[] SeatDetails { get; set; }

        [EdiPath("PFD/7..*")]
        public PFD_SeatDefinition[] SeatDefinitions { get; set; }

But that results in

System.InvalidOperationException: 'Failed to compare two elements in the array.'
InvalidCastException: Cannot convert the fragment value "6..*" to an Index. Must be a positive integer

I have been trying different models, but here is a trimmed down one:

    //PFD
    public class Interchange_PFD
    {
        public PFD PFD { get; set; }
    }
    
    [EdiSegment, EdiPath("PFD")]
    public class PFD
    {
        [EdiValue(Path = "PFD/0/0")]
        public string PFD_01A_SpecificSeat { get; set; }

        [EdiValue(Path = "PFD/0/1")]
        public string PFD_01B_FreeSeatingReference { get; set; }

        [EdiValue(Path = "PFD/1/0")]
        public string PFD_02A_NoSmokingIndicator { get; set; }

        [EdiValue(Path = "PFD/1/1")]
        public string PFD_02B_CabinClassDesignator { get; set; }

        [EdiValue(Path = "PFD/1/2")]
        public string PFD_02C_CabinClassNumber { get; set; }

        [EdiValue(Path = "PFD/1/3")]
        public string PFD_02D_FreeTextCabinClassZone { get; set; }

        [EdiValue(Path = "PFD/1/4")]
        public string PFD_02E_SegmentAirportOfDeparture { get; set; }

        [EdiValue(Path = "PFD/1/5")]
        public string PFD_02F_SegmentAirportOfArrival { get; set; }

        [EdiValue(Path = "PFD/1/6")]
        public string PFD_02G_EquipmentCode { get; set; }

        [EdiValue(Path = "PFD/1/7")]
        public string PFD_02H_SeatRequestFullfilledIndicator { get; set; }

        [EdiPath("PFD/1/8..*")]
        public PFD_SeatCharacteristic[] SeatCharacteristics { get; set; }

        [EdiValue(Path = "PFD/2/0")]
        public string PFD_07_PaxIdForBPPrint { get; set; }

        [EdiValue(Path = "PFD/2/1")]
        public string PFD_07_InfantIdForBPPrint { get; set; }

        [EdiValue(Path = "PFD/3/0")]
        public string PFD_08_IssueReissueBoardingPass { get; set; }

        [EdiValue(Path = "PFD/4/0")]
        public string PFD_09_BarcodeForBoardingPass { get; set; }

        [EdiValue(Path = "PFD/5/0")]
        public string PFD_10_PaxPriorityInformation { get; set; }

        [EdiPath("PFD/6..*")]
        public PFD_SeatDetail[] SeatDetails { get; set; }

        [EdiPath("PFD/7..*")]
        public PFD_SeatDefinition[] SeatDefinitions { get; set; }
    }

    [EdiElement]
    public class PFD_SeatCharacteristic
    {
        [EdiValue(Path = "PFD/1/8")]
        public string PFD_02I_SeatCharacteristics { get; set; }
    }

    [EdiElement]
    public class PFD_SeatDetail
    {
        [EdiValue(Path = "*/*/0")]
        public string PFD_11A_SpecificSeat { get; set; }

        [EdiValue(Path = "*/*/1")]
        public string PFD_11B_FreeSeatingReference { get; set; }
    }

    [EdiElement]
    public class PFD_SeatDefinition
    {
        [EdiValue(Path = "*/*/0")]
        public string PFD_12A_NoSmokingIndicator { get; set; }

        [EdiValue(Path = "*/*/1")]
        public string PFD_12B_CabinClassDesignator { get; set; }

        [EdiValue(Path = "*/*/2")]
        public string PFD_12C_CabinClassNumber { get; set; }

        [EdiValue(Path = "*/*/3")]
        public string PFD_12D_FreeTextCabinClassZone { get; set; }

        [EdiValue(Path = "*/*/4")]
        public string PFD_12E_SegmentAirportOfDeparture { get; set; }

        [EdiValue(Path = "*/*/5")]
        public string PFD_12F_SegmentAirportOfArrival { get; set; }

        [EdiValue(Path = "*/*/6")]
        public string PFD_12G_EquipmentCode { get; set; }

        [EdiValue(Path = "*/*/7")]
        public string PFD_12H_SeatRequestFullfilledIndicator { get; set; }

        [EdiValue(Path = "*/*/8")]
        public string PFD_12I_SeatCharacteristics { get; set; }

        [EdiValue(Path = "*/*/9")]
        public string PFD_12J_SeatCharacteristics { get; set; }

        [EdiValue(Path = "*/*/10")]
        public string PFD_12K_SeatCharacteristics { get; set; }

        [EdiValue(Path = "*/*/11")]
        public string PFD_12L_SeatCharacteristics { get; set; }

        [EdiValue(Path = "*/*/12")]
        public string PFD_12M_SeatCharacteristics { get; set; }
    }
            var interchange = new Interchange_PFD()
            {
                PFD = new PFD
                {
                    PFD_01A_SpecificSeat = "12C",
                    PFD_02A_NoSmokingIndicator = "N",
                    PFD_02B_CabinClassDesignator = "M",
                    PFD_02C_CabinClassNumber = "3",
                    PFD_02E_SegmentAirportOfDeparture = "FRA",
                    PFD_02F_SegmentAirportOfArrival = "MEX",
                    PFD_02G_EquipmentCode = "744",
                    SeatCharacteristics = new PFD_SeatCharacteristic []
                    {
                        new PFD_SeatCharacteristic { 
                            PFD_02I_SeatCharacteristics = "Y"
                        },
                        new PFD_SeatCharacteristic {
                            PFD_02I_SeatCharacteristics = "Z"
                        }
                    },
                    PFD_07_PaxIdForBPPrint = "12",
                    PFD_10_PaxPriorityInformation = "M/M",
                    SeatDetails = new PFD_SeatDetail[] {
                                            new PFD_SeatDetail {
                                                PFD_11A_SpecificSeat = "01X"
                                            },
                                            new PFD_SeatDetail {
                                                PFD_11A_SpecificSeat = "02X"
                                            }
                                        },
                    SeatDefinitions = new PFD_SeatDefinition[] {
                                            new PFD_SeatDefinition {
                                                PFD_12A_NoSmokingIndicator = "A"
                                            },
                                            new PFD_SeatDefinition {
                                                PFD_12A_NoSmokingIndicator = "B"
                                            }
                                        }
                }
            };

            var output = new StringBuilder();
            var grammar = EdiGrammar.NewEdiFact();
            using (var writer = new EdiTextWriter(new StringWriter(output), grammar))
            {
                new EdiSerializer() { EnableCompression = true }.Serialize(writer, interchange);
                Debug.Write(output);
            }

Again, the goal is to get these to serialize all into a single PFD segment

Is this possible by any means?

Thank you

@nochancenine
Copy link
Author

nochancenine commented Nov 14, 2024

This didn't seem right, but just trying things and at least doesn't have any errors.

However, it serializes them into separate PFD segments (see below)

    [EdiSegment, EdiPath("PFD")]
    public class PFD
    {
        [EdiValue(Path = "PFD/0/0")]
        public string PFD_01A_SpecificSeat { get; set; }

        [EdiValue(Path = "PFD/0/1")]
        public string PFD_01B_FreeSeatingReference { get; set; }

        [EdiValue(Path = "PFD/1/0")]
        public string PFD_02A_NoSmokingIndicator { get; set; }

        [EdiValue(Path = "PFD/1/1")]
        public string PFD_02B_CabinClassDesignator { get; set; }

        [EdiValue(Path = "PFD/1/2")]
        public string PFD_02C_CabinClassNumber { get; set; }

        [EdiValue(Path = "PFD/1/3")]
        public string PFD_02D_FreeTextCabinClassZone { get; set; }

        [EdiValue(Path = "PFD/1/4")]
        public string PFD_02E_SegmentAirportOfDeparture { get; set; }

        [EdiValue(Path = "PFD/1/5")]
        public string PFD_02F_SegmentAirportOfArrival { get; set; }

        [EdiValue(Path = "PFD/1/6")]
        public string PFD_02G_EquipmentCode { get; set; }

        [EdiValue(Path = "PFD/1/7")]
        public string PFD_02H_SeatRequestFullfilledIndicator { get; set; }

        [EdiValue(Path = "PFD/1/8")]
        public string PFD_02I_SeatCharacteristics { get; set; }

        [EdiValue(Path = "PFD/1/9")]
        public string PFD_02J_SeatCharacteristics { get; set; }

        [EdiValue(Path = "PFD/1/10")]
        public string PFD_02K_SeatCharacteristics { get; set; }

        [EdiValue(Path = "PFD/1/11")]
        public string PFD_02L_SeatCharacteristics { get; set; }

        [EdiValue(Path = "PFD/1/12")]
        public string PFD_02M_SeatCharacteristics { get; set; }

        [EdiValue(Path = "PFD/2/0")]
        public string PFD_07_PaxIdForBPPrint { get; set; }

        [EdiValue(Path = "PFD/2/1")]
        public string PFD_07_InfantIdForBPPrint { get; set; }

        [EdiValue(Path = "PFD/3/0")]
        public string PFD_08_IssueReissueBoardingPass { get; set; }

        [EdiValue(Path = "PFD/4/0")]
        public string PFD_09_BarcodeForBoardingPass { get; set; }

        [EdiValue(Path = "PFD/5/0")]
        public string PFD_10_PaxPriorityInformation { get; set; }

        [EdiPath("PFD/6/0..*")]
        public PFD_SeatDetail[] SeatDetails { get; set; }

        [EdiPath("PFD/7/0..*")]
        public PFD_SeatDefinition[] SeatDefinitions { get; set; }
    }

    [EdiElement]
    public class PFD_SeatDetail
    {
        [EdiValue(Path = "PFD/*/0")]
        public string PFD_11A_SpecificSeat { get; set; }

        [EdiValue(Path = "PFD/*/1")]
        public string PFD_11B_FreeSeatingReference { get; set; }
    }

    [EdiElement]
    public class PFD_SeatDefinition
    {
        [EdiValue(Path = "PFD/*/0")]
        public string PFD_12A_NoSmokingIndicator { get; set; }

        [EdiValue(Path = "PFD/*/1")]
        public string PFD_12B_CabinClassDesignator { get; set; }

        [EdiValue(Path = "PFD/*/2")]
        public string PFD_12C_CabinClassNumber { get; set; }

        [EdiValue(Path = "PFD/*/3")]
        public string PFD_12D_FreeTextCabinClassZone { get; set; }

        [EdiValue(Path = "PFD/*/4")]
        public string PFD_12E_SegmentAirportOfDeparture { get; set; }

        [EdiValue(Path = "PFD/*/5")]
        public string PFD_12F_SegmentAirportOfArrival { get; set; }

        [EdiValue(Path = "PFD/*/6")]
        public string PFD_12G_EquipmentCode { get; set; }

        [EdiValue(Path = "PFD/*/7")]
        public string PFD_12H_SeatRequestFullfilledIndicator { get; set; }

        [EdiValue(Path = "PFD/*/8")]
        public string PFD_12I_SeatCharacteristics { get; set; }

        [EdiValue(Path = "PFD/*/9")]
        public string PFD_12J_SeatCharacteristics { get; set; }

        [EdiValue(Path = "PFD/*/10")]
        public string PFD_12K_SeatCharacteristics { get; set; }

        [EdiValue(Path = "PFD/*/11")]
        public string PFD_12L_SeatCharacteristics { get; set; }

        [EdiValue(Path = "PFD/*/12")]
        public string PFD_12M_SeatCharacteristics { get; set; }
    }
            var interchange = new Interchange_PFD()
            {
                PFD = new PFD
                {
                    PFD_01A_SpecificSeat = "12C",
                    PFD_02A_NoSmokingIndicator = "N",
                    PFD_02B_CabinClassDesignator = "M",
                    PFD_02C_CabinClassNumber = "3",
                    PFD_02E_SegmentAirportOfDeparture = "FRA",
                    PFD_02F_SegmentAirportOfArrival = "MEX",
                    PFD_02G_EquipmentCode = "744",
                    SeatCharacteristics = new PFD_SeatCharacteristic []
                    {
                        new PFD_SeatCharacteristic { 
                            PFD_02I_SeatCharacteristics = "Y"
                        },
                        new PFD_SeatCharacteristic {
                            PFD_02I_SeatCharacteristics = "Z"
                        }
                    },
                    PFD_07_PaxIdForBPPrint = "12",
                    PFD_10_PaxPriorityInformation = "M/M",
                    SeatDetails = new PFD_SeatDetail[] {
                                            new PFD_SeatDetail {
                                                PFD_11A_SpecificSeat = "01X"
                                            },
                                            new PFD_SeatDetail {
                                                PFD_11A_SpecificSeat = "02X"
                                            }
                                        },
                    SeatDefinitions = new PFD_SeatDefinition[] {
                                            new PFD_SeatDefinition {
                                                PFD_12A_NoSmokingIndicator = "A"
                                            },
                                            new PFD_SeatDefinition {
                                                PFD_12A_NoSmokingIndicator = "B"
                                            }
                                        }
                }
            };

            var output = new StringBuilder();
            var grammar = EdiGrammar.NewEdiFact();
            using (var writer = new EdiTextWriter(new StringWriter(output), grammar))
            {
                new EdiSerializer() { EnableCompression = true }.Serialize(writer, interchange);
                Debug.Write(output);
            }

Serializes them into separate PFD segments instead of a single PFD segment. The goal is a single PFD segment.

UNA:+.? '
PFD+12C+N:M:3::FRA:MEX:744::Y:Z+12+++M/M'
PFD+01X+02X'
PFD+A+B'

@cleftheris
Copy link
Contributor

Hi @nochancenine this is a nice test that you can add it to the tests project with an assertion. If you give it a try I can look at a pull request.

On a quick note, probably you need to omit the PFD from your component values and add it to the segment itself. So I would make these attributes have the segmentName part as a wildcard [EdiValue(Path = "*/*/0")].

But I have to give it a closer look to be sure.

@nochancenine
Copy link
Author

Hello, thank you

I have tried the [EdiValue(Path = "*/*/0")] wildcards as well and am seeing the same results

I have created a new pull request with a sample test here:
#273

@cleftheris
Copy link
Contributor

Thanks for the pull request I will check it out as soon as possible.

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

No branches or pull requests

2 participants