Search in sources :

Example 1 with SocialIndicatorDao

use of org.openlca.core.database.SocialIndicatorDao in project olca-modules by GreenDelta.

the class Sequence method init.

private void init(IDatabase db) {
    index(CATEGORY, new CategoryDao(db));
    index(LOCATION, new LocationDao(db));
    index(ACTOR, new ActorDao(db));
    index(SOURCE, new SourceDao(db));
    index(UNIT, new UnitDao(db));
    index(UNIT_GROUP, new UnitGroupDao(db));
    index(FLOW_PROPERTY, new FlowPropertyDao(db));
    index(FLOW, new FlowDao(db));
    index(CURRENCY, new CurrencyDao(db));
    index(PROCESS, new ProcessDao(db));
    index(PRODUCT_SYSTEM, new ProductSystemDao(db));
    index(IMPACT_CATEGORY, new ImpactCategoryDao(db));
    index(IMPACT_METHOD, new ImpactMethodDao(db));
    index(NW_SET, new NwSetDao(db));
    index(PROJECT, new ProjectDao(db));
    index(DQ_SYSTEM, new DQSystemDao(db));
    index(SOCIAL_INDICATOR, new SocialIndicatorDao(db));
}
Also used : SourceDao(org.openlca.core.database.SourceDao) CurrencyDao(org.openlca.core.database.CurrencyDao) ImpactCategoryDao(org.openlca.core.database.ImpactCategoryDao) CategoryDao(org.openlca.core.database.CategoryDao) ActorDao(org.openlca.core.database.ActorDao) FlowPropertyDao(org.openlca.core.database.FlowPropertyDao) LocationDao(org.openlca.core.database.LocationDao) UnitDao(org.openlca.core.database.UnitDao) DQSystemDao(org.openlca.core.database.DQSystemDao) NwSetDao(org.openlca.core.database.NwSetDao) FlowDao(org.openlca.core.database.FlowDao) ImpactMethodDao(org.openlca.core.database.ImpactMethodDao) ProcessDao(org.openlca.core.database.ProcessDao) UnitGroupDao(org.openlca.core.database.UnitGroupDao) SocialIndicatorDao(org.openlca.core.database.SocialIndicatorDao) ImpactCategoryDao(org.openlca.core.database.ImpactCategoryDao) ProductSystemDao(org.openlca.core.database.ProductSystemDao) ProjectDao(org.openlca.core.database.ProjectDao)

Example 2 with SocialIndicatorDao

use of org.openlca.core.database.SocialIndicatorDao in project olca-modules by GreenDelta.

the class SocialIndicatorTest method testSocialIndicator.

@Test
public void testSocialIndicator() {
    SocialIndicatorDao dao = new SocialIndicatorDao(Tests.getDb());
    SocialIndicator indicator = createModel(dao);
    doExport(indicator, dao);
    doImport(dao, indicator);
    dao.delete(indicator);
}
Also used : SocialIndicator(org.openlca.core.model.SocialIndicator) SocialIndicatorDao(org.openlca.core.database.SocialIndicatorDao) AbstractZipTest(org.openlca.jsonld.AbstractZipTest) Test(org.junit.Test)

Example 3 with SocialIndicatorDao

use of org.openlca.core.database.SocialIndicatorDao in project olca-modules by GreenDelta.

the class TestSocialAspectImport method testCopySocialAspects.

/**
 * Test that social aspects of processes are copied between databases:
 * https://github.com/GreenDelta/olca-app/issues/88. We ignore this test by
 * default, because creating temporary databases take so long...
 */
@Test
@Ignore
public void testCopySocialAspects() throws Exception {
    IDatabase db1 = Derby.createInMemory();
    SocialIndicator indicator = new SocialIndicator();
    indicator.refId = "si";
    SocialIndicatorDao idao = new SocialIndicatorDao(db1);
    idao.insert(indicator);
    Process process = new Process();
    process.refId = "pr";
    SocialAspect aspect = new SocialAspect();
    aspect.indicator = indicator;
    process.socialAspects.add(aspect);
    ProcessDao pdao = new ProcessDao(db1);
    pdao.insert(process);
    IDatabase db2 = Derby.createInMemory();
    DatabaseImport imp = new DatabaseImport(db1, db2);
    imp.run();
    db1.close();
    idao = new SocialIndicatorDao(db2);
    indicator = idao.getForRefId("si");
    assertNotNull(indicator);
    pdao = new ProcessDao(db2);
    process = pdao.getForRefId("pr");
    assertEquals(1, process.socialAspects.size());
    aspect = process.socialAspects.get(0);
    assertNotNull(aspect.indicator);
    assertEquals("si", aspect.indicator.refId);
    db2.close();
}
Also used : IDatabase(org.openlca.core.database.IDatabase) SocialAspect(org.openlca.core.model.SocialAspect) ProcessDao(org.openlca.core.database.ProcessDao) SocialIndicator(org.openlca.core.model.SocialIndicator) Process(org.openlca.core.model.Process) SocialIndicatorDao(org.openlca.core.database.SocialIndicatorDao) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 4 with SocialIndicatorDao

