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