annotate backend/src/main/java/org/dive4elements/river/importer/ImportAnnotationType.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 a275ddf7a3a1
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;
763
8076f6a689d0 First part of flys/issue18
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
a275ddf7a3a1 Added some trim and lowercase in the where clauses of the selects of existing recordsets; added AnnotationType select
mschaefer
parents: 8856
diff changeset
13 import org.apache.log4j.Logger;
5829
18619c1e7c2a Repaired internal references.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5828
diff changeset
14 import org.dive4elements.river.model.AnnotationType;
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
15 import org.hibernate.Query;
763
8076f6a689d0 First part of flys/issue18
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
16 import org.hibernate.Session;
8076f6a689d0 First part of flys/issue18
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
17
8076f6a689d0 First part of flys/issue18
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
18 public class ImportAnnotationType
8076f6a689d0 First part of flys/issue18
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
19 implements Comparable<ImportAnnotationType>
8076f6a689d0 First part of flys/issue18
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
20 {
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
21 private static final Logger log = Logger.getLogger(ImportAnnotationType.class);
763
8076f6a689d0 First part of flys/issue18
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
22 protected String name;
8076f6a689d0 First part of flys/issue18
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
23 protected AnnotationType peer;
8076f6a689d0 First part of flys/issue18
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
24
8076f6a689d0 First part of flys/issue18
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
25 public ImportAnnotationType() {
8076f6a689d0 First part of flys/issue18
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
26 }
8076f6a689d0 First part of flys/issue18
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
27
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
28 public ImportAnnotationType(final String name) {
763
8076f6a689d0 First part of flys/issue18
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
29 this.name = name;
8076f6a689d0 First part of flys/issue18
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
30 }
8076f6a689d0 First part of flys/issue18
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
31
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 @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
33 public int compareTo(final ImportAnnotationType 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
34 return this.name.compareTo(other.name);
763
8076f6a689d0 First part of flys/issue18
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
35 }
8076f6a689d0 First part of flys/issue18
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
36
766
aa9e3da95c31 Importer: Fix import of annotation type classification.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 763
diff changeset
37 public String getName() {
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
38 return this.name;
766
aa9e3da95c31 Importer: Fix import of annotation type classification.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 763
diff changeset
39 }
aa9e3da95c31 Importer: Fix import of annotation type classification.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 763
diff changeset
40
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
41 public void setName(final String name) {
766
aa9e3da95c31 Importer: Fix import of annotation type classification.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 763
diff changeset
42 this.name = name;
aa9e3da95c31 Importer: Fix import of annotation type classification.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 763
diff changeset
43 }
aa9e3da95c31 Importer: Fix import of annotation type classification.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 763
diff changeset
44
aa9e3da95c31 Importer: Fix import of annotation type classification.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 763
diff changeset
45
763
8076f6a689d0 First part of flys/issue18
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
46 public AnnotationType 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
47 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
48 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
49 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
50 final Query query = session.createQuery("FROM AnnotationType WHERE lower(name)=:name");
a275ddf7a3a1 Added some trim and lowercase in the where clauses of the selects of existing recordsets; added AnnotationType select
mschaefer
parents: 8856
diff changeset
51 query.setParameter("name", this.name.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
52 final List<AnnotationType> types = 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
53 if (types.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
54 this.peer = new AnnotationType(this.name);
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 session.save(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
56 log.info(String.format("Create new database instance: %d, '%s'", this.peer.getId(), this.name));
763
8076f6a689d0 First part of flys/issue18
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
57 }
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
58 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
59 this.peer = types.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
60 }
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 return this.peer;
763
8076f6a689d0 First part of flys/issue18
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
62 }
8076f6a689d0 First part of flys/issue18
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
63 }
8076f6a689d0 First part of flys/issue18
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
64 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org