Search in sources :

Example 6 with SourceDao

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

the class SourceImport method of.

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

Aggregations

SourceDao (org.openlca.core.database.SourceDao)6 Source (org.openlca.core.model.Source)4 Test (org.junit.Test)1 TextDropComponent (org.openlca.app.components.TextDropComponent)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 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 ProcessDao (org.openlca.core.database.ProcessDao)1 ProductSystemDao (org.openlca.core.database.ProductSystemDao)1 ProjectDao (org.openlca.core.database.ProjectDao)1 SocialIndicatorDao (org.openlca.core.database.SocialIndicatorDao)1 UnitDao (org.openlca.core.database.UnitDao)1 UnitGroupDao (org.openlca.core.database.UnitGroupDao)1