use of com.axelor.meta.db.repo.MetaFileRepository in project axelor-open-suite by axelor.
the class BpmDeploymentServiceImpl method addDmn.
protected void addDmn(DeploymentBuilder deploymentBuilder, Set<MetaFile> dmnFiles) {
MetaFileRepository metaFileRepo = Beans.get(MetaFileRepository.class);
for (MetaFile dmnFile : dmnFiles) {
dmnFile = metaFileRepo.find(dmnFile.getId());
deploymentBuilder.addModelInstance(dmnFile.getId() + ".dmn", Dmn.readModelFromFile(MetaFiles.getPath(dmnFile).toFile()));
}
}
use of com.axelor.meta.db.repo.MetaFileRepository 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