Package com.salesforce.dataloader.dao.csv

Examples of com.salesforce.dataloader.dao.csv.CSVFileReader


    }

    private void initializeCSVViewer(Shell shell) throws DataAccessObjectInitializationException {
        GridData data;

        CSVFileReader csvReader = new CSVFileReader(filename, controller);

        try {
            csvReader.open();

            List<String> header = csvReader.getColumnNames();

            //sforce field table viewer
            csvTblViewer = new TableViewer(shell, SWT.FULL_SELECTION);
            csvTblViewer.setContentProvider(new CSVContentProvider());
            csvTblViewer.setLabelProvider(new CSVLabelProvider());

            // Set up the sforce table
            Table csvTable = csvTblViewer.getTable();
            data = new GridData(GridData.FILL_BOTH);
            data.heightHint = 300;
            csvTable.setLayoutData(data);

            Iterator<String> iter = header.iterator();

            new TableColumn(csvTable, SWT.LEFT).setText(Labels.getString("CSVViewerDialog.rowNumber")); //$NON-NLS-1$

            while (iter.hasNext()) {
                TableColumn tc = new TableColumn(csvTable, SWT.LEFT);
                tc.setText(iter.next().toString());
            }

            //update the model
            updateCSVTable(csvReader);

            //pack the columns
            packSforceColumns();

            // Turn on the header and the lines
            csvTable.setHeaderVisible(true);
            csvTable.setLinesVisible(true);

            //start scrolled up, dumb swt
            if (csvTable.getItemCount() > 0) {
                csvTable.showItem(csvTable.getItem(0));
            }
        } finally {
            csvReader.close();
        }
    }
View Full Code Here


            Assert.fail("creation of task failed with error " + result[0].getErrors()[0].getMessage());
        return result[0].getId();
    }

    private String getCsvFieldValue(String csvFile, String fieldName) throws Exception {
        CSVFileReader reader = new CSVFileReader(csvFile, getController());
        reader.open();
        assertEquals(1, reader.getTotalRows());
        String fieldValue = (String)reader.readRow().get(fieldName);
        reader.close();
        return fieldValue;
    }
View Full Code Here

    public void testCSVReadBasic() throws Exception {
        File f = new File(getTestDataDir(), "csvtext.csv");
        assertTrue(f.exists());
        assertTrue(f.canRead());

        CSVFileReader csv = new CSVFileReader(f, getController().getConfig());
        csv.open();

        List<String> headerRow = csv.getColumnNames();
        assertEquals(COLUMN_1_NAME, headerRow.get(0));
        assertEquals(COLUMN_2_NAME, headerRow.get(1));
        assertEquals(COLUMN_3_NAME, headerRow.get(2));

        Row firstRow = csv.readRow();
        assertEquals("row1-1", firstRow.get(COLUMN_1_NAME));
        assertEquals("row1-2", firstRow.get(COLUMN_2_NAME));
        assertEquals("row1-3", firstRow.get(COLUMN_3_NAME));

        Row secondRow = csv.readRow();
        assertEquals("row2-1", secondRow.get(COLUMN_1_NAME));
        assertEquals("row2-2", secondRow.get(COLUMN_2_NAME));
        assertEquals("row2-3", secondRow.get(COLUMN_3_NAME));

        csv.close();
    }
View Full Code Here

    public void testReadingEscapedValues() throws Exception {
        File f = new File(getTestDataDir(), "csvEscapedQuotes.csv");
        assertTrue(f.exists());
        assertTrue(f.canRead());

        CSVFileReader csv = new CSVFileReader(f, getController().getConfig());
        csv.open();

        Row firstRow = csv.readRow();
        assertEquals("\"The Best\" Account", firstRow.get(COLUMN_1_NAME));

        Row secondRow = csv.readRow();
        assertEquals("The \"Best\" Account", secondRow.get(COLUMN_1_NAME));

        csv.close();
    }
View Full Code Here

        csv.close();
    }

    @Test
    public void testCsvWithManyRowsCanBeParsed() throws Exception {
        CSVFileReader csvFileReader = new CSVFileReader(new File(getTestDataDir(), "20kRows.csv"), getController().getConfig());
        csvFileReader.open();
        assertEquals(20000, csvFileReader.getTotalRows());
        int count = 0;
        for(Row row = csvFileReader.readRow(); row != null; row = csvFileReader.readRow(), count++);
        assertEquals(20000, count);
    }
