# HG changeset patch # User Felix Wolfsteller # Date 1314793385 0 # Node ID 05e4ef0f94895d8d124f7387ed20b9527fd4a7ad # Parent eaf32c767bac373ce9a84a3c327ad43d4c773d46 Improved stub for CrossSections (including Factory and Facet). flys-artifacts/trunk@2623 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r eaf32c767bac -r 05e4ef0f9489 flys-artifacts/ChangeLog --- a/flys-artifacts/ChangeLog Wed Aug 31 12:20:23 2011 +0000 +++ b/flys-artifacts/ChangeLog Wed Aug 31 12:23:05 2011 +0000 @@ -1,3 +1,18 @@ +2011-08-31 Felix Wolfsteller + + More bones to CrossSection sceleton. + + * src/main/java/de/intevation/flys/artifacts/model/CrossSectionFactory.java, + src/main/java/de/intevation/flys/artifacts/model/CrossSectionFacet.java: + New, yet trivial implementations of Factory and Facet for CrossSections. + + * src/main/java/de/intevation/flys/artifacts/states/WaterlevelState.java: + Add new CrossSection- (instead of Default-)Facet. + + * src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java, + src/main/java/de/intevation/flys/exports/CrossSectionGenerator.java: + Adjusted to use (touch) new Factory and Facet. + 2011-08-31 Felix Wolfsteller Cosmetics. diff -r eaf32c767bac -r 05e4ef0f9489 flys-artifacts/src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java --- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java Wed Aug 31 12:20:23 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java Wed Aug 31 12:23:05 2011 +0000 @@ -25,6 +25,7 @@ import de.intevation.flys.artifacts.model.Calculation4; import de.intevation.flys.artifacts.model.Calculation; import de.intevation.flys.artifacts.model.CalculationResult; +import de.intevation.flys.artifacts.model.CrossSectionFactory; import de.intevation.flys.artifacts.model.DischargeTables; import de.intevation.flys.artifacts.model.MainValuesFactory; import de.intevation.flys.artifacts.model.Segment; @@ -37,6 +38,7 @@ import de.intevation.flys.model.Gauge; import de.intevation.flys.model.River; +import de.intevation.flys.model.CrossSection; import de.intevation.flys.utils.DoubleUtil; import de.intevation.flys.utils.FLYSUtils; @@ -597,6 +599,15 @@ return Segment.parseSegments(input); } + public List getCrossSections() { + River river = FLYSUtils.getRiver(this); + if (river == null) { + logger.warn("No river in WINFO found"); + return null; + } + return CrossSectionFactory.getCrossSections(river); + } + /** * Returns the Qs for a number of Ws. This method makes use of diff -r eaf32c767bac -r 05e4ef0f9489 flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/CrossSectionFacet.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/CrossSectionFacet.java Wed Aug 31 12:23:05 2011 +0000 @@ -0,0 +1,51 @@ +package de.intevation.flys.artifacts.model; + +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.flys.artifacts.WINFOArtifact; + +import de.intevation.flys.artifacts.states.DefaultState.ComputeType; + + +/** + * Trival Facet for Cross Sections. + */ +public class CrossSectionFacet +extends DefaultFacet +implements FacetTypes { + + private static Logger logger = Logger.getLogger(CrossSectionFacet.class); + + + /** Trivial constructor, set (maybe localized) description. */ + public CrossSectionFacet(String description) { + super(0, CROSS_SECTION, description); + } + + + /** + * Gets dummy data. + */ + public Object getData(Artifact artifact, CallContext context) { + logger.debug("Get data for cross section"); + + WINFOArtifact winfo = (WINFOArtifact)artifact; + + return winfo.getCrossSections(); + } + + @Override + public Facet deepCopy() { + CrossSectionFacet copy = new CrossSectionFacet(this.description); + copy.set(this); + return copy; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : + diff -r eaf32c767bac -r 05e4ef0f9489 flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/CrossSectionFactory.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/CrossSectionFactory.java Wed Aug 31 12:23:05 2011 +0000 @@ -0,0 +1,49 @@ +package de.intevation.flys.artifacts.model; + +import java.math.BigDecimal; + +import java.util.List; +import java.util.Iterator; + +import de.intevation.flys.backend.SessionHolder; +import de.intevation.flys.model.CrossSection; +import de.intevation.flys.model.Range; +import de.intevation.flys.model.River; + +import org.hibernate.Session; +import org.hibernate.Query; + +/** + * Get Cross Sections. + */ +public class CrossSectionFactory { + + /** + * Get CrossSections for an instantiated River. + * + * @param river river object. + * + * @return List of Cross Sections of river. + */ + public static List getCrossSections(River river) { + return getCrossSections(river.getName()); + } + + + /** + * Get Cross Sections for a river by name. + * + * @param river name of the river of interest. + * + * @return List of Cross Sections of river. + */ + public static List getCrossSections(String riverName) { + Session session = SessionHolder.HOLDER.get(); + Query query = session.createQuery( + "from CrossSection where river.name = :rivername"); + query.setParameter("rivername", riverName); + return query.list(); + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 : + diff -r eaf32c767bac -r 05e4ef0f9489 flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/WaterlevelState.java --- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/WaterlevelState.java Wed Aug 31 12:20:23 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/WaterlevelState.java Wed Aug 31 12:23:05 2011 +0000 @@ -16,6 +16,7 @@ import de.intevation.flys.artifacts.model.WQKms; import de.intevation.flys.artifacts.model.DataFacet; +import de.intevation.flys.artifacts.model.CrossSectionFacet; import de.intevation.flys.artifacts.model.CalculationResult; import de.intevation.artifactdatabase.state.DefaultFacet; @@ -95,7 +96,8 @@ facets.add(new ReportFacet(ComputeType.ADVANCE, hash, id)); } - facets.add(new DefaultFacet(0, "cross_section", "facet.cross_section")); + // Also register the CrossSectionFacet (added to respective out). + facets.add(new CrossSectionFacet("facet.cross_section")); return res; } } diff -r eaf32c767bac -r 05e4ef0f9489 flys-artifacts/src/main/java/de/intevation/flys/exports/CrossSectionGenerator.java --- a/flys-artifacts/src/main/java/de/intevation/flys/exports/CrossSectionGenerator.java Wed Aug 31 12:20:23 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/CrossSectionGenerator.java Wed Aug 31 12:23:05 2011 +0000 @@ -8,6 +8,7 @@ import org.jfree.chart.plot.XYPlot; import org.jfree.chart.title.TextTitle; import org.jfree.data.Range; +import org.jfree.data.xy.XYSeries; import org.w3c.dom.Document; @@ -147,6 +148,9 @@ } + /** + * Let one facet do its job. + */ public void doOut(Artifact artifact, Facet facet, Document attr) { String name = facet.getName(); @@ -175,17 +179,18 @@ /** - * Register annotations available for the diagram. + * Do cross sections out. * - * @param o list of annotations (data of facet). - * @param theme yet ignored. + * @param theme Theme for the data series. */ protected void doCrossSectionOut(Object o, Document theme) { - logger.debug("LongitudinalSectionGenerator.doCrossSectionOut"); + logger.debug("CrossSectionGenerator.doCrossSectionOut"); - /*Object[] args = new Object[] {getRiverName()}; - String label = msg(I18N_ANNOTATIONS_LABEL, "", args); - pseudoAnnotationData.addSeries(new StyledXYSeries(label, theme));*/ + XYSeries series = new StyledXYSeries("bogus", theme); + // Add increadibly sophisticated values. + series.add(4, 4); + series.add(5, 14); + addFirstAxisSeries(series); }