Package com.salesforce.dataloader.dao.csv

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


    //Factor out the verification query
    private SObject[] retrieveAccounts(Controller resultController, String... accountFieldsToReturn) throws Exception {

        List<String> ids = new ArrayList<String>();
        String fileName = resultController.getConfig().getString(Config.OUTPUT_SUCCESS);
        final CSVFileReader successRdr = new CSVFileReader(fileName, getController());
        try {
            // TODO: revise the use of Integer.MAX_VALUE
            for (Row row : successRdr.readRowList(Integer.MAX_VALUE)) {
                final String rowId = (String) row.get("ID");
                if (rowId != null) {
                    ids.add(rowId);
                }
            }
        } finally {
            successRdr.close();
        }


        // query them and verify that they have the values
        StringBuilder fields = new StringBuilder("id");
View Full Code Here


        deleteSfdcRecords("Contact", CONTACT_WHERE_CLAUSE, 0);
    }

    protected void verifyErrors(Controller controller, String expectedErrorMessage) throws DataAccessObjectException {
        String fileName = controller.getConfig().getString(Config.OUTPUT_ERROR);
        final CSVFileReader errReader = new CSVFileReader(fileName, controller);
        try {
            errReader.open();
            for (Row errorRow : errReader.readRowList(errReader.getTotalRows())) {
                String actualMessage = (String) errorRow.get("ERROR");
                if (actualMessage == null || !actualMessage.startsWith(expectedErrorMessage))
                    Assert.fail("Error row does not have the expected error message: " + expectedErrorMessage
                            + "\n  Actual row: " + errorRow);
            }
        } finally {
            errReader.close();
        }
    }
View Full Code Here

        verifySuccessIds(theController, new HashSet<String>(Arrays.asList(ids)));
    }

    protected void verifySuccessIds(Controller ctl, Set<String> ids) throws DataAccessObjectException {
        String fileName = ctl.getConfig().getString(Config.OUTPUT_SUCCESS);
        final CSVFileReader successRdr = new CSVFileReader(fileName, ctl);
        final Set<String> remaining = new HashSet<String>(ids);
        final Set<String> unexpected = new HashSet<String>();
        try {
            for (Row row : successRdr.readRowList(Integer.MAX_VALUE)) {
                final String rowid = (String) row.get("ID");
                if (rowid != null && rowid.length() > 0 && !remaining.remove(rowid)) unexpected.add(rowid);
            }
        } finally {
            successRdr.close();
        }

        if (!remaining.isEmpty()) Assert.fail("Ids not found: " + remaining);
        if (!unexpected.isEmpty()) Assert.fail("Unexpected ids found: " + unexpected);
    }
View Full Code Here

     */
    protected String convertTemplateToInput(String templateFileName, String inputFileName,
            TemplateListener... listeners) throws DataAccessObjectException {

        String fileName = new File(getTestDataDir(), templateFileName).getAbsolutePath();
        final CSVFileReader templateReader = new CSVFileReader(fileName, getController());
        try {
            templateReader.open();

            int numRows = templateReader.getTotalRows();
            final List<Row> templateRows = templateReader.readRowList(numRows);
            assertNotNull("CVSReader returned a null list of rows, but expected a list with size " + numRows,
                    templateRows);
            final List<Row> inputRows = new ArrayList<Row>(templateRows.size());

            // verify that the template file is useable
            assertEquals("Wrong number of rows were read using readRowList while attempting to convert template file: "
                    + templateFileName, numRows, templateRows.size());

            // insert accounts for the whole template or part of it if
            // maxInserts is smaller then template size
            int idx = 0;
            for (Row templateRow : templateRows) {
                final Row row = new Row(templateRow);
                if (listeners != null) {
                    for (TemplateListener l : listeners) {
                        l.updateRow(idx, row);
                    }
                }
                inputRows.add(row);
                idx++;
            }
            final String inputPath = new File(getTestDataDir(), inputFileName).getAbsolutePath();
            final CSVFileWriter inputWriter = new CSVFileWriter(inputPath, getController().getConfig());
            try {
                inputWriter.open();
                inputWriter.setColumnNames(templateReader.getColumnNames());
                inputWriter.writeRowList(inputRows);
                return inputPath;
            } finally {
                inputWriter.close();
            }
        } finally {
            templateReader.close();
        }
    }
