package com.intrasoft.ermis.transit.officeofdeparture.service;

import com.intrasoft.ermis.common.logging.ErmisLogger;
import com.intrasoft.ermis.ddntav5152.messages.AddressType07;
import com.intrasoft.ermis.ddntav5152.messages.AddressType09;
import com.intrasoft.ermis.ddntav5152.messages.AddressType12;
import com.intrasoft.ermis.ddntav5152.messages.AddressType17;
import com.intrasoft.ermis.ddntav5152.messages.AddressType19;
import com.intrasoft.ermis.ddntav5152.messages.AddressType20;
import com.intrasoft.ermis.ddntav5152.messages.CC015CType;
import com.intrasoft.ermis.ddntav5152.messages.CC029CType;
import com.intrasoft.ermis.ddntav5152.messages.CD001CType;
import com.intrasoft.ermis.ddntav5152.messages.CD003CType;
import com.intrasoft.ermis.ddntav5152.messages.CD038CType;
import com.intrasoft.ermis.ddntav5152.messages.CD050CType;
import com.intrasoft.ermis.ddntav5152.messages.CD115CType;
import com.intrasoft.ermis.ddntav5152.messages.CD160CType;
import com.intrasoft.ermis.ddntav5152.messages.CD165CType;
import com.intrasoft.ermis.ddntav5152.messages.ConsigneeType02;
import com.intrasoft.ermis.ddntav5152.messages.ConsigneeType03;
import com.intrasoft.ermis.ddntav5152.messages.ConsigneeType04;
import com.intrasoft.ermis.ddntav5152.messages.ConsigneeType05;
import com.intrasoft.ermis.ddntav5152.messages.ConsigneeType06;
import com.intrasoft.ermis.ddntav5152.messages.ConsigneeType07;
import com.intrasoft.ermis.ddntav5152.messages.ConsignmentItemType09;
import com.intrasoft.ermis.ddntav5152.messages.ConsignorType03;
import com.intrasoft.ermis.ddntav5152.messages.ConsignorType04;
import com.intrasoft.ermis.ddntav5152.messages.ConsignorType07;
import com.intrasoft.ermis.ddntav5152.messages.ConsignorType08;
import com.intrasoft.ermis.ddntav5152.messages.ConsignorType09;
import com.intrasoft.ermis.ddntav5152.messages.HolderOfTheTransitProcedureType05;
import com.intrasoft.ermis.ddntav5152.messages.HolderOfTheTransitProcedureType11;
import com.intrasoft.ermis.ddntav5152.messages.HolderOfTheTransitProcedureType14;
import com.intrasoft.ermis.ddntav5152.messages.HolderOfTheTransitProcedureType16;
import com.intrasoft.ermis.ddntav5152.messages.HolderOfTheTransitProcedureType17;
import com.intrasoft.ermis.ddntav5152.messages.HolderOfTheTransitProcedureType18;
import com.intrasoft.ermis.ddntav5152.messages.HouseConsignmentType10;
import com.intrasoft.ermis.platform.shared.adapter.party.management.core.PartyManagementPort;
import com.intrasoft.ermis.platform.shared.adapter.party.management.core.domain.PartyIdentification;
import com.intrasoft.ermis.platform.shared.adapter.party.management.core.domain.PhysicalAddress;
import com.intrasoft.ermis.platform.shared.adapter.party.management.core.domain.organization.Organization;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;
import lombok.AllArgsConstructor;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
@AllArgsConstructor(onConstructor_ = {@Autowired})
public class ProcessPersonDetailsServiceImpl implements ProcessPersonDetailsService {


    private static final String DUMMY_VALUE_FOR_VOID_DATA = "---";

    public static final String STREET_AND_NUMBER = "streetAndNumber";

    public static final String POSTCODE = "postcode";

    public static final String CITY = "city";

    public static final String COUNTRY = "country";

    public static final String NAME = "name";

    private final PartyManagementPort partyManagementPort;

    private final ErmisLogger log;

    private static final String IDENTIFICATION_TYPE_EORI = "1";

