Search in sources :

Example 11 with ProductSystemDao

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

the class ProductSystemWriter method mapProcesses.

private Map<Long, RootDescriptor> mapProcesses(ProductSystem system, ProtoProductSystem.Builder proto) {
    var processes = new ProcessDao(config.db).descriptorMap();
    var systems = new ProductSystemDao(config.db).descriptorMap();
    Map<Long, RootDescriptor> map = new HashMap<>();
    for (var id : system.processes) {
        RootDescriptor d = processes.get(id);
        if (d == null) {
            d = systems.get(id);
        }
        if (d == null)
            continue;
        map.put(id, d);
        proto.addProcesses(Refs.refOf(d));
        Out.dep(config, d);
    }
    return map;
}
Also used : TLongIntHashMap(gnu.trove.map.hash.TLongIntHashMap) HashMap(java.util.HashMap) ProcessDao(org.openlca.core.database.ProcessDao) RootDescriptor(org.openlca.core.model.descriptors.RootDescriptor) ProductSystemDao(org.openlca.core.database.ProductSystemDao)

Example 12 with ProductSystemDao

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

the class ModelImport method run.

public ProductSystem run(Model model) {
    if (model == null)
        return null;
    var dao = new ProductSystemDao(config.db());
    system = dao.getForRefId(model.getUUID());
    if (system != null)
        return system;
    String origin = Models.getOrigin(model);
    if (Strings.nullOrEqual("openLCA", origin)) {
        system = new ProductSystem();
        IO.mapMetaData(model, system);
        String[] path = Categories.getPath(model);
        system.category = new CategoryDao(config.db()).sync(ModelType.PRODUCT_SYSTEM, path);
        mapModel(model);
        system = dao.insert(system);
        config.log().imported(system);
        return system;
    } else {
        Graph g = Graph.build(model, config.db());
        g = Transformation.on(g);
        return new GraphSync(config).sync(model, g);
    }
}
Also used : CategoryDao(org.openlca.core.database.CategoryDao) ProductSystem(org.openlca.core.model.ProductSystem) ProductSystemDao(org.openlca.core.database.ProductSystemDao)

Example 13 with ProductSystemDao

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

the class Export method tryExportSystem.

private void tryExportSystem(ExportConfig config, Descriptor d) {
    try {
        ProductSystem system = new ProductSystemDao(database).getForId(d.id);
        SystemExport export = new SystemExport(config);
        export.run(system);
        monitor.worked(1);
    } catch (Exception e) {
        log.error("System export failed", e);
    }
}
Also used : ProductSystem(org.openlca.core.model.ProductSystem) SystemExport(org.openlca.io.ilcd.output.SystemExport) InvocationTargetException(java.lang.reflect.InvocationTargetException) ProductSystemDao(org.openlca.core.database.ProductSystemDao)

Example 14 with ProductSystemDao

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

the class CalculateSystemAction method run.

@Override
public void run() {
    var system = new ProductSystemDao(Database.get()).getForId(systemId);
    if (system == null)
        return;
    CalculationWizard.open(system);
}
Also used : ProductSystemDao(org.openlca.core.database.ProductSystemDao)

Aggregations

ProductSystemDao (org.openlca.core.database.ProductSystemDao)14 ProcessDao (org.openlca.core.database.ProcessDao)6 ProductSystem (org.openlca.core.model.ProductSystem)6 Test (org.junit.Test)3 FlowDao (org.openlca.core.database.FlowDao)3 HashMap (java.util.HashMap)2 CategoryDao (org.openlca.core.database.CategoryDao)2 FlowPropertyDao (org.openlca.core.database.FlowPropertyDao)2 IDatabase (org.openlca.core.database.IDatabase)2 UnitGroupDao (org.openlca.core.database.UnitGroupDao)2 ProductSystemBuilder (org.openlca.core.matrix.ProductSystemBuilder)2 LinkingConfig (org.openlca.core.matrix.linking.LinkingConfig)2 ProcessLink (org.openlca.core.model.ProcessLink)2 RootDescriptor (org.openlca.core.model.descriptors.RootDescriptor)2 JsonObject (com.google.gson.JsonObject)1 TLongIntHashMap (gnu.trove.map.hash.TLongIntHashMap)1 File (java.io.File)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 ArrayDeque (java.util.ArrayDeque)1 ArrayList (java.util.ArrayList)1