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;
}
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;
}
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));
});
}
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;
}
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;
}
Aggregations