use of com.axelor.data.xml.XMLImporter in project axelor-open-suite by axelor.
the class WkfModelServiceImpl method importStandardBPM.
@Override
public void importStandardBPM() {
List<App> appList = Beans.get(AppRepository.class).all().filter("self.active = true").fetch();
if (CollectionUtils.isEmpty(appList)) {
return;
}
String configFileName = "/data-import/import-wkf-models.xml";
File configFile = null;
try {
configFile = File.createTempFile("config", ".xml");
FileOutputStream fout = new FileOutputStream(configFile);
InputStream inputStream = this.getClass().getResourceAsStream(configFileName);
IOUtil.copyCompletely(inputStream, fout);
} catch (Exception e) {
TraceBackService.trace(e);
}
if (configFile == null) {
return;
}
try {
String dataFileName = "/data-wkf-models/input/";
File tempDir = Files.createTempDir();
File dataFile = new File(tempDir, "wkfModels.xml");
XMLImporter importer = getXMLImpoter(configFile.getAbsolutePath(), tempDir.getAbsolutePath());
for (App app : appList) {
String fileName = dataFileName + app.getCode() + ".xml";
InputStream dataInputStream = this.getClass().getResourceAsStream(fileName);
if (dataInputStream == null) {
continue;
}
FileOutputStream fout = new FileOutputStream(dataFile);
IOUtil.copyCompletely(dataInputStream, fout);
importer.run();
}
} catch (Exception e) {
TraceBackService.trace(e);
}
}
use of com.axelor.data.xml.XMLImporter 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.data.xml.XMLImporter 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.data.xml.XMLImporter 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.data.xml.XMLImporter in project axelor-open-suite by axelor.
the class WkfModelServiceImpl method importWkfModels.
@Override
public String importWkfModels(MetaFile metaFile, boolean isTranslate, String sourceLanguage, String targetLanguage) throws AxelorException {
if (metaFile == null) {
return null;
}
String extension = Files.getFileExtension(metaFile.getFileName());
if (extension == null || !extension.equals("xml")) {
throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(ITranslation.INVALID_WKF_MODEL_XML));
}
try {
InputStream inputStream = getClass().getResourceAsStream(IMPORT_CONFIG_PATH);
File configFile = File.createTempFile("config", ".xml");
FileOutputStream fout = new FileOutputStream(configFile);
IOUtil.copyCompletely(inputStream, fout);
File xmlFile = MetaFiles.getPath(metaFile).toFile();
File tempDir = Files.createTempDir();
File importFile = new File(tempDir, "wkfModels.xml");
Files.copy(xmlFile, importFile);
if (isTranslate) {
importFile = this.translateNodeName(importFile, sourceLanguage, targetLanguage);
}
XMLImporter importer = new XMLImporter(configFile.getAbsolutePath(), tempDir.getAbsolutePath());
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);
importer.run();
FileUtils.forceDelete(configFile);
FileUtils.forceDelete(tempDir);
FileUtils.forceDelete(xmlFile);
MetaFileRepository metaFileRepository = Beans.get(MetaFileRepository.class);
metaFileRepository.remove(metaFile);
return log.toString();
} catch (Exception e) {
return e.getMessage();
}
}
Aggregations