Search in sources :

Example 1 with ParameterDao

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

the class ParameterReferenceSearch method findParameterReferences.

private List<Reference> findParameterReferences(Set<Long> ids) {
    List<String> formulaQueries = Search.createQueries("SELECT id, lower(formula) FROM tbl_parameters", "WHERE id IN", ids);
    Map<Long, Set<String>> variables = getVariablesUsedInFormulas(formulaQueries);
    Set<String> names = new HashSet<>();
    for (Long key : variables.keySet()) names.addAll(variables.get(key));
    List<Reference> results = new ArrayList<>();
    List<ParameterDescriptor> descriptors = new ParameterDao(database).getDescriptors(names.toArray(new String[names.size()]), ParameterScope.GLOBAL);
    results.addAll(toReferences(descriptors, false, variables));
    Set<String> found = new HashSet<>();
    for (ParameterDescriptor d : descriptors) found.add(d.name.toLowerCase());
    for (String name : names) if (!found.contains(name)) {
        List<Reference> refs = createMissingReferences(name, variables);
        results.addAll(refs);
    }
    return results;
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) ParameterDescriptor(org.openlca.core.model.descriptors.ParameterDescriptor) ArrayList(java.util.ArrayList) ParameterDao(org.openlca.core.database.ParameterDao) ArrayList(java.util.ArrayList) List(java.util.List) HashSet(java.util.HashSet)

Example 2 with ParameterDao

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

the class ProcessParameterConversion method addDatabaseParams.

private void addDatabaseParams(List<org.openlca.ilcd.processes.Parameter> params) {
    ParameterDao dao = new ParameterDao(config.db);
    for (Parameter param : dao.getGlobalParameters()) {
        if (!valid(param))
            continue;
        org.openlca.ilcd.processes.Parameter iParam = convertParam(param);
        params.add(iParam);
        addScope(iParam, ParameterScope.GLOBAL);
    }
}
Also used : ParameterDao(org.openlca.core.database.ParameterDao) Parameter(org.openlca.core.model.Parameter)

Example 3 with ParameterDao

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

the class ParameterSheet method syncGlobals.

private void syncGlobals(List<Parameter> sheetParams) {
    ParameterDao dao = new ParameterDao(config.database);
    List<Parameter> globals = new ArrayList<>();
    globals.addAll(dao.getGlobalParameters());
    for (Parameter p : sheetParams) {
        boolean found = false;
        for (Parameter global : globals) {
            String name = global.name;
            if (name == null)
                continue;
            if (name.equalsIgnoreCase(p.name)) {
                found = true;
                break;
            }
        }
        if (!found)
            globals.add(dao.insert(p));
    }
}
Also used : ParameterDao(org.openlca.core.database.ParameterDao) ArrayList(java.util.ArrayList) Parameter(org.openlca.core.model.Parameter)

Example 4 with ParameterDao

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

the class ProcessImport method handleParameters.

private void handleParameters(DataSet dataSet, Process process) {
    List<Parameter> list = Parameters.fetch(dataSet, config);
    List<Parameter> newGlobals = new ArrayList<>();
    for (Parameter p : list) {
        if (p.scope == ParameterScope.PROCESS)
            process.parameters.add(p);
        else if (p.scope == ParameterScope.GLOBAL)
            newGlobals.add(p);
    }
    ParameterDao dao = new ParameterDao(config.db);
    Map<String, Boolean> map = new HashMap<>();
    for (Parameter p : dao.getGlobalParameters()) map.put(p.name, Boolean.TRUE);
    for (Parameter newGlobal : newGlobals) {
        Boolean exists = map.get(newGlobal.name);
        if (exists == null) {
            dao.insert(newGlobal);
            map.put(newGlobal.name, Boolean.TRUE);
        }
    }
}
Also used : ParameterDao(org.openlca.core.database.ParameterDao) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Parameter(org.openlca.core.model.Parameter)

Example 5 with ParameterDao

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

the class ParameterTableTest method tearDown.

@After
public void tearDown() {
    IDatabase db = Tests.getDb();
    new ParameterDao(db).deleteAll();
    new ProcessDao(db).deleteAll();
}
Also used : ParameterDao(org.openlca.core.database.ParameterDao) IDatabase(org.openlca.core.database.IDatabase) ProcessDao(org.openlca.core.database.ProcessDao) After(org.junit.After)

Aggregations

ParameterDao (org.openlca.core.database.ParameterDao)23 Parameter (org.openlca.core.model.Parameter)10 ArrayList (java.util.ArrayList)5 ProcessDao (org.openlca.core.database.ProcessDao)5 HashSet (java.util.HashSet)4 HashMap (java.util.HashMap)3 Set (java.util.Set)3 Before (org.junit.Before)3 ParameterDescriptor (org.openlca.core.model.descriptors.ParameterDescriptor)3 After (org.junit.After)2 IDatabase (org.openlca.core.database.IDatabase)2 Process (org.openlca.core.model.Process)2 TLongLongHashMap (gnu.trove.map.hash.TLongLongHashMap)1 List (java.util.List)1 InputDialog (org.eclipse.jface.dialogs.InputDialog)1 IContentProposal (org.eclipse.jface.fieldassist.IContentProposal)1 Test (org.junit.Test)1 CategoryElement (org.openlca.app.navigation.elements.CategoryElement)1 ModelElement (org.openlca.app.navigation.elements.ModelElement)1 ImpactCategoryDao (org.openlca.core.database.ImpactCategoryDao)1