use of com.axelor.apps.base.service.imports.listener.ImporterListener in project axelor-open-suite by axelor.
the class DataImportServiceImpl method importData.
private MetaFile importData(List<CSVInput> inputs) throws IOException {
if (CollectionUtils.isEmpty(inputs)) {
return null;
}
CSVConfig config = new CSVConfig();
config.setInputs(inputs);
if (!CollectionUtils.isEmpty(adapterMap.values())) {
config.getAdapters().addAll(adapterMap.values());
}
CSVImporter importer = new CSVImporter(config, dataDir.getAbsolutePath());
ImporterListener listener = new ImporterListener("importData");
importer.addListener(listener);
importer.setContext(importContext);
importer.run();
if (!listener.isImported()) {
MetaFile logFile = this.createImportLogFile(listener);
return logFile;
}
return null;
}
use of com.axelor.apps.base.service.imports.listener.ImporterListener in project axelor-open-suite by axelor.
the class ImporterXML method process.
@Override
protected ImportHistory process(String bind, String data, Map<String, Object> importContext) throws IOException {
XMLImporter importer = new XMLImporter(bind, data);
ImporterListener listener = new ImporterListener(getConfiguration().getName());
importer.addListener(listener);
importer.setContext(importContext);
importer.run();
return addHistory(listener);
}
use of com.axelor.apps.base.service.imports.listener.ImporterListener in project axelor-open-suite by axelor.
the class EbicsController method importEbicsUsers.
@Transactional
public void importEbicsUsers(ActionRequest request, ActionResponse response) {
String config = "/data-import/import-ebics-user-config.xml";
try {
InputStream inputStream = this.getClass().getResourceAsStream(config);
File configFile = File.createTempFile("config", ".xml");
FileOutputStream fout = new FileOutputStream(configFile);
IOUtil.copyCompletely(inputStream, fout);
Path path = MetaFiles.getPath((String) ((Map) request.getContext().get("dataFile")).get("filePath"));
File tempDir = Files.createTempDir();
File importFile = new File(tempDir, "ebics-user.xml");
Files.copy(path.toFile(), importFile);
XMLImporter importer = new XMLImporter(configFile.getAbsolutePath(), tempDir.getAbsolutePath());
ImporterListener listner = new ImporterListener("EbicsUser");
importer.addListener(listner);
importer.run();
FileUtils.forceDelete(configFile);
FileUtils.forceDelete(tempDir);
response.setValue("importLog", listner.getImportLog());
} catch (IOException e) {
e.printStackTrace();
}
}
use of com.axelor.apps.base.service.imports.listener.ImporterListener in project axelor-open-suite by axelor.
the class PrintTemplateController method importPrintTemplate.
public void importPrintTemplate(ActionRequest request, ActionResponse response) {
String config = "/data-import/import-print-template-config.xml";
try {
InputStream inputStream = this.getClass().getResourceAsStream(config);
File configFile = File.createTempFile("config", ".xml");
FileOutputStream fout = new FileOutputStream(configFile);
IOUtil.copyCompletely(inputStream, fout);
Path path = MetaFiles.getPath((String) ((Map) request.getContext().get("dataFile")).get("filePath"));
File tempDir = Files.createTempDir();
File importFile = new File(tempDir, "print-template.xml");
Files.copy(path.toFile(), importFile);
XMLImporter importer = new XMLImporter(configFile.getAbsolutePath(), tempDir.getAbsolutePath());
ImporterListener listner = new ImporterListener("PrintTemplate");
importer.addListener(listner);
importer.run();
FileUtils.forceDelete(configFile);
FileUtils.forceDelete(tempDir);
response.setValue("importLog", listner.getImportLog());
} catch (Exception e) {
TraceBackService.trace(response, e);
}
}
use of com.axelor.apps.base.service.imports.listener.ImporterListener 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