Search in sources :

Example 11 with XMLImporter

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

the class XMLImportTest method test.

@Test
public void test() throws FileNotFoundException {
    XMLImporter importer = new XMLImporter("data/xml-config.xml");
    Map<String, Object> context = new HashMap<>();
    context.put("LOCATION", "FR");
    context.put("DATE_FORMAT", "dd/MM/yyyy");
    importer.setContext(context);
    importer.run(new ImportTask() {

        @Override
        public void configure() throws IOException {
            input("contacts.xml", new File("data/xml/contacts.xml"));
            input("contacts.xml", new File("data/xml/contacts-non-unicode.xml"), Charset.forName("ISO-8859-15"));
        }

        @Override
        public boolean handle(ImportException exception) {
            System.err.println("Import error: " + exception);
            return true;
        }
    });
}
Also used : HashMap(java.util.HashMap) XMLImporter(com.axelor.data.xml.XMLImporter) IOException(java.io.IOException) File(java.io.File) 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