view flys-backend/src/main/java/de/intevation/flys/model/BedHeightEpoch.java @ 4573:b87073a05f9d

flys-client: Patch to render combobox options as clickable links. The way of passing data arguments to the links and further to the Artifact feeding service is somewhat hacked and should be refactored (later...).
author Christian Lins <christian.lins@intevation.de>
date Tue, 27 Nov 2012 12:50:10 +0100
parents b9a99fcc78c3
children
line wrap: on
line source
package de.intevation.flys.model;

import java.io.Serializable;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.GeneratedValue;
import javax.persistence.Column;
import javax.persistence.SequenceGenerator;
import javax.persistence.GenerationType;
import javax.persistence.JoinColumn;
import javax.persistence.OneToOne;
import javax.persistence.OneToMany;

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

import de.intevation.flys.backend.SessionHolder;


@Entity
@Table(name = "bed_height_epoch")
public class BedHeightEpoch implements Serializable {

    private Integer id;

    private River river;

    private TimeInterval timeInterval;

    private ElevationModel curElevationModel;
    private ElevationModel oldElevationModel;

    private Range range;

    private String evaluationBy;
    private String description;

    private List<BedHeightEpochValue> values;


    public BedHeightEpoch() {
    }


    public BedHeightEpoch(
        River          river,
        TimeInterval   timeInterval,
        Range          range,
        ElevationModel curElevationModel,
        ElevationModel oldElevationModel,
        String         evaluationBy,
        String         description
    ) {
        this.river             = river;
        this.timeInterval      = timeInterval;
        this.range             = range;
        this.curElevationModel = curElevationModel;
        this.oldElevationModel = oldElevationModel;
        this.evaluationBy      = evaluationBy;
        this.description       = description;
        this.values            = new ArrayList<BedHeightEpochValue>();
    }


    @Id
    @SequenceGenerator(
        name           = "SEQUENCE_BED_HEIGHT_EPOCH_ID_SEQ",
        sequenceName   = "BED_HEIGHT_EPOCH_ID_SEQ",
        allocationSize = 1)
    @GeneratedValue(
        strategy  = GenerationType.SEQUENCE,
        generator = "SEQUENCE_BED_HEIGHT_EPOCH_ID_SEQ")
    @Column(name = "id")
    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    @OneToOne
    @JoinColumn(name = "river_id" )
    public River getRiver() {
        return river;
    }

    public void setRiver(River river) {
        this.river = river;
    }

    @OneToOne
    @JoinColumn(name = "time_interval_id")
    public TimeInterval getTimeInterval() {
        return timeInterval;
    }

    public void setTimeInterval(TimeInterval timeInterval) {
        this.timeInterval = timeInterval;
    }

    @OneToOne
    @JoinColumn(name = "cur_elevation_model_id")
    public ElevationModel getCurElevationModel() {
        return curElevationModel;
    }

    public void setCurElevationModel(ElevationModel curElevationModel) {
        this.curElevationModel = curElevationModel;
    }

    @OneToOne
    @JoinColumn(name = "old_elevation_model_id")
    public ElevationModel getOldElevationModel() {
        return oldElevationModel;
    }

    public void setOldElevationModel(ElevationModel oldElevationModel) {
        this.oldElevationModel = oldElevationModel;
    }

    @OneToOne
    @JoinColumn(name = "range_id")
    public Range getRange() {
        return range;
    }

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

    @Column(name = "evaluation_by")
    public String getEvaluationBy() {
        return evaluationBy;
    }

    public void setEvaluationBy(String evaluationBy) {
        this.evaluationBy = evaluationBy;
    }

    @Column(name = "description")
    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    @OneToMany
    @JoinColumn(name = "bed_height_epoch_id")
    public List<BedHeightEpochValue> getValues() {
        return values;
    }

    public void setValues(List<BedHeightEpochValue> values) {
        this.values = values;
    }


    public static List<BedHeightEpoch> getBedHeightEpochs(
        River  river,
        double kmLo,
        double kmHi
    ) {
        Session session = SessionHolder.HOLDER.get();

        Query query = session.createQuery(
            "from BedHeightEpoch where river=:river");

        query.setParameter("river", river);

        // TODO Do km range filtering in SQL statement

        List<BedHeightEpoch> epochs = query.list();
        List<BedHeightEpoch> good   = new ArrayList<BedHeightEpoch>();

        OUTER: for (BedHeightEpoch e: epochs) {
            for (BedHeightEpochValue value: e.getValues()) {
                double station = value.getStation().doubleValue();

                if (station >= kmLo && station <= kmHi) {
                    good.add(e);
                    continue OUTER;
                }
            }
        }

        return good;
    }


    public static BedHeightEpoch getBedHeightEpochById(int id) {
        Session session = SessionHolder.HOLDER.get();

        Query query = session.createQuery(
            "from BedHeightEpoch where id=:id");

        query.setParameter("id", id);

        List<BedHeightEpoch> singles = query.list();

        return singles != null ? singles.get(0) : null;
    }
}
// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org