ingo@2581: package de.intevation.flys.artifacts;
ingo@2581: 
ingo@2581: import java.util.List;
ingo@2581: 
ingo@2581: import org.w3c.dom.Document;
ingo@2581: 
ingo@2581: import org.apache.log4j.Logger;
ingo@2581: 
ingo@2581: import com.vividsolutions.jts.geom.Envelope;
ingo@2581: 
ingo@2581: import de.intevation.artifacts.ArtifactFactory;
ingo@2581: import de.intevation.artifacts.CallMeta;
ingo@2581: 
ingo@2581: import de.intevation.artifactdatabase.state.DefaultOutput;
ingo@2581: import de.intevation.artifactdatabase.state.Facet;
ingo@2581: import de.intevation.artifactdatabase.state.State;
ingo@2581: 
ingo@2581: import de.intevation.flys.model.River;
ingo@2581: import de.intevation.flys.model.Floodmaps;
ingo@2581: 
ingo@2581: import de.intevation.flys.artifacts.model.FacetTypes;
ingo@2581: import de.intevation.flys.artifacts.model.RiverFactory;
ingo@2581: import de.intevation.flys.utils.FLYSUtils;
ingo@2581: 
ingo@2581: 
ingo@2581: public class WMSFloodmapsArtifact extends WMSDBArtifact {
ingo@2581: 
ingo@2581:     public static final String NAME = "floodmaps";
ingo@2581: 
ingo@2581: 
ingo@2581:     private static final Logger logger =
ingo@2581:         Logger.getLogger(WMSFloodmapsArtifact.class);
ingo@2581: 
ingo@2581: 
ingo@2581:     @Override
ingo@2581:     public void setup(
ingo@2581:         String          identifier,
ingo@2581:         ArtifactFactory factory,
ingo@2581:         Object          context,
ingo@2581:         CallMeta        callMeta,
ingo@2581:         Document        data)
ingo@2581:     {
ingo@2581:         logger.debug("WMSFloodmapsArtifact.setup");
ingo@2581: 
ingo@2581:         super.setup(identifier, factory, context, callMeta, data);
ingo@2581:     }
ingo@2581: 
ingo@2581: 
ingo@2581:     @Override
ingo@2581:     public String getName() {
ingo@2581:         return NAME;
ingo@2581:     }
ingo@2581: 
ingo@2581: 
ingo@2581:     @Override
ingo@2581:     public State getCurrentState(Object cc) {
ingo@2581:         State s = new FloodmapsState(this);
ingo@2581: 
ingo@2581:         List<Facet> fs = facets.get(getCurrentStateId());
ingo@2581: 
ingo@2581:         DefaultOutput o = new DefaultOutput(
ingo@2581:             "floodmap",
ingo@2581:             "floodmap",
ingo@2581:             "image/png",
ingo@2581:             fs,
ingo@2581:             "map");
ingo@2581: 
ingo@2581:         s.getOutputs().add(o);
ingo@2581: 
ingo@2581:         return s;
ingo@2581:     }
ingo@2581: 
ingo@2581: 
ingo@2581:     public static class FloodmapsState extends WMSDBState implements FacetTypes
ingo@2581:     {
ingo@2581:         private static final Logger logger =
ingo@2581:             Logger.getLogger(FloodmapsState.class);
ingo@2581: 
ingo@2581:         protected int    riverId;
ingo@2581: 
ingo@2581:         public FloodmapsState(WMSDBArtifact artifact) {
ingo@2581:             super(artifact);
ingo@2581:             riverId      = 0;
ingo@2581:         }
ingo@2581: 
ingo@2581:         @Override
ingo@2581:         protected String getFacetType() {
ingo@2581:             return FLOODMAP_FLOODMAPS;
ingo@2581:         }
ingo@2581: 
ingo@2581:         @Override
ingo@2581:         protected String getUrl() {
ingo@2581:             return FLYSUtils.getUserWMSUrl(artifact.identifier());
ingo@2581:         }
ingo@2581: 
ingo@2581:         @Override
ingo@2581:         protected String getSrid() {
ingo@2581:             River river = RiverFactory.getRiver(getRiverId());
ingo@2581:             return FLYSUtils.getRiverSrid(river.getName());
ingo@2581:         }
ingo@2581: 
ingo@2581:         @Override
ingo@2581:         protected Envelope getExtent() {
ingo@2581:             List<Floodmaps> floodmaps =
ingo@2683:                 Floodmaps.getFloodmaps(getRiverId(), getName());
ingo@2581: 
ingo@2581:             Envelope max = null;
ingo@2581: 
ingo@2581:             for (Floodmaps f: floodmaps) {
ingo@2581:                 Envelope env = f.getGeom().getEnvelopeInternal();
ingo@2581: 
ingo@2581:                 if (max == null) {
ingo@2581:                     max = env;
ingo@2581:                     continue;
ingo@2581:                 }
ingo@2581: 
ingo@2581:                 max.expandToInclude(env);
ingo@2581:             }
ingo@2581: 
ingo@2581:             return max;
ingo@2581:         }
ingo@2581: 
ingo@2581:         @Override
ingo@2581:         protected String getFilter() {
ingo@2581:             return "river_id=" + String.valueOf(getRiverId())
ingo@2683:                 + " AND name='" + getName() + "'";
ingo@2581:         }
ingo@2581: 
ingo@2581:         @Override
ingo@2581:         protected String getDataString() {
ingo@2581:             String srid = getSrid();
ingo@2581: 
ingo@2581:             if (FLYSUtils.isUsingOracle()) {
ingo@2581:                 return "geom FROM floodmaps USING SRID " + srid;
ingo@2581:             }
ingo@2581:             else {
ingo@2581:                 return "geom FROM floodmaps USING UNIQUE id USING SRID " + srid;
ingo@2581:             }
ingo@2581:         }
ingo@2581: 
ingo@2581:         @Override
ingo@2581:         protected String getGeometryType() {
ingo@2595:             return "POLYGON";
ingo@2581:         }
ingo@2581:     } // end of WMSKmState
ingo@2581: }
ingo@2581: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :