Mercurial > dive4elements > river
changeset 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 (2012-04-04) |
parents | 036e234c2385 |
children | 27cc95e65f18 |
files | flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/FixingsColumn.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/FixingsColumnFactory.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/services/FixingsKMChartService.java |
diffstat | 4 files changed, 160 insertions(+), 40 deletions(-) [+] |
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog Wed Apr 04 14:41:27 2012 +0000 +++ b/flys-artifacts/ChangeLog Wed Apr 04 18:30:44 2012 +0000 @@ -1,3 +1,16 @@ +2012-04-04 Sascha L. Teichmann <sascha.teichmann@intevation.de> + + * src/main/java/de/intevation/flys/artifacts/services/FixingsKMChartService.java: + Extract parameters from input xml and fetch fixings filters and overview + to find the columns to be viewed. + TODO: Generate chart. + + * src/main/java/de/intevation/flys/artifacts/model/FixingsColumn.java: Added + boolean result to indicate if value comes from table or is interpolated. + + * src/main/java/de/intevation/flys/artifacts/model/FixingsColumnFactory.java: + New. Factory to fetch fixings column data from cache or database. Stub by now. + 2012-04-04 Sascha L. Teichmann <sascha.teichmann@intevation.de> * src/main/java/de/intevation/flys/artifacts/services/FixingsKMChartService.java:
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/FixingsColumn.java Wed Apr 04 14:41:27 2012 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/FixingsColumn.java Wed Apr 04 18:30:44 2012 +0000 @@ -33,19 +33,24 @@ return columnId; } - public double getW(double km) { + public boolean getW(double km, double [] w) { if (km < kms[0] || km > kms[kms.length-1]) { - return Double.NaN; + w[0] = Double.NaN; + return true; } int idx = Arrays.binarySearch(kms, km); - if (idx >= 0) return ws[idx]; + if (idx >= 0) { + w[0] = ws[idx]; + return true; + } idx = -idx - 1; - return Linear.linear(km, kms[idx], kms[idx+1], ws[idx], ws[idx+1]); + w[0] = Linear.linear(km, kms[idx], kms[idx+1], ws[idx], ws[idx+1]); + return false; } public double getQ(double km) {
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/FixingsColumnFactory.java Wed Apr 04 18:30:44 2012 +0000 @@ -0,0 +1,33 @@ +package de.intevation.flys.artifacts.model; + +import de.intevation.flys.artifacts.model.FixingsOverview.Fixing; + +public class FixingsColumnFactory +{ + public static final String CACHE_NAME = "fixing-columns"; + + public static final String SQL_COLUMN_W = + "SELECT wcv.position AS km, wcv.w AS w " + + "FROM wst_column_values wcv " + + "WHERE wst_column_id = :column_id " + + "ORDER by wcv.position"; + + public static final String SQL_COLUMN_Q = + "SELECT wqr.q AS q, r.a AS a, r.b AS b " + + "FROM wst_column_q_ranges wcqr " + + "JOIN wst_q_ranges wqr ON wcqr.wst_q_range_id = wqr.id " + + "JOIN ranges r ON wqr.range_id = r.id " + + "WHERE wcqr.wst_column_id = :column_id ORDER by r.a"; + + public static final FixingsColumnFactory INSTANCE = + new FixingsColumnFactory(); + + private FixingsColumnFactory() { + } + + public FixingsColumn getColumnData(Fixing.Column column) { + // TODO: Implement me! + return null; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/services/FixingsKMChartService.java Wed Apr 04 14:41:27 2012 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/services/FixingsKMChartService.java Wed Apr 04 18:30:44 2012 +0000 @@ -1,14 +1,28 @@ package de.intevation.flys.artifacts.services; +import java.util.List; + import de.intevation.artifactdatabase.DefaultService; import de.intevation.artifacts.CallMeta; import de.intevation.artifacts.GlobalContext; import de.intevation.artifacts.Service; +import de.intevation.flys.artifacts.model.FixingsFilterBuilder; +import de.intevation.flys.artifacts.model.FixingsOverview; +import de.intevation.flys.artifacts.model.FixingsColumn; +import de.intevation.flys.artifacts.model.FixingsColumnFactory; +import de.intevation.flys.artifacts.model.FixingsOverviewFactory; + +import de.intevation.flys.artifacts.model.FixingsOverview.Fixing; + +import de.intevation.flys.backend.SessionHolder; + import org.apache.log4j.Logger; import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.NodeList; public class FixingsKMChartService extends DefaultService @@ -16,28 +30,19 @@ private static final Logger log = Logger.getLogger(FixingsKMChartService.class); - public static final byte [] DATA0 = { + public static final byte [] EMPTY = { (byte)0x89, (byte)0x50, (byte)0x4e, (byte)0x47, (byte)0x0d, (byte)0x0a, (byte)0x1a, (byte)0x0a, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x0d, (byte)0x49, (byte)0x48, (byte)0x44, (byte)0x52, - (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x1d, - (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x1d, - (byte)0x04, (byte)0x03, (byte)0x00, (byte)0x00, - (byte)0x00, (byte)0xa4, (byte)0xbd, (byte)0x7a, - (byte)0x3c, (byte)0x00, (byte)0x00, (byte)0x00, + (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x01, + (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x01, + (byte)0x08, (byte)0x00, (byte)0x00, (byte)0x00, + (byte)0x00, (byte)0x3a, (byte)0x7e, (byte)0x9b, + (byte)0x55, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x01, (byte)0x73, (byte)0x52, (byte)0x47, (byte)0x42, (byte)0x00, (byte)0xae, (byte)0xce, (byte)0x1c, (byte)0xe9, (byte)0x00, (byte)0x00, - (byte)0x00, (byte)0x18, (byte)0x50, (byte)0x4c, - (byte)0x54, (byte)0x45, (byte)0xff, (byte)0xff, - (byte)0xff, (byte)0x08, (byte)0x08, (byte)0x08, - (byte)0x29, (byte)0x29, (byte)0x29, (byte)0x52, - (byte)0x52, (byte)0x52, (byte)0x8c, (byte)0x8c, - (byte)0x8c, (byte)0xbd, (byte)0xbd, (byte)0xbd, - (byte)0xe7, (byte)0xe7, (byte)0xe7, (byte)0x00, - (byte)0x00, (byte)0x00, (byte)0xcf, (byte)0x3a, - (byte)0xd7, (byte)0x12, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x09, (byte)0x70, (byte)0x48, (byte)0x59, (byte)0x73, (byte)0x00, (byte)0x00, (byte)0x0b, (byte)0x13, (byte)0x00, (byte)0x00, @@ -45,26 +50,27 @@ (byte)0x9a, (byte)0x9c, (byte)0x18, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x07, (byte)0x74, (byte)0x49, (byte)0x4d, (byte)0x45, (byte)0x07, - (byte)0xdc, (byte)0x04, (byte)0x04, (byte)0x0a, - (byte)0x32, (byte)0x0f, (byte)0xa3, (byte)0x92, - (byte)0x8b, (byte)0x55, (byte)0x00, (byte)0x00, - (byte)0x00, (byte)0x2b, (byte)0x49, (byte)0x44, - (byte)0x41, (byte)0x54, (byte)0x18, (byte)0xd3, - (byte)0x63, (byte)0x60, (byte)0x18, (byte)0x1a, - (byte)0x20, (byte)0x0c, (byte)0x95, (byte)0x9b, - (byte)0x5c, (byte)0x6e, (byte)0x80, (byte)0xc2, - (byte)0x37, (byte)0x2f, (byte)0x2f, (byte)0x41, - (byte)0xe1, (byte)0x8b, (byte)0x97, (byte)0x17, - (byte)0xa3, (byte)0xf0, (byte)0xd5, (byte)0xd1, - (byte)0xf8, (byte)0x81, (byte)0xe5, (byte)0x6a, - (byte)0x28, (byte)0x7c, (byte)0x36, (byte)0x97, - (byte)0x04, (byte)0x86, (byte)0x61, (byte)0x01, - (byte)0x00, (byte)0xf0, (byte)0xaa, (byte)0x06, - (byte)0x2d, (byte)0x16, (byte)0xcb, (byte)0xb9, - (byte)0x3c, (byte)0x00, (byte)0x00, (byte)0x00, - (byte)0x00, (byte)0x49, (byte)0x45, (byte)0x4e, - (byte)0x44, (byte)0xae, (byte)0x42, (byte)0x60, - (byte)0x82}; + (byte)0xdc, (byte)0x04, (byte)0x04, (byte)0x10, + (byte)0x30, (byte)0x15, (byte)0x7d, (byte)0x77, + (byte)0x36, (byte)0x0b, (byte)0x00, (byte)0x00, + (byte)0x00, (byte)0x08, (byte)0x74, (byte)0x45, + (byte)0x58, (byte)0x74, (byte)0x43, (byte)0x6f, + (byte)0x6d, (byte)0x6d, (byte)0x65, (byte)0x6e, + (byte)0x74, (byte)0x00, (byte)0xf6, (byte)0xcc, + (byte)0x96, (byte)0xbf, (byte)0x00, (byte)0x00, + (byte)0x00, (byte)0x0a, (byte)0x49, (byte)0x44, + (byte)0x41, (byte)0x54, (byte)0x08, (byte)0xd7, + (byte)0x63, (byte)0xf8, (byte)0x0f, (byte)0x00, + (byte)0x01, (byte)0x01, (byte)0x01, (byte)0x00, + (byte)0x1b, (byte)0xb6, (byte)0xee, (byte)0x56, + (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, + (byte)0x49, (byte)0x45, (byte)0x4e, (byte)0x44, + (byte)0xae, (byte)0x42, (byte)0x60, (byte)0x82 + }; + + private static final Output empty() { + return new Output(EMPTY, "image/png"); + } @Override public Service.Output process( @@ -73,7 +79,70 @@ CallMeta callMeta ) { log.debug("FixingsKMChartService.process"); - return new Output(DATA0, "image/png"); + + SessionHolder.acquire(); + try { + return doProcess(data, globalContext, callMeta); + } + finally { + SessionHolder.HOLDER.get().close(); + SessionHolder.release(); + } + } + + protected Service.Output doProcess( + Document data, + GlobalContext globalContext, + CallMeta callMeta + ) { + NodeList rivers = data.getElementsByTagName("river"); + NodeList kms = data.getElementsByTagName("km"); + + if (rivers.getLength() == 0 || kms.getLength() == 0) { + log.warn("Missing river and/or km."); + return empty(); + } + + String river = ((Element)rivers.item(0)).getAttribute("name"); + String kmS = ((Element)kms .item(0)).getAttribute("value"); + + if (river.length() == 0 || kmS.length() == 0) { + log.warn("River and/or km empty string."); + return empty(); + } + + double km; + try { + km = Double.parseDouble(kmS); + } + catch (NumberFormatException nfe) { + log.warn("Km '" + kmS + " is not a valid number."); + return empty(); + } + + FixingsOverview overview = FixingsOverviewFactory.getOverview(river); + + if (overview == null) { + log.warn("No overview found for river '" + river + "'"); + return empty(); + } + + FixingsFilterBuilder ffb = new FixingsFilterBuilder(data); + + List<Fixing.Column> columns = overview.filter( + ffb.getRange(), + ffb.getFilter()); + + for (Fixing.Column column: columns) { + FixingsColumn columnData = + FixingsColumnFactory.INSTANCE.getColumnData(column); + if (columnData == null) { + continue; + } + } + // TODO: Implement chart generation! + + return empty(); } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :