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;
}
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);
}
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;
}
}
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);
}