Mercurial > dive4elements > river
diff 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 |
line wrap: on
line diff
--- 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 :