Search in sources :

Example 1 with LocationDao

use of org.openlca.core.database.LocationDao 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 LocationDao

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

the class LocationExport method doIt.

@Override
protected void doIt(CSVPrinter printer, IDatabase db) throws IOException {
    log.trace("write locations");
    LocationDao dao = new LocationDao(db);
    List<Location> locations = dao.getAll();
    for (Location location : locations) {
        Object[] line = createLine(location);
        printer.printRecord(line);
    }
    log.trace("{} locations written", locations.size());
}
Also used : LocationDao(org.openlca.core.database.LocationDao) Location(org.openlca.core.model.Location)

Example 3 with LocationDao

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

the class GeoJsonImport method run.

@Override
public void run() {
    try {
        // parse GeoJSON
        log.trace("parse GeoJSON file {}", file);
        FeatureCollection coll = GeoJSON.read(file);
        if (coll == null || coll.features.isEmpty())
            return;
        // index locations
        LocationDao dao = new LocationDao(db);
        indexLocations(dao);
        // match and update the locations
        for (Feature f : coll.features) {
            if (f.geometry == null || f.properties == null)
                continue;
            Location loc = findMatch(f);
            if (loc == null)
                continue;
            loc.geodata = GeoJSON.pack(FeatureCollection.of(f.geometry));
            dao.update(loc);
        }
    } catch (Exception e) {
        log.error("Failed to import GeoJSON file " + file, e);
    }
}
Also used : FeatureCollection(org.openlca.geo.geojson.FeatureCollection) LocationDao(org.openlca.core.database.LocationDao) Feature(org.openlca.geo.geojson.Feature) Location(org.openlca.core.model.Location)

Example 4 with LocationDao

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

the class LocationResult method getLocation.

private Location getLocation(long id) {
    Location loc = cache.get(id);
    if (loc != null)
        return loc;
    loc = new LocationDao(db).getForId(id);
    cache.put(id, loc);
    return loc;
}
Also used : LocationDao(org.openlca.core.database.LocationDao) Location(org.openlca.core.model.Location)

Example 5 with LocationDao

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

the class Library method syncElementaryFlows.

/**
 * Returns the elementary flows of the library in matrix order. If this
 * information is not present or something went wrong while synchronizing
 * the flow index with the database, an empty option is returned.
 */
public Optional<EnviIndex> syncElementaryFlows(IDatabase db) {
    var proto = getElemFlowIndex();
    int size = proto.getFlowCount();
    if (size == 0)
        return Optional.empty();
    var info = getInfo();
    var index = info.isRegionalized() ? EnviIndex.createRegionalized() : EnviIndex.create();
    var flows = descriptors(new FlowDao(db));
    var locations = descriptors(new LocationDao(db));
    for (int i = 0; i < size; i++) {
        var entry = proto.getFlow(i);
        var flow = flows.get(entry.getFlow().getId());
        var location = locations.get(entry.getLocation().getId());
        if (flow == null)
            return Optional.empty();
        if (entry.getIsInput()) {
            index.add(EnviFlow.inputOf(flow, location));
        } else {
            index.add(EnviFlow.outputOf(flow, location));
        }
    }
    return Optional.of(index);
}
Also used : FlowDao(org.openlca.core.database.FlowDao) LocationDao(org.openlca.core.database.LocationDao)

Aggregations

LocationDao (org.openlca.core.database.LocationDao)18 Location (org.openlca.core.model.Location)11 FlowDao (org.openlca.core.database.FlowDao)4 Test (org.junit.Test)3 ProcessDao (org.openlca.core.database.ProcessDao)3 Flow (org.openlca.core.model.Flow)3 ProcessDescriptor (org.openlca.core.model.descriptors.ProcessDescriptor)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Objects (java.util.Objects)2 Collectors (java.util.stream.Collectors)2 FlowPropertyDao (org.openlca.core.database.FlowPropertyDao)2 IDatabase (org.openlca.core.database.IDatabase)2 FlowPropertyFactor (org.openlca.core.model.FlowPropertyFactor)2 Unit (org.openlca.core.model.Unit)2 AbstractZipTest (org.openlca.jsonld.AbstractZipTest)2 Collections (java.util.Collections)1 Map (java.util.Map)1 Stream (java.util.stream.Stream)1 M (org.openlca.app.M)1