Search in sources :

Example 11 with EntityCache

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;
}
Also used : Category(org.openlca.core.model.Category) EntityCache(org.openlca.core.database.EntityCache) FlowDescriptor(org.openlca.core.model.descriptors.FlowDescriptor) TechFlow(org.openlca.core.matrix.index.TechFlow) ArrayList(java.util.ArrayList) RootDescriptor(org.openlca.core.model.descriptors.RootDescriptor) CategoryPair(org.openlca.io.CategoryPair) ProcessDescriptor(org.openlca.core.model.descriptors.ProcessDescriptor) Location(org.openlca.core.model.Location)

Example 12 with EntityCache

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

Example 13 with EntityCache

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

Example 14 with EntityCache

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

Example 15 with EntityCache

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

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