use of org.openlca.core.model.Project in project olca-modules by GreenDelta.
the class DataUtil method toDataSet.
static ProtoDataSet.Builder toDataSet(IDatabase db, RefEntity e) {
var ds = ProtoDataSet.newBuilder();
var conf = WriterConfig.of(db);
if (e instanceof Actor)
return ds.setActor(new ActorWriter(conf).write((Actor) e));
if (e instanceof Category)
return ds.setCategory(new CategoryWriter(conf).write((Category) e));
if (e instanceof Currency)
return ds.setCurrency(new CurrencyWriter(conf).write((Currency) e));
if (e instanceof DQSystem)
return ds.setDqSystem(new DQSystemWriter(conf).write((DQSystem) e));
if (e instanceof Flow)
return ds.setFlow(new FlowWriter(conf).write((Flow) e));
if (e instanceof FlowProperty)
return ds.setFlowProperty(new FlowPropertyWriter(conf).write((FlowProperty) e));
if (e instanceof ImpactCategory)
return ds.setImpactCategory(new ImpactCategoryWriter(conf).write((ImpactCategory) e));
if (e instanceof ImpactMethod)
return ds.setImpactMethod(new ImpactMethodWriter(conf).write((ImpactMethod) e));
if (e instanceof Location)
return ds.setLocation(new LocationWriter(conf).write((Location) e));
if (e instanceof Parameter)
return ds.setParameter(new ParameterWriter(conf).write((Parameter) e));
if (e instanceof Process)
return ds.setProcess(new ProcessWriter(conf).write((Process) e));
if (e instanceof ProductSystem)
return ds.setProductSystem(new ProductSystemWriter(conf).write((ProductSystem) e));
if (e instanceof Project)
return ds.setProject(new ProjectWriter(conf).write((Project) e));
if (e instanceof SocialIndicator)
return ds.setSocialIndicator(new SocialIndicatorWriter(conf).write((SocialIndicator) e));
if (e instanceof Source)
return ds.setSource(new SourceWriter(conf).write((Source) e));
if (e instanceof UnitGroup)
return ds.setUnitGroup(new UnitGroupWriter(conf).write((UnitGroup) e));
return ds;
}
use of org.openlca.core.model.Project in project olca-modules by GreenDelta.
the class ProjectImport method of.
@Override
public ImportStatus<Project> of(String id) {
var project = imp.get(Project.class, id);
// check if we are in update mode
var update = false;
if (project != null) {
update = imp.shouldUpdate(project);
if (!update) {
return ImportStatus.skipped(project);
}
}
// resolve the proto object
var proto = imp.reader.getProject(id);
if (proto == null)
return project != null ? ImportStatus.skipped(project) : ImportStatus.error("Could not resolve Project " + id);
var wrap = ProtoWrap.of(proto);
if (update) {
if (imp.skipUpdate(project, wrap))
return ImportStatus.skipped(project);
}
// map the data
if (project == null) {
project = new Project();
project.refId = id;
}
wrap.mapTo(project, imp);
map(proto, project);
// insert or update it
var dao = new ProjectDao(imp.db);
project = update ? dao.update(project) : dao.insert(project);
imp.putHandled(project);
return update ? ImportStatus.updated(project) : ImportStatus.created(project);
}
use of org.openlca.core.model.Project in project olca-modules by GreenDelta.
the class ParameterReferencesTest method createProject.
private Project createProject(ParameterRedef... redefs) {
Project p = new Project();
p.refId = UUID.randomUUID().toString();
ProjectVariant v = new ProjectVariant();
p.variants.add(v);
v.parameterRedefs.addAll(Arrays.asList(redefs));
return p;
}
use of org.openlca.core.model.Project in project olca-modules by GreenDelta.
the class ParametersTest method testFindRedefOwners.
@Test
public void testFindRedefOwners() {
// create a process with a local parameter
var process = TestProcess.refProduct("prod", 1, "kg").param("param", 42).get();
var param = process.parameters.get(0);
// create project and product system
var project = new Project();
project.variants.add(new ProjectVariant());
db.insert(project);
var system = new ProductSystem();
system.parameterSets.add(new ParameterRedefSet());
db.insert(system);
// should not find something
var owners = Parameters.findRedefOwners(param, process, db);
assertTrue(owners.isEmpty());
// add parameter redefs
var redef = new ParameterRedef();
redef.name = param.name;
redef.contextId = process.id;
redef.contextType = ModelType.PROCESS;
redef.value = 24;
project.variants.get(0).parameterRedefs.add(redef.copy());
project = db.update(project);
system.parameterSets.get(0).parameters.add(redef.copy());
system = db.update(system);
// should find something
owners = Parameters.findRedefOwners(param, process, db);
assertEquals(2, owners.size());
assertTrue(owners.contains(Descriptor.of(system)));
assertTrue(owners.contains(Descriptor.of(project)));
db.clear();
}
use of org.openlca.core.model.Project in project olca-modules by GreenDelta.
the class ProjectImport method map.
@Override
Project map(JsonObject json, long id) {
if (json == null)
return null;
Project p = new Project();
In.mapAtts(json, p, id, conf);
mapAtts(json, p);
mapVariants(json, p);
return conf.db.put(p);
}
Aggregations