comparison backend/src/main/java/org/dive4elements/river/model/sinfo/Infrastructure.java @ 9625:07f02019065e

Nachtrag Pos. 20: infrastructure query added, calculation updated for extended access class
author mschaefer
date Mon, 14 Oct 2019 08:14:58 +0200
parents 02ca823ec9c6
children
comparison
equal deleted inserted replaced
9624:02ca823ec9c6 9625:07f02019065e
69 69
70 private String evaluation_by; 70 private String evaluation_by;
71 71
72 private List<InfrastructureValue> values; 72 private List<InfrastructureValue> values;
73 73
74
74 /***** CONSTRUCTORS *****/ 75 /***** CONSTRUCTORS *****/
75 76
76 public Infrastructure() { 77 public Infrastructure() {
77 } 78 }
79
78 80
79 public Infrastructure(final River river, final String filename, final String kmrange_info, final String notes, final AnnotationType type, 81 public Infrastructure(final River river, final String filename, final String kmrange_info, final String notes, final AnnotationType type,
80 final AnnotationType group, final Integer year, final String dataprovider, final String evaluation_by) { 82 final AnnotationType group, final Integer year, final String dataprovider, final String evaluation_by) {
81 this.river = river; 83 this.river = river;
82 this.filename = filename; 84 this.filename = filename;
88 this.dataprovider = dataprovider; 90 this.dataprovider = dataprovider;
89 this.evaluation_by = evaluation_by; 91 this.evaluation_by = evaluation_by;
90 this.values = new ArrayList<>(); 92 this.values = new ArrayList<>();
91 } 93 }
92 94
95
93 /***** METHODS *****/ 96 /***** METHODS *****/
94 97
95 @Id 98 @Id
96 @SequenceGenerator(name = "SEQUENCE_INFRASTRUCTURE_ID_SEQ", sequenceName = "INFRASTRUCTURE_ID_SEQ", allocationSize = 1) 99 @SequenceGenerator(name = "SEQUENCE_INFRASTRUCTURE_ID_SEQ", sequenceName = "INFRASTRUCTURE_ID_SEQ", allocationSize = 1)
97 @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "SEQUENCE_INFRASTRUCTURE_ID_SEQ") 100 @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "SEQUENCE_INFRASTRUCTURE_ID_SEQ")
228 231
229 /** 232 /**
230 * Fetches from the database the infrastructure groups and types of a river's km range and river side(s) 233 * Fetches from the database the infrastructure groups and types of a river's km range and river side(s)
231 * as tab-separated strings ordered by the infrastructure group, then the type 234 * as tab-separated strings ordered by the infrastructure group, then the type
232 */ 235 */
233 @Deprecated 236 public static Set<String> fetchInfrastructureTypes(final River river, final double kmLo, final double kmHi,
234 public static Set<String> fetchInfrastructureTypes(final River river, final double kmLo, final double kmHi, final AttributeKey riverside) { 237 final AttributeKey riverside) {
235 final Set<String> groupTypes = new HashSet<>(); 238 final Set<String> groupTypes = new HashSet<>();
236 for (final Infrastructure ifs : fetchInfrastructureTypeList(river, kmLo, kmHi, riverside)) 239 for (final Infrastructure ifs : fetchInfrastructureTypeList(river, kmLo, kmHi, riverside))
237 groupTypes.add(ifs.getGroup().getName() + "\t" + ifs.getType().getName()); 240 groupTypes.add(ifs.getGroup().getName() + "\t" + ifs.getType().getName());
238 return groupTypes; 241 return groupTypes;
239 } 242 }
240 243
241 /** 244 /**
242 * Fetches from the database the list of infrastructure types of a river's km range and river side(s) 245 * Fetches from the database the list of infrastructure types of a river's km range and river side(s)
243 * ordered by type group 246 * ordered by type group
244 */ 247 */
245 private static List<Infrastructure> fetchInfrastructureTypeList(final River river, final double kmLo, final double kmHi, final AttributeKey riverside) { 248 private static List<Infrastructure> fetchInfrastructureTypeList(final River river, final double kmLo, final double kmHi,
249 final AttributeKey riverside) {
246 250
247 final Session session = SessionHolder.HOLDER.get(); 251 final Session session = SessionHolder.HOLDER.get();
248 252
249 final Query query = session.createQuery("FROM Infrastructure" + " WHERE (river=:river)" 253 final Query query = session.createQuery("FROM Infrastructure"
250 + " AND (id IN (SELECT v.infrastructure.id FROM InfrastructureValue v" + " WHERE (v.station BETWEEN (:kmLo - 0.0001) AND (:kmHi + 0.0001))" 254 + " WHERE (river=:river)"
251 + InfrastructureValue.getRiversideClause(riverside, "v.", "attr_id") + "))" + " ORDER BY group, type"); 255 + " AND (id IN (SELECT v.infrastructure.id FROM InfrastructureValue v"
256 + " WHERE (v.station BETWEEN (:kmLo - 0.0001) AND (:kmHi + 0.0001))"
257 + InfrastructureValue.getRiversideClause(riverside, "v.", "attr_id")
258 + "))"
259 + " ORDER BY group, type");
252 query.setParameter("river", river); 260 query.setParameter("river", river);
253 query.setParameter("kmLo", new Double(kmLo)); 261 query.setParameter("kmLo", new Double(kmLo));
254 query.setParameter("kmHi", new Double(kmHi)); 262 query.setParameter("kmHi", new Double(kmHi));
255 if (!InfrastructureValue.getRiversideClause(riverside, "v", "attr_id").isEmpty()) 263 if (!InfrastructureValue.getRiversideClause(riverside, "v", "attr_id").isEmpty())
256 query.setParameter("attr_id", riverside.getId()); 264 query.setParameter("attr_id", riverside.getId());

http://dive4elements.wald.intevation.org