annotate backend/src/main/java/org/dive4elements/river/importer/uinfo/importitem/VegetationTypeImport.java @ 9014:201817aa7b1c

Added the missing vegetation import classes
author mschaefer
date Wed, 18 Apr 2018 12:11:39 +0200
parents
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.ImporterSession;
201817aa7b1c Added the missing vegetation import classes
mschaefer
parents:
diff changeset
17 import org.dive4elements.river.model.uinfo.VegetationType;
201817aa7b1c Added the missing vegetation import classes
mschaefer
parents:
diff changeset
18 import org.hibernate.Query;
201817aa7b1c Added the missing vegetation import classes
mschaefer
parents:
diff changeset
19 import org.hibernate.Session;
201817aa7b1c Added the missing vegetation import classes
mschaefer
parents:
diff changeset
20
201817aa7b1c Added the missing vegetation import classes
mschaefer
parents:
diff changeset
21 /**
201817aa7b1c Added the missing vegetation import classes
mschaefer
parents:
diff changeset
22 * Imported vegetation zone type
201817aa7b1c Added the missing vegetation import classes
mschaefer
parents:
diff changeset
23 *
201817aa7b1c Added the missing vegetation import classes
mschaefer
parents:
diff changeset
24 * @author Matthias Schäfer
201817aa7b1c Added the missing vegetation import classes
mschaefer
parents:
diff changeset
25 *
201817aa7b1c Added the missing vegetation import classes
mschaefer
parents:
diff changeset
26 */
201817aa7b1c Added the missing vegetation import classes
mschaefer
parents:
diff changeset
27 public class VegetationTypeImport implements Comparable<VegetationTypeImport> {
201817aa7b1c Added the missing vegetation import classes
mschaefer
parents:
diff changeset
28
201817aa7b1c Added the missing vegetation import classes
mschaefer
parents:
diff changeset
29 /***** FIELDS *****/
201817aa7b1c Added the missing vegetation import classes
mschaefer
parents:
diff changeset
30
201817aa7b1c Added the missing vegetation import classes
mschaefer
parents:
diff changeset
31 private static final Logger log = Logger.getLogger(VegetationTypeImport.class);
201817aa7b1c Added the missing vegetation import classes
mschaefer
parents:
diff changeset
32
201817aa7b1c Added the missing vegetation import classes
mschaefer
parents:
diff changeset
33 protected Integer id;
201817aa7b1c Added the missing vegetation import classes
mschaefer
parents:
diff changeset
34
201817aa7b1c Added the missing vegetation import classes
mschaefer
parents:
diff changeset
35 protected String name;
201817aa7b1c Added the missing vegetation import classes
mschaefer
parents:
diff changeset
36
201817aa7b1c Added the missing vegetation import classes
mschaefer
parents:
diff changeset
37 protected VegetationType peer;
201817aa7b1c Added the missing vegetation import classes
mschaefer
parents:
diff changeset
38
201817aa7b1c Added the missing vegetation import classes
mschaefer
parents:
diff changeset
39 /***** CONSTRUCTOR *****/
201817aa7b1c Added the missing vegetation import classes
mschaefer
parents:
diff changeset
40
201817aa7b1c Added the missing vegetation import classes
mschaefer
parents:
diff changeset
41 public VegetationTypeImport() {
201817aa7b1c Added the missing vegetation import classes
mschaefer
parents:
diff changeset
42 }
201817aa7b1c Added the missing vegetation import classes
mschaefer
parents:
diff changeset
43
201817aa7b1c Added the missing vegetation import classes
mschaefer
parents:
diff changeset
44 public VegetationTypeImport(final int id) {
201817aa7b1c Added the missing vegetation import classes
mschaefer
parents:
diff changeset
45 this.id = Integer.valueOf(id);
201817aa7b1c Added the missing vegetation import classes
mschaefer
parents:
diff changeset
46 }
201817aa7b1c Added the missing vegetation import classes
mschaefer
parents:
diff changeset
47
201817aa7b1c Added the missing vegetation import classes
mschaefer
parents:
diff changeset
48 /***** METHODS *****/
201817aa7b1c Added the missing vegetation import classes
mschaefer
parents:
diff changeset
49
201817aa7b1c Added the missing vegetation import classes
mschaefer
parents:
diff changeset
50 @Override
201817aa7b1c Added the missing vegetation import classes
mschaefer
parents:
diff changeset
51 public int compareTo(final VegetationTypeImport other) {
201817aa7b1c Added the missing vegetation import classes
mschaefer
parents:
diff changeset
52 return this.id.compareTo(other.getId());
201817aa7b1c Added the missing vegetation import classes
mschaefer
parents:
diff changeset
53 }
201817aa7b1c Added the missing vegetation import classes
mschaefer
parents:
diff changeset
54
201817aa7b1c Added the missing vegetation import classes
mschaefer
parents:
diff changeset
55 @Override
201817aa7b1c Added the missing vegetation import classes
mschaefer
parents:
diff changeset
56 public int hashCode() {
201817aa7b1c Added the missing vegetation import classes
mschaefer
parents:
diff changeset
57 return this.id;
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 public Integer getId() {
201817aa7b1c Added the missing vegetation import classes
mschaefer
parents:
diff changeset
61 return this.id;
201817aa7b1c Added the missing vegetation import classes
mschaefer
parents:
diff changeset
62 }
201817aa7b1c Added the missing vegetation import classes
mschaefer
parents:
diff changeset
63
201817aa7b1c Added the missing vegetation import classes
mschaefer
parents:
diff changeset
64 public void setId(final Integer id) {
201817aa7b1c Added the missing vegetation import classes
mschaefer
parents:
diff changeset
65 this.id = id;
201817aa7b1c Added the missing vegetation import classes
mschaefer
parents:
diff changeset
66 }
201817aa7b1c Added the missing vegetation import classes
mschaefer
parents:
diff changeset
67
201817aa7b1c Added the missing vegetation import classes
mschaefer
parents:
diff changeset
68 public String getName() {
201817aa7b1c Added the missing vegetation import classes
mschaefer
parents:
diff changeset
69 return this.name;
201817aa7b1c Added the missing vegetation import classes
mschaefer
parents:
diff changeset
70 }
201817aa7b1c Added the missing vegetation import classes
mschaefer
parents:
diff changeset
71
201817aa7b1c Added the missing vegetation import classes
mschaefer
parents:
diff changeset
72 public void setName(final String name) {
201817aa7b1c Added the missing vegetation import classes
mschaefer
parents:
diff changeset
73 this.name = name;
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 public VegetationType getPeer() {
201817aa7b1c Added the missing vegetation import classes
mschaefer
parents:
diff changeset
77 if (this.peer != null)
201817aa7b1c Added the missing vegetation import classes
mschaefer
parents:
diff changeset
78 return this.peer;
201817aa7b1c Added the missing vegetation import classes
mschaefer
parents:
diff changeset
79 final Session session = ImporterSession.getInstance().getDatabaseSession();
201817aa7b1c Added the missing vegetation import classes
mschaefer
parents:
diff changeset
80 final Query query = session.createQuery("FROM VegetationType WHERE id=:id");
201817aa7b1c Added the missing vegetation import classes
mschaefer
parents:
diff changeset
81 query.setParameter("id", this.id);
201817aa7b1c Added the missing vegetation import classes
mschaefer
parents:
diff changeset
82 final List<VegetationType> types = query.list();
201817aa7b1c Added the missing vegetation import classes
mschaefer
parents:
diff changeset
83 if (types.isEmpty()) {
201817aa7b1c Added the missing vegetation import classes
mschaefer
parents:
diff changeset
84 // Type table is not modifiable by the importer
201817aa7b1c Added the missing vegetation import classes
mschaefer
parents:
diff changeset
85 // this.peer = new VegetationType(this.name);
201817aa7b1c Added the missing vegetation import classes
mschaefer
parents:
diff changeset
86 // session.save(this.peer);
201817aa7b1c Added the missing vegetation import classes
mschaefer
parents:
diff changeset
87 // log.info(String.format("Create new database instance: %d, '%s'", this.peer.getId(), this.name));
201817aa7b1c Added the missing vegetation import classes
mschaefer
parents:
diff changeset
88 }
201817aa7b1c Added the missing vegetation import classes
mschaefer
parents:
diff changeset
89 else {
201817aa7b1c Added the missing vegetation import classes
mschaefer
parents:
diff changeset
90 this.peer = types.get(0);
201817aa7b1c Added the missing vegetation import classes
mschaefer
parents:
diff changeset
91 }
201817aa7b1c Added the missing vegetation import classes
mschaefer
parents:
diff changeset
92 return this.peer;
201817aa7b1c Added the missing vegetation import classes
mschaefer
parents:
diff changeset
93 }
201817aa7b1c Added the missing vegetation import classes
mschaefer
parents:
diff changeset
94 }

http://dive4elements.wald.intevation.org