Mercurial > dive4elements > river
changeset 2001:28a5c163f9cd
Added partial area-infrastructure.
flys-artifacts/trunk@3442 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Felix Wolfsteller <felix.wolfsteller@intevation.de> |
---|---|
date | Fri, 16 Dec 2011 14:02:59 +0000 |
parents | e71719483546 |
children | 98f3ef8da857 |
files | flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/artifacts/AreaArtifact.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/AreaFacet.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/AreaCreationState.java |
diffstat | 4 files changed, 338 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog Fri Dec 16 13:37:58 2011 +0000 +++ b/flys-artifacts/ChangeLog Fri Dec 16 14:02:59 2011 +0000 @@ -1,3 +1,12 @@ +2011-12-16 Felix Wolfsteller <felix.wolfsteller@intevation.de> + + Added partial area-infrastructure. + + * src/main/java/de/intevation/flys/artifacts/model/AreaFacet.java, + src/main/java/de/intevation/flys/artifacts/AreaArtifact.java, + src/main/java/de/intevation/flys/artifacts/states/AreaCreationState.java: + New artifact, facet and state for area rendering. + 2011-12-16 Ingo Weinzierl <ingo@intevation.de> * src/main/java/de/intevation/flys/exports/XYChartGenerator.java: Defined an
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/AreaArtifact.java Fri Dec 16 14:02:59 2011 +0000 @@ -0,0 +1,150 @@ +package de.intevation.flys.artifacts; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.log4j.Logger; + +import org.w3c.dom.Document; + +import de.intevation.artifacts.Artifact; +import de.intevation.artifacts.ArtifactFactory; +import de.intevation.artifacts.CallMeta; + +import de.intevation.flys.artifacts.model.AreaFacet; + +import de.intevation.artifacts.common.ArtifactNamespaceContext; +import de.intevation.artifacts.common.utils.XMLUtils; + +import de.intevation.flys.artifacts.states.AreaCreationState; +import de.intevation.flys.artifacts.states.StaticState; + +import de.intevation.artifactdatabase.state.Facet; +import de.intevation.artifactdatabase.state.State; + +import de.intevation.flys.utils.FLYSUtils; + +/** + * Artifact describing the area between two WKms. + */ +public class AreaArtifact extends StaticFLYSArtifact { + + /** Access ids of doc. */ + public static final String XPATH_IDS = "/art:action/art:ids/@value"; + + /** Name of Artifact. */ + public static final String AREA_ARTIFACT_NAME = "area_artifact"; + + /** Name of state. */ + public static final String STATIC_STATE_NAME = "state.area_artifact"; + + /** data item name to access upper curve. */ + public static final String AREA_CURVE_OVER = "area.curve_over"; + + /** data item name to access lower curve. */ + public static final String AREA_CURVE_UNDER = "area.curve_under"; + + /** Own logger. */ + private static final Logger logger = + Logger.getLogger(AreaArtifact.class); + + + /** Return given name. */ + @Override + public String getName() { + return AREA_ARTIFACT_NAME; + } + + + /** Store ids, create an AreaFacet. */ + @Override + public void setup( + String identifier, + ArtifactFactory factory, + Object context, + CallMeta callMeta, + Document data) + { + logger.info("AreaArtifact.setup"); + + super.setup(identifier, factory, context, callMeta, data); + + // TODO ye unused. + String ids = XMLUtils.xpathString( + data, XPATH_IDS, ArtifactNamespaceContext.INSTANCE); + + List<Facet> fs = new ArrayList<Facet>(); + fs.add(new AreaFacet(0, "TODO: I am an AreaFacet")); + + AreaCreationState state = (AreaCreationState) getCurrentState(context); + + if (!fs.isEmpty()) { + facets.put(getCurrentStateId(), fs); + } + } + + // TODO Data is not cached in this way. + + /** Do not copy data from daddyfact. */ + @Override + protected void initialize( + Artifact artifact, + Object context, + CallMeta callMeta) + { + // do nothing + } + + + /** + * Get dataprovider key for the 'lower' curve (we got that information fed + * from the client and store it as data). + */ + public String getLowerDPKey() { + return getDataAsString(AREA_CURVE_UNDER); + } + + + /** + * Get dataprovider key for the 'upper' curve (we got that information fed + * from the client and store it as data). + */ + public String getUpperDPKey() { + return getDataAsString(AREA_CURVE_OVER); + } + + + /** + * Create and return a new AreaCreationState with charting output. + */ + @Override + public State getCurrentState(Object cc) { + final List<Facet> fs = facets.get(getCurrentStateId()); + + AreaCreationState state = new AreaCreationState(); + + StaticState.addDefaultChartOutput(state, "cross_section", fs); + + return state; + } + + + /** + * Get a list containing the one and only State. + * @param context ignored. + * @return list with one and only state. + */ + @Override + protected List<State> getStates(Object context) { + ArrayList<State> states = new ArrayList<State>(); + states.add(getCurrentState(context)); + + return states; + } + + /** Trivia. */ + protected State getState(Object context, String stateID) { + return getCurrentState(null); + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/AreaFacet.java Fri Dec 16 14:02:59 2011 +0000 @@ -0,0 +1,90 @@ +package de.intevation.flys.artifacts.model; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.log4j.Logger; + +import de.intevation.artifacts.Artifact; +import de.intevation.artifacts.CallContext; + +import de.intevation.artifactdatabase.state.DefaultFacet; +import de.intevation.artifactdatabase.state.Facet; + +import de.intevation.artifacts.DataProvider; + +import de.intevation.flys.artifacts.AreaArtifact; + +import de.intevation.flys.artifacts.states.DefaultState.ComputeType; +import de.intevation.flys.artifacts.states.DefaultState.ComputeType; + + +/** + * Trival Facet for areas. + */ +public class AreaFacet +extends DefaultFacet +implements FacetTypes { + + private static Logger logger = Logger.getLogger(AreaFacet.class); + + /** Trivial constructor, set (maybe localized) description. */ + public AreaFacet(int idx, String description) { + super(idx, AREA, description); + } + + + /** + * Gets Cross Section (profile). + * @param art artifact to get data from. + * @param context ignored + */ + public Object getData(Artifact art, CallContext context) { + logger.debug("Get data for area ding"); + + // Get information from artifact about which + // info to grab from blackboard. + // + // All compatible facets should provide their data + // under the key (Artifact-UUID + Facet-Index). + AreaArtifact artifact = (AreaArtifact) art; + Object lowerData = null; + Object upperData = null; + + List<DataProvider> providers = context. + getDataProvider(artifact.getLowerDPKey()); + if (providers.size() < 1) { + logger.warn("No 'lower' given for area"); + } + else { + lowerData = providers.get(0).provideData( + artifact.getLowerDPKey(), null, context); + } + + providers = context.getDataProvider(artifact.getUpperDPKey()); + if (providers.size() < 1) { + logger.warn("No 'upper' given for area"); + } + else { + upperData = providers.get(0).provideData( + artifact.getUpperDPKey(), null, context); + } + + if (upperData == null && lowerData == null) { + logger.warn("No 'upper' given for area"); + return null; + } + + return new Object[] {lowerData, upperData}; + } + + + /** Do a deep copy. */ + @Override + public Facet deepCopy() { + AreaFacet copy = new AreaFacet(this.index, this.description); + copy.set(this); + return copy; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/AreaCreationState.java Fri Dec 16 14:02:59 2011 +0000 @@ -0,0 +1,89 @@ +package de.intevation.flys.artifacts.states; + +import java.util.List; + +import org.apache.log4j.Logger; + +import de.intevation.artifacts.CallContext; + +import de.intevation.flys.artifacts.model.AreaFacet; + +import de.intevation.artifactdatabase.state.Facet; + +import de.intevation.flys.artifacts.FLYSArtifact; +import de.intevation.flys.artifacts.WINFOArtifact; +import de.intevation.flys.artifacts.model.DataFacet; +import de.intevation.flys.artifacts.model.CrossSectionWaterLineFacet; +import de.intevation.flys.artifacts.model.CalculationResult; +import de.intevation.flys.artifacts.model.FacetTypes; +import de.intevation.flys.artifacts.model.ReportFacet; +import de.intevation.flys.artifacts.model.WaterlevelFacet; +import de.intevation.flys.artifacts.model.WQKms; +import de.intevation.flys.utils.FLYSUtils; + + +public class AreaCreationState +extends DefaultState +implements FacetTypes +{ + /** The logger that is used in this state. */ + private static Logger logger = Logger.getLogger(AreaCreationState.class); + + + /** + * From this state can only be continued trivially. + */ + @Override + protected String getUIProvider() { + return "continue"; + } + + + protected Object compute( + FLYSArtifact winfo, + CallContext cc, + String hash, + List<Facet> facets, + Object old + ) { + logger.debug("AreaCreationState.compute"); + if (facets != null) { + // TODO title + facets.add(new AreaFacet(0, "TODo now i am a different facet")); + } + + // TODO use compute to exploit caching strategies. + + return null; + } + + + /** + */ + @Override + public Object computeFeed( + FLYSArtifact artifact, + String hash, + CallContext context, + List<Facet> facets, + Object old + ) { + return compute((FLYSArtifact) artifact, context, hash, facets, old); + } + + + /** + * + */ + @Override + public Object computeAdvance( + FLYSArtifact artifact, + String hash, + CallContext context, + List<Facet> facets, + Object old + ) { + return compute((FLYSArtifact) artifact, context, hash, facets, old); + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :