Search in sources :

Example 1 with Exchange

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

the class ProcessReferenceSearchTest method createModel.

@Override
protected Process createModel() {
    Process process = new Process();
    process.category = insertAndAddExpected("category", new Category());
    process.location = insertAndAddExpected("location", new Location());
    process.dqSystem = insertAndAddExpected("dqSystem", new DQSystem());
    process.exchangeDqSystem = insertAndAddExpected("exchangeDqSystem", new DQSystem());
    process.socialDqSystem = insertAndAddExpected("socialDqSystem", new DQSystem());
    String n1 = generateName();
    String n2 = generateName();
    String n3 = generateName();
    String n4 = generateName();
    String n5 = generateName();
    createExchange(process, 3d, true);
    createExchange(process, "2*" + n4, false);
    process.parameters.add(createParameter(n1, 3d, false));
    process.parameters.add(createParameter(n2, n1 + "*2*" + n3, false));
    process.socialAspects.add(createSocialAspect());
    process.socialAspects.add(createSocialAspect());
    process.documentation = createDocumentation();
    insertAndAddExpected(n3, createParameter(n3, "5*5", true));
    // formula with parameter to see if added as reference (unexpected)
    insertAndAddExpected(n4, createParameter(n4, "3*" + n5, true));
    Parameter globalUnreferenced = createParameter(n1, "3*3", true);
    Parameter globalUnreferenced2 = createParameter(n5, "3*3", true);
    // must be inserted manually
    globalUnreferenced = db.insert(globalUnreferenced);
    globalUnreferenced2 = db.insert(globalUnreferenced2);
    process = db.insert(process);
    for (Exchange e : process.exchanges) {
        addExpected("flow", e.flow, "exchanges", Exchange.class, e.id);
        addExpected("flowPropertyFactor", e.flowPropertyFactor, "exchanges", Exchange.class, e.id);
        addExpected("flowProperty", e.flowPropertyFactor.flowProperty, "flowPropertyFactor", FlowPropertyFactor.class, e.flowPropertyFactor.id);
        addExpected("unit", e.unit, "exchanges", Exchange.class, e.id);
        Process provider = processes.get(e.defaultProviderId);
        if (provider != null)
            addExpected("defaultProviderId", provider, "exchanges", Exchange.class, e.id);
    }
    for (SocialAspect a : process.socialAspects) {
        addExpected("indicator", a.indicator, "socialAspects", SocialAspect.class, a.id);
        addExpected("source", a.source, "socialAspects", SocialAspect.class, a.id);
    }
    ProcessDocumentation doc = process.documentation;
    addExpected("dataDocumentor", doc.dataDocumentor, "documentation", ProcessDocumentation.class, doc.id);
    addExpected("dataGenerator", doc.dataGenerator, "documentation", ProcessDocumentation.class, doc.id);
    addExpected("dataSetOwner", doc.dataSetOwner, "documentation", ProcessDocumentation.class, doc.id);
    addExpected("reviewer", doc.reviewer, "documentation", ProcessDocumentation.class, doc.id);
    addExpected("publication", doc.publication, "documentation", ProcessDocumentation.class, doc.id);
    for (Source s : process.documentation.sources) addExpected("sources", s, "documentation", ProcessDocumentation.class, doc.id);
    return process;
}
Also used : Exchange(org.openlca.core.model.Exchange) Category(org.openlca.core.model.Category) SocialAspect(org.openlca.core.model.SocialAspect) DQSystem(org.openlca.core.model.DQSystem) Parameter(org.openlca.core.model.Parameter) Process(org.openlca.core.model.Process) ProcessDocumentation(org.openlca.core.model.ProcessDocumentation) Source(org.openlca.core.model.Source) Location(org.openlca.core.model.Location)

Example 2 with Exchange

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

the class ProductSystemReferenceSearchTest method createLink.

private ProcessLink createLink(Process p1, Process p2) {
    ProcessLink link = new ProcessLink();
    Flow flow = createFlow(false);
    Exchange e1 = new Exchange();
    e1.flow = flow;
    p1.exchanges.add(e1);
    Exchange e2 = new Exchange();
    e2.flow = flow;
    p2.exchanges.add(e2);
    link.processId = p1.id;
    link.providerId = p2.id;
    link.flowId = flow.id;
    addExpected("processId", p1);
    addExpected("providerId", p2);
    addExpected("exchangeId", e1);
    return link;
}
Also used : Exchange(org.openlca.core.model.Exchange) ProcessLink(org.openlca.core.model.ProcessLink) Flow(org.openlca.core.model.Flow)

Example 3 with Exchange

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

the class TestProcess method addCosts.

public TestProcess addCosts(String flow, double amount, String currency) {
    for (Exchange e : process.exchanges) {
        Flow f = e.flow;
        if (f == null || !Strings.nullOrEqual(f.name, flow))
            continue;
        e.currency = TestData.currency(currency);
        e.costs = amount;
        break;
    }
    return this;
}
Also used : Exchange(org.openlca.core.model.Exchange) Flow(org.openlca.core.model.Flow)

Example 4 with Exchange

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

the class TestProcess method alloc.

/**
 * Adds an economic or physical allocation factor with a formula for the
 * given flow and method to the process. Use this method *after* the
 * exchanges are added.
 */
public TestProcess alloc(String flow, AllocationMethod method, String formula) {
    AllocationFactor f = new AllocationFactor();
    f.method = method;
    Exchange e = findExchange(process, flow);
    f.productId = e.flow.id;
    f.formula = formula;
    process.allocationFactors.add(f);
    return this;
}
Also used : Exchange(org.openlca.core.model.Exchange) AllocationFactor(org.openlca.core.model.AllocationFactor)

Example 5 with Exchange

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

the class TestSystem method link.

public TestSystem link(Process process) {
    if (processes.contains(process))
        return this;
    index(process);
    for (Process p : processes) {
        for (Exchange e : p.exchanges) {
            if (isProvider(e))
                continue;
            if (e.flow == null || e.flow.flowType == FlowType.ELEMENTARY_FLOW)
                continue;
            long flowId = e.flow.id;
            Process provider = providers.get(flowId);
            if (provider == null)
                continue;
            ProcessLink link = new ProcessLink();
            link.providerId = provider.id;
            link.flowId = flowId;
            link.processId = p.id;
            link.exchangeId = e.id;
            if (!system.processLinks.contains(link)) {
                system.processLinks.add(link);
            }
        }
    }
    return this;
}
Also used : Exchange(org.openlca.core.model.Exchange) ProcessLink(org.openlca.core.model.ProcessLink) Process(org.openlca.core.model.Process)

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