com.kcs.service.impl.GenerateXmlServiceImpl.java Source code

Java tutorial

Introduction

Here is the source code for com.kcs.service.impl.GenerateXmlServiceImpl.java

Source

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.kcs.service.impl;

import com.kcs.core.utilities.CollectionUtil;
import com.kcs.core.utilities.StringUtil;
import com.kcs.core.utilities.Utility;
import com.kcs.dao.DatasetFcpDao;
import com.kcs.dao.DatasetFlaDao;
import com.kcs.dao.DatasetFrfDao;
import com.kcs.dao.DatasetFrwDao;
import com.kcs.dao.DatasetFtxDao;
import com.kcs.dao.DatasetFxpBalDao;
import com.kcs.dao.DatasetIrfDao;
import com.kcs.dao.DatasetOffDao;
import com.kcs.dao.DatasetPtxDao;
import com.kcs.dao.DfFxuDao;
import com.kcs.dao.DfFxmDao;
import com.kcs.dao.DfOlbDao;
import com.kcs.dao.DfSlbDao;
import com.kcs.dao.FtsDao;
import com.kcs.dao.FtuDao;
import com.kcs.dao.HeadGenXMLControlDao;
import com.kcs.dao.LtxDao;
import com.kcs.dao.DfFcrDao;
import com.kcs.dao.DfIiaDao;
import com.kcs.dao.DfBirDao;
import com.kcs.genxml.beans.fcp.*;
import com.kcs.genxml.beans.fts.*;
import com.kcs.genxml.beans.ltx.*;
import com.kcs.genxml.beans.fla.*;
import com.kcs.genxml.beans.ftx.*;
import com.kcs.genxml.beans.ftu.*;
import com.kcs.genxml.beans.frf.*;
import com.kcs.genxml.beans.frw.*;
import com.kcs.genxml.beans.irf.*;
import com.kcs.genxml.beans.off.*;
import com.kcs.genxml.beans.fxp.*;
import com.kcs.genxml.beans.fxu.*;
import com.kcs.genxml.beans.fxm.*;
import com.kcs.genxml.beans.olb.*;
import com.kcs.genxml.beans.slb.*;
import com.kcs.genxml.beans.fcr.*;
import com.kcs.genxml.beans.iia.*;
import com.kcs.genxml.beans.bir.*;
import com.kcs.genxml.beans.ptx.*;
import com.kcs.model.DatasetFxpBal;
import com.kcs.model.Datasetfcp;
import com.kcs.model.Datasetfla;
import com.kcs.model.Datasetfrf;
import com.kcs.model.Datasetfrw;
import com.kcs.model.Datasetfts;
import com.kcs.model.Datasetftu;
import com.kcs.model.Datasetftx;
import com.kcs.model.Datasetirf;
import com.kcs.model.Datasetltx;
import com.kcs.model.Datasetoff;
import com.kcs.model.Datasetptx;
import com.kcs.model.DfFcr;
import com.kcs.model.DfFxu;
import com.kcs.model.DfFxm;
import com.kcs.model.DfIia;
import com.kcs.model.DfOlb;
import com.kcs.model.DfSlb;
import com.kcs.model.DfBir;
import com.kcs.model.HeadGenXMLControl;
import com.kcs.service.GenerateXmlService;
import java.io.ByteArrayOutputStream;
import java.lang.reflect.Method;
import java.math.BigDecimal;
import java.text.NumberFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import javax.xml.datatype.DatatypeConfigurationException;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.Predicate;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 *
 * @author Sarawut
 */
@Service("generateXmlService")
public class GenerateXmlServiceImpl extends Utility implements GenerateXmlService {

    private final Logger logger = Logger.getLogger(GenerateXmlServiceImpl.class);

    private static final String defaultPattern = "dd/MM/yyyy";

    // <editor-fold defaultstate="collapsed" desc="ObjectFactory">
    private final com.kcs.genxml.beans.fts.ObjectFactory ftsOf = new com.kcs.genxml.beans.fts.ObjectFactory();
    private final com.kcs.genxml.beans.fcp.ObjectFactory fcpOf = new com.kcs.genxml.beans.fcp.ObjectFactory();
    private final com.kcs.genxml.beans.ltx.ObjectFactory ltxOf = new com.kcs.genxml.beans.ltx.ObjectFactory();
    private final com.kcs.genxml.beans.fla.ObjectFactory flaOf = new com.kcs.genxml.beans.fla.ObjectFactory();
    private final com.kcs.genxml.beans.ftx.ObjectFactory ftxOf = new com.kcs.genxml.beans.ftx.ObjectFactory();
    private final com.kcs.genxml.beans.ftu.ObjectFactory ftuOf = new com.kcs.genxml.beans.ftu.ObjectFactory();
    private final com.kcs.genxml.beans.frf.ObjectFactory frfOf = new com.kcs.genxml.beans.frf.ObjectFactory();
    private final com.kcs.genxml.beans.frw.ObjectFactory frwOf = new com.kcs.genxml.beans.frw.ObjectFactory();
    private final com.kcs.genxml.beans.irf.ObjectFactory irfOf = new com.kcs.genxml.beans.irf.ObjectFactory();
    private final com.kcs.genxml.beans.off.ObjectFactory offOf = new com.kcs.genxml.beans.off.ObjectFactory();
    private final com.kcs.genxml.beans.fxp.ObjectFactory fxpOf = new com.kcs.genxml.beans.fxp.ObjectFactory();
    private final com.kcs.genxml.beans.fxu.ObjectFactory fxuOf = new com.kcs.genxml.beans.fxu.ObjectFactory();
    private final com.kcs.genxml.beans.fxm.ObjectFactory fxmOf = new com.kcs.genxml.beans.fxm.ObjectFactory();
    private final com.kcs.genxml.beans.olb.ObjectFactory olbOf = new com.kcs.genxml.beans.olb.ObjectFactory();
    private final com.kcs.genxml.beans.slb.ObjectFactory slbOf = new com.kcs.genxml.beans.slb.ObjectFactory();
    private final com.kcs.genxml.beans.fcr.ObjectFactory fcrOf = new com.kcs.genxml.beans.fcr.ObjectFactory();
    private final com.kcs.genxml.beans.iia.ObjectFactory iiaOf = new com.kcs.genxml.beans.iia.ObjectFactory();
    private final com.kcs.genxml.beans.bir.ObjectFactory birOf = new com.kcs.genxml.beans.bir.ObjectFactory();
    // </editor-fold>

    // <editor-fold defaultstate="collapsed" desc="dao">
    @Autowired
    private HeadGenXMLControlDao headDao;
    @Autowired
    private FtsDao ftsDao;
    @Autowired
    private DatasetFcpDao fcpDao;
    @Autowired
    private LtxDao ltxDao;
    @Autowired
    private DatasetFlaDao flaDao;
    @Autowired
    private DatasetFtxDao ftxDao;
    @Autowired
    private FtuDao ftuDao;
    @Autowired
    private DatasetFrfDao frfDao;
    @Autowired
    private DatasetFrwDao frwDao;
    @Autowired
    private DatasetIrfDao irfDao;
    @Autowired
    private DatasetOffDao offDao;
    @Autowired
    private DatasetFxpBalDao fxpDao;
    @Autowired
    private DfFxuDao fxuDao;
    @Autowired
    private DfFxmDao fxmDao;
    @Autowired
    private DfOlbDao olbDao;
    @Autowired
    private DfSlbDao slbDao;
    @Autowired
    private DfFcrDao fcrDao;
    @Autowired
    private DfIiaDao iiaDao;
    @Autowired
    private DfBirDao birDao;

    // </editor-fold>

    // <editor-fold defaultstate="collapsed" desc="fts">
    @Override
    public byte[] generateXmlFts(String dataSetDate, String tmpTcb) throws Exception {
        try {
            final String[] transItems = { "129002", "129004", "129006", "129007", "129008", "129009", "129010",
                    "129011", "129013", "129014", "129015", "129016", "129017", "129018", "129020", "129021",
                    "129022", "129023", "129024", "129025", "129027", "129030", "129031", "129034", "129035",
                    "129037", "129038", "129040", "129041", "129043", "129044", "129046", "129047", "129050",
                    "129051", "129053", "129054", "129056", "129057", "129059", "129060", "129061", "129062" };

            List<Datasetfts> mainList = ftsDao.findListMainFts(dataSetDate, tmpTcb);

            ByteArrayOutputStream output = new ByteArrayOutputStream();

            DSFTS dsfts = ftsOf.createDSFTS();
            com.kcs.genxml.beans.fts.DataSetCommonHeader commonHeader = ftsOf.createDataSetCommonHeader();
            commonHeader.setOrganizationId(mainList.get(0).getOrgId());
            commonHeader.setDataSetDate(getXMLGregorianCalendarDate(mainList.get(0).getDataSetDate()));

            DSFTS.DSFTSHeader dsftsHeader = ftsOf.createDSFTSDSFTSHeader();
            dsftsHeader.setDataSubmissionPeriod(mainList.get(0).getDataSubPrd());

            DSFTS.DSFTSContent content = ftsOf.createDSFTSDSFTSContent();

            for (Datasetfts main : mainList) {
                List<Datasetfts> childList = ftsDao.findListChildFts(main.getDataSetDate());
                logger.debug("all child size : " + childList.size());

                List<Datasetfts> subChildList = getChildFromMainFts(main, childList);
                logger.debug("sub child size : " + subChildList.size());

                DSFTS.DSFTSContent.ContentRecordGroup contentRecordGroup = ftsOf
                        .createDSFTSDSFTSContentContentRecordGroup();
                contentRecordGroup.setFiReportingGroupId(main.getFiRptGrp());

                //                DSFTS.DSFTSContent.ContentRecordGroup.ForeignCurrencyTransactionItem129002 currencyTransactionItem129002 
                //                        = of.createDSFTSDSFTSContentContentRecordGroupForeignCurrencyTransactionItem129002();
                //                List<Datasetfts> transItemSubChildList = getChildFromsTransItem("129002", subChildList);
                //                for(Datasetfts datasetfts : transItemSubChildList){
                //                    DSFTS.DSFTSContent.ContentRecordGroup.ForeignCurrencyTransactionItem129002.ForeignCurrencyTransactionInfo info =
                //                            of.createDSFTSDSFTSContentContentRecordGroupForeignCurrencyTransactionItem129002ForeignCurrencyTransactionInfo();
                //                    info.setCurrencyId(MV0072.fromValue(datasetfts.getCurr()));
                //                    info.setBuyAmount(datasetfts.getBuyAmt().toString());
                //                    info.setSellAmount(datasetfts.getSellAmt().toString());
                //                    currencyTransactionItem129002.getForeignCurrencyTransactionInfo().add(info);
                //                }
                //                contentRecordGroup.setForeignCurrencyTransactionItem129002(currencyTransactionItem129002);
                for (String transItem : transItems) {
                    String createCurrencyTransactionItemMethodName = "createDSFTSDSFTSContentContentRecordGroupForeignCurrencyTransactionItem"
                            + transItem;
                    String createCurrencyTransactionItemInfoMethodName = "createDSFTSDSFTSContentContentRecordGroupForeignCurrencyTransactionItem"
                            + transItem + "ForeignCurrencyTransactionInfo";
                    String setForeignCurrencyTransactionItem = "setForeignCurrencyTransactionItem" + transItem;

                    Method createCurrencyTransactionItemMethod = com.kcs.genxml.beans.fts.ObjectFactory.class
                            .getMethod(createCurrencyTransactionItemMethodName);
                    Object createCurrencyTransactionItemObj = createCurrencyTransactionItemMethod.invoke(ftsOf);
                    List<Datasetfts> transItemSubChild = getChildFromsTransItem(transItem, subChildList);
                    logger.debug(transItem + " child size : " + transItemSubChild.size());
                    for (Datasetfts datasetfts : transItemSubChild) {
                        Method createCurrencyTransactionItemInfoMethod = com.kcs.genxml.beans.fts.ObjectFactory.class
                                .getMethod(createCurrencyTransactionItemInfoMethodName);
                        Object currencyTransactionItemInfoObj = createCurrencyTransactionItemInfoMethod
                                .invoke(ftsOf);
                        Method setCurrencyId = currencyTransactionItemInfoObj.getClass().getMethod("setCurrencyId",
                                com.kcs.genxml.beans.fts.MV0072.class);
                        Method setBuyAmount = currencyTransactionItemInfoObj.getClass().getMethod("setBuyAmount",
                                String.class);
                        Method setSellAmount = currencyTransactionItemInfoObj.getClass().getMethod("setSellAmount",
                                String.class);

                        setCurrencyId.invoke(currencyTransactionItemInfoObj,
                                com.kcs.genxml.beans.fts.MV0072.fromValue(datasetfts.getCurr()));
                        setBuyAmount.invoke(currencyTransactionItemInfoObj, datasetfts.getBuyAmt().toString());
                        setSellAmount.invoke(currencyTransactionItemInfoObj, datasetfts.getSellAmt().toString());

                        Method getForeignCurrencyTransactionInfo = createCurrencyTransactionItemObj.getClass()
                                .getMethod("getForeignCurrencyTransactionInfo");
                        //                        Class<?> clazz = createCurrencyTransactionItemInfoMethodObj.getClass();
                        ((List) getForeignCurrencyTransactionInfo.invoke(createCurrencyTransactionItemObj))
                                .add(currencyTransactionItemInfoObj);
                    }

                    Method setForeignCurrencyTransactionItemMethod = contentRecordGroup.getClass().getMethod(
                            setForeignCurrencyTransactionItem, createCurrencyTransactionItemObj.getClass());
                    setForeignCurrencyTransactionItemMethod.invoke(contentRecordGroup,
                            createCurrencyTransactionItemObj);
                }
                content.getContentRecordGroup().add(contentRecordGroup);
            }

            HeadGenXMLControl head = headDao.getHeadGenXMLControlByDatasetCode("DS_FTS");
            if (head != null) {
                dsfts.setName(head.getAttributesName());
                dsfts.setType(head.getAttributesType());
                dsfts.setSchemaVersion(head.getAttributesSchemaVersion());
            }
            dsfts.setCommonHeader(commonHeader);
            dsfts.setDSFTSHeader(dsftsHeader);
            dsfts.setDSFTSContent(content);

            return generateToBytes(dsfts);
        } catch (Exception ex) {
            logger.error("error generateXmlFts : " + ex.getMessage(), ex);
            throw ex;
        }
    }

    private List<Datasetfts> getChildFromMainFts(Datasetfts main, List<Datasetfts> childList) {
        List<Datasetfts> subList = new ArrayList<Datasetfts>();

        if (CollectionUtil.isEmpty(childList)) {
            return Collections.EMPTY_LIST;
        }

        for (Datasetfts o : childList) {
            if (o.getFiRptGrp().equals(main.getFiRptGrp()) && o.getDataSubPrd().equals(main.getDataSubPrd())) {
                subList.add(o);
            }
        }

        return subList;
    }

    private List<Datasetfts> getChildFromsTransItem(String tranItem, List<Datasetfts> childList) {
        List<Datasetfts> subList = new ArrayList<Datasetfts>();

        if (CollectionUtil.isEmpty(childList)) {
            return Collections.EMPTY_LIST;
        }

        for (Datasetfts o : childList) {
            if (tranItem.equals(o.getTranItem())) {
                subList.add(o);
            }
        }

        return subList;
    }
    // </editor-fold>

    // <editor-fold defaultstate="collapsed" desc="fcp">
    @Override
    public byte[] generateXmlFcp(String dataSetDate, String tmpTcb) throws Exception {
        try {
            final String[] postItems = { "119002", "119004", "119005", "119006", "119007", "119009", "119010",
                    "119012", "119013", "119014", "119015", "119016", "119017", "119020", "119021", "119022",
                    "119024", "119025", "119026", "119027", "119028", "119029", "119030", "119031"

            };

            List<Datasetfcp> mainList = fcpDao.findMainDatasetFcpList(dataSetDate, tmpTcb);

            DSFCP dsfcp = fcpOf.createDSFCP();
            com.kcs.genxml.beans.fcp.DataSetCommonHeader commonHeader = fcpOf.createDataSetCommonHeader();
            commonHeader.setOrganizationId(mainList.get(0).getOrgId());
            commonHeader.setDataSetDate(getXMLGregorianCalendarDate(mainList.get(0).getDataSetDate()));

            DSFCP.DSFCPHeader dsftsHeader = fcpOf.createDSFCPDSFCPHeader();
            dsftsHeader.setDataSubmissionPeriod(mainList.get(0).getDataSubPrd());

            DSFCP.DSFCPContent content = fcpOf.createDSFCPDSFCPContent();

            for (Datasetfcp main : mainList) {
                List<Datasetfcp> childList = fcpDao.findChildDatasetFcpList(main.getDataSetDate());
                logger.debug("all child size : " + childList.size());

                List<Datasetfcp> subChildList = getChildFromMainFcp(main, childList);
                logger.debug("sub child size : " + subChildList.size());

                DSFCP.DSFCPContent.ContentRecordGroup contentRecordGroup = fcpOf
                        .createDSFCPDSFCPContentContentRecordGroup();
                contentRecordGroup.setFiReportingGroupId(main.getFiRptGrp());

                for (String postItem : postItems) {
                    String createForeignCurrencyPositionItemMethodName = "createDSFCPDSFCPContentContentRecordGroupForeignCurrencyPositionItem"
                            + postItem;
                    String createForeignCurrencyPositionItemInfoMethodName = "createDSFCPDSFCPContentContentRecordGroupForeignCurrencyPositionItem"
                            + postItem + "ForeignCurrencyPositionItemInfo";
                    String setForeignCurrencyPositionItemMethodName = "setForeignCurrencyPositionItem" + postItem;
                    Method createForeignCurrencyPositionItemMethod = com.kcs.genxml.beans.fcp.ObjectFactory.class
                            .getMethod(createForeignCurrencyPositionItemMethodName);
                    Object createForeignCurrencyPositionItemObj = createForeignCurrencyPositionItemMethod
                            .invoke(fcpOf);

                    List<Datasetfcp> postItemSubChild = getChildFcpFromPostItem(postItem, subChildList);
                    logger.debug(postItem + " child size : " + postItemSubChild.size());

                    for (Datasetfcp datasetfcp : postItemSubChild) {
                        Method createForeignCurrencyPositionItemInfoMethod = com.kcs.genxml.beans.fcp.ObjectFactory.class
                                .getMethod(createForeignCurrencyPositionItemInfoMethodName);
                        Object foreignCurrencyPositionItemInfoObj = createForeignCurrencyPositionItemInfoMethod
                                .invoke(fcpOf);
                        Method setCurrencyId = foreignCurrencyPositionItemInfoObj.getClass()
                                .getMethod("setCurrencyId", com.kcs.genxml.beans.fcp.MV0072.class);
                        Method setForeignCurrencyAmount = foreignCurrencyPositionItemInfoObj.getClass()
                                .getMethod("setForeignCurrencyAmount", String.class);

                        setCurrencyId.invoke(foreignCurrencyPositionItemInfoObj,
                                com.kcs.genxml.beans.fcp.MV0072.fromValue(datasetfcp.getCurr()));
                        setForeignCurrencyAmount.invoke(foreignCurrencyPositionItemInfoObj,
                                datasetfcp.getAmt().toString());

                        Method getForeignCurrencyTransactionInfo = createForeignCurrencyPositionItemObj.getClass()
                                .getMethod("getForeignCurrencyPositionItemInfo");
                        ((List) getForeignCurrencyTransactionInfo.invoke(createForeignCurrencyPositionItemObj))
                                .add(foreignCurrencyPositionItemInfoObj);
                    }

                    Method setForeignCurrencyPositionItemMethod = contentRecordGroup.getClass().getMethod(
                            setForeignCurrencyPositionItemMethodName,
                            createForeignCurrencyPositionItemObj.getClass());
                    setForeignCurrencyPositionItemMethod.invoke(contentRecordGroup,
                            createForeignCurrencyPositionItemObj);
                }

                content.getContentRecordGroup().add(contentRecordGroup);
            }

            HeadGenXMLControl head = headDao.getHeadGenXMLControlByDatasetCode("DS_FCP");
            if (head != null) {
                dsfcp.setName(head.getAttributesName());
                dsfcp.setType(head.getAttributesType());
                dsfcp.setSchemaVersion(head.getAttributesSchemaVersion());
            }
            dsfcp.setCommonHeader(commonHeader);
            dsfcp.setDSFCPHeader(dsftsHeader);
            dsfcp.setDSFCPContent(content);

            byte[] xmlBytes = generateToBytes(dsfcp);

            return xmlBytes;
        } catch (Exception e) {
            logger.error("generateXmlFcp error " + e.getMessage(), e);
            throw e;
        }
    }

