view flys-backend/src/main/java/de/intevation/flys/importer/ImportWstColumn.java @ 4198:1cdbd8a0c994

Added two new tables ClickableQDTable and ClickableWTable and made Ws and Qs clickable in historical discharge calculation. The new tables define listener interfaces (clicked lower or upper icon) to listen to user clicks. In addition to this, there is an enum ClickMode with NONE, SINGLE and RANGE options, which allows to specifiy, which icons are displayed in the tables. NONE means no icon for user clicks, SINGLE has 1 icon, RANGE 2 icons for lower and upper.
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Mon, 22 Oct 2012 13:31:25 +0200
parents 2e18e12fac11
children 99b452967737
line wrap: on
line source
package de.intevation.flys.importer;

import de.intevation.flys.model.Wst;
import de.intevation.flys.model.WstColumn;
import de.intevation.flys.model.River;
import de.intevation.flys.model.TimeInterval;

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

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

import java.math.BigDecimal;

import org.apache.log4j.Logger;

public class ImportWstColumn
{
    private static Logger log = Logger.getLogger(ImportWstColumn.class);

    protected ImportWst wst;
    protected String    name;
    protected String    description;
    protected Integer   position;

    protected ImportTimeInterval timeInterval;

    protected List<ImportWstColumnQRange> columnQRanges;
    protected List<ImportWstColumnValue>  columnValues;

    protected WstColumn peer;

    public ImportWstColumn() {
        columnQRanges = new ArrayList<ImportWstColumnQRange>();
        columnValues  = new ArrayList<ImportWstColumnValue>();
    }

    public ImportWstColumn(
        ImportWst wst,
        String    name,
        String    description,
        Integer   position
    ) {
        this();
        this.wst         = wst;
        this.name        = name;
        this.description = description;
        this.position    = position;
    }

    public ImportWst getWst() {
        return wst;
    }

    public void setWst(ImportWst wst) {
        this.wst = wst;
    }

    public String getName() {
        return name;
    }

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

    public String getDescription() {
        return description;
    }

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

    public Integer getPosition() {
        return position;
    }

    public void setPosition(Integer position) {
        this.position = position;
    }

    public void addColumnValue(BigDecimal position, BigDecimal w) {
        columnValues.add(
            new ImportWstColumnValue(this, position, w));
    }

    public void addColumnQRange(ImportWstQRange columnQRange) {
        columnQRanges.add(
            new ImportWstColumnQRange(this, columnQRange));
    }

    public void storeDependencies(River river) {
        log.info("store column '" + name + "'");
        WstColumn column = getPeer(river);

        for (ImportWstColumnQRange columnQRange: columnQRanges) {
            columnQRange.getPeer(river);
        }

        for (ImportWstColumnValue columnValue: columnValues) {
            columnValue.getPeer(river);
        }
    }

    public ImportTimeInterval getTimeInterval() {
        return timeInterval;
    }

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

    public WstColumn getPeer(River river) {
        if (peer == null) {
            Wst w = wst.getPeer(river);
            Session session = ImporterSession.getInstance().getDatabaseSession();
            Query query = session.createQuery(
                "from WstColumn where " +
                "wst=:wst and name=:name and description=:description" +
                " and position=:position");
            query.setParameter("wst",         w);
            query.setParameter("name",        name);
            query.setParameter("description", description);
            query.setParameter("position",    position);

            TimeInterval ti = timeInterval != null
                ? timeInterval.getPeer()
                : null;

            List<WstColumn> columns = query.list();
            if (columns.isEmpty()) {
                peer = new WstColumn(w, name, description, position, ti);
                session.save(peer);
            }
            else {
                peer = columns.get(0);
            }
        }
        return peer;
    }
}
// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org