use of org.openlca.jsonld.input.JsonImport in project olca-modules by GreenDelta.
the class ProcessTest method doImport.
private void doImport() {
with(zip -> {
JsonImport jImport = new JsonImport(zip, Tests.getDb());
jImport.setUpdateMode(UpdateMode.ALWAYS);
jImport.run();
});
}
use of org.openlca.jsonld.input.JsonImport in project olca-modules by GreenDelta.
the class CurrencyTest method doImport.
private void doImport(CurrencyDao dao, Currency currency) {
with(zip -> {
JsonImport jImport = new JsonImport(zip, Tests.getDb());
jImport.run();
});
Assert.assertTrue(dao.contains(currency.refId));
Currency clone = dao.getForRefId(currency.refId);
Assert.assertEquals(currency.name, clone.name);
}
use of org.openlca.jsonld.input.JsonImport in project olca-modules by GreenDelta.
the class ExchangeCostTest method testCostAttributes.
@Test
public void testCostAttributes() {
Currency currency = createCurrency();
Process process = createProcess(currency);
with(zip -> {
JsonExport export = new JsonExport(Tests.getDb(), zip);
export.write(process);
});
delete(currency, process);
with(zip -> {
JsonImport jImport = new JsonImport(zip, Tests.getDb());
jImport.run();
});
checkImport(process);
}
use of org.openlca.jsonld.input.JsonImport in project olca-modules by GreenDelta.
the class JsonNewFieldsV2Test method testInlinedNwSets.
@Test
public void testInlinedNwSets() {
var impact = db.insert(ImpactCategory.of("impact"));
var method = ImpactMethod.of("method");
method.impactCategories.add(impact);
var nwSet = NwSet.of("nw-set");
nwSet.factors.add(NwFactor.of(impact, 100, 0.01));
method.add(nwSet);
db.insert(method);
var store = withExport(export -> export.write(method));
db.clear();
new JsonImport(store, db).run();
var methodCopy = db.get(ImpactMethod.class, method.refId);
var nwSetCopy = methodCopy.nwSets.get(0);
assertEquals("nw-set", nwSetCopy.name);
var factor = nwSetCopy.factors.get(0);
assertEquals(impact.refId, factor.impactCategory.refId);
assertEquals(100, factor.normalisationFactor, 1e-10);
assertEquals(0.01, factor.weightingFactor, 1e-10);
}
use of org.openlca.jsonld.input.JsonImport in project olca-modules by GreenDelta.
the class ModelHandler method saveModel.
private RpcResponse saveModel(RpcRequest req, UpdateMode mode) {
Descriptor d = descriptorOf(req);
if (d == null)
return Responses.invalidParams("params must be an object with" + " valid @id and @type", req);
JsonObject obj = req.params.getAsJsonObject();
try {
MemStore store = new MemStore();
store.put(d.type, obj);
JsonImport imp = new JsonImport(store, db);
imp.setUpdateMode(mode);
imp.run(d.type, d.refId);
return Responses.ok(req);
} catch (Exception e) {
return Responses.serverError(e, req);
}
}
Aggregations