Mercurial > dive4elements > river
view backend/src/main/java/org/dive4elements/river/importer/sinfo/importitem/CollisionTypeImport.java @ 9657:a79881a892c9
Importer (s/u-info) extensions: depth-evolution: corrected directory name Bezug_aktueller_GlW,
detecting and logging of wrong units, then cancelling,
various checks of the plausibility of the meta data year values and cancelling in case of errors,
detecting and logging missing change values, skipping those lines
author | mschaefer |
---|---|
date | Mon, 23 Mar 2020 15:26:50 +0100 |
parents | 50416a0df385 |
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.sinfo.importitem; import java.util.List; import org.apache.log4j.Logger; import org.dive4elements.river.importer.ImporterSession; import org.dive4elements.river.model.sinfo.CollisionType; import org.hibernate.Query; import org.hibernate.Session; /** * Imported collision type * * @author Matthias Schäfer * */ public class CollisionTypeImport implements Comparable<CollisionTypeImport> { /***** FIELDS *****/ private static final Logger log = Logger.getLogger(CollisionTypeImport.class); protected String name; protected CollisionType peer; /***** CONSTRUCTOR *****/ public CollisionTypeImport() { } public CollisionTypeImport(final String name) { this.name = name; } /***** METHODS *****/ @Override public int compareTo(final CollisionTypeImport other) { return this.name.compareTo(other.name); } @Override public int hashCode() { return this.name.hashCode(); } public String getName() { return this.name; } public void setName(final String name) { this.name = name; } public CollisionType getPeer() { if (this.peer != null) return this.peer; final Session session = ImporterSession.getInstance().getDatabaseSession(); final Query query = session.createQuery("FROM CollisionType WHERE lower(name)=:name"); query.setParameter("name", this.name.trim().toLowerCase()); final List<CollisionType> types = query.list(); if (types.isEmpty()) { this.peer = new CollisionType(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; } }