Search in sources :

Example 11 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 12 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 13 with ParameterRedef

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

the class ParameterReferencesTest method testProjectRedef.

@Test
public void testProjectRedef() {
    Parameter p1 = createParameter("p1", "3", null, null);
    Parameter p2 = createParameter("p2", "3", ParameterScope.PROCESS, null);
    ParameterRedef redef1 = createRedef(p1);
    ParameterRedef redef2 = createRedef(p2);
    Project project = createProject(redef1, redef2);
    with((store) -> {
        JsonExport export = new JsonExport(db, store);
        export.write(project);
        assertNotNull(store.get(ModelType.PROJECT, project.refId));
        assertNotNull(store.get(ModelType.PARAMETER, p1.refId));
        assertNull(store.get(ModelType.PARAMETER, p2.refId));
    });
}
Also used : Project(org.openlca.core.model.Project) Parameter(org.openlca.core.model.Parameter) ParameterRedef(org.openlca.core.model.ParameterRedef) AbstractZipTest(org.openlca.jsonld.AbstractZipTest) Test(org.junit.Test)

Example 14 with ParameterRedef

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

the class ProjectReferenceSearchTest method createModel.

@Override
protected Project createModel() {
    Project project = new Project();
    project.category = insertAndAddExpected("category", new Category());
    project.impactMethod = insertAndAddExpected("impactMethodId", new ImpactMethod());
    String n1 = generateName();
    String n2 = generateName();
    String n3 = generateName();
    Parameter globalUnreferenced = createParameter(n1, "3*3", true);
    Parameter globalUnreferenced2 = createParameter(n3, "3*3", true);
    // must be inserted manually
    globalUnreferenced = db.insert(globalUnreferenced);
    globalUnreferenced2 = db.insert(globalUnreferenced2);
    project.variants.add(createProjectVariant(n1, n2, n3, project.impactMethod.id));
    project.variants.add(createProjectVariant(n1, n2, n3, project.impactMethod.id));
    project = db.insert(project);
    for (ProjectVariant v : project.variants) {
        addExpected("productSystem", v.productSystem, "variants", ProjectVariant.class, v.id);
        addExpected("unit", v.unit, "variants", ProjectVariant.class, v.id);
        addExpected("flowPropertyFactor", v.flowPropertyFactor, "variants", ProjectVariant.class, v.id);
        for (ParameterRedef p : v.parameterRedefs) {
            if (p.contextType == null) {
                addExpected(p.name, parameters.get(p.name), "variants", ProjectVariant.class, v.id);
            }
        }
    }
    return project;
}
Also used : Project(org.openlca.core.model.Project) Category(org.openlca.core.model.Category) ProjectVariant(org.openlca.core.model.ProjectVariant) Parameter(org.openlca.core.model.Parameter) ParameterRedef(org.openlca.core.model.ParameterRedef) ImpactMethod(org.openlca.core.model.ImpactMethod)

Example 15 with ParameterRedef

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

the class ProjectResultExport method fetchParameters.

private List<ParameterRedef> fetchParameters() {
    List<ParameterRedef> parameters = new ArrayList<>();
    for (ProjectVariant variant : project.variants) {
        for (ParameterRedef redef : variant.parameterRedefs) {
            ParameterRedef contained = findRedef(redef, parameters);
            if (contained == null)
                parameters.add(redef);
        }
    }
    parameters.sort((o1, o2) -> Strings.compare(o1.name, o2.name));
    return parameters;
}
Also used : ProjectVariant(org.openlca.core.model.ProjectVariant) ArrayList(java.util.ArrayList) 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