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);
}
}
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));
}
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);
}
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);
}
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);
}
Aggregations