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
201817aa7b1c Added the missing vegetation import classes
mschaefer
parents:
diff changeset
1 /* Copyright (C) 2017 by Bundesanstalt für Gewässerkunde
201817aa7b1c Added the missing vegetation import classes
mschaefer
parents:
diff changeset
2 * Software engineering by
201817aa7b1c Added the missing vegetation import classes
mschaefer
parents:
diff changeset
3 * Björnsen Beratende Ingenieure GmbH
201817aa7b1c Added the missing vegetation import classes
mschaefer
parents:
diff changeset
4 * Dr. Schumacher Ingenieurbüro für Wasser und Umwelt
201817aa7b1c Added the missing vegetation import classes
mschaefer
parents:
diff changeset
5 *
201817aa7b1c Added the missing vegetation import classes
mschaefer
parents:
diff changeset
6 * This file is Free Software under the GNU AGPL (>=v3)
201817aa7b1c Added the missing vegetation import classes
mschaefer
parents:
diff changeset
7 * and comes with ABSOLUTELY NO WARRANTY! Check out the
201817aa7b1c Added the missing vegetation import classes
mschaefer
parents:
diff changeset
8 * documentation coming with Dive4Elements River for details.
201817aa7b1c Added the missing vegetation import classes
mschaefer
parents:
diff changeset
9 */
201817aa7b1c Added the missing vegetation import classes
mschaefer
parents:
diff changeset
10
201817aa7b1c Added the missing vegetation import classes
mschaefer
parents:
diff changeset
11 package org.dive4elements.river.importer.uinfo.importitem;
201817aa7b1c Added the missing vegetation import classes
mschaefer
parents:
diff changeset
12
201817aa7b1c Added the missing vegetation import classes
mschaefer
parents:
diff changeset
13 import java.util.List;
201817aa7b1c Added the missing vegetation import classes
mschaefer
parents:
diff changeset
14
201817aa7b1c Added the missing vegetation import classes
mschaefer
parents:
diff changeset
15 import org.apache.log4j.Logger;
201817aa7b1c Added the missing vegetation import classes
mschaefer
parents:
diff changeset
16 import org.dive4elements.river.importer.common.AbstractKmLineImport;
201817aa7b1c Added the missing vegetation import classes
mschaefer
parents:
diff changeset
17 import org.dive4elements.river.model.uinfo.Vegetation;
201817aa7b1c Added the missing vegetation import classes
mschaefer
parents:
diff changeset
18 import org.dive4elements.river.model.uinfo.VegetationType;
201817aa7b1c Added the missing vegetation import classes
mschaefer
parents:
diff changeset
19 import org.dive4elements.river.model.uinfo.VegetationZone;
201817aa7b1c Added the missing vegetation import classes
mschaefer
parents:
diff changeset
20 import org.hibernate.Query;
201817aa7b1c Added the missing vegetation import classes
mschaefer
parents:
diff changeset
21 import org.hibernate.Session;
201817aa7b1c Added the missing vegetation import classes
mschaefer
parents:
diff changeset
22
201817aa7b1c Added the missing vegetation import classes
mschaefer
parents:
diff changeset
23 /**
201817aa7b1c Added the missing vegetation import classes
mschaefer
parents:
diff changeset
24 * Imported vegetation values of a river station.
201817aa7b1c Added the missing vegetation import classes
mschaefer
parents:
diff changeset
25 *
201817aa7b1c Added the missing vegetation import classes
mschaefer
parents:
diff changeset
26 * @author Matthias Schäfer
201817aa7b1c Added the missing vegetation import classes
mschaefer
parents:
diff changeset
27 *
201817aa7b1c Added the missing vegetation import classes
mschaefer
parents:
diff changeset
28 */
201817aa7b1c Added the missing vegetation import classes
mschaefer
parents:
diff changeset
29 public class VegetationZoneImport extends AbstractKmLineImport<Vegetation, VegetationZone> {
201817aa7b1c Added the missing vegetation import classes
mschaefer
parents:
diff changeset
30
201817aa7b1c Added the missing vegetation import classes
mschaefer
parents:
diff changeset
31 /***** FIELDS *****/
201817aa7b1c Added the missing vegetation import classes
mschaefer
parents:
diff changeset
32
201817aa7b1c Added the missing vegetation import classes
mschaefer
parents:
diff changeset
33 private static Logger log = Logger.getLogger(VegetationZoneImport.class);
201817aa7b1c Added the missing vegetation import classes
mschaefer
parents:
diff changeset
34
201817aa7b1c Added the missing vegetation import classes
mschaefer
parents:
diff changeset
35 private final VegetationTypeImport vegetationType;
201817aa7b1c Added the missing vegetation import classes
mschaefer
parents:
diff changeset
36
201817aa7b1c Added the missing vegetation import classes
mschaefer
parents:
diff changeset
37 private final Integer minOverflowDays;
201817aa7b1c Added the missing vegetation import classes
mschaefer
parents:
diff changeset
38
201817aa7b1c Added the missing vegetation import classes
mschaefer
parents:
diff changeset
39 private final Integer maxOverflowDays;
201817aa7b1c Added the missing vegetation import classes
mschaefer
parents:
diff changeset
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
201817aa7b1c Added the missing vegetation import classes
mschaefer
parents:
diff changeset
46
201817aa7b1c Added the missing vegetation import classes
mschaefer
parents:
diff changeset
47 /***** CONSTRUCTOR *****/
201817aa7b1c Added the missing vegetation import classes
mschaefer
parents:
diff changeset
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
201817aa7b1c Added the missing vegetation import classes
mschaefer
parents:
diff changeset
51 super(Double.NaN);
201817aa7b1c Added the missing vegetation import classes
mschaefer
parents:
diff changeset
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
201817aa7b1c Added the missing vegetation import classes
mschaefer
parents:
diff changeset
58 }
201817aa7b1c Added the missing vegetation import classes
mschaefer
parents:
diff changeset
59
201817aa7b1c Added the missing vegetation import classes
mschaefer
parents:
diff changeset
60
201817aa7b1c Added the missing vegetation import classes
mschaefer
parents:
diff changeset
61 /***** METHODS *****/
201817aa7b1c Added the missing vegetation import classes
mschaefer
parents:
diff changeset
62
201817aa7b1c Added the missing vegetation import classes
mschaefer
parents:
diff changeset
63 @Override
201817aa7b1c Added the missing vegetation import classes
mschaefer
parents:
diff changeset
64 public VegetationZone queryValueItem(final Session session, final Vegetation parent) {
201817aa7b1c Added the missing vegetation import classes
mschaefer
parents:
diff changeset
65 final Query query = session.createQuery("FROM VegetationZone WHERE (vegetation=:parent)"
201817aa7b1c Added the missing vegetation import classes
mschaefer
parents:
diff changeset
66 + " AND (vegetationType=:type)");
201817aa7b1c Added the missing vegetation import classes
mschaefer
parents:
diff changeset
67 query.setParameter("parent", parent);
201817aa7b1c Added the missing vegetation import classes
mschaefer
parents:
diff changeset
68 query.setParameter("type", this.vegetationType);
201817aa7b1c Added the missing vegetation import classes
mschaefer
parents:
diff changeset
69 final List rows = query.list();
201817aa7b1c Added the missing vegetation import classes
mschaefer
parents:
diff changeset
70 if (!rows.isEmpty())
201817aa7b1c Added the missing vegetation import classes
mschaefer
parents:
diff changeset
71 return (VegetationZone) rows.get(0);
201817aa7b1c Added the missing vegetation import classes
mschaefer
parents:
diff changeset
72 else
201817aa7b1c Added the missing vegetation import classes
mschaefer
parents:
diff changeset
73 return null;
201817aa7b1c Added the missing vegetation import classes
mschaefer
parents:
diff changeset
74 }
201817aa7b1c Added the missing vegetation import classes
mschaefer
parents:
diff changeset
75
201817aa7b1c Added the missing vegetation import classes
mschaefer
parents:
diff changeset
76
201817aa7b1c Added the missing vegetation import classes
mschaefer
parents:
diff changeset
77 @Override
201817aa7b1c Added the missing vegetation import classes
mschaefer
parents:
diff changeset
78 public VegetationZone createValueItem(final Vegetation parent) {
201817aa7b1c Added the missing vegetation import classes
mschaefer
parents:
diff changeset
79 final VegetationType type = this.vegetationType.getPeer();
201817aa7b1c Added the missing vegetation import classes
mschaefer
parents:
diff changeset
80 if (type == null) {
201817aa7b1c Added the missing vegetation import classes
mschaefer
parents:
diff changeset
81 log.error("Unknown vegetation zone class " + this.vegetationType.getId());
201817aa7b1c Added the missing vegetation import classes
mschaefer
parents:
diff changeset
82 return null;
201817aa7b1c Added the missing vegetation import classes
mschaefer
parents:
diff changeset
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
201817aa7b1c Added the missing vegetation import classes
mschaefer
parents:
diff changeset
85 }
201817aa7b1c Added the missing vegetation import classes
mschaefer
parents:
diff changeset
86 }

http://dive4elements.wald.intevation.org