annotate artifacts/src/main/java/org/dive4elements/river/artifacts/bundu/bezugswst/LoadSingleYearSelectState.java @ 9256:6c24c857ccf9

fixation refactoring and inputItem behaviour to interfaces
author gernotbelger
date Fri, 13 Jul 2018 12:04:21 +0200
parents
children
rev   line source
9256
6c24c857ccf9 fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
diff changeset
1 /* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde
6c24c857ccf9 fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
diff changeset
2 * Software engineering by Intevation GmbH
6c24c857ccf9 fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
diff changeset
3 *
6c24c857ccf9 fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
diff changeset
4 * This file is Free Software under the GNU AGPL (>=v3)
6c24c857ccf9 fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
diff changeset
5 * and comes with ABSOLUTELY NO WARRANTY! Check out the
6c24c857ccf9 fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
diff changeset
6 * documentation coming with Dive4Elements River for details.
6c24c857ccf9 fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
diff changeset
7 */
6c24c857ccf9 fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
diff changeset
8
6c24c857ccf9 fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
diff changeset
9 package org.dive4elements.river.artifacts.bundu.bezugswst;
6c24c857ccf9 fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
diff changeset
10
6c24c857ccf9 fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
diff changeset
11 import java.util.HashMap;
6c24c857ccf9 fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
diff changeset
12 import java.util.List;
6c24c857ccf9 fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
diff changeset
13 import java.util.Map;
6c24c857ccf9 fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
diff changeset
14
6c24c857ccf9 fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
diff changeset
15 import org.apache.log4j.Logger;
6c24c857ccf9 fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
diff changeset
16 import org.dive4elements.artifacts.Artifact;
6c24c857ccf9 fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
diff changeset
17 import org.dive4elements.artifacts.CallContext;
6c24c857ccf9 fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
diff changeset
18 import org.dive4elements.artifacts.common.utils.XMLUtils.ElementCreator;
6c24c857ccf9 fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
diff changeset
19 import org.dive4elements.river.artifacts.D4EArtifact;
6c24c857ccf9 fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
diff changeset
20 import org.dive4elements.river.artifacts.access.RiverAccess;
6c24c857ccf9 fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
diff changeset
21 import org.dive4elements.river.artifacts.model.CollisionHibernateFactory;
6c24c857ccf9 fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
diff changeset
22 import org.dive4elements.river.artifacts.states.AddTableDataHelper;
6c24c857ccf9 fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
diff changeset
23 import org.dive4elements.river.artifacts.states.DefaultState;
6c24c857ccf9 fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
diff changeset
24 import org.dive4elements.river.model.sinfo.Collision;
6c24c857ccf9 fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
diff changeset
25 import org.w3c.dom.Element;
6c24c857ccf9 fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
diff changeset
26
6c24c857ccf9 fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
diff changeset
27 /** State in which to fetch years for sedminent load calculation. */
6c24c857ccf9 fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
diff changeset
28 public class LoadSingleYearSelectState extends DefaultState {
6c24c857ccf9 fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
diff changeset
29 private static final long serialVersionUID = 1L;
6c24c857ccf9 fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
diff changeset
30 /** The log used in this class. */
6c24c857ccf9 fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
diff changeset
31 private static Logger log = Logger.getLogger(LoadSingleYearSelectState.class);
6c24c857ccf9 fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
diff changeset
32
6c24c857ccf9 fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
diff changeset
33 /**
6c24c857ccf9 fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
diff changeset
34 * The default constructor that initializes an empty State object.
6c24c857ccf9 fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
diff changeset
35 */
6c24c857ccf9 fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
diff changeset
36 public LoadSingleYearSelectState() {
6c24c857ccf9 fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
diff changeset
37 }
6c24c857ccf9 fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
diff changeset
38
6c24c857ccf9 fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
diff changeset
39 /** Year Select Widget. */
6c24c857ccf9 fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
diff changeset
40 @Override
6c24c857ccf9 fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
diff changeset
41 protected String getUIProvider() {
6c24c857ccf9 fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
diff changeset
42 return "common.state.load_single_year_select.show_hint";
6c24c857ccf9 fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
diff changeset
43 }
6c24c857ccf9 fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
diff changeset
44
6c24c857ccf9 fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
diff changeset
45 @Override
6c24c857ccf9 fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
diff changeset
46 protected void appendItems(final Artifact artifact, final ElementCreator creator, final String name, final CallContext context, final Element select) {
6c24c857ccf9 fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
diff changeset
47 final String dataKey = "singleyear";
6c24c857ccf9 fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
diff changeset
48 try {
6c24c857ccf9 fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
diff changeset
49 if (dataKey.equals(name)) {
6c24c857ccf9 fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
diff changeset
50
6c24c857ccf9 fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
diff changeset
51 final AddTableDataHelper helper = new AddTableDataHelper(creator, select, "year", context.getMeta()); // pinKeycolum; nicht zu verweschseln mit
6c24c857ccf9 fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
diff changeset
52 // datakey..artifact.
6c24c857ccf9 fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
diff changeset
53
6c24c857ccf9 fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
diff changeset
54 helper.addColumn(0, "pinfrom", "60", "common.client.ui.selection", "ICON", "CENTER", "from");
6c24c857ccf9 fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
diff changeset
55 helper.addColumn(1, "year", "60", "year", "INTEGER", "LEFT", null);
6c24c857ccf9 fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
diff changeset
56
6c24c857ccf9 fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
diff changeset
57 final RiverAccess access = new RiverAccess((D4EArtifact) artifact);
6c24c857ccf9 fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
diff changeset
58 final List<Collision> collisions = CollisionHibernateFactory.getCollisionsByRiver(access.getRiver());// TODO: DATASOURCE?! Has to be
6c24c857ccf9 fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
diff changeset
59 // uinfo.inundation_duration
6c24c857ccf9 fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
diff changeset
60 // (Überflutungsdauern Aue) irgendwas...
6c24c857ccf9 fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
diff changeset
61
6c24c857ccf9 fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
diff changeset
62 for (final Collision coll : collisions) {
6c24c857ccf9 fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
diff changeset
63 final Integer year = coll.getYear();
6c24c857ccf9 fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
diff changeset
64 final Map<String, String> row = new HashMap<>();
6c24c857ccf9 fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
diff changeset
65 row.put("year", year.toString()); // Nullpointer-Check?
6c24c857ccf9 fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
diff changeset
66 helper.addRow(row);
6c24c857ccf9 fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
diff changeset
67
6c24c857ccf9 fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
diff changeset
68 }
6c24c857ccf9 fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
diff changeset
69 helper.submitMapToXml();
6c24c857ccf9 fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
diff changeset
70 }
6c24c857ccf9 fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
diff changeset
71 }
6c24c857ccf9 fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
diff changeset
72 catch (final IllegalArgumentException iae) {
6c24c857ccf9 fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
diff changeset
73 iae.printStackTrace();
6c24c857ccf9 fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
diff changeset
74 }
6c24c857ccf9 fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
diff changeset
75 }
6c24c857ccf9 fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
diff changeset
76
6c24c857ccf9 fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
diff changeset
77 @Override
6c24c857ccf9 fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
diff changeset
78 public boolean validate(final Artifact artifact) throws IllegalArgumentException {
6c24c857ccf9 fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
diff changeset
79 return true;
6c24c857ccf9 fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
diff changeset
80 // final CollisionLoadYearEpochAccess access = new CollisionLoadYearEpochAccess((D4EArtifact) artifact);
6c24c857ccf9 fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
diff changeset
81 //
6c24c857ccf9 fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
diff changeset
82 // // Second year should be later than first.
6c24c857ccf9 fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
diff changeset
83 // if (access.getYears() == null || access.getYears().length == 0)
6c24c857ccf9 fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
diff changeset
84 // return true; // TODO: richtig in CollisionLoadYear... implementieren
6c24c857ccf9 fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
diff changeset
85 // // throw new IllegalArgumentException("error_years_wrong");
6c24c857ccf9 fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
diff changeset
86 //
6c24c857ccf9 fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
diff changeset
87 // return true;
6c24c857ccf9 fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
diff changeset
88 }
6c24c857ccf9 fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
diff changeset
89 }

http://dive4elements.wald.intevation.org