view flys-backend/src/main/java/de/intevation/flys/importer/ImportGauge.java @ 192:f1fce41347ea

Added missing ImportGauge.getPeer() method flys-backend/trunk@1530 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Mon, 21 Mar 2011 10:27:14 +0000
parents c4fb5141ce11
children 31c48d54f09d
line wrap: on
line source
package de.intevation.flys.importer;

import java.io.File;

import java.util.List;

import java.math.BigDecimal;

import de.intevation.flys.model.River;
import de.intevation.flys.model.Gauge;

import org.hibernate.Session;
import org.hibernate.Query;

import java.io.IOException;

public class ImportGauge
{
    protected ImportRange range;

    protected File        staFile;
    protected File        atFile;

    protected String      name;
    protected BigDecimal  aeo;
    protected BigDecimal  datum;
    protected BigDecimal  station;

    protected Gauge  peer;

    public ImportGauge() {
    }

    public ImportGauge(ImportRange range, File staFile, File atFile) {
        this.range   = range;
        this.staFile = staFile;
        this.atFile  = atFile;
    }

    public void setRange(ImportRange range) {
        this.range = range;
    }

    public void setStaFile(File staFile) {
        this.staFile = staFile;
    }

    public File getStaFile() {
        return staFile;
    }

    public void setAtFile(File atFile) {
        this.atFile = atFile;
    }

    public File getAtFile() {
        return atFile;
    }

    public BigDecimal getAeo() {
        return aeo;
    }

    public void setAeo(BigDecimal aeo) {
        this.aeo = aeo;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public BigDecimal getDatum() {
        return datum;
    }

    public void setDatum(BigDecimal datum) {
        this.datum = datum;
    }

    public BigDecimal getStation() {
        return station;
    }

    public void setStation(BigDecimal station) {
        this.station = station;
    }

    public void parseDependencies() throws IOException {
        StaFileParser sfp = new StaFileParser();
        sfp.parse(this);
    }

    public void storeDependencies(River river) {
        Gauge gauge = getPeer(river);
        // TODO: Implement me!
    }

    public Gauge getPeer(River river) {
        if (peer == null) {
            Session session = Importer.sessionHolder.get();
            Query query = session.createQuery(
                "from Gauge where name=:name " +
                "and river.id=:id");
            query.setString("name", name);
            query.setInteger("id", river.getId());
            List<Gauge> gauges = query.list();
            if (gauges.isEmpty()) {
                peer = new Gauge(
                    name, river,
                    station, aeo, datum, 
                    range.getPeer(river));
                session.save(peer);
            }
            else {
                peer = gauges.get(0);
            }
        }
        return peer;
    }
}
// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org