Mercurial > dive4elements > river
comparison backend/src/main/java/org/dive4elements/river/model/uinfo/VegetationZone.java @ 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 | 201817aa7b1c |
children |
comparison
equal
deleted
inserted
replaced
9400:8e100593aec3 | 9401:361de818f76e |
---|---|
9 */ | 9 */ |
10 | 10 |
11 package org.dive4elements.river.model.uinfo; | 11 package org.dive4elements.river.model.uinfo; |
12 | 12 |
13 import java.io.Serializable; | 13 import java.io.Serializable; |
14 import java.util.List; | |
14 | 15 |
15 import javax.persistence.Column; | 16 import javax.persistence.Column; |
16 import javax.persistence.Entity; | 17 import javax.persistence.Entity; |
17 import javax.persistence.GeneratedValue; | 18 import javax.persistence.GeneratedValue; |
18 import javax.persistence.GenerationType; | 19 import javax.persistence.GenerationType; |
19 import javax.persistence.Id; | 20 import javax.persistence.Id; |
20 import javax.persistence.JoinColumn; | 21 import javax.persistence.JoinColumn; |
21 import javax.persistence.OneToOne; | 22 import javax.persistence.OneToOne; |
22 import javax.persistence.SequenceGenerator; | 23 import javax.persistence.SequenceGenerator; |
23 import javax.persistence.Table; | 24 import javax.persistence.Table; |
25 import javax.persistence.Transient; | |
26 | |
27 import org.dive4elements.river.backend.SessionHolder; | |
28 import org.dive4elements.river.model.River; | |
29 import org.hibernate.Query; | |
30 import org.hibernate.Session; | |
24 | 31 |
25 | 32 |
26 /** | 33 /** |
27 * Hibernate binding for the DB table vegetation_zone | 34 * Hibernate binding for the DB table vegetation_zone |
28 * | 35 * |
45 | 52 |
46 private Integer min_overflow_days; | 53 private Integer min_overflow_days; |
47 | 54 |
48 private Integer max_overflow_days; | 55 private Integer max_overflow_days; |
49 | 56 |
57 private Integer color_r; | |
58 | |
59 private Integer color_g; | |
60 | |
61 private Integer color_b; | |
50 | 62 |
51 /***** CONSTRUCTORS *****/ | 63 /***** CONSTRUCTORS *****/ |
52 | 64 |
53 public VegetationZone() { | 65 public VegetationZone() { |
54 } | 66 } |
55 | 67 |
56 public VegetationZone(final Vegetation vegetation, final VegetationType vegetationType, final Integer min_overflow_days, final Integer max_overflow_days) { | 68 public VegetationZone(final Vegetation vegetation, final VegetationType vegetationType, final Integer min_overflow_days, final Integer max_overflow_days, |
69 final Integer color_r, | |
70 final Integer color_g, final Integer color_b) { | |
57 this.vegetation = vegetation; | 71 this.vegetation = vegetation; |
58 this.vegetationType = vegetationType; | 72 this.vegetationType = vegetationType; |
59 this.min_overflow_days = min_overflow_days; | 73 this.min_overflow_days = min_overflow_days; |
60 this.max_overflow_days = max_overflow_days; | 74 this.max_overflow_days = max_overflow_days; |
75 this.color_r = color_r; | |
76 this.color_g = color_g; | |
77 this.color_b = color_b; | |
61 } | 78 } |
62 | 79 |
63 | 80 |
64 /***** METHODS *****/ | 81 /***** METHODS *****/ |
65 | 82 |
110 } | 127 } |
111 | 128 |
112 public void setMax_overflow_days(final Integer max_overflow_days) { | 129 public void setMax_overflow_days(final Integer max_overflow_days) { |
113 this.max_overflow_days = max_overflow_days; | 130 this.max_overflow_days = max_overflow_days; |
114 } | 131 } |
132 | |
133 @Column(name = "color_r") | |
134 public Integer getColor_r() { | |
135 return this.color_r; | |
136 } | |
137 | |
138 public void setColor_r(final Integer color_r) { | |
139 this.color_r = color_r; | |
140 } | |
141 | |
142 @Column(name = "color_g") | |
143 public Integer getColor_g() { | |
144 return this.color_g; | |
145 } | |
146 | |
147 public void setColor_g(final Integer color_g) { | |
148 this.color_g = color_g; | |
149 } | |
150 | |
151 @Column(name = "color_b") | |
152 public Integer getColor_b() { | |
153 return this.color_b; | |
154 } | |
155 | |
156 public void setColor_b(final Integer color_b) { | |
157 this.color_b = color_b; | |
158 } | |
159 | |
160 @Transient | |
161 public String getColor() { | |
162 return String.format("#%02x%02x%02x", getColor_r(), getColor_g(), getColor_b()); | |
163 } | |
164 | |
165 /** | |
166 * Selects from the database the vegetation zones of a river | |
167 */ | |
168 public static List<VegetationZone> getValues(final River river) { | |
169 final Session session = SessionHolder.HOLDER.get(); | |
170 final Query query = session.createQuery("SELECT v" | |
171 + " FROM VegetationZone AS v JOIN v.vegetation AS s" | |
172 + " WHERE (s.river.id=:riverid)" | |
173 + " ORDER BY v.vegetationType.id"); | |
174 query.setParameter("riverid", river.getId()); | |
175 return query.list(); | |
176 } | |
115 } | 177 } |