    private List<Datasetfcp> getChildFromMainFcp(Datasetfcp main, List<Datasetfcp> childList) {
        List<Datasetfcp> subList = new ArrayList<Datasetfcp>();

        if (CollectionUtil.isEmpty(childList)) {
            return Collections.EMPTY_LIST;
        }

        for (Datasetfcp o : childList) {
            if (o.getFiRptGrp().equals(main.getFiRptGrp()) && o.getDataSubPrd().equals(main.getDataSubPrd())) {
                subList.add(o);
            }
        }

        return subList;
    }

    private List<Datasetfcp> getChildFcpFromPostItem(String postItem, List<Datasetfcp> childList) {
        List<Datasetfcp> subList = new ArrayList<Datasetfcp>();

        if (CollectionUtil.isEmpty(childList)) {
            return Collections.EMPTY_LIST;
        }

        for (Datasetfcp o : childList) {
            if (postItem.equals(o.getPosItem())) {
                subList.add(o);
            }
        }

        return subList;
    }
    // </editor-fold>

    // <editor-fold defaultstate="collapsed" desc="ltx">
    @Override
    public byte[] generateXmlLtx(String tmpDataSetDate, String tmpTcb) throws Exception {
        try {
            List<Datasetltx> mainList = ltxDao.findMainDatasetLtxList(tmpDataSetDate, tmpTcb);
            if (CollectionUtil.isEmpty(mainList)) {
                logger.error("Can't find main dataset ltx list.");
                return new byte[0];
            }
            Datasetltx o = mainList.get(0);

            List<Datasetltx> childBotRefList = ltxDao.findChildBotRefDatasetLtxList(o.getDataSetDate());
            List<Datasetltx> childRelatedFiGroupList = ltxDao
                    .findChildRelatedFiGroupDatasetLtxList(o.getDataSetDate());

            DSLTX dsLtx = ltxOf.createDSLTX();
            com.kcs.genxml.beans.ltx.DataSetCommonHeader commonHeader = ltxOf.createDataSetCommonHeader();
            DSLTX.DSLTXHeader dsLtxHeader = ltxOf.createDSLTXDSLTXHeader();
            DSLTX.DSLTXContent content = ltxOf.createDSLTXDSLTXContent();

            HeadGenXMLControl head = headDao.getHeadGenXMLControlByDatasetCode("DS_LTX");
            if (head != null) {
                dsLtx.setName(head.getAttributesName());
                dsLtx.setType(head.getAttributesType());
                dsLtx.setSchemaVersion(head.getAttributesSchemaVersion());
            }

            commonHeader.setOrganizationId(o.getOrgId());
            commonHeader.setDataSetDate(getXMLGregorianCalendarDate(o.getDataSetDate()));

            dsLtxHeader.setDataSubmissionPeriod(o.getDataSubPrd());

            for (Datasetltx mainltx : mainList) {
                nullToEmptyString(mainltx);
                DSLTX.DSLTXContent.ContentRecordGroup contentRecordGroup = ltxOf
                        .createDSLTXDSLTXContentContentRecordGroup();

                contentRecordGroup.setDataProviderBranchNumber(mainltx.getDataPvdrBrcNo());
                contentRecordGroup.setFiArrangementNumber(mainltx.getFiArrgNo());
                contentRecordGroup.setLoanDepositTransactionType(mainltx.getTranType());
                contentRecordGroup.setTransactionDate(getXMLGregorianCalendarDate(mainltx.getTranDate()));
                contentRecordGroup.setCurrencyId(com.kcs.genxml.beans.ltx.MV0053.fromValue(mainltx.getCurr()));
                contentRecordGroup.setPaymentMethod(mainltx.getPymtMethd());
                contentRecordGroup.setFromTransactionType(mainltx.getFromTranType());
                contentRecordGroup.setToTransactionType(mainltx.getToTranType());
                contentRecordGroup.setInflowTransactionPurpose(mainltx.getInTranPurp());
                contentRecordGroup.setOutflowTransactionPurpose(mainltx.getOutTranPurp());
                contentRecordGroup.setOtherTransactionPurposeDescription(mainltx.getOthTranPurpDesc());
                contentRecordGroup.setInstallmentNumber(getXmlLongString(mainltx.getInstNo()));
                contentRecordGroup.setRepaymentReason(mainltx.getRepymtReason());
                contentRecordGroup.setOtherRepaymentReasonDescription(mainltx.getOthRepymtDesc());
                contentRecordGroup.setTransactionAmount(getXmlString(mainltx.getTranAmt()));
                contentRecordGroup.setBeneficiaryOrSenderName(mainltx.getBnftSendrName());
                contentRecordGroup.setCountryIdOfBeneficiaryOrSender(mainltx.getCtryBnftSendr());
                contentRecordGroup.setRelationshipWithBeneficiaryOrSender(mainltx.getRelnBnftSendr());
                contentRecordGroup.setResidentInvolvedPartyId(mainltx.getResIp());
                contentRecordGroup.setResidentInvolvedPartyUniqueIdType(mainltx.getResIpType());
                contentRecordGroup.setUnderlyingOwnerName(mainltx.getUnderlyingOwnName());
                contentRecordGroup.setDescription(mainltx.getDescription());

                //ApprovalDocumentGroupInfo
                contentRecordGroup.setApprovalDocumentGroupInfo(createApprovalDocumentGroupInfo(mainltx));

                //TransactionPurposeInfo
                contentRecordGroup.setTransactionPurposeInfo(createTransactionPurposeInfo(mainltx));

                //BotReferenceNumberGroupInfo
                contentRecordGroup.setBotReferenceNumberGroupInfo(
                        createBotReferenceNumberGroupInfo(childBotRefList, mainltx));

                //RelatedFiGroupInfo
                contentRecordGroup
                        .setRelatedFiGroupInfo(createRelatedFiGroupInfo(childRelatedFiGroupList, mainltx));

                content.getContentRecordGroup().add(contentRecordGroup);
            }

            dsLtx.setCommonHeader(commonHeader);
            dsLtx.setDSLTXHeader(dsLtxHeader);
            dsLtx.setDSLTXContent(content);

            return generateToBytes(dsLtx);
        } catch (Exception e) {
            logger.error("generateXmlLtx error " + e.getMessage(), e);
            throw e;
        }
    }

    //ApprovalDocumentGroupInfo
    private DSLTX.DSLTXContent.ContentRecordGroup.ApprovalDocumentGroupInfo createApprovalDocumentGroupInfo(
            Datasetltx datasetltx) throws DatatypeConfigurationException {
        DSLTX.DSLTXContent.ContentRecordGroup.ApprovalDocumentGroupInfo approvalDocumentGroupInfo = ltxOf
                .createDSLTXDSLTXContentContentRecordGroupApprovalDocumentGroupInfo();
        if (StringUtil.isNotEmpty(datasetltx.getAppvDocNo())) {
            DSLTX.DSLTXContent.ContentRecordGroup.ApprovalDocumentGroupInfo.ApprovalDocumentGroupDetails approvalDocumentGroupDetails = ltxOf
                    .createDSLTXDSLTXContentContentRecordGroupApprovalDocumentGroupInfoApprovalDocumentGroupDetails();
            approvalDocumentGroupDetails.setApprovalDocumentNumber(datasetltx.getAppvDocNo());
            approvalDocumentGroupDetails
                    .setApprovalDocumentDate(getXMLGregorianCalendarDate(datasetltx.getAppvDocDate()));
            approvalDocumentGroupInfo.getApprovalDocumentGroupDetails().add(approvalDocumentGroupDetails);
        }
        return approvalDocumentGroupInfo;
    }