    @Override
    public <T> void processEmptyPersonDetails(T ddntaMessage, String countryToBeUsed, CC015CType cc015cMessage) {

        if (ddntaMessage.getClass().equals(CD001CType.class)) {
            List<String> eoriNumbersFromCD001 = getEORIsFromCD001(ddntaMessage);
            log.info("processDetails;CD001 EORI Numbers: {}", eoriNumbersFromCD001);
            Map<String, Map<String, String>> eoriDetailsMap = getEoriDetails(eoriNumbersFromCD001);

            // HolderOfTheTransitProcedure fields:
            if (ObjectUtils.isNotEmpty(((CD001CType) ddntaMessage).getHolderOfTheTransitProcedure())) {
                HolderOfTheTransitProcedureType14 holderFromIE015 = getHolderFromIE015(cc015cMessage);
                editHolderOfTheTransitProcedureType11(((CD001CType) ddntaMessage).getHolderOfTheTransitProcedure(), countryToBeUsed, eoriDetailsMap,
                        holderFromIE015);
            }
            if (ObjectUtils.isNotEmpty(((CD001CType) ddntaMessage).getConsignment())) {
                // Consignment.Consignor fields:
                if (ObjectUtils.isNotEmpty(((CD001CType) ddntaMessage).getConsignment().getConsignor())) {
                    ConsignorType07 consignmentConsignorFromIE015 = getConsignmentConsignorFromIE015(cc015cMessage);
                    editConsignorType08(((CD001CType) ddntaMessage).getConsignment().getConsignor(), countryToBeUsed, eoriDetailsMap,
                            consignmentConsignorFromIE015);
                }
                // Consignment.Consignee fields:
                if (ObjectUtils.isNotEmpty(((CD001CType) ddntaMessage).getConsignment().getConsignee())) {
                    ConsigneeType05 consignmentConsigneeFromIE015 = getConsignmentConsigneeFromIE015(cc015cMessage);
                    editConsigneeType07(((CD001CType) ddntaMessage).getConsignment().getConsignee(), countryToBeUsed, eoriDetailsMap,
                            consignmentConsigneeFromIE015);
                }
                // Consignment.HouseConsignment.Consignor fields:
                AtomicInteger houseConsignmentConsignorCounter = new AtomicInteger(0);
                ((CD001CType) ddntaMessage).getConsignment().getHouseConsignment().forEach(houseConsignment -> {
                    if (ObjectUtils.isNotEmpty((houseConsignment.getConsignor()))) {
                        ConsignorType07 consignmentHCConsignorFromIE015 = getConsignmentHCConsignorFromIE015(houseConsignmentConsignorCounter, cc015cMessage);
                        editConsignorType09(houseConsignment.getConsignor(), countryToBeUsed, eoriDetailsMap, consignmentHCConsignorFromIE015);
                    }
                    houseConsignmentConsignorCounter.getAndIncrement();
                    // ConsignmentItems of IE001 have no Consignor.
                });
                // Consignment.HouseConsignment.Consignee & Consignment.HouseConsignment.ConsignmentItem.Consignee fields:
                AtomicInteger houseConsignmentConsigneeCounter = new AtomicInteger(0);
                ((CD001CType) ddntaMessage).getConsignment().getHouseConsignment().forEach(houseConsignment -> {
                    if (ObjectUtils.isNotEmpty((houseConsignment.getConsignee()))) {
                        ConsigneeType05 consignmentHCConsigneeFromIE015 = getConsignmentHCConsigneeFromIE015(houseConsignmentConsigneeCounter, cc015cMessage);
                        editConsigneeType07(houseConsignment.getConsignee(), countryToBeUsed, eoriDetailsMap, consignmentHCConsigneeFromIE015);
                    }
                    // ConsignmentItems:
                    AtomicInteger houseConsignmentCIConsigneeCounter = new AtomicInteger(0);
                    houseConsignment.getConsignmentItem().forEach(consignmentItem -> {
                        if (ObjectUtils.isNotEmpty((consignmentItem.getConsignee()))) {
                            ConsigneeType02 consignmentHCConsignmentItemConsigneeFromIE015 =
                                    getConsignmentHCConsignmentItemConsigneeFromIE015(houseConsignmentConsigneeCounter, houseConsignmentCIConsigneeCounter,
                                            cc015cMessage);
                            editConsigneeType06(consignmentItem.getConsignee(), countryToBeUsed, eoriDetailsMap,
                                    consignmentHCConsignmentItemConsigneeFromIE015);
                        }
                        houseConsignmentCIConsigneeCounter.getAndIncrement();
                    });
                    houseConsignmentConsigneeCounter.getAndIncrement();
                });
            }
        } else if (ddntaMessage.getClass().equals(CD050CType.class)) {
            List<String> eoriNumbersFromCD050 = getEORIsFromCD050(ddntaMessage);
            log.info("processDetails;CD050 EORI Numbers: {}", eoriNumbersFromCD050);
            Map<String, Map<String, String>> eoriDetailsMap = getEoriDetails(eoriNumbersFromCD050);

            // HolderOfTheTransitProcedure fields:
            if (ObjectUtils.isNotEmpty(((CD050CType) ddntaMessage).getHolderOfTheTransitProcedure())) {
                HolderOfTheTransitProcedureType14 holderFromIE015 = getHolderFromIE015(cc015cMessage);
                editHolderOfTheTransitProcedureType17(((CD050CType) ddntaMessage).getHolderOfTheTransitProcedure(), countryToBeUsed, eoriDetailsMap,
                        holderFromIE015);
            }
            if (ObjectUtils.isNotEmpty(((CD050CType) ddntaMessage).getConsignment())) {
                // Consignment.Consignor fields:
                if (ObjectUtils.isNotEmpty(((CD050CType) ddntaMessage).getConsignment().getConsignor())) {
                    ConsignorType07 consignmentConsignorFromIE015 = getConsignmentConsignorFromIE015(cc015cMessage);
                    editConsignorType08(((CD050CType) ddntaMessage).getConsignment().getConsignor(), countryToBeUsed, eoriDetailsMap,
                            consignmentConsignorFromIE015);
                }
                // Consignment.Consignee fields:
                if (ObjectUtils.isNotEmpty(((CD050CType) ddntaMessage).getConsignment().getConsignee())) {
                    ConsigneeType05 consignmentConsigneeFromIE015 = getConsignmentConsigneeFromIE015(cc015cMessage);
                    editConsigneeType07(((CD050CType) ddntaMessage).getConsignment().getConsignee(), countryToBeUsed, eoriDetailsMap,
                            consignmentConsigneeFromIE015);
                }
                // Consignment.HouseConsignment.Consignor fields:
                AtomicInteger houseConsignmentConsignorCounter = new AtomicInteger(0);
                ((CD050CType) ddntaMessage).getConsignment().getHouseConsignment().forEach(houseConsignment -> {
                    if (ObjectUtils.isNotEmpty((houseConsignment.getConsignor()))) {
                        ConsignorType07 consignmentHCConsignorFromIE015 = getConsignmentHCConsignorFromIE015(houseConsignmentConsignorCounter, cc015cMessage);
                        editConsignorType09(houseConsignment.getConsignor(), countryToBeUsed, eoriDetailsMap, consignmentHCConsignorFromIE015);
                    }
                    houseConsignmentConsignorCounter.getAndIncrement();
                    // ConsignmentItems of IE050 have no Consignor.
                });
                // Consignment.HouseConsignment.Consignee & Consignment.HouseConsignment.ConsignmentItem.Consignee fields:
                AtomicInteger houseConsignmentConsigneeCounter = new AtomicInteger(0);
                ((CD050CType) ddntaMessage).getConsignment().getHouseConsignment().forEach(houseConsignment -> {
                    if (ObjectUtils.isNotEmpty((houseConsignment.getConsignee()))) {
                        ConsigneeType05 consignmentHCConsigneeFromIE015 = getConsignmentHCConsigneeFromIE015(houseConsignmentConsigneeCounter, cc015cMessage);
                        editConsigneeType07(houseConsignment.getConsignee(), countryToBeUsed, eoriDetailsMap, consignmentHCConsigneeFromIE015);
                    }
                    // ConsignmentItems:
                    AtomicInteger houseConsignmentCIConsigneeCounter = new AtomicInteger(0);
                    houseConsignment.getConsignmentItem().forEach(consignmentItem -> {
                        if (ObjectUtils.isNotEmpty((consignmentItem.getConsignee()))) {
                            ConsigneeType02 consignmentHCConsignmentItemConsigneeFromIE015 =
                                    getConsignmentHCConsignmentItemConsigneeFromIE015(houseConsignmentConsigneeCounter, houseConsignmentCIConsigneeCounter,
                                            cc015cMessage);
                            editConsigneeType06(consignmentItem.getConsignee(), countryToBeUsed, eoriDetailsMap,
                                    consignmentHCConsignmentItemConsigneeFromIE015);
                        }
                        houseConsignmentCIConsigneeCounter.getAndIncrement();
                    });
                    houseConsignmentConsigneeCounter.getAndIncrement();
                });
            }
        } else if (ddntaMessage.getClass().equals(CD160CType.class)) {
            List<String> eoriNumbersFromCD160 = getEORIsFromCD160(ddntaMessage);
            log.info("processDetails;CD160 EORI Numbers: {}", eoriNumbersFromCD160);
            Map<String, Map<String, String>> eoriDetailsMap = getEoriDetails(eoriNumbersFromCD160);

            // HolderOfTheTransitProcedure fields:
            if (ObjectUtils.isNotEmpty(((CD160CType) ddntaMessage).getHolderOfTheTransitProcedure())) {
                HolderOfTheTransitProcedureType14 holderFromIE015 = getHolderFromIE015(cc015cMessage);
                editHolderOfTheTransitProcedureType17(((CD160CType) ddntaMessage).getHolderOfTheTransitProcedure(), countryToBeUsed, eoriDetailsMap,
                        holderFromIE015);
            }
            if (ObjectUtils.isNotEmpty(((CD160CType) ddntaMessage).getConsignment())) {
                // Consignment.Consignor fields:
                if (ObjectUtils.isNotEmpty(((CD160CType) ddntaMessage).getConsignment().getConsignor())) {
                    ConsignorType07 consignmentConsignorFromIE015 = getConsignmentConsignorFromIE015(cc015cMessage);
                    editConsignorType08(((CD160CType) ddntaMessage).getConsignment().getConsignor(), countryToBeUsed, eoriDetailsMap,
                            consignmentConsignorFromIE015);
                }
                // Consignment.Consignee fields:
                if (ObjectUtils.isNotEmpty(((CD160CType) ddntaMessage).getConsignment().getConsignee())) {
                    ConsigneeType05 consignmentConsigneeFromIE015 = getConsignmentConsigneeFromIE015(cc015cMessage);
                    editConsigneeType07(((CD160CType) ddntaMessage).getConsignment().getConsignee(), countryToBeUsed, eoriDetailsMap,
                            consignmentConsigneeFromIE015);
                }
                // Consignment.HouseConsignment.Consignor fields:
                AtomicInteger houseConsignmentConsignorCounter = new AtomicInteger(0);
                ((CD160CType) ddntaMessage).getConsignment().getHouseConsignment().forEach(houseConsignment -> {
                    if (ObjectUtils.isNotEmpty((houseConsignment.getConsignor()))) {
                        ConsignorType07 consignmentHCConsignorFromIE015 = getConsignmentHCConsignorFromIE015(houseConsignmentConsignorCounter, cc015cMessage);
                        editConsignorType09(houseConsignment.getConsignor(), countryToBeUsed, eoriDetailsMap, consignmentHCConsignorFromIE015);
                    }
                    houseConsignmentConsignorCounter.getAndIncrement();
                    // ConsignmentItems of IE160 have no Consignor.
                });
                // Consignment.HouseConsignment.Consignee & Consignment.HouseConsignment.ConsignmentItem.Consignee fields:
                AtomicInteger houseConsignmentConsigneeCounter = new AtomicInteger(0);
                ((CD160CType) ddntaMessage).getConsignment().getHouseConsignment().forEach(houseConsignment -> {
                    if (ObjectUtils.isNotEmpty((houseConsignment.getConsignee()))) {
                        ConsigneeType05 consignmentHCConsigneeFromIE015 = getConsignmentHCConsigneeFromIE015(houseConsignmentConsigneeCounter, cc015cMessage);
                        editConsigneeType07(houseConsignment.getConsignee(), countryToBeUsed, eoriDetailsMap, consignmentHCConsigneeFromIE015);
                    }
                    // ConsignmentItems:
                    AtomicInteger houseConsignmentCIConsigneeCounter = new AtomicInteger(0);
                    houseConsignment.getConsignmentItem().forEach(consignmentItem -> {
                        if (ObjectUtils.isNotEmpty((consignmentItem.getConsignee()))) {
                            ConsigneeType02 consignmentHCConsignmentItemConsigneeFromIE015 =
                                    getConsignmentHCConsignmentItemConsigneeFromIE015(houseConsignmentConsigneeCounter, houseConsignmentCIConsigneeCounter,
                                            cc015cMessage);
                            editConsigneeType06(consignmentItem.getConsignee(), countryToBeUsed, eoriDetailsMap,
                                    consignmentHCConsignmentItemConsigneeFromIE015);
                        }
                        houseConsignmentCIConsigneeCounter.getAndIncrement();
                    });
                    houseConsignmentConsigneeCounter.getAndIncrement();
                });
            }
        } else if (ddntaMessage.getClass().equals(CD038CType.class)) {
            List<String> eoriNumbersFromCD038 = getEORIsFromCD038(ddntaMessage);
            log.info("processDetails;CD038 EORI Numbers: {}", eoriNumbersFromCD038);
            Map<String, Map<String, String>> eoriDetailsMap = getEoriDetails(eoriNumbersFromCD038);

            // HolderOfTheTransitProcedure fields:
            if (ObjectUtils.isNotEmpty(((CD038CType) ddntaMessage).getHolderOfTheTransitProcedure())) {
                HolderOfTheTransitProcedureType14 holderFromIE015 = getHolderFromIE015(cc015cMessage);
                editHolderOfTheTransitProcedureType16(((CD038CType) ddntaMessage).getHolderOfTheTransitProcedure(), countryToBeUsed, eoriDetailsMap,
                        holderFromIE015);
            }
            if (ObjectUtils.isNotEmpty(((CD038CType) ddntaMessage).getConsignment())) {
                // Consignment.Consignor fields:
                if (ObjectUtils.isNotEmpty(((CD038CType) ddntaMessage).getConsignment().getConsignor())) {
                    ConsignorType07 consignmentConsignorFromIE015 = getConsignmentConsignorFromIE015(cc015cMessage);
                    editConsignorType08(((CD038CType) ddntaMessage).getConsignment().getConsignor(), countryToBeUsed, eoriDetailsMap,
                            consignmentConsignorFromIE015);
                }
                // Consignment.Consignee fields:
                if (ObjectUtils.isNotEmpty(((CD038CType) ddntaMessage).getConsignment().getConsignee())) {
                    ConsigneeType05 consignmentConsigneeFromIE015 = getConsignmentConsigneeFromIE015(cc015cMessage);
                    editConsigneeType07(((CD038CType) ddntaMessage).getConsignment().getConsignee(), countryToBeUsed, eoriDetailsMap,
                            consignmentConsigneeFromIE015);
                }
                // Consignment.HouseConsignment.Consignor fields:
                AtomicInteger houseConsignmentConsignorCounter = new AtomicInteger(0);
                ((CD038CType) ddntaMessage).getConsignment().getHouseConsignment().forEach(houseConsignment -> {
                    if (ObjectUtils.isNotEmpty((houseConsignment.getConsignor()))) {
                        ConsignorType07 consignmentHCConsignorFromIE015 = getConsignmentHCConsignorFromIE015(houseConsignmentConsignorCounter, cc015cMessage);
                        editConsignorType09(houseConsignment.getConsignor(), countryToBeUsed, eoriDetailsMap, consignmentHCConsignorFromIE015);
                    }
                    houseConsignmentConsignorCounter.getAndIncrement();
                    // ConsignmentItems of IE038 have no Consignor.
                });
                // Consignment.HouseConsignment.Consignee & Consignment.HouseConsignment.ConsignmentItem.Consignee fields:
                AtomicInteger houseConsignmentConsigneeCounter = new AtomicInteger(0);
                ((CD038CType) ddntaMessage).getConsignment().getHouseConsignment().forEach(houseConsignment -> {
                    if (ObjectUtils.isNotEmpty((houseConsignment.getConsignee()))) {
                        ConsigneeType05 consignmentHCConsigneeFromIE015 = getConsignmentHCConsigneeFromIE015(houseConsignmentConsigneeCounter, cc015cMessage);
                        editConsigneeType07(houseConsignment.getConsignee(), countryToBeUsed, eoriDetailsMap, consignmentHCConsigneeFromIE015);
                    }
                    // ConsignmentItems:
                    AtomicInteger houseConsignmentCIConsigneeCounter = new AtomicInteger(0);
                    houseConsignment.getConsignmentItem().forEach(consignmentItem -> {
                        if (ObjectUtils.isNotEmpty((consignmentItem.getConsignee()))) {
                            ConsigneeType02 consignmentHCConsignmentItemConsigneeFromIE015 =
                                    getConsignmentHCConsignmentItemConsigneeFromIE015(houseConsignmentConsigneeCounter, houseConsignmentCIConsigneeCounter,
                                            cc015cMessage);
                            editConsigneeType06(consignmentItem.getConsignee(), countryToBeUsed, eoriDetailsMap,
                                    consignmentHCConsignmentItemConsigneeFromIE015);
                        }
                        houseConsignmentCIConsigneeCounter.getAndIncrement();
                    });
                    houseConsignmentConsigneeCounter.getAndIncrement();
                });
            }
        } else if (ddntaMessage.getClass().equals(CD003CType.class)) {
            List<String> eoriNumbersFromCD003 = getEORIsFromCD003(ddntaMessage);
            log.info("processDetails;CD003 EORI Numbers: {}", eoriNumbersFromCD003);
            Map<String, Map<String, String>> eoriDetailsMap = getEoriDetails(eoriNumbersFromCD003);

            // HolderOfTheTransitProcedure fields:
            if (ObjectUtils.isNotEmpty(((CD003CType) ddntaMessage).getHolderOfTheTransitProcedure())) {
                HolderOfTheTransitProcedureType14 holderFromIE015 = getHolderFromIE015(cc015cMessage);
                editHolderOfTheTransitProcedureType16(((CD003CType) ddntaMessage).getHolderOfTheTransitProcedure(), countryToBeUsed, eoriDetailsMap,
                        holderFromIE015);
            }
            if (ObjectUtils.isNotEmpty(((CD003CType) ddntaMessage).getConsignment())) {
                // Consignment.Consignor fields:
                if (ObjectUtils.isNotEmpty(((CD003CType) ddntaMessage).getConsignment().getConsignor())) {
                    ConsignorType07 consignmentConsignorFromIE015 = getConsignmentConsignorFromIE015(cc015cMessage);
                    editConsignorType08(((CD003CType) ddntaMessage).getConsignment().getConsignor(), countryToBeUsed, eoriDetailsMap,
                            consignmentConsignorFromIE015);
                }
                // Consignment.Consignee fields:
                if (ObjectUtils.isNotEmpty(((CD003CType) ddntaMessage).getConsignment().getConsignee())) {
                    ConsigneeType05 consignmentConsigneeFromIE015 = getConsignmentConsigneeFromIE015(cc015cMessage);
                    editConsigneeType07(((CD003CType) ddntaMessage).getConsignment().getConsignee(), countryToBeUsed, eoriDetailsMap,
                            consignmentConsigneeFromIE015);
                }
                // Consignment.HouseConsignment.Consignor fields:
                AtomicInteger houseConsignmentConsignorCounter = new AtomicInteger(0);
                ((CD003CType) ddntaMessage).getConsignment().getHouseConsignment().forEach(houseConsignment -> {
                    if (ObjectUtils.isNotEmpty((houseConsignment.getConsignor()))) {
                        ConsignorType07 consignmentHCConsignorFromIE015 = getConsignmentHCConsignorFromIE015(houseConsignmentConsignorCounter, cc015cMessage);
                        editConsignorType09(houseConsignment.getConsignor(), countryToBeUsed, eoriDetailsMap, consignmentHCConsignorFromIE015);
                    }
                    houseConsignmentConsignorCounter.getAndIncrement();
                    // ConsignmentItems of IE003 have no Consignor.
                });
                // Consignment.HouseConsignment.Consignee & Consignment.HouseConsignment.ConsignmentItem.Consignee fields:
                AtomicInteger houseConsignmentConsigneeCounter = new AtomicInteger(0);
                ((CD003CType) ddntaMessage).getConsignment().getHouseConsignment().forEach(houseConsignment -> {
                    if (ObjectUtils.isNotEmpty((houseConsignment.getConsignee()))) {
                        ConsigneeType05 consignmentHCConsigneeFromIE015 = getConsignmentHCConsigneeFromIE015(houseConsignmentConsigneeCounter, cc015cMessage);
                        editConsigneeType07(houseConsignment.getConsignee(), countryToBeUsed, eoriDetailsMap, consignmentHCConsigneeFromIE015);
                    }
                    // ConsignmentItems:
                    AtomicInteger houseConsignmentCIConsigneeCounter = new AtomicInteger(0);
                    houseConsignment.getConsignmentItem().forEach(consignmentItem -> {
                        if (ObjectUtils.isNotEmpty((consignmentItem.getConsignee()))) {
                            ConsigneeType02 consignmentHCConsignmentItemConsigneeFromIE015 =
                                    getConsignmentHCConsignmentItemConsigneeFromIE015(houseConsignmentConsigneeCounter, houseConsignmentCIConsigneeCounter,
                                            cc015cMessage);
                            editConsigneeType06(consignmentItem.getConsignee(), countryToBeUsed, eoriDetailsMap,
                                    consignmentHCConsignmentItemConsigneeFromIE015);
                        }
                        houseConsignmentCIConsigneeCounter.getAndIncrement();
                    });
                    houseConsignmentConsigneeCounter.getAndIncrement();
                });
            }
        } else if (ddntaMessage.getClass().equals(CD115CType.class)) {
            List<String> eoriNumbersFromCD115 = getEORIsFromCD115(ddntaMessage);
            log.info("processDetails;CD115 EORI Numbers: {}", eoriNumbersFromCD115);
            Map<String, Map<String, String>> eoriDetailsMap = getEoriDetails(eoriNumbersFromCD115);

            // HolderOfTheTransitProcedure fields:
            if (ObjectUtils.isNotEmpty(((CD115CType) ddntaMessage).getHolderOfTheTransitProcedure())) {
                HolderOfTheTransitProcedureType14 holderFromIE015 = getHolderFromIE015(cc015cMessage);
                editHolderOfTheTransitProcedureType18(((CD115CType) ddntaMessage).getHolderOfTheTransitProcedure(), countryToBeUsed, eoriDetailsMap,
                        holderFromIE015);
            }
            if (ObjectUtils.isNotEmpty(((CD115CType) ddntaMessage).getConsignment())) {
                // Consignment.Consignor fields:
                if (ObjectUtils.isNotEmpty(((CD115CType) ddntaMessage).getConsignment().getConsignor())) {
                    ConsignorType07 consignmentConsignorFromIE015 = getConsignmentConsignorFromIE015(cc015cMessage);
                    editConsignorType08(((CD115CType) ddntaMessage).getConsignment().getConsignor(), countryToBeUsed, eoriDetailsMap,
                            consignmentConsignorFromIE015);
                }
                // Consignment.Consignee fields:
                if (ObjectUtils.isNotEmpty(((CD115CType) ddntaMessage).getConsignment().getConsignee())) {
                    ConsigneeType05 consignmentConsigneeFromIE015 = getConsignmentConsigneeFromIE015(cc015cMessage);
                    editConsigneeType07(((CD115CType) ddntaMessage).getConsignment().getConsignee(), countryToBeUsed, eoriDetailsMap,
                            consignmentConsigneeFromIE015);
                }
                // Consignment.HouseConsignment.Consignor fields:
                AtomicInteger houseConsignmentConsignorCounter = new AtomicInteger(0);
                ((CD115CType) ddntaMessage).getConsignment().getHouseConsignment().forEach(houseConsignment -> {
                    if (ObjectUtils.isNotEmpty((houseConsignment.getConsignor()))) {
                        ConsignorType07 consignmentHCConsignorFromIE015 = getConsignmentHCConsignorFromIE015(houseConsignmentConsignorCounter, cc015cMessage);
                        editConsignorType09(houseConsignment.getConsignor(), countryToBeUsed, eoriDetailsMap, consignmentHCConsignorFromIE015);
                    }
                    houseConsignmentConsignorCounter.getAndIncrement();
                    // ConsignmentItems of IE115 have no Consignor.
                });
                // Consignment.HouseConsignment.Consignee & Consignment.HouseConsignment.ConsignmentItem.Consignee fields:
                AtomicInteger houseConsignmentConsigneeCounter = new AtomicInteger(0);
                ((CD115CType) ddntaMessage).getConsignment().getHouseConsignment().forEach(houseConsignment -> {
                    if (ObjectUtils.isNotEmpty((houseConsignment.getConsignee()))) {
                        ConsigneeType05 consignmentHCConsigneeFromIE015 = getConsignmentHCConsigneeFromIE015(houseConsignmentConsigneeCounter, cc015cMessage);
                        editConsigneeType07(houseConsignment.getConsignee(), countryToBeUsed, eoriDetailsMap, consignmentHCConsigneeFromIE015);
                    }
                    // ConsignmentItems:
                    AtomicInteger houseConsignmentCIConsigneeCounter = new AtomicInteger(0);
                    houseConsignment.getConsignmentItem().forEach(consignmentItem -> {
                        if (ObjectUtils.isNotEmpty((consignmentItem.getConsignee()))) {
                            ConsigneeType02 consignmentHCConsignmentItemConsigneeFromIE015 =
                                    getConsignmentHCConsignmentItemConsigneeFromIE015(houseConsignmentConsigneeCounter, houseConsignmentCIConsigneeCounter,
                                            cc015cMessage);
                            editConsigneeType06(consignmentItem.getConsignee(), countryToBeUsed, eoriDetailsMap,
                                    consignmentHCConsignmentItemConsigneeFromIE015);
                        }
                        houseConsignmentCIConsigneeCounter.getAndIncrement();
                    });
                    houseConsignmentConsigneeCounter.getAndIncrement();
                });
            }
        } else if (ddntaMessage.getClass().equals(CD165CType.class)) {
            List<String> eoriNumbersFromCD165 = getEORIsFromCD165(ddntaMessage);
            log.info("processDetails;CD165 EORI Numbers: {}", eoriNumbersFromCD165);
            Map<String, Map<String, String>> eoriDetailsMap = getEoriDetails(eoriNumbersFromCD165);

            // HolderOfTheTransitProcedure fields:
            if (ObjectUtils.isNotEmpty(((CD165CType) ddntaMessage).getHolderOfTheTransitProcedure())) {
                HolderOfTheTransitProcedureType14 holderFromIE015 = getHolderFromIE015(cc015cMessage);
                editHolderOfTheTransitProcedureType18(((CD165CType) ddntaMessage).getHolderOfTheTransitProcedure(), countryToBeUsed, eoriDetailsMap,
                        holderFromIE015);
            }
            if (ObjectUtils.isNotEmpty(((CD165CType) ddntaMessage).getConsignment())) {
                // Consignment.Consignor fields:
                if (ObjectUtils.isNotEmpty(((CD165CType) ddntaMessage).getConsignment().getConsignor())) {
                    ConsignorType07 consignmentConsignorFromIE015 = getConsignmentConsignorFromIE015(cc015cMessage);
                    editConsignorType08(((CD165CType) ddntaMessage).getConsignment().getConsignor(), countryToBeUsed, eoriDetailsMap,
                            consignmentConsignorFromIE015);
                }
                // Consignment.Consignee fields:
                if (ObjectUtils.isNotEmpty(((CD165CType) ddntaMessage).getConsignment().getConsignee())) {
                    ConsigneeType05 consignmentConsigneeFromIE015 = getConsignmentConsigneeFromIE015(cc015cMessage);
                    editConsigneeType07(((CD165CType) ddntaMessage).getConsignment().getConsignee(), countryToBeUsed, eoriDetailsMap,
                            consignmentConsigneeFromIE015);
                }
                // Consignment.HouseConsignment.Consignor fields:
                AtomicInteger houseConsignmentConsignorCounter = new AtomicInteger(0);
                ((CD165CType) ddntaMessage).getConsignment().getHouseConsignment().forEach(houseConsignment -> {
                    if (ObjectUtils.isNotEmpty((houseConsignment.getConsignor()))) {
                        ConsignorType07 consignmentHCConsignorFromIE015 = getConsignmentHCConsignorFromIE015(houseConsignmentConsignorCounter, cc015cMessage);
                        editConsignorType09(houseConsignment.getConsignor(), countryToBeUsed, eoriDetailsMap, consignmentHCConsignorFromIE015);
                    }
                    houseConsignmentConsignorCounter.getAndIncrement();
                    // ConsignmentItems of IE165 have no Consignor.
                });
                // Consignment.HouseConsignment.Consignee & Consignment.HouseConsignment.ConsignmentItem.Consignee fields:
                AtomicInteger houseConsignmentConsigneeCounter = new AtomicInteger(0);
                ((CD165CType) ddntaMessage).getConsignment().getHouseConsignment().forEach(houseConsignment -> {
                    if (ObjectUtils.isNotEmpty((houseConsignment.getConsignee()))) {
                        ConsigneeType05 consignmentHCConsigneeFromIE015 = getConsignmentHCConsigneeFromIE015(houseConsignmentConsigneeCounter, cc015cMessage);
                        editConsigneeType07(houseConsignment.getConsignee(), countryToBeUsed, eoriDetailsMap, consignmentHCConsigneeFromIE015);
                    }
                    // ConsignmentItems:
                    AtomicInteger houseConsignmentCIConsigneeCounter = new AtomicInteger(0);
                    houseConsignment.getConsignmentItem().forEach(consignmentItem -> {
                        if (ObjectUtils.isNotEmpty((consignmentItem.getConsignee()))) {
                            ConsigneeType02 consignmentHCConsignmentItemConsigneeFromIE015 =
                                    getConsignmentHCConsignmentItemConsigneeFromIE015(houseConsignmentConsigneeCounter, houseConsignmentCIConsigneeCounter,
                                            cc015cMessage);
                            editConsigneeType06(consignmentItem.getConsignee(), countryToBeUsed, eoriDetailsMap,
                                    consignmentHCConsignmentItemConsigneeFromIE015);
                        }
                        houseConsignmentCIConsigneeCounter.getAndIncrement();
                    });
                    houseConsignmentConsigneeCounter.getAndIncrement();
                });
            }
        } else if (ddntaMessage.getClass().equals(CC029CType.class)) {
            List<String> eoriNumbersFromCC029 = getEORIsFromCC029(ddntaMessage);
            log.info("processDetails;CC029 EORI Numbers: {}", eoriNumbersFromCC029);
            Map<String, Map<String, String>> eoriDetailsMap = getEoriDetails(eoriNumbersFromCC029);

            // HolderOfTheTransitProcedure fields:
            if (ObjectUtils.isNotEmpty(((CC029CType) ddntaMessage).getHolderOfTheTransitProcedure())) {
                HolderOfTheTransitProcedureType14 holderFromIE015 = getHolderFromIE015(cc015cMessage);
                editHolderOfTheTransitProcedureType05(((CC029CType) ddntaMessage).getHolderOfTheTransitProcedure(), countryToBeUsed, eoriDetailsMap,
                        holderFromIE015);
            }
            if (ObjectUtils.isNotEmpty(((CC029CType) ddntaMessage).getConsignment())) {
                // Consignment.Consignor fields:
                if (ObjectUtils.isNotEmpty(((CC029CType) ddntaMessage).getConsignment().getConsignor())) {
                    ConsignorType07 consignmentConsignorFromIE015 = getConsignmentConsignorFromIE015(cc015cMessage);
                    editConsignorType03(((CC029CType) ddntaMessage).getConsignment().getConsignor(), countryToBeUsed, eoriDetailsMap,
                            consignmentConsignorFromIE015);
                }
                // Consignment.Consignee fields:
                if (ObjectUtils.isNotEmpty(((CC029CType) ddntaMessage).getConsignment().getConsignee())) {
                    ConsigneeType05 consignmentConsigneeFromIE015 = getConsignmentConsigneeFromIE015(cc015cMessage);
                    editConsigneeType04(((CC029CType) ddntaMessage).getConsignment().getConsignee(), countryToBeUsed, eoriDetailsMap,
                            consignmentConsigneeFromIE015);
                }
                // Consignment.HouseConsignment.Consignor fields:
                AtomicInteger houseConsignmentConsignorCounter = new AtomicInteger(0);
                ((CC029CType) ddntaMessage).getConsignment().getHouseConsignment().forEach(houseConsignment -> {
                    if (ObjectUtils.isNotEmpty((houseConsignment.getConsignor()))) {
                        ConsignorType07 consignmentHCConsignorFromIE015 = getConsignmentHCConsignorFromIE015(houseConsignmentConsignorCounter, cc015cMessage);
                        editConsignorType04(houseConsignment.getConsignor(), countryToBeUsed, eoriDetailsMap, consignmentHCConsignorFromIE015);
                    }
                    houseConsignmentConsignorCounter.getAndIncrement();
                    // ConsignmentItems of IE029 have no Consignor.
                });
                // Consignment.HouseConsignment.Consignee & Consignment.HouseConsignment.ConsignmentItem.Consignee fields:
                AtomicInteger houseConsignmentConsigneeCounter = new AtomicInteger(0);
                ((CC029CType) ddntaMessage).getConsignment().getHouseConsignment().forEach(houseConsignment -> {
                    if (ObjectUtils.isNotEmpty((houseConsignment.getConsignee()))) {
                        ConsigneeType05 consignmentHCConsigneeFromIE015 = getConsignmentHCConsigneeFromIE015(houseConsignmentConsigneeCounter, cc015cMessage);
                        editConsigneeType04(houseConsignment.getConsignee(), countryToBeUsed, eoriDetailsMap, consignmentHCConsigneeFromIE015);
                    }
                    // ConsignmentItems:
                    AtomicInteger houseConsignmentCIConsigneeCounter = new AtomicInteger(0);
                    houseConsignment.getConsignmentItem().forEach(consignmentItem -> {
                        if (ObjectUtils.isNotEmpty((consignmentItem.getConsignee()))) {
                            ConsigneeType02 consignmentHCConsignmentItemConsigneeFromIE015 =
                                    getConsignmentHCConsignmentItemConsigneeFromIE015(houseConsignmentConsigneeCounter, houseConsignmentCIConsigneeCounter,
                                            cc015cMessage);
                            editConsigneeType03(consignmentItem.getConsignee(), countryToBeUsed, eoriDetailsMap,
                                    consignmentHCConsignmentItemConsigneeFromIE015);
                        }
                        houseConsignmentCIConsigneeCounter.getAndIncrement();
                    });
                    houseConsignmentConsigneeCounter.getAndIncrement();
                });
            }
        }
    }

