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