annotate backend/src/main/java/org/dive4elements/river/importer/ImportAttribute.java @ 9650:a2a42a6bac6b

Importer (s/u-info) extensions: outer try/catch for parse and log of line no, catching parsing exception if not enough value fields, parsing error and warning log messages with line number, detecting and rejecting duplicate data series, better differentiation between error and warning log messages
author mschaefer
date Mon, 23 Mar 2020 14:57:03 +0100
parents c347512a07bd
children
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();
9488
c347512a07bd Fixed: finding attributes record first case sensitive, insensitive then as fallback
mschaefer
parents: 8974
diff changeset
62 final Query query = session.createQuery("FROM Attribute WHERE value=:value");
c347512a07bd Fixed: finding attributes record first case sensitive, insensitive then as fallback
mschaefer
parents: 8974
diff changeset
63 query.setString("value", this.value.trim());
c347512a07bd Fixed: finding attributes record first case sensitive, insensitive then as fallback
mschaefer
parents: 8974
diff changeset
64 final List<Attribute> attributes = query.list();
c347512a07bd Fixed: finding attributes record first case sensitive, insensitive then as fallback
mschaefer
parents: 8974
diff changeset
65 if (attributes.isEmpty()) {
c347512a07bd Fixed: finding attributes record first case sensitive, insensitive then as fallback
mschaefer
parents: 8974
diff changeset
66 this.peer = getPeerCaseInsensitive();
c347512a07bd Fixed: finding attributes record first case sensitive, insensitive then as fallback
mschaefer
parents: 8974
diff changeset
67 if (this.peer == null) {
c347512a07bd Fixed: finding attributes record first case sensitive, insensitive then as fallback
mschaefer
parents: 8974
diff changeset
68 this.peer = new Attribute(this.value);
c347512a07bd Fixed: finding attributes record first case sensitive, insensitive then as fallback
mschaefer
parents: 8974
diff changeset
69 session.save(this.peer);
c347512a07bd Fixed: finding attributes record first case sensitive, insensitive then as fallback
mschaefer
parents: 8974
diff changeset
70 }
c347512a07bd Fixed: finding attributes record first case sensitive, insensitive then as fallback
mschaefer
parents: 8974
diff changeset
71 }
c347512a07bd Fixed: finding attributes record first case sensitive, insensitive then as fallback
mschaefer
parents: 8974
diff changeset
72 else {
c347512a07bd Fixed: finding attributes record first case sensitive, insensitive then as fallback
mschaefer
parents: 8974
diff changeset
73 this.peer = attributes.get(0);
c347512a07bd Fixed: finding attributes record first case sensitive, insensitive then as fallback
mschaefer
parents: 8974
diff changeset
74 }
c347512a07bd Fixed: finding attributes record first case sensitive, insensitive then as fallback
mschaefer
parents: 8974
diff changeset
75 return this.peer;
c347512a07bd Fixed: finding attributes record first case sensitive, insensitive then as fallback
mschaefer
parents: 8974
diff changeset
76 }
c347512a07bd Fixed: finding attributes record first case sensitive, insensitive then as fallback
mschaefer
parents: 8974
diff changeset
77
c347512a07bd Fixed: finding attributes record first case sensitive, insensitive then as fallback
mschaefer
parents: 8974
diff changeset
78 private Attribute getPeerCaseInsensitive() {
c347512a07bd Fixed: finding attributes record first case sensitive, insensitive then as fallback
mschaefer
parents: 8974
diff changeset
79 if (this.peer != null)
c347512a07bd Fixed: finding attributes record first case sensitive, insensitive then as fallback
mschaefer
parents: 8974
diff changeset
80 return this.peer;
c347512a07bd Fixed: finding attributes record first case sensitive, insensitive then as fallback
mschaefer
parents: 8974
diff changeset
81 final Session session = ImporterSession.getInstance().getDatabaseSession();
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
82 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
83 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
84 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
85 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
86 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
87 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
88 }
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
89 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
90 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
91 }
a275ddf7a3a1 Added some trim and lowercase in the where clauses of the selects of existing recordsets; added AnnotationType select
mschaefer
parents: 8856
diff changeset
92 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
93 }
185
a60edcfe5f53 Added new helper models for import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
94 }
a60edcfe5f53 Added new helper models for import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
95 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org