    private <T> List<String> getEORIsFromCC029(T ddntaMessage) {
        Set<String> eoriNumbers = new HashSet<>();
        // HolderOfTheTransitProcedure fields:
        if (ObjectUtils.isNotEmpty(((CC029CType) ddntaMessage).getHolderOfTheTransitProcedure())) {
            eoriNumbers.add(getEORINumber(((CC029CType) ddntaMessage).getHolderOfTheTransitProcedure()));
        }
        if (ObjectUtils.isNotEmpty(((CC029CType) ddntaMessage).getConsignment())) {
            // Consignment.Consignor fields:
            if (ObjectUtils.isNotEmpty(((CC029CType) ddntaMessage).getConsignment().getConsignor())) {
                eoriNumbers.add(getEORINumber(((CC029CType) ddntaMessage).getConsignment().getConsignor()));
            }
            // Consignment.Consignee fields:
            if (ObjectUtils.isNotEmpty(((CC029CType) ddntaMessage).getConsignment().getConsignee())) {
                eoriNumbers.add(getEORINumber(((CC029CType) ddntaMessage).getConsignment().getConsignee()));
            }
            // Consignment.HouseConsignment.Consignor fields:
            ((CC029CType) ddntaMessage).getConsignment().getHouseConsignment().forEach(houseConsignment -> {
                if (ObjectUtils.isNotEmpty((houseConsignment.getConsignor()))) {
                    eoriNumbers.add(getEORINumber(houseConsignment.getConsignor()));
                }
                // ConsignmentItems of IE029 have no Consignor.
            });
            // Consignment.HouseConsignment.Consignee & Consignment.HouseConsignment.ConsignmentItem.Consignee fields:
            ((CC029CType) ddntaMessage).getConsignment().getHouseConsignment().forEach(houseConsignment -> {
                if (ObjectUtils.isNotEmpty((houseConsignment.getConsignee()))) {
                    eoriNumbers.add(getEORINumber(houseConsignment.getConsignee()));
                }
                // ConsignmentItems:
                houseConsignment.getConsignmentItem().forEach(consignmentItem -> {
                    if (ObjectUtils.isNotEmpty((consignmentItem.getConsignee()))) {
                        eoriNumbers.add(getEORINumber(consignmentItem.getConsignee()));
                    }
                });
            });
        }
        return eoriNumbers.stream().filter(Objects::nonNull).collect(Collectors.toList());
    }

    private <T> List<String> getEORIsFromCD165(T ddntaMessage) {
        Set<String> eoriNumbers = new HashSet<>();

        // HolderOfTheTransitProcedure fields:
        if (ObjectUtils.isNotEmpty(((CD165CType) ddntaMessage).getHolderOfTheTransitProcedure())) {
            eoriNumbers.add(getEORINumber(((CD165CType) ddntaMessage).getHolderOfTheTransitProcedure()));
        }
        if (ObjectUtils.isNotEmpty(((CD165CType) ddntaMessage).getConsignment())) {
            // Consignment.Consignor fields:
            if (ObjectUtils.isNotEmpty(((CD165CType) ddntaMessage).getConsignment().getConsignor())) {
                eoriNumbers.add(getEORINumber(((CD165CType) ddntaMessage).getConsignment().getConsignor()));
            }
            // Consignment.Consignee fields:
            if (ObjectUtils.isNotEmpty(((CD165CType) ddntaMessage).getConsignment().getConsignee())) {
                eoriNumbers.add(getEORINumber(((CD165CType) ddntaMessage).getConsignment().getConsignee()));
            }
            // Consignment.HouseConsignment.Consignor fields:
            ((CD165CType) ddntaMessage).getConsignment().getHouseConsignment().forEach(houseConsignment -> {
                if (ObjectUtils.isNotEmpty((houseConsignment.getConsignor()))) {
                    eoriNumbers.add(getEORINumber(houseConsignment.getConsignor()));
                }
                // ConsignmentItems of IE165 have no Consignor.
            });
            // Consignment.HouseConsignment.Consignee & Consignment.HouseConsignment.ConsignmentItem.Consignee fields:
            ((CD165CType) ddntaMessage).getConsignment().getHouseConsignment().forEach(houseConsignment -> {
                if (ObjectUtils.isNotEmpty((houseConsignment.getConsignee()))) {
                    eoriNumbers.add(getEORINumber(houseConsignment.getConsignee()));
                }
                // ConsignmentItems:
                houseConsignment.getConsignmentItem().forEach(consignmentItem -> {
                    if (ObjectUtils.isNotEmpty((consignmentItem.getConsignee()))) {
                        eoriNumbers.add(getEORINumber(consignmentItem.getConsignee()));
                    }
                });
            });
        }
        return eoriNumbers.stream().filter(Objects::nonNull).collect(Collectors.toList());
    }

    private <T> List<String> getEORIsFromCD115(T ddntaMessage) {
        Set<String> eoriNumbers = new HashSet<>();
        // HolderOfTheTransitProcedure fields:
        if (ObjectUtils.isNotEmpty(((CD115CType) ddntaMessage).getHolderOfTheTransitProcedure())) {
            eoriNumbers.add(getEORINumber(((CD115CType) ddntaMessage).getHolderOfTheTransitProcedure()));
        }
        if (ObjectUtils.isNotEmpty(((CD115CType) ddntaMessage).getConsignment())) {
            // Consignment.Consignor fields:
            if (ObjectUtils.isNotEmpty(((CD115CType) ddntaMessage).getConsignment().getConsignor())) {
                eoriNumbers.add(getEORINumber(((CD115CType) ddntaMessage).getConsignment().getConsignor()));
            }
            // Consignment.Consignee fields:
            if (ObjectUtils.isNotEmpty(((CD115CType) ddntaMessage).getConsignment().getConsignee())) {
                eoriNumbers.add(getEORINumber(((CD115CType) ddntaMessage).getConsignment().getConsignee()));
            }
            // Consignment.HouseConsignment.Consignor fields:
            ((CD115CType) ddntaMessage).getConsignment().getHouseConsignment().forEach(houseConsignment -> {
                if (ObjectUtils.isNotEmpty((houseConsignment.getConsignor()))) {
                    eoriNumbers.add(getEORINumber(houseConsignment.getConsignor()));
                }
                // ConsignmentItems of IE115 have no Consignor.
            });
            // Consignment.HouseConsignment.Consignee & Consignment.HouseConsignment.ConsignmentItem.Consignee fields:
            ((CD115CType) ddntaMessage).getConsignment().getHouseConsignment().forEach(houseConsignment -> {
                if (ObjectUtils.isNotEmpty((houseConsignment.getConsignee()))) {
                    eoriNumbers.add(getEORINumber(houseConsignment.getConsignee()));
                }
                // ConsignmentItems:
                houseConsignment.getConsignmentItem().forEach(consignmentItem -> {
                    if (ObjectUtils.isNotEmpty((consignmentItem.getConsignee()))) {
                        eoriNumbers.add(getEORINumber(consignmentItem.getConsignee()));
                    }
                });
            });
        }
        return eoriNumbers.stream().filter(Objects::nonNull).collect(Collectors.toList());
    }

    private <T> List<String> getEORIsFromCD003(T ddntaMessage) {
        Set<String> eoriNumbers = new HashSet<>();
        // HolderOfTheTransitProcedure fields:
        if (ObjectUtils.isNotEmpty(((CD003CType) ddntaMessage).getHolderOfTheTransitProcedure())) {
            eoriNumbers.add(getEORINumber(((CD003CType) ddntaMessage).getHolderOfTheTransitProcedure()));
        }
        if (ObjectUtils.isNotEmpty(((CD003CType) ddntaMessage).getConsignment())) {
            // Consignment.Consignor fields:
            if (ObjectUtils.isNotEmpty(((CD003CType) ddntaMessage).getConsignment().getConsignor())) {
                eoriNumbers.add(getEORINumber(((CD003CType) ddntaMessage).getConsignment().getConsignor()));
            }
            // Consignment.Consignee fields:
            if (ObjectUtils.isNotEmpty(((CD003CType) ddntaMessage).getConsignment().getConsignee())) {
                eoriNumbers.add(getEORINumber(((CD003CType) ddntaMessage).getConsignment().getConsignee()));
            }
            // Consignment.HouseConsignment.Consignor fields:
            ((CD003CType) ddntaMessage).getConsignment().getHouseConsignment().forEach(houseConsignment -> {
                if (ObjectUtils.isNotEmpty((houseConsignment.getConsignor()))) {
                    eoriNumbers.add(getEORINumber(houseConsignment.getConsignor()));
                }
                // ConsignmentItems of IE003 have no Consignor.
            });
            // Consignment.HouseConsignment.Consignee & Consignment.HouseConsignment.ConsignmentItem.Consignee fields:
            ((CD003CType) ddntaMessage).getConsignment().getHouseConsignment().forEach(houseConsignment -> {
                if (ObjectUtils.isNotEmpty((houseConsignment.getConsignee()))) {
                    eoriNumbers.add(getEORINumber(houseConsignment.getConsignee()));
                }
                // ConsignmentItems:
                houseConsignment.getConsignmentItem().forEach(consignmentItem -> {
                    if (ObjectUtils.isNotEmpty((consignmentItem.getConsignee()))) {
                        eoriNumbers.add(getEORINumber(consignmentItem.getConsignee()));
                    }
                });
            });
        }
        return eoriNumbers.stream().filter(Objects::nonNull).collect(Collectors.toList());
    }

    private <T> List<String> getEORIsFromCD038(T ddntaMessage) {
        Set<String> eoriNumbers = new HashSet<>();
        // HolderOfTheTransitProcedure fields:
        if (ObjectUtils.isNotEmpty(((CD038CType) ddntaMessage).getHolderOfTheTransitProcedure())) {
            eoriNumbers.add(getEORINumber(((CD038CType) ddntaMessage).getHolderOfTheTransitProcedure()));
        }
        if (ObjectUtils.isNotEmpty(((CD038CType) ddntaMessage).getConsignment())) {
            // Consignment.Consignor fields:
            if (ObjectUtils.isNotEmpty(((CD038CType) ddntaMessage).getConsignment().getConsignor())) {
                eoriNumbers.add(getEORINumber(((CD038CType) ddntaMessage).getConsignment().getConsignor()));
            }
            // Consignment.Consignee fields:
            if (ObjectUtils.isNotEmpty(((CD038CType) ddntaMessage).getConsignment().getConsignee())) {
                eoriNumbers.add(getEORINumber(((CD038CType) ddntaMessage).getConsignment().getConsignee()));
            }
            // Consignment.HouseConsignment.Consignor fields:
            ((CD038CType) ddntaMessage).getConsignment().getHouseConsignment().forEach(houseConsignment -> {
                if (ObjectUtils.isNotEmpty((houseConsignment.getConsignor()))) {
                    eoriNumbers.add(getEORINumber(houseConsignment.getConsignor()));
                }
                // ConsignmentItems of IE038 have no Consignor.
            });
            // Consignment.HouseConsignment.Consignee & Consignment.HouseConsignment.ConsignmentItem.Consignee fields:
            ((CD038CType) ddntaMessage).getConsignment().getHouseConsignment().forEach(houseConsignment -> {
                if (ObjectUtils.isNotEmpty((houseConsignment.getConsignee()))) {
                    eoriNumbers.add(getEORINumber(houseConsignment.getConsignee()));
                }
                // ConsignmentItems:
                houseConsignment.getConsignmentItem().forEach(consignmentItem -> {
                    if (ObjectUtils.isNotEmpty((consignmentItem.getConsignee()))) {
                        eoriNumbers.add(getEORINumber(consignmentItem.getConsignee()));
                    }
                });
            });
        }
        return eoriNumbers.stream().filter(Objects::nonNull).collect(Collectors.toList());
    }

    private <T> List<String> getEORIsFromCD160(T ddntaMessage) {
        Set<String> eoriNumbers = new HashSet<>();
        if (ObjectUtils.isNotEmpty(((CD160CType) ddntaMessage).getHolderOfTheTransitProcedure())) {
            eoriNumbers.add(getEORINumber(((CD160CType) ddntaMessage).getHolderOfTheTransitProcedure()));
        }
        if (ObjectUtils.isNotEmpty(((CD160CType) ddntaMessage).getConsignment())) {
            // Consignment.Consignor fields:
            if (ObjectUtils.isNotEmpty(((CD160CType) ddntaMessage).getConsignment().getConsignor())) {
                eoriNumbers.add(getEORINumber(((CD160CType) ddntaMessage).getConsignment().getConsignor()));
            }
            // Consignment.Consignee fields:
            if (ObjectUtils.isNotEmpty(((CD160CType) ddntaMessage).getConsignment().getConsignee())) {
                eoriNumbers.add(getEORINumber(((CD160CType) ddntaMessage).getConsignment().getConsignee()));
            }
            // Consignment.HouseConsignment.Consignor fields:
            ((CD160CType) ddntaMessage).getConsignment().getHouseConsignment().forEach(houseConsignment -> {
                if (ObjectUtils.isNotEmpty((houseConsignment.getConsignor()))) {
                    eoriNumbers.add(getEORINumber(houseConsignment.getConsignor()));
                }
                // ConsignmentItems of IE160 have no Consignor.
            });
            // Consignment.HouseConsignment.Consignee & Consignment.HouseConsignment.ConsignmentItem.Consignee fields:
            ((CD160CType) ddntaMessage).getConsignment().getHouseConsignment().forEach(houseConsignment -> {
                if (ObjectUtils.isNotEmpty((houseConsignment.getConsignee()))) {
                    eoriNumbers.add(getEORINumber(houseConsignment.getConsignee()));
                }
                // ConsignmentItems:
                houseConsignment.getConsignmentItem().forEach(consignmentItem -> {
                    if (ObjectUtils.isNotEmpty((consignmentItem.getConsignee()))) {
                        eoriNumbers.add(getEORINumber(consignmentItem.getConsignee()));
                    }
                });
            });
        }
        return eoriNumbers.stream().filter(Objects::nonNull).collect(Collectors.toList());
    }

