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