Skip to content

Commit

Permalink
remove cruft
Browse files Browse the repository at this point in the history
  • Loading branch information
naknomum committed Jan 29, 2025
1 parent b09e6b7 commit fc6d435
Showing 1 changed file with 18 additions and 65 deletions.
83 changes: 18 additions & 65 deletions src/main/java/org/ecocean/ia/plugin/WildbookIAM.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
import javax.servlet.ServletContextEvent;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.ecocean.acm.AcmUtil;
import org.ecocean.Annotation;
import org.ecocean.cache.CachedQuery;
import org.ecocean.cache.QueryCache;
import org.ecocean.cache.QueryCacheFactory;
import org.ecocean.Annotation;
import org.ecocean.ia.IA;
import org.ecocean.ia.Task;
import org.ecocean.media.*;
Expand Down Expand Up @@ -82,48 +82,6 @@ public void prime() {
IBEISIA.setIAPrimed(true);
}

public void _OLD_prime() {
IA.log("INFO: WildbookIAM.prime(" + this.context + ") called");
IBEISIA.setIAPrimed(false);
if (!isEnabled()) return;
final List<String> iaAnnotIds = iaAnnotationIds();
final List<String> iaImageIds = iaImageIds();
Runnable r = new Runnable() {
public void run() {
Shepherd myShepherd = new Shepherd(context);
myShepherd.setAction("WildbookIAM.prime");
myShepherd.beginDBTransaction();
ArrayList<Annotation> matchingSet = Annotation.getAllMatchAgainstTrue(myShepherd);
ArrayList<Annotation> sendAnns = new ArrayList<Annotation>();
ArrayList<MediaAsset> mas = new ArrayList<MediaAsset>();
for (Annotation ann : matchingSet) {
if (iaAnnotIds.contains(ann.getAcmId())) continue; // no need to send
sendAnns.add(ann);
MediaAsset ma = ann.getDerivedMediaAsset();
if (ma == null) ma = ann.getMediaAsset();
if (ma == null) continue;
if (iaImageIds.contains(ma.getAcmId())) continue;
mas.add(ma);
}
IA.log("INFO: WildbookIAM.prime(" + context + ") sending " + sendAnns.size() +
" annots (of " + matchingSet.size() + ") and " + mas.size() + " images");
try {
// think we can checkFirst on both of these -- no need to re-send anything during priming
sendMediaAssets(mas, true);
sendAnnotations(sendAnns, true, myShepherd);
} catch (Exception ex) {
IA.log("ERROR: WildbookIAM.prime() failed due to " + ex.toString());
ex.printStackTrace();
}
myShepherd.commitDBTransaction(); // MAs and annots may have had acmIds changed
myShepherd.closeDBTransaction();
IBEISIA.setIAPrimed(true);
IA.log("INFO: WildbookIAM.prime(" + context + ") complete");
}
};
new Thread(r).start();
}

/*
note: sendMediaAssets() and sendAnnotations() need to be *batched* now in small chunks, particularly sendMediaAssets().
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
Expand Down Expand Up @@ -317,33 +275,28 @@ public List<String> iaAnnotationIds() {
public static List<String> iaAnnotationIds(String context) {
List<String> ids = new ArrayList<String>();
JSONArray jids = null;
String cacheName="iaAnnotationIds";
String cacheName = "iaAnnotationIds";

try {


QueryCache qc = QueryCacheFactory.getQueryCache(context);
QueryCache qc = QueryCacheFactory.getQueryCache(context);
if (qc.getQueryByName(cacheName) != null &&
System.currentTimeMillis() <
qc.getQueryByName(cacheName).getNextExpirationTimeout()) {

org.datanucleus.api.rest.orgjson.JSONObject jobj = Util.toggleJSONObject(qc.getQueryByName(cacheName).getJSONSerializedQueryResult());
jids=Util.toggleJSONArray(jobj.getJSONArray("iaAnnotationIds"));
}
else {
jids = apiGetJSONArray("/api/annot/json/", context);
if(jids!=null) {
org.datanucleus.api.rest.orgjson.JSONObject jobj =new org.datanucleus.api.rest.orgjson.JSONObject();
jobj.put("iaAnnotationIds",Util.toggleJSONArray(jids));
CachedQuery cq = new CachedQuery(cacheName, Util.toggleJSONObject(jobj));
cq.nextExpirationTimeout = System.currentTimeMillis() + (15*60*1000);
qc.addCachedQuery(cq);
}

org.datanucleus.api.rest.orgjson.JSONObject jobj = Util.toggleJSONObject(
qc.getQueryByName(cacheName).getJSONSerializedQueryResult());
jids = Util.toggleJSONArray(jobj.getJSONArray("iaAnnotationIds"));
} else {
jids = apiGetJSONArray("/api/annot/json/", context);
if (jids != null) {
org.datanucleus.api.rest.orgjson.JSONObject jobj =
new org.datanucleus.api.rest.orgjson.JSONObject();
jobj.put("iaAnnotationIds", Util.toggleJSONArray(jids));
CachedQuery cq = new CachedQuery(cacheName, Util.toggleJSONObject(jobj));
cq.nextExpirationTimeout = System.currentTimeMillis() + (15 * 60 * 1000);
qc.addCachedQuery(cq);
}
}


}
catch (Exception ex) {
} catch (Exception ex) {
ex.printStackTrace();
IA.log("ERROR: WildbookIAM.iaAnnotationIds() returning empty; failed due to " +
ex.toString());
Expand Down

0 comments on commit fc6d435

Please sign in to comment.