    private <T> List<String> getEORIsFromCD050(T ddntaMessage) {
        Set<String> eoriNumbers = new HashSet<>();
        if (ObjectUtils.isNotEmpty(((CD050CType) ddntaMessage).getHolderOfTheTransitProcedure())) {
            eoriNumbers.add(getEORINumber(((CD050CType) ddntaMessage).getHolderOfTheTransitProcedure()));
        }
        if (ObjectUtils.isNotEmpty(((CD050CType) ddntaMessage).getConsignment())) {
            // Consignment.Consignor fields:
            if (ObjectUtils.isNotEmpty(((CD050CType) ddntaMessage).getConsignment().getConsignor())) {
                eoriNumbers.add(getEORINumber(((CD050CType) ddntaMessage).getConsignment().getConsignor()));
            }
            // Consignment.Consignee fields:
            if (ObjectUtils.isNotEmpty(((CD050CType) ddntaMessage).getConsignment().getConsignee())) {
                eoriNumbers.add(getEORINumber(((CD050CType) ddntaMessage).getConsignment().getConsignee()));
            }
            // Consignment.HouseConsignment.Consignor fields:
            ((CD050CType) ddntaMessage).getConsignment().getHouseConsignment().forEach(houseConsignment -> {
                if (ObjectUtils.isNotEmpty((houseConsignment.getConsignor()))) {
                    eoriNumbers.add(getEORINumber(houseConsignment.getConsignor()));
                }
                // ConsignmentItems of IE050 have no Consignor.
            });
            // Consignment.HouseConsignment.Consignee & Consignment.HouseConsignment.ConsignmentItem.Consignee fields:
            ((CD050CType) ddntaMessage).getConsignment().getHouseConsignment().forEach(houseConsignment -> {
                if (ObjectUtils.isNotEmpty((houseConsignment.getConsignee()))) {
                    eoriNumbers.add(getEORINumber(houseConsignment.getConsignee()));
                }
                // ConsignmentItems:
                houseConsignment.getConsignmentItem().forEach(consignmentItem -> {
                    if (ObjectUtils.isNotEmpty((consignmentItem.getConsignee()))) {
                        eoriNumbers.add(getEORINumber(consignmentItem.getConsignee()));
                    }
                });
            });
        }
        return eoriNumbers.stream().filter(Objects::nonNull).collect(Collectors.toList());
    }

    private List<Organization> getOrganizations(List<String> eoriNumbers) {
        List<Organization> partyMgtResponse = new ArrayList<>();
        try {
            // call the party-mgt endpoint
            partyMgtResponse = partyManagementPort.findOrganizationsByIdentificationValues(IDENTIFICATION_TYPE_EORI, eoriNumbers, false);
        } catch (Exception e) {
            // catch the failure in order to proceed with filling '---' in the messages
            log.error("ERROR while calling party management {}", e.getMessage());
        }
        return partyMgtResponse;
    }

    private Map<String, Map<String, String>> getEoriDetails(List<String> eoriNumbers) {

        Map<String, Map<String, String>> eoriDetailsMap = new HashMap<>();
        List<Organization> organizationList = getOrganizations(eoriNumbers);
        // For each EORI number found:
        eoriNumbers.forEach(eori ->
                // Iterate over all returned Organizations:
                organizationList.forEach(organization -> {
                    // If Organization includes identification matching that of the EORI Number...
                    if (organization.getIdentifications()
                                    .stream()
                                    .anyMatch(partyIdentification -> IDENTIFICATION_TYPE_EORI.equals(partyIdentification.getPartyIdentificationType())
                                            && eori.equals(partyIdentification.getNumber()))) {
                        // ...then add first address (if exists) to the eoriDetailsMap:
                        Map<String, String> innerDetailsMap = new HashMap<>();
                        innerDetailsMap.put(NAME, organization.getName());

                        if (organization.getAddresses() != null && !organization.getAddresses().isEmpty() && organization.getAddresses().get(0) != null) {
                            PhysicalAddress partyAddress = organization.getAddresses().get(0);

                            innerDetailsMap.put(STREET_AND_NUMBER, partyAddress.getStreetAndNumber());
                            innerDetailsMap.put(POSTCODE, partyAddress.getZipCode());
                            innerDetailsMap.put(CITY, partyAddress.getCityName());
                            innerDetailsMap.put(COUNTRY, partyAddress.getCountry());
                        }

                        eoriDetailsMap.put(eori, innerDetailsMap);
                    }
                })
        );

        return eoriDetailsMap;
    }

    private <T> List<String> getEORIsFromCD001(T ddntaMessage) {
        Set<String> eoriNumbers = new HashSet<>();
        if (ObjectUtils.isNotEmpty(((CD001CType) ddntaMessage).getHolderOfTheTransitProcedure())) {
            eoriNumbers.add(getEORINumber(((CD001CType) ddntaMessage).getHolderOfTheTransitProcedure()));
        }
        if (ObjectUtils.isNotEmpty(((CD001CType) ddntaMessage).getConsignment())) {
            // Consignment.Consignor fields:
            if (ObjectUtils.isNotEmpty(((CD001CType) ddntaMessage).getConsignment().getConsignor())) {
                eoriNumbers.add(getEORINumber(((CD001CType) ddntaMessage).getConsignment().getConsignor()));
            }
            // Consignment.Consignee fields:
            if (ObjectUtils.isNotEmpty(((CD001CType) ddntaMessage).getConsignment().getConsignee())) {
                eoriNumbers.add(getEORINumber(((CD001CType) ddntaMessage).getConsignment().getConsignee()));
            }
            // Consignment.HouseConsignment.Consignor fields:
            ((CD001CType) ddntaMessage).getConsignment().getHouseConsignment().forEach(houseConsignment -> {
                if (ObjectUtils.isNotEmpty((houseConsignment.getConsignor()))) {
                    eoriNumbers.add(getEORINumber(houseConsignment.getConsignor()));
                }
                // ConsignmentItems of IE001 have no Consignor.
            });
            // Consignment.HouseConsignment.Consignee & Consignment.HouseConsignment.ConsignmentItem.Consignee fields:
            ((CD001CType) ddntaMessage).getConsignment().getHouseConsignment().forEach(houseConsignment -> {
                if (ObjectUtils.isNotEmpty((houseConsignment.getConsignee()))) {
                    eoriNumbers.add(getEORINumber(houseConsignment.getConsignee()));
                }
                // ConsignmentItems:
                houseConsignment.getConsignmentItem().forEach(consignmentItem -> {
                    if (ObjectUtils.isNotEmpty((consignmentItem.getConsignee()))) {
                        eoriNumbers.add(getEORINumber(consignmentItem.getConsignee()));
                    }
                });
            });
        }
        return eoriNumbers.stream().filter(Objects::nonNull).collect(Collectors.toList());
    }

    private void editHolderOfTheTransitProcedureType05(HolderOfTheTransitProcedureType05 holderOfTheTransitProcedure, String countryToBeUsed,
            Map<String, Map<String, String>> eoriDetailsMap, HolderOfTheTransitProcedureType14 holderFromIE015) {
        String nameFromIE015 = getNameOfHolderFromIE015(holderFromIE015);
        editNameFieldByReflection(holderOfTheTransitProcedure, eoriDetailsMap, nameFromIE015);

        if (ObjectUtils.isEmpty(holderOfTheTransitProcedure.getAddress())) {
            holderOfTheTransitProcedure.setAddress(new AddressType07());
        }
        AddressType17 addressFromIE015 = getAddressOfHolderFromIE015(holderFromIE015);
        editAddressFieldsByReflection(holderOfTheTransitProcedure.getAddress(), countryToBeUsed, getEORINumber(holderOfTheTransitProcedure), eoriDetailsMap,
                addressFromIE015);
    }

    private void editHolderOfTheTransitProcedureType11(HolderOfTheTransitProcedureType11 holderOfTheTransitProcedure, String countryToBeUsed,
            Map<String, Map<String, String>> eoriDetailsMap, HolderOfTheTransitProcedureType14 holderFromIE015) {
        String nameFromIE015 = getNameOfHolderFromIE015(holderFromIE015);
        editNameFieldByReflection(holderOfTheTransitProcedure, eoriDetailsMap, nameFromIE015);

        if (ObjectUtils.isEmpty(holderOfTheTransitProcedure.getAddress())) {
            holderOfTheTransitProcedure.setAddress(new AddressType20());
        }

        AddressType17 addressFromIE015 = getAddressOfHolderFromIE015(holderFromIE015);
        editAddressFieldsByReflection(holderOfTheTransitProcedure.getAddress(), countryToBeUsed, getEORINumber(holderOfTheTransitProcedure), eoriDetailsMap,
                addressFromIE015);
    }

    private void editHolderOfTheTransitProcedureType16(HolderOfTheTransitProcedureType16 holderOfTheTransitProcedure, String countryToBeUsed,
            Map<String, Map<String, String>> eoriDetailsMap, HolderOfTheTransitProcedureType14 holderFromIE015) {
        String nameFromIE015 = getNameOfHolderFromIE015(holderFromIE015);
        editNameFieldByReflection(holderOfTheTransitProcedure, eoriDetailsMap, nameFromIE015);

        if (ObjectUtils.isEmpty(holderOfTheTransitProcedure.getAddress())) {
            holderOfTheTransitProcedure.setAddress(new AddressType20());
        }
        AddressType17 addressFromIE015 = getAddressOfHolderFromIE015(holderFromIE015);
        editAddressFieldsByReflection(holderOfTheTransitProcedure.getAddress(), countryToBeUsed, getEORINumber(holderOfTheTransitProcedure), eoriDetailsMap,
                addressFromIE015);
    }

    private void editHolderOfTheTransitProcedureType17(HolderOfTheTransitProcedureType17 holderOfTheTransitProcedure, String countryToBeUsed,
            Map<String, Map<String, String>> eoriDetailsMap, HolderOfTheTransitProcedureType14 holderFromIE015) {
        String nameFromIE015 = getNameOfHolderFromIE015(holderFromIE015);
        editNameFieldByReflection(holderOfTheTransitProcedure, eoriDetailsMap, nameFromIE015);

        if (ObjectUtils.isEmpty(holderOfTheTransitProcedure.getAddress())) {
            holderOfTheTransitProcedure.setAddress(new AddressType20());
        }
        AddressType17 addressFromIE015 = getAddressOfHolderFromIE015(holderFromIE015);
        editAddressFieldsByReflection(holderOfTheTransitProcedure.getAddress(), countryToBeUsed, getEORINumber(holderOfTheTransitProcedure), eoriDetailsMap,
                addressFromIE015);
    }

    private void editHolderOfTheTransitProcedureType18(HolderOfTheTransitProcedureType18 holderOfTheTransitProcedure, String countryToBeUsed,
            Map<String, Map<String, String>> eoriDetailsMap, HolderOfTheTransitProcedureType14 holderFromIE015) {
        String nameFromIE015 = getNameOfHolderFromIE015(holderFromIE015);
        editNameFieldByReflection(holderOfTheTransitProcedure, eoriDetailsMap, nameFromIE015);

        if (ObjectUtils.isEmpty(holderOfTheTransitProcedure.getAddress())) {
            holderOfTheTransitProcedure.setAddress(new AddressType20());
        }
        AddressType17 addressFromIE015 = getAddressOfHolderFromIE015(holderFromIE015);
        editAddressFieldsByReflection(holderOfTheTransitProcedure.getAddress(), countryToBeUsed, getEORINumber(holderOfTheTransitProcedure), eoriDetailsMap,
                addressFromIE015);
    }

    private void editConsignorType03(ConsignorType03 consignor, String countryToBeUsed, Map<String, Map<String, String>> eoriDetailsMap,
            ConsignorType07 consignorFromIE015) {
        String consignorNameFromIE015 = getNameOfConsignorFromIE015(consignorFromIE015);
        editNameFieldByReflection(consignor, eoriDetailsMap, consignorNameFromIE015);

        if (ObjectUtils.isEmpty(consignor.getAddress())) {
            consignor.setAddress(new AddressType07());
        }
        AddressType17 consignorAddressFromIE015 = getAddressOfConsignorFromIE015(consignorFromIE015);
        editAddressFieldsByReflection(consignor.getAddress(), countryToBeUsed, getEORINumber(consignor), eoriDetailsMap, consignorAddressFromIE015);

    }

    private void editConsignorType04(ConsignorType04 consignor, String countryToBeUsed, Map<String, Map<String, String>> eoriDetailsMap,
            ConsignorType07 consignorFromIE015) {
        String consignorNameFromIE015 = getNameOfConsignorFromIE015(consignorFromIE015);
        editNameFieldByReflection(consignor, eoriDetailsMap, consignorNameFromIE015);

        if (ObjectUtils.isEmpty(consignor.getAddress())) {
            consignor.setAddress(new AddressType07());
        }
        AddressType17 consignorAddressFromIE015 = getAddressOfConsignorFromIE015(consignorFromIE015);
        editAddressFieldsByReflection(consignor.getAddress(), countryToBeUsed, getEORINumber(consignor), eoriDetailsMap, consignorAddressFromIE015);
    }

    private void editConsignorType08(ConsignorType08 consignor, String countryToBeUsed, Map<String, Map<String, String>> eoriDetailsMap,
            ConsignorType07 consignorFromIE015) {
        String consignorNameFromIE015 = getNameOfConsignorFromIE015(consignorFromIE015);
        editNameFieldByReflection(consignor, eoriDetailsMap, consignorNameFromIE015);

        if (ObjectUtils.isEmpty(consignor.getAddress())) {
            consignor.setAddress(new AddressType20());
        }
        AddressType17 consignorAddressFromIE015 = getAddressOfConsignorFromIE015(consignorFromIE015);
        editAddressFieldsByReflection(consignor.getAddress(), countryToBeUsed, getEORINumber(consignor), eoriDetailsMap, consignorAddressFromIE015);
    }

    private void editConsignorType09(ConsignorType09 consignor, String countryToBeUsed, Map<String, Map<String, String>> eoriDetailsMap,
            ConsignorType07 consignorFromIE015) {
        String consignorNameFromIE015 = getNameOfConsignorFromIE015(consignorFromIE015);
        editNameFieldByReflection(consignor, eoriDetailsMap, consignorNameFromIE015);

        if (ObjectUtils.isEmpty(consignor.getAddress())) {
            consignor.setAddress(new AddressType20());
        }
        AddressType17 consignorAddressFromIE015 = getAddressOfConsignorFromIE015(consignorFromIE015);
        editAddressFieldsByReflection(consignor.getAddress(), countryToBeUsed, getEORINumber(consignor), eoriDetailsMap, consignorAddressFromIE015);

    }

    private void editConsigneeType03(ConsigneeType03 consignee, String countryToBeUsed, Map<String, Map<String, String>> eoriDetailsMap,
            ConsigneeType02 consigneeFromIE015) {
        String consigneeNameFromIE015 = getNameOfConsigneeType02FromIE015(consigneeFromIE015);
        editNameFieldByReflection(consignee, eoriDetailsMap, consigneeNameFromIE015);

        if (ObjectUtils.isEmpty(consignee.getAddress())) {
            consignee.setAddress(new AddressType09());
        }
        AddressType12 consigneeAddressFromIE015 = getAddressOfConsigneeType02FromIE015(consigneeFromIE015);
        editAddressFieldsByReflection(consignee.getAddress(), countryToBeUsed, getEORINumber(consignee), eoriDetailsMap, consigneeAddressFromIE015);

    }

    private void editConsigneeType04(ConsigneeType04 consignee, String countryToBeUsed, Map<String, Map<String, String>> eoriDetailsMap,
            ConsigneeType05 consigneeFromIE015) {
        String consigneeNameFromIE015 = getNameOfConsigneeFromIE015(consigneeFromIE015);
        editNameFieldByReflection(consignee, eoriDetailsMap, consigneeNameFromIE015);

        if (ObjectUtils.isEmpty(consignee.getAddress())) {
            consignee.setAddress(new AddressType07());
        }
        AddressType17 consigneeAddressFromIE015 = getAddressOfConsigneeFromIE015(consigneeFromIE015);
        editAddressFieldsByReflection(consignee.getAddress(), countryToBeUsed, getEORINumber(consignee), eoriDetailsMap, consigneeAddressFromIE015);
    }

    private void editConsigneeType06(ConsigneeType06 consignee, String countryToBeUsed, Map<String, Map<String, String>> eoriDetailsMap,
            ConsigneeType02 consigneeFromIE015) {
        String consigneeNameFromIE015 = getNameOfConsigneeType02FromIE015(consigneeFromIE015);
        editNameFieldByReflection(consignee, eoriDetailsMap, consigneeNameFromIE015);

        if (ObjectUtils.isEmpty(consignee.getAddress())) {
            consignee.setAddress(new AddressType19());
        }
        AddressType12 consigneeAddressFromIE015 = getAddressOfConsigneeType02FromIE015(consigneeFromIE015);
        editAddressFieldsByReflection(consignee.getAddress(), countryToBeUsed, getEORINumber(consignee), eoriDetailsMap, consigneeAddressFromIE015);

    }

    private void editConsigneeType07(ConsigneeType07 consignee, String countryToBeUsed, Map<String, Map<String, String>> eoriDetailsMap,
            ConsigneeType05 consigneeFromIE015) {
        String consigneeNameFromIE015 = getNameOfConsigneeFromIE015(consigneeFromIE015);
        editNameFieldByReflection(consignee, eoriDetailsMap, consigneeNameFromIE015);

        if (ObjectUtils.isEmpty(consignee.getAddress())) {
            consignee.setAddress(new AddressType20());
        }
        AddressType17 consigneeAddressFromIE015 = getAddressOfConsigneeFromIE015(consigneeFromIE015);
        editAddressFieldsByReflection(consignee.getAddress(), countryToBeUsed, getEORINumber(consignee), eoriDetailsMap, consigneeAddressFromIE015);
    }

    private <T> void editNameFieldByReflection(T input,
            Map<String, Map<String, String>> eoriDetailsMap, String nameFromIE015) {

        try {
            Field nameField = input.getClass().getDeclaredField("name");
            nameField.setAccessible(true);

            String identificationNumber = getEORINumber(input);
            String nameProp = getKeyFromEoriDetailsMap(NAME, identificationNumber, eoriDetailsMap);
            log.info("processDetails;In editNameFieldByReflection, nameProperty '{}' for identificationNumber '{}'", nameProp, identificationNumber);

            if (StringUtils.isNotBlank(nameProp)) {
                nameField.set(input, nameProp);
            } else if (StringUtils.isNotBlank(nameFromIE015)) {
                nameField.set(input, nameFromIE015);
            } else {
                nameField.set(input, DUMMY_VALUE_FOR_VOID_DATA);
            }

        } catch (NoSuchFieldException | IllegalAccessException e) {
            log.error("ERROR: Failed to edit 'name' field in " + input.getClass().getSimpleName() + " Class.");
        }
    }

