Search in sources :

Example 6 with XMLImporter

use of com.axelor.data.xml.XMLImporter in project axelor-open-suite by axelor.

the class WkfModelServiceImpl method getXMLImpoter.

protected XMLImporter getXMLImpoter(String configFile, String dataFile) {
    XMLImporter importer = new XMLImporter(configFile, dataFile);
    final StringBuilder log = new StringBuilder();
    Listener listner = new Listener() {

        @Override
        public void imported(Integer imported, Integer total) {
        }

        @Override
        public void imported(Model arg0) {
        }

        @Override
        public void handle(Model arg0, Exception err) {
            log.append("Error in import: " + err.getStackTrace().toString());
        }
    };
    importer.addListener(listner);
    return importer;
}
Also used : Listener(com.axelor.data.Listener) WkfModel(com.axelor.apps.bpm.db.WkfModel) MetaModel(com.axelor.meta.db.MetaModel) Model(com.axelor.db.Model) XMLImporter(com.axelor.data.xml.XMLImporter) AxelorException(com.axelor.exception.AxelorException)

Example 7 with XMLImporter

use of com.axelor.data.xml.XMLImporter in project axelor-open-suite by axelor.

the class ConfiguratorCreatorImportServiceImpl method importConfiguratorCreators.

@Transactional(rollbackOn = { Exception.class })
@Override
public String importConfiguratorCreators(InputStream xmlInputStream, String configFilePath) throws IOException {
    InputStream inputStream = this.getClass().getResourceAsStream(configFilePath);
    File configFile = File.createTempFile("config", ".xml");
    FileOutputStream fout = new FileOutputStream(configFile);
    IOUtil.copyCompletely(inputStream, fout);
    File tempDir = Files.createTempDir();
    File importFile = new File(tempDir, "configurator-creator.xml");
    FileUtils.copyInputStreamToFile(xmlInputStream, importFile);
    XMLImporter importer = new XMLImporter(configFile.getAbsolutePath(), tempDir.getAbsolutePath());
    final StringBuilder importLog = new StringBuilder();
    Listener listener = new Listener() {

        @Override
        public void imported(Integer imported, Integer total) {
            importLog.append("Total records: " + total + ", Total imported: " + total);
        }

        @Override
        public void imported(Model arg0) {
            try {
                completeAfterImport(arg0);
            } catch (AxelorException e) {
                importLog.append("Error in import: " + Arrays.toString(e.getStackTrace()));
            }
        }

        @Override
        public void handle(Model arg0, Exception err) {
            importLog.append("Error in import: " + Arrays.toString(err.getStackTrace()));
        }
    };
    importer.addListener(listener);
    importer.run();
    FileUtils.forceDelete(configFile);
    FileUtils.forceDelete(tempDir);
    return importLog.toString();
}
Also used : AxelorException(com.axelor.exception.AxelorException) Listener(com.axelor.data.Listener) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) FileOutputStream(java.io.FileOutputStream) Model(com.axelor.db.Model) XMLImporter(com.axelor.data.xml.XMLImporter) File(java.io.File) AxelorException(com.axelor.exception.AxelorException) IOException(java.io.IOException) Transactional(com.google.inject.persist.Transactional)

Example 8 with XMLImporter

use of com.axelor.data.xml.XMLImporter in project axelor-open-suite by axelor.

the class AppLoaderImportServiceImpl method importApp.

protected File importApp(AppLoader appLoader, File dataDir) throws IOException, FileNotFoundException {
    File logFile = appLoader.getImportLog() != null ? MetaFiles.getPath(appLoader.getImportLog()).toFile() : MetaFiles.createTempFile("import-", "log").toFile();
    PrintWriter pw = new PrintWriter(logFile);
    for (File confiFile : getAppImportConfigFiles(dataDir)) {
        XMLImporter xmlImporter = new XMLImporter(confiFile.getAbsolutePath(), dataDir.getAbsolutePath());
        xmlImporter.setContext(getImportContext(appLoader));
        xmlImporter.addListener(new Listener() {

            @Override
            public void imported(Integer total, Integer success) {
            }

            @Override
            public void imported(Model bean) {
            }

            @Override
            public void handle(Model bean, Exception e) {
                pw.write("Error Importing: " + bean);
                e.printStackTrace(pw);
            }
        });
        xmlImporter.run();
    }
    pw.flush();
    pw.close();
    return logFile;
}
Also used : Listener(com.axelor.data.Listener) Model(com.axelor.db.Model) XMLImporter(com.axelor.data.xml.XMLImporter) File(java.io.File) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) PrintWriter(java.io.PrintWriter)

Example 9 with XMLImporter

use of com.axelor.data.xml.XMLImporter in project open-platform-demo by axelor.

the class XMLDataTest method testDefault.

@Test
public void testDefault() throws IOException {
    Importer importer = new XMLImporter("data/xml-config.xml", "data/xml");
    importer.run();
}
Also used : XMLImporter(com.axelor.data.xml.XMLImporter) XMLImporter(com.axelor.data.xml.XMLImporter) Test(org.junit.jupiter.api.Test)

Example 10 with XMLImporter

use of com.axelor.data.xml.XMLImporter in project open-platform-demo by axelor.

the class XMLDataTest method testTypes.

@Test
public void testTypes() throws IOException {
    Importer importer = new XMLImporter("data/xml-config-types.xml", "data/xml");
    importer.run();
}
Also used : XMLImporter(com.axelor.data.xml.XMLImporter) XMLImporter(com.axelor.data.xml.XMLImporter) Test(org.junit.jupiter.api.Test)

Aggregations

XMLImporter (com.axelor.data.xml.XMLImporter)11 File (java.io.File)7 AxelorException (com.axelor.exception.AxelorException)5 FileOutputStream (java.io.FileOutputStream)5 InputStream (java.io.InputStream)5 Listener (com.axelor.data.Listener)4 Model (com.axelor.db.Model)4 IOException (java.io.IOException)4 ImporterListener (com.axelor.apps.base.service.imports.listener.ImporterListener)3 MetaFile (com.axelor.meta.db.MetaFile)3 Test (org.junit.jupiter.api.Test)3 WkfModel (com.axelor.apps.bpm.db.WkfModel)2 MetaModel (com.axelor.meta.db.MetaModel)2 Transactional (com.google.inject.persist.Transactional)2 Path (java.nio.file.Path)2 Map (java.util.Map)2 App (com.axelor.apps.base.db.App)1 AppRepository (com.axelor.apps.base.db.repo.AppRepository)1 MetaFileRepository (com.axelor.meta.db.repo.MetaFileRepository)1 FileInputStream (java.io.FileInputStream)1