comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/services/FixingsKMChartService.java @ 2615:b0597a63fe70

More code for the fixings km chart service. flys-artifacts/trunk@4199 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Wed, 04 Apr 2012 18:30:44 +0000
parents 036e234c2385
children cc0fa1798a3c
comparison
equal deleted inserted replaced
2614:036e234c2385 2615:b0597a63fe70
1 package de.intevation.flys.artifacts.services; 1 package de.intevation.flys.artifacts.services;
2
3 import java.util.List;
2 4
3 import de.intevation.artifactdatabase.DefaultService; 5 import de.intevation.artifactdatabase.DefaultService;
4 6
5 import de.intevation.artifacts.CallMeta; 7 import de.intevation.artifacts.CallMeta;
6 import de.intevation.artifacts.GlobalContext; 8 import de.intevation.artifacts.GlobalContext;
7 import de.intevation.artifacts.Service; 9 import de.intevation.artifacts.Service;
8 10
11 import de.intevation.flys.artifacts.model.FixingsFilterBuilder;
12 import de.intevation.flys.artifacts.model.FixingsOverview;
13 import de.intevation.flys.artifacts.model.FixingsColumn;
14 import de.intevation.flys.artifacts.model.FixingsColumnFactory;
15 import de.intevation.flys.artifacts.model.FixingsOverviewFactory;
16
17 import de.intevation.flys.artifacts.model.FixingsOverview.Fixing;
18
19 import de.intevation.flys.backend.SessionHolder;
20
9 import org.apache.log4j.Logger; 21 import org.apache.log4j.Logger;
10 22
11 import org.w3c.dom.Document; 23 import org.w3c.dom.Document;
24 import org.w3c.dom.Element;
25 import org.w3c.dom.NodeList;
12 26
13 public class FixingsKMChartService 27 public class FixingsKMChartService
14 extends DefaultService 28 extends DefaultService
15 { 29 {
16 private static final Logger log = 30 private static final Logger log =
17 Logger.getLogger(FixingsKMChartService.class); 31 Logger.getLogger(FixingsKMChartService.class);
18 32
19 public static final byte [] DATA0 = { 33 public static final byte [] EMPTY = {
20 (byte)0x89, (byte)0x50, (byte)0x4e, (byte)0x47, 34 (byte)0x89, (byte)0x50, (byte)0x4e, (byte)0x47,
21 (byte)0x0d, (byte)0x0a, (byte)0x1a, (byte)0x0a, 35 (byte)0x0d, (byte)0x0a, (byte)0x1a, (byte)0x0a,
22 (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x0d, 36 (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x0d,
23 (byte)0x49, (byte)0x48, (byte)0x44, (byte)0x52, 37 (byte)0x49, (byte)0x48, (byte)0x44, (byte)0x52,
24 (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x1d, 38 (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x01,
25 (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x1d, 39 (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x01,
26 (byte)0x04, (byte)0x03, (byte)0x00, (byte)0x00, 40 (byte)0x08, (byte)0x00, (byte)0x00, (byte)0x00,
27 (byte)0x00, (byte)0xa4, (byte)0xbd, (byte)0x7a, 41 (byte)0x00, (byte)0x3a, (byte)0x7e, (byte)0x9b,
28 (byte)0x3c, (byte)0x00, (byte)0x00, (byte)0x00, 42 (byte)0x55, (byte)0x00, (byte)0x00, (byte)0x00,
29 (byte)0x01, (byte)0x73, (byte)0x52, (byte)0x47, 43 (byte)0x01, (byte)0x73, (byte)0x52, (byte)0x47,
30 (byte)0x42, (byte)0x00, (byte)0xae, (byte)0xce, 44 (byte)0x42, (byte)0x00, (byte)0xae, (byte)0xce,
31 (byte)0x1c, (byte)0xe9, (byte)0x00, (byte)0x00, 45 (byte)0x1c, (byte)0xe9, (byte)0x00, (byte)0x00,
32 (byte)0x00, (byte)0x18, (byte)0x50, (byte)0x4c,
33 (byte)0x54, (byte)0x45, (byte)0xff, (byte)0xff,
34 (byte)0xff, (byte)0x08, (byte)0x08, (byte)0x08,
35 (byte)0x29, (byte)0x29, (byte)0x29, (byte)0x52,
36 (byte)0x52, (byte)0x52, (byte)0x8c, (byte)0x8c,
37 (byte)0x8c, (byte)0xbd, (byte)0xbd, (byte)0xbd,
38 (byte)0xe7, (byte)0xe7, (byte)0xe7, (byte)0x00,
39 (byte)0x00, (byte)0x00, (byte)0xcf, (byte)0x3a,
40 (byte)0xd7, (byte)0x12, (byte)0x00, (byte)0x00,
41 (byte)0x00, (byte)0x09, (byte)0x70, (byte)0x48, 46 (byte)0x00, (byte)0x09, (byte)0x70, (byte)0x48,
42 (byte)0x59, (byte)0x73, (byte)0x00, (byte)0x00, 47 (byte)0x59, (byte)0x73, (byte)0x00, (byte)0x00,
43 (byte)0x0b, (byte)0x13, (byte)0x00, (byte)0x00, 48 (byte)0x0b, (byte)0x13, (byte)0x00, (byte)0x00,
44 (byte)0x0b, (byte)0x13, (byte)0x01, (byte)0x00, 49 (byte)0x0b, (byte)0x13, (byte)0x01, (byte)0x00,
45 (byte)0x9a, (byte)0x9c, (byte)0x18, (byte)0x00, 50 (byte)0x9a, (byte)0x9c, (byte)0x18, (byte)0x00,
46 (byte)0x00, (byte)0x00, (byte)0x07, (byte)0x74, 51 (byte)0x00, (byte)0x00, (byte)0x07, (byte)0x74,
47 (byte)0x49, (byte)0x4d, (byte)0x45, (byte)0x07, 52 (byte)0x49, (byte)0x4d, (byte)0x45, (byte)0x07,
48 (byte)0xdc, (byte)0x04, (byte)0x04, (byte)0x0a, 53 (byte)0xdc, (byte)0x04, (byte)0x04, (byte)0x10,
49 (byte)0x32, (byte)0x0f, (byte)0xa3, (byte)0x92, 54 (byte)0x30, (byte)0x15, (byte)0x7d, (byte)0x77,
50 (byte)0x8b, (byte)0x55, (byte)0x00, (byte)0x00, 55 (byte)0x36, (byte)0x0b, (byte)0x00, (byte)0x00,
51 (byte)0x00, (byte)0x2b, (byte)0x49, (byte)0x44, 56 (byte)0x00, (byte)0x08, (byte)0x74, (byte)0x45,
52 (byte)0x41, (byte)0x54, (byte)0x18, (byte)0xd3, 57 (byte)0x58, (byte)0x74, (byte)0x43, (byte)0x6f,
53 (byte)0x63, (byte)0x60, (byte)0x18, (byte)0x1a, 58 (byte)0x6d, (byte)0x6d, (byte)0x65, (byte)0x6e,
54 (byte)0x20, (byte)0x0c, (byte)0x95, (byte)0x9b, 59 (byte)0x74, (byte)0x00, (byte)0xf6, (byte)0xcc,
55 (byte)0x5c, (byte)0x6e, (byte)0x80, (byte)0xc2, 60 (byte)0x96, (byte)0xbf, (byte)0x00, (byte)0x00,
56 (byte)0x37, (byte)0x2f, (byte)0x2f, (byte)0x41, 61 (byte)0x00, (byte)0x0a, (byte)0x49, (byte)0x44,
57 (byte)0xe1, (byte)0x8b, (byte)0x97, (byte)0x17, 62 (byte)0x41, (byte)0x54, (byte)0x08, (byte)0xd7,
58 (byte)0xa3, (byte)0xf0, (byte)0xd5, (byte)0xd1, 63 (byte)0x63, (byte)0xf8, (byte)0x0f, (byte)0x00,
59 (byte)0xf8, (byte)0x81, (byte)0xe5, (byte)0x6a, 64 (byte)0x01, (byte)0x01, (byte)0x01, (byte)0x00,
60 (byte)0x28, (byte)0x7c, (byte)0x36, (byte)0x97, 65 (byte)0x1b, (byte)0xb6, (byte)0xee, (byte)0x56,
61 (byte)0x04, (byte)0x86, (byte)0x61, (byte)0x01, 66 (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00,
62 (byte)0x00, (byte)0xf0, (byte)0xaa, (byte)0x06, 67 (byte)0x49, (byte)0x45, (byte)0x4e, (byte)0x44,
63 (byte)0x2d, (byte)0x16, (byte)0xcb, (byte)0xb9, 68 (byte)0xae, (byte)0x42, (byte)0x60, (byte)0x82
64 (byte)0x3c, (byte)0x00, (byte)0x00, (byte)0x00, 69 };
65 (byte)0x00, (byte)0x49, (byte)0x45, (byte)0x4e, 70
66 (byte)0x44, (byte)0xae, (byte)0x42, (byte)0x60, 71 private static final Output empty() {
67 (byte)0x82}; 72 return new Output(EMPTY, "image/png");
73 }
68 74
69 @Override 75 @Override
70 public Service.Output process( 76 public Service.Output process(
71 Document data, 77 Document data,
72 GlobalContext globalContext, 78 GlobalContext globalContext,
73 CallMeta callMeta 79 CallMeta callMeta
74 ) { 80 ) {
75 log.debug("FixingsKMChartService.process"); 81 log.debug("FixingsKMChartService.process");
76 return new Output(DATA0, "image/png"); 82
83 SessionHolder.acquire();
84 try {
85 return doProcess(data, globalContext, callMeta);
86 }
87 finally {
88 SessionHolder.HOLDER.get().close();
89 SessionHolder.release();
90 }
91 }
92
93 protected Service.Output doProcess(
94 Document data,
95 GlobalContext globalContext,
96 CallMeta callMeta
97 ) {
98 NodeList rivers = data.getElementsByTagName("river");
99 NodeList kms = data.getElementsByTagName("km");
100
101 if (rivers.getLength() == 0 || kms.getLength() == 0) {
102 log.warn("Missing river and/or km.");
103 return empty();
104 }
105
106 String river = ((Element)rivers.item(0)).getAttribute("name");
107 String kmS = ((Element)kms .item(0)).getAttribute("value");
108
109 if (river.length() == 0 || kmS.length() == 0) {
110 log.warn("River and/or km empty string.");
111 return empty();
112 }
113
114 double km;
115 try {
116 km = Double.parseDouble(kmS);
117 }
118 catch (NumberFormatException nfe) {
119 log.warn("Km '" + kmS + " is not a valid number.");
120 return empty();
121 }
122
123 FixingsOverview overview = FixingsOverviewFactory.getOverview(river);
124
125 if (overview == null) {
126 log.warn("No overview found for river '" + river + "'");
127 return empty();
128 }
129
130 FixingsFilterBuilder ffb = new FixingsFilterBuilder(data);
131
132 List<Fixing.Column> columns = overview.filter(
133 ffb.getRange(),
134 ffb.getFilter());
135
136 for (Fixing.Column column: columns) {
137 FixingsColumn columnData =
138 FixingsColumnFactory.INSTANCE.getColumnData(column);
139 if (columnData == null) {
140 continue;
141 }
142 }
143 // TODO: Implement chart generation!
144
145 return empty();
77 } 146 }
78 } 147 }
79 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : 148 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org