    //TransactionPurposeInfo
    private DSLTX.DSLTXContent.ContentRecordGroup.TransactionPurposeInfo createTransactionPurposeInfo(
            Datasetltx datasetltx) throws DatatypeConfigurationException {
        String inTranPurp = datasetltx.getInTranPurp();
        DSLTX.DSLTXContent.ContentRecordGroup.TransactionPurposeInfo transactionPurposeInfo = ltxOf
                .createDSLTXDSLTXContentContentRecordGroupTransactionPurposeInfo();
        if ("318063".equals(inTranPurp)) {
            DSLTX.DSLTXContent.ContentRecordGroup.TransactionPurposeInfo.ForeignDirectInvestmentInflowDetails directInvestmentInflowDetails = ltxOf
                    .createDSLTXDSLTXContentContentRecordGroupTransactionPurposeInfoForeignDirectInvestmentInflowDetails();
            directInvestmentInflowDetails.setListedInMarketFlag(datasetltx.getMktFlag());
            transactionPurposeInfo.setForeignDirectInvestmentInflowDetails(directInvestmentInflowDetails);
        } else if ("318064".equals(inTranPurp)) {
            DSLTX.DSLTXContent.ContentRecordGroup.TransactionPurposeInfo.ForeignDirectInvestmentDepositDetails directInvestmentDepositDetails = ltxOf
                    .createDSLTXDSLTXContentContentRecordGroupTransactionPurposeInfoForeignDirectInvestmentDepositDetails();
            directInvestmentDepositDetails.setListedInMarketFlag(datasetltx.getMktFlag());
            directInvestmentDepositDetails.setInvestmentRepatriatedReason(datasetltx.getInvtReptReason());
            transactionPurposeInfo.setForeignDirectInvestmentDepositDetails(directInvestmentDepositDetails);
        } else if ("318067".equals(inTranPurp)) {
            DSLTX.DSLTXContent.ContentRecordGroup.TransactionPurposeInfo.ThaiDirectInvestmentInflowDetails thaiDirectInvestmentInflowDetails = ltxOf
                    .createDSLTXDSLTXContentContentRecordGroupTransactionPurposeInfoThaiDirectInvestmentInflowDetails();
            thaiDirectInvestmentInflowDetails.setInvestmentRepatriatedReason(datasetltx.getInvtReptReason());
            transactionPurposeInfo.setThaiDirectInvestmentInflowDetails(thaiDirectInvestmentInflowDetails);
        } else if ("318077".equals(inTranPurp)) {
            DSLTX.DSLTXContent.ContentRecordGroup.TransactionPurposeInfo.ForeignPortfolioInvestmentInflowDetails foreignPortfolioInvestmentInflowDetails = ltxOf
                    .createDSLTXDSLTXContentContentRecordGroupTransactionPurposeInfoForeignPortfolioInvestmentInflowDetails();
            foreignPortfolioInvestmentInflowDetails.setListedInMarketFlag(datasetltx.getMktFlag());
            foreignPortfolioInvestmentInflowDetails.setCustomerInvestmentType(datasetltx.getCustInvtType());
            foreignPortfolioInvestmentInflowDetails.setTermRange(datasetltx.getTermRange());
            transactionPurposeInfo
                    .setForeignPortfolioInvestmentInflowDetails(foreignPortfolioInvestmentInflowDetails);
        } else if ("318078".equals(inTranPurp)) {
            DSLTX.DSLTXContent.ContentRecordGroup.TransactionPurposeInfo.ForeignPortfolioInvestmentDepositDetails foreignPortfolioInvestmentDepositDetails = ltxOf
                    .createDSLTXDSLTXContentContentRecordGroupTransactionPurposeInfoForeignPortfolioInvestmentDepositDetails();
            foreignPortfolioInvestmentDepositDetails.setListedInMarketFlag(datasetltx.getMktFlag());
            foreignPortfolioInvestmentDepositDetails.setCustomerInvestmentType(datasetltx.getCustInvtType());
            foreignPortfolioInvestmentDepositDetails.setTermRange(datasetltx.getTermRange());
            transactionPurposeInfo
                    .setForeignPortfolioInvestmentDepositDetails(foreignPortfolioInvestmentDepositDetails);
        } else if ("318202".equals(inTranPurp)) {
            DSLTX.DSLTXContent.ContentRecordGroup.TransactionPurposeInfo.ThaiPortfolioInvestmentByForeignInflowDetails thaiPortfolioInvestmentByForeignInflowDetails = ltxOf
                    .createDSLTXDSLTXContentContentRecordGroupTransactionPurposeInfoThaiPortfolioInvestmentByForeignInflowDetails();
            thaiPortfolioInvestmentByForeignInflowDetails.setCustomerInvestmentType(datasetltx.getCustInvtType());
            thaiPortfolioInvestmentByForeignInflowDetails.setTermRange(datasetltx.getTermRange());
            transactionPurposeInfo.setThaiPortfolioInvestmentByForeignInflowDetails(
                    thaiPortfolioInvestmentByForeignInflowDetails);
        } else if ("318203".equals(inTranPurp)) {
            DSLTX.DSLTXContent.ContentRecordGroup.TransactionPurposeInfo.ThaiPortfolioInvestmentByThaiInflowDetails thaiPortfolioInvestmentByThaiInflowDetails = ltxOf
                    .createDSLTXDSLTXContentContentRecordGroupTransactionPurposeInfoThaiPortfolioInvestmentByThaiInflowDetails();
            thaiPortfolioInvestmentByThaiInflowDetails.setCustomerInvestmentType(datasetltx.getCustInvtType());
            thaiPortfolioInvestmentByThaiInflowDetails.setTermRange(datasetltx.getTermRange());
            transactionPurposeInfo
                    .setThaiPortfolioInvestmentByThaiInflowDetails(thaiPortfolioInvestmentByThaiInflowDetails);
        } else if ("318200".equals(inTranPurp)) {
            DSLTX.DSLTXContent.ContentRecordGroup.TransactionPurposeInfo.ThaiPortfolioInvestmentByForeignDepositDetails thaiPortfolioInvestmentByForeignDepositDetails = ltxOf
                    .createDSLTXDSLTXContentContentRecordGroupTransactionPurposeInfoThaiPortfolioInvestmentByForeignDepositDetails();
            thaiPortfolioInvestmentByForeignDepositDetails.setCustomerInvestmentType(datasetltx.getCustInvtType());
            thaiPortfolioInvestmentByForeignDepositDetails.setTermRange(datasetltx.getTermRange());
            transactionPurposeInfo.setThaiPortfolioInvestmentByForeignDepositDetails(
                    thaiPortfolioInvestmentByForeignDepositDetails);
        } else if ("318201".equals(inTranPurp)) {
            DSLTX.DSLTXContent.ContentRecordGroup.TransactionPurposeInfo.ThaiPortfolioInvestmentByThaiDepositDetails thaiPortfolioInvestmentByThaiDepositDetails = ltxOf
                    .createDSLTXDSLTXContentContentRecordGroupTransactionPurposeInfoThaiPortfolioInvestmentByThaiDepositDetails();
            thaiPortfolioInvestmentByThaiDepositDetails.setCustomerInvestmentType(datasetltx.getCustInvtType());
            thaiPortfolioInvestmentByThaiDepositDetails.setTermRange(datasetltx.getTermRange());
            transactionPurposeInfo
                    .setThaiPortfolioInvestmentByThaiDepositDetails(thaiPortfolioInvestmentByThaiDepositDetails);
        } else if ("318084".equals(inTranPurp)) {
            DSLTX.DSLTXContent.ContentRecordGroup.TransactionPurposeInfo.ForeignLoanInflowDetails foreignLoanInflowDetails = ltxOf
                    .createDSLTXDSLTXContentContentRecordGroupTransactionPurposeInfoForeignLoanInflowDetails();
            foreignLoanInflowDetails.setTermRange(datasetltx.getTermRange());
            foreignLoanInflowDetails.setTerm(getXmlString(datasetltx.getTerm()));
            foreignLoanInflowDetails.setTermUnit(datasetltx.getTermUnit());
            foreignLoanInflowDetails.setInterestRateType(datasetltx.getIntRateType());
            foreignLoanInflowDetails.setInterestRate(getXmlString(datasetltx.getIntRate()));
            foreignLoanInflowDetails.setInterestRateMargin(getXmlString(datasetltx.getIntRateMrgn()));
            foreignLoanInflowDetails.setNumberOfInstallments(getXmlString(datasetltx.getNoOfInstl()));
            foreignLoanInflowDetails.setInstallmentTerm(getXmlString(datasetltx.getInstlTerm()));
            foreignLoanInflowDetails.setInstallmentTermUnit(datasetltx.getInstlTermUnit());
            foreignLoanInflowDetails
                    .setFirstInstallmentDate(getXmlDateFormatString(datasetltx.getFirstInstlDate()));
            foreignLoanInflowDetails.setMaturityDate(getXmlDateFormatString(datasetltx.getMatDate()));
            transactionPurposeInfo.setForeignLoanInflowDetails(foreignLoanInflowDetails);
        } else if ("318085".equals(inTranPurp)) {
            DSLTX.DSLTXContent.ContentRecordGroup.TransactionPurposeInfo.ForeignLoanDepositDetails foreignLoanDepositDetails = ltxOf
                    .createDSLTXDSLTXContentContentRecordGroupTransactionPurposeInfoForeignLoanDepositDetails();
            foreignLoanDepositDetails.setTermRange(datasetltx.getTermRange());
            foreignLoanDepositDetails.setLoanDeclarationType(datasetltx.getLoanDclrType());
            transactionPurposeInfo.setForeignLoanDepositDetails(foreignLoanDepositDetails);
        } else if ("318092".equals(inTranPurp)) {
            DSLTX.DSLTXContent.ContentRecordGroup.TransactionPurposeInfo.ThaiLoanInflowDetails thaiLoanInflowDetails = ltxOf
                    .createDSLTXDSLTXContentContentRecordGroupTransactionPurposeInfoThaiLoanInflowDetails();
            thaiLoanInflowDetails.setTermRange(datasetltx.getTermRange());
            transactionPurposeInfo.setThaiLoanInflowDetails(thaiLoanInflowDetails);
        } else if ("318091".equals(inTranPurp)) {
            DSLTX.DSLTXContent.ContentRecordGroup.TransactionPurposeInfo.ThaiLoanDepositDetails thaiLoanDepositDetails = ltxOf
                    .createDSLTXDSLTXContentContentRecordGroupTransactionPurposeInfoThaiLoanDepositDetails();
            thaiLoanDepositDetails.setTermRange(datasetltx.getTermRange());
            thaiLoanDepositDetails.setYtdAccumulatedAmount(getXmlString(datasetltx.getYtdAccumAmt()));
            transactionPurposeInfo.setThaiLoanDepositDetails(thaiLoanDepositDetails);
        } else if ("318087".equals(inTranPurp)) {
            DSLTX.DSLTXContent.ContentRecordGroup.TransactionPurposeInfo.ForeignDebtInstrumentInflowDetails foreignDebtInstrumentInflowDetails = ltxOf
                    .createDSLTXDSLTXContentContentRecordGroupTransactionPurposeInfoForeignDebtInstrumentInflowDetails();
            foreignDebtInstrumentInflowDetails.setCustomerInvestmentType(datasetltx.getCustInvtType());
            foreignDebtInstrumentInflowDetails.setTermRange(datasetltx.getTermRange());
            foreignDebtInstrumentInflowDetails.setTerm(getXmlString(datasetltx.getTerm()));
            foreignDebtInstrumentInflowDetails.setTermUnit(datasetltx.getTermUnit());
            foreignDebtInstrumentInflowDetails.setInterestRateType(datasetltx.getIntRateType());
            foreignDebtInstrumentInflowDetails.setInterestRate(getXmlString(datasetltx.getIntRate()));
            foreignDebtInstrumentInflowDetails.setInterestRateMargin(getXmlString(datasetltx.getIntRateMrgn()));
            foreignDebtInstrumentInflowDetails.setMaturityDate(getXmlDateFormatString(datasetltx.getMatDate()));
            transactionPurposeInfo.setForeignDebtInstrumentInflowDetails(foreignDebtInstrumentInflowDetails);
        } else if ("318088".equals(inTranPurp)) {
            DSLTX.DSLTXContent.ContentRecordGroup.TransactionPurposeInfo.ForeignDebtInstrumentDepositDetails foreignDebtInstrumentDepositDetails = ltxOf
                    .createDSLTXDSLTXContentContentRecordGroupTransactionPurposeInfoForeignDebtInstrumentDepositDetails();
            foreignDebtInstrumentDepositDetails.setCustomerInvestmentType(datasetltx.getCustInvtType());
            foreignDebtInstrumentDepositDetails.setTermRange(datasetltx.getTermRange());
            foreignDebtInstrumentDepositDetails.setLoanDeclarationType(datasetltx.getLoanDclrType());
            transactionPurposeInfo.setForeignDebtInstrumentDepositDetails(foreignDebtInstrumentDepositDetails);
        } else if ("318095".equals(inTranPurp)) {
            DSLTX.DSLTXContent.ContentRecordGroup.TransactionPurposeInfo.ThaiDebtInstrumentInflowDetails thaiDebtInstrumentInflowDetails = ltxOf
                    .createDSLTXDSLTXContentContentRecordGroupTransactionPurposeInfoThaiDebtInstrumentInflowDetails();
            thaiDebtInstrumentInflowDetails.setCustomerInvestmentType(datasetltx.getCustInvtType());
            thaiDebtInstrumentInflowDetails.setTermRange(datasetltx.getTermRange());
            thaiDebtInstrumentInflowDetails.setWholePartialRepaymentFlag(datasetltx.getRepymtFlag());
            thaiDebtInstrumentInflowDetails
                    .setDebtInstrumentIssuedDate(getXMLGregorianCalendarDate(datasetltx.getDeptInsmIssuDate()));
            thaiDebtInstrumentInflowDetails
                    .setDebtInstrumentIssuedAmount(getXmlString(datasetltx.getDeptInsmIssuAmt()));
            transactionPurposeInfo.setThaiDebtInstrumentInflowDetails(thaiDebtInstrumentInflowDetails);
        } else if ("318094".equals(inTranPurp)) {
            DSLTX.DSLTXContent.ContentRecordGroup.TransactionPurposeInfo.ThaiDebtInstrumentDepositDetails thaiDebtInstrumentDepositDetails = ltxOf
                    .createDSLTXDSLTXContentContentRecordGroupTransactionPurposeInfoThaiDebtInstrumentDepositDetails();
            thaiDebtInstrumentDepositDetails.setCustomerInvestmentType(datasetltx.getCustInvtType());
            thaiDebtInstrumentDepositDetails.setTermRange(datasetltx.getTermRange());
            thaiDebtInstrumentDepositDetails.setYtdAccumulatedAmount(getXmlString(datasetltx.getYtdAccumAmt()));
            transactionPurposeInfo.setThaiDebtInstrumentDepositDetails(thaiDebtInstrumentDepositDetails);
        } else if ("318066".equals(inTranPurp)) {
            DSLTX.DSLTXContent.ContentRecordGroup.TransactionPurposeInfo.ThaiDirectInvestmentDepositDetails thaiDirectInvestmentDepositDetails = ltxOf
                    .createDSLTXDSLTXContentContentRecordGroupTransactionPurposeInfoThaiDirectInvestmentDepositDetails();
            thaiDirectInvestmentDepositDetails.setYtdAccumulatedAmount(getXmlString(datasetltx.getYtdAccumAmt()));
            transactionPurposeInfo.setThaiDirectInvestmentDepositDetails(thaiDirectInvestmentDepositDetails);
        } else if ("318172".equals(inTranPurp)) {
            DSLTX.DSLTXContent.ContentRecordGroup.TransactionPurposeInfo.ThaiPortfolioInvestmentDomesticMarketDepositDetails thaiPortfolioInvestmentDomesticMarketDepositDetails = ltxOf
                    .createDSLTXDSLTXContentContentRecordGroupTransactionPurposeInfoThaiPortfolioInvestmentDomesticMarketDepositDetails();
            thaiPortfolioInvestmentDomesticMarketDepositDetails
                    .setCustomerInvestmentType(datasetltx.getCustInvtType());
            thaiPortfolioInvestmentDomesticMarketDepositDetails.setTermRange(datasetltx.getTermRange());
            transactionPurposeInfo.setThaiPortfolioInvestmentDomesticMarketDepositDetails(
                    thaiPortfolioInvestmentDomesticMarketDepositDetails);
        }

        String outTranPurp = datasetltx.getOutTranPurp();
        if ("318063".equals(outTranPurp)) {
            DSLTX.DSLTXContent.ContentRecordGroup.TransactionPurposeInfo.ForeignDirectInvestmentWithdrawDetails directInvestmentWithdrawDetails = ltxOf
                    .createDSLTXDSLTXContentContentRecordGroupTransactionPurposeInfoForeignDirectInvestmentWithdrawDetails();
            directInvestmentWithdrawDetails.setListedInMarketFlag(datasetltx.getMktFlag());
            transactionPurposeInfo.setForeignDirectInvestmentWithdrawDetails(directInvestmentWithdrawDetails);
        } else if ("318064".equals(outTranPurp)) {
            DSLTX.DSLTXContent.ContentRecordGroup.TransactionPurposeInfo.ForeignDirectInvestmentOutflowDetails directInvestmentOutflowDetails = ltxOf
                    .createDSLTXDSLTXContentContentRecordGroupTransactionPurposeInfoForeignDirectInvestmentOutflowDetails();
            directInvestmentOutflowDetails.setListedInMarketFlag(datasetltx.getMktFlag());
            directInvestmentOutflowDetails.setInvestmentRepatriatedReason(datasetltx.getInvtReptReason());
            transactionPurposeInfo.setForeignDirectInvestmentOutflowDetails(directInvestmentOutflowDetails);
        } else if ("318067".equals(outTranPurp)) {
            DSLTX.DSLTXContent.ContentRecordGroup.TransactionPurposeInfo.ThaiDirectInvestmentWithdrawDetails thaiDirectInvestmentWithdrawDetails = ltxOf
                    .createDSLTXDSLTXContentContentRecordGroupTransactionPurposeInfoThaiDirectInvestmentWithdrawDetails();
            thaiDirectInvestmentWithdrawDetails.setInvestmentRepatriatedReason(datasetltx.getInvtReptReason());
            transactionPurposeInfo.setThaiDirectInvestmentWithdrawDetails(thaiDirectInvestmentWithdrawDetails);
        } else if ("318077".equals(outTranPurp)) {
            DSLTX.DSLTXContent.ContentRecordGroup.TransactionPurposeInfo.ForeignPortfolioInvestmentWithdrawDetails foreignPortfolioInvestmentWithdrawDetails = ltxOf
                    .createDSLTXDSLTXContentContentRecordGroupTransactionPurposeInfoForeignPortfolioInvestmentWithdrawDetails();
            foreignPortfolioInvestmentWithdrawDetails.setListedInMarketFlag(datasetltx.getMktFlag());
            foreignPortfolioInvestmentWithdrawDetails.setCustomerInvestmentType(datasetltx.getCustInvtType());
            foreignPortfolioInvestmentWithdrawDetails.setTermRange(datasetltx.getTermRange());
            transactionPurposeInfo
                    .setForeignPortfolioInvestmentWithdrawDetails(foreignPortfolioInvestmentWithdrawDetails);
        } else if ("318078".equals(outTranPurp)) {
            DSLTX.DSLTXContent.ContentRecordGroup.TransactionPurposeInfo.ForeignPortfolioInvestmentOutflowDetails foreignPortfolioInvestmentOutflowDetails = ltxOf
                    .createDSLTXDSLTXContentContentRecordGroupTransactionPurposeInfoForeignPortfolioInvestmentOutflowDetails();
            foreignPortfolioInvestmentOutflowDetails.setListedInMarketFlag(datasetltx.getMktFlag());
            foreignPortfolioInvestmentOutflowDetails.setCustomerInvestmentType(datasetltx.getCustInvtType());
            foreignPortfolioInvestmentOutflowDetails.setTermRange(datasetltx.getTermRange());
            transactionPurposeInfo
                    .setForeignPortfolioInvestmentOutflowDetails(foreignPortfolioInvestmentOutflowDetails);
        } else if ("318202".equals(outTranPurp)) {
            DSLTX.DSLTXContent.ContentRecordGroup.TransactionPurposeInfo.ThaiPortfolioInvestmentByForeignWithdrawDetails thaiPortfolioInvestmentByForeignWithdrawDetails = ltxOf
                    .createDSLTXDSLTXContentContentRecordGroupTransactionPurposeInfoThaiPortfolioInvestmentByForeignWithdrawDetails();
            thaiPortfolioInvestmentByForeignWithdrawDetails.setCustomerInvestmentType(datasetltx.getCustInvtType());
            thaiPortfolioInvestmentByForeignWithdrawDetails.setTermRange(datasetltx.getTermRange());
            transactionPurposeInfo.setThaiPortfolioInvestmentByForeignWithdrawDetails(
                    thaiPortfolioInvestmentByForeignWithdrawDetails);
        } else if ("318203".equals(outTranPurp)) {
            DSLTX.DSLTXContent.ContentRecordGroup.TransactionPurposeInfo.ThaiPortfolioInvestmentByThaiWithdrawDetails thaiPortfolioInvestmentByThaiWithdrawDetails = ltxOf
                    .createDSLTXDSLTXContentContentRecordGroupTransactionPurposeInfoThaiPortfolioInvestmentByThaiWithdrawDetails();
            thaiPortfolioInvestmentByThaiWithdrawDetails.setCustomerInvestmentType(datasetltx.getCustInvtType());
            thaiPortfolioInvestmentByThaiWithdrawDetails.setTermRange(datasetltx.getTermRange());
            transactionPurposeInfo
                    .setThaiPortfolioInvestmentByThaiWithdrawDetails(thaiPortfolioInvestmentByThaiWithdrawDetails);
        } else if ("318200".equals(outTranPurp)) {
            DSLTX.DSLTXContent.ContentRecordGroup.TransactionPurposeInfo.ThaiPortfolioInvestmentByForeignOutflowDetails thaiPortfolioInvestmentByForeignOutflowDetails = ltxOf
                    .createDSLTXDSLTXContentContentRecordGroupTransactionPurposeInfoThaiPortfolioInvestmentByForeignOutflowDetails();
            thaiPortfolioInvestmentByForeignOutflowDetails.setCustomerInvestmentType(datasetltx.getCustInvtType());
            thaiPortfolioInvestmentByForeignOutflowDetails.setTermRange(datasetltx.getTermRange());
            transactionPurposeInfo.setThaiPortfolioInvestmentByForeignOutflowDetails(
                    thaiPortfolioInvestmentByForeignOutflowDetails);
        } else if ("318201".equals(outTranPurp)) {
            DSLTX.DSLTXContent.ContentRecordGroup.TransactionPurposeInfo.ThaiPortfolioInvestmentByThaiOutflowDetails thaiPortfolioInvestmentByThaiOutflowDetails = ltxOf
                    .createDSLTXDSLTXContentContentRecordGroupTransactionPurposeInfoThaiPortfolioInvestmentByThaiOutflowDetails();
            thaiPortfolioInvestmentByThaiOutflowDetails.setCustomerInvestmentType(datasetltx.getCustInvtType());
            thaiPortfolioInvestmentByThaiOutflowDetails.setTermRange(datasetltx.getTermRange());
            transactionPurposeInfo
                    .setThaiPortfolioInvestmentByThaiOutflowDetails(thaiPortfolioInvestmentByThaiOutflowDetails);
        } else if ("318084".equals(outTranPurp)) {
            DSLTX.DSLTXContent.ContentRecordGroup.TransactionPurposeInfo.ForeignLoanWithdrawDetails foreignLoanWithdrawDetails = ltxOf
                    .createDSLTXDSLTXContentContentRecordGroupTransactionPurposeInfoForeignLoanWithdrawDetails();
            foreignLoanWithdrawDetails.setTermRange(datasetltx.getTermRange());
            transactionPurposeInfo.setForeignLoanWithdrawDetails(foreignLoanWithdrawDetails);
        } else if ("318085".equals(outTranPurp)) {
            DSLTX.DSLTXContent.ContentRecordGroup.TransactionPurposeInfo.ForeignLoanOutflowDetails foreignLoanOutflowDetails = ltxOf
                    .createDSLTXDSLTXContentContentRecordGroupTransactionPurposeInfoForeignLoanOutflowDetails();
            foreignLoanOutflowDetails.setTermRange(datasetltx.getTermRange());
            foreignLoanOutflowDetails
                    .setFirstDisbursementDate(getXMLGregorianCalendarDate(datasetltx.getFirstDisbDate()));
            foreignLoanOutflowDetails.setLoanDeclarationType(datasetltx.getLoanDclrType());
            foreignLoanOutflowDetails.setRepaymentDueIndicator(datasetltx.getRepymtDueInd());
            transactionPurposeInfo.setForeignLoanOutflowDetails(foreignLoanOutflowDetails);
        } else if ("318092".equals(outTranPurp)) {
            DSLTX.DSLTXContent.ContentRecordGroup.TransactionPurposeInfo.ThaiLoanWithdrawDetails thaiLoanWithdrawDetails = ltxOf
                    .createDSLTXDSLTXContentContentRecordGroupTransactionPurposeInfoThaiLoanWithdrawDetails();
            thaiLoanWithdrawDetails.setTermRange(datasetltx.getTermRange());
            transactionPurposeInfo.setThaiLoanWithdrawDetails(thaiLoanWithdrawDetails);
        } else if ("318091".equals(outTranPurp)) {
            DSLTX.DSLTXContent.ContentRecordGroup.TransactionPurposeInfo.ThaiLoanOutflowDetails thaiLoanOutflowDetails = ltxOf
                    .createDSLTXDSLTXContentContentRecordGroupTransactionPurposeInfoThaiLoanOutflowDetails();
            thaiLoanOutflowDetails.setYtdAccumulatedAmount(getXmlString(datasetltx.getYtdAccumAmt()));
            thaiLoanOutflowDetails.setTermRange(datasetltx.getTermRange());
            thaiLoanOutflowDetails.setTerm(getXmlString(datasetltx.getTerm()));
            thaiLoanOutflowDetails.setTermUnit(datasetltx.getTermUnit());
            thaiLoanOutflowDetails.setInterestRateType(datasetltx.getIntRateType());
            thaiLoanOutflowDetails.setInterestRate(getXmlString(datasetltx.getIntRate()));
            thaiLoanOutflowDetails.setInterestRateMargin(getXmlString(datasetltx.getIntRateMrgn()));
            thaiLoanOutflowDetails.setNumberOfInstallments(getXmlString(datasetltx.getNoOfInstl()));
            thaiLoanOutflowDetails.setInstallmentTerm(getXmlString(datasetltx.getInstlTerm()));
            thaiLoanOutflowDetails.setInstallmentTermUnit(datasetltx.getInstlTermUnit());
            thaiLoanOutflowDetails.setFirstInstallmentDate(getXmlDateFormatString(datasetltx.getFirstInstlDate()));
            thaiLoanOutflowDetails.setMaturityDate(getXmlDateFormatString(datasetltx.getMatDate()));
            transactionPurposeInfo.setThaiLoanOutflowDetails(thaiLoanOutflowDetails);
        } else if ("318087".equals(outTranPurp)) {
            DSLTX.DSLTXContent.ContentRecordGroup.TransactionPurposeInfo.ForeignDebtInstrumentWithdrawDetails foreignDebtInstrumentWithdrawDetails = ltxOf
                    .createDSLTXDSLTXContentContentRecordGroupTransactionPurposeInfoForeignDebtInstrumentWithdrawDetails();
            foreignDebtInstrumentWithdrawDetails.setCustomerInvestmentType(datasetltx.getCustInvtType());
            foreignDebtInstrumentWithdrawDetails.setTermRange(datasetltx.getTermRange());
            transactionPurposeInfo.setForeignDebtInstrumentWithdrawDetails(foreignDebtInstrumentWithdrawDetails);
        } else if ("318088".equals(outTranPurp)) {
            DSLTX.DSLTXContent.ContentRecordGroup.TransactionPurposeInfo.ForeignDebtInstrumentOutflowDetails foreignDebtInstrumentOutflowDetails = ltxOf
                    .createDSLTXDSLTXContentContentRecordGroupTransactionPurposeInfoForeignDebtInstrumentOutflowDetails();
            foreignDebtInstrumentOutflowDetails.setCustomerInvestmentType(datasetltx.getCustInvtType());
            foreignDebtInstrumentOutflowDetails.setTermRange(datasetltx.getTermRange());
            foreignDebtInstrumentOutflowDetails.setWholePartialRepaymentFlag(datasetltx.getRepymtFlag());
            foreignDebtInstrumentOutflowDetails
                    .setDebtInstrumentIssuedDate(getXMLGregorianCalendarDate(datasetltx.getDeptInsmIssuDate()));
            foreignDebtInstrumentOutflowDetails
                    .setDebtInstrumentIssuedAmount(getXmlString(datasetltx.getDeptInsmIssuAmt()));
            transactionPurposeInfo.setForeignDebtInstrumentOutflowDetails(foreignDebtInstrumentOutflowDetails);
        } else if ("318095".equals(outTranPurp)) {
            DSLTX.DSLTXContent.ContentRecordGroup.TransactionPurposeInfo.ThaiDebtInstrumentWithdrawDetails thaiDebtInstrumentWithdrawDetails = ltxOf
                    .createDSLTXDSLTXContentContentRecordGroupTransactionPurposeInfoThaiDebtInstrumentWithdrawDetails();
            thaiDebtInstrumentWithdrawDetails.setCustomerInvestmentType(datasetltx.getCustInvtType());
            thaiDebtInstrumentWithdrawDetails.setTermRange(datasetltx.getTermRange());
            transactionPurposeInfo.setThaiDebtInstrumentWithdrawDetails(thaiDebtInstrumentWithdrawDetails);
        } else if ("318094".equals(outTranPurp)) {
            DSLTX.DSLTXContent.ContentRecordGroup.TransactionPurposeInfo.ThaiDebtInstrumentOutflowDetails thaiDebtInstrumentOutflowDetails = ltxOf
                    .createDSLTXDSLTXContentContentRecordGroupTransactionPurposeInfoThaiDebtInstrumentOutflowDetails();
            thaiDebtInstrumentOutflowDetails.setYtdAccumulatedAmount(getXmlString(datasetltx.getYtdAccumAmt()));
            thaiDebtInstrumentOutflowDetails.setCustomerInvestmentType(datasetltx.getCustInvtType());
            thaiDebtInstrumentOutflowDetails.setTermRange(datasetltx.getTermRange());
            thaiDebtInstrumentOutflowDetails.setTerm(getXmlString(datasetltx.getTerm()));
            thaiDebtInstrumentOutflowDetails.setTermUnit(datasetltx.getTermUnit());
            thaiDebtInstrumentOutflowDetails.setInterestRateType(datasetltx.getIntRateType());
            thaiDebtInstrumentOutflowDetails.setInterestRate(getXmlString(datasetltx.getIntRate()));
            thaiDebtInstrumentOutflowDetails.setInterestRateMargin(getXmlString(datasetltx.getIntRateMrgn()));
            thaiDebtInstrumentOutflowDetails.setMaturityDate(getXmlDateFormatString(datasetltx.getMatDate()));
            transactionPurposeInfo.setThaiDebtInstrumentOutflowDetails(thaiDebtInstrumentOutflowDetails);
        } else if ("318066".equals(outTranPurp)) {
            DSLTX.DSLTXContent.ContentRecordGroup.TransactionPurposeInfo.ThaiDirectInvestmentOutflowDetails thaiDirectInvestmentOutflowDetails = ltxOf
                    .createDSLTXDSLTXContentContentRecordGroupTransactionPurposeInfoThaiDirectInvestmentOutflowDetails();
            thaiDirectInvestmentOutflowDetails.setNumberOfShares(getXmlString(datasetltx.getNoOfShare()));
            thaiDirectInvestmentOutflowDetails.setParValuePerShare(getXmlString(datasetltx.getParVal()));
            thaiDirectInvestmentOutflowDetails.setYtdAccumulatedAmount(getXmlString(datasetltx.getYtdAccumAmt()));
            transactionPurposeInfo.setThaiDirectInvestmentOutflowDetails(thaiDirectInvestmentOutflowDetails);
        } else if ("318173".equals(outTranPurp)) {
            DSLTX.DSLTXContent.ContentRecordGroup.TransactionPurposeInfo.ThaiPortfolioInvestmentDomesticMarketWithdrawDetails thaiPortfolioInvestmentDomesticMarketWithdrawDetails = ltxOf
                    .createDSLTXDSLTXContentContentRecordGroupTransactionPurposeInfoThaiPortfolioInvestmentDomesticMarketWithdrawDetails();
            thaiPortfolioInvestmentDomesticMarketWithdrawDetails
                    .setCustomerInvestmentType(datasetltx.getCustInvtType());
            thaiPortfolioInvestmentDomesticMarketWithdrawDetails.setTermRange(datasetltx.getTermRange());
            transactionPurposeInfo.setThaiPortfolioInvestmentDomesticMarketWithdrawDetails(
                    thaiPortfolioInvestmentDomesticMarketWithdrawDetails);
        }
        return transactionPurposeInfo;
    }

