Mercurial > dive4elements > river
changeset 1832:a8910c1c82fb
Refactored the RiverAxisArtifact and its State - uses the same base as WMSKmArtifact now.
flys-artifacts/trunk@3168 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Fri, 04 Nov 2011 12:15:03 +0000 (2011-11-04) |
parents | 490ab097f58c |
children | d4e80e9b40b5 |
files | flys-artifacts/ChangeLog flys-artifacts/doc/conf/artifacts/riveraxis.xml flys-artifacts/doc/conf/conf.xml flys-artifacts/src/main/java/de/intevation/flys/artifacts/RiverAxisArtifact.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/RiverAxisState.java |
diffstat | 5 files changed, 122 insertions(+), 152 deletions(-) [+] |
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog Fri Nov 04 11:59:08 2011 +0000 +++ b/flys-artifacts/ChangeLog Fri Nov 04 12:15:03 2011 +0000 @@ -1,3 +1,18 @@ +2011-11-04 Ingo Weinzierl <ingo@intevation.de> + + * src/main/java/de/intevation/flys/artifacts/RiverAxisArtifact.java: + Subclasses WMSDBArtifact now and defines an inner class RiverAxisState + which subclasses WMSDBState. + + * src/main/java/de/intevation/flys/artifacts/states/RiverAxisState.java: + Removed. The RiverAxisState is an inner class of RiverAxisArtifact now + which subclasses WMSDBState. + + * doc/conf/artifacts/riveraxis.xml: Removed, because the RiverAxisArtifact + has a fixed static State only. + + * doc/conf/conf.xml: Removed riveraxis.xml definition. + 2011-11-04 Felix Wolfsteller <felix.wolfsteller@intevation.de> For a Flys-Collection, add outputt to attributes-part of describe
--- a/flys-artifacts/doc/conf/artifacts/riveraxis.xml Fri Nov 04 11:59:08 2011 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,16 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<artifact name="riveraxis"> - <states> - <state id="state.riveraxis.layer" - description="state.riveraxis.layer.description" - state="de.intevation.flys.artifacts.states.RiverAxisState"> - <outputmodes> - <outputmode name="floodmap" description="output.uesk.map.description" type="map"> - <facets> - <facet name="floodmap.riveraxis"/> - </facets> - </outputmode> - </outputmodes> - </state> - </states> -</artifact>
--- a/flys-artifacts/doc/conf/conf.xml Fri Nov 04 11:59:08 2011 +0000 +++ b/flys-artifacts/doc/conf/conf.xml Fri Nov 04 12:15:03 2011 +0000 @@ -83,7 +83,6 @@ <artifacts> <artifact name="winfo" xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="${artifacts.config.dir}/artifacts/winfo.xml" /> <artifact name="waterlevel" xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="${artifacts.config.dir}/artifacts/waterlevel.xml" /> - <artifact name="riveraxis" xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="${artifacts.config.dir}/artifacts/riveraxis.xml" /> <artifact name="annotation" xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="${artifacts.config.dir}/artifacts/annotation.xml" /> <artifact name="wmsbackground" xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="${artifacts.config.dir}/artifacts/wmsbackground.xml" /> </artifacts>
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/RiverAxisArtifact.java Fri Nov 04 11:59:08 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/RiverAxisArtifact.java Fri Nov 04 12:15:03 2011 +0000 @@ -1,46 +1,40 @@ package de.intevation.flys.artifacts; -import java.util.ArrayList; import java.util.List; import org.w3c.dom.Document; import org.apache.log4j.Logger; -import de.intevation.artifacts.Artifact; +import com.vividsolutions.jts.geom.Envelope; +import com.vividsolutions.jts.geom.Geometry; + import de.intevation.artifacts.ArtifactFactory; import de.intevation.artifacts.CallMeta; -import de.intevation.artifacts.common.ArtifactNamespaceContext; -import de.intevation.artifacts.common.utils.XMLUtils; - -import de.intevation.artifactdatabase.data.DefaultStateData; +import de.intevation.artifactdatabase.state.DefaultOutput; import de.intevation.artifactdatabase.state.Facet; +import de.intevation.artifactdatabase.state.State; import de.intevation.flys.model.River; +import de.intevation.flys.artifacts.model.FacetTypes; import de.intevation.flys.artifacts.model.RiverFactory; -import de.intevation.flys.artifacts.states.DefaultState; +import de.intevation.flys.artifacts.resources.Resources; +import de.intevation.flys.utils.FLYSUtils; +import de.intevation.flys.utils.GeometryUtils; -public class RiverAxisArtifact extends StaticFLYSArtifact { +public class RiverAxisArtifact extends WMSDBArtifact { public static final String NAME = "riveraxis"; - public static final String XPATH_IDS = "/art:action/art:ids/@value"; - private static final Logger logger = Logger.getLogger(RiverAxisArtifact.class); @Override - public String getName() { - return NAME; - } - - - @Override public void setup( String identifier, ArtifactFactory factory, @@ -51,50 +45,107 @@ logger.debug("RiverAxisArtifact.setup"); super.setup(identifier, factory, context, callMeta, data); - - String ids = XMLUtils.xpathString( - data, XPATH_IDS, ArtifactNamespaceContext.INSTANCE); - - String[] splitted = ids != null ? ids.split(" ") : null; - - if (splitted != null && splitted.length > 0) { - try { - int river_id = Integer.parseInt(splitted[0]); - River river = RiverFactory.getRiver(river_id); - - if (river == null) { - throw new IllegalArgumentException( - "No river found for id: " + river_id); - } - - String name = river.getName(); - - addData("river", new DefaultStateData("river",null,null,name)); - - List<Facet> fs = new ArrayList<Facet>(); - - DefaultState state = (DefaultState) getCurrentState(context); - state.computeInit(this, hash(), context, callMeta, fs); - - if (!fs.isEmpty()) { - facets.put(getCurrentStateId(), fs); - } - } - catch (NumberFormatException nfe) { - logger.error("Could not create Artifact: " + nfe.getMessage()); - throw new IllegalArgumentException("No river id given."); - } - } } @Override - protected void initialize( - Artifact artifact, - Object context, - CallMeta callMeta) + public String getName() { + return NAME; + } + + + @Override + public State getCurrentState(Object cc) { + State s = new RiverAxisState(this); + + List<Facet> fs = facets.get(getCurrentStateId()); + + DefaultOutput o = new DefaultOutput( + "floodmap", + "floodmap", + "image/png", + fs, + "map"); + + s.getOutputs().add(o); + + return s; + } + + + public static class RiverAxisState extends WMSDBState implements FacetTypes { - // do nothing - } + private static final Logger logger = + Logger.getLogger(RiverAxisState.class); + + protected Geometry geom; + protected int riverId; + + public RiverAxisState(WMSDBArtifact artifact) { + super(artifact); + riverId = 0; + } + + public int getRiverId() { + if (riverId == 0) { + String ids = artifact.getDataAsString("ids"); + + try { + riverId = Integer.valueOf(ids); + } + catch (NumberFormatException nfe) { + logger.error("Cannot parse river id from '" + ids + "'"); + } + } + + return riverId; + } + + @Override + protected String getFacetType() { + return FLOODMAP_RIVERAXIS; + } + + @Override + protected String getTitle(CallMeta meta) { + return Resources.getMsg( + meta, + FLOODMAP_RIVERAXIS, + FLOODMAP_RIVERAXIS); + } + + @Override + protected String getUrl() { + return FLYSUtils.getUserWMSUrl(artifact.identifier()); + } + + @Override + protected String getSrid() { + River river = RiverFactory.getRiver(getRiverId()); + return FLYSUtils.getRiverSrid(river.getName()); + } + + @Override + protected Envelope getExtent() { + River river = RiverFactory.getRiver(getRiverId()); + return GeometryUtils.getRiverBoundary(river.getName()); + } + + @Override + protected String getFilter() { + return "river_id=" + String.valueOf(getRiverId()); + } + + @Override + protected String getDataString() { + // TODO SRID + return "geom FROM river_axes USING UNIQUE id USING SRID 31466"; + } + + @Override + protected String getGeometryType() { + return "LINE"; + } + } // end of WMSKmState } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/RiverAxisState.java Fri Nov 04 11:59:08 2011 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,79 +0,0 @@ -package de.intevation.flys.artifacts.states; - -import java.util.List; - -import org.apache.log4j.Logger; - -import de.intevation.artifacts.CallContext; -import de.intevation.artifacts.CallMeta; - -import de.intevation.artifactdatabase.state.Facet; - -import de.intevation.flys.artifacts.FLYSArtifact; -import de.intevation.flys.artifacts.context.FLYSContext; -import de.intevation.flys.artifacts.model.WMSDBLayerFacet; -import de.intevation.flys.artifacts.resources.Resources; -import de.intevation.flys.artifacts.states.DefaultState.ComputeType; -import de.intevation.flys.utils.FLYSUtils; -import de.intevation.flys.utils.GeometryUtils; - - -public class RiverAxisState extends OutputState { - - public static final String I18N_DESCRIPTION = "floodmap.riveraxis"; - - - private static final Logger logger = Logger.getLogger(RiverAxisState.class); - - - @Override - public Object computeInit( - FLYSArtifact artifact, - String hash, - Object context, - CallMeta meta, - List<Facet> facets - ) { - logger.debug("RiverAxisState.computeInit()"); - - FLYSContext flysContext = null; - - if (context instanceof FLYSContext) { - flysContext = (FLYSContext) context; - } - else { - flysContext = (FLYSContext) ((CallContext) context).globalContext(); - } - - String river = artifact.getDataAsString("river"); - - if(river == null || river.length() == 0) { - logger.warn("No river found in the current parameterization."); - return null; - } - - String url = FLYSUtils.getUserWMSUrl(artifact.identifier()); - - WMSDBLayerFacet facet = new WMSDBLayerFacet( - 0, - FLOODMAP_RIVERAXIS, - Resources.getMsg(meta, I18N_DESCRIPTION, I18N_DESCRIPTION), - ComputeType.INIT, - getID(), hash, - url); - - String name = artifact.identifier() + "-" + FLOODMAP_RIVERAXIS; - - facet.addLayer(name); - facet.setExtent(GeometryUtils.getRiverBoundary(river)); - facet.setSrid(FLYSUtils.getRiverSrid(artifact)); - facet.setData("geom FROM river_axes USING UNIQUE id USING SRID 31466"); - facet.setFilter("river_id=1"); - facet.setGeometryType("LINE"); - - facets.add(facet); - - return null; - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :