Search in sources :

Example 1 with MetaFileRepository

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()));
    }
}
Also used : MetaFileRepository(com.axelor.meta.db.repo.MetaFileRepository) MetaFile(com.axelor.meta.db.MetaFile)

Example 2 with MetaFileRepository

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();
    }
}
Also used : AxelorException(com.axelor.exception.AxelorException) MetaFileRepository(com.axelor.meta.db.repo.MetaFileRepository) Listener(com.axelor.data.Listener) InputStream(java.io.InputStream) FileOutputStream(java.io.FileOutputStream) WkfModel(com.axelor.apps.bpm.db.WkfModel) MetaModel(com.axelor.meta.db.MetaModel) Model(com.axelor.db.Model) XMLImporter(com.axelor.data.xml.XMLImporter) File(java.io.File) MetaFile(com.axelor.meta.db.MetaFile) AxelorException(com.axelor.exception.AxelorException)

Aggregations

MetaFile (com.axelor.meta.db.MetaFile)2 MetaFileRepository (com.axelor.meta.db.repo.MetaFileRepository)2 WkfModel (com.axelor.apps.bpm.db.WkfModel)1 Listener (com.axelor.data.Listener)1 XMLImporter (com.axelor.data.xml.XMLImporter)1 Model (com.axelor.db.Model)1 AxelorException (com.axelor.exception.AxelorException)1 MetaModel (com.axelor.meta.db.MetaModel)1 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 InputStream (java.io.InputStream)1