    //BotReferenceNumberGroupInfo
    private DSLTX.DSLTXContent.ContentRecordGroup.BotReferenceNumberGroupInfo createBotReferenceNumberGroupInfo(
            List<Datasetltx> childBotRefList, Datasetltx mainltx) {
        DSLTX.DSLTXContent.ContentRecordGroup.BotReferenceNumberGroupInfo botReferenceNumberGroupInfo = ltxOf
                .createDSLTXDSLTXContentContentRecordGroupBotReferenceNumberGroupInfo();
        List<Datasetltx> childBotRefSubList = getChildBotRefSubList(childBotRefList, mainltx);
        if (CollectionUtil.isNotEmpty(childBotRefSubList)) {
            for (Datasetltx child : childBotRefSubList) {
                DSLTX.DSLTXContent.ContentRecordGroup.BotReferenceNumberGroupInfo.BotReferenceNumberGroupDetails detail = ltxOf
                        .createDSLTXDSLTXContentContentRecordGroupBotReferenceNumberGroupInfoBotReferenceNumberGroupDetails();
                detail.setBotReferenceNumber(child.getBotRefNum());
                botReferenceNumberGroupInfo.getBotReferenceNumberGroupDetails().add(detail);
            }
        }
        return botReferenceNumberGroupInfo;
    }

    //RelatedFiGroupInfo
    private DSLTX.DSLTXContent.ContentRecordGroup.RelatedFiGroupInfo createRelatedFiGroupInfo(
            List<Datasetltx> childRelatedFiGroupList, Datasetltx mainltx) throws DatatypeConfigurationException {
        DSLTX.DSLTXContent.ContentRecordGroup.RelatedFiGroupInfo relatedFiGroupInfo = ltxOf
                .createDSLTXDSLTXContentContentRecordGroupRelatedFiGroupInfo();
        List<Datasetltx> childRelateFiGroupSubList = getChildRelatedFiGroupSubList(childRelatedFiGroupList,
                mainltx);
        if (CollectionUtil.isNotEmpty(childRelateFiGroupSubList)) {
            for (Datasetltx child : childRelateFiGroupSubList) {
                DSLTX.DSLTXContent.ContentRecordGroup.RelatedFiGroupInfo.RelatedFiGroupDetails detail = ltxOf
                        .createDSLTXDSLTXContentContentRecordGroupRelatedFiGroupInfoRelatedFiGroupDetails();
                detail.setFromOrToFiCode(child.getFromToFiCode());
                detail.setFromOrToAccountNumber(child.getFromToAcctNo());
                detail.setFromOrToRelatedTransactionDate(getXmlDateFormatString(child.getFromToRltdDate()));
                relatedFiGroupInfo.getRelatedFiGroupDetails().add(detail);
            }
        }
        return relatedFiGroupInfo;
    }

    private List<Datasetltx> getChildBotRefSubList(List<Datasetltx> childBotRefList, Datasetltx main) {
        List<Datasetltx> subList = new ArrayList<Datasetltx>();
        for (Datasetltx child : childBotRefList) {
            if (objEquals(child.getSeq(), main.getSeq()) && child.getDataSetDate().equals(main.getDataSetDate())
                    && child.getCustCode().equals(main.getCustCode())
                    && child.getSysCode().equals(main.getSysCode())) {
                subList.add(child);
            }
        }
        return subList;
    }

    private List<Datasetltx> getChildRelatedFiGroupSubList(List<Datasetltx> childBotRefList, Datasetltx main) {
        List<Datasetltx> subList = new ArrayList<Datasetltx>();
        for (Datasetltx child : childBotRefList) {
            if (objEquals(child.getSeq(), main.getSeq()) && child.getDataSetDate().equals(main.getDataSetDate())) {
                subList.add(child);
            }
        }
        return subList;
    }
    // </editor-fold>

    // <editor-fold defaultstate="collapsed" desc="fla">
    @Override
    public byte[] generateXmlFla(String dataSetDate, String tmpTcb) throws Exception {
        try {
            List<Datasetfla> mainList = flaDao.findMainDatasetFlaList(dataSetDate, tmpTcb);

            if (CollectionUtil.isEmpty(mainList)) {
                logger.error("main list is empty");
                return new byte[0];
            }

            Datasetfla obj = mainList.get(0);

            DSFLA dsfla = flaOf.createDSFLA();
            HeadGenXMLControl head = headDao.getHeadGenXMLControlByDatasetCode("DS_FLA");
            if (head != null) {
                dsfla.setName(head.getAttributesName());
                dsfla.setType(head.getAttributesType());
                dsfla.setSchemaVersion(head.getAttributesSchemaVersion());
            }

            com.kcs.genxml.beans.fla.DataSetCommonHeader dataSetCommonHeader = flaOf.createDataSetCommonHeader();
            dataSetCommonHeader.setDataSetDate(getXMLGregorianCalendarDate(obj.getDataSetDate()));
            dataSetCommonHeader.setOrganizationId(obj.getOrgId());

            DSFLA.DSFLAHeader dsflaHeader = flaOf.createDSFLADSFLAHeader();
            dsflaHeader.setDataSubmissionPeriod(obj.getDataSubPrd());

            DSFLA.DSFLAContent dsflaContent = flaOf.createDSFLADSFLAContent();
            for (Datasetfla datasetfla : mainList) {
                nullToEmptyString(datasetfla);
                DSFLA.DSFLAContent.ContentRecordGroup contentRecordGroup = flaOf
                        .createDSFLADSFLAContentContentRecordGroup();
                contentRecordGroup.setDataProviderBranchNumber(datasetfla.getDataPvdrBrcNo());
                contentRecordGroup.setFiArrangementNumber(datasetfla.getFiArrgNo());
                contentRecordGroup.setPreviousArrangementNumber(datasetfla.getPrevArrgNo());
                contentRecordGroup.setLoanType(datasetfla.getLoanType());
                contentRecordGroup.setCreditType(datasetfla.getCrType());
                contentRecordGroup.setPrimaryInvolvedPartyId(datasetfla.getPriIpId());
                contentRecordGroup.setPrimaryInvolvedPartyUniqueIdType(datasetfla.getPriIpIdType());
                contentRecordGroup.setPrimaryInvolvedPartyBranchNumber(datasetfla.getPriIpBrcNo());
                contentRecordGroup.setPrimaryInvolvedPartyIbfIndicator(datasetfla.getPriIpIbfIbd());
                contentRecordGroup
                        .setArrangementContractDate(getXMLGregorianCalendarDate(datasetfla.getArrgCtrDate()));
                contentRecordGroup.setArrangementTermType(datasetfla.getArrgTermType());
                contentRecordGroup.setArrangementTerm(getXmlString(datasetfla.getArrgTerm()));
                contentRecordGroup.setArrangementTermUnit(datasetfla.getArrgTermUnit());
                contentRecordGroup.setEffectiveDate(getXMLGregorianCalendarDate(datasetfla.getEffDate()));
                contentRecordGroup.setMaturityDate(getXmlDateFormatString(datasetfla.getMatDate()));
                contentRecordGroup.setExtendedFlag(datasetfla.getExtFlag());
                contentRecordGroup.setDescription(datasetfla.getDescpt());
                contentRecordGroup.setFirstRepaymentDate(getXmlDateFormatString(datasetfla.getFirstRepymtDate()));
                contentRecordGroup.setNumberOfPrincipalRepayments(getXmlString(datasetfla.getNoPrinRepymt()));
                contentRecordGroup.setPrincipalRepaymentTerm(getXmlString(datasetfla.getPrinRepymtTerm()));
                contentRecordGroup.setPrincipalRepaymentTermUnit(datasetfla.getPrinRepymtTermUnit());
                contentRecordGroup.setNumberOfInterestRepayments(getXmlString(datasetfla.getNoIntRepymt()));
                contentRecordGroup.setInterestRepaymentTerm(getXmlString(datasetfla.getIntRepymtTerm()));
                contentRecordGroup.setInterestRepaymentTermUnit(datasetfla.getIntRepymtTermUnit());
                contentRecordGroup
                        .setFirstDisbursementDate(getXMLGregorianCalendarDate(datasetfla.getFirstDisbDate()));
                contentRecordGroup.setNumberOfDisbursements(getXmlString(datasetfla.getNoDisb()));
                contentRecordGroup.setInterestRateType(datasetfla.getIntRateType());
                contentRecordGroup.setInterestRate(getXmlString(datasetfla.getIntRate()));
                contentRecordGroup.setInterestRateMargin(getXmlString(datasetfla.getIntRateMrgn()));
                contentRecordGroup
                        .setContractCurrencyId(com.kcs.genxml.beans.fla.MV0072.fromValue(datasetfla.getCtrCurr()));
                contentRecordGroup.setContractAmount(getXmlString(datasetfla.getCtrAmt()));
                contentRecordGroup
                        .setLoanPutOptionExerciseDate(getXmlDateFormatString(datasetfla.getLoanPutDate()));
                contentRecordGroup.setLoanPutOptionAmount(getXmlString(datasetfla.getLoanPutAmt()));
                contentRecordGroup.setPutOptionWholeOrPartialFlag(datasetfla.getPutFlag());
                contentRecordGroup.setCallOptionWholeOrPartialFlag(datasetfla.getCallFlag());
                contentRecordGroup
                        .setLoanCallOptionExerciseDate(getXmlDateFormatString(datasetfla.getLoanCallDate()));
                contentRecordGroup.setLoanCallOptionAmount(getXmlString(datasetfla.getLoanCallAmt()));

                DSFLA.DSFLAContent.ContentRecordGroup.RelatedIpGroupInfo relatedIpGroupInfo = flaOf
                        .createDSFLADSFLAContentContentRecordGroupRelatedIpGroupInfo();
                DSFLA.DSFLAContent.ContentRecordGroup.RelatedIpGroupInfo.RelatedIpGroupDetails relatedIpGroupDetails = flaOf
                        .createDSFLADSFLAContentContentRecordGroupRelatedIpGroupInfoRelatedIpGroupDetails();
                relatedIpGroupDetails.setRelatedInvolvedPartyName(datasetfla.getRltdIpName());
                relatedIpGroupInfo.getRelatedIpGroupDetails().add(relatedIpGroupDetails);
                contentRecordGroup.setRelatedIpGroupInfo(relatedIpGroupInfo);

                dsflaContent.getContentRecordGroup().add(contentRecordGroup);
            }

            dsfla.setCommonHeader(dataSetCommonHeader);
            dsfla.setDSFLAHeader(dsflaHeader);
            dsfla.setDSFLAContent(dsflaContent);

            return generateToBytes(dsfla);
        } catch (Exception e) {
            logger.error("generateXmlFla error : " + e.getMessage(), e);
            throw e;
        }
    }
    // </editor-fold>

