Mercurial > dive4elements > river
comparison backend/src/main/java/org/dive4elements/river/importer/ImportAnnotation.java @ 7730:e1b831fe435a slt-simplify-cross-sections
Merged default into slt-simplify-cross-sections branch and updated package and class names.
author | Tom Gottfried <tom@intevation.de> |
---|---|
date | Mon, 20 Jan 2014 14:04:20 +0100 |
parents | 4c3ccf2b0304 |
children | 5e38e2924c07 |
comparison
equal
deleted
inserted
replaced
5084:ca45dd039b54 | 7730:e1b831fe435a |
---|---|
1 /* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde | |
2 * Software engineering by Intevation GmbH | |
3 * | |
4 * This file is Free Software under the GNU AGPL (>=v3) | |
5 * and comes with ABSOLUTELY NO WARRANTY! Check out the | |
6 * documentation coming with Dive4Elements River for details. | |
7 */ | |
8 | |
9 package org.dive4elements.river.importer; | |
10 | |
11 import org.dive4elements.river.model.Annotation; | |
12 import org.dive4elements.river.model.AnnotationType; | |
13 import org.dive4elements.river.model.Range; | |
14 import org.dive4elements.river.model.Position; | |
15 import org.dive4elements.river.model.Attribute; | |
16 import org.dive4elements.river.model.River; | |
17 import org.dive4elements.river.model.Edge; | |
18 | |
19 import org.hibernate.Session; | |
20 import org.hibernate.Query; | |
21 | |
22 import java.util.List; | |
23 | |
24 public class ImportAnnotation | |
25 implements Comparable<ImportAnnotation> | |
26 { | |
27 protected ImportAttribute attribute; | |
28 protected ImportPosition position; | |
29 protected ImportRange range; | |
30 protected ImportEdge edge; | |
31 protected ImportAnnotationType type; | |
32 | |
33 protected Annotation peer; | |
34 | |
35 public ImportAnnotation() { | |
36 } | |
37 | |
38 public ImportAnnotation( | |
39 ImportAttribute attribute, | |
40 ImportPosition position, | |
41 ImportRange range, | |
42 ImportEdge edge, | |
43 ImportAnnotationType type | |
44 ) { | |
45 this.attribute = attribute; | |
46 this.position = position; | |
47 this.range = range; | |
48 this.edge = edge; | |
49 this.type = type; | |
50 } | |
51 | |
52 public int compareTo(ImportAnnotation other) { | |
53 int d = attribute.compareTo(other.attribute); | |
54 if (d != 0) { | |
55 return d; | |
56 } | |
57 | |
58 if ((d = position.compareTo(other.position)) != 0) { | |
59 return d; | |
60 } | |
61 | |
62 if ((d = range.compareTo(other.range)) != 0) { | |
63 return d; | |
64 } | |
65 | |
66 if (edge == null && other.edge != null) return -1; | |
67 if (edge != null && other.edge == null) return +1; | |
68 if (edge == null && other.edge == null) return 0; | |
69 | |
70 if ((d = edge.compareTo(other.edge)) != 0) { | |
71 return d; | |
72 } | |
73 | |
74 if (type == null && other.type != null) return -1; | |
75 if (type != null && other.type == null) return +1; | |
76 if (type == null && other.type == null) return 0; | |
77 | |
78 return type.compareTo(other.type); | |
79 } | |
80 | |
81 public ImportAttribute getAttribute() { | |
82 return attribute; | |
83 } | |
84 | |
85 public void setAttribute(ImportAttribute attribute) { | |
86 this.attribute = attribute; | |
87 } | |
88 | |
89 public ImportPosition getPosition() { | |
90 return position; | |
91 } | |
92 | |
93 public void setPosition(ImportPosition position) { | |
94 this.position = position; | |
95 } | |
96 | |
97 public ImportRange getRange() { | |
98 return range; | |
99 } | |
100 | |
101 public void setRange(ImportRange range) { | |
102 this.range = range; | |
103 } | |
104 | |
105 public ImportEdge getEdge() { | |
106 return edge; | |
107 } | |
108 | |
109 public void setEdge(ImportEdge edge) { | |
110 this.edge = edge; | |
111 } | |
112 | |
113 public ImportAnnotationType getType() { | |
114 return type; | |
115 } | |
116 | |
117 public void setType(ImportAnnotationType type) { | |
118 this.type = type; | |
119 } | |
120 | |
121 public Annotation getPeer(River river) { | |
122 if (peer == null) { | |
123 Range r = range.getPeer(river); | |
124 Attribute a = attribute.getPeer(); | |
125 Position p = position.getPeer(); | |
126 Edge e = edge != null ? edge.getPeer() : null; | |
127 AnnotationType t = type != null ? type.getPeer() : null; | |
128 | |
129 Session session = ImporterSession.getInstance().getDatabaseSession(); | |
130 Query query = session.createQuery( | |
131 "from Annotation where " + | |
132 "range=:range and " + | |
133 "attribute=:attribute and " + | |
134 "position=:position and " + | |
135 "edge=:edge and " + | |
136 "type=:type"); | |
137 query.setParameter("range", r); | |
138 query.setParameter("attribute", a); | |
139 query.setParameter("position", p); | |
140 query.setParameter("edge", e); | |
141 query.setParameter("type", t); | |
142 List<Annotation> annotations = query.list(); | |
143 if (annotations.isEmpty()) { | |
144 peer = new Annotation(r, a, p, e, t); | |
145 session.save(peer); | |
146 } | |
147 else { | |
148 peer = annotations.get(0); | |
149 } | |
150 } | |
151 return peer; | |
152 } | |
153 } | |
154 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |