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();
});
}
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);
}
Aggregations