Mercurial > dive4elements > river
annotate backend/src/main/java/org/dive4elements/river/importer/uinfo/importitem/VegetationZoneImport.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.importer.uinfo.importitem; | |
12 | |
13 import java.util.List; | |
14 | |
15 import org.apache.log4j.Logger; | |
16 import org.dive4elements.river.importer.common.AbstractKmLineImport; | |
17 import org.dive4elements.river.model.uinfo.Vegetation; | |
18 import org.dive4elements.river.model.uinfo.VegetationType; | |
19 import org.dive4elements.river.model.uinfo.VegetationZone; | |
20 import org.hibernate.Query; | |
21 import org.hibernate.Session; | |
22 | |
23 /** | |
24 * Imported vegetation values of a river station. | |
25 * | |
26 * @author Matthias Schäfer | |
27 * | |
28 */ | |
29 public class VegetationZoneImport extends AbstractKmLineImport<Vegetation, VegetationZone> { | |
30 | |
31 /***** FIELDS *****/ | |
32 | |
33 private static Logger log = Logger.getLogger(VegetationZoneImport.class); | |
34 | |
35 private final VegetationTypeImport vegetationType; | |
36 | |
37 private final Integer minOverflowDays; | |
38 | |
39 private final Integer maxOverflowDays; | |
40 | |
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
|
41 private 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
|
42 |
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
|
43 private 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
|
44 |
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
|
45 private final Integer color_b; |
9014 | 46 |
47 /***** CONSTRUCTOR *****/ | |
48 | |
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
|
49 public VegetationZoneImport(final int vegetationTypeId, final int minOverflowDays, final int maxOverflowDays, final int 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
|
50 final int color_g, final int color_b) { |
9014 | 51 super(Double.NaN); |
52 this.vegetationType = new VegetationTypeImport(vegetationTypeId); | |
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
|
53 this.minOverflowDays = Integer.valueOf(minOverflowDays); |
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
|
54 this.maxOverflowDays = Integer.valueOf(maxOverflowDays); |
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
|
55 this.color_r = Integer.valueOf(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
|
56 this.color_g = Integer.valueOf(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
|
57 this.color_b = Integer.valueOf(color_b); |
9014 | 58 } |
59 | |
60 | |
61 /***** METHODS *****/ | |
62 | |
63 @Override | |
64 public VegetationZone queryValueItem(final Session session, final Vegetation parent) { | |
65 final Query query = session.createQuery("FROM VegetationZone WHERE (vegetation=:parent)" | |
66 + " AND (vegetationType=:type)"); | |
67 query.setParameter("parent", parent); | |
68 query.setParameter("type", this.vegetationType); | |
69 final List rows = query.list(); | |
70 if (!rows.isEmpty()) | |
71 return (VegetationZone) rows.get(0); | |
72 else | |
73 return null; | |
74 } | |
75 | |
76 | |
77 @Override | |
78 public VegetationZone createValueItem(final Vegetation parent) { | |
79 final VegetationType type = this.vegetationType.getPeer(); | |
80 if (type == null) { | |
81 log.error("Unknown vegetation zone class " + this.vegetationType.getId()); | |
82 return null; | |
83 } | |
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
|
84 return new VegetationZone(parent, type, this.minOverflowDays, this.maxOverflowDays, this.color_r, this.color_g, this.color_b); |
9014 | 85 } |
86 } |