Mercurial > dive4elements > river
changeset 9401:361de818f76e
Added color fields to the vegetation zone database table and importer, max days field changed from exclusive to inclusive
author | mschaefer |
---|---|
date | Tue, 14 Aug 2018 14:02:26 +0200 |
parents | 8e100593aec3 |
children | e511eb935ccd |
files | backend/doc/schema/oracle-sinfo-uinfo.sql backend/doc/schema/postgresql-sinfo-uinfo.sql backend/src/main/java/org/dive4elements/river/importer/uinfo/importitem/VegetationZoneImport.java backend/src/main/java/org/dive4elements/river/importer/uinfo/parsers/VegetationParser.java backend/src/main/java/org/dive4elements/river/model/uinfo/Vegetation.java backend/src/main/java/org/dive4elements/river/model/uinfo/VegetationType.java backend/src/main/java/org/dive4elements/river/model/uinfo/VegetationZone.java |
diffstat | 7 files changed, 107 insertions(+), 16 deletions(-) [+] |
line wrap: on
line diff
--- a/backend/doc/schema/oracle-sinfo-uinfo.sql Tue Aug 14 11:06:00 2018 +0200 +++ b/backend/doc/schema/oracle-sinfo-uinfo.sql Tue Aug 14 14:02:26 2018 +0200 @@ -461,11 +461,17 @@ vegetation_id NUMBER(9,0) NOT NULL CONSTRAINT cVegetationZoneVegetation REFERENCES vegetation(id) ON DELETE CASCADE, vegetation_type_id NUMBER(9,0) NOT NULL CONSTRAINT cVegetationZoneVegetationType REFERENCES vegetation_type(id) ON DELETE CASCADE, min_overflow_days NUMBER(3,0) NOT NULL, - max_overflow_days NUMBER(3,0) NOT NULL + max_overflow_days NUMBER(3,0) NOT NULL, + color_r NUMBER(3,0) NOT NULL, + color_g NUMBER(3,0) NOT NULL, + color_b NUMBER(3,0) NOT NULL ); COMMENT ON TABLE vegetation_zone IS 'Vegetation zone of a river station' ; COMMENT ON COLUMN vegetation_zone.min_overflow_days IS 'Minimum number (inclusive) of overflow days in a year for the zone type' ; -COMMENT ON COLUMN vegetation_zone.max_overflow_days IS 'Maximum number (exclusive) of overflow days in a year for the zone type' ; +COMMENT ON COLUMN vegetation_zone.max_overflow_days IS 'Maximum number (inclusive) of overflow days in a year for the zone type' ; +COMMENT ON COLUMN vegetation_zone.color_r IS 'Red value (0-255) of the zone color' ; +COMMENT ON COLUMN vegetation_zone.color_g IS 'Green value (0-255) of the zone color' ; +COMMENT ON COLUMN vegetation_zone.color_b IS 'Blue value (0-255) of the zone color' ; CREATE SEQUENCE VEGETATION_ZONE_ID_SEQ ;
--- a/backend/doc/schema/postgresql-sinfo-uinfo.sql Tue Aug 14 11:06:00 2018 +0200 +++ b/backend/doc/schema/postgresql-sinfo-uinfo.sql Tue Aug 14 14:02:26 2018 +0200 @@ -457,12 +457,18 @@ vegetation_id NUMERIC(9,0) NOT NULL CONSTRAINT cVegetationZoneVegetation REFERENCES vegetation(id) ON DELETE CASCADE, vegetation_type_id NUMERIC(9,0) NOT NULL CONSTRAINT cVegetationZoneVegetationType REFERENCES vegetation_type(id) ON DELETE CASCADE, min_overflow_days NUMERIC(3,0) NOT NULL, - max_overflow_days NUMERIC(3,0) NOT NULL + max_overflow_days NUMERIC(3,0) NOT NULL, + color_r NUMERIC(3,0) NOT NULL, + color_g NUMERIC(3,0) NOT NULL, + color_b NUMERIC(3,0) NOT NULL ); COMMENT ON TABLE vegetation_zone IS 'Vegetation zone of a river station' ; COMMENT ON COLUMN vegetation_zone.min_overflow_days IS 'Minimum number (inclusive) of overflow days in a year for the zone type' ; -COMMENT ON COLUMN vegetation_zone.max_overflow_days IS 'Maximum number (exclusive) of overflow days in a year for the zone type' ; +COMMENT ON COLUMN vegetation_zone.max_overflow_days IS 'Maximum number (inclusive) of overflow days in a year for the zone type' ; +COMMENT ON COLUMN vegetation_zone.color_r IS 'Red value (0-255) of the zone color' ; +COMMENT ON COLUMN vegetation_zone.color_g IS 'Green value (0-255) of the zone color' ; +COMMENT ON COLUMN vegetation_zone.color_b IS 'Blue value (0-255) of the zone color' ; CREATE SEQUENCE VEGETATION_ZONE_ID_SEQ ;
--- a/backend/src/main/java/org/dive4elements/river/importer/uinfo/importitem/VegetationZoneImport.java Tue Aug 14 11:06:00 2018 +0200 +++ b/backend/src/main/java/org/dive4elements/river/importer/uinfo/importitem/VegetationZoneImport.java Tue Aug 14 14:02:26 2018 +0200 @@ -38,14 +38,23 @@ private final Integer maxOverflowDays; + private final Integer color_r; + + private final Integer color_g; + + private final Integer color_b; /***** CONSTRUCTOR *****/ - public VegetationZoneImport(final int vegetationTypeId, final Integer minOverflowDays, final Integer maxOverflowDays) { + public VegetationZoneImport(final int vegetationTypeId, final int minOverflowDays, final int maxOverflowDays, final int color_r, + final int color_g, final int color_b) { super(Double.NaN); this.vegetationType = new VegetationTypeImport(vegetationTypeId); - this.minOverflowDays = minOverflowDays; - this.maxOverflowDays = maxOverflowDays; + this.minOverflowDays = Integer.valueOf(minOverflowDays); + this.maxOverflowDays = Integer.valueOf(maxOverflowDays); + this.color_r = Integer.valueOf(color_r); + this.color_g = Integer.valueOf(color_g); + this.color_b = Integer.valueOf(color_b); } @@ -72,6 +81,6 @@ log.error("Unknown vegetation zone class " + this.vegetationType.getId()); return null; } - return new VegetationZone(parent, type, this.minOverflowDays, this.maxOverflowDays); + return new VegetationZone(parent, type, this.minOverflowDays, this.maxOverflowDays, this.color_r, this.color_g, this.color_b); } }
--- a/backend/src/main/java/org/dive4elements/river/importer/uinfo/parsers/VegetationParser.java Tue Aug 14 11:06:00 2018 +0200 +++ b/backend/src/main/java/org/dive4elements/river/importer/uinfo/parsers/VegetationParser.java Tue Aug 14 14:02:26 2018 +0200 @@ -45,7 +45,10 @@ private enum ColTitlePattern { OVERFLOW_LIMIT("((.)|(Ue))berflutungsdauer-bis\\s*\\[(.*)\\].*"), // - CLASSNO("Vegetationsklasse.*"); + CLASSNO("Vegetationsklasse.*"), // + COLOR_R("Rot"), // + COLOR_G("Gr((.)|(ue))n"), // + COLOR_B("Blau"); private final Pattern pattern; @@ -153,13 +156,13 @@ return true; } this.previousClassNo = 0; - this.previousDaysLimit = 0; + this.previousDaysLimit = -1; return true; } @Override protected VegetationZoneImport createKmLineImport(final Double km, final String[] values) { - int daysLimit = 365; + int daysLimit = 366; int classNo = 0; try { if (!values[this.cols.get(ColTitlePattern.OVERFLOW_LIMIT)].trim().isEmpty()) @@ -180,8 +183,11 @@ // return null; // } this.previousClassNo = classNo; - final Integer minDays = Integer.valueOf(this.previousDaysLimit); - this.previousDaysLimit = daysLimit + 1; - return new VegetationZoneImport(classNo, minDays, Integer.valueOf(this.previousDaysLimit)); + final int minDays = this.previousDaysLimit + 1; + this.previousDaysLimit = daysLimit; + final int red = (this.cols.get(ColTitlePattern.COLOR_R) >= 0) ? Integer.parseInt(values[this.cols.get(ColTitlePattern.COLOR_R)]) : 0; + final int green = (this.cols.get(ColTitlePattern.COLOR_G) >= 0) ? Integer.parseInt(values[this.cols.get(ColTitlePattern.COLOR_G)]) : 0; + final int blue = (this.cols.get(ColTitlePattern.COLOR_B) >= 0) ? Integer.parseInt(values[this.cols.get(ColTitlePattern.COLOR_B)]) : 0; + return new VegetationZoneImport(classNo, minDays, daysLimit, red, green, blue); } }
--- a/backend/src/main/java/org/dive4elements/river/model/uinfo/Vegetation.java Tue Aug 14 11:06:00 2018 +0200 +++ b/backend/src/main/java/org/dive4elements/river/model/uinfo/Vegetation.java Tue Aug 14 14:02:26 2018 +0200 @@ -69,6 +69,7 @@ this.values = new ArrayList<>(); } + /***** METHODS *****/ @Id
--- a/backend/src/main/java/org/dive4elements/river/model/uinfo/VegetationType.java Tue Aug 14 11:06:00 2018 +0200 +++ b/backend/src/main/java/org/dive4elements/river/model/uinfo/VegetationType.java Tue Aug 14 14:02:26 2018 +0200 @@ -71,8 +71,9 @@ public void setName(final String name) { this.name = name; } + /** - * Queries all salix ranks from the database, orders by id + * Queries all vegetation types from the database, ordered by id */ public static List<VegetationType> getTypes() { final Session session = SessionHolder.HOLDER.get();
--- a/backend/src/main/java/org/dive4elements/river/model/uinfo/VegetationZone.java Tue Aug 14 11:06:00 2018 +0200 +++ b/backend/src/main/java/org/dive4elements/river/model/uinfo/VegetationZone.java Tue Aug 14 14:02:26 2018 +0200 @@ -11,6 +11,7 @@ package org.dive4elements.river.model.uinfo; import java.io.Serializable; +import java.util.List; import javax.persistence.Column; import javax.persistence.Entity; @@ -21,6 +22,12 @@ import javax.persistence.OneToOne; import javax.persistence.SequenceGenerator; import javax.persistence.Table; +import javax.persistence.Transient; + +import org.dive4elements.river.backend.SessionHolder; +import org.dive4elements.river.model.River; +import org.hibernate.Query; +import org.hibernate.Session; /** @@ -47,17 +54,27 @@ private Integer max_overflow_days; + private Integer color_r; + + private Integer color_g; + + private Integer color_b; /***** CONSTRUCTORS *****/ public VegetationZone() { } - public VegetationZone(final Vegetation vegetation, final VegetationType vegetationType, final Integer min_overflow_days, final Integer max_overflow_days) { + public VegetationZone(final Vegetation vegetation, final VegetationType vegetationType, final Integer min_overflow_days, final Integer max_overflow_days, + final Integer color_r, + final Integer color_g, final Integer color_b) { this.vegetation = vegetation; this.vegetationType = vegetationType; this.min_overflow_days = min_overflow_days; this.max_overflow_days = max_overflow_days; + this.color_r = color_r; + this.color_g = color_g; + this.color_b = color_b; } @@ -112,4 +129,49 @@ public void setMax_overflow_days(final Integer max_overflow_days) { this.max_overflow_days = max_overflow_days; } + + @Column(name = "color_r") + public Integer getColor_r() { + return this.color_r; + } + + public void setColor_r(final Integer color_r) { + this.color_r = color_r; + } + + @Column(name = "color_g") + public Integer getColor_g() { + return this.color_g; + } + + public void setColor_g(final Integer color_g) { + this.color_g = color_g; + } + + @Column(name = "color_b") + public Integer getColor_b() { + return this.color_b; + } + + public void setColor_b(final Integer color_b) { + this.color_b = color_b; + } + + @Transient + public String getColor() { + return String.format("#%02x%02x%02x", getColor_r(), getColor_g(), getColor_b()); + } + + /** + * Selects from the database the vegetation zones of a river + */ + public static List<VegetationZone> getValues(final River river) { + final Session session = SessionHolder.HOLDER.get(); + final Query query = session.createQuery("SELECT v" + + " FROM VegetationZone AS v JOIN v.vegetation AS s" + + " WHERE (s.river.id=:riverid)" + + " ORDER BY v.vegetationType.id"); + query.setParameter("riverid", river.getId()); + return query.list(); + } }