View Full Code Here

        final String successFile = ctl.getConfig().getStringRequired(Config.OUTPUT_SUCCESS);
        //final String suceessFule2 = ctl.getConfig().
        assertNumRowsInCSVFile(successFile, numInserts + numUpdates);

        Row row = null;
        CSVFileReader rdr = new CSVFileReader(successFile, getController());
        String updateMsg = UPDATE_MSGS.get(ctl.getConfig().getOperationInfo());
        int insertsFound = 0;
        int updatesFound = 0;
        while ((row = rdr.readRow()) != null) {
            String id = (String)row.get("ID");
            if (emptyId) assertEquals("Expected empty id", "", id);
            else
                assertValidId(id);
            String status = (String)row.get("STATUS");
View Full Code Here

        assertNumRowsInCSVFile(ctl.getConfig().getStringRequired(
                Config.OUTPUT_ERROR), numFailures);
    }

    private void assertNumRowsInCSVFile(String fName, int expectedRows) throws DataAccessObjectException {
        CSVFileReader rdr = new CSVFileReader(fName, getController());
        rdr.open();
        int actualRows = rdr.getTotalRows();
        assertEquals("Wrong number of rows in file :" + fName, expectedRows, actualRows);
    }
View Full Code Here

        // assert that it's a CSV...if not fail
        final Set<String> unexpectedIds = new HashSet<String>();
        final Set<String> expectedIds = new HashSet<String>(Arrays.asList(ids));
        String fileName = control.getConfig().getString(Config.OUTPUT_SUCCESS);
        final DataReader resultReader = new CSVFileReader(fileName, getController());
        try {
            resultReader.open();

            // go through item by item and assert that it's there
            Row row;
            while ((row = resultReader.readRow()) != null) {
                final String resultId = (String)row.get(Config.ID_COLUMN_NAME);
                assertValidId(resultId);
                if (!expectedIds.remove(resultId)) {
                    unexpectedIds.add(resultId);
                }
            }
        } finally {
            resultReader.close();
        }

        if (!expectedIds.isEmpty()) {
            Assert.fail("These ids were not found in the result file: " + expectedIds);
        }
View Full Code Here

            runProcessNegative(
                    argMap,
                    "Batch failed: InvalidBatch : Failed to process query: FUNCTIONALITY_NOT_ENABLED: Foreign Key Relationships not supported in Bulk Query");
        } else {
            runProcess(argMap, 1);
            final CSVFileReader resultReader = new CSVFileReader(argMap.get(Config.DAO_NAME), getController());
            try {
                final Row resultRow = resultReader.readRow();
                assertEquals("Query returned incorrect Contact ID", contactId, resultRow.get("CONTACT_ID"));
                assertEquals("Query returned incorrect Contact Name", "First 000000 Last 000000",
                        resultRow.get("CONTACT_NAME"));
                assertEquals("Query returned incorrect Account ID", accountId, resultRow.get("ACCOUNT_ID"));
                assertEquals("Query returned incorrect Account Name", "account insert#000000",
                        resultRow.get("ACCOUNT_NAME"));

            } finally {
                resultReader.close();
            }
        }
    }
View Full Code Here

                        expectedError);
            } else {
                // run the extract
                runProcess(argmap, 1);
                // open the results of the extraction
                final CSVFileReader rdr = new CSVFileReader(argmap.get(Config.DAO_NAME), getController());
                rdr.open();
                Row row = rdr.readRow();
                assertNotNull(row);
                assertEquals(5,row.size());
                // validate the extract results are correct.
                assertEquals(leadidArr[0], row.get("LID"));
                assertEquals("loader", row.get("LNAME"));
                assertEquals("data loader", row.get("NAME__RESULT"));
                assertEquals(uid, row.get("OID"));
                assertEquals(uid,row.get("OWNID"));
                // validate that we have read the only result. there should be only one.
                assertNull(rdr.readRow());

            }
        } finally {
            // cleanup here since the parent doesn't clean up leads
            getBinding().delete(leadidArr);
View Full Code Here

            runProcessNegative(
                    argMap,
                    "Batch failed: InvalidBatch : Failed to process query: FUNCTIONALITY_NOT_ENABLED: Aggregate Relationships not supported in Bulk Query");
        } else {
            runProcess(argMap, 1, true);
            final CSVFileReader resultReader = new CSVFileReader(argMap.get(Config.DAO_NAME), getController());
            try {
                assertEquals(String.valueOf(numRecords - 1), resultReader.readRow().get("MAX(NUMBEROFEMPLOYEES)"));
            } finally {
                resultReader.close();
            }
        }
    }
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.