Mercurial > dive4elements > river
annotate backend/src/main/java/org/dive4elements/river/importer/ImportAttribute.java @ 9012:abe069eb180c
Import of vegetation zones added
author | mschaefer |
---|---|
date | Wed, 18 Apr 2018 07:43:55 +0200 |
parents | a275ddf7a3a1 |
children | c347512a07bd |
rev | line source |
---|---|
5844
4dd33b86dc61
Added header to river backend.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5838
diff
changeset
|
1 /* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde |
4dd33b86dc61
Added header to river backend.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5838
diff
changeset
|
2 * Software engineering by Intevation GmbH |
4dd33b86dc61
Added header to river backend.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5838
diff
changeset
|
3 * |
5992
4c3ccf2b0304
Removed trailing whitespace.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5844
diff
changeset
|
4 * This file is Free Software under the GNU AGPL (>=v3) |
5844
4dd33b86dc61
Added header to river backend.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5838
diff
changeset
|
5 * and comes with ABSOLUTELY NO WARRANTY! Check out the |
5992
4c3ccf2b0304
Removed trailing whitespace.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5844
diff
changeset
|
6 * documentation coming with Dive4Elements River for details. |
5844
4dd33b86dc61
Added header to river backend.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5838
diff
changeset
|
7 */ |
4dd33b86dc61
Added header to river backend.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5838
diff
changeset
|
8 |
5829
18619c1e7c2a
Repaired internal references.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5828
diff
changeset
|
9 package org.dive4elements.river.importer; |
185
a60edcfe5f53
Added new helper models for import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
10 |
8974
a275ddf7a3a1
Added some trim and lowercase in the where clauses of the selects of existing recordsets; added AnnotationType select
mschaefer
parents:
8856
diff
changeset
|
11 import java.util.List; |
a275ddf7a3a1
Added some trim and lowercase in the where clauses of the selects of existing recordsets; added AnnotationType select
mschaefer
parents:
8856
diff
changeset
|
12 |
5829
18619c1e7c2a
Repaired internal references.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5828
diff
changeset
|
13 import org.dive4elements.river.model.Attribute; |
8974
a275ddf7a3a1
Added some trim and lowercase in the where clauses of the selects of existing recordsets; added AnnotationType select
mschaefer
parents:
8856
diff
changeset
|
14 import org.hibernate.Query; |
187
ecf90018563b
Importer: Bound Attributes and Positions to there backend peers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
186
diff
changeset
|
15 import org.hibernate.Session; |
ecf90018563b
Importer: Bound Attributes and Positions to there backend peers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
186
diff
changeset
|
16 |
185
a60edcfe5f53
Added new helper models for import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
17 public class ImportAttribute |
186
cf8cbcb6a10d
Added parser to read *.KM files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
185
diff
changeset
|
18 implements Comparable<ImportAttribute> |
185
a60edcfe5f53
Added new helper models for import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
19 { |
a60edcfe5f53
Added new helper models for import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
20 protected String value; |
a60edcfe5f53
Added new helper models for import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
21 |
187
ecf90018563b
Importer: Bound Attributes and Positions to there backend peers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
186
diff
changeset
|
22 protected Attribute peer; |
ecf90018563b
Importer: Bound Attributes and Positions to there backend peers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
186
diff
changeset
|
23 |
185
a60edcfe5f53
Added new helper models for import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
24 public ImportAttribute() { |
a60edcfe5f53
Added new helper models for import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
25 } |
a60edcfe5f53
Added new helper models for import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
26 |
8974
a275ddf7a3a1
Added some trim and lowercase in the where clauses of the selects of existing recordsets; added AnnotationType select
mschaefer
parents:
8856
diff
changeset
|
27 public ImportAttribute(final String value) { |
186
cf8cbcb6a10d
Added parser to read *.KM files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
185
diff
changeset
|
28 this.value = value; |
cf8cbcb6a10d
Added parser to read *.KM files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
185
diff
changeset
|
29 } |
cf8cbcb6a10d
Added parser to read *.KM files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
185
diff
changeset
|
30 |
185
a60edcfe5f53
Added new helper models for import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
31 public String getValue() { |
8974
a275ddf7a3a1
Added some trim and lowercase in the where clauses of the selects of existing recordsets; added AnnotationType select
mschaefer
parents:
8856
diff
changeset
|
32 return this.value; |
185
a60edcfe5f53
Added new helper models for import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
33 } |
a60edcfe5f53
Added new helper models for import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
34 |
8974
a275ddf7a3a1
Added some trim and lowercase in the where clauses of the selects of existing recordsets; added AnnotationType select
mschaefer
parents:
8856
diff
changeset
|
35 public void setValue(final String value) { |
185
a60edcfe5f53
Added new helper models for import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
36 this.value = value; |
a60edcfe5f53
Added new helper models for import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
37 } |
a60edcfe5f53
Added new helper models for import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
38 |
8974
a275ddf7a3a1
Added some trim and lowercase in the where clauses of the selects of existing recordsets; added AnnotationType select
mschaefer
parents:
8856
diff
changeset
|
39 @Override |
a275ddf7a3a1
Added some trim and lowercase in the where clauses of the selects of existing recordsets; added AnnotationType select
mschaefer
parents:
8856
diff
changeset
|
40 public int compareTo(final ImportAttribute other) { |
a275ddf7a3a1
Added some trim and lowercase in the where clauses of the selects of existing recordsets; added AnnotationType select
mschaefer
parents:
8856
diff
changeset
|
41 return this.value.compareTo(other.value); |
186
cf8cbcb6a10d
Added parser to read *.KM files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
185
diff
changeset
|
42 } |
cf8cbcb6a10d
Added parser to read *.KM files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
185
diff
changeset
|
43 |
185
a60edcfe5f53
Added new helper models for import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
44 @Override |
8974
a275ddf7a3a1
Added some trim and lowercase in the where clauses of the selects of existing recordsets; added AnnotationType select
mschaefer
parents:
8856
diff
changeset
|
45 public boolean equals(final Object other) { |
a275ddf7a3a1
Added some trim and lowercase in the where clauses of the selects of existing recordsets; added AnnotationType select
mschaefer
parents:
8856
diff
changeset
|
46 if (other == this) |
a275ddf7a3a1
Added some trim and lowercase in the where clauses of the selects of existing recordsets; added AnnotationType select
mschaefer
parents:
8856
diff
changeset
|
47 return true; |
a275ddf7a3a1
Added some trim and lowercase in the where clauses of the selects of existing recordsets; added AnnotationType select
mschaefer
parents:
8856
diff
changeset
|
48 if (!(other instanceof ImportAttribute)) |
a275ddf7a3a1
Added some trim and lowercase in the where clauses of the selects of existing recordsets; added AnnotationType select
mschaefer
parents:
8856
diff
changeset
|
49 return false; |
a275ddf7a3a1
Added some trim and lowercase in the where clauses of the selects of existing recordsets; added AnnotationType select
mschaefer
parents:
8856
diff
changeset
|
50 return this.value.equals(((ImportAttribute) other).value); |
185
a60edcfe5f53
Added new helper models for import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
51 } |
a60edcfe5f53
Added new helper models for import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
52 |
a60edcfe5f53
Added new helper models for import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
53 @Override |
a60edcfe5f53
Added new helper models for import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
54 public int hashCode() { |
8974
a275ddf7a3a1
Added some trim and lowercase in the where clauses of the selects of existing recordsets; added AnnotationType select
mschaefer
parents:
8856
diff
changeset
|
55 return this.value.hashCode(); |
185
a60edcfe5f53
Added new helper models for import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
56 } |
187
ecf90018563b
Importer: Bound Attributes and Positions to there backend peers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
186
diff
changeset
|
57 |
ecf90018563b
Importer: Bound Attributes and Positions to there backend peers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
186
diff
changeset
|
58 public Attribute getPeer() { |
8974
a275ddf7a3a1
Added some trim and lowercase in the where clauses of the selects of existing recordsets; added AnnotationType select
mschaefer
parents:
8856
diff
changeset
|
59 if (this.peer != null) |
a275ddf7a3a1
Added some trim and lowercase in the where clauses of the selects of existing recordsets; added AnnotationType select
mschaefer
parents:
8856
diff
changeset
|
60 return this.peer; |
a275ddf7a3a1
Added some trim and lowercase in the where clauses of the selects of existing recordsets; added AnnotationType select
mschaefer
parents:
8856
diff
changeset
|
61 final Session session = ImporterSession.getInstance().getDatabaseSession(); |
a275ddf7a3a1
Added some trim and lowercase in the where clauses of the selects of existing recordsets; added AnnotationType select
mschaefer
parents:
8856
diff
changeset
|
62 final Query query = session.createQuery("FROM Attribute WHERE lower(value)=:value"); |
a275ddf7a3a1
Added some trim and lowercase in the where clauses of the selects of existing recordsets; added AnnotationType select
mschaefer
parents:
8856
diff
changeset
|
63 query.setString("value", this.value.trim().toLowerCase()); |
a275ddf7a3a1
Added some trim and lowercase in the where clauses of the selects of existing recordsets; added AnnotationType select
mschaefer
parents:
8856
diff
changeset
|
64 final List<Attribute> attributes = query.list(); |
a275ddf7a3a1
Added some trim and lowercase in the where clauses of the selects of existing recordsets; added AnnotationType select
mschaefer
parents:
8856
diff
changeset
|
65 if (attributes.isEmpty()) { |
a275ddf7a3a1
Added some trim and lowercase in the where clauses of the selects of existing recordsets; added AnnotationType select
mschaefer
parents:
8856
diff
changeset
|
66 this.peer = new Attribute(this.value); |
a275ddf7a3a1
Added some trim and lowercase in the where clauses of the selects of existing recordsets; added AnnotationType select
mschaefer
parents:
8856
diff
changeset
|
67 session.save(this.peer); |
187
ecf90018563b
Importer: Bound Attributes and Positions to there backend peers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
186
diff
changeset
|
68 } |
8974
a275ddf7a3a1
Added some trim and lowercase in the where clauses of the selects of existing recordsets; added AnnotationType select
mschaefer
parents:
8856
diff
changeset
|
69 else { |
a275ddf7a3a1
Added some trim and lowercase in the where clauses of the selects of existing recordsets; added AnnotationType select
mschaefer
parents:
8856
diff
changeset
|
70 this.peer = attributes.get(0); |
a275ddf7a3a1
Added some trim and lowercase in the where clauses of the selects of existing recordsets; added AnnotationType select
mschaefer
parents:
8856
diff
changeset
|
71 } |
a275ddf7a3a1
Added some trim and lowercase in the where clauses of the selects of existing recordsets; added AnnotationType select
mschaefer
parents:
8856
diff
changeset
|
72 return this.peer; |
187
ecf90018563b
Importer: Bound Attributes and Positions to there backend peers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
186
diff
changeset
|
73 } |
185
a60edcfe5f53
Added new helper models for import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
74 } |
a60edcfe5f53
Added new helper models for import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
75 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |