Search in sources :

Example 11 with Category

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));
    }
}
Also used : Category(org.openlca.core.model.Category) ModelType(org.openlca.core.model.ModelType) Test(org.junit.Test)

Example 12 with Category

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());
}
Also used : Category(org.openlca.core.model.Category) CategoryDao(org.openlca.core.database.CategoryDao)

Example 13 with Category

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;
}
Also used : Category(org.openlca.core.model.Category)

Example 14 with Category

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;
}
Also used : Category(org.openlca.core.model.Category)

Example 15 with Category

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);
    }
}
Also used : Category(org.openlca.core.model.Category)

Aggregations

Category (org.openlca.core.model.Category)77 Test (org.junit.Test)11 CategoryDao (org.openlca.core.database.CategoryDao)11 Flow (org.openlca.core.model.Flow)6 Parameter (org.openlca.core.model.Parameter)6 CategoryElement (org.openlca.app.navigation.elements.CategoryElement)4 ModelElement (org.openlca.app.navigation.elements.ModelElement)4 IDatabase (org.openlca.core.database.IDatabase)4 FlowProperty (org.openlca.core.model.FlowProperty)4 Location (org.openlca.core.model.Location)4 Process (org.openlca.core.model.Process)4 UnitGroup (org.openlca.core.model.UnitGroup)4 ArrayList (java.util.ArrayList)3 ImpactCategory (org.openlca.core.model.ImpactCategory)3 ImpactMethod (org.openlca.core.model.ImpactMethod)3 ModelType (org.openlca.core.model.ModelType)3 IsicNode (org.openlca.io.ecospold2.input.IsicTree.IsicNode)3 Actor (org.openlca.core.model.Actor)2 Currency (org.openlca.core.model.Currency)2 DQSystem (org.openlca.core.model.DQSystem)2