Mercurial > dive4elements > river
view backend/src/main/java/org/dive4elements/river/importer/uinfo/importitem/VegetationTypeImport.java @ 9014:201817aa7b1c
Added the missing vegetation import classes
author | mschaefer |
---|---|
date | Wed, 18 Apr 2018 12:11:39 +0200 |
parents | |
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.importer.uinfo.importitem; import java.util.List; import org.apache.log4j.Logger; import org.dive4elements.river.importer.ImporterSession; import org.dive4elements.river.model.uinfo.VegetationType; import org.hibernate.Query; import org.hibernate.Session; /** * Imported vegetation zone type * * @author Matthias Schäfer * */ public class VegetationTypeImport implements Comparable<VegetationTypeImport> { /***** FIELDS *****/ private static final Logger log = Logger.getLogger(VegetationTypeImport.class); protected Integer id; protected String name; protected VegetationType peer; /***** CONSTRUCTOR *****/ public VegetationTypeImport() { } public VegetationTypeImport(final int id) { this.id = Integer.valueOf(id); } /***** METHODS *****/ @Override public int compareTo(final VegetationTypeImport other) { return this.id.compareTo(other.getId()); } @Override public int hashCode() { return this.id; } public Integer getId() { return this.id; } public void setId(final Integer id) { this.id = id; } public String getName() { return this.name; } public void setName(final String name) { this.name = name; } public VegetationType getPeer() { if (this.peer != null) return this.peer; final Session session = ImporterSession.getInstance().getDatabaseSession(); final Query query = session.createQuery("FROM VegetationType WHERE id=:id"); query.setParameter("id", this.id); final List<VegetationType> types = query.list(); if (types.isEmpty()) { // Type table is not modifiable by the importer // this.peer = new VegetationType(this.name); // session.save(this.peer); // log.info(String.format("Create new database instance: %d, '%s'", this.peer.getId(), this.name)); } else { this.peer = types.get(0); } return this.peer; } }