    // <editor-fold defaultstate="collapsed" desc="ftx">
    @Override
    public byte[] generateXmlFtx(String dataSetDate, String tmpTcb) throws Exception {
        try {
            List<Datasetftx> mainList = ftxDao.findMainList(dataSetDate, tmpTcb);
            if (CollectionUtil.isEmpty(mainList)) {
                logger.error("Can't find main dataset ftx list.");
                return new byte[0];
            }

            Datasetftx obj = mainList.get(0);

            List<Datasetftx> childBotRefList = ftxDao.findChildBotRefNumGroupInfo(obj.getDataSetDate());
            List<Datasetftx> childRelatedFiGroupList = ftxDao.findChildRelatedFiGroupInfo(obj.getDataSetDate());

            DSFTX dsftx = ftxOf.createDSFTX();
            HeadGenXMLControl head = headDao.getHeadGenXMLControlByDatasetCode("DS_FTX");
            if (head != null) {
                dsftx.setName(head.getAttributesName());
                dsftx.setType(head.getAttributesType());
                dsftx.setSchemaVersion(head.getAttributesSchemaVersion());
            }
            com.kcs.genxml.beans.ftx.DataSetCommonHeader dataSetCommonHeader = ftxOf.createDataSetCommonHeader();
            dataSetCommonHeader.setOrganizationId(obj.getOrgId());
            dataSetCommonHeader.setDataSetDate(getXMLGregorianCalendarDate(obj.getDataSetDate()));
            DSFTX.DSFTXHeader dSFTXHeader = ftxOf.createDSFTXDSFTXHeader();
            dSFTXHeader.setDataSubmissionPeriod(obj.getDataSubPrd());

            DSFTX.DSFTXContent content = ftxOf.createDSFTXDSFTXContent();

            for (Datasetftx main : mainList) {
                nullToEmptyString(main);
                DSFTX.DSFTXContent.ContentRecordGroup contentRecordGroup = ftxOf
                        .createDSFTXDSFTXContentContentRecordGroup();
                contentRecordGroup.setFiArrangementNumber(main.getFiArrgNo());
                contentRecordGroup.setFxArrangementType(main.getFxArrgType());
                contentRecordGroup.setFxTradingTransactionType(main.getFxTradeTranType());
                contentRecordGroup.setCancelationReasonType(main.getCancelReason());
                contentRecordGroup
                        .setTransactionDate(getXMLGregorianCalendarDate(main.getTranDate(), defaultPattern));
                contentRecordGroup.setExercisingInvolvedPartyId(main.getIpId());
                contentRecordGroup.setExercisingInvolvedPartyUniqueIdType(main.getIpIdType());
                contentRecordGroup.setExercisingInvolvedPartyBranchNumber(main.getIpBrcNo());
                contentRecordGroup.setExercisingInvolvedPartyIbfIndicator(main.getIpIbfInd());
                contentRecordGroup.setExercisingInvolvedPartyName(main.getIpName());
                contentRecordGroup.setExercisingInvolvedPartyBusinessType(main.getIpBusType());
                contentRecordGroup.setPaymentMethod(main.getPayMethod());
                contentRecordGroup.setFromTransactionType(main.getFromTranType());
                contentRecordGroup.setToTransactionType(main.getToTranType());
                contentRecordGroup.setInflowTransactionPurpose(main.getInfTranPurp());
                contentRecordGroup.setOutflowTransactionPurpose(main.getOutTranPurp());
                contentRecordGroup.setOtherTransactionPurposeDescription(main.getOthTranPurpDesc());
                contentRecordGroup.setObjectiveType(main.getObjectiveType());
                contentRecordGroup.setExchangeRate(getXmlString(main.getExcRate()));
                contentRecordGroup.setBuyCurrencyId(com.kcs.genxml.beans.ftx.MV0053.fromValue(main.getBuyCurr()));
                contentRecordGroup.setBuyAmount(getXmlString(main.getBuyAmt()));
                contentRecordGroup.setSellCurrencyId(com.kcs.genxml.beans.ftx.MV0053.fromValue(main.getSellCurr()));
                contentRecordGroup.setSellAmount(getXmlString(main.getSellAmt()));
                contentRecordGroup.setNotionalCurrencyId(main.getNtnCurr());
                contentRecordGroup.setNotionalAmount(getXmlString(main.getNtnAmt()));
                contentRecordGroup.setOutstandingNotionalCurrencyId(main.getOutstNtnCurr());
                contentRecordGroup.setOutstandingNotionalAmount(getXmlString(main.getOutstNtnAmt()));

                contentRecordGroup.setApprovalDocumentGroupInfo(createApprovalDocumentGroupInfo(main));

                contentRecordGroup
                        .setBotReferenceNumberGroupInfo(createBotReferenceNumberGroupInfo(main, childBotRefList));

                contentRecordGroup.setRelatedFiGroupInfo(createRelatedFiGroupInfo(main, childRelatedFiGroupList));

                contentRecordGroup.setBeneficiaryOrSenderName(main.getBnftSendrName());
                contentRecordGroup.setCountryIdOfBeneficiaryOrSender(main.getCtryBnftSendr());
                contentRecordGroup.setRelationshipWithBeneficiaryOrSender(main.getRelnBeftSendr());
                contentRecordGroup.setUnderlyingOwnerName(main.getUnderlyingOwnName());

                contentRecordGroup.setTransactionPurposeInfo(createTransactionPurposeInfo(main));

                contentRecordGroup.setDescription(main.getDescription());

                content.getContentRecordGroup().add(contentRecordGroup);
            }

            dsftx.setCommonHeader(dataSetCommonHeader);
            dsftx.setDSFTXHeader(dSFTXHeader);
            dsftx.setDSFTXContent(content);

            return generateToBytes(dsftx);
        } catch (Exception e) {
            e.printStackTrace();
            throw e;
        }
    }

    DSFTX.DSFTXContent.ContentRecordGroup.ApprovalDocumentGroupInfo createApprovalDocumentGroupInfo(Datasetftx main)
            throws Exception {
        DSFTX.DSFTXContent.ContentRecordGroup.ApprovalDocumentGroupInfo approvalDocumentGroupInfo = ftxOf
                .createDSFTXDSFTXContentContentRecordGroupApprovalDocumentGroupInfo();
        if (StringUtil.isNotEmpty(main.getAppvDocDate())) {
            DSFTX.DSFTXContent.ContentRecordGroup.ApprovalDocumentGroupInfo.ApprovalDocumentGroupDetails detail = ftxOf
                    .createDSFTXDSFTXContentContentRecordGroupApprovalDocumentGroupInfoApprovalDocumentGroupDetails();
            logger.debug("appv doc date : " + main.getAppvDocDate());
            detail.setApprovalDocumentDate(getXMLGregorianCalendarDate(main.getAppvDocDate(), defaultPattern));
            detail.setApprovalDocumentNumber(main.getAppvDocNo());
            approvalDocumentGroupInfo.getApprovalDocumentGroupDetails().add(detail);
        }
        return approvalDocumentGroupInfo;
    }

    DSFTX.DSFTXContent.ContentRecordGroup.BotReferenceNumberGroupInfo createBotReferenceNumberGroupInfo(
            Datasetftx main, List<Datasetftx> childBotRefList) {
        DSFTX.DSFTXContent.ContentRecordGroup.BotReferenceNumberGroupInfo botReferenceNumberGroupInfo = ftxOf
                .createDSFTXDSFTXContentContentRecordGroupBotReferenceNumberGroupInfo();
        List<Datasetftx> child = filterChildBot(main, childBotRefList);
        logger.debug("childBotRefList : " + childBotRefList.size());
        logger.debug("child : " + child.size());
        for (Datasetftx c : child) {
            DSFTX.DSFTXContent.ContentRecordGroup.BotReferenceNumberGroupInfo.BotReferenceNumberGroupDetails detail = ftxOf
                    .createDSFTXDSFTXContentContentRecordGroupBotReferenceNumberGroupInfoBotReferenceNumberGroupDetails();
            detail.setBotReferenceNumber(c.getBotRefNum());
            botReferenceNumberGroupInfo.getBotReferenceNumberGroupDetails().add(detail);
        }
        return botReferenceNumberGroupInfo;
    }

    DSFTX.DSFTXContent.ContentRecordGroup.RelatedFiGroupInfo createRelatedFiGroupInfo(Datasetftx main,
            List<Datasetftx> childRelatedFiGroupList) throws Exception {
        DSFTX.DSFTXContent.ContentRecordGroup.RelatedFiGroupInfo relatedFiGroupInfo = ftxOf
                .createDSFTXDSFTXContentContentRecordGroupRelatedFiGroupInfo();
        List<Datasetftx> child = filterChildRelateFiGroup(main, childRelatedFiGroupList);
        for (Datasetftx c : child) {
            analyze(c);
            DSFTX.DSFTXContent.ContentRecordGroup.RelatedFiGroupInfo.RelatedFiGroupDetails detail = ftxOf
                    .createDSFTXDSFTXContentContentRecordGroupRelatedFiGroupInfoRelatedFiGroupDetails();
            detail.setFromOrToFiCode(c.getFromToFiCode());
            detail.setFromOrToAccountNumber(c.getFromToAcctNo());
            detail.setFromOrToRelatedTransactionDate(
                    getXMLGregorianCalendarDate(c.getFromToRltdTranDate(), "yyyy-MM-dd hh:mm:ss.S").toXMLFormat());
            relatedFiGroupInfo.getRelatedFiGroupDetails().add(detail);
        }
        return relatedFiGroupInfo;
    }

    List<Datasetftx> filterChildBot(final Datasetftx main, List<Datasetftx> child) {
        List<Datasetftx> result = new ArrayList<Datasetftx>();
        //        for(Datasetftx c : child){
        ////            if(equals(c.getSeq(),main.getSeq())){
        ////            logger.debug("seq     ==> " + c.getSeq() + "," + main.getSeq() + " : " + (equals(c.getSeq(),main.getSeq())));
        //////            logger.debug("cusCode ==> " + c.getCustCode() + "," + main.getCustCode() + " : " + equals(c.getCustCode(), main.getCustCode()));
        //////            logger.debug("sysCode ==> " + c.getSysCode() + "," + main.getSysCode() + " : " + (c.getSysCode().equals(main.getSysCode())));
        ////            }
        //            if(objEquals(c.getSeq(),main.getSeq()) && c.getCustCode().equals(main.getCustCode()) && c.getSysCode().equals(main.getSysCode())){
        //                result.add(c);
        //            }
        //        }
        final Predicate childBotPredicate = new Predicate() {
            @Override
            public boolean evaluate(Object o) {
                if (Utility.isNotNull(o)) {
                    Datasetftx child = (Datasetftx) o;
                    boolean result = (objEquals(child.getSeq(), main.getSeq())
                            && (child.getCustCode().equals(main.getCustCode()))
                            && (child.getSysCode().equals(main.getSysCode())));
                    return result;
                }
                return false;
            }
        };
        result = (List<Datasetftx>) CollectionUtils.select(child, childBotPredicate);
        return result;
    }

    List<Datasetftx> filterChildRelateFiGroup(final Datasetftx main, List<Datasetftx> childRelateFiGroupList) {
        List<Datasetftx> result = new ArrayList<Datasetftx>();
        //        for(Datasetftx c : childRelateFiGroupList){
        //            if(objEquals(c.getSeq(),main.getSeq())){
        //                result.add(c);
        //            }
        //        }
        final Predicate childRelateFiPredicate = new Predicate() {
            @Override
            public boolean evaluate(Object o) {
                if (Utility.isNotNull(o)) {
                    Datasetftx child = (Datasetftx) o;
                    boolean result = (objEquals(child.getSeq(), main.getSeq()));
                    return result;
                }
                return false;
            }
        };
        result = (List<Datasetftx>) CollectionUtils.select(childRelateFiGroupList, childRelateFiPredicate);
        return result;
    }

    DSFTX.DSFTXContent.ContentRecordGroup.TransactionPurposeInfo createTransactionPurposeInfo(Datasetftx main)
            throws Exception {
        DSFTX.DSFTXContent.ContentRecordGroup.TransactionPurposeInfo transactionPurposeInfo = ftxOf
                .createDSFTXDSFTXContentContentRecordGroupTransactionPurposeInfo();

        String infTranPurp = main.getInfTranPurp();
        String outTranPurp = main.getOutTranPurp();

        logger.debug("infTranPurp : " + infTranPurp);
        logger.debug("outTranPurp : " + outTranPurp);

        if ("318063".equals(infTranPurp)) {
            DSFTX.DSFTXContent.ContentRecordGroup.TransactionPurposeInfo.ForeignDirectInvestmentInflowDetails detail = ftxOf
                    .createDSFTXDSFTXContentContentRecordGroupTransactionPurposeInfoForeignDirectInvestmentInflowDetails();
            detail.setRelatedInvolvedPartyName(main.getRetdInvPartyName());
            detail.setRelatedInvolvedPartyBusinessType(main.getRltdInvBusType());
            detail.setListedInMarketFlag(main.getMktFlag());
            transactionPurposeInfo.setForeignDirectInvestmentInflowDetails(detail);
        } else if ("318067".equals(infTranPurp)) {
            DSFTX.DSFTXContent.ContentRecordGroup.TransactionPurposeInfo.ThaiDirectInvestmentInflowDetails detail = ftxOf
                    .createDSFTXDSFTXContentContentRecordGroupTransactionPurposeInfoThaiDirectInvestmentInflowDetails();
            detail.setRelatedInvolvedPartyName(main.getRetdInvPartyName());
            detail.setRelatedInvolvedPartyBusinessType(main.getRltdInvBusType());
            detail.setInvestmentRepatriatedReason(main.getInvtReptReson());
            detail.setRelationshipWithRelatedInvolvedParty(main.getRelnRltdInvParty());
            transactionPurposeInfo.setThaiDirectInvestmentInflowDetails(detail);
        } else if ("318077".equals(infTranPurp)) {
            String[] custInvTypes = { "168010", "168012", "168013", "168014", "168015", "168016", "168017",
                    "168018", "168019", "168020", "168021", "168022" };
            String custInvType = main.getCustInvtType();
            boolean hasIn = false;
            for (String type : custInvTypes) {
                if (type.equals(custInvType)) {
                    hasIn = true;
                    break;
                }
            }
            DSFTX.DSFTXContent.ContentRecordGroup.TransactionPurposeInfo.ForeignPortfolioInvestmentInflowDetails detail = ftxOf
                    .createDSFTXDSFTXContentContentRecordGroupTransactionPurposeInfoForeignPortfolioInvestmentInflowDetails();
            detail.setListedInMarketFlag(main.getMktFlag());
            detail.setCustomerInvestmentType(main.getCustInvtType());
            if (hasIn) {
                detail.setTermRange(main.getTermRange());
            } else {
                detail.setTermRange(null);
            }
            transactionPurposeInfo.setForeignPortfolioInvestmentInflowDetails(detail);
        } else if ("318202".equals(infTranPurp)) {
            DSFTX.DSFTXContent.ContentRecordGroup.TransactionPurposeInfo.ThaiPortfolioInvestmentByForeignInflowDetails detail = ftxOf
                    .createDSFTXDSFTXContentContentRecordGroupTransactionPurposeInfoThaiPortfolioInvestmentByForeignInflowDetails();
            detail.setRelatedInvolvedPartyName(main.getRetdInvPartyName());
            detail.setRelatedInvolvedPartyBusinessType(main.getRltdInvBusType());
            detail.setCustomerInvestmentType(main.getCustInvtType());
            detail.setTermRange(main.getTermRange());
            transactionPurposeInfo.setThaiPortfolioInvestmentByForeignInflowDetails(detail);
        } else if ("318203".equals(infTranPurp)) {
            DSFTX.DSFTXContent.ContentRecordGroup.TransactionPurposeInfo.ThaiPortfolioInvestmentByThaiInflowDetails detail = ftxOf
                    .createDSFTXDSFTXContentContentRecordGroupTransactionPurposeInfoThaiPortfolioInvestmentByThaiInflowDetails();
            detail.setRelatedInvolvedPartyName(main.getRetdInvPartyName());
            detail.setRelatedInvolvedPartyBusinessType(main.getRltdInvBusType());
            detail.setCustomerInvestmentType(main.getCustInvtType());
            detail.setTermRange(main.getTermRange());
            transactionPurposeInfo.setThaiPortfolioInvestmentByThaiInflowDetails(detail);
        } else if ("318084".equals(infTranPurp)) {
            DSFTX.DSFTXContent.ContentRecordGroup.TransactionPurposeInfo.ForeignLoanInflowDetails detail = ftxOf
                    .createDSFTXDSFTXContentContentRecordGroupTransactionPurposeInfoForeignLoanInflowDetails();
            detail.setRelatedInvolvedPartyName(main.getRetdInvPartyName());
            detail.setRelatedInvolvedPartyBusinessType(main.getRltdInvBusType());
            detail.setRelationshipWithRelatedInvolvedParty(main.getRelnRltdInvParty());
            detail.setTermRange(main.getTermRange());
            detail.setTerm(main.getTerm());
            detail.setTermUnit(main.getTermUnit());
            detail.setInterestRateType(main.getIntRateType());
            detail.setInterestRate(getXmlString(main.getIntRate()));
            detail.setInterestRateMargin(getXmlString(main.getIntRateMrgn()));
            detail.setNumberOfInstallments(main.getNoOfInstl());
            detail.setInstallmentTerm(main.getInstlTerm());
            detail.setInstallmentTermUnit(main.getInstlTermUnit());
            detail.setFirstInstallmentDate(
                    getXMLGregorianCalendarDate(main.getFirstInstlDate(), defaultPattern).toXMLFormat());
            detail.setMaturityDate(getXMLGregorianCalendarDate(main.getMatDate(), defaultPattern).toXMLFormat());
            transactionPurposeInfo.setForeignLoanInflowDetails(detail);
        } else if ("318092".equals(infTranPurp)) {
            DSFTX.DSFTXContent.ContentRecordGroup.TransactionPurposeInfo.ThaiLoanInflowDetails detail = ftxOf
                    .createDSFTXDSFTXContentContentRecordGroupTransactionPurposeInfoThaiLoanInflowDetails();
            detail.setRelatedInvolvedPartyName(main.getRetdInvPartyName());
            detail.setRelatedInvolvedPartyBusinessType(main.getRltdInvBusType());
            detail.setRelationshipWithRelatedInvolvedParty(main.getRelnRltdInvParty());
            detail.setTermRange(main.getTermRange());
            transactionPurposeInfo.setThaiLoanInflowDetails(detail);
        } else if ("318087".equals(infTranPurp)) {
            DSFTX.DSFTXContent.ContentRecordGroup.TransactionPurposeInfo.ForeignDebtInstrumentInflowDetails detail = ftxOf
                    .createDSFTXDSFTXContentContentRecordGroupTransactionPurposeInfoForeignDebtInstrumentInflowDetails();
            detail.setRelatedInvolvedPartyName(main.getRetdInvPartyName());
            detail.setRelatedInvolvedPartyBusinessType(main.getRltdInvBusType());
            detail.setRelationshipWithRelatedInvolvedParty(main.getRelnRltdInvParty());
            detail.setCustomerInvestmentType(main.getCustInvtType());
            detail.setTermRange(main.getTermRange());
            detail.setTerm(main.getTerm());
            detail.setTermUnit(main.getTermUnit());
            detail.setInterestRateType(main.getIntRateType());
            detail.setInterestRate(getXmlString(main.getIntRate()));
            detail.setInterestRateMargin(getXmlString(main.getIntRateMrgn()));
            detail.setMaturityDate(main.getMatDate());
            transactionPurposeInfo.setForeignDebtInstrumentInflowDetails(detail);
        } else if ("318095".equals(infTranPurp)) {
            DSFTX.DSFTXContent.ContentRecordGroup.TransactionPurposeInfo.ThaiDebtInstrumentInflowDetails detail = ftxOf
                    .createDSFTXDSFTXContentContentRecordGroupTransactionPurposeInfoThaiDebtInstrumentInflowDetails();
            detail.setRelatedInvolvedPartyName(main.getRetdInvPartyName());
            detail.setRelatedInvolvedPartyBusinessType(main.getRltdInvBusType());
            detail.setRelationshipWithRelatedInvolvedParty(main.getRelnRltdInvParty());
            detail.setCustomerInvestmentType(main.getCustInvtType());
            detail.setTermRange(main.getTermRange());
            detail.setWholePartialRepaymentFlag(main.getWhlPartRepayFlag());
            detail.setDebtInstrumentIssuedDate(
                    getXMLGregorianCalendarDate(main.getDebtInsmIssDate(), defaultPattern));
            detail.setDebtInstrumentIssuedAmount(getXmlString(main.getDebtInsmIssAmt()));
            transactionPurposeInfo.setThaiDebtInstrumentInflowDetails(detail);
        }

        if ("318064".equals(outTranPurp)) {
            DSFTX.DSFTXContent.ContentRecordGroup.TransactionPurposeInfo.ForeignDirectInvestmentOutflowDetails detail = ftxOf
                    .createDSFTXDSFTXContentContentRecordGroupTransactionPurposeInfoForeignDirectInvestmentOutflowDetails();
            detail.setRelatedInvolvedPartyName(main.getRetdInvPartyName());
            detail.setRelatedInvolvedPartyBusinessType(main.getRltdInvBusType());
            detail.setListedInMarketFlag(main.getMktFlag());
            detail.setInvestmentRepatriatedReason(main.getInvtReptReson());
            transactionPurposeInfo.setForeignDirectInvestmentOutflowDetails(detail);
        } else if ("318066".equals(outTranPurp)) {
            DSFTX.DSFTXContent.ContentRecordGroup.TransactionPurposeInfo.ThaiDirectInvestmentOutflowDetails detail = ftxOf
                    .createDSFTXDSFTXContentContentRecordGroupTransactionPurposeInfoThaiDirectInvestmentOutflowDetails();
            detail.setRelatedInvolvedPartyName(main.getRetdInvPartyName());
            detail.setRelatedInvolvedPartyBusinessType(main.getRltdInvBusType());
            detail.setNumberOfShares(main.getNoOfShare());
            detail.setParValuePerShare(getXmlString(main.getParVal()));
            detail.setYtdAccumulatedAmount(getXmlString(main.getYtdAccumAmt()));
            detail.setRelationshipWithRelatedInvolvedParty(main.getRelnRltdInvParty());
            transactionPurposeInfo.setThaiDirectInvestmentOutflowDetails(detail);
        } else if ("318078".equals(outTranPurp)) {
            DSFTX.DSFTXContent.ContentRecordGroup.TransactionPurposeInfo.ForeignPortfolioInvestmentOutflowDetails detail = ftxOf
                    .createDSFTXDSFTXContentContentRecordGroupTransactionPurposeInfoForeignPortfolioInvestmentOutflowDetails();
            detail.setListedInMarketFlag(main.getMktFlag());
            detail.setCustomerInvestmentType(main.getCustInvtType());
            detail.setTermRange(main.getTermRange());
            transactionPurposeInfo.setForeignPortfolioInvestmentOutflowDetails(detail);
        } else if ("318200".equals(outTranPurp)) {
            DSFTX.DSFTXContent.ContentRecordGroup.TransactionPurposeInfo.ThaiPortfolioInvestmentByForeignOutflowDetails detail = ftxOf
                    .createDSFTXDSFTXContentContentRecordGroupTransactionPurposeInfoThaiPortfolioInvestmentByForeignOutflowDetails();
            detail.setRelatedInvolvedPartyName(main.getRetdInvPartyName());
            detail.setRelatedInvolvedPartyBusinessType(main.getRltdInvBusType());
            detail.setCustomerInvestmentType(main.getCustInvtType());
            detail.setTermRange(main.getTermRange());
            transactionPurposeInfo.setThaiPortfolioInvestmentByForeignOutflowDetails(detail);
        } else if ("318201".equals(outTranPurp)) {
            DSFTX.DSFTXContent.ContentRecordGroup.TransactionPurposeInfo.ThaiPortfolioInvestmentByThaiOutflowDetails detail = ftxOf
                    .createDSFTXDSFTXContentContentRecordGroupTransactionPurposeInfoThaiPortfolioInvestmentByThaiOutflowDetails();
            detail.setRelatedInvolvedPartyName(main.getRetdInvPartyName());
            detail.setRelatedInvolvedPartyBusinessType(main.getRltdInvBusType());
            detail.setCustomerInvestmentType(main.getCustInvtType());
            detail.setTermRange(main.getTermRange());
            transactionPurposeInfo.setThaiPortfolioInvestmentByThaiOutflowDetails(detail);
        } else if ("318085".equals(outTranPurp)) {
            DSFTX.DSFTXContent.ContentRecordGroup.TransactionPurposeInfo.ForeignLoanOutflowDetails detail = ftxOf
                    .createDSFTXDSFTXContentContentRecordGroupTransactionPurposeInfoForeignLoanOutflowDetails();
            detail.setRelatedInvolvedPartyName(main.getRetdInvPartyName());
            detail.setRelatedInvolvedPartyBusinessType(main.getRltdInvBusType());
            detail.setRelationshipWithRelatedInvolvedParty(main.getRelnRltdInvParty());
            detail.setTermRange(main.getTermRange());
            if (StringUtil.isNotEmpty(main.getFirstDisbDate())) {
                detail.setFirstDisbursementDate(
                        getXMLGregorianCalendarDate(main.getFirstDisbDate(), defaultPattern));
            }
            detail.setLoanDeclarationType(main.getLoanDclrType());
            detail.setRepaymentDueIndicator(main.getRepayDueInd());
            transactionPurposeInfo.setForeignLoanOutflowDetails(detail);
        } else if ("318091".equals(outTranPurp)) {
            DSFTX.DSFTXContent.ContentRecordGroup.TransactionPurposeInfo.ThaiLoanOutflowDetails detail = ftxOf
                    .createDSFTXDSFTXContentContentRecordGroupTransactionPurposeInfoThaiLoanOutflowDetails();
            detail.setRelatedInvolvedPartyName(main.getRetdInvPartyName());
            detail.setRelatedInvolvedPartyBusinessType(main.getRltdInvBusType());
            detail.setRelationshipWithRelatedInvolvedParty(main.getRelnRltdInvParty());
            detail.setYtdAccumulatedAmount(getXmlString(main.getYtdAccumAmt()));
            detail.setTermRange(main.getTermRange());
            detail.setTerm(main.getTerm());
            detail.setTermUnit(main.getTermUnit());
            detail.setInterestRateType(main.getIntRateType());
            detail.setInterestRate(getXmlString(main.getIntRate()));
            detail.setInterestRateMargin(getXmlString(main.getIntRateMrgn()));
            detail.setNumberOfInstallments(main.getNoOfInstl());
            detail.setInstallmentTerm(main.getInstlTerm());
            detail.setInstallmentTermUnit(main.getInstlTermUnit());
            detail.setFirstInstallmentDate(
                    getXMLGregorianCalendarDate(main.getFirstInstlDate(), defaultPattern).toXMLFormat());
            detail.setMaturityDate(getXMLGregorianCalendarDate(main.getMatDate(), defaultPattern).toXMLFormat());
            transactionPurposeInfo.setThaiLoanOutflowDetails(detail);
        } else if ("318088".equals(outTranPurp)) {
            DSFTX.DSFTXContent.ContentRecordGroup.TransactionPurposeInfo.ForeignDebtInstrumentOutflowDetails detail = ftxOf
                    .createDSFTXDSFTXContentContentRecordGroupTransactionPurposeInfoForeignDebtInstrumentOutflowDetails();
            detail.setRelatedInvolvedPartyName(main.getRetdInvPartyName());
            detail.setRelatedInvolvedPartyBusinessType(main.getRltdInvBusType());
            detail.setRelationshipWithRelatedInvolvedParty(main.getRelnRltdInvParty());
            detail.setCustomerInvestmentType(main.getCustInvtType());
            detail.setTermRange(main.getTermRange());
            detail.setWholePartialRepaymentFlag(main.getWhlPartRepayFlag());
            detail.setDebtInstrumentIssuedDate(
                    getXMLGregorianCalendarDate(main.getDebtInsmIssDate(), defaultPattern));
            detail.setDebtInstrumentIssuedAmount(getXmlString(main.getDebtInsmIssAmt()));
            detail.setLoanDeclarationType(main.getLoanDclrType());
            transactionPurposeInfo.setForeignDebtInstrumentOutflowDetails(detail);
        } else if ("318094".equals(outTranPurp)) {
            DSFTX.DSFTXContent.ContentRecordGroup.TransactionPurposeInfo.ThaiDebtInstrumentOutflowDetails detail = ftxOf
                    .createDSFTXDSFTXContentContentRecordGroupTransactionPurposeInfoThaiDebtInstrumentOutflowDetails();
            detail.setRelatedInvolvedPartyName(main.getRetdInvPartyName());
            detail.setRelatedInvolvedPartyBusinessType(main.getRltdInvBusType());
            detail.setRelationshipWithRelatedInvolvedParty(main.getRelnRltdInvParty());
            detail.setYtdAccumulatedAmount(getXmlString(main.getYtdAccumAmt()));
            detail.setCustomerInvestmentType(main.getCustInvtType());
            detail.setTermRange(main.getTermRange());
            detail.setTerm(main.getTerm());
            detail.setTermUnit(main.getTermUnit());
            detail.setInterestRateType(main.getIntRateType());
            detail.setInterestRate(getXmlString(main.getIntRate()));
            detail.setInterestRateMargin(getXmlString(main.getIntRateMrgn()));
            detail.setMaturityDate(main.getMatDate());
            transactionPurposeInfo.setThaiDebtInstrumentOutflowDetails(detail);
        }

        return transactionPurposeInfo;
    }
    // </editor-fold>