    private <T1, T2> void editAddressFieldsByReflection(T1 input, String countryToBeUsed, String identificationNumber,
            Map<String, Map<String, String>> eoriDetailsMap, T2 addressFromIE015) {

        try {
            Field streetAndNumberField = input.getClass().getDeclaredField(STREET_AND_NUMBER);
            Field postcodeField = input.getClass().getDeclaredField(POSTCODE);
            Field cityField = input.getClass().getDeclaredField(CITY);
            Field countryField = input.getClass().getDeclaredField(COUNTRY);

            streetAndNumberField.setAccessible(true);
            postcodeField.setAccessible(true);
            cityField.setAccessible(true);
            countryField.setAccessible(true);

            String streetAndNumberFromIE015 = null;
            String postCodeFromIE015 = null;
            String cityFromIE015 = null;
            String countryFromIE015 = null;
            // get details from IE015
            if (addressFromIE015 != null) {
                Field streetAndNumberFieldFromIE015 = addressFromIE015.getClass().getDeclaredField(STREET_AND_NUMBER);
                Field postcodeFieldFromIE015 = addressFromIE015.getClass().getDeclaredField(POSTCODE);
                Field cityFieldFromIE015 = addressFromIE015.getClass().getDeclaredField(CITY);
                Field countryFieldFromIE015 = addressFromIE015.getClass().getDeclaredField(COUNTRY);

                streetAndNumberFieldFromIE015.setAccessible(true);
                postcodeFieldFromIE015.setAccessible(true);
                cityFieldFromIE015.setAccessible(true);
                countryFieldFromIE015.setAccessible(true);

                streetAndNumberFromIE015 = (String) streetAndNumberFieldFromIE015.get(addressFromIE015);
                postCodeFromIE015 = (String) postcodeFieldFromIE015.get(addressFromIE015);
                cityFromIE015 = (String) cityFieldFromIE015.get(addressFromIE015);
                countryFromIE015 = (String) countryFieldFromIE015.get(addressFromIE015);
            }
            log.info("processDetails; In editAddressFieldsByReflection for identificationNumber: '{}'", identificationNumber);
            log.info("streetAndNumberFromIE015 '{}' ", streetAndNumberFromIE015);
            log.info("postCodeFromIE015 '{}' ", postCodeFromIE015);
            log.info("cityFromIE015 '{}' ", cityFromIE015);
            log.info("countryFromIE015 '{}' ", countryFromIE015);

            String streetAndNumberProp = getKeyFromEoriDetailsMap(STREET_AND_NUMBER, identificationNumber, eoriDetailsMap);
            String postCodeProp = getKeyFromEoriDetailsMap(POSTCODE, identificationNumber, eoriDetailsMap);
            String cityProp = getKeyFromEoriDetailsMap(CITY, identificationNumber, eoriDetailsMap);
            String countryProp = getKeyFromEoriDetailsMap(COUNTRY, identificationNumber, eoriDetailsMap);
            log.info("streetAndNumberPropFromPM '{}' ", streetAndNumberProp);
            log.info("postCodePropFromPM '{}' ", postCodeProp);
            log.info("cityPropFromPM '{}' ", cityProp);
            log.info("countryPropFromPM '{}' ", countryProp);

            if (StringUtils.isNotBlank(streetAndNumberProp)) {
                streetAndNumberField.set(input, streetAndNumberProp);
            } else if (StringUtils.isNotBlank(streetAndNumberFromIE015)) {
                streetAndNumberField.set(input, streetAndNumberFromIE015);
            } else {
                streetAndNumberField.set(input, DUMMY_VALUE_FOR_VOID_DATA);
            }

            if (StringUtils.isNotBlank(postCodeProp)) {
                postcodeField.set(input, postCodeProp);
            } else if (StringUtils.isNotBlank(postCodeFromIE015)) {
                postcodeField.set(input, postCodeFromIE015);
            } else {
                postcodeField.set(input, DUMMY_VALUE_FOR_VOID_DATA);
            }

            if (StringUtils.isNotBlank(cityProp)) {
                cityField.set(input, cityProp);
            } else if (StringUtils.isNotBlank(cityFromIE015)) {
                cityField.set(input, cityFromIE015);
            } else {
                cityField.set(input, DUMMY_VALUE_FOR_VOID_DATA);
            }

            if (StringUtils.isNotBlank(countryProp)) {
                countryField.set(input, countryProp);
            } else if (StringUtils.isNotBlank(countryFromIE015)) {
                countryField.set(input, countryFromIE015);
            } else {
                countryField.set(input, countryToBeUsed);
            }

        } catch (NoSuchFieldException | IllegalAccessException e) {
            log.error("ERROR: Failed to edit fields streetAndNumber/postcode/city/country in " + input.getClass().getSimpleName() + " Class.");
        }
    }

    private String getKeyFromEoriDetailsMap(String key, String identificationNumber, Map<String, Map<String, String>> eoriDetailsMap) {
        Optional<Map<String, String>> optionalEoriDetailsMap = Optional.ofNullable(eoriDetailsMap.get(identificationNumber));
        String value = null;
        if (optionalEoriDetailsMap.isPresent() && !optionalEoriDetailsMap.get().isEmpty()) {
            Map<String, String> eoriDetailsValues = optionalEoriDetailsMap.get();
            log.debug("processdetails;Values from eoriDetailsValues: {}", eoriDetailsValues);
            value = eoriDetailsValues.get(key);
        }
        return value;
    }

    private <T> String getEORINumber(T input) {
        String eori = null;
        try {
            Field identificationNumberField = input.getClass().getDeclaredField("identificationNumber");
            identificationNumberField.setAccessible(true);
            if (ObjectUtils.isNotEmpty(identificationNumberField.get(input))) {
                eori = identificationNumberField.get(input).toString();
            }
        } catch (NoSuchFieldException | IllegalAccessException e) {
            log.error("ERROR: Failed to get 'identificationNumber' field from " + input.getClass().getSimpleName() + " Class.");
        }
        return eori;
    }

    private HolderOfTheTransitProcedureType14 getHolderFromIE015(CC015CType cc015cMessage) {
        log.info("processDetails;In getHolderFromIE015");
        HolderOfTheTransitProcedureType14 holderFromIE015 = null;
        if (cc015cMessage != null) {
            holderFromIE015 = cc015cMessage.getHolderOfTheTransitProcedure();
        }
        return holderFromIE015;
    }

    private ConsignorType07 getConsignmentConsignorFromIE015(CC015CType cc015cMessage) {
        log.info("processDetails;In getConsignmentConsignorFromIE015");
        ConsignorType07 consignmentConsignorFromIE015 = null;
        if (cc015cMessage != null && cc015cMessage.getConsignment() != null) {
            consignmentConsignorFromIE015 = cc015cMessage.getConsignment().getConsignor();
        }
        return consignmentConsignorFromIE015;
    }

    private ConsigneeType05 getConsignmentConsigneeFromIE015(CC015CType cc015cMessage) {
        log.info("processDetails;In getConsignmentConsigneeFromIE015");
        ConsigneeType05 consignmentConsigneeFromIE015 = null;
        if (cc015cMessage != null && cc015cMessage.getConsignment() != null) {
            consignmentConsigneeFromIE015 = cc015cMessage.getConsignment().getConsignee();
        }
        return consignmentConsigneeFromIE015;
    }

    private ConsigneeType05 getConsignmentHCConsigneeFromIE015(AtomicInteger houseConsignmentCounter, CC015CType cc015cMessage) {
        log.info("processDetails;In getConsignmentHCConsigneeFromIE015");
        ConsigneeType05 consignmentHCConsigneeFromIE015 = null;
        HouseConsignmentType10 consignmentHC = getConsigneeOfHCFromIE015(houseConsignmentCounter, cc015cMessage);
        if (consignmentHC != null) {
            consignmentHCConsigneeFromIE015 = consignmentHC.getConsignee();
        }
        return consignmentHCConsigneeFromIE015;
    }

    private HouseConsignmentType10 getConsigneeOfHCFromIE015(AtomicInteger houseConsignmentCounter, CC015CType cc015cMessage) {
        log.info("processDetails;In getConsigneeOfHCFromIE015");
        HouseConsignmentType10 houseConsignmentType10 = null;
        if (cc015cMessage != null && cc015cMessage.getConsignment() != null &&
                cc015cMessage.getConsignment().getHouseConsignment() != null) {
            try {
                houseConsignmentType10 = cc015cMessage.getConsignment()
                                                      .getHouseConsignment()
                                                      .get(houseConsignmentCounter.get());
            } catch (IndexOutOfBoundsException e) {
                log.info("There is no houseConsignment({}) entry in CC015C", houseConsignmentCounter.get());
            }
        }
        return houseConsignmentType10;
    }

    private ConsigneeType02 getConsignmentHCConsignmentItemConsigneeFromIE015(AtomicInteger houseConsignmentCounter, AtomicInteger hcConsignmentItemCounter,
            CC015CType cc015cMessage) {
        log.info("processDetails;In getConsignmentHCConsignmentItemConsigneeFromIE015");
        ConsignmentItemType09 consignmentItemFromIE015 = null;
        ConsigneeType02 consignee = null;
        if (cc015cMessage != null && cc015cMessage.getConsignment() != null &&
                cc015cMessage.getConsignment().getHouseConsignment() != null) {
            try {
                consignmentItemFromIE015 = cc015cMessage.getConsignment().getHouseConsignment()
                                                        .get(houseConsignmentCounter.get())
                                                        .getConsignmentItem()
                                                        .get(hcConsignmentItemCounter.get());
            } catch (IndexOutOfBoundsException e) {
                log.info("There is no houseConsignment({}).consignmentItem({}) entry in CC015C", houseConsignmentCounter.get(), hcConsignmentItemCounter.get());
            }
        }
        if (consignmentItemFromIE015 != null) {
            consignee = consignmentItemFromIE015.getConsignee();
        }
        return consignee;
    }

    private ConsignorType07 getConsignmentHCConsignorFromIE015(AtomicInteger houseConsignmentCounter, CC015CType cc015cMessage) {
        log.info("processDetails;In getConsignmentHCConsignorFromIE015");
        ConsignorType07 consignmentHCConsignorFromIE015 = null;
        HouseConsignmentType10 consignmentHC = getConsignorOfHCFromIE015(houseConsignmentCounter, cc015cMessage);
        if (consignmentHC != null) {
            consignmentHCConsignorFromIE015 = consignmentHC.getConsignor();
        }
        return consignmentHCConsignorFromIE015;
    }

    private HouseConsignmentType10 getConsignorOfHCFromIE015(AtomicInteger houseConsignmentCounter, CC015CType cc015cMessage) {
        log.info("processDetails;In getConsignorOfHCFromIE015");
        HouseConsignmentType10 houseConsignmentType10 = null;
        if (cc015cMessage != null && cc015cMessage.getConsignment() != null &&
                cc015cMessage.getConsignment().getHouseConsignment() != null) {
            try {
                houseConsignmentType10 = cc015cMessage.getConsignment()
                                                      .getHouseConsignment()
                                                      .get(houseConsignmentCounter.get());
            } catch (IndexOutOfBoundsException e) {
                log.info("There is no houseConsignment({}) entry in CC015C", houseConsignmentCounter.get());
            }
        }
        return houseConsignmentType10;
    }

    private String getNameOfHolderFromIE015(HolderOfTheTransitProcedureType14 holderFromIE015) {
        log.info("processDetails;In getNameOfHolderFromIE015");
        String nameFromIE015 = null;
        if (holderFromIE015 != null) {
            nameFromIE015 = holderFromIE015.getName();
        }
        return nameFromIE015;
    }

    private String getNameOfConsignorFromIE015(ConsignorType07 consignorFromIE015) {
        log.info("processDetails;In getNameOfConsignorFromIE015");
        String nameFromIE015 = null;
        if (consignorFromIE015 != null) {
            nameFromIE015 = consignorFromIE015.getName();
        }
        return nameFromIE015;
    }

    private String getNameOfConsigneeFromIE015(ConsigneeType05 consigneeFromIE015) {
        log.info("processDetails;In getNameOfConsigneeFromIE015");
        String nameFromIE015 = null;
        if (consigneeFromIE015 != null) {
            nameFromIE015 = consigneeFromIE015.getName();
        }
        return nameFromIE015;
    }

    private String getNameOfConsigneeType02FromIE015(ConsigneeType02 consigneeFromIE015) {
        log.info("processDetails;In getNameOfConsigneeType02FromIE015");
        String nameFromIE015 = null;
        if (consigneeFromIE015 != null) {
            nameFromIE015 = consigneeFromIE015.getName();
        }
        return nameFromIE015;
    }

    private AddressType17 getAddressOfConsignorFromIE015(ConsignorType07 consignorFromIE015) {
        log.info("processDetails;In getAddressOfConsignorFromIE015");
        AddressType17 addressFromIE015 = new AddressType17();
        if (consignorFromIE015 != null) {
            addressFromIE015 = consignorFromIE015.getAddress();
        }
        return addressFromIE015;
    }

    private AddressType17 getAddressOfConsigneeFromIE015(ConsigneeType05 consigneeFromIE015) {
        log.info("processDetails;In getAddressOfConsigneeFromIE015");
        AddressType17 addressFromIE015 = new AddressType17();
        if (consigneeFromIE015 != null) {
            addressFromIE015 = consigneeFromIE015.getAddress();
        }
        return addressFromIE015;
    }

    private AddressType17 getAddressOfHolderFromIE015(HolderOfTheTransitProcedureType14 holderFromIE015) {
        log.info("processDetails;In getAddressOfHolderFromIE015");
        AddressType17 addressFromIE015 = new AddressType17();
        if (holderFromIE015 != null) {
            addressFromIE015 = holderFromIE015.getAddress();
        }
        return addressFromIE015;
    }

    private AddressType12 getAddressOfConsigneeType02FromIE015(ConsigneeType02 consigneeFromIE015) {
        log.info("processDetails;In getAddressOfConsigneeType02FromIE015");
        AddressType12 addressFromIE015 = new AddressType12();
        if (consigneeFromIE015 != null) {
            addressFromIE015 = consigneeFromIE015.getAddress();
        }
        return addressFromIE015;
    }

}

package com.intrasoft.ermis.trs.officeofdeparture.service;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.when;

import com.intrasoft.ermis.common.json.parsing.JsonConverter;
import com.intrasoft.ermis.common.json.parsing.JsonConverterFactory;
import com.intrasoft.ermis.common.logging.ErmisLogger;
import com.intrasoft.ermis.ddntav5152.messages.AddressType12;
import com.intrasoft.ermis.ddntav5152.messages.AddressType17;
import com.intrasoft.ermis.ddntav5152.messages.AddressType19;
import com.intrasoft.ermis.ddntav5152.messages.AddressType20;
import com.intrasoft.ermis.ddntav5152.messages.CC015CType;
import com.intrasoft.ermis.ddntav5152.messages.CD001CType;
import com.intrasoft.ermis.ddntav5152.messages.ConsigneeType02;
import com.intrasoft.ermis.ddntav5152.messages.ConsigneeType05;
import com.intrasoft.ermis.ddntav5152.messages.ConsigneeType06;
import com.intrasoft.ermis.ddntav5152.messages.ConsigneeType07;
import com.intrasoft.ermis.ddntav5152.messages.ConsignmentItemType09;
import com.intrasoft.ermis.ddntav5152.messages.ConsignmentItemType11;
import com.intrasoft.ermis.ddntav5152.messages.ConsignmentType10;
import com.intrasoft.ermis.ddntav5152.messages.ConsignmentType20;
import com.intrasoft.ermis.ddntav5152.messages.ConsignorType07;
import com.intrasoft.ermis.ddntav5152.messages.ConsignorType08;
import com.intrasoft.ermis.ddntav5152.messages.ConsignorType09;
import com.intrasoft.ermis.ddntav5152.messages.HolderOfTheTransitProcedureType11;
import com.intrasoft.ermis.ddntav5152.messages.HolderOfTheTransitProcedureType14;
import com.intrasoft.ermis.ddntav5152.messages.HouseConsignmentType10;
import com.intrasoft.ermis.ddntav5152.messages.HouseConsignmentType12;
import com.intrasoft.ermis.platform.shared.adapter.party.management.core.PartyManagementPort;
import com.intrasoft.ermis.platform.shared.adapter.party.management.core.domain.PartyIdentification;
import com.intrasoft.ermis.platform.shared.adapter.party.management.core.domain.PhysicalAddress;
import com.intrasoft.ermis.platform.shared.adapter.party.management.core.domain.organization.Organization;
import com.intrasoft.ermis.transit.officeofdeparture.domain.ExternalSystemResponseProperty;
import com.intrasoft.ermis.transit.officeofdeparture.service.ProcessPersonDetailsServiceImpl;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;

@ExtendWith(MockitoExtension.class)
public class ProcessPersonDetailsServiceImplUT {

    @Mock
    private ErmisLogger log;

    private static final JsonConverter JSON_CONVERTER = JsonConverterFactory.getDefaultJsonConverter();

    private static final String DUMMY_VALUE_FOR_VOID_DATA = "---";

    private static final String DUMMY_VALUE_FOR_VOID_COUNTRY = "DK";

    private static final String MOCKED_EXISTING_DATA = "DATA";
    private static final String MOCKED_EXISTING_DATA_IE015 = "DATA_IE015";

    private static final String EORI_1 = "DK222222221";
    private static final String EORI_2 = "DK222222222";
    private static final String EORI_3 = "DK222222223";
    public static final String NAME_1 = "Thomas Richtigen";
    public static final String NAME_2 = "Laura Pasparten";
    public static final String NAME_3 = "Steve Stevensunt";
    public static final String POST_CODE_1 = "65631";
    public static final String POST_CODE_2 = "65632";
    public static final String POST_CODE_3 = "65633";
    public static final String STREET_AND_NUMBER_1 = "KarlStrasse 2";
    public static final String STREET_AND_NUMBER_2 = "Philipou 2";
    public static final String CITY_1 = "Berlin";
    public static final String CITY_2 = "Athina";
    public static final String COUNTRY_1 = "Germany";
    public static final String COUNTRY_2 = "Greece";

    private static final String MESSAGE_ID = "d7647fe0-e0cb-419e-81cc-2fd95e5ad555";

