Mercurial > dive4elements > river
annotate flys-backend/src/main/java/de/intevation/flys/importer/ImportGrainFraction.java @ 4447:a5993b69439b
Add processor to be able to generate curves for WKms values
author | Björn Ricks <bjoern.ricks@intevation.de> |
---|---|
date | Wed, 07 Nov 2012 15:52:25 +0100 |
parents | 71175502d868 |
children | 7aeb2c101628 |
rev | line source |
---|---|
2838
75446c47ef77
Added new importer classes for importing sediment yield data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
1 package de.intevation.flys.importer; |
75446c47ef77
Added new importer classes for importing sediment yield data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
2 |
75446c47ef77
Added new importer classes for importing sediment yield data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
3 import java.util.List; |
75446c47ef77
Added new importer classes for importing sediment yield data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
4 |
75446c47ef77
Added new importer classes for importing sediment yield data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
5 import org.apache.log4j.Logger; |
75446c47ef77
Added new importer classes for importing sediment yield data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
6 |
75446c47ef77
Added new importer classes for importing sediment yield data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
7 import org.hibernate.Session; |
75446c47ef77
Added new importer classes for importing sediment yield data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
8 import org.hibernate.Query; |
75446c47ef77
Added new importer classes for importing sediment yield data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
9 |
75446c47ef77
Added new importer classes for importing sediment yield data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
10 import de.intevation.flys.model.GrainFraction; |
75446c47ef77
Added new importer classes for importing sediment yield data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
11 import de.intevation.flys.model.Unit; |
75446c47ef77
Added new importer classes for importing sediment yield data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
12 |
75446c47ef77
Added new importer classes for importing sediment yield data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
13 |
75446c47ef77
Added new importer classes for importing sediment yield data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
14 public class ImportGrainFraction { |
75446c47ef77
Added new importer classes for importing sediment yield data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
15 |
75446c47ef77
Added new importer classes for importing sediment yield data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
16 private static final Logger log = |
75446c47ef77
Added new importer classes for importing sediment yield data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
17 Logger.getLogger(ImportGrainFraction.class); |
75446c47ef77
Added new importer classes for importing sediment yield data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
18 |
75446c47ef77
Added new importer classes for importing sediment yield data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
19 private String name; |
75446c47ef77
Added new importer classes for importing sediment yield data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
20 |
75446c47ef77
Added new importer classes for importing sediment yield data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
21 private Double lower; |
75446c47ef77
Added new importer classes for importing sediment yield data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
22 private Double upper; |
75446c47ef77
Added new importer classes for importing sediment yield data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
23 |
75446c47ef77
Added new importer classes for importing sediment yield data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
24 private ImportUnit unit; |
75446c47ef77
Added new importer classes for importing sediment yield data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
25 |
75446c47ef77
Added new importer classes for importing sediment yield data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
26 private GrainFraction peer; |
75446c47ef77
Added new importer classes for importing sediment yield data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
27 |
75446c47ef77
Added new importer classes for importing sediment yield data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
28 |
2840
71175502d868
Added a parser for sediment yield files; started parsing and store values in db.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2838
diff
changeset
|
29 public ImportGrainFraction(String name) { |
71175502d868
Added a parser for sediment yield files; started parsing and store values in db.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2838
diff
changeset
|
30 this.name = name; |
71175502d868
Added a parser for sediment yield files; started parsing and store values in db.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2838
diff
changeset
|
31 } |
71175502d868
Added a parser for sediment yield files; started parsing and store values in db.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2838
diff
changeset
|
32 |
71175502d868
Added a parser for sediment yield files; started parsing and store values in db.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2838
diff
changeset
|
33 |
2838
75446c47ef77
Added new importer classes for importing sediment yield data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
34 public ImportGrainFraction( |
75446c47ef77
Added new importer classes for importing sediment yield data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
35 String name, |
75446c47ef77
Added new importer classes for importing sediment yield data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
36 Double lower, |
75446c47ef77
Added new importer classes for importing sediment yield data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
37 Double upper, |
75446c47ef77
Added new importer classes for importing sediment yield data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
38 ImportUnit unit |
75446c47ef77
Added new importer classes for importing sediment yield data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
39 ) { |
75446c47ef77
Added new importer classes for importing sediment yield data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
40 this.name = name; |
75446c47ef77
Added new importer classes for importing sediment yield data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
41 this.lower = lower; |
75446c47ef77
Added new importer classes for importing sediment yield data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
42 this.upper = upper; |
75446c47ef77
Added new importer classes for importing sediment yield data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
43 this.unit = unit; |
75446c47ef77
Added new importer classes for importing sediment yield data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
44 } |
75446c47ef77
Added new importer classes for importing sediment yield data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
45 |
75446c47ef77
Added new importer classes for importing sediment yield data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
46 |
75446c47ef77
Added new importer classes for importing sediment yield data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
47 public void storeDependencies() { |
75446c47ef77
Added new importer classes for importing sediment yield data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
48 log.debug("store dependencies"); |
75446c47ef77
Added new importer classes for importing sediment yield data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
49 |
75446c47ef77
Added new importer classes for importing sediment yield data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
50 getPeer(); |
75446c47ef77
Added new importer classes for importing sediment yield data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
51 } |
75446c47ef77
Added new importer classes for importing sediment yield data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
52 |
75446c47ef77
Added new importer classes for importing sediment yield data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
53 |
75446c47ef77
Added new importer classes for importing sediment yield data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
54 public GrainFraction getPeer() { |
75446c47ef77
Added new importer classes for importing sediment yield data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
55 log.debug("get peer"); |
75446c47ef77
Added new importer classes for importing sediment yield data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
56 |
75446c47ef77
Added new importer classes for importing sediment yield data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
57 Unit u = unit != null ? unit.getPeer() : null; |
75446c47ef77
Added new importer classes for importing sediment yield data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
58 |
75446c47ef77
Added new importer classes for importing sediment yield data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
59 if (peer == null) { |
75446c47ef77
Added new importer classes for importing sediment yield data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
60 Session session = ImporterSession.getInstance().getDatabaseSession(); |
75446c47ef77
Added new importer classes for importing sediment yield data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
61 Query query = session.createQuery( |
75446c47ef77
Added new importer classes for importing sediment yield data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
62 "from GrainFraction where " + |
75446c47ef77
Added new importer classes for importing sediment yield data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
63 " name=:name and " + |
75446c47ef77
Added new importer classes for importing sediment yield data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
64 " lower=:lower and " + |
75446c47ef77
Added new importer classes for importing sediment yield data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
65 " upper=:upper and " + |
75446c47ef77
Added new importer classes for importing sediment yield data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
66 " unit=:unit" |
75446c47ef77
Added new importer classes for importing sediment yield data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
67 ); |
75446c47ef77
Added new importer classes for importing sediment yield data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
68 |
75446c47ef77
Added new importer classes for importing sediment yield data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
69 query.setParameter("name", name); |
75446c47ef77
Added new importer classes for importing sediment yield data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
70 query.setParameter("lower", lower); |
75446c47ef77
Added new importer classes for importing sediment yield data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
71 query.setParameter("upper", upper); |
75446c47ef77
Added new importer classes for importing sediment yield data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
72 query.setParameter("unit", u); |
75446c47ef77
Added new importer classes for importing sediment yield data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
73 |
75446c47ef77
Added new importer classes for importing sediment yield data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
74 List<GrainFraction> fractions = query.list(); |
75446c47ef77
Added new importer classes for importing sediment yield data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
75 if (fractions.isEmpty()) { |
75446c47ef77
Added new importer classes for importing sediment yield data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
76 log.info("create new GrainFraction"); |
75446c47ef77
Added new importer classes for importing sediment yield data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
77 |
75446c47ef77
Added new importer classes for importing sediment yield data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
78 peer = new GrainFraction(name, lower, upper, u); |
75446c47ef77
Added new importer classes for importing sediment yield data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
79 session.save(peer); |
75446c47ef77
Added new importer classes for importing sediment yield data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
80 } |
75446c47ef77
Added new importer classes for importing sediment yield data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
81 else { |
75446c47ef77
Added new importer classes for importing sediment yield data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
82 peer = fractions.get(0); |
75446c47ef77
Added new importer classes for importing sediment yield data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
83 } |
75446c47ef77
Added new importer classes for importing sediment yield data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
84 } |
75446c47ef77
Added new importer classes for importing sediment yield data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
85 |
75446c47ef77
Added new importer classes for importing sediment yield data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
86 return peer; |
75446c47ef77
Added new importer classes for importing sediment yield data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
87 } |
75446c47ef77
Added new importer classes for importing sediment yield data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
88 } |
75446c47ef77
Added new importer classes for importing sediment yield data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
89 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |