Search in sources :

Example 26 with Exchange

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);
}
Also used : Exchange(org.openlca.core.model.Exchange) ArrayList(java.util.ArrayList) Process(org.openlca.core.model.Process)

Example 27 with Exchange

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);
}
Also used : Exchange(org.openlca.core.model.Exchange) Process(org.openlca.core.model.Process)

Example 28 with Exchange

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);
}
Also used : Exchange(org.openlca.core.model.Exchange) Process(org.openlca.core.model.Process)

Example 29 with Exchange

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));
    }
}
Also used : Exchange(org.openlca.core.model.Exchange) ProcessDao(org.openlca.core.database.ProcessDao)

Example 30 with Exchange

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);
}
Also used : Exchange(org.openlca.core.model.Exchange) HashSet(java.util.HashSet)

Aggregations

Exchange (org.openlca.core.model.Exchange)90 Process (org.openlca.core.model.Process)21 ArrayList (java.util.ArrayList)15 Flow (org.openlca.core.model.Flow)14 Test (org.junit.Test)7 AllocationFactor (org.openlca.core.model.AllocationFactor)6 ProcessDao (org.openlca.core.database.ProcessDao)5 Parameter (org.openlca.core.model.Parameter)5 ProcessLink (org.openlca.core.model.ProcessLink)5 HashSet (java.util.HashSet)3 Uncertainty (org.openlca.core.model.Uncertainty)3 JsonObject (com.google.gson.JsonObject)2 HashMap (java.util.HashMap)2 List (java.util.List)2 M (org.openlca.app.M)2 Labels (org.openlca.app.util.Labels)2 MsgBox (org.openlca.app.util.MsgBox)2 FlowProperty (org.openlca.core.model.FlowProperty)2 FlowPropertyFactor (org.openlca.core.model.FlowPropertyFactor)2 IExchange (org.openlca.ecospold.IExchange)2