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;
}
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();
}
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;
}
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();
}
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();
}
Aggregations