Search in sources :

Example 21 with IDatabase

use of org.openlca.core.database.IDatabase in project olca-app by GreenDelta.

the class EcoSpold2ImportWizard method createImport.

private EcoSpold2Import createImport() {
    File[] files = filePage.getFiles();
    IDatabase db = Database.get();
    if (files == null || files.length == 0 || db == null)
        return null;
    ImportConfig conf = new ImportConfig(db);
    if (App.runsInDevMode()) {
        conf.checkFormulas = true;
        conf.skipNullExchanges = true;
        conf.withParameterFormulas = false;
        conf.withParameters = false;
    }
    if (filePage.flowMap != null) {
        conf.setFlowMap(filePage.flowMap);
    }
    EcoSpold2Import pi = new EcoSpold2Import(conf);
    pi.setFiles(files);
    return pi;
}
Also used : IDatabase(org.openlca.core.database.IDatabase) ImportConfig(org.openlca.io.ecospold2.input.ImportConfig) EcoSpold2Import(org.openlca.io.ecospold2.input.EcoSpold2Import) File(java.io.File)

Example 22 with IDatabase

use of org.openlca.core.database.IDatabase in project olca-app by GreenDelta.

the class RcpActionBarAdvisor method runSpold2Import.

private void runSpold2Import(ModelType type) {
    IDatabase db = Database.get();
    if (db == null) {
        MsgBox.error("No database opened", "You need to open a database for the import");
        return;
    }
    File file = FileChooser.open("*.zip");
    if (file == null)
        return;
    File[] files = new File[] { file };
    Runnable imp = null;
    if (type == ModelType.IMPACT_METHOD) {
        imp = new MethodImport(files, db);
    } else if (type == ModelType.PROCESS) {
        ImportConfig conf = new ImportConfig(db);
        conf.checkFormulas = true;
        conf.skipNullExchanges = true;
        conf.withParameterFormulas = false;
        conf.withParameters = false;
        EcoSpold2Import imp_ = new EcoSpold2Import(conf);
        imp_.setFiles(files);
        imp = imp_;
    }
    if (imp == null)
        return;
    try {
        Database.getWorkspaceIdUpdater().beginTransaction();
        App.runWithProgress("Run import", imp);
    } catch (Exception e) {
        Logger log = LoggerFactory.getLogger(getClass());
        log.error("EcoSpold 2 import failed", e);
    } finally {
        Database.getWorkspaceIdUpdater().endTransaction();
        Navigator.refresh();
        Cache.evictAll();
    }
}
Also used : IDatabase(org.openlca.core.database.IDatabase) MethodImport(org.openlca.io.ecospold2.input.MethodImport) ImportConfig(org.openlca.io.ecospold2.input.ImportConfig) EcoSpold2Import(org.openlca.io.ecospold2.input.EcoSpold2Import) Logger(org.slf4j.Logger) File(java.io.File)

Example 23 with IDatabase

use of org.openlca.core.database.IDatabase in project olca-app by GreenDelta.

the class MySQLDatabaseExport method run.

@Override
public void run() {
    try {
        IDatabase sourceDb = config.connect(DataDir.databases());
        var targetDb = createTemporaryDb();
        DatabaseImport io = new DatabaseImport(sourceDb, targetDb);
        io.run();
        sourceDb.close();
        targetDb.close();
        ZipUtil.pack(targetDb.getDatabaseDirectory(), zolcaFile);
        FileUtils.deleteDirectory(targetDb.getDatabaseDirectory());
        success = true;
    } catch (Exception e) {
        success = false;
        ErrorReporter.on("failed export MySQL database as zolca-File", e);
    }
}
Also used : IDatabase(org.openlca.core.database.IDatabase) DatabaseImport(org.openlca.io.olca.DatabaseImport)

Example 24 with IDatabase

use of org.openlca.core.database.IDatabase in project olca-app by GreenDelta.

the class DeleteModelAction method delete.

@SuppressWarnings("unchecked")
private <T extends RootEntity> void delete(Descriptor d) {
    try {
        log.trace("delete model {}", d);
        IDatabase database = Database.get();
        Class<T> clazz = (Class<T>) d.type.getModelClass();
        BaseDao<T> dao = Daos.base(database, clazz);
        T instance = dao.getForId(d.id);
        dao.delete(instance);
        Cache.evict(d);
        DatabaseDir.deleteDir(d);
        log.trace("element deleted");
    } catch (Exception e) {
        ErrorReporter.on("failed to delete " + d, e);
    }
}
Also used : IDatabase(org.openlca.core.database.IDatabase)

Example 25 with IDatabase

use of org.openlca.core.database.IDatabase in project olca-app by GreenDelta.

the class XNexusIndexExportAction method run.

@Override
public void run() {
    IDatabase db = Database.get();
    if (db == null) {
        log.trace("no database activated");
        return;
    }
    String defaultName = db.getName() + "_nexus_index.json";
    File file = FileChooser.forSavingFile(M.Export, defaultName);
    if (file == null)
        return;
    App.run("Export Nexus index", new Runner(file, db));
}
Also used : IDatabase(org.openlca.core.database.IDatabase) File(java.io.File)

Aggregations

IDatabase (org.openlca.core.database.IDatabase)25 ProcessDao (org.openlca.core.database.ProcessDao)12 File (java.io.File)9 Process (org.openlca.core.model.Process)9 Test (org.junit.Test)8 Category (org.openlca.core.model.Category)4 Logger (org.slf4j.Logger)4 ArrayList (java.util.ArrayList)3 List (java.util.List)3 Collectors (java.util.stream.Collectors)3 FlowDao (org.openlca.core.database.FlowDao)3 ProcessDescriptor (org.openlca.core.model.descriptors.ProcessDescriptor)3 HashMap (java.util.HashMap)2 Map (java.util.Map)2 CategoryDao (org.openlca.core.database.CategoryDao)2 Derby (org.openlca.core.database.Derby)2 NativeSql (org.openlca.core.database.NativeSql)2 ParameterDao (org.openlca.core.database.ParameterDao)2 ProductSystemDao (org.openlca.core.database.ProductSystemDao)2 ProductSystemBuilder (org.openlca.core.matrix.ProductSystemBuilder)2