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

Java tutorial

Introduction

Here is the source code for com.kcs.service.impl.GenerateXmlOtherServiceImpl.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.DarDao;
import com.kcs.dao.DatasetDipDao;
import com.kcs.dao.DatasetEpeDao;
import com.kcs.dao.DatasetIsiDao;
import com.kcs.dao.DatasetOpaDao;
import com.kcs.dao.FraDao;
import com.kcs.dao.FtaDao;
import com.kcs.dao.FxaDao;
import com.kcs.dao.HeadGenXMLControlDao;
import com.kcs.dao.SwaDao;
import com.kcs.genxml.beans.dar.*;
import com.kcs.genxml.beans.opa.*;
import com.kcs.genxml.beans.swa.*;
import com.kcs.genxml.beans.fxa.*;
import com.kcs.genxml.beans.isi.*;
import com.kcs.genxml.beans.fra.*;
import com.kcs.genxml.beans.fta.*;
import com.kcs.genxml.beans.dip.*;
import com.kcs.genxml.beans.epe.*;
import com.kcs.model.Datasetdar;
import com.kcs.model.Datasetdip;
import com.kcs.model.Datasetepe;
import com.kcs.model.Datasetfra;
import com.kcs.model.Datasetfta;
import com.kcs.model.Datasetfxa;
import com.kcs.model.Datasetisi;
import com.kcs.model.Datasetopa;
import com.kcs.model.Datasetswa;
import com.kcs.model.HeadGenXMLControl;
import com.kcs.service.GenerateXmlOtherService;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
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("generateXmlOtherService")
public class GenerateXmlOtherServiceImpl extends Utility implements GenerateXmlOtherService {

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

    // <editor-fold defaultstate="collapsed" desc="ObjectFactory">
    private final com.kcs.genxml.beans.dar.ObjectFactory darOf = new com.kcs.genxml.beans.dar.ObjectFactory();
    private final com.kcs.genxml.beans.opa.ObjectFactory opaOf = new com.kcs.genxml.beans.opa.ObjectFactory();
    private final com.kcs.genxml.beans.swa.ObjectFactory swaOf = new com.kcs.genxml.beans.swa.ObjectFactory();
    private final com.kcs.genxml.beans.fxa.ObjectFactory fxaOf = new com.kcs.genxml.beans.fxa.ObjectFactory();
    private final com.kcs.genxml.beans.isi.ObjectFactory isiOf = new com.kcs.genxml.beans.isi.ObjectFactory();
    private final com.kcs.genxml.beans.fra.ObjectFactory fraOf = new com.kcs.genxml.beans.fra.ObjectFactory();
    private final com.kcs.genxml.beans.fta.ObjectFactory ftaOf = new com.kcs.genxml.beans.fta.ObjectFactory();
    private final com.kcs.genxml.beans.dip.ObjectFactory dipOf = new com.kcs.genxml.beans.dip.ObjectFactory();
    private final com.kcs.genxml.beans.epe.ObjectFactory epeOf = new com.kcs.genxml.beans.epe.ObjectFactory();
    // </editor-fold>

    // <editor-fold defaultstate="collapsed" desc="dao">
    @Autowired
    private HeadGenXMLControlDao headDao;
    @Autowired
    private DarDao darDao;
    @Autowired
    private DatasetOpaDao opaDao;
    @Autowired
    private SwaDao swaDao;
    @Autowired
    private FxaDao fxaDao;
    @Autowired
    private DatasetIsiDao isiDao;
    @Autowired
    private FraDao fraDao;
    @Autowired
    private FtaDao ftaDao;
    @Autowired
    private DatasetDipDao dipDao;
    @Autowired
    private DatasetEpeDao epeDao;
    // </editor-fold>

