Search in sources :

Example 16 with FlowPropertyDao

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);
}
Also used : FlowPropertyDao(org.openlca.core.database.FlowPropertyDao) UnitDao(org.openlca.core.database.UnitDao) UnitGroupDao(org.openlca.core.database.UnitGroupDao)

Example 17 with FlowPropertyDao

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);
}
Also used : FlowPropertyDao(org.openlca.core.database.FlowPropertyDao) FlowProperty(org.openlca.core.model.FlowProperty) AbstractZipTest(org.openlca.jsonld.AbstractZipTest) Test(org.junit.Test)

Example 18 with FlowPropertyDao

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 };
}
Also used : UnitGroup(org.openlca.core.model.UnitGroup) FlowDao(org.openlca.core.database.FlowDao) FlowPropertyDao(org.openlca.core.database.FlowPropertyDao) ProcessDao(org.openlca.core.database.ProcessDao) Process(org.openlca.core.model.Process) UnitGroupDao(org.openlca.core.database.UnitGroupDao) FlowProperty(org.openlca.core.model.FlowProperty) Flow(org.openlca.core.model.Flow)

Example 19 with FlowPropertyDao

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);
            }
        }
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) FlowPropertyDao(org.openlca.core.database.FlowPropertyDao) BufferedReader(java.io.BufferedReader) UnitDao(org.openlca.core.database.UnitDao) Unit(org.openlca.core.model.Unit) FlowProperty(org.openlca.core.model.FlowProperty)

Example 20 with FlowPropertyDao

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;
}
Also used : FlowType(org.openlca.core.model.FlowType) Descriptor(org.openlca.core.model.descriptors.Descriptor) Categories(org.openlca.util.Categories) Fn(org.openlca.app.util.Fn) FlowPropertyDao(org.openlca.core.database.FlowPropertyDao) Process(org.openlca.core.model.Process) ProcessDao(org.openlca.core.database.ProcessDao) Unit(org.openlca.core.model.Unit) Collectors(java.util.stream.Collectors) FlowRef(org.openlca.io.maps.FlowRef) ArrayList(java.util.ArrayList) Flow(org.openlca.core.model.Flow) FlowPropertyFactor(org.openlca.core.model.FlowPropertyFactor) Objects(java.util.Objects) LocationDao(org.openlca.core.database.LocationDao) List(java.util.List) Stream(java.util.stream.Stream) IDatabase(org.openlca.core.database.IDatabase) Map(java.util.Map) FlowDao(org.openlca.core.database.FlowDao) FlowProperty(org.openlca.core.model.FlowProperty) MappingStatus(org.openlca.io.maps.MappingStatus) FlowPropertyDao(org.openlca.core.database.FlowPropertyDao) ArrayList(java.util.ArrayList) LocationDao(org.openlca.core.database.LocationDao) FlowRef(org.openlca.io.maps.FlowRef) FlowDao(org.openlca.core.database.FlowDao) FlowProperty(org.openlca.core.model.FlowProperty)

Aggregations

FlowPropertyDao (org.openlca.core.database.FlowPropertyDao)20 FlowProperty (org.openlca.core.model.FlowProperty)14 FlowDao (org.openlca.core.database.FlowDao)7 UnitGroupDao (org.openlca.core.database.UnitGroupDao)7 ProcessDao (org.openlca.core.database.ProcessDao)5 Flow (org.openlca.core.model.Flow)5 Unit (org.openlca.core.model.Unit)5 UnitGroup (org.openlca.core.model.UnitGroup)5 IDatabase (org.openlca.core.database.IDatabase)3 UnitDao (org.openlca.core.database.UnitDao)3 Process (org.openlca.core.model.Process)3 ArrayList (java.util.ArrayList)2 After (org.junit.After)2 Before (org.junit.Before)2 Test (org.junit.Test)2 CategoryDao (org.openlca.core.database.CategoryDao)2 LocationDao (org.openlca.core.database.LocationDao)2 ProductSystemDao (org.openlca.core.database.ProductSystemDao)2 FlowPropertyFactor (org.openlca.core.model.FlowPropertyFactor)2 FlowType (org.openlca.core.model.FlowType)2