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 |
|
41 |
|
42 /***** CONSTRUCTOR *****/ |
|
43 |
|
44 public VegetationZoneImport(final int vegetationTypeId, final Integer minOverflowDays, final Integer maxOverflowDays) { |
|
45 super(Double.NaN); |
|
46 this.vegetationType = new VegetationTypeImport(vegetationTypeId); |
|
47 this.minOverflowDays = minOverflowDays; |
|
48 this.maxOverflowDays = maxOverflowDays; |
|
49 } |
|
50 |
|
51 |
|
52 /***** METHODS *****/ |
|
53 |
|
54 @Override |
|
55 public VegetationZone queryValueItem(final Session session, final Vegetation parent) { |
|
56 final Query query = session.createQuery("FROM VegetationZone WHERE (vegetation=:parent)" |
|
57 + " AND (vegetationType=:type)"); |
|
58 query.setParameter("parent", parent); |
|
59 query.setParameter("type", this.vegetationType); |
|
60 final List rows = query.list(); |
|
61 if (!rows.isEmpty()) |
|
62 return (VegetationZone) rows.get(0); |
|
63 else |
|
64 return null; |
|
65 } |
|
66 |
|
67 |
|
68 @Override |
|
69 public VegetationZone createValueItem(final Vegetation parent) { |
|
70 final VegetationType type = this.vegetationType.getPeer(); |
|
71 if (type == null) { |
|
72 log.error("Unknown vegetation zone class " + this.vegetationType.getId()); |
|
73 return null; |
|
74 } |
|
75 return new VegetationZone(parent, type, this.minOverflowDays, this.maxOverflowDays); |
|
76 } |
|
77 } |