# HG changeset patch # User Ingo Weinzierl # Date 1320408903 0 # Node ID a8910c1c82fb8b0b174ca0b773e61974ef047aa4 # Parent 490ab097f58c98ddc6ce2ef2e75fbde47cee9828 Refactored the RiverAxisArtifact and its State - uses the same base as WMSKmArtifact now. flys-artifacts/trunk@3168 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r 490ab097f58c -r a8910c1c82fb flys-artifacts/ChangeLog --- 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 + + * 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 For a Flys-Collection, add outputt to attributes-part of describe diff -r 490ab097f58c -r a8910c1c82fb flys-artifacts/doc/conf/artifacts/riveraxis.xml --- 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 @@ - - - - - - - - - - - - - - diff -r 490ab097f58c -r a8910c1c82fb flys-artifacts/doc/conf/conf.xml --- 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 @@ - diff -r 490ab097f58c -r a8910c1c82fb flys-artifacts/src/main/java/de/intevation/flys/artifacts/RiverAxisArtifact.java --- 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 fs = new ArrayList(); - - 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 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 : diff -r 490ab097f58c -r a8910c1c82fb flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/RiverAxisState.java --- 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 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 :