use of org.openlca.core.model.Category in project olca-modules by GreenDelta.
the class CategoryDaoTest method findAllRootTypes.
@Test
public void findAllRootTypes() {
// in categories, but this test should work
for (ModelType type : ModelType.values()) {
Category cat = create();
cat.modelType = type;
dao.insert(cat);
Tests.emptyCache();
List<Category> categories = dao.getRootCategories(type);
Assert.assertTrue(categories.contains(cat));
dao.delete(cat);
categories = dao.getRootCategories(type);
Assert.assertFalse(categories.contains(cat));
}
}
use of org.openlca.core.model.Category in project olca-modules by GreenDelta.
the class CategoryExport method doIt.
@Override
protected void doIt(CSVPrinter writer, IDatabase database) throws Exception {
log.trace("write categories");
CategoryDao dao = new CategoryDao(database);
List<Category> categories = dao.getAll();
for (Category category : categories) {
Object[] line = createLine(category);
writer.printRecord(line);
}
log.trace("{} categories written", categories.size());
}
use of org.openlca.core.model.Category in project olca-modules by GreenDelta.
the class ImpactMethodExport method createLine.
private Object[] createLine(ImpactMethodDescriptor method, CategoryDao categoryDao) {
Object[] line = new Object[4];
line[0] = method.refId;
line[1] = method.name;
line[2] = method.description;
if (method.category != null) {
Category category = categoryDao.getForId(method.category);
if (category != null)
line[3] = category.refId;
}
return line;
}
use of org.openlca.core.model.Category in project olca-modules by GreenDelta.
the class CategoryImport method copy.
/**
* Creates a flat copy of the given category. Note that the clone function
* in the category class creates a deep copy.
*/
private Category copy(Category srcCat) {
Category copy = new Category();
copy.description = srcCat.description;
copy.name = srcCat.name;
copy.refId = srcCat.refId;
copy.modelType = srcCat.modelType;
return copy;
}
use of org.openlca.core.model.Category in project olca-modules by GreenDelta.
the class CategoryImport method synchCategories.
private void synchCategories(ModelType type) {
log.trace("synch categories for type {}", type);
List<Category> sourceRoots = sourceDao.getRootCategories(type);
List<Category> destRoots = destDao.getRootCategories(type);
for (Category sourceRoot : sourceRoots) {
Category destRoot = find(sourceRoot, destRoots);
if (destRoot != null) {
synchCategories(sourceRoot, destRoot);
destRoot = destDao.update(destRoot);
} else {
destRoot = copy(sourceRoot);
synchCategories(sourceRoot, destRoot);
destRoot = destDao.insert(destRoot);
}
index(sourceRoot, destRoot);
}
}
Aggregations