Search in sources :

Example 1 with ParameterRedef

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

the class ProductSystemReferenceSearchTest method createParameterRedef.

private ParameterRedef createParameterRedef(String name, Object contextOrValue) {
    ParameterRedef redef = new ParameterRedef();
    redef.name = name;
    redef.value = 1d;
    if (contextOrValue instanceof Long) {
        redef.contextType = ModelType.PROCESS;
        redef.contextId = (long) contextOrValue;
    } else if (contextOrValue instanceof String) {
        insertAndAddExpected(name, createParameter(name, contextOrValue.toString(), true));
    }
    return redef;
}
Also used : ParameterRedef(org.openlca.core.model.ParameterRedef)

Example 2 with ParameterRedef

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

the class ProjectReferenceSearchTest method createParameterRedef.

private ParameterRedef createParameterRedef(String name, Object contextOrValue) {
    ParameterRedef redef = new ParameterRedef();
    redef.name = name;
    redef.value = 1d;
    if (contextOrValue instanceof Long) {
        redef.contextType = ModelType.IMPACT_METHOD;
        redef.contextId = (long) contextOrValue;
    } else {
        if (!parameters.containsKey(name)) {
            Parameter parameter = createParameter(name, contextOrValue.toString(), true);
            parameters.put(name, db.insert(parameter));
        }
    }
    return redef;
}
Also used : Parameter(org.openlca.core.model.Parameter) ParameterRedef(org.openlca.core.model.ParameterRedef)

Example 3 with ParameterRedef

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

the class ProductSystemDaoTest method testParameterRedefSets.

@Test
public void testParameterRedefSets() {
    ProductSystemDao dao = new ProductSystemDao(Tests.getDb());
    ProductSystem sys = new ProductSystem();
    ParameterRedefSet s1 = new ParameterRedefSet();
    sys.parameterSets.add(s1);
    s1.name = "Baseline";
    s1.isBaseline = true;
    ParameterRedef p1 = new ParameterRedef();
    p1.name = "p";
    p1.description = "just for testing";
    p1.value = 42.0;
    s1.parameters.add(p1);
    ParameterRedefSet s2 = new ParameterRedefSet();
    sys.parameterSets.add(s2);
    s2.name = "Something else";
    s2.isBaseline = false;
    s2.parameters.add(p1.copy());
    dao.insert(sys);
    sys = dao.getForId(sys.id);
    Assert.assertEquals(2, sys.parameterSets.size());
    for (ParameterRedefSet s : sys.parameterSets) {
        if (s.isBaseline) {
            Assert.assertEquals("Baseline", s.name);
        } else {
            Assert.assertEquals("Something else", s.name);
        }
        Assert.assertEquals("p", s.parameters.get(0).name);
    }
    dao.delete(sys);
}
Also used : ProductSystem(org.openlca.core.model.ProductSystem) ParameterRedef(org.openlca.core.model.ParameterRedef) ParameterRedefSet(org.openlca.core.model.ParameterRedefSet) Test(org.junit.Test)

Example 4 with ParameterRedef

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

the class ProjectImport method switchVariantReferences.

private void switchVariantReferences(ProjectVariant variant) {
    variant.productSystem = refs.switchRef(variant.productSystem);
    variant.unit = refs.switchRef(variant.unit);
    switchVariantProperty(variant);
    for (ParameterRedef redef : variant.parameterRedefs) {
        if (redef.contextId == null)
            continue;
        if (redef.contextType == ModelType.IMPACT_METHOD) {
            redef.contextId = refs.getDestImpactMethodId(redef.contextId);
        } else {
            redef.contextId = refs.getDestProcessId(redef.contextId);
        }
    }
}
Also used : ParameterRedef(org.openlca.core.model.ParameterRedef)

Example 5 with ParameterRedef

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

the class ParameterReferencesTest method createRedef.

private ParameterRedef createRedef(Parameter p) {
    ParameterRedef redef = new ParameterRedef();
    redef.name = p.name;
    if (p.scope == ParameterScope.PROCESS)
        redef.contextType = ModelType.PROCESS;
    else if (p.scope == ParameterScope.IMPACT)
        redef.contextType = ModelType.IMPACT_CATEGORY;
    if (p.scope != ParameterScope.GLOBAL)
        redef.contextId = 1L;
    redef.value = 1;
    return redef;
}
Also used : ParameterRedef(org.openlca.core.model.ParameterRedef)

Aggregations

ParameterRedef (org.openlca.core.model.ParameterRedef)17 Parameter (org.openlca.core.model.Parameter)6 Test (org.junit.Test)5 ProjectVariant (org.openlca.core.model.ProjectVariant)4 ArrayList (java.util.ArrayList)3 ProductSystem (org.openlca.core.model.ProductSystem)3 Project (org.openlca.core.model.Project)3 ParameterRedefSet (org.openlca.core.model.ParameterRedefSet)2 AbstractZipTest (org.openlca.jsonld.AbstractZipTest)2 HashMap (java.util.HashMap)1 TableColumn (org.eclipse.swt.widgets.TableColumn)1 Before (org.junit.Before)1 ParameterDao (org.openlca.core.database.ParameterDao)1 Category (org.openlca.core.model.Category)1 Exchange (org.openlca.core.model.Exchange)1 ImpactFactor (org.openlca.core.model.ImpactFactor)1 ImpactMethod (org.openlca.core.model.ImpactMethod)1 Uncertainty (org.openlca.core.model.Uncertainty)1 Logger (org.slf4j.Logger)1