    // <editor-fold defaultstate="collapsed" desc="ftu">
    @Override
    public byte[] generateXmlFtu(String dataSetDate, String tmpTcb) throws Exception {
        try {
            List<Datasetftu> mainList = ftuDao.findMainDatasetList(dataSetDate, tmpTcb);

            if (CollectionUtil.isEmpty(mainList)) {
                logger.error("not found ftu main list");
                return new byte[0];
            }

            Datasetftu obj = mainList.get(0);

            DSFTU dsFtu = ftuOf.createDSFTU();
            com.kcs.genxml.beans.ftu.DataSetCommonHeader headerCommand = ftuOf.createDataSetCommonHeader();
            headerCommand.setOrganizationId(obj.getOrgId());
            headerCommand.setDataSetDate(getXMLGregorianCalendarDate(obj.getDataSetDate()));
            DSFTU.DSFTUHeader dsFtuHeader = ftuOf.createDSFTUDSFTUHeader();
            dsFtuHeader.setDataSubmissionPeriod(obj.getDataSubPrd());

            dsFtu.setCommonHeader(headerCommand);
            dsFtu.setDSFTUHeader(dsFtuHeader);
            HeadGenXMLControl head = headDao.getHeadGenXMLControlByDatasetCode("DS_FTU");
            if (head != null) {
                dsFtu.setType(head.getAttributesType());
                dsFtu.setName(head.getAttributesName());
                dsFtu.setSchemaVersion(head.getAttributesSchemaVersion());
            }

            DSFTU.DSFTUContent content = ftuOf.createDSFTUDSFTUContent();

            for (Datasetftu main : mainList) {
                nullToEmptyString(main);
                DSFTU.DSFTUContent.ContentRecordGroup recordGroup = ftuOf
                        .createDSFTUDSFTUContentContentRecordGroup();
                recordGroup.setFiReportingGroupId(main.getFiRptGrp());

                DSFTU.DSFTUContent.ContentRecordGroup.FxTransactionSummaryGroupInfo fxTransactionSummaryGroupInfo = ftuOf
                        .createDSFTUDSFTUContentContentRecordGroupFxTransactionSummaryGroupInfo();
                DSFTU.DSFTUContent.ContentRecordGroup.FxTransactionSummaryGroupInfo.FxTransactionSummaryGroupDetails detail = ftuOf
                        .createDSFTUDSFTUContentContentRecordGroupFxTransactionSummaryGroupInfoFxTransactionSummaryGroupDetails();

                detail.setFxArrangementType(main.getFxArrgType());
                detail.setCountryIdOfBeneficiaryInvolvedParty(
                        com.kcs.genxml.beans.ftu.MV0025.fromValue(main.getCntyBnft()));
                detail.setBusinessTypeOfExercisingInvolvedParty(main.getBusType());
                detail.setInflowTransactionPurpose(main.getInfTranPurp());
                detail.setOutflowTransactionPurpose(main.getOutTranPurp());
                detail.setCurrencyId(com.kcs.genxml.beans.ftu.MV0072.fromValue(main.getCurr()));
                detail.setLegType(main.getLegType());
                detail.setForeignCurrencyAmount(getXmlString(main.getFrgnCurrAmt()));

                fxTransactionSummaryGroupInfo.getFxTransactionSummaryGroupDetails().add(detail);
                recordGroup.setFxTransactionSummaryGroupInfo(fxTransactionSummaryGroupInfo);
                content.getContentRecordGroup().add(recordGroup);
            }
            dsFtu.setDSFTUContent(content);

            return generateToBytes(dsFtu);
        } catch (Exception e) {
            e.printStackTrace();
            throw e;
        }
    }
    // </editor-fold>

    // <editor-fold defaultstate="collapsed" desc="frf">
    @Override
    public byte[] generateXmlFrf(String dataSetDate, String tmpTcb) throws Exception {
        try {
            List<Datasetfrf> mainList = frfDao.findMainList(dataSetDate, tmpTcb);
            if (CollectionUtil.isEmpty(mainList)) {
                logger.error("not found frf main list");
                return new byte[0];
            }

            Datasetfrf o = mainList.get(0);

            DSFRF dsFrf = frfOf.createDSFRF();
            HeadGenXMLControl head = headDao.getHeadGenXMLControlByDatasetCode("DS_FRF");
            if (head != null) {
                dsFrf.setName(head.getAttributesName());
                dsFrf.setType(head.getAttributesType());
                dsFrf.setSchemaVersion(head.getAttributesSchemaVersion());
            }

            com.kcs.genxml.beans.frf.DataSetCommonHeader dataSetCommonHeader = frfOf.createDataSetCommonHeader();
            dataSetCommonHeader.setDataSetDate(getXMLGregorianCalendarDate(o.getDataSetDate()));
            dataSetCommonHeader.setOrganizationId(o.getOrgId());

            DSFRF.DSFRFHeader dSFRFHeader = frfOf.createDSFRFDSFRFHeader();

            DSFRF.DSFRFContent content = frfOf.createDSFRFDSFRFContent();

            for (Datasetfrf main : mainList) {
                nullToEmptyString(main);
                DSFRF.DSFRFContent.ContentRecordGroup contentRecordGroup = frfOf
                        .createDSFRFDSFRFContentContentRecordGroup();
                contentRecordGroup.setLoanDepositTransactionType(main.getLoanDepsitTrnTye());
                contentRecordGroup.setCurrencyId(com.kcs.genxml.beans.frf.MV0072.fromValue(main.getCurrCode()));
                contentRecordGroup.setPaymentMethod(main.getPaymentMethod());
                contentRecordGroup.setBrOrBcFlag(main.getBrOrBcFlg());
                contentRecordGroup.setCommissionInLieuRate(main.getCommInLieuRate());
                contentRecordGroup.setMinCommissionInLieu(main.getMinCommInLieu());
                contentRecordGroup.setMaxCommissionInLieu(main.getMaxCommInLieu());
                contentRecordGroup.setOtherFeeDescription(main.getOthFeeDesc());

                content.getContentRecordGroup().add(contentRecordGroup);
            }

            dsFrf.setCommonHeader(dataSetCommonHeader);
            dsFrf.setDSFRFHeader(dSFRFHeader);
            dsFrf.setDSFRFContent(content);

            return generateToBytes(dsFrf);
        } catch (Exception e) {
            e.printStackTrace();
            throw e;
        }
    }
    // </editor-fold>

    // <editor-fold defaultstate="collapsed" desc="frw">
    public byte[] generateXmlFrw(String dataSetDate, String tmpTcb) throws Exception {
        try {
            List<Datasetfrw> mainList = frwDao.findMainList(dataSetDate, tmpTcb);
            if (CollectionUtil.isEmpty(mainList)) {
                logger.error("not found frw main list");
                return new byte[0];
            }

            Datasetfrw o = mainList.get(0);

            DSFRW dsFrw = frwOf.createDSFRW();

            HeadGenXMLControl head = headDao.getHeadGenXMLControlByDatasetCode("DS_FRW");
            if (head != null) {
                dsFrw.setName(head.getAttributesName());
                dsFrw.setType(head.getAttributesType());
                dsFrw.setSchemaVersion(head.getAttributesSchemaVersion());
            }

            com.kcs.genxml.beans.frw.DataSetCommonHeader dataSetCommonHeader = frwOf.createDataSetCommonHeader();
            dataSetCommonHeader.setDataSetDate(getXMLGregorianCalendarDate(o.getDataSetDate()));
            dataSetCommonHeader.setOrganizationId(o.getOrgId());

            DSFRW.DSFRWHeader dSFRWHeader = frwOf.createDSFRWDSFRWHeader();

            DSFRW.DSFRWContent dSFRWContent = frwOf.createDSFRWDSFRWContent();
            for (Datasetfrw main : mainList) {
                nullToEmptyString(main);
                DSFRW.DSFRWContent.ContentRecordGroup contentRecordGroup = frwOf
                        .createDSFRWDSFRWContentContentRecordGroup();
                contentRecordGroup.setCurrencyId(com.kcs.genxml.beans.frw.MV0072.fromValue(main.getCurrCode()));
                contentRecordGroup.setCommissionInLieuRateForDeposit(main.getCommInLieuRateForDepsit());
                contentRecordGroup.setMinCommissionInLieuForDeposit(main.getMinCommInLieuForDepsit());
                contentRecordGroup.setMaxCommissionInLieuForDeposit(main.getMaxCommInLieuForDepsit());
                contentRecordGroup.setInwardsTransferFeeForDeposit(main.getInwTransfFeeForDepsit());
                contentRecordGroup.setMinInwardsTransferFeeForDeposit(main.getMinInwTransfFeeForDepsit());
                contentRecordGroup.setMaxInwardsTransferFeeForDeposit(main.getMaxInwTransfFeeForDepsit());
                contentRecordGroup.setOtherFeeDescriptionForDeposit(main.getOthFeeDescForDepsit());
                contentRecordGroup.setCommissionInLieuRateForWithdrawal(main.getCommInLieuRateForWithdw());
                contentRecordGroup.setMinCommissionInLieuForWithdrawal(main.getMinCommInLieuRateFWithdw());
                contentRecordGroup.setMaxCommissionInLieuForWithdrawal(main.getMaxCommInLieuRateFWithdw());
                contentRecordGroup.setWithdrawalFeeForOtherTransfer(main.getWithdwFeeForOthTransf());
                contentRecordGroup.setEffectiveDate(getXmlDateFormatString(main.getEffectiveDate()));
                contentRecordGroup.setEndDate(getXmlDateFormatString(main.getEndDate()));
                dSFRWContent.getContentRecordGroup().add(contentRecordGroup);
            }
            dsFrw.setCommonHeader(dataSetCommonHeader);
            dsFrw.setDSFRWHeader(dSFRWHeader);
            dsFrw.setDSFRWContent(dSFRWContent);

            return generateToBytes(dsFrw);
        } catch (Exception e) {
            e.printStackTrace();
            throw e;
        }
    }
    // </editor-fold>

