use of org.openlca.core.database.EntityCache in project olca-modules by GreenDelta.
the class ProductInfo method getAll.
public static List<ProductInfo> getAll(SystemExportConfig conf, TechIndex index) {
EntityCache cache = conf.getEntityCache();
List<ProductInfo> infos = new ArrayList<>(index.size() + 2);
for (int i = 0; i < index.size(); i++) {
TechFlow pair = index.at(i);
RootDescriptor process = pair.provider();
FlowDescriptor product = pair.flow();
ProductInfo info = new ProductInfo();
info.provider = pair;
info.ref = pair.equals(index.getRefFlow());
info.process = process.name;
info.processId = process.refId;
info.product = product.name;
info.productId = product.refId;
if (process.category != null) {
Category cat = cache.get(Category.class, process.category);
CategoryPair catPair = new CategoryPair(cat);
info.processCategory = catPair.getCategory();
info.processSubCategory = catPair.getSubCategory();
}
if (process instanceof ProcessDescriptor) {
ProcessDescriptor p = (ProcessDescriptor) process;
if (p.location != null) {
Location loc = cache.get(Location.class, p.location);
if (loc != null)
info.processLocation = loc.code;
}
}
infos.add(info);
}
return infos;
}
use of org.openlca.core.database.EntityCache in project olca-modules by GreenDelta.
the class Utils method fullImpact.
RpcResponse fullImpact(RpcRequest req, FullImpact handler) {
if (req == null || req.params == null || !req.params.isJsonObject())
return Responses.invalidParams("No parameter given", req);
JsonObject json = req.params.getAsJsonObject();
FullResult result = getResult(json);
ImpactDescriptor impact = get(result.impactIndex(), json);
if (impact == null)
return Responses.invalidParams("Missing or invalid impact category parameter", req);
EntityCache cache = EntityCache.create(ctx.db);
return Responses.ok(handler.handle(result, impact, cache), req);
}
use of org.openlca.core.database.EntityCache in project olca-modules by GreenDelta.
the class Utils method fullProcess.
RpcResponse fullProcess(RpcRequest req, FullProcess handler) {
if (req == null || req.params == null || !req.params.isJsonObject())
return Responses.invalidParams("No parameter given", req);
JsonObject json = req.params.getAsJsonObject();
FullResult result = getResult(json);
ProcessDescriptor process = get(ModelType.PROCESS, json, result.techIndex().getProcessIds());
if (process == null)
return Responses.invalidParams("Missing or invalid process parameter", req);
EntityCache cache = EntityCache.create(ctx.db);
return Responses.ok(handler.handle(result, process, cache), req);
}
use of org.openlca.core.database.EntityCache in project olca-modules by GreenDelta.
the class Utils method fullFlow.
RpcResponse fullFlow(RpcRequest req, FullFlow handler) {
if (req == null || req.params == null || !req.params.isJsonObject())
return Responses.invalidParams("No parameter given", req);
JsonObject json = req.params.getAsJsonObject();
FullResult result = getResult(json);
EnviFlow flow = get(result.enviIndex(), json);
if (flow == null)
return Responses.invalidParams("Missing or invalid flow parameter", req);
EntityCache cache = EntityCache.create(ctx.db);
return Responses.ok(handler.handle(result, flow, cache), req);
}
use of org.openlca.core.database.EntityCache in project olca-modules by GreenDelta.
the class Utils method contributionImpactProcess.
RpcResponse contributionImpactProcess(RpcRequest req, ContributionImpactProcess handler) {
if (req == null || req.params == null || !req.params.isJsonObject())
return Responses.invalidParams("No parameter given", req);
JsonObject json = req.params.getAsJsonObject();
ContributionResult result = getResult(json);
ImpactDescriptor impact = get(result.impactIndex(), json);
if (impact == null)
return Responses.invalidParams("Missing or invalid impact category parameter", req);
ProcessDescriptor process = get(ModelType.PROCESS, json, result.techIndex().getProcessIds());
if (process == null)
return Responses.invalidParams("Missing or invalid process parameter", req);
EntityCache cache = EntityCache.create(ctx.db);
return Responses.ok(handler.handle(result, impact, process, cache), req);
}
Aggregations