Search in sources :

Example 21 with JsonImport

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();
    });
}
Also used : JsonImport(org.openlca.jsonld.input.JsonImport)

Example 22 with JsonImport

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);
}
Also used : JsonImport(org.openlca.jsonld.input.JsonImport) Currency(org.openlca.core.model.Currency)

Example 23 with JsonImport

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);
}
Also used : JsonImport(org.openlca.jsonld.input.JsonImport) Currency(org.openlca.core.model.Currency) Process(org.openlca.core.model.Process) JsonExport(org.openlca.jsonld.output.JsonExport) AbstractZipTest(org.openlca.jsonld.AbstractZipTest) Test(org.junit.Test)

Example 24 with JsonImport

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);
}
Also used : JsonImport(org.openlca.jsonld.input.JsonImport) Test(org.junit.Test)

Example 25 with JsonImport

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);
    }
}
Also used : JsonImport(org.openlca.jsonld.input.JsonImport) MemStore(org.openlca.jsonld.MemStore) ProcessDescriptor(org.openlca.core.model.descriptors.ProcessDescriptor) Descriptor(org.openlca.core.model.descriptors.Descriptor) JsonObject(com.google.gson.JsonObject)

Aggregations

JsonImport (org.openlca.jsonld.input.JsonImport)28 Test (org.junit.Test)14 JsonExport (org.openlca.jsonld.output.JsonExport)8 AbstractZipTest (org.openlca.jsonld.AbstractZipTest)6 ProductSystem (org.openlca.core.model.ProductSystem)5 Flow (org.openlca.core.model.Flow)4 Process (org.openlca.core.model.Process)4 MemStore (org.openlca.jsonld.MemStore)4 Parameter (org.openlca.core.model.Parameter)3 TechFlow (org.openlca.core.matrix.index.TechFlow)2 Currency (org.openlca.core.model.Currency)2 FlowProperty (org.openlca.core.model.FlowProperty)2 ImpactCategory (org.openlca.core.model.ImpactCategory)2 Location (org.openlca.core.model.Location)2 ParameterRedefSet (org.openlca.core.model.ParameterRedefSet)2 Result (org.openlca.core.model.Result)2 UnitGroup (org.openlca.core.model.UnitGroup)2 ZipStore (org.openlca.jsonld.ZipStore)2 Gson (com.google.gson.Gson)1 JsonObject (com.google.gson.JsonObject)1