[PATCH] Fixed dateformat with 4-digit year, added query method for collision years of a river

Wald Commits scm-commit at wald.intevation.org
Thu Jun 21 08:14:02 CEST 2018


# HG changeset patch
# User mschaefer
# Date 1529561617 -7200
# Node ID d2472018740c04c486efdf0f4096027963714fcf
# Parent  cb3a91dc4e3b8bdddb31a99643bb17f3b16a2f95
Fixed dateformat with 4-digit year, added query method for collision years of a river

diff -r cb3a91dc4e3b -r d2472018740c artifacts/src/main/java/org/dive4elements/river/artifacts/common/AbstractResultType.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/common/AbstractResultType.java	Wed Jun 20 18:25:58 2018 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/common/AbstractResultType.java	Thu Jun 21 08:13:37 2018 +0200
@@ -88,7 +88,7 @@
 
     protected final String exportDateValue(final CallContext context, final Date value) {
         final Locale locale = Resources.getLocale(context.getMeta());
-        final DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT, locale);
+        final DateFormat df = DateFormat.getDateInstance(DateFormat.MEDIUM, locale);
         return df.format(value);
     }
 
diff -r cb3a91dc4e3b -r d2472018740c artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/collision/LoadMultipleYearSelectState.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/collision/LoadMultipleYearSelectState.java	Wed Jun 20 18:25:58 2018 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/collision/LoadMultipleYearSelectState.java	Thu Jun 21 08:13:37 2018 +0200
@@ -9,14 +9,12 @@
 package org.dive4elements.river.artifacts.sinfo.collision;
 
 import java.util.HashMap;
-import java.util.List;
 import java.util.Map;
 
 import org.apache.log4j.Logger;
 import org.dive4elements.artifacts.Artifact;
 import org.dive4elements.artifacts.CallContext;
 import org.dive4elements.artifacts.common.utils.XMLUtils.ElementCreator;
-import org.dive4elements.river.artifacts.model.CollisionHibernateFactory;
 import org.dive4elements.river.artifacts.sinfo.SINFOArtifact;
 import org.dive4elements.river.artifacts.states.AddTableDataHelper;
 import org.dive4elements.river.artifacts.states.DefaultState;
@@ -55,13 +53,13 @@
 
                 final CollisionAccess access = new CollisionAccess((SINFOArtifact) artifact); // Der River wurde im vorigen State bereits gesetzt
 
-                final List<Collision> collisions = CollisionHibernateFactory.getCollisionsByRiver(access.getRiver());
-                for (final Collision coll : collisions) {
-                    final Integer year = coll.getYear();
+                // final List<Collision> collisions = CollisionHibernateFactory.getCollisionsByRiver(access.getRiver());
+                // for (final Collision coll : collisions) {
+                for (final Integer year : Collision.getYearsOfRiver(access.getRiver())) {
+                    // final Integer year = coll.getYear();
                     final Map<String, String> row = new HashMap<>();
                     row.put("year", year.toString()); // Nullpointer?
                     helper.addRow(row);
-
                 }
                 helper.submitMapToXml();
             }
diff -r cb3a91dc4e3b -r d2472018740c backend/src/main/java/org/dive4elements/river/model/sinfo/Collision.java
--- a/backend/src/main/java/org/dive4elements/river/model/sinfo/Collision.java	Wed Jun 20 18:25:58 2018 +0200
+++ b/backend/src/main/java/org/dive4elements/river/model/sinfo/Collision.java	Thu Jun 21 08:13:37 2018 +0200
@@ -158,4 +158,25 @@
         query.setParameter("id", id);
         return (Collision) query.list().get(0);
     }
+
+    /**
+     * Selects from the database the years of the collisions of a river
+     */
+    public static List<Integer> getYearsOfRiver(final River river) {
+        final Session session = SessionHolder.HOLDER.get();
+        final Query query = session.createQuery("SELECT c.year, COUNT(cv) AS count"
+                + " FROM Collision c INNER JOIN c.values cv"
+                + " WHERE c.river=:river"
+                + " GROUP BY c.year"
+                + " ORDER BY c.year");
+        query.setParameter("river", river);
+        final List<Integer> years = new ArrayList<>();
+        final List<Object[]> rows = query.list();
+        if (rows != null) {
+            for (int i = 0; i <= rows.size() - 1; i++) {
+                years.add(Integer.valueOf((int) rows.get(i)[0]));
+            }
+        }
+        return years;
+    }
 }
\ No newline at end of file


More information about the Dive4Elements-commits mailing list