Search in sources :

Example 1 with JsonExport

use of org.openlca.jsonld.output.JsonExport in project olca-modules by GreenDelta.

the class MetaDataExport method run.

@Override
public void run() {
    if (!export.withInventory && !export.withImpacts)
        return;
    try (var zip = ZipStore.open(new File(export.folder, "meta.zip"))) {
        var exp = new JsonExport(db, zip);
        if (export.withInventory) {
            writeProcesses(exp);
        }
        if (export.withImpacts) {
            writeImpactCategories(exp);
            writeImpactMethods(exp);
        }
    } catch (Exception e) {
        throw new RuntimeException("failed to write meta data in library export", e);
    }
}
Also used : JsonExport(org.openlca.jsonld.output.JsonExport) File(java.io.File)

Example 2 with JsonExport

use of org.openlca.jsonld.output.JsonExport in project olca-modules by GreenDelta.

the class LocationTest method doExport.

private void doExport(Location location, LocationDao dao) {
    with(zip -> {
        JsonExport export = new JsonExport(Tests.getDb(), zip);
        export.write(location);
    });
    dao.delete(location);
    Assert.assertFalse(dao.contains(location.refId));
}
Also used : JsonExport(org.openlca.jsonld.output.JsonExport)

Example 3 with JsonExport

use of org.openlca.jsonld.output.JsonExport in project olca-modules by GreenDelta.

the class ParameterRedefTest method testInProductSystem.

@Test
public void testInProductSystem() {
    // create the model
    var sys = new ProductSystem();
    sys.refId = UUID.randomUUID().toString();
    sys.parameterSets.add(ParameterRedefSet.of("baseline", redef));
    db.insert(sys);
    // write and clear DB
    with(zip -> new JsonExport(db, zip).write(sys));
    db.clear();
    Assert.assertNull(db.get(ProductSystem.class, sys.refId));
    Assert.assertNull(paramDao.getForRefId(globalParam.refId));
    // import and check
    with(zip -> new JsonImport(zip, db).run());
    var copy = db.get(ProductSystem.class, sys.refId);
    Assert.assertEquals("R", copy.parameterSets.get(0).parameters.get(0).name);
    Parameter p = paramDao.getForRefId(globalParam.refId);
    Assert.assertEquals("R", p.name);
}
Also used : JsonImport(org.openlca.jsonld.input.JsonImport) ProductSystem(org.openlca.core.model.ProductSystem) Parameter(org.openlca.core.model.Parameter) JsonExport(org.openlca.jsonld.output.JsonExport) AbstractZipTest(org.openlca.jsonld.AbstractZipTest) Test(org.junit.Test)

Example 4 with JsonExport

use of org.openlca.jsonld.output.JsonExport in project olca-modules by GreenDelta.

the class ParameterTest method testGlobal.

@Test
public void testGlobal() {
    var param = Parameter.global("param", "1+1");
    var dao = new ParameterDao(Tests.getDb());
    dao.insert(param);
    with(zip -> {
        JsonExport export = new JsonExport(Tests.getDb(), zip);
        export.write(param);
    });
    dao.delete(param);
    Assert.assertFalse(dao.contains(param.refId));
    with(zip -> {
        JsonImport jImport = new JsonImport(zip, Tests.getDb());
        jImport.run();
    });
    Assert.assertTrue(dao.contains(param.refId));
    dao.delete(param);
}
Also used : ParameterDao(org.openlca.core.database.ParameterDao) JsonImport(org.openlca.jsonld.input.JsonImport) JsonExport(org.openlca.jsonld.output.JsonExport) AbstractZipTest(org.openlca.jsonld.AbstractZipTest) Test(org.junit.Test)

Example 5 with JsonExport

use of org.openlca.jsonld.output.JsonExport in project olca-modules by GreenDelta.

the class ParameterTest method testProcess.

@Test
public void testProcess() {
    var process = new Process();
    process.refId = UUID.randomUUID().toString();
    var param = process.parameter("param", 42);
    var dao = new ProcessDao(Tests.getDb());
    dao.insert(process);
    with(zip -> {
        JsonExport export = new JsonExport(Tests.getDb(), zip);
        export.write(process);
    });
    dao.delete(process);
    with(zip -> {
        JsonImport jImport = new JsonImport(zip, Tests.getDb());
        jImport.run();
    });
    var clone = dao.getForRefId(process.refId);
    Assert.assertEquals(param.refId, clone.parameters.get(0).refId);
}
Also used : JsonImport(org.openlca.jsonld.input.JsonImport) ProcessDao(org.openlca.core.database.ProcessDao) Process(org.openlca.core.model.Process) JsonExport(org.openlca.jsonld.output.JsonExport) AbstractZipTest(org.openlca.jsonld.AbstractZipTest) Test(org.junit.Test)

Aggregations

JsonExport (org.openlca.jsonld.output.JsonExport)25 Test (org.junit.Test)13 JsonImport (org.openlca.jsonld.input.JsonImport)7 AbstractZipTest (org.openlca.jsonld.AbstractZipTest)6 File (java.io.File)4 MemStore (org.openlca.jsonld.MemStore)3 Parameter (org.openlca.core.model.Parameter)2 Process (org.openlca.core.model.Process)2 ProductSystem (org.openlca.core.model.ProductSystem)2 Rpc (org.openlca.ipc.Rpc)2 JsonArray (com.google.gson.JsonArray)1 JsonObject (com.google.gson.JsonObject)1 IOException (java.io.IOException)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 ImpactCategoryDao (org.openlca.core.database.ImpactCategoryDao)1 ParameterDao (org.openlca.core.database.ParameterDao)1 ProcessDao (org.openlca.core.database.ProcessDao)1 ProductSystemDao (org.openlca.core.database.ProductSystemDao)1 Currency (org.openlca.core.model.Currency)1