|
11 | 11 | import javax.servlet.ServletContextEvent; |
12 | 12 | import org.apache.commons.lang3.builder.ToStringBuilder; |
13 | 13 | import org.ecocean.acm.AcmUtil; |
| 14 | +import org.ecocean.Annotation; |
14 | 15 | import org.ecocean.cache.CachedQuery; |
15 | 16 | import org.ecocean.cache.QueryCache; |
16 | 17 | import org.ecocean.cache.QueryCacheFactory; |
17 | | -import org.ecocean.Annotation; |
18 | 18 | import org.ecocean.ia.IA; |
19 | 19 | import org.ecocean.ia.Task; |
20 | 20 | import org.ecocean.media.*; |
@@ -82,48 +82,6 @@ public void prime() { |
82 | 82 | IBEISIA.setIAPrimed(true); |
83 | 83 | } |
84 | 84 |
|
85 | | - public void _OLD_prime() { |
86 | | - IA.log("INFO: WildbookIAM.prime(" + this.context + ") called"); |
87 | | - IBEISIA.setIAPrimed(false); |
88 | | - if (!isEnabled()) return; |
89 | | - final List<String> iaAnnotIds = iaAnnotationIds(); |
90 | | - final List<String> iaImageIds = iaImageIds(); |
91 | | - Runnable r = new Runnable() { |
92 | | - public void run() { |
93 | | - Shepherd myShepherd = new Shepherd(context); |
94 | | - myShepherd.setAction("WildbookIAM.prime"); |
95 | | - myShepherd.beginDBTransaction(); |
96 | | - ArrayList<Annotation> matchingSet = Annotation.getAllMatchAgainstTrue(myShepherd); |
97 | | - ArrayList<Annotation> sendAnns = new ArrayList<Annotation>(); |
98 | | - ArrayList<MediaAsset> mas = new ArrayList<MediaAsset>(); |
99 | | - for (Annotation ann : matchingSet) { |
100 | | - if (iaAnnotIds.contains(ann.getAcmId())) continue; // no need to send |
101 | | - sendAnns.add(ann); |
102 | | - MediaAsset ma = ann.getDerivedMediaAsset(); |
103 | | - if (ma == null) ma = ann.getMediaAsset(); |
104 | | - if (ma == null) continue; |
105 | | - if (iaImageIds.contains(ma.getAcmId())) continue; |
106 | | - mas.add(ma); |
107 | | - } |
108 | | - IA.log("INFO: WildbookIAM.prime(" + context + ") sending " + sendAnns.size() + |
109 | | - " annots (of " + matchingSet.size() + ") and " + mas.size() + " images"); |
110 | | - try { |
111 | | - // think we can checkFirst on both of these -- no need to re-send anything during priming |
112 | | - sendMediaAssets(mas, true); |
113 | | - sendAnnotations(sendAnns, true, myShepherd); |
114 | | - } catch (Exception ex) { |
115 | | - IA.log("ERROR: WildbookIAM.prime() failed due to " + ex.toString()); |
116 | | - ex.printStackTrace(); |
117 | | - } |
118 | | - myShepherd.commitDBTransaction(); // MAs and annots may have had acmIds changed |
119 | | - myShepherd.closeDBTransaction(); |
120 | | - IBEISIA.setIAPrimed(true); |
121 | | - IA.log("INFO: WildbookIAM.prime(" + context + ") complete"); |
122 | | - } |
123 | | - }; |
124 | | - new Thread(r).start(); |
125 | | - } |
126 | | - |
127 | 85 | /* |
128 | 86 | note: sendMediaAssets() and sendAnnotations() need to be *batched* now in small chunks, particularly sendMediaAssets(). |
129 | 87 | this is because we **must** get the return value from the POST, in order that we can map the corresponding (returned) acmId values. if we |
@@ -317,33 +275,28 @@ public List<String> iaAnnotationIds() { |
317 | 275 | public static List<String> iaAnnotationIds(String context) { |
318 | 276 | List<String> ids = new ArrayList<String>(); |
319 | 277 | JSONArray jids = null; |
320 | | - String cacheName="iaAnnotationIds"; |
| 278 | + String cacheName = "iaAnnotationIds"; |
| 279 | + |
321 | 280 | try { |
322 | | - |
323 | | - |
324 | | - QueryCache qc = QueryCacheFactory.getQueryCache(context); |
| 281 | + QueryCache qc = QueryCacheFactory.getQueryCache(context); |
325 | 282 | if (qc.getQueryByName(cacheName) != null && |
326 | 283 | System.currentTimeMillis() < |
327 | 284 | qc.getQueryByName(cacheName).getNextExpirationTimeout()) { |
328 | | - |
329 | | - org.datanucleus.api.rest.orgjson.JSONObject jobj = Util.toggleJSONObject(qc.getQueryByName(cacheName).getJSONSerializedQueryResult()); |
330 | | - jids=Util.toggleJSONArray(jobj.getJSONArray("iaAnnotationIds")); |
331 | | - } |
332 | | - else { |
333 | | - jids = apiGetJSONArray("/api/annot/json/", context); |
334 | | - if(jids!=null) { |
335 | | - org.datanucleus.api.rest.orgjson.JSONObject jobj =new org.datanucleus.api.rest.orgjson.JSONObject(); |
336 | | - jobj.put("iaAnnotationIds",Util.toggleJSONArray(jids)); |
337 | | - CachedQuery cq = new CachedQuery(cacheName, Util.toggleJSONObject(jobj)); |
338 | | - cq.nextExpirationTimeout = System.currentTimeMillis() + (15*60*1000); |
339 | | - qc.addCachedQuery(cq); |
340 | | - } |
341 | | - |
| 285 | + org.datanucleus.api.rest.orgjson.JSONObject jobj = Util.toggleJSONObject( |
| 286 | + qc.getQueryByName(cacheName).getJSONSerializedQueryResult()); |
| 287 | + jids = Util.toggleJSONArray(jobj.getJSONArray("iaAnnotationIds")); |
| 288 | + } else { |
| 289 | + jids = apiGetJSONArray("/api/annot/json/", context); |
| 290 | + if (jids != null) { |
| 291 | + org.datanucleus.api.rest.orgjson.JSONObject jobj = |
| 292 | + new org.datanucleus.api.rest.orgjson.JSONObject(); |
| 293 | + jobj.put("iaAnnotationIds", Util.toggleJSONArray(jids)); |
| 294 | + CachedQuery cq = new CachedQuery(cacheName, Util.toggleJSONObject(jobj)); |
| 295 | + cq.nextExpirationTimeout = System.currentTimeMillis() + (15 * 60 * 1000); |
| 296 | + qc.addCachedQuery(cq); |
| 297 | + } |
342 | 298 | } |
343 | | - |
344 | | - |
345 | | - } |
346 | | - catch (Exception ex) { |
| 299 | + } catch (Exception ex) { |
347 | 300 | ex.printStackTrace(); |
348 | 301 | IA.log("ERROR: WildbookIAM.iaAnnotationIds() returning empty; failed due to " + |
349 | 302 | ex.toString()); |
|
0 commit comments