Mercurial > dive4elements > river
diff backend/src/main/java/org/dive4elements/river/importer/ImportBedHeight.java @ 8975:a0a0a7f912ab
Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
author | mschaefer |
---|---|
date | Tue, 03 Apr 2018 10:40:57 +0200 |
parents | 5e38e2924c07 |
children | 392bbcd8a88b |
line wrap: on
line diff
--- a/backend/src/main/java/org/dive4elements/river/importer/ImportBedHeight.java Tue Apr 03 10:37:30 2018 +0200 +++ b/backend/src/main/java/org/dive4elements/river/importer/ImportBedHeight.java Tue Apr 03 10:40:57 2018 +0200 @@ -12,15 +12,13 @@ import java.util.List; import org.apache.log4j.Logger; - -import org.hibernate.Session; -import org.hibernate.Query; - 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 @@ -37,165 +35,155 @@ protected ImportLocationSystem locationSystem; protected ImportElevationModel curElevationModel; protected ImportElevationModel oldElevationModel; + protected String sounding_width_info; + protected String comment; protected List<ImportBedHeightValue> values; protected BedHeight peer; - public ImportBedHeight(String description) { + public ImportBedHeight(final String description) { this.description = description; - this.values = new ArrayList<ImportBedHeightValue>(); + this.values = new ArrayList<>(); } public String getDescription() { - return description; + return this.description; } public int getValueCount() { - return values.size(); + return this.values.size(); } - public void setYear(int year) { + public void setYear(final int year) { this.year = year; } - public void setTimeInterval(ImportTimeInterval timeInterval) { + public void setTimeInterval(final ImportTimeInterval timeInterval) { // do nothing } - public void setEvaluationBy(String evaluationBy) { + public void setEvaluationBy(final String evaluationBy) { this.evaluationBy = evaluationBy; } - public void setDescription(String description) { + public void setDescription(final String description) { this.description = description; } - public void setRange(ImportRange range) { + public void setRange(final ImportRange range) { this.range = range; } - public void setType(ImportBedHeightType type) { + public void setType(final ImportBedHeightType type) { this.type = type; } - public void setLocationSystem(ImportLocationSystem locationSystem) { + public void setLocationSystem(final ImportLocationSystem locationSystem) { this.locationSystem = locationSystem; } - public void setCurElevationModel(ImportElevationModel curElevationModel) { + public void setCurElevationModel(final ImportElevationModel curElevationModel) { this.curElevationModel = curElevationModel; } - public void setOldElevationModel(ImportElevationModel oldElevationModel) { + public void setOldElevationModel(final ImportElevationModel oldElevationModel) { this.oldElevationModel = oldElevationModel; } - public void addValue(ImportBedHeightValue value) { - values.add((ImportBedHeightValue) value); + public void setSoundingWidthInfo(final String sounding_width_info) { + this.sounding_width_info = sounding_width_info; } - public void storeDependencies(River river) { + public void setComment(final String comment) { + this.comment = comment; + } + + public void addValue(final ImportBedHeightValue value) { + this.values.add(value); + } + + public void storeDependencies(final River river) { log.info("Store dependencies for single: '" + getDescription() + "'"); - if (type != null) { - type.storeDependencies(); + if (this.type != null) { + this.type.storeDependencies(); } - if (locationSystem != null) { - locationSystem.storeDependencies(); - } - - if (curElevationModel != null) { - curElevationModel.storeDependencies(); + if (this.locationSystem != null) { + this.locationSystem.storeDependencies(); } - if (oldElevationModel != null) { - oldElevationModel.storeDependencies(); + if (this.curElevationModel != null) { + this.curElevationModel.storeDependencies(); } - BedHeight peer = getPeer(river); + if (this.oldElevationModel != null) { + this.oldElevationModel.storeDependencies(); + } + + final BedHeight peer = getPeer(river); if (peer != null) { - for (ImportBedHeightValue value: values) { + for (final ImportBedHeightValue value: this.values) { value.storeDependencies(peer); } } - Session session = ImporterSession.getInstance().getDatabaseSession(); + final Session session = ImporterSession.getInstance().getDatabaseSession(); session.flush(); } - public BedHeight getPeer(River river) { - if (peer == null) { - BedHeightType theType = type != null ? type.getPeer() : null; - ElevationModel theCurModel = curElevationModel.getPeer(); - Range theRange = range != null - ? range.getPeer(river) - : null; - - if (theType == null) { - log.warn("BHS: No bed height type given. Skip file '" + - description + "'"); - return null; - } - - if (theCurModel == null) { - log.warn("BHS: No elevation model given. Skip file '" + - description + "'"); - return null; - } - - if (theRange == null) { - log.warn("BHS: No km-range given: '" + - description + "'"); - } - - Session session = ImporterSession.getInstance() - .getDatabaseSession(); + public BedHeight getPeer(final River river) { + if (this.peer != null) + return null; - 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", year); - query.setParameter("type", theType); - query.setParameter("locationSystem", locationSystem.getPeer()); - query.setParameter("curElevationModel", theCurModel); - query.setParameter("range", range.getPeer(river)); - - List<BedHeight> bedHeights = query.list(); - if (bedHeights.isEmpty()) { - log.info("Create new BedHeight DB instance."); + 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; - peer = new BedHeight( - river, - year, - theType, - locationSystem.getPeer(), - theCurModel, - oldElevationModel != null - ? oldElevationModel.getPeer() - : null, - range.getPeer(river), - evaluationBy, - description - ); - - session.save(peer); - } - else { - peer = bedHeights.get(0); - } + if (theType == null) { + log.warn("BHS: No bed height type given. Skip file '" + this.description + "'"); + return null; } - return peer; + 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.comment); + session.save(this.peer); + } + else { + this.peer = bedHeights.get(0); + } + + return this.peer; } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :