Search in sources :

Example 26 with FlowPropertyFactor

use of org.openlca.core.model.FlowPropertyFactor in project olca-modules by GreenDelta.

the class ProductSystemReferenceSearchTest method createFlow.

private Flow createFlow(boolean reference) {
    if (!reference)
        return insertAndAddExpected("flowId", new Flow());
    Flow flow = new Flow();
    FlowProperty property = new FlowProperty();
    FlowPropertyFactor factor = new FlowPropertyFactor();
    factor.flowProperty = property;
    UnitGroup group = new UnitGroup();
    Unit unit = new Unit();
    unit.name = "unit";
    group.units.add(unit);
    property.unitGroup = group;
    flow.flowPropertyFactors.add(factor);
    group = db.insert(group);
    addExpected("targetUnit", group.getUnit(unit.name));
    property = db.insert(property);
    flow = db.insert(flow);
    addExpected("targetFlowPropertyFactor", flow.getFactor(property));
    return flow;
}
Also used : UnitGroup(org.openlca.core.model.UnitGroup) FlowPropertyFactor(org.openlca.core.model.FlowPropertyFactor) Unit(org.openlca.core.model.Unit) FlowProperty(org.openlca.core.model.FlowProperty) Flow(org.openlca.core.model.Flow)

Example 27 with FlowPropertyFactor

use of org.openlca.core.model.FlowPropertyFactor in project olca-modules by GreenDelta.

the class FlowPropertyUseSearchTest method setUp.

@Before
public void setUp() {
    unused = db.insert(new FlowProperty());
    used = db.insert(new FlowProperty());
    unitGroup = new UnitGroup();
    unitGroup.defaultFlowProperty = used;
    unitGroup = db.insert(unitGroup);
    flow = new Flow();
    var fac = new FlowPropertyFactor();
    fac.flowProperty = used;
    flow.flowPropertyFactors.add(fac);
    flow = db.insert(flow);
}
Also used : UnitGroup(org.openlca.core.model.UnitGroup) FlowPropertyFactor(org.openlca.core.model.FlowPropertyFactor) FlowProperty(org.openlca.core.model.FlowProperty) Flow(org.openlca.core.model.Flow) Before(org.junit.Before)

Example 28 with FlowPropertyFactor

use of org.openlca.core.model.FlowPropertyFactor in project olca-modules by GreenDelta.

the class IdGeneratorTest method testCascadeId.

@Test
public void testCascadeId() {
    IDatabase database = Tests.getDb();
    Flow flow = new Flow();
    FlowPropertyFactor factor1 = new FlowPropertyFactor();
    flow.flowPropertyFactors.add(factor1);
    Assert.assertEquals(0L, factor1.id);
    // when inserting an entity we use persist -> EclipseLink directly
    // generates an ID for cascade objects
    new FlowDao(database).insert(flow);
    // new ID
    Assert.assertTrue(factor1.id > 0L);
    FlowPropertyFactor factor2 = new FlowPropertyFactor();
    flow.flowPropertyFactors.add(factor2);
    Assert.assertEquals(0L, factor2.id);
    // when updating an entity we use merge -> EclipseLink does not
    // manipulates the original object graph
    Flow managedFlow = new FlowDao(database).update(flow);
    // still no ID set
    Assert.assertEquals(0L, factor2.id);
    // for the managed flow has generated IDs for the cascade objects
    int count = 0;
    for (FlowPropertyFactor f : managedFlow.flowPropertyFactors) {
        Assert.assertTrue(f.id > 0L);
        count++;
    }
    Assert.assertTrue(count == 2);
}
Also used : FlowPropertyFactor(org.openlca.core.model.FlowPropertyFactor) Flow(org.openlca.core.model.Flow) Test(org.junit.Test)

Example 29 with FlowPropertyFactor

use of org.openlca.core.model.FlowPropertyFactor in project olca-modules by GreenDelta.

the class ImpactMethodExport method getRefAmount.

private double getRefAmount(ImpactFactor factor) {
    double val = factor.value;
    Unit unit = factor.unit;
    if (unit != null)
        val = val / unit.conversionFactor;
    FlowPropertyFactor propFactor = factor.flowPropertyFactor;
    if (propFactor != null)
        val = val * propFactor.conversionFactor;
    return val;
}
Also used : Unit(org.openlca.core.model.Unit) FlowPropertyFactor(org.openlca.core.model.FlowPropertyFactor)

Example 30 with FlowPropertyFactor

use of org.openlca.core.model.FlowPropertyFactor in project olca-modules by GreenDelta.

the class FlowPropertyFactorExport method doIt.

@Override
protected void doIt(CSVPrinter printer, IDatabase db) throws IOException {
    log.trace("write flow property factors");
    FlowDao dao = new FlowDao(db);
    int count = 0;
    for (Flow flow : dao.getAll()) {
        for (FlowPropertyFactor factor : flow.flowPropertyFactors) {
            Object[] line = createLine(flow, factor);
            printer.printRecord(line);
            count++;
        }
    }
    log.trace("{} flow property factors written", count);
}
Also used : FlowDao(org.openlca.core.database.FlowDao) FlowPropertyFactor(org.openlca.core.model.FlowPropertyFactor) Flow(org.openlca.core.model.Flow)

Aggregations

FlowPropertyFactor (org.openlca.core.model.FlowPropertyFactor)36 Flow (org.openlca.core.model.Flow)21 FlowProperty (org.openlca.core.model.FlowProperty)17 Unit (org.openlca.core.model.Unit)11 FlowDao (org.openlca.core.database.FlowDao)9 UnitGroup (org.openlca.core.model.UnitGroup)6 ArrayList (java.util.ArrayList)4 ImpactFactor (org.openlca.core.model.ImpactFactor)3 Collections (java.util.Collections)2 List (java.util.List)2 Objects (java.util.Objects)2 Before (org.junit.Before)2 Test (org.junit.Test)2 M (org.openlca.app.M)2 Category (org.openlca.core.model.Category)2 Exchange (org.openlca.core.model.Exchange)2 Uncertainty (org.openlca.core.model.Uncertainty)2 UnitMappingEntry (org.openlca.io.UnitMappingEntry)2 Strings (org.openlca.util.Strings)2 SQLException (java.sql.SQLException)1