# HG changeset patch # User Felix Wolfsteller # Date 1344594347 0 # Node ID 374c2d70b98264aa2dc7caee59ae1e2bd82c5773 # Parent b8b1280606c24208c40a5fadbc71337e3d671ed7 Added stub of QSector-Artifact-infrastructure. flys-artifacts/trunk@5188 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r b8b1280606c2 -r 374c2d70b982 flys-artifacts/ChangeLog --- a/flys-artifacts/ChangeLog Thu Aug 09 08:04:06 2012 +0000 +++ b/flys-artifacts/ChangeLog Fri Aug 10 10:25:47 2012 +0000 @@ -1,3 +1,20 @@ +2012-08-10 Felix Wolfsteller + + * doc/conf/artifacts/qsector.xml: + Trivial state model for qsector artifact. + + * src/main/java/de/intevation/flys/artifacts/model/QSectorFacet.java: + Rather trivial facet to get QSectors from QSectorArtifact. + + * src/main/java/de/intevation/flys/artifacts/QSectorArtifact.java: + New QSectorArtifact. + +2012-08-09 Felix Wolfsteller + + * src/main/java/de/intevation/flys/artifacts/services/FixingsKMChartService.java, + src/main/java/de/intevation/flys/artifacts/datacage/templating/Builder.java: + Cosmetics. + 2012-08-09 Sascha L. Teichmann * src/main/java/de/intevation/flys/artifacts/model/sq/Fitting.java, diff -r b8b1280606c2 -r 374c2d70b982 flys-artifacts/doc/conf/artifacts/qsector.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-artifacts/doc/conf/artifacts/qsector.xml Fri Aug 10 10:25:47 2012 +0000 @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + diff -r b8b1280606c2 -r 374c2d70b982 flys-artifacts/src/main/java/de/intevation/flys/artifacts/QSectorArtifact.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/QSectorArtifact.java Fri Aug 10 10:25:47 2012 +0000 @@ -0,0 +1,131 @@ +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.artifactdatabase.state.Facet; + +import de.intevation.artifacts.Artifact; +import de.intevation.artifacts.ArtifactFactory; +import de.intevation.artifacts.CallMeta; + +import de.intevation.flys.artifacts.model.FacetTypes; +import de.intevation.flys.artifacts.model.GaugeFinder; +import de.intevation.flys.artifacts.model.GaugeFinderFactory; +import de.intevation.flys.artifacts.model.GaugeRange; +import de.intevation.flys.artifacts.model.NamedDouble; + +import de.intevation.flys.artifacts.services.FixingsKMChartService; + +import de.intevation.flys.artifacts.states.DefaultState; + + + +/** + * Artifact to produce sector markers. + */ +public class QSectorArtifact +extends StaticFLYSArtifact +implements FacetTypes +{ + /** The logger for this class. */ + private static Logger logger = Logger.getLogger(QSectorArtifact.class); + + /** The name of the artifact. */ + public static final String ARTIFACT_NAME = "qsector"; + + + /** + * Trivial Constructor. + */ + public QSectorArtifact() { + logger.debug("QSectorArtifact.QSectorArtifact()"); + } + + + /** + * Gets called from factory, to set things up. + */ + @Override + public void setup( + String identifier, + ArtifactFactory factory, + Object context, + CallMeta callMeta, + Document data) + { + logger.debug("QSectorArtifact.setup"); + super.setup(identifier, factory, context, callMeta, data); + initialize(null, context, callMeta); + } + + + /** Return the name of this artifact. */ + public String getName() { + return ARTIFACT_NAME; + } + + + /** Get list of NamedDouble s (QSectors). */ + public Object getQSectors(double km) { + + String river = getDataAsString("river"); + List qsectors = new ArrayList(); + + GaugeFinderFactory ggf = GaugeFinderFactory.getInstance(); + GaugeFinder gf = ggf.getGaugeFinder(river); + + if (gf == null) { + logger.warn("No gauge finder found for river '" + river + "'"); + return null; + } + + GaugeRange gr = gf.find(km); + if (gr == null) { + logger.debug("No gauge range found for km " + + km + " on river " + river + "."); + return null; + } + + if (logger.isDebugEnabled()) { + logger.debug(gr); + } + + for (int i = 0; i < FixingsKMChartService.I18N_Q_SECTOR_BOARDERS.length; ++i) { + String key = FixingsKMChartService.I18N_Q_SECTOR_BOARDERS[i]; + String def = FixingsKMChartService.DEFAULT_Q_SECTOR_BORDERS[i]; + String label = "label";//Resources.getMsg(meta, key, def); + + qsectors.add(new NamedDouble(label, gr.getSectorBorder(i))); + } + + return qsectors; + } + + + /** Setup state and facet. */ + @Override + protected void initialize(Artifact artifact, Object context, CallMeta meta) { + logger.debug("QSectorArtifact.initialize"); + List fs = new ArrayList(); + + FLYSArtifact flys = (FLYSArtifact) artifact; + importData(flys, "river"); + + DefaultState state = (DefaultState) getCurrentState(context); + state.computeInit(this, hash(), context, meta, fs); + if (!fs.isEmpty()) { + logger.debug("Facets to add in QSectorArtifact.initialize ."); + facets.put(getCurrentStateId(), fs); + } + else { + logger.debug("No facets to add in QSectorArtifact.initialize (" + + state.getID() + ")."); + } + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : diff -r b8b1280606c2 -r 374c2d70b982 flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/QSectorFacet.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/QSectorFacet.java Fri Aug 10 10:25:47 2012 +0000 @@ -0,0 +1,66 @@ +package de.intevation.flys.artifacts.model; + +import org.apache.log4j.Logger; + +import de.intevation.artifacts.Artifact; +import de.intevation.artifacts.CallContext; + +import de.intevation.flys.artifacts.QSectorArtifact; + +import de.intevation.artifactdatabase.state.DefaultFacet; +import de.intevation.artifactdatabase.state.Facet; + + +/** + * Facet to access QSector that where added by user. + */ +public class QSectorFacet +extends DefaultFacet +{ + /** Logger for this class. */ + private static final Logger logger = Logger.getLogger(QSectorFacet.class); + + + /** + * Trivial Constructor. + */ + public QSectorFacet() { + } + + + /** + * Trivial Constructor for a QSectorFacet. + * + * @param index Database-Index to use. + * @param name Name (~type) of Facet. + * @param description Description of Facet. + */ + public QSectorFacet(int index, String name, String description) { + super(index, name, description); + } + + + /** + * Get List of QSector for river from Artifact. + * + * @param artifact (QSector-)Artifact to query for list of QSector. + * @param context Ignored. + */ + @Override + public Object getData(Artifact artifact, CallContext context) { + QSectorArtifact qsectorArtifact = (QSectorArtifact) artifact; + double currentKm = + ((Double)context.getContextValue("currentKm")).doubleValue(); + return qsectorArtifact.getQSectors(currentKm); + } + + + /** Do a deep copy. */ + @Override + public Facet deepCopy() { + QSectorFacet copy = new QSectorFacet(); + copy.set(this); + return copy; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :