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