Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/AnnotationArtifact.java @ 1032:abd2ab6dff4f
Let AnnotationArtifact fetch "more correct" data.
flys-artifacts/trunk@2492 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Felix Wolfsteller <felix.wolfsteller@intevation.de> |
---|---|
date | Fri, 12 Aug 2011 12:54:19 +0000 |
parents | a39511688679 |
children | 821aaceb2776 |
comparison
equal
deleted
inserted
replaced
1031:bcef54a563ea | 1032:abd2ab6dff4f |
---|---|
9 | 9 |
10 import org.apache.log4j.Logger; | 10 import org.apache.log4j.Logger; |
11 | 11 |
12 import org.hibernate.Session; | 12 import org.hibernate.Session; |
13 | 13 |
14 import net.sf.ehcache.Cache; | 14 //import net.sf.ehcache.Cache; |
15 | 15 |
16 import de.intevation.artifacts.Artifact; | 16 import de.intevation.artifacts.Artifact; |
17 import de.intevation.artifacts.ArtifactNamespaceContext; | 17 import de.intevation.artifacts.ArtifactNamespaceContext; |
18 import de.intevation.artifacts.CallContext; | 18 import de.intevation.artifacts.CallContext; |
19 import de.intevation.artifacts.CallMeta; | 19 import de.intevation.artifacts.CallMeta; |
46 private static Logger logger = Logger.getLogger(WINFOArtifact.class); | 46 private static Logger logger = Logger.getLogger(WINFOArtifact.class); |
47 | 47 |
48 /** The name of the artifact. */ | 48 /** The name of the artifact. */ |
49 public static final String ARTIFACT_NAME = "annotation"; | 49 public static final String ARTIFACT_NAME = "annotation"; |
50 | 50 |
51 public static final String CACHE_NAME = "service-distanceinfo"; | 51 /* Name of cache. */ |
52 | 52 //public static final String CACHE_NAME = "annotations"; |
53 | 53 |
54 @Override | 54 @Override |
55 protected void initialize(Artifact artifact, Object context, CallMeta meta) { | 55 protected void initialize(Artifact artifact, Object context, CallMeta meta) { |
56 logger.debug("Initialize internal state of AnnotationArtifact with: " + artifact.identifier()); | 56 logger.debug("Initialize internal state of AnnotationArtifact with: " + artifact.identifier()); |
57 | 57 |
58 FLYSArtifact flys = (FLYSArtifact) artifact; | 58 FLYSArtifact flys = (FLYSArtifact) artifact; |
59 addData("river", flys.getData("river")); | 59 addData("river", flys.getData("river")); |
60 /* | |
61 logger.debug("Could set ranges to " + | |
62 AnnotationsFactory.getAnnotationsBreadth( | |
63 getRiver().getName())[0]); | |
64 */ | |
60 | 65 |
61 List<Facet> fs = new ArrayList<Facet>(); | 66 List<Facet> fs = new ArrayList<Facet>(); |
62 | 67 |
63 // TODO Add CallMeta (duplicate TODO in RiverAxisArtifact.java). | 68 // TODO Add CallMeta (duplicate TODO in RiverAxisArtifact.java). |
64 DefaultState state = (DefaultState) getCurrentState(context); | 69 DefaultState state = (DefaultState) getCurrentState(context); |
74 } | 79 } |
75 | 80 |
76 | 81 |
77 @Override | 82 @Override |
78 public double[] getDistance() { | 83 public double[] getDistance() { |
79 /** TODO In initialize(), access maximal range of river instead of | 84 /** TODO In initialize(), access maximal range of river (via |
80 * overriding getDistance, important for diagram generation. */ | 85 * AnnotationFactory) instead of overriding getDistance, |
86 * important for diagram generation. */ | |
81 return new double[] {0f, 1000f}; | 87 return new double[] {0f, 1000f}; |
82 } | 88 } |
83 | 89 |
84 | 90 |
85 /** | 91 /** |
224 * Get Annotations for Points (opposed to segments) in river in range. | 230 * Get Annotations for Points (opposed to segments) in river in range. |
225 * | 231 * |
226 * @return list of Annotations. | 232 * @return list of Annotations. |
227 */ | 233 */ |
228 public List<Annotation> getAnnotations() { | 234 public List<Annotation> getAnnotations() { |
229 // TODO Use Cache of DistanceInfoService. | 235 String river = getRiver().getName(); |
230 // TODO Use given river. | |
231 // TODO Query Points (opposed to segments) only. | |
232 String river = "Saar"; | |
233 logger.debug("Search annotations for river: " /*+ river*/); | 236 logger.debug("Search annotations for river: " /*+ river*/); |
234 //Cache cache = CacheFactory.getCache(CACHE_NAME); | 237 //Cache cache = CacheFactory.getCache(CACHE_NAME); |
235 | 238 |
236 List<Annotation> annotations = new ArrayList<Annotation>(); | 239 List<Annotation> annotations = new ArrayList<Annotation>(); |
237 | 240 |
238 //if (cache == null) { | 241 return getAnnotationsUncached(river); |
239 // logger.debug("No cache configured for distance info."); | 242 } |
240 //return getUncached(river, filter); | 243 |
241 //} | 244 /** |
245 * Gets Annotations from Session/Database. | |
246 * | |
247 * @return List of Annotations fetched fresh from session/database. | |
248 * @see DistanceInfoService to access cached documents. | |
249 */ | |
250 protected List<Annotation> getAnnotationsUncached(String river) { | |
251 List<Annotation> annotations = new ArrayList<Annotation>(); | |
242 Session session = SessionHolder.acquire(); | 252 Session session = SessionHolder.acquire(); |
243 try { | 253 try { |
244 Iterator<Annotation> iter = | 254 annotations = AnnotationsFactory.getPointAnnotations(river); |
245 AnnotationsFactory.getAnnotationsIterator(river); | |
246 while (iter.hasNext()) { | |
247 Annotation a = iter.next(); | |
248 logger.debug("Annotation: " + a.getPosition().getValue()); | |
249 annotations.add(a); | |
250 } | |
251 } finally {session.close(); SessionHolder.release();} | 255 } finally {session.close(); SessionHolder.release();} |
252 return annotations; | 256 return annotations; |
253 } | 257 } |
254 } | 258 } |
255 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : | 259 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |