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