Mercurial > dive4elements > river
view backend/src/main/java/org/dive4elements/river/importer/ImportBedHeight.java @ 9659:75bd347147ad
Importer (s/u-info) extensions: infrastructures: detecting, logging, cancelling in case of wrong column titles,
detecting, logging and skipping lines with duplicate km+bank
author | mschaefer |
---|---|
date | Mon, 23 Mar 2020 15:37:37 +0100 |
parents | 4c5eeaff554c |
children |
line wrap: on
line source
/* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde * Software engineering by Intevation GmbH * * 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; import java.util.ArrayList; import java.util.List; import org.apache.log4j.Logger; import org.dive4elements.river.importer.common.StoreMode; import org.dive4elements.river.model.BedHeight; import org.dive4elements.river.model.BedHeightType; import org.dive4elements.river.model.ElevationModel; import org.dive4elements.river.model.Range; import org.dive4elements.river.model.River; import org.hibernate.Query; import org.hibernate.Session; public class ImportBedHeight { private static Logger log = Logger.getLogger(ImportBedHeight.class); protected Integer year; protected String evaluationBy; protected String description; protected ImportRange range; protected ImportBedHeightType type; protected ImportLocationSystem locationSystem; protected ImportElevationModel curElevationModel; protected ImportElevationModel oldElevationModel; protected String sounding_width_info; protected String notes; protected List<ImportBedHeightValue> values; protected StoreMode storeMode; protected BedHeight peer; public ImportBedHeight(final String description) { this.description = description; this.values = new ArrayList<>(); this.storeMode = StoreMode.NONE; } public String getDescription() { return this.description; } public int getValueCount() { return this.values.size(); } public void setYear(final int year) { this.year = year; } public void setTimeInterval(final ImportTimeInterval timeInterval) { // do nothing } public void setEvaluationBy(final String evaluationBy) { this.evaluationBy = evaluationBy; } public void setDescription(final String description) { this.description = description; } public void setRange(final ImportRange range) { this.range = range; } public void setType(final ImportBedHeightType type) { this.type = type; } public void setLocationSystem(final ImportLocationSystem locationSystem) { this.locationSystem = locationSystem; } public void setCurElevationModel(final ImportElevationModel curElevationModel) { this.curElevationModel = curElevationModel; } public void setOldElevationModel(final ImportElevationModel oldElevationModel) { this.oldElevationModel = oldElevationModel; } public void setSoundingWidthInfo(final String sounding_width_info) { this.sounding_width_info = sounding_width_info; } public void setNotes(final String notes) { this.notes = notes; } public void addValue(final ImportBedHeightValue value) { this.values.add(value); } public void storeDependencies(final River river) { log.info("Store dependencies for single: '" + getDescription() + "'"); if (this.type != null) { this.type.storeDependencies(); } if (this.locationSystem != null) { this.locationSystem.storeDependencies(); } if (this.curElevationModel != null) { this.curElevationModel.storeDependencies(); } if (this.oldElevationModel != null) { this.oldElevationModel.storeDependencies(); } final BedHeight peer = getPeer(river); if (peer != null) { for (final ImportBedHeightValue value: this.values) { value.storeDependencies(peer); } } final Session session = ImporterSession.getInstance().getDatabaseSession(); session.flush(); } public BedHeight getPeer(final River river) { if (this.peer != null) return null; final BedHeightType theType = this.type != null ? this.type.getPeer() : null; final ElevationModel theCurModel = this.curElevationModel.getPeer(); final Range theRange = (this.range != null) ? this.range.getPeer(river) : null; if (theType == null) { log.warn("BHS: No bed height type given. Skip file '" + this.description + "'"); return null; } if (theCurModel == null) { log.warn("BHS: No elevation model given. Skip file '" + this.description + "'"); return null; } if (theRange == null) { log.warn("BHS: No km-range given: '" + this.description + "'"); } final Session session = ImporterSession.getInstance().getDatabaseSession(); final Query query = session.createQuery("FROM BedHeight WHERE (river=:river) AND (year=:year)" + " AND (type=:type) AND (locationSystem=:locationSystem)" + " AND (curElevationModel=:curElevationModel) AND (range=:range)"); query.setParameter("river", river); query.setParameter("year", this.year); query.setParameter("type", theType); query.setParameter("locationSystem", this.locationSystem.getPeer()); query.setParameter("curElevationModel", theCurModel); query.setParameter("range", this.range.getPeer(river)); final List<BedHeight> bedHeights = query.list(); if (bedHeights.isEmpty()) { log.info("Create new BedHeight DB instance."); this.peer = new BedHeight(river, this.year, theType, this.locationSystem.getPeer(), theCurModel, (this.oldElevationModel != null) ? this.oldElevationModel.getPeer() : null, this.range.getPeer(river), this.evaluationBy, this.description, this.sounding_width_info, this.notes); session.save(this.peer); this.storeMode = StoreMode.INSERT; } else { this.peer = bedHeights.get(0); this.storeMode = StoreMode.UPDATE; } return this.peer; } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :