Search in sources :

Example 1 with EntityCache

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;
}
Also used : Descriptor(org.openlca.core.model.descriptors.Descriptor) UpstreamNode(org.openlca.core.results.UpstreamNode) JsonObject(com.google.gson.JsonObject) SimpleResult(org.openlca.core.results.SimpleResult) ImpactValue(org.openlca.core.results.ImpactValue) UpstreamTree(org.openlca.core.results.UpstreamTree) Collection(java.util.Collection) FlowValue(org.openlca.core.results.FlowValue) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) Consumer(java.util.function.Consumer) JsonArray(com.google.gson.JsonArray) EnviFlow(org.openlca.core.matrix.index.EnviFlow) TechIndex(org.openlca.core.matrix.index.TechIndex) EntityCache(org.openlca.core.database.EntityCache) Contribution(org.openlca.core.results.Contribution) JsonObject(com.google.gson.JsonObject)

Example 2 with EntityCache

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);
}
Also used : EntityCache(org.openlca.core.database.EntityCache) JsonObject(com.google.gson.JsonObject) EnviFlow(org.openlca.core.matrix.index.EnviFlow) ContributionResult(org.openlca.core.results.ContributionResult)

Example 3 with EntityCache

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);
}
Also used : EntityCache(org.openlca.core.database.EntityCache) JsonObject(com.google.gson.JsonObject) ImpactDescriptor(org.openlca.core.model.descriptors.ImpactDescriptor) ContributionResult(org.openlca.core.results.ContributionResult)

Example 4 with EntityCache

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);
}
Also used : EntityCache(org.openlca.core.database.EntityCache) LocationDescriptor(org.openlca.core.model.descriptors.LocationDescriptor) JsonObject(com.google.gson.JsonObject) EnviFlow(org.openlca.core.matrix.index.EnviFlow) ContributionResult(org.openlca.core.results.ContributionResult)

Example 5 with EntityCache

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);
}
Also used : EntityCache(org.openlca.core.database.EntityCache) JsonObject(com.google.gson.JsonObject) SimpleResult(org.openlca.core.results.SimpleResult)

Aggregations

EntityCache (org.openlca.core.database.EntityCache)18 JsonObject (com.google.gson.JsonObject)13 ContributionResult (org.openlca.core.results.ContributionResult)7 ImpactDescriptor (org.openlca.core.model.descriptors.ImpactDescriptor)6 EnviFlow (org.openlca.core.matrix.index.EnviFlow)4 LocationDescriptor (org.openlca.core.model.descriptors.LocationDescriptor)4 ProcessDescriptor (org.openlca.core.model.descriptors.ProcessDescriptor)4 FullResult (org.openlca.core.results.FullResult)4 ArrayList (java.util.ArrayList)3 Location (org.openlca.core.model.Location)2 FlowDescriptor (org.openlca.core.model.descriptors.FlowDescriptor)2 SimpleResult (org.openlca.core.results.SimpleResult)2 CategoryPair (org.openlca.io.CategoryPair)2 JsonArray (com.google.gson.JsonArray)1 Collection (java.util.Collection)1 Consumer (java.util.function.Consumer)1 Function (java.util.function.Function)1 Collectors (java.util.stream.Collectors)1 SWT (org.eclipse.swt.SWT)1 IDatabase (org.openlca.core.database.IDatabase)1