Mercurial > dive4elements > river
changeset 2817:8979f2294af9
Finished parsing MINFO specific sediment density.
flys-backend/trunk@4234 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Fri, 13 Apr 2012 11:45:29 +0000 |
parents | 70b4a31a3306 |
children | 25ed1f18fcc4 |
files | flys-backend/ChangeLog flys-backend/doc/schema/oracle-minfo.sql flys-backend/src/main/java/de/intevation/flys/backend/SessionFactoryProvider.java flys-backend/src/main/java/de/intevation/flys/importer/ImportDepth.java flys-backend/src/main/java/de/intevation/flys/importer/ImportRiver.java flys-backend/src/main/java/de/intevation/flys/importer/ImportSedimentDensity.java flys-backend/src/main/java/de/intevation/flys/importer/ImportSedimentDensityValue.java flys-backend/src/main/java/de/intevation/flys/importer/parsers/SedimentDensityParser.java flys-backend/src/main/java/de/intevation/flys/model/SedimentDensity.java flys-backend/src/main/java/de/intevation/flys/model/SedimentDensityValue.java |
diffstat | 10 files changed, 256 insertions(+), 19 deletions(-) [+] |
line wrap: on
line diff
--- a/flys-backend/ChangeLog Fri Apr 13 10:59:15 2012 +0000 +++ b/flys-backend/ChangeLog Fri Apr 13 11:45:29 2012 +0000 @@ -1,3 +1,27 @@ +2012-04-13 Ingo Weinzierl <ingo@intevation.de> + + * doc/schema/oracle-minfo.sql: Added a description field to table + sediment_density. + + * src/main/java/de/intevation/flys/model/SedimentDensityValue.java, + src/main/java/de/intevation/flys/model/SedimentDensity.java: Some + modifications based on the changes of the schema adaption in last commit. + + * src/main/java/de/intevation/flys/importer/parsers/SedimentDensityParser.java: + Override parse() of parent class to get the filename. + + * src/main/java/de/intevation/flys/importer/ImportSedimentDensity.java, + src/main/java/de/intevation/flys/importer/ImportDepth.java, + src/main/java/de/intevation/flys/importer/ImportSedimentDensityValue.java: + Implemented the methods storeDependencies() and getPeer() to save new + instances into database. + + * src/main/java/de/intevation/flys/importer/ImportRiver.java: Save all + ImportSedimentDensity objects to database. + + * src/main/java/de/intevation/flys/backend/SessionFactoryProvider.java: + Registered the new model classes. + 2012-04-13 Ingo Weinzierl <ingo@intevation.de> * doc/schema/oracle-minfo.sql,
--- a/flys-backend/doc/schema/oracle-minfo.sql Fri Apr 13 10:59:15 2012 +0000 +++ b/flys-backend/doc/schema/oracle-minfo.sql Fri Apr 13 11:45:29 2012 +0000 @@ -123,6 +123,7 @@ river_id NUMBER(38,0) NOT NULL, depth_id NUMBER(38,0) NOT NULL, unit_id NUMBER(38,0) NOT NULL, + description VARCHAR(256), PRIMARY KEY(id), CONSTRAINT fk_sd_river_id FOREIGN KEY (river_id) REFERENCES rivers(id), CONSTRAINT fk_sd_depth_id FOREIGN KEY (depth_id) REFERENCES depths(id),
--- a/flys-backend/src/main/java/de/intevation/flys/backend/SessionFactoryProvider.java Fri Apr 13 10:59:15 2012 +0000 +++ b/flys-backend/src/main/java/de/intevation/flys/backend/SessionFactoryProvider.java Fri Apr 13 11:45:29 2012 +0000 @@ -35,6 +35,7 @@ import de.intevation.flys.model.CrossSectionLine; import de.intevation.flys.model.CrossSectionPoint; import de.intevation.flys.model.CrossSectionTrack; +import de.intevation.flys.model.Depth; import de.intevation.flys.model.DGM; import de.intevation.flys.model.DischargeTable; import de.intevation.flys.model.DischargeTableValue; @@ -60,6 +61,8 @@ import de.intevation.flys.model.River; import de.intevation.flys.model.RiverAxis; import de.intevation.flys.model.RiverAxisKm; +import de.intevation.flys.model.SedimentDensity; +import de.intevation.flys.model.SedimentDensityValue; import de.intevation.flys.model.TimeInterval; import de.intevation.flys.model.Unit; import de.intevation.flys.model.WstColumn; @@ -231,6 +234,7 @@ cfg.addAnnotatedClass(CrossSectionLine.class); cfg.addAnnotatedClass(CrossSectionPoint.class); cfg.addAnnotatedClass(CrossSectionTrack.class); + cfg.addAnnotatedClass(Depth.class); cfg.addAnnotatedClass(DGM.class); cfg.addAnnotatedClass(DischargeTable.class); cfg.addAnnotatedClass(DischargeTableValue.class); @@ -256,6 +260,8 @@ cfg.addAnnotatedClass(River.class); cfg.addAnnotatedClass(RiverAxis.class); cfg.addAnnotatedClass(RiverAxisKm.class); + cfg.addAnnotatedClass(SedimentDensity.class); + cfg.addAnnotatedClass(SedimentDensityValue.class); cfg.addAnnotatedClass(TimeInterval.class); cfg.addAnnotatedClass(Unit.class); cfg.addAnnotatedClass(WstColumn.class);
--- a/flys-backend/src/main/java/de/intevation/flys/importer/ImportDepth.java Fri Apr 13 10:59:15 2012 +0000 +++ b/flys-backend/src/main/java/de/intevation/flys/importer/ImportDepth.java Fri Apr 13 11:45:29 2012 +0000 @@ -2,8 +2,13 @@ import java.math.BigDecimal; +import java.util.List; + import org.apache.log4j.Logger; +import org.hibernate.Session; +import org.hibernate.Query; + import de.intevation.flys.model.Depth; @@ -29,13 +34,42 @@ public void storeDependencies() { log.info("store dependencies"); + + getPeer(); } public Depth getPeer() { log.info("get peer"); - return null; + if (peer == null) { + Session session = ImporterSession.getInstance().getDatabaseSession(); + + Query query = session.createQuery( + "from Depth where " + + " lower=:lower and " + + " upper=:upper and " + + " unit=:unit"); + + query.setParameter("lower", lower); + query.setParameter("upper", upper); + query.setParameter("unit", unit.getPeer()); + + List<Depth> depths = query.list(); + + if (depths.isEmpty()) { + log.debug("Create new Depth DB instance."); + + peer = new Depth(lower, upper, unit.getPeer()); + + session.save(peer); + } + else { + peer = depths.get(0); + } + } + + return peer; } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-backend/src/main/java/de/intevation/flys/importer/ImportRiver.java Fri Apr 13 10:59:15 2012 +0000 +++ b/flys-backend/src/main/java/de/intevation/flys/importer/ImportRiver.java Fri Apr 13 11:45:29 2012 +0000 @@ -816,7 +816,23 @@ if (!Config.INSTANCE.skipSedimentDensity()) { log.info("store sediment density"); - // TODO + River river = getPeer(); + + for (ImportSedimentDensity density: sedimentDensities) { + String desc = density.getDescription(); + + log.debug("name: " + desc); + + try { + density.storeDependencies(river); + } + catch (SQLException sqle) { + log.error("File '" + desc + "' is broken!"); + } + catch (ConstraintViolationException cve) { + log.error("File '" + desc + "' is broken!"); + } + } } }
--- a/flys-backend/src/main/java/de/intevation/flys/importer/ImportSedimentDensity.java Fri Apr 13 10:59:15 2012 +0000 +++ b/flys-backend/src/main/java/de/intevation/flys/importer/ImportSedimentDensity.java Fri Apr 13 11:45:29 2012 +0000 @@ -1,10 +1,16 @@ package de.intevation.flys.importer; +import java.sql.SQLException; + import java.util.ArrayList; import java.util.List; import org.apache.log4j.Logger; +import org.hibernate.Session; +import org.hibernate.Query; +import org.hibernate.exception.ConstraintViolationException; + import de.intevation.flys.model.River; import de.intevation.flys.model.SedimentDensity; @@ -20,11 +26,19 @@ protected ImportUnit unit; + protected String description; + protected List<ImportSedimentDensityValue> values; - public ImportSedimentDensity() { - values = new ArrayList<ImportSedimentDensityValue>(); + public ImportSedimentDensity(String description) { + this.description = description; + this.values = new ArrayList<ImportSedimentDensityValue>(); + } + + + public String getDescription() { + return description; } @@ -43,15 +57,60 @@ } - public void storeDependencies(River river) { + public void storeDependencies(River river) + throws SQLException, ConstraintViolationException + { log.info("store dependencies"); + + if (depth != null) { + depth.storeDependencies(); + } + + log.info("store sediment density values."); + + SedimentDensity peer = getPeer(river); + + for (ImportSedimentDensityValue value: values) { + value.storeDependencies(peer); + } } public SedimentDensity getPeer(River river) { log.info("get peer"); - return null; + if (peer == null) { + Session session = ImporterSession.getInstance().getDatabaseSession(); + + Query query = session.createQuery( + "from SedimentDensity where " + + " river=:river and " + + " depth=:depth and " + + " unit=:unit"); + + query.setParameter("river", river); + query.setParameter("depth", depth.getPeer()); + query.setParameter("unit", unit.getPeer()); + + List<SedimentDensity> density = query.list(); + + if (density.isEmpty()) { + log.debug("Create new SedimentDensity DB instance."); + + peer = new SedimentDensity( + river, + depth.getPeer(), + unit.getPeer(), + description); + + session.save(peer); + } + else { + peer = density.get(0); + } + } + + return peer; } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-backend/src/main/java/de/intevation/flys/importer/ImportSedimentDensityValue.java Fri Apr 13 10:59:15 2012 +0000 +++ b/flys-backend/src/main/java/de/intevation/flys/importer/ImportSedimentDensityValue.java Fri Apr 13 11:45:29 2012 +0000 @@ -2,8 +2,13 @@ import java.math.BigDecimal; +import java.util.List; + import org.apache.log4j.Logger; +import org.hibernate.Session; +import org.hibernate.Query; + import de.intevation.flys.model.SedimentDensity; import de.intevation.flys.model.SedimentDensityValue; @@ -36,13 +41,47 @@ public void storeDependencies(SedimentDensity sedimentDensity) { log.info("store dependencies"); + + getPeer(sedimentDensity); } public SedimentDensityValue getPeer(SedimentDensity sedimentDensity) { log.info("get peer"); - return null; + if (peer == null) { + Session session = ImporterSession.getInstance().getDatabaseSession(); + + Query query = session.createQuery( + "from SedimentDensityValue where " + + " sedimentDensity=:sedimentDensity and " + + " station=:station and " + + " density=:density and " + + " description=:description"); + + query.setParameter("sedimentDensity", sedimentDensity); + query.setParameter("station", station); + query.setParameter("density", density); + query.setParameter("description", description); + + List<SedimentDensityValue> values = query.list(); + if (values.isEmpty()) { + log.debug("Create new SedimentDensityValue DB instance."); + + peer = new SedimentDensityValue( + sedimentDensity, + station, + density, + description); + + session.save(peer); + } + else { + peer = values.get(0); + } + } + + return peer; } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-backend/src/main/java/de/intevation/flys/importer/parsers/SedimentDensityParser.java Fri Apr 13 10:59:15 2012 +0000 +++ b/flys-backend/src/main/java/de/intevation/flys/importer/parsers/SedimentDensityParser.java Fri Apr 13 11:45:29 2012 +0000 @@ -1,5 +1,8 @@ package de.intevation.flys.importer.parsers; +import java.io.File; +import java.io.IOException; + import java.math.BigDecimal; import java.text.NumberFormat; @@ -39,6 +42,8 @@ protected ImportSedimentDensity current; + protected String currentDescription; + public SedimentDensityParser() { sedimentDensities = new ArrayList<ImportSedimentDensity>(); @@ -46,8 +51,16 @@ @Override + public void parse(File file) throws IOException { + currentDescription = file.getName(); + + super.parse(file); + } + + + @Override protected void reset() { - current = new ImportSedimentDensity(); + current = new ImportSedimentDensity(currentDescription); }
--- a/flys-backend/src/main/java/de/intevation/flys/model/SedimentDensity.java Fri Apr 13 10:59:15 2012 +0000 +++ b/flys-backend/src/main/java/de/intevation/flys/model/SedimentDensity.java Fri Apr 13 11:45:29 2012 +0000 @@ -25,16 +25,22 @@ private Depth depth; + private Unit unit; + private List<SedimentDensityValue> values; + private String description; + public SedimentDensity() { } - public SedimentDensity(River river, Depth depth) { - this.river = river; - this.depth = depth; + public SedimentDensity(River river, Depth depth, Unit unit, String desc) { + this.river = river; + this.depth = depth; + this.unit = unit; + this.description = desc; } @Id @@ -74,12 +80,35 @@ this.depth = depth; } + @OneToOne + @JoinColumn(name = "unit_id") + public Unit getUnit() { + return unit; + } + + public void setUnit(Unit unit) { + this.unit = unit; + } + + @Column(name = "description") + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + @OneToMany @JoinColumn(name="sediment_density_id") public List<SedimentDensityValue> getValues() { return values; } + public void setValues(List<SedimentDensityValue> values) { + this.values = values; + } + public void addValue(SedimentDensityValue value) { this.values.add(value); }
--- a/flys-backend/src/main/java/de/intevation/flys/model/SedimentDensityValue.java Fri Apr 13 10:59:15 2012 +0000 +++ b/flys-backend/src/main/java/de/intevation/flys/model/SedimentDensityValue.java Fri Apr 13 11:45:29 2012 +0000 @@ -20,8 +20,9 @@ private Integer id; - private Range station; + private SedimentDensity sedimentDensity; + private BigDecimal station; private BigDecimal density; private String description; @@ -31,10 +32,16 @@ } - public SedimentDensityValue(Range station, BigDecimal density, String desc) { - this.station = station; - this.density = density; - this.description = desc; + public SedimentDensityValue( + SedimentDensity sedimentDensity, + BigDecimal station, + BigDecimal density, + String desc + ) { + this.sedimentDensity = sedimentDensity; + this.station = station; + this.density = density; + this.description = desc; } @Id @@ -55,12 +62,21 @@ } @OneToOne - @JoinColumn(name = "station_id") - public Range getStation() { + @JoinColumn(name = "sediment_density_id") + public SedimentDensity getSedimentDensity() { + return sedimentDensity; + } + + public void setSedimentDensity(SedimentDensity sedimentDensity) { + this.sedimentDensity = sedimentDensity; + } + + @Column(name = "station") + public BigDecimal getStation() { return station; } - public void setStation(Range station) { + public void setStation(BigDecimal station) { this.station = station; }