    private static final String EXTERNAL_SYSTEM = "party-mgt";

    private static final String IDENTIFICATION_TYPE_EORI = "1";

    @Mock
    private PartyManagementPort partyManagementPort;

    @InjectMocks
    private ProcessPersonDetailsServiceImpl processPersonDetailsService;

    @ParameterizedTest
    @ValueSource(strings = {"empty", "incomplete"})
    @DisplayName("Test - EORI Data Mock Utility Functionality Without EORIs for IE001")
    void testEORIPersonDetailsWithoutEORIsForIE001(String testCase) {

        boolean isEmptyTestCase = "empty".equals(testCase.toLowerCase(Locale.ROOT));

        CD001CType cd001cTypeMessage = isEmptyTestCase? createEmptyIE001() : createIncompleteIE001();
        log.info("Initial payload: " + JSON_CONVERTER.convertToJsonString(cd001cTypeMessage));

        // without external system properties
        List<Organization> partyMgtResponse = new ArrayList<>();
        List<String> eoriNumbers = new ArrayList<>();
        when(partyManagementPort.findOrganizationsByIdentificationValues(IDENTIFICATION_TYPE_EORI, eoriNumbers, false)).thenReturn(partyMgtResponse);

        processPersonDetailsService.processEmptyPersonDetails(cd001cTypeMessage, DUMMY_VALUE_FOR_VOID_COUNTRY, null);
        log.info("Modified payload: " + JSON_CONVERTER.convertToJsonString(cd001cTypeMessage));

        // HolderOfTheTransitProcedure fields:
        assertEquals(DUMMY_VALUE_FOR_VOID_DATA,
                cd001cTypeMessage.getHolderOfTheTransitProcedure().getName());
        assertEquals(DUMMY_VALUE_FOR_VOID_DATA,
                cd001cTypeMessage.getHolderOfTheTransitProcedure().getAddress().getStreetAndNumber());
        assertEquals(DUMMY_VALUE_FOR_VOID_DATA,
                cd001cTypeMessage.getHolderOfTheTransitProcedure().getAddress().getPostcode());
        assertEquals(DUMMY_VALUE_FOR_VOID_DATA,
                cd001cTypeMessage.getHolderOfTheTransitProcedure().getAddress().getCity());
        assertEquals(DUMMY_VALUE_FOR_VOID_COUNTRY,
                cd001cTypeMessage.getHolderOfTheTransitProcedure().getAddress().getCountry());
        // Consignment.Consignor fields:
        assertEquals(DUMMY_VALUE_FOR_VOID_DATA,
                cd001cTypeMessage.getConsignment().getConsignor().getName());
        assertEquals(DUMMY_VALUE_FOR_VOID_DATA,
                cd001cTypeMessage.getConsignment().getConsignor().getAddress().getStreetAndNumber());
        assertEquals(DUMMY_VALUE_FOR_VOID_DATA,
                cd001cTypeMessage.getConsignment().getConsignor().getAddress().getPostcode());
        assertEquals(DUMMY_VALUE_FOR_VOID_DATA,
                cd001cTypeMessage.getConsignment().getConsignor().getAddress().getCity());
        assertEquals(DUMMY_VALUE_FOR_VOID_COUNTRY,
                cd001cTypeMessage.getConsignment().getConsignor().getAddress().getCountry());
        // Consignment.Consignee fields:
        assertEquals(DUMMY_VALUE_FOR_VOID_DATA,
                cd001cTypeMessage.getConsignment().getConsignee().getName());
        assertEquals(DUMMY_VALUE_FOR_VOID_DATA,
                cd001cTypeMessage.getConsignment().getConsignee().getAddress().getStreetAndNumber());
        assertEquals(DUMMY_VALUE_FOR_VOID_DATA,
                cd001cTypeMessage.getConsignment().getConsignee().getAddress().getPostcode());
        assertEquals(DUMMY_VALUE_FOR_VOID_DATA,
                cd001cTypeMessage.getConsignment().getConsignee().getAddress().getCity());
        assertEquals(DUMMY_VALUE_FOR_VOID_COUNTRY,
                cd001cTypeMessage.getConsignment().getConsignee().getAddress().getCountry());
        // Consignment.HouseConsignment.Consignor fields:
        assertEquals(DUMMY_VALUE_FOR_VOID_DATA,
                cd001cTypeMessage.getConsignment().getHouseConsignment().get(0).getConsignor().getName());
        assertEquals(DUMMY_VALUE_FOR_VOID_DATA,
                cd001cTypeMessage.getConsignment().getHouseConsignment().get(0).getConsignor().getAddress().getStreetAndNumber());
        assertEquals(DUMMY_VALUE_FOR_VOID_DATA,
                cd001cTypeMessage.getConsignment().getHouseConsignment().get(0).getConsignor().getAddress().getPostcode());
        assertEquals(DUMMY_VALUE_FOR_VOID_DATA,
                cd001cTypeMessage.getConsignment().getHouseConsignment().get(0).getConsignor().getAddress().getCity());
        assertEquals(DUMMY_VALUE_FOR_VOID_COUNTRY,
                cd001cTypeMessage.getConsignment().getHouseConsignment().get(0).getConsignor().getAddress().getCountry());
        // Consignment.HouseConsignment.Consignee fields:
        assertEquals(DUMMY_VALUE_FOR_VOID_DATA,
                cd001cTypeMessage.getConsignment().getHouseConsignment().get(0).getConsignee().getName());
        assertEquals(DUMMY_VALUE_FOR_VOID_DATA,
                cd001cTypeMessage.getConsignment().getHouseConsignment().get(0).getConsignee().getAddress().getStreetAndNumber());
        assertEquals(DUMMY_VALUE_FOR_VOID_DATA,
                cd001cTypeMessage.getConsignment().getHouseConsignment().get(0).getConsignee().getAddress().getPostcode());
        assertEquals(DUMMY_VALUE_FOR_VOID_DATA,
                cd001cTypeMessage.getConsignment().getHouseConsignment().get(0).getConsignee().getAddress().getCity());
        assertEquals(DUMMY_VALUE_FOR_VOID_COUNTRY,
                cd001cTypeMessage.getConsignment().getHouseConsignment().get(0).getConsignee().getAddress().getCountry());
        // Consignment.HouseConsignment.ConsignmentItem.Consignee fields:
        assertEquals(DUMMY_VALUE_FOR_VOID_DATA,
                cd001cTypeMessage.getConsignment().getHouseConsignment().get(0).getConsignmentItem().get(0).getConsignee().getName());
        assertEquals(DUMMY_VALUE_FOR_VOID_DATA,
                cd001cTypeMessage.getConsignment().getHouseConsignment().get(0).getConsignmentItem().get(0).getConsignee().getAddress().getStreetAndNumber());
        assertEquals(DUMMY_VALUE_FOR_VOID_DATA,
                cd001cTypeMessage.getConsignment().getHouseConsignment().get(0).getConsignmentItem().get(0).getConsignee().getAddress().getPostcode());
        assertEquals(DUMMY_VALUE_FOR_VOID_DATA,
                cd001cTypeMessage.getConsignment().getHouseConsignment().get(0).getConsignmentItem().get(0).getConsignee().getAddress().getCity());
        assertEquals(DUMMY_VALUE_FOR_VOID_COUNTRY,
                cd001cTypeMessage.getConsignment().getHouseConsignment().get(0).getConsignmentItem().get(0).getConsignee().getAddress().getCountry());
    }

    @Test
    @DisplayName("Test - EORI Data Mock Utility Functionality With EORI for IE001")
    void testEORIPersonDetailsWithEORIsForIE001_WithoutPartyMgtResponseData() {

        CD001CType cd001cTypeMessage = createIncompleteIE001WithEORIs();
        log.info("Initial payload: " + JSON_CONVERTER.convertToJsonString(cd001cTypeMessage));

        List<Organization> partyMgtResponse = new ArrayList<>();
        List<String> eoriNumbers = new ArrayList<>();
        eoriNumbers.add(EORI_1);
        eoriNumbers.add(EORI_2);
        eoriNumbers.add(EORI_3);
        when(partyManagementPort.findOrganizationsByIdentificationValues(IDENTIFICATION_TYPE_EORI, eoriNumbers, false)).thenReturn(partyMgtResponse);

        processPersonDetailsService.processEmptyPersonDetails(cd001cTypeMessage, DUMMY_VALUE_FOR_VOID_COUNTRY, null);
        log.info("Modified payload: " + JSON_CONVERTER.convertToJsonString(cd001cTypeMessage));

        // HolderOfTheTransitProcedure fields:
        assertEquals(DUMMY_VALUE_FOR_VOID_DATA,
                cd001cTypeMessage.getHolderOfTheTransitProcedure().getName());
        assertEquals(DUMMY_VALUE_FOR_VOID_DATA,
                cd001cTypeMessage.getHolderOfTheTransitProcedure().getAddress().getStreetAndNumber());
        assertEquals(DUMMY_VALUE_FOR_VOID_DATA,
                cd001cTypeMessage.getHolderOfTheTransitProcedure().getAddress().getPostcode());
        assertEquals(DUMMY_VALUE_FOR_VOID_DATA,
                cd001cTypeMessage.getHolderOfTheTransitProcedure().getAddress().getCity());
        assertEquals(DUMMY_VALUE_FOR_VOID_COUNTRY,
                cd001cTypeMessage.getHolderOfTheTransitProcedure().getAddress().getCountry());
        // Consignment.Consignor fields:
        assertEquals(DUMMY_VALUE_FOR_VOID_DATA,
                cd001cTypeMessage.getConsignment().getConsignor().getName());
        assertEquals(DUMMY_VALUE_FOR_VOID_DATA,
                cd001cTypeMessage.getConsignment().getConsignor().getAddress().getStreetAndNumber());
        assertEquals(DUMMY_VALUE_FOR_VOID_DATA,
                cd001cTypeMessage.getConsignment().getConsignor().getAddress().getPostcode());
        assertEquals(DUMMY_VALUE_FOR_VOID_DATA,
                cd001cTypeMessage.getConsignment().getConsignor().getAddress().getCity());
        assertEquals(DUMMY_VALUE_FOR_VOID_COUNTRY,
                cd001cTypeMessage.getConsignment().getConsignor().getAddress().getCountry());
        // Consignment.Consignee fields:
        assertEquals(DUMMY_VALUE_FOR_VOID_DATA,
                cd001cTypeMessage.getConsignment().getConsignee().getName());
        assertEquals(DUMMY_VALUE_FOR_VOID_DATA,
                cd001cTypeMessage.getConsignment().getConsignee().getAddress().getStreetAndNumber());
        assertEquals(DUMMY_VALUE_FOR_VOID_DATA,
                cd001cTypeMessage.getConsignment().getConsignee().getAddress().getPostcode());
        assertEquals(DUMMY_VALUE_FOR_VOID_DATA,
                cd001cTypeMessage.getConsignment().getConsignee().getAddress().getCity());
        assertEquals(DUMMY_VALUE_FOR_VOID_COUNTRY,
                cd001cTypeMessage.getConsignment().getConsignee().getAddress().getCountry());
        // Consignment.HouseConsignment.Consignor fields:
        assertEquals(DUMMY_VALUE_FOR_VOID_DATA,
                cd001cTypeMessage.getConsignment().getHouseConsignment().get(0).getConsignor().getName());
        assertEquals(DUMMY_VALUE_FOR_VOID_DATA,
                cd001cTypeMessage.getConsignment().getHouseConsignment().get(0).getConsignor().getAddress().getStreetAndNumber());
        assertEquals(DUMMY_VALUE_FOR_VOID_DATA,
                cd001cTypeMessage.getConsignment().getHouseConsignment().get(0).getConsignor().getAddress().getPostcode());
        assertEquals(DUMMY_VALUE_FOR_VOID_DATA,
                cd001cTypeMessage.getConsignment().getHouseConsignment().get(0).getConsignor().getAddress().getCity());
        assertEquals(DUMMY_VALUE_FOR_VOID_COUNTRY,
                cd001cTypeMessage.getConsignment().getHouseConsignment().get(0).getConsignor().getAddress().getCountry());
        // Consignment.HouseConsignment.Consignee fields:
        assertEquals(DUMMY_VALUE_FOR_VOID_DATA,
                cd001cTypeMessage.getConsignment().getHouseConsignment().get(0).getConsignee().getName());
        assertEquals(DUMMY_VALUE_FOR_VOID_DATA,
                cd001cTypeMessage.getConsignment().getHouseConsignment().get(0).getConsignee().getAddress().getStreetAndNumber());
        assertEquals(DUMMY_VALUE_FOR_VOID_DATA,
                cd001cTypeMessage.getConsignment().getHouseConsignment().get(0).getConsignee().getAddress().getPostcode());
        assertEquals(DUMMY_VALUE_FOR_VOID_DATA,
                cd001cTypeMessage.getConsignment().getHouseConsignment().get(0).getConsignee().getAddress().getCity());
        assertEquals(DUMMY_VALUE_FOR_VOID_COUNTRY,
                cd001cTypeMessage.getConsignment().getHouseConsignment().get(0).getConsignee().getAddress().getCountry());
        // Consignment.HouseConsignment.ConsignmentItem.Consignee fields:
        assertEquals(DUMMY_VALUE_FOR_VOID_DATA,
                cd001cTypeMessage.getConsignment().getHouseConsignment().get(0).getConsignmentItem().get(0).getConsignee().getName());
        assertEquals(DUMMY_VALUE_FOR_VOID_DATA,
                cd001cTypeMessage.getConsignment().getHouseConsignment().get(0).getConsignmentItem().get(0).getConsignee().getAddress().getStreetAndNumber());
        assertEquals(DUMMY_VALUE_FOR_VOID_DATA,
                cd001cTypeMessage.getConsignment().getHouseConsignment().get(0).getConsignmentItem().get(0).getConsignee().getAddress().getPostcode());
        assertEquals(DUMMY_VALUE_FOR_VOID_DATA,
                cd001cTypeMessage.getConsignment().getHouseConsignment().get(0).getConsignmentItem().get(0).getConsignee().getAddress().getCity());
        assertEquals(DUMMY_VALUE_FOR_VOID_COUNTRY,
                cd001cTypeMessage.getConsignment().getHouseConsignment().get(0).getConsignmentItem().get(0).getConsignee().getAddress().getCountry());
    }

    @Test
    @DisplayName("Test 1 - EORI Data Mock Utility Functionality With EORI for IE001 and IE015 data")
    void testEORIPersonDetailsWithEORIsForIE001_WithDataFromIE015() {

        CD001CType cd001cTypeMessage = createIncompleteIE001WithEORIs();
        log.info("Initial payload IE001: " + JSON_CONVERTER.convertToJsonString(cd001cTypeMessage));
        CC015CType cc015cTypeMessage = createIncompleteIE015WithEORIs();

        List<Organization> partyMgtResponse = new ArrayList<>();
        List<String> eoriNumbers = new ArrayList<>();
        eoriNumbers.add(EORI_1);
        eoriNumbers.add(EORI_2);
        eoriNumbers.add(EORI_3);
        when(partyManagementPort.findOrganizationsByIdentificationValues(IDENTIFICATION_TYPE_EORI, eoriNumbers, false)).thenReturn(partyMgtResponse);

        processPersonDetailsService.processEmptyPersonDetails(cd001cTypeMessage, DUMMY_VALUE_FOR_VOID_COUNTRY, cc015cTypeMessage);
        log.info("Modified payload: " + JSON_CONVERTER.convertToJsonString(cd001cTypeMessage));

        // HolderOfTheTransitProcedure fields:
        assertEquals(MOCKED_EXISTING_DATA_IE015,
                cd001cTypeMessage.getHolderOfTheTransitProcedure().getName());
        assertEquals(DUMMY_VALUE_FOR_VOID_DATA,
                cd001cTypeMessage.getHolderOfTheTransitProcedure().getAddress().getStreetAndNumber());
        assertEquals(DUMMY_VALUE_FOR_VOID_DATA,
                cd001cTypeMessage.getHolderOfTheTransitProcedure().getAddress().getPostcode());
        assertEquals(MOCKED_EXISTING_DATA_IE015,
                cd001cTypeMessage.getHolderOfTheTransitProcedure().getAddress().getCity());
        assertEquals(DUMMY_VALUE_FOR_VOID_COUNTRY,
                cd001cTypeMessage.getHolderOfTheTransitProcedure().getAddress().getCountry());
        // Consignment.Consignor fields:
        assertEquals(DUMMY_VALUE_FOR_VOID_DATA,
                cd001cTypeMessage.getConsignment().getConsignor().getName());
        assertEquals(MOCKED_EXISTING_DATA_IE015,
                cd001cTypeMessage.getConsignment().getConsignor().getAddress().getStreetAndNumber());
        assertEquals(DUMMY_VALUE_FOR_VOID_DATA,
                cd001cTypeMessage.getConsignment().getConsignor().getAddress().getPostcode());
        assertEquals(DUMMY_VALUE_FOR_VOID_DATA,
                cd001cTypeMessage.getConsignment().getConsignor().getAddress().getCity());
        assertEquals(DUMMY_VALUE_FOR_VOID_COUNTRY,
                cd001cTypeMessage.getConsignment().getConsignor().getAddress().getCountry());
        // Consignment.Consignee fields:
        assertEquals(DUMMY_VALUE_FOR_VOID_DATA,
                cd001cTypeMessage.getConsignment().getConsignee().getName());
        assertEquals(DUMMY_VALUE_FOR_VOID_DATA,
                cd001cTypeMessage.getConsignment().getConsignee().getAddress().getStreetAndNumber());
        assertEquals(MOCKED_EXISTING_DATA_IE015,
                cd001cTypeMessage.getConsignment().getConsignee().getAddress().getPostcode());
        assertEquals(DUMMY_VALUE_FOR_VOID_DATA,
                cd001cTypeMessage.getConsignment().getConsignee().getAddress().getCity());
        assertEquals(MOCKED_EXISTING_DATA_IE015,
                cd001cTypeMessage.getConsignment().getConsignee().getAddress().getCountry());
        // Consignment.HouseConsignment.Consignor fields:
        assertEquals(MOCKED_EXISTING_DATA_IE015,
                cd001cTypeMessage.getConsignment().getHouseConsignment().get(0).getConsignor().getName());
        assertEquals(DUMMY_VALUE_FOR_VOID_DATA,
                cd001cTypeMessage.getConsignment().getHouseConsignment().get(0).getConsignor().getAddress().getStreetAndNumber());
        assertEquals(DUMMY_VALUE_FOR_VOID_DATA,
                cd001cTypeMessage.getConsignment().getHouseConsignment().get(0).getConsignor().getAddress().getPostcode());
        assertEquals(DUMMY_VALUE_FOR_VOID_DATA,
                cd001cTypeMessage.getConsignment().getHouseConsignment().get(0).getConsignor().getAddress().getCity());
        assertEquals(DUMMY_VALUE_FOR_VOID_COUNTRY,
                cd001cTypeMessage.getConsignment().getHouseConsignment().get(0).getConsignor().getAddress().getCountry());
        // Consignment.HouseConsignment.Consignee fields:
        assertEquals(DUMMY_VALUE_FOR_VOID_DATA,
                cd001cTypeMessage.getConsignment().getHouseConsignment().get(0).getConsignee().getName());
        assertEquals(DUMMY_VALUE_FOR_VOID_DATA,
                cd001cTypeMessage.getConsignment().getHouseConsignment().get(0).getConsignee().getAddress().getStreetAndNumber());
        assertEquals(DUMMY_VALUE_FOR_VOID_DATA,
                cd001cTypeMessage.getConsignment().getHouseConsignment().get(0).getConsignee().getAddress().getPostcode());
        assertEquals(MOCKED_EXISTING_DATA_IE015,
                cd001cTypeMessage.getConsignment().getHouseConsignment().get(0).getConsignee().getAddress().getCity());
        assertEquals(DUMMY_VALUE_FOR_VOID_COUNTRY,
                cd001cTypeMessage.getConsignment().getHouseConsignment().get(0).getConsignee().getAddress().getCountry());
        // Consignment.HouseConsignment.ConsignmentItem.Consignee fields:
        assertEquals(MOCKED_EXISTING_DATA_IE015,
                cd001cTypeMessage.getConsignment().getHouseConsignment().get(0).getConsignmentItem().get(0).getConsignee().getName());
        assertEquals(MOCKED_EXISTING_DATA_IE015,
                cd001cTypeMessage.getConsignment().getHouseConsignment().get(0).getConsignmentItem().get(0).getConsignee().getAddress().getStreetAndNumber());
        assertEquals(DUMMY_VALUE_FOR_VOID_DATA,
                cd001cTypeMessage.getConsignment().getHouseConsignment().get(0).getConsignmentItem().get(0).getConsignee().getAddress().getPostcode());
        assertEquals(MOCKED_EXISTING_DATA_IE015,
                cd001cTypeMessage.getConsignment().getHouseConsignment().get(0).getConsignmentItem().get(0).getConsignee().getAddress().getCity());
        assertEquals(DUMMY_VALUE_FOR_VOID_COUNTRY,
                cd001cTypeMessage.getConsignment().getHouseConsignment().get(0).getConsignmentItem().get(0).getConsignee().getAddress().getCountry());
    }


