view backend/src/main/java/org/dive4elements/river/model/uinfo/VegetationType.java @ 9661:9b8ba3b83a15

Importer (s/u-info) vegetation zones: new database column in vegetation_type table for german type name, localized vegetation type names by querying the database instead of translating by resource property, detecting and cancelling the import of a second vegetation zone file for a river, detecting, logging, cancelling in case of wrong column titles, detecting, logging and ignoring lines with missing (color) values, comparing vegetation zone name and class with the database and logging+ignoring in case of inconsistencies, starting the most elevated zone with 0 instead of -1 overflow days
author mschaefer
date Mon, 23 Mar 2020 16:38:12 +0100
parents 361de818f76e
children
line wrap: on
line source
/* Copyright (C) 2017 by Bundesanstalt für Gewässerkunde
 * Software engineering by
 *  Björnsen Beratende Ingenieure GmbH
 *  Dr. Schumacher Ingenieurbüro für Wasser und Umwelt
 *
 * This file is Free Software under the GNU AGPL (>=v3)
 * and comes with ABSOLUTELY NO WARRANTY! Check out the
 * documentation coming with Dive4Elements River for details.
 */

package org.dive4elements.river.model.uinfo;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;

import org.dive4elements.river.backend.SessionHolder;
import org.hibernate.Query;
import org.hibernate.Session;

/**
 * Hibernate binding for the DB table vegetation_type
 *
 * @author Matthias Schäfer
 *
 */
@Entity
@Table(name = "vegetation_type")
public class VegetationType implements Serializable {

    /***** FIELDS *****/

    private static final long serialVersionUID = -845317173014273709L;

    private Integer id;

    private String  name;

    private String de_name;

    /***** CONSTRUCTORS *****/

    public VegetationType() {
    }

    public VegetationType(final String name) {
        this.name = name;
    }

    /***** METHODS *****/

    @Id
    @Column(name = "id")
    public Integer getId() {
        return this.id;
    }

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

    @Column(name = "name")
    public String getName() {
        return this.name;
    }

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

    @Column(name = "de_name")
    public String getDe_name() {
        return this.de_name;
    }

    public void setDe_name(final String de_name) {
        this.de_name = de_name;
    }

    /**
     * Queries all vegetation types from the database, ordered by id
     */
    public static List<VegetationType> getTypes() {
        return getTypes(SessionHolder.HOLDER.get());
    }

    /**
     * Queries all vegetation types from the database, ordered by id
     */
    public static List<VegetationType> getTypes(final Session session) {
        final Query query = session.createQuery("FROM VegetationType ORDER BY id");
        return new ArrayList<>(query.list());
    }

    /**
     * Localized name of the vegetation type
     */
    public String getLocalizedName(final Locale locale) {
        if ((locale == Locale.GERMAN) || (locale == Locale.GERMANY))
            return getDe_name();
        else
            return getName();
    }
}

http://dive4elements.wald.intevation.org