use of org.openlca.core.database.EntityCache in project olca-modules by GreenDelta.
the class JsonRpc method encode.
static JsonObject encode(SimpleResult r, String id, EntityCache cache) {
JsonObject obj = new JsonObject();
obj.addProperty("@id", id);
if (r == null)
return obj;
obj.addProperty("@type", r.getClass().getSimpleName());
obj.add("flows", encode(r.getFlows().stream().map(EnviFlow::flow).collect(Collectors.toSet()), cache));
obj.add("processes", encode(r.getProcesses(), cache));
obj.add("flowResults", encode(r.getTotalFlowResults(), result -> encode(result, cache)));
if (!r.hasImpacts())
return obj;
obj.add("impacts", encode(r.getImpacts(), cache));
obj.add("impactResults", encode(r.getTotalImpactResults(), result -> encode(result, cache)));
return obj;
}
use of org.openlca.core.database.EntityCache in project olca-modules by GreenDelta.
the class Utils method contributionFlow.
RpcResponse contributionFlow(RpcRequest req, ContributionFlow 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);
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 contributionImpact.
RpcResponse contributionImpact(RpcRequest req, ContributionImpact 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);
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 contributionFlowLocation.
RpcResponse contributionFlowLocation(RpcRequest req, ContributionFlowLocation 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);
EnviFlow flow = get(result.enviIndex(), json);
if (flow == null)
return Responses.invalidParams("Missing or invalid flow parameter", req);
LocationDescriptor location = get(ModelType.LOCATION, json);
if (location == null)
return Responses.invalidParams("Missing or invalid location parameter", req);
EntityCache cache = EntityCache.create(ctx.db);
return Responses.ok(handler.handle(result, flow, location, cache), req);
}
use of org.openlca.core.database.EntityCache in project olca-modules by GreenDelta.
the class Utils method simple.
RpcResponse simple(RpcRequest req, Simple handler) {
if (req == null || req.params == null || !req.params.isJsonObject())
return Responses.invalidParams("No parameter given", req);
JsonObject json = req.params.getAsJsonObject();
SimpleResult result = getResult(json);
EntityCache cache = EntityCache.create(ctx.db);
return Responses.ok(handler.handle(result, cache), req);
}
Aggregations