use of com.axelor.data.csv.CSVImporter in project open-platform-demo by axelor.
the class CSVDataTest method testMulti.
@Test
public void testMulti() throws IOException {
Importer importer = new CSVImporter("data/csv-multi-config.xml");
importer.run(new ImportTask() {
@Override
public void configure() throws IOException {
input("[sale.order]", new File("data/csv-multi/so1.csv"));
input("[sale.order]", new File("data/csv-multi/so2.csv"));
}
});
}
use of com.axelor.data.csv.CSVImporter in project open-platform-demo by axelor.
the class CSVDataTest method testDefault.
@Test
public void testDefault() throws IOException {
Importer importer = new CSVImporter("data/csv-config.xml", "data/csv");
importer.run();
}
use of com.axelor.data.csv.CSVImporter in project open-platform-demo by axelor.
the class CSVImportTest method test.
@Test
public void test() throws ClassNotFoundException {
final List<Model> records = new ArrayList<>();
CSVImporter importer = new CSVImporter("data/csv-multi-config.xml");
Map<String, Object> context = new HashMap<>();
context.put("CUSTOMER_PHONE", "+3326253225");
importer.setContext(context);
importer.addListener(new Listener() {
@Override
public void imported(Model bean) {
log.info("Bean saved : {}(id={})", bean.getClass().getSimpleName(), bean.getId());
records.add(bean);
}
@Override
public void imported(Integer total, Integer success) {
log.info("Record (total): " + total);
log.info("Record (success): " + success);
}
@Override
public void handle(Model bean, Exception e) {
}
});
importer.run(new ImportTask() {
@Override
public void configure() throws IOException {
input("[sale.order]", new File("data/csv-multi/so1.csv"));
input("[sale.order]", new File("data/csv-multi/so2.csv"));
}
@Override
public boolean handle(ImportException exception) {
log.error("Import error : " + exception);
return false;
}
@Override
public boolean handle(IOException e) {
log.error("IOException error : " + e);
return true;
}
});
}
use of com.axelor.data.csv.CSVImporter in project axelor-open-suite by axelor.
the class UnitCostCalculationServiceImpl method importUnitCostCalc.
@Override
public void importUnitCostCalc(MetaFile dataFile, UnitCostCalculation unitCostCalculation) throws IOException {
File tempDir = Files.createTempDir();
File csvFile = new File(tempDir, "unitcostcalc.csv");
Files.copy(MetaFiles.getPath(dataFile).toFile(), csvFile);
File configXmlFile = this.getConfigXmlFile();
CSVImporter csvImporter = new CSVImporter(configXmlFile.getAbsolutePath(), tempDir.getAbsolutePath());
Map<String, Object> context = new HashMap<>();
context.put("_unitCostCalculation", unitCostCalculation.getId());
csvImporter.setContext(context);
csvImporter.run();
}
use of com.axelor.data.csv.CSVImporter in project axelor-open-suite by axelor.
the class ImporterCSV method process.
@Override
protected ImportHistory process(String bind, String data, Map<String, Object> importContext) throws IOException {
CSVImporter importer = new CSVImporter(bind, data);
ImporterListener listener = new ImporterListener(getConfiguration().getName());
importer.addListener(listener);
importer.setContext(importContext);
importer.run();
return addHistory(listener);
}
Aggregations