use of org.openlca.core.model.Exchange in project olca-modules by GreenDelta.
the class ProcessTest method assertTestCyclicProvider.
private void assertTestCyclicProvider(Process[] processes, ProcessDao dao) {
List<Process> clones = new ArrayList<>();
for (int i = 0; i < processes.length; i++) {
Process process = processes[i];
Assert.assertTrue(dao.contains(process.refId));
Process clone = dao.getForRefId(process.refId);
Assert.assertEquals(process.name, clone.name);
Assert.assertNotEquals(process.id, clone.id);
clones.add(i, clone);
}
Exchange in = null;
for (Exchange e : clones.get(1).exchanges) {
if (e.isInput) {
in = e;
}
}
Assert.assertNotNull(in);
Assert.assertEquals(clones.get(0).id, in.defaultProviderId);
for (Exchange e : clones.get(0).exchanges) if (e.isInput)
in = e;
Assert.assertEquals(clones.get(1).id, in.defaultProviderId);
}
use of org.openlca.core.model.Exchange in project olca-modules by GreenDelta.
the class ProcessTest method createProcess.
private Process createProcess(Flow product, ProcessDao dao) {
Process p = new Process();
p.name = "process";
p.refId = UUID.randomUUID().toString();
Exchange out = createExchange(p, product, null);
out.isInput = false;
p.exchanges.add(out);
p.quantitativeReference = out;
return dao.insert(p);
}
use of org.openlca.core.model.Exchange in project olca-modules by GreenDelta.
the class ExchangeCostTest method checkImport.
private void checkImport(Process originalProc) {
Process importedProc = processDao.getForRefId(originalProc.refId);
Exchange original = originalProc.exchanges.get(0);
Exchange imported = importedProc.exchanges.get(0);
Assert.assertEquals(original.costs, imported.costs);
}
use of org.openlca.core.model.Exchange in project olca-modules by GreenDelta.
the class ProcessWriter method map.
private void map(Exchange e, JsonObject obj) {
Json.put(obj, "@type", Exchange.class.getSimpleName());
Json.put(obj, "isAvoidedProduct", e.isAvoided);
Json.put(obj, "isInput", e.isInput);
Json.put(obj, "baseUncertainty", e.baseUncertainty);
Json.put(obj, "amount", e.amount);
Json.put(obj, "amountFormula", e.formula);
Json.put(obj, "dqEntry", e.dqEntry);
Json.put(obj, "description", e.description);
Json.put(obj, "costFormula", e.costFormula);
Json.put(obj, "costValue", e.costs);
Json.put(obj, "currency", exp.handleRef(e.currency));
Json.put(obj, "internalId", e.internalId);
Json.put(obj, "location", exp.handleRef(e.location));
Json.put(obj, "flow", exp.handleRef(e.flow));
Json.put(obj, "unit", Json.asRef(e.unit));
var property = e.flowPropertyFactor != null ? e.flowPropertyFactor.flowProperty : null;
Json.put(obj, "flowProperty", exp.handleRef(property));
Json.put(obj, "uncertainty", Uncertainties.map(e.uncertainty));
// default provider
if (e.defaultProviderId == 0L || exp.db == null)
return;
if (exp.exportProviders) {
Json.put(obj, "defaultProvider", exp.handleRef(ModelType.PROCESS, e.defaultProviderId));
} else {
var d = new ProcessDao(exp.db).getDescriptor(e.defaultProviderId);
Json.put(obj, "defaultProvider", Json.asRef(d));
}
}
use of org.openlca.core.model.Exchange in project olca-modules by GreenDelta.
the class GlobalParameters method sync.
/**
* Exports global parameters that are referenced from the formulas in the given
* process if necessary.
*/
public static void sync(Process p, JsonExport exp) {
if (skipSync(exp))
return;
var names = new HashSet<String>();
for (Exchange e : p.exchanges) {
names.addAll(Formula.getVariables(e.formula));
names.addAll(Formula.getVariables(e.costFormula));
names.addAll(variablesOf(e.uncertainty));
}
names.addAll(variablesOf(p.parameters));
filterLocals(names, p.parameters);
writeGlobals(names, exp);
}
Aggregations