Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    DataImport.importDataSourceRecords() exception question

    Hi Isomorphic,

    I'm using DataImporter from a servlet with v10.1p_2016-04-12.
    I'm switching to a importDataSourceRecords()-overload with columnRemap-parameter (this one).
    Before it worked as expected. The columnRemap is built with this code:
    Code:
        private Map<String, String> getImportColumnMapping(String importDS) throws Exception {
            Map<String, String> columnMap = new LinkedHashMap<String, String>();
            DataSource uploadDS = DataSourceManager.get(importDS);
    
            for (String fieldName : uploadDS.getFieldNames()) {
                DSField field = uploadDS.getField(fieldName);
                String uploadFieldName = field.getProperty("uploadFieldName");
                if (uploadFieldName != null)
                    columnMap.put(fieldName, uploadFieldName);
            }
            DataSourceManager.free(uploadDS);
            return columnMap;
        }
    I now get an exception in importDataSourceRecords()-code where you can tell me for sure what is going wrong:
    Code:
    [B]java.lang.IndexOutOfBoundsException: Index: 2, Size: 2
        at java.util.ArrayList.rangeCheck(Unknown Source)
        at java.util.ArrayList.get(Unknown Source)
        at com.isomorphic.tools.DataImport.importToRows(DataImport.java:1191)
        at com.isomorphic.tools.DataImport.importDataSourceRecords(DataImport.java:903)
        at com.isomorphic.tools.DataImport.importDataSourceRecords(DataImport.java:775)[/B]
        at com.lmscompany.lms.server.ReceiveMail.receiveEmail(ReceiveMail.java:207)
        at com.lmscompany.lms.server.ReceiveMail.doGet(ReceiveMail.java:73)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:622)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at com.isomorphic.servlet.CompressionFilter._doFilter(CompressionFilter.java:260)
        at com.isomorphic.servlet.BaseFilter.doFilter(BaseFilter.java:88)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:212)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
        at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:141)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
        at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:616)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:521)
        at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1096)
        at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:674)
        at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1500)
        at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1456)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
        at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
        at java.lang.Thread.run(Unknown Source)
    Thank you & Best regards
    Blama

    #2
    Hi Isomorphic,

    could you already look into this one?

    Thank you & Best regards
    Blama

    Comment


      #3
      The only way we can see this error occurring is because in your uploaded file, the last column in the header is missing and there is a trailing comma. For example, your header has two columns, whereas your data rows have three columns.

      Please, confirm that this is causing your issue.

      Regards
      Isomorphic Software

      Comment


        #4
        Hi Isomorphic,

        I got to the ground of this. My columnRemap was columnMap.put(fieldName, uploadFieldName) but should have been columnMap.put(uploadFieldName, fieldName).

        I found other errors as well and prepared a testcase for them.
        1. 1st row empty
        2. My (solved) issue (=No matching column names in columnRemap)
        3. The issue you mentioned
        DataImportTest.java:
        Code:
        package com.smartgwt.sample.server.listener;
        
        import java.io.IOException;
        import java.io.Reader;
        import java.io.StringReader;
        import java.util.Date;
        import java.util.LinkedHashMap;
        import java.util.List;
        import java.util.Map;
        
        import javax.servlet.ServletException;
        import javax.servlet.http.HttpServlet;
        import javax.servlet.http.HttpServletRequest;
        import javax.servlet.http.HttpServletResponse;
        
        import com.isomorphic.tools.DataImport;
        import com.isomorphic.tools.DataImport.ImportFormat;
        
        public class DataImportTest extends HttpServlet {
            private static final long serialVersionUID = 6052735004239581488L;
        
            @Override
            public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
                try {
                    response.getWriter().append("Test 1 (1st row empty):\r\n");
                    doDataImportTest(1, request, response);
                } catch (Exception e) {
                    e.printStackTrace();
                    response.getWriter().append(e.getMessage());
                }
        
                try {
                    response.getWriter().append("\r\n\r\nTest 2 (my (solved) issue):\r\n");
                    doDataImportTest(2, request, response);
                } catch (Exception e) {
                    e.printStackTrace();
                    response.getWriter().append(e.getMessage());
                }
        
                try {
                    response.getWriter().append("\r\n\r\nTest 3 (issue you mentioned):\r\n");
                    doDataImportTest(3, request, response);
                } catch (Exception e) {
                    e.printStackTrace();
                    response.getWriter().append(e.getMessage());
                }
            }
        
            @Override
            public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
                doGet(request, response);
            }
        
            private void doDataImportTest(int test, HttpServletRequest request, HttpServletResponse response) throws Exception {
                String header = null;
                String datarow = null;
                String csvData = null;
                Reader emailContentReader = null;
                DataImport dataImporter = new DataImport(ImportFormat.CSV, ";");
                dataImporter.setPopulateDisplayFields(true);
                Map<String, String> columnRemap = new LinkedHashMap<String, String>();
        
                List<Map<String, Object>> dataImported = null;
        
                switch (test) {
                case 1:
                header = "\r\nMy-Name;My-SKU";
                datarow = "New Tool;123";
                csvData = header + "\r\n" + datarow + "\r\n";
                emailContentReader = new StringReader(csvData);
        
                columnRemap.put("My-Name", "itemName");
                columnRemap.put("My-SKU", "SKU");
                
                dataImported = dataImporter.importDataSourceRecords(emailContentReader, columnRemap, "supplyItem");
                break;
        
                case 2:
                    header = "My-Name;My-SKU";
                    datarow = "New Tool;123";
                    csvData = header + "\r\n" + datarow + "\r\n";
                    emailContentReader = new StringReader(csvData);
        
                    columnRemap.put("nomatchatall", "itemName");
                    
                    dataImported = dataImporter.importDataSourceRecords(emailContentReader, columnRemap, "supplyItem");
                    break;
        
                case 3:
                    header = "My-Name;My-SKU";
                    datarow = "New Tool;123;foo;";
                    csvData = header + "\r\n" + datarow + "\r\n";
                    emailContentReader = new StringReader(csvData);
        
                    columnRemap.put("My-Name", "itemName");
                    columnRemap.put("My-SKU", "SKU");
        
                    dataImported = dataImporter.importDataSourceRecords(emailContentReader, columnRemap, "supplyItem");
                    break;
                }
                response.getWriter().append(new Date().toString() + "\r\n" + dataImported.toString());
            }
        };
        web.xml addition (call http://127.0.0.1:8888/DataImportTest):
        Code:
            <servlet>
                <servlet-name>DataImportTest</servlet-name>
                <servlet-class>com.smartgwt.sample.server.listener.DataImportTest</servlet-class>
            </servlet>
            <servlet-mapping>
                <servlet-name>DataImportTest</servlet-name>
                <url-pattern>/DataImportTest</url-pattern>
            </servlet-mapping>
        While I can continue now, I think those should be fixed as nevertheless. I'll also update this thread now.

        Best regards
        Blama

        Comment


          #5
          These issues have been solved. Please try the next nightly build, dated April 27.

          Regards
          Isomorphic Software

          Comment


            #6
            Hi Isomorphic,

            I can confirm that the issues are fixed using v10.1p_2016-04-27.

            Thank you & Best regards
            Blama

            Comment

            Working...
            X