use of org.openlca.core.database.FlowPropertyDao in project olca-modules by GreenDelta.
the class RefData method loadUnits.
/**
* Loads the units, unit groups and flow properties from the database. This
* method must be called after unit sheets where read.
*/
void loadUnits(IDatabase database) throws Exception {
UnitDao unitDao = new UnitDao(database);
load(unitDao, units);
load(new UnitGroupDao(database), unitGroups);
load(new FlowPropertyDao(database), flowProperties);
}
use of org.openlca.core.database.FlowPropertyDao in project olca-modules by GreenDelta.
the class FlowPropertyTest method testFlowProperty.
@Test
public void testFlowProperty() {
FlowPropertyDao dao = new FlowPropertyDao(Tests.getDb());
FlowProperty property = createModel(dao);
doExport(property, dao);
doImport(dao, property);
dao.delete(property);
}
use of org.openlca.core.database.FlowPropertyDao in project olca-modules by GreenDelta.
the class ProcessTest method createCyclicModel.
private Process[] createCyclicModel(IDatabase db) {
UnitGroup ug = createUnitGroup(new UnitGroupDao(db));
FlowProperty fp = createFlowProperty(ug, new FlowPropertyDao(db));
Flow product1 = createProduct(fp, new FlowDao(db));
Flow product2 = createProduct(fp, new FlowDao(db));
ProcessDao dao = new ProcessDao(db);
Process p1 = createProcess(product1, dao);
Process p2 = createProcess(product2, dao);
p1 = addProvider(p1, p2, dao);
p2 = addProvider(p2, p1, dao);
return new Process[] { p1, p2 };
}
use of org.openlca.core.database.FlowPropertyDao in project olca-modules by GreenDelta.
the class RefDataImport method loadUnitMaps.
private void loadUnitMaps(IDatabase database) throws Exception {
var is = getClass().getResourceAsStream("ei3_unit_map.csv");
if (is == null)
return;
try (var reader = new BufferedReader(new InputStreamReader(is))) {
String line;
while ((line = reader.readLine()) != null) {
String[] args = line.split(",");
String eiUnitKey = args[0];
UnitDao unitDao = new UnitDao(database);
Unit unit = unitDao.getForRefId(args[1]);
FlowPropertyDao propDao = new FlowPropertyDao(database);
FlowProperty prop = propDao.getForRefId(args[2]);
if (unit == null || prop == null)
log.warn("no unit or property found for '" + eiUnitKey + "' in database, no reference data?");
else {
index.putUnit(eiUnitKey, unit);
index.putFlowProperty(eiUnitKey, prop);
}
}
}
}
use of org.openlca.core.database.FlowPropertyDao in project olca-app by GreenDelta.
the class DBProvider method getFlowRefs.
@Override
public List<FlowRef> getFlowRefs() {
// collect categories, properties, locations
var categories = Categories.pathsOf(db);
Map<Long, FlowProperty> props = new FlowPropertyDao(db).getAll().stream().collect(Collectors.toMap(fp -> fp.id, fp -> fp));
Map<Long, String> locations = new LocationDao(db).getCodes();
List<FlowRef> refs = new ArrayList<>();
new FlowDao(db).getDescriptors().forEach(flow -> {
FlowRef ref = new FlowRef();
ref.flow = flow;
ref.flowCategory = categories.pathOf(flow.category);
ref.flowLocation = locations.get(flow.location);
Fn.with(props.get(flow.refFlowPropertyId), prop -> {
if (prop == null)
return;
ref.property = Descriptor.of(prop);
if (prop.unitGroup != null && prop.unitGroup.referenceUnit != null) {
ref.unit = Descriptor.of(prop.unitGroup.referenceUnit);
}
});
refs.add(ref);
});
return refs;
}
Aggregations