    @Test
    @DisplayName("Test 2 - EORI Data Mock Utility Functionality With EORI for IE001 and IE015 data")
    void testEORIPersonDetailsWithEORIsForIE001_WithDataFromIE015_NoHCCiMatch() {

        CD001CType cd001cTypeMessage = createIncompleteIE001WithEORIs();
        log.info("Initial payload IE001: " + JSON_CONVERTER.convertToJsonString(cd001cTypeMessage));
        CC015CType cc015cTypeMessage = createIncompleteIE015WithEORIsNoHCCiMatch();

        List<Organization> partyMgtResponse = new ArrayList<>();
        List<String> eoriNumbers = new ArrayList<>();
        eoriNumbers.add(EORI_1);
        eoriNumbers.add(EORI_2);
        eoriNumbers.add(EORI_3);
        when(partyManagementPort.findOrganizationsByIdentificationValues(IDENTIFICATION_TYPE_EORI, eoriNumbers, false)).thenReturn(partyMgtResponse);

        processPersonDetailsService.processEmptyPersonDetails(cd001cTypeMessage, DUMMY_VALUE_FOR_VOID_COUNTRY, cc015cTypeMessage);
        log.info("Modified payload: " + JSON_CONVERTER.convertToJsonString(cd001cTypeMessage));

        // HolderOfTheTransitProcedure fields:
        assertEquals(MOCKED_EXISTING_DATA_IE015,
                cd001cTypeMessage.getHolderOfTheTransitProcedure().getName());
        assertEquals(DUMMY_VALUE_FOR_VOID_DATA,
                cd001cTypeMessage.getHolderOfTheTransitProcedure().getAddress().getStreetAndNumber());
        assertEquals(DUMMY_VALUE_FOR_VOID_DATA,
                cd001cTypeMessage.getHolderOfTheTransitProcedure().getAddress().getPostcode());
        assertEquals(MOCKED_EXISTING_DATA_IE015,
                cd001cTypeMessage.getHolderOfTheTransitProcedure().getAddress().getCity());
        assertEquals(DUMMY_VALUE_FOR_VOID_COUNTRY,
                cd001cTypeMessage.getHolderOfTheTransitProcedure().getAddress().getCountry());
        // Consignment.Consignor fields:
        assertEquals(DUMMY_VALUE_FOR_VOID_DATA,
                cd001cTypeMessage.getConsignment().getConsignor().getName());
        assertEquals(MOCKED_EXISTING_DATA_IE015,
                cd001cTypeMessage.getConsignment().getConsignor().getAddress().getStreetAndNumber());
        assertEquals(DUMMY_VALUE_FOR_VOID_DATA,
                cd001cTypeMessage.getConsignment().getConsignor().getAddress().getPostcode());
        assertEquals(DUMMY_VALUE_FOR_VOID_DATA,
                cd001cTypeMessage.getConsignment().getConsignor().getAddress().getCity());
        assertEquals(DUMMY_VALUE_FOR_VOID_COUNTRY,
                cd001cTypeMessage.getConsignment().getConsignor().getAddress().getCountry());
        // Consignment.Consignee fields:
        assertEquals(DUMMY_VALUE_FOR_VOID_DATA,
                cd001cTypeMessage.getConsignment().getConsignee().getName());
        assertEquals(DUMMY_VALUE_FOR_VOID_DATA,
                cd001cTypeMessage.getConsignment().getConsignee().getAddress().getStreetAndNumber());
        assertEquals(MOCKED_EXISTING_DATA_IE015,
                cd001cTypeMessage.getConsignment().getConsignee().getAddress().getPostcode());
        assertEquals(DUMMY_VALUE_FOR_VOID_DATA,
                cd001cTypeMessage.getConsignment().getConsignee().getAddress().getCity());
        assertEquals(MOCKED_EXISTING_DATA_IE015,
                cd001cTypeMessage.getConsignment().getConsignee().getAddress().getCountry());
        // Consignment.HouseConsignment.Consignor fields:
        assertEquals(MOCKED_EXISTING_DATA_IE015,
                cd001cTypeMessage.getConsignment().getHouseConsignment().get(0).getConsignor().getName());
        assertEquals(DUMMY_VALUE_FOR_VOID_DATA,
                cd001cTypeMessage.getConsignment().getHouseConsignment().get(0).getConsignor().getAddress().getStreetAndNumber());
        assertEquals(DUMMY_VALUE_FOR_VOID_DATA,
                cd001cTypeMessage.getConsignment().getHouseConsignment().get(0).getConsignor().getAddress().getPostcode());
        assertEquals(DUMMY_VALUE_FOR_VOID_DATA,
                cd001cTypeMessage.getConsignment().getHouseConsignment().get(0).getConsignor().getAddress().getCity());
        assertEquals(DUMMY_VALUE_FOR_VOID_COUNTRY,
                cd001cTypeMessage.getConsignment().getHouseConsignment().get(0).getConsignor().getAddress().getCountry());
        // Consignment.HouseConsignment.Consignee fields:
        assertEquals(DUMMY_VALUE_FOR_VOID_DATA,
                cd001cTypeMessage.getConsignment().getHouseConsignment().get(0).getConsignee().getName());
        assertEquals(DUMMY_VALUE_FOR_VOID_DATA,
                cd001cTypeMessage.getConsignment().getHouseConsignment().get(0).getConsignee().getAddress().getStreetAndNumber());
        assertEquals(DUMMY_VALUE_FOR_VOID_DATA,
                cd001cTypeMessage.getConsignment().getHouseConsignment().get(0).getConsignee().getAddress().getPostcode());
        assertEquals(MOCKED_EXISTING_DATA_IE015,
                cd001cTypeMessage.getConsignment().getHouseConsignment().get(0).getConsignee().getAddress().getCity());
        assertEquals(DUMMY_VALUE_FOR_VOID_COUNTRY,
                cd001cTypeMessage.getConsignment().getHouseConsignment().get(0).getConsignee().getAddress().getCountry());
        // Consignment.HouseConsignment.ConsignmentItem.Consignee fields:
        assertEquals(MOCKED_EXISTING_DATA_IE015,
                cd001cTypeMessage.getConsignment().getHouseConsignment().get(0).getConsignmentItem().get(0).getConsignee().getName());
        assertEquals(MOCKED_EXISTING_DATA_IE015,
                cd001cTypeMessage.getConsignment().getHouseConsignment().get(0).getConsignmentItem().get(0).getConsignee().getAddress().getStreetAndNumber());
        assertEquals(DUMMY_VALUE_FOR_VOID_DATA,
                cd001cTypeMessage.getConsignment().getHouseConsignment().get(0).getConsignmentItem().get(0).getConsignee().getAddress().getPostcode());
        assertEquals(MOCKED_EXISTING_DATA_IE015,
                cd001cTypeMessage.getConsignment().getHouseConsignment().get(0).getConsignmentItem().get(0).getConsignee().getAddress().getCity());
        assertEquals(DUMMY_VALUE_FOR_VOID_COUNTRY,
                cd001cTypeMessage.getConsignment().getHouseConsignment().get(0).getConsignmentItem().get(0).getConsignee().getAddress().getCountry());
    }

    @Test
    @DisplayName("Test - EORI Data Mock Utility Functionality With EORI for IE001 and Party Mgt Response Data")
    void testEORIPersonDetailsWithEORIsForIE001_WithPartyMgtResponseData() {

        CD001CType cd001cTypeMessage = createIncompleteIE001WithEORIs();
        log.info("Initial payload: " + JSON_CONVERTER.convertToJsonString(cd001cTypeMessage));

        List<Organization> partyMgtResponse = getPartyMgtResponseData();
        List<String> eoriNumbers = new ArrayList<>();
        eoriNumbers.add(EORI_1);
        eoriNumbers.add(EORI_2);
        eoriNumbers.add(EORI_3);
        when(partyManagementPort.findOrganizationsByIdentificationValues(eq(IDENTIFICATION_TYPE_EORI), any(), eq(false))).thenReturn(partyMgtResponse);

        processPersonDetailsService.processEmptyPersonDetails(cd001cTypeMessage, DUMMY_VALUE_FOR_VOID_COUNTRY, null);
        log.info("Modified payload: " + JSON_CONVERTER.convertToJsonString(cd001cTypeMessage));

        // HolderOfTheTransitProcedure fields:
        assertEquals(NAME_1,
                cd001cTypeMessage.getHolderOfTheTransitProcedure().getName());
        assertEquals(STREET_AND_NUMBER_1,
                cd001cTypeMessage.getHolderOfTheTransitProcedure().getAddress().getStreetAndNumber());
        assertEquals(POST_CODE_1,
                cd001cTypeMessage.getHolderOfTheTransitProcedure().getAddress().getPostcode());
        assertEquals(CITY_1,
                cd001cTypeMessage.getHolderOfTheTransitProcedure().getAddress().getCity());
        assertEquals(COUNTRY_1,
                cd001cTypeMessage.getHolderOfTheTransitProcedure().getAddress().getCountry());
        // Consignment.Consignor fields:
        assertEquals(NAME_2,
                cd001cTypeMessage.getConsignment().getConsignor().getName());
        assertEquals(STREET_AND_NUMBER_2,
                cd001cTypeMessage.getConsignment().getConsignor().getAddress().getStreetAndNumber());
        assertEquals(POST_CODE_2,
                cd001cTypeMessage.getConsignment().getConsignor().getAddress().getPostcode());
        assertEquals(CITY_2,
                cd001cTypeMessage.getConsignment().getConsignor().getAddress().getCity());
        assertEquals(COUNTRY_2,
                cd001cTypeMessage.getConsignment().getConsignor().getAddress().getCountry());
        // Consignment.Consignee fields:
        assertEquals(DUMMY_VALUE_FOR_VOID_DATA,
                cd001cTypeMessage.getConsignment().getConsignee().getName());
        assertEquals(DUMMY_VALUE_FOR_VOID_DATA,
                cd001cTypeMessage.getConsignment().getConsignee().getAddress().getStreetAndNumber());
        assertEquals(DUMMY_VALUE_FOR_VOID_DATA,
                cd001cTypeMessage.getConsignment().getConsignee().getAddress().getPostcode());
        assertEquals(DUMMY_VALUE_FOR_VOID_DATA,
                cd001cTypeMessage.getConsignment().getConsignee().getAddress().getCity());
        assertEquals(DUMMY_VALUE_FOR_VOID_COUNTRY,
                cd001cTypeMessage.getConsignment().getConsignee().getAddress().getCountry());
        // Consignment.HouseConsignment.Consignor fields:
        assertEquals(NAME_1,
                cd001cTypeMessage.getConsignment().getHouseConsignment().get(0).getConsignor().getName());
        assertEquals(STREET_AND_NUMBER_1,
                cd001cTypeMessage.getConsignment().getHouseConsignment().get(0).getConsignor().getAddress().getStreetAndNumber());
        assertEquals(POST_CODE_1,
                cd001cTypeMessage.getConsignment().getHouseConsignment().get(0).getConsignor().getAddress().getPostcode());
        assertEquals(CITY_1,
                cd001cTypeMessage.getConsignment().getHouseConsignment().get(0).getConsignor().getAddress().getCity());
        assertEquals(COUNTRY_1,
                cd001cTypeMessage.getConsignment().getHouseConsignment().get(0).getConsignor().getAddress().getCountry());
        // Consignment.HouseConsignment.Consignee fields:
        assertEquals(NAME_2,
                cd001cTypeMessage.getConsignment().getHouseConsignment().get(0).getConsignee().getName());
        assertEquals(STREET_AND_NUMBER_2,
                cd001cTypeMessage.getConsignment().getHouseConsignment().get(0).getConsignee().getAddress().getStreetAndNumber());
        assertEquals(POST_CODE_2,
                cd001cTypeMessage.getConsignment().getHouseConsignment().get(0).getConsignee().getAddress().getPostcode());
        assertEquals(CITY_2,
                cd001cTypeMessage.getConsignment().getHouseConsignment().get(0).getConsignee().getAddress().getCity());
        assertEquals(COUNTRY_2,
                cd001cTypeMessage.getConsignment().getHouseConsignment().get(0).getConsignee().getAddress().getCountry());
        // Consignment.HouseConsignment.ConsignmentItem.Consignee fields:
        assertEquals(DUMMY_VALUE_FOR_VOID_DATA,
                cd001cTypeMessage.getConsignment().getHouseConsignment().get(0).getConsignmentItem().get(0).getConsignee().getName());
        assertEquals(DUMMY_VALUE_FOR_VOID_DATA,
                cd001cTypeMessage.getConsignment().getHouseConsignment().get(0).getConsignmentItem().get(0).getConsignee().getAddress().getStreetAndNumber());
        assertEquals(DUMMY_VALUE_FOR_VOID_DATA,
                cd001cTypeMessage.getConsignment().getHouseConsignment().get(0).getConsignmentItem().get(0).getConsignee().getAddress().getPostcode());
        assertEquals(DUMMY_VALUE_FOR_VOID_DATA,
                cd001cTypeMessage.getConsignment().getHouseConsignment().get(0).getConsignmentItem().get(0).getConsignee().getAddress().getCity());
        assertEquals(DUMMY_VALUE_FOR_VOID_COUNTRY,
                cd001cTypeMessage.getConsignment().getHouseConsignment().get(0).getConsignmentItem().get(0).getConsignee().getAddress().getCountry());
    }

    private List<Organization> getPartyMgtResponseData() {
        List<Organization> organizations = new ArrayList<>();
        List<PartyIdentification> identifications1 = new ArrayList<>();
        PartyIdentification identification1 = new PartyIdentification(IDENTIFICATION_TYPE_EORI, EORI_1, LocalDateTime.now().minusDays(1), LocalDateTime.now().plusDays(1));
        identifications1.add(identification1);
        List<PhysicalAddress> addresses1 = new ArrayList<>();
        PhysicalAddress physicalAddress1 = new PhysicalAddress(null,null,STREET_AND_NUMBER_1,null,
                CITY_1,POST_CODE_1,null,null,null,COUNTRY_1);
        addresses1.add(physicalAddress1);
        Organization org1 = new Organization(NAME_1,null,identifications1,null,addresses1,null,
                null,null,null,null,null,null,null,0,
                null,null,null,null,null,null);
        organizations.add(org1);

        List<PartyIdentification> identifications2 = new ArrayList<>();
        PartyIdentification identification2 = new PartyIdentification(IDENTIFICATION_TYPE_EORI, EORI_2, LocalDateTime.now().minusDays(1), LocalDateTime.now().plusDays(1));
        identifications2.add(identification2);
        List<PhysicalAddress> addresses2 = new ArrayList<>();
        PhysicalAddress physicalAddress2 = new PhysicalAddress(null,null,STREET_AND_NUMBER_2,null,
                CITY_2,POST_CODE_2,null,null,null,COUNTRY_2);
        addresses2.add(physicalAddress2);
        Organization org2 = new Organization(NAME_2,null,identifications2,null,addresses2,null,
                null,null,null,null,null,null,null,0,
                null,null,null,null,null,null);
        organizations.add(org2);

        return organizations;
    }

