Search in sources :

Example 6 with CategoryDao

use of org.openlca.core.database.CategoryDao in project olca-modules by GreenDelta.

the class FlowPropertyImport method createNew.

private FlowProperty createNew() {
    property = new FlowProperty();
    var path = Categories.getPath(ilcdProperty.getValue());
    property.category = new CategoryDao(config.db()).sync(ModelType.FLOW_PROPERTY, path);
    mapDescriptionAttributes();
    Ref unitGroupRef = ilcdProperty.getUnitGroupReference();
    if (unitGroupRef != null) {
        property.unitGroup = UnitGroupImport.get(config, unitGroupRef.uuid);
    }
    return config.insert(property);
}
Also used : Ref(org.openlca.ilcd.commons.Ref) CategoryDao(org.openlca.core.database.CategoryDao) FlowProperty(org.openlca.core.model.FlowProperty)

Example 7 with CategoryDao

use of org.openlca.core.database.CategoryDao 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);
}
Also used : Category(org.openlca.core.model.Category) CategoryDao(org.openlca.core.database.CategoryDao) AbstractZipTest(org.openlca.jsonld.AbstractZipTest) Test(org.junit.Test)

Example 8 with CategoryDao

use of org.openlca.core.database.CategoryDao in project olca-modules by GreenDelta.

the class IsicTreeTest method testSyncProcessCategories.

@Test
public void testSyncProcessCategories() {
    IDatabase database = Tests.getDb();
    CategoryDao dao = new CategoryDao(database);
    Category cat = new Category();
    String catName = "01:Crop and animal production, hunting and related service activities";
    cat.name = catName;
    cat.modelType = ModelType.PROCESS;
    cat = dao.insert(cat);
    new IsicCategoryTreeSync(database, ModelType.PROCESS).run();
    cat = dao.getForId(cat.id);
    Assert.assertNotNull(cat.category);
    Assert.assertEquals("A:Agriculture, forestry and fishing", cat.category.name);
}
Also used : IDatabase(org.openlca.core.database.IDatabase) Category(org.openlca.core.model.Category) CategoryDao(org.openlca.core.database.CategoryDao) Test(org.junit.Test)

Example 9 with CategoryDao

use of org.openlca.core.database.CategoryDao in project olca-modules by GreenDelta.

the class Categories method findOrAddChild.

public static Category findOrAddChild(IDatabase database, Category parent, String childName) {
    for (Category child : parent.childCategories) {
        if (StringUtils.equalsIgnoreCase(child.name, childName))
            return child;
    }
    try {
        Category child = new Category();
        child.modelType = parent.modelType;
        child.name = childName;
        child.refId = UUID.randomUUID().toString();
        child.category = parent;
        parent.childCategories.add(child);
        CategoryDao dao = new CategoryDao(database);
        dao.insert(child);
        new CategoryDao(database).update(parent);
        return child;
    } catch (Exception e) {
        Logger log = LoggerFactory.getLogger(Categories.class);
        log.error("failed to add child", e);
        return null;
    }
}
Also used : Category(org.openlca.core.model.Category) CategoryDao(org.openlca.core.database.CategoryDao) Logger(org.slf4j.Logger)

Example 10 with CategoryDao

use of org.openlca.core.database.CategoryDao in project olca-app by GreenDelta.

the class CopyPaste method copy.

private static void copy(CategoryElement element, INavigationElement<?> category) {
    Category parent = getCategory(category);
    Queue<CategoryElement> elements = new LinkedList<>();
    elements.add(element);
    while (!elements.isEmpty()) {
        CategoryElement current = elements.poll();
        Category copy = current.getContent().copy();
        copy.childCategories.clear();
        copy.category = parent;
        if (parent == null)
            copy = new CategoryDao(Database.get()).insert(copy);
        else {
            parent.childCategories.add(copy);
            copy = new CategoryDao(Database.get()).update(parent);
        }
        for (INavigationElement<?> child : current.getChildren()) if (child instanceof CategoryElement)
            elements.add((CategoryElement) child);
        else {
            RootEntity modelCopy = copy((ModelElement) child);
            modelCopy.category = copy;
            insert(modelCopy);
        }
        parent = copy;
    }
}
Also used : ModelElement(org.openlca.app.navigation.elements.ModelElement) Category(org.openlca.core.model.Category) CategoryElement(org.openlca.app.navigation.elements.CategoryElement) CategoryDao(org.openlca.core.database.CategoryDao) LinkedList(java.util.LinkedList) RootEntity(org.openlca.core.model.RootEntity)

Aggregations

CategoryDao (org.openlca.core.database.CategoryDao)20 Category (org.openlca.core.model.Category)11 Test (org.junit.Test)4 CategoryElement (org.openlca.app.navigation.elements.CategoryElement)2 ModelElement (org.openlca.app.navigation.elements.ModelElement)2 FlowDao (org.openlca.core.database.FlowDao)2 IDatabase (org.openlca.core.database.IDatabase)2 ImpactMethodDao (org.openlca.core.database.ImpactMethodDao)2 ProductSystemDao (org.openlca.core.database.ProductSystemDao)2 FlowProperty (org.openlca.core.model.FlowProperty)2 Logger (org.slf4j.Logger)2 Date (java.util.Date)1 LinkedList (java.util.LinkedList)1 ActorDao (org.openlca.core.database.ActorDao)1 CurrencyDao (org.openlca.core.database.CurrencyDao)1 DQSystemDao (org.openlca.core.database.DQSystemDao)1 FlowPropertyDao (org.openlca.core.database.FlowPropertyDao)1 ImpactCategoryDao (org.openlca.core.database.ImpactCategoryDao)1 LocationDao (org.openlca.core.database.LocationDao)1 NwSetDao (org.openlca.core.database.NwSetDao)1