use of gnu.trove.map.hash.TLongLongHashMap in project olca-modules by GreenDelta.
the class ProductSystemWriter method write.
@Override
JsonObject write(ProductSystem system) {
JsonObject obj = super.write(system);
if (obj == null)
return null;
this.system = system;
TLongLongHashMap exchangeIDs = exchangeIDs(system);
Json.put(obj, "referenceProcess", exp.handleRef(system.referenceProcess));
// the reference exchange
if (system.referenceExchange != null) {
var eObj = new JsonObject();
Json.put(eObj, "@type", "Exchange");
Json.put(eObj, "internalId", exchangeIDs.get(system.referenceExchange.id));
Json.put(eObj, "flow", exp.handleRef(system.referenceExchange.flow));
Json.put(obj, "referenceExchange", eObj);
}
FlowProperty property = null;
if (system.targetFlowPropertyFactor != null)
property = system.targetFlowPropertyFactor.flowProperty;
Json.put(obj, "targetFlowProperty", exp.handleRef(property));
Json.put(obj, "targetUnit", Json.asRef(system.targetUnit));
Json.put(obj, "targetAmount", system.targetAmount);
// map the parameter redefinitions
GlobalParameters.sync(system, exp);
putParameterSets(obj, system.parameterSets);
if (exp.db == null)
return obj;
mapProcesses(obj);
mapLinks(obj, exchangeIDs);
return obj;
}
use of gnu.trove.map.hash.TLongLongHashMap in project olca-app by GreenDelta.
the class Param method fetchAll.
static void fetchAll(IDatabase db, List<Param> params) {
if (db == null || params == null)
return;
// collect the owner relations
var processes = new ProcessDao(db).descriptorMap();
var impacts = new ImpactCategoryDao(db).descriptorMap();
var owners = new TLongLongHashMap();
try {
var sql = "select id, f_owner from tbl_parameters";
NativeSql.on(db).query(sql, r -> {
var ownerId = r.getLong(2);
if (r.wasNull() || ownerId == 0)
return true;
owners.put(r.getLong(1), ownerId);
return true;
});
} catch (Exception e) {
var log = LoggerFactory.getLogger(Param.class);
log.error("Failed to query parameter onwers", e);
}
new ParameterDao(db).getAll().forEach(p -> {
var ownerId = owners.get(p.id);
// global parameters
if (p.scope == ParameterScope.GLOBAL || ownerId == 0) {
params.add(new Param(p));
return;
}
// local parameters
var owner = p.scope == ParameterScope.IMPACT ? impacts.get(ownerId) : processes.get(ownerId);
if (owner == null) {
var log = LoggerFactory.getLogger(Param.class);
log.error("invalid owner in parameter {}", p);
return;
}
params.add(new Param(p, owner));
});
Collections.sort(params);
}
Aggregations