use of org.openlca.core.database.FlowDao in project olca-app by GreenDelta.
the class ReplaceFlowsDialog method okPressed.
@Override
protected void okPressed() {
FlowDescriptor oldFlow = selectionViewer.getSelected();
FlowDescriptor newFlow = replacementViewer.getSelected();
FlowDao dao = new FlowDao(Database.get());
boolean replaceFlows = replaceBothButton.getSelection() || replaceFlowsButton.getSelection();
boolean replaceImpacts = replaceBothButton.getSelection() || replaceImpactsButton.getSelection();
if (replaceFlows) {
if (excludeWithProviders.getSelection()) {
dao.replaceExchangeFlowsWithoutProviders(oldFlow.id, newFlow.id);
} else {
dao.replaceExchangeFlows(oldFlow.id, newFlow.id);
}
}
if (replaceImpacts) {
dao.replaceImpactFlows(oldFlow.id, newFlow.id);
}
Database.get().getEntityFactory().getCache().evictAll();
super.okPressed();
}
use of org.openlca.core.database.FlowDao in project olca-app by GreenDelta.
the class FactorClipboard method factor.
private ImpactFactor factor(String[] row) {
if (row.length < 4)
return null;
String name = row[0];
String category = row[1];
String amount = row[2];
String unit = row[3];
// filter the flows by matching names and categories
List<Flow> candidates = flows.stream().filter(d -> Strings.nullOrEqual(d.name, name)).map(d -> new FlowDao(db).getForId(d.id)).filter(flow -> {
if (flow.category == null)
return Strings.nullOrEmpty(category);
String path = CategoryPath.getFull(flow.category);
return Strings.nullOrEqual(path, category);
}).collect(Collectors.toList());
if (candidates.isEmpty())
return null;
// find a matching flow for the unit
// the unit in the table has the format:
// <LCIA ref. unit> / <flow unit>
// the following only works if the LCIA
// ref. unit does not contain a slash, but
// this should be very unlikely
int i = unit.indexOf('/');
if (i >= 0) {
unit = unit.substring(i + 1).trim();
}
ImpactFactor factor = new ImpactFactor();
for (Flow flow : candidates) {
for (FlowPropertyFactor p : flow.flowPropertyFactors) {
if (p.flowProperty == null || p.flowProperty.unitGroup == null)
continue;
Unit u = p.flowProperty.unitGroup.getUnit(unit);
if (u == null)
continue;
factor.flow = flow;
factor.flowPropertyFactor = p;
factor.unit = u;
if (Objects.equals(p.flowProperty, flow.referenceFlowProperty))
break;
}
if (factor.flow != null)
break;
}
if (factor.flow == null)
return null;
// set the amount value / formula
try {
factor.value = Double.parseDouble(amount);
} catch (Exception e) {
factor.formula = amount;
}
// uncertainty value
if (row.length > 4) {
factor.uncertainty = Uncertainty.fromString(row[4]);
}
// location
if (row.length > 5) {
String code = row[5];
if (!Strings.nullOrEmpty(code)) {
LocationDao dao = new LocationDao(db);
factor.location = dao.getDescriptors().stream().filter(d -> Strings.nullOrEqual(code, d.code)).map(d -> dao.getForId(d.id)).findFirst().orElse(null);
}
}
return factor;
}
use of org.openlca.core.database.FlowDao in project olca-app by GreenDelta.
the class ReplaceProvidersDialog method getProviders.
private List<ProcessDescriptor> getProviders(FlowDescriptor product) {
List<ProcessDescriptor> result = new ArrayList<>();
// TODO: search for processes and waste flows
FlowDao flowDao = new FlowDao(Database.get());
Set<Long> ids = flowDao.getWhereOutput(product.id);
ProcessDao processDao = new ProcessDao(Database.get());
result.addAll(processDao.getDescriptors(ids));
result.remove(processViewer.getSelected());
return result;
}
Aggregations