Mercurial > dive4elements > river
changeset 9168:d2472018740c
Fixed dateformat with 4-digit year, added query method for collision years of a river
author | mschaefer |
---|---|
date | Thu, 21 Jun 2018 08:13:37 +0200 |
parents | cb3a91dc4e3b |
children | 1f94b3673ed3 |
files | artifacts/src/main/java/org/dive4elements/river/artifacts/common/AbstractResultType.java artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/collision/LoadMultipleYearSelectState.java backend/src/main/java/org/dive4elements/river/model/sinfo/Collision.java |
diffstat | 3 files changed, 26 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- 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); }
--- 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(); }
--- 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