package org.recap.camel;

import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.file.FileEndpoint;
import org.apache.camel.component.file.GenericFile;
import org.apache.camel.component.file.GenericFileFilter;
import org.apache.commons.io.FilenameUtils;
import org.junit.Ignore;
import org.junit.Test;
import org.recap.BaseTestCase;

import org.recap.repository.XmlRecordRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;

/**
 * Created by peris on 7/17/16.
 */

@Ignore
public class CamelJdbcUT extends BaseTestCase {

    @Value("${etl.split.xml.tag.name}")
    String xmlTagName;

    @Value("${etl.load.directory}")
    Integer etlPoolSize;

    @Value("${etl.pool.size}")
    Integer etlMaxPoolSize;

    @Value("${etl.max.pool.size}")
    String inputDirectoryPath;

    @Autowired
    XmlRecordRepository xmlRecordRepository;

    @Test
    public void parseXmlAndInsertIntoDb() throws Exception {


        camelContext.addRoutes(new RouteBuilder() {
            @Override
            public void configure() throws Exception {
                FileEndpoint fileEndpoint = endpoint("file:" + inputDirectoryPath, FileEndpoint.class);
                fileEndpoint.setFilter(new XmlFileFilter());

                from(fileEndpoint)
                        .split()
                        .tokenizeXML(xmlTagName)
                        .streaming()
                        .threads(etlPoolSize, etlMaxPoolSize, "xmlProcessingThread")
                        .process(new XmlProcessor(xmlRecordRepository))
                        .to("jdbc:dataSource");
            }
        });

        java.lang.Thread.sleep(10000);
    }

    class XmlFileFilter implements GenericFileFilter {
        @Override
        public boolean accept(GenericFile file) {
            return FilenameUtils.getExtension(file.getAbsoluteFilePath()).equalsIgnoreCase("xml");
        }
    }
}

@@ -352,16 +352,49 @@
 tCase;%0A%0A
+import org.recap.ReCAPConstants;%0A
 import o
@@ -2007,10 +2007,818 @@
 %7D%0A    %7D%0A
+%0A%0A%0A//    @Test%0A//    public void exportDataDump() throws Exception %7B%0A//%0A//        camelContext.addRoutes(new RouteBuilder() %7B%0A//            @Override%0A//            public void configure() throws Exception %7B%0A//                from(%22scsbactivemq:queue:bibEntityForDataExportQ%22)%0A//                        .marshal()%0A//                        .to(ReCAPConstants.DATADUMP_FILE_SYSTEM_Q);%0A//%0A//            %7D%0A//        %7D);%0A//%0A//        camelContext.addRoutes(new RouteBuilder() %7B%0A//            @Override%0A//            public void configure() throws Exception %7B%0A//                from(%22scsbactivemq:queue:solrInputForDataExportQ%22)%0A//                        .process(new SolrSearchResultsProcessorForExport())%0A//                .to(%22scsbactivemq:queue:bibEntityForDataExportQ%22);%0A//            %7D%0A//        %7D);%0A//    %7D%0A
 %7D%0A

Test for cameljdbc