View Full Code Here

     *
     * @param filePath
     */

    private void compareWriterFile(String filePath) throws Exception {
        CSVFileReader csv = new CSVFileReader(filePath, getController());
        csv.open();

        //check that the header is the same as what we wanted to write
        List<String> headerRow = csv.getColumnNames();
        for (int i = 0; i < writeHeader.size(); i++) {
            assertEquals(headerRow.get(i), writeHeader.get(i));
        }

        //check that row 1 is valid
        Row firstRow = csv.readRow();
        for (String headerColumn : writeHeader) {
            assertEquals(row1.get(headerColumn), firstRow.get(headerColumn));
        }

        //check that row 2 is valid
        Row secondRow = csv.readRow();
        for (String headerColumn : writeHeader) {
            assertEquals(row2.get(headerColumn), secondRow.get(headerColumn));
        }
        csv.close();
    }
View Full Code Here

        // finding rows in input file and opening it

        numberOfInputRows = getNumCsvRows(cfg, Config.DAO_NAME);

        // finding rows in success file and opening it
        CSVFileReader successFileReader = openConfiguredPath(cfg, Config.OUTPUT_SUCCESS);
        numberOfSuccessRows = getNumCsvRows(cfg, Config.OUTPUT_SUCCESS);

        // finding rows in error file and opening it
        CSVFileReader errorFileReader = openConfiguredPath(cfg, Config.OUTPUT_ERROR);
        numberOfErrorRows = getNumCsvRows(cfg, Config.OUTPUT_ERROR);

        if (numberOfOffsetRows <= numberOfInputRows) {
            assertEquals("Number of lines between input and output do not match", numberOfInputRows,
                    numberOfSuccessRows + numberOfErrorRows + numberOfOffsetRows);
        }

        // Initializations of row results
        Row firstInputOffsetAdjustedRow = new Row();
        Row lastInputRow = new Row();
        Row firstSuccessRow = new Row();
        Row lastSuccessRow = new Row();
        Row firstErrorRow = new Row();
        Row lastErrorRow = new Row();

        // The next few if statements deal with the edge statements on file size...(i.e. suppose that there are no
        // errors)
        if (numberOfSuccessRows > 0) {
            getFirstRow(firstSuccessRow, successFileReader, true, 0);
            getLastRow(lastSuccessRow, successFileReader, true);
        }

        if (numberOfErrorRows > 0) {
            getFirstRow(firstErrorRow, errorFileReader, false, 0);
            getLastRow(lastErrorRow, errorFileReader, false);
        }

        if (numberOfInputRows > 0) {
            final CSVFileReader inputFileReader = openConfiguredPath(cfg, Config.DAO_NAME);

            getFirstRow(firstInputOffsetAdjustedRow, inputFileReader, false, numberOfOffsetRows);
            getLastRow(lastInputRow, inputFileReader, false);
        }
View Full Code Here

                    || lastInputRow.get("NAME").equals(lastErrorRow.get("NAME")));
        } //otherwise vacuously true
    }

    private int getNumCsvRows(Config cfg, String setting) throws DataAccessObjectException {
        final CSVFileReader rdr = openConfiguredPath(cfg, setting);
        try {
            return rdr.getTotalRows();
        } finally {
            rdr.close();
        }
    }
View Full Code Here

        }
    }

    private CSVFileReader openConfiguredPath(Config cfg, String configSetting)
            throws DataAccessObjectInitializationException {
        final CSVFileReader rdr = new CSVFileReader(new File(cfg.getString(configSetting)), cfg);
        rdr.open();
        return rdr;
    }
View Full Code Here

        DataAccessObject dao = null;

        logger.info(Messages.getFormattedString("DataAccessObjectFactory.creatingDao", new String[] {config.getString(Config.DAO_NAME), daoType}));

        if (CSV_READ_TYPE.equalsIgnoreCase(daoType)) {
            dao = new CSVFileReader(config);
        } else if (CSV_WRITE_TYPE.equalsIgnoreCase(daoType)) {
            dao = new CSVFileWriter(config.getString(Config.DAO_NAME), config);
        } else if (DATABASE_READ_TYPE.equalsIgnoreCase(daoType)) {
            dao = new DatabaseReader(config);
        } else if (DATABASE_WRITE_TYPE.equalsIgnoreCase(daoType)) {
View Full Code Here

TOP

Related Classes of com.salesforce.dataloader.dao.csv.CSVFileReader

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.