Search in sources :

Example 1 with DBProvider

use of org.openlca.app.tools.mapping.model.DBProvider in project olca-app by GreenDelta.

the class MappingMenu method onApply.

private void onApply() {
    MappingTool tool = Editors.getActive();
    if (tool == null || tool.mapping == null)
        return;
    // check if we can apply the mapping
    IProvider source = tool.sourceSystem;
    if (!(source instanceof DBProvider)) {
        MsgBox.error("Source system should be a database", "This only works when the source system " + "is a database where the flows should " + "be replaced with flows from the target " + "system (which could be the same database).");
        return;
    }
    IProvider target = tool.targetSystem;
    if (target == null) {
        MsgBox.error("No target system selected", "No target system was selected.");
        return;
    }
    if (!tool.checked.get()) {
        MsgBox.error("Unchecked mappings", "You should first run a check before applying the mapping.");
        return;
    }
    Optional<ReplacerConfig> opt = ReplacerDialog.open(tool.mapping, target);
    if (!opt.isPresent())
        return;
    Replacer replacer = new Replacer(opt.get());
    App.runWithProgress("Replace flows ...", replacer, () -> {
        tool.refresh();
        Navigator.refresh();
    });
}
Also used : IProvider(org.openlca.app.tools.mapping.model.IProvider) DBProvider(org.openlca.app.tools.mapping.model.DBProvider) Replacer(org.openlca.app.tools.mapping.replacer.Replacer) ReplacerConfig(org.openlca.app.tools.mapping.replacer.ReplacerConfig)

Example 2 with DBProvider

use of org.openlca.app.tools.mapping.model.DBProvider in project olca-app by GreenDelta.

the class Replacer method buildIndices.

private void buildIndices() {
    // first persist all target flows in the database that
    // do not have an error flag
    List<FlowRef> targetFlows = conf.mapping.entries.stream().filter(e -> e.targetFlow() != null && e.targetFlow().status != null && !e.targetFlow().status.isError()).map(FlowMapEntry::targetFlow).collect(Collectors.toList());
    conf.provider.persist(targetFlows, db);
    DBProvider dbProvider = new DBProvider(db);
    for (FlowMapEntry e : conf.mapping.entries) {
        // (both flows should have no error flag)
        if (e.sourceFlow() == null || e.sourceFlow().status == null || e.sourceFlow().status.isError() || e.targetFlow() == null || e.targetFlow().status == null || e.targetFlow().status.isError())
            continue;
        // sync the flows
        Flow source = dbProvider.sync(e.sourceFlow());
        if (source == null)
            continue;
        Flow target = dbProvider.sync(e.targetFlow());
        if (target == null)
            continue;
        entries.put(source.id, e);
        flows.put(source.id, source);
        flows.put(target.id, target);
    }
    factors = new FactorProvider(db, flows);
}
Also used : FlowRef(org.openlca.io.maps.FlowRef) FlowMapEntry(org.openlca.io.maps.FlowMapEntry) DBProvider(org.openlca.app.tools.mapping.model.DBProvider) Flow(org.openlca.core.model.Flow)

Aggregations

DBProvider (org.openlca.app.tools.mapping.model.DBProvider)2 IProvider (org.openlca.app.tools.mapping.model.IProvider)1 Replacer (org.openlca.app.tools.mapping.replacer.Replacer)1 ReplacerConfig (org.openlca.app.tools.mapping.replacer.ReplacerConfig)1 Flow (org.openlca.core.model.Flow)1 FlowMapEntry (org.openlca.io.maps.FlowMapEntry)1 FlowRef (org.openlca.io.maps.FlowRef)1