Mercurial > dive4elements > river
comparison artifacts/src/main/java/org/dive4elements/river/artifacts/states/sq/SQStaticState.java @ 7236:a9bd4a23a852
(issue1474) Add datacage loading for SQ Relations
author | Andre Heinecke <aheinecke@intevation.de> |
---|---|
date | Wed, 02 Oct 2013 17:04:23 +0200 |
parents | af13ceeba52a |
children | a56fe3bc6700 |
comparison
equal
deleted
inserted
replaced
7235:03201eaf594f | 7236:a9bd4a23a852 |
---|---|
8 | 8 |
9 package org.dive4elements.river.artifacts.states.sq; | 9 package org.dive4elements.river.artifacts.states.sq; |
10 | 10 |
11 import java.text.DateFormat; | 11 import java.text.DateFormat; |
12 import java.util.List; | 12 import java.util.List; |
13 | 13 import java.text.SimpleDateFormat; |
14 | 14 |
15 import org.apache.log4j.Logger; | 15 import org.apache.log4j.Logger; |
16 | 16 |
17 import org.dive4elements.artifactdatabase.state.Facet; | 17 import org.dive4elements.artifactdatabase.state.Facet; |
18 import org.dive4elements.artifacts.CallMeta; | |
18 import org.dive4elements.river.artifacts.D4EArtifact; | 19 import org.dive4elements.river.artifacts.D4EArtifact; |
19 import org.dive4elements.river.artifacts.access.StaticSQRelationAccess; | 20 import org.dive4elements.river.artifacts.access.StaticSQRelationAccess; |
20 import org.dive4elements.river.artifacts.model.sq.StaticSQContainer; | 21 import org.dive4elements.river.artifacts.model.sq.StaticSQContainer; |
21 import org.dive4elements.river.artifacts.model.sq.StaticSQFactory; | 22 import org.dive4elements.river.artifacts.model.sq.StaticSQFactory; |
22 import org.dive4elements.river.artifacts.model.sq.StaticSQRelation; | 23 import org.dive4elements.river.artifacts.model.sq.StaticSQRelation; |
23 import org.dive4elements.river.artifacts.states.StaticState; | 24 import org.dive4elements.river.artifacts.states.StaticState; |
24 | 25 |
26 import org.dive4elements.river.artifacts.resources.Resources; | |
25 | 27 |
26 public class SQStaticState | 28 public class SQStaticState |
27 extends StaticState | 29 extends StaticState |
28 { | 30 { |
31 | |
29 private static final Logger log = | 32 private static final Logger log = |
30 Logger.getLogger(SQStaticState.class); | 33 Logger.getLogger(SQStaticState.class); |
34 | |
35 private static final String FACET_DESCRIPTION = | |
36 "facet.sq_relation.static_data"; | |
31 | 37 |
32 public SQStaticState() { | 38 public SQStaticState() { |
33 super(); | 39 super(); |
34 } | 40 } |
35 | 41 |
36 public SQStaticState(String name) { | 42 public SQStaticState(String name) { |
37 super(name); | 43 super(name); |
38 } | 44 } |
39 | 45 |
40 @Override | 46 @Override |
41 public Object staticCompute( | 47 public Object computeInit( |
42 List<Facet> facets, | 48 D4EArtifact artifact, |
43 D4EArtifact artifact | 49 String hash, |
50 Object context, | |
51 CallMeta meta, | |
52 List<Facet> facets | |
44 ) { | 53 ) { |
45 StaticSQRelationAccess access = new StaticSQRelationAccess(artifact); | 54 StaticSQContainer sqRelations; |
46 | 55 |
47 String river = access.getRiver(); | 56 String id_string = artifact.getDataAsString("ids"); |
48 String measurementStation = access.getMeasurementStation(); | |
49 | 57 |
50 int ms = -1; | 58 int static_id = -1; |
51 try { | 59 String static_desc = null; |
52 ms = Integer.parseInt(measurementStation); | 60 |
53 } | 61 if (id_string != null && !id_string.isEmpty()) { |
54 catch (NumberFormatException nfe) { | 62 String[] id_parts = id_string.split(";"); |
55 log.error("Unparseable measurement station: " + measurementStation); | 63 static_id = Integer.parseInt(id_parts[0]); |
56 return null; | 64 if (id_parts.length > 1) { |
65 static_desc = id_parts[1]; | |
66 } | |
57 } | 67 } |
58 | 68 |
59 StaticSQContainer sqRelations = | 69 if (static_id != -1) { |
60 StaticSQFactory.getSQRelations(river, ms); | 70 // If the next line fails a traceback is the best debug output anyhow |
71 sqRelations = StaticSQFactory.getDistinctRelation(static_id); | |
72 log.debug("Got a distinct relation" + sqRelations); | |
73 } else { | |
74 StaticSQRelationAccess access = new StaticSQRelationAccess(artifact); | |
75 String river = access.getRiver(); | |
76 String measurementStation = access.getMeasurementStation(); | |
77 | |
78 int ms = -1; | |
79 try { | |
80 ms = Integer.parseInt(measurementStation); | |
81 } | |
82 catch (NumberFormatException nfe) { | |
83 log.error("Unparseable measurement station: " + measurementStation); | |
84 return null; | |
85 } | |
86 log.debug("Parsed measurement station: " + ms); | |
87 | |
88 sqRelations = StaticSQFactory.getSQRelations(river, ms); | |
89 } | |
90 | |
91 DateFormat df = new SimpleDateFormat("yyyy"); | |
61 | 92 |
62 for (StaticSQRelation.Parameter p: StaticSQRelation.Parameter.values()) { | 93 for (StaticSQRelation.Parameter p: StaticSQRelation.Parameter.values()) { |
63 | 94 |
64 List<StaticSQRelation> relations = | 95 List<StaticSQRelation> relations = |
65 sqRelations.getRelationsByParameter(p); | 96 sqRelations.getRelationsByParameter(p); |
67 if (!relations.isEmpty()) { | 98 if (!relations.isEmpty()) { |
68 int count = 0; | 99 int count = 0; |
69 | 100 |
70 for (StaticSQRelation relation : relations) { | 101 for (StaticSQRelation relation : relations) { |
71 String name = "sq_" + p.toString().toLowerCase() + "_curve"; | 102 String name = "sq_" + p.toString().toLowerCase() + "_curve"; |
72 DateFormat df = | 103 String desc = static_desc == null ? |
73 DateFormat.getDateInstance(DateFormat.SHORT); | 104 Resources.getMsg(meta, |
74 String desc = p.toString() + ": " + | 105 FACET_DESCRIPTION, |
75 df.format(relation.getStartTime()) + " - " + | 106 FACET_DESCRIPTION, |
76 df.format(relation.getStopTime()); | 107 new Object[] { |
108 df.format(relation.getStartTime()), | |
109 df.format(relation.getStopTime())}) : | |
110 static_desc; | |
77 facets.add(new StaticSQRelationFacet( | 111 facets.add(new StaticSQRelationFacet( |
78 count, | 112 count, |
79 name, | 113 name, |
80 desc, | 114 desc, |
81 relation)); | 115 relation)); |