use of org.openlca.core.model.Category in project olca-modules by GreenDelta.
the class IsicCategoryTreeSync method syncWithDatabase.
private void syncWithDatabase(IsicNode root) {
Category category = root.category;
if (category == null)
return;
if (category.id == 0L) {
category = dao.insert(category);
root.category = category;
}
for (IsicNode childNode : root.childs) {
if (childNode.category != null) {
syncWithDatabase(childNode);
category.childCategories.add(childNode.category);
childNode.category.category = category;
}
}
category = dao.update(category);
root.category = category;
}
use of org.openlca.core.model.Category 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.Category in project olca-modules by GreenDelta.
the class CategoryTest method testCategory.
@Test
public void testCategory() {
CategoryDao dao = new CategoryDao(Tests.getDb());
Category category = createModel(dao);
doExport(category, dao);
doImport(dao, category);
dao.delete(category);
}
use of org.openlca.core.model.Category in project olca-modules by GreenDelta.
the class CategoryTest method doImport.
private void doImport(CategoryDao dao, Category category) {
with(zip -> {
JsonImport jImport = new JsonImport(zip, Tests.getDb());
jImport.run();
});
Assert.assertTrue(dao.contains(category.refId));
Category clone = dao.getForRefId(category.refId);
Assert.assertEquals(category.name, clone.name);
}
use of org.openlca.core.model.Category in project olca-modules by GreenDelta.
the class CategoryTest method createModel.
private Category createModel(CategoryDao dao) {
Category category = new Category();
category.name = "category";
category.refId = UUID.randomUUID().toString();
dao.insert(category);
return category;
}
Aggregations