Mercurial > dive4elements > river
changeset 1822:6ed439ff61bf
Changed theme-mapping mechanism to include further condition (on master-artifacts attributes), added point themes for longitudinal.ws for calculations at locations.
flys-artifacts/trunk@3151 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Felix Wolfsteller <felix.wolfsteller@intevation.de> |
---|---|
date | Thu, 03 Nov 2011 10:25:23 +0000 |
parents | e55f1a851923 |
children | 7a11b37d8594 |
files | flys-artifacts/ChangeLog flys-artifacts/doc/conf/themes.xml flys-artifacts/src/main/java/de/intevation/flys/artifacts/context/FLYSContextFactory.java flys-artifacts/src/main/java/de/intevation/flys/collections/FLYSArtifactCollection.java flys-artifacts/src/main/java/de/intevation/flys/themes/ThemeFactory.java flys-artifacts/src/main/java/de/intevation/flys/themes/ThemeMapping.java |
diffstat | 6 files changed, 308 insertions(+), 37 deletions(-) [+] |
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog Thu Nov 03 10:19:29 2011 +0000 +++ b/flys-artifacts/ChangeLog Thu Nov 03 10:25:23 2011 +0000 @@ -1,3 +1,31 @@ +2011-11-03 Felix Wolfsteller <felix.wolfsteller@intevation.de> + + Added new matching options for theme-mappings to allow more + overspecification of defaults (e.g. now name,description-pattern and + master-artifacts attributes are matched). The first full match from + the configuration file is done. + New matching option in the masterAttr- field of a mapping are + super-basic until new use-cases come up. + Concrete new themes are point-styles of Ws when locations where chosen + to calculate. + + * doc/conf/themes.xml: Added newly defined Themes. + + * src/main/java/de/intevation/flys/collections/FLYSArtifactCollection.java: + Put master-artifact in flys-context. + + * src/main/java/de/intevation/flys/themes/ThemeMapping.java: + Accept masterAttr in constructor. + (masterAttrMatches): New, check masterAttr-condition against + artifact. + + * src/main/java/de/intevation/flys/artifacts/context/FLYSContextFactory.java: + When creating ThemeMappings, pass in masterAttr. + + * src/main/java/de/intevation/flys/themes/ThemeFactory.java: + (getTheme): Evaluate masterAttr-condition, always return first full + match. + 2011-11-03 Felix Wolfsteller <felix.wolfsteller@intevation.de> * src/main/java/de/intevation/flys/artifacts/context/FLYSContext.java:
--- a/flys-artifacts/doc/conf/themes.xml Thu Nov 03 10:19:29 2011 +0000 +++ b/flys-artifacts/doc/conf/themes.xml Thu Nov 03 10:25:23 2011 +0000 @@ -185,6 +185,146 @@ </fields> </theme> + <theme name="LongitudinalSectionPoints"> + <inherits> + <inherit from="LongitudinalSectionW"/> + </inherits> + <fields> + <field name="showlines" type="boolean" display="Linie anzeigen" default="false"/> + <field name="showpoints" type="boolean" display="Punkte anzeigen" default="true"/> + </fields> + </theme> + + <theme name="LongitudinalSectionW_HQ1_Points"> + <inherits><inherit from="LongitudinalSectionPoints"/></inherits> + <fields> + <field name="linecolor" type="Color" display="Linienfarbe" default="0, 0, 102"/> + </fields> + </theme> + + <theme name="LongitudinalSectionW_HQ2_Points"> + <inherits><inherit from="LongitudinalSectionPoints"/></inherits> + <fields> + <field name="linecolor" type="Color" display="Linienfarbe" default="0, 0, 102"/> + </fields> + </theme> + + <theme name="LongitudinalSectionW_HQ5_Points"> + <inherits><inherit from="LongitudinalSectionPoints"/></inherits> + <fields> + <field name="linecolor" type="Color" display="Linienfarbe" default="0, 153, 51"/> + </fields> + </theme> + + <theme name="LongitudinalSectionW_HQ10_Points"> + <inherits><inherit from="LongitudinalSectionPoints"/></inherits> + <fields> + <field name="linecolor" type="Color" display="Linienfarbe" default="0, 204, 204"/> + </fields> + </theme> + + <theme name="LongitudinalSectionW_HQ20_Points"> + <inherits><inherit from="LongitudinalSectionPoints"/></inherits> + <fields> + <field name="linecolor" type="Color" display="Linienfarbe" default="153, 153, 0"/> + </fields> + </theme> + + <theme name="LongitudinalSectionW_HQ25_Points"> + <inherits><inherit from="LongitudinalSectionPoints"/></inherits> + <fields> + <field name="linecolor" type="Color" display="Linienfarbe" default="102, 51, 0"/> + </fields> + </theme> + + <theme name="LongitudinalSectionW_HQ50_Points"> + <inherits><inherit from="LongitudinalSectionPoints"/></inherits> + <fields> + <field name="linecolor" type="Color" display="Linienfarbe" default="255, 153, 153"/> + </fields> + </theme> + + <theme name="LongitudinalSectionW_HQ100_Points"> + <inherits><inherit from="LongitudinalSectionPoints"/></inherits> + <fields> + <field name="linecolor" type="Color" display="Linienfarbe" default="255, 0, 51"/> + </fields> + </theme> + + <theme name="LongitudinalSectionW_HQ200_Points"> + <inherits><inherit from="LongitudinalSectionPoints"/></inherits> + <fields> + <field name="linecolor" type="Color" display="Linienfarbe" default="255, 0, 255"/> + </fields> + </theme> + + <theme name="LongitudinalSectionW_HQ500_Points"> + <inherits><inherit from="LongitudinalSectionPoints"/></inherits> + <fields> + <field name="linecolor" type="Color" display="Linienfarbe" default="102, 0, 102"/> + </fields> + </theme> + + <theme name="LongitudinalSectionW_HQ1000_Points"> + <inherits><inherit from="LongitudinalSectionPoints"/></inherits> + <fields> + <field name="linecolor" type="Color" display="Linienfarbe" default="0, 0, 0"/> + </fields> + </theme> + + <theme name="LongitudinalSectionW_HQRZ_Points"> + <inherits><inherit from="LongitudinalSectionPoints"/></inherits> + <fields> + <field name="linecolor" type="Color" display="Linienfarbe" default="102, 0, 102"/> + </fields> + </theme> + + <theme name="LongitudinalSectionW_HSQ_Points"> + <inherits><inherit from="LongitudinalSectionPoints"/></inherits> + <fields> + <field name="linecolor" type="Color" display="Linienfarbe" default="253, 153, 0"/> + </fields> + </theme> + + <theme name="LongitudinalSectionW_MHQ_Points"> + <inherits><inherit from="LongitudinalSectionPoints"/></inherits> + <fields> + <field name="linecolor" type="Color" display="Linienfarbe" default="102, 255, 102"/> + </fields> + </theme> + + <theme name="LongitudinalSectionW_MNQ_Points"> + <inherits><inherit from="LongitudinalSectionPoints"/></inherits> + <fields> + <field name="linecolor" type="Color" display="Linienfarbe" default="0, 255, 255"/> + </fields> + </theme> + + <theme name="LongitudinalSectionW_MQ_Points"> + <inherits><inherit from="LongitudinalSectionPoints"/></inherits> + <fields> + <field name="linecolor" type="Color" display="Linienfarbe" default="0, 51, 204"/> + </fields> + </theme> + + <theme name="LongitudinalSectionW_NQ_Points"> + <inherits><inherit from="LongitudinalSectionPoints"/></inherits> + <fields> + <field name="linecolor" type="Color" display="Linienfarbe" default="153, 204, 255"/> + </fields> + </theme> + + <theme name="LongitudinalSectionW_HQExtrem_Points"> + <inherits><inherit from="LongitudinalSectionPoints"/></inherits> + <fields> + <field name="linecolor" type="Color" display="Linienfarbe" default="0, 0, 0"/> + </fields> + </theme> + + <!-- + Longitudinal Section Q's + --> + <theme name="LongitudinalSectionQ"> <inherits> <inherit from="HiddenColorLines"/> @@ -577,10 +717,32 @@ </theme> - <!-- Mappings are following now. A mapping maps between a name of a facet - and a theme. --> + <!-- + Mappings are following now. A mapping maps between a name of a facet + and a theme. + Always the first matching mapping is taken, so consider putting most + specific mappings on top of the list. + --> <mappings> - <mapping from="longitudinal_section.w" to="LongitudinalSectionW"/> + <mapping from="longitudinal_section.w" masterAttr="ld_mode==location" pattern=".*(HQ1)(\D.*)*" to="LongitudinalSectionW_HQ1_Points"/> + <mapping from="longitudinal_section.w" masterAttr="ld_mode==location" pattern=".*(HQ2)(\D.*)*" to="LongitudinalSectionW_HQ2_Points"/> + <mapping from="longitudinal_section.w" masterAttr="ld_mode==location" pattern=".*(HQ5)(\D.*)*" to="LongitudinalSectionW_HQ5_Points"/> + <mapping from="longitudinal_section.w" masterAttr="ld_mode==location" pattern=".*(HQ10)(\D.*)*" to="LongitudinalSectionW_HQ10_Points"/> + <mapping from="longitudinal_section.w" masterAttr="ld_mode==location" pattern=".*(HQ20)(\D.*)*" to="LongitudinalSectionW_HQ20_Points"/> + <mapping from="longitudinal_section.w" masterAttr="ld_mode==location" pattern=".*(HQ25)(\D.*)*" to="LongitudinalSectionW_HQ25_Points"/> + <mapping from="longitudinal_section.w" masterAttr="ld_mode==location" pattern=".*(HQ50)(\D.*)*" to="LongitudinalSectionW_HQ50_Points"/> + <mapping from="longitudinal_section.w" masterAttr="ld_mode==location" pattern=".*(HQ100)(\D.*)*" to="LongitudinalSectionW_HQ100_Points"/> + <mapping from="longitudinal_section.w" masterAttr="ld_mode==location" pattern=".*(HQ200)(\D.*)*" to="LongitudinalSectionW_HQ200_Points"/> + <mapping from="longitudinal_section.w" masterAttr="ld_mode==location" pattern=".*(HQ500)(\D.*)*" to="LongitudinalSectionW_HQ500_Points"/> + <mapping from="longitudinal_section.w" masterAttr="ld_mode==location" pattern=".*(HQ1000)(\D.*)*" to="LongitudinalSectionW_HQ1000_Points"/> + <mapping from="longitudinal_section.w" masterAttr="ld_mode==location" pattern=".*(HQExtrem)(\D.*)*" to="LongitudinalSectionW_HQExtrem_Points"/> + <mapping from="longitudinal_section.w" masterAttr="ld_mode==location" pattern=".*(HQRZ)(\D.*)*" to="LongitudinalSectionW_HQRZ_Points"/> + <mapping from="longitudinal_section.w" masterAttr="ld_mode==location" pattern=".*(HSQ)(\D.*)*" to="LongitudinalSectionW_HSQ_Points"/> + <mapping from="longitudinal_section.w" masterAttr="ld_mode==location" pattern=".*(MHQ)(\D.*)*" to="LongitudinalSectionW_MHQ_Points"/> + <mapping from="longitudinal_section.w" masterAttr="ld_mode==location" pattern=".*(MNQ)(\D.*)*" to="LongitudinalSectionW_MNQ_Points"/> + <mapping from="longitudinal_section.w" masterAttr="ld_mode==location" pattern=".*(MQ)(\D.*)*" to="LongitudinalSectionW_MQ_Points"/> + <mapping from="longitudinal_section.w" masterAttr="ld_mode==location" pattern=".*(NQ)(\D.*)*" to="LongitudinalSectionW_NQ_Points"/> + <mapping from="longitudinal_section.w" masterAttr="ld_mode==location" to="LongitudinalSectionPoints"/> <mapping from="longitudinal_section.w" pattern=".*(HQ1)(\D.*)*" to="LongitudinalSectionW_HQ1"/> <mapping from="longitudinal_section.w" pattern=".*(HQ2)(\D.*)*" to="LongitudinalSectionW_HQ2"/> <mapping from="longitudinal_section.w" pattern=".*(HQ5)(\D.*)*" to="LongitudinalSectionW_HQ5"/> @@ -599,7 +761,8 @@ <mapping from="longitudinal_section.w" pattern=".*(MNQ)(\D.*)*" to="LongitudinalSectionW_MNQ"/> <mapping from="longitudinal_section.w" pattern=".*(MQ)(\D.*)*" to="LongitudinalSectionW_MQ"/> <mapping from="longitudinal_section.w" pattern=".*(NQ)(\D.*)*" to="LongitudinalSectionW_NQ"/> - <mapping from="longitudinal_section.q" to="LongitudinalSectionQ"/> + <mapping from="longitudinal_section.w" to="LongitudinalSectionW"/> + <mapping from="longitudinal_section.q" pattern="(HQ1)(\D.*)*" to="LongitudinalSectionQ_HQ1"/> <mapping from="longitudinal_section.q" pattern="(HQ2)(\D.*)*" to="LongitudinalSectionQ_HQ2"/> <mapping from="longitudinal_section.q" pattern="(HQ5)(\D.*)*" to="LongitudinalSectionQ_HQ5"/> @@ -618,6 +781,7 @@ <mapping from="longitudinal_section.q" pattern="(MNQ)(\D.*)*" to="LongitudinalSectionQ_MNQ"/> <mapping from="longitudinal_section.q" pattern="(MQ)(\D.*)*" to="LongitudinalSectionQ_MQ"/> <mapping from="longitudinal_section.q" pattern="(NQ)(\D.*)*" to="LongitudinalSectionQ_NQ"/> + <mapping from="longitudinal_section.q" to="LongitudinalSectionQ"/> <mapping from="discharge_curve.curve" to="DischargeCurve"/> <mapping from="cross_section" to="CrossSection"/> <mapping from="cross_section_water_line" to="CrossSectionWaterLine"/>
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/context/FLYSContextFactory.java Thu Nov 03 10:19:29 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/context/FLYSContextFactory.java Thu Nov 03 10:25:23 2011 +0000 @@ -360,6 +360,9 @@ String pattern = (String) XMLUtils.xpath( node, "@pattern", XPathConstants.STRING); + String masterAttrPattern = (String) XMLUtils.xpath( + node, "@masterAttr", XPathConstants.STRING); + if (from != null && to != null) { List<ThemeMapping> tm = mapping.get(from); @@ -368,7 +371,8 @@ mapping.put(from, tm); } - tm.add(new ThemeMapping(from, to, pattern)); + tm.add(new ThemeMapping( + from, to, pattern, masterAttrPattern)); } }
--- a/flys-artifacts/src/main/java/de/intevation/flys/collections/FLYSArtifactCollection.java Thu Nov 03 10:19:29 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/collections/FLYSArtifactCollection.java Thu Nov 03 10:25:23 2011 +0000 @@ -494,8 +494,8 @@ /** - * Returns the attribute that belongs to an artifact stored in this - * collection. + * Returns the attribute that belongs to an artifact and facet stored in + * this collection. * * @param uuid The Artifact's uuid. * @param outname The name of the requested output. @@ -723,6 +723,17 @@ ? (FLYSContext) context : (FLYSContext) context.globalContext(); + // Push artifact in flysContext. + ArtifactDatabase db = context.getDatabase(); + try { + FLYSArtifact artifact = (FLYSArtifact) db.getRawArtifact(uuid); + log.debug("Got raw artifact"); + flysContext.put(flysContext.ARTIFACT_KEY, artifact); + } + catch (Exception e) { + log.error("Exception caught when trying to get art.", e); + } + Theme t = ThemeFactory.getTheme(flysContext, facet, pattern); if (t != null) {
--- a/flys-artifacts/src/main/java/de/intevation/flys/themes/ThemeFactory.java Thu Nov 03 10:19:29 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/themes/ThemeFactory.java Thu Nov 03 10:25:23 2011 +0000 @@ -15,16 +15,21 @@ import de.intevation.artifacts.common.utils.XMLUtils; import de.intevation.flys.artifacts.context.FLYSContext; - +import de.intevation.flys.artifacts.FLYSArtifact; /** * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + * + * Mapping-matching rules: + * */ public class ThemeFactory { private static Logger logger = Logger.getLogger(ThemeFactory.class); + /** Trivial, hidden constructor. */ private ThemeFactory() { + ; } @@ -66,19 +71,32 @@ } + /** + * Get first matching theme for facet. + * + * @param name Name to match "from" of theme mapping. + * @param pattern String to 'compare' to pattern in mapping. + * + * @return First matching theme. + */ public static Theme getTheme(FLYSContext c, String name, String pattern) { + logger.debug("Search theme for: " + name + " - " + pattern); + if (c == null || name == null) { logger.warn("Cannot search for theme."); return null; } + // Fetch mapping and themes. Map<String, List<ThemeMapping>> map = (Map<String, List<ThemeMapping>>) c.get(FLYSContext.THEME_MAPPING); Map<String, Theme> t = (Map<String, Theme>) c.get(FLYSContext.THEMES); + FLYSArtifact artifact = (FLYSArtifact) c.get(FLYSContext.ARTIFACT_KEY); + if (map == null || map.size() == 0 || t == null || t.size() == 0) { logger.warn("No mappings or themes found. Cannot retrieve theme!"); return null; @@ -87,32 +105,17 @@ List<ThemeMapping> mapping = map.get(name); if (mapping == null) { - logger.warn("No theme fount for mapping: " + name); + logger.warn("No theme found for mapping: " + name); return null; } - int patternLen = pattern != null ? pattern.length() : 0; - - Theme defaultTheme = null; - + // Take first mapping of which all conditions are satisfied. for (ThemeMapping tm: mapping) { - if (name.equals(tm.getFrom())) { - String tmPattern = tm.getPatternStr(); - - int tmLen = tmPattern != null ? tmPattern.length() : 0; - - if (tmLen == 0 && patternLen == 0) { - // we want and get the default theme - return t.get(tm.getTo()); - } - else if (tmLen == 0 && patternLen > 0) { - // found a defaultTheme, lets save it - defaultTheme = t.get(tm.getTo()); - } - else if (tm.applyPattern(pattern)) { - // found the special theme we have searched for - return t.get(tm.getTo()); - } + if (name.equals(tm.getFrom()) + && tm.applyPattern(pattern) + && tm.masterAttrMatches(artifact)) + { + return t.get(tm.getTo()); } } @@ -120,11 +123,6 @@ "No theme found for '" + name + "' with pattern '" + pattern + "'."; - if (defaultTheme != null) { - logger.info(msg + " Use the default instead."); - return defaultTheme; - } - logger.warn(msg); return null;
--- a/flys-artifacts/src/main/java/de/intevation/flys/themes/ThemeMapping.java Thu Nov 03 10:19:29 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/themes/ThemeMapping.java Thu Nov 03 10:25:23 2011 +0000 @@ -1,28 +1,51 @@ package de.intevation.flys.themes; +import org.apache.log4j.Logger; + import java.io.Serializable; import java.util.regex.Matcher; import java.util.regex.Pattern; +import de.intevation.flys.artifacts.FLYSArtifact; +/** + * Represents mapping to a theme (including conditions). + */ public class ThemeMapping implements Serializable { + /** The logger that is used in this class */ + private static Logger logger = Logger.getLogger(ThemeMapping.class); + + /** Name from which to map. */ protected String from; + + /** Name to which to map. */ protected String to; + + /** Given pattern (held against facet description). */ protected String patternStr; + /** Given masterAttr pattern (held against masterartifacts attributes). */ + protected String masterAttr; + protected Pattern pattern; public ThemeMapping(String from, String to) { - this(from, to, null); + this(from, to, null, null); } - public ThemeMapping(String from, String to, String patternStr) { + public ThemeMapping( + String from, + String to, + String patternStr, + String masterAttr) + { this.from = from; this.to = to; this.patternStr = patternStr; + this.masterAttr = masterAttr; this.pattern = Pattern.compile(patternStr); } @@ -33,19 +56,62 @@ } + /** + * Get name of theme that is mapped to. + */ public String getTo() { return to; } + /** + * Get pattern. + */ public String getPatternStr() { return patternStr; } + /** + * Match regular expression against text. + * + * @param text string to be matched against. + * @return true if pattern matches text or pattern is empty. + */ public boolean applyPattern(String text) { + if (patternStr == null || patternStr.equals("")) { + return true; + } Matcher m = pattern.matcher(text); return m.matches(); } + + + /** + * Inspects Artifacts data given the masterAttr-condition. + * + * The only condition implemented so far is 'key==value', for which + * the Artifacts data with name "key" has to be of value "value" in order + * for true to be returned. + * + * @param artifact Artifact of which to inspect data. + * @return true if no condition is specified or condition is met. + */ + public boolean masterAttrMatches(FLYSArtifact artifact) { + if (masterAttr == null || masterAttr.equals("")) { + return true; + } + + // Operator split. + String[] parts = masterAttr.split("=="); + if (parts.length != 2) { + logger.error("ThemeMapping could not parse masterAttr.-condition:_" + + masterAttr + "_"); + return false; + } + + // Test. + return artifact.getDataAsString(parts[0]).equals(parts[1]); + } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :