Mercurial > dive4elements > river
annotate 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 |
rev | line source |
---|---|
9014 | 1 /* Copyright (C) 2017 by Bundesanstalt für Gewässerkunde |
2 * Software engineering by | |
3 * Björnsen Beratende Ingenieure GmbH | |
4 * Dr. Schumacher Ingenieurbüro für Wasser und Umwelt | |
5 * | |
6 * This file is Free Software under the GNU AGPL (>=v3) | |
7 * and comes with ABSOLUTELY NO WARRANTY! Check out the | |
8 * documentation coming with Dive4Elements River for details. | |
9 */ | |
10 | |
11 package org.dive4elements.river.model.uinfo; | |
12 | |
13 import java.io.Serializable; | |
9401
361de818f76e
Added color fields to the vegetation zone database table and importer, max days field changed from exclusive to inclusive
mschaefer
parents:
9014
diff
changeset
|
14 import java.util.List; |
9014 | 15 |
16 import javax.persistence.Column; | |
17 import javax.persistence.Entity; | |
18 import javax.persistence.GeneratedValue; | |
19 import javax.persistence.GenerationType; | |
20 import javax.persistence.Id; | |
21 import javax.persistence.JoinColumn; | |
22 import javax.persistence.OneToOne; | |
23 import javax.persistence.SequenceGenerator; | |
24 import javax.persistence.Table; | |
9401
361de818f76e
Added color fields to the vegetation zone database table and importer, max days field changed from exclusive to inclusive
mschaefer
parents:
9014
diff
changeset
|
25 import javax.persistence.Transient; |
361de818f76e
Added color fields to the vegetation zone database table and importer, max days field changed from exclusive to inclusive
mschaefer
parents:
9014
diff
changeset
|
26 |
361de818f76e
Added color fields to the vegetation zone database table and importer, max days field changed from exclusive to inclusive
mschaefer
parents:
9014
diff
changeset
|
27 import org.dive4elements.river.backend.SessionHolder; |
361de818f76e
Added color fields to the vegetation zone database table and importer, max days field changed from exclusive to inclusive
mschaefer
parents:
9014
diff
changeset
|
28 import org.dive4elements.river.model.River; |
361de818f76e
Added color fields to the vegetation zone database table and importer, max days field changed from exclusive to inclusive
mschaefer
parents:
9014
diff
changeset
|
29 import org.hibernate.Query; |
361de818f76e
Added color fields to the vegetation zone database table and importer, max days field changed from exclusive to inclusive
mschaefer
parents:
9014
diff
changeset
|
30 import org.hibernate.Session; |
9014 | 31 |
32 | |
33 /** | |
34 * Hibernate binding for the DB table vegetation_zone | |
35 * | |
36 * @author Matthias Schäfer | |
37 * | |
38 */ | |
39 @Entity | |
40 @Table(name = "vegetation_zone") | |
41 public class VegetationZone implements Serializable { | |
42 | |
43 /***** FIELDS *****/ | |
44 | |
45 private static final long serialVersionUID = -6579828019873800147L; | |
46 | |
47 private Integer id; | |
48 | |
49 private Vegetation vegetation; | |
50 | |
51 private VegetationType vegetationType; | |
52 | |
53 private Integer min_overflow_days; | |
54 | |
55 private Integer max_overflow_days; | |
56 | |
9401
361de818f76e
Added color fields to the vegetation zone database table and importer, max days field changed from exclusive to inclusive
mschaefer
parents:
9014
diff
changeset
|
57 private Integer color_r; |
361de818f76e
Added color fields to the vegetation zone database table and importer, max days field changed from exclusive to inclusive
mschaefer
parents:
9014
diff
changeset
|
58 |
361de818f76e
Added color fields to the vegetation zone database table and importer, max days field changed from exclusive to inclusive
mschaefer
parents:
9014
diff
changeset
|
59 private Integer color_g; |
361de818f76e
Added color fields to the vegetation zone database table and importer, max days field changed from exclusive to inclusive
mschaefer
parents:
9014
diff
changeset
|
60 |
361de818f76e
Added color fields to the vegetation zone database table and importer, max days field changed from exclusive to inclusive
mschaefer
parents:
9014
diff
changeset
|
61 private Integer color_b; |
9014 | 62 |
63 /***** CONSTRUCTORS *****/ | |
64 | |
65 public VegetationZone() { | |
66 } | |
67 | |
9401
361de818f76e
Added color fields to the vegetation zone database table and importer, max days field changed from exclusive to inclusive
mschaefer
parents:
9014
diff
changeset
|
68 public VegetationZone(final Vegetation vegetation, final VegetationType vegetationType, final Integer min_overflow_days, final Integer max_overflow_days, |
361de818f76e
Added color fields to the vegetation zone database table and importer, max days field changed from exclusive to inclusive
mschaefer
parents:
9014
diff
changeset
|
69 final Integer color_r, |
361de818f76e
Added color fields to the vegetation zone database table and importer, max days field changed from exclusive to inclusive
mschaefer
parents:
9014
diff
changeset
|
70 final Integer color_g, final Integer color_b) { |
9014 | 71 this.vegetation = vegetation; |
72 this.vegetationType = vegetationType; | |
73 this.min_overflow_days = min_overflow_days; | |
74 this.max_overflow_days = max_overflow_days; | |
9401
361de818f76e
Added color fields to the vegetation zone database table and importer, max days field changed from exclusive to inclusive
mschaefer
parents:
9014
diff
changeset
|
75 this.color_r = color_r; |
361de818f76e
Added color fields to the vegetation zone database table and importer, max days field changed from exclusive to inclusive
mschaefer
parents:
9014
diff
changeset
|
76 this.color_g = color_g; |
361de818f76e
Added color fields to the vegetation zone database table and importer, max days field changed from exclusive to inclusive
mschaefer
parents:
9014
diff
changeset
|
77 this.color_b = color_b; |
9014 | 78 } |
79 | |
80 | |
81 /***** METHODS *****/ | |
82 | |
83 @Id | |
84 @SequenceGenerator(name = "SEQUENCE_VEGETATION_ZONE_ID_SEQ", sequenceName = "VEGETATION_ZONE_ID_SEQ", allocationSize = 1) | |
85 @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "SEQUENCE_VEGETATION_ZONE_ID_SEQ") | |
86 @Column(name = "id") | |
87 public Integer getId() { | |
88 return this.id; | |
89 } | |
90 | |
91 public void setId(final Integer id) { | |
92 this.id = id; | |
93 } | |
94 | |
95 @OneToOne | |
96 @JoinColumn(name = "vegetation_id") | |
97 public Vegetation getVegetation() { | |
98 return this.vegetation; | |
99 } | |
100 | |
101 public void setVegetation(final Vegetation vegetation) { | |
102 this.vegetation = vegetation; | |
103 } | |
104 | |
105 @OneToOne | |
106 @JoinColumn(name = "vegetation_type_id") | |
107 public VegetationType getVegetationType() { | |
108 return this.vegetationType; | |
109 } | |
110 | |
111 public void setVegetationType(final VegetationType vegetationType) { | |
112 this.vegetationType = vegetationType; | |
113 } | |
114 | |
115 @Column(name = "min_overflow_days") | |
116 public Integer getMin_overflow_days() { | |
117 return this.min_overflow_days; | |
118 } | |
119 | |
120 public void setMin_overflow_days(final Integer min_overflow_days) { | |
121 this.min_overflow_days = min_overflow_days; | |
122 } | |
123 | |
124 @Column(name = "max_overflow_days") | |
125 public Integer getMax_overflow_days() { | |
126 return this.max_overflow_days; | |
127 } | |
128 | |
129 public void setMax_overflow_days(final Integer max_overflow_days) { | |
130 this.max_overflow_days = max_overflow_days; | |
131 } | |
9401
361de818f76e
Added color fields to the vegetation zone database table and importer, max days field changed from exclusive to inclusive
mschaefer
parents:
9014
diff
changeset
|
132 |
361de818f76e
Added color fields to the vegetation zone database table and importer, max days field changed from exclusive to inclusive
mschaefer
parents:
9014
diff
changeset
|
133 @Column(name = "color_r") |
361de818f76e
Added color fields to the vegetation zone database table and importer, max days field changed from exclusive to inclusive
mschaefer
parents:
9014
diff
changeset
|
134 public Integer getColor_r() { |
361de818f76e
Added color fields to the vegetation zone database table and importer, max days field changed from exclusive to inclusive
mschaefer
parents:
9014
diff
changeset
|
135 return this.color_r; |
361de818f76e
Added color fields to the vegetation zone database table and importer, max days field changed from exclusive to inclusive
mschaefer
parents:
9014
diff
changeset
|
136 } |
361de818f76e
Added color fields to the vegetation zone database table and importer, max days field changed from exclusive to inclusive
mschaefer
parents:
9014
diff
changeset
|
137 |
361de818f76e
Added color fields to the vegetation zone database table and importer, max days field changed from exclusive to inclusive
mschaefer
parents:
9014
diff
changeset
|
138 public void setColor_r(final Integer color_r) { |
361de818f76e
Added color fields to the vegetation zone database table and importer, max days field changed from exclusive to inclusive
mschaefer
parents:
9014
diff
changeset
|
139 this.color_r = color_r; |
361de818f76e
Added color fields to the vegetation zone database table and importer, max days field changed from exclusive to inclusive
mschaefer
parents:
9014
diff
changeset
|
140 } |
361de818f76e
Added color fields to the vegetation zone database table and importer, max days field changed from exclusive to inclusive
mschaefer
parents:
9014
diff
changeset
|
141 |
361de818f76e
Added color fields to the vegetation zone database table and importer, max days field changed from exclusive to inclusive
mschaefer
parents:
9014
diff
changeset
|
142 @Column(name = "color_g") |
361de818f76e
Added color fields to the vegetation zone database table and importer, max days field changed from exclusive to inclusive
mschaefer
parents:
9014
diff
changeset
|
143 public Integer getColor_g() { |
361de818f76e
Added color fields to the vegetation zone database table and importer, max days field changed from exclusive to inclusive
mschaefer
parents:
9014
diff
changeset
|
144 return this.color_g; |
361de818f76e
Added color fields to the vegetation zone database table and importer, max days field changed from exclusive to inclusive
mschaefer
parents:
9014
diff
changeset
|
145 } |
361de818f76e
Added color fields to the vegetation zone database table and importer, max days field changed from exclusive to inclusive
mschaefer
parents:
9014
diff
changeset
|
146 |
361de818f76e
Added color fields to the vegetation zone database table and importer, max days field changed from exclusive to inclusive
mschaefer
parents:
9014
diff
changeset
|
147 public void setColor_g(final Integer color_g) { |
361de818f76e
Added color fields to the vegetation zone database table and importer, max days field changed from exclusive to inclusive
mschaefer
parents:
9014
diff
changeset
|
148 this.color_g = color_g; |
361de818f76e
Added color fields to the vegetation zone database table and importer, max days field changed from exclusive to inclusive
mschaefer
parents:
9014
diff
changeset
|
149 } |
361de818f76e
Added color fields to the vegetation zone database table and importer, max days field changed from exclusive to inclusive
mschaefer
parents:
9014
diff
changeset
|
150 |
361de818f76e
Added color fields to the vegetation zone database table and importer, max days field changed from exclusive to inclusive
mschaefer
parents:
9014
diff
changeset
|
151 @Column(name = "color_b") |
361de818f76e
Added color fields to the vegetation zone database table and importer, max days field changed from exclusive to inclusive
mschaefer
parents:
9014
diff
changeset
|
152 public Integer getColor_b() { |
361de818f76e
Added color fields to the vegetation zone database table and importer, max days field changed from exclusive to inclusive
mschaefer
parents:
9014
diff
changeset
|
153 return this.color_b; |
361de818f76e
Added color fields to the vegetation zone database table and importer, max days field changed from exclusive to inclusive
mschaefer
parents:
9014
diff
changeset
|
154 } |
361de818f76e
Added color fields to the vegetation zone database table and importer, max days field changed from exclusive to inclusive
mschaefer
parents:
9014
diff
changeset
|
155 |
361de818f76e
Added color fields to the vegetation zone database table and importer, max days field changed from exclusive to inclusive
mschaefer
parents:
9014
diff
changeset
|
156 public void setColor_b(final Integer color_b) { |
361de818f76e
Added color fields to the vegetation zone database table and importer, max days field changed from exclusive to inclusive
mschaefer
parents:
9014
diff
changeset
|
157 this.color_b = color_b; |
361de818f76e
Added color fields to the vegetation zone database table and importer, max days field changed from exclusive to inclusive
mschaefer
parents:
9014
diff
changeset
|
158 } |
361de818f76e
Added color fields to the vegetation zone database table and importer, max days field changed from exclusive to inclusive
mschaefer
parents:
9014
diff
changeset
|
159 |
361de818f76e
Added color fields to the vegetation zone database table and importer, max days field changed from exclusive to inclusive
mschaefer
parents:
9014
diff
changeset
|
160 @Transient |
361de818f76e
Added color fields to the vegetation zone database table and importer, max days field changed from exclusive to inclusive
mschaefer
parents:
9014
diff
changeset
|
161 public String getColor() { |
361de818f76e
Added color fields to the vegetation zone database table and importer, max days field changed from exclusive to inclusive
mschaefer
parents:
9014
diff
changeset
|
162 return String.format("#%02x%02x%02x", getColor_r(), getColor_g(), getColor_b()); |
361de818f76e
Added color fields to the vegetation zone database table and importer, max days field changed from exclusive to inclusive
mschaefer
parents:
9014
diff
changeset
|
163 } |
361de818f76e
Added color fields to the vegetation zone database table and importer, max days field changed from exclusive to inclusive
mschaefer
parents:
9014
diff
changeset
|
164 |
361de818f76e
Added color fields to the vegetation zone database table and importer, max days field changed from exclusive to inclusive
mschaefer
parents:
9014
diff
changeset
|
165 /** |
361de818f76e
Added color fields to the vegetation zone database table and importer, max days field changed from exclusive to inclusive
mschaefer
parents:
9014
diff
changeset
|
166 * Selects from the database the vegetation zones of a river |
361de818f76e
Added color fields to the vegetation zone database table and importer, max days field changed from exclusive to inclusive
mschaefer
parents:
9014
diff
changeset
|
167 */ |
361de818f76e
Added color fields to the vegetation zone database table and importer, max days field changed from exclusive to inclusive
mschaefer
parents:
9014
diff
changeset
|
168 public static List<VegetationZone> getValues(final River river) { |
361de818f76e
Added color fields to the vegetation zone database table and importer, max days field changed from exclusive to inclusive
mschaefer
parents:
9014
diff
changeset
|
169 final Session session = SessionHolder.HOLDER.get(); |
361de818f76e
Added color fields to the vegetation zone database table and importer, max days field changed from exclusive to inclusive
mschaefer
parents:
9014
diff
changeset
|
170 final Query query = session.createQuery("SELECT v" |
361de818f76e
Added color fields to the vegetation zone database table and importer, max days field changed from exclusive to inclusive
mschaefer
parents:
9014
diff
changeset
|
171 + " FROM VegetationZone AS v JOIN v.vegetation AS s" |
361de818f76e
Added color fields to the vegetation zone database table and importer, max days field changed from exclusive to inclusive
mschaefer
parents:
9014
diff
changeset
|
172 + " WHERE (s.river.id=:riverid)" |
361de818f76e
Added color fields to the vegetation zone database table and importer, max days field changed from exclusive to inclusive
mschaefer
parents:
9014
diff
changeset
|
173 + " ORDER BY v.vegetationType.id"); |
361de818f76e
Added color fields to the vegetation zone database table and importer, max days field changed from exclusive to inclusive
mschaefer
parents:
9014
diff
changeset
|
174 query.setParameter("riverid", river.getId()); |
361de818f76e
Added color fields to the vegetation zone database table and importer, max days field changed from exclusive to inclusive
mschaefer
parents:
9014
diff
changeset
|
175 return query.list(); |
361de818f76e
Added color fields to the vegetation zone database table and importer, max days field changed from exclusive to inclusive
mschaefer
parents:
9014
diff
changeset
|
176 } |
9014 | 177 } |