use of org.openlca.core.database.SocialIndicatorDao in project olca-modules by GreenDelta.

the class SocialIndicatorImport method of.

@Override
public ImportStatus<SocialIndicator> of(String id) {
    var indicator = imp.get(SocialIndicator.class, id);
    // check if we are in update mode
    var update = false;
    if (indicator != null) {
        update = imp.shouldUpdate(indicator);
        if (!update) {
            return ImportStatus.skipped(indicator);
        }
    }
    // resolve the proto object
    var proto = imp.reader.getSocialIndicator(id);
    if (proto == null)
        return indicator != null ? ImportStatus.skipped(indicator) : ImportStatus.error("Could not resolve SocialIndicator " + id);
    var wrap = ProtoWrap.of(proto);
    if (update) {
        if (imp.skipUpdate(indicator, wrap))
            return ImportStatus.skipped(indicator);
    }
    // map the data
    if (indicator == null) {
        indicator = new SocialIndicator();
        indicator.refId = id;
    }
    wrap.mapTo(indicator, imp);
    map(proto, indicator);
    // insert or update it
    var dao = new SocialIndicatorDao(imp.db);
    indicator = update ? dao.update(indicator) : dao.insert(indicator);
    imp.putHandled(indicator);
    return update ? ImportStatus.updated(indicator) : ImportStatus.created(indicator);
}
Also used : SocialIndicator(org.openlca.core.model.SocialIndicator) ProtoSocialIndicator(org.openlca.proto.ProtoSocialIndicator) SocialIndicatorDao(org.openlca.core.database.SocialIndicatorDao)

Example 5 with SocialIndicatorDao

use of org.openlca.core.database.SocialIndicatorDao in project olca-app by GreenDelta.

the class SocialAspectsPage method addIndicator.

private void addIndicator(Descriptor d) {
    SocialIndicatorDao dao = new SocialIndicatorDao(Database.get());
    SocialIndicator i = dao.getForId(d.id);
    SocialAspect a = new SocialAspect();
    a.indicator = i;
    getModel().socialAspects.add(a);
    treeModel.addAspect(a);
    tree.refresh();
    editor.setDirty(true);
}
Also used : SocialAspect(org.openlca.core.model.SocialAspect) SocialIndicator(org.openlca.core.model.SocialIndicator) SocialIndicatorDao(org.openlca.core.database.SocialIndicatorDao)

Aggregations

SocialIndicatorDao (org.openlca.core.database.SocialIndicatorDao)5 SocialIndicator (org.openlca.core.model.SocialIndicator)4 Test (org.junit.Test)2 ProcessDao (org.openlca.core.database.ProcessDao)2 SocialAspect (org.openlca.core.model.SocialAspect)2 Ignore (org.junit.Ignore)1 ActorDao (org.openlca.core.database.ActorDao)1 CategoryDao (org.openlca.core.database.CategoryDao)1 CurrencyDao (org.openlca.core.database.CurrencyDao)1 DQSystemDao (org.openlca.core.database.DQSystemDao)1 FlowDao (org.openlca.core.database.FlowDao)1 FlowPropertyDao (org.openlca.core.database.FlowPropertyDao)1 IDatabase (org.openlca.core.database.IDatabase)1 ImpactCategoryDao (org.openlca.core.database.ImpactCategoryDao)1 ImpactMethodDao (org.openlca.core.database.ImpactMethodDao)1 LocationDao (org.openlca.core.database.LocationDao)1 NwSetDao (org.openlca.core.database.NwSetDao)1 ProductSystemDao (org.openlca.core.database.ProductSystemDao)1 ProjectDao (org.openlca.core.database.ProjectDao)1 SourceDao (org.openlca.core.database.SourceDao)1