use of org.openlca.ipc.Rpc in project olca-modules by GreenDelta.
the class ImpactHandler method getLocationContributions.
@Rpc("get/impacts/contributions/locations")
public RpcResponse getLocationContributions(RpcRequest req) {
return utils.contributionImpact(req, (result, impact, cache) -> {
LocationResult r = new LocationResult(result, cache.db);
List<Contribution<LocationDescriptor>> contributions = utils.toDescriptors(r.getContributions(impact));
contributions = utils.filter(contributions, contribution -> contribution.amount != 0);
return JsonRpc.encode(contributions, cache, json -> json.addProperty("unit", impact.referenceUnit));
});
}
use of org.openlca.ipc.Rpc in project olca-modules by GreenDelta.
the class ImpactHandler method getUpstream.
@Rpc("get/impacts/upstream")
public RpcResponse getUpstream(RpcRequest req) {
return utils.fullImpact(req, (result, impact, cache) -> {
List<StringPair> products = utils.parseProducts(req);
UpstreamTree tree = result.getTree(impact);
List<UpstreamNode> results = Upstream.calculate(tree, products);
return JsonRpc.encode(results, tree, cache, json -> {
json.addProperty("unit", impact.referenceUnit);
json.add("upstream", json.remove("amount"));
});
});
}
use of org.openlca.ipc.Rpc in project olca-modules by GreenDelta.
the class InventoryHandler method getUpstream.
@Rpc("get/inventory/upstream")
public RpcResponse getUpstream(RpcRequest req) {
return utils.fullFlow(req, (result, flow, cache) -> {
List<StringPair> products = utils.parseProducts(req);
UpstreamTree tree = result.getTree(flow);
List<UpstreamNode> results = Upstream.calculate(tree, products);
String unit = utils.getUnit(flow, cache);
return JsonRpc.encode(results, tree, cache, json -> {
json.addProperty("unit", unit);
json.add("upstream", json.remove("amount"));
});
});
}
use of org.openlca.ipc.Rpc in project olca-modules by GreenDelta.
the class ModelHandler method getAll.
@Rpc("get/models")
public RpcResponse getAll(RpcRequest req) {
if (req.params == null || !req.params.isJsonObject())
return Responses.invalidParams("params must be an object with" + " valid @type attribute", req);
var type = getType(req.params.getAsJsonObject());
if (type == null)
return Responses.invalidParams("params must be an object with" + " valid @type attribute", req);
try {
var store = new MemStore();
var exp = new JsonExport(db, store).withReferences(false);
Daos.refDao(db, type).getAll().forEach(exp::write);
var array = new JsonArray();
store.getAll(type).forEach(array::add);
return Responses.ok(array, req);
} catch (Exception e) {
return Responses.serverError(e, req);
}
}
use of org.openlca.ipc.Rpc in project olca-modules by GreenDelta.
the class CacheHandler method dispose.
@Rpc("dispose")
public RpcResponse dispose(RpcRequest req) {
if (req.params == null || !req.params.isJsonObject())
return Responses.error(400, "No object with '@id' provided", req);
JsonObject param = req.params.getAsJsonObject();
String id = Json.getString(param, "@id");
if (id == null)
return Responses.error(400, "No '@id' provided", req);
boolean removed = cache.remove(id) != null;
if (removed) {
log.info("Removed {} from memory", id);
return Responses.ok(req);
}
return Responses.ok("Did not find something with @id=" + id + "in memory; did nothing", req);
}
Aggregations