Search in sources :

Example 1 with IsicNode

use of org.openlca.io.ecospold2.input.IsicTree.IsicNode 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;
}
Also used : IsicNode(org.openlca.io.ecospold2.input.IsicTree.IsicNode) Category(org.openlca.core.model.Category)

Example 2 with IsicNode

use of org.openlca.io.ecospold2.input.IsicTree.IsicNode in project olca-modules by GreenDelta.

the class IsicTreeTest method testFindNode.

@Test
public void testFindNode() {
    IsicNode node = tree.findNode("9492");
    Assert.assertEquals("Activities of political organizations", node.name);
    Assert.assertEquals("949", node.parent.code);
    Assert.assertEquals("94", node.parent.parent.code);
    Assert.assertEquals("S", node.parent.parent.parent.code);
}
Also used : IsicNode(org.openlca.io.ecospold2.input.IsicTree.IsicNode) Test(org.junit.Test)

Example 3 with IsicNode

use of org.openlca.io.ecospold2.input.IsicTree.IsicNode in project olca-modules by GreenDelta.

the class IsicCategoryTreeSync method syncPath.

private void syncPath(IsicNode node) {
    if (node.parent == null)
        return;
    IsicNode parent = node.parent;
    while (parent != null) {
        Category parentCategory = parent.category;
        if (parentCategory == null) {
            parentCategory = createCategory(parent);
            parent.category = parentCategory;
        }
        parent = parent.parent;
    }
}
Also used : IsicNode(org.openlca.io.ecospold2.input.IsicTree.IsicNode) Category(org.openlca.core.model.Category)

Example 4 with IsicNode

use of org.openlca.io.ecospold2.input.IsicTree.IsicNode in project olca-modules by GreenDelta.

the class IsicCategoryTreeSync method run.

@Override
public void run() {
    IsicTree isicTree = IsicTree.fromFile(getClass().getResourceAsStream("isic_codes_rev4.txt"));
    List<Category> roots = dao.getRootCategories(type);
    List<IsicNode> assignedNodes = new ArrayList<>();
    for (Category root : roots) {
        IsicNode node = findNode(root, isicTree);
        if (node == null)
            continue;
        node.category = root;
        assignedNodes.add(node);
    }
    for (IsicNode assignedNode : assignedNodes) syncPath(assignedNode);
    for (IsicNode root : isicTree.getRoots()) syncWithDatabase(root);
}
Also used : IsicNode(org.openlca.io.ecospold2.input.IsicTree.IsicNode) Category(org.openlca.core.model.Category) ArrayList(java.util.ArrayList)

Aggregations

IsicNode (org.openlca.io.ecospold2.input.IsicTree.IsicNode)4 Category (org.openlca.core.model.Category)3 ArrayList (java.util.ArrayList)1 Test (org.junit.Test)1