# HG changeset patch # User Felix Wolfsteller # Date 1326977564 0 # Node ID 923256599afe6a3029511dabf44a7a473fab55e5 # Parent 59bb5c895be3daa9147438f9e10f78566131a6c4 Somewhat improved hyk handling and rendering. flys-artifacts/trunk@3717 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r 59bb5c895be3 -r 923256599afe flys-artifacts/ChangeLog --- a/flys-artifacts/ChangeLog Thu Jan 19 11:00:27 2012 +0000 +++ b/flys-artifacts/ChangeLog Thu Jan 19 12:52:44 2012 +0000 @@ -1,3 +1,18 @@ +2012-01-19 Felix Wolfsteller + + Somewhat improved HYK handling and rendering. + + * src/main/java/de/intevation/flys/artifacts/HYKArtifact.java: + Store ids in more sensibly named data item and expose it. + Spawn all facets in inactive state. + + * src/main/java/de/intevation/flys/artifacts/model/HYKFactory.java: + Make HYK name accessible, do not query hyks by river, but by hyk-id, + made query more real-world. + + * src/main/java/de/intevation/flys/artifacts/states/StaticHYKState.java: + Use hyks name as facet name, pass hyk-id when asking for hyks. + 2012-01-19 Felix Wolfsteller Somewhat improved HYK handling and rendering. diff -r 59bb5c895be3 -r 923256599afe flys-artifacts/src/main/java/de/intevation/flys/artifacts/HYKArtifact.java --- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/HYKArtifact.java Thu Jan 19 11:00:27 2012 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/HYKArtifact.java Thu Jan 19 12:52:44 2012 +0000 @@ -30,6 +30,9 @@ /** Name of Artifact. */ public static final String HYK_ARTIFACT_NAME = "hyk"; + /** Name of data item keeping the hyk id to load formations from. */ + public static final String HYK_ID = "hyk_artifact.data.id"; + /** Name of data item keeping the km of cs master. */ public static final String HYK_KM = "hyk_artifact.data.km"; @@ -56,12 +59,15 @@ { logger.info("HYKArtifact.setup"); - super.setup(identifier, factory, context, callMeta, data); String ids = XMLUtils.xpathString( data, XPATH_IDS, ArtifactNamespaceContext.INSTANCE); - addStringData("ids", ids); + logger.info("HYKArtifact.setup: id is " + ids); + + addStringData(HYK_ID, ids); + + super.setup(identifier, factory, context, callMeta, data); } @@ -96,6 +102,11 @@ return getDataAsDouble(HYK_KM); } + /** Get hyk-id from state data. */ + public int getHykId() { + return getDataAsInteger(HYK_ID); + } + /** Do not copy data from daddyfact. */ @Override protected void initialize( @@ -120,5 +131,25 @@ + state.getID() + ")."); } } + + + /** + * Determines Facets initial disposition regarding activity (think of + * selection in Client ThemeList GUI). This will be checked one time + * when the facet enters a collections describe document. + * + * @param facetName name of the facet. + * @param index index of the facet. + * + * @return Always 0. Hyk Data will enter plots inactive. + */ + @Override + public int getInitialFacetActivity( + String outputName, + String facetName, + int index) + { + return 0; + } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : diff -r 59bb5c895be3 -r 923256599afe flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/HYKFactory.java --- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/HYKFactory.java Thu Jan 19 11:00:27 2012 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/HYKFactory.java Thu Jan 19 12:52:44 2012 +0000 @@ -39,7 +39,7 @@ /** * Get List of Zones for given river and km. */ - public static Object getHYKs(int riverId, double km) { + public static Object getHYKs(int hykid, double km) { logger.debug("HYKFactory.getHYKs"); Cache cache = CacheFactory.getCache(HYK_CACHE_NAME); @@ -47,7 +47,7 @@ String cacheKey; if (cache != null) { - cacheKey = "" + riverId + "_" + km; + cacheKey = "" + hykid + "_" + km; Element element = cache.get(cacheKey); if (element != null) { logger.debug("Got hyk from cache"); @@ -58,7 +58,7 @@ cacheKey = null; } - List zones = getZonesUncached(riverId, km); + List zones = getZonesUncached(hykid, km); if (zones != null && cacheKey != null) { logger.debug("Store hykzones in cache."); @@ -70,6 +70,21 @@ } + public static String getHykName(int hykid) { + logger.debug("HYKFactory.getHykName " + hykid); + + Session session = SessionHolder.HOLDER.get(); + + // TODO respect interval better. respect multiples (sort, limit), + // TODO respect flow direction of river. + Query query = session.createQuery( + "select description from HYK where id = :hykid "); + query.setParameter("hykid", hykid); + + return (String) query.uniqueResult(); + } + + /** * * @param column the position columns value @@ -78,10 +93,10 @@ */ // TODO we also need to know the HYK-id to specify which set we are // inspecting. - public static List getZonesUncached(int riverId, double km) { + public static List getZonesUncached(int hykid, double km) { if (logger.isDebugEnabled()) { - logger.debug("HYKFactory.getZoneUncached " + riverId + " km " + km); + logger.debug("HYKFactory.getZoneUncached " + hykid + " km " + km); } Session session = SessionHolder.HOLDER.get(); @@ -89,21 +104,20 @@ // TODO respect interval better. respect multiples (sort, limit), // TODO respect flow direction of river. Query query = session.createQuery( - "from HYKFormation where entry.HYK.river.id = :riverid " + - " and entry.km between " + - ":km - cast(distance_vl/1000.0 - 0.001 as big_decimal) and " + - ":km + cast(distance_vl/1000.0 + 0.001 as big_decimal)"); - query.setParameter("riverid", riverId); + "from HYKFormation where entry.HYK.id = :hykid " + + " and :km between entry.km - cast(distance_vl/1000.0 + 0.001 as big_decimal) and " + + " entry.km + cast(distance_vl/1000.0 + 0.001 as big_decimal)" + + " order by entry.km asc"); + query.setParameter("hykid", hykid); query.setParameter("km", new BigDecimal(km)); logger.debug("Big km " + new BigDecimal(km)); List forms = query.list(); List zones = new ArrayList(); - for (HYKFormation form : forms) { - logger.debug("One HYKFormation found (entry: " - + form.getEntry().getId() - + ") /km " + form.getEntry().getKm() + "."); - + // TODO limit query by one; sensible sorting. + // Take the first one. + if (forms.size() >= 1) { + HYKFormation form = forms.get(0); // Create respective zones. for (HYKFlowZone flowZone: form.getZones()) { Zone z = new Zone(flowZone.getA().doubleValue(), diff -r 59bb5c895be3 -r 923256599afe flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/StaticHYKState.java --- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/StaticHYKState.java Thu Jan 19 11:00:27 2012 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/StaticHYKState.java Thu Jan 19 12:52:44 2012 +0000 @@ -27,7 +27,7 @@ implements FacetTypes { /** The logger that is used in this state. */ - private static Logger logger = Logger.getLogger(StaticHYKState.class); + transient private static final Logger logger = Logger.getLogger(StaticHYKState.class); /** @@ -69,14 +69,14 @@ // Need river id and km. List zones = (List) - HYKFactory.getHYKs(FLYSUtils.getRiver(hyk).getId(), hyk.getKm()); + HYKFactory.getHYKs(hyk.getHykId(), hyk.getKm()); if (facets == null) { logger.debug("StaticHYKState.compute no facets"); return zones; } - Facet facet = new HYKFacet(0, "I am hyked."); + Facet facet = new HYKFacet(0, HYKFactory.getHykName(hyk.getHykId())); facets.add(facet);