    private Map<String, ExternalSystemResponseProperty> getExternalSystemProperties() {
        Map<String, ExternalSystemResponseProperty> propertyMap = new HashMap<>();
        ExternalSystemResponseProperty property1 = new ExternalSystemResponseProperty();
        property1.setMessageId(MESSAGE_ID);
        property1.setExternalSystem(EXTERNAL_SYSTEM);
        property1.setKey("name-" + EORI_1);
        property1.setValue(NAME_1);
        propertyMap.put("name-" + EORI_1, property1);

        ExternalSystemResponseProperty property2 = new ExternalSystemResponseProperty();
        property2.setMessageId(MESSAGE_ID);
        property2.setExternalSystem(EXTERNAL_SYSTEM);
        property2.setKey("name-" + EORI_2);
        property2.setValue(NAME_2);
        propertyMap.put("name-" + EORI_2, property2);

        ExternalSystemResponseProperty property3 = new ExternalSystemResponseProperty();
        property3.setMessageId(MESSAGE_ID);
        property3.setExternalSystem(EXTERNAL_SYSTEM);
        property3.setKey("name-" + EORI_3);
        property3.setValue(NAME_3);
        propertyMap.put("name-" + EORI_3, property3);

        ExternalSystemResponseProperty property4 = new ExternalSystemResponseProperty();
        property4.setMessageId(MESSAGE_ID);
        property4.setExternalSystem(EXTERNAL_SYSTEM);
        property4.setKey("postcode-" + EORI_1);
        property4.setValue(POST_CODE_1);
        propertyMap.put("postcode-" + EORI_1, property4);

        ExternalSystemResponseProperty property5 = new ExternalSystemResponseProperty();
        property5.setMessageId(MESSAGE_ID);
        property5.setExternalSystem(EXTERNAL_SYSTEM);
        property5.setKey("postcode-" + EORI_2);
        property5.setValue(POST_CODE_2);
        propertyMap.put("postcode-" + EORI_2, property5);

        ExternalSystemResponseProperty property6 = new ExternalSystemResponseProperty();
        property6.setMessageId(MESSAGE_ID);
        property6.setExternalSystem(EXTERNAL_SYSTEM);
        property6.setKey("postcode-" + POST_CODE_3);
        property6.setValue(POST_CODE_3);
        propertyMap.put("postcode-" + EORI_3, property6);

        return propertyMap;
    }

    private CD001CType createEmptyIE001() {

        CD001CType cd001cTypeMessage = new CD001CType();

        cd001cTypeMessage.setHolderOfTheTransitProcedure(new HolderOfTheTransitProcedureType11());

        cd001cTypeMessage.setConsignment(new ConsignmentType10());
        cd001cTypeMessage.getConsignment().setConsignor(new ConsignorType08());
        cd001cTypeMessage.getConsignment().setConsignee(new ConsigneeType07());

        cd001cTypeMessage.getConsignment().getHouseConsignment().add(new HouseConsignmentType12());
        cd001cTypeMessage.getConsignment().getHouseConsignment().get(0).setConsignor(new ConsignorType09());
        cd001cTypeMessage.getConsignment().getHouseConsignment().get(0).setConsignee(new ConsigneeType07());

        cd001cTypeMessage.getConsignment().getHouseConsignment().get(0).getConsignmentItem().add(new ConsignmentItemType11());
        cd001cTypeMessage.getConsignment().getHouseConsignment().get(0).getConsignmentItem().get(0).setConsignee(new ConsigneeType06());

        return cd001cTypeMessage;
    }

    private CD001CType createIncompleteIE001() {

        CD001CType cd001cTypeMessage = createEmptyIE001();

        cd001cTypeMessage.getHolderOfTheTransitProcedure().setName(MOCKED_EXISTING_DATA);
        cd001cTypeMessage.getHolderOfTheTransitProcedure().setAddress(new AddressType20());
        cd001cTypeMessage.getHolderOfTheTransitProcedure().getAddress().setCity(MOCKED_EXISTING_DATA);

        cd001cTypeMessage.getConsignment().getConsignor().setAddress(new AddressType20());
        cd001cTypeMessage.getConsignment().getConsignor().getAddress().setStreetAndNumber(MOCKED_EXISTING_DATA);

        cd001cTypeMessage.getConsignment().getConsignee().setAddress(new AddressType20());
        cd001cTypeMessage.getConsignment().getConsignee().getAddress().setCountry(MOCKED_EXISTING_DATA);
        cd001cTypeMessage.getConsignment().getConsignee().getAddress().setPostcode(MOCKED_EXISTING_DATA);

        cd001cTypeMessage.getConsignment().getHouseConsignment().get(0).getConsignor().setName(MOCKED_EXISTING_DATA);

        cd001cTypeMessage.getConsignment().getHouseConsignment().get(0).getConsignee().setAddress(new AddressType20());
        cd001cTypeMessage.getConsignment().getHouseConsignment().get(0).getConsignee().getAddress().setCity(MOCKED_EXISTING_DATA);

        cd001cTypeMessage.getConsignment().getHouseConsignment().get(0).getConsignmentItem().get(0).getConsignee().setAddress(new AddressType19());
        cd001cTypeMessage.getConsignment().getHouseConsignment().get(0).getConsignmentItem().get(0).getConsignee().setName(MOCKED_EXISTING_DATA);
        cd001cTypeMessage.getConsignment().getHouseConsignment().get(0).getConsignmentItem().get(0).getConsignee().getAddress().setStreetAndNumber(MOCKED_EXISTING_DATA);
        cd001cTypeMessage.getConsignment().getHouseConsignment().get(0).getConsignmentItem().get(0).getConsignee().getAddress().setCity(MOCKED_EXISTING_DATA);

        return cd001cTypeMessage;
    }

    private CD001CType createIncompleteIE001WithEORIs() {

        CD001CType cd001cTypeMessage = createEmptyIE001();

        cd001cTypeMessage.getHolderOfTheTransitProcedure().setIdentificationNumber(EORI_1);
        cd001cTypeMessage.getHolderOfTheTransitProcedure().setName(MOCKED_EXISTING_DATA);
        cd001cTypeMessage.getHolderOfTheTransitProcedure().setAddress(new AddressType20());
        cd001cTypeMessage.getHolderOfTheTransitProcedure().getAddress().setCity(MOCKED_EXISTING_DATA);

        cd001cTypeMessage.getConsignment().getConsignor().setIdentificationNumber(EORI_2);
        cd001cTypeMessage.getConsignment().getConsignor().setAddress(new AddressType20());
        cd001cTypeMessage.getConsignment().getConsignor().getAddress().setStreetAndNumber(MOCKED_EXISTING_DATA);

        cd001cTypeMessage.getConsignment().getConsignee().setIdentificationNumber(EORI_3);
        cd001cTypeMessage.getConsignment().getConsignee().setAddress(new AddressType20());
        cd001cTypeMessage.getConsignment().getConsignee().getAddress().setCountry(MOCKED_EXISTING_DATA);
        cd001cTypeMessage.getConsignment().getConsignee().getAddress().setPostcode(MOCKED_EXISTING_DATA);

        cd001cTypeMessage.getConsignment().getHouseConsignment().get(0).getConsignor().setIdentificationNumber(EORI_1);
        cd001cTypeMessage.getConsignment().getHouseConsignment().get(0).getConsignor().setName(MOCKED_EXISTING_DATA);

        cd001cTypeMessage.getConsignment().getHouseConsignment().get(0).getConsignee().setIdentificationNumber(EORI_2);
        cd001cTypeMessage.getConsignment().getHouseConsignment().get(0).getConsignee().setAddress(new AddressType20());
        cd001cTypeMessage.getConsignment().getHouseConsignment().get(0).getConsignee().getAddress().setCity(MOCKED_EXISTING_DATA);

        cd001cTypeMessage.getConsignment().getHouseConsignment().get(0).getConsignmentItem().get(0).getConsignee().setIdentificationNumber(EORI_3);
        cd001cTypeMessage.getConsignment().getHouseConsignment().get(0).getConsignmentItem().get(0).getConsignee().setAddress(new AddressType19());
        cd001cTypeMessage.getConsignment().getHouseConsignment().get(0).getConsignmentItem().get(0).getConsignee().setName(MOCKED_EXISTING_DATA);
        cd001cTypeMessage.getConsignment().getHouseConsignment().get(0).getConsignmentItem().get(0).getConsignee().getAddress().setStreetAndNumber(MOCKED_EXISTING_DATA);
        cd001cTypeMessage.getConsignment().getHouseConsignment().get(0).getConsignmentItem().get(0).getConsignee().getAddress().setCity(MOCKED_EXISTING_DATA);

        return cd001cTypeMessage;
    }

    private CC015CType createEmptyIE015() {

        CC015CType cc015cTypeMessage = new CC015CType();

        cc015cTypeMessage.setHolderOfTheTransitProcedure(new HolderOfTheTransitProcedureType14());

        cc015cTypeMessage.setConsignment(new ConsignmentType20());
        cc015cTypeMessage.getConsignment().setConsignor(new ConsignorType07());
        cc015cTypeMessage.getConsignment().setConsignee(new ConsigneeType05());

        cc015cTypeMessage.getConsignment().getHouseConsignment().add(new HouseConsignmentType10());
        cc015cTypeMessage.getConsignment().getHouseConsignment().get(0).setConsignor(new ConsignorType07());
        cc015cTypeMessage.getConsignment().getHouseConsignment().get(0).setConsignee(new ConsigneeType05());

        cc015cTypeMessage.getConsignment().getHouseConsignment().get(0).getConsignmentItem().add(new ConsignmentItemType09());
        cc015cTypeMessage.getConsignment().getHouseConsignment().get(0).getConsignmentItem().get(0).setConsignee(new ConsigneeType02());
        cc015cTypeMessage.getConsignment().getHouseConsignment().get(0).getConsignmentItem().add(new ConsignmentItemType09());
        cc015cTypeMessage.getConsignment().getHouseConsignment().get(0).getConsignmentItem().get(1).setConsignee(new ConsigneeType02());

        return cc015cTypeMessage;
    }

    private CC015CType createIncompleteIE015WithEORIs() {

        CC015CType cc015cTypeMessage = createEmptyIE015();

        cc015cTypeMessage.getHolderOfTheTransitProcedure().setIdentificationNumber(EORI_1);
        cc015cTypeMessage.getHolderOfTheTransitProcedure().setName(MOCKED_EXISTING_DATA_IE015);
        cc015cTypeMessage.getHolderOfTheTransitProcedure().setAddress(new AddressType17());
        cc015cTypeMessage.getHolderOfTheTransitProcedure().getAddress().setCity(MOCKED_EXISTING_DATA_IE015);

        cc015cTypeMessage.getConsignment().getConsignor().setIdentificationNumber(EORI_2);
        cc015cTypeMessage.getConsignment().getConsignor().setAddress(new AddressType17());
        cc015cTypeMessage.getConsignment().getConsignor().getAddress().setStreetAndNumber(MOCKED_EXISTING_DATA_IE015);

        cc015cTypeMessage.getConsignment().getConsignee().setIdentificationNumber(EORI_3);
        cc015cTypeMessage.getConsignment().getConsignee().setAddress(new AddressType17());
        cc015cTypeMessage.getConsignment().getConsignee().getAddress().setCountry(MOCKED_EXISTING_DATA_IE015);
        cc015cTypeMessage.getConsignment().getConsignee().getAddress().setPostcode(MOCKED_EXISTING_DATA_IE015);

        cc015cTypeMessage.getConsignment().getHouseConsignment().get(0).getConsignor().setIdentificationNumber(EORI_1);
        cc015cTypeMessage.getConsignment().getHouseConsignment().get(0).getConsignor().setName(MOCKED_EXISTING_DATA_IE015);

        cc015cTypeMessage.getConsignment().getHouseConsignment().get(0).getConsignee().setIdentificationNumber(EORI_2);
        cc015cTypeMessage.getConsignment().getHouseConsignment().get(0).getConsignee().setAddress(new AddressType17());
        cc015cTypeMessage.getConsignment().getHouseConsignment().get(0).getConsignee().getAddress().setCity(MOCKED_EXISTING_DATA_IE015);

        cc015cTypeMessage.getConsignment().getHouseConsignment().get(0).getConsignmentItem().get(0).getConsignee().setIdentificationNumber(EORI_2);
        cc015cTypeMessage.getConsignment().getHouseConsignment().get(0).getConsignmentItem().get(0).getConsignee().setAddress(new AddressType12());
        cc015cTypeMessage.getConsignment().getHouseConsignment().get(0).getConsignmentItem().get(0).getConsignee().setName(MOCKED_EXISTING_DATA_IE015);
        cc015cTypeMessage.getConsignment().getHouseConsignment().get(0).getConsignmentItem().get(0).getConsignee().getAddress().setStreetAndNumber(MOCKED_EXISTING_DATA_IE015);
        cc015cTypeMessage.getConsignment().getHouseConsignment().get(0).getConsignmentItem().get(0).getConsignee().getAddress().setCity(MOCKED_EXISTING_DATA_IE015);

        cc015cTypeMessage.getConsignment().getHouseConsignment().get(0).getConsignmentItem().get(1).getConsignee().setIdentificationNumber(EORI_3);
        cc015cTypeMessage.getConsignment().getHouseConsignment().get(0).getConsignmentItem().get(1).getConsignee().setAddress(new AddressType12());
        cc015cTypeMessage.getConsignment().getHouseConsignment().get(0).getConsignmentItem().get(1).getConsignee().setName(MOCKED_EXISTING_DATA_IE015);
        cc015cTypeMessage.getConsignment().getHouseConsignment().get(0).getConsignmentItem().get(1).getConsignee().getAddress().setStreetAndNumber(MOCKED_EXISTING_DATA_IE015);
        cc015cTypeMessage.getConsignment().getHouseConsignment().get(0).getConsignmentItem().get(1).getConsignee().getAddress().setCity(MOCKED_EXISTING_DATA_IE015);

        return cc015cTypeMessage;
    }


    private CC015CType createIncompleteIE015WithEORIsNoHCCiMatch() {

        CC015CType cc015cTypeMessage = createEmptyIE015();

        cc015cTypeMessage.getHolderOfTheTransitProcedure().setIdentificationNumber(EORI_1);
        cc015cTypeMessage.getHolderOfTheTransitProcedure().setName(MOCKED_EXISTING_DATA_IE015);
        cc015cTypeMessage.getHolderOfTheTransitProcedure().setAddress(new AddressType17());
        cc015cTypeMessage.getHolderOfTheTransitProcedure().getAddress().setCity(MOCKED_EXISTING_DATA_IE015);

        cc015cTypeMessage.getConsignment().getConsignor().setIdentificationNumber(EORI_2);
        cc015cTypeMessage.getConsignment().getConsignor().setAddress(new AddressType17());
        cc015cTypeMessage.getConsignment().getConsignor().getAddress().setStreetAndNumber(MOCKED_EXISTING_DATA_IE015);

        cc015cTypeMessage.getConsignment().getConsignee().setIdentificationNumber(EORI_3);
        cc015cTypeMessage.getConsignment().getConsignee().setAddress(new AddressType17());
        cc015cTypeMessage.getConsignment().getConsignee().getAddress().setCountry(MOCKED_EXISTING_DATA_IE015);
        cc015cTypeMessage.getConsignment().getConsignee().getAddress().setPostcode(MOCKED_EXISTING_DATA_IE015);

        cc015cTypeMessage.getConsignment().getHouseConsignment().get(0).getConsignor().setIdentificationNumber(EORI_1);
        cc015cTypeMessage.getConsignment().getHouseConsignment().get(0).getConsignor().setName(MOCKED_EXISTING_DATA_IE015);

        cc015cTypeMessage.getConsignment().getHouseConsignment().get(0).getConsignee().setIdentificationNumber(EORI_2);
        cc015cTypeMessage.getConsignment().getHouseConsignment().get(0).getConsignee().setAddress(new AddressType17());
        cc015cTypeMessage.getConsignment().getHouseConsignment().get(0).getConsignee().getAddress().setCity(MOCKED_EXISTING_DATA_IE015);

        cc015cTypeMessage.getConsignment().getHouseConsignment().get(0).getConsignmentItem().get(0).getConsignee().setIdentificationNumber(EORI_1);
        cc015cTypeMessage.getConsignment().getHouseConsignment().get(0).getConsignmentItem().get(0).getConsignee().setAddress(new AddressType12());
        cc015cTypeMessage.getConsignment().getHouseConsignment().get(0).getConsignmentItem().get(0).getConsignee().setName(MOCKED_EXISTING_DATA_IE015);
        cc015cTypeMessage.getConsignment().getHouseConsignment().get(0).getConsignmentItem().get(0).getConsignee().getAddress().setStreetAndNumber(MOCKED_EXISTING_DATA_IE015);
        cc015cTypeMessage.getConsignment().getHouseConsignment().get(0).getConsignmentItem().get(0).getConsignee().getAddress().setCity(MOCKED_EXISTING_DATA_IE015);

        cc015cTypeMessage.getConsignment().getHouseConsignment().get(0).getConsignmentItem().get(1).getConsignee().setIdentificationNumber(EORI_2);
        cc015cTypeMessage.getConsignment().getHouseConsignment().get(0).getConsignmentItem().get(1).getConsignee().setAddress(new AddressType12());
        cc015cTypeMessage.getConsignment().getHouseConsignment().get(0).getConsignmentItem().get(1).getConsignee().setName(MOCKED_EXISTING_DATA_IE015);
        cc015cTypeMessage.getConsignment().getHouseConsignment().get(0).getConsignmentItem().get(1).getConsignee().getAddress().setStreetAndNumber(MOCKED_EXISTING_DATA_IE015);
        cc015cTypeMessage.getConsignment().getHouseConsignment().get(0).getConsignmentItem().get(1).getConsignee().getAddress().setCity(MOCKED_EXISTING_DATA_IE015);

        return cc015cTypeMessage;
    }
}
