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