Search in sources :

Example 1 with ImporterListener

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;
}
Also used : ImporterListener(com.axelor.apps.base.service.imports.listener.ImporterListener) MetaFile(com.axelor.meta.db.MetaFile) CSVImporter(com.axelor.data.csv.CSVImporter) CSVConfig(com.axelor.data.csv.CSVConfig)

Example 2 with ImporterListener

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);
}
Also used : ImporterListener(com.axelor.apps.base.service.imports.listener.ImporterListener) XMLImporter(com.axelor.data.xml.XMLImporter)

Example 3 with ImporterListener

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();
    }
}
Also used : Path(java.nio.file.Path) ImporterListener(com.axelor.apps.base.service.imports.listener.ImporterListener) InputStream(java.io.InputStream) FileOutputStream(java.io.FileOutputStream) XMLImporter(com.axelor.data.xml.XMLImporter) IOException(java.io.IOException) File(java.io.File) MetaFile(com.axelor.meta.db.MetaFile) Map(java.util.Map) Transactional(com.google.inject.persist.Transactional)

Example 4 with ImporterListener

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);
    }
}
Also used : Path(java.nio.file.Path) ImporterListener(com.axelor.apps.base.service.imports.listener.ImporterListener) InputStream(java.io.InputStream) FileOutputStream(java.io.FileOutputStream) XMLImporter(com.axelor.data.xml.XMLImporter) File(java.io.File) Map(java.util.Map) AxelorException(com.axelor.exception.AxelorException)

Example 5 with ImporterListener

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);
}
Also used : ImporterListener(com.axelor.apps.base.service.imports.listener.ImporterListener) CSVImporter(com.axelor.data.csv.CSVImporter)

Aggregations

ImporterListener (com.axelor.apps.base.service.imports.listener.ImporterListener)5 XMLImporter (com.axelor.data.xml.XMLImporter)3 CSVImporter (com.axelor.data.csv.CSVImporter)2 MetaFile (com.axelor.meta.db.MetaFile)2 File (java.io.File)2 FileOutputStream (java.io.FileOutputStream)2 InputStream (java.io.InputStream)2 Path (java.nio.file.Path)2 Map (java.util.Map)2 CSVConfig (com.axelor.data.csv.CSVConfig)1 AxelorException (com.axelor.exception.AxelorException)1 Transactional (com.google.inject.persist.Transactional)1 IOException (java.io.IOException)1