    // <editor-fold defaultstate="collapsed" desc="irf">
    @Override
    public byte[] generateXmlIrf(String dataSetDate, String tmpTcb) throws Exception {
        try {
            List<Datasetirf> mainList = irfDao.findMainList(dataSetDate, tmpTcb);
            if (CollectionUtil.isEmpty(mainList)) {
                logger.error("not found irf main list");
                return new byte[0];
            }

            List<Datasetirf> childList = irfDao.findChildList(dataSetDate, tmpTcb);

            Datasetirf o = mainList.get(0);

            DSIRF dsIrf = irfOf.createDSIRF();

            HeadGenXMLControl head = headDao.getHeadGenXMLControlByDatasetCode("DS_IRF");
            if (head != null) {
                dsIrf.setName(head.getAttributesName());
                dsIrf.setType(head.getAttributesType());
                dsIrf.setSchemaVersion(head.getAttributesSchemaVersion());
            }

            com.kcs.genxml.beans.irf.DataSetCommonHeader dataSetCommonHeader = irfOf.createDataSetCommonHeader();
            dataSetCommonHeader.setDataSetDate(getXMLGregorianCalendarDate(o.getDataSetDate()));
            dataSetCommonHeader.setOrganizationId(o.getOrgId());

            DSIRF.DSIRFHeader dSIRFHeader = irfOf.createDSIRFDSIRFHeader();

            DSIRF.DSIRFContent dSFRWContent = irfOf.createDSIRFDSIRFContent();
            for (Datasetirf main : mainList) {
                nullToEmptyString(main);
                List<Datasetirf> subChildList = filterRepeatChild(main, childList);

                DSIRF.DSIRFContent.ContentRecordGroup contentRecordGroup = irfOf
                        .createDSIRFDSIRFContentContentRecordGroup();
                contentRecordGroup.setArrangementType(main.getArrgmentTye());
                contentRecordGroup.setInvolvedPartyType(main.getInvPartyTye());
                contentRecordGroup.setCurrencyId(com.kcs.genxml.beans.irf.MV0072.fromValue(main.getCurrCode()));
                contentRecordGroup.setDepositTerm(getXmlLongString(main.getDepsitTerm()));
                contentRecordGroup.setDepositTermUnit(main.getDepsitTermUnt());

                DSIRF.DSIRFContent.ContentRecordGroup.DataGroupInfo dataGroupInfo = irfOf
                        .createDSIRFDSIRFContentContentRecordGroupDataGroupInfo();
                if (StringUtil.isNotEmpty(main.getBalTierAmt())) {
                    DSIRF.DSIRFContent.ContentRecordGroup.DataGroupInfo.DataGroupDetails detail = irfOf
                            .createDSIRFDSIRFContentContentRecordGroupDataGroupInfoDataGroupDetails();
                    detail.setBalanceTierAmount(main.getBalTierAmt());
                    detail.setInterestRate(getXmlString(main.getInterestRate()));
                    dataGroupInfo.getDataGroupDetails().add(detail);
                }
                if (CollectionUtil.isNotEmpty(subChildList)) {
                    for (Datasetirf child : subChildList) {
                        DSIRF.DSIRFContent.ContentRecordGroup.DataGroupInfo.DataGroupDetails detail = irfOf
                                .createDSIRFDSIRFContentContentRecordGroupDataGroupInfoDataGroupDetails();
                        detail.setBalanceTierAmount(child.getBalTierAmt());
                        detail.setInterestRate(getXmlString(child.getInterestRate()));
                        dataGroupInfo.getDataGroupDetails().add(detail);
                    }
                }

                contentRecordGroup.setDataGroupInfo(dataGroupInfo);
                contentRecordGroup.setEffectiveDate(getXmlDateFormatString(main.getEffectiveDate()));
                contentRecordGroup.setEndDate(getXmlDateFormatString(main.getEndDate()));
                dSFRWContent.getContentRecordGroup().add(contentRecordGroup);
            }
            dsIrf.setCommonHeader(dataSetCommonHeader);
            dsIrf.setDSIRFHeader(dSIRFHeader);
            dsIrf.setDSIRFContent(dSFRWContent);

            return generateToBytes(dsIrf);
        } catch (Exception e) {
            e.printStackTrace();
            throw e;
        }
    }

    private List<Datasetirf> filterRepeatChild(final Datasetirf main, List<Datasetirf> childList) {
        List<Datasetirf> result = new ArrayList<Datasetirf>();
        final Predicate childRepeatPredicate = new Predicate() {
            @Override
            public boolean evaluate(Object o) {
                if (Utility.isNotNull(o)) {
                    Datasetirf child = (Datasetirf) o;
                    boolean result = (main.getArrgmentTye().equals(child.getArrgmentTye())
                            && main.getInvPartyTye().equals(child.getInvPartyTye())
                            && main.getCurrCode().equals(child.getCurrCode())
                            && main.getDepsitTerm().equals(child.getDepsitTerm())
                            && main.getDepsitTermUnt().equals(child.getDepsitTermUnt())
                            && main.getEffectiveDate().equals(child.getEffectiveDate())
                            && objEquals(main.getEndDate(), child.getEndDate()));
                    return result;
                }
                return false;
            }
        };
        result = (List<Datasetirf>) CollectionUtils.select(childList, childRepeatPredicate);
        return result;
    }
    // </editor-fold>

    // <editor-fold defaultstate="collapsed" desc="off">
    @Override
    public byte[] generateXmlOff(String dataSetDate, String tmpTcb) throws Exception {
        try {
            List<Datasetoff> mainList = offDao.findMainList(dataSetDate, tmpTcb);
            if (CollectionUtil.isEmpty(mainList)) {
                logger.error("not found off main list");
                return new byte[0];
            }

            Datasetoff o = mainList.get(0);

            DSOFF dsoff = offOf.createDSOFF();
            HeadGenXMLControl head = headDao.getHeadGenXMLControlByDatasetCode("DS_OFF");
            if (head != null) {
                dsoff.setName(head.getAttributesName());
                dsoff.setType(head.getAttributesType());
                dsoff.setSchemaVersion(head.getAttributesSchemaVersion());
            }

            com.kcs.genxml.beans.off.DataSetCommonHeader dataSetCommonHeader = offOf.createDataSetCommonHeader();
            dataSetCommonHeader.setDataSetDate(getXMLGregorianCalendarDate(o.getDataSetDate()));
            dataSetCommonHeader.setOrganizationId(o.getOrgId());

            DSOFF.DSOFFHeader dSOFFHeader = offOf.createDSOFFDSOFFHeader();

            DSOFF.DSOFFContent content = offOf.createDSOFFDSOFFContent();
            for (Datasetoff main : mainList) {
                nullToEmptyString(main);
                DSOFF.DSOFFContent.ContentRecordGroup contentRecordGroup = offOf
                        .createDSOFFDSOFFContentContentRecordGroup();
                contentRecordGroup.setArrangementType(main.getArrgmentTye());
                contentRecordGroup.setCurrencyId(com.kcs.genxml.beans.off.MV0072.fromValue(main.getCurrCode()));
                contentRecordGroup.setMinimumOpenAccountAmount(main.getMinimOpenAcctAmt());
                contentRecordGroup.setMinimumBalanceForMaintenanceFee(main.getMinimBalForMaintenanceFee());
                contentRecordGroup.setMaintenanceFee(main.getMaintenanceFee());
                contentRecordGroup.setInactiveTerm(getXmlString(main.getInactiveTerm()));
                contentRecordGroup.setInactiveTermUnit(main.getInactiveTermUnt());
                contentRecordGroup.setInactiveFee(main.getInactiveFee());
                contentRecordGroup.setEffectiveDate(getXmlDateFormatString(main.getEffectiveDate()));
                contentRecordGroup.setEndDate(getXmlDateFormatString(main.getEndDate()));
                content.getContentRecordGroup().add(contentRecordGroup);
            }
            dsoff.setCommonHeader(dataSetCommonHeader);
            dsoff.setDSOFFHeader(dSOFFHeader);
            dsoff.setDSOFFContent(content);

            return generateToBytes(dsoff);
        } catch (Exception ex) {
            ex.printStackTrace();
            throw ex;
        }
    }
    //</editor-fold>

    // <editor-fold defaultstate="collapsed" desc="fxp">
    public byte[] generateXmlFxp(String dataSetDate, String tmpTcb) throws Exception {
        try {
            List<DatasetFxpBal> mainList = fxpDao.findMainList(dataSetDate, tmpTcb);
            if (CollectionUtil.isEmpty(mainList)) {
                logger.error("not found fxp main list");
                return new byte[0];
            }

            DatasetFxpBal o = mainList.get(0);
            DFFXP dffxp = fxpOf.createDFFXP();
            HeadGenXMLControl head = headDao.getHeadGenXMLControlByDatasetCode("DF_FXP");
            if (head != null) {
                dffxp.setName(head.getAttributesName());
                dffxp.setType(head.getAttributesType());
                dffxp.setSchemaVersion(head.getAttributesSchemaVersion());
            }

            com.kcs.genxml.beans.fxp.DataSetCommonHeader dataSetCommonHeader = fxpOf.createDataSetCommonHeader();
            dataSetCommonHeader.setDataSetDate(getXMLGregorianCalendarDate(o.getDataSetDate()));
            dataSetCommonHeader.setOrganizationId(o.getOrgId());

            DFFXP.DFFXPHeader dFFXPHeader = fxpOf.createDFFXPDFFXPHeader();

            DFFXP.DFFXPContent content = fxpOf.createDFFXPDFFXPContent();
            NumberFormat nf = NumberFormat.getInstance();
            nf.setMinimumFractionDigits(2);
            for (DatasetFxpBal main : mainList) {
                nullToEmptyString(main);
                DFFXP.DFFXPContent.ContentRecordGroup contentRecordGroup = fxpOf
                        .createDFFXPDFFXPContentContentRecordGroup();
                contentRecordGroup.setBeginningBalance(nf.format(main.getBeginningBalance()));
                contentRecordGroup.setNewBuyContractAmount(nf.format(main.getNewBuyContractAmt()));
                contentRecordGroup.setNewSellContractAmount(nf.format(main.getNewSellContractAmt()));
                contentRecordGroup.setNetChangeInContractAmount(nf.format(main.getNetChgInContractAmt()));
                contentRecordGroup.setErrorTransaction(nf.format(main.getErrorTransaction()));
                contentRecordGroup.setOtherTransaction(nf.format(main.getOtherTransaction()));
                contentRecordGroup.setOptionNotionalAmount(nf.format(main.getOptionNotionalAmt()));
                contentRecordGroup.setOptionDeltaAmount(nf.format(main.getOptionDeltaAmt()));
                contentRecordGroup.setCashPositionAmount(nf.format(main.getCashPositionAmt()));

                content.getContentRecordGroup().add(contentRecordGroup);
            }
            dffxp.setCommonHeader(dataSetCommonHeader);
            dffxp.setDFFXPHeader(dFFXPHeader);
            dffxp.setDFFXPContent(content);

            return generateToBytes(dffxp);
        } catch (Exception e) {
            e.printStackTrace();
            throw e;
        }
    }
    // </editor-fold>

    // <editor-fold defaultstate="collapsed" desc="fxu">
    @Override
    public byte[] generateXmlFxu(String dataSetDate, String tmpTcb) throws Exception {
        try {
            List<DfFxu> mainList = fxuDao.findMainList(dataSetDate, tmpTcb);
            if (CollectionUtil.isEmpty(mainList)) {
                logger.error("not found fxp main list");
                return new byte[0];
            }
            DfFxu o = mainList.get(0);
            DFFXU dffxu = fxuOf.createDFFXU();
            HeadGenXMLControl head = headDao.getHeadGenXMLControlByDatasetCode("DF_FXU");
            if (head != null) {
                dffxu.setName(head.getAttributesName());
                dffxu.setType(head.getAttributesType());
                dffxu.setSchemaVersion(head.getAttributesSchemaVersion());
            }

            com.kcs.genxml.beans.fxu.DataSetCommonHeader dataSetCommonHeader = fxuOf.createDataSetCommonHeader();
            dataSetCommonHeader.setDataSetDate(getXMLGregorianCalendarDate(o.getDataSetDate()));
            dataSetCommonHeader.setOrganizationId(o.getOrgId());

            DFFXU.DFFXUHeader dFFXUHeader = fxuOf.createDFFXUDFFXUHeader();

            DFFXU.DFFXUContent content = fxuOf.createDFFXUDFFXUContent();
            NumberFormat nf = NumberFormat.getInstance();
            nf.setMinimumFractionDigits(2);

            for (DfFxu main : mainList) {
                nullToEmptyString(main);
                DFFXU.DFFXUContent.ContentRecordGroup contentRecordGroup = fxuOf
                        .createDFFXUDFFXUContentContentRecordGroup();
                contentRecordGroup.setArrangementType(main.getArrgmtType());
                contentRecordGroup.setLegType(main.getLegType());
                contentRecordGroup.setUsdEquivalentAmount(nf.format(main.getUsdEquivlntAmt()));

                content.getContentRecordGroup().add(contentRecordGroup);
            }

            dffxu.setCommonHeader(dataSetCommonHeader);
            dffxu.setDFFXUHeader(dFFXUHeader);
            dffxu.setDFFXUContent(content);

            return generateToBytes(dffxu);
        } catch (Exception e) {
            e.printStackTrace();
            throw e;
        }
    }
    // </editor-fold>

    // <editor-fold defaultstate="collapsed" desc="fxm">
    public byte[] generateXmlFxm(String dataSetDate, String tmpTcb) throws Exception {
        try {
            List<DfFxm> mainList = fxmDao.findMainList(dataSetDate, tmpTcb);
            if (CollectionUtil.isEmpty(mainList)) {
                logger.error("not found fxm main list");
                return new byte[0];
            }
            List<DfFxm> childList = fxmDao.findChildList(dataSetDate);
            DfFxm o = mainList.get(0);
            DFFXM dffxm = fxmOf.createDFFXM();
            HeadGenXMLControl head = headDao.getHeadGenXMLControlByDatasetCode("DF_FXU");
            if (head != null) {
                dffxm.setName(head.getAttributesName());
                dffxm.setType(head.getAttributesType());
                dffxm.setSchemaVersion(head.getAttributesSchemaVersion());
            }

            com.kcs.genxml.beans.fxm.DataSetCommonHeader dataSetCommonHeader = fxmOf.createDataSetCommonHeader();
            dataSetCommonHeader.setDataSetDate(getXMLGregorianCalendarDate(o.getDataSetDate()));
            dataSetCommonHeader.setOrganizationId(o.getOrgId());

            DFFXM.DFFXMHeader dFFXMHeader = fxmOf.createDFFXMDFFXMHeader();

            DFFXM.DFFXMContent content = fxmOf.createDFFXMDFFXMContent();

            NumberFormat nf1 = NumberFormat.getInstance();
            nf1.setMinimumFractionDigits(2);

            NumberFormat excRateNf = NumberFormat.getInstance();
            excRateNf.setMinimumFractionDigits(7);

            for (DfFxm main : mainList) {
                nullToEmptyString(main);
                DFFXM.DFFXMContent.ContentRecordGroup contentRecordGroup = fxmOf
                        .createDFFXMDFFXMContentContentRecordGroup();
                contentRecordGroup.setTradeDate(getXmlDateFormatString(main.getTradeDate()));
                contentRecordGroup.setCounterPartyName(main.getCounterPtyName());
                contentRecordGroup.setCounterPartyId(main.getCounterPtyId());
                contentRecordGroup.setCounterPartyUniqueIdType(main.getCounterPtyUniqIdType());
                contentRecordGroup.setCounterPartyType(main.getCounterPtyType());
                contentRecordGroup.setFiArrangementNumber(main.getFiArrgmtNumber());
                contentRecordGroup.setArrangementType(main.getArrgmtType());
                contentRecordGroup.setLegType(main.getLegType());
                contentRecordGroup.setCurrencyCode(com.kcs.genxml.beans.fxm.MV0072.fromValue(main.getCurrCode()));
                contentRecordGroup.setStartDate(getXMLGregorianCalendarDate(main.getStartDate()));
                contentRecordGroup.setMaturityDate(getXMLGregorianCalendarDate(main.getMaturityDate()));

                logger.debug("excRate1 : " + main.getExcRate1());
                logger.debug("excRate2 : " + main.getExcRate2());

                String tmpExcRate1 = ((BigDecimal.ZERO.equals(main.getExcRate1()) || main.getExcRate1() == null)
                        ? ""
                        : excRateNf.format(main.getExcRate1()));
                String tmpExcRate2 = ((BigDecimal.ZERO.equals(main.getExcRate2()) || main.getExcRate2() == null)
                        ? ""
                        : excRateNf.format(main.getExcRate2()));

                contentRecordGroup.setExchangeRate1(tmpExcRate1);
                contentRecordGroup.setExchangeRate2(tmpExcRate2);
                contentRecordGroup.setUsdEquivalentAmount(nf1.format(main.getUsdEquivlntAmt()));
                contentRecordGroup
                        .setOptionDeltaUsdEquivalentAmount(getXmlString(main.getOptDeltaUsdEquivlntAmt()));
                contentRecordGroup.setTransactionPurposeCode(main.getTransPurposeCode());
                contentRecordGroup.setPurposeRemarks(main.getPurposeRemarks());

                DFFXM.DFFXMContent.ContentRecordGroup.RelatedFiGroupInfo relatedFiGroupInfo = fxmOf
                        .createDFFXMDFFXMContentContentRecordGroupRelatedFiGroupInfo();
                List<DfFxm> subChildList = filterRelateFiGroupInfoChild(main, childList);
                for (DfFxm child : subChildList) {
                    DFFXM.DFFXMContent.ContentRecordGroup.RelatedFiGroupInfo.RelatedFiGroupDetails detail = fxmOf
                            .createDFFXMDFFXMContentContentRecordGroupRelatedFiGroupInfoRelatedFiGroupDetails();
                    detail.setRelatedFiArrangementNumber(child.getRelatedFiArrgmNumber());
                    relatedFiGroupInfo.getRelatedFiGroupDetails().add(detail);
                }

                contentRecordGroup.setRelatedFiGroupInfo(relatedFiGroupInfo);
                contentRecordGroup.setArrangementRemarks(main.getArrgmtRemarks());

                content.getContentRecordGroup().add(contentRecordGroup);
            }
            dffxm.setCommonHeader(dataSetCommonHeader);
            dffxm.setDFFXMHeader(dFFXMHeader);
            dffxm.setDFFXMContent(content);

            return generateToBytes(dffxm);
        } catch (Exception e) {
            e.printStackTrace();
            throw e;
        }
    }

