annotate artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/collision/CollisionArtifact.java @ 9125:820ae41c81b6

Fixed adding missing files for the river bed collision counts selectable in the datacage
author mschaefer
date Wed, 06 Jun 2018 08:02:55 +0200
parents
children f9bb5d0a6ff3
rev   line source
9125
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
1 /** Copyright (C) 2017 by Bundesanstalt für Gewässerkunde
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
2 * Software engineering by
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
3 * Björnsen Beratende Ingenieure GmbH
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
4 * Dr. Schumacher Ingenieurbüro für Wasser und Umwelt
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
5 *
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
6 * This file is Free Software under the GNU AGPL (>=v3)
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
7 * and comes with ABSOLUTELY NO WARRANTY! Check out the
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
8 * documentation coming with Dive4Elements River for details.
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
9 */
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
10
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
11 package org.dive4elements.river.artifacts.sinfo.collision;
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
12
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
13 import java.util.ArrayList;
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
14 import java.util.List;
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
15
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
16 import org.apache.log4j.Logger;
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
17 import org.dive4elements.artifactdatabase.state.DefaultOutput;
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
18 import org.dive4elements.artifactdatabase.state.Facet;
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
19 import org.dive4elements.artifactdatabase.state.FacetActivity;
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
20 import org.dive4elements.artifacts.Artifact;
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
21 import org.dive4elements.artifacts.ArtifactFactory;
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
22 import org.dive4elements.artifacts.CallMeta;
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
23 import org.dive4elements.artifacts.common.utils.XMLUtils;
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
24 import org.dive4elements.river.artifacts.AbstractStaticStateArtifact;
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
25 import org.dive4elements.river.artifacts.D4EArtifact;
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
26 import org.dive4elements.river.artifacts.model.FacetTypes;
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
27 import org.dive4elements.river.artifacts.sinfo.common.CollisionCountProcessor;
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
28 import org.dive4elements.river.artifacts.states.StaticState;
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
29 import org.w3c.dom.Document;
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
30
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
31 /**
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
32 * Display of a river bed collision data series loaded from database
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
33 *
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
34 * @author Matthias Schäfer
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
35 *
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
36 */
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
37 public class CollisionArtifact extends AbstractStaticStateArtifact implements FacetTypes {
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
38
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
39 /** The log for this class. */
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
40 private static Logger log = Logger.getLogger(CollisionArtifact.class);
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
41
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
42 /** Artifact name. */
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
43 private static final String NAME = "collision";
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
44
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
45 static {
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
46 // TODO: Move to configuration.
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
47 FacetActivity.Registry.getInstance().register(NAME, FacetActivity.INACTIVE);
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
48 }
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
49
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
50 public static final String STATIC_STATE_NAME = "state.collision.static";
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
51
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
52 /**
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
53 * Trivial Constructor.
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
54 */
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
55 public CollisionArtifact() {
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
56 log.debug("new CollisionArtifact");
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
57 }
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
58
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
59 @Override
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
60 public String getName() {
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
61 return NAME;
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
62 }
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
63
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
64 /**
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
65 * Gets called from factory, to set things up.
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
66 */
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
67 @Override
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
68 public void setup(final String identifier, final ArtifactFactory factory, final Object context, final CallMeta callMeta, final Document data,
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
69 final List<Class> loadFacets) {
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
70
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
71 log.debug("CollisionArtifact.setup");
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
72
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
73 if (log.isDebugEnabled()) {
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
74 log.debug(XMLUtils.toString(data));
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
75 }
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
76
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
77 final String code = getDatacageIDValue(data);
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
78 final String[] parts = code.split("-");
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
79 if (parts.length >= 2)
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
80 addStringData("collision_id", parts[1]);
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
81 if (parts.length >= 3)
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
82 addStringData("year", parts[2]);
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
83 else
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
84 addStringData("year", "jahr?");
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
85 String seriesName;
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
86 if (parts.length >= 4)
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
87 seriesName = parts[3];
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
88 else
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
89 seriesName = "name?";
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
90
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
91 createFacets(callMeta, code, seriesName, getDataAsString("year"));
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
92
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
93 super.setup(identifier, factory, context, callMeta, data, loadFacets);
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
94 }
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
95
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
96 private void createFacets(final CallMeta callMeta, final String code, final String seriesName, final String year) {
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
97 if (code == null)
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
98 return;
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
99 final String[] parts = code.split("-");
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
100 if (parts.length < 2) {
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
101 log.error("Invalid datacage ID '" + code + "'");
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
102 return;
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
103 }
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
104 final ArrayList<Facet> facets = new ArrayList<>(2);
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
105 facets.add(CollisionCountProcessor.createFacet(callMeta, year));
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
106 // facets.add(CollisionGaugeWProcessor.createFacet(callMeta, seriesName)); //REMARK gauge_w is the cm above gauge datum,
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
107 // therefore only useful with transformation to NHN
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
108 addFacets(STATIC_STATE_NAME, facets);
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
109 }
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
110
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
111 @Override
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
112 protected void initStaticState() {
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
113
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
114 log.debug("initStaticState " + getName() + " " + identifier());
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
115
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
116 final StaticState state = new StaticState(STATIC_STATE_NAME);
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
117 final DefaultOutput output = new DefaultOutput("general", "general", "image/png", "chart");
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
118
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
119 final List<Facet> facets = getFacets(STATIC_STATE_NAME);
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
120 output.addFacets(facets);
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
121 state.addOutput(output);
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
122
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
123 setStaticState(state);
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
124 }
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
125
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
126 @Override
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
127 protected void initialize(final Artifact artifact, final Object context, final CallMeta meta) {
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
128 // do not clone facets, etc. from master artifact
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
129
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
130 log.debug("initialize");
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
131 importData((D4EArtifact) artifact, "river");
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
132 importData((D4EArtifact) artifact, "ld_from");
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
133 importData((D4EArtifact) artifact, "ld_to");
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
134
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
135 log.debug("ld_from " + getDataAsString("ld_from"));
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
136 log.debug("ld_to " + getDataAsString("ld_to"));
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
137 }
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
138 }

http://dive4elements.wald.intevation.org