comparison backend/src/main/java/org/dive4elements/river/importer/ImportSedimentLoadLS.java @ 8059:bde5f5ec7c72

SCHEMA CHANGE and Importer: get time intervals of SQ-relations from metalines in sediment load files.
author Tom Gottfried <tom@intevation.de>
date Fri, 18 Jul 2014 18:01:49 +0200
parents d86cc6a17b7a
children 5e38e2924c07
comparison
equal deleted inserted replaced
8058:fbe3ba5a480e 8059:bde5f5ec7c72
31 31
32 private ImportUnit unit; 32 private ImportUnit unit;
33 33
34 private ImportTimeInterval timeInterval; 34 private ImportTimeInterval timeInterval;
35 35
36 private ImportTimeInterval sqTimeInterval;
37
36 private String description; 38 private String description;
37 39
38 private Integer kind; 40 private Integer kind;
39 41
40 private List<ImportSedimentLoadLSValue> values; 42 private List<ImportSedimentLoadLSValue> values;
46 this.description = description; 48 this.description = description;
47 } 49 }
48 50
49 public void setTimeInterval(ImportTimeInterval timeInterval) { 51 public void setTimeInterval(ImportTimeInterval timeInterval) {
50 this.timeInterval = timeInterval; 52 this.timeInterval = timeInterval;
53 }
54
55 public void setSQTimeInterval(ImportTimeInterval sqTimeInterval) {
56 this.sqTimeInterval = sqTimeInterval;
51 } 57 }
52 58
53 public void setUnit(ImportUnit unit) { 59 public void setUnit(ImportUnit unit) {
54 this.unit = unit; 60 this.unit = unit;
55 } 61 }
90 : null; 96 : null;
91 97
92 Unit u = unit != null ? unit.getPeer() : null; 98 Unit u = unit != null ? unit.getPeer() : null;
93 99
94 TimeInterval ti = timeInterval != null ? timeInterval.getPeer() : null; 100 TimeInterval ti = timeInterval != null ? timeInterval.getPeer() : null;
101 TimeInterval sqti = sqTimeInterval != null
102 ? sqTimeInterval.getPeer()
103 : null;
95 104
96 if (ti == null || u == null) { 105 if (ti == null || u == null) {
97 log.warn("Skip invalid SedimentLoadLS: time interval or unit null!"); 106 log.warn("Skip invalid SedimentLoadLS: time interval or unit null!");
98 return null; 107 return null;
99 } 108 }
100 109
101 if (peer == null) { 110 if (peer == null) {
102 Session session = ImporterSession.getInstance() 111 Session session = ImporterSession.getInstance()
103 .getDatabaseSession(); 112 .getDatabaseSession();
113
114 String sqtquery = sqTimeInterval == null ?
115 "sq_time_interval_id is null" :
116 "sqTimeInterval = :sqTimeInterval";
104 Query query = session.createQuery("from SedimentLoadLS where " 117 Query query = session.createQuery("from SedimentLoadLS where "
105 + " river=:river and " 118 + " river=:river and "
106 + " grainFraction=:grainFraction and " + " unit=:unit and " 119 + " grainFraction=:grainFraction and "
120 + " unit=:unit and "
107 + " timeInterval=:timeInterval and " 121 + " timeInterval=:timeInterval and "
108 + " description=:description"); 122 + " description=:description and "
123 + " kind = :kind and " +
124 sqtquery);
109 125
110 query.setParameter("river", river); 126 query.setParameter("river", river);
111 query.setParameter("grainFraction", gf); 127 query.setParameter("grainFraction", gf);
112 query.setParameter("unit", u); 128 query.setParameter("unit", u);
113 query.setParameter("timeInterval", ti); 129 query.setParameter("timeInterval", ti);
130 if (sqti != null) {
131 query.setParameter("sqTimeInterval", sqti);
132 }
114 query.setParameter("description", description); 133 query.setParameter("description", description);
134 query.setParameter("kind", kind);
115 135
116 List<SedimentLoadLS> loads = query.list(); 136 List<SedimentLoadLS> loads = query.list();
117 if (loads.isEmpty()) { 137 if (loads.isEmpty()) {
118 log.debug("create new SedimentLoadLS"); 138 log.debug("create new SedimentLoadLS");
119 139
120 peer = new SedimentLoadLS(river, u, ti, gf, description); 140 peer = new SedimentLoadLS(river, u, ti, sqti, gf, description);
121 peer.setKind(this.kind); 141 peer.setKind(this.kind);
122 session.save(peer); 142 session.save(peer);
123 } 143 }
124 else { 144 else {
125 peer = loads.get(0); 145 peer = loads.get(0);

http://dive4elements.wald.intevation.org