    private List<DfFxm> filterRelateFiGroupInfoChild(final DfFxm main, List<DfFxm> childList) {
        List<DfFxm> result = new ArrayList<DfFxm>();
        final Predicate childRepeatPredicate = new Predicate() {
            @Override
            public boolean evaluate(Object o) {
                if (Utility.isNotNull(o)) {
                    DfFxm child = (DfFxm) o;
                    boolean result = (objEquals(main.getCustomerCode(), child.getCustomerCode())
                            && objEquals(main.getSeq(), child.getSeq()));
                    return result;
                }
                return false;
            }
        };
        result = (List<DfFxm>) CollectionUtils.select(childList, childRepeatPredicate);
        return result;
    }
    // </editor-fold>

    // <editor-fold defaultstate="collapsed" desc="olb">
    @Override
    public byte[] generateXmlOlb(String dataSetDate, String tmpTcb) throws Exception {
        try {
            List<DfOlb> mainList = olbDao.findMainList(dataSetDate, tmpTcb);
            if (CollectionUtil.isEmpty(mainList)) {
                logger.error("not found olb main list");
                return new byte[0];
            }
            List<DfOlb> childList = olbDao.findChildList(dataSetDate, tmpTcb);

            DfOlb o = mainList.get(0);

            DSOLB dsolb = olbOf.createDSOLB();
            HeadGenXMLControl head = headDao.getHeadGenXMLControlByDatasetCode("DS_OLB");
            if (head != null) {
                dsolb.setName(head.getAttributesName());
                dsolb.setType(head.getAttributesType());
                dsolb.setSchemaVersion(head.getAttributesSchemaVersion());
            }

            com.kcs.genxml.beans.olb.DataSetCommonHeader dataSetCommonHeader = olbOf.createDataSetCommonHeader();
            dataSetCommonHeader.setDataSetDate(getXMLGregorianCalendarDate(o.getDataSetDate()));
            dataSetCommonHeader.setOrganizationId(o.getOrgId());

            DSOLB.DSOLBHeader dSOLBHeader = olbOf.createDSOLBDSOLBHeader();

            DSOLB.DSOLBContent content = olbOf.createDSOLBDSOLBContent();

            NumberFormat nf = NumberFormat.getInstance();
            nf.setMinimumFractionDigits(2);

            for (DfOlb main : mainList) {
                nullToEmptyString(main);
                DSOLB.DSOLBContent.ContentRecordGroup contentRecordGroup = olbOf
                        .createDSOLBDSOLBContentContentRecordGroup();
                contentRecordGroup.setFiArrangementNumber(main.getFiArrgNo());
                contentRecordGroup
                        .setArrangementContractDate(getXMLGregorianCalendarDate(main.getArrgContractDate()));
                contentRecordGroup.setEffectiveDate(getXMLGregorianCalendarDate(main.getEffectiveDate()));
                contentRecordGroup.setMaturityDate(getXMLGregorianCalendarDate(main.getMaturityDate()));
                contentRecordGroup.setPrimaryInvolvedPartyId(main.getPrimaryInvPartyId());
                contentRecordGroup.setPrimaryInvolvedPartyUniqueIdType(main.getPrimaryInvPartyUniqIdType());
                contentRecordGroup.setPrimaryInvolvedPartyName(main.getPrimaryInvPartyName());
                contentRecordGroup.setPrimaryInvolvedPartyType(main.getPrimaryInvPartyType());
                contentRecordGroup
                        .setCountryOfNonresident(com.kcs.genxml.beans.olb.MV0260.fromValue(main.getCountryOfNr()));
                contentRecordGroup.setArrangementType(main.getArrgType());

                DSOLB.DSOLBContent.ContentRecordGroup.RelatedFiGroupInfo relatedFiGroupInfo = olbOf
                        .createDSOLBDSOLBContentContentRecordGroupRelatedFiGroupInfo();
                List<DfOlb> subChildList = filterRelateFiGroupInfoOlbChild(main, childList);
                for (DfOlb subChild : subChildList) {
                    DSOLB.DSOLBContent.ContentRecordGroup.RelatedFiGroupInfo.RelatedFiGroupDetails detail = olbOf
                            .createDSOLBDSOLBContentContentRecordGroupRelatedFiGroupInfoRelatedFiGroupDetails();
                    detail.setRelatedFiArrangementNumber(subChild.getRelatedFiArrgNo());
                    relatedFiGroupInfo.getRelatedFiGroupDetails().add(detail);
                }
                contentRecordGroup.setRelatedFiGroupInfo(relatedFiGroupInfo);

                contentRecordGroup.setCustomerInvestmentType(main.getCustInvestmentType());
                contentRecordGroup.setInvestmentDescription(main.getInvestmentDesc());
                contentRecordGroup.setFxArrangementType(main.getFxArrgType());
                contentRecordGroup.setFxArrangementDescription(main.getFxArrgDesc());
                contentRecordGroup.setIndexInvolvementType(main.getIndexInvolType());
                contentRecordGroup.setLegType(main.getLegType());
                contentRecordGroup.setPaymentInterestRateType(main.getPaymentIntRateType());
                contentRecordGroup.setReceivedInterestRateType(main.getReceivedIntRateType());
                contentRecordGroup.setCurrencyId(com.kcs.genxml.beans.olb.MV0272.fromValue(main.getCurrId()));
                contentRecordGroup.setThbOutstandingAmount(
                        (main.getThbOutsAmt() == null ? "0.00" : nf.format(main.getThbOutsAmt())));
                contentRecordGroup.setInvestorType(main.getInvestorType());
                contentRecordGroup.setUnderlyingCurrencyId(main.getUndlyingCurrId());
                contentRecordGroup.setUnderlyingPurposeType(main.getUndlyingPurposeType());
                contentRecordGroup.setUnderlyingCustomerInvestmentType(main.getUndlyingCustInvestmentType());
                contentRecordGroup.setUnderlyingPurposeDescription(main.getUndlyingPurposeDesc());
                contentRecordGroup.setUnderlyingLocalCompanyName(main.getUndlyingLocalCompName());
                contentRecordGroup.setNameOfNrBeneficiary(main.getNameOfNrBeneficiary());

                content.getContentRecordGroup().add(contentRecordGroup);
            }
            dsolb.setCommonHeader(dataSetCommonHeader);
            dsolb.setDSOLBHeader(dSOLBHeader);
            dsolb.setDSOLBContent(content);

            return generateToBytes(dsolb);
        } catch (Exception e) {
            e.printStackTrace();
            throw e;
        }
    }

    private List<DfOlb> filterRelateFiGroupInfoOlbChild(final DfOlb main, List<DfOlb> childList) {
        List<DfOlb> result = new ArrayList<DfOlb>();
        final Predicate childRepeatPredicate = new Predicate() {
            @Override
            public boolean evaluate(Object o) {
                if (Utility.isNotNull(o)) {
                    DfOlb child = (DfOlb) o;
                    boolean result = (objEquals(main.getCustCode(), child.getCustCode())
                            && objEquals(main.getSeq(), child.getSeq()));
                    return result;
                }
                return false;
            }
        };
        result = (List<DfOlb>) CollectionUtils.select(childList, childRepeatPredicate);
        return result;
    }
    // </editor-fold>

    // <editor-fold defaultstate="collapsed" desc="slb">
    @Override
    public byte[] generateXmlSlb(String dataSetDate, String tmpTcb) throws Exception {
        List<DfSlb> mainList = slbDao.findMainList(dataSetDate, tmpTcb);
        if (CollectionUtil.isEmpty(mainList)) {
            logger.error("not found slb main list");
            return new byte[0];
        }

        DfSlb o = mainList.get(0);

        DSSLB dsslb = slbOf.createDSSLB();

        HeadGenXMLControl head = headDao.getHeadGenXMLControlByDatasetCode("DS_SLB");
        if (head != null) {
            dsslb.setName(head.getAttributesName());
            dsslb.setType(head.getAttributesType());
            dsslb.setSchemaVersion(head.getAttributesSchemaVersion());
        }

        com.kcs.genxml.beans.slb.DataSetCommonHeader dataSetCommonHeader = slbOf.createDataSetCommonHeader();
        dataSetCommonHeader.setDataSetDate(getXMLGregorianCalendarDate(o.getDataSetDate()));
        dataSetCommonHeader.setOrganizationId(o.getOrgId());

        DSSLB.DSSLBHeader dSSLBHeader = slbOf.createDSSLBDSSLBHeader();

        DSSLB.DSSLBContent content = slbOf.createDSSLBDSSLBContent();

        NumberFormat nf = NumberFormat.getInstance();
        nf.setMinimumFractionDigits(2);

        for (DfSlb main : mainList) {
            nullToEmptyString(main);
            DSSLB.DSSLBContent.ContentRecordGroup contentRecordGroup = slbOf
                    .createDSSLBDSSLBContentContentRecordGroup();
            contentRecordGroup.setArrangementType(main.getArrgType());
            contentRecordGroup.setFxArrangementType(main.getFxArrgType());
            contentRecordGroup.setNumberOfTransaction(getXmlString(main.getNumberOfTransaction()));
            contentRecordGroup.setThbOutstandingAmount(nf.format(main.getThbOutstandingAmt()));

            content.getContentRecordGroup().add(contentRecordGroup);
        }
        dsslb.setCommonHeader(dataSetCommonHeader);
        dsslb.setDSSLBHeader(dSSLBHeader);
        dsslb.setDSSLBContent(content);

        return generateToBytes(dsslb);

    }
    // </editor-fold>

    // <editor-fold defaultstate="collapsed" desc="fcr">
    public byte[] generateXmlFcr(String dataSetDate, String tmpTcb) throws Exception {
        try {
            List<DfFcr> mainList = fcrDao.findMainRoundNumberList(dataSetDate, tmpTcb);
            if (CollectionUtil.isEmpty(mainList)) {
                logger.error("not found slb main list");
                return new byte[0];
            }

            DfFcr o = mainList.get(0);

            DSFCR dsfcr = fcrOf.createDSFCR();

            HeadGenXMLControl head = headDao.getHeadGenXMLControlByDatasetCode("DS_FCR");
            if (head != null) {
                dsfcr.setName(head.getAttributesName());
                dsfcr.setType(head.getAttributesType());
                dsfcr.setSchemaVersion(head.getAttributesSchemaVersion());
            }

            com.kcs.genxml.beans.fcr.DataSetCommonHeader dataSetCommonHeader = fcrOf.createDataSetCommonHeader();
            dataSetCommonHeader.setDataSetDate(getXMLGregorianCalendarDate(o.getDataSetDate()));
            dataSetCommonHeader.setOrganizationId(o.getOrgId());

            DSFCR.DSFCRHeader dSFCRHeader = fcrOf.createDSFCRDSFCRHeader();

            DSFCR.DSFCRContent dSFCRContent = fcrOf.createDSFCRDSFCRContent();

            NumberFormat nf = NumberFormat.getInstance();
            String currencyArr[] = { "AUD", "BND", "CAD", "CHF", "CNY", "DKK", "EUR", "GBP", "HKD", "IDR", "INR",
                    "JPY", "MYR", "NOK", "NZD", "PHP", "PKR", "SEK", "SGD", "USD" };
            nf.setMinimumFractionDigits(7);
            for (DfFcr main : mainList) {
                List<DfFcr> childList = fcrDao.findChildList(main.getDataSetDate(), main.getRoundNumber(), tmpTcb);
                DSFCR.DSFCRContent.ContentRecordGroup contentRecordGroup = fcrOf
                        .createDSFCRDSFCRContentContentRecordGroup();
                contentRecordGroup.setRoundNumber(getXmlLongString(main.getRoundNumber()));

                for (String curr : currencyArr) {
                    DfFcr child = getChildByCurrencyId(curr, childList);
                    String createMethodName = "createDSFCRDSFCRContentContentRecordGroupCurrencyID" + curr;
                    Method createMethod = fcrOf.getClass().getMethod(createMethodName);
                    Object obj = createMethod.invoke(fcrOf);

                    Method setSellingRate = obj.getClass().getMethod("setSellingRate", String.class);
                    Method setSightBillRate = obj.getClass().getMethod("setSightBillRate", String.class);
                    Method setTtRate = obj.getClass().getMethod("setTtRate", String.class);

                    setSellingRate.invoke(obj, nf.format(child.getSellingRate()));
                    setSightBillRate.invoke(obj, nf.format(child.getSightBillRate()));
                    setTtRate.invoke(obj, nf.format(child.getTtRate()));

                    String setCurrencyMethodName = "setCurrencyID" + curr;
                    Method setCurrencyMethod = contentRecordGroup.getClass().getMethod(setCurrencyMethodName,
                            obj.getClass());
                    setCurrencyMethod.invoke(contentRecordGroup, obj);
                }
                dSFCRContent.getContentRecordGroup().add(contentRecordGroup);
            }

            dsfcr.setCommonHeader(dataSetCommonHeader);
            dsfcr.setDSFCRHeader(dSFCRHeader);
            dsfcr.setDSFCRContent(dSFCRContent);

            return generateToBytes(dsfcr);
        } catch (Exception e) {
            e.printStackTrace();
            throw e;
        }
    }

    private DfFcr getChildByCurrencyId(String currencyId, List<DfFcr> childList) {
        for (DfFcr dfFcr : childList) {
            if (currencyId.equalsIgnoreCase(dfFcr.getCurrencyId())) {
                return dfFcr;
            }
        }
        return null;
    }
    // </editor-fold>

    // <editor-fold defaultstate="collapsed" desc="iia">
    public byte[] generateXmlIia(String dataSetDate, String tmpTcb) throws Exception {
        try {
            List<DfIia> mainList = iiaDao.findMainList(dataSetDate, tmpTcb);
            if (CollectionUtil.isEmpty(mainList)) {
                logger.error("not found slb main list");
                return new byte[0];
            }

            DfIia o = mainList.get(0);

            DSIIA dsiia = iiaOf.createDSIIA();

            HeadGenXMLControl head = headDao.getHeadGenXMLControlByDatasetCode("DS_IIA");
            if (head != null) {
                dsiia.setName(head.getAttributesName());
                dsiia.setType(head.getAttributesType());
                dsiia.setSchemaVersion(head.getAttributesSchemaVersion());
            }

            com.kcs.genxml.beans.iia.DataSetCommonHeader dataSetCommonHeader = iiaOf.createDataSetCommonHeader();
            dataSetCommonHeader.setDataSetDate(getXMLGregorianCalendarDate(o.getDataSetDate()));
            dataSetCommonHeader.setOrganizationId(o.getOrgId());

            DSIIA.DSIIAHeader dSIIAHeader = iiaOf.createDSIIADSIIAHeader();

            DSIIA.DSIIAContent content = iiaOf.createDSIIADSIIAContent();

            NumberFormat nf1 = NumberFormat.getInstance();
            nf1.setMinimumFractionDigits(2);

            NumberFormat nf2 = NumberFormat.getInstance();
            nf2.setMinimumFractionDigits(7);

            for (DfIia main : mainList) {
                nullToEmptyString(main);
                DSIIA.DSIIAContent.ContentRecordGroup contentRecordGroup = iiaOf
                        .createDSIIADSIIAContentContentRecordGroup();
                contentRecordGroup.setArrangementType(main.getArragType());
                contentRecordGroup.setPrimaryInvolvedPartyId(main.getPrimaryInvPartyId());
                contentRecordGroup.setPrimaryInvolvedPartyUniqueIdType(main.getPrimaryInvPartyUniqIdType());
                contentRecordGroup.setTransactionAmount(nf1.format(main.getTransactionAmt()));
                contentRecordGroup.setInterestRate(nf2.format(main.getInterestRate()));
                contentRecordGroup.setTransactionType(main.getTransactionType());
                contentRecordGroup.setTerm(main.getTermUnit());
                contentRecordGroup.setTermUnit(main.getTermUnit());
                contentRecordGroup.setTimeOfAgreement(main.getTimeOfAgreement());
                contentRecordGroup
                        .setArrangementContractDate(getXMLGregorianCalendarDate(main.getArrgContractDate()));
                contentRecordGroup.setEffectiveDate(getXMLGregorianCalendarDate(main.getEffectiveDate()));
                contentRecordGroup.setMaturityDate(getXmlDateFormatString(main.getMaturityDate()));
                contentRecordGroup.setCallFlag(main.getCallFlag());
                contentRecordGroup.setClearingFlag(main.getClearingFlag());
                content.getContentRecordGroup().add(contentRecordGroup);
            }

            dsiia.setCommonHeader(dataSetCommonHeader);
            dsiia.setDSIIAHeader(dSIIAHeader);
            dsiia.setDSIIAContent(content);

            return generateToBytes(dsiia);
        } catch (Exception e) {
            e.printStackTrace();
            throw e;
        }
    }
    // </editor-fold>

    // <editor-fold defaultstate="collapsed" desc="bir">
    public byte[] generateXmlBir(String dataSetDate, String tmpTcb) throws Exception {
        try {
            List<DfBir> mainList = birDao.findMainList(dataSetDate, tmpTcb);
            if (CollectionUtil.isEmpty(mainList)) {
                logger.error("not found slb main list");
                return new byte[0];
            }

            DfBir o = mainList.get(0);

            DSBIR dsbir = birOf.createDSBIR();

            HeadGenXMLControl head = headDao.getHeadGenXMLControlByDatasetCode("DS_BIR");
            if (head != null) {
                dsbir.setName(head.getAttributesName());
                dsbir.setType(head.getAttributesType());
                dsbir.setSchemaVersion(head.getAttributesSchemaVersion());
            }

            com.kcs.genxml.beans.bir.DataSetCommonHeader dataSetCommonHeader = birOf.createDataSetCommonHeader();
            dataSetCommonHeader.setDataSetDate(getXMLGregorianCalendarDate(o.getDataSetDate()));
            dataSetCommonHeader.setOrganizationId(o.getOrgId());

            DSBIR.DSBIRHeader dSBIRHeader = birOf.createDSBIRDSBIRHeader();

            DSBIR.DSBIRContent content = birOf.createDSBIRDSBIRContent();

            NumberFormat nf = NumberFormat.getInstance();
            nf.setMinimumFractionDigits(7);

            for (DfBir main : mainList) {
                nullToEmptyString(main);
                DSBIR.DSBIRContent.ContentRecordGroup contentRecordGroup = birOf
                        .createDSBIRDSBIRContentContentRecordGroup();
                contentRecordGroup.setTermType(main.getTermType());
                contentRecordGroup.setTerm(getXmlLongString(main.getTerm()));
                contentRecordGroup.setTermUnit(main.getTermUnit());
                contentRecordGroup.setInterestRate(nf.format(main.getInterestRate()));
                content.getContentRecordGroup().add(contentRecordGroup);
            }

            dsbir.setCommonHeader(dataSetCommonHeader);
            dsbir.setDSBIRHeader(dSBIRHeader);
            dsbir.setDSBIRContent(content);

            return generateToBytes(dsbir);
        } catch (Exception e) {
            e.printStackTrace();
            throw e;
        }
    }
    // </editor-fold>
}