    // <editor-fold defaultstate="collapsed" desc="dar">
    @Override
    public byte[] generateXmlDar(String dataSetDate, String tcb) throws Exception {
        try {
            List<Datasetdar> darDtoList = darDao.findMainList(dataSetDate, tcb);

            if (Utility.isNull(darDtoList)) {
                logger.error("jaxbElement is null");
                return new byte[0];
            }

            Datasetdar o = darDtoList.get(0);

            com.kcs.genxml.beans.dar.DSDAR dsDar = darOf.createDSDAR();
            com.kcs.genxml.beans.dar.DSDAR.DSDARContent content = darOf.createDSDARDSDARContent();
            DSDAR.DSDARHeader dsDarHeader = darOf.createDSDARDSDARHeader();
            com.kcs.genxml.beans.dar.DataSetCommonHeader dataSetCommonHeader = darOf.createDataSetCommonHeader();

            dsDarHeader.setDataSubmissionPeriod(o.getDataSubPrd());
            dataSetCommonHeader.setDataSetDate(getXMLGregorianCalendarDate(o.getDataSetDate()));
            dataSetCommonHeader.setOrganizationId(o.getOrgId());

            dsDar.setCommonHeader(dataSetCommonHeader);
            dsDar.setDSDARHeader(dsDarHeader);

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

            for (Datasetdar darDto : darDtoList) {
                nullToEmptyString(darDto);
                com.kcs.genxml.beans.dar.DSDAR.DSDARContent.ContentRecordGroup contentRecordGroup = darOf
                        .createDSDARDSDARContentContentRecordGroup();

                contentRecordGroup.setFiArrangementNumber(darDto.getFiArrgNo());
                contentRecordGroup.setDepositAccountType(darDto.getDepositAccType());
                contentRecordGroup.setDepositType(darDto.getDepType());
                contentRecordGroup.setObjectiveType(darDto.getObjectiveType());
                contentRecordGroup.setPrimaryInvolvedPartyId(darDto.getPriIpId());
                contentRecordGroup.setPrimaryInvolvedPartyUniqueIdType(darDto.getPriIpIdType());
                contentRecordGroup.setPrimaryInvolvedPartyIbfIndicator(darDto.getPriIpIbfInd());
                contentRecordGroup.setArrangementContractDate(getXMLGregorianCalendarDate(darDto.getArrgCtrDate()));
                contentRecordGroup.setArrangementTerm(getXmlString(darDto.getArrgTerm()));
                contentRecordGroup.setArrangementTermUnit(darDto.getArrgTermUnit());
                contentRecordGroup.setArrangementName(darDto.getArrgName());
                contentRecordGroup.setDescription(darDto.getDescpt());
                contentRecordGroup
                        .setContractCurrencyId(com.kcs.genxml.beans.dar.MV0053.fromValue(darDto.getCtrCurr()));
                contentRecordGroup.setInterestRate(getXmlString(darDto.getIntRate()));
                contentRecordGroup.setInterestRateMargin(getXmlString(darDto.getIntRateMgrn()));
                contentRecordGroup.setInterestRateType(darDto.getIntRateType());
                contentRecordGroup.setPrimaryInvolvedPartyBranchNumber(darDto.getPriIpBrcNo());

                com.kcs.genxml.beans.dar.DSDAR.DSDARContent.ContentRecordGroup.RelatedIpGroupInfo relatedIpGroupInfo = darOf
                        .createDSDARDSDARContentContentRecordGroupRelatedIpGroupInfo();
                if (StringUtil.isNotEmpty(darDto.getRltdIpId())) {
                    com.kcs.genxml.beans.dar.DSDAR.DSDARContent.ContentRecordGroup.RelatedIpGroupInfo.RelatedIpGroupDetails relatedIpGroupDetails = darOf
                            .createDSDARDSDARContentContentRecordGroupRelatedIpGroupInfoRelatedIpGroupDetails();

                    relatedIpGroupDetails.setRelatedInvolvedPartyId(darDto.getRltdIpId());
                    relatedIpGroupDetails.setRelatedInvolvedPartyUniqueIdType(darDto.getRltdIpIdType());

                    relatedIpGroupInfo.getRelatedIpGroupDetails().add(relatedIpGroupDetails);
                }

                contentRecordGroup.setRelatedIpGroupInfo(relatedIpGroupInfo);

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

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

    // <editor-fold defaultstate="collapsed" desc="opa">
    @Override
    public byte[] generateXmlOpa(String dataSetDate, String category) throws Exception {
        try {
            List<Datasetopa> mainList = opaDao.findMainList(dataSetDate, category);
            if (CollectionUtil.isEmpty(mainList)) {
                logger.error("main list is empty");
                return new byte[0];
            }
            Datasetopa obj = mainList.get(0);
            DSOPA dsopa = opaOf.createDSOPA();
            HeadGenXMLControl head = headDao.getHeadGenXMLControlByDatasetCode("DS_OPA");
            if (head != null) {
                dsopa.setName(head.getAttributesName());
                dsopa.setType(head.getAttributesType());
                dsopa.setSchemaVersion(head.getAttributesSchemaVersion());
            }

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

            DSOPA.DSOPAHeader dSOPAHeader = opaOf.createDSOPADSOPAHeader();
            dSOPAHeader.setDataSubmissionPeriod(obj.getDataSubPrd());

            DSOPA.DSOPAContent content = opaOf.createDSOPADSOPAContent();
            List<Datasetopa> childApprList = opaDao.findChildAppvList(dataSetDate);
            List<Datasetopa> childBotNumList = opaDao.findChildBotRefList(dataSetDate);

            for (Datasetopa main : mainList) {
                nullToEmptyString(main);
                DSOPA.DSOPAContent.ContentRecordGroup contentRecordGroup = opaOf
                        .createDSOPADSOPAContentContentRecordGroup();
                contentRecordGroup.setFiArrangementNumber(main.getFiArrgNo());
                contentRecordGroup.setOptionsProductType(main.getOptProdType());
                contentRecordGroup.setOptionType(main.getOptType());
                contentRecordGroup.setPrimaryInvolvedPartyId(main.getPriIpId());
                contentRecordGroup.setPrimaryInvolvedPartyUniqueIdType(main.getPriIpIdType());
                contentRecordGroup.setPrimaryInvolvedPartyBranchNumber(main.getPriIpBrcNo());
                contentRecordGroup.setPrimaryInvolvedPartyIbfIndicator(main.getPriIpIbfInd());
                contentRecordGroup.setArrangementContractDate(getXMLGregorianCalendarDate(main.getArrgCtrDate()));
                contentRecordGroup.setExpireDate(getXMLGregorianCalendarDate(main.getExpDate()));
                contentRecordGroup.setObjectiveType(main.getObjectiveType());
                contentRecordGroup.setOptionsPurposeCode(main.getOptPurpCode());
                contentRecordGroup.setOptionsRightType(main.getOptRightType());
                contentRecordGroup.setAuctionType(main.getActType());
                contentRecordGroup.setContractPrice(getXmlString(main.getCtrPrice()));
                contentRecordGroup.setBaseExchangeRate(getXmlString(main.getBaseExcRate()));
                contentRecordGroup.setPremiumAmount(getXmlString(main.getPremAmt()));
                if (BigDecimal.ZERO.equals(main.getNtnAmt())) {
                    contentRecordGroup.setNotionalAmount("");
                } else {
                    contentRecordGroup.setNotionalAmount(getXmlString(main.getNtnAmt()));
                }
                contentRecordGroup.setNotionalCurrencyId(main.getNatCurr());
                contentRecordGroup.setLegType(main.getLegType());
                contentRecordGroup.setBuyCurrencyId(main.getBuyCurr());
                contentRecordGroup.setBuyAmount(getXmlString(main.getBuyAmt()));
                contentRecordGroup.setSellCurrencyId(main.getSellCurr());
                contentRecordGroup.setSellAmount(getXmlString(main.getSellAmt()));

                DSOPA.DSOPAContent.ContentRecordGroup.ApprovalDocumentGroupInfo adgi = opaOf
                        .createDSOPADSOPAContentContentRecordGroupApprovalDocumentGroupInfo();
                List<Datasetopa> subChildList = filterChildOpa(main, childApprList);
                for (Datasetopa child : subChildList) {
                    DSOPA.DSOPAContent.ContentRecordGroup.ApprovalDocumentGroupInfo.ApprovalDocumentGroupDetails details = opaOf
                            .createDSOPADSOPAContentContentRecordGroupApprovalDocumentGroupInfoApprovalDocumentGroupDetails();
                    details.setApprovalDocumentDate(getXMLGregorianCalendarDate(child.getApprovalDocDate()));
                    details.setApprovalDocumentNumber(child.getApprovalDocNum());
                    adgi.getApprovalDocumentGroupDetails().add(details);
                }
                contentRecordGroup.setApprovalDocumentGroupInfo(adgi);

                DSOPA.DSOPAContent.ContentRecordGroup.BotReferenceNumberGroupInfo brngi = opaOf
                        .createDSOPADSOPAContentContentRecordGroupBotReferenceNumberGroupInfo();
                subChildList = filterChildOpa(main, childBotNumList);
                for (Datasetopa child : subChildList) {
                    DSOPA.DSOPAContent.ContentRecordGroup.BotReferenceNumberGroupInfo.BotReferenceNumberGroupDetails details = opaOf
                            .createDSOPADSOPAContentContentRecordGroupBotReferenceNumberGroupInfoBotReferenceNumberGroupDetails();
                    details.setBotReferenceNumber(child.getBotRefNum());
                    brngi.getBotReferenceNumberGroupDetails().add(details);
                }
                contentRecordGroup.setBotReferenceNumberGroupInfo(brngi);

                content.getContentRecordGroup().add(contentRecordGroup);
            }
            dsopa.setCommonHeader(dataSetCommonHeader);
            dsopa.setDSOPAHeader(dSOPAHeader);
            dsopa.setDSOPAContent(content);

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

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

    // <editor-fold defaultstate="collapsed" desc="swa">
    @Override
    public byte[] generateXmlSwa(String dataSetDate, String category) throws Exception {
        try {
            List<Datasetswa> mainList = swaDao.findMainList(dataSetDate, category);
            if (CollectionUtil.isEmpty(mainList)) {
                logger.error("main list is empty");
                return new byte[0];
            }
            Datasetswa obj = mainList.get(0);
            DSSWA dsswa = swaOf.createDSSWA();
            HeadGenXMLControl head = headDao.getHeadGenXMLControlByDatasetCode("DS_SWA");
            if (head != null) {
                dsswa.setName(head.getAttributesName());
                dsswa.setType(head.getAttributesType());
                dsswa.setSchemaVersion(head.getAttributesSchemaVersion());
            }

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

            DSSWA.DSSWAHeader dSSWAHeader = swaOf.createDSSWADSSWAHeader();
            dSSWAHeader.setDataSubmissionPeriod(obj.getDataSubPrd());

            DSSWA.DSSWAContent content = swaOf.createDSSWADSSWAContent();

            List<Datasetswa> childAppvList = swaDao.findChildAppvList(dataSetDate);
            List<Datasetswa> childBotRefList = swaDao.findChildBotRefList(dataSetDate);

            for (Datasetswa main : mainList) {
                nullToEmptyString(main);
                DSSWA.DSSWAContent.ContentRecordGroup contentRecordGroup = swaOf
                        .createDSSWADSSWAContentContentRecordGroup();
                contentRecordGroup.setFiArrangementNumber(main.getFiArrgNo());
                contentRecordGroup.setPrimaryInvolvedPartyId(main.getPriIpIp());
                contentRecordGroup.setPrimaryInvolvedPartyUniqueIdType(main.getPriIpIdType());
                contentRecordGroup.setPrimaryInvolvedPartyBranchNumber(main.getPriIpBrcNo());
                contentRecordGroup.setPrimaryInvolvedPartyIbfIndicator(main.getPriIpIbfInd());
                contentRecordGroup.setCrossCurrencyFlag(main.getCrossCurrFlag());
                contentRecordGroup.setArrangementContractDate(getXMLGregorianCalendarDate(main.getArrgCtrDate()));
                contentRecordGroup.setEffectiveDate(getXMLGregorianCalendarDate(main.getEffDate()));
                contentRecordGroup.setMaturityDate(getXMLGregorianCalendarDate(main.getMatDate()));
                contentRecordGroup.setObjectiveType(main.getObjectiveType());
                contentRecordGroup.setCcirsArrangementPurposeCode(main.getCcrisArrgPurpCode());
                contentRecordGroup.setDescription(main.getDescpt());
                contentRecordGroup.setContractExchangeRate(getXmlString(main.getCtrExcRate()));
                contentRecordGroup.setPrincipalExchangeIndicator(main.getPrinExcInd());
                contentRecordGroup.setPaymentInterestRateType(main.getPymtIntRateType());
                contentRecordGroup.setPaymentInterestRate(getXmlString(main.getPymtIntRate()));
                contentRecordGroup.setPaymentInterestRateMargin(getXmlString(main.getPymtIntRateMrgn()));
                contentRecordGroup.setPaymentInterestTerm(getXmlString(main.getPymtIntTerm()));
                contentRecordGroup.setPaymentInterestTermUnit(main.getPymtIntTermUnit());
                contentRecordGroup.setReceivedInterestCurrencyId(main.getRecvIntCurr());
                contentRecordGroup.setReceivedInterestRateType(main.getRecvIntRateType());
                contentRecordGroup.setReceivedInterestRate(getXmlString(main.getRecvIntRate()));
                contentRecordGroup.setReceivedInterestRateMargin(getXmlString(main.getRecvIntRateMrgn()));
                contentRecordGroup.setReceivedInterestTerm(getXmlString(main.getRecvIntTerm()));
                contentRecordGroup.setReceivedInterestTermUnit(main.getRecvIntTermMrgn());
                contentRecordGroup
                        .setInitialBuyCurrencyId(com.kcs.genxml.beans.swa.MV0053.fromValue(main.getInitBuyCurr()));
                contentRecordGroup.setInitialBuyAmount(getXmlString(main.getInitBuyAmt()));
                contentRecordGroup.setInitialSellCurrencyId(
                        com.kcs.genxml.beans.swa.MV0053.fromValue(main.getInitSellCurr()));
                contentRecordGroup.setInitialSellAmount(getXmlString(main.getInitSellAmt()));
                contentRecordGroup
                        .setFinalBuyCurrencyId(com.kcs.genxml.beans.swa.MV0053.fromValue(main.getFinalBuyCurr()));
                contentRecordGroup.setFinalBuyAmount(getXmlString(main.getFinalBuyAmt()));
                contentRecordGroup
                        .setFinalBuyCurrencyId(com.kcs.genxml.beans.swa.MV0053.fromValue(main.getFinalSellCurr()));
                contentRecordGroup.setFinalSellAmount(getXmlString(main.getFinalSellAmt()));

                DSSWA.DSSWAContent.ContentRecordGroup.ApprovalDocumentGroupInfo adgi = swaOf
                        .createDSSWADSSWAContentContentRecordGroupApprovalDocumentGroupInfo();
                List<Datasetswa> subChildList = filterChildSwa(main, childAppvList);
                for (Datasetswa child : subChildList) {
                    DSSWA.DSSWAContent.ContentRecordGroup.ApprovalDocumentGroupInfo.ApprovalDocumentGroupDetails details = swaOf
                            .createDSSWADSSWAContentContentRecordGroupApprovalDocumentGroupInfoApprovalDocumentGroupDetails();
                    details.setApprovalDocumentDate(getXMLGregorianCalendarDate(child.getApprovalDocDate()));
                    details.setApprovalDocumentNumber(child.getApprovalDocNum());
                    adgi.getApprovalDocumentGroupDetails().add(details);
                }
                contentRecordGroup.setApprovalDocumentGroupInfo(adgi);

                DSSWA.DSSWAContent.ContentRecordGroup.BotReferenceNumberGroupInfo brngi = swaOf
                        .createDSSWADSSWAContentContentRecordGroupBotReferenceNumberGroupInfo();
                subChildList = filterChildSwa(main, childBotRefList);
                for (Datasetswa child : subChildList) {
                    DSSWA.DSSWAContent.ContentRecordGroup.BotReferenceNumberGroupInfo.BotReferenceNumberGroupDetails details = swaOf
                            .createDSSWADSSWAContentContentRecordGroupBotReferenceNumberGroupInfoBotReferenceNumberGroupDetails();
                    details.setBotReferenceNumber(child.getBotRefNum());
                    brngi.getBotReferenceNumberGroupDetails().add(details);
                }
                contentRecordGroup.setBotReferenceNumberGroupInfo(brngi);

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

            dsswa.setCommonHeader(dataSetCommonHeader);
            dsswa.setDSSWAHeader(dSSWAHeader);
            dsswa.setDSSWAContent(content);

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

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

    // <editor-fold defaultstate="collapsed" desc="fxa">
    @Override
    public byte[] generateXmlFxa(String dataSetDate, String category) throws Exception {
        try {
            List<Datasetfxa> mainList = fxaDao.findMainList(dataSetDate, category);
            if (CollectionUtil.isEmpty(mainList)) {
                logger.error("main list is empty");
                return new byte[0];
            }
            Datasetfxa obj = mainList.get(0);
            DSFXA dsfxa = fxaOf.createDSFXA();
            HeadGenXMLControl head = headDao.getHeadGenXMLControlByDatasetCode("DS_FXA");
            if (head != null) {
                dsfxa.setName(head.getAttributesName());
                dsfxa.setType(head.getAttributesType());
                dsfxa.setSchemaVersion(head.getAttributesSchemaVersion());
            }

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

            DSFXA.DSFXAHeader dSFXAHeader = fxaOf.createDSFXADSFXAHeader();
            dSFXAHeader.setDataSubmissionPeriod(obj.getDataSubPrd());

            DSFXA.DSFXAContent content = fxaOf.createDSFXADSFXAContent();

            List<Datasetfxa> childAppvList = fxaDao.findChildAppvList(dataSetDate);
            List<Datasetfxa> childBotRefList = fxaDao.findChildBotRefList(dataSetDate);

            for (Datasetfxa main : mainList) {
                nullToEmptyString(main);
                DSFXA.DSFXAContent.ContentRecordGroup contentRecordGroup = fxaOf
                        .createDSFXADSFXAContentContentRecordGroup();
                contentRecordGroup.setFiArrangementNumber(main.getFiArrgNo());
                contentRecordGroup.setPreviousArrangementNumber(main.getPrevArrgNo());
                contentRecordGroup.setSwapPairArrangementNumber(main.getSwapPairArrgNo());
                contentRecordGroup.setSetUpReasonType(main.getSetReasonType());
                contentRecordGroup.setFxArrangementType(main.getFxArrgNo());
                contentRecordGroup.setPrimaryInvolvedPartyId(main.getPriIpId());
                contentRecordGroup.setPrimaryInvolvedPartyUniqueIdType(main.getPriIpIdType());
                contentRecordGroup.setPrimaryInvolvedPartyBranchNumber(main.getPriIpBrcNo());
                contentRecordGroup.setPrimaryInvolvedPartyIbfIndicator(main.getPriIpIbfInd());
                contentRecordGroup.setArrangementContractDate(getXMLGregorianCalendarDate(main.getArrgCtrDate()));
                contentRecordGroup.setMaturityDate(getXMLGregorianCalendarDate(main.getMatDate()));
                contentRecordGroup.setObjectiveType(main.getObjectiveType());
                contentRecordGroup.setFxArrangementPurposeCode(main.getArrgPurpCode());
                contentRecordGroup.setLegType(main.getLegType());
                contentRecordGroup.setBuyCurrencyId(com.kcs.genxml.beans.fxa.MV0053.fromValue(main.getBuyCurr()));
                contentRecordGroup.setBuyAmount(getXmlString(main.getBuyAmt()));
                contentRecordGroup.setSellCurrencyId(com.kcs.genxml.beans.fxa.MV0053.fromValue(main.getSellCurr()));
                contentRecordGroup.setSellAmount(getXmlString(main.getSellAmt()));
                contentRecordGroup.setContractExchangeRate(getXmlFloat(main.getCtrExcRate()));
                contentRecordGroup.setBaseExchangeRate(getXmlFloat(main.getBaseExcRate()));
                contentRecordGroup.setDescription(main.getDescription());

                DSFXA.DSFXAContent.ContentRecordGroup.ApprovalDocumentGroupInfo adgi = fxaOf
                        .createDSFXADSFXAContentContentRecordGroupApprovalDocumentGroupInfo();
                List<Datasetfxa> subChildList = filterChildFxa(main, childAppvList);
                for (Datasetfxa child : subChildList) {
                    DSFXA.DSFXAContent.ContentRecordGroup.ApprovalDocumentGroupInfo.ApprovalDocumentGroupDetails details = fxaOf
                            .createDSFXADSFXAContentContentRecordGroupApprovalDocumentGroupInfoApprovalDocumentGroupDetails();
                    details.setApprovalDocumentDate(getXMLGregorianCalendarDate(child.getApprovalDocDate()));
                    details.setApprovalDocumentNumber(child.getApprovalDocNum());
                    adgi.getApprovalDocumentGroupDetails().add(details);
                }
                contentRecordGroup.setApprovalDocumentGroupInfo(adgi);

                DSFXA.DSFXAContent.ContentRecordGroup.BotReferenceNumberGroupInfo brngi = fxaOf
                        .createDSFXADSFXAContentContentRecordGroupBotReferenceNumberGroupInfo();
                subChildList = filterChildFxa(main, childBotRefList);
                for (Datasetfxa child : subChildList) {
                    DSFXA.DSFXAContent.ContentRecordGroup.BotReferenceNumberGroupInfo.BotReferenceNumberGroupDetails details = fxaOf
                            .createDSFXADSFXAContentContentRecordGroupBotReferenceNumberGroupInfoBotReferenceNumberGroupDetails();
                    details.setBotReferenceNumber(child.getBotRefNum());
                    brngi.getBotReferenceNumberGroupDetails().add(details);
                }
                contentRecordGroup.setBotReferenceNumberGroupInfo(brngi);

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

            dsfxa.setCommonHeader(dataSetCommonHeader);
            dsfxa.setDSFXAHeader(dSFXAHeader);
            dsfxa.setDSFXAContent(content);

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

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

    // <editor-fold defaultstate="collapsed" desc="isi">
    @Override
    public byte[] generateXmlIsi(String dataSetDate, String category) throws Exception {
        try {
            List<Datasetisi> mainList = isiDao.findMainList(dataSetDate, category);
            if (CollectionUtil.isEmpty(mainList)) {
                logger.error("main list is empty");
                return new byte[0];
            }
            Datasetisi obj = mainList.get(0);
            DSISI dsisi = isiOf.createDSISI();
            HeadGenXMLControl head = headDao.getHeadGenXMLControlByDatasetCode("DS_ISI");
            if (head != null) {
                dsisi.setName(head.getAttributesName());
                dsisi.setType(head.getAttributesType());
                dsisi.setSchemaVersion(head.getAttributesSchemaVersion());
            }

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

            DSISI.DSISIHeader dSISIHeader = isiOf.createDSISIDSISIHeader();
            dSISIHeader.setDataSubmissionPeriod(obj.getDataSubPrd());

            DSISI.DSISIContent content = isiOf.createDSISIDSISIContent();

            for (Datasetisi main : mainList) {
                nullToEmptyString(main);
                DSISI.DSISIContent.ContentRecordGroup contentRecordGroup = isiOf
                        .createDSISIDSISIContentContentRecordGroup();
                contentRecordGroup.setDataProviderBranchNumber(main.getDataPvdrBrcNo());
                contentRecordGroup.setInstrumentIssueTransactionType(main.getInsmTranType());
                contentRecordGroup.setIssuingInvolvedPartyId(main.getIssuIpNo());
                contentRecordGroup.setIssuingInvolvedPartyUniqueIdType(main.getIssuIpIdType());
                contentRecordGroup.setDebtInstrumentType(main.getDebtInsmType());
                contentRecordGroup.setDebtInstrumentReferenceNumber(main.getDebtInsmRefNo());
                contentRecordGroup.setDebtInstrumentName(main.getDebtInsmName());
                contentRecordGroup.setIsinCode(main.getIsinCode());
                contentRecordGroup.setIssueDate(getXMLGregorianCalendarDate(main.getIssuDate()));
                contentRecordGroup.setMaturityDate(getXMLGregorianCalendarDate(main.getMatDate()));
                contentRecordGroup.setOriginalTerm(getXmlString(main.getOrigTerm()));
                contentRecordGroup.setCouponRate(getXmlString(main.getCoupRate()));
                contentRecordGroup.setCurrencyId(com.kcs.genxml.beans.isi.MV0072.fromValue(main.getCurr()));
                contentRecordGroup.setTransactionAmount(getXmlString(main.getAmt()));
                contentRecordGroup
                        .setIntentionCountryId(com.kcs.genxml.beans.isi.MV0025.fromValue(main.getIntenCtry()));
                contentRecordGroup.setInstrumentCondition(main.getInsmCond());
                contentRecordGroup.setRepaymentReason(main.getRepymt());
                contentRecordGroup.setOtherRepaymentReasonDescription(main.getRepymtDesc());

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

            dsisi.setCommonHeader(dataSetCommonHeader);
            dsisi.setDSISIHeader(dSISIHeader);
            dsisi.setDSISIContent(content);

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

    // <editor-fold defaultstate="collapsed" desc="fra">
    @Override
    public byte[] generateXmlFra(String dataSetDate, String category) throws Exception {
        try {
            List<Datasetfra> mainList = fraDao.findMainList(dataSetDate, category);
            if (CollectionUtil.isEmpty(mainList)) {
                logger.error("main list is empty");
                return new byte[0];
            }
            Datasetfra obj = mainList.get(0);
            DSFRA dsfra = fraOf.createDSFRA();
            HeadGenXMLControl head = headDao.getHeadGenXMLControlByDatasetCode("DS_FRA");
            if (head != null) {
                dsfra.setName(head.getAttributesName());
                dsfra.setType(head.getAttributesType());
                dsfra.setSchemaVersion(head.getAttributesSchemaVersion());
            }

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

            DSFRA.DSFRAHeader dSFRAHeader = fraOf.createDSFRADSFRAHeader();
            dSFRAHeader.setDataSubmissionPeriod(obj.getDataSubPrd());

            DSFRA.DSFRAContent content = fraOf.createDSFRADSFRAContent();

            List<Datasetfra> childBotRefList = fraDao.findChildBotRefList(dataSetDate);

            for (Datasetfra main : mainList) {
                nullToEmptyString(obj);
                DSFRA.DSFRAContent.ContentRecordGroup contentRecordGroup = fraOf
                        .createDSFRADSFRAContentContentRecordGroup();
                contentRecordGroup.setFiArrangementNumber(main.getFiArrgNo());
                contentRecordGroup.setPrimaryInvolvedPartyId(main.getPriIpId());
                contentRecordGroup.setPrimaryInvolvedPartyUniqueIdType(main.getPriIpIdType());
                contentRecordGroup.setPrimaryInvolvedPartyBranchNumber(main.getPriIpBrcNo());
                contentRecordGroup.setPrimaryInvolvedPartyIbfIndicator(main.getPriIpIbfInd());
                contentRecordGroup.setArrangementContractDate(getXMLGregorianCalendarDate(main.getArrgCtrDate()));
                contentRecordGroup.setObjectiveType(main.getObjectiveType());
                contentRecordGroup.setFraArrangementPurposeCode(main.getArrgPurpCode());
                contentRecordGroup.setEffectiveDate(getXMLGregorianCalendarDate(main.getEffDate()));
                contentRecordGroup.setMaturityDate(getXMLGregorianCalendarDate(main.getMatDate()));
                contentRecordGroup.setBuyOrSellFraFlag(main.getBuySellFlag());
                contentRecordGroup.setInterestRateType(main.getIntRateType());
                contentRecordGroup.setInterestRate(getXmlString(main.getIntRate()));
                contentRecordGroup.setContractTenor(main.getCtrTenor());
                contentRecordGroup.setNotionalAmount(getXmlString(main.getNtnAmt()));
                contentRecordGroup
                        .setNotionalCurrencyId(com.kcs.genxml.beans.fra.MV0053.fromValue(main.getNtnCurr()));
                contentRecordGroup.setDescription(main.getDescription());

                DSFRA.DSFRAContent.ContentRecordGroup.BotReferenceNumberGroupInfo brngi = fraOf
                        .createDSFRADSFRAContentContentRecordGroupBotReferenceNumberGroupInfo();
                List<Datasetfra> subChildList = filterChildFra(main, childBotRefList);
                for (Datasetfra child : subChildList) {
                    DSFRA.DSFRAContent.ContentRecordGroup.BotReferenceNumberGroupInfo.BotReferenceNumberGroupDetails details = fraOf
                            .createDSFRADSFRAContentContentRecordGroupBotReferenceNumberGroupInfoBotReferenceNumberGroupDetails();
                    details.setBotReferenceNumber(child.getBotRefNum());
                    brngi.getBotReferenceNumberGroupDetails().add(details);
                }
                contentRecordGroup.setBotReferenceNumberGroupInfo(brngi);

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

            dsfra.setCommonHeader(dataSetCommonHeader);
            dsfra.setDSFRAHeader(dSFRAHeader);
            dsfra.setDSFRAContent(content);

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

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

    // <editor-fold defaultstate="collapsed" desc="fta">
    @Override
    public byte[] generateXmlFta(String dataSetDate, String category) throws Exception {
        try {
            List<Datasetfta> mainList = ftaDao.findMainList(dataSetDate, category);
            if (CollectionUtil.isEmpty(mainList)) {
                logger.error("main list is empty");
                return new byte[0];
            }
            Datasetfta obj = mainList.get(0);
            DSFTA dsfta = ftaOf.createDSFTA();
            HeadGenXMLControl head = headDao.getHeadGenXMLControlByDatasetCode("DS_FTA");
            if (head != null) {
                dsfta.setName(head.getAttributesName());
                dsfta.setType(head.getAttributesType());
                dsfta.setSchemaVersion(head.getAttributesSchemaVersion());
            }

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

            DSFTA.DSFTAHeader dSFTAHeader = ftaOf.createDSFTADSFTAHeader();
            dSFTAHeader.setDataSubmissionPeriod(obj.getDataSubPrd());

            DSFTA.DSFTAContent content = ftaOf.createDSFTADSFTAContent();
            for (Datasetfta main : mainList) {
                nullToEmptyString(main);
                DSFTA.DSFTAContent.ContentRecordGroup contentRecordGroup = ftaOf
                        .createDSFTADSFTAContentContentRecordGroup();
                contentRecordGroup.setFiArrangementNumber(main.getFiArrgNo());
                contentRecordGroup.setFuturesProductType(main.getProdType());
                contentRecordGroup.setPrimaryInvolvedPartyId(main.getPriIpId());
                contentRecordGroup.setPrimaryInvolvedPartyUniqueIdType(main.getPriIpIdType());
                contentRecordGroup.setFuturesMarketId(main.getMktId());
                contentRecordGroup.setArrangementContractDate(getXMLGregorianCalendarDate(main.getArrgCtrDate()));
                contentRecordGroup.setMaturityDate(getXMLGregorianCalendarDate(main.getMatDate()));
                contentRecordGroup.setArrangementPurposeDescription(main.getArrgPurpDesc());
                contentRecordGroup.setBuyOrSellFuturesFlag(main.getBuySellFlag());
                contentRecordGroup.setLegType(main.getLegType());
                contentRecordGroup.setContractPrice(getXmlString(main.getCtrPrice()));
                contentRecordGroup.setNumberOfContracts(getXmlString(main.getNoOfCtr()));
                contentRecordGroup.setAmountPerContract(getXmlString(main.getAmtPerCtr()));
                contentRecordGroup.setBuyCurrencyId(main.getBuyCurr());
                contentRecordGroup.setBuyAmount(getXmlString(main.getBuyAmt()));
                contentRecordGroup.setSellCurrencyId(main.getSellCurr());
                contentRecordGroup.setSellAmount(getXmlString(main.getSellAmt()));
                contentRecordGroup.setNotionalAmount(getXmlString(main.getNtnAmt()));
                contentRecordGroup.setNotionalCurrencyId(main.getNtnCurr());
                contentRecordGroup.setDescription(main.getDescription());

                content.getContentRecordGroup().add(contentRecordGroup);
            }
            dsfta.setCommonHeader(dataSetCommonHeader);
            dsfta.setDSFTAHeader(dSFTAHeader);
            dsfta.setDSFTAContent(content);

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

    // <editor-fold defaultstate="collapsed" desc="dip">
    @Override
    public byte[] generateXmlDip(String datasetDate, String category) throws Exception {
        try {
            List<Datasetdip> mainList = dipDao.findMainList(datasetDate, category);
            if (CollectionUtil.isEmpty(mainList)) {
                logger.error("main list is empty");
                return new byte[0];
            }
            Datasetdip obj = mainList.get(0);
            DSDIP dsdip = dipOf.createDSDIP();

            HeadGenXMLControl head = headDao.getHeadGenXMLControlByDatasetCode("DS_DIP");
            if (head != null) {
                dsdip.setName(head.getAttributesName());
                dsdip.setType(head.getAttributesType());
                dsdip.setSchemaVersion(head.getAttributesSchemaVersion());
            }
            com.kcs.genxml.beans.dip.DataSetCommonHeader dataSetCommonHeader = dipOf.createDataSetCommonHeader();
            dataSetCommonHeader.setDataSetDate(getXMLGregorianCalendarDate(obj.getDataSetDate()));
            dataSetCommonHeader.setOrganizationId(obj.getOrgId());

            DSDIP.DSDIPHeader dIPHeader = dipOf.createDSDIPDSDIPHeader();

            DSDIP.DSDIPContent content = dipOf.createDSDIPDSDIPContent();
            for (Datasetdip main : mainList) {
                nullToEmptyString(main);
                DSDIP.DSDIPContent.ContentRecordGroup contentRecordGroup = dipOf
                        .createDSDIPDSDIPContentContentRecordGroup();
                contentRecordGroup.setFiReportingGroupId(main.getFiRptGrp());
                DSDIP.DSDIPContent.ContentRecordGroup.ForeignCurrencyDepositAndInvestmentItemTypeGroupInfo info = dipOf
                        .createDSDIPDSDIPContentContentRecordGroupForeignCurrencyDepositAndInvestmentItemTypeGroupInfo();
                DSDIP.DSDIPContent.ContentRecordGroup.ForeignCurrencyDepositAndInvestmentItemTypeGroupInfo.ForeignCurrencyDepositAndInvestmentItemTypeGroupDetails detail = dipOf
                        .createDSDIPDSDIPContentContentRecordGroupForeignCurrencyDepositAndInvestmentItemTypeGroupInfoForeignCurrencyDepositAndInvestmentItemTypeGroupDetails();
                detail.setForeignCurrencyDepositAndInvestmentItemType(main.getItemType());
                detail.setItemDescription(main.getItemDesc());
                detail.setCountryId(main.getCtryId());
                detail.setCurrencyId(com.kcs.genxml.beans.dip.MV0072.fromValue(main.getCurr()));
                detail.setForeignCurrencyAmount(getXmlString(main.getAmt()));
                info.getForeignCurrencyDepositAndInvestmentItemTypeGroupDetails().add(detail);
                contentRecordGroup.setForeignCurrencyDepositAndInvestmentItemTypeGroupInfo(info);

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

            dsdip.setCommonHeader(dataSetCommonHeader);
            dsdip.setDSDIPHeader(dIPHeader);
            dsdip.setDSDIPContent(content);

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

    // <editor-fold defaultstate="collapsed" desc="epe">
    @Override
    public byte[] generateXmlEpe(String datasetDate, String category) throws Exception {
        try {
            List<Datasetepe> mainList = epeDao.findMainList(datasetDate, category);
            if (CollectionUtil.isEmpty(mainList)) {
                logger.error("main list is empty");
                return new byte[0];
            }
            Datasetepe obj = mainList.get(0);
            DSEPE dsepe = epeOf.createDSEPE();
            HeadGenXMLControl head = headDao.getHeadGenXMLControlByDatasetCode("DS_EPE");
            if (head != null) {
                dsepe.setName(head.getAttributesName());
                dsepe.setType(head.getAttributesType());
                dsepe.setSchemaVersion(head.getAttributesSchemaVersion());
            }
            com.kcs.genxml.beans.epe.DataSetCommonHeader dataSetCommonHeader = epeOf.createDataSetCommonHeader();
            dataSetCommonHeader.setDataSetDate(getXMLGregorianCalendarDate(obj.getDataSetDate()));
            dataSetCommonHeader.setOrganizationId(obj.getOrgId());

            DSEPE.DSEPEHeader dSEPEHeader = epeOf.createDSEPEDSEPEHeader();

            List<Datasetepe> childAppvList = epeDao.findChildAppvList(datasetDate);
            List<Datasetepe> childInvolvedList = epeDao.findChildInvolvedList(datasetDate);
            List<Datasetepe> childTransList = epeDao.findChildTransList(datasetDate);

            DSEPE.DSEPEContent content = epeOf.createDSEPEDSEPEContent();
            for (Datasetepe main : mainList) {
                nullToEmptyString(main);
                DSEPE.DSEPEContent.ContentRecordGroup contentRecordGroup = epeOf
                        .createDSEPEDSEPEContentContentRecordGroup();
                contentRecordGroup.setTransactionDate(getXMLGregorianCalendarDate(main.getTransactionDate()));
                contentRecordGroup.setPaymentExemptionReasonCode(main.getReasonCode());
                contentRecordGroup.setPaymentExemptionReasonDescription(main.getReasonDesc());
                contentRecordGroup.setCurrencyId(com.kcs.genxml.beans.epe.MV0053.fromValue((main.getCurr())));
                contentRecordGroup.setPaymentExemptionAmount(getXmlString(main.getAmt()));
                contentRecordGroup.setNetInflowOutflowAmount(getXmlString(main.getNetInflowOutflowAmt()));

                DSEPE.DSEPEContent.ContentRecordGroup.ApprovalDocumentGroupInfo appvInfo = epeOf
                        .createDSEPEDSEPEContentContentRecordGroupApprovalDocumentGroupInfo();
                List<Datasetepe> subChildAppvList = filterChildEpe(main, childAppvList);
                for (Datasetepe childAppv : subChildAppvList) {
                    DSEPE.DSEPEContent.ContentRecordGroup.ApprovalDocumentGroupInfo.ApprovalDocumentGroupDetails details = epeOf
                            .createDSEPEDSEPEContentContentRecordGroupApprovalDocumentGroupInfoApprovalDocumentGroupDetails();
                    details.setApprovalDocumentDate(getXMLGregorianCalendarDate(childAppv.getAppvDocDate()));
                    details.setApprovalDocumentNumber(childAppv.getAppvDocNo());
                    appvInfo.getApprovalDocumentGroupDetails().add(details);
                }
                contentRecordGroup.setApprovalDocumentGroupInfo(appvInfo);

                DSEPE.DSEPEContent.ContentRecordGroup.InvolvedPartyGroupInfo involvedInfo = epeOf
                        .createDSEPEDSEPEContentContentRecordGroupInvolvedPartyGroupInfo();
                List<Datasetepe> subChildInvolvedList = filterChildEpe(main, childInvolvedList);
                for (Datasetepe childInvolved : subChildInvolvedList) {
                    DSEPE.DSEPEContent.ContentRecordGroup.InvolvedPartyGroupInfo.InvolvedPartyGroupDetails details = epeOf
                            .createDSEPEDSEPEContentContentRecordGroupInvolvedPartyGroupInfoInvolvedPartyGroupDetails();
                    details.setInvolvedPartyId(childInvolved.getIpId());
                    details.setInvolvedPartyUniqueIdType(childInvolved.getIpIdType());
                    DSEPE.DSEPEContent.ContentRecordGroup.InvolvedPartyGroupInfo.InvolvedPartyGroupDetails.TransactionPurposeGroupInfo transInfo = epeOf
                            .createDSEPEDSEPEContentContentRecordGroupInvolvedPartyGroupInfoInvolvedPartyGroupDetailsTransactionPurposeGroupInfo();
                    List<Datasetepe> subChildTransList = filterChildEpeTrans(childInvolved, childTransList);
                    for (Datasetepe childTrans : subChildTransList) {
                        nullToEmptyString(childTrans);
                        DSEPE.DSEPEContent.ContentRecordGroup.InvolvedPartyGroupInfo.InvolvedPartyGroupDetails.TransactionPurposeGroupInfo.TransactionPurposeGroupDetails transDetails = epeOf
                                .createDSEPEDSEPEContentContentRecordGroupInvolvedPartyGroupInfoInvolvedPartyGroupDetailsTransactionPurposeGroupInfoTransactionPurposeGroupDetails();
                        transDetails.setSourceTransactionPurposeCode(childTrans.getSourceTransS());
                        transDetails.setUsedTransactionPurposeCode(childTrans.getUsedTransS());
                        transDetails.setSourceOrUsedAmount(getXmlString(childTrans.getSourceUsedAmtS()));
                        transInfo.getTransactionPurposeGroupDetails().add(transDetails);
                    }
                    details.setTransactionPurposeGroupInfo(transInfo);
                    involvedInfo.getInvolvedPartyGroupDetails().add(details);
                }
                contentRecordGroup.setInvolvedPartyGroupInfo(involvedInfo);
                content.getContentRecordGroup().add(contentRecordGroup);
            }

            dsepe.setCommonHeader(dataSetCommonHeader);
            dsepe.setDSEPEHeader(dSEPEHeader);
            dsepe.setDSEPEContent(content);

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

    private List<Datasetepe> filterChildEpe(final Datasetepe main, List<Datasetepe> childList) {
        List<Datasetepe> result = new ArrayList<Datasetepe>();
        final Predicate predicate = new Predicate() {
            @Override
            public boolean evaluate(Object o) {
                if (Utility.isNotNull(o)) {
                    Datasetepe child = (Datasetepe) o;
                    boolean result = (objEquals(main.getCustCode(), child.getCustCode())
                            && objEquals(main.getSeq(), child.getSeq())
                            && objEquals(main.getSysCode(), child.getSysCode()));
                    return result;
                }
                return false;
            }
        };
        result = (List<Datasetepe>) CollectionUtils.select(childList, predicate);
        return result;
    }

    private List<Datasetepe> filterChildEpeTrans(final Datasetepe childInvolved, List<Datasetepe> childTransList) {
        List<Datasetepe> result = new ArrayList<Datasetepe>();
        final Predicate predicate = new Predicate() {
            @Override
            public boolean evaluate(Object o) {
                if (Utility.isNotNull(o)) {
                    Datasetepe child = (Datasetepe) o;
                    boolean result = (objEquals(childInvolved.getIpId(), child.getIpId())
                            && objEquals(childInvolved.getSeq(), child.getSeq())
                            && objEquals(childInvolved.getIpIdType(), child.getIpIdType()));
                    return result;
                }
                return false;
            }
        };
        result = (List<Datasetepe>) CollectionUtils.select(childTransList, predicate);
        return result;
    }
    // </editor-fold>
}