diff --git a/devops/deploy/.dockerfiles/nginx/nginx-https.conf b/devops/deploy/.dockerfiles/nginx/nginx-https.conf index c2f2919967..47e1e2c644 100644 --- a/devops/deploy/.dockerfiles/nginx/nginx-https.conf +++ b/devops/deploy/.dockerfiles/nginx/nginx-https.conf @@ -1,16 +1,8 @@ -# this is an UNSUPPORTED file. +# this is an UNSUPPORTED file, but is maintained as a rough template. # it is only included as possible suggestions for people looking to # do their own https support using something like certbot to generate the # certs. -# TODO forward port 80 to https -#server { - #listen 80; - #server_name 0.0.0.0; - - - - server { listen 443 ssl; server_name wildbook.example.com; diff --git a/src/main/java/org/ecocean/Annotation.java b/src/main/java/org/ecocean/Annotation.java index ec502f0dbc..5f96a0e9c6 100644 --- a/src/main/java/org/ecocean/Annotation.java +++ b/src/main/java/org/ecocean/Annotation.java @@ -1,7 +1,4 @@ -/* - TODO note: this is very ibeis-specific concept of "Annotation" - we should probably consider a general version which can be manipulated into an ibeis one somehow - */ + package org.ecocean; import java.awt.Rectangle; @@ -26,11 +23,9 @@ import org.json.JSONArray; import org.json.JSONObject; -// import java.time.LocalDateTime; - public class Annotation implements java.io.Serializable { - public Annotation() {} // empty for jdo - private String id; // TODO java.util.UUID ? + public Annotation() {} + private String id; private static final String[][] VALID_VIEWPOINTS = new String[][] { { "up", "up", "up", "up", "up", "up", "up", "up", }, { "upfront", "upfrontright", "upright", "upbackright", "upback", "upbackleft", "upleft", @@ -43,7 +38,7 @@ public Annotation() {} // empty for jdo }; private String species; - private String iaClass; // This is just how it gonna be for now. Swap the methods to draw from Taxonomy later if ya like? + private String iaClass; private String name; private boolean isExemplar = false; @@ -53,10 +48,10 @@ public Annotation() {} // empty for jdo protected String acmId; // this is used to decide "should we match against this" problem is: that is not very (IA-)algorithm agnostic - // hoping this will be obsoleted by ACM and friends + // TODO: was this made obsolete by ACM and friends? private boolean matchAgainst = false; -////// these will go away after transition to Features + // TODO: can these (thru mediaAsset) be removed now that there Features? private int x; private int y; private int width; @@ -83,7 +78,7 @@ public Annotation() {} // empty for jdo // ~'annot_tags': 'TEXT', private MediaAsset mediaAsset = null; -////// end of what will go away + // end of what will go away // the "trivial" Annotation - will have a single feature which references the total MediaAsset public Annotation(String species, MediaAsset ma) { @@ -120,20 +115,6 @@ public Annotation(String species, ArrayList f, String iaClass) { this.iaClass = iaClass; } -/* - public Annotation(MediaAsset ma, String species, int x, int y, int w, int h, float[] tm) { - this.id = org.ecocean.Util.generateUUID(); - this.x = x; - this.y = y; - this.width = w; - this.height = h; - this.transformMatrix = tm; - this.theta = 0.0; - this.species = species; - this.mediaAsset = ma; - } - */ - // this is for use *only* to migrate old-world Annotations to new-world public Feature migrateToFeatures() { Feature f; @@ -259,17 +240,13 @@ public Taxonomy getTaxonomy(Shepherd myShepherd) { return enc.getTaxonomy(myShepherd); } - // TODO this needs to be fixed to mean "has the unity feature"... i think(!?) -- but migrating to features needs a legacy-compatible version! - // ouch - // good luck on that one, jon public boolean isTrivial() { MediaAsset ma = this.getMediaAsset(); if (ma == null) return false; for (Feature ft : getFeatures()) { - if (ft.isUnity()) return true; // TODO what *really* of multiple features?? does "just one unity" make sense? + if (ft.isUnity()) return true; } - // see note above. this is to attempt to be backwards-compatible. :/ "untested" return (!needsTransform() && (getWidth() == (int)ma.getWidth()) && (getHeight() == (int)ma.getHeight())); } @@ -392,12 +369,11 @@ JSONObject iaViewpointFromAnnotUUID(String uuid, String context) throws RuntimeE NoSuchAlgorithmException, InvalidKeyException { */ -// FIXME this all needs to be deprecated once deployed sites are migrated +// TODO: Deprecate "all of this" now that deployed sites are migrated public MediaAsset __getMediaAsset() { return mediaAsset; } - // TODO what should we do for multiple features that point to more than one MediaAsset ? public MediaAsset getMediaAsset() { ArrayList fts = getFeatures(); @@ -406,32 +382,17 @@ public MediaAsset getMediaAsset() { " is featureless, falling back to deprecated __getMediaAsset(). please fix!"); return __getMediaAsset(); } - return fts.get(0).getMediaAsset(); // should this instead return first feature *that has a MediaAsset* ?? + return fts.get(0).getMediaAsset(); } public boolean hasMediaAsset() { return (getMediaAsset() != null); } -/* deprecated public void setMediaAsset(MediaAsset ma) { - mediaAsset = ma; - } - */ - - // get the MediaAsset created using this Annotation TODO make this happen public MediaAsset getDerivedMediaAsset() { return null; } -/* - public void setMediaAsset(MediaAsset ma) { - mediaAsset = ma; - if ((ma.getAnnotationCount() == 0) || !ma.getAnnotations().contains(this)) { - ma.getAnnotations().add(this); - } - } - */ - // detaches this Annotation from MediaAsset by removing the corresponding feature *from the MediaAsset* // (the Feature is deleted forever, tho!) public MediaAsset detachFromMediaAsset() { @@ -468,15 +429,13 @@ public int relativePosition() { return anns.indexOf(this); } - // standard -1, 0, 1 expected - // fbow, return 0 if "not comparable"... :/ - // note that this does not assume they are the same MediaAsset... fwiw? + // standard -1, 0, 1 expected; return 0 if "not comparable" + // note that this does not assume they are the same MediaAsset public int comparePositional(Annotation other) { if (other == null) return 0; if ((Util.collectionSize(this.getFeatures()) * Util.collectionSize(other.getFeatures())) == - 0) return 0; // no features, oops - // i have *no idea* how we should handle *multiple Features* here... so i am just going to look for any non-zero response as "useful" :( - // thus we do NxM comparing all Feature combinations; which seems like it might suck but i think we "almost always" only have one! + 0) return 0; + // We currently do NxM comparing all Feature combinations (potentially excessive but typically single feature so unneeded) for (Feature f1 : this.getFeatures()) { for (Feature f2 : other.getFeatures()) { if (!f1.equals(f2)) { @@ -601,31 +560,6 @@ public int[] getBbox() { return bbox; } -/* TODO should this use the IBEIS-IA attribute names or what? - public JSONObject toJSONObject() { - JSONObject obj = new JSONObject(); - obj.put("annot_uuid", annot_uuid); - obj.put("annot_xtl", annot_xtl); - obj.put("annot_ytl", annot_ytl); - obj.put("annot_width", annot_width); - obj.put("annot_height", annot_height); - obj.put("annot_theta", annot_theta); - obj.put("species_text", species_text); - obj.put("image_uuid", this.mediaAsset.getUUID()); - obj.put("name_text", name_text); - return obj; - } - */ - -/* we no longer make a MediaAsset "from an Annotation", but rather from its associated Feature(s) public MediaAsset createMediaAsset() throws - IOException { - if (mediaAsset == null) return null; - if (this.isTrivial()) return null; //we shouldnt make a new MA that is identical, right? - HashMap hmap = new HashMap(); - hmap.put("annotation", this); - return mediaAsset.updateChild("annotation", hmap); - } - */ public String getBboxAsString() { return Arrays.toString(this.getBbox()); } @@ -636,20 +570,9 @@ public String toString() { .append("species", species) .append("iaClass", iaClass) .append("bbox", getBbox()) -/* - //.append("transform", ((getTransformMatrix == null) ? null : Arrays.toString(getTransformMatrix()))) - .append("transform", Arrays.toString(getTransformMatrix())) - .append("asset", mediaAsset) - */ .toString(); } -/* - public MediaAsset getCorrespondingMediaAsset(Shepherd myShepherd) { - return MediaAsset.findByAnnotation(this, myShepherd); - } - */ - // *for now* this will only(?) be called from an Encounter, which means that Encounter must be sanitized // so we assume this *must* be sanitized too. public org.datanucleus.api.rest.orgjson.JSONObject sanitizeJson(HttpServletRequest request, @@ -680,11 +603,7 @@ public org.datanucleus.api.rest.orgjson.JSONObject sanitizeJson(HttpServletReque return this.sanitizeJson(request, false); } -///////////////////// TODO fix this for Feature upgrade //////////////////////// - /** - * returns only the MediaAsset sanitized JSON, because whenever UI queries our DB (regardless of class query), all they want in return are - * MediaAssets TODO: add metadata? - **/ + // returns only the MediaAsset sanitized JSON, because whenever UI queries our DB (regardless of class query), all they want in return are public org.datanucleus.api.rest.orgjson.JSONObject sanitizeMedia(HttpServletRequest request, boolean fullAccess) throws org.datanucleus.api.rest.orgjson.JSONException { @@ -821,7 +740,6 @@ else if (specificEpithet.equals("sp")) { return getMatchingSetForFilter(myShepherd, filter); } - // figgeritout public ArrayList getMatchingSetForTaxonomy(Shepherd myShepherd, JSONObject params) { Encounter enc = this.findEncounter(myShepherd); @@ -831,7 +749,6 @@ public ArrayList getMatchingSetForTaxonomy(Shepherd myShepherd, JSON } // pass in a generic SELECT filter query string and get back Annotations - // currently not taking params, but we can add later if we find useful (for now just trusting filter!) static public ArrayList getMatchingSetForFilter(Shepherd myShepherd, String filter) { if (filter == null) return null; @@ -877,11 +794,6 @@ private String getMatchingSetFilterViewpointClause(Shepherd myShepherd) { String[] viewpoints = this.getViewpointAndNeighbors(); if (viewpoints == null) return ""; - // else if(getSpecies(myShepherd)!=null && getSpecies(myShepherd).equals("Tursiops truncatus")) || (getSpecies(myShepherd)!=null && - // getSpecies(myShepherd).equals("Orcinus orca"))|| (getSpecies(myShepherd)!=null && getSpecies(myShepherd).equals("Tursiops aduncus")) || - // (getSpecies(myShepherd)!=null && getSpecies(myShepherd).equals("Tursiops sp.")) || (getSpecies(myShepherd)!=null && - // getSpecies(myShepherd).equals("Delphinus delphis")) return ""; - // if explicitly told to ignore viewpoint matching, skip this step else if (getTaxonomy(myShepherd) != null && IA.getProperty(myShepherd.getContext(), "ignoreViewpointMatching", getTaxonomy(myShepherd)) != null && IA.getProperty(myShepherd.getContext(), @@ -939,25 +851,13 @@ private String getMatchingSetFilterFromParameters(JSONObject taskParams) { } } } - // TODO we could have an option to skip expansion (i.e. not include children) + List expandedLocationIds = LocationID.expandIDs(rawLocationIds); String locFilter = ""; if (expandedLocationIds.size() > 0) { // locFilter += "enc.locationID == ''"; // loc ID's were breaking for Hawaiian names with apostrophe(s) and stuff, so overkill now - // OLD WAY - /* - for (int i = 0; i < expandedLocationIds.size(); i++) { - String orString = " || "; - if (locFilter.equals("")) orString = ""; - String expandedLoc = expandedLocationIds.get(i); - expandedLoc = expandedLoc.replaceAll("'", "\\\\'"); - locFilter += (orString + "enc.locationID == '" + expandedLoc + "'"); - } - */ - - // NEW WAY String literal = "{"; for (int i = 0; i < expandedLocationIds.size(); i++) { if (i > 0) literal += ","; @@ -982,7 +882,7 @@ private String getMatchingSetFilterFromParameters(JSONObject taskParams) { if (opt.equals("me")) f += " && user.uuid == '" + userId + "' && (enc.submitters.contains(user) || enc.submitterID == user.username) "; - ///TODO also handle "collab" (users you collab with) :/ + // TODO: also handle user "collab" } } // add projectID to filter @@ -1053,30 +953,11 @@ public Encounter findEncounter(Shepherd myShepherd) { return Encounter.findByAnnotation(this, myShepherd); } -/* untested! - public Encounter findEncounterDeep(Shepherd myShepherd) { - Encounter enc = this.findEncounter(myShepherd); - System.out.println(">>>> findEncounterDeep(" + this + ") -> enc1 = " + enc); - if (enc != null) return enc; - MediaAsset ma = this.getMediaAsset(); - System.out.println(" >> findEncounterDeep() -> ma = " + ma + " .... getting Annotations:"); - if (ma == null) return null; - ArrayList anns = ma.getAnnotations(); - for (Annotation ann : anns) { - System.out.println(" >> findEncounterDeep() -> ann = " + ann); - //question: do we *only* look for trivial here? seems like we would want that... cuz we crawl hierarchy only in weird video cases etc if - (ann.isTrivial()) return ann.findEncounterDeep(myShepherd); //recurse! (and effectively bottom-out here... do or die - } - return null; //fall thru, no luck! - } - */ - // this is a little tricky. the idea is the end result will get us an Encounter, which *may* be new // if it is new, its pretty straight forward (uses findEncounter) .. if not, creation is as follows: // look for "sibling" Annotations on same MediaAsset. if one of them has an Encounter, we clone that. // additionally, if one is a trivial annotation, we drop it after. if no siblings are found, we create // an Encounter based on this Annotation (which may get us something, e.g. species, date, loc) - // ###### NOTE: this is going away due to WB-945. (see MediaAsset.assignEncounters() instead) ###### public Encounter toEncounterDEPRECATED(Shepherd myShepherd) { // fairly certain this will *never* happen as code currently stands. this (Annotation) is always new, and // therefore unattached to any Encounter for sure. so skipping this for now! @@ -1098,14 +979,14 @@ public Encounter toEncounterDEPRECATED(Shepherd myShepherd) { return enc; } - /* + /* TODO: evaluate what of these notes are necessary ok, we have sibling Annotations. if one is trivial, we just go for it and replace that one. is this wise? well, if it is the *only* sibling then probably the MediaAsset was attached to the Annotation using legacy (non-IA) methods, and we are "zooming in" on the actual animal. or *one of* the actual animals -- if there are others, they should get added in subsequent iterations of toEncounter(). in theory. - the one case that is still to be considered ( TODO ) is when (theoretically) detection *improves* and we will want a new detection to + the one case that is still to be considered is when (theoretically) detection *improves* and we will want a new detection to replace a *non-trivial* Annotation. but we arent considering that just now! */ @@ -1132,7 +1013,6 @@ the one case that is still to be considered ( TODO ) is when (theoretically) det // do we have an an encounter from the sibling? if (someEnc != null) { for (Annotation ann : sibs) { - // TODO lets make this better at handling part designation if ((ann.getIAClass() == null || this.getIAClass() == null) || ann.getIAClass().equals(this.getIAClass())) { break; } // if these two intersect and have a different detected class they are allowed to reside on the same encounter @@ -1157,7 +1037,6 @@ the one case that is still to be considered ( TODO ) is when (theoretically) det newEnc.setSpecificEpithet(someEnc.getSpecificEpithet()); newEnc.setGenus(someEnc.getGenus()); newEnc.setSex(null); - // myShepherd.storeNewEncounter(newEnc); } catch (Exception e) { e.printStackTrace(); } @@ -1182,44 +1061,8 @@ the one case that is still to be considered ( TODO ) is when (theoretically) det } return newEnc; -/* NOTE: for now i am snipping out this sibling stuff! youtube-sourced frames used this but now doesnt... here for prosperity... - System.out.println(".toEncounter() on " + this + " found no Encounter.... trying to find one on siblings or make one...."); - List sibs = this.getSiblings(); - Annotation sourceSib = null; - Encounter sourceEnc = null; - if (sibs != null) { - //we look for one that has an Encounter, favoring the trivial one (so we can replace it) otherwise any will do for (Annotation sib : sibs) - { - sourceEnc = sib.findEncounter(myShepherd); - if (sourceEnc == null) continue; - sourceSib = sib; - if (sib.isTrivial()) break; //we have a winner - } - } - - System.out.println(" * sourceSib = " + sourceSib + "; sourceEnc = " + sourceEnc); - if (sourceSib == null) return new Encounter(this); //from scratch it is then! - - if (sourceSib.isTrivial()) { - System.out.println("INFO: annot.toEncounter() replaced trivial " + sourceSib + " with " + this + " on " + sourceEnc); - sourceEnc.addAnnotationReplacingUnityFeature(this); - sourceEnc.setSpeciesFromAnnotations(); - return sourceEnc; - } - - enc = sourceEnc.cloneWithoutAnnotations(); - enc.addAnnotation(this); - enc.setSpeciesFromAnnotations(); - return enc; - */ } -/* deprecated, maybe? - public String toHtmlElement(HttpServletRequest request, Shepherd myShepherd) { - if (mediaAsset == null) return ""; - return mediaAsset.toHtmlElement(request, myShepherd, this); - } - */ public Annotation revertToTrivial(Shepherd myShepherd) throws IOException { return this.revertToTrivial(myShepherd, false); @@ -1264,12 +1107,12 @@ public List getRootIATasks(Shepherd myShepherd) { // convenience } public static boolean isValidViewpoint(String vp) { - if (vp == null) return true; // ?? is this desired behavior? + if (vp == null) return true; return getAllValidViewpoints().contains(vp); } public static List getAllValidViewpoints() { - // add code to limit based on IA.properties viewpoints enabled switches if you want i guess + // add code to limit based on IA.properties viewpoints enabled switches List all = new ArrayList<>(); for (int i = 0; i < VALID_VIEWPOINTS.length; i++) { @@ -1299,7 +1142,7 @@ public static ArrayList checkForConflictingIDsforAnnotation(Annotatio } /* - these will update(/create) AnnotationLite.cache for this Annotation note: use sparingly? i.e. should only happen when (related) taxonomy or + these will update(/create) AnnotationLite.cache for this Annotation. should only happen when (related) taxonomy or individual or validForIdentification changes */ public void refreshLiteTaxonomy(String tax) { @@ -1338,8 +1181,6 @@ public void refreshLiteValid(Boolean validForId) { AnnotationLite.setCache(this.acmId, annl); } - // TODO ... other permutations? - public boolean contains(Annotation ann) { Rectangle myRect = getRect(this); Rectangle queryRect = getRect(ann); diff --git a/src/main/java/org/ecocean/AnnotationLite.java b/src/main/java/org/ecocean/AnnotationLite.java index 26e3e73445..b2e1eb9552 100644 --- a/src/main/java/org/ecocean/AnnotationLite.java +++ b/src/main/java/org/ecocean/AnnotationLite.java @@ -16,11 +16,6 @@ import org.json.JSONObject; public class AnnotationLite { - /* - should imageId and individualId be stored as UUID? it is 16 bytes vs 36 (string)... but is it slower to convert? TODO - - also note: we dont (seem to) need imageId, bbox, or theta, as they are available via the ann already - */ // private String imageId; private String individualId = null; // private int[] bbox; @@ -46,25 +41,6 @@ public class AnnotationLite { public AnnotationLite() {} -/* - public AnnotationLite(Annotation ann) { - this(); - if (ann != null) { - if (ann.getMediaAsset() != null) this.setImageId(ann.getMediaAsset().getAcmId()); - this.setBbox(ann.getBbox()); - this.setTheta(ann.getTheta()); - } - } - public AnnotationLite(Annotation ann, String indivId) { - this(ann); - this.setIndividualId(indivId); - } - public AnnotationLite(Annotation ann, String indivId, String tax) { - this(ann); - this.setIndividualId(indivId); - this.setTaxonomy(tax); - } - */ public AnnotationLite(String indivId) { this(); this.setIndividualId(indivId); @@ -89,29 +65,6 @@ public void setValidForIdentification(Boolean b) { validForIdentification = b; } -/* - public String getImageId() { - return imageId; - } - public void setImageId(String id) { - imageId = id; - } - - - public int[] getBbox() { - return bbox; - } - public void setBbox(int[] b) { - bbox = b; - } - - public double getTheta() { - return theta; - } - public void setTheta(double t) { - theta = t; - } - */ public String getIndividualId() { return individualId; } @@ -219,7 +172,7 @@ public static void cacheRead(String filepath) taxonomyList.add(tlist.optString(i, null)); // we add nulls too (snh,flw) to maintain offset } } - // i guess??? we should zero out this cache when reading + // we should zero out this cache when reading cache = new ConcurrentHashMap(); Iterator it = jcache.keys(); while (it.hasNext()) { @@ -253,7 +206,7 @@ public static void cacheRead(String filepath) cache.size() + " objects in " + (System.currentTimeMillis() - t) + "ms"); } - // this reads the cache from disk *and* starts a thread for saving upon shutdown, oy + // this reads the cache from disk *and* starts a thread for saving upon shutdown public static void startup(final ServletContext sContext, final String context) { try { cacheRead(CommonConfiguration.getDataDirectory(sContext, diff --git a/src/main/java/org/ecocean/ApiAccess.java b/src/main/java/org/ecocean/ApiAccess.java index 851be89ddf..67968590d2 100644 --- a/src/main/java/org/ecocean/ApiAccess.java +++ b/src/main/java/org/ecocean/ApiAccess.java @@ -70,7 +70,7 @@ public String checkRequest(Object obj, HttpServletRequest request, JSONObject js // returns map of (negative) permissions for this user (based on role) for this object class // note: no hash key for a property means all access, therefore a null value means user CANNOT write - // TODO this structure is subject to change for sure! + // TODO: this structure is subject to change for sure! public HashMap permissions(Object o, HttpServletRequest request) { return permissions(o.getClass().getName(), request); } @@ -120,7 +120,7 @@ public HashMap permissions(String cname, HttpServletRequest requ Element pel = (Element)props.item(j); String propName = pel.getAttribute("name"); if (propName != null) { - ///////////// TODO for now we assume we ONLY have a sub element for perm here so we skip a step + // TODO: for now we assume we ONLY have a sub element for perm here so we skip a step NodeList proles = pel.getElementsByTagName("role"); boolean allowed = false; for (int k = 0; k < proles.getLength(); k++) { diff --git a/src/main/java/org/ecocean/Cluster.java b/src/main/java/org/ecocean/Cluster.java index f3e05e4017..7d8070af1a 100644 --- a/src/main/java/org/ecocean/Cluster.java +++ b/src/main/java/org/ecocean/Cluster.java @@ -1,3 +1,5 @@ +// TODO: #825 evaluate and remove as deprecated + package org.ecocean; import org.joda.time.DateTime; @@ -79,7 +81,6 @@ public static List fromSmartXml(File smartXmlFile, List Node wnode = wlist.item(w); if (wnode.getNodeType() != Node.ELEMENT_NODE) continue; Element wel = (Element)wnode; // -///////TODO verify that this produces correct output String x = wel.getAttribute("x"); Double decimalLongitude = strToDoubleNoExceptions(x); String y = wel.getAttribute("y"); @@ -105,47 +106,6 @@ public static List fromSmartXml(File smartXmlFile, List System.out.println(" - valid observation found at waypoint id=" + wel.getAttribute("id")); -/* here is an example of stuff we have in an animal observation. not sure if this is exhaustive?? - a whole bunch of these were implemented for lewa in "previous ibeis branch" on the occurrence, such as: - occ.setNumBachMales(int); see Occurrence.java for those... which will need to be ported... :/ TODO - - - - chordata_rl.mammalia_rl.perissodactyla_rl.equidae_rl.equus_rl.equusgrevyi_rl7950. - - - openwoodland - - - 6.0 - - - 6.0 - - - 1.0 - - - 51.0 - - - 7.0 - - - 2.0 - - - 2.0 - - - 30.0 - - - 1 - - - - */ Occurrence occ = new Occurrence(); occ.setOccurrenceID(Util.generateUUID()); occ.setDecimalLatitude(decimalLatitude); @@ -154,7 +114,6 @@ public static List fromSmartXml(File smartXmlFile, List Integer photoOffset = null; NodeList alist = oel.getElementsByTagName("attributes"); - // TODO this is where we would build out the Occurrence if (alist.getLength() > 0) { for (int a = 0; a < alist.getLength(); a++) { Node anode = alist.item(a); @@ -173,37 +132,7 @@ public static List fromSmartXml(File smartXmlFile, List " > assets.size() " + assets.size()); } break; - /* legacy zebra stuff - case "habitat": - occ.setHabitat(getValueString(ael)); - break; - case "bearing": - occ.setBearing(getValueDouble(ael)); - break; - case "groupsize": - occ.setGroupSize(getValueDoubleAsInt(ael)); - break; - case "noofbm": - occ.setNumBachMales(getValueDoubleAsInt(ael)); - break; - case "nooftm": - occ.setNumTerMales(getValueDoubleAsInt(ael)); - break; - case "distancem": - occ.setDistance(getValueDouble(ael)); - break; - case "noofnlf": - occ.setNumNonLactFemales(getValueDoubleAsInt(ael)); - break; - case "nooflf": - occ.setNumLactFemales(getValueDoubleAsInt(ael)); - break; - case "numberof612monthsfemales": - // - break; - */ } - // TODO ... do something with the value! } } System.out.println(" - created Occurrence " + occ); @@ -234,16 +163,6 @@ public static List fromSmartXml(File smartXmlFile, List } // persist the occ! } -/* - val.put("time", el.getAttribute("time")); - NodeList anlist = el.getElementsByTagName("attributes"); - if (an.getNodeType() != Node.ELEMENT_NODE) continue; - Element ael = (Element) an; - String aval = ""; - NodeList vl = ael.getElementsByTagName("dValue"); //numeric if (vl.getLength() < 1) vl = - ael.getElementsByTagName("itemKey"); //string if (vl.getLength() > 0) aval = vl.item(0).getTextContent(); - System.out.println(ael.getAttribute("attributeKey") + " -> " + aval); - */ return occs; } @@ -423,11 +342,7 @@ public static String runJonsScript(List assets, Shepherd myShepherd) String output = runPythonCommand(command); int[] occNums = parseJonsOutput(output); List > occurrenceGroups = groupAssetsByJonsOutput(validAssets, occNums); - /* - for (List occGroup : occurrenceGroups) { - Occurrence occ = new Occurrence(occGroup); - myShepherd.storeNewOccurrence(occ); - }*/ + for (int i = 0; i < occurrenceGroups.size(); i++) { List occGroup = occurrenceGroups.get(i); Occurrence occ = new Occurrence(occGroup, myShepherd); diff --git a/src/main/java/org/ecocean/CommonConfiguration.java b/src/main/java/org/ecocean/CommonConfiguration.java index 4879cf0754..c1fb456956 100644 --- a/src/main/java/org/ecocean/CommonConfiguration.java +++ b/src/main/java/org/ecocean/CommonConfiguration.java @@ -215,7 +215,6 @@ public static String getServerURL(Shepherd myShepherd) { return u.toASCIIString().replaceFirst(":80\\b", ""); // hide :80 cuz its tacky } - // TODO maybe these should be private so as not to be overused public static JSONObject getServerInfo(Shepherd myShepherd) { return SystemValue.getJSONObject(myShepherd, "SERVER_INFO"); } @@ -519,11 +518,6 @@ public static String getGoogleAnalyticsId(String context) { context).getProperty("ga_id", context); } - /* - public static String getGoogleSearchKey(String context) { - return getProperty("googleSearchKey",context); - } - */ public static String getDefaultGoogleMapsCenter(String context) { if (getProperty("googleMapsCenter", context) != null) { return getProperty("googleMapsCenter", context); @@ -647,7 +641,6 @@ private static boolean parseBoolean(String s, boolean def) { * @return Fully-qualified class name of the plugin to use, or null. */ public static String getBatchUploadPlugin(String context) { - // initialize(context); if (getProperty("batchUploadPlugin", context) != null) { return getProperty("batchUploadPlugin", context).trim(); } @@ -782,7 +775,7 @@ public static boolean showReleaseDate(String context) { public static String appendEmailRemoveHashString(HttpServletRequest request, String originalString, String emailAddress, String context) { - return null; // disabled via issue #397 + return null; } public static Map getIndexedValuesMap(String baseKey, String context) { @@ -894,7 +887,6 @@ public static String getDataDirectoryName(String context) { initialize(context); String dataDirectoryName = "shepherd_data_dir"; // new context code here - // if(props.getProperty("dataDirectoryName")!=null){return props.getProperty("dataDirectoryName").trim();} if ((ContextConfiguration.getDataDirForContext(context) != null) && (!ContextConfiguration.getDataDirForContext(context).trim().equals(""))) { dataDirectoryName = ContextConfiguration.getDataDirForContext(context); diff --git a/src/main/java/org/ecocean/Encounter.java b/src/main/java/org/ecocean/Encounter.java index cb8e7128b3..dc43900bb4 100644 --- a/src/main/java/org/ecocean/Encounter.java +++ b/src/main/java/org/ecocean/Encounter.java @@ -66,22 +66,14 @@ public class Encounter extends Base implements java.io.Serializable { @Override public String opensearchIndexName() { return "encounter"; } - // at least one frame/image (e.g. from YouTube detection) must have this confidence or encounter will be ignored public static final double ENCOUNTER_AUTO_SOURCE_CONFIDENCE_CUTOFF = 0.7; public static final String STATE_AUTO_SOURCED = "auto_sourced"; - /** - * The following attributes are described in the Darwin Core quick reference at: - * http://rs.tdwg.org/dwc/terms/#dcterms:type - *

- * Wherever possible, this class will be extended with Darwin Core attributes for greater adoption of the standard. - */ private String sex = null; private String locationID = null; private Double maximumDepthInMeters; private Double maximumElevationInMeters; private String catalogNumber = ""; - // private String individualID; private MarkedIndividual individual; private int day = 0; private int month = -1; @@ -110,7 +102,6 @@ public class Encounter extends Base implements java.io.Serializable { public String country; public String zebraClass = ""; // via lewa: lactating female, territorial male, etc etc - // fields from Dan's sample csv private String imageSet; private String soil; @@ -158,9 +149,6 @@ public void setSampleTakenForDiet(Boolean sampleTakenForDiet) { private static HashMap > _matchEncounterCache = new HashMap >(); - /* - * The following fields are specific to this mark-recapture project and do not have an easy to map Darwin Core equivalent. - */ // An URL to a thumbnail image representing the encounter. private String dwcImageURL; @@ -226,22 +214,9 @@ public void setSampleTakenForDiet(Boolean sampleTakenForDiet) { private String gpsLongitude = "", gpsLatitude = ""; private String gpsEndLongitude = "", gpsEndLatitude = ""; - // whether this encounter has been rejected and should be hidden from public display - // unidentifiable encounters generally contain some data worth saving but not enough for accurate photo-identification - // private boolean unidentifiable = false; - // whether this encounter has a left-side spot image extracted - // public boolean hasSpotImage = false; - // whether this encounter has a right-side spot image extracted - // public boolean hasRightSpotImage = false; - // Indicates whether this record can be exposed via TapirLink private boolean okExposeViaTapirLink = false; - // whether this encounter has been approved for public display - // private boolean approved = true; - // integers of the latitude and longitude degrees - // private int lat=-1000, longitude=-1000; - // name of the stored file from which the left-side spots were extracted public String spotImageFileName = ""; // name of the stored file from which the right-side spots were extracted @@ -252,10 +227,6 @@ public void setSampleTakenForDiet(Boolean sampleTakenForDiet) { public String distinguishingScar = "None"; // describes how this encounter was matched to an existing shark - by eye, by pattern recognition algorithm etc. - // DEPRECATING OLD DATA CONSTRUCT - // private int numSpotsLeft = 0; - // private int numSpotsRight = 0; - // SPOTS // an array of the extracted left-side superSpots // private superSpot[] spots; @@ -343,7 +314,7 @@ public Encounter(boolean skipSetup) { * Use this constructor to add the minimum level of information for a new encounter The Vector additionalImages must be a Vector of * Blob objects * - * NOTE: technically this is DEPRECATED cuz, SinglePhotoVideos? really? + * TODO: evaluate and remove if this is DEPRECATED cuz, SinglePhotoVideos? really? */ public Encounter(int day, int month, int year, int hour, String minutes, String size_guess, String location) { @@ -351,11 +322,6 @@ public Encounter(int day, int month, int year, int hour, String minutes, String System.out.println( "WARNING: danger! deprecated SinglePhotoVideo-based Encounter constructor used!"); this.verbatimLocality = location; - // this.recordedBy = submitterName; - // this.submitterEmail = submitterEmail; - - // now we need to set the hashed form of the email addresses - // this.hashedSubmitterEmail = Encounter.getHashOfEmailString(submitterEmail); this.images = images; this.day = day; @@ -566,12 +532,10 @@ public String addAllImageNamesFromAnnots() { * @return the array of superSpots, taken from the croppedImage, that make up the digital fingerprint for this encounter */ public ArrayList getSpots() { - // return HACKgetSpots(); return spots; } public ArrayList getRightSpots() { - // return HACKgetRightSpots(); return rightSpots; } @@ -580,7 +544,8 @@ public ArrayList getRightSpots() { * * @return the array of superSpots, taken from the croppedImage, that make up the digital fingerprint for this encounter */ -/* these have gone away! dont be setting spots on Encounter any more .... NOT SO FAST... we regress for whaleshark.org... */ +/* TODO: evaluate if this is deprecate and can be removed + these have gone away! dont be setting spots on Encounter any more .... NOT SO FAST... we regress for whaleshark.org... */ public void setSpots(ArrayList newSpots) { spots = newSpots; } @@ -694,20 +659,10 @@ public void nukeAllSpots() { */ public int getNumSpots() { return (spots == null) ? 0 : spots.size(); -/* - ArrayList fakeSpots = HACKgetSpots(); - if(fakeSpots!=null){return fakeSpots.size();} - else{return 0;} - */ } public int getNumRightSpots() { return (rightSpots == null) ? 0 : rightSpots.size(); -/* - ArrayList fakeRightSpots = HACKgetRightSpots(); - if(fakeRightSpots!=null){return fakeRightSpots.size();} - else{return 0;} - */ } public boolean hasLeftSpotImage() { @@ -718,18 +673,13 @@ public boolean hasRightSpotImage() { return (this.getNumRightSpots() > 0); } - /** - * Sets the recorded length of the shark for this encounter. - */ + + // Sets the recorded length of the shark for this encounter. public void setSize(Double mysize) { if (mysize != null) { size = mysize; } else { size = null; } } - /** - * Returns the recorded length of the shark for this encounter. - * - * @return the length of the shark - */ + // @return the length of the shark public double getSize() { return size.doubleValue(); } @@ -738,18 +688,12 @@ public Double getSizeAsDouble() { return size; } - /** - * Sets the units of the recorded size and depth of the shark for this encounter. Acceptable entries are either "Feet" or "Meters" - */ + // Sets the units of the recorded size and depth of the shark for this encounter. Acceptable entries are either "Feet" or "Meters" public void setMeasureUnits(String measure) { measurementUnit = measure; } - /** - * Returns the units of the recorded size and depth of the shark for this encounter. - * - * @return the units of measure used by the recorded of this encounter, either "feet" or "meters" - */ + // @return the units of measure used by the recorded of this encounter, either "feet" or "meters" public String getMeasureUnits() { return measurementUnit; } @@ -758,11 +702,7 @@ public String getMeasurementUnit() { return measurementUnit; } - /** - * Returns the recorded location of this encounter. - * - * @return the location of this encounter - */ + // @return the location of this encounter public String getLocation() { return verbatimLocality; } @@ -771,27 +711,17 @@ public void setLocation(String location) { this.verbatimLocality = location; } - /** - * Sets the recorded sex of the shark in this encounter. Acceptable values are "Male" or "Female" - */ + // Sets the recorded sex of the shark in this encounter. Acceptable values are "Male" or "Female" public void setSex(String thesex) { if (thesex != null) { sex = thesex; } else { sex = null; } } - /** - * Returns the recorded sex of the shark in this encounter. - * - * @return the sex of the shark, either "male" or "female" - */ + // @return the sex of the shark, either "male" or "female" public String getSex() { return sex; } - /** - * Returns any submitted comments about scarring on the shark. - * - * @return any comments regarding observed scarring on the shark's body - */ + // @return any comments regarding observed scarring on the shark's body public boolean getMmaCompatible() { if (mmaCompatible == null) return false; return mmaCompatible; @@ -801,38 +731,22 @@ public void setMmaCompatible(boolean b) { mmaCompatible = b; } - /** - * Returns Occurrence Remarks. - * - * @return Occurrence Remarks String - */ + // @return Occurrence Remarks String @Override public String getComments() { return occurrenceRemarks; } - /** - * Sets the initially submitted comments about markings and additional details on the shark. - * - * @param newComments Occurrence remarks to set - */ + // @param newComments Occurrence remarks to set @Override public void setComments(String newComments) { occurrenceRemarks = newComments; } - /** - * Returns any comments added by researchers - * - * @return any comments added by authroized researchers - */ + // @return any comments added by authroized researchers public String getRComments() { return researcherComments; } - /** - * Adds additional comments about the encounter - * - * @param newComments any additional comments to be added to the encounter - */ + // @param newComments any additional comments to be added to the encounter @Override public void addComments(String newComments) { if ((researcherComments != null) && (!(researcherComments.equals("None")))) { researcherComments += newComments; @@ -841,11 +755,7 @@ public String getRComments() { } } - /** - * Returns the name of the person who submitted this encounter data. - * - * @return the name of the person who submitted this encounter to the database - */ + // @return the name of the person who submitted this encounter to the database public String getSubmitterName() { return recordedBy; } @@ -858,11 +768,7 @@ public void setSubmitterName(String newname) { } } - /** - * Returns the e-mail address of the person who submitted this encounter data - * - * @return the e-mail address of the person who submitted this encounter data - */ + // @return the e-mail address of the person who submitted this encounter data public String getSubmitterEmail() { return submitterEmail; } @@ -877,18 +783,12 @@ public void setSubmitterEmail(String newemail) { } } - /** - * Returns the phone number of the person who submitted this encounter data. - * - * @return the phone number of the person who submitted this encounter data - */ + // @return the phone number of the person who submitted this encounter data public String getSubmitterPhone() { return submitterPhone; } - /** - * Sets the phone number of the person who submitted this encounter data. - */ + // Sets the phone number of the person who submitted this encounter data. public void setSubmitterPhone(String newphone) { if (newphone == null) { submitterPhone = null; @@ -897,18 +797,12 @@ public void setSubmitterPhone(String newphone) { } } - /** - * Returns the mailing address of the person who submitted this encounter data. - * - * @return the mailing address of the person who submitted this encounter data - */ + // @return the mailing address of the person who submitted this encounter data public String getSubmitterAddress() { return submitterAddress; } - /** - * Sets the mailing address of the person who submitted this encounter data. - */ + // Sets the mailing address of the person who submitted this encounter data. public void setSubmitterAddress(String address) { if (address == null) { submitterAddress = null; @@ -917,18 +811,12 @@ public void setSubmitterAddress(String address) { } } - /** - * Returns the name of the person who took the primaryImage this encounter. - * - * @return the name of the photographer who took the primary image for this encounter - */ + // @return the name of the photographer who took the primary image for this encounter public String getPhotographerName() { return photographerName; } - /** - * Sets the name of the person who took the primaryImage this encounter. - */ + // @return the name of the photographer who took the primary image for this encounter public void setPhotographerName(String name) { if (name == null) { photographerName = null; @@ -937,18 +825,12 @@ public void setPhotographerName(String name) { } } - /** - * Returns the e-mail address of the person who took the primaryImage this encounter. - * - * @return @return the e-mail address of the photographer who took the primary image for this encounter - */ + // @return the e-mail address of the photographer who took the primary image for this encounter public String getPhotographerEmail() { return photographerEmail; } - /** - * Sets the e-mail address of the person who took the primaryImage this encounter. - */ + // Sets the e-mail address of the person who took the primaryImage this encounter. public void setPhotographerEmail(String email) { if (email == null) { photographerEmail = null; @@ -959,11 +841,7 @@ public void setPhotographerEmail(String email) { } } - /** - * Returns the phone number of the person who took the primaryImage this encounter. - * - * @return the phone number of the photographer who took the primary image for this encounter - */ + // @return the phone number of the photographer who took the primary image for this encounter public String getPhotographerPhone() { return photographerPhone; } @@ -1038,19 +916,7 @@ public static String getWebUrl(String encId, String serverUrl) { return (serverUrl + "/encounters/encounter.jsp?number=" + encId); } - // public String getHyperlink(HttpServletRequest req, int labelLength) { - // String label=""; - // if (labelLength==1) label = "Enc "; - // if (labelLength> 1) label = "Encounter "; - // return ""+label+getCatalogNumber()+ ""; - // } - // public String getHyperlink(HttpServletRequest req) { - // return getHyperlink(req, 1); - // } - - /** - * Sets the phone number of the person who took the primaryImage this encounter. - */ + // Sets the phone number of the person who took the primaryImage this encounter. public void setPhotographerPhone(String phone) { if (phone == null) { photographerPhone = null; @@ -1059,18 +925,12 @@ public void setPhotographerPhone(String phone) { } } - /** - * Returns the mailing address of the person who took the primaryImage this encounter. - * - * @return the mailing address of the photographer who took the primary image for this encounter - */ + // @return the mailing address of the photographer who took the primary image for this encounter public String getPhotographerAddress() { return photographerAddress; } - /** - * Sets the mailing address of the person who took the primaryImage this encounter. - */ + // Sets the mailing address of the person who took the primaryImage this encounter. public void setPhotographerAddress(String address) { if (address == null) { photographerAddress = null; @@ -1079,20 +939,14 @@ public void setPhotographerAddress(String address) { } } - /** - * Sets the recorded depth of this encounter. - */ + // Sets the recorded depth of this encounter. public void setDepth(Double myDepth) { if (myDepth != null) { maximumDepthInMeters = myDepth; } else { maximumDepthInMeters = null; } } - /** - * Returns the recorded depth of this encounter. - * - * @return the recorded depth for this encounter - */ + // @return the recorded depth for this encounter public double getDepth() { return maximumDepthInMeters.doubleValue(); } @@ -1101,17 +955,10 @@ public Double getDepthAsDouble() { return maximumDepthInMeters; } - // public Vector getAdditionalImages() {return additionalImages;} - - /** - * Returns the file names of all images taken for this encounter. - * - * @return a vector of image name Strings - */ + // @return a vector of image name Strings public Vector getAdditionalImageNames() { Vector imageNamesOnly = new Vector(); - // List images=getCollectedDataOfClass(SinglePhotoVideo.class); if ((images != null) && (images.size() > 0)) { int imagesSize = images.size(); for (int i = 0; i < imagesSize; i++) { @@ -1153,61 +1000,7 @@ public String getImageOriginalName() { return ma.getFilename(); } - /** - * Adds another image to the collection of images for this encounter. These images should be the additional or non-side shots. - * - - public void addAdditionalImageName(SinglePhotoVideo file) { - images.add(file); - - } - */ -/* - public void approve() { - approved = true; - okExposeViaTapirLink = true; - } - */ -/** - public void resetAdditionalImageName(int position, String fileName) { - additionalImageNames.set(position, fileName); - //additionalImageNames.add(fileName); - } - */ - - /** - * Removes the specified additional image from this encounter. - * - * @param imageFile the image to be removed from the additional images stored for this encounter - */ - /* - public void removeAdditionalImageName(String imageFile) { - - for (int i = 0; i < collectedData.size(); i++) { - - - String thisName = images.get(i).getFilename(); - if ((thisName.equals(imageFile)) || (thisName.indexOf("#") != -1)) { - images.remove(i); - i--; - } - - } - - - } - */ - - /* - public void removeDataCollectionEvent(DataCollectionEvent dce) { - collectedData.remove(dce); - } - */ - /** - * Returns the unique encounter identifier number for this encounter. - * - * @return a unique integer String used to identify this encounter in the database - */ + // @return a unique integer String used to identify this encounter in the database public String getEncounterNumber() { return catalogNumber; } @@ -1245,12 +1038,7 @@ public static String subdir(String id) { return d; } - /** - * Returns the date of this encounter. - * - * @return a Date object - * @see java.util.Date - */ + // @return a Date object public String getDate() { String date = ""; String time = ""; @@ -1291,11 +1079,7 @@ public String getShortDate() { return date; } - /** - * Returns the String discussing how the size of this animal was approximated. - * - * @return a String with text about how the size of this animal was estimated/measured - */ + // @return a String with text about how the size of this animal was estimated/measured public String getSizeGuess() { return size_guess; } @@ -1357,43 +1141,27 @@ public boolean wasInPeriod(DateTime start, DateTime end) { return (start.getMillis() <= thisTime && end.getMillis() >= thisTime); } - /** - * Returns the String holding specific location data used for searching - * - * @return the String holding specific location data used for searching - */ + // @return the String holding specific location data used for searching public String getLocationCode() { return locationID; } - /** - * A legacy method replaced by setLocationID(...). - * - * - */ + // TODO: Verify and remove if this is deprecated: A legacy method replaced by setLocationID(...). public void setLocationCode(String newLoc) { setLocationID(newLoc); } - /** - * Returns the String holding specific location data used for searching - * - * @return the String holding specific location data used for searching - */ + // @return the String holding specific location data used for searching public String getDistinguishingScar() { return distinguishingScar; } - /** - * Sets the String holding scarring information for the encounter - */ + // Sets the String holding scarring information for the encounter public void setDistinguishingScar(String scar) { distinguishingScar = scar; } - /** - * Sets the String documenting how the size of this animal was approximated. - */ + // Sets the String documenting how the size of this animal was approximated. public void setSizeGuess(String newGuess) { size_guess = newGuess; } @@ -1455,22 +1223,6 @@ public String getIndividualID() { return individual.getId(); } - /* - public boolean wasRejected() { - - return unidentifiable; - } - - public void reject() { - unidentifiable = true; - //okExposeViaTapirLink=false; - } - - public void reaccept() { - unidentifiable = false; - //okExposeViaTapirLink=true; - } - */ public String getGPSLongitude() { if (gpsLongitude == null) { return ""; @@ -1527,7 +1279,7 @@ public void setRightSpotImageFileName(String name) { // ---------------- - // really only intended to convert legacy SinglePhotoVideo to MediaAsset/Annotation world + // TODO: evaluate and remove if this has been deprecated: really only intended to convert legacy SinglePhotoVideo to MediaAsset/Annotation world public ArrayList generateAnnotations(String baseDir, Shepherd myShepherd) { if ((annotations != null) && (annotations.size() > 0)) return annotations; if ((images == null) || (images.size() < 1)) return null; // probably pointless, so... @@ -1561,11 +1313,8 @@ public ArrayList generateAnnotations(String baseDir, Shepherd myShep haveMedia.add(ma); annotations.add(new Annotation(getTaxonomyString(), ma)); - // if (!media.contains(ma)) media.add(ma); - // File idir = new File(this.dir(baseDir)); File idir = new File(spv.getFullFileSystemPath()).getParentFile(); - // now we iterate through flavors that could be derived - // TODO is it bad to assume ".jpg" ? i forget! + addMediaIfNeeded(myShepherd, new File(idir, spv.getDataCollectionEventID() + ".jpg"), "spv/" + spv.getDataCollectionEventID() + "/" + spv.getDataCollectionEventID() + ".jpg", ma, "_watermark"); @@ -1624,8 +1373,6 @@ private MediaAsset addMediaIfNeeded(Shepherd myShepherd, File mpath, String key, } // this makes assumption (for flukes) that both right and left image files are identical - // TODO handle that they are different - // TODO also maybe should reuse addMediaIfNeeded() for some of this where redundant public MediaAsset spotImageAsMediaAsset(MediaAsset parent, String baseDir, Shepherd myShepherd) { if ((spotImageFileName == null) || spotImageFileName.equals("")) return null; @@ -1692,22 +1439,6 @@ public void addInterestedResearcher(String email) { interestedResearchers.add(email); } - /* - public boolean isApproved() { - return approved; - } - */ - - /* - public void removeInterestedResearcher(String email) { - for (int i = 0; i < interestedResearchers.size(); i++) { - String rName = (String) interestedResearchers.get(i); - if (rName.equals(email)) { - interestedResearchers.remove(i); - } - } - } - */ public double getRightmostSpot() { double rightest = 0; ArrayList spots = getSpots(); @@ -1874,10 +1605,7 @@ public void setRightReferenceSpots(ArrayList rightReferenceSpots) { this.rightReferenceSpots = rightReferenceSpots; } - /** - * @param population array values to get the variance for - * @return the variance - */ + // @return the variance for population public double variance(double[] population) { long n = 0; double mean = 0; @@ -1895,22 +1623,11 @@ public double variance(double[] population) { return (s / (n - 1)); } - /** - * @param population array values to get the standard deviation for - * @return the standard deviation - */ + // @return the standard deviation for population public double standard_deviation(double[] population) { return Math.sqrt(variance(population)); } -/* GONE! no more spots on encounters public void setNumLeftSpots(int numspots) { - numSpotsLeft = numspots; - } - - public void setNumRightSpots(int numspots) { - numSpotsRight = numspots; - } - */ public void setDWCGlobalUniqueIdentifier(String guid) { this.guid = guid; } @@ -1970,15 +1687,9 @@ public void setDWCDateAdded() { public void setDWCDateAdded(Long m_dateAdded) { dwcDateAddedLong = m_dateAdded; - // org.joda.time.DateTime dt=new org.joda.time.DateTime(dwcDateAddedLong.longValue()); - // DateTimeFormatter parser1 = ISODateTimeFormat.dateOptionalTimeParser(); - // setDWCDateAdded(dt.toString(parser1)); - // System.out.println(" Encounter.detDWCDateAded(Long): "+dt.toString(parser1)+" which is also "+m_dateAdded.longValue()); } - // public void setDateAdded(long date){dateAdded=date;} - // public long getDateAdded(){return dateAdded;} - + // TODO: evaluate and remove if deprecated public Date getReleaseDateDONOTUSE() { return releaseDate; } @@ -2041,7 +1752,7 @@ public void setSurveyID(String id) { public void setSurvey() { } - // TODO Get all this lat lon over to Locations + // TODO: Get all this lat lon over to Locations public void setDWCDecimalLatitude(double lat) { if (lat == -9999.0) { @@ -2101,12 +1812,6 @@ public String getOLDInformOthersFORLEGACYCONVERSION() { return informothers; } - /* - public void setInformOthers(String others) { - this.informothers = others; - this.hashedInformOthers = Encounter.getHashOfEmailString(others); - } - */ public String getLocationID() { return locationID; } @@ -2140,48 +1845,36 @@ public void setMaximumElevationInMeters(Double newElev) { this.maximumElevationInMeters = newElev; } - /** - * Retrieves the Catalog Number. - * - * @return Catalog Number String - */ + // @return Catalog Number String @Override public String getId() { return catalogNumber; } - /** - * Sets the Catalog Number. - * - * @param newNumber The Catalog Number to set. - */ + // @param newNumber The Catalog Number to set. @Override public void setId(String newNumber) { this.catalogNumber = newNumber; } - /** - * ##DEPRECATED #509 - Base class getId() method - */ + // TODO: remove if actually deprecated and unused + // ##DEPRECATED #509 - Base class getId() method public String getCatalogNumber() { return catalogNumber; } - /** - * ##DEPRECATED #509 - Base class setId() method - */ + // TODO: remove if actually deprecated and unused + // ##DEPRECATED #509 - Base class setId() method public void setCatalogNumber(String newNumber) { this.catalogNumber = newNumber; } - /** - * ##DEPRECATED #509 - Base class getId() method - */ + // TODO: remove if actually deprecated and unused + // ##DEPRECATED #509 - Base class getId() method public String getID() { return catalogNumber; } - /** - * ##DEPRECATED #509 - Base class setId() method - */ + // TODO: remove if actually deprecated and unused + // ##DEPRECATED #509 - Base class setId() method public void setID(String newNumber) { this.catalogNumber = newNumber; } @@ -2194,8 +1887,6 @@ public void setVerbatimLocality(String vlcl) { this.verbatimLocality = vlcl; } -/* i cant for the life of me figure out why/how gps stuff is stored on encounters, cuz we have some strings and decimal (double, er Double?) values -- - so i am doing my best to standardize on the decimal one (Double) .. half tempted to break out a class for this: lat/lon/alt/bearing etc */ public Double getDecimalLatitudeAsDouble() { return (decimalLatitude == null) ? null : decimalLatitude.doubleValue(); } @@ -2465,7 +2156,7 @@ public String getTaxonomyString() { } // hacky (as generates new Taxonomy -- with random uuid) but still should work for tax1.equals(tax2); - // TODO FIXME this should be superceded by the getter for Taxonomy property in the future.... + // TODO: FIXME this should be superceded by the getter for Taxonomy property in the future.... public Taxonomy getTaxonomy(Shepherd myShepherd) { String sciname = this.getTaxonomyString(); @@ -2510,7 +2201,7 @@ public void setTaxonomyFromIAClass(String iaClass, Shepherd myShepherd) { public String getPatterningCode() { return patterningCode; } public void setPatterningCode(String newCode) { this.patterningCode = newCode; } - // crawls thru assets and sets date.. in an ideal world would do some kinda avg or whatever if more than one TODO? + // crawls thru assets and sets date public void setDateFromAssets() { // FIXME if you dare. i can *promise you* there are some timezone problems here. ymmv. if ((annotations == null) || (annotations.size() < 1)) return; @@ -2635,8 +2326,6 @@ public String getDecimalLatitude() { return null; } - // public void setDecimalLatitude(String lat){this.decimalLatitude=Double.parseDouble(lat);} - public String getDecimalLongitude() { if (decimalLongitude != null) { return Double.toString(decimalLongitude); } return null; @@ -2687,50 +2376,6 @@ public List getProjects(Shepherd myShepherd) { return myShepherd.getProjectsForEncounter(this); } - // public List getCollectedData(){return collectedData;} - - /* - public ArrayList getCollectedDataOfType(String type){ - ArrayList filteredList=new ArrayList(); - int cdSize=collectedData.size(); - System.out.println("cdSize="+cdSize); - for(int i=0;i(); - System.out.println("n annotations = "+annotations.size()); - - for (int i=0; i " + newEnc); groupsMade++; @@ -3285,11 +2900,6 @@ public ArrayList findAllMediaByLabel(Shepherd myShepherd, String lab return MediaAsset.findAllByLabel(getMedia(), myShepherd, label); } -/* - public MediaAsset findOneMediaByLabel(Shepherd myShepherd, String label) { - return MediaAsset.findOneByLabel(media, myShepherd, label); - } - */ public boolean hasKeyword(Keyword word) { int imagesSize = images.size(); @@ -3360,11 +2970,7 @@ public boolean hasBiologicalMeasurement(String type) { return false; } - /** - * Returns the first measurement of the specified type - * @param type - * @return - */ + // Returns the first measurement of the specified type public Measurement getMeasurement(String type) { if ((measurements != null) && (measurements.size() > 0)) { int numMeasurements = measurements.size(); @@ -3646,38 +3252,6 @@ public boolean refreshAssetFormats(Shepherd myShepherd) { NOTE on "thumb.jpg" ... we only get one of these per encounter; and we do not have stored (i dont think?) which SPV it came from! this is a problem, as we cant make a thumb in refreshAssetFormats(req, spv) since we dont know if that is the "right" spv. thus, we have to treat it as a special case. - */ -/* - public boolean refreshAssetFormats(String context, String baseDir) { - boolean ok = true; - //List allSPV = this.getImages(); - boolean thumb = true; - for (SinglePhotoVideo spv : this.getImages()) { - ok &= this.refreshAssetFormats(context, baseDir, spv, thumb); - thumb = false; - } - return ok; - } - - //as above, but for specific SinglePhotoVideo public boolean refreshAssetFormats(String context, String baseDir, SinglePhotoVideo spv, - boolean doThumb) { - if (spv == null) return false; - String encDir = this.dir(baseDir); - - boolean ok = true; - if (doThumb) ok &= spv.scaleTo(context, 100, 75, encDir + File.separator + "thumb.jpg"); - //TODO some day this will be a structure/definition that lives in a config file or on MediaAsset, etc. for now, ya get - hard-coded - - //this will first try watermark version, then regular ok &= (spv.scaleToWatermark(context, 250, 200, encDir + File.separator + - spv.getDataCollectionEventID() + ".jpg", "") || spv.scaleTo(context, 250, 200, encDir + File.separator + - spv.getDataCollectionEventID() + ".jpg")); - - ok &= spv.scaleTo(context, 1024, 768, encDir + File.separator + spv.getDataCollectionEventID() + "-mid.jpg"); //for use in VM - tool etc. (bandwidth friendly?) return ok; - } - - */ // see also: future, MediaAssets public String getThumbnailUrl(String context) { @@ -3725,18 +3299,10 @@ public boolean restAccess(HttpServletRequest request, org.json.JSONObject jsonob String fail = access.checkRequest(this, request, jsonobj); System.out.println("fail -----> " + fail); if (fail != null) throw new Exception(fail); - // HashMap perm = access.permissions(this, request); -// System.out.println(perm); - -/* - System.out.println("!!!----------------------------------------"); - System.out.println(request.getMethod()); - throw new Exception(); - */ return true; } -///////// these are bunk now - dont use Features TODO fix these - perhaps by crawlng thru ma.getAnnotations() ? +///////// these are bunk now - dont use Features TODO: fix these - perhaps by crawlng thru ma.getAnnotations() ? public static Encounter findByMediaAsset(MediaAsset ma, Shepherd myShepherd) { String queryString = "SELECT FROM org.ecocean.Encounter WHERE annotations.contains(ann) && ann.mediaAsset.id ==" @@ -3759,8 +3325,6 @@ public static List findAllByMediaAsset(MediaAsset ma, Shepherd myShep String queryString = "SELECT FROM org.ecocean.Encounter WHERE annotations.contains(ann) && ann.mediaAsset.id ==" + ma.getId(); - // String queryString = "SELECT FROM org.ecocean.Encounter WHERE annotations.contains(ann) && ann.features.contains(mAsset) && mAsset.id - // ==" + ma.getId(); Query query = myShepherd.getPM().newQuery(queryString); Collection results = (Collection)query.execute(); returnEncs = new ArrayList(results); @@ -3803,14 +3367,6 @@ public static Encounter findByAnnotationId(String annid, Shepherd myShepherd) { return findByAnnotation(ann, myShepherd); } -/* not really sure we need this now/yet - - public void refreshDependentProperties() { - this.resetDateInMilliseconds(); - //TODO could possibly do integrity check, re: individuals/occurrences linking? - } - - */ public static ArrayList getEncountersForMatching(String taxonomyString, Shepherd myShepherd) { if (_matchEncounterCache.get(taxonomyString) != null) @@ -3847,11 +3403,6 @@ public ArrayList HACKgetRightSpots() { } public ArrayList HACKgetAnySpots(String which) { -/* - RuntimeException ex = new RuntimeException(" ===== DEPRECATED ENCOUNTER SPOT BEHAVIOR! PLEASE FIX ====="); - System.out.println(ex.toString()); - ex.printStackTrace(); - */ ArrayList mas = findAllMediaByFeatureId( new String[] { "org.ecocean.flukeEdge.edgeSpots", "org.ecocean.dorsalEdge.edgeSpots" }); @@ -3868,11 +3419,6 @@ public ArrayList HACKgetAnySpots(String which) { // err, i think ref spots are the same right or left.... at least for flukes/dorsals. :/ good luck with mantas and whalesharks! public ArrayList HACKgetAnyReferenceSpots() { -/* - RuntimeException ex = new RuntimeException(" ===== DEPRECATED ENCOUNTER SPOT BEHAVIOR! PLEASE FIX ====="); - System.out.println(ex.toString()); - ex.printStackTrace(); - */ ArrayList mas = findAllMediaByFeatureId( new String[] { "org.ecocean.flukeEdge.referenceSpots", "org.ecocean.referenceEdge.edgeSpots" }); @@ -3941,7 +3487,7 @@ public ImportTask getImportTask(Shepherd myShepherd) { } // this is a special state only used now for match.jsp but basically means the data should be mostly hidden and soon deleted, roughly speaking??? - // TODO figure out what this really means + // TODO: figure out what this really means public void setMatchingOnly() { this.setState(STATE_MATCHING_ONLY); } @@ -3955,7 +3501,7 @@ public void detectedAnnotation(Shepherd myShepherd, Annotation ann) { /* note: these are baby steps into proper ownership of Encounters. a similar (but cleaner) attempt is done in MediaAssets... however, really this probably should be upon some (mythical) BASE CLASS!!!! ... for now, this Encounter variation kinda fudges with existing "ownership" stuff, - namely, the submitterID - which maps (in theory!) to a User username. TODO much much much ... incl call via constructor maybe ?? etc. + namely, the submitterID - which maps (in theory!) to a User username. TODO: much much much ... incl call via constructor maybe ?? etc. */ // NOTE: not going to currently persist the AccessControl object yet, but create on the fly... clever? stupid? public AccessControl getAccessControl() { @@ -4447,16 +3993,6 @@ public void opensearchDocumentSerializer(JsonGenerator jgen) encDate = Util.getISO8601Date(encs[encs.length - 1].getDate()); if (encDate != null) jgen.writeStringField("individualLastEncounterDate", encDate); } -/* - this currently is not needed as-is. we instead use just the social unit name as its own property (below) - - jgen.writeObjectFieldStart("individualSocialUnitMap"); - for (SocialUnit su : myShepherd.getAllSocialUnitsForMarkedIndividual(indiv)) { - Membership mem = su.getMembershipForMarkedIndividual(indiv); - if (mem != null) jgen.writeStringField(su.getSocialUnitName(), mem.getRole()); - } - jgen.writeEndObject(); - */ jgen.writeArrayFieldStart("individualSocialUnits"); for (SocialUnit su : myShepherd.getAllSocialUnitsForMarkedIndividual(indiv)) { @@ -4522,20 +4058,6 @@ public void opensearchDocumentSerializer(JsonGenerator jgen) jgen.writeNumberField(type, bmeas.get(type).getValue()); } jgen.writeEndObject(); - -/* not really sure if we need to search on TissueSamples but just putting this in for reference - - this.getTissueSamples() - - private String tissueType; - private String preservationMethod; - private String storageLabID; - private String sampleID; - private String alternateSampleID; - private List analyses; - private String permit; - private String state; - */ myShepherd.rollbackAndClose(); } @@ -4555,10 +4077,6 @@ public org.json.JSONObject opensearchMapping() { org.json.JSONObject keywordType = new org.json.JSONObject("{\"type\": \"keyword\"}"); org.json.JSONObject keywordNormalType = new org.json.JSONObject( "{\"type\": \"keyword\", \"normalizer\": \"wildbook_keyword_normalizer\"}"); -/* - org.json.JSONObject fieldKeywordNormalType = new org.json.JSONObject( - "{\"fields\": {\"keyword\": {\"type\": \"keyword\", \"normalizer\": \"wildbook_keyword_normalizer\"}}, \"type\": \"object\"}"); - */ map.put("date", new org.json.JSONObject("{\"type\": \"date\"}")); map.put("dateSubmitted", new org.json.JSONObject("{\"type\": \"date\"}")); map.put("locationGeoPoint", new org.json.JSONObject("{\"type\": \"geo_point\"}")); @@ -4588,11 +4106,6 @@ public org.json.JSONObject opensearchMapping() { map.put("organizations", keywordNormalType); map.put("otherCatalogNumbers", keywordNormalType); -/* - map.put("mediaAssetLabeledKeywords", fieldKeywordNormalType); - map.put("individualSocialUnits", fieldKeywordNormalType); - */ - // https://stackoverflow.com/questions/68760699/matching-documents-where-multiple-fields-match-in-an-array-of-objects map.put("measurements", new org.json.JSONObject("{\"type\": \"nested\"}")); map.put("metalTags", new org.json.JSONObject("{\"type\": \"nested\"}")); diff --git a/src/main/java/org/ecocean/EncounterQueryProcessor.java b/src/main/java/org/ecocean/EncounterQueryProcessor.java index b15fb774db..a1f1a2934f 100644 --- a/src/main/java/org/ecocean/EncounterQueryProcessor.java +++ b/src/main/java/org/ecocean/EncounterQueryProcessor.java @@ -135,7 +135,6 @@ public static String queryStringBuilder(HttpServletRequest request, StringBuffer " VARIABLES org.ecocean.User user; org.ecocean.Organization org"; jdoqlVariableDeclaration = addOrgVars(variables_statement, filter); } else { - // TODO } // end filter for organization------------------ // filter for projectName------------------- @@ -156,7 +155,6 @@ public static String queryStringBuilder(HttpServletRequest request, StringBuffer } else { projIdFilter += " || proj.id == \"" + currentProjId + "\""; } - // prettyPrint.append(filter + " " + projIdFilter); } } projIdFilter += " )"; @@ -169,16 +167,11 @@ public static String queryStringBuilder(HttpServletRequest request, StringBuffer prettyPrint.append(filter); prettyPrint.append("
"); } - // TODO - // filter = "SELECT FROM org.ecocean.Encounter WHERE proj.id == '" + projectId + "' && proj.encounters.contains(this)"; String variables_statement = " VARIABLES org.ecocean.Project proj"; jdoqlVariableDeclaration = addOrgVars(variables_statement, filter); } else { - // TODO } // end filter for projectName------------------ - - // ------------------------------------------------------------------ // username filters------------------------------------------------- String[] usernames = request.getParameterValues("username"); if ((usernames != null) && (!usernames[0].equals("None"))) { @@ -220,43 +213,6 @@ public static String queryStringBuilder(HttpServletRequest request, StringBuffer prettyPrint.append("Unidentified.
"); } // end unassigned filter-------------------------------------------------------------------------------------- - -/** - //filter for unidentifiable encounters------------------------------------------ - if(request.getParameter("unidentifiable")==null) { - if(filter.equals(SELECT_FROM_ORG_ECOCEAN_ENCOUNTER_WHERE)){filter+="!unidentifiable";} - else{filter+=" && !unidentifiable";} - prettyPrint.append("Not identifiable.
"); - } - //----------------------------------------------------- - - //---filter out approved if((request.getParameter("approved")==null)&&(request.getParameter("unapproved")!=null)) { - if(filter.equals(SELECT_FROM_ORG_ECOCEAN_ENCOUNTER_WHERE)){filter+="!approved";} - else{filter+=" && !approved";} - prettyPrint.append("Not approved.
"); - } - //---------------------------- - - //---filter out unapproved if((request.getParameter("unapproved")==null)&&(request.getParameter("approved")!=null)) { - - if(filter.equals(SELECT_FROM_ORG_ECOCEAN_ENCOUNTER_WHERE)){filter+="approved";} - else{filter+=" && approved";} - prettyPrint.append("Not unapproved.
"); - } - //---------------------------- - - //---filter out unapproved and unapproved, leaving only unidentifiable - if((request.getParameter("unapproved")==null)&&(request.getParameter("approved")==null)&&(request.getParameter("unidentifiable")!=null)) { - - if(filter.equals(SELECT_FROM_ORG_ECOCEAN_ENCOUNTER_WHERE)){filter+="unidentifiable";} - else{filter+=" && unidentifiable";} - prettyPrint.append("Not unapproved.
"); - } - //---------------------------- - - */ - - // ------------------------------------------------------------------ // locationID filters------------------------------------------------- String[] locCodes = request.getParameterValues("locationCodeField"); if ((locCodes != null) && (!locCodes[0].equals(""))) { @@ -281,8 +237,6 @@ public static String queryStringBuilder(HttpServletRequest request, StringBuffer prettyPrint.append("
"); } // end locationID filters----------------------------------------------- - - // ------------------------------------------------------------------ // annotation viewpoint and class filters------------------------------------------------- String[] hasViewpoint = request.getParameterValues("hasViewpoint"); String[] hasIAClass = request.getParameterValues("hasIAClass"); @@ -339,8 +293,6 @@ public static String queryStringBuilder(HttpServletRequest request, StringBuffer } } // end viewpoint and class filters----------------------------------------------- - - // ------------------------------------------------------------------ // state filters------------------------------------------------- String[] states = request.getParameterValues("state"); if ((states != null) && (!states[0].equals("None"))) { @@ -365,8 +317,6 @@ public static String queryStringBuilder(HttpServletRequest request, StringBuffer prettyPrint.append("
"); } // end state filters----------------------------------------------- - - // ------------------------------------------------------------------ // individualID filters------------------------------------------------- // supports multiple individualID parameters as well as comma-separated lists of individualIDs within them String individualID = request.getParameter("individualID"); @@ -383,7 +333,6 @@ public static String queryStringBuilder(HttpServletRequest request, StringBuffer prettyPrint.append("
"); } // end individualID filters----------------------------------------------- - // occurrenceID filters------------------------------------------------- String occurrenceID = request.getParameter("occurrenceID"); if ((occurrenceID != null) && (!occurrenceID.equals("None")) && @@ -397,8 +346,6 @@ public static String queryStringBuilder(HttpServletRequest request, StringBuffer prettyPrint.append("
"); } // end occurrenceID filters----------------------------------------------- - - // ------------------------------------------------------------------ // individualIDExact filters------------------------------------------------- // supports one individualID parameter as well as comma-separated lists of individualIDs within them String individualIDExact = request.getParameter("individualIDExact"); @@ -522,7 +469,6 @@ public static String queryStringBuilder(HttpServletRequest request, StringBuffer } prettyPrint.append("
"); } - // ------------------------------------------------------------------ // patterningCode filters------------------------------------------------- String[] patterningCodes = request.getParameterValues("patterningCodeField"); if ((patterningCodes != null) && (!patterningCodes[0].equals("None"))) { @@ -547,8 +493,6 @@ public static String queryStringBuilder(HttpServletRequest request, StringBuffer prettyPrint.append("
"); } // end patterningCode filters----------------------------------------------- - - // ------------------------------------------------------------------ // behavior filters------------------------------------------------- String[] behaviors = request.getParameterValues("behaviorField"); if ((behaviors != null) && (!behaviors[0].equals("None"))) { @@ -573,8 +517,6 @@ public static String queryStringBuilder(HttpServletRequest request, StringBuffer prettyPrint.append("
"); } // end behavior filters----------------------------------------------- - // ------------------------------------------------------------------ - // begin observation filters ----------------------------------------- boolean hasValue = false; if (request.getParameter("numSearchedObs") != null) { @@ -648,8 +590,6 @@ public static String queryStringBuilder(HttpServletRequest request, StringBuffer } } } - // ------------------------------------------------------------------- - // Tag Filters-------------------------------------------------------- StringBuilder metalTagFilter = new StringBuilder(); @@ -699,7 +639,6 @@ public static String queryStringBuilder(HttpServletRequest request, StringBuffer filter += tagFilters.toString(); } // end tag filters---------------------------------------------------- - // lifeStage filters------------------------------------------------- String[] stages = request.getParameterValues("lifeStageField"); if ((stages != null) && (!stages[0].equals("None")) && (!stages[0].equals(""))) { @@ -724,7 +663,6 @@ public static String queryStringBuilder(HttpServletRequest request, StringBuffer prettyPrint.append("
"); } // end lifeStage filters - // country filters------------------------------------------------- String[] countries = request.getParameterValues("country"); if ((countries != null) && (!countries[0].equals("None")) && (!countries[0].equals(""))) { @@ -749,7 +687,6 @@ public static String queryStringBuilder(HttpServletRequest request, StringBuffer prettyPrint.append("
"); } // end country filters - // Measurement filters----------------------------------------------- List measurementDescs = Util.findMeasurementDescs("en", context); String measurementPrefix = "measurement"; @@ -820,7 +757,6 @@ public static String queryStringBuilder(HttpServletRequest request, StringBuffer } } // end measurement filters - // BiologicalMeasurement filters----------------------------------------------- List bioMeasurementDescs = Util.findBiologicalMeasurementDescs("en", context); @@ -896,8 +832,6 @@ public static String queryStringBuilder(HttpServletRequest request, StringBuffer } } // end BiologicalMeasurement filters - - // ------------------------------------------------------------------ // verbatimEventDate filters------------------------------------------------- String[] verbatimEventDates = request.getParameterValues("verbatimEventDateField"); if ((verbatimEventDates != null) && (!verbatimEventDates[0].equals("None"))) { @@ -922,7 +856,6 @@ public static String queryStringBuilder(HttpServletRequest request, StringBuffer prettyPrint.append("
"); } // end verbatimEventDate filters----------------------------------------------- - // ------------------------------------------------------------------ // hasTissueSample filters------------------------------------------------- if (request.getParameter("hasTissueSample") != null) { prettyPrint.append("Has tissue sample."); @@ -940,7 +873,6 @@ public static String queryStringBuilder(HttpServletRequest request, StringBuffer } } // end hasTissueSample filters----------------------------------------------- - // ------------------------------------------------------------------ // TissueSample sampleID filters------------------------------------------------- if ((request.getParameter("tissueSampleID") != null) && (!request.getParameter("tissueSampleID").trim().equals(""))) { @@ -965,7 +897,6 @@ public static String queryStringBuilder(HttpServletRequest request, StringBuffer } } // end hasTissueSample filters----------------------------------------------- - // ------------------------------------------------------------------ // hasPhoto filters------------------------------------------------- if (request.getParameter("hasPhoto") != null) { prettyPrint.append("Has at least one MediaAsset."); @@ -990,7 +921,6 @@ public static String queryStringBuilder(HttpServletRequest request, StringBuffer } } // end hasPhoto filters----------------------------------------------- - // ------------------------------------------------------------------ // hasSpots filters------------------------------------------------- if (request.getParameter("hasSpots") != null) { prettyPrint.append("Has patterning points."); @@ -1030,8 +960,6 @@ public static String queryStringBuilder(HttpServletRequest request, StringBuffer } else { jdoqlVariableDeclaration += ";org.ecocean.MarkedIndividual markedindy"; } } // end if resightOnly-------------------------------------------------------------------------------------- - - // ------------------------------------------------------------------ // keyword filters------------------------------------------------- // shared var between keywords and labeledKeywords @@ -1105,8 +1033,6 @@ public static String queryStringBuilder(HttpServletRequest request, StringBuffer myShepherd.closeDBTransaction(); // end photo keyword filters----------------------------------------------- - - // ------------------------------------------------------------------------ // labeled keyword filters------------------------------------------------- List labels = ServletUtilities.getIndexedParameters("label", request); System.out.println("LKW filter got labels " + labels); @@ -1145,7 +1071,6 @@ public static String queryStringBuilder(HttpServletRequest request, StringBuffer String wordVar = "word" + kwNum; if (labelN == 0) lkwFilter += " && "; lkwFilter += featVar + ".asset.keywords.contains(" + wordVar + ")"; - // TODO: is jdoql OK with typing wordVar as a LabeledKeyword even though features have a plain Keyword list? jdoqlVariableDeclaration = QueryProcessor.updateJdoqlVariableDeclaration( jdoqlVariableDeclaration, "org.ecocean.LabeledKeyword " + wordVar); // ------ done with variables and declarations for this LKW @@ -1184,8 +1109,6 @@ public static String queryStringBuilder(HttpServletRequest request, StringBuffer prettyPrint.append("
"); } // end labeled keyword filters - - // ------------------------------------------------------------------ // ms markers filters------------------------------------------------- myShepherd.beginDBTransaction(); List markers = myShepherd.getAllLoci(); @@ -1284,7 +1207,6 @@ public static String queryStringBuilder(HttpServletRequest request, StringBuffer } prettyPrint.append("alternateID field contains \"" + altID + "\".
"); } - // ------------------------------------------------------------------ // haplotype filters------------------------------------------------- String[] haplotypes = request.getParameterValues("haplotypeField"); if ((haplotypes != null) && (!haplotypes[0].equals("None"))) { @@ -1331,8 +1253,6 @@ public static String queryStringBuilder(HttpServletRequest request, StringBuffer } } // end haplotype filters----------------------------------------------- - - // ------------------------------------------------------------------ // genetic sex filters------------------------------------------------- String[] genSexes = request.getParameterValues("geneticSexField"); if ((genSexes != null) && (!genSexes[0].equals("None"))) { @@ -1379,30 +1299,6 @@ public static String queryStringBuilder(HttpServletRequest request, StringBuffer } } // end genetic sex filters----------------------------------------------- - /* - //start photo filename filtering if((request.getParameter("filenameField")!=null)&&(!request.getParameter("filenameField").equals(""))) - { - - //clean the input string to create its equivalent as if it had been submitted through the web form String - nameString=ServletUtilities.cleanFileName(ServletUtilities.preventCrossSiteScriptingAttacks(request.getParameter("filenameField").trim())); - - String locIDFilter="( photo.filename == \""+nameString+"\" )"; - - - if(filter.equals(SELECT_FROM_ORG_ECOCEAN_ENCOUNTER_WHERE)){filter+="images.contains(photo) && "+locIDFilter;} - else{ - filter+=" && images.contains(photo) && "+locIDFilter; - } - - prettyPrint.append("SinglePhotoVideo filename is: \""+nameString+"\"
"); - prettyPrint.append("
"); - if(jdoqlVariableDeclaration.equals("")){jdoqlVariableDeclaration=" VARIABLES org.ecocean.SinglePhotoVideo photo;";} - else{ - jdoqlVariableDeclaration+=";org.ecocean.SinglePhotoVideo photo"; - - } - } - */ // end photo filename filtering // filter for genus------------------------------------------ if ((request.getParameter("genusField") != null) && @@ -1439,16 +1335,6 @@ public static String queryStringBuilder(HttpServletRequest request, StringBuffer filter = filterWithGpsBox("decimalLatitude", "decimalLongitude", filter, request); } // end filter gpsOnly - /** - //filter for behavior------------------------------------------ - if((request.getParameter("behaviorField")!=null)&&(!request.getParameter("behaviorField").equals(""))) { - String behString=request.getParameter("behaviorField").toLowerCase().replaceAll("%20", " ").trim(); - if(filter.equals("")){filter="behavior.toLowerCase().indexOf('"+behString+"') != -1";} - else{filter+=" && behavior.toLowerCase().indexOf('"+behString+"') != -1";} - prettyPrint.append("behaviorField contains \""+behString+"\".
"); - } - //end behavior filter-------------------------------------------------------------------------------------- - */ // filter by alive/dead status------------------------------------------ if ((request.getParameter("alive") != null) || (request.getParameter("dead") != null)) { if (request.getParameter("alive") == null) { @@ -1471,9 +1357,6 @@ public static String queryStringBuilder(HttpServletRequest request, StringBuffer String nameString = request.getParameter("nameField").replaceAll("%20", " ").toLowerCase().trim(); - // String filterString="((recordedBy.toLowerCase().indexOf('"+nameString+"') != - // -1)||(submitterEmail.toLowerCase().indexOf('"+nameString+"') != -1)||(photographerName.toLowerCase().indexOf('"+nameString+"') != - // -1)||(photographerEmail.toLowerCase().indexOf('"+nameString+"') != -1)||(informothers.toLowerCase().indexOf('"+nameString+"') != -1))"; String filterString = "" + "(" + "(submitters.contains(submitter) && ((submitter.fullName.toLowerCase().indexOf('" + nameString + "') != -1)||(submitter.emailAddress.toLowerCase().indexOf('" + @@ -1518,35 +1401,6 @@ public static String queryStringBuilder(HttpServletRequest request, StringBuffer prettyPrint.append("Remarks contains: \"" + nameString + "\"
"); } // end additional comments filter-------------------------------------------------------------------------------------- -/* - This code is no longer necessary with Charles Overbeck's new multi-measurement feature. - - //filter for length------------------------------------------ - if((request.getParameter("selectLength")!=null)&&(request.getParameter("lengthField")!=null)&&(!request.getParameter("lengthField").equals("skip"))&&(!request.getParameter("selectLength").equals(""))) - { - - String size=request.getParameter("lengthField").trim(); - - if(request.getParameter("selectLength").equals("gt")) { - String filterString="size > "+size; - if(filter.equals(SELECT_FROM_ORG_ECOCEAN_ENCOUNTER_WHERE)){filter+=filterString;} - else{filter+=(" && "+filterString);} - prettyPrint.append("selectLength is > "+size+".
"); - } - else if(request.getParameter("selectLength").equals("lt")) { - String filterString="size < "+size; - if(filter.equals(SELECT_FROM_ORG_ECOCEAN_ENCOUNTER_WHERE)){filter+=filterString;} - else{filter+=(" && "+filterString);} - prettyPrint.append("selectLength is < "+size+".
"); - } - else if(request.getParameter("selectLength").equals("eq")) { - String filterString="size == "+size; - if(filter.equals(SELECT_FROM_ORG_ECOCEAN_ENCOUNTER_WHERE)){filter+=filterString;} - else{filter+=(" && "+filterString);} - prettyPrint.append("selectLength is = "+size+".
"); - } - } - */ // start date filter---------------------------- if ((request.getParameter("datepicker1") != null) && (!request.getParameter("datepicker1").trim().equals("")) && @@ -1558,10 +1412,8 @@ else if(request.getParameter("selectLength").equals("eq")) { DateTime date2 = parser.parseDateTime(request.getParameter("datepicker2")); long date1Millis = date1.getMillis(); long date2Millis = date2.getMillis(); - // if(request.getParameter("datepicker1").trim().equals(request.getParameter("datepicker2").trim())){ // if same dateTime is set by both pickers, then add a full day of milliseconds to picker2 to cover the entire day date2Millis += (24 * 60 * 60 * 1000 - 1); - // } prettyPrint.append("Dates between: " + date1.toString(ISODateTimeFormat.date()) + " and " + date2.toString(ISODateTimeFormat.date()) + "
"); @@ -1620,7 +1472,6 @@ else if(request.getParameter("selectLength").equals("eq")) { System.out.println("Filter at end of sex filtering: " + filter); } // filter by sex-------------------------------------------------------------------------------------- - String releaseDateFromStr = request.getParameter("releaseDateFrom"); String releaseDateToStr = request.getParameter("releaseDateTo"); String pattern = CommonConfiguration.getProperty("releaseDateFormat", context); @@ -1655,7 +1506,6 @@ else if(request.getParameter("selectLength").equals("eq")) { e.printStackTrace(); } } - // I choose to put this on one line out of pride alone -db for (String fieldName : SIMPLE_STRING_FIELDS) filter = QueryProcessor.filterWithBasicStringField(filter, fieldName, request, prettyPrint); @@ -1679,9 +1529,6 @@ public static EncounterQueryResult processQuery(Shepherd myShepherd, HttpServlet String currentUser = null; if (request.getUserPrincipal() != null) currentUser = request.getUserPrincipal().getName(); - // Extent encClass=myShepherd.getPM().getExtent(Encounter.class, true); - // Query query=myShepherd.getPM().newQuery(encClass); - // if(!order.equals("")){query.setOrdering(order);} String searchQueryId = request.getParameter("searchQueryId"); long startTime = System.currentTimeMillis(); @@ -1763,72 +1610,16 @@ public static EncounterQueryResult processQuery(Shepherd myShepherd, HttpServlet Query query = myShepherd.getPM().newQuery(filter); if (!order.equals("")) { query.setOrdering(order); } if (!filter.trim().equals("")) { - // filter="("+filter+")"; - // query.setFilter(filter); allEncounters = myShepherd.getAllEncounters(query, paramMap); } else { allEncounters = myShepherd.getAllEncountersNoFilter(); } - // System.out.println("Final filter: "+filter); - // allEncounters=myShepherd.getAllEncountersNoQuery(); if (allEncounters != null) { while (allEncounters.hasNext()) { Encounter temp_enc = allEncounters.next(); rEncounters.add(temp_enc); } } - /** - //filter for vessel------------------------------------------ - if((request.getParameter("vesselField")!=null)&&(!request.getParameter("vesselField").equals(""))) { - String vesString=request.getParameter("vesselField"); - for(int q=0;q"); - } - //end vessel filter-------------------------------------------------------------------------------------- - */ - -/* - //keyword filters------------------------------------------------- - String[] keywords=request.getParameterValues("keyword"); - if((keywords!=null)&&(!keywords[0].equals("None"))){ - - prettyPrint.append("Keywords: "); - int kwLength=keywords.length; - for(int y=0;y"); - - } - //end keyword filters----------------------------------------------- - */ query.closeAll(); diff --git a/src/main/java/org/ecocean/FormUtilities.java b/src/main/java/org/ecocean/FormUtilities.java index c1a92b3e6f..58f40fcec8 100644 --- a/src/main/java/org/ecocean/FormUtilities.java +++ b/src/main/java/org/ecocean/FormUtilities.java @@ -90,7 +90,7 @@ public static void setUpProjectDropdown(Boolean isForIndividualOrOccurrenceSearc ArrayList projOptions = new ArrayList(); ArrayList projIds = new ArrayList(); if (projects != null && projects.size() > 0) { - for (int i = 0; i < projects.size(); i++) { // TODO DRY up + for (int i = 0; i < projects.size(); i++) { Project currentProj = projects.get(i); String currentProjName = currentProj.getResearchProjectName(); String currentProjId = currentProj.getId(); @@ -121,14 +121,12 @@ public static void setUpProjectIncrementalIdDropdown(Boolean isForIndividualOrOc String pattern = "(.*)"; Pattern r = Pattern.compile(pattern); Matcher matcher = r.matcher("tmp"); - for (Project currentProject : projects) { // TODO DRY up - // Project currentProject = projects.get(i); + for (Project currentProject : projects) { pattern = "(.*;?.*)(" + currentProject.getProjectIdPrefix() + "\\d+)(.*)"; r = Pattern.compile(pattern); List individuals = myShepherd.getMarkedIndividualsFromProject( currentProject); for (MarkedIndividual currentIndividual : individuals) { - // MarkedIndividual currentIndividual = individuals.get(j); if (currentIndividual != null) { List namesList = currentIndividual.getNamesList( currentProject.getProjectIdPrefix()); @@ -170,7 +168,7 @@ public static void setUpOrgDropdown(String fieldName, Boolean isForIndividualOrO } else { orgsUserBelongsTo = usr.getOrganizations(); } ArrayList orgOptions = new ArrayList(); ArrayList orgIds = new ArrayList(); - for (int i = 0; i < orgsUserBelongsTo.size(); i++) { // TODO DRY up + for (int i = 0; i < orgsUserBelongsTo.size(); i++) { Organization currentOrg = orgsUserBelongsTo.get(i); String currentOrgName = currentOrg.getName(); String currentOrgId = currentOrg.getId(); diff --git a/src/main/java/org/ecocean/ImageProcessor.java b/src/main/java/org/ecocean/ImageProcessor.java index 1930602599..6cd5384aa3 100644 --- a/src/main/java/org/ecocean/ImageProcessor.java +++ b/src/main/java/org/ecocean/ImageProcessor.java @@ -13,24 +13,10 @@ import java.net.InetAddress; import java.net.UnknownHostException; -/** - * Does actual comparison processing of batch-uploaded images. - * - * @author Jon Van Oast - */ +// Does actual comparison processing of batch-uploaded images. public final class ImageProcessor implements Runnable { private static Logger log = LoggerFactory.getLogger(ImageProcessor.class); -///** Enumeration representing possible status values for the batch processor. */ -// public enum Status { WAITING, INIT, RUNNING, FINISHED, ERROR }; -///** Enumeration representing possible processing phases. */ -// public enum Phase { NONE, MEDIA_DOWNLOAD, PERSISTENCE, THUMBNAILS, PLUGIN, DONE }; -///** Current status of the batch processor. */ -// private Status status = Status.WAITING; -///** Current phase of the batch processor. */ -// private Phase phase = Phase.NONE; -///** Throwable instance produced by the batch processor (if any). */ -// private Throwable thrown; private String context = "context0"; private String command = null; @@ -137,14 +123,11 @@ public void run() { } catch (UnknownHostException e) {} int year = Calendar.getInstance().get(Calendar.YEAR); comment = comment.replaceAll("%year", Integer.toString(year)); - // TODO should we handle ' better? -- this also assumes command uses '%comment' quoting :/ comment = comment.replaceAll("'", ""); String fullCommand; fullCommand = this.command.replaceAll("%width", Integer.toString(this.width)) .replaceAll("%height", Integer.toString(this.height)) - // .replaceAll("%imagesource", this.imageSourcePath) - // .replaceAll("%imagetarget", this.imageTargetPath) .replaceAll("%maId", maId) .replaceAll("%additional", rotation); // walk thru transform array and replace "tN" with transform[N] @@ -169,10 +152,6 @@ public void run() { ProcessBuilder pb = new ProcessBuilder(); pb.command(command); -/* - Map env = pb.environment(); - env.put("LD_LIBRARY_PATH", "/home/jon/opencv2.4.7"); - */ // System.out.println("before!"); try { @@ -190,7 +169,6 @@ public void run() { } proc.waitFor(); System.out.println("DONE?????"); - ////int returnCode = p.exitValue(); } catch (Exception ioe) { log.error("Trouble running processor [" + command + "]", ioe); } diff --git a/src/main/java/org/ecocean/IndividualQueryProcessor.java b/src/main/java/org/ecocean/IndividualQueryProcessor.java index d8d2e143c0..cec0bc5713 100644 --- a/src/main/java/org/ecocean/IndividualQueryProcessor.java +++ b/src/main/java/org/ecocean/IndividualQueryProcessor.java @@ -137,17 +137,12 @@ public static String queryStringBuilder(HttpServletRequest request, StringBuffer prettyPrint.append(filter); prettyPrint.append("
"); } - // TODO - // filter = "SELECT FROM org.ecocean.Encounter WHERE proj.id == '" + projectId + "' && proj.encounters.contains(this)"; String variables_statement = " VARIABLES org.ecocean.Encounter enc; org.ecocean.Project proj"; jdoqlVariableDeclaration = addOrgVars(variables_statement, filter); } else { - // TODO } // end filter for projectName------------------ - - // ------------------------------------------------------------------ // locationID filters------------------------------------------------- String[] locCodes = request.getParameterValues("locationCodeField"); if (locCodes == null && ServletUtilities.getParameterOrAttribute("locationCodeField", @@ -177,8 +172,6 @@ public static String queryStringBuilder(HttpServletRequest request, StringBuffer prettyPrint.append("
"); } // end locationID filters----------------------------------------------- - - // ------------------------------------------------------------------ // individualID filters------------------------------------------------- // supports multiple individualID parameters as well as comma-separated lists of individualIDs within them String individualID = request.getParameter("individualID"); @@ -195,8 +188,6 @@ public static String queryStringBuilder(HttpServletRequest request, StringBuffer prettyPrint.append("
"); } // end individualID filters----------------------------------------------- - - // ------------------------------------------------------------------ // patterningCode filters------------------------------------------------- String[] patterningCodes = request.getParameterValues("patterningCodeField"); if ((patterningCodes != null) && (!patterningCodes[0].equals("None"))) { @@ -224,8 +215,6 @@ public static String queryStringBuilder(HttpServletRequest request, StringBuffer prettyPrint.append("
"); } // end patterningCode filters----------------------------------------------- - - // ------------------------------------------------------------------ // haplotype filters------------------------------------------------- String[] haplos = request.getParameterValues("haplotypeField"); if ((haplos != null) && (!haplos[0].equals("None"))) { @@ -248,8 +237,6 @@ public static String queryStringBuilder(HttpServletRequest request, StringBuffer prettyPrint.append("
"); } // end haplotype filters----------------------------------------------- - - // ------------------------------------------------------------------ // annotation viewpoint and class filters------------------------------------------------- String[] hasViewpoint = request.getParameterValues("hasViewpoint"); String[] hasIAClass = request.getParameterValues("hasIAClass"); @@ -308,8 +295,6 @@ public static String queryStringBuilder(HttpServletRequest request, StringBuffer } } // end viewpoint and class filters----------------------------------------------- - - // ------------------------------------------------------------------ // username filters------------------------------------------------- String[] usernames = request.getParameterValues("username"); if ((usernames != null) && (!usernames[0].equals("None"))) { @@ -337,8 +322,6 @@ public static String queryStringBuilder(HttpServletRequest request, StringBuffer prettyPrint.append("
"); } // end username filters----------------------------------------------- - - // ------------------------------------------------------------------ // behavior filters------------------------------------------------- String[] behaviors = request.getParameterValues("behaviorField"); if ((behaviors != null) && (!behaviors[0].equals("None"))) { @@ -361,8 +344,6 @@ public static String queryStringBuilder(HttpServletRequest request, StringBuffer prettyPrint.append("
"); } // end behavior filters----------------------------------------------- - // ------------------------------------------------------------------ - // lifeStage filters------------------------------------------------- String[] stages = request.getParameterValues("lifeStageField"); if ((stages != null) && (!stages[0].equals("None")) && (!stages[0].equals(""))) { @@ -442,7 +423,6 @@ public static String queryStringBuilder(HttpServletRequest request, StringBuffer if (jdoqlVariableDeclaration.length() > 0) { jdoqlVariableDeclaration += ";"; } - // jdoqlVariableDeclaration=" VARIABLES "; for (int i = 0; i < measurementsInQuery; i++) { if (i > 0) { jdoqlVariableDeclaration += "; "; @@ -452,7 +432,6 @@ public static String queryStringBuilder(HttpServletRequest request, StringBuffer filter = filterWithCondition(filter, measurementFilter.toString()); } // end measurement filters - // BiologicalMeasurement filters----------------------------------------------- List bioMeasurementDescs = Util.findBiologicalMeasurementDescs("en", context); @@ -494,7 +473,6 @@ public static String queryStringBuilder(HttpServletRequest request, StringBuffer prettyPrint.append(value); prettyPrint.append("
"); if (bioAtLeastOneMeasurement) { - // bioMeasurementFilter.append("&&"); } String measurementVar = "biomeasurement" + bioMeasurementsInQuery++; bioMeasurementFilter.append(" && dce322.analyses.contains(" + @@ -525,8 +503,6 @@ public static String queryStringBuilder(HttpServletRequest request, StringBuffer filter = filterWithCondition(filter, bioMeasurementFilter.toString()); } // end BiologicalMeasurement filters - - // ------------------------------------------------------------------ // verbatimEventDate filters------------------------------------------------- String[] verbatimEventDates = request.getParameterValues("verbatimEventDateField"); if ((verbatimEventDates != null) && (!verbatimEventDates[0].equals("None"))) { @@ -567,7 +543,6 @@ public static String queryStringBuilder(HttpServletRequest request, StringBuffer "((enc.dwcDateAddedLong >= " + date1.getMillis() + ") && (enc.dwcDateAddedLong <= " + date2.getMillis() + "))"); } catch (NumberFormatException nfe) { - // do nothing, just skip on nfe.printStackTrace(); } } @@ -675,7 +650,6 @@ public static String queryStringBuilder(HttpServletRequest request, StringBuffer jdoqlVariableDeclaration, "org.ecocean.Encounter enc11"); } // end Tag Filters ------------------------------------------------- - // ------------------------------------------------------------------ // hasTissueSample filters------------------------------------------------- if (request.getParameter("hasTissueSample") != null) { prettyPrint.append("Has tissue sample."); @@ -698,7 +672,6 @@ public static String queryStringBuilder(HttpServletRequest request, StringBuffer } } // end hasTissueSample filters----------------------------------------------- - // ------------------------------------------------------------------ // hasPhoto filters------------------------------------------------- if (request.getParameter("hasPhoto") != null) { prettyPrint.append("Has at least one photo."); @@ -722,8 +695,6 @@ public static String queryStringBuilder(HttpServletRequest request, StringBuffer } } // end hasPhoto filters----------------------------------------------- - - // ------------------------------------------------------------------ // keyword filters------------------------------------------------- myShepherd.beginDBTransaction(); String[] keywords = request.getParameterValues("keyword"); @@ -795,8 +766,6 @@ public static String queryStringBuilder(HttpServletRequest request, StringBuffer myShepherd.closeDBTransaction(); // end photo keyword filters----------------------------------------------- - - // ------------------------------------------------------------------ // ms markers filters------------------------------------------------- myShepherd.beginDBTransaction(); @@ -883,7 +852,6 @@ public static String queryStringBuilder(HttpServletRequest request, StringBuffer myShepherd.rollbackDBTransaction(); myShepherd.closeDBTransaction(); // end ms markers filters----------------------------------------------- - // ------------------------------------------------------------------ // has msmarkers filter------------------------------------------------- if (request.getParameter("hasMSMarkers") != null) { if (filter.equals(SELECT_FROM_ORG_ECOCEAN_INDIVIDUAL_WHERE)) { @@ -916,66 +884,6 @@ public static String queryStringBuilder(HttpServletRequest request, StringBuffer prettyPrint.append(theseMarkers); } // end ms markers filters----------------------------------------------- -/* - //alternateID and nickName are now handled here (and commented out below) List nameIds = new ArrayList(); - String altVal = request.getParameter("alternateIDField"); - String nickVal = request.getParameter("nickNameField"); - // adding the stars means we're looking for a substring not exact match if (Util.stringExists(altVal)) - nameIds.addAll(MarkedIndividual.findNameIds(".*" + altVal + ".*")); - if (Util.stringExists(nickVal)) nameIds.addAll(MarkedIndividual.findNameIds(".*" + nickVal + ".*")); - if (nameIds.size() > 0) { - String clause = " (names.id == " + String.join(" || names.id == ", nameIds) + ") "; - - filter +=filterWithCondition(filter, clause); - - } - - */ - // ------------------------------------------------------------------ - // haplotype filters------------------------------------------------- - /* - String[] haplotypes=request.getParameterValues("haplotypeField"); - if((haplotypes!=null)&&(!haplotypes[0].equals("None"))){ - prettyPrint.append("Haplotype is one of the following: "); - int kwLength=haplotypes.length; - String locIDFilter="("; - for(int kwIter=0;kwIter"); - if(!jdoqlVariableDeclaration.contains("org.ecocean.Encounter enc7")){jdoqlVariableDeclaration+=";org.ecocean.Encounter enc7";} - - if(!jdoqlVariableDeclaration.contains("org.ecocean.genetics.TissueSample - dce1")){jdoqlVariableDeclaration+=";org.ecocean.genetics.TissueSample dce1";} - if(!jdoqlVariableDeclaration.contains("org.ecocean.genetics.MitochondrialDNAAnalysis - analysis")){jdoqlVariableDeclaration+=";org.ecocean.genetics.MitochondrialDNAAnalysis analysis";} - - - } - */ - // end haplotype filters----------------------------------------------- - // ------------------------------------------------------------------ // hasHaplotype filters------------------------------------------------- if (request.getParameter("hasHaplotype") != null) { prettyPrint.append("Has a haplotype assigned. "); @@ -1007,8 +915,6 @@ public static String queryStringBuilder(HttpServletRequest request, StringBuffer } } // end hasHaplotype filters----------------------------------------------- - - // ------------------------------------------------------------------ // genetic sex filters------------------------------------------------- String[] genSexes = request.getParameterValues("geneticSexField"); if ((genSexes != null) && (!genSexes[0].equals("None"))) { @@ -1101,53 +1007,6 @@ public static String queryStringBuilder(HttpServletRequest request, StringBuffer prettyPrint.append("Dead.
"); } } - // filter by alive/dead status-------------------------------------------------------------------------------------- - /** - * Try this again with DataNucleus 5.x+. JDOQL does not compile correctly. - //submitter or photographer name filter------------------------------------------ - if((request.getParameter("nameField")!=null)&&(!request.getParameter("nameField").equals(""))) { - String nameString=request.getParameter("nameField").replaceAll("%20"," ").toLowerCase().trim(); - - - //String filterString="((recordedBy.toLowerCase().indexOf('"+nameString+"') != -1)||(submitterEmail.toLowerCase().indexOf('"+nameString+"') - * != -1)||(photographerName.toLowerCase().indexOf('"+nameString+"') != -1)||(photographerEmail.toLowerCase().indexOf('"+nameString+"') != - * -1)||(informothers.toLowerCase().indexOf('"+nameString+"') != -1))"; - String filterString=""+ - //" ( " + - "(" - +" (enc.submitters.contains(submitter)) " - +" && ( " - - +" (submitter.emailAddress.toLowerCase().indexOf('"+nameString+"') != -1)" - //+" || (submitter.fullName.toLowerCase().indexOf('"+nameString+"') != -1)" - - +")" - +") " - // + " || (enc.photographers.contains(submitter) && (submitter.emailAddress.toLowerCase().indexOf('"+nameString+"') != -1)) " - // +"||(enc72.informothers.toLowerCase().indexOf('"+nameString+"') != -1)" - - //+" ) " - ; - - - - if(jdoqlVariableDeclaration.equals("")){jdoqlVariableDeclaration=" VARIABLES org.ecocean.User submitter";} - else{ - if(!jdoqlVariableDeclaration.contains("org.ecocean.User submitter")){jdoqlVariableDeclaration+=";org.ecocean.User submitter";} - //if(!jdoqlVariableDeclaration.contains("org.ecocean.User photographer")){jdoqlVariableDeclaration+=";org.ecocean.User photographer";} - //if(!jdoqlVariableDeclaration.contains("org.ecocean.Encounter enc72")){jdoqlVariableDeclaration+=";org.ecocean.Encounter enc72";} - - } - - - if(filter.equals(SELECT_FROM_ORG_ECOCEAN_INDIVIDUAL_WHERE)){filter+=filterString;} - else{filter+=(" && "+filterString);} - - prettyPrint.append("Related fullName or emailAddress contains: \""+nameString+"\"
"); - - } - //end name and email filter-------------------------------------------------------------------------------------- - */ // start DOB filter---------------------------- if ((request.getParameter("DOBstart") != null) && (request.getParameter("DOBend") != null) && @@ -1164,7 +1023,6 @@ public static String queryStringBuilder(HttpServletRequest request, StringBuffer prettyPrint.append("Date of birth between: " + request.getParameter("DOBstart") + " and " + request.getParameter("DOBend") + "
"); } catch (Exception nfe) { - // do nothing, just skip on nfe.printStackTrace(); } } @@ -1185,7 +1043,6 @@ public static String queryStringBuilder(HttpServletRequest request, StringBuffer prettyPrint.append("Date of death between: " + request.getParameter("DODstart") + " and " + request.getParameter("DODend") + "
"); } catch (Exception nfe) { - // do nothing, just skip on nfe.printStackTrace(); } } @@ -1211,12 +1068,10 @@ public static String queryStringBuilder(HttpServletRequest request, StringBuffer "((enc.dateInMilliseconds >= " + date1Millis + ") && (enc.dateInMilliseconds <= " + date2Millis + "))"); } catch (NumberFormatException nfe) { - // do nothing, just skip on nfe.printStackTrace(); } } // end date filter ---------------------------------------- - // ------------------------------------------------------------------ // GPS filters------------------------------------------------- if ((request.getParameter("ne_lat") != null) && (!request.getParameter("ne_lat").equals(""))) { @@ -1237,8 +1092,6 @@ public static String queryStringBuilder(HttpServletRequest request, StringBuffer double sw_long = (new Double(request.getParameter( "sw_long"))).doubleValue(); if ((sw_long > 0) && (ne_long < 0)) { - // if(!((encLat<=ne_lat)&&(encLat>=sw_lat)&&((encLong<=ne_long)||(encLong>=sw_long)))){ - // process lats thisLocalFilter += "(enc.decimalLatitude <= " + request.getParameter("ne_lat") + @@ -1253,8 +1106,6 @@ public static String queryStringBuilder(HttpServletRequest request, StringBuffer // } } else { - // if(!((encLat<=ne_lat)&&(encLat>=sw_lat)&&(encLong<=ne_long)&&(encLong>=sw_long))){ - // process lats thisLocalFilter += "(enc.decimalLatitude <= " + request.getParameter("ne_lat") + @@ -1266,8 +1117,6 @@ public static String queryStringBuilder(HttpServletRequest request, StringBuffer request.getParameter("ne_long") + ") && (enc.decimalLongitude >= " + request.getParameter("sw_long") + ")"; - - // } } thisLocalFilter += " )"; if (filter.equals("")) { filter = thisLocalFilter; } else { @@ -1324,18 +1173,15 @@ public static String queryStringBuilder(HttpServletRequest request, StringBuffer (request.getParameter("unknown") != null)) { if (request.getParameter("male") == null) { filter = filterWithCondition(filter, "!sex.startsWith('male')"); - // if(filter.indexOf("sex!=null")==-1){filter+=" && sex!=null";} prettyPrint.append("Sex is not male.
"); } if (request.getParameter("female") == null) { filter = filterWithCondition(filter, "!sex.startsWith('female')"); - // if(filter.indexOf("sex!=null")==-1){filter+=" && sex!=null";} prettyPrint.append("Sex is not female.
"); } if (request.getParameter("unknown") == null) { filter = filterWithCondition(filter, "!sex.startsWith('unknown') && sex != null"); - // if(filter.indexOf("sex!=null")==-1){filter+=" && sex!=null";} prettyPrint.append("Sex is not unknown.
"); } } @@ -1365,7 +1211,6 @@ public static MarkedIndividualQueryResult processQuery(Shepherd myShepherd, Map paramMap = new HashMap(); String filter = queryStringBuilder(request, prettyPrint, paramMap); - // query.setFilter(filter); Query query = myShepherd.getPM().newQuery(filter); if ((order != null) && (!order.trim().equals(""))) { @@ -1532,8 +1377,6 @@ else if (request.getParameter("sort").equals("dateTimeLatestSighting")) { String[] locCodes = request.getParameterValues("locationCodeField"); // check whether locationIDs are AND'd rather than OR'd if (request.getParameter("andLocationIDs") != null) { - // String[] locCodes=request.getParameterValues("locationCodeField"); - prettyPrint = new StringBuffer(prettyPrint.toString().replaceAll( "Sighted in at least one of the following locationsIDs", "Sighted at least once in each of the following location IDs")); diff --git a/src/main/java/org/ecocean/MarkedIndividual.java b/src/main/java/org/ecocean/MarkedIndividual.java index 37e750aec8..5f107f84f2 100644 --- a/src/main/java/org/ecocean/MarkedIndividual.java +++ b/src/main/java/org/ecocean/MarkedIndividual.java @@ -43,8 +43,8 @@ public class MarkedIndividual extends Base implements java.io.Serializable { private static HashMap NAMES_CACHE = new HashMap(); // this is for searching private static HashMap NAMES_KEY_CACHE = new HashMap(); - private String alternateid; // TODO this will go away soon - private String legacyIndividualID; // TODO this "could" go away "eventually" + private String alternateid; + private String legacyIndividualID; // additional comments added by researchers private String comments = "None"; @@ -84,7 +84,7 @@ public class MarkedIndividual extends Base implements java.io.Serializable { // first sighting private String dateFirstIdentified; - // points to thumbnail (usually of most recent encounter) - TODO someday will be superceded by MediaAsset magic[tm] + // points to thumbnail (usually of most recent encounter) - TODO: evaluate and remove if has been superceded by MediaAsset private String thumbnailUrl; // a Vector of Strings of email addresses to notify when this MarkedIndividual is modified @@ -128,9 +128,7 @@ public MarkedIndividual(String name, Encounter enc) { maxYearsBetweenResightings = 0; } - /** - * empty constructor used by JDO Enhancer - DO NOT USE - */ + // TODO: evaluate if this can be removed: empty constructor used by JDO Enhancer - DO NOT USE public MarkedIndividual() { this.individualID = Util.generateUUID(); } @@ -143,20 +141,12 @@ public MarkedIndividual(Encounter enc) { refreshDependentProperties(); } - /** - * Retrieves the Individual Id. - * - * @return Individual Id String - */ + // Retrieves the Individual Id. @Override public String getId() { return individualID; } - /** - * Sets the Individual Id. - * - * @param id The Individual Id to set - */ + // Sets the Individual Id. @Override public void setId(String id) { individualID = id; } @@ -370,15 +360,12 @@ public String getFirstMatchingName(String query) { if (NAMES_CACHE.get(nid).matches(query.toLowerCase()) && tracker < 1) { returnVal = NAMES_CACHE.get(nid); return returnVal; - // tracker ++; // System.out.println("tracker is: " + tracker); } } return returnVal; } -///////////////// TODO other setters!!!! e.g. addNameByKey(s) - // this should be run once, as it will set (default key) values based on old field values // see, e.g. appadmin/migrateMarkedIndividualNames.jsp public MultiValue setNamesFromLegacy() { @@ -416,7 +403,7 @@ public static List allNamesValues(Shepherd myShepherd, Object keyHint) { List keysList = new ArrayList(keys); // we want a list to use .replaceAll keysList.replaceAll(s -> s.replaceAll("'", "''")); keysList.replaceAll(s -> s.replaceAll("_", "\\_")); - keysList.replaceAll(s -> s.replaceAll(":", "_")); // $*#(@*(! JDO PARAMETERS!!! + keysList.replaceAll(s -> s.replaceAll(":", "_")); String sql = "SELECT DISTINCT(\"ID_OID\") AS \"ID\" FROM \"MULTIVALUE_VALUES\" JOIN \"MARKEDINDIVIDUAL\" ON (\"NAMES_ID_OID\" = \"ID_OID\") WHERE \"KEY\" LIKE '" + StringUtils.join(keysList, "' OR \"KEY\" LIKE '") + "'"; @@ -459,11 +446,7 @@ public void addIncrementalProjectId(Project project) { } } - /**Adds a new encounter to this MarkedIndividual. - *@param newEncounter the new encounter to add - *@return true for successful addition, false for unsuccessful - Note: this change must still be committed for it to be stored in the database - *@see Shepherd#commitDBTransaction() - */ + // Adds a new encounter to this MarkedIndividual. public boolean addEncounter(Encounter newEncounter) { // get and therefore set the haplotype if necessary getHaplotype(); @@ -503,16 +486,10 @@ public boolean addEncounterNoCommit(Encounter newEncounter) { numberEncounters++; refreshDependentProperties(); } - // setTaxonomyFromEncounters(); //will only set if has no value - // setSexFromEncounters(); //likewise return isNew; } - /**Removes an encounter from this MarkedIndividual. - *@param getRidOfMe the encounter to remove from this MarkedIndividual - *@return true for successful removal, false for unsuccessful - Note: this change must still be committed for it to be stored in the database - *@see Shepherd#commitDBTransaction() - */ + // Removes an encounter from this MarkedIndividual. public boolean removeEncounter(Encounter getRidOfMe) { numberEncounters--; boolean changed = false; @@ -533,11 +510,7 @@ public boolean removeEncounter(Encounter getRidOfMe) { return changed; } - /** - * Returns the total number of submitted encounters for this MarkedIndividual - * - * @return the total number of encounters recorded for this MarkedIndividual - */ + // Returns the total number of submitted encounters for this MarkedIndividual public int totalEncounters() { return encounters.size(); } @@ -587,21 +560,12 @@ public String refreshThumbnailUrl(Shepherd myShepherd, HttpServletRequest req) return thumbUrl; } -/* - public int totalLogEncounters() { - if (unidentifiableEncounters == null) { - //unidentifiableEncounters = new Vector(); - } - return unidentifiableEncounters.size(); - } - */ public Vector returnEncountersWithGPSData(HttpServletRequest request) { return returnEncountersWithGPSData(false, false, "context0", request); } public Vector returnEncountersWithGPSData(boolean useLocales, boolean reverseOrder, String context, HttpServletRequest request) { - // if(unidentifiableEncounters==null) {unidentifiableEncounters=new Vector();} Vector haveData = new Vector(); Encounter[] myEncs = getDateSortedEncounters(reverseOrder); @@ -633,23 +597,12 @@ public Vector returnEncountersWithGPSData(boolean useLocales, boolean reverseOrd } public boolean isDeceased() { - // if (unidentifiableEncounters == null) { - // unidentifiableEncounters = new Vector(); - // } for (int c = 0; c < encounters.size(); c++) { Encounter temp = (Encounter)encounters.get(c); if ((temp.getLivingStatus() != null) && temp.getLivingStatus().equals("dead")) { return true; } } - /* - for (int d = 0; d < numUnidentifiableEncounters; d++) { - Encounter temp = (Encounter) unidentifiableEncounters.get(d); - if (temp.getLivingStatus().equals("dead")) { - return true; - } - } - */ return false; } @@ -684,11 +637,7 @@ public boolean wasSightedInYearLeftTagsOnly(int year, String locCode) { return false; } - /** - * - * - * @deprecated - */ + // TODO: evaluate and remove if deprecated public double averageLengthInYear(int year) { int numLengths = 0; double total = 0; @@ -708,11 +657,7 @@ public double averageLengthInYear(int year) { return avg; } - /** - * - * - * @deprecated - */ + // TODO: evaluate and remove if deprecated public double averageMeasuredLengthInYear(int year, boolean allowGuideGuess) { int numLengths = 0; double total = 0; @@ -746,17 +691,6 @@ public boolean isDescribedByPhotoKeyword(Keyword word) { return false; } - /* - public boolean hasApprovedEncounters() { - for (int c = 0; c < encounters.size(); c++) { - Encounter temp = (Encounter) encounters.get(c); - if (temp.getState()!=null) { - return true; - } - } - return false; - } - */ public boolean wasSightedInMonth(int year, int month) { for (int c = 0; c < encounters.size(); c++) { Encounter temp = (Encounter)encounters.get(c); @@ -870,19 +804,11 @@ public String getName(Object keyHint) { return names.getValue(keyHint); } - /** - * ##DEPRECATED #509 - Base class getId() method - */ + // TODO: evaluate and remove if deprecated: ##DEPRECATED #509 - Base class getId() method public String getIndividualID() { return individualID; } -/* - now part of migration of all names to .names MultiValue property we still want "a (singular) nickname" and notably a nickNamer so we set nickname - to a special keyed value, but leave nicknameR as its own property - - TODO someday(?) we might want to move the nicknamer to a key, so we could have multiple nicknamers/nicknames - */ public String getNickName() { if (names == null) return null; List many = names.getValuesByKey(NAMES_KEY_NICKNAME); @@ -915,9 +841,7 @@ public String getLegacyIndividualID() { return legacyIndividualID; } - /** - * ##DEPRECATED #509 - Base class setId() method - */ + // TODO: evaluate and remove if deprecated: ##DEPRECATED #509 - Base class getId() method public void setIndividualID(String id) { individualID = id; } @@ -928,33 +852,17 @@ public void setAlternateID(String alt) { this.addNameByKey(NAMES_KEY_ALTERNATEID, alt); } - /** - * Returns the specified encounter, where the encounter numbers range from 0 to n-1, where n is the total number of encounters stored for this - * MarkedIndividual. - * - * @return the encounter at position i in the stored Vector of encounters - * @param i the specified encounter number, where i=0...(n-1) - */ + // Returns the specified encounter, where the encounter numbers range from 0 to n-1, where n is the total number of encounters stored for this MarkedIndividual. public Encounter getEncounter(int i) { return (Encounter)encounters.get(i); } - /* - public Encounter getLogEncounter(int i) { - return (Encounter) unidentifiableEncounters.get(i); - } - */ public int numEncounters() { if (encounters == null) return 0; return encounters.size(); } - /** - * Returns the complete Vector of stored encounters for this MarkedIndividual. - * - * @return a Vector of encounters - * @see java.util.Vector - */ + // Returns the complete Vector of stored encounters for this MarkedIndividual. public Vector getEncounters() { return encounters; } @@ -1019,33 +927,10 @@ public String getWebUrl(HttpServletRequest req) { return getWebUrl(this.getIndividualID(), req); } - // public String getHyperlink(HttpServletRequest req) { - // return " Individual "+getDisplayName(req)+ ""; - // } - // sorted with the most recent first public Encounter[] getDateSortedEncounters() { return getDateSortedEncounters(false); } - // preserved for legacy purposes - /** public Encounter[] getDateSortedEncounters(boolean includeLogEncounters) { - return getDateSortedEncounters(); - } - */ - - /* - public Vector getUnidentifiableEncounters() { - if (unidentifiableEncounters == null) { - unidentifiableEncounters = new Vector(); - } - return unidentifiableEncounters; - } - */ - - /** - * Returns any additional, general comments recorded for this MarkedIndividual as a whole. - * - * @return a String of comments - */ + // Returns any additional, general comments recorded for this MarkedIndividual as a whole. @Override public String getComments() { if (comments != null) { return comments; @@ -1054,11 +939,7 @@ public Vector getUnidentifiableEncounters() { } } - /** - * Adds any general comments recorded for this MarkedIndividual as a whole. - * - * @return a String of comments - */ + // Adds any general comments recorded for this MarkedIndividual as a whole. @Override public void addComments(String newComments) { System.out.println("addComments called. oldComments=" + comments + " and new comments = " + newComments); @@ -1069,37 +950,22 @@ public Vector getUnidentifiableEncounters() { } } - /** - * Sets any additional, general comments recorded for this MarkedIndividual as a whole. - * - * @param comments to set - */ + // Sets any additional, general comments recorded for this MarkedIndividual as a whole. @Override public void setComments(String comments) { this.comments = comments; } - /** - * Returns the complete Vector of stored satellite tag data files for this MarkedIndividual. - * - * @return a Vector of Files - * @see java.util.Vector - */ + // Returns the complete Vector of stored satellite tag data files for this MarkedIndividual. public Vector getDataFiles() { return dataFiles; } - /** - * Returns the sex of this MarkedIndividual. - * - * @return a String - */ + // Returns the sex of this MarkedIndividual. public String getSex() { return sex; } - /** - * Sets the sex of this MarkedIndividual. - */ + // Sets the sex of this MarkedIndividual. public void setSex(String newSex) { if (newSex != null) { sex = newSex; } else { sex = null; } } @@ -1147,7 +1013,7 @@ public String getTaxonomyString() { ///this is really only for when dont have a value set; i.e. it should not be run after set on the instance; /// therefore we dont allow that unless you pass boolean true to force it - /// TODO we only pick first one - perhaps smarter would be to check all encounters and pick dominant one? + /// we only pick first from all encounters public String setTaxonomyFromEncounters(boolean force) { if (!force && ((genus != null) || (specificEpithet != null))) return getTaxonomyString(); if ((encounters == null) || (encounters.size() < 1)) return getTaxonomyString(); @@ -1328,21 +1194,13 @@ public void setSeriesCode(String newCode) { seriesCode = newCode; } - /** - * Adds a satellite tag data file for this MarkedIndividual. - * - * @param dataFile the satellite tag data file to be added - */ + // Adds a satellite tag data file for this MarkedIndividual. public void addDataFile(String dataFile) { if (dataFiles == null) { dataFiles = new Vector(); } dataFiles.add(dataFile); } - /** - * Removes a satellite tag data file for this MarkedIndividual. - * - * @param dataFile The satellite data file, as a String, to be removed. - */ + // Removes a satellite tag data file for this MarkedIndividual. public void removeDataFile(String dataFile) { if (dataFiles != null) { dataFiles.remove(dataFile); @@ -1399,28 +1257,8 @@ public Vector getRightTrainableEncounters() { return results; } - /*public int getFirstTrainingEncounter() { - for(int iter=0;iter getAllValuesForDynamicProperty(String propertyName) { return listPropertyValues; } - /** - Returns the patterning type evident on this MarkedIndividual instance. - - */ + // Returns the patterning type evident on this MarkedIndividual instance. public String getPatterningCode() { int numEncs = encounters.size(); @@ -1787,10 +1622,7 @@ public String getPatterningCode() { return null; } - /** - Sets the patterning type evident on this MarkedIndividual instance. - - */ + // Sets the patterning type evident on this MarkedIndividual instance. public void setPatterningCode(String newCode) { this.patterningCode = newCode; } public void resetMaxNumYearsBetweenSightings() { @@ -1861,10 +1693,7 @@ public String getGenusSpeciesDeep() { return null; } -/** - Returns the first haplotype found in the Encounter objects for this MarkedIndividual. - @return a String if found or null if no haplotype is found - */ +// Returns the first haplotype found in the Encounter objects for this MarkedIndividual. public String getHaplotype() { return localHaplotypeReflection; } @@ -1994,10 +1823,7 @@ public boolean hasGeneticSex() { return false; } -/** - * Obtains the email addresses of all submitters, photographs, and others to notify. - *@return ArrayList of all emails to inform - */ +// Obtains the email addresses of all submitters, photographs, and others to notify. public List getAllEmailsToUpdate() { ArrayList notifyUs = new ArrayList(); int numEncounters = encounters.size(); @@ -2007,30 +1833,6 @@ public List getAllEmailsToUpdate() { for (int i = 0; i < numEncounters; i++) { Encounter enc = (Encounter)encounters.get(i); - /* - if((enc.getSubmitterEmail()!=null)&&(!enc.getSubmitterEmail().trim().equals(""))){ - String submitter = enc.getSubmitterEmail(); - if (submitter.indexOf(",") != -1) { - StringTokenizer str = new StringTokenizer(submitter, ","); - while (str.hasMoreTokens()) { - String token = str.nextToken().trim(); - if((!token.equals(""))&&(!notifyUs.contains(token))){notifyUs.add(token);} - } - } - else{if(!notifyUs.contains(submitter)){notifyUs.add(submitter);}} - } - if((enc.getPhotographerEmail()!=null)&&(!enc.getPhotographerEmail().trim().equals(""))){ - String photog = enc.getPhotographerEmail(); - if (photog.indexOf(",") != -1) { - StringTokenizer str = new StringTokenizer(photog, ","); - while (str.hasMoreTokens()) { - String token = str.nextToken().trim(); - if((!token.equals(""))&&(!notifyUs.contains(token))){notifyUs.add(token);} - } - } - else{if(!notifyUs.contains(photog)){notifyUs.add(photog);}} - } - */ List allUsers = new ArrayList(); if (enc.getSubmitters() != null) allUsers.addAll(enc.getSubmitters()); if (enc.getPhotographers() != null) allUsers.addAll(enc.getPhotographers()); @@ -2042,65 +1844,10 @@ public List getAllEmailsToUpdate() { notifyUs.add(use.getEmailAddress()); } } - /* - if((enc.getInformOthers()!=null)&&(!enc.getInformOthers().trim().equals(""))){ - String photog = enc.getInformOthers(); - if (photog.indexOf(",") != -1) { - StringTokenizer str = new StringTokenizer(photog, ","); - while (str.hasMoreTokens()) { - String token = str.nextToken().trim(); - if((!token.equals(""))&&(!notifyUs.contains(token))){notifyUs.add(token);} - } - } - else{if(!notifyUs.contains(photog)){notifyUs.add(photog);}} - } - */ - } - /* - //process log encounters for(int i=0;i getAllAssignedUsers() { return allIDs; } -/** - * DO NOT SET DIRECTLY!! - * - * @param myDepth - */ +// DO NOT SET DIRECTLY!! public void doNotSetLocalHaplotypeReflection(String myHaplo) { if (myHaplo != null) { localHaplotypeReflection = myHaplo; } else { localHaplotypeReflection = null; @@ -2277,9 +2020,6 @@ public boolean canUserAccess(HttpServletRequest request) { List ids = new ArrayList(); for (User user : myShepherd.getAllUsers()) { -/* FIXME we do not have user-flavored Collaboration.canUserAccessMarkedIndividual yet - if ((user.getId() != null) && this.canUserAccess(user, myShepherd.getContext())) ids.add(user.getId()); - */ if (user.getId() != null) ids.add(user.getId()); } return ids; @@ -2289,9 +2029,6 @@ public boolean canUserAccess(HttpServletRequest request) { List ids = new ArrayList(); for (User user : myShepherd.getAllUsers()) { -/* FIXME we do not have edit stuff for MarkedIndividual - if ((user.getId() != null) && this.canUserEdit(user)) ids.add(user.getId()); - */ if (user.getId() != null) ids.add(user.getId()); } return ids; @@ -2307,7 +2044,6 @@ public JSONObject sanitizeJson(HttpServletRequest request, JSONObject jobj) jobj.remove("timeOfDeath"); jobj.remove("timeOfBirth"); jobj.remove("maxYearsBetweenResightings"); - // jobj.remove("numUnidentifiableEncounters"); jobj.remove("nickName"); jobj.remove("nickNamer"); jobj.put("_sanitized", true); @@ -2367,7 +2103,7 @@ public String getUrl(HttpServletRequest request) { /** * returns an array of the MediaAsset sanitized JSON, because whenever UI queries our DB (regardless of class query), all they want in return are - * MediaAssets TODO: decorate with metadata + * MediaAssets; does not include metadata **/ public org.datanucleus.api.rest.orgjson.JSONArray sanitizeMedia(HttpServletRequest request) throws org.datanucleus.api.rest.orgjson.JSONException { @@ -2445,18 +2181,14 @@ public ArrayList getExemplarImagesW ArrayList al = new ArrayList(); List kwNamesLeft = new ArrayList(kwNames); // a copy of kwNames - // boolean haveProfilePhoto=false; for (Encounter enc : this.getDateSortedEncounters()) { - // if((enc.getDynamicPropertyValue("PublicView")==null)||(enc.getDynamicPropertyValue("PublicView").equals("Yes"))){ ArrayList anns = enc.getAnnotations(); if ((anns == null) || (anns.size() < 1)) { continue; } for (Annotation ann : anns) { - // if (!ann.isTrivial()) continue; MediaAsset ma = ann.getMediaAsset(); if (ma != null) { - // JSONObject j = new JSONObject(); JSONObject j = ma.sanitizeJson(req, new JSONObject()); // we get a url which is potentially more detailed than we might normally be allowed (e.g. anonymous user) @@ -2528,8 +2260,6 @@ public ArrayList getBestKeywordPhot al.add(j); } } - // myShepherd.rollbackDBTransaction(); - // myShepherd.closeDBTransaction(); return al; } @@ -2785,7 +2515,6 @@ public void mergeIndividual(MarkedIndividual other, String username, Shepherd my this.names.merge(other.getNames()); this.setComments(getMergedComments(other, username)); - // WB-951: merge relationships ArrayList rels = myShepherd.getAllRelationshipsForMarkedIndividual( other.getIndividualID()); if (rels != null && rels.size() > 0) { @@ -2801,7 +2530,6 @@ public void mergeIndividual(MarkedIndividual other, String username, Shepherd my } } } - // WB-951: merge social units List units = myShepherd.getAllSocialUnitsForMarkedIndividual(other); if (units != null && units.size() > 0) { for (SocialUnit unit : units) { diff --git a/src/main/java/org/ecocean/MetricsBot.java b/src/main/java/org/ecocean/MetricsBot.java index dbd8805061..0ce00ecb30 100644 --- a/src/main/java/org/ecocean/MetricsBot.java +++ b/src/main/java/org/ecocean/MetricsBot.java @@ -56,7 +56,7 @@ public static boolean startServices(String context) { // basically our "listener" daemon; but is more pull (poll?) than push so to speak. private static void startCollector(final String context) { // throws IOException { - collectorStartTime = System.currentTimeMillis(); // TODO should really be keyed off context! + collectorStartTime = System.currentTimeMillis(); long interval = 60; // number minutes between metrics refreshes of data in the CSV long initialDelay = 1; // number minutes before first execution occurs System.out.println("+ MetricsBot.startCollector(" + context + ") starting."); @@ -89,7 +89,7 @@ public void run() { System.out.println("+ MetricsBot.startCollector(" + context + ") backgrounded"); } - // mostly for ContextDestroyed in StartupWildbook..... i think? + // mostly for ContextDestroyed in StartupWildbook public static void cleanup() { System.out.println( "================ = = = = = = ===================== MetricsBot.cleanup() finished."); @@ -537,27 +537,6 @@ private static void addTasksToCsv(ArrayList csvLines, String context) filterTasksUsersQuery.closeAll(); // end WB-1968 - // too slow and error-prone for various usernames - /* - for (User user:users) - { - // Try catch for nulls, because tasks executed by anonymous users don't have a name tied to them String userFilter = ""; - String name = ""; - try{ - userFilter = (String) user.getUsername(); - - name+=user.getUUID(); - - name=name.replaceAll("-", "_"); - //System.out.println("NAME:" + name); - csvLines.add(buildGauge("SELECT count(this) FROM org.ecocean.ia.Task where parameters.indexOf(" + "'" + userFilter + "'" + ") > -1 && - (parameters.indexOf('ibeis.identification') > -1 || parameters.indexOf('pipeline_root') > -1 || parameters.indexOf('graph') > - -1)","wildbook_user_tasks_"+name, "Number of tasks from user " + name, context)); - } - catch (NullPointerException e) {e.printStackTrace(); } - catch(java.util.regex.PatternSyntaxException pe) {pe.printStackTrace();} - } - */ } catch (Exception exy) { exy.printStackTrace(); } finally { myShepherd.rollbackAndClose(); } diff --git a/src/main/java/org/ecocean/Occurrence.java b/src/main/java/org/ecocean/Occurrence.java index 60b109ddec..c66d3a33d6 100644 --- a/src/main/java/org/ecocean/Occurrence.java +++ b/src/main/java/org/ecocean/Occurrence.java @@ -95,7 +95,7 @@ public class Occurrence extends Base implements java.io.Serializable { private Integer numCalves; private String observer; - private String submitterID; // not sure if this should atrophy, now that we have .submitters ??? TODO what does Encounter do? + private String submitterID; private List submitters; private List informOthers; @@ -129,10 +129,6 @@ public Occurrence(String occurrenceID, Encounter enc) { assets = new ArrayList(); setDWCDateLastModified(); setDateTimeCreated(); - // if(encounters!=null){ - // updateNumberOfEncounters(); - // } - // if((enc.getLocationID()!=null)&&(!enc.getLocationID().equals("None"))){this.locationID=enc.getLocationID();} } public Occurrence(List assets, Shepherd myShepherd) { @@ -167,12 +163,6 @@ public boolean addEncounter(Encounter enc) { return true; } - // private void updateNumberOfEncounters() { - // if (individualCount!=null) { - // individualCount = encounters.size(); - // } - // } - // like addEncounter but adds backwards link to this enc public void addEncounterAndUpdateIt(Encounter enc) { addEncounter(enc); @@ -221,7 +211,6 @@ public boolean addAsset(MediaAsset ma) { } } if (isNew) { assets.add(ma); } - // if((locationID!=null) && (enc.getLocationID()!=null)&&(!enc.getLocationID().equals("None"))){this.locationID=enc.getLocationID();} return isNew; } @@ -311,7 +300,6 @@ public List getAssets() { public void removeEncounter(Encounter enc) { if (encounters != null) { encounters.remove(enc); - // updateNumberOfEncounters(); } } @@ -395,16 +383,12 @@ public ArrayList getMarkedIndividualNamesForThisOccurrence() { return names; } - /** - * ##DEPRECATED #509 - Base class setId() method - */ + //TODO: validate and remove if ##DEPRECATED #509 - Base class setId() method public void setID(String id) { occurrenceID = id; } - /** - * ##DEPRECATED #509 - Base class getId() method - */ + //TODO: validate and remove if ##DEPRECATED #509 - Base class setId() method public String getID() { return occurrenceID; } @@ -417,34 +401,22 @@ public String getWebUrl(HttpServletRequest req) { return getWebUrl(getOccurrenceID(), req); } - /** - * ##DEPRECATED #509 - Base class getId() method - */ + //TODO: validate and remove if ##DEPRECATED #509 - Base class setId() method public String getOccurrenceID() { return occurrenceID; } - /** - * Retrieves the Occurrence Id. - * - * @return Occurrence Id String - */ + // Retrieves the Occurrence Id. @Override public String getId() { return occurrenceID; } - /** - * Sets the Occurrence Id. - * - * @param id The Occurrence Id to set - */ + // Sets the Occurrence Id. @Override public void setId(String id) { occurrenceID = id; } - /** - * ##DEPRECATED #509 - Base class setId() method - */ + //TODO: validate and remove if ##DEPRECATED #509 - Base class setId() method public void setOccurrenceID(String id) { occurrenceID = id; } @@ -506,11 +478,7 @@ public Encounter[] getDateSortedEncounters(boolean reverse) { return encs2; } - /** - * Returns any additional, general comments recorded for this Occurrence as a whole. - * - * @return a String of comments - */ + // Returns any additional, general comments recorded for this Occurrence as a whole. @Override public String getComments() { if (comments != null) { return comments; @@ -519,20 +487,12 @@ public Encounter[] getDateSortedEncounters(boolean reverse) { } } - /** - * Sets any additional, general comments recorded for this Occurrence as a whole. - * - * @return a String of comments - */ + // Sets any additional, general comments recorded for this Occurrence as a whole. @Override public void setComments(String comments) { this.comments = comments; } - /** - * Returns any additional, general comments recorded for this Occurrence as a whole. - * - * @return a String of comments - */ + // Returns any additional, general comments recorded for this Occurrence as a whole. public String getCommentsExport() { if (comments != null && !(comments.equals("None"))) { return comments; @@ -541,11 +501,7 @@ public String getCommentsExport() { } } - /** - * Adds any general comments recorded for this Occurrence as a whole. - * - * @return a String of comments - */ + // Adds any general comments recorded for this Occurrence as a whole. @Override public void addComments(String newComments) { if ((comments != null) && (!(comments.equals("None")))) { comments += newComments; @@ -597,7 +553,6 @@ public Long getMillisRobust() { public Vector returnEncountersWithGPSData(boolean useLocales, boolean reverseOrder, String context, HttpServletRequest request) { - // if(unidentifiableEncounters==null) {unidentifiableEncounters=new Vector();} Vector haveData = new Vector(); Encounter[] myEncs = getDateSortedEncounters(reverseOrder); @@ -734,11 +689,7 @@ public void setDWCDateLastModified() { modified = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new java.util.Date()); } - /** - * This method simply iterates through the encounters for the occurrence and returns the first Encounter.locationID that it finds or returns null. - * - * @return - */ + // This method simply iterates through the encounters for the occurrence and returns the first Encounter.locationID that it finds or returns null. public String getLocationID() { int size = encounters.size(); @@ -803,8 +754,6 @@ public Survey getSurvey(Shepherd myShepherd) { return null; } - // public void setLocationID(String newLocID){this.locationID=newLocID;} - public String getDateTimeCreated() { if (dateTimeCreated != null) { return dateTimeCreated; @@ -870,7 +819,7 @@ public boolean canUserAccess(HttpServletRequest request) { List ids = new ArrayList(); for (User user : myShepherd.getAllUsers()) { -/* FIXME we do not have user-flavored Collaboration.canUserAccessOccurrence yet +/* TODO: we do not have user-flavored Collaboration.canUserAccessOccurrence yet if ((user.getId() != null) && this.canUserAccess(user, myShepherd.getContext())) ids.add(user.getId()); */ if (user.getId() != null) ids.add(user.getId()); @@ -882,7 +831,7 @@ public boolean canUserAccess(HttpServletRequest request) { List ids = new ArrayList(); for (User user : myShepherd.getAllUsers()) { -/* FIXME we do not have edit stuff for occurrence +/* TODO: we do not have edit stuff for occurrence if ((user.getId() != null) && this.canUserEdit(user)) ids.add(user.getId()); */ if (user.getId() != null) ids.add(user.getId()); @@ -909,44 +858,6 @@ public JSONObject uiJson(HttpServletRequest request) return sanitizeJson(request, decorateJson(request, jobj)); } -///* this was messing up the co-occur js (d3?), so lets kill for now? -// public org.datanucleus.api.rest.orgjson.JSONObject sanitizeJson(HttpServletRequest request, -// org.datanucleus.api.rest.orgjson.JSONObject jobj) throws org.datanucleus.api.rest.orgjson.JSONException { -// return sanitizeJson(request, jobj, true); -// } -// -// public org.datanucleus.api.rest.orgjson.JSONObject sanitizeJson(HttpServletRequest request, org.datanucleus.api.rest.orgjson.JSONObject jobj, -// boolean fullAccess) throws org.datanucleus.api.rest.orgjson.JSONException { -// jobj.put("ID", this.occurrenceID); -// jobj.put("encounters", this.encounters); -// if ((this.getEncounters() != null) && (this.getEncounters().size() > 0)) { -// JSONArray jarr = new JSONArray(); -///// *if* we want full-blown: public JSONObject Encounter.sanitizeJson(HttpServletRequest request, JSONObject jobj) throws JSONException { -////but for *now* (see note way above) this is all we need for gallery/image display js: -// for (Encounter enc : this.getEncounters()) { -// JSONObject je = new JSONObject(); -// je.put("id", enc.getID()); -// if (enc.hasMarkedIndividual()) je.put("individualID", enc.getIndividualID()); -// if ((enc.getAnnotations() != null) && (enc.getAnnotations().size() > 0)) { -// JSONArray ja = new JSONArray(); -// for (Annotation ann : enc.getAnnotations()) { -// ja.put(ann.getId()); -// } -// je.put("annotations", ja); -// } -// jarr.put(je); -// } -// jobj.put("encounters", jarr); -// } -// int[] assetIds = new int[this.assets.size()]; -// for (int i=0; i getExemplarImages( throws JSONException { ArrayList al = new ArrayList(); - // boolean haveProfilePhoto=false; for (Encounter enc : this.getDateSortedEncounters(false)) { - // if((enc.getDynamicPropertyValue("PublicView")==null)||(enc.getDynamicPropertyValue("PublicView").equals("Yes"))){ ArrayList anns = enc.getAnnotations(); if ((anns == null) || (anns.size() < 1)) { continue; } for (Annotation ann : anns) { - // if (!ann.isTrivial()) continue; MediaAsset ma = ann.getMediaAsset(); if (ma != null) { - // JSONObject j = new JSONObject(); JSONObject j = ma.sanitizeJson(req, new JSONObject()); if (j != null) { // ok, we have a viable candidate @@ -989,7 +896,6 @@ public ArrayList getExemplarImages( } } } - // } } return al; } diff --git a/src/main/java/org/ecocean/OpenSearch.java b/src/main/java/org/ecocean/OpenSearch.java index 2e64446906..64b3c78be7 100644 --- a/src/main/java/org/ecocean/OpenSearch.java +++ b/src/main/java/org/ecocean/OpenSearch.java @@ -583,8 +583,8 @@ public static JSONObject querySanitize(JSONObject query, User user) { return newQuery; } - // TODO right now this respects index timestamp and only indexes objects with versions > timestamp. - // probably want to make an option to index everything and ignore version/timestamp. + // TODO: right now this respects index timestamp and only indexes objects with versions > timestamp. + // want to make an option to index everything and ignore version/timestamp. public void indexAll(Shepherd myShepherd, Base obj) throws IOException { String clause = ""; diff --git a/src/main/java/org/ecocean/Organization.java b/src/main/java/org/ecocean/Organization.java index a9ca6fc2b6..2694d109bb 100644 --- a/src/main/java/org/ecocean/Organization.java +++ b/src/main/java/org/ecocean/Organization.java @@ -215,11 +215,6 @@ public boolean removeChild(Organization kid) { return true; } -/* not sure if this is evil ?? - public void setParent(Organization t) { - parent = t; - } - */ public Organization getParent() { return parent; } @@ -299,7 +294,7 @@ public boolean canManage(User user, Shepherd myShepherd) { if (user == null) return false; if (user.hasRoleByName("admin", myShepherd) || user.hasRoleByName(ROLE_ADMIN, myShepherd)) return true; - if (!this.hasMember(user)) return false; // TODO should this be .hasMemberDeep() ? + if (!this.hasMember(user)) return false; return user.hasRoleByName(ROLE_MANAGER, myShepherd); } @@ -429,29 +424,4 @@ public static Organization load(String id, Shepherd myShepherd) { } catch (Exception ex) {}; // swallow jdo not found noise return o; } - -/* - public static List getOrganizationsFor(Annotation ann, Shepherd myShepherd) { - String qstr = "SELECT FROM org.ecocean.ia.Organization WHERE objectAnnotations.contains(obj) && obj.id == \"" + ann.getId() + "\" VARIABLES - org.ecocean.Annotation obj"; - Query query = myShepherd.getPM().newQuery(qstr); - query.setOrdering("created"); - return (List) query.execute(); - } - public static List getRootOrganizationsFor(Annotation ann, Shepherd myShepherd) { - return onlyRoots(getOrganizationsFor(ann, myShepherd)); - } - - public static List getOrganizationsFor(MediaAsset ma, Shepherd myShepherd) { - String qstr = "SELECT FROM org.ecocean.ia.Organization WHERE objectMediaAssets.contains(obj) && obj.id == " + ma.getId() + " VARIABLES - org.ecocean.media.MediaAsset obj"; - Query query = myShepherd.getPM().newQuery(qstr); - query.setOrdering("created"); - return (List) query.execute(); - } - public static List getRootOrganizationsFor(MediaAsset ma, Shepherd myShepherd) { - return onlyRoots(getOrganizationsFor(ma, myShepherd)); - } - - */ } diff --git a/src/main/java/org/ecocean/PPSR.java b/src/main/java/org/ecocean/PPSR.java index 53a2ea73fb..599bc5249f 100644 --- a/src/main/java/org/ecocean/PPSR.java +++ b/src/main/java/org/ecocean/PPSR.java @@ -54,7 +54,6 @@ public static JSONObject generateJSONObject(String context) // the rest of these are optional _setJSON(context, jobj, "twitter_name", "ProjectTwitter", null); _setJSON(context, jobj, "facebook_page", "ProjectFacebook", null); - /////// etc! add these later.... TODO /// note: "image" // self-promotion a little bit @@ -140,18 +139,3 @@ private static Properties getProperties(String context) { } } } - -/* - - * exhaustive* list of properties scistarter accepts. - https://scistarter.com/api#add for details - - it appears that scistarter *also* supports all of these (untested) https://www.citsci.org/CWIS438/Websites/CitSci/PPSR_CORE_Documentation.php - - in properties file, scistarter ones are prepended with "sciStarter." and PPSR with "ppsr." - - name scistarter_id description url origin contact_name contact_affiliation contact_email contact_phone contact_address presenting_org rsvp address - * city state zip country video_url blog_url twitter_name facebook_page status preregistration goal task image image_credit how_to_join - * special_skills gear outdoors indoors time_commitment project_type audience regions region_label UN_regions - - */ diff --git a/src/main/java/org/ecocean/PatterningPassport.java b/src/main/java/org/ecocean/PatterningPassport.java index 9ef644572d..d89935c5f7 100644 --- a/src/main/java/org/ecocean/PatterningPassport.java +++ b/src/main/java/org/ecocean/PatterningPassport.java @@ -74,9 +74,9 @@ private Boolean makeNewPassportXml(String context) { CommonConfiguration.getDataDirectoryName(context)); // Universal passport fields for the XML - String encounterUrlString = "foo/" + this.encounterId; // TODO -- generate URL - String mediaSourceUrlString = "foo/" + this.mediaId; // TODO -- generate URL - String passportXmlUrlString = "foo"; // TODO -- generate URL + String encounterUrlString = "foo/" + this.encounterId; // TODO: -- generate URL + String mediaSourceUrlString = "foo/" + this.mediaId; // TODO: -- generate URL + String passportXmlUrlString = "foo"; // TODO: -- generate URL String encounterDir = this.webappsDir + "/shepherd_data_dir/encounters/" + this.encounterId; String xmlFilePathString = encounterDir + "/" + mediaId + "_pp.xml"; @@ -182,7 +182,7 @@ public Boolean setPassportDataXml(String passportDataXml, String context) { * @return the encounterUrl */ public String getEncounterUrl() { - // TODO read it from XML if needed + // TODO: read it from XML if needed return encounterUrl; } @@ -198,7 +198,7 @@ public void setEncounterUrl(String encounterUrl) { * @return the mediaUrl */ public String getMediaUrl() { - // TODO read it from XML if needed + // TODO: read it from XML if needed return mediaUrl; } @@ -214,7 +214,7 @@ public void setMediaUrl(String mediaUrl) { * @return the patterningPassportXmlUrl */ public String getPatterningPassportXmlUrl() { - // TODO read it from XML if needed + // TODO: read it from XML if needed return patterningPassportXmlUrl; } diff --git a/src/main/java/org/ecocean/PointLocation.java b/src/main/java/org/ecocean/PointLocation.java index fda0d75454..84049489ac 100644 --- a/src/main/java/org/ecocean/PointLocation.java +++ b/src/main/java/org/ecocean/PointLocation.java @@ -186,7 +186,6 @@ private boolean latLonCheck(Double lat, Double lon) { } // distance squared - // TODO maybe also take into account time? elev? etc? public Double diff2(PointLocation p2) { if (p2 == null) return null; if ((this.longitude == null) || (this.latitude == null) || (p2.longitude == null) || diff --git a/src/main/java/org/ecocean/RestClient.java b/src/main/java/org/ecocean/RestClient.java index 7091fee3ea..55463e7d7d 100644 --- a/src/main/java/org/ecocean/RestClient.java +++ b/src/main/java/org/ecocean/RestClient.java @@ -1,8 +1,5 @@ package org.ecocean; -/* NOTE: due to the authentication header stuff, this is effectively IBEIS-specific. break this out later i guess! TODO - - 2018-02-02 - i am starting to break this out into generic... but very much a work-in-progress.... see methods at the end of the file which will - hopefully allow control over auth stuff better.... -jon +/* NOTE: due to the authentication header stuff, this is effectively IBEIS-specific but starting to break this out into generic. Still a work-in-progress.... see methods at the end of the file which will hopefully allow control over auth stuff better */ import java.io.BufferedReader; @@ -33,7 +30,6 @@ */ public class RestClient { - ///TODO this is IBEIS-specific -- need to generalize for RestClient to be universal private static final String HMAC_SHA1_ALGORITHM = "HmacSHA1"; private static final int CONNECTION_TIMEOUT = 300000; // maybe this should be service-specific? @@ -96,7 +92,7 @@ private static JSONObject anyMethod(String method, URL url, JSONObject data, int conn.connect(); boolean success = true; - // TODO the 600 response here is IBEIS-specific, so we need to genericize this + // the 600 response here is IBEIS-specific, so we need to genericize this if ((conn.getResponseCode() != HttpURLConnection.HTTP_OK) && (conn.getResponseCode() != 600)) { // conn.disconnnect(); @@ -105,13 +101,7 @@ private static JSONObject anyMethod(String method, URL url, JSONObject data, int success = false; } BufferedReader br = null; -/* - if (success) { - br = new BufferedReader(new InputStreamReader((conn.getInputStream()))); - } else { - br = new BufferedReader(new InputStreamReader((conn.getErrorStream()))); - } - */ + try { br = new BufferedReader(new InputStreamReader((conn.getInputStream()))); } catch (IOException ioe) { @@ -132,17 +122,6 @@ private static JSONObject anyMethod(String method, URL url, JSONObject data, int if (jtext.equals("")) return null; return new JSONObject(jtext); -/* - } catch (MalformedURLException e) { - - e.printStackTrace(); - - } catch (IOException e) { - - e.printStackTrace(); - - } - */ } public static JSONObject postStream(URL url, InputStream in) @@ -156,7 +135,6 @@ public static JSONObject postStream(URL url, InputStream in) conn.setDoInput(true); conn.setRequestMethod("POST"); conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); - // conn.setRequestProperty("Authorization", getAuthorizationHeader(url.toString())); OutputStream os = conn.getOutputStream(); byte[] buffer = new byte[10240]; int len; @@ -172,7 +150,6 @@ public static JSONObject postStream(URL url, InputStream in) boolean success = true; if ((conn.getResponseCode() != HttpURLConnection.HTTP_OK)) { - // conn.disconnnect(); System.out.println("!!!!!!!!!!!!!!!!!!! bad response code = " + conn.getResponseCode()); success = false; } @@ -181,24 +158,9 @@ public static JSONObject postStream(URL url, InputStream in) rtn.put("error", conn.getResponseCode()); return rtn; } -/* - InputStream is = request.getInputStream(); - byte buffer[] = new byte[10240]; - int i; - System.out.println("before...."); - while ((i = is.read(buffer)) > 0) { - System.out.write(buffer, 0, i); - } - */ BufferedReader br = null; -/* - if (success) { - br = new BufferedReader(new InputStreamReader((conn.getInputStream()))); - } else { - br = new BufferedReader(new InputStreamReader((conn.getErrorStream()))); - } - */ + try { br = new BufferedReader(new InputStreamReader((conn.getInputStream()))); } catch (IOException ioe) { @@ -211,19 +173,13 @@ public static JSONObject postStream(URL url, InputStream in) jtext += output; } br.close(); - // conn.disconnect(); -/* - if (!success) { - System.out.println("========= anyMethod failed with code=" + conn.getResponseCode() + "\n" + jtext + "\n============"); - throw new RuntimeException("Failed : HTTP error code : " + conn.getResponseCode()); - } - */ + if (jtext.equals("")) return null; System.out.println("======================== postStream -> " + jtext); return new JSONObject(jtext); } - ///TODO this chunk below is IBEIS-specific -- need to generalize for RestClient to be universal + // this chunk below is IBEIS-specific -- need to generalize for RestClient to be universal private static String getSignature(String key, byte[] messageToSendBytes) throws NoSuchAlgorithmException, InvalidKeyException { @@ -242,7 +198,7 @@ public static String getAuthorizationHeader(String url) return appName + ":" + getSignature(appSecret, url.getBytes()); } - ///// end TODO + // end IBEIS-specific private static String getPostDataString(JSONObject obj) { StringBuilder result = new StringBuilder(); @@ -283,9 +239,10 @@ public static void writeToFile(URL url, File file) } /*********************************************************************************************** + TODO: evaluate strategy, rewrite as needed and define future actions that need to be taken to truly update some attempts to *truly* genericize these.... - rather than authUsername/authPassword, we might want to have our own credential class that allows us to set headers etc accordingly! TODO + rather than authUsername/authPassword, we might want to have our own credential class that allows us to set headers etc accordingly! note also that data passed in (for post) is a string, so encode it accordingly first one annoying thing we attempt to handle now is that there may be plain-text returned (not always json) @@ -318,14 +275,12 @@ private static String anyMethodGeneric(String method, URL url, String authUserna throws RuntimeException, MalformedURLException, IOException, NoSuchAlgorithmException, InvalidKeyException { System.out.println("TRYING anyMethodGeneric(" + method + ") url -> " + url); - // System.setProperty("http.keepAlive", "false"); HttpURLConnection conn = (HttpURLConnection)url.openConnection(); conn.setReadTimeout(ctimeout); conn.setConnectTimeout(ctimeout); conn.setDoOutput((data != null)); conn.setDoInput(true); conn.setRequestMethod(method); - ////conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); TODO should this be here for GET ??? if ((authUsername != null) && (authPassword != null)) { byte[] authBytes = (authUsername + ":" + authPassword).getBytes("UTF-8"); String authEncoded = javax.xml.bind.DatatypeConverter.printBase64Binary(authBytes); @@ -341,7 +296,6 @@ private static String anyMethodGeneric(String method, URL url, String authUserna boolean success = true; if (conn.getResponseCode() != HttpURLConnection.HTTP_OK) { - // conn.disconnnect(); success = false; } BufferedReader br = null; @@ -356,7 +310,6 @@ private static String anyMethodGeneric(String method, URL url, String authUserna jtext += output; } br.close(); - // conn.disconnect(); if (!success) { System.out.println("========= anyMethod failed with code=" + conn.getResponseCode() + "\n" + jtext + "\n============"); @@ -403,7 +356,6 @@ public static String postRaw(URL url, String data, Map headers) jtext += output; } br.close(); - // conn.disconnect(); if (!success) { System.out.println("WARNING: postRaw() on " + url + " failed with code=" + conn.getResponseCode() + "\n" + jtext + "\n============"); diff --git a/src/main/java/org/ecocean/Shepherd.java b/src/main/java/org/ecocean/Shepherd.java index a8bb11e276..4575511c6b 100644 --- a/src/main/java/org/ecocean/Shepherd.java +++ b/src/main/java/org/ecocean/Shepherd.java @@ -46,45 +46,27 @@ import org.json.JSONArray; /** - * Shepherd is the main information retrieval, processing, and persistence class to be used for all shepherd - * project applications. The shepherd class interacts directly with the database and all persistent objects stored within it. - * Any application seeking access to whale shark data must invoke an instance of shepherd first and use it to retrieve any data stored + * Shepherd is the main information retrieval, processing, and persistence class to be used for all shepherd + * project applications. The shepherd class interacts directly with the database and all persistent objects stored within it. + * Any application seeking access to encounter data must invoke an instance of shepherd first and use it to retrieve any data stored * in the database. - *

- * While a shepherd object is easily invoked with a single, simple constructor, no data can be retrieved until a new - * Transaction has been started. Changes made using the Transaction must be committed (store changes) or rolled back (ignore changes) before the - * application can finish. Example: - *

- *

- * shepherd myShepherd=new shepherd();
- * myShepherd.beginDBTransaction(); - *

Now make any changes to the database objects that are needed. - *

- *

- * myShepherd.commitDBTransaction(); - * *myShepherd.closeDBTransaction(); - * - *

* * @author Jason Holmberg * @version alpha-2 * @see shark, encounter, superSpot, spot */ + public class Shepherd { private PersistenceManager pm; public static Vector matches = new Vector(); - // private PersistenceManagerFactory pmf; private String localContext; private String action = "undefined"; private String shepherdID = ""; - /** - * Constructor to create a new shepherd thread object - */ + // Constructor to create a new shepherd thread object public Shepherd(String context) { if (pm == null || pm.isClosed()) { - // PersistenceManagerFactory pmf = ShepherdPMF.getPMF(context); localContext = context; try { pm = ShepherdPMF.getPMF(localContext).getPersistenceManager(); @@ -96,7 +78,6 @@ public Shepherd(String context) { "Hit an excpetion while trying to instantiate a PM. Not fatal I think."); e.printStackTrace(); } - // pmf=null; } } @@ -135,10 +116,6 @@ public String getDataDirectoryName() { return CommonConfiguration.getDataDirectoryName(getContext()); } - // public PersistenceManagerFactory getPMF() { - // return pmf; - // } - /** * Stores a new, unassigned encounter in the database for later retrieval and analysis. Each new encounter is assigned a unique number which is * also its unique retrievable ID in the database. This method will be the primary method used for future web submissions to shepherd from @@ -170,7 +147,6 @@ public String storeNewEncounter(Encounter enc) { } public String storeNewAnnotation(Annotation enc) { - // enc.setOccurrenceID(uniqueID); beginDBTransaction(); try { pm.makePersistent(enc); @@ -206,7 +182,6 @@ public String storeNewWorkspace(Workspace wSpace) { } public void storeNewOccurrence(Occurrence enc) { - // enc.setOccurrenceID(uniqueID); beginDBTransaction(); try { pm.makePersistent(enc); @@ -475,36 +450,16 @@ public void throwAwayCollaboration(Collaboration collab) { } public void throwAwayTissueSample(TissueSample genSample) { - // String removedParameters = genSample.getHTMLString(); - // List list=genSample.getGeneticAnalyses(); - /* - for(int i=0;i0){ - Locus l=analysis.getLoci().get(0); - analysis.getLoci().remove(0); - pm.deletePersistent(l); - } - */ pm.deletePersistent(analysis); - // return removedParameters; } public void throwAwayAnnotation(Annotation ad) { @@ -752,32 +707,6 @@ public ArrayList getMediaAssetsForOwner(String owner, String status) } } - // like above but filters on Workspace.isImageSet - /* - public ArrayList getWorkspacesForUser(String owner, boolean isImageSet) { - String quotedOwner = (owner==null) ? "null" : ("\""+owner+"\'"); - - String isImageSetBit = isImageSet ? "1" : "0"; - - String filter = "this.owner == "+quotedOwner+" && this.isImageSet == "+isImageSetBit; - - Extent allWorkspaces = pm.getExtent(Workspace.class, true); - Query workspaceQuery = pm.newQuery(allWorkspaces, filter); - workspaceQuery.setOrdering("accessed descending"); - - try { - Collection results = (Collection) (workspaceQuery.execute()); - ArrayList resultList = new ArrayList(); - if (results!=null) { - resultList = new ArrayList(results); - } - workspaceQuery.closeAll(); - return resultList; - } catch (Exception npe) { - npe.printStackTrace(); - return null; - } - }*/ public ArrayList getWorkspacesForUser(String owner, boolean isImageSet) throws JSONException { ArrayList unfilteredSpaces = getWorkspacesForUser(owner); @@ -884,10 +813,6 @@ public SocialUnit getCommunity(String name) { return tempCom; } - // public ArrayList getMembershipsForMarkedIndividual(MarkedIndividual mi) { - - // } - public List getAllSocialUnitsForMarkedIndividual(MarkedIndividual indie) { String filter2use = "SELECT FROM org.ecocean.social.SocialUnit WHERE members.contains(member) && member.mi.individualID == '" @@ -1098,9 +1023,6 @@ public Organization getOrCreateOrganizationByName(String name, boolean commit) { } public String storeNewOrganization(Organization org) { - // enc.setOccurrenceID(uniqueID); - // boolean transactionWasActive = isDBTransactionActive(); - // beginDBTransaction(); try { pm.makePersistent(org); commitDBTransaction(); @@ -1112,10 +1034,6 @@ public String storeNewOrganization(Organization org) { e.printStackTrace(); return "fail"; } - // finally { - // closeDBTransaction(); - // } - // if (transactionWasActive) beginDBTransaction(); return (org.getId()); } @@ -1498,7 +1416,6 @@ public Taxonomy getTaxonomyById(String id) { } public String storeNewTaxonomy(Taxonomy enc) { - // enc.setOccurrenceID(uniqueID); boolean transactionWasActive = isDBTransactionActive(); beginDBTransaction(); @@ -1579,7 +1496,6 @@ public List getKeywordsInCommon(String encounterNumber1, String encounte while (keywords.hasNext()) { Keyword kw = keywords.next(); - // if ((kw.isMemberOf(enc1)) && (kw.isMemberOf(enc2))) { if (enc1.hasKeyword(kw) && enc2.hasKeyword(kw)) { inCommon.add(kw.getReadableName()); } @@ -1999,9 +1915,9 @@ public boolean isRelationship(String type, String markedIndividualName1, } /** - * Adds a new shark to the database + * Adds a new individual to the database TODO: newShark -> newIndividual * - * @param newShark the new shark to be added to the database + * @param newShark the new individual to be added to the database * @see MarkedIndividual */ public boolean addMarkedIndividual(MarkedIndividual newShark) { @@ -2015,15 +1931,7 @@ public boolean addMarkedIndividual(MarkedIndividual newShark) { * @return an Iterator of shark encounters that have yet to be assigned shark status or assigned to an existing shark in the database * @see encounter, java.util.Iterator */ - /* - public Iterator getUnassignedEncounters() { - String filter = "this.individual == null"; - Extent encClass = pm.getExtent(Encounter.class, true); - Query orphanedEncounters = pm.newQuery(encClass, filter); - Collection c = (Collection) (orphanedEncounters.execute()); - return c.iterator(); - } - */ + public List getMediaAssetsFromStore(int assetStoreId) { String filter = "SELECT FROM org.ecocean.media.MediaAsset WHERE this.assetStore == as && as.id == " + @@ -2038,40 +1946,7 @@ public List getMediaAssetsFromStore(int assetStoreId) { return al; } - /* - public Iterator getUnassignedEncountersIncludingUnapproved() { - String filter = "this.individual == null"; - Extent encClass = pm.getExtent(Encounter.class, true); - Query orphanedEncounters = pm.newQuery(encClass, filter); - Collection c = (Collection) (orphanedEncounters.execute()); - return c.iterator(); - } - */ - -/* - public Iterator getUnassignedEncountersIncludingUnapproved(Query orphanedEncounters) { - String filter = "this.individual == null && this.state != \"unidentifiable\""; - //Extent encClass=pm.getExtent(encounter.class, true); - orphanedEncounters.setFilter(filter); - Collection c = (Collection) (orphanedEncounters.execute()); - return c.iterator(); - } - */ public Iterator getAllEncountersNoFilter() { - /*Collection c; - Extent encClass = pm.getExtent(Encounter.class, true); - Query acceptedEncounters = pm.newQuery(encClass); - try { - c = (Collection) (acceptedEncounters.execute()); - //ArrayList list = new ArrayList(c); - Iterator it = c.iterator(); - return it; - } catch (Exception npe) { - System.out.println("Error encountered when trying to execute getAllEncountersNoFilter. Returning a null collection because I didn't have a - transaction to use."); - npe.printStackTrace(); - return null; - }*/ return getAllEncountersNoQuery(); } @@ -2248,21 +2123,6 @@ public Iterator getAllScanWorkItemsNoQuery() { * @see encounter, java.util.Iterator */ public Iterator getAllEncounters() { - /*Collection c; - //String filter = "!this.state == \"unidentifiable\" && this.state == \"approved\""; - Extent encClass = pm.getExtent(Encounter.class, true); - Query acceptedEncounters = pm.newQuery(encClass); - try { - c = (Collection) (acceptedEncounters.execute()); - ArrayList list = new ArrayList(c); - Iterator it = list.iterator(); - return it; - } catch (Exception npe) { - System.out.println("Error encountered when trying to execute getAllEncounters. Returning a null collection because I didn't have a - transaction to use."); - npe.printStackTrace(); - return null; - }*/ return getAllEncountersNoQuery(); } @@ -2494,28 +2354,6 @@ public List getPairs(Query query, int pageSize) { } } -/** - public Iterator getAllEncountersAndUnapproved() { - Collection c; - String filter = "this.state != \"unidentifiable\""; - Extent encClass = pm.getExtent(Encounter.class, true); - Query acceptedEncounters = pm.newQuery(encClass, filter); - try { - c = (Collection) (acceptedEncounters.execute()); - ArrayList list = new ArrayList(c); - int wr = list.size(); - Iterator it = list.iterator(); - return it; - } catch (Exception npe) { - System.out.println("Error encountered when trying to execute getAllEncounters. Returning a null collection because I didn't have a transaction - to use."); - npe.printStackTrace(); - return null; - } - - } - */ - /** * Retrieves all encounters that are stored in the database in the order specified by the input String * @@ -2716,21 +2554,6 @@ public User getUserBySocialId(String service, String id) { if (id.equals(users.get(i).getSocial(service))) return users.get(i); } return null; - -/* TODO figure out how to query on HashMaps within fields String filter="SELECT FROM org.ecocean.User WHERE social_" + service + " == \"" + id + - "\""; - Query query=getPM().newQuery(filter); - Collection c = (Collection) (query.execute()); - Iterator it = c.iterator(); - - while(it.hasNext()){ - User myUser=(User)it.next(); - query.closeAll(); - return myUser; - } - query.closeAll(); - return null; - */ } public ArrayList getAllProjectsForMarkedIndividual(MarkedIndividual individual) { @@ -2813,7 +2636,7 @@ public List getAllOtherIndividualsOccurringWithMarkedIndividual( } } } - } // end if + } ArrayList as = new ArrayList(hmap.entrySet()); if (as.size() > 0) { @@ -2896,17 +2719,6 @@ public List getAllSinglePhotoVideosForEncounter(String encNum) return myArray; } -/* - public ArrayList getAllSinglePhotoVideosWithKeyword(Keyword word) { - String keywordQueryString="SELECT FROM org.ecocean.SinglePhotoVideo WHERE keywords.contains(word0) && ( word0.indexname == - \""+word.getIndexname()+"\" ) VARIABLES org.ecocean.Keyword word0"; - Query samples = pm.newQuery(keywordQueryString); - Collection c = (Collection) (samples.execute()); - ArrayList myArray=new ArrayList(c); - samples.closeAll(); - return myArray; - } - */ public ArrayList getAllMediAssetsWithKeyword(Keyword word0) { String keywordQueryString = "SELECT FROM org.ecocean.media.MediaAsset WHERE ( this.keywords.contains(word0) && ( word0.indexname == \"" @@ -3048,8 +2860,6 @@ public ArrayList getEncountersArrayWithMillis(long millis) { public List getEncountersSubmittedDuring(long start, long end) { String startStr = String.valueOf(start); String endStr = String.valueOf(end); - // String keywordQueryString="SELECT FROM org.ecocean.Encounter WHERE catalogNumber != null && dwcDateAddedLong >= "+startStr+" && - // dateInMilliseconds <= "+endStr+" "; String keywordQueryString = "SELECT FROM org.ecocean.Encounter WHERE catalogNumber != null && dwcDateAddedLong >= " + startStr + " && dwcDateAddedLong <= " + endStr + " "; @@ -3620,8 +3430,6 @@ public List getAllMarkedIndividualsFromLocationID(String locCo public Iterator getAllMarkedIndividuals(Query sharks) { Collection c = (Collection)(sharks.execute()); - // ArrayList list = new ArrayList(c); - // Collections.reverse(list); Iterator it = c.iterator(); return it; @@ -3644,7 +3452,6 @@ public Iterator getAllMarkedIndividuals(Query sharkies, String sharkies.setOrdering(order); Collection c = (Collection)(sharkies.executeWithMap(params)); ArrayList list = new ArrayList(c); - // Collections.reverse(list); Iterator it = list.iterator(); return it; } @@ -4016,19 +3823,6 @@ public void beginDBTransaction() { pm.addInstanceLifecycleListener(new WildbookLifecycleListener(), null); -/* this as unnecessary but holding for further possible use - // https://www.datanucleus.org/products/accessplatform_4_1/jdo/transactions.html#isolation - tx = pm.currentTransaction(); - tx.setSynchronization(new javax.transaction.Synchronization() { - public void beforeCompletion() { - System.out.println("###########>>>>>>>>>>>>>>>>>> BEFORE"); - } - public void afterCompletion(int status) { - //javax.transaction.Status.STATUS_COMMITTED - System.out.println("###########>>>>>>>>>>>>>>>>>> AFTER status=" + status); - } - }); - */ } catch (JDOUserException jdoe) { jdoe.printStackTrace(); } catch (NullPointerException npe) { @@ -4044,8 +3838,7 @@ public boolean isDBTransactionActive() { /** * Commits (makes permanent) any changes made to an open database */ -//////////// TODO it seems like this should either (a) throw an exception itself; or (b) return boolean of success. obviously the latter was -// disabled(?). whassup? -jon 20140619 + // TODO: Either (a) throw an exception itself or (b) return boolean of success (the latter was disabled, needs investigation) public void commitDBTransaction() { try { // System.out.println(" shepherd:"+identifyMe+" is trying to commit a transaction"); @@ -4249,13 +4042,6 @@ public List getAllKeywordsList() { return al; } - /* - public Iterator getAllKeywords() { - Extent allKeywords = pm.getExtent(Keyword.class); - Query acceptedKeywords = pm.newQuery(allKeywords); - return getAllKeywords(acceptedKeywords); - } - */ public Iterator getAllKeywords() { Extent allOccurs = null; Iterator it = null; @@ -4300,12 +4086,6 @@ public List getAllLabeledKeywords() { } } -/* - public Iterator getAllKeywords(Query acceptedKeywords) { - List words = getSortedKeywordList(acceptedKeywords); - return ((words==null) ? null : words.iterator()); - } - */ // allows keywords to be defined in properties file and appear at the top // of the list of all keywords public List getSortedKeywordList() { @@ -4448,11 +4228,8 @@ public List getThumbnails(Shepherd myShepherd, HttpServletRequ Keyword word = getKeyword(keywords[n]); if ((images.get(i).getKeywords() != null) && images.get(i).getKeywords().contains(word)) { - // if (word.isMemberOf(enc.getCatalogNumber() + "/" + imageName)) { - - hasKeyword = true; - // System.out.println("member of: "+word.getReadableName()); - } + hasKeyword = true; + } } else { hasKeyword = true; } @@ -4526,10 +4303,7 @@ public List getMarkedIndividualThumbnails(HttpServletRequest r Keyword word = getKeyword(keywords[n]); if ((images.get(i).getKeywords() != null) && images.get(i).getKeywords().contains(word)) { - // if (word.isMemberOf(enc.getCatalogNumber() + "/" + imageName)) { - - hasKeyword = true; - // System.out.println("member of: "+word.getReadableName()); + hasKeyword = true; } } else { hasKeyword = true; @@ -4609,11 +4383,7 @@ public int getNumThumbnails(Iterator it, String[] keywords) { } } if (hasKeyword && isAcceptableVideoFile(imageName)) { - // m_thumb="http://"+CommonConfiguration.getURLLocation()+"/images/video.jpg"+"BREAK"+enc.getEncounterNumber()+"BREAK"+imageName; - // thumbs.add(m_thumb); } else if (hasKeyword && isAcceptableImageFile(imageName)) { - // m_thumb=enc.getEncounterNumber()+"/"+(i+1)+".jpg"+"BREAK"+enc.getEncounterNumber()+"BREAK"+imageName; - // thumbs.add(m_thumb); } else { count--; } @@ -5260,7 +5030,6 @@ public ArrayList getAllRoleNamesForMarkedIndividual(String indieName) { } public ArrayList getAllRelationshipsForCommunity(String commName) { - // ArrayList relies=new ArrayList(); Extent encClass = pm.getExtent(Relationship.class, true); String filter2use = "this.communityName == \"" + commName + "\""; Query acceptedEncounters = pm.newQuery(encClass, filter2use); @@ -5370,7 +5139,6 @@ public ArrayList getAllScanTasksForUser(String user) { } public User getRandomUserWithPhotoAndStatement() { - // (username.toLowerCase().indexOf('demo') == -1) String filter = "fullName != null && userImage != null && userStatement != null && (username.toLowerCase().indexOf('demo') == -1) && (username.toLowerCase().indexOf('test') == -1)"; Extent encClass = pm.getExtent(User.class, true); @@ -5745,7 +5513,7 @@ public User getUserByWhatever(String value) { if (u != null) return u; u = getUserByUUID(value); if (u != null) return u; - return getUserByEmailAddress(value); // see note below about uniqueness, alas + return getUserByEmailAddress(value); } public JSONArray getAllProjectACMIdsJSON(String projectId) { @@ -5765,4 +5533,4 @@ public JSONArray getAllProjectACMIdsJSON(String projectId) { } return allAnnotIds; } -} // end Shepherd class +} diff --git a/src/main/java/org/ecocean/ShepherdProperties.java b/src/main/java/org/ecocean/ShepherdProperties.java index 34a47b2838..69b90306d9 100644 --- a/src/main/java/org/ecocean/ShepherdProperties.java +++ b/src/main/java/org/ecocean/ShepherdProperties.java @@ -154,8 +154,6 @@ public static Properties getProperties(String fileName, String langCode, String } Properties props = loadProperties(overridePathStr, defaultProps); if (!Util.stringExists(overridePrefix)) return (Properties)props; - // todo: now actually load the override string - // we Do have an overridePrefix so we need to load it now String customUserPathString = "webapps/" + shepherdDataDir + "/WEB-INF/classes/bundles/" + overridePrefix; return (Properties)loadProperties(customUserPathString, props); diff --git a/src/main/java/org/ecocean/SinglePhotoVideo.java b/src/main/java/org/ecocean/SinglePhotoVideo.java index 38a684a26d..de37fab0e3 100644 --- a/src/main/java/org/ecocean/SinglePhotoVideo.java +++ b/src/main/java/org/ecocean/SinglePhotoVideo.java @@ -1,3 +1,5 @@ +// TODO: remove any residual references to this and delete entirely + package org.ecocean; import java.io.File; @@ -26,11 +28,6 @@ public class SinglePhotoVideo extends DataCollectionEvent { public String webURL; - /* - private String thumbnailFilename; - private String thumbnailFullFileSystemPath; - */ - private static String type = "SinglePhotoVideo"; private String copyrightOwner; private String copyrightStatement; @@ -59,14 +56,12 @@ public SinglePhotoVideo(String correspondingEncounterNumber, File file) { public SinglePhotoVideo(Encounter enc, FileItem formFile, String context, String dataDir) throws Exception { -// TODO FUTURE: should use context to find out METHOD of storage (e.g. remote, amazon, etc) and switch accordingly? super(enc.getEncounterNumber(), type); String encID = enc.getEncounterNumber(); if ((encID == null) || encID.equals("")) { throw new Exception("called SinglePhotoVideo(enc) with Encounter missing an ID"); } - // TODO generalize this when we encorporate METHOD? // File dir = new File(dataDir + File.separator + correspondingEncounterNumber.charAt(0) + File.separator + // correspondingEncounterNumber.charAt(1), correspondingEncounterNumber); File dir = new File(enc.dir(dataDir)); @@ -76,7 +71,7 @@ public SinglePhotoVideo(Encounter enc, FileItem formFile, String context, String File file = new File(dir, this.filename); this.fullFileSystemPath = file.getAbsolutePath(); - formFile.write(file); // TODO catch errors and return them, duh + formFile.write(file); System.out.println("full path??? = " + this.fullFileSystemPath + " WRITTEN!"); } @@ -107,7 +102,7 @@ public String urlPath(HttpServletRequest request) { // string name of a url = (new File(url.substring(i + rootWebappPath.length())).getParentFile()).toString(); } else { - url = "/unknownUrlPath"; // TODO handle this better + url = "/unknownUrlPath"; } try { String serverUrl = request.getServerName(); @@ -117,14 +112,6 @@ public String urlPath(HttpServletRequest request) { } } - /* - public File getThumbnailFile(){ - if(thumbnailFullFileSystemPath!=null){ - return (new File(thumbnailFullFileSystemPath)); - } - else{return null;} - } - */ public String getFilename() { return filename; } public void setFilename(String newName) { this.filename = newName; } @@ -137,14 +124,6 @@ public File getThumbnailFile(){ public String getCopyrightStatement() { return copyrightStatement; } public void setCopyrightStatement(String statement) { copyrightStatement = statement; } - // public String getThumbnailFilename(){return (this.getDataCollectionEventID()+".jpg");} - - /* - public void setThumbnailFilename(String newName){this.thumbnailFilename=newName;} - - public String getThumbnailFullFileSystemPath(){return thumbnailFullFileSystemPath;} - public void setThumbnailFullFileSystemPath(String newPath){this.thumbnailFullFileSystemPath=newPath;} - */ public void addKeyword(Keyword dce) { if (keywords == null) { keywords = new ArrayList(); } if (!keywords.contains(dce)) { keywords.add(dce); } @@ -231,21 +210,14 @@ public boolean transformTo(String context, float[] transform, float clientWidth, if ((cmd == null) || cmd.equals("")) return false; String sourcePath = this.getFullFileSystemPath(); -/* - if (!Shepherd.isAcceptableImageFile(sourcePath)) return false; - ImageProcessor iproc = new ImageProcessor(context, sourcePath, targetPath, transform); //, clientWidth); - Thread t = new Thread(iproc); - t.start(); - */ + return true; } // *for now* this will only be called from an Encounter, which means that Encounter must be sanitized - // so we assume this *must* be sanitized too. (TODO fix that when MediaAsset takes over, obvs) + // so we assume this *must* be sanitized too. public JSONObject sanitizeJson(HttpServletRequest request, boolean fullAccess) throws JSONException { -// System.out.println("um, i am sanitizing " + this); - // JSONObject jobj = new JSONObject(this); //ugh JSONObject() is failing on Keywords, so lets start empty JSONObject jobj = new JSONObject(); String urlPath = this.urlPath(request); diff --git a/src/main/java/org/ecocean/SpotterConserveIO.java b/src/main/java/org/ecocean/SpotterConserveIO.java index e9b81ace29..191560e74b 100644 --- a/src/main/java/org/ecocean/SpotterConserveIO.java +++ b/src/main/java/org/ecocean/SpotterConserveIO.java @@ -1,3 +1,5 @@ +// TODO: evaluate and delete if deprecated work + package org.ecocean; import java.net.URL; @@ -82,7 +84,6 @@ public static Survey ciToSurvey(JSONObject jin, Shepherd myShepherd) { DateTime endDate = toDateTime(jin.optString("end_date", null)); DateTime createDate = toDateTime(jin.optString("create_date", null)); Survey survey = new Survey(startDate); - // if (startDate != null) survey.setStartTimeMilli(startDate.getMillis()); if (endDate != null) survey.setEndTimeMilli(endDate.getMillis()); if (createDate != null) survey.addComments("

Created on source: " + createDate.toString() + "

"); @@ -98,7 +99,6 @@ public static Survey ciToSurvey(JSONObject jin, Shepherd myShepherd) { String integ = checkIntegrity(st, myShepherd); survey.addSurveyTrack(st); if (integ != null) survey.addComments("

Note: SurveyTrack failed integrity check

"); -///TODO do we .setEffort based on survey track lengths or what??? if (jin.optJSONArray("CINMS Weather") != null) { ArrayList wths = new ArrayList(); JSONArray jw = jin.getJSONArray("CINMS Weather"); @@ -166,10 +166,7 @@ public static Occurrence ciToOccurrence(JSONObject jin, JSONObject jin2, JSONObj occ.setBestGroupSizeEstimate(new Double(numTotal)); occ.setSightingPlatform(allJson.optString("CINMS Vessel", null)); occ.setSource("SpotterConserveIO:ci:" + tripId); -/* - String taxString = jin.optString("CINMS Species", null); - if (taxString != null) occ.addSpecies(taxString, myShepherd); - */ + Taxonomy tax = ciToTaxonomy(jin.optString("CINMS Species", null), myShepherd); System.out.println("ciToTaxonomy => " + tax); if (tax != null) occ.addTaxonomy(tax); @@ -216,18 +213,8 @@ public static Taxonomy ciToTaxonomy(String taxString, Shepherd myShepherd) { return tax; } -/* - { - create_date: "2017-06-03 18:41:00+00:00", Card Number: 1, PID Code: "SBE", Image Number Start: 1583, \__ use these to fill out some - (new!) kinda placeholder Features (via Annotations) Image Number End: 1588, / - Animals Identified: 1 - } - */ public static Encounter ciToEncounter(JSONObject jin, JSONObject occJson, String occId, - JSONObject allJson, Shepherd myShepherd) { // occJson we - // need for - // species (if - // not more) + JSONObject allJson, Shepherd myShepherd) { //occJson we need for species (if not more) Encounter enc = new Encounter(); enc.setCatalogNumber(Util.generateUUID()); @@ -307,9 +294,8 @@ public static Instant ciToBehavior(JSONObject jin) { return new Instant(name, dt, null); } - // someday, Taxonomy! sigh TODO private static String ciSpecies(String species) { // e.g. "Blue Whale" --> "Balaenoptera musculus" ... also: may be null - return species; // meh. for now. + return species; } private static String[] ciSpeciesSplit(String species) { // e.g. "Foo Bar" --> ["Foo", "Bar"] @@ -317,18 +303,6 @@ private static String[] ciSpeciesSplit(String species) { // e.g. "Foo Bar" --> [ return species.split(" +"); } -/* - unfortunately, we get a lot of noise for the "Observer Names" field, which need to be broken up into names to search on User.fullName ... examples - we need to split on: - ci_data/ci_21339.json: "Observer Names": "Jess Morten, Sean Hastings, Brad pilot", - ci_data/ci_21340.json: "Observer Names": "Emilee Hurlbert", - ci_data/ci_21346.json: "Observer Names": "Maria Ornelas\n", #trailing noise! ugh ci_data/ci_21367.json: "Observer Names": "Carolyn - McCleskey,Sue Miller", #comma-no-space, oof ci_data/ci_21371.json: "Observer Names": "Rosie Romo\nDave Morse (PID)\n", #wtf, gimme a break! - ci_data/ci_21384.json: "Observer Names": "Sophie Busch", - ci_data/ci_21390.json: "Observer Names": "Sophie Busch and Marian Jean", #you serious here??? - ci_data/ci_21408.json: "Observer Names": "Larry Driscoll\nAnn Camou", #etc. - - */ public static List ciGetVolunteerUsers(JSONObject jin, Shepherd myShepherd) { if (jin == null) return null; String namesIn = jin.optString("Observer Names", "").replaceAll("\\n$", @@ -343,15 +317,6 @@ public static User ciToUser(JSONObject jin, Shepherd myShepherd) { return ciGetSubmitterUser(myShepherd); } -/****************************************** - CaribWhale flavor - "Jake's trips are under project #4 which is Carib Whale and should be very similar to the CINMS format" -virgil thus, some of this piggybacks on - ci* calls. - - also, seems like project id=26 (shane's) is close enough to this that i am going to go ahead and piggyback on this there are of course (sigh) some - minor differences, so mind the hacking. - - ******************************************/ // this is the "starting point" for JSON from the API public static Survey cwToSurvey(JSONObject jin, Shepherd myShepherd) { if (jin == null) return null; @@ -359,7 +324,6 @@ public static Survey cwToSurvey(JSONObject jin, Shepherd myShepherd) { DateTime endDate = toDateTime(jin.optString("end_date", null)); DateTime createDate = toDateTime(jin.optString("create_date", null)); Survey survey = new Survey(startDate); - // if (startDate != null) survey.setStartTimeMilli(startDate.getMillis()); if (endDate != null) survey.setEndTimeMilli(endDate.getMillis()); if (createDate != null) survey.addComments("

Created on source: " + createDate.toString() + "

"); @@ -381,7 +345,6 @@ public static Survey cwToSurvey(JSONObject jin, Shepherd myShepherd) { String integ = checkIntegrity(st, myShepherd); survey.addSurveyTrack(st); if (integ != null) survey.addComments("

Note: SurveyTrack failed integrity check

"); -///TODO do we .setEffort based on survey track lengths or what??? // HACK ... can be either one of these JSONArray weatherArr = jin.optJSONArray("Demo Weather"); @@ -397,16 +360,6 @@ public static Survey cwToSurvey(JSONObject jin, Shepherd myShepherd) { return survey; } -/* - public static Observation ciToWeather(JSONObject wj, Survey surv) { - if (wj == null) return null; - Observation obs = new Observation(OBS_WEATHER_NAME, wj.toString(), surv, surv.getID()); - DateTime dt = toDateTime(wj.optString("create_date", null)); - obs.setDateAddedMilli((dt == null) ? null : dt.getMillis()); - obs.setDateLastModifiedMilli(); - return obs; - } - */ public static SurveyTrack cwToSurveyTrack(JSONObject jin, Shepherd myShepherd) { SurveyTrack st = new SurveyTrack(); @@ -463,10 +416,7 @@ public static Occurrence cwToOccurrence(JSONObject jin, JSONObject jin2, JSONObj false) ? "yes" : "no") + "; "; bool += "

"; occ.addComments(bool); -/* - String taxString = jin.optString("CINMS Species", null); - if (taxString != null) occ.addSpecies(taxString, myShepherd); - */ + Taxonomy tax = ciToTaxonomy(jin.optString("CINMS Species", null), myShepherd); System.out.println("(cw)ciToTaxonomy => " + tax); if (tax != null) occ.addTaxonomy(tax); @@ -485,24 +435,11 @@ public static Occurrence cwToOccurrence(JSONObject jin, JSONObject jin2, JSONObj } occ.setBehaviors(bhvs); } -/* this does not seem to exist in CaribWhale ... :/ - if (jin.optJSONArray("CINMS Photo Log") != null) { - ArrayList encs = new ArrayList(); - JSONArray je = jin.getJSONArray("CINMS Photo Log"); - for (int i = 0 ; i < je.length() ; i++) { - Encounter enc = ciToEncounter(je.optJSONObject(i), jin, occ.getOccurrenceID(), allJson, myShepherd); - if (enc != null) encs.add(enc); - } - occ.setEncounters(encs); - } - */ /* NOTE! jin2 does seem to have a "photos" array. not sure if it is the same as use in Whale Alert, e.g.: Encounter enc = waToEncounter(je.optString(i, null), jin, occ, myShepherd); */ occ.setSubmitter(cwToUser(allJson, myShepherd)); - // List vols = ciGetVolunteerUsers(allJson, myShepherd); - // occ.setInformOthers(vols); return occ; } @@ -516,7 +453,7 @@ public static Instant cwToBehavior(JSONObject jin) { return new Instant(name, dt, null); } - // FIXME these are hardcoded for now cuz i have no idea how to map these -- no email addresses. :/ + // remove or genericize; these are currently hardcoded public static User cwToUser(JSONObject jin, Shepherd myShepherd) { if (jin.optString("creator").equals("Jlevenson1")) return myShepherd.getUserByUUID("dc23b977-dfaa-4cda-b074-78df4f388dd8"); @@ -620,7 +557,7 @@ public static Encounter waToEncounter(String photoUrl, JSONObject occJson, Occur // we have a start_date and end_date in *very top level* (not occJson!) but it seems (!??) to always be the // same timestamp throughout as create_date as well!! so we are going to use this value for: - // enc.DWCDateAdded as well as enc *date of encounter*. :/ TODO figure out whats up here! + // enc.DWCDateAdded as well as enc *date of encounter*. String dc = occJson.optString("create_date", null); if (dc != null) { @@ -636,13 +573,7 @@ public static Encounter waToEncounter(String photoUrl, JSONObject occJson, Occur enc.setDecimalLongitude(occ.getDecimalLongitude()); String waSpecies = occJson.optString("Whale Alert Species", null); -/* - /// TODO FIX FOR Taxonomy class!!! String tax[] = ciSpeciesSplit(occJson.optString("Whale Alert Species", null)); - if ((tax != null) && (tax.length > 1)) { - enc.setGenus(tax[0]); - enc.setSpecificEpithet(tax[1]); - } - */ + String annotSpecies = "annot_species"; enc.setGenus("test"); enc.setSpecificEpithet("test"); @@ -795,7 +726,7 @@ public static Encounter oaToEncounter(String photoUrl, JSONObject occJson, Occur // we have a start_date and end_date in *very top level* (not occJson!) but it seems (!??) to always be the // same timestamp throughout as create_date as well!! so we are going to use this value for: - // enc.DWCDateAdded as well as enc *date of encounter*. :/ TODO figure out whats up here! + // enc.DWCDateAdded as well as enc *date of encounter*. String dc = occJson.optString("create_date", null); if (dc != null) { @@ -844,32 +775,6 @@ public static User oaToUser(JSONObject jin, Shepherd myShepherd, Occurrence occ) jin.optString("Whale Alert Submitter Phone", null), myShepherd); } -/* saved for prosperity? - public static User PREVIOUS____oaToUser(JSONObject jin, Shepherd myShepherd, Occurrence occ) { - String subEmail = jin.optString("Whale Alert Submitter Email", null); - String subName = jin.optString("Whale Alert Submitter Name", null); - /////String subPhone = jin.optString("Whale Alert Submitter Phone", null); //ignore! - - User user = null; - if (Util.stringExists(subEmail)) { - String emhash = User.generateEmailHash(subEmail); - //we get by *email hash* here (and not email) in case the email has been reset (e.g. GDPR) user = - myShepherd.getUserByHashedEmailAddress(emhash); - if (user == null) { - user = new User(subEmail, Util.generateUUID()); - if (Util.stringExists(subName)) user.setFullName(subName); - user.setNotes("

Created via Ocean Alert, Occurrence " + occ.getID() + ".

"); - } - - } else { //no subEmail (so anonymous submission) user = new User(Util.generateUUID()); - if (Util.stringExists(subName)) user.setFullName(subName); - user.setNotes("

Created via Ocean Alert, Occurrence " + occ.getID() + ".

"); - } - System.out.println("INFO: oaToUser(" + subEmail + ", " + subName + " --> " + user); - return user; - } - */ - /* ITIS Species Scientific Name: "Mysticeti", ITIS Species Common Name: "baleen whales", ITIS Species TSN: "552298", */ @@ -906,36 +811,6 @@ public static Taxonomy findTaxonomy(Shepherd myShepherd, String tstring) { return null; } - /* - note: seems gpx has a trk made up of trkseg, which are made of trkpts... - i suppose we really should have trkseg -> path, then have surveytrack made of multiple paths... - however, *for now* we just combine all leaf points into one Path TODO discuss with colin et al - - also: really should we be able to pass in entire "track" structure (find .gpx, save schema, etc)? probably! - something like: trackToSurveyTrackPaths(surveyTrack) - - NOTE! trkpt can be JSONArray or JSONObject single pt!! not sure if same is true of trkseg!!! TODO - - track: { - gpx: { - @xsi:schemaLocation: "http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd", - @creator: "TrailBehind", - @xmlns:xsi: "http://www.w3.org/2001/XMLSchema-instance", - @xmlns: "http://www.topografix.com/GPX/1/1", - @version: "1.1", trk: { - trkseg: [ - { - trkpt: [{....}, ...., {....}] // ARRAY - }, - { - trkpt: { // SINGLE POINT - @lat: "34.321975", - @lon: "-119.691129", time: "2017-06-01T20:57:49Z", ele: "-3.248924" - ....... - - NOTE2! also trkseg can be a JSONArray or a (singleton) JSONObject!! grrffff... NOTE3: JP asks "what if it is empty?" ... ARGH. haha - - */ public static Path trkToPath(JSONObject trk) { if (trk == null) return null; JSONArray segs = trk.optJSONArray("trkseg"); @@ -1071,7 +946,6 @@ public static JSONObject waGetTripListSince(int since) return apiGet("/project/" + PROJECT_ID_WA + "/trip_data/" + since + "/0"); } - // TODO needs some better way to tell some of these... sigh public static String tripFlavor(JSONObject tripData) { if (tripData == null) return null; if ((tripData.optString("Ship Name", null) != null) || (tripData.optString("Data Collector", diff --git a/src/main/java/org/ecocean/StartupWildbook.java b/src/main/java/org/ecocean/StartupWildbook.java index 688a1e2499..2d0f64486c 100644 --- a/src/main/java/org/ecocean/StartupWildbook.java +++ b/src/main/java/org/ecocean/StartupWildbook.java @@ -45,7 +45,7 @@ public static void initializeWildbook(HttpServletRequest request, Shepherd myShe } /* - right now this *only* uses SERVER_URL env variable TODO: should _probably_ make this work in the more general case where it isnt e.g. + right now this *only* uses SERVER_URL env variable TODO: make this work in the more general case where it isnt e.g. CommonConfiguration.checkServerInfo(myShepherd, request) */ public static void ensureServerInfo(Shepherd myShepherd) { @@ -119,9 +119,6 @@ public static void ensureTomcatUserExists(Shepherd myShepherd) { Role newRole3 = new Role("tomcat", "machinelearning"); newRole3.setContext("context0"); myShepherd.getPM().makePersistent(newRole3); - // Role newRole4=new Role("tomcat","destroyer"); - // newRole4.setContext("context0"); - // myShepherd.getPM().makePersistent(newRole4); Role newRole5 = new Role("tomcat", "rest"); newRole5.setContext("context0"); myShepherd.getPM().makePersistent(newRole5); @@ -157,7 +154,7 @@ public static void ensureProfilePhotoKeywordExists(Shepherd myShepherd) { // these get run with each tomcat startup/shutdown, if web.xml is configured accordingly. see, e.g. https://stackoverflow.com/a/785802 public void contextInitialized(ServletContextEvent sce) { ServletContext sContext = sce.getServletContext(); - String context = "context0"; // TODO ??? how???? + String context = "context0"; System.out.println(new org.joda.time.DateTime() + " ### StartupWildbook initialized for: " + servletContextInfo(sContext)); @@ -173,9 +170,8 @@ public void contextInitialized(ServletContextEvent sce) { if (CommonConfiguration.useSpotPatternRecognition(context)) { createMatchGraph(); } - // TODO genericize starting "all" consumers ... configurable? how? etc. - // actually, i think we want to move this to WildbookIAM.startup() ... probably!!! - startIAQueues(context); // TODO this should get moved to plugins!!!! FIXME + // TODO: set strategy for the following (genericize starting "all" consumers, make configurable, move to WildbookIAM.startup, move to plugins, or other) + startIAQueues(context); TwitterBot.startServices(context); MetricsBot.startServices(context); AcmIdBot.startServices(context); @@ -306,13 +302,12 @@ private static void startWildbookScheduledTaskThread(String context) { } myShepherd.closeDBTransaction(); } - // }, 0, 2, TimeUnit.HOURS); //TODO restore desired interval after testing }, 0, 1, TimeUnit.HOURS); } public void contextDestroyed(ServletContextEvent sce) { ServletContext sContext = sce.getServletContext(); - String context = "context0"; ///HOW?? (see above) TODO FIXME + String context = "context0"; System.out.println("* StartupWildbook destroyed called for: " + servletContextInfo(sContext)); @@ -332,13 +327,9 @@ public static void createMatchGraph() { public static boolean skipInit(ServletContextEvent sce, String extra) { ServletContext sc = sce.getServletContext(); + /* WARNING! this bad hackery to try to work around "double deployment" ... yuck! see: https://octopus.com/blog/defining-tomcat-context-paths - - if ("".equals(sc.getContextPath())) { - System.out.println("++ StartupWildbook.skipInit() skipping ROOT (empty string context path)"); - return true; - } */ String fname = "/tmp/WB_SKIP_INIT" + ((extra == null) ? "" : "_" + extra); boolean skip = new File(fname).exists(); @@ -348,24 +339,6 @@ public static boolean skipInit(ServletContextEvent sce, String extra) { return skip; } -/* NOTE: this is back-burnered for now.... maybe it will be useful later? cant quite figure out *when* tomcat is "double startup" problem... - //this is very hacky but is meant to be a way for us to make sure we arent just deploying.... TODO do this right???? - private static boolean properStartupResource(ServletContextEvent sce) { - if (sce == null) return false; - ServletContext context = sce.getServletContext(); - if (context == null) return false; - URL res = null; - try { - res = context.getResource("/"); - } catch (Exception ex) { - System.out.println(" ERROR: StartupWildbook.properStartupResource() .getResource() threw exception: " + ex); - return false; - } - System.out.println(" StartupWildbook.properStartupResource() res = " + res); - if (res == null) return false; - return res.toString().equals("jndi:/localhost/uptest/"); - } - */ public static String servletContextInfo(ServletContext sc) { if (sc == null) return null; try { diff --git a/src/main/java/org/ecocean/Survey.java b/src/main/java/org/ecocean/Survey.java index 7bb3e9bc7c..f3f5d0b00c 100644 --- a/src/main/java/org/ecocean/Survey.java +++ b/src/main/java/org/ecocean/Survey.java @@ -154,7 +154,7 @@ public int numSurveyTracks() { return surveyTracks.size(); } - // TODO what does this method do (differently than getSurveyTracks()) ??? -jon + // TODO: evaluate this method in relation to getSurveyTracks(); remove if duplicate public ArrayList getAllSurveyTracks() { if (surveyTracks == null) return null; if (!surveyTracks.isEmpty()) { @@ -368,9 +368,9 @@ public Long getComputedDurationTrackSum() { if (Util.collectionIsEmptyOrNull(surveyTracks)) return null; Long sum = 0L; for (SurveyTrack st : surveyTracks) { - if (st == null) continue; // TODO or return null ???? + if (st == null) continue; Long dur = st.getComputedDuration(); - if (dur == null) return null; // TODO or continue ??? argument for null: we have a track but it has unknown duration but cant assume 0 + if (dur == null) return null; sum += dur; } return sum; diff --git a/src/main/java/org/ecocean/TwitterBot.java b/src/main/java/org/ecocean/TwitterBot.java index 55afe7b15d..64c13ebb0b 100644 --- a/src/main/java/org/ecocean/TwitterBot.java +++ b/src/main/java/org/ecocean/TwitterBot.java @@ -1,5 +1,6 @@ /* aka "Tweet-a-Whale" .. implements listening for and processing tweets + TODO: deprecate and remove */ package org.ecocean; @@ -46,7 +47,7 @@ public class TwitterBot { private static RateLimitation outgoingRL = new RateLimitation(48 * 60 * 60 * 1000); // only care about last 48 hrs // kind of convenience method (to TwitterUtil) but also swallows exception - // TODO yeah this really should be based off context. :( + // yeah this really should be based off context. :( public static twitter4j.User myUser() { try { return TwitterUtil.myUser(); @@ -102,7 +103,7 @@ public static void processIncomingTweet(Status tweet, String context) { } } } else { - ///TODO ... do we even *want* to process a tweet that is already stored?????? going to say NO for now! + /// ... do we even *want* to process a tweet that is already stored?????? going to say NO for now! System.out.println("WARNING: TwitterBot.processIncomingTweet() -- tweet " + tweet.getId() + " already stored, so skipping"); myShepherd.rollbackDBTransaction(); @@ -155,7 +156,7 @@ public static void processIncomingTweet(Status tweet, String context) { } } - // TODO this should probably live somewhere more useful. and be resolved to be less confusing re: IAIntake? + // this should probably live somewhere more useful. and be resolved to be less confusing re: IAIntake? private static JSONObject detectionQueueJob(List mas, String context, String baseUrl, String taskId) { JSONObject qj = new JSONObject(); @@ -174,9 +175,7 @@ private static JSONObject detectionQueueJob(List mas, String context } public static void sendCourtesyTweet(String context, Status originTweet, MediaAsset ma) { - Map vars = new HashMap(); // %SOURCE_TWEET_ID, %SOURCE_IMAGE_ID, %SOURCE_SCREENNAME, %INDIV_ID, %URL_INDIV, - - // %URL_SUBMIT + Map vars = new HashMap(); vars.put("SOURCE_SCREENNAME", originTweet.getUser().getScreenName()); vars.put("SOURCE_TWEET_ID", Long.toString(originTweet.getId())); @@ -225,7 +224,7 @@ private static void messageInHandler(String msg) { private static void messageOutHandler(String msg) { int lastHour = outgoingRL.numSinceHoursAgo(1); - while (lastHour > 10) { // TODO maybe this is configurable? must adhere to twitter policy etc + while (lastHour > 10) { // maybe this is configurable? must adhere to twitter policy etc System.out.println( "INFO: TwitterBot.messageOutHandler() got message. Last hour rate = " + lastHour + ", so stalling..."); @@ -306,7 +305,7 @@ public boolean handler(String msg) { return true; } - // TODO could potentially read listenHashtags from twitter.properties, perhaps??? + // could potentially read listenHashtags from twitter.properties, perhaps??? public static String searchString() { String handle = null; @@ -387,7 +386,7 @@ public static int collectTweets(Shepherd myShepherd) { // gets the template string and substitutes (using 'vars' Map) // substitution keys (so far): %SOURCE_TWEET_ID, %SOURCE_IMAGE_ID, %SOURCE_SCREENNAME, %INDIV_ID, %URL_INDIV, %URL_SUBMIT - // TODO might want to live in TwitterUtil + // might want to live in TwitterUtil public static String tweetText(String context, String key, Map vars) { String text = TwitterUtil.getProperty(context, key); @@ -405,8 +404,8 @@ public static String tweetText(String context, String key, Map v // basically our "listener" daemon; but is more pull (poll?) than push so to speak. // just checks for tweets at regular intervals private static void startCollector(final String context) { // throws IOException { - collectorStartTime = System.currentTimeMillis(); // TODO should really be keyed off context! - // note: up to user discretion not to violate twitter rate limits TODO maybe handle this in code? (value in seconds) + collectorStartTime = System.currentTimeMillis(); // should really be keyed off context! + // note: up to user discretion not to violate twitter rate limits maybe handle this in code? (value in seconds) long interval = 600; String ci = TwitterUtil.getProperty(context, "collectorInterval"); if (ci != null) { @@ -496,7 +495,7 @@ public static String processDetectionResults(Shepherd myShepherd, tweetMA; vars.put("SOURCE_SCREENNAME", originTweet.getUser().getScreenName()); // vars.put("SOURCE_TWEET_ID", Long.toString(originTweet.getId())); - // TODO: only send below tweet if every detection job for the tweet has returned negative. This will take some research. + // only send below tweet if every detection job for the tweet has returned negative. This will take some research. sendTweet(tweetText(context, "tweetTextIANone", vars), originTweet.getId()); return "Failed to find any Annotations; sent tweet"; } @@ -607,25 +606,6 @@ private static void updateEncounter(MediaAsset tweetMA, ArrayList an // mostly for ContextDestroyed in StartupWildbook..... i think? public static void cleanup() { -/* - for (ScheduledExecutorService ses : runningSES) { - ses.shutdown(); - try { - if (ses.awaitTermintation(20, TimeUnit.SECONDS)) { - ses.shutdownNow(); - if (ses.awaitTermintation(20, TimeUnit.SECONDS)) { - System.out.println("!!! QueueUtil.cleanup() -- ExecutorService did not terminate"); - } - } - } catch (InterruptedException ie) { - ses.shutdownNow(); - Thread.currentThread().interrupt(); - } - } - for (ScheduledFuture sf : runningSF) { - sf.cancel(true); - } - */ System.out.println( "================ = = = = = = ===================== TwitterBot.cleanup() finished."); } diff --git a/src/main/java/org/ecocean/TwitterUtil.java b/src/main/java/org/ecocean/TwitterUtil.java index 96855b3199..955f69beb8 100644 --- a/src/main/java/org/ecocean/TwitterUtil.java +++ b/src/main/java/org/ecocean/TwitterUtil.java @@ -1,4 +1,5 @@ /* + TODO: deprecate and remove entirely this class is for **generic** (usable across many applications) Twitter functions. for application-specific Twitter functionality, please create own class e.g. TwitterBot.java */ @@ -24,7 +25,7 @@ this class is for **generic** (usable across many applications) Twitter function import twitter4j.Status; public class TwitterUtil { - private static TwitterFactory tfactory = null; // note should be based on context like below no???? TODO + private static TwitterFactory tfactory = null; // note should be based on context like below no???? private static HashMap Props = new HashMap(); // keyed on context public static Twitter init(HttpServletRequest request) { @@ -145,21 +146,13 @@ public static String getProperty(String context, String key) { // http://twitter4j.org/en/configuration.html public static TwitterFactory getTwitterFactory(String context) { -/* - Properties props = ShepherdProperties.getProperties("twitter.properties", "", context); - if (props == null) throw new RuntimeException("no twitter.properties"); - String debug = props.getProperty("debug"); - String consumerKey = props.getProperty("consumerKey"); - */ + String debug = getProperty(context, "debug"); String consumerKey = getProperty(context, "consumerKey"); if ((consumerKey == null) || consumerKey.equals("")) throw new RuntimeException("twitter.properties missing consumerKey"); // hopefully enough of // a hint - // String consumerSecret = props.getProperty("consumerSecret"); - // String accessToken = props.getProperty("accessToken"); - // String accessTokenSecret = props.getProperty("accessTokenSecret"); String consumerSecret = getProperty(context, "consumerSecret"); String accessToken = getProperty(context, "accessToken"); String accessTokenSecret = getProperty(context, "accessTokenSecret"); diff --git a/src/main/java/org/ecocean/User.java b/src/main/java/org/ecocean/User.java index bc3d219ad4..93b457d30c 100644 --- a/src/main/java/org/ecocean/User.java +++ b/src/main/java/org/ecocean/User.java @@ -382,7 +382,7 @@ public void unsetSocial(String type) { social.remove(type); } - // TODO this needs to be dealt with better. see: rant about saving usernames from forms + // TODO: this needs to be dealt with better. see: rant about saving usernames from forms public static boolean isUsernameAnonymous(String uname) { return ((uname == null) || uname.trim().equals("") || uname.equals("N/A") || uname.equals("public")); @@ -414,10 +414,6 @@ public Set getMultiValueKeys() { Set rtn = new HashSet(); rtn.add("_userId_:" + uuid); // kinda like "private" key? -/* these should migrate to Organizations!! - if (Util.stringExists(userProject)) rtn.add("_userProject_:" + userProject.toLowerCase()); - if (Util.stringExists(affiliation)) rtn.add("_affiliation_:" + affiliation.toLowerCase()); - */ // if the best context we have is a user, we add all the (toplevel) groups they are members of if (organizations != null) {} return rtn; diff --git a/src/main/java/org/ecocean/Util.java b/src/main/java/org/ecocean/Util.java index a74b2cb9fb..9535a67c96 100644 --- a/src/main/java/org/ecocean/Util.java +++ b/src/main/java/org/ecocean/Util.java @@ -165,12 +165,6 @@ public static List findSamplingProtocols(String langCode, String con context); List list = new ArrayList(); - /* - for (String key : values) { - String label = findLabel(key, langCode,context); - list.add(new OptionDesc(key, label)); - } - */ int valuesSize = values.size(); for (int i = 0; i < valuesSize; i++) { @@ -233,20 +227,6 @@ public static List findSatelliteTagNames(String context) { private static String findLabel(String key, String langCode, String context) { // System.out.println("Trying to find key: "+key+" with langCode "+langCode); - /* - Locale locale = Locale.US; - if (langCode != null) { - locale = new Locale(langCode); - } - try { - ResourceBundle bundle = ResourceBundle.getBundle("bundles.commonConfigurationLabels", locale); - return bundle.getString(key + ".label"); - } - catch (MissingResourceException ex) { - System.out.println("Error finding bundle or key for key: " + key); - } - return key;*/ - Properties myProps = ShepherdProperties.getProperties( "commonConfigurationLabels.properties", langCode, context); @@ -411,7 +391,7 @@ public static String getEXIFDataFromJPEGAsHTML(File exifImage) { } // got sick of having to concat these strings with a space in the middle. - // TODO: someday make a Taxonomy class for storing/processing this stuff right! (or find the wheel someone already invented!!) + // TODO: Make a Taxonomy class for storing/processing this stuff right public static String taxonomyString(String genus, String species) { if (stringExists(genus) && stringExists(species)) return genus + " " + species; if (stringExists(genus)) return genus; @@ -436,7 +416,7 @@ public static String[] stringToGenusSpecificEpithet(String s) { } // a generic version of our uuid-dir-structure-creating algorithm -- adjust as needed!? - // TODO check for incoming slashes and similar weirdness + // TODO: check for incoming slashes and similar weirdness public static String hashDirectories(String in, String separator) { if ((in == null) || (in.length() < 4)) return in; return in.charAt(0) + separator + in.charAt(1) + separator + in; @@ -521,8 +501,6 @@ public static org.datanucleus.api.rest.orgjson.JSONObject stringToDatanucleusJSO return j; } - // NEW - // this basically just swallows exceptions in parsing and returns a null if failure public static JSONArray stringToJSONArray(String s) { JSONArray j = null; @@ -619,12 +597,12 @@ public static Double getDecimalCoordFromString(String latOrLong) { return null; } -/////GPS Longitude: "-69.0° 22.0' 45.62999999998169"", + //GPS Longitude: "-69.0° 22.0' 45.62999999998169"", public static Double latlonDMStoDD(String dms) { String[] d = dms.split(" +"); if (d.length < 1) return null; -// System.out.println("latlonDMStoDD(" + dms + ") --> " + d[0] + "/" + d[1] + "/" + d[2]); + // System.out.println("latlonDMStoDD(" + dms + ") --> " + d[0] + "/" + d[1] + "/" + d[2]); Double dd = null; try { dd = Double.valueOf(d[0].substring(0, d[0].length() - 1)); @@ -633,7 +611,7 @@ public static Double latlonDMStoDD(String dms) { if (d.length > 1) m = Double.valueOf(d[1].substring(0, d[1].length() - 1)); if (d.length > 2) s = Double.valueOf(d[2].substring(0, d[2].length() - 1)); dd = Math.signum(dd) * (Math.abs(dd) + ((m * 60) + s) / (60 * 60)); -// System.out.println(" --> " + dd + " deg, " + m + " min, " + s + " sec => " + dd); + // System.out.println(" --> " + dd + " deg, " + m + " min, " + s + " sec => " + dd); return dd; } catch (NumberFormatException nfe) { return null; @@ -769,10 +747,6 @@ public static boolean requestHasVal(HttpServletRequest request, String paramName // h/t https://www.mkyong.com/regular-expressions/how-to-validate-email-address-with-regular-expression/ public static String validEmailRegexPattern() { - // return "^[_A-Za-z0-9-\\+]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9-]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$"; //THIS FAILED on sito.org+foo@gmail.com - // !! - // return "^[_A-Za-z0-9-\\+\\.]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9-]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$"; // this failed on - // myha@studserv.uni-leipzig.de return "^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$"; // from https://stackoverflow.com/questions/201323/how-can-i-validate-an-email-address-using-a-regular-expression (JP found on 30 Aug 2021) @@ -995,19 +969,6 @@ public static boolean booleanNotFalse(String value) { } public static String basicSanitize(String input) { - // String sanitized = null; - // if (input!=null) { - // sanitized = input; - // sanitized = input.replace(":", ""); - // sanitized = input.replace(";", ""); - // sanitized = sanitized.replace("\"", ""); - // sanitized = sanitized.replace("'", ""); - // sanitized = sanitized.replace("(", ""); - // sanitized = sanitized.replace(")", ""); - // sanitized = sanitized.replace("*", ""); - // sanitized = sanitized.replace("%", ""); - // } - // return sanitized; return sanitizeUserInput(input); } @@ -1086,14 +1047,6 @@ public static int xxhash(String s) return xxhash(s.getBytes("UTF-8")); } -/* - //note: maybe if files become too huge, this would suck? there is a streaming version (see docs link above) - // turns out it did kinda suck!! see below instead. - public static int xxhash(File f) throws IOException { - if (f == null) throw new IOException("xxhash() passed null file"); - return xxhash(Files.readAllBytes(f.toPath())); - } - */ public static int xxhash(File f) throws IOException { if (f == null) throw new IOException("xxhash() passed null file"); @@ -1180,7 +1133,7 @@ public static String getISO8601Date(final String date) { String iso8601 = date.replace(" ", "T"); if (iso8601.length() == 10) iso8601 += "T00:00:00"; - // TODO better testing of string format + // TODO: better testing of date's string format (or transition to date format support?) if (iso8601.length() < 16) return null; if (iso8601.length() == 16) iso8601 += 'Z'; return iso8601; diff --git a/src/main/java/org/ecocean/WBQuery.java b/src/main/java/org/ecocean/WBQuery.java index b0a9da0899..fb18cf5d93 100644 --- a/src/main/java/org/ecocean/WBQuery.java +++ b/src/main/java/org/ecocean/WBQuery.java @@ -22,7 +22,6 @@ public class WBQuery implements java.io.Serializable { protected AccessControl owner; protected long revision; - // TODO: ? find a more elegant solution to range queries protected int range; protected int minRange; @@ -41,7 +40,6 @@ public WBQuery(final int id, final JSONObject params, final AccessControl owner) this.className = params.optString("class"); this.parameters = new JSONObject(params.optString("query", "{}")); System.out.println("initialized query-param as " + this.parameters.toString()); - // TODO: ? find a more elegant solution to range queries this.minRange = params.optInt("minRange", 0); this.range = params.optInt("range", 100); @@ -115,10 +113,6 @@ public List doQuery(Shepherd myShepherd) return out; } -/* something like this? - WBQuery qry = new WBQuery(new JSONObject("{ \"foo\" : \"bar\" }")); - List res = qry.doQuery(myShepherd); - */ public Query toQuery(Shepherd myShepherd) throws RuntimeException { Query query = null; @@ -131,7 +125,6 @@ public Query toQuery(Shepherd myShepherd) query = myShepherd.getPM().newQuery(qString); query.setClass(getCandidateClass()); - // TODO: double-check that this is the best way to do datestuff queryDeclareImports(query); querySetOrdering(query); @@ -170,8 +163,7 @@ public Class getCandidateClass() } /** - * this is run on each query, and is necessary to enable e.g. datetime comparisons in the query TODO: double-check that this is necessary; I - * haven't seen this kind of thing elsewhere in wildbook -DB + * this is run on each query, and is necessary to enable e.g. datetime comparisons in the query **/ private void queryDeclareImports(Query query) { if (containsDateTime()) { @@ -180,23 +172,19 @@ private void queryDeclareImports(Query query) { } /** - * TODO: make this not constant * @returns whether or not this WBQuery contains a datetime within it, which has implications for how to handle the jdoql query **/ private boolean containsDateTime() { return parameters.has("dateTime"); } - // TODO: parse parameters for an optional range entry // note: mongoDB's 'find' command (which is our syntactic model for json queries) just adds this as a callback function 'limit' e.g. // db.collection.find({queryargs}).limit(10); - // this parses the range, which is passed as an optional third argument of the original query TODO: + // this parses the range, which is passed as an optional third argument of the original query public void querySetRange(Query query) { - // TODO: ? find a more elegant solution to range queries query.setRange(minRange, range); } - // TODO private void querySetOrdering(Query query) { if (this.ordering != null && !this.ordering.equals("")) { query.setOrdering(this.ordering); @@ -307,7 +295,7 @@ private String parseOperatorField(String field) output += ("LOGICAL OPERATORS NOT SUPPORTED YET: Error parsing " + operator); } } - return output; // " operators = ("+output+"): ( (not parsable)" + fieldQuery.toString() + ")"; + return output; } private static String parseOperator(String field, String operator, String value) { @@ -348,7 +336,7 @@ private static String buildComparisonOperator(String field, String operator, Str private static String buildBooleanOperator(String field, String operator, String value) { String isNot = ""; - if (value != "true") isNot = " not"; // TODO: double-check the logic on this line once we have examples + if (value != "true") isNot = " not"; return buildComparisonOperator(field, "is" + isNot, value); } @@ -449,7 +437,6 @@ public String execute(String[] values) { } // Here are literal sets for looking up which class fields are _not_ string-like (for use with classFieldIsEscapedInQuotes) - // TODO: perhaps generate these dynamically? These MUST correspond with classDefinitions.json private static final Set encounterNonStringFields; private static final Set mediaAssetNonStringFields; private static final Set mediaAssetSetNonStringFields; diff --git a/src/main/java/org/ecocean/api/SearchApi.java b/src/main/java/org/ecocean/api/SearchApi.java index b08442f5bb..4751baa255 100644 --- a/src/main/java/org/ecocean/api/SearchApi.java +++ b/src/main/java/org/ecocean/api/SearchApi.java @@ -61,8 +61,8 @@ protected void doPost(HttpServletRequest request, HttpServletResponse response) String sizeStr = request.getParameter("size"); String sort = request.getParameter("sort"); String sortOrder = request.getParameter("sortOrder"); - // for now, we delete pit by default. we will need to let frontend decide when to keep it - // by passing in the previous pit (e.g. for pagination) TODO + // for now, we delete pit by default. TODO: let frontend decide when to keep it + // by passing in the previous pit (e.g. for pagination) // boolean deletePit = Util.requestParameterSet(request.getParameter("deletePit")); boolean deletePit = true; int numFrom = 0; diff --git a/src/main/java/org/ecocean/api/SiteSettings.java b/src/main/java/org/ecocean/api/SiteSettings.java index 215202a638..0cff0862fa 100644 --- a/src/main/java/org/ecocean/api/SiteSettings.java +++ b/src/main/java/org/ecocean/api/SiteSettings.java @@ -68,7 +68,7 @@ protected void doGet(HttpServletRequest request, HttpServletResponse response) settings.put("measurement", CommonConfiguration.getIndexedPropertyValues("measurement", context)); - // TODO: there was some discussion in slack about this being derived differently + // TODO: evaluate deriving this differently // NOTE: historically this list was generated via CommonConfiguration using // List states = CommonConfiguration.getIndexedPropertyValues("encounterState",context) settings.put("encounterState", VALUES_ENCOUNTER_STATES); diff --git a/src/main/java/org/ecocean/api/UserHome.java b/src/main/java/org/ecocean/api/UserHome.java index a7686442c7..9c09ed71a9 100644 --- a/src/main/java/org/ecocean/api/UserHome.java +++ b/src/main/java/org/ecocean/api/UserHome.java @@ -42,7 +42,7 @@ protected void doGet(HttpServletRequest request, HttpServletResponse response) } home.put("user", currentUser.infoJSONObject(context, true)); - // TODO ES replace + // TODO: Replace with OpenSearch JSONArray encountersArr = new JSONArray(); int count = 0; diff --git a/src/main/java/org/ecocean/api/UserInfo.java b/src/main/java/org/ecocean/api/UserInfo.java index 969e00e0fb..561b667ce2 100644 --- a/src/main/java/org/ecocean/api/UserInfo.java +++ b/src/main/java/org/ecocean/api/UserInfo.java @@ -32,7 +32,7 @@ protected void doHead(HttpServletRequest request, HttpServletResponse response) } response.setStatus(200); response.setHeader("X-User-Id", currentUser.getId()); - // TODO could also set: notification stuff? login time? etc? + // TODO: evaluate if other header information (notifications, login time) should be set here myShepherd.rollbackDBTransaction(); myShepherd.closeDBTransaction(); } diff --git a/src/main/java/org/ecocean/cache/CachedQuery.java b/src/main/java/org/ecocean/cache/CachedQuery.java index f241f4b6e0..381bb45c62 100644 --- a/src/main/java/org/ecocean/cache/CachedQuery.java +++ b/src/main/java/org/ecocean/cache/CachedQuery.java @@ -242,7 +242,7 @@ public JSONObject convertToJson(Collection coll, ExecutionContext ec) { for (Object o : coll) { if (o instanceof Collection) { jarr.put(convertToJson((Collection)o, ec)); - } else { // TODO can it *only* be an JSONObject-worthy object at this point? + } else { try { jarr.put(Util.toggleJSONObject(RESTUtils.getJSONObjectFromPOJO(o, ec))); } catch (Exception e) { diff --git a/src/main/java/org/ecocean/genetics/distance/ShareDst.java b/src/main/java/org/ecocean/genetics/distance/ShareDst.java index 0304ddb972..4d43ba2189 100644 --- a/src/main/java/org/ecocean/genetics/distance/ShareDst.java +++ b/src/main/java/org/ecocean/genetics/distance/ShareDst.java @@ -6,94 +6,11 @@ import org.ecocean.*; public class ShareDst { - // NumInputBox NIBnumLoci; - // NumInputBox NIBgenoTypes; - // NumOutputBox NOBoutput; - // Checkbox cbNoDivide; - // Checkbox cbLowerTriangle; - // Checkbox cbNamesPresent; - // Button buClearInputs; - // Button buCalculate; - public final static int ploidy = 2; // hard wired, for now - public ShareDst(String context) { - // setLayout (new GridBagLayout ()); - -/* - NIBnumLoci = new NumInputBox (this, - "Number of Loci", - "How many loci are you examining?", 0, 0, 0, 1, 1, GridBagConstraints.NONE, GridBagConstraints.WEST - ); - */ - - /* - NIBgenoTypes = new NumInputBox (this, - "Individual Genotypes", - "Enter in this order: I1L1A1 I1L1A2 I1L2A1 I1L2A2... I2L1A1 I2L1A2...", 2, 0, 2, 5, 1, - GridBagConstraints.BOTH, GridBagConstraints.WEST, 10.0, 10.0, 1, 1, 1, 1 - ); - */ - - // buClearInputs = new Button ("Clear Inputs"); - // MyFuns.constrain (this, buClearInputs, 0, 18, 1, 1, GridBagConstraints.NONE, GridBagConstraints.WEST, 1.0, 1.0, 1, 1, 1, 1 ); - - // buCalculate = new Button ("Calculate!"); - // MyFuns.constrain (this, buCalculate, 1, 18, 1, 1, GridBagConstraints.NONE, GridBagConstraints.WEST, 1.0, 1.0, 1, 1, 1, 1 ); - // cbNamesPresent = new Checkbox ("Individual names are present as first item in each line", null, false); - // MyFuns.constrain (this, cbNamesPresent, 0, 19, 2, 1, GridBagConstraints.NONE, GridBagConstraints.WEST, 1.0, 1.0, 1, 1, 1, 1 ); - // cbNamesPresent.setFont (new Font("Times", Font.BOLD, 12)); - - // cbNoDivide = new Checkbox ("Don't divide by 2r - makes smaller output", null, false); - // MyFuns.constrain (this, cbNoDivide, 0, 20, 2, 1, GridBagConstraints.NONE, GridBagConstraints.WEST, 1.0, 1.0, 1, 1, 1, 1 ); - // cbNoDivide.setFont (new Font("Times", Font.BOLD, 12)); - - // cbLowerTriangle = new Checkbox ("Only show lower triangle - makes smaller output", null, false); - // MyFuns.constrain (this, cbLowerTriangle, 0, 21, 2, 1, GridBagConstraints.NONE, GridBagConstraints.WEST, 1.0, 1.0, 1, 1, 1, 1 ); - // cbLowerTriangle.setFont (new Font("Times", Font.BOLD, 12)); - -/* - NOBoutput = new NumOutputBox (this, - "Output", - "Use copy/paste to move the results into other programs.", 2, 0, 22, 5, 1, GridBagConstraints.BOTH, - GridBagConstraints.WEST, 10.0, 10.0, 1, 1, 1, 1 - ); - */ - - // run(); } - /* - public String getAppletInfo() - { - return "Name: ShareDst\n" + - "Author: John Brzustowski - jbrzusto@powersurfr.com\n" + - "Compute the shared allele measure of genetic distance between individuals.\n"; - } - */ - - /* - public boolean action( Event evt, Object arg ) - { - if ( evt.target instanceof Button ) - { - if (evt.target == buClearInputs ) - { - NIBnumLoci.setText (""); - NIBgenoTypes.setText (""); - return true; - } - else if (evt.target == buCalculate) - { - run (); - return true; - } - } - return false; - } - */ - /* * * @parameter numLoci The number of loci in the study. @@ -106,7 +23,6 @@ public static String getDistanceOuput(String individualNames[], String lociNames boolean noDivide, boolean lowTriangle, String EOL, String DELIM, String context) { String output = ""; - // NOBoutput.setText (output); int numIndividuals = individualNames.length; int numLoci = lociNames.length; int numAlleles = numLoci * 2; @@ -114,31 +30,17 @@ public static String getDistanceOuput(String individualNames[], String lociNames Hashtable hash = new Hashtable(); int maxCode = 0; - // put in the null value field hash.put("empty", new Integer(maxCode++)); - - // String EOL = NOBoutput.getEOL (); - // String EOL = "\n"; - // String DELIM = NOBoutput.getDelim (); - // String DELIM = " "; - - // String individualNames[] = null; boolean namesPresent = true; Shepherd myShepherd = new Shepherd(context); myShepherd.setAction("ShareDst.java"); myShepherd.beginDBTransaction(); try { - // numLoci = NIBnumLoci.posIntValue (); - // numIndividuals = NIBgenoTypes.countValues () / (numLoci * 2 + (namesPresent ? 1 : 0)); - // if (namesPresent) individualNames = new String[numIndividuals]; genoTypes = new int[numIndividuals][]; - // HashTokenizer htok = new HashTokenizer (NIBgenoTypes.getText(), "-"); for (int i = 0; i < numIndividuals; ++i) { MarkedIndividual indy = myShepherd.getMarkedIndividual(individualNames[i]); genoTypes[i] = new int[numLoci * 2]; - // if (namesPresent) - // individualNames[i] = htok.nextToken(); int j = 0; while (j < numAlleles) { String thisLocus = lociNames[(j / 2)]; @@ -147,7 +49,6 @@ public static String getDistanceOuput(String individualNames[], String lociNames if (!hash.containsKey(vals.get(0))) { hash.put(vals.get(0), new Integer(maxCode++)); } - // return ((Integer) hash.get (s) ).intValue (); genoTypes[i][j] = ((Integer)hash.get(vals.get(0))).intValue(); } else { genoTypes[i][j] = ((Integer)hash.get("empty")).intValue(); @@ -156,7 +57,6 @@ public static String getDistanceOuput(String individualNames[], String lociNames if (!hash.containsKey(vals.get(1))) { hash.put(vals.get(1), new Integer(maxCode++)); } - // return ((Integer) hash.get (s) ).intValue (); genoTypes[i][j + 1] = ((Integer)hash.get(vals.get(1))).intValue(); } else { genoTypes[i][j + 1] = ((Integer)hash.get("empty")).intValue(); @@ -165,7 +65,6 @@ public static String getDistanceOuput(String individualNames[], String lociNames } } } catch (Exception e) { - // NOBoutput.setText (e.getMessage ()); e.printStackTrace(); myShepherd.rollbackDBTransaction(); myShepherd.closeDBTransaction(); @@ -176,8 +75,6 @@ public static String getDistanceOuput(String individualNames[], String lociNames myShepherd.closeDBTransaction(); int i, j; - // boolean noDivide = cbNoDivide.getState (); - // boolean lowTriangle = cbLowerTriangle.getState (); int intDist[][] = null; double Dist[][] = null; if (lowTriangle) { @@ -196,8 +93,6 @@ public static String getDistanceOuput(String individualNames[], String lociNames else Dist = new double[numIndividuals][numIndividuals]; } - // ProgressBar pb = new ProgressBar (this, "Computing shared allele distance: "); - // pb.SetTotalCount (numIndividuals); if (!noDivide) { for (i = 0; i < numIndividuals; ++i) { Dist[i][i] = 0; @@ -207,7 +102,6 @@ public static String getDistanceOuput(String individualNames[], String lociNames if (!lowTriangle) Dist[j][i] = Dist[i][j]; } - // pb.ShowProgress (); } } else { for (i = 0; i < numIndividuals; ++i) { @@ -218,18 +112,12 @@ public static String getDistanceOuput(String individualNames[], String lociNames if (!lowTriangle) intDist[j][i] = intDist[i][j]; } - // pb.ShowProgress (); } } - // pb.finalize (); - // output = output.concat ("There are " + numIndividuals + " individuals and " + numLoci + " loci.\n"); + if (noDivide) { - // output = output.concat ( "\nUnShared Allele Count\n" + "======================\n" ); } else { - // output = output.concat ( "\nShared Allele Distance\n"+ "======================\n" ); } - // pb = new ProgressBar (this, "Formatting output: "); - // pb.SetTotalCount (numIndividuals); if (namesPresent) { StringBuffer s = new StringBuffer(numIndividuals * numIndividuals * (lowTriangle ? 2 : 4)); @@ -255,18 +143,7 @@ public static String getDistanceOuput(String individualNames[], String lociNames output = output.concat(MyFuns.MatrixToString(Dist, 6, 1, DELIM, EOL, lowTriangle)); } Dist = null; - // pb.finalize (); - /* - try - { - NOBoutput.setText (output); - } - catch (Exception e) - { - showStatus (e.getMessage ()); - } - */ return output; } @@ -282,16 +159,6 @@ public String[][] getParameterInfo() { } public void init() { - // TODO: Place additional initialization code here - - /* - String s; - - s = this.getParameter ("numLoci"); - if (s != null) NIBnumLoci.setText (s); - s = this.getParameter ("genoTypes"); - if (s != null) NIBgenoTypes.setText (s.replace (',', '\n')); - */ } } diff --git a/src/main/java/org/ecocean/grid/Geometry.java b/src/main/java/org/ecocean/grid/Geometry.java index 2f0661fb12..33c83360b6 100644 --- a/src/main/java/org/ecocean/grid/Geometry.java +++ b/src/main/java/org/ecocean/grid/Geometry.java @@ -298,7 +298,6 @@ public static double distance(int x0, int y0, int x1, int y1, int x, int y) { double u = ((x - x0) * (x1 - x0) + (y - y0) * (y1 - y0)) / (length * length); // This is the intersection point of the normal. - // TODO: Might consider returning this as well. double xp = x0 + u * (x1 - x0); double yp = y0 + u * (y1 - y0); @@ -672,7 +671,6 @@ public static void findPolygonExtent(int[] x, int[] y, int[] xExtent, // xMin, x */ public static int findLineSegmentIntersection(double x0, double y0, double x1, double y1, double x2, double y2, double x3, double y3, double[] intersection) { - // TODO: Make limit depend on input domain final double LIMIT = 1e-5; final double INFINITY = 1e10; double x, y; diff --git a/src/main/java/org/ecocean/grid/GridManager.java b/src/main/java/org/ecocean/grid/GridManager.java index c666afa564..1605f10fa0 100644 --- a/src/main/java/org/ecocean/grid/GridManager.java +++ b/src/main/java/org/ecocean/grid/GridManager.java @@ -84,16 +84,6 @@ public synchronized void reportCollision() { numCollisions++; } - /* - public void setNodeTimeout(long timeout) { - nodeTimeout = timeout; - } - */ - - /*public long getNodeTimeout() { - return nodeTimeout; - } - */ public void setCreationThread(boolean status) { creationThread = status; } @@ -122,28 +112,9 @@ public int getCreationDeletionThreadQueueSize() { return creationDeletionThreadQueueSize; } - /* - public String getSupportedAppletVersion() { - return appletVersion; - } - */ + public int getNumNodes() { return nodes.size(); - // int returnValue = 0; - // long currenTime = System.currentTimeMillis(); - // for (int i = 0; i < numNodes; i++) { - // System.out.println("gridManager: Time diff is: "+(currenTime-nodes.get(i).getLastCheckin())); - // if ((currenTime - nodes.get(i).getLastHeartbeat()) < nodeTimeout) { - // returnValue++; - // } - /*else { - nodes.remove(i); - i--; - numNodes--; - } - */ - // } - // return returnValue; } public int getNumAllowedNodes() { @@ -152,16 +123,6 @@ public int getNumAllowedNodes() { public void setNumAllowedNodes(int num) { numAllowedNodes = num; - - // if the current number of nodes exceeds the new allowed number - // then we have to remove them - // for now, remove them from the bottom - // int the future, we should consider removing them according - // to an algorithm determining their potential - // while(nodes.size()>numAllowedNodes){ - // int size=nodes.size(); - // nodes.remove(size-1); - // } } public boolean containsNode(String nodeID) { @@ -175,28 +136,9 @@ public boolean containsNode(String nodeID) { return false; } - /*public boolean canMakeSpace(HttpServletRequest request){ - String nodeID=request.getParameter("nodeIdentifier"); - int numNodes=nodes.size(); - long currenTime=System.currentTimeMillis(); - for(int i=0;inodeTimeout){ - nodes.remove(i); - nodes.add(new gridNode(request)); - return true; - } - } - return false; - }*/ public synchronized boolean isGridSpaceAvailable(HttpServletRequest request, boolean targeted) { String nodeID = request.getParameter("nodeIdentifier"); - // clean out old nodes - // int numNodes=nodes.size(); - // long currenTime=System.currentTimeMillis(); - // cleanupOldNodes(); - // first, add the node to the queue if (!containsNode(nodeID)) { GridNode node = new GridNode(request, groupSize); nodes.add(node); @@ -224,11 +166,6 @@ public synchronized boolean isInAllowedPosition(String nodeID) { if (nodes.get(i).getNodeIdentifier().equals(nodeID)) { if (i <= (numAllowedNodes - 1)) return true; } - // else if((currenTime-nodes.get(i).getLastHeartbeat())>nodeTimeout){ - // nodes.remove(i); - // i--; - // numNodes--; - // } } return false; } @@ -269,20 +206,6 @@ public void setScanTaskLimit(int limit) { this.scanTaskLimit = limit; } - /* - private void cleanupOldNodes() { - int numNodes = nodes.size(); - long currenTime = System.currentTimeMillis(); - for (int i = 0; i < numNodes; i++) { - if ((currenTime - nodes.get(i).getLastHeartbeat()) > nodeTimeout) { - nodes.remove(i); - i--; - numNodes--; - } - - } - } - */ public int getPerMinuteRate() { int rate = 0; // cleanupOldNodes(); @@ -324,12 +247,6 @@ public int getNumTasks(String context) { return numScanTasks; } - /* - public int getNumWorkItems(String context) { - updateGridStats(context); - return numScanWorkItems; - } - */ public int getNumCompletedWorkItems() { return numCompletedWorkItems; } @@ -491,15 +408,7 @@ public synchronized void checkinResult(ScanWorkItemResult swir) { } else { numCollisions++; } - // if(!done.contains(swir)){done.add(swir);} - - // if ((!swir.getUniqueNumberTask().equals("TuningTask")) && (!swir.getUniqueNumberTask().equals("FalseMatchTask"))) { removeWorkItem(swir.getUniqueNumberWorkItem()); - // } - // else { - // ScanWorkItem swi = getWorkItem(swir.getUniqueNumberWorkItem()); - // swi.setDone(true); - // } } catch (Exception e) { e.printStackTrace(); } } @@ -665,34 +574,6 @@ public int getNumProcessors() { return numProcessors; } - /* - public static SummaryStatistics getDTWStats(HttpServletRequest request){ - if(dtwStats==null){dtwStats=TrainNetwork.getDTWStats(request);} - return dtwStats; - } - - public static SummaryStatistics getI3SStats(HttpServletRequest request){ - if(i3sStats==null){i3sStats=TrainNetwork.getI3SStats(request);} - return i3sStats; - } - - public static SummaryStatistics getIntersectionStats(HttpServletRequest request){ - if(intersectionStats==null){intersectionStats=TrainNetwork.getIntersectionStats(request);} - return intersectionStats; - } - - public static SummaryStatistics getProportionStats(HttpServletRequest request){ - if(proportionStats==null){proportionStats=TrainNetwork.getProportionStats(request);} - return proportionStats; - } - */ - - // public void addScanTaskSize(String scanTaskID, int size){ - // scanTaskSizes.put(scanTaskID, new Integer(size)); - // } - - // public Integer getScanTaskSize(String scanTaskID){return scanTaskSizes.get(scanTaskID);} - public static ConcurrentHashMap getMatchGraph() { return matchGraph; } public static void addMatchGraphEntry(String elID, EncounterLite el) { matchGraph.put(elID, el); diff --git a/src/main/java/org/ecocean/grid/MatchedPoints.java b/src/main/java/org/ecocean/grid/MatchedPoints.java index fee3e814f2..1a63580085 100644 --- a/src/main/java/org/ecocean/grid/MatchedPoints.java +++ b/src/main/java/org/ecocean/grid/MatchedPoints.java @@ -1,9 +1,5 @@ package org.ecocean.grid; -/** - * ToDO: comment here - */ - import org.ecocean.Spot; import java.util.ArrayList; diff --git a/src/main/java/org/ecocean/ia/IA.java b/src/main/java/org/ecocean/ia/IA.java index 241ca8bffe..e4c506a348 100644 --- a/src/main/java/org/ecocean/ia/IA.java +++ b/src/main/java/org/ecocean/ia/IA.java @@ -220,8 +220,7 @@ public static void handleMissingAcmids(List mediaAssets, Shepherd my } if ((assetsWithMissingAcmids.size() >= batchThreshold) || count == mediaAssets.size()) { - if (assetsWithMissingAcmids.size() > 0) { // if count gets to the end and assetsWithMissingAcmids is still empty, no need to do - // any of this + if (assetsWithMissingAcmids.size() > 0) { // if count gets to the end and assetsWithMissingAcmids is still empty, no need to do any of this try { IBEISIA.sendMediaAssetsNew(assetsWithMissingAcmids, myShepherd.getContext()); @@ -420,7 +419,6 @@ public static void handleRest(JSONObject jin) { myShepherd.storeNewTask(topTask); JSONObject opt = jin.optJSONObject("opt"); // should use this to decide how to branch differently than "default" - // for now (TODO) we just send MAs off to detection and annots off to identification JSONArray mlist = jin.optJSONArray("mediaAssetIds"); if ((mlist != null) && (mlist.length() > 0)) { System.out.println("MLIST: " + mlist); diff --git a/src/main/java/org/ecocean/ia/IAPluginManager.java b/src/main/java/org/ecocean/ia/IAPluginManager.java index bea035e783..ce9562c56e 100644 --- a/src/main/java/org/ecocean/ia/IAPluginManager.java +++ b/src/main/java/org/ecocean/ia/IAPluginManager.java @@ -19,7 +19,7 @@ public class IAPluginManager { // StartupWildbook calls this public static void startup(ServletContextEvent sce) { System.out.println("INFO: IAPluginManager.startup() called"); -// TODO do we only call this in ONE context based on sce????? FIXME +// do we only call this in ONE context based on sce????? for (String context : plugins.keySet()) { for (IAPlugin p : plugins.get(context)) { p.startup(sce); @@ -109,21 +109,4 @@ public static Task intakeAnnotations(Shepherd myShepherd, List anns) return rootTask; } -/* - public static List getAllEnabledPluginClasses(String context) { - List all = getAllPluginClasses(context); - List enabled = new ArrayList(); - for (Class c : all) { - Object p; - try { - p = c.getDeclaredConstructor(String.class).newInstance(context); - } catch (Exception ex) { - throw new RuntimeException("ERROR: IAPluginManager.getAllEnabledPlugins() broke -- " + ex.toString()); - } - IAPlugin plugin = (IAPlugin)p; - if (plugin.isEnabled()) enabled.add(c); - } - return enabled; - } - */ } diff --git a/src/main/java/org/ecocean/ia/IAUtils.java b/src/main/java/org/ecocean/ia/IAUtils.java index 604ce21be2..1fda583fc3 100644 --- a/src/main/java/org/ecocean/ia/IAUtils.java +++ b/src/main/java/org/ecocean/ia/IAUtils.java @@ -28,8 +28,7 @@ public static List intakeMediaAssets(ImportTask it, Shepherd myShepherd) tp.put("matchingSetFilter", mf); parentTask.setParameters(tp); } - Task task = org.ecocean.ia.IA.intakeMediaAssets(myShepherd, enc.getMedia(), parentTask); // TODO are they *really* persisted for another - // thread (queue) + Task task = org.ecocean.ia.IA.intakeMediaAssets(myShepherd, enc.getMedia(), parentTask); // are they *really* persisted for another thread (queue) myShepherd.storeNewTask(task); taskIDs.add(task.getId()); } diff --git a/src/main/java/org/ecocean/ia/Task.java b/src/main/java/org/ecocean/ia/Task.java index dca882f10b..f345a722c3 100644 --- a/src/main/java/org/ecocean/ia/Task.java +++ b/src/main/java/org/ecocean/ia/Task.java @@ -304,7 +304,7 @@ public Map identificationStatusSummary() { return cts; } - public JSONObject getParameters() { // only return as JSONObject! TODO probably validate content below? + public JSONObject getParameters() { // only return as JSONObject! if (parameters == null) return null; return Util.stringToJSONObject(parameters); } @@ -412,7 +412,7 @@ public static Task load(String taskId, Shepherd myShepherd) { return t; } - // TODO versions for multiple objects (when needed) + // TODO: evaluate if we should support versions for multiple objects (when needed) public static List getTasksFor(Annotation ann, Shepherd myShepherd) { String qstr = "SELECT FROM org.ecocean.ia.Task WHERE objectAnnotations.contains(obj) && obj.id == \"" diff --git a/src/main/java/org/ecocean/ia/plugin/TestPlugin.java b/src/main/java/org/ecocean/ia/plugin/TestPlugin.java index 1d1faee88d..cd9582a659 100644 --- a/src/main/java/org/ecocean/ia/plugin/TestPlugin.java +++ b/src/main/java/org/ecocean/ia/plugin/TestPlugin.java @@ -14,7 +14,6 @@ import org.json.JSONObject; /* - TestPlugin is meant to a be "template" plugin to serve as a guide to creating other IA plugins. (As well as test out new ideas/features, perhaps.) @@ -25,9 +24,6 @@ A Queue is not strictly necessary. The intake methods could have simply done whatever processing necessary (e.g. send the objects to a blackbox IA service) in real-time. The Queue just demostrates how to allow intake methods to asynchronously stack up jobs in the background. - - TODO -- mockup a TestPlugin callback, once we figure out how that will get routed thru IAGateway!! - */ public class TestPlugin extends IAPlugin { private String context = null; diff --git a/src/main/java/org/ecocean/ia/plugin/WildbookIAM.java b/src/main/java/org/ecocean/ia/plugin/WildbookIAM.java index 9c462eec3a..3d5f47cfdd 100644 --- a/src/main/java/org/ecocean/ia/plugin/WildbookIAM.java +++ b/src/main/java/org/ecocean/ia/plugin/WildbookIAM.java @@ -30,9 +30,7 @@ /* Wildbook Image Analysis Module (IAM) - Initial stab at "plugin architecture" for "Image Analysis" - */ public class WildbookIAM extends IAPlugin { private String context = null; @@ -56,7 +54,6 @@ public WildbookIAM(String context) { } @Override public void startup(ServletContextEvent sce) { - // TODO genericize this to be under .ia (with startup hooks for *any* IA plugin) // if we dont need identificaiton, no need to prime boolean skipIdent = Util.booleanNotFalse(IA.getProperty(context, "IBEISIADisableIdentification")); @@ -64,7 +61,6 @@ public WildbookIAM(String context) { if (!skipIdent && !org.ecocean.StartupWildbook.skipInit(sce, "PRIMEIA")) prime(); } - // TODO we need to "reclaim" these from IA.intake() stuff! @Override public Task intakeMediaAssets(Shepherd myShepherd, List mas, final Task parentTask) { return null; @@ -119,12 +115,6 @@ public void run() { IA.log("ERROR: WildbookIAM.prime() failed due to " + ex.toString()); ex.printStackTrace(); } -/* - for (MediaAsset ma : mas) { - System.out.println("B: " + ma.getAcmId() + " --> " + ma); - MediaAssetFactory.save(ma, myShepherd); - } - */ myShepherd.commitDBTransaction(); // MAs and annots may have had acmIds changed myShepherd.closeDBTransaction(); IBEISIA.setIAPrimed(true); @@ -155,7 +145,6 @@ public JSONObject sendMediaAssets(ArrayList mas, boolean checkFirst) // sometimes (i.e. when we already did the work, like priming) we dont want to check IA first List iaImageIds = new ArrayList(); if (checkFirst) iaImageIds = iaImageIds(); - // initial initialization(!) HashMap map = new HashMap(); map.put("image_uri_list", new ArrayList()); map.put("image_unixtime_list", new ArrayList()); @@ -236,18 +225,6 @@ public JSONObject sendAnnotations(ArrayList anns, boolean checkFirst URL url = new URL(u); int ct = 0; // may be different shepherd, but findIndividualId() below will only work if its all persisted anyway. :/ - /* - Shepherd myShepherd = null; - try { - myShepherd = new Shepherd(context); - } catch (Exception e) { - e.printStackTrace(); - } - - myShepherd.setAction("WildbookIAM.sendAnnotations"); - myShepherd.beginDBTransaction(); - */ - // sometimes (i.e. when we already did the work, like priming) we dont want to check IA first List iaAnnotIds = new ArrayList(); if (checkFirst) iaAnnotIds = iaAnnotationIds(); @@ -286,8 +263,6 @@ public JSONObject sendAnnotations(ArrayList anns, boolean checkFirst map.get("image_uuid_list").add(iid); int[] bbox = ann.getBbox(); map.get("annot_bbox_list").add(bbox); -// TODO both of these shepherd/db calls can probably be combined !!! FIXME - // yuck - IA class is not species // map.get("annot_species_list").add(getIASpecies(ann, myShepherd)); // better @@ -452,9 +427,6 @@ public static JSONObject toFancyUUID(String u) { } private static Object mediaAssetToUri(MediaAsset ma) { - // URL curl = ma.containerURLIfPresent(); //what is this?? - // if (curl == null) curl = ma.webURL(); - URL curl = ma.webURL(); String urlStr = curl.toString(); diff --git a/src/main/java/org/ecocean/identity/IAQueryCache.java b/src/main/java/org/ecocean/identity/IAQueryCache.java index c0c995d9ad..a87d98effc 100644 --- a/src/main/java/org/ecocean/identity/IAQueryCache.java +++ b/src/main/java/org/ecocean/identity/IAQueryCache.java @@ -25,15 +25,13 @@ public static int buildTargetAnnotationsCache(String context, ArrayList anns = qanns.get(0).getMatchingSetForTaxonomy(myShepherd, null); if (anns == null) return -2; JSONObject jdata = new JSONObject(); JSONArray idArr = new JSONArray(); JSONArray nameArr = new JSONArray(); for (Annotation ann : anns) { -// TODO do we also filter on name conflicts etc here???????????????????????????? + // Doesn't filter on name conflicts etc String name = ann.findIndividualId(myShepherd); if (name == null) name = IBEISIA.IA_UNKNOWN_NAME; nameArr.put(name); @@ -60,9 +58,6 @@ public static CachedQuery setTargetAnnotationsCache(String context, Annotation a QueryCache qc = QueryCacheFactory.getQueryCache(context); CachedQuery q = qc.getQueryByName(qname); if (q == null) { - // Shepherd myShepherd = new Shepherd(context); - // myShepherd.setAction("IAQueryCache.setTargetAnnotationsCache"); - // myShepherd.beginDBTransaction(); q = new CachedQuery(qname, jobj, true, myShepherd); qc.addCachedQuery(q); myShepherd.updateDBTransaction(); @@ -117,17 +112,12 @@ public static JSONObject tryTargetAnnotationsCache(String context, Annotation an // weed out sibling (including ourself!) annots List famAnnotIds = new ArrayList(); - // Shepherd myShepherd = new Shepherd(context); - // myShepherd.setAction("IAQueryCache.tryTargetAnnotationsCache"); - // myShepherd.beginDBTransaction(); Encounter enc = ann.findEncounter(myShepherd); if ((enc != null) && (enc.getAnnotations() != null)) { // second part is impossible (flw) for (Annotation ea : enc.getAnnotations()) { famAnnotIds.add(ea.getAcmId()); } } - // myShepherd.rollbackDBTransaction(); - // TODO some other checks here, obviously????? (or will it just expire by itself) (e.g. validAnnotation???) JSONObject postData = new JSONObject(); JSONArray outIdArr = new JSONArray(); JSONArray outNameArr = new JSONArray(); @@ -140,17 +130,6 @@ public static JSONObject tryTargetAnnotationsCache(String context, Annotation an outIdArr.put(aid); outNameArr.put(an); } -/* - JSONObject sent = IBEISIA.beginIdentifyAnnotations(qanns, matchingSet, queryConfigDict, userConfidence, myShepherd, annTaskId, baseUrl); - ann.setIdentificationStatus(IBEISIA.STATUS_PROCESSING); - taskRes.put("beginIdentify", sent); - String jobId = null; - if ((sent.optJSONObject("status") != null) && sent.getJSONObject("status").optBoolean("success", false)) jobId = - sent.optString("response", null); - taskRes.put("jobId", jobId); - //validIds.toArray(new String[validIds.size()]) IBEISIA.log(annTaskId, ann.getId(), jobId, new JSONObject("{\"_action\": - \"initIdentify\"}"), context); - */ rtn.put("success", false); // tmp during development return rtn; } @@ -170,13 +149,9 @@ public static JSONObject addTargetAnnotation(String context, Annotation ann, log("WARNING: addTargetAnnotation() found empty current arrays! weird."); return null; } - // Shepherd myShepherd = new Shepherd(context); - // myShepherd.setAction("IAQueryCache.addTargetAnnotation"); - // myShepherd.beginDBTransaction(); + String indivId = ann.findIndividualId(myShepherd); - // myShepherd.rollbackDBTransaction(); // cheap fix to handle name-conflict potential: we dont add an annot which is already on list in cache! - // TODO ... do this! :) :( if (indivId == null) { tNameArr.put(IBEISIA.IA_UNKNOWN_NAME); } else { @@ -192,12 +167,7 @@ public static JSONObject addTargetAnnotation(String context, Annotation ann, private static String generateQueryName(String context, Annotation ann, String type, Shepherd myShepherd) { if (ann == null) return null; - // Shepherd myShepherd = new Shepherd(context); - // myShepherd.setAction("IAQueryCache.generateQueryName"); - // myShepherd.beginDBTransaction(); Encounter enc = ann.findEncounter(myShepherd); - // myShepherd.rollbackDBTransaction(); - // myShepherd.closeDBTransaction(); if (enc == null) return null; String val = enc.getTaxonomyString(); if (val == null) return null; diff --git a/src/main/java/org/ecocean/identity/IBEISIA.java b/src/main/java/org/ecocean/identity/IBEISIA.java index a33c10b376..94f959ff68 100644 --- a/src/main/java/org/ecocean/identity/IBEISIA.java +++ b/src/main/java/org/ecocean/identity/IBEISIA.java @@ -69,7 +69,7 @@ import org.joda.time.LocalDateTime; public class IBEISIA { - // TODO move this ish to its own class asap! + // move this ish to its own class asap! private static final Map speciesMap; static { speciesMap = new HashMap(); @@ -91,24 +91,14 @@ public class IBEISIA { private static AtomicBoolean iaPrimed = new AtomicBoolean(false); private static HashMap alreadySentMA = new HashMap(); private static HashMap alreadySentAnn = new HashMap(); - // private static HashMap identificationMatchingState = new HashMap(); private static HashMap identificationUserActiveTaskId = new HashMap(); - // cache-like, in order to speed up IA; TODO make this some kind of smarter class + // cache-like, in order to speed up IA; make this some kind of smarter class private static HashMap cacheAnnotIndiv = new HashMap(); private static String iaBaseURL = null; // gets set the first time it is needed by iaURL() - // public static JSONObject post(URL url, JSONObject data) throws RuntimeException, MalformedURLException, IOException { - - /* - NOTE: good practice is to call IBEISIA.waitForIAPriming(); before any of the sendFoo() or beginFoo() methods, so that some of the - time-consuming hassle can finish. these things should happen upon tomcat startup, but can take a few minutes to run, so there may be cases - where IA jobs are started during this time. technically nothing "bad" happens if a job starts during this process, but it will create a - longer wait time. there is, however, a chance that waitForIAPriming() times out with a RuntimeException thrown. - */ - // a convenience way to send MediaAssets with no (i.e. with only the "trivial") Annotation public static JSONObject __sendMediaAssets(ArrayList mas, String context) throws RuntimeException, MalformedURLException, IOException, NoSuchAlgorithmException, @@ -177,8 +167,6 @@ public static JSONObject __sendMediaAssets(ArrayList mas, return RestClient.post(url, hashMapToJSONObject(map)); } - // Annotation ann = new Annotation(ma, species); - public static JSONObject __sendAnnotations(ArrayList anns, String context, Shepherd myShepherd) throws RuntimeException, MalformedURLException, IOException, NoSuchAlgorithmException, @@ -197,11 +185,7 @@ public static JSONObject __sendAnnotations(ArrayList anns, String co map.put("annot_species_list", new ArrayList()); map.put("annot_bbox_list", new ArrayList()); map.put("annot_name_list", new ArrayList()); - /* - Shepherd myShepherd = new Shepherd(context); - myShepherd.setAction("IBEISIA.class_sendAnnotations"); - myShepherd.beginDBTransaction(); - */ + for (Annotation ann : anns) { if (!needToSend(ann)) continue; if (!validForIdentification(ann, context)) { @@ -231,8 +215,7 @@ public static JSONObject __sendAnnotations(ArrayList anns, String co markSent(ann); ct++; } - // myShepherd.commitDBTransaction(); - // myShepherd.closeDBTransaction(); + System.out.println("sendAnnotations(): sending " + ct); if (ct < 1) return null; @@ -284,7 +267,6 @@ public static JSONObject sendIdentify(ArrayList qanns, ArrayList tnlist = new ArrayList(); ///note: for names here, we make the gigantic assumption that they individualID has been migrated to uuid already! - // String species = null; String iaClass = null; Util.mark("sendIdentify-1", startTime); for (Annotation ann : qanns) { @@ -293,7 +275,6 @@ public static JSONObject sendIdentify(ArrayList qanns, ArrayList qanns, ArrayList qanns, ArrayList qanns, ArrayList qanns, ArrayList mas, String baseUrl, String context, Shepherd myShepherd) throws RuntimeException, MalformedURLException, IOException, NoSuchAlgorithmException, @@ -473,17 +446,7 @@ Object> addImageUuidListToDetectArgs(Map detectArgsMap, return detectArgsMap; } - // DUPLICATE - /* - public static String getModelTag(String context, Taxonomy tax) { - if ((tax == null) || (tax.getScientificName() == null)) return IA.getProperty(context, "modelTag"); //best we can hope for String propKey = - "modelTag_".concat(tax.getScientificName()).replaceAll(" ", "_"); - System.out.println("[INFO] getModelTag() using propKey=" + propKey + " based on " + tax); - String mt = IA.getProperty(context, propKey); - if (mt == null) mt = IA.getProperty(context, "modelTag"); //too bad, fallback! - return mt; - } - */ + private static String getDetectUrlByModelTag(String context, String modelTag) { if (modelTag == null) return IA.getProperty(context, "IBEISIARestUrlStartDetectImages"); String u = IA.getProperty(context, "IBEISIARestUrlStartDetectImages." + modelTag); @@ -523,12 +486,7 @@ public static String getLabelerAlgo(String context, Taxonomy tax) { return vp; } - /* - THIS IS NOW UNUSED BY ABOVE (see note above) note: this is "for internal use only" -- i.e. this is used for getModelTag above, so re-use with - caution? - (that is, it is meant to generate a string to derive a property key in IA.properties and not much else) - - */ + public static String inferIaClass(Annotation ann, Shepherd myShepherd) { Taxonomy tax = ann.getTaxonomy(myShepherd); @@ -571,15 +529,7 @@ public static Taxonomy taxonomyFromMediaAsset(Shepherd myShepherd, MediaAsset ma return null; } - // DUPLICATE - /* - private static String getDetectUrlByModelTag(String context, String modelTag) { - if (modelTag == null) return IA.getProperty(context, "IBEISIARestUrlStartDetectImages"); - String u = IA.getProperty(context, "IBEISIARestUrlStartDetectImages." + modelTag); - if (u != null) return u; - return IA.getProperty(context, "IBEISIARestUrlStartDetectImages"); - } - */ + /* note: i originally was going to base modelTag_FOO on iaClass, but this seems problematic for allowing one model for multiple species (e.g. "all @@ -604,20 +554,10 @@ public static String getViewpointTag(String context) { return getViewpointTag(context, null); } - // DUPLICATE - /* - public static String getViewpointTag(String context, Taxonomy tax) { - if ((tax == null) || (tax.getScientificName() == null)) return IA.getProperty(context, "viewpointModelTag"); //best we can hope for String - propKey = "viewpointModelTag_".concat(tax.getScientificName()).replaceAll(" ", "_"); - System.out.println("[INFO] getViewpointTag() using propKey=" + propKey + " based on " + tax); - String vp = IA.getProperty(context, propKey); - if (vp == null) vp = IA.getProperty(context, "viewpointModelTag"); //too bad, fallback! - return vp; - } - */ + /* - THIS IS NOW UNUSED BY ABOVE (see note above) note: this is "for internal use only" -- i.e. this is used for getModelTag above, so re-use with - caution? + TODO: As THIS IS NOW UNUSED BY ABOVE (see note above), evaluate full deprecation and removal + note: this is "for internal use only" -- i.e. this is used for getModelTag above, so re-use with caution? (that is, it is meant to generate a string to derive a property key in IA.properties and not much else) this uses taxonomyMap, which (via IA.properties) maps detectionClassN -> taxonomyScientificName0 @@ -628,21 +568,7 @@ public static String taxonomyStringToIAClass(String taxonomyString, Shepherd myS return taxonomyToIAClass(myShepherd.getContext(), tax); } - // DUPLICATE - /* - public static String taxonomyToIAClass(String context, Taxonomy tax) { - if (tax == null) return null; - Shepherd myShepherd = new Shepherd(context); - myShepherd.setAction("IBEISIA.taxonomyToIAClass"); - myShepherd.beginDBTransaction(); - HashMap tmap = iaTaxonomyMap(myShepherd); - myShepherd.rollbackDBTransaction(); - for (String iaClass : tmap.keySet()) { - if (tax.equals(tmap.get(iaClass))) return iaClass; - } - return null; - } - */ + public static Taxonomy taxonomyFromMediaAssets(String context, List mas) { if (Util.collectionIsEmptyOrNull(mas)) return null; Shepherd myShepherd = new Shepherd(context); @@ -718,16 +644,6 @@ public static JSONObject getJobResultLogged(String jobID, String context) { return tr.getJSONObject("_debug").getJSONObject("_response"); } - /* - //null return means we are still waiting... JSONObject will have success property = true/false (and results or error) - /* - we get back an *array* like this: - json_result: "[{"qaid": 492, "daid_list": [493], "score_list": [1.5081310272216797], "qauuid": {"__UUID__": - "f6b27df2-5d81-4e62-b770-b56fe1dcf5c2"}, "dauuid_list": [{"__UUID__": "d88c974b-c746-49db-8178-e7b7414708cf"}]}]" - there would be one element for each queried annotation (492 here)... but we are FOR NOW always only sending one. we should TODO adapt for - many-to-many eventually? - */ - // this is "new" identification results public static JSONObject getTaskResults(String taskID, String context) { JSONObject rtn = getTaskResultsBasic(taskID, context); @@ -737,25 +653,7 @@ public static JSONObject getTaskResults(String taskID, String context) { rtn.put("results", res); rtn.remove("_json_result"); return rtn; - /* - - for (int i = 0 ; i < res.length() ; i++) { - JSONObject el = new JSONObject(); - el.put("score_list", res.getJSONObject(i).get("score_list")); - el.put("query_annot_uuid", fromFancyUUID(res.getJSONObject(i).getJSONObject("qauuid"))); - JSONArray matches = new JSONArray(); - JSONArray dlist = res.getJSONObject(i).getJSONArray("dauuid_list"); - for (int d = 0 ; d < dlist.length() ; d++) { - matches.put(fromFancyUUID(dlist.getJSONObject(d))); - } - el.put("match_annot_list", matches); - resOut.put(el); - } - rtn.put("results", resOut); - rtn.remove("_json_result"); - return rtn; - */ } public static JSONObject getTaskResultsDetect(String taskID, String context) { @@ -763,25 +661,7 @@ public static JSONObject getTaskResultsDetect(String taskID, String context) { if ((rtn == null) || !rtn.optBoolean("success", false)) return rtn; // all the ways we can fail JSONArray resOut = new JSONArray(); -/* - JSONArray res = (JSONObject)rtn.get("_json_result"); - - for (int i = 0 ; i < res.length() ; i++) { - JSONObject el = new JSONObject(); - el.put("score_list", res.getJSONObject(i).get("score_list")); - el.put("query_annot_uuid", fromFancyUUID(res.getJSONObject(i).getJSONObject("qauuid"))); - JSONArray matches = new JSONArray(); - JSONArray dlist = res.getJSONObject(i).getJSONArray("dauuid_list"); - for (int d = 0 ; d < dlist.length() ; d++) { - matches.put(fromFancyUUID(dlist.getJSONObject(d))); - } - el.put("match_annot_list", matches); - resOut.put(el); - } - rtn.put("results", resOut); - rtn.remove("_json_result"); - */ return rtn; } @@ -803,7 +683,7 @@ public static JSONObject getTaskResultsBasic(String taskID, ArrayList logs) { JSONObject rtn = new JSONObject(); -///System.out.println("getTaskResultsBasic logs -->\n" + logs); + ///System.out.println("getTaskResultsBasic logs -->\n" + logs); if ((logs == null) || (logs.size() < 1)) { rtn.put("success", false); rtn.put("error", "could not find any log of task ID = " + taskID); @@ -811,7 +691,7 @@ public static JSONObject getTaskResultsBasic(String taskID, } // since "we can", lets also get the object ids here.... String[] objIds = IdentityServiceLog.findObjectIDs(logs); -// System.out.println("objIds -> " + objIds); + // System.out.println("objIds -> " + objIds); // we have to walk through (newest to oldest) and find the (first) one with _action == 'getJobResult' ... but we should also stop on // getJobStatus @@ -825,7 +705,7 @@ public static JSONObject getTaskResultsBasic(String taskID, break; } } -// note: jobstatus == completed seems to be the thing we want + // note: jobstatus == completed seems to be the thing we want if ("getJobStatus".equals(last.optString("_action")) && "unknown".equals(last.getJSONObject("_response").getJSONObject("response").getString( "jobstatus"))) { @@ -844,34 +724,12 @@ public static JSONObject getTaskResultsBasic(String taskID, rtn.put("success", true); rtn.put("_debug", last); rtn.put("_json_result", - last.getJSONObject("_response").getJSONObject("response").opt("json_result")); // "should never" fail. HA! + last.getJSONObject("_response").getJSONObject("response").opt("json_result")); // "should never" fail. HA! if (rtn.get("_json_result") == null) { rtn.put("success", false); rtn.put("error", "json_result seems empty"); } -/* - JSONArray resOut = new JSONArray(); - JSONArray res = last.getJSONObject("_response").getJSONObject("response").getJSONArray("json_result"); //"should never" fail. HA! - //JSONArray res = new JSONArray(last.getJSONObject("_response").getJSONObject("response").getString("json_result")); //"should never" - fail. HA! - - for (int i = 0 ; i < res.length() ; i++) { - JSONObject el = new JSONObject(); - el.put("score_list", res.getJSONObject(i).get("score_list")); - el.put("query_annot_uuid", fromFancyUUID(res.getJSONObject(i).getJSONObject("qauuid"))); - JSONArray matches = new JSONArray(); - JSONArray dlist = res.getJSONObject(i).getJSONArray("dauuid_list"); - for (int d = 0 ; d < dlist.length() ; d++) { - matches.put(fromFancyUUID(dlist.getJSONObject(d))); - } - el.put("match_annot_list", matches); - resOut.put(el); - } - - rtn.put("results", resOut); - - */ } else { rtn.put("error", "getJobResult for task " + taskID + @@ -879,12 +737,12 @@ public static JSONObject getTaskResultsBasic(String taskID, rtn.put("details", last.get("_response")); rtn.put("success", false); } -// System.out.println("objIds ??? " + objIds); + // System.out.println("objIds ??? " + objIds); if ((objIds != null) && (objIds.length > 0)) rtn.put("_objectIds", new JSONArray(Arrays.asList(objIds))); return rtn; } - // TODO we could also do a comparison with when it was started to enable a failure due to timeout + // we could also do a comparison with when it was started to enable a failure due to timeout return null; // if we fall through, it means we are still waiting ...... } @@ -931,40 +789,22 @@ public static HashMap getTaskResultsAsHashMap(String taskID, Str public static boolean waitingOnTask(String taskID, String context) { JSONObject res = getTaskResults(taskID, context); -// System.out.println(" . . . . . . . . . . . . waitingOnTask(" + taskID + ") -> " + res); + // System.out.println(" . . . . . . . . . . . . waitingOnTask(" + taskID + ") -> " + res); if (res == null) return true; return false; // anything else means we are done (good or bad) } -/* - anyMethod failed with code=600 - {"status": {"cache": -1, "message": "Missing image and/or annotation UUIDs (0, 1)", "code": 600, "success": false}, "response": - {"missing_image_uuid_list": [], "missing_annot_uuid_list": [{"__UUID__": "523e8e9d-941c-4879-a5a6-aeafebf34f65"}]}} - - ########## iaCheckMissing res -> {"response":[],"status":{"message":"","cache":-1,"code":200,"success":true}} - ===================================== qlist & tlist ========================= - [{"__UUID__":"cd67cf0f-f2f1-4b16-89e3-e00e5584d23a"}] tlist.size()=1885 - ########## iaCheckMissing res -> - ########## {"response":{"missing_annot_uuid_list":[{"__UUID__":"523e8e9d-941c-4879-a5a6-aeafebf34f65"}],"missing_image_uuid_list":[]},"status":{"message":"Missing - ########## image and/or annotation UUIDs (0, 1)","cache":-1,"code":600,"success":false}} - WARN: IBEISIA.beginIdentity() failed due to an exception: org.json.JSONException: JSONObject["missing_image_annot_list"] not found. - org.json.JSONException: JSONObject["missing_image_annot_list"] not found. - */ + // should return true if we attempted to add missing and caller should try again -/////////////// HOPEFULLY THE NEED FOR THIS IS DEPRECATED NOW? + // TODO: Evaluate, deprecate fully and remove: HOPEFULLY THE NEED FOR THIS IS DEPRECATED NOW? public static boolean iaCheckMissing(JSONObject res, String context, Shepherd myShepherd) { -/////System.out.println("########## iaCheckMissing res -> " + res); -// if (res != null) throw new RuntimeException("fubar!"); + // System.out.println("########## iaCheckMissing res -> " + res); try { if (!((res != null) && (res.getJSONObject("status") != null) && - (res.getJSONObject("status").getInt("code") == 600))) return false; // - // not - // a - // needy - // 600 + (res.getJSONObject("status").getInt("code") == 600))) return false; // note a needy 600 } catch (JSONException je) {} // You don't always get an error code.. Especially if the anns got swatted before sending boolean tryAgain = false; -// TODO handle loop where we keep trying to add same objects but keep failing (e.g. store count of attempts internally in class?) + // TODO: handle loop where we keep trying to add same objects but keep failing (e.g. store count of attempts internally in class?) if ((res.getJSONObject("response") != null) && res.getJSONObject("response").has("missing_image_uuid_list")) { JSONArray list = res.getJSONObject("response").getJSONArray("missing_image_uuid_list"); @@ -972,7 +812,7 @@ public static boolean iaCheckMissing(JSONObject res, String context, Shepherd my for (int i = 0; i < list.length(); i++) { String uuid = fromFancyUUID(list.getJSONObject(i)); System.out.println("**** FAKE ATTEMPT to sendMediaAssets: uuid=" + uuid); - // TODO actually send the mediaasset duh ... future-jon, please fix this + // TODO: actually send the mediaasset duh } } } @@ -981,11 +821,6 @@ public static boolean iaCheckMissing(JSONObject res, String context, Shepherd my JSONArray list = res.getJSONObject("response").getJSONArray("missing_annot_uuid_list"); if (list.length() > 0) { ArrayList anns = new ArrayList(); - - /*Shepherd myShepherd = new Shepherd(context); - myShepherd.setAction("IBEISIA.iaCheckMissing"); - myShepherd.beginDBTransaction(); - */ try { for (int i = 0; i < list.length(); i++) { String acmId = fromFancyUUID(list.getJSONObject(i)); @@ -993,7 +828,7 @@ public static boolean iaCheckMissing(JSONObject res, String context, Shepherd my anns.add(annsTemp.get(0)); } } catch (Exception e) { e.printStackTrace(); } - // would this ever recurse? seems like a 600 would only happen inside sendAnnotations for missing MediaAssets. is this true? TODO + // would this ever recurse? seems like a 600 would only happen inside sendAnnotations for missing MediaAssets. System.out.println("**** attempting to make up for missing Annotation(s): " + anns.toString()); JSONObject srtn = null; @@ -1002,11 +837,7 @@ public static boolean iaCheckMissing(JSONObject res, String context, Shepherd my } catch (Exception ex) {} System.out.println(" returned --> " + srtn); if ((srtn != null) && (srtn.getJSONObject("status") != null) && - srtn.getJSONObject("status").getBoolean("success")) tryAgain = true; // - // it - // "worked"? - // myShepherd.rollbackDBTransaction(); - // myShepherd.closeDBTransaction(); + srtn.getJSONObject("status").getBoolean("success")) tryAgain = true; // it "worked"? } } System.out.println("iaCheckMissing -> " + tryAgain); @@ -1014,7 +845,7 @@ public static boolean iaCheckMissing(JSONObject res, String context, Shepherd my } private static Object mediaAssetToUri(MediaAsset ma) { -// System.out.println("=================== mediaAssetToUri " + ma + "\n" + ma.getParameters() + ")\n"); + // System.out.println("=================== mediaAssetToUri " + ma + "\n" + ma.getParameters() + ")\n"); URL curl = ma.containerURLIfPresent(); if (curl == null) curl = ma.webURL(); @@ -1024,81 +855,12 @@ private static Object mediaAssetToUri(MediaAsset ma) { return curl.toString(); } else if (ma.getStore() instanceof S3AssetStore) { return ma.getParameters(); -/* - JSONObject params = ma.getParameters(); - if (params == null) return null; - //return "s3://s3.amazon.com/" + params.getString("bucket") + "/" + params.getString("key"); - JSONObject b = new JSONObject(); - b.put("bucket", params.getString("bucket")); - b.put("key", params.getString("key")); - return b; - */ } else { if (curl == null) return null; return curl.toString(); } } -/******* quite possibly deprecated! FIXME -jon - //like below, but you can pass Encounters (which will be mined for Annotations and passed along) public static JSONObject - beginIdentify(ArrayList queryEncs, ArrayList targetEncs, Shepherd myShepherd, String species, String taskID, String - baseUrl, String context, JSONObject opt) { - if (!isIAPrimed()) System.out.println("WARNING: beginIdentify() called without IA primed"); - JSONObject results = new JSONObject(); - results.put("success", false); //pessimism! - if ((queryEncs == null) || (queryEncs.size() < 1)) { - results.put("error", "queryEncs is empty"); - return results; - } - if ((targetEncs == null) || (targetEncs.size() < 1)) { - results.put("error", "targetEncs is empty"); - return results; - } - - ArrayList qanns = new ArrayList(); - ArrayList tanns = new ArrayList(); - for (Encounter enc : queryEncs) { - if (enc.getAnnotations() != null) { - for (Annotation ann : enc.getAnnotations()) { - if (validForIdentification(ann)){ - qanns.add(ann); - } - } - } - } - for (Encounter enc : targetEncs) { - if (enc.getAnnotations() != null) { - for (Annotation ann : enc.getAnnotations()) { - if (validForIdentification(ann)){ - tanns.add(ann); - } - } - } - } - - JSONObject queryConfigDict = queryConfigDict(myShepherd, opt); - - return beginIdentifyAnnotations(qanns, tanns, queryConfigDict, null, myShepherd, species, taskID, baseUrl); - } - - */ - -/* i think this method is unused??? -jon private static String getAnnotationSpeciesFromArray(ArrayList qanns, Shepherd myShepherd) { - // Accept the species from the first Ann in the list, complain if inconsistancies. String species = null; - for (Annotation ann : qanns) { - Encounter enc = ann.findEncounter(myShepherd); - String tempSpecies = enc.getGenus()+" "+enc.getSpecificEpithet(); - //AAAAACCCKKKK squishy if (species!=null&&species!=tempSpecies) { - System.out.println("WARNING:SEVERE: beginIdentifyAnnotations called on qann array with inconsistant species at Encounter level!"); - System.out.println("Species A: "+species+" Species B: "+tempSpecies); - } else { - species = tempSpecies; - } - } - return species; - } - */ - // If you realllllly want to send species I'll just swallow it. public static JSONObject beginIdentifyAnnotations(ArrayList qanns, ArrayList tanns, JSONObject queryConfigDict, JSONObject userConfidence, @@ -1109,142 +871,7 @@ public static JSONObject beginIdentifyAnnotations(ArrayList qanns, task, baseUrl, fastlane); } - /* - //actually ties the whole thing together and starts a job with all the pieces needed - // note: if tanns is null, that means we get all exemplar for species public static JSONObject - beginIdentifyAnnotationsOriginal(ArrayList qanns, ArrayList tanns, JSONObject queryConfigDict, JSONObject - userConfidence, Shepherd myShepherd, Task task, String baseUrl) { - - long tt = System.currentTimeMillis(); - if (!isIAPrimed()) System.out.println("WARNING: beginIdentifyAnnotations() called without IA primed"); - //TODO possibly could exclude qencs from tencs? - String jobID = "-1"; - JSONObject results = new JSONObject(); - results.put("success", false); //pessimism! - ArrayList mas = new ArrayList(); //0th item will have "query" encounter ArrayList allAnns = new - ArrayList(); - - String taskID = "_UNKNOWN_"; - if (task != null) taskID = task.getId(); //"should never happen" - log(taskID, jobID, new JSONObject("{\"_action\": \"initIdentify\"}"), myShepherd.getContext()); - String curvrankDailyTag = null; - - Util.mark("identify process start", tt); - try { - for (Annotation ann : qanns) { - if (validForIdentification(ann, myShepherd.getContext())) { - allAnns.add(ann); - MediaAsset ma = ann.getDerivedMediaAsset(); - if (ma == null) ma = ann.getMediaAsset(); - if (ma != null) { - mas.add(ma); - System.out.println("Adding MA to list for sending to sendMediaAssetsNew..."); - } - } - } - - //this voodoo via JH will insure that .acmId is on the MediaAssets which are loaded via getMatchingSet() below (for speed) - javax.jdo.FetchGroup grp = myShepherd.getPM().getPersistenceManagerFactory().getFetchGroup(MediaAsset.class, "BIA"); - grp.addMember("acmId").addMember("store").addMember("id").addMember("parametersAsString").addMember("parameters").addMember("metadata").addMember("labels").addMember("userLatitude").addMember("userLongitude").addMember("userDateTime").addMember("features"); - myShepherd.getPM().getFetchPlan().addGroup("BIA"); - - Util.mark("bia 2", tt); - if (tanns==null||tanns.isEmpty()) { - String iaClass = qanns.get(0).getIAClass(); - System.out.println("beginIdentifyAnnotations(): have to set tanns. Matching set being built from the first ann in the list."); - tanns = qanns.get(0).getMatchingSet(myShepherd, (task == null) ? null : task.getParameters()); - curvrankDailyTag = qanns.get(0).getCurvrankDailyTag((task == null) ? null : task.getParameters()); - } - Util.mark("bia 3", tt); - - System.out.println("- mark 2"); - if (tanns!=null&&!tanns.isEmpty()) { - System.out.println("INFO: tanns, (matchingSet) is not null. Contains "+tanns.size()+" annotations."); - for (Annotation ann : tanns) { - allAnns.add(ann); - MediaAsset ma = ann.getDerivedMediaAsset(); - if (ma == null) ma = ann.getMediaAsset(); - if (ma != null) mas.add(ma); - } - } - Util.mark("bia 4", tt); - - results.put("sendMediaAssets", sendMediaAssetsNew(mas, myShepherd.getContext())); - Util.mark("bia 4A", tt); - results.put("sendAnnotations", sendAnnotationsNew(allAnns, myShepherd.getContext(),myShepherd)); - Util.mark("bia 4B", tt); - - if (tanns!=null) { - System.out.println(" ... qanns has: "+qanns.size()+" ... taans has: "+tanns.size()); - } else { - System.out.println(" ... qanns has: "+qanns.size()+" ... taans is null! Target is all annotations."); - } - - if (curvrankDailyTag != null) { - if (queryConfigDict == null) queryConfigDict = new JSONObject(); - - //from JP on 12/27/2019 - if we want to specify an unfiltered list, just omit the tag - if(!curvrankDailyTag.toLowerCase().equals("user:any") && !curvrankDailyTag.toLowerCase().equals("user:any;locs:")) { - queryConfigDict.put("curvrank_daily_tag", curvrankDailyTag); - } - } - - Util.mark("bia 4C", tt); - //this should attempt to repair missing Annotations boolean tryAgain = true; - JSONObject identRtn = null; - while (tryAgain) { - identRtn = sendIdentify(qanns, tanns, queryConfigDict, userConfidence, baseUrl, myShepherd.getContext(), taskID,fastlane); - System.out.println("identRtn contains ========> "+identRtn); - if (identRtn == null) { - results.put("error", "identRtn == NULL"); - results.put("success", false); - return results; - } else if - (identRtn!=null&&identRtn.getJSONObject("status")!=null&&!identRtn.getJSONObject("status").getString("message").equals("rejected")) - { - tryAgain = iaCheckMissing(identRtn, myShepherd.getContext(), myShepherd); - } else { - results.put("error", identRtn.get("status")); - results.put("success", false); - return results; - } - - - } - - - results.put("sendIdentify", identRtn); - - System.out.println("sendIdentify ---> " + identRtn); - //if ((identRtn != null) && (identRtn.get("status") != null) && identRtn.get("status") //TODO check success == true :/ - //########## iaCheckMissing res -> {"response":[],"status":{"message":"","cache":-1,"code":200,"success":true}} - if ((identRtn != null) && identRtn.has("status") && identRtn.getJSONObject("status").getBoolean("success")) { - jobID = identRtn.get("response").toString(); - results.put("success", true); - } else { - System.out.println("beginIdentifyAnnotations() unsuccessful on sendIdentify(): " + identRtn); - results.put("error", identRtn.get("status")); - results.put("success", false); - } - - } catch (Exception ex) { //most likely from sendFoo() System.out.println("WARN: IBEISIA.beginIdentity() failed due to an exception: " + - ex.toString()); - ex.printStackTrace(); - results.put("success", false); - results.put("error", ex.toString()); - } - - JSONObject jlog = new JSONObject(); - jlog.put("_action", "sendIdentify"); - jlog.put("_response", results); - log(taskID, jobID, jlog, myShepherd.getContext()); - - return results; - } - */ - -// trying to optimize the original beginIdentifyAnnotations() [above] - + // trying to optimize the original beginIdentifyAnnotations() [above] public static JSONObject beginIdentifyAnnotations(ArrayList qanns, ArrayList tanns, JSONObject queryConfigDict, JSONObject userConfidence, Shepherd myShepherd, Task task, String baseUrl, boolean fastlane) { @@ -1252,11 +879,10 @@ public static JSONObject beginIdentifyAnnotations(ArrayList qanns, if (!isIAPrimed()) System.out.println("WARNING: beginIdentifyAnnotations() called without IA primed"); - // TODO possibly could exclude qencs from tencs? + // possibly could exclude qencs from tencs? String jobID = "-1"; JSONObject results = new JSONObject(); results.put("success", false); // pessimism! - // ArrayList mas = new ArrayList(); //0th item will have "query" encounter ArrayList allAnns = new ArrayList(); String taskID = "_UNKNOWN_"; if (task != null) taskID = task.getId(); // "should never happen" @@ -1269,14 +895,7 @@ public static JSONObject beginIdentifyAnnotations(ArrayList qanns, for (Annotation ann : qanns) { if (validForIdentification(ann, myShepherd.getContext())) { allAnns.add(ann); -/* - MediaAsset ma = ann.getDerivedMediaAsset(); - if (ma == null) ma = ann.getMediaAsset(); - if (ma != null) { - mas.add(ma); - System.out.println("Adding MA to list for sending to sendMediaAssetsNew..."); - } - */ + } } // this voodoo via JH will insure that .acmId is on the MediaAssets which are loaded via getMatchingSet() below (for speed) @@ -1307,21 +926,12 @@ public static JSONObject beginIdentifyAnnotations(ArrayList qanns, tanns.size() + " annotations."); for (Annotation ann : tanns) { allAnns.add(ann); -/* - MediaAsset ma = ann.getDerivedMediaAsset(); - if (ma == null) ma = ann.getMediaAsset(); - if (ma != null) mas.add(ma); - */ + } } Util.mark("OPT bia 4", tt); -/* - results.put("sendMediaAssets", sendMediaAssetsNew(mas, myShepherd.getContext())); - Util.mark("bia 4A", tt); - results.put("sendAnnotations", sendAnnotationsNew(allAnns, myShepherd.getContext(),myShepherd)); - Util.mark("bia 4B", tt); - */ + results.put("sendAnnotationsAsNeeded", sendAnnotationsAsNeeded(allAnns, myShepherd)); Util.mark("OPT bia 4X", tt); if (tanns != null) { @@ -1363,8 +973,6 @@ public static JSONObject beginIdentifyAnnotations(ArrayList qanns, results.put("sendIdentify", identRtn); System.out.println("sendIdentify ---> " + identRtn); - // if ((identRtn != null) && (identRtn.get("status") != null) && identRtn.get("status") //TODO check success == true :/ -// ########## iaCheckMissing res -> {"response":[],"status":{"message":"","cache":-1,"code":200,"success":true}} if ((identRtn != null) && identRtn.has("status") && identRtn.getJSONObject("status").getBoolean("success")) { jobID = identRtn.get("response").toString(); @@ -1391,82 +999,8 @@ public static JSONObject beginIdentifyAnnotations(ArrayList qanns, } // a slightly different flavor -- we can explicitely pass the query annotation - // NOTE!!! TODO this might be redundant with beginIdentifyAnnotations above. (this came from crc) -/* - public static JSONObject beginIdentify(Annotation qann, ArrayList targetEncs, Shepherd myShepherd, String species, String taskID, - String baseUrl, String context) { - //TODO possibly could exclude qencs from tencs? - String jobID = "-1"; - JSONObject results = new JSONObject(); - results.put("success", false); //pessimism! - ArrayList mas = new ArrayList(); - ArrayList tanns = new ArrayList(); - ArrayList allAnns = new ArrayList(); - - if (targetEncs.size() < 1) { - results.put("error", "targetEncs is empty"); - return results; - } - - log(taskID, qann.getId(), jobID, new JSONObject("{\"_action\": \"init\"}"), context); - - try { - allAnns.add(qann); - MediaAsset qma = qann.getDerivedMediaAsset(); - if (qma == null) qma = qann.getMediaAsset(); - if (qma != null) mas.add(qma); - - for (Encounter enc : targetEncs) { - ArrayList annotations = enc.getAnnotations(); - for (Annotation ann : annotations) { - if (qann.getId().equals(ann.getId())) continue; //skip the query annotation allAnns.add(ann); - tanns.add(ann); - MediaAsset ma = ann.getDerivedMediaAsset(); - if (ma == null) ma = ann.getMediaAsset(); - if (ma != null) mas.add(ma); - } - } - - results.put("sendMediaAssets", sendMediaAssets(mas)); - results.put("sendAnnotations", sendAnnotations(allAnns)); + // NOTE!!! this might be redundant with beginIdentifyAnnotations above. (this came from crc) - //this should attempt to repair missing Annotations boolean tryAgain = true; - JSONObject identRtn = null; - while (tryAgain) { - ArrayList qanns = new ArrayList(); - qanns.add(qann); - identRtn = sendIdentify(qanns, tanns, baseUrl); - tryAgain = iaCheckMissing(identRtn); - } - results.put("sendIdentify", identRtn); - - //if ((identRtn != null) && (identRtn.get("status") != null) && identRtn.get("status") //TODO check success == true :/ - //########## iaCheckMissing res -> {"response":[],"status":{"message":"","cache":-1,"code":200,"success":true}} - if ((identRtn != null) && identRtn.has("status") && identRtn.getJSONObject("status").getBoolean("success")) { - jobID = identRtn.get("response").toString(); - results.put("success", true); - } else { - System.out.println("beginIdentify() unsuccessful on sendIdentify(): " + identRtn); - results.put("error", identRtn.get("status")); - results.put("success", false); - } - - } catch (Exception ex) { //most likely from sendFoo() System.out.println("WARN: IBEISIA.beginIdentity() failed due to an exception: " + - ex.toString()); - ex.printStackTrace(); - results.put("success", false); - results.put("error", ex.toString()); - } - - JSONObject jlog = new JSONObject(); - jlog.put("_action", "sendIdentify"); - jlog.put("_response", results); - log(taskID, jobID, jlog, context); - - return results; - } - - */ public static IdentityServiceLog log(String taskID, String jobID, JSONObject jlog, String context) { String[] sa = null; @@ -1484,7 +1018,7 @@ public static IdentityServiceLog log(String taskID, String objectID, String jobI public static IdentityServiceLog log(String taskID, String[] objectIDs, String jobID, JSONObject jlog, String context) { -// System.out.println("#LOG: taskID=" + taskID + ", jobID=" + jobID + " --> " + jlog.toString()); + // System.out.println("#LOG: taskID=" + taskID + ", jobID=" + jobID + " --> " + jlog.toString()); IdentityServiceLog log = new IdentityServiceLog(taskID, objectIDs, SERVICE_NAME, jobID, jlog); Shepherd myShepherd = new Shepherd(context); @@ -1597,106 +1131,10 @@ private static void markSent(Annotation ann) { alreadySentAnn.put(ann.getId(), true); } -/* no longer needed?? - public static JSONObject send(URL url, JSONObject jobj) throws RuntimeException, MalformedURLException, IOException, NoSuchAlgorithmException, - InvalidKeyException { - System.out.println("SENDING: ------\n" + jobj.toString() + "\n---------- to " + iaUrl.toString()); - JSONObject jrtn = RestClient.post(iaUrl, jobj); - System.out.println("RESPONSE:\n" + jrtn.toString()); - return jrtn; - } - */ /* - image_attrs = { - ~'image_rowid': 'INTEGER', - 'image_uuid': 'UUID', - 'image_uri': 'TEXT', - 'image_ext': 'TEXT', - *'image_original_name': 'TEXT', - 'image_width': 'INTEGER', - 'image_height': 'INTEGER', - *'image_time_posix': 'INTEGER', - *'image_gps_lat': 'REAL', - *'image_gps_lon': 'REAL', - !'image_toggle_enabled': 'INTEGER', - !'image_toggle_reviewed': 'INTEGER', - ~'image_note': 'TEXT', - *'image_timedelta_posix': 'INTEGER', - *'image_original_path': 'TEXT', - !'image_location_code': 'TEXT', - *'contributor_tag': 'TEXT', - *'party_tag': 'TEXT', - } - */ - -/* - public static JSONObject imageJSONObjectFromMediaAsset(MediaAsset ma) { - JSONObject obj = new JSONObject(); - obj.put("image_uuid", ma.getUUID()); - ImageAttributes iatt = ma.getImageAttributes(); - obj.put("image_width", (int) iatt.getWidth()); - obj.put("image_height", (int) iatt.getHeight()); - obj.put("image_ext", iatt.getExtension()); - - JSONObject params = new JSONObject(ma.getParameters(), JSONObject.getNames(ma.getParameters())); - params.put("store_type", ma.getStore().getType()); - obj.put("image_storage_parameters", params); - return obj; - } - */ - -/**** i think this is no longer used -- and as such we can eliminate beginIdentify() !! - public static ArrayList startTrainingJobs(ArrayList encs, String taskPrefix, String taxonomyString, Shepherd myShepherd, String - baseUrl, String context) { - ArrayList ids = new ArrayList(); - System.out.println("beginning IBEIS-IA training jobs on " + encs.size() + " encounters (taskPrefix " + taskPrefix + ")"); - for(int i = 0 ; i < encs.size() ; i++) { - Encounter qenc = encs.get(i); - ArrayList qencs=new ArrayList(); - qencs.add(qenc); - ArrayList tencs=new ArrayList(); - for (int j = (i+1) ; j < encs.size() ; j++) { - tencs.add(encs.get(j)); - } - String taskID = taskPrefix + qenc.getEncounterNumber(); - System.out.println(i + ") beginIdentify (taskID=" + taskID + ") - ========================================================================================"); - JSONObject res = beginIdentify(qencs, tencs, myShepherd, taxonomyString, taskID, baseUrl, context, null); - if (res.optBoolean("success")) { - ids.add(taskID); - } else { - System.out.println("WARNING - could not start job for " + taskID + ": " + res.optString("error", "[unknown error]") + "; skipping"); - } - } - return ids; - } - - public static void waitForTrainingJobs(ArrayList taskIds, String context) { - boolean stillWaiting = true; - int countdown = 100; - while (stillWaiting && (countdown > 0)) { - countdown--; - stillWaiting = false; //optimism; prove us wrong int idLen = taskIds.size(); - for (int i = 0 ; i < idLen ; i++) { - if (waitingOnTask(taskIds.get(i), context)) { - System.out.println("++++ waitForTrainingJobs() still waiting on " + taskIds.get(i) + " so will sleep a while (countdown=" + countdown + "; passed " - + i + " of " + idLen +")"); - stillWaiting = true; - break; //this is cause enough to sleep for a bit -- we dont need to check any more! - } - } - if (stillWaiting) { - try { Thread.sleep(3000); } catch (java.lang.InterruptedException ex) {} - } - } - System.out.println("!!!! waitForTrainingJobs() has finished."); - } - */ - -/* - WB-945 - this is the re-tooling of this method which does nothing with encounter(s) REMINDER TODO: - shouldUpdateSpeciesFromIa() no longer gets called here and thus should be called once all annots are made, i guess/ + this is the re-tooling of this method which does nothing with encounter(s) + REMINDER: shouldUpdateSpeciesFromIa() no longer gets called here and thus should be called once all annots are made */ public static Annotation createAnnotationFromIAResult(JSONObject jann, MediaAsset asset, Shepherd myShepherd, String context, String rootDir) { @@ -1709,8 +1147,7 @@ public static Annotation createAnnotationFromIAResult(JSONObject jann, MediaAsse return ann; } -// {"xtl":910,"height":413,"theta":0,"width":444,"class":"giraffe_reticulated","confidence":0.2208,"ytl":182} - // WB-945 - this is the old deprecated version for prosperity or whatever + // TODO: evaluate for deprecation and remove: this is the old deprecated version for prosperity or whatever public static Annotation createAnnotationFromIAResultDEPRECATED(JSONObject jann, MediaAsset asset, Shepherd myShepherd, String context, String rootDir, boolean skipEncounter) { @@ -1725,8 +1162,6 @@ public static Annotation createAnnotationFromIAResultDEPRECATED(JSONObject jann, } Encounter enc = null; try { - // removed due to deprecating ann.toEncounter() for WB-945 - // enc = ann.toEncounter(myShepherd); //this does the magic of making a new Encounter if needed etc. good luck! myShepherd.getPM().makePersistent(enc); enc.detectedAnnotation(myShepherd, ann); // this is a stub presently, so meh? @@ -1776,7 +1211,7 @@ public static int updateSpeciesOnIA(Shepherd myShepherd, List anns) if ((enc == null) || (ann.getAcmId() == null)) continue; String taxonomyString = enc.getTaxonomyString(); if (!shouldUpdateSpeciesFromIa(taxonomyString, myShepherd.getContext())) continue; - // WB-1251, switch species to iaClass + // switch species to iaClass if (ann.getIAClass() == null) continue; uuids.add(ann.getAcmId()); // species.add(taxonomyString); @@ -1848,7 +1283,7 @@ public static Annotation convertAnnotation(MediaAsset ma, JSONObject iaResult, iaResult.optDouble("ytl", 0), fparams); System.out.println("convertAnnotation() generated ft = " + ft + "; params = " + ft.getParameters()); -// TODO get rid of convertSpecies stuff re: Taxonomy!!!! + // get rid of convertSpecies stuff re: Taxonomy!!!! Annotation ann = new Annotation(convertSpeciesToString(iaResult.optString("class", null)), ft, iaClass); ann.setIAExtractedKeywords(myShepherd, taxonomyBeforeDetection); @@ -2011,7 +1446,7 @@ public static JSONObject processCallback(String taskID, JSONObject resp, String boolean skipIdent = Util.booleanNotFalse(IA.getProperty(context, "IBEISIADisableIdentification")); // now we pick up IA.intake(anns) from detection above (if applicable) - // TODO should we cluster these based on MediaAsset instead? send them in groups to IA.intake()? + // should we cluster these based on MediaAsset instead? send them in groups to IA.intake()? if (!skipIdent && (newAnns != null)) { List needIdentifying = new ArrayList(); Shepherd myShepherd2 = new Shepherd(context); @@ -2063,9 +1498,7 @@ public static JSONObject processCallback(String taskID, JSONObject resp, String return rtn; } -/* resp -> - {"_action":"getJobResult","_response":{"response":{"json_result":{"score_list":[0],"results_list":[[{"xtl":679,"theta":0,"height":366,"width":421,"class":"elephant_savanna","confidence":0.215,"ytl":279},{"xtl":71,"theta":0,"height":206,"width":166,"class":"elephant_savanna","confidence":0.2685,"ytl":425},{"xtl":1190,"theta":0,"height":222,"width":67,"class":"elephant_savanna","confidence":0.2947,"ytl":433}]],"image_uuid_list":[{"__UUID__":"f0f9cc19-a56d-3a81-be40-bc51e65714e6"}]},"status":"ok","jobid":"jobid-0025"},"status":{"message":"","cache":-1,"code":200,"success":true}},"jobID":"jobid-0025"} - */ + private static JSONObject processCallbackDetect(String taskID, ArrayList logs, JSONObject resp, Shepherd myShepherd, HttpServletRequest request) { @@ -2102,24 +1535,21 @@ private static JSONObject processCallbackDetect(String taskID, "json_result"); JSONArray rlist = j.optJSONArray("results_list"); JSONArray ilist = j.optJSONArray("image_uuid_list"); -/* TODO lots to consider here: - --1. how do we determine where the cutoff is for auto-creating the annotation?-- made some methods for this 2. if we do create (or dont!) how do - we denote this for the sake of the user/ui querying status? +/* lots to consider here: + 1. how do we determine where the cutoff is for auto-creating the annotation?-- made some methods for this + 2. if we do create (or dont!) how do we denote this for the sake of the user/ui querying status? 3. do we first clear out existing annotations? 4. do we allow duplicate (identical) annoations? if not, do we block that at the level where we attach to encounter? or globally? 5. do we have to tell IA when we auto-approve (i.e. no user review) results? 6. how do (when do) we kick off *identification* on an annotation? and what are the target annotations? 7. etc??? - */ -/* - update due to WB-945 work: we now must _first_ build all the Annotations, and then after that decide how they get distributed to Encounters... + update: we now must _first_ build all the Annotations, and then after that decide how they get distributed to Encounters... */ if ((rlist != null) && (rlist.length() > 0) && (ilist != null) && (ilist.length() == rlist.length())) { FeatureType.initAll(myShepherd); JSONArray needReview = new JSONArray(); JSONObject amap = new JSONObject(); - // JSONObject ident = new JSONObject(); List allAnns = new ArrayList(); List alreadyDetected = new ArrayList(); for (int i = 0; i < rlist.length(); i++) { @@ -2146,7 +1576,7 @@ private static JSONObject processCallbackDetect(String taskID, if (janns.length() == 0) { // OK, for some species and conditions we may just want to trust the user // that there is an animal in the image and set trivial annot to matchAgainst=true - // WB-945 note: this case janns is empty, so loop below will be skipped + // this case janns is empty, so loop below will be skipped if (asset.getAnnotations() != null && asset.getAnnotations().size() == 1 && asset.getAnnotations().get(0).isTrivial()) { // so this media asset currently only has one trivial annot @@ -2179,8 +1609,7 @@ private static JSONObject processCallbackDetect(String taskID, } // these are annotations we can make automatically from ia detection. we also do the same upon review return // note this creates other stuff too, like encounter - // Annotation ann = createAnnotationFromIAResult(jann, asset, myShepherd, context, rootDir, skipEncounters); - // WB-945 update: new version *will not* create encounter(s) + // new version *will not* create encounter(s) Annotation ann = createAnnotationFromIAResult(jann, asset, myShepherd, context, rootDir); if (ann == null) { @@ -2189,7 +1618,7 @@ private static JSONObject processCallbackDetect(String taskID, + asset + " and " + jann); continue; } - // MAYBE NOT NEEDED - same(?) logic in createAnnotationFromIAResult above ????? if (!skipEncounters) + // TODO: evaluate for deprecation and remove: MAYBE NOT NEEDED - same(?) logic in createAnnotationFromIAResult above ????? if (!skipEncounters) // _tellEncounter(myShepherd, ann); // ???, context, rootDir); allAnns.add(ann); // this is cumulative over *all MAs* newAnns.put(ann.getId()); @@ -2204,13 +1633,12 @@ private static JSONObject processCallbackDetect(String taskID, asset.setDetectionStatus(STATUS_COMPLETE); } if (newAnns.length() > 0) { - List assignedEncs = asset.assignEncounters(myShepherd); // WB-945 here is where we make some encounter(s) if we - // need to + List assignedEncs = asset.assignEncounters(myShepherd); // here is where we make some encounter(s) if we need to rtn.put("_assignedEncsSize", assignedEncs.size()); amap.put(Integer.toString(asset.getId()), newAnns); - // now we have to collect them under an Occurrence and/or ImportTask as applicable [WB-430] + // now we have to collect them under an Occurrence and/or ImportTask as applicable // we basically pick the first of these we find (in case there is more than one?) - // and only assign it where there is none. #TODO is that wise? would we rather consolidate if under many occs??? + // and only assign it where there is none. if (!Util.collectionIsEmptyOrNull(assignedEncs)) { ImportTask itask = null; Occurrence occ = null; @@ -2271,7 +1699,7 @@ private static JSONObject processCallbackDetect(String taskID, jlog.put("collatedOccurrence", occ.getOccurrenceID()); } jlog.put("twitterBot", - TwitterBot.processDetectionResults(myShepherd, mas, rootDir)); // will do nothing if not twitter-sourced + TwitterBot.processDetectionResults(myShepherd, mas, rootDir)); // will do nothing if not twitter-sourced jlog.put("_action", "processedCallbackDetect"); if (amap.length() > 0) jlog.put("annotations", amap); if (needReview.length() > 0) jlog.put("needReview", needReview); @@ -2283,16 +1711,6 @@ private static JSONObject processCallbackDetect(String taskID, return rtn; } -/* not convinced we need this at all!!! -jon private static void _tellEncounter(Shepherd myShepherd, Annotation ann) { //, String context, String - rootDir) { - System.out.println("/------ _tellEncounter ann = " + ann); - Encounter enc = ann.toEncounter(myShepherd); - System.out.println("\\------ _tellEncounter enc = " + enc); - if (enc == null) return; - myShepherd.getPM().makePersistent(enc); - enc.detectedAnnotation(myShepherd, ann); - } - */ private static JSONObject processCallbackIdentify(String taskID, ArrayList logs, JSONObject resp, String context, String rootDir) { JSONObject rtn = new JSONObject("{\"success\": false}"); @@ -2321,15 +1739,13 @@ private static JSONObject processCallbackIdentify(String taskID, int numCreated = 0; JSONObject infDict = null; JSONObject j = null; -// System.out.println("___________________________________________________\n" + resp + "\n------------------------------------------------------"); + // System.out.println("___________________________________________________\n" + resp + "\n------------------------------------------------------"); if ((resp.optJSONObject("_response") != null) && (resp.getJSONObject("_response").optJSONObject("response") != null) && (resp.getJSONObject("_response").getJSONObject("response").optJSONObject( "json_result") != null)) { j = resp.getJSONObject("_response").getJSONObject("response").getJSONObject( "json_result"); - // if ((resp != null) && (resp.optJSONObject("json_result") != null) && (resp.getJSONObject("json_result").optJSONObject("inference_dict") - // != null)) if (j.optJSONObject("inference_dict") != null) infDict = j.getJSONObject("inference_dict"); } @@ -2358,10 +1774,9 @@ private static JSONObject processCallbackIdentify(String taskID, // Chris assumed this was true in the line below that looks like String matchUuid = // rlist.getJSONObject(i).optJSONObject("annot_uuid_2"); - // NOTE: will the review_pair_list and confidence_list always be in descending order? IF not, then TODO we'll have to only select the + // NOTE: will the review_pair_list and confidence_list always be in descending order? IF not, then we'll have to only select the // best match (what if there's more than one really good match) - String acmId = fromFancyUUID(rlist.getJSONObject(i).getJSONObject("annot_uuid_1")); // gets not opts here... so ungraceful fail - // possible + String acmId = fromFancyUUID(rlist.getJSONObject(i).getJSONObject("annot_uuid_1")); // gets not opts here... so ungraceful fail possible if (!needReviewMap.containsKey(acmId)) needReviewMap.put(acmId, false); // only set first, so if set true it stays true if (needIdentificationReview(rlist, clist, i, context)) { needReview = true; @@ -2463,7 +1878,7 @@ private static boolean needIdentificationReview(JSONArray rlist, JSONArray clist if ((rlist == null) || (clist == null) || (i < 0) || (rlist.length() == 0) || (clist.length() == 0) || (rlist.length() != clist.length()) || (i >= rlist.length())) return false; -////TODO work is still out if we need to ignore based on our own matchingState!!! for now we skip review if we already did it + // work is still out if we need to ignore based on our own matchingState!!! for now we skip review if we already did it if (rlist.optJSONObject(i) == null) return false; String ms = getIdentificationMatchingState(fromFancyUUID(rlist.getJSONObject( i).optJSONObject("annot_uuid_1")), @@ -2471,8 +1886,6 @@ private static boolean needIdentificationReview(JSONArray rlist, JSONArray clist System.out.println( "needIdentificationReview() got matching_state --------------------------> " + ms); if (ms != null) return false; -////// - return (clist.optDouble(i, -99.0) < getIdentificationCutoffValue(context)); } @@ -2535,13 +1948,7 @@ private static String _parseIdentification(IdentityServiceLog log) { if (status == null) return null; String action = status.optString("_action", null); if (action == null) return null; -/* - if (action.equals("processedCallbackDetection")) { - JSONArray need = stats.optJSONArray("needReview"); - if ((need == null) || (need.length() < 1)) return "complete"; - return "pending"; - } - */ + System.out.println("identification most recent action found is " + action); return "processing"; } @@ -2623,14 +2030,14 @@ public static URL iaURL(String context, String urlSuffix) { } } - ////note: we *could* try to grab these as lists from IA, but that is more complicated so lets iterate for now... + // note: we *could* try to grab these as lists from IA, but that is more complicated so lets iterate for now... public static List grabAnnotations(List annIds, Shepherd myShepherd) { List anns = new ArrayList(); for (String annId : annIds) { Annotation ann = null; ArrayList existing = myShepherd.getAnnotationsWithACMId(annId); - // TODO do we need to verify MediaAsset has been retreived? for now, lets assume that happened during creation + // do we need to verify MediaAsset has been retreived? for now, lets assume that happened during creation if ((existing != null) && (existing.size() > 0)) { // we take the first one that exists anns.add(existing.get(0)); continue; @@ -2712,7 +2119,7 @@ public static MediaAsset grabMediaAsset(String maUUID, Shepherd myShepherd) { return getMediaAssetFromIA(maUUID, myShepherd); } -// http://52.37.240.178:5000/api/image/src/json/cb2e67a4-7094-d971-c5c6-3b5bed251fec/ + // http://52.37.240.178:5000/api/image/src/json/cb2e67a4-7094-d971-c5c6-3b5bed251fec/ // making a decision to persist these upon creation... there was a conflict cuz loadByUuid above failed on subsequent // iterations and this was created multiple times before saving public static MediaAsset getMediaAssetFromIA(String maUUID, Shepherd myShepherd) { @@ -2741,7 +2148,7 @@ public static MediaAsset getMediaAssetFromIA(String maUUID, Shepherd myShepherd) file = ma.localPath().toFile(); File dir = file.getParentFile(); if (!dir.exists()) dir.mkdirs(); - // TODO we actually need to handle bad maUUID better. :( (returns + // we actually need to handle bad maUUID better. :( (returns RestClient.writeToFile(iaURL(context, "/api/image/src/json/" + maUUID + "/"), file); ma.copyIn(file); ma.addDerivationMethod("pulledFromIA", System.currentTimeMillis()); @@ -2850,8 +2257,7 @@ public static JSONObject mergeIAImageSet(String setId, Shepherd myShepherd) List auList = new ArrayList(); for (int j = 0; j < auuidSet.length(); j++) { /* critical here is that we only pass on (for assignment) annots which (a) are new from the set, or (b) we already have in wb. - not sure what to do of annotations we dont have yet -- they need their own encounters!! TODO FIXME we kind of decided ignore what - we dont have yet.... (?) i think. */ + not sure what to do of annotations we dont have yet -- they need their own encounters!! */ String u = fromFancyUUID(auuidSet.optJSONObject(j)); if (origAnnUUIDs.contains(u)) { auList.add(u); @@ -2907,7 +2313,7 @@ public static JSONObject mergeIAImageSet(String setId, Shepherd myShepherd) } if (addToOccurrence) { if (occ == null) { - // TODO should we allow recycling an existing Occurrence? (i.e. loading it here if it exists) + // should we allow recycling an existing Occurrence? (i.e. loading it here if it exists) occ = new Occurrence(setId, enc); } else { occ.addEncounter(enc); @@ -2978,14 +2384,7 @@ public static HashMap assignFromIA(String individualId, List 0) { Encounter newEnc = new Encounter(needEnc); -/* dont need this any more as annot already set times when passed to Encounter() constructor above! - DateTime dt = null; - try { - dt = iaDateTimeFromAnnotUUID(needEnc.get(0).getId()); - } catch (Exception ex) {} - if (dt != null) newEnc.setDateInMilliseconds(dt.getMillis()); - System.out.println(" ============ dt millis = " + dt); - */ + System.out.println("INFO: assignFromIA() created " + newEnc + " for " + needEnc.size() + " annots"); encs.add(newEnc); @@ -3080,21 +2479,9 @@ public static HashMap assignFromIANoCreation(String individualId } } } -/* going to NOT do this for now and just throw exception (above).... til we get a handle on how often this happens if (staying.size() == 0) { //we - dont need a new encounter; we just modify the indiv on here if (!encs.contains(enc)) encs.add(enc); - } else { //we need to split up the encounter, with a newer one that gets the new indiv id System.out.println("CRITICAL: - assignFromIANoCreation() " + enc + " requires split - staying=" + staying + "; going=" + going); - throw new RuntimeException("reassigning Annotation " + ann.getId() + " to " + individualId + " would cause split on Encounter " + - enc.getCatalogNumber()); - Encounter newEnc = enc.cloneWithoutAnnotations(); - System.out.println("INFO: assignFromIA() splitting " + enc + " - staying=" + staying + "; to " + newEnc + " going=" + going); - enc.setAnnotations(staying); - newEnc.setAnnotations(going); - encs.add(newEnc); - } - */ - // right now if we get to here, this enc is good to be reassigned ... TODO logic here will change a bit when handling splits better + + // right now if we get to here, this enc is good to be reassigned ... logic here will change a bit when handling splits better encs.add(enc); } System.out.println("assignFromIANoCreation() okay to reassign: " + encs); @@ -3228,9 +2615,7 @@ public static JSONObject arbitraryAnnotationsFromIA(JSONArray arg, Shepherd mySh return rtn; } -/* - these are mostly utility functions to fetch stuff from IA ... some of these may be unused currently but got made during chaostime - */ + // these are mostly utility functions to fetch stuff from IA ... some of these may be unused currently but got made during chaostime public static JSONArray __iaAnnotationUUIDsFromIds(JSONArray aids, String context) throws RuntimeException, MalformedURLException, IOException, NoSuchAlgorithmException, InvalidKeyException { @@ -3242,7 +2627,7 @@ public static JSONArray __iaAnnotationUUIDsFromIds(JSONArray aids, String contex return rtn.getJSONArray("response"); } -// http://52.37.240.178:5000/api/annot/name/uuid/json/?annot_uuid_list=[{%22__UUID__%22:%22c368747b-a4a8-4f59-900d-a9a529c92bca%22}]&__format__=True + // http://52.37.240.178:5000/api/annot/name/uuid/json/?annot_uuid_list=[{%22__UUID__%22:%22c368747b-a4a8-4f59-900d-a9a529c92bca%22}]&__format__=True public static JSONArray iaAnnotationNameUUIDsFromUUIDs(JSONArray uuids, String context) throws RuntimeException, MalformedURLException, IOException, NoSuchAlgorithmException, InvalidKeyException { @@ -3254,7 +2639,7 @@ public static JSONArray iaAnnotationNameUUIDsFromUUIDs(JSONArray uuids, String c return rtn.getJSONArray("response"); } -// http://52.37.240.178:5000/api/annot/name/text/json/?annot_uuid_list=[{%22__UUID__%22:%22c368747b-a4a8-4f59-900d-a9a529c92bca%22}]&__format__=True + // http://52.37.240.178:5000/api/annot/name/text/json/?annot_uuid_list=[{%22__UUID__%22:%22c368747b-a4a8-4f59-900d-a9a529c92bca%22}]&__format__=True public static JSONArray iaAnnotationNamesFromUUIDs(JSONArray uuids, String context) throws RuntimeException, MalformedURLException, IOException, NoSuchAlgorithmException, InvalidKeyException { @@ -3288,7 +2673,7 @@ public static JSONArray __iaAnnotationNamesFromIds(JSONArray aids, String contex return rtn.getJSONArray("response"); } -// http://52.37.240.178:5000/api/name/annot/rowid/?nid_list=[5] + // http://52.37.240.178:5000/api/name/annot/rowid/?nid_list=[5] public static JSONArray ___iaAnnotationIdsFromNameIds(JSONArray nids, String context) throws RuntimeException, MalformedURLException, IOException, NoSuchAlgorithmException, InvalidKeyException { @@ -3300,7 +2685,7 @@ public static JSONArray ___iaAnnotationIdsFromNameIds(JSONArray nids, String con return rtn.getJSONArray("response"); } -// http://52.37.240.178:5000/api/name/annot/uuid/json/?name_uuid_list=[{%22__UUID__%22:%22302cc5dc-4028-490b-99ee-5dc1680d057e%22}]&__format__=True + // http://52.37.240.178:5000/api/name/annot/uuid/json/?name_uuid_list=[{%22__UUID__%22:%22302cc5dc-4028-490b-99ee-5dc1680d057e%22}]&__format__=True public static JSONArray iaAnnotationUUIDsFromNameUUIDs(JSONArray uuids, String context) throws RuntimeException, MalformedURLException, IOException, NoSuchAlgorithmException, InvalidKeyException { @@ -3312,7 +2697,7 @@ public static JSONArray iaAnnotationUUIDsFromNameUUIDs(JSONArray uuids, String c return rtn.getJSONArray("response"); } -// http://52.37.240.178:5000/api/name/text/?name_rowid_list=[5,21]&__format__=True + // http://52.37.240.178:5000/api/name/text/?name_rowid_list=[5,21]&__format__=True public static JSONArray __iaNamesFromNameIds(JSONArray nids, String context) throws RuntimeException, MalformedURLException, IOException, NoSuchAlgorithmException, InvalidKeyException { @@ -3324,7 +2709,7 @@ public static JSONArray __iaNamesFromNameIds(JSONArray nids, String context) return rtn.getJSONArray("response"); } -// http://52.37.240.178:5000/api/name/text/json/?name_uuid_list=[{%22__UUID__%22:%22302cc5dc-4028-490b-99ee-5dc1680d057e%22}]&__format__=True + // http://52.37.240.178:5000/api/name/text/json/?name_uuid_list=[{%22__UUID__%22:%22302cc5dc-4028-490b-99ee-5dc1680d057e%22}]&__format__=True public static JSONArray iaNamesFromNameUUIDs(JSONArray uuids, String context) throws RuntimeException, MalformedURLException, IOException, NoSuchAlgorithmException, InvalidKeyException { @@ -3336,7 +2721,7 @@ public static JSONArray iaNamesFromNameUUIDs(JSONArray uuids, String context) return rtn.getJSONArray("response"); } -// http://52.37.240.178:5000/api/annot/name/text/json/?annot_uuid_list=[{%22__UUID__%22:%20%22deee5d41-c264-4179-aa6c-5b735975cbc9%22}]&__format__=True + // http://52.37.240.178:5000/api/annot/name/text/json/?annot_uuid_list=[{%22__UUID__%22:%20%22deee5d41-c264-4179-aa6c-5b735975cbc9%22}]&__format__=True public static JSONArray iaNamesFromAnnotUUIDs(JSONArray auuids, String context) throws RuntimeException, MalformedURLException, IOException, NoSuchAlgorithmException, InvalidKeyException { @@ -3348,7 +2733,7 @@ public static JSONArray iaNamesFromAnnotUUIDs(JSONArray auuids, String context) return rtn.getJSONArray("response"); } -// http://52.37.240.178:5000/api/imageset/smart/xml/file/content/?imageset_rowid_list=[65] + // http://52.37.240.178:5000/api/imageset/smart/xml/file/content/?imageset_rowid_list=[65] public static String iaSmartXmlFromSetId(int setId, String context) throws RuntimeException, MalformedURLException, IOException, NoSuchAlgorithmException, InvalidKeyException { @@ -3360,7 +2745,7 @@ public static String iaSmartXmlFromSetId(int setId, String context) return rtn.getJSONArray("response").optString(0, null); } -// http://52.37.240.178:5000/api/imageset/smart/waypoint/?imageset_rowid_list=[55] + // http://52.37.240.178:5000/api/imageset/smart/waypoint/?imageset_rowid_list=[55] public static int iaSmartXmlWaypointIdFromSetId(int setId, String context) throws RuntimeException, MalformedURLException, IOException, NoSuchAlgorithmException, InvalidKeyException { @@ -3401,7 +2786,7 @@ public static HashMap iaNameMapUUIDToString(JSONArray uuids, Str return map; } -// http://52.37.240.178:5000/api/imageset/uuid/?imgsetid_list=[3] + // http://52.37.240.178:5000/api/imageset/uuid/?imgsetid_list=[3] public static String iaImageSetUUIDFromId(int setId, String context) throws RuntimeException, MalformedURLException, IOException, NoSuchAlgorithmException, InvalidKeyException { @@ -3413,7 +2798,7 @@ public static String iaImageSetUUIDFromId(int setId, String context) return fromFancyUUID(rtn.getJSONArray("response").optJSONObject(0)); } -// http://52.37.240.178:5000/api/imageset/rowid/uuid/?uuid_list=[%7B%22__UUID__%22:%228e0850a7-7b29-4150-aedb-8bafb5149757%22%7D] + // http://52.37.240.178:5000/api/imageset/rowid/uuid/?uuid_list=[%7B%22__UUID__%22:%228e0850a7-7b29-4150-aedb-8bafb5149757%22%7D] public static int iaImageSetIdFromUUID(String uuid, String context) throws RuntimeException, MalformedURLException, IOException, NoSuchAlgorithmException, InvalidKeyException { @@ -3425,8 +2810,8 @@ public static int iaImageSetIdFromUUID(String uuid, String context) return rtn.getJSONArray("response").optInt(0, -1); } -// this --> is from annot uuid (note returns in seconds, not milli) -// http://52.37.240.178:5000/api/annot/image/unixtime/json/?annot_uuid_list=[{%22__UUID__%22:%20%22e95f6af3-4b7a-4d29-822f-5074d5d91c9c%22}] + // this --> is from annot uuid (note returns in seconds, not milli) + // http://52.37.240.178:5000/api/annot/image/unixtime/json/?annot_uuid_list=[{%22__UUID__%22:%20%22e95f6af3-4b7a-4d29-822f-5074d5d91c9c%22}] public static DateTime iaDateTimeFromAnnotUUID(String uuid, String context) throws RuntimeException, MalformedURLException, IOException, NoSuchAlgorithmException, InvalidKeyException { @@ -3440,7 +2825,7 @@ public static DateTime iaDateTimeFromAnnotUUID(String uuid, String context) return new DateTime(t * 1000); // IA returns secs not millisecs } -/// http://71.59.132.88:5007/api/annot/interest/json/?annot_uuid_list=[{"__UUID__":"8ddbb0fa-6eda-44ae-862a-c2ad333e7918"}] + // http://71.59.132.88:5007/api/annot/interest/json/?annot_uuid_list=[{"__UUID__":"8ddbb0fa-6eda-44ae-862a-c2ad333e7918"}] public static Boolean iaIsOfInterestFromAnnotUUID(String uuid, String context) throws RuntimeException, MalformedURLException, IOException, NoSuchAlgorithmException, InvalidKeyException { @@ -3453,7 +2838,7 @@ public static Boolean iaIsOfInterestFromAnnotUUID(String uuid, String context) return rtn.getJSONArray("response").optBoolean(0); } -// http://52.37.240.178:5000/api/annot/image/gps/json/?annot_uuid_list=[{%22__UUID__%22:%20%22e95f6af3-4b7a-4d29-822f-5074d5d91c9c%22}] + // http://52.37.240.178:5000/api/annot/image/gps/json/?annot_uuid_list=[{%22__UUID__%22:%20%22e95f6af3-4b7a-4d29-822f-5074d5d91c9c%22}] public static Double[] iaLatLonFromAnnotUUID(String uuid, String context) throws RuntimeException, MalformedURLException, IOException, NoSuchAlgorithmException, InvalidKeyException { @@ -3467,7 +2852,7 @@ public static Double[] iaLatLonFromAnnotUUID(String uuid, String context) return new Double[] { ll.optDouble(0), ll.optDouble(1) }; } -// http://71.59.132.88:5005/api/annot/theta/json/?annot_uuid_list=[{%22__UUID__%22:%224ec2f978-cb4d-48f8-adaf-8eecca120285%22}] + // http://71.59.132.88:5005/api/annot/theta/json/?annot_uuid_list=[{%22__UUID__%22:%224ec2f978-cb4d-48f8-adaf-8eecca120285%22}] public static Double iaThetaFromAnnotUUID(String uuid, String context) throws RuntimeException, MalformedURLException, IOException, NoSuchAlgorithmException, InvalidKeyException { @@ -3479,7 +2864,7 @@ public static Double iaThetaFromAnnotUUID(String uuid, String context) return rtn.getJSONArray("response").optDouble(0, 0.0); } -// http://52.37.240.178:5000/api/image/lat/json/?image_uuid_list=[{%22__UUID__%22:%22e985b3d4-bb2a-8291-07af-1ec4028d4649%22}] + // http://52.37.240.178:5000/api/image/lat/json/?image_uuid_list=[{%22__UUID__%22:%22e985b3d4-bb2a-8291-07af-1ec4028d4649%22}] public static Double[] iaLatLonFromImageUUID(String uuid, String context) throws RuntimeException, MalformedURLException, IOException, NoSuchAlgorithmException, InvalidKeyException { @@ -3500,7 +2885,7 @@ public static Double[] iaLatLonFromImageUUID(String uuid, String context) return new Double[] { lat, lon }; } -// http://52.37.240.178:5000/api/image/unixtime/json/?image_uuid_list=[{%22__UUID__%22:%22cb2e67a4-7094-d971-c5c6-3b5bed251fec%22}] + // http://52.37.240.178:5000/api/image/unixtime/json/?image_uuid_list=[{%22__UUID__%22:%22cb2e67a4-7094-d971-c5c6-3b5bed251fec%22}] public static DateTime iaDateTimeFromImageUUID(String uuid, String context) throws RuntimeException, MalformedURLException, IOException, NoSuchAlgorithmException, InvalidKeyException { @@ -3514,18 +2899,9 @@ public static DateTime iaDateTimeFromImageUUID(String uuid, String context) return new DateTime(t * 1000); // IA returns secs not millisecs } -// http://52.37.240.178:5000/api/name/sex/json/?name_uuid_list=[{%22__UUID__%22:%22302cc5dc-4028-490b-99ee-5dc1680d057e%22}]&__format__=True -/* - public static String iaSexFromName(String name) throws RuntimeException, MalformedURLException, IOException, NoSuchAlgorithmException, - InvalidKeyException { - JSONObject rtn = RestClient.get(iaURL("context0", "/api/annot/image/unixtime/json/?annot_uuid_list=[" + toFancyUUID(uuid) + "]")); - if ((rtn == null) || (rtn.optJSONArray("response") == null)) throw new RuntimeException("could not get unixtime from annot uuid=" + uuid); - long t = rtn.getJSONArray("response").optLong(0, -1); - if (t == -1) return null; - return null; - } - */ -// http://52.37.240.178:5000/api/annot/sex/json/?annot_uuid_list=[{%22__UUID__%22:%224517636f-65ad-a236-950c-107f2c962c19%22}] + // http://52.37.240.178:5000/api/name/sex/json/?name_uuid_list=[{%22__UUID__%22:%22302cc5dc-4028-490b-99ee-5dc1680d057e%22}]&__format__=True + + // http://52.37.240.178:5000/api/annot/sex/json/?annot_uuid_list=[{%22__UUID__%22:%224517636f-65ad-a236-950c-107f2c962c19%22}] public static String iaSexFromAnnotUUID(String uuid, String context) throws RuntimeException, MalformedURLException, IOException, NoSuchAlgorithmException, InvalidKeyException { @@ -3553,7 +2929,7 @@ public static String iaSexFromAnnotUUID(String uuid, String context) public static JSONObject iaViewpointFromAnnotUUID(String uuid, String context) throws RuntimeException, MalformedURLException, IOException, NoSuchAlgorithmException, InvalidKeyException { - String algo = IA.getProperty(context, "labelerAlgo"); // TODO handle the taxonomy-flavor of these + String algo = IA.getProperty(context, "labelerAlgo"); // TODO: handle the taxonomy-flavor of these String tag = IA.getProperty(context, "labelerModelTag"); if ((algo == null) || (tag == null)) @@ -3665,7 +3041,7 @@ public static Double iaAgeFromAnnotUUID(String uuid, String context) // NOTE! this is in months. UNSURE what **unit** Encounter.age is meant to be! storing value as-is (months) FIXME Double min = rtn.getJSONArray("response").getJSONArray(0).optDouble(0, -1.0); Double max = rtn.getJSONArray("response").getJSONArray(0).optDouble(1, -1.0); - if (max != -1.0D) { // we basically favor max (if both min and max are set) TODO kosher??? we could average + if (max != -1.0D) { // we basically favor max (if both min and max are set) kosher??? we could average return max; } else if (min != -1.0D) { return min; @@ -3725,20 +3101,10 @@ public static JSONObject iaStatus(HttpServletRequest request) { URL iau = iaURL(context, ""); rtn.put("iaURL", iau.toString()); rtn.put("iaEnabled", true); -/* turns out this is kinda crazy expensive on the IA side! so we certainly dont want to do this unless we really need to. - try { - // these 2 seem borked - //JSONObject rtn = RestClient.get(iaURL("context0", "/api/core/version/") - //JSONObject rtn = RestClient.get(iaURL("context0", "/api/core/db/version/") JSONObject r = RestClient.get(iaURL("context0", - "/api/core/db/name/")); - if ((r != null) && (r.optString("response", null) != null)) rtn.put("iaDbName", r.getString("response")); - r = RestClient.get(iaURL("context0", "/api/core/db/info/")); - if ((r != null) && (r.optString("response", null) != null)) rtn.put("iaDbInfo", r.getString("response")); - } catch (Exception ex) {} - */ + } rtn.put("timestamp", System.currentTimeMillis()); - JSONObject settings = new JSONObject(); // TODO this is just one, as a kind of sanity check/debugging -- sh/could expand to more if needed + JSONObject settings = new JSONObject(); settings.put("IBEISIARestUrlAddAnnotations", IA.getProperty(context, "IBEISIARestUrlAddAnnotations")); @@ -3757,7 +3123,7 @@ public static boolean unknownName(String name) { } /* - * DEPRECATED! see primeIA() instead This static method sends all annotations and media assets for a species in Wildbook to Image Analysis in + * TODO: evaluate as deprecated and remove. See primeIA() instead This static method sends all annotations and media assets for a species in Wildbook to Image Analysis in * preparation for future matching. It basically primes the system. */ public static JSONObject primeImageAnalysisForSpecies(ArrayList targetEncs, @@ -3787,40 +3153,13 @@ public static JSONObject primeImageAnalysisForSpecies(ArrayList targe if (ma != null) mas.add(ma); } } -/* - System.out.println("======= beginIdentify (qanns, tanns, allAnns) ====="); - System.out.println(qanns); - System.out.println(tanns); - System.out.println(allAnns); - */ + results.put("sendMediaAssets", sendMediaAssetsNew(mas, myShepherd.getContext())); results.put("sendAnnotations", sendAnnotationsNew(allAnns, myShepherd.getContext(), myShepherd)); // this should attempt to repair missing Annotations - /* - boolean tryAgain = true; - JSONObject identRtn = null; - while (tryAgain) { - identRtn = sendIdentify(qanns, tanns, baseUrl); - tryAgain = iaCheckMissing(identRtn); - } - results.put("sendIdentify", identRtn); - - - //if ((identRtn != null) && (identRtn.get("status") != null) && identRtn.get("status") //TODO check success == true :/ - //########## iaCheckMissing res -> {"response":[],"status":{"message":"","cache":-1,"code":200,"success":true}} - if ((identRtn != null) && identRtn.has("status") && identRtn.getJSONObject("status").getBoolean("success")) { - jobID = identRtn.get("response").toString(); - results.put("success", true); - } else { - System.out.println("beginIdentify() unsuccessful on sendIdentify(): " + identRtn); - results.put("error", identRtn.get("status")); - results.put("success", false); - } - */ - results.put("success", true); } catch (Exception ex) { // most likely from sendFoo() System.out.println( @@ -3838,34 +3177,7 @@ public static JSONObject primeImageAnalysisForSpecies(ArrayList targe return results; } -/* - status: { - _action: "getJobResult", _response: { - response: { - json_result: { - query_annot_uuid_list: [ - { - __UUID__: "ea272459-c82c-4f37-9800-045965fd1393" - } - ], query_config_dict: { }, inference_dict: { - annot_pair_dict: { - review_pair_list: [ - { - prior_matching_state: { - p_match: 0.9470680954707609, p_nomatch: 0.05293190452923913, p_notcomp: 0 - }, annot_uuid_2: { - __UUID__: "b889b610-55aa-4407-8b02-b5632839a201" - }, annot_uuid_1: { - __UUID__: "ea272459-c82c-4f37-9800-045965fd1393" - }, annot_uuid_key: { - __UUID__: "ea272459-c82c-4f37-9800-045965fd1393" - } - } - ], confidence_list: [ - 0.7994795279514134 - ] - }, - */ + // qid (query id) can be null, in which case the first one we find is good enough public static JSONArray simpleResultsFromAnnotPairDict(JSONObject apd, String qid) { if (apd == null) return null; @@ -3914,46 +3226,7 @@ private static String annotGetIndiv(Annotation ann, Shepherd myShepherd) { return id; } -/* - public static void primeIA() { - primeIA(ContextConfiguration.getDefaultContext()); - } - - public static void primeIA(final String context) { - setIAPrimed(false); - if (!iaEnabled()) return; - System.out.println("<<<<< BEFORE : " + isIAPrimed()); - System.out.println(" ............. alreadySentMA size = " + alreadySentMA.keySet().size()); - Runnable r = new Runnable() { - public void run() { - Shepherd myShepherd = new Shepherd(context); - myShepherd.setAction("IBEISIA.class.run"); - myShepherd.beginDBTransaction(); - ArrayList anns = Annotation.getMatchingSet(myShepherd); - System.out.println("-- priming IBEISIA (anns size: " + anns.size() + ")"); - ArrayList mas = new ArrayList(); - for (Annotation ann : anns) { - MediaAsset ma = ann.getDerivedMediaAsset(); - if (ma == null) ma = ann.getMediaAsset(); - if (ma != null) mas.add(ma); - } - try { - sendMediaAssets(mas, context); - sendAnnotations(anns, context); - } catch (Exception ex) { - System.out.println("!! IBEISIA.primeIA() failed: " + ex.toString()); - ex.printStackTrace(); - } - myShepherd.rollbackDBTransaction(); - myShepherd.closeDBTransaction(); - setIAPrimed(true); - System.out.println("-- priming IBEISIA **complete**"); - } - }; - new Thread(r).start(); - System.out.println(">>>>>> AFTER : " + isIAPrimed()); - } - */ + public static synchronized boolean isIAPrimed() { System.out.println(" ............. alreadySentMA size = " + alreadySentMA.keySet().size()); // return true; // uncomment this, comment-out below, to hard-skip iaPriming (has been useful on staging servers) @@ -3992,9 +3265,9 @@ public static String IAIntake(MediaAsset ma, Shepherd myShepherd, HttpServletReq public static String IAIntake(List mas, Shepherd myShepherd, HttpServletRequest request) throws ServletException, IOException { -// TODO support parent-task (eventually?) -// roughly IA.intake(MediaAsset) i hope... thus this does detection (returns taskId) -// superhactacular! now we piggyback on IAGateway which kinda does this. sorta. obvs this will come into IA.intake() ultimately no? + // support parent-task (eventually?) + // roughly IA.intake(MediaAsset) i hope... thus this does detection (returns taskId) + // superhactacular! now we piggyback on IAGateway which kinda does this. sorta. obvs this will come into IA.intake() ultimately no? String baseUrl = null; try { @@ -4033,34 +3306,9 @@ public static String _deprecated_IAIntake(Annotation ann, Shepherd myShepherd, S throws ServletException, IOException { System.out.println("* * * * * * * IAIntake(ident) NOT YET IMPLEMENTED ====> " + ann); return Util.generateUUID(); -////////// TODO how do we know when IA has auto-started identification when detection found an annotation??? -/* - String baseUrl = null; - try { - baseUrl = CommonConfiguration.getServerURL(request, request.getContextPath()); - } catch (java.net.URISyntaxException ex) {} - String context = ServletUtilities.getContext(request); - JSONObject jin = new JSONObject(); - JSONObject ja = new JSONObject(); - JSONArray jaids = new JSONArray(); - jaids.put(ann.getId()); - ja.put("annotationIds", jaids); - jin.put("identify", ja); - JSONObject res = new JSONObject(); - String taskId = Util.generateUUID(); - res.put("taskId", taskId); - org.ecocean.servlet.IAGateway._doIdentify(jin, res, myShepherd, context, baseUrl); - System.out.println("IAIntake(identify:" + ann + ") [taskId=" + taskId + "] -> " + res); - return taskId; - */ - } + // how do we know when IA has auto-started identification when detection found an annotation??? -/* - public static String IAIntake(List anns, Shepherd myShepherd, HttpServletRequest request) throws ServletException, IOException { - System.out.println("* * * * * * * IAIntake(ident) NOT YET IMPLEMENTED ====> " + ann); - return Util.generateUUID(); } - */ // this is called when a batch of encounters (which should be on this occurrence) were made from detection // *as a group* ... see also Encounter.detectedAnnotation() for the one-at-a-time equivalent @@ -4073,27 +3321,14 @@ public static void fromDetection(Occurrence occ, Shepherd myShepherd, String con public static JSONObject hashMapToJSONObject(HashMap map) { if (map == null) return null; return new JSONObject(map); // this *used to work*, i swear!!! -/* this will end me. -jon JSONObject rtn = new JSONObject(); - for (String k : map.keySet()) { - rtn.put(k, map.get(k)); - } - return rtn; - */ } public static JSONObject hashMapToJSONObject2(HashMap map) { // note: Object-flavoured if (map == null) return null; return new JSONObject(map); // this *used to work*, i swear!!! -/* - JSONObject rtn = new JSONObject(); - for (String k : map.keySet()) { - rtn.put(k, map.get(k)); - } - return rtn; - */ } - // TODO cache??? + // cache??? public static HashMap iaTaxonomyMap(Shepherd myShepherd) { String context = myShepherd.getContext(); HashMap map = new HashMap(); @@ -4227,12 +3462,6 @@ public static void callbackFromQueue(JSONObject qjob) { System.out.println("whoops got exception: " + ex.toString()); ex.printStackTrace(); } -/* - finally { - //myShepherd.rollbackDBTransaction(); - //myShepherd.closeDBTransaction(); - } - */ all.put("_timestamp", System.currentTimeMillis()); System.out.println( @@ -4358,7 +3587,7 @@ public static boolean validForIdentification(Annotation ann, String context) { return true; } - // FIXME this is likely deprecated as it uses the properties file rather than IA.json + // this is likely deprecated as it uses the properties file rather than IA.json public static ArrayList getAllIdentificationClasses(String context) { String className = ""; ArrayList allClasses = new ArrayList(); @@ -4382,7 +3611,7 @@ public static boolean taskParametersSkipIdent(Task task) { private static void resolveNames(ArrayList anns, JSONObject cmDict, Shepherd myShepherd) { -// TODO under development! +// under development! // cmDict has a structure like: { acmId1: { dname_list: [], dannot_uuid_list: [] } } .... um, i think? // resolveNames(anns, j.optJSONObject("cm_dict"), myShepherd); } @@ -4519,7 +3748,7 @@ public static Map iaSpeciesDiff(Shepherd myShepherd, boolean inc Map diff = new HashMap(); for (int i = 0; i < iaIds.size(); i++) { String ours = ourMap.get(iaIds.get(i)); - // TODO if this is null, i guess it means we have null species set *OR* we dont have that. should never be the latter? + // if this is null, i guess it means we have null species set *OR* we dont have that. should never be the latter? // ... either way, not going to tell IA to set to null, so.... (is this bad?) if (ours == null) continue; String ias = iaList.get(i); diff --git a/src/main/java/org/ecocean/importutils/RowFeedback.java b/src/main/java/org/ecocean/importutils/RowFeedback.java index c9e0401dde..35a82d034f 100644 --- a/src/main/java/org/ecocean/importutils/RowFeedback.java +++ b/src/main/java/org/ecocean/importutils/RowFeedback.java @@ -76,13 +76,12 @@ public void logParseError(int colNum, Object value, Row row, String exactMessage // if (!cellFeedback.isBlank()) { this.cells[colNum].setSuccess(false); this.cells[colNum].setIsBlank(false); - // TODO replace this universal NOT FOUND for an overwrite with something specific. + // TODO: replace this universally NOT FOUND for an overwrite with something specific. if (exactMessageToDisplay != null) { this.cells[colNum].setValueString(exactMessageToDisplay); } else { this.cells[colNum].setValueString(value + " NOT FOUND"); } - // } } else { System.out.println("Setting ERROR value on NEW CellFeedback for col " + colNum + " val " + String.valueOf(value) + " row " + row.getRowNum()); @@ -104,22 +103,3 @@ public int getColNum() { return this.num; } } - -// public String getStringNoLog(Row row, int i) { -// String str = null; -// try { -// str = row.getCell(i).getStringCellValue().trim(); -// if (str.equals("")) return null; -// } -// catch (Exception e) {} -// return str; -// } - -//// cannot put this inside CellFeedback bc java inner classes are not allowed static methods or vars (this is stupid). -// static String nullCellHtml() { -// return ""; -// } - -// } diff --git a/src/main/java/org/ecocean/media/AssetStore.java b/src/main/java/org/ecocean/media/AssetStore.java index 4fef7473a2..cea0a09fb9 100644 --- a/src/main/java/org/ecocean/media/AssetStore.java +++ b/src/main/java/org/ecocean/media/AssetStore.java @@ -62,9 +62,7 @@ public abstract class AssetStore implements java.io.Serializable { // probably also will be used to denote S3 temporary upload asset protected String usage; - /** - * Create a new AssetStore. - */ + // Create a new AssetStore. protected AssetStore(final Integer id, final String name, final AssetStoreType type, final AssetStoreConfig config, final boolean writable) { if (name == null) throw new IllegalArgumentException("null name"); @@ -133,9 +131,7 @@ public abstract boolean cacheLocal(MediaAsset ma, boolean force) public abstract URL webURL(MediaAsset ma); - public abstract String getFilename(MediaAsset ma); // this should be null if there is no such thing. "filename" is subjective here (e.g. youtube - - // id?) + public abstract String getFilename(MediaAsset ma); // this should be null if there is no such thing. "filename" is subjective here (e.g. youtube id?) // human-facing, "user-chosen" filename that may include complex characters like utf8 etc // defaults to just using getFilename() above, but can and should be overridden if applicable @@ -155,8 +151,7 @@ public DateTime getDateTime(MediaAsset ma) { return null; } - // these have to do with "child types" which are essentially derived MediaAssets ... much work TODO here -- including possibly making this its own - // class? + // these have to do with "child types" which are essentially derived MediaAssets. TODO: evaluate if this should be its own class // i am not making this an abstract now but rather subclass can override. maybe silly? future will decide // also, order matters here! should be from "best" to "worst" so that things can degrade nicely when better ones are not available public List allChildTypes() { @@ -197,13 +192,10 @@ public ArrayList findAll(String hashCode, Shepherd myShepherd) { try { Collection c = (Collection)(matches.execute()); all = new ArrayList(c); - // matches.closeAll(); - // return all; } catch (javax.jdo.JDOException ex) { System.out.println(this.toString() + " .findAll(" + hashCode + ") threw exception " + ex.toString()); ex.printStackTrace(); - // return null; } matches.closeAll(); return all; @@ -217,21 +209,19 @@ public MediaAsset findOrCreate(JSONObject params, Shepherd myShepherd) { } /* - hello! 2017-03-09 important paradigm shift here! now this no longer limiting search to parent-store. - (1) this "should be" backwards compatible; (2) we now have parent-child assets that cross store boundaries (YouTubeAssetStore / children) (3) - restricting to store is kinda silly cuz id is primary key so would never have duplicate id across more than one store anyway + this no longer limiting search to parent-store. + 1) this "should be" backwards compatible + 2) we now have parent-child assets that cross store boundaries (YouTubeAssetStore / children) + 3) restricting to store is kinda silly cuz id is primary key so would never have duplicate id across more than one store anyway */ public ArrayList findAllChildren(MediaAsset parent, Shepherd myShepherd) { if ((parent == null) || (parent.getId() < 1)) return null; ArrayList all = new ArrayList(); Extent mac = myShepherd.getPM().getExtent(MediaAsset.class, true); - // Query matches = myShepherd.getPM().newQuery(mac, "parentId == " + parent.getId() + " && this.store.id == " + this.id); Query matches = myShepherd.getPM().newQuery(mac, "parentId == " + parent.getId()); try { Collection c = (Collection)(matches.execute()); all = new ArrayList(c); - // matches.closeAll(); - // return all; } catch (javax.jdo.JDOException ex) { System.out.println(this.toString() + " .findAllChildren(" + parent.toString() + ") threw exception " + ex.toString()); @@ -276,7 +266,7 @@ public MediaAsset updateChild(MediaAsset parent, String type, HashMap params = " + params); width = (int)Math.round(params.optDouble("width", -1)); @@ -396,12 +377,10 @@ right now we only handle bbox (xywh) and transforms ... so we kinda get ugly her } System.out.println("AssetStore.updateChild(): " + sourceFile + " --> " + targetFile); -/* a quandry - i *think* "we all" (?) have generally agreed that a *new* MediaAsset should be created for each change in the contents of the source - file. - as such, finding an existing child MediaAsset of the type desired probably means it should either be deleted or orphaned ... or maybe simply marked - older? - in short: "revisioning". further, if the *parent has changed* should it also then not be a NEW MediaAsset itself anyway!? as such, we "should - never" be altering an existing child type on an existing parent. i think. ??? sigh.... not sure what TODO -jon */ + /* generally agreed that a *new* MediaAsset should be created for each change in the contents of the source file. + as such, finding an existing child MediaAsset of the type desired probably means it should either be deleted or orphaned ... or maybe simply marked older? + in short: "revisioning". further, if the *parent has changed* should it also then not be a NEW MediaAsset itself anyway!? as such, we "should + never" be altering an existing child type on an existing parent. */ ImageProcessor iproc = null; if (needsTransform) { @@ -424,11 +403,6 @@ right now we only handle bbox (xywh) and transforms ... so we kinda get ugly her return true; } -/* do we even want to allow this? - public MediaAsset create(String jsonString) { - } - */ - /** * Create a new asset from a File. The file is copied in to the store as part of this process. * @@ -464,8 +438,8 @@ protected abstract MediaAsset copyIn(final File file, final JSONObject params, */ public void copyAssetAny(final MediaAsset fromMA, final MediaAsset toMA) throws IOException { -// System.out.println("FROM " + fromMA); -// System.out.println("TO " + toMA); + // System.out.println("FROM " + fromMA); + // System.out.println("TO " + toMA); if (fromMA == null) throw new IOException("copyAssetAny(): fromMA is null"); if (toMA == null) throw new IOException("copyAssetAny(): toMA is null"); if (fromMA.getStore() == null) @@ -486,20 +460,6 @@ public abstract void copyAsset(final MediaAsset fromMA, final MediaAsset toMA) private void copyAssetAcross(final MediaAsset fromMA, final MediaAsset toMA) throws IOException { throw new IOException("copyAssetAcross() not yet implemented! :/"); -/* - //we basically always use a local version as the go-between... Path fromPath = null; - try { - fromMa.cacheLocal(); - fromPath = fromMa.localPath(); - } catch (Exception ex) { - throw new IOException("error creating local copy of " + fromMA.toString() + ": " + ex.toString()); - } - try { - toMA.copyIn(fromPath.toFile()); - } catch (Exception ex) { - throw new IOException("error copying to " + toMA.toString() + ": " + ex.toString()); - } - */ } /** @@ -534,36 +494,6 @@ public static AssetStore get(Shepherd myShepherd, int id) { return get(id); } -/* - public static AssetStore getByUsage(Shepherd myShepherd, String usage) { - if (usage == null) return null; - init(AssetStoreFactory.getStores(myShepherd)); - if ((stores == null) || (stores.size() < 1)) return null; - for (AssetStore st : stores.values()) { - if (usage.equals(st.getUsage())) return st; - } - return null; - } - */ - -/* - { - for (AssetStore store : getMap().values()) { - if (store.type == AssetStoreType.LOCAL) { - return store; - } - } - - // - // Otherwise return the first one in the map? - // - if (stores.values().iterator().hasNext()) { - return stores.values().iterator().next(); - } - - return null; - } - */ public static Map getStores() { return stores; } @@ -608,21 +538,11 @@ public String mediaAssetToHtmlElement(MediaAsset ma, HttpServletRequest request, if (url == null) return "
no webURL
"; -// TODO branch based upon permissions String more = ""; ArrayList kids = new ArrayList(); -// FOR NOW (TODO) we are disabling non-trivial annotations display, such is life? +// FOR NOW we are disabling non-trivial annotations display if ((ann != null) && !ann.isTrivial()) return ""; -/* - //for non-trivial annotations, lets try to find the - if ((ann != null) && !ann.isTrivial()) { - kids = ma.findChildrenByLabel(myShepherd, "_annotation"); - if ((kids != null) && (kids.size() > 0) && (kids.get(0).webURL() != null)) ma = kids.get(0); - url = ma.webURL(); - } - if (ann != null) more += " data-annotation-id=\"" + ann.getId() + "\" "; - */ String smallUrl = url.toString(); kids = ma.findChildrenByLabel(myShepherd, "_watermark"); @@ -692,7 +612,7 @@ public static JSONObject extractMetadataAttributes(File file) return j; } - /////////////// regarding pulling "useful" Metadata, see: https://github.com/drewnoakes/metadata-extractor/issues/10 + // regarding pulling "useful" Metadata, see: https://github.com/drewnoakes/metadata-extractor/issues/10 public static JSONObject extractMetadataExif(File file) throws IOException { Metadata md = null; @@ -745,9 +665,6 @@ public static boolean isValidImage(final File file) { System.out.println("WARNING: isValidImage(" + file + ") is truncated[1]"); return false; } else { - // no need to announce this in the logs - - // System.out.println("INFO: isValidImage(" + file + ") is valid JPEG"); return true; } } diff --git a/src/main/java/org/ecocean/media/AssetStoreFactory.java b/src/main/java/org/ecocean/media/AssetStoreFactory.java index 68f25537bc..37f4f1371a 100644 --- a/src/main/java/org/ecocean/media/AssetStoreFactory.java +++ b/src/main/java/org/ecocean/media/AssetStoreFactory.java @@ -12,13 +12,11 @@ public class AssetStoreFactory { private static Logger logger = LoggerFactory.getLogger(AssetStoreFactory.class); - ///////private static final String TABLENAME_ASSETSTORE = "assetstore"; - private AssetStoreFactory() { // do not instantiate } - // TODO this *should* make an attempt to put the "default" one first (or generally order it in a preferred way????) based on configuration + // Does not make an attempt to put the "default" one first (or generally order it in a preferred way????) based on configuration // this is because AssetStore.getDefault() currently uses the 0th element as default public static List getStores(final Shepherd myShepherd) { System.out.println("ASF.getStores() is called for shepherd w context " + @@ -66,62 +64,11 @@ public static List getStores2(final Shepherd myShepherd) { return s; } -/* - private static AssetStore buildAssetStore(final Integer id, final String name, final AssetStoreType type, final AssetStoreConfig config, final - boolean writable) - { - if (name == null) throw new IllegalArgumentException("null asset store name"); - if (type == null) throw new IllegalArgumentException("null asset store type"); - - switch (type) { - case LOCAL: - return new LocalAssetStore(id, name, config, writable); - default: - logger.error("Unhandled asset store type: " + type); - return null; - } - } - - */ public static void save(final AssetStore store) { } -/* - public static void save(final Database db, final AssetStore store) throws DatabaseException { - Table table = db.getTable(TABLENAME_ASSETSTORE); - - if (store.id == null) { - SqlInsertFormatter formatter = new SqlInsertFormatter(); - fillFormatter(formatter, store); - - store.id = table.insertSequencedRow(formatter, "id"); - - AssetStore.add(store); - } else { - SqlUpdateFormatter formatter = new SqlUpdateFormatter(); - fillFormatter(formatter, store); - - SqlWhereFormatter where = new SqlWhereFormatter(); - where.append("id", store.id); - table.updateRow(formatter.getUpdateClause(), where.getWhereClause()); - } - } - */ public static void delete(final AssetStore store) { AssetStore.remove(store); } -/* - public static void delete(final Database db, final AssetStore store) throws DatabaseException { - if (store.id == null) { - return; - } - - Table table = db.getTable(TABLENAME_ASSETSTORE); - - table.deleteRows("id = " + store.id); - - AssetStore.remove(store); - } - */ } diff --git a/src/main/java/org/ecocean/media/AssetStoreType.java b/src/main/java/org/ecocean/media/AssetStoreType.java index ccb695200d..73a1d7aeb8 100644 --- a/src/main/java/org/ecocean/media/AssetStoreType.java +++ b/src/main/java/org/ecocean/media/AssetStoreType.java @@ -5,5 +5,4 @@ */ public enum AssetStoreType { LOCAL, S3, URL, YouTube, Twitter - // TODO Azure, SCP... } diff --git a/src/main/java/org/ecocean/media/FeatureType.java b/src/main/java/org/ecocean/media/FeatureType.java index 70927c585f..4ee0416794 100644 --- a/src/main/java/org/ecocean/media/FeatureType.java +++ b/src/main/java/org/ecocean/media/FeatureType.java @@ -8,16 +8,14 @@ /** * A FeatureType (still under development) will be the unique identifier of the content type of a feature, such as "fluke trailing edge". Likely it - * should also include (as part of a compound id) a version as well, so changes to meanings can be reflected here. - * etc. TODO + * should also include (as part of a compound id) a version as well. */ public class FeatureType implements java.io.Serializable { static final long serialVersionUID = 8844233450443974780L; private static ArrayList allTypes; - protected String id = null; // TODO maybe should take on form of "org.ecocean.flukeTrailingEdge" or something? - + protected String id = null; protected String description = null; public FeatureType(final String id) { @@ -83,11 +81,6 @@ public static ArrayList initAll(Shepherd myShepherd) { public String toString() { return id; -/* - return new ToStringBuilder(this) - .append("id", id) - .toString(); - */ } private static void initializeFeatureTypes(Shepherd myShepherd) { diff --git a/src/main/java/org/ecocean/media/LocalAssetStore.java b/src/main/java/org/ecocean/media/LocalAssetStore.java index a3d771a410..c2bd24650c 100644 --- a/src/main/java/org/ecocean/media/LocalAssetStore.java +++ b/src/main/java/org/ecocean/media/LocalAssetStore.java @@ -107,11 +107,6 @@ public String webRoot() { Path subpath = pathFromParameters(params, false); // file can not exist (for sake of subsequent copyIn() being called) ... sorry? if (subpath == null) return null; -/* - Path root = root(); - Path subpath = ensurePath(root, path); - System.out.println("create() has subpath = " + subpath); - */ params.put("path", subpath.toString()); // always store it relative, not absolute try { return new MediaAsset(this, params); @@ -150,25 +145,15 @@ public Path pathFromParameters(JSONObject params, boolean checkExists) { if (params == null) throw new IllegalArgumentException("null path"); Object p = getParameter(params, "path"); if (p == null) { - // if ((params == null) || !params.has("path") || (params.get("path") == null)) { logger.warn("pathFromParameters(): Invalid parameters"); throw new IllegalArgumentException("null path"); } - // Path passed = Paths.get(params.getString("path")); Path passed = Paths.get(p.toString()); Path path = null; if (checkExists) { path = ensurePath(root(), passed); } else { path = checkPath(root(), passed); -/* - System.out.println("root = " + root); - System.out.println(params.getString("path") + " is .path"); - path = new File(params.getString("path")).toPath(); - System.out.println("path = " + path); - Path subpath = ensurePath(root, path); - System.out.println("subpath = " + subpath); - */ } return path; } @@ -179,8 +164,6 @@ public Path pathFromParameters(JSONObject params, boolean checkExists) { if (!this.writable) throw new IOException(this.name + " is a read-only AssetStore"); Path subpath = pathFromParameters(params); if (subpath == null) throw new IOException("no path passed in parameters"); - // Path root = root(); - // Path subpath = ensurePath(root, path); Path fullpath = root().resolve(subpath); fullpath.getParent().toFile().mkdirs(); logger.debug("copying from " + file + " to " + fullpath); @@ -199,11 +182,11 @@ public Path pathFromParameters(JSONObject params, boolean checkExists) { !(toMA.getStore() instanceof LocalAssetStore)) throw new IOException("invalid AssetStore type(s)"); if (!this.writable) throw new IOException(this.name + " is a read-only AssetStore"); - throw new IOException("oops, LocalAssetStore.copyAsset() still not implemented. :/"); // TODO + throw new IOException("oops, LocalAssetStore.copyAsset() still not implemented. :/"); } @Override public void deleteFrom(final MediaAsset ma) { - if (!this.contains(ma)) return; // TODO ?? exception + if (!this.contains(ma)) return; if (!this.writable) return; File file = localPath(ma).toFile(); System.out.println("LocalAssetStore attempting to delete file=" + file); @@ -211,14 +194,6 @@ public Path pathFromParameters(JSONObject params, boolean checkExists) { return; } file.delete(); - -/* TODO not sure if we should remove empty parent dirs? maybe some other spaghetti depends on it? - File parentDir = file.getParentFile(); - - File[] files = parentDir.listFiles(); - if (files == null || files.length == 0) { //some JVMs return null for empty dirs parentDir.delete(); - } - */ } /** diff --git a/src/main/java/org/ecocean/media/MediaAsset.java b/src/main/java/org/ecocean/media/MediaAsset.java index b6b4013ac9..8a0633c610 100644 --- a/src/main/java/org/ecocean/media/MediaAsset.java +++ b/src/main/java/org/ecocean/media/MediaAsset.java @@ -85,21 +85,6 @@ public class MediaAsset implements java.io.Serializable { private String correspondingSurveyTrackID; private String correspondingSurveyID; - - // protected MediaAssetType type; - // protected Integer submitterid; - - // protected Set tags; - // protected Integer rootId; - - // protected AssetStore thumbStore; - // protected Path thumbPath; - // protected Path midPath; - - // private LocalDateTime metaTimestamp; - // private Double metaLatitude; - // private Double metaLongitude; - private String acmId; private Boolean validImageForIA; @@ -107,12 +92,6 @@ public class MediaAsset implements java.io.Serializable { /** * To be called by AssetStore factory method. */ -/* - public MediaAsset(final AssetStore store, final JSONObject params, final String category) - { - this(MediaAssetFactory.NOT_SAVED, store, params, MediaAssetType.fromFilename(path.toString()), category); - } - */ public MediaAsset(final AssetStore store, final JSONObject params) { // this(store, params, null); @@ -375,7 +354,7 @@ public long setRevision() { public String setHashCode() { if (store == null) return null; this.hashCode = store.hashCode(getParameters()); -// System.out.println("hashCode on " + this + " = " + this.hashCode); + // System.out.println("hashCode on " + this + " = " + this.hashCode); return this.hashCode; } @@ -522,11 +501,8 @@ public void addToMetadata(String key, String value) { } /** - this function resolves (how???) various difference in "when" this image was taken. it might use different metadata (in EXIF etc) and/or - human-input (e.g. perhaps encounter data might trump it?) TODO wtf should we do? + this function resolves (how???) various difference in "when" this image was taken. it might use different metadata (in EXIF etc) and/or human-input FOR NOW: we rely first on (a) metadata.attributes.dateTime (as iso8601 string), then (b) crawl metadata.exif for something date-y - - TODO maybe someday this actually should be *only* punting to store.getDateTime() ???? */ public DateTime getDateTime() { if (this.userDateTime != null) return this.userDateTime; @@ -585,7 +561,6 @@ public void setUserLongitude(Double lon) { } // note: default behavior will add this to the features on this MediaAsset -- can pass false to disable - // TODO expand to handle things other than images (some day) public Feature generateUnityFeature() { return generateUnityFeature(true); } @@ -657,55 +632,6 @@ class AnnotationPositionalComparator implements Comparator { } } -/* - return annotations; - } - - //this will create the "trivial" Annotation (dimensions of the MediaAsset) iff no Annotations exist public ArrayList - getAnnotationsGenerate(String species) { - if (annotations == null) annotations = new ArrayList(); - if (annotations.size() < 1) addTrivialAnnotation(species); - return annotations; - } - - //TODO check if it is already here? maybe? - public Annotation addTrivialAnnotation(String species) { - Annotation ann = new Annotation(this, species); //this will add it to our .annotations collection as well String newId = - generateUUIDv3((byte)65, (byte)110); //set Annotation UUID relative to our ID An___ if (newId != null) ann.setId(newId); - return ann; - } - - public int getAnnotationCount() { - if (annotations == null) return 0; - return annotations.size(); - } - - public static MediaAsset findByAnnotation(Annotation annot, Shepherd myShepherd) { - String queryString = "SELECT FROM org.ecocean.media.MediaAsset WHERE annotations.contains(ann) && ann.id == \"" + annot.getId() + "\""; - Query query = myShepherd.getPM().newQuery(queryString); - List results = (List)query.execute(); - if (results.size() < 1) return null; - return (MediaAsset)results.get(0); - } - */ - -/* - public Path getThumbPath() - { - return thumbPath; - } - - public Path getMidPath() - { - return midPath; - } - */ - -/* - public MediaAssetType getType() { - return type; - } - */ /** * Return a full web-accessible url to the asset, or null if the asset is not web-accessible. NOTE: now you should *almost always* use .safeURL() @@ -727,12 +653,6 @@ public URL webURL() { return store.webURL(this); } -/* has been deprecated, cuz you should make a better choice about what you want the url of. see: safeURL() and friends public String webURLString() - { - return getUrlString(this.webURL()); - } - */ - // the primary purpose here is to mask (i.e. never send) the original (uploaded) image file. // right now "master" labelled image is used, if available, otherwise children are chosen by allChildTypes() order.... public URL safeURL(Shepherd myShepherd, HttpServletRequest request, String bestType) { @@ -791,10 +711,8 @@ public URL containerURLIfPresent() { public MediaAsset bestSafeAsset(Shepherd myShepherd, HttpServletRequest request, String bestType) { if (store == null) return null; - // this logic is simplistic now, but TODO make more complex (e.g. configurable) later.... - // TODO should be block "original" ??? is that overkill?? if (bestType == null) bestType = "master"; - // note, this next line means bestType may get bumped *up* for anon user.... so we should TODO some logic in there if ever needed + // note, this next line means bestType may get bumped *up* for anon user if (AccessControl.isAnonymous(request)) bestType = "mid"; if (store instanceof URLAssetStore) bestType = "original"; // this is cuz it is assumed to be a "public" url @@ -821,7 +739,7 @@ public MediaAsset bestSafeAsset(Shepherd myShepherd, HttpServletRequest request, if (t.equals(bestType)) gotBest = true; else gotBest = false; if (!gotBest) continue; // skip over any "better" types until we get to best we can use -// System.out.println(" .... ??? do we have a " + t); + // System.out.println(" .... ??? do we have a " + t); // now try to see if we have one! ArrayList kids = top.findChildrenByLabel(myShepherd, "_" + t); if ((kids != null) && (kids.size() > 0)) { @@ -840,97 +758,6 @@ public MediaAsset bestSafeAsset(Shepherd myShepherd) { return bestSafeAsset(myShepherd, null); } -/* - public String thumbWebPathString() { - return getUrlString(thumbWebPath()); - } - - public String midWebPathString() { - return getUrlString(midWebPath()); - } - - public URL thumbWebPath() { - return getUrl(thumbStore, thumbPath); - } - - public void setThumb(final AssetStore store, final Path path) - { - thumbStore = store; - thumbPath = path; - } - - public AssetStore getThumbstore() { - return thumbStore; - } - - public URL midWebPath() { - if (midPath == null) { - return webPath(); - } - - // - // Just use thumb store for now. - // - return getUrl(thumbStore, midPath); - } - - public void setMid(final Path path) { - // - // Just use thumb store for now. - // - this.midPath = path; - } - - */ - -/* - public Integer getSubmitterId() { - return submitterid; - } - - public void setSubmitterId(final Integer submitterid) { - this.submitterid = submitterid; - } - */ - -/* - public LocalDateTime getMetaTimestamp() { - return metaTimestamp; - } - - - public void setMetaTimestamp(LocalDateTime metaTimestamp) { - this.metaTimestamp = metaTimestamp; - } - - - public Double getMetaLatitude() { - return metaLatitude; - } - - - public void setMetaLatitude(Double metaLatitude) { - this.metaLatitude = metaLatitude; - } - - - public Double getMetaLongitude() { - return metaLongitude; - } - - - public void setMetaLongitude(Double metaLongitude) { - this.metaLongitude = metaLongitude; - } - */ - -/* - public void delete() { - MediaAssetFactory.delete(this.id); - MediaAssetFactory.deleteFromStore(this); - } - */ - // this takes contents of this MediaAsset and copies it to the target (note MediaAssets must exist with sufficient params already) // please note this uses *source* AssetStore for copying, which can/will affect how, for example, credentials in aws s3 are chosen. // for tighter control of this, you can call copyAsset() (or copyAssetAny()?) directly on desired store @@ -972,7 +799,7 @@ public org.datanucleus.api.rest.orgjson.JSONObject sanitizeJson(HttpServletReque return sanitizeJson(request, jobj, true, myShepherd); } - // fullAccess just gets cascaded down from Encounter -> Annotation -> us... not sure if it should win vs security(request) TODO + // fullAccess just gets cascaded down from Encounter -> Annotation -> us... not sure if it should win vs security(request) public org.datanucleus.api.rest.orgjson.JSONObject sanitizeJson(HttpServletRequest request, org.datanucleus.api.rest.orgjson.JSONObject jobj, boolean fullAccess, Shepherd myShepherd) throws org.datanucleus.api.rest.orgjson.JSONException { @@ -982,7 +809,6 @@ public org.datanucleus.api.rest.orgjson.JSONObject sanitizeJson(HttpServletReque jobj.remove("parametersAsString"); // jobj.put("guid", "http://" + CommonConfiguration.getURLLocation(request) + "/api/org.ecocean.media.MediaAsset/" + id); - // TODO something better with store? fix .put("store", store) ??? HashMap s = new HashMap(); s.put("type", store.getType().toString()); jobj.put("store", s); @@ -1200,7 +1026,7 @@ public ArrayList findChildrenByLabel(Shepherd myShepherd, String lab } // NOTE: these currrently do not recurse. this makes a big assumption that one only wants children of _original - // (e.g. on an encounter) and will *probably* need to change in the future. TODO? + // (e.g. on an encounter) and will *probably* need to change in the future. public static MediaAsset findOneByLabel(ArrayList mas, Shepherd myShepherd, String label) { ArrayList all = findAllByLabel(mas, myShepherd, label, true); @@ -1507,7 +1333,7 @@ public void setMetadata() } public MediaAssetMetadata updateMetadata() - throws IOException { // TODO should this overwrite existing, or append? + throws IOException { if (store == null) return null; metadata = store.extractMetadata(this); return metadata; @@ -1634,8 +1460,7 @@ public Boolean validateSourceImage() { encounter(s) made to hold them. this will be based on their sibling annots on this asset, among other things. note: current logic here ignores edge-case where annots may span multiple species. this is due in part to the fact that deriving species from - iaClass is a gray area in some wildbooks. this will need to be a future enhancement. TODO IAJsonProperties.taxonomyFromIAClass() may help - toward this end, but it is new and can give null results. + iaClass is a gray area in some wildbooks. this will need to be a future enhancement. */ public List assignEncounters(Shepherd myShepherd) { List newEncs = new ArrayList(); @@ -1687,7 +1512,7 @@ public List assignEncounters(Shepherd myShepherd) { try { IAJsonProperties iaJson = new IAJsonProperties(); whichever.setTaxonomy(iaJson.taxonomyFromIAClass(needsEncounter.get( - 0).getIAClass(), myShepherd)); // might work! + 0).getIAClass(), myShepherd)); } catch (Exception ex) { System.out.println( "INFO: assignEncounters() could not load iaJson, so could not deduce taxonomy for " diff --git a/src/main/java/org/ecocean/media/MediaAssetFactory.java b/src/main/java/org/ecocean/media/MediaAssetFactory.java index 5c9432ccd5..48ba8dba1d 100644 --- a/src/main/java/org/ecocean/media/MediaAssetFactory.java +++ b/src/main/java/org/ecocean/media/MediaAssetFactory.java @@ -8,11 +8,6 @@ import org.ecocean.Util; public class MediaAssetFactory { - // private static final Logger logger = LoggerFactory.getLogger(MediaAssetFactory.class); - - // public static final String TABLENAME_MEDIAASSET = "mediaasset"; - // public static final String ALIAS_MEDIAASSET = "ma"; - // public static final String PK_MEDIAASSET = "id"; public static final int NOT_SAVED = -1; @@ -54,7 +49,7 @@ public static MediaAsset loadByUuid(final String uuid, Shepherd myShepherd) { // NOTE!!! acmId is NOT unique, so there could be more than one.... this will return "oldest" (order by revision) public static MediaAsset loadByAcmId(final String id, Shepherd myShepherd) { MediaAsset ma = null; - // if (!Util.isUUID(uuid)) return null; //TODO yes or no? + // if (!Util.isUUID(uuid)) return null; Query query = myShepherd.getPM().newQuery(MediaAsset.class); query.setFilter("acmId=='" + id + "'"); @@ -65,21 +60,6 @@ public static MediaAsset loadByAcmId(final String id, Shepherd myShepherd) { return ma; } -/* - public static MediaAsset load(final Database db, final long id) throws DatabaseException - { - SqlWhereFormatter where = new SqlWhereFormatter(); - where.append(PK_MEDIAASSET, id); - - Table table = db.getTable(TABLENAME_MEDIAASSET); - - RecordSet rs = table.getRecordSet(where.getWhereClause(), 1); - if (rs.next()) { - return valueOf(rs); - } - return null; - } - */ private static Path createPath(final String pathstr) { if (pathstr == null) { return null; @@ -96,7 +76,7 @@ public static void save(MediaAsset ma, Shepherd myShepherd) { "; parent MediaAsset object likely not yet persisted; aborting save"); } // ma.setRevision(); - // for some reason (!?) parameters are getting lost when saving... sigh. HACK for now... lookout. TODO + // for some reason (!?) parameters are getting lost when saving... sigh. HACK for now... lookout. ////JSONObject p = ma.getParameters(); myShepherd.getPM().makePersistent(ma); ////if (p != null) ma.setParameters(p); @@ -110,12 +90,6 @@ public static void save(MediaAsset ma, Shepherd myShepherd) { public static void delete(final int id) { } -/* - public static void delete(final Database db, final int id) throws DatabaseException { - Table table = db.getTable(TABLENAME_MEDIAASSET); - table.deleteRows("id = " + id); - } - */ public static void deleteFromStore(final MediaAsset ma) { ma.store.deleteFrom(ma); } diff --git a/src/main/java/org/ecocean/media/MediaAssetMetadata.java b/src/main/java/org/ecocean/media/MediaAssetMetadata.java index d3d9945738..8bffd8ee02 100644 --- a/src/main/java/org/ecocean/media/MediaAssetMetadata.java +++ b/src/main/java/org/ecocean/media/MediaAssetMetadata.java @@ -115,7 +115,6 @@ public DateTime getDateTime() { // we attempt to find "the most prevalant" one. ugh. give me a break. HashMap count = new HashMap(); SimpleDateFormat dateParser = new SimpleDateFormat("yyyy:MM:dd HH:mm:ss"); // note: exif doesnt carry tz :( - // TODO maybe? we could also try just yyyy:MM:dd which sometimes exists. sigh. (etc x infinity) for (String key : matches.keySet()) { String val = matches.get(key); DateTime dt = null; @@ -238,13 +237,4 @@ private Double _parseAltitude(String alt) { ?? */ -/* - public String toString() { - return new ToStringBuilder(this) - .append("id", id) - .append("rev", revision) - .append("type", type.toString()) - .toString(); - } - */ } diff --git a/src/main/java/org/ecocean/media/MediaAssetSet.java b/src/main/java/org/ecocean/media/MediaAssetSet.java index 2bc0aac72f..3f99a6ac6a 100644 --- a/src/main/java/org/ecocean/media/MediaAssetSet.java +++ b/src/main/java/org/ecocean/media/MediaAssetSet.java @@ -54,7 +54,6 @@ public void setStatus(String s) { public org.datanucleus.api.rest.orgjson.JSONObject sanitizeJson(HttpServletRequest request, org.datanucleus.api.rest.orgjson.JSONObject jobj) throws org.datanucleus.api.rest.orgjson.JSONException { - // TODO security check, duh jobj.put("id", id); jobj.put("timestamp", timestamp); if ((getMediaAssets() != null) && (getMediaAssets().size() > 0)) { diff --git a/src/main/java/org/ecocean/media/S3AssetStore.java b/src/main/java/org/ecocean/media/S3AssetStore.java index cbcc96af57..fe8b8caac1 100644 --- a/src/main/java/org/ecocean/media/S3AssetStore.java +++ b/src/main/java/org/ecocean/media/S3AssetStore.java @@ -1,3 +1,5 @@ +// TODO: evaluate for deprecation and removal as we do not support S3 specifically anymore + package org.ecocean.media; import static java.nio.file.StandardCopyOption.REPLACE_EXISTING; @@ -40,10 +42,8 @@ public class S3AssetStore extends AssetStore { org.ecocean.media.S3AssetStore.class); /** - For information on credentials used to access Amazon AWS S3, see: - https://docs.aws.amazon.com/AWSSdkDocsJava/latest/DeveloperGuide/credentials.html TODO possibly allow per-AssetStore or even per-MediaAsset - credentials. these should be passed by reference (e.g. dont store them in, for example, MediaAsset parameters) perhaps to Profile or some - properties etc? + possibly allow per-AssetStore or even per-MediaAsset credentials. these should be passed by reference + (e.g. dont store them in, for example, MediaAsset parameters) perhaps to Profile or some properties etc? */ AmazonS3 s3Client = null; @@ -91,7 +91,6 @@ public AmazonS3 getS3Client() { */ @Override public MediaAsset create(final JSONObject params) throws IllegalArgumentException { - // TODO sanity check of params? try { return new MediaAsset(this, params); } catch (IllegalArgumentException e) { @@ -103,7 +102,7 @@ public boolean cacheLocal(MediaAsset ma, boolean force) throws IOException { Path lpath = localPath(ma); - if (lpath == null) return false; // TODO or throw Exception? + if (lpath == null) return false; if (!force && Files.exists(lpath)) return true; // we assume if we have it, then we should be cool System.out.println("S3.cacheLocal() trying to write to " + lpath); S3Object s3obj = getS3Object(ma); @@ -139,7 +138,6 @@ public MediaAsset copyIn(final File file, final JSONObject params, throws IOException { if (!this.writable) throw new IOException(this.name + " is a read-only AssetStore"); if (!file.exists()) throw new IOException(file.toString() + " does not exist"); - // TODO handle > 5G files: https://docs.aws.amazon.com/AmazonS3/latest/dev/UploadingObjects.html if (file.length() > 5 * 1024 * 1024 * 1024) throw new IOException("S3AssetStore does not yet support file upload > 5G"); Object bp = getParameter(params, "bucket"); @@ -190,12 +188,6 @@ public void copyAsset(final MediaAsset fromMA, final MediaAsset toMA) getS3Client().deleteObject(new DeleteObjectRequest(bp.toString(), kp.toString())); } -/* - public File getFile(final Path path) { - return new File(root().toString(), path.toString()); - } - */ - /** * Return a full URL to the given MediaAsset, or null if the asset is not web-accessible. */ diff --git a/src/main/java/org/ecocean/media/TwitterAssetStore.java b/src/main/java/org/ecocean/media/TwitterAssetStore.java index af35b50098..2bdaddc061 100644 --- a/src/main/java/org/ecocean/media/TwitterAssetStore.java +++ b/src/main/java/org/ecocean/media/TwitterAssetStore.java @@ -1,3 +1,5 @@ +// TODO: Deprecate and remove as part of twitter bot deprecate + package org.ecocean.media; import java.io.File; @@ -12,10 +14,9 @@ import org.json.JSONObject; import twitter4j.Status; -/** +/* * NOTE TwitterAssetStore references MediaAssets that reside on Twitter; tweets and their media currently this is read-only but later could be writable * with an API key if needed? - * */ public class TwitterAssetStore extends AssetStore { private static final String METADATA_KEY_RAWJSON = "twitterRawJson"; @@ -80,7 +81,7 @@ public MediaAsset create(final String id, final String type) { } @Override public void deleteFrom(final MediaAsset ma) { - return; // TODO exception? + return; } @Override public URL webURL(final MediaAsset ma) { @@ -110,7 +111,6 @@ public MediaAsset create(final String id, final String type) { @Override public JSONObject createParameters(File file, String grouping) { JSONObject p = new JSONObject(); - // will we even ever need this for a read-only system??? TODO so returning empty [or should be null?] return p; } @@ -136,20 +136,6 @@ private static Long longIdFromParameters(JSONObject params) { } } -/* TODO not really sure what to do with updateChild() and friends here..... hmmmm... - presently opting to create these manually via entitiesAsMediaAssets() (which will utilize .parent property) - - public List allChildTypes() { - return Arrays.asList(new String[]{"entity"}); - } - //awkwardly named subset of the above which will be used to determine which should be derived with updateStandardChildren() public List - standardChildTypes() { - return Arrays.asList(new String[]{"entity"}); - } - public MediaAsset updateChild(MediaAsset parent, String type, HashMap opts) throws IOException { - } - */ - /* regarding media (etc) in tweets: seems .extended_entities.media is the same as .entities.media ??? but extended (duh?) might have more details? https://dev.twitter.com/overview/api/entities-in-twitter-objects https://dev.twitter.com/overview/api/entities */ @@ -182,35 +168,6 @@ public static List entitiesAsMediaAssets(MediaAsset ma) { return mas; } -/* remove? TODO public static List entitiesAsMediaAssetsGsonObj(MediaAsset ma, Long parentTweetId) { - JSONObject raw = getRawJSONObject(ma); - // System.out.println(raw.toString()); - AssetStore store = ma.getStore(); - if (raw == null) return null; - if ((raw.optJSONArray("extendedMediaEntities") == null)){ - System.out.println("aw.optJSONArray('extendedMediaEntities') is null"); - return null; - } - List mas = new ArrayList(); - JSONArray jarr = raw.getJSONArray("extendedMediaEntities"); - for (int i = 0 ; i < jarr.length() ; i++) { - JSONObject p = jarr.optJSONObject(i); - if (p == null) continue; - p.put("id", p.optString("id", null)); //squash the long id at "id" with string MediaAsset kid = store.create(p); - kid.addLabel("_entity"); - kid.addLabel("_parentTweet:" + Long.toString(parentTweetId)); - setEntityMetadata(kid); - kid.getMetadata().getDataAsString(); //TODO no idea what this does -MF kid.setParentId(ma.getId()); - //derivationMethods? metadata? (of image) etc.... ?? - mas.add(kid); - System.out.println("i is: " + Integer.toString(i)); - JSONObject test = TwitterUtil.toJSONObject(kid); - System.out.println(TwitterUtil.toJSONString(test)); - } - return mas; - } - */ - // this assumes we already set metadata public static JSONObject getRawJSONObject(MediaAsset ma) { if (ma == null) return null; @@ -233,37 +190,6 @@ public MediaAssetMetadata extractMetadata(MediaAsset ma, boolean minimal) return new MediaAssetMetadata(data); } -/* - public Long getParentTweetIdFromLabels(ArrayList labels) throws Exception{ - Long returnVal = null; - for(int i = 0; i grab(MediaAsset ma) // returns success (stuff grabbed and parsed) // 'wait' refers only for other process, if we need to do the grabbing, right now it will always wait for that - // NOTE: wait is untested! TODO + // NOTE: wait is untested! public static boolean grabAndParse(Shepherd myShepherd, MediaAsset ma, boolean wait) throws IOException { boolean processing = ((ma.getDerivationMethod() != null) && @@ -193,9 +193,9 @@ public static List extractFrames(MediaAsset ma) throw new IOException("deprecated"); } - // returns success (frames extracted) -- passed in parent/_original MA ... maybe later we would want to also allow _video child option? TODO + // returns success (frames extracted) -- passed in parent/_original MA ... maybe later we would want to also allow _video child option? // 'wait' refers only for other process, if we need to do the grabbing, right now it will always wait for that - // NOTE: wait is untested! TODO + // NOTE: wait is untested! // note that uses same _processing derivation method as .grabAndParse() above. this is cuz these should not be run simultaneous anyway public static boolean extractFramesAndParse(Shepherd myShepherd, MediaAsset ma, boolean wait) throws IOException { @@ -337,7 +337,7 @@ public MediaAssetMetadata extractMetadata(MediaAsset ma, boolean minimal) new JSONObject("{\"_processing\": true, \"timestamp\": " + System.currentTimeMillis() + "}")); // assume it will // be.... soon? - // TODO do actual grabAndProcess here??? + // do actual grabAndProcess here??? } return new MediaAssetMetadata(data); } @@ -356,7 +356,7 @@ public static YouTubeAssetStore find(Shepherd myShepherd) { note: this assumes the MediaAsset has been persisted, so we can create our own Shepherd object and affect it accordingly.... there are potentials for race conditions here for sure, especially if the caller has gone on to (or caused something to go on to) further alter the MediaAsset in memory etc. use caution! - TODO perhaps for this reason we should have a synchronous version of this too? + perhaps for this reason we should have a synchronous version of this too? */ public static void backgroundGrabAndParse(final MediaAsset otherMa, HttpServletRequest request) { diff --git a/src/main/java/org/ecocean/metrics/junit/TestJunit.java b/src/main/java/org/ecocean/metrics/junit/TestJunit.java index 9de112a633..cf0d8bae87 100644 --- a/src/main/java/org/ecocean/metrics/junit/TestJunit.java +++ b/src/main/java/org/ecocean/metrics/junit/TestJunit.java @@ -35,31 +35,6 @@ public class TestJunit { this.wLogin = 22; this.woLogin = 9; this.encsInWildbook = 32; - // TODO: FIGURE THIS OUT - // Read input from file (cannot find file for some reason) - // File myFile = new File("databaseDump.txt"); - // Scanner sc = new Scanner(myFile); - // boolean reachedUserSection = false; - - // while(sc.hasNextLine()) - // { - // if(reachedUserSection) - // { - // try - // { - // this.usersInWildbook = Integer.parseInt(sc.nextLine()); - // this.wLogin = Integer.parseInt(sc.nextLine()); - // this.woLogin = Integer.parseInt(sc.nextLine()); - // } - // catch(Exception e) {} - // reachedUserSection = false; - // } - // else if(sc.hasNext("NumberOfUsers")) - // { - // reachedUserSection = true; - // } - // sc.nextLine(); - // } } @Test public void testPrintMessage() { @@ -67,24 +42,9 @@ public class TestJunit { } @Test public void testSetNumberOfUsers() { - // this.myShepherd.beginDBTransaction(); - // run method - // this.promObject.setNumberOfUsers(); - // int s = this.myShepherd.getNumUsers(); - // assertEquals((int) this.promObject.numUsersInWildbook.get(), this.usersInWildbook); - // assertEquals((int) this.promObject.numUsersWithLogin.get(), this.wLogin); - // assertEquals((int) this.promObject.numUsersWithoutLogin.get(), this.woLogin); - // TODO: get active users metric is pending - - // this.myShepherd.closeDBTransaction(); } @Test public void testSetNumberOfEncounters() { - // this.myShepherd.closeDBTransaction(); - // this.promObject.setNumberOfEncounters(); - // assertEquals((int) this.promObject.encs.get(), this.encsInWildbook); - // TODO: The rest of the metrics for this method - // this.myShepherd.closeDBTransaction(); } @Test public void testSetNumberOfIndividuals() { diff --git a/src/main/java/org/ecocean/mmutil/DataUtilities.java b/src/main/java/org/ecocean/mmutil/DataUtilities.java index 2159a42b48..b120f44766 100644 --- a/src/main/java/org/ecocean/mmutil/DataUtilities.java +++ b/src/main/java/org/ecocean/mmutil/DataUtilities.java @@ -12,7 +12,7 @@ public class DataUtilities { private DataUtilities() {} /** - * Creates a unique ID string for encounters. Unique to millisecond precision. TODO: Further improve UID generation algorithm (UUID class?) + * Creates a unique ID string for encounters. Unique to millisecond precision. * @return unique ID string */ public static String createUniqueId() { diff --git a/src/main/java/org/ecocean/mmutil/MMAResultsProcessor.java b/src/main/java/org/ecocean/mmutil/MMAResultsProcessor.java index c2cbe0ad78..c07bac9612 100644 --- a/src/main/java/org/ecocean/mmutil/MMAResultsProcessor.java +++ b/src/main/java/org/ecocean/mmutil/MMAResultsProcessor.java @@ -241,7 +241,6 @@ private static void parseMatchResultsHeader(Shepherd shepherd, MMAResult result, */ private static void parseMatchResultsSummary(Shepherd shepherd, MMAResult result, String text) throws ParseException { - // TODO: implement } /** diff --git a/src/main/java/org/ecocean/opendata/OBISSeamap.java b/src/main/java/org/ecocean/opendata/OBISSeamap.java index 78cb58a755..b45b7f4807 100644 --- a/src/main/java/org/ecocean/opendata/OBISSeamap.java +++ b/src/main/java/org/ecocean/opendata/OBISSeamap.java @@ -32,7 +32,6 @@ public void init() { // do these once to get into cache getCollaborationUser(); getShareAll(); - // TODO support organizationId (when Organization makes it to master!) } public void generate() @@ -195,7 +194,7 @@ public String tabRow(Encounter enc, Shepherd myShepherd) { fields.add(forceString(enc.getIndividualID())); fields.add(forceString(enc.getSex())); fields.add(forceString(enc.getLifeStage())); - //////fields.add("1"); //for encounter, always just one individual + // fields.add("1"); //for encounter, always just one individual ArrayList mas = enc.getMedia(); if ((mas == null) || (mas.size() < 1)) { fields.add(""); diff --git a/src/main/java/org/ecocean/queue/FileQueue.java b/src/main/java/org/ecocean/queue/FileQueue.java index 594fb2ea8d..81792697e0 100644 --- a/src/main/java/org/ecocean/queue/FileQueue.java +++ b/src/main/java/org/ecocean/queue/FileQueue.java @@ -25,7 +25,7 @@ public class FileQueue extends Queue { private File queueDir = null; public static boolean isAvailable(String context) { - return true; // TODO until we come up with a scenario where it wont work? + return true; } public FileQueue(final String name) @@ -34,7 +34,7 @@ public FileQueue(final String name) if (queueBaseDir == null) throw new IOException("FileQueue.init() has not yet been called!"); this.type = TYPE_NAME; - queueDir = new File(queueBaseDir, name); // TODO scrub name of invalid chars + queueDir = new File(queueBaseDir, name); if (!queueDir.exists() || !queueDir.isDirectory()) { boolean ok = queueDir.mkdirs(); if (!ok) throw new IOException("FileQueue failed to create " + queueDir.toString()); @@ -55,7 +55,6 @@ public static synchronized File setQueueDir(String context) String qd = Queue.getProperty(context, "filequeue_basedir"); if (qd == null) qd = CommonConfiguration.getProperty("ScheduledQueueDir", "context0"); // legacy if (qd == null) { // lets try to make one *somewhere* - // queueBaseDir = Files.createTempDirectory("WildbookFileQueue").toFile(); queueBaseDir = new File("/tmp/WildbookFileQueue"); System.out.println("INFO: default (temporary) queueBaseDir being used: " + queueBaseDir); @@ -95,13 +94,11 @@ public String getNext() if (activeFile.exists()) { System.out.println("WARNING: " + this.toString() + " wanted to create " + activeFile.toString() + " but it exists; skipping"); - // TODO keep a count maybe then skip over for real after N tries? something like that.... return null; } if (!nextFile.renameTo(activeFile)) { System.out.println("WARNING: " + this.toString() + " wanted to create " + activeFile.toString() + " but rename failed; skipping"); - // TODO ditto above comment return null; } System.out.println("INFO: " + this.toString() + " successfully engaged file " + @@ -120,13 +117,11 @@ public String getNext() if (completedFile.exists()) { System.out.println("WARNING: " + this.toString() + " wanted to create " + completedFile.toString() + " but it exists; skipping"); - // TODO ditto return null; } if (!activeFile.renameTo(completedFile)) { System.out.println("WARNING: " + this.toString() + " wanted to create " + completedFile.toString() + " but rename failed; skipping"); - // TODO ditto return null; } if (this.isConsumerShutdownMessage(fcontents)) diff --git a/src/main/java/org/ecocean/queue/QueueUtil.java b/src/main/java/org/ecocean/queue/QueueUtil.java index 11267c5ceb..4ef2f46219 100644 --- a/src/main/java/org/ecocean/queue/QueueUtil.java +++ b/src/main/java/org/ecocean/queue/QueueUtil.java @@ -57,15 +57,14 @@ public void run() { ioex.toString()); } } -//////System.out.println("count=" + count + "; handled-ok=" + ok + "; cont=" + cont + "; msg=" + message); - ////TODO what does !ok mean for us here???? we dont really have ACK like rabbitmq.... so... ???? +// System.out.println("count=" + count + "; handled-ok=" + ok + "; cont=" + cont + "; msg=" + message); if (!cont) { System.out.println(":::: " + queue.toString() + " shutdown via discontinue signal ::::"); schedExec.shutdown(); } } - }, 1, // initial delay ... TODO these could be configurable, obvs + }, 1, // initial delay 1, // period delay *after* execution finishes TimeUnit.SECONDS); diff --git a/src/main/java/org/ecocean/queue/RabbitMQQueue.java b/src/main/java/org/ecocean/queue/RabbitMQQueue.java index 0892d71777..2cba2be424 100644 --- a/src/main/java/org/ecocean/queue/RabbitMQQueue.java +++ b/src/main/java/org/ecocean/queue/RabbitMQQueue.java @@ -81,8 +81,6 @@ public Channel getChannel() public void publish(String msg) throws java.io.IOException { -// TODO check connection *and* channel?? - // channel.basicPublish(EXCHANGE_NAME, ROUTING_KEY, null, msg.getBytes()); channel.basicPublish(EXCHANGE_NAME, this.queueName, null, msg.getBytes()); System.out.println("[INFO] " + this.toString() + " published to {" + this.queueName + "}: " + msg); diff --git a/src/main/java/org/ecocean/resumableupload/UploadServlet.java b/src/main/java/org/ecocean/resumableupload/UploadServlet.java index d68332c60c..90226aba08 100644 --- a/src/main/java/org/ecocean/resumableupload/UploadServlet.java +++ b/src/main/java/org/ecocean/resumableupload/UploadServlet.java @@ -28,17 +28,11 @@ import org.ecocean.servlet.ServletUtilities; import org.ecocean.Shepherd; -/** - * - * This is a servlet demo, for using Flow.js to upload files. - * - * by fanxu123 - */ public class UploadServlet extends HttpServlet { private static final long serialVersionUID = 1L; /* - * In ORDER to allow CORS to multiple domains you can set a list of valid domains here + * In ORDER to allow CORS to multiple domains you can set a list of valid domains here */ private List authorizedUrl = Arrays.asList("http://localhost", "http://example.com"); @@ -70,7 +64,6 @@ public void doOptions(HttpServletRequest request, HttpServletResponse response) if (request.getHeader("Access-Control-Request-Headers") != null) response.setHeader("Access-Control-Allow-Headers", request.getHeader("Access-Control-Request-Headers")); - // response.setContentType("text/plain"); } protected void doPost(HttpServletRequest request, HttpServletResponse response) @@ -81,7 +74,6 @@ protected void doPost(HttpServletRequest request, HttpServletResponse response) if (!ServletFileUpload.isMultipartContent(request)) throw new IOException("doPost is not multipart"); ServletFileUpload upload = new ServletFileUpload(new DiskFileItemFactory()); - // upload.setHeaderEncoding("UTF-8"); List multiparts = null; try { multiparts = upload.parseRequest(request); @@ -113,7 +105,6 @@ protected void doPost(HttpServletRequest request, HttpServletResponse response) response.setHeader("Expires", "-1"); response.setHeader("Access-Control-Allow-Origin", "*"); // allow us stuff from localhost - // response.setHeader("Access-Control-Allow-Origin", getOriginDomain(request)); response.setHeader("Access-Control-Allow-Credentials", "true"); response.setHeader("Access-Control-Allow-Methods", "POST"); response.setHeader("Access-Control-Allow-Headers", "Content-Type"); @@ -130,10 +121,8 @@ protected void doPost(HttpServletRequest request, HttpServletResponse response) raf.seek((flowChunkNumber - 1) * info.flowChunkSize); // Save to file - // InputStream is = request.getInputStream(); InputStream is = fileChunk.getInputStream(); long readed = 0; - // long content_length = request.getContentLength(); long content_length = fileChunk.getSize(); byte[] bytes = new byte[1024 * 100]; while (readed < content_length) { @@ -149,8 +138,7 @@ protected void doPost(HttpServletRequest request, HttpServletResponse response) // Mark as uploaded. info.uploadedChunks.add(new FlowInfo.flowChunkNumber(flowChunkNumber)); String archivoFinal = info.checkIfUploadFinished(); - if (archivoFinal != null) { // Check if all chunks uploaded, and - // change filename + if (archivoFinal != null) { // Check if all chunks uploaded, and change filename FlowInfoStorage.getInstance().remove(info); response.getWriter().print("{\"success\": true, \"uploadComplete\": true}"); } else { @@ -163,7 +151,7 @@ protected void doPost(HttpServletRequest request, HttpServletResponse response) out.close(); } -/* UGH TODO i think doGet is broken, so best skip testChunk with testChunks: false essentially, i doubt GET will be multipart -- so we need to also +/* TODO: verifiy doGet works. skip testChunk with testChunks: false essentially, i doubt GET will be multipart -- so we need to also support that, esp getflowChunkNumber() and getFlowInfo() ... :( */ protected void doGet(HttpServletRequest request, HttpServletResponse response) @@ -190,7 +178,6 @@ protected void doGet(HttpServletRequest request, HttpServletResponse response) response.setHeader("Pragma", "no-cache"); response.setHeader("Expires", "-1"); - // response.setHeader("Access-Control-Allow-Origin", getOriginDomain(request)); response.setHeader("Access-Control-Allow-Origin", "*"); // allow us stuff from localhost response.setHeader("Access-Control-Allow-Methods", "GET"); response.setHeader("Access-Control-Allow-Credentials", "true"); @@ -204,8 +191,7 @@ protected void doGet(HttpServletRequest request, HttpServletResponse response) Object fcn = new FlowInfo.flowChunkNumber(flowChunkNumber); if (info.uploadedChunks.contains(fcn)) { System.out.println("Do Get arriba"); - response.getWriter().print("Uploaded."); // This Chunk has been - // Uploaded. + response.getWriter().print("Uploaded."); // This Chunk has been Uploaded. } else { System.out.println("Do Get something is wrong"); response.setStatus(HttpServletResponse.SC_NOT_FOUND); diff --git a/src/main/java/org/ecocean/security/Collaboration.java b/src/main/java/org/ecocean/security/Collaboration.java index 5c959c0e9c..f65324bf8a 100644 --- a/src/main/java/org/ecocean/security/Collaboration.java +++ b/src/main/java/org/ecocean/security/Collaboration.java @@ -37,7 +37,6 @@ public class Collaboration implements java.io.Serializable { // JDOQL required empty instantiator public Collaboration() {} -////////////////TODO prevent duplicates public Collaboration(String username1, String username2) { this.setUsername1(username1); this.setUsername2(username2); @@ -127,12 +126,9 @@ public void setId() { } } -// TODO this should do other steps? maybe? like notify user?? // NOTE the first user, by convention, is the initiator public static Collaboration create(String u1, String u2) { Collaboration c = new Collaboration(u1, u2); - - // storeNewCollaboration(Collaboration collab) { return c; } @@ -146,7 +142,7 @@ public static List collaborationsForCurrentUser(HttpServletReques String state) { String context = ServletUtilities.getContext(request); - if (request.getUserPrincipal() == null) return null; // TODO is this cool? + if (request.getUserPrincipal() == null) return null; // TODO: evaluate is this cool? String username = request.getUserPrincipal().getName(); return collaborationsForUser(context, username, state); } @@ -186,7 +182,7 @@ public static List collaborationsForUser(Shepherd myShepherd, Str @SuppressWarnings("unchecked") public static List collaborationsForUser( String context, String username, String state) { -// TODO cache!!! (may be hit a lot) +// TODO: implement cache as this may be hit a lot String queryString = "SELECT FROM org.ecocean.security.Collaboration WHERE ((username1 == '" + username + "') || (username2 == '" + username + "'))"; @@ -213,10 +209,6 @@ public static List collaborationsForUser(Shepherd myShepherd, Str return returnMe; } - // public static Collaboration collaborationBetweenUsers(User u1, User u2, String context) { - // return collaborationBetweenUsers(context, u1.getUsername(), u2.getUsername()); - // } - public static Collaboration collaborationBetweenUsers(Shepherd myShepherd, String u1, String u2) { return findCollaborationWithUser(u2, collaborationsForUser(myShepherd, u1)); @@ -272,9 +264,6 @@ public static Collaboration collaborationBetweenUsers(String username1, String u return ((Collaboration)results.get(0)); } - // public static Collaboration collaborationBetweenUsers(String context, String u1, String u2) { - // return findCollaborationWithUser(u2, collaborationsForUser(context, u1)); - // } public static boolean canCollaborate(User u1, User u2, String context) { if (u1.equals(u2)) return true; Collaboration c = collaborationBetweenUsers(u1, u2, context); @@ -285,7 +274,7 @@ public static boolean canCollaborate(User u1, User u2, String context) { } public static boolean canCollaborate(String context, String u1, String u2) { - if (User.isUsernameAnonymous(u1) || User.isUsernameAnonymous(u2)) return true; // TODO not sure??? + if (User.isUsernameAnonymous(u1) || User.isUsernameAnonymous(u2)) return true; if (u1.equals(u2)) return true; Collaboration c = collaborationBetweenUsers(u1, u2, context); // System.out.println("canCollaborate(String context, String u1, String u2)"); @@ -388,7 +377,7 @@ public static boolean securityEnabled(String context) { // "View" means "you can see that the data exists but may not necessarily access the data" public static boolean canUserViewOwnedObject(String ownerName, HttpServletRequest request, Shepherd myShepherd) { - if (request.isUserInRole("admin")) return true; // TODO generalize and/or allow other roles all-access + if (request.isUserInRole("admin")) return true; if (ownerName == null || request.isUserInRole("admin")) return true; User viewer = myShepherd.getUser(request); User owner = myShepherd.getUser(ownerName); @@ -399,10 +388,7 @@ public static boolean canUserViewOwnedObject(User viewer, User owner, HttpServletRequest request) { // if they own it if (viewer != null && owner != null && viewer.getUUID() != null && - viewer.getUUID().equals(owner.getUUID())) return true; // should really - // be user - // .equals() - // method + viewer.getUUID().equals(owner.getUUID())) return true; // should really be user .equals() method // if viewer and owner have sharing turned on if (((viewer != null && viewer.hasSharing() && (owner == null || owner.hasSharing())))) return true; // just based on sharing @@ -414,7 +400,7 @@ public static boolean canUserAccessOwnedObject(String ownerName, HttpServletRequ String context = ServletUtilities.getContext(request); if (!securityEnabled(context)) return true; - if (request.isUserInRole("admin")) return true; // TODO generalize and/or allow other roles all-access + if (request.isUserInRole("admin")) return true; if (User.isUsernameAnonymous(ownerName)) return true; // anon-owned is "fair game" to anyone if (request.getUserPrincipal() == null) { return canCollaborate(context, ownerName, "public"); @@ -477,7 +463,7 @@ public static boolean canUserAccessMarkedIndividual(MarkedIndividual mi, // Check if User (via request) has edit access to every Encounter in this Individual public static boolean canUserFullyEditMarkedIndividual(MarkedIndividual mi, HttpServletRequest request) { - if (request.isUserInRole("admin")) return true; // TODO generalize and/or allow other roles all-access + if (request.isUserInRole("admin")) return true; Vector all = mi.getEncounters(); if ((all == null) || (all.size() < 1)) return false; for (Encounter enc : all) { @@ -522,18 +508,6 @@ public void setEditInitiator(String username) { } } -/* CURRENTLY NOT USED public static boolean doesQueryExcludeUser(Query query, HttpServletRequest request) { - System.out.println("query>>>> " + query.toString()); - String context = ServletUtilities.getContext(request); - if (!securityEnabled(context)) return false; - - if (request.getUserPrincipal() == null) return true; //anon user excluded if security enabled???? - String username = request.getUserPrincipal().getName(); - System.out.println("username->"+username); - - return false; - } - */ private static List addAssumedOrgAdminCollaborations( List returnMe, Shepherd myShepherd, String username) { // orgAdmin check diff --git a/src/main/java/org/ecocean/servlet/AnnotationEdit.java b/src/main/java/org/ecocean/servlet/AnnotationEdit.java index 4af2fd63b5..8b0ecb0694 100644 --- a/src/main/java/org/ecocean/servlet/AnnotationEdit.java +++ b/src/main/java/org/ecocean/servlet/AnnotationEdit.java @@ -43,7 +43,6 @@ public class AnnotationEdit extends HttpServlet { JSONObject jsonIn = ServletUtilities.jsonFromHttpServletRequest(request); PrintWriter out = response.getWriter(); - // TODO we could make this check owner of Encounter(s) etc etc User user = AccessControl.getUser(request, myShepherd); boolean isAdmin = false; if (user != null) diff --git a/src/main/java/org/ecocean/servlet/EncounterAddImage.java b/src/main/java/org/ecocean/servlet/EncounterAddImage.java index f4f7797974..6639498ecd 100644 --- a/src/main/java/org/ecocean/servlet/EncounterAddImage.java +++ b/src/main/java/org/ecocean/servlet/EncounterAddImage.java @@ -75,13 +75,10 @@ public void doPost(HttpServletRequest request, HttpServletResponse response) encounterNumber = value; } } -////TODO this will need to be generified for offsite storage prob via SinglePhotoVideo? as in EncounterForm? if (part.isFile()) { FilePart filePart = (FilePart)part; fileName = ServletUtilities.cleanFileName(filePart.getFileName()); if (fileName != null) { - // fileName = Util.generateUUID() + "-orig." + FilenameUtils.getExtension(fileName); - // File thisSharkDir = new File(encountersDir.getAbsolutePath() +"/"+ Encounter.subdir(encounterNumber)); File thisSharkDir = new File(Encounter.dir(shepherdDataDir, encounterNumber)); if (!thisSharkDir.exists()) { thisSharkDir.mkdirs(); } @@ -91,7 +88,6 @@ public void doPost(HttpServletRequest request, HttpServletResponse response) } } } - // File thisEncounterDir = new File(encountersDir, Encounter.subdir(encounterNumber)); File thisEncounterDir = new File(Encounter.dir(shepherdDataDir, encounterNumber)); myShepherd.beginDBTransaction(); @@ -102,8 +98,6 @@ public void doPost(HttpServletRequest request, HttpServletResponse response) SinglePhotoVideo newSPV = new SinglePhotoVideo(encounterNumber, (new File(fullPathFilename))); enc.addSinglePhotoVideo(newSPV); - ///// NOT YET --> enc.refreshAssetFormats(myShepherd); - // enc.refreshAssetFormats(context, ServletUtilities.dataDir(context, rootWebappPath), newSPV, false); enc.addComments("

" + request.getRemoteUser() + " on " + (new java.util.Date()).toString() + "
" + "Submitted new encounter image graphic: " + fileName + ".

"); diff --git a/src/main/java/org/ecocean/servlet/EncounterAddMantaPattern.java b/src/main/java/org/ecocean/servlet/EncounterAddMantaPattern.java index c4e899d1a7..d2df8c9e00 100644 --- a/src/main/java/org/ecocean/servlet/EncounterAddMantaPattern.java +++ b/src/main/java/org/ecocean/servlet/EncounterAddMantaPattern.java @@ -58,9 +58,7 @@ public class EncounterAddMantaPattern extends HttpServlet { // setup data dir File shepherdDataDir = CommonConfiguration.getDataDirectory(getServletContext(), context); - // if(!shepherdDataDir.exists()){shepherdDataDir.mkdir();} File encountersDir = new File(shepherdDataDir.getAbsolutePath() + "/encounters"); - // if(!encountersDir.exists()){encountersDir.mkdir();} // set up for response response.setContentType("text/html"); @@ -87,7 +85,6 @@ else if (request.getParameter("action") != null && action = "imageadd2"; } try { - // ==================================================================== if (action.equals("imageremove")) { encounterNumber = request.getParameter("number"); try { @@ -111,12 +108,10 @@ else if (request.getParameter("action") != null && "I hit a security error trying to delete the old feature image. Please check your file system permissions."); } } - // ==================================================================== else if (action.equals("rescan")) { encounterNumber = request.getParameter("number"); try { Encounter enc = myShepherd.getEncounter(encounterNumber); - // File encDir = new File(encountersDir, enc.getEncounterNumber()); File encDir = new File(Encounter.dir(shepherdDataDir, encounterNumber)); spv = myShepherd.getSinglePhotoVideo(request.getParameter( @@ -186,12 +181,10 @@ else if (action.equals("rescan")) { "I hit a security error trying to rescan manta feature image. Please check your file system permissions."); } } - // ==================================================================== else if (action.equals("rescanRegional")) { encounterNumber = request.getParameter("number"); try { Encounter enc = myShepherd.getEncounter(encounterNumber); - // File dirEnc = new File(encountersDir, enc.getEncounterNumber()); File dirEnc = new File(Encounter.dir(shepherdDataDir, encounterNumber)); spv = myShepherd.getSinglePhotoVideo(request.getParameter( @@ -260,7 +253,6 @@ else if (action.equals("rescanRegional")) { "I hit a security error trying to rescan manta feature image. Please check your file system permissions."); } } - // ==================================================================== else if (action.equals("imageadd")) { MultipartParser mp = new MultipartParser(request, CommonConfiguration.getMaxMediaSizeInMegabytes(context) * 1048576); @@ -348,8 +340,6 @@ else if (action.equals("imageadd")) { } } } - // ==================================================================== - // ==================================================================== // imageadd2 is added for the new candidate region selection tool and should eventually replace the original imageadd action else if (action.equals("imageadd2")) { encounterNumber = request.getParameter("encounterID"); @@ -400,10 +390,7 @@ else if (action.equals("imageadd2")) { } else { // note: matchFilename (and extension) should be the same as mmFiles, i think -jon int dot = matchFilename.lastIndexOf('.'); - String extension = matchFilename.substring(dot + 1, matchFilename.length()); // TODO get actual - // format from - // file magic - // instead? + String extension = matchFilename.substring(dot + 1, matchFilename.length()); String targetFormat = null; if (extension.equalsIgnoreCase("jpg") || extension.equalsIgnoreCase("jpeg")) { @@ -427,9 +414,7 @@ else if (action.equals("imageadd2")) { BufferedImage bufferedImage = new BufferedImage(image.getWidth( null), image.getHeight(null), BufferedImage.TYPE_INT_RGB); Graphics2D g2 = bufferedImage.createGraphics(); - g2.drawImage(image, null, null); // might need bgcolor if ever - // transparency a problem? - // http://stackoverflow.com/a/1545417 + g2.drawImage(image, null, null); // might need bgcolor if ever transparency a problem? http://stackoverflow.com/a/1545417 ImageIO.write(bufferedImage, targetFormat, write2me); } catch (Exception e) { errorMessage = "problem converting/saving image: " + @@ -449,8 +434,6 @@ else if (action.equals("imageadd2")) { if (errorMessage != null) { // had a problem resultComment.append("error: " + errorMessage); } else { - // myShepherd.commitDBTransaction(); - resultComment.append("Successfully saved the new feature image: " + write2me.getAbsolutePath() + "
"); @@ -493,7 +476,6 @@ else if (action.equals("imageadd2")) { } } } - // ==================================================================== myShepherd.beginDBTransaction(); System.out.println(" I see encounterNumber as: " + encounterNumber); diff --git a/src/main/java/org/ecocean/servlet/EncounterForm.java b/src/main/java/org/ecocean/servlet/EncounterForm.java index 90b61ef91e..6dfb53f4b2 100644 --- a/src/main/java/org/ecocean/servlet/EncounterForm.java +++ b/src/main/java/org/ecocean/servlet/EncounterForm.java @@ -104,7 +104,7 @@ private AcousticTag getAcousticTag(Map formValues) { private List getMetalTags(Map formValues) { List list = new ArrayList(); - List keys = Arrays.asList("left", "right"); // TODO programatically build from form + List keys = Arrays.asList("left", "right"); for (String key : keys) { // The keys are the location @@ -116,22 +116,8 @@ private List getMetalTags(Map formValues) { return list; } - // private List getProjects(Map formValues){ - // List projects = new ArrayList(); - // String projectNames = getVal(formValues, "proj-id-dropdown"); - // if(Util.stringExists(projectNames)){ - // System.out.println("projectNames is: " + projectNames); - // } - // String defaultProject = getVal(formValues, "defaultSelection"); - // if(Util.stringExists(defaultProject)){ - // System.out.println("defaultProject is: " + defaultProject); - // } - // return projects; - // } - private List getMeasurements(Map formValues, String encID, String context) { List list = new ArrayList(); - // List keys = Arrays.asList("weight", "length", "height"); //TODO programatically build from form // dynamically adapt to project-specific measurements List keys = CommonConfiguration.getIndexedPropertyValues("measurement", context); @@ -146,38 +132,12 @@ private List getMeasurements(Map formValues, String encID, String c Double doubleVal = Double.valueOf(value); list.add(new Measurement(encID, key, doubleVal, units, samplingProtocol)); } catch (Exception ex) { - // TODO was reporting via comments, but now how to handle? } } } return list; } -/* - got regular field (measurement(weight))=(111) got regular field (measurement(weightunits))=(kilograms) got regular field - (measurement(weightsamplingProtocol))=(samplingProtocol1) got regular field (measurement(length))=(222) got regular field - (measurement(lengthunits))=(meters) got regular field (measurement(lengthsamplingProtocol))=(samplingProtocol0) got regular field - (measurement(height))=(333) got regular field (measurement(heightunits))=(meters) got regular field - (measurement(heightsamplingProtocol))=(samplingProtocol0) Map measurements = theForm.getMeasurements(); - for (String key : measurements.keySet()) { - if (!key.endsWith("units") && !key.endsWith("samplingProtocol")) { - String value = ((String) measurements.get(key)).trim(); - if (value.length() > 0) { - try { - Double doubleVal = Double.valueOf(value); - String units = (String) measurements.get(key + "units"); - String samplingProtocol = (String) measurements.get(key + "samplingProtocol"); - Measurement measurement = new Measurement(enc.getEncounterNumber(), key, doubleVal, units, samplingProtocol); - enc.addMeasurement(measurement); - } - catch(Exception ex) { - enc.addComments("

Reported measurement " + key + " was problematic: " + value + "

"); - } - } - } - } - */ - public static final String ERROR_PROPERTY_MAX_LENGTH_EXCEEDED = "The maximum upload length has been exceeded by the client."; @@ -187,8 +147,7 @@ got regular field (measurement(weight))=(111) got regular field (measurement(wei List projects = new ArrayList(); Map formValues = new HashMap(); - // IMPORTANT - processingNotes can be used to add notes on data handling (e.g., poorly formatted dates) that can be reconciled later by the - // reviewer + // IMPORTANT - processingNotes can be used to add notes on data handling (e.g., poorly formatted dates) that can be reconciled later by the reviewer // Example usage: processingNotes.append("

Error encountered processing this date submitted by user: "+getVal(formValues, // "datepicker")+"

"); StringBuffer processingNotes = new StringBuffer(); @@ -198,79 +157,9 @@ got regular field (measurement(weight))=(111) got regular field (measurement(wei Shepherd myShepherd = new Shepherd(context); myShepherd.setAction("EncounterForm.class"); System.out.println("in context " + context); - // request.getSession()getServlet().getServletContext().getRealPath("/")); String rootDir = getServletContext().getRealPath("/"); System.out.println("rootDir=" + rootDir); -/* - Vector fbImages = new Vector(); - int fbi = 0; - while (request.getParameter("socialphoto_" + fbi) != null) { - fbImages.add(request.getParameter("socialphoto_" + fbi)); - fbi++; - } - System.out.println(fbImages); - if (fbImages.size() > 0) { - FacebookClient fbclient = null; - try { - fbclient = SocialAuth.getFacebookClient(context); - } catch (Exception ex) { - System.out.println("SocialAuth.getFacebookClient threw exception " + ex.toString()); - } - WebContext ctx = new J2EContext(request, response); - //String callbackUrl = "http://localhost.wildme.org/a/SocialConnect?type=facebook"; - String callbackUrl = "http://" + CommonConfiguration.getURLLocation(request) + "/XXXSocialConnect?type=facebook"; - if (request.getParameter("disconnect") != null) callbackUrl += "&disconnect=1"; - fbclient.setCallbackUrl(callbackUrl); - OAuthCredentials credentials = null; - try { - credentials = fbclient.getCredentials(ctx); - } catch (Exception ex) { - System.out.println("caught exception on facebook credentials: " + ex.toString()); - } - if (credentials != null) { - FacebookProfile facebookProfile = fbclient.getUserProfile(credentials, ctx); - User fbuser = myShepherd.getUserBySocialId("facebook", facebookProfile.getId()); - System.out.println("getId() = " + facebookProfile.getId() + " -> user = " + fbuser); - if (fbuser != null) System.out.println("user = " + user.getUsername() + "; fbuser = " + fbuser.getUsername()); - if ((fbuser != null) && (fbuser.getUsername().equals(user.getUsername())) && (request.getParameter("disconnect") != null)) { - fbuser.unsetSocial("facebook"); - //myShepherd.getPM().makePersistent(user); - session.setAttribute("message", "disconnected from facebook"); - response.sendRedirect("myAccount.jsp"); - return; - } else if (fbuser != null) { - session.setAttribute("error", "looks like this account is already connected to an account"); - response.sendRedirect("myAccount.jsp"); - return; - } else { //lets do this user.setSocial("facebook", facebookProfile.getId()); - //myShepherd.getPM().makePersistent(user); - session.setAttribute("message", "connected to facebook"); - response.sendRedirect("myAccount.jsp"); - return; - } - } else { - System.out.println("*** trying redirect?"); - try { - fbclient.redirect(ctx, false, false); - } catch (Exception ex) { - System.out.println("caught exception on facebook processing: " + ex.toString()); - } - return; - } - } - */ - // private Map measurements = new HashMap(); - // Map metalTags = new HashMap(); - -/* - private String acousticTagSerial = ""; - private String acousticTagId = ""; - private String satelliteTagSerial = ""; - private String satelliteTagArgosPttNumber = ""; - private String satelliteTagName = ""; - */ - // set up for response response.setContentType("text/html"); PrintWriter out = response.getWriter(); @@ -299,13 +188,7 @@ got regular field (measurement(weight))=(111) got regular field (measurement(wei if (item.isFormField()) { // plain field formValues.put(item.getFieldName(), ServletUtilities.preventCrossSiteScriptingAttacks(item.getString( - "UTF-8").trim())); // TODO - // do - // we - // want - // trim() - // here??? - // -jon + "UTF-8").trim())); if (item.getFieldName().equals("defaultProject")) { if (!projectIdSelection.contains(item.getString().trim())) { projectIdSelection.add(item.getString().trim()); @@ -319,7 +202,7 @@ got regular field (measurement(weight))=(111) got regular field (measurement(wei } else if (item.getName().startsWith("socialphoto_")) { System.out.println(item.getName() + ": " + item.getString("UTF-8")); } else { // file -// System.out.println("content type???? " + item.getContentType()); TODO note, the helpers only check extension +// System.out.println("content type???? " + item.getContentType()); note: the helpers only check extension if (item.getSize() > maxSizeBytes) { filesBad.put(item.getName(), "file is larger than " + maxSizeMB + "MB"); } else if (myShepherd.isAcceptableImageFile(item.getName()) || @@ -359,7 +242,6 @@ got regular field (measurement(weight))=(111) got regular field (measurement(wei if (formValues.get("social_files_id") != null) { System.out.println("BBB: Social_files_id: " + formValues.get("social_files_id")); - // TODO better checking of files (size, type etc) File socDir = new File(ServletUtilities.dataDir(context, rootDir) + "/social_files/" + formValues.get("social_files_id")); for (File sf : socDir.listFiles()) { @@ -380,18 +262,8 @@ got regular field (measurement(weight))=(111) got regular field (measurement(wei if (badmsg.equals("")) { badmsg = "none"; } session.setAttribute("filesBadMessage", badmsg); if (fileSuccess) { -//////////////////////////////////////////// START - -// {submitterID=tomcat, submitterProject=, photographerEmail=, metalTag(left)=, sex=unknown, measurement(weight)=34234, location=, acousticTagId=, -// behavior=yow behavior..., measurement(weightunits)=kilograms, acousticTagSerial=, photographerName=, lifeStage=sub-adult, submitterAddress=, -// satelliteTagSerial=, releaseDate=, photographerPhone=, measurement(lengthunits)=meters, measurement(weightsamplingProtocol)=samplingProtocol0, -// measurement(length)=, submitterOrganization=, photographerAddress=, longitude=, year=2014, lat=, -// measurement(lengthsamplingProtocol)=samplingProtocol0, submitterEmail=, minutes=00, elevation=, measurement(height)=, -// measurement(heightsamplingProtocol)=samplingProtocol0, scars=None, submitterPhone=, submitterName=tomcat, hour=-1, livingStatus=alive, depth=, -// country=, satelliteTagName=Wild Life Computers, metalTag(right)=, month=1, measurement(heightunits)=meters, Submit=Send encounter report, -// informothers=, day=0, satelliteTagArgosPttNumber=, comments=} - - // check for spamBots TODO possibly move this to Util for general/global usage? + + // check for spamBots boolean spamBot = false; String[] spamFieldsToCheck = new String[] { "submitterPhone", "submitterName", "photographerName", "" + "Phone", "location", @@ -408,10 +280,6 @@ got regular field (measurement(weight))=(111) got regular field (measurement(wei spamBot = true; } System.out.println("spambot: " + spamBot); - // else if(spamFields.toString().toLowerCase().indexOf("[url]")!=-1){spamBot=true;} - // else if(spamFields.toString().toLowerCase().indexOf("url=")!=-1){spamBot=true;} - // else if(spamFields.toString().toLowerCase().trim().equals("")){spamBot=true;} - // else if((theForm.getSubmitterID()!=null)&&(theForm.getSubmitterID().equals("N%2FA"))) {spamBot=true;} String locCode = ""; System.out.println(" **** here is what i think locationID is: " + @@ -439,11 +307,9 @@ else if (formValues.get("location") != null) { } catch (Exception props_e) { props_e.printStackTrace(); } - } // end else - // end location code setter + } // end else and location code setter formValues.put("locCode", locCode); - // TODO this should live somewhere else as constant? (e.g. to build in form as well) String[] scarType = new String[] { "None", "Tail (caudal) fin", "1st dorsal fin", "2nd dorsal fin", "Left pectoral fin", "Right pectoral fin", "Head", "Body" @@ -465,16 +331,12 @@ else if (formValues.get("location") != null) { // need some ints for day/month/year/hour (other stuff seems to be strings) int day = 0, month = -1, year = 0, hour = 0; String minutes = ""; - // try { day = Integer.parseInt(getVal(formValues, "day")); } catch (NumberFormatException e) { day = 0; } - // try { month = Integer.parseInt(getVal(formValues, "month")); } catch (NumberFormatException e) { month = 0; } - // try { year = Integer.parseInt(getVal(formValues, "year")); } catch (NumberFormatException e) { year = 0; } // switch to datepicker LocalDateTime dt = new LocalDateTime(); if ((getVal(formValues, "datepicker") != null) && (!getVal(formValues, "datepicker").trim().equals(""))) { // System.out.println("Trying to read date: "+getVal(formValues, "datepicker").replaceAll(" ", "T")); - // boolean badDate=false; try { DateTimeFormatter parser1 = ISODateTimeFormat.dateOptionalTimeParser(); LocalDateTime reportedDateTime = new LocalDateTime(parser1.parseMillis(getVal( @@ -483,16 +345,13 @@ else if (formValues.get("location") != null) { "datepicker").replaceAll(" ", "T"), "-"); int numTokens = str.countTokens(); if (numTokens >= 1) { - // try { year = reportedDateTime.getYear(); if (year > (dt.getYear() + 1)) { - // badDate=true; year = 0; throw new Exception( " An unknown exception occurred during date processing in EncounterForm. The user may have input an improper format: " + year + " > " + dt.getYear()); } - // } catch (Exception e) { year=-1;} } if (numTokens >= 2) { try { month = reportedDateTime.getMonthOfYear(); } catch (Exception e) { @@ -542,10 +401,8 @@ else if (formValues.get("location") != null) { "genusSpecies").toString(), " "); if (tokenizer.countTokens() >= 2) { genus = tokenizer.nextToken(); - // enc.setGenus(tokenizer.nextToken()); specificEpithet = tokenizer.nextToken().replaceAll(",", "").replaceAll("_", " "); - // enc.setSpecificEpithet(tokenizer.nextToken().replaceAll(",","").replaceAll("_"," ")); } // handle malformed Genus Species formats else { @@ -562,7 +419,6 @@ else if (formValues.get("location") != null) { Encounter enc = new Encounter(day, month, year, hour, minutes, guess, getVal(formValues, "location")); boolean llSet = false; - // Encounter enc = new Encounter(); // System.out.println("Submission detected date: "+enc.getDate()); String encID = enc.generateEncounterNumber(); if ((formValues.get("catalogNumber") != null) && @@ -574,8 +430,7 @@ else if (formValues.get("location") != null) { enc.setEncounterNumber(encID); // Adding to a project should not generate an error that blocks data capture - // throw exception and move on - // add encounter to projects + // throw exception and move on to add encounter to projects try { if (projects != null) { for (Project currentProject : projects) { @@ -598,7 +453,6 @@ else if (formValues.get("location") != null) { makeMediaAssetsFromJavaFileItemObject(item, encID, astore, enc, newAnnotations, genus, specificEpithet); } - ///////////////////TODO social files also!!! System.out.println("BBB: Checking if we have social files..."); if (socialFiles.size() > 0) { int numSocialFiles = socialFiles.size(); @@ -648,7 +502,7 @@ else if (formValues.get("location") != null) { User user = myShepherd.getUserByHashedEmailAddress(hashedTok); submitters.add(user); } else { - User user = new User(tok, Util.generateUUID()); // TODO delete TODO comment if this is still here + User user = new User(tok, Util.generateUUID()); // TODO: evaluate for deprecation and remove user.setAffiliation(subO); if ((numTokens == 1) && (subN != null)) { user.setFullName(subN); } myShepherd.getPM().makePersistent(user); @@ -679,7 +533,7 @@ else if (formValues.get("location") != null) { } photographers.add(user); } else { - User user = new User(tok, Util.generateUUID()); // TODO delete this TODO if still here + User user = new User(tok, Util.generateUUID()); if ((numTokens == 1) && (photoN != null)) { user.setFullName(photoN); } myShepherd.getPM().makePersistent(user); myShepherd.commitDBTransaction(); @@ -715,32 +569,6 @@ else if (formValues.get("location") != null) { enc.setInformOthers(informOthers); // end informOthers-user processing -/* - String baseDir = ServletUtilities.dataDir(context, rootDir); - ArrayList images = new ArrayList(); - for (FileItem item : formFiles) { - // this will actually write file to filesystem (or [FUTURE] wherever) - // TODO: either (a) undo this if any failure of writing encounter; or (b) dont write til success of enc. - try { - //SinglePhotoVideo spv = new SinglePhotoVideo(encID, item, context, encDataDir); - SinglePhotoVideo spv = new SinglePhotoVideo(enc, item, context, baseDir); - //images.add(spv); - enc.addSinglePhotoVideo(spv); - } catch (Exception ex) { - System.out.println("failed to save " + item.toString() + ": " + ex.toString()); - } - } - for (File sf : socialFiles) { - File encDir = new File(enc.dir(baseDir)); - if (!encDir.exists()) encDir.mkdirs(); - File targetFile = new File(encDir, sf.getName()); - System.out.println("socialFile copy: " + sf.toString() + " ---> " + targetFile.toString()); - Files.copy(sf.toPath(), targetFile.toPath(), StandardCopyOption.REPLACE_EXISTING); - SinglePhotoVideo spv = new SinglePhotoVideo(encID, targetFile); - enc.addSinglePhotoVideo(spv); - } - */ - // now let's add our encounter to the database enc.setComments(getVal(formValues, "comments").replaceAll("\n", "
")); @@ -793,8 +621,7 @@ else if (formValues.get("location") != null) { MarkedIndividual ind = myShepherd.getMarkedIndividualQuiet(indID); if (ind == null) { ind = new MarkedIndividual(enc); - ind.addName(request, indID); // we don't just create the individual using the encounter+indID bc this request might key the name - // off of the logged-in user + ind.addName(request, indID); // we don't just create the individual using the encounter+indID bc this request might key the name off of the logged-in user myShepherd.storeNewMarkedIndividual(ind); ind.refreshNamesCache(); System.out.println(" ENCOUNTERFORM: created new individual " + indID); @@ -867,7 +694,6 @@ else if (formValues.get("location") != null) { double tempDouble = (new Double(formValues.get( "elevation").toString())).doubleValue() / 3.3; String truncElev = (new Double(tempDouble)).toString(); - // String truncElev = ((new Double(elevation)) / 3.3).toString(); sizePeriod = truncElev.indexOf("."); truncElev = truncElev.substring(0, sizePeriod + 2); formValues.put("elevation", (new Double(truncElev)).toString()); @@ -885,7 +711,6 @@ else if (formValues.get("location") != null) { double tempDouble = (new Double(formValues.get( "size").toString())).doubleValue() / 3.3; String truncSize = (new Double(tempDouble)).toString(); - // String truncSize = ((new Double(size)) / 3.3).toString(); sizePeriod = truncSize.indexOf("."); truncSize = truncSize.substring(0, sizePeriod + 2); formValues.put("size", (new Double(truncSize)).toString()); @@ -938,23 +763,11 @@ else if (formValues.get("location") != null) { if ((formValues.get("lat") != null) && (formValues.get("longitude") != null) && !formValues.get("lat").toString().equals("") && !formValues.get("longitude").toString().equals("")) { - // enc.setGPSLatitude(lat + "° " + gpsLatitudeMinutes + "\' " + gpsLatitudeSeconds + "\" " + latDirection); try { double degrees = (new Double(formValues.get("lat").toString())).doubleValue(); double position = degrees; - /* - if (!gpsLatitudeMinutes.equals("")) { - double minutes2 = ((new Double(gpsLatitudeMinutes)).doubleValue()) / 60; - position += minutes2; - } - if (!gpsLatitudeSeconds.equals("")) { - double seconds2 = ((new Double(gpsLatitudeSeconds)).doubleValue()) / 3600; - position += seconds2; - } - if (latDirection.toLowerCase().equals("south")) { - position = position * -1; - }*/ + enc.setDWCDecimalLatitude(position); double degrees2 = (new Double(formValues.get( @@ -967,14 +780,7 @@ else if (formValues.get("location") != null) { e.printStackTrace(); } } - // enc.setMeasureUnits("Meters"); - // enc.setSubmitterPhone(getVal(formValues, "submitterPhone")); - // enc.setSubmitterAddress(getVal(formValues, "submitterAddress")); - - // enc.setPhotographerPhone(getVal(formValues, "photographerPhone")); - // enc.setPhotographerAddress(getVal(formValues, "photographerAddress")); - // enc.setPhotographerName(getVal(formValues, "photographerName")); - // enc.setPhotographerEmail(getVal(formValues, "photographerEmail")); + enc.addComments("

Submitted on " + (new java.util.Date()).toString() + " from address: " + ServletUtilities.getRemoteHost(request) + "

"); // enc.approved = false; @@ -1091,8 +897,7 @@ else if (formValues.get("location") != null) { parentTask.setParameters(tp); } Task task = org.ecocean.ia.IA.intakeMediaAssets(myShepherd, enc.getMedia(), - parentTask); // TODO are they *really* persisted for - // another thread (queue) + parentTask); myShepherd.storeNewTask(task); Logger log = LoggerFactory.getLogger(EncounterForm.class); log.info("New encounter submission: cOther = NotificationMailer.splitEmails(enc.getInformOthers()); - for (String emailTo : cOther) { - String msg = CommonConfiguration.appendEmailRemoveHashString(request, "", emailTo, context); - tagMap.put(NotificationMailer.EMAIL_HASH_TAG, Encounter.getHashOfEmailString(emailTo)); - NotificationMailer mailer=new NotificationMailer(context, null, emailTo, "newSubmission", tagMap); - mailer.setUrlScheme(request.getScheme()); - es.execute(mailer); - } - } - */ es.shutdown(); } catch (Exception e) { @@ -1310,7 +1103,6 @@ private void makeMediaAssetsFromJavaFileObject(File item, String encID, AssetSto // System.out.println("attempting to write uploaded file to " + tmpFile); try { FileUtilities.copyFile(item, tmpFile); - // item.write(tmpFile); } catch (Exception ex) { System.out.println("Could not write " + tmpFile + ": " + ex.toString()); } diff --git a/src/main/java/org/ecocean/servlet/EncounterVMData.java b/src/main/java/org/ecocean/servlet/EncounterVMData.java index 0f1b0cf28c..f655465471 100644 --- a/src/main/java/org/ecocean/servlet/EncounterVMData.java +++ b/src/main/java/org/ecocean/servlet/EncounterVMData.java @@ -84,18 +84,14 @@ public void doPost(HttpServletRequest request, HttpServletResponse response) candEnc.setMatchedBy("Visual Matcher"); indiv.addEncounter(candEnc); } - // myShepherd.addMarkedIndividual(indiv); } else { enc.setIndividual(indiv); } - // enc.assignToMarkedIndividual(matchID); enc.addComments("

" + request.getRemoteUser() + " on " + (new java.util.Date()).toString() + "
" + "Added to " + matchID + ".

"); enc.setMatchedBy("Visual Matcher"); - // myShepherd.storeNewEncounter(enc, enc.getCatalogNumber()); myShepherd.commitDBTransaction(); - // myShepherd.closeDBTransaction(); redirUrl = "encounters/encounter.jsp?number=" + enc.getCatalogNumber(); } else { rtn.put("error", "unauthorized"); @@ -110,7 +106,7 @@ public void doPost(HttpServletRequest request, HttpServletResponse response) String[] fields = { "locationID", "sex", "patterningCode" }; for (String f : fields) { String val = request.getParameter(f); - if (val != null) filter += " && " + f + " == '" + val + "'"; // TODO safely quote! sql injection etc + if (val != null) filter += " && " + f + " == '" + val + "'"; } String mma = request.getParameter("mmaCompatible"); if ((mma != null) && !mma.equals("")) { @@ -138,10 +134,7 @@ public void doPost(HttpServletRequest request, HttpServletResponse response) (System.currentTimeMillis() - startTime) + " milliseconds. Result set was: " + resultsSize); int numConsidered = 0; - // Iterator all = myShepherd.getAllEncounters("catalogNumber", filter); - // while (all.hasNext() && (candidates.size() < MAX_MATCH)) { for (int i = 0; ((i < resultsSize) && (candidates.size() < MAX_MATCH)); i++) { - // Encounter cand = all.next(); System.out.println(" i=" + i); Encounter cand = results.get(i); numConsidered++; @@ -192,7 +185,6 @@ public void doPost(HttpServletRequest request, HttpServletResponse response) } rtn.put("dateInMilliseconds", enc.getDateInMilliseconds()); rtn.put("mmaCompatible", enc.getMmaCompatible()); - // if (!images.isEmpty()) rtn.put("images", images); } } // end try catch (Exception e) { @@ -230,7 +222,6 @@ private void addImages(Encounter enc, HashMap m, Shepherd myShepherd, for (MediaAsset ma : enc.getMedia()) { HashMap i = new HashMap(); i.put("id", ma.getId()); - // URL safe = ma.safeURL(myShepherd, request); URL safe = ma.webURL(); i.put("url", safe); i.put("thumbUrl", safe); diff --git a/src/main/java/org/ecocean/servlet/IAGateway.java b/src/main/java/org/ecocean/servlet/IAGateway.java index 7037c4af3b..4ec4a8d853 100644 --- a/src/main/java/org/ecocean/servlet/IAGateway.java +++ b/src/main/java/org/ecocean/servlet/IAGateway.java @@ -99,9 +99,7 @@ public void doPost(HttpServletRequest request, HttpServletResponse response) // sendtoIAscripts for bulk command line detection use this v2 option // uses detection queue if (j.optBoolean("enqueue", false) || j.optBoolean("v2", false)) { // short circuits and just blindly writes out to queue and is done! - // magic? - // TODO if queue is not active/okay, fallback to synchronous??? - // TODO could probably add other stuff (e.g. security/user etc) + // TODO: if queue is not active/okay, fallback to synchronous j.put("__context", context); j.put("__baseUrl", baseUrl); j.put("__enqueuedByIAGateway", System.currentTimeMillis()); @@ -184,7 +182,6 @@ else if (j.optJSONObject("bulkImport") != null) { out.close(); } - // TODO wedge in IA.intake here i guess? (once it exists) public static JSONObject _doDetect(JSONObject jin, JSONObject res, Shepherd myShepherd, String baseUrl) throws ServletException, IOException { @@ -194,7 +191,7 @@ public static JSONObject _doDetect(JSONObject jin, JSONObject res, Shepherd mySh if (taskId == null) throw new RuntimeException("IAGateway._doDetect() has no taskId passed in"); System.out.println("PRELOADED"); - Task task = Task.load(taskId, myShepherd); // might be null in some cases, such as non-queued ... maybe FIXME when we dump cruft? + Task task = Task.load(taskId, myShepherd); // might be null in some cases, such as non-queued System.out.println("LOADED???? " + taskId + " --> " + task); String context = myShepherd.getContext(); if (baseUrl == null) return res; @@ -219,15 +216,6 @@ public static JSONObject _doDetect(JSONObject jin, JSONObject res, Shepherd mySh } } } - /* - else if (j.optJSONArray("mediaAssetSetIds") != null) { - JSONArray ids = j.getJSONArray("mediaAssetSetIds"); - for (int i = 0 ; i < ids.length() ; i++) { - MediaAssetSet set = myShepherd.getMediaAssetSet(ids.optString(i)); - if ((set != null) && (set.getMediaAssets() != null) && (set.getMediaAssets().size() > 0)) mas.addAll(set.getMediaAssets()); - } - } - */ else { res.put("success", false); res.put("error", "unknown detect value"); @@ -253,7 +241,6 @@ else if (j.optJSONArray("mediaAssetSetIds") != null) { res.put("sendMediaAssets", IBEISIA.sendMediaAssetsNew(mas, context)); JSONObject sent = IBEISIA.sendDetect(mas, baseUrl, context, myShepherd, detectArgs, detectUrl); - // JSONObject sent = IBEISIA.sendDetect(mas, baseUrl, context, myShepherd); res.put("sendDetect", sent); String jobId = null; if ((sent.optJSONObject("status") != null) && @@ -280,7 +267,7 @@ else if (j.optJSONArray("mediaAssetSetIds") != null) { return res; } - // TODO not sure why we pass 'res' in but also it is the return value... potentially should be fixed; likely when we create IA package + // we pass 'res' in but also it is the return value public static JSONObject _doIdentify(JSONObject jin, JSONObject res, Shepherd myShepherd, String context, String baseUrl, boolean fastlane) throws ServletException, IOException { @@ -294,7 +281,6 @@ public static JSONObject _doIdentify(JSONObject jin, JSONObject res, Shepherd my JSONObject j = jin.optJSONObject("identify"); if (j == null) return res; // "should never happen" /* - TODO? right now this 'opt' is directly from IBEISIA.identOpts() ????? hmmmm.... note then that for IBEIS this effectively gets mapped via queryConfigDict to usable values we also might consider incorporating j.opt (passed within identify:{} object itself, from the api/gateway) ??? */ @@ -303,8 +289,7 @@ public static JSONObject _doIdentify(JSONObject jin, JSONObject res, Shepherd my ArrayList validIds = new ArrayList(); int limitTargetSize = j.optInt("limitTargetSize", -1); // really "only" for debugging/testing, so use if you know what you are doing - // currently this implies each annotation should be sent one-at-a-time TODO later will be allow clumping (to be sent as multi-annotation - // query lists.... *when* that is supported by IA + // currently this implies each annotation should be sent one-at-a-time JSONArray alist = j.optJSONArray("annotationIds"); if ((alist != null) && (alist.length() > 0)) { for (int i = 0; i < alist.length(); i++) { @@ -317,9 +302,7 @@ public static JSONObject _doIdentify(JSONObject jin, JSONObject res, Shepherd my validIds.add(aid); } } - // i think that "in the future" co-occurring annotations should be sent together as one set of query list; but since we dont have support for - // that - // now, we just send these all in one at a time. hope that is good enough! TODO + // i think that "in the future" co-occurring annotations should be sent together as one set of query list; but since we dont have support for that now, we just send these all in one at a time. JSONArray olist = j.optJSONArray("occurrenceIds"); if ((olist != null) && (olist.length() > 0)) { for (int i = 0; i < olist.length(); i++) { @@ -415,7 +398,6 @@ private static JSONObject _sendIdentificationTask(Annotation ann, String context String baseUrl, JSONObject queryConfigDict, JSONObject userConfidence, int limitTargetSize, Task task, Shepherd myShepherd, boolean fastlane) throws IOException { - // String iaClass = ann.getIAClass(); boolean success = true; String annTaskId = "UNKNOWN_" + Util.generateUUID(); @@ -429,13 +411,9 @@ private static JSONObject _sendIdentificationTask(Annotation ann, String context JSONObject shortCut = IAQueryCache.tryTargetAnnotationsCache(context, ann, taskRes, myShepherd); if (shortCut != null) return shortCut; - // Shepherd myShepherd = new Shepherd(context); - // myShepherd.setAction("IAGateway._sendIdentificationTask"); - // myShepherd.beginDBTransaction(); try { - // TODO we might want to cache this examplars list (per species) yes? - + // TODO: cache this examplars list (per species) ///note: this can all go away if/when we decide not to need limitTargetSize ArrayList matchingSet = null; if (limitTargetSize > -1) { @@ -488,7 +466,7 @@ private static JSONObject _sendIdentificationTask(Annotation ann, String context IBEISIA.log(annTaskId, ann.getId(), jobId, new JSONObject("{\"_action\": \"initIdentify\"}"), context); - // WB-1665: log as error when we cannot send ident task + // log as error when we cannot send ident task System.out.println("WB-1665 checking for error state in sent=" + sent); if (!sent.optBoolean("success", false) || (sent.optJSONObject("error") != null)) { System.out.println("_sendIdentificationTask() unable to initiate identification: " + @@ -505,48 +483,10 @@ private static JSONObject _sendIdentificationTask(Annotation ann, String context myShepherd.commitDBTransaction(); myShepherd.beginDBTransaction(); } -/* TODO ????????? - if (!success) { - for (MediaAsset ma : mas) { - ma.setDetectionStatus(IBEISIA.STATUS_ERROR); - } - } - */ + return taskRes; } - /* - public static JSONObject expandAnnotation(String annID, Shepherd myShepherd, HttpServletRequest request) { - if (annID == null) return null; - JSONObject rtn = new JSONObject(); - Annotation ann = null; - try { - ann = ((Annotation) (myShepherd.getPM().getObjectById(myShepherd.getPM().newObjectIdInstance(Annotation.class, annID), true))); - } catch (Exception ex) {} - if (ann != null) { - rtn.put("annotationID", annID); - Encounter enc = Encounter.findByAnnotation(ann, myShepherd); - if (enc != null) { - JSONObject jenc = new JSONObject(); - jenc.put("catalogNumber", enc.getCatalogNumber()); - jenc.put("date", enc.getDate()); - jenc.put("sex", enc.getSex()); - jenc.put("verbatimLocality", enc.getVerbatimLocality()); - jenc.put("locationID", enc.getLocationID()); - jenc.put("individualID", enc.getIndividualID()); - jenc.put("otherCatalogNumbers", enc.getOtherCatalogNumbers()); - rtn.put("encounter", jenc); - } - MediaAsset ma = ann.getMediaAsset(); - if (ma != null) { - try { - rtn.put("mediaAsset", new JSONObject(ma.sanitizeJson(request, new org.datanucleus.api.rest.orgjson.JSONObject()).toString())); - } catch (Exception ex) {} - } - } - return rtn; - } - */ public static JSONObject taskSummary(JSONArray taskIds, Shepherd myShepherd) { JSONObject rtn = new JSONObject(); @@ -631,26 +571,22 @@ public static boolean addToDetectionQueue(String context, String content) public static Queue getIAQueue(String context) throws IOException { - // if (IAQueue != null) return IAQueue; IAQueue = QueueUtil.getBest(context, "IA"); return IAQueue; } public static Queue getDetectionQueue(String context) throws IOException { - // if (detectionQueue != null) return detectionQueue; detectionQueue = QueueUtil.getBest(context, "detection"); return detectionQueue; } public static Queue getIACallbackQueue(String context) throws IOException { - // if (IACallbackQueue != null) return IACallbackQueue; IACallbackQueue = QueueUtil.getBest(context, "IACallback"); return IACallbackQueue; } - // TODO clean this up! now that this is moved here, there is probably lots of redundancy with above no? public static void processQueueMessage(String message) { // System.out.println("DEBUG: IAGateway.processQueueMessage -> " + message); if (message == null) return; @@ -696,7 +632,6 @@ public static void processQueueMessage(String message) { System.out.println( "ERROR: IAGateway.processQueueMessage() 'detect' threw exception: " + ex.toString()); - // now for certain returns, we want to increment our retry-ticker (this is TODO research in progress!) if (ex.toString().contains("HTTP error code : 500")) { requeueIncrement = true; requeue = true; @@ -911,27 +846,12 @@ public static JSONObject handleBulkImport(JSONObject jin, JSONObject res, Shephe System.out.println("IAGateway.handleBulkImport() created parentTask " + parentTask + " to link to " + itask); } - // JSONObject maMap = jin.optJSONObject("bulkImport"); - // System.out.println("IAGateway.handleBulkImport() preparing to parse " + maMap.keySet().size() + " encounter detection jobs"); - // if (maMap == null) return res; // "should never happen" - /* - maMap is just js_jarrs from imports.jsp, basically { encID0: [ma0, ... maN], ... encIDX: [maY, .. maZ] } - so we need 1 detection job per element - */ - // JSONObject mapRes = new JSONObject(); int okCount = 0; JSONArray maIds = new JSONArray(); for (MediaAsset asset : itask.getMediaAssets()) { maIds.put(asset.getId()); } - // for (Object e: maMap.keySet()) { - // String encId = (String)e; - // JSONArray maIds = maMap.optJSONArray(encId); - // if (maIds == null) { - // mapRes.put(encId, "no JSONArray"); - // System.out.println("[ERROR] IAGateway.handleBulkImport() maMap could not find JSONArray of MediaAsset ids at encId key=" + encId); - // continue; - // } + Task task = new Task(); task.setParameters(taskParameters); myShepherd.storeNewTask(task); @@ -949,11 +869,7 @@ public static JSONObject handleBulkImport(JSONObject jin, JSONObject res, Shephe task.setQueueResumeMessage(qjob.toString()); boolean ok = addToDetectionQueue(context, qjob.toString()); if (ok) okCount++; - // mapRes.put(encId, "task id=" + task.getId() + " queued=" + ok); - // } - // res.put("encounterCount", maMap.keySet().size()); res.put("queuedCount", okCount); - // res.put("mapResults", mapRes); res.remove("error"); res.put("success", true); return res; diff --git a/src/main/java/org/ecocean/servlet/InterconnectSubmitSpots.java b/src/main/java/org/ecocean/servlet/InterconnectSubmitSpots.java index e4e2d80a6e..be9879e3d3 100644 --- a/src/main/java/org/ecocean/servlet/InterconnectSubmitSpots.java +++ b/src/main/java/org/ecocean/servlet/InterconnectSubmitSpots.java @@ -16,21 +16,15 @@ import java.io.PrintWriter; import java.util.ArrayList; -// import java.util.Vector; - // adds spots to a new encounter public class InterconnectSubmitSpots extends HttpServlet { private void deleteOldScans(String side, String num) { try { - // File file=new File((new - // File(".")).getCanonicalPath()+File.separator+"webapps"+File.separator+"ROOT"+File.separator+"encounters"+File.separator+num+File.separator+"lastFull"+side+"Scan.xml"); File file = new File(getServletContext().getRealPath(("/encounters/" + num + "/lastFull" + side + "Scan.xml"))); if (file.exists()) { file.delete(); } - // file=new File((new - // File(".")).getCanonicalPath()+File.separator+"webapps"+File.separator+"ROOT"+File.separator+"encounters"+File.separator+num+File.separator+"lastFull"+side+"I3SScan.xml"); file = new File(getServletContext().getRealPath(("/encounters/" + num + "/lastFull" + side + "I3SScan.xml"))); if (file.exists()) { @@ -117,18 +111,6 @@ public void doGet(HttpServletRequest request, HttpServletResponse response) refs.add(new SuperSpot(ref2x, ref2y)); refs.add(new SuperSpot(ref3x, ref3y)); -/* TODO no more spots on Encounter -- FIXME if ((request.getParameter("rightSide") != null) && (request.getParameter("rightSide").equals("true"))) { - side = "right"; - enc.setRightSpots(superSpotArray2); - enc.setRightReferenceSpots(refs); - enc.setNumRightSpots(superSpotArray2.size()); - } else { - - enc.setSpots(superSpotArray2); - enc.setLeftReferenceSpots(refs); - enc.setNumLeftSpots(superSpotArray2.size()); - } - */ String user = "Unknown User"; if (request.getRemoteUser() != null) { user = request.getRemoteUser(); diff --git a/src/main/java/org/ecocean/servlet/JavascriptGlobals.java b/src/main/java/org/ecocean/servlet/JavascriptGlobals.java index ec9f2d1d8f..c027f1a512 100644 --- a/src/main/java/org/ecocean/servlet/JavascriptGlobals.java +++ b/src/main/java/org/ecocean/servlet/JavascriptGlobals.java @@ -49,8 +49,6 @@ public void doPost(HttpServletRequest request, HttpServletResponse response) String gtmKey = CommonConfiguration.getGoogleTagManagerKey(context); String gaId = CommonConfiguration.getGoogleAnalyticsId(context); String gMapKey = CommonConfiguration.getGoogleMapsKey(context); - // Properties props = new Properties(); - // props = ShepherdProperties.getProperties("collaboration.properties", langCode, context); HashMap rtn = new HashMap(); rtn.put("context", context); @@ -66,7 +64,6 @@ public void doPost(HttpServletRequest request, HttpServletResponse response) HashMap props = new HashMap(); HashMap lang = new HashMap(); - // lang.put("collaboration", ShepherdProperties.getProperties("collaboration.properties", langCode, context)); lang.put("visualMatcher", ShepherdProperties.getProperties("visualMatcher.properties", langCode, context)); @@ -93,14 +90,11 @@ public void doPost(HttpServletRequest request, HttpServletResponse response) fhm.put(f.getName(), f.getType().getName()); } defn.put("fields", fhm); - // HashMap ap = access.permissions(cls.getName(), request); - // defn.put("permissions", ap); defn.put("permissions", access.permissions(cls.getName(), request)); classDefn.put(cls.getName(), defn); } rtn.put("classDefinitions", classDefn); - // TODO we could do this for all sorts of property files too? HashMap uploader = new HashMap(); String s3key = CommonConfiguration.getProperty("s3upload_accessKeyId", context); if (s3key == null) { @@ -144,12 +138,10 @@ public void doPost(HttpServletRequest request, HttpServletResponse response) out.close(); } -// wildbookGlobals.properties.lang.collaboration.invitePromptOne public void propvalToHashMap(String name, String val, HashMap h) { // System.out.println("name->" + name); - if (name.equals("secret")) return; // TODO **totally** hactacular, but we dont want social secret keys sent out -- maybe pass in optional - // blacklist??? + if (name.equals("secret")) return; if (h == null) h = new HashMap(); int i = name.indexOf("."); if (i < 0) { @@ -159,7 +151,6 @@ public void propvalToHashMap(String name, String val, HashMap h) { String key = name.substring(0, i); // System.out.println("HASH key="+key); if (h.get(key) == null) h.put(key, new HashMap()); -/* TODO handle case where prop file might have foo.bar = 1 and then foo.bar.baz = 2 */ HashMap sub = (HashMap)h.get(key); propvalToHashMap(name.substring(i + 1), val, sub); } diff --git a/src/main/java/org/ecocean/servlet/LightRestServlet.java b/src/main/java/org/ecocean/servlet/LightRestServlet.java index 73e3f52abf..65f0939ab1 100644 --- a/src/main/java/org/ecocean/servlet/LightRestServlet.java +++ b/src/main/java/org/ecocean/servlet/LightRestServlet.java @@ -79,49 +79,11 @@ public class LightRestServlet extends HttpServlet { public static final NucleusLogger LOGGER_REST = NucleusLogger.getLoggerInstance( "DataNucleus.REST"); - // Shepherd myShepherd; - // PersistenceManagerFactory pmf; PersistenceNucleusContext nucCtx; HttpServletRequest thisRequest; - /* (non-Javadoc) - * @see javax.servlet.GenericServlet#destroy() - */ - - /* - public void destroy() - { - if (pmf != null && !pmf.isClosed()) - { - LOGGER_REST.info("REST : Closing PMF"); - pmf.close(); - } - super.destroy(); - } - */ public void init(ServletConfig config) throws ServletException { - /* - String factory = config.getInitParameter("persistence-context"); - if (factory == null) - { - throw new ServletException("You haven't specified \"persistence-context\" property defining the persistence unit"); - } - - - try - { - LOGGER_REST.info("REST : Creating PMF for factory=" + factory); - pmf = JDOHelper.getPersistenceManagerFactory(factory); - this.nucCtx = ((JDOPersistenceManagerFactory)pmf).getNucleusContext(); - } - catch (Exception e) - { - LOGGER_REST.error("Exception creating PMF", e); - throw new ServletException("Could not create internal PMF. See nested exception for details", e); - } - */ - super.init(config); } @@ -229,15 +191,11 @@ protected void doGet(HttpServletRequest req, HttpServletResponse resp) JSONArray jsonobj = convertToJson(req, (Collection)result, ((JDOPersistenceManager)myShepherd.getPM()).getExecutionContext(), myShepherd); - // JSONArray jsonobj = RESTUtils.getJSONArrayFromCollection((Collection)result, - // ((JDOPersistenceManager)pm).getExecutionContext()); tryCompress(req, resp, jsonobj, useCompression); } else { JSONObject jsonobj = convertToJson(req, result, ((JDOPersistenceManager)myShepherd.getPM()).getExecutionContext(), myShepherd); - // JSONObject jsonobj = RESTUtils.getJSONObjectFromPOJO(result, - // ((JDOPersistenceManager)pm).getExecutionContext()); System.out.println(" LIGHTREST: has jsonobj, about to tryCompress "); tryCompress(req, resp, jsonobj, useCompression); } @@ -245,68 +203,19 @@ protected void doGet(HttpServletRequest req, HttpServletResponse resp) resp.setHeader("Content-Type", "application/json"); resp.setStatus(200); myShepherd.commitDBTransaction(); - // ShepherdPMF.setShepherdState("LightRestServlet.class"+"_"+servletID, "commit"); } catch (Exception e) { System.out.println("Exception on lightRestServlet!"); e.printStackTrace(); } finally { if (myShepherd.getPM().currentTransaction().isActive()) { myShepherd.rollbackDBTransaction(); - // ShepherdPMF.setShepherdState("LightRestServlet.class"+"_"+servletID, "rollback"); } myShepherd.closeDBTransaction(); - // ShepherdPMF.setShepherdState("RestServlet.class"+"_"+servletID, "close"); - // ShepherdPMF.removeShepherdState("LightRestServlet.class"+"_"+servletID); } return; } - /* - else if (token.equalsIgnoreCase("jpql")) - { - // GET "/jpql?the_query_details" where "the_query_details" is "SELECT ... FROM ... WHERE ... ORDER BY ..." - String queryString = URLDecoder.decode(req.getQueryString(), "UTF-8"); - PersistenceManager pm = pmf.getPersistenceManager(); - try - { - pm.currentTransaction().begin(); - Query query = pm.newQuery("JPQL", queryString); - if (fetchParam != null) - { - query.getFetchPlan().addGroup(fetchParam); - } - Object result = filterResult(query.execute()); - if (result instanceof Collection) - { - JSONArray jsonobj = convertToJson(req, (Collection)result, ((JDOPersistenceManager)pm).getExecutionContext()); - //JSONArray jsonobj = RESTUtils.getJSONArrayFromCollection((Collection)result, - //((JDOPersistenceManager)pm).getExecutionContext()); - tryCompress(req, resp, jsonobj, useCompression); - } - else - { - JSONObject jsonobj = convertToJson(req, result, ((JDOPersistenceManager)pm).getExecutionContext()); - //JSONObject jsonobj = RESTUtils.getJSONObjectFromPOJO(result, - //((JDOPersistenceManager)pm).getExecutionContext()); - tryCompress(req, resp, jsonobj, useCompression); - } - query.closeAll(); - resp.setHeader("Content-Type", "application/json"); - resp.setStatus(200); - pm.currentTransaction().commit(); - } - finally - { - if (pm.currentTransaction().isActive()) - { - pm.currentTransaction().rollback(); - } - pm.close(); - } - return; - } - */ + else { - // GET "/{candidateclass}..." String className = token; ClassLoaderResolver clr = nucCtx.getClassLoaderResolver( LightRestServlet.class.getClassLoader()); @@ -322,7 +231,6 @@ else if (token.equalsIgnoreCase("jpql")) resp.getWriter().write(error.toString()); resp.setStatus(404); resp.setHeader("Content-Type", "application/json"); - // ShepherdPMF.removeShepherdState("LightRestServlet.class"); return; } Object id = getId(req); @@ -337,7 +245,6 @@ else if (token.equalsIgnoreCase("jpql")) queryString += " WHERE " + URLDecoder.decode(req.getQueryString(), "UTF-8"); } - // PersistenceManager pm = pmf.getPersistenceManager(); if (fetchParam != null) { myShepherd.getPM().getFetchPlan().setGroup(fetchParam); } @@ -348,19 +255,15 @@ else if (token.equalsIgnoreCase("jpql")) JSONArray jsonobj = convertToJson(req, result, ((JDOPersistenceManager)myShepherd.getPM()).getExecutionContext(), myShepherd); - // JSONArray jsonobj = RESTUtils.getJSONArrayFromCollection(result, - // ((JDOPersistenceManager)pm).getExecutionContext()); tryCompress(req, resp, jsonobj, useCompression); query.closeAll(); resp.setHeader("Content-Type", "application/json"); resp.setStatus(200); - // pm.currentTransaction().commit(); } finally { if (myShepherd.getPM().currentTransaction().isActive()) { myShepherd.rollbackDBTransaction(); } myShepherd.closeDBTransaction(); - // ShepherdPMF.removeShepherdState("LightRestServlet.class"); } return; } catch (NucleusUserException e) { @@ -369,7 +272,6 @@ else if (token.equalsIgnoreCase("jpql")) resp.getWriter().write(error.toString()); resp.setStatus(400); resp.setHeader("Content-Type", "application/json"); - // ShepherdPMF.removeShepherdState("LightRestServlet.class"); myShepherd.rollbackDBTransaction(); myShepherd.closeDBTransaction(); return; @@ -379,7 +281,6 @@ else if (token.equalsIgnoreCase("jpql")) resp.getWriter().write(error.toString()); resp.setStatus(404); resp.setHeader("Content-Type", "application/json"); - // ShepherdPMF.removeShepherdState("LightRestServlet.class"); myShepherd.rollbackDBTransaction(); myShepherd.closeDBTransaction(); return; @@ -392,7 +293,6 @@ else if (token.equalsIgnoreCase("jpql")) resp.setHeader("Content-Type", "application/json"); myShepherd.rollbackDBTransaction(); myShepherd.closeDBTransaction(); - // ShepherdPMF.removeShepherdState("LightRestServlet.class"); return; } } else { @@ -402,14 +302,11 @@ else if (token.equalsIgnoreCase("jpql")) resp.getWriter().write(error.toString()); resp.setStatus(400); resp.setHeader("Content-Type", "application/json"); - // ShepherdPMF.removeShepherdState("LightRestServlet.class"); myShepherd.rollbackDBTransaction(); myShepherd.closeDBTransaction(); return; } } - // GET "/{candidateclass}/id" - Find object by id - // PersistenceManager pm = pmf.getPersistenceManager(); if (fetchParam != null) { myShepherd.getPM().getFetchPlan().setGroup(fetchParam); } @@ -419,12 +316,8 @@ else if (token.equalsIgnoreCase("jpql")) JSONObject jsonobj = convertToJson(req, result, ((JDOPersistenceManager)myShepherd.getPM()).getExecutionContext(), myShepherd); - // JSONObject jsonobj = RESTUtils.getJSONObjectFromPOJO(result, - // ((JDOPersistenceManager)pm).getExecutionContext()); tryCompress(req, resp, jsonobj, useCompression); - // resp.getWriter().write(jsonobj.toString()); resp.setHeader("Content-Type", "application/json"); - // pm.currentTransaction().commit(); } catch (NucleusObjectNotFoundException ex) { resp.setContentLength(0); resp.setStatus(404); @@ -439,7 +332,6 @@ else if (token.equalsIgnoreCase("jpql")) myShepherd.rollbackDBTransaction(); } myShepherd.closeDBTransaction(); - // ShepherdPMF.removeShepherdState("LightRestServlet.class"); return; } } @@ -483,7 +375,6 @@ protected void doPost(HttpServletRequest req, HttpServletResponse resp) req.getReader().read(buffer); String str = new String(buffer); JSONObject jsonobj; - // PersistenceManager pm = pmf.getPersistenceManager(); ExecutionContext ec = ((JDOPersistenceManager)myShepherd.getPM()).getExecutionContext(); try { myShepherd.beginDBTransaction(); @@ -513,34 +404,11 @@ protected void doPost(HttpServletRequest req, HttpServletResponse resp) } } Object pc = RESTUtils.getObjectFromJSONObject(jsonobj, className, ec); - // boolean restAccessOk = restAccessCheck(pc, req, jsonobj); - boolean restAccessOk = false; // TEMPORARILY disable ALL access to POST/PUT until we really test things TODO -/* - System.out.println(jsonobj); - System.out.println("+++++"); - - Method restAccess = null; - boolean restAccessOk = true; - try { - restAccess = pc.getClass().getMethod("restAccess", new Class[] { HttpServletRequest.class }); - } catch (NoSuchMethodException nsm) { - //nothing to do - } + boolean restAccessOk = false; - if (restAccess != null) { - try { - restAccess.invoke(pc, req); - } catch (Exception ex) { - restAccessOk = false; - //this is the expected result when we are blocked (user not allowed) System.out.println("got Exception trying to - invoke restAccess: " + ex.toString()); - } - } - */ if (restAccessOk) { Object obj = myShepherd.getPM().makePersistent(pc); JSONObject jsonobj2 = convertToJson(req, obj, ec, myShepherd); - // JSONObject jsonobj2 = RESTUtils.getJSONObjectFromPOJO(obj, ec); resp.getWriter().write(jsonobj2.toString()); resp.setHeader("Content-Type", "application/json"); myShepherd.getPM().currentTransaction().commit(); @@ -602,8 +470,6 @@ protected void doPost(HttpServletRequest req, HttpServletResponse resp) protected void doDelete(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { - // getPMF(req); - // PersistenceManager pm = pmf.getPersistenceManager(); Shepherd myShepherd = new Shepherd(req); myShepherd.setAction("LightRestServlet.class.Delete"); @@ -638,14 +504,7 @@ protected void doDelete(HttpServletRequest req, HttpServletResponse resp) myShepherd.commitDBTransaction(); q.closeAll(); } else { - // we disable any delete for now, until permission testing complete TODO throw new NucleusUserException("DELETE access denied"); -/* - // Delete the object with the supplied id pm.currentTransaction().begin(); - Object obj = pm.getObjectById(id); - pm.deletePersistent(obj); - pm.currentTransaction().commit(); - */ } } catch (NucleusObjectNotFoundException ex) { try { @@ -690,97 +549,6 @@ protected void doDelete(HttpServletRequest req, HttpServletResponse resp) resp.setStatus(204); // created } - /* - protected void doHead(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException - { - //getPMF(req); - String className = getNextTokenAfterSlash(req); - ClassLoaderResolver clr = nucCtx.getClassLoaderResolver(RestServlet.class.getClassLoader()); - AbstractClassMetaData cmd = nucCtx.getMetaDataManager().getMetaDataForEntityName(className); - try - { - if (cmd == null) - { - cmd = nucCtx.getMetaDataManager().getMetaDataForClass(className, clr); - } - } - catch (ClassNotResolvedException ex) - { - resp.setStatus(404); - return; - } - - Object id = getId(req); - if (id == null) - { - // no id provided try - { - // get the whole extent String queryString = "SELECT FROM " + cmd.getFullClassName(); - if (req.getQueryString() != null) - { - // query by filter queryString += " WHERE " + URLDecoder.decode(req.getQueryString(), "UTF-8"); - } - //PersistenceManager pm = pmf.getPersistenceManager(); - try - { - pm.currentTransaction().begin(); - Query query = pm.newQuery("JDOQL", queryString); - query.execute(); - resp.setStatus(200); - pm.currentTransaction().commit(); - query.closeAll(); - } - finally - { - if (pm.currentTransaction().isActive()) - { - pm.currentTransaction().rollback(); - } - pm.close(); - } - return; - } - catch (NucleusUserException e) - { - resp.setStatus(400); - return; - } - catch (NucleusException ex) - { - resp.setStatus(404); - return; - } - catch (RuntimeException ex) - { - resp.setStatus(404); - return; - } - } - - PersistenceManager pm = pmf.getPersistenceManager(); - try - { - pm.currentTransaction().begin(); - pm.getObjectById(id); - resp.setStatus(200); - pm.currentTransaction().commit(); - return; - } - catch (NucleusException ex) - { - resp.setStatus(404); - return; - } - finally - { - if (pm.currentTransaction().isActive()) - { - pm.currentTransaction().rollback(); - } - pm.close(); - } - } - */ boolean restAccessCheck(Object obj, HttpServletRequest req, JSONObject jsonobj) { System.out.println(jsonobj.toString()); System.out.println(obj); @@ -895,33 +663,13 @@ JSONArray convertToJson(HttpServletRequest req, Collection coll, ExecutionContex for (Object o : coll) { if (o instanceof Collection) { jarr.put(convertToJson(req, (Collection)o, ec, myShepherd)); - } else { // TODO can it *only* be an JSONObject-worthy object at this point? + } else { jarr.put(convertToJson(req, o, ec, myShepherd)); } } return jarr; } -/* - //jo can be either JSONObject or JSONArray Object scrubJson(HttpServletRequest req, Object jo) throws JSONException { - System.out.println("scrubJson"); - if (jo instanceof JSONArray) { - JSONArray newArray = new JSONArray(); - JSONArray ja = (JSONArray)jo; - System.out.println("- JSON Array " + ja); - for (int i = 0 ; i < ja.length() ; i++) { - newArray.put(scrubJson(req, ja.getJSONObject(i))); - } - return newArray; - - } else { - JSONObject jobj = (JSONObject)jo; - System.out.println("- JSON Object " + jobj); - System.out.println("- scrubJson reporting class=" + jobj.get("class").toString()); - return jobj; - } - } - */ void tryCompress(HttpServletRequest req, HttpServletResponse resp, Object jo, boolean useComp) throws IOException, JSONException { System.out.println("??? TRY COMPRESS ??"); @@ -940,16 +688,6 @@ void tryCompress(HttpServletRequest req, HttpServletResponse resp, Object jo, bo } } - /* - private void getPMF(HttpServletRequest req){ - String context="context0"; - context=ServletUtilities.getContext(req); - ShepherdPMF.setShepherdState("LightRestServlet.class", "new"); - pmf=ShepherdPMF.getPMF(context); - this.nucCtx = ((JDOPersistenceManagerFactory)pmf).getNucleusContext(); - thisRequest = req; - } - */ private JSONObject getEncLightJson(Encounter enc, HttpServletRequest req, Shepherd myShepherd) { String context = ServletUtilities.getContext(req); diff --git a/src/main/java/org/ecocean/servlet/MediaAssetCreate.java b/src/main/java/org/ecocean/servlet/MediaAssetCreate.java index 8679a08978..7477ff168b 100644 --- a/src/main/java/org/ecocean/servlet/MediaAssetCreate.java +++ b/src/main/java/org/ecocean/servlet/MediaAssetCreate.java @@ -43,7 +43,7 @@ public void doGet(HttpServletRequest request, HttpServletResponse response) Shepherd myShepherd = new Shepherd(context); myShepherd.setAction("MediaAssetCreate.class"); - // note: a null status will be considered throw-away, cuz we no doubt will get aborted uploads etc. TODO cleanup of these with cronjob? + // note: a null status will be considered throw-away, cuz we no doubt will get aborted uploads etc. MediaAssetSet maSet = new MediaAssetSet(); myShepherd.beginDBTransaction(); myShepherd.getPM().makePersistent(maSet); @@ -58,28 +58,6 @@ public void doGet(HttpServletRequest request, HttpServletResponse response) out.println(res.toString()); } -/* - - NOTE: for now(?) we *require* a *valid* setId *and* that the asset *key be prefixed with it* -- this is for security purposes, so that users dont - fish out files stored in temporary bucket as their own. unlikely? yes. impossible? no. - { - "MediaAssetCreate" : [ - { - "setId" : "xxx", - "assetStoreId" : 4, ///DISABLED FOR NOW (TODO enable later if we need it?? how to handle security? need valid targets) - "assets" : [ - { "filename" : "foo.jpg" }, //this should live in uploadTmpDir (see below) on local drive - { "bucket" : "A", "key" : "xxx/B" }, - { "bucket" : "Y", "key" : "xxx/Z" }, - .... - ] - }, - "skipIA": false, //default is do-not-skipIA, but you may want off when done later (e.g. match.jsp which does in CreateEncounter) - .... (other types) ... - ] - - } - */ public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setHeader("Access-Control-Allow-Origin", "*"); // allow us stuff from localhost @@ -170,7 +148,6 @@ public void doPost(HttpServletRequest request, HttpServletResponse response) out.close(); } - // TODO could also return failures? errors? private JSONObject createMediaAssets(JSONArray jarr, Shepherd myShepherd, HttpServletRequest request) throws IOException { @@ -193,18 +170,6 @@ private JSONObject createMediaAssets(JSONArray jarr, Shepherd myShepherd, for (int i = 0; i < jarr.length(); i++) { JSONObject st = jarr.optJSONObject(i); if (st == null) continue; -/* disabled now for security(?) reasons ... TODO fix this -- if we have a need??? - int storeId = st.optInt("assetStoreId"); - if (storeId < 1) { - System.out.println("WARNING: createMediaAssets() - no assetStoreId on i=" + i); - continue; - } - AssetStore store = AssetStore.get(myShepherd, storeId); - if (store == null) { - System.out.println("WARNING: createMediaAssets() - AssetStore.get() failed for assetStoreId=" + storeId + ", i=" + i); - continue; - } - */ String setId = st.optString("setId", null); // attempt to validate setId (if we have one) @@ -233,14 +198,12 @@ private JSONObject createMediaAssets(JSONArray jarr, Shepherd myShepherd, for (int j = 0; j < assets.length(); j++) { boolean success = true; MediaAsset targetMA = null; - JSONObject params = assets.optJSONObject(j); // TODO sanitize + JSONObject params = assets.optJSONObject(j); if (params == null) continue; - // TODO we should probably also use the "SETID/" prefix (see below) standard for local too right????? String fname = params.optString("filename", null); String userFilename = params.optString("userFilename", fname); String url = params.optString("url", null); - String accessKey = params.optString("accessKey", null); // kinda specialty use to validate certain anon-uploaded cases (e.g. - // match.jsp) + String accessKey = params.optString("accessKey", null); // kinda specialty use to validate certain anon-uploaded cases (e.g. match.jsp) if (fname != null) { // this is local if (fname.indexOf("..") > -1) continue; // no hax0ring plz File inFile = new File(uploadTmpDir, fname); @@ -265,14 +228,6 @@ private JSONObject createMediaAssets(JSONArray jarr, Shepherd myShepherd, } } if (success) { -/* - TODO when annotation-building no longer needs dimensions, technically this Metadata building will not be required. however, we likely will need to - eat the cost of s3 cacheLocal() anyway for the children creation. however[2], we can likely just do it in the background. - at least doing this now will avoid collision of it happening twice during form submission... ug yeah what about that? ug, locking! - - update: errrr, maybe not. i think we *must* grab "real" (exif) metadata so we can get (primarily) date/time for image. :/ - but probably still could be done in the background.... - */ targetMA.validateSourceImage(); targetMA.updateMetadata(); targetMA.addLabel("_original"); @@ -290,7 +245,7 @@ eat the cost of s3 cacheLocal() anyway for the children creation. however[2], w } } // this duplicates some of MediaAssetAttach, but lets us get done in one API call - // TODO we dont sanity-check *ownership* of the encounter.... :/ + // TODO: sanity-check *ownership* of the encounter JSONObject attEnc = st.optJSONObject("attachToEncounter"); JSONObject attOcc = st.optJSONObject("attachToOccurrence"); if (attEnc != null) { diff --git a/src/main/java/org/ecocean/servlet/MergeIndividual.java b/src/main/java/org/ecocean/servlet/MergeIndividual.java index d0a530d05a..21fa3cf7e9 100644 --- a/src/main/java/org/ecocean/servlet/MergeIndividual.java +++ b/src/main/java/org/ecocean/servlet/MergeIndividual.java @@ -106,20 +106,7 @@ public void doPost(HttpServletRequest request, HttpServletResponse response) } // if we can't determine who is requeting this, no merge if (currentUsername != null) { - /* - ArrayList allUniqueUsers = new ArrayList<>(mark1Users); - for (String user : mark2Users) { - if (!allUniqueUsers.contains(user)&&!"".equals(user)&&user!=null) { - allUniqueUsers.add(user); - System.out.println("unique user == "+user); - } - - - }//end for - */ - // WB-1017 - // 1. if user is in role admin, they can force the automatic merge. we trust our admins. this also prevents unnecessary database - // calls. + // 1. if user is in role admin, they can force the automatic merge. we trust our admins. this also prevents unnecessary database calls. // 2. if User has full edit access to every Encounter of both MarkedIndividuals, they are trusted to make this decision automatically // if (allUniqueUsers.size()==1&&allUniqueUsers.get(0).equals(currentUsername)) { if (request.isUserInRole("admin") || @@ -187,8 +174,6 @@ public void doPost(HttpServletRequest request, HttpServletResponse response) // redirect to the confirm page try { - // WebUtils.redirectToSavedRequest(request, response, "/confirmSubmit.jsp?oldNameA="+oldName1+"&oldNameB="+oldName2+"&newId="+ id1); - RequestDispatcher dispatcher = getServletContext().getRequestDispatcher( ("/confirmSubmit.jsp?oldNameA=" + oldName1 + "&oldNameB=" + oldName2 + "&newId=" + id1)); @@ -217,16 +202,12 @@ private void errorAndClose(String msg, HttpServletResponse response) { // out.println(ServletUtilities.getFooter(context)); out.close(); response.setStatus(HttpServletResponse.SC_BAD_REQUEST); - // myShepherd.rollbackDBTransaction(); - // myShepherd.closeDBTransaction(); } private long twoWeeksFromNowLong() { // i know. this was really the least stupid way. final long twoWeeksInMillis = 1209600000; - // TODO restore desired delay after testing OR, add to task as variable - // final long twoWeeksInMillis = 60000; return System.currentTimeMillis() + twoWeeksInMillis; } } diff --git a/src/main/java/org/ecocean/servlet/OrganizationEdit.java b/src/main/java/org/ecocean/servlet/OrganizationEdit.java index 196dada553..16733776e3 100644 --- a/src/main/java/org/ecocean/servlet/OrganizationEdit.java +++ b/src/main/java/org/ecocean/servlet/OrganizationEdit.java @@ -108,7 +108,6 @@ public class OrganizationEdit extends HttpServlet { response.sendError(401, "access denied"); // only "admin" can create a new **top-level** org, otherwise user must create under an existing one - // we need to have some sort of OrgSuperUser Role i suppose? TODO } else if ((org == null) && (orgId == null) && isAdmin && (jsonIn.optString("create", null) != null)) { Organization newOrg = new Organization(jsonIn.getString("create")); diff --git a/src/main/java/org/ecocean/servlet/ProjectCreate.java b/src/main/java/org/ecocean/servlet/ProjectCreate.java index 18826b9c2f..db30941006 100644 --- a/src/main/java/org/ecocean/servlet/ProjectCreate.java +++ b/src/main/java/org/ecocean/servlet/ProjectCreate.java @@ -56,8 +56,6 @@ public void doPost(HttpServletRequest request, HttpServletResponse response) String projectIdPrefix = null; String researchProjectName = null; - // TODO handle add users by organization - try { res.put("success", "false"); encsJSON = j.optJSONArray("encounterIds"); diff --git a/src/main/java/org/ecocean/servlet/RestKeyword.java b/src/main/java/org/ecocean/servlet/RestKeyword.java index a9d6cefc06..efda843b0d 100644 --- a/src/main/java/org/ecocean/servlet/RestKeyword.java +++ b/src/main/java/org/ecocean/servlet/RestKeyword.java @@ -29,18 +29,13 @@ public void init(ServletConfig config) super.init(config); } -/* - public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { - doPost(request, response); - } - */ public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String context = ServletUtilities.getContext(request); JSONObject jin = ServletUtilities.jsonFromHttpServletRequest(request); JSONObject jout = new JSONObject("{\"success\": false}"); - if (request.getUserPrincipal() == null) { // TODO use AccessControl... + if (request.getUserPrincipal() == null) { response.setStatus(401); jout.put("error", "access denied"); } else if (jin.optJSONObject("onMediaAssets") != null) { @@ -123,11 +118,9 @@ public void doPost(HttpServletRequest request, HttpServletResponse response) for (int i = 0; i < toAdd.size(); i++) { if (!mine.contains(toAdd.get(i))) newList.add(toAdd.get(i)); // Here we also want to set IA viewpoint - // TODO: generalize this Keyword kw = toAdd.get(i); String kwName = kw.getReadableName(); - // We could simply use kwName as the viewpoint, but - // not sure if IA would play nicely with "Tail Fluke" for humpbacks + // We could simply use kwName as the viewpoint, but not sure if IA would play nicely with "Tail Fluke" for humpbacks String viewpoint = getViewpoint(kwName); if (viewpoint != null) { ArrayList anns = ma.getAnnotations(); @@ -165,7 +158,6 @@ public void doPost(HttpServletRequest request, HttpServletResponse response) jout.put("results", jassigned); jout.put("success", true); myShepherd.commitDBTransaction(); - // myShepherd.closeDBTransaction(); } } catch (Exception e) { e.printStackTrace(); @@ -205,7 +197,6 @@ public static String getViewpoint(String kwName, Taxonomy taxy, String context) return IA.getProperty(context, propKey); } - // TODO: make this one generic public static String getKwNameFromIaViewpoint(String iaViewpoint) { if (iaViewpoint == null) return null; String lower = iaViewpoint.toLowerCase(); diff --git a/src/main/java/org/ecocean/servlet/RestServlet.java b/src/main/java/org/ecocean/servlet/RestServlet.java index 102b59b583..2a247b050d 100644 --- a/src/main/java/org/ecocean/servlet/RestServlet.java +++ b/src/main/java/org/ecocean/servlet/RestServlet.java @@ -88,27 +88,6 @@ public void destroy() { public void init(ServletConfig config) throws ServletException { - /* - String factory = config.getInitParameter("persistence-context"); - if (factory == null) - { - throw new ServletException("You haven't specified \"persistence-context\" property defining the persistence unit"); - } - - - try - { - LOGGER_REST.info("REST : Creating PMF for factory=" + factory); - pmf = JDOHelper.getPersistenceManagerFactory(factory); - this.nucCtx = ((JDOPersistenceManagerFactory)pmf).getNucleusContext(); - } - catch (Exception e) - { - LOGGER_REST.error("Exception creating PMF", e); - throw new ServletException("Could not create internal PMF. See nested exception for details", e); - } - */ - super.init(config); } @@ -248,14 +227,10 @@ protected void doGet(HttpServletRequest req, HttpServletResponse resp) if (result instanceof Collection) { JSONArray jsonobj = convertToJson(req, (Collection)result, ((JDOPersistenceManager)pm).getExecutionContext()); - // JSONArray jsonobj = RESTUtils.getJSONArrayFromCollection((Collection)result, - // ((JDOPersistenceManager)pm).getExecutionContext()); tryCompress(req, resp, jsonobj, useCompression); } else { JSONObject jsonobj = convertToJson(req, result, ((JDOPersistenceManager)pm).getExecutionContext()); - // JSONObject jsonobj = RESTUtils.getJSONObjectFromPOJO(result, - // ((JDOPersistenceManager)pm).getExecutionContext()); tryCompress(req, resp, jsonobj, useCompression); } query.closeAll(); @@ -274,51 +249,6 @@ protected void doGet(HttpServletRequest req, HttpServletResponse resp) } return; } - /* - else if (token.equalsIgnoreCase("jpql")) - { - // GET "/jpql?the_query_details" where "the_query_details" is "SELECT ... FROM ... WHERE ... ORDER BY ..." - String queryString = URLDecoder.decode(req.getQueryString(), "UTF-8"); - PersistenceManager pm = pmf.getPersistenceManager(); - try - { - pm.currentTransaction().begin(); - Query query = pm.newQuery("JPQL", queryString); - if (fetchParam != null) - { - query.getFetchPlan().addGroup(fetchParam); - } - Object result = filterResult(query.execute()); - if (result instanceof Collection) - { - JSONArray jsonobj = convertToJson(req, (Collection)result, ((JDOPersistenceManager)pm).getExecutionContext()); - //JSONArray jsonobj = RESTUtils.getJSONArrayFromCollection((Collection)result, - //((JDOPersistenceManager)pm).getExecutionContext()); - tryCompress(req, resp, jsonobj, useCompression); - } - else - { - JSONObject jsonobj = convertToJson(req, result, ((JDOPersistenceManager)pm).getExecutionContext()); - //JSONObject jsonobj = RESTUtils.getJSONObjectFromPOJO(result, - //((JDOPersistenceManager)pm).getExecutionContext()); - tryCompress(req, resp, jsonobj, useCompression); - } - query.closeAll(); - resp.setHeader("Content-Type", "application/json"); - resp.setStatus(200); - pm.currentTransaction().commit(); - } - finally - { - if (pm.currentTransaction().isActive()) - { - pm.currentTransaction().rollback(); - } - pm.close(); - } - return; - } - */ else { // GET "/{candidateclass}..." String className = token; @@ -372,13 +302,10 @@ else if (token.equalsIgnoreCase("jpql")) List result = (List)filterResult(query.execute()); JSONArray jsonobj = convertToJson(req, result, ((JDOPersistenceManager)pm).getExecutionContext()); - // JSONArray jsonobj = RESTUtils.getJSONArrayFromCollection(result, - // ((JDOPersistenceManager)pm).getExecutionContext()); tryCompress(req, resp, jsonobj, useCompression); query.closeAll(); resp.setHeader("Content-Type", "application/json"); resp.setStatus(200); - // pm.currentTransaction().commit(); } finally { if (pm.currentTransaction().isActive()) { pm.currentTransaction().rollback(); @@ -444,10 +371,7 @@ else if (token.equalsIgnoreCase("jpql")) Object result = filterResult(pm.getObjectById(id)); JSONObject jsonobj = convertToJson(req, result, ((JDOPersistenceManager)pm).getExecutionContext()); - // JSONObject jsonobj = RESTUtils.getJSONObjectFromPOJO(result, - // ((JDOPersistenceManager)pm).getExecutionContext()); tryCompress(req, resp, jsonobj, useCompression); - // resp.getWriter().write(jsonobj.toString()); resp.setHeader("Content-Type", "application/json"); return; @@ -538,29 +462,7 @@ protected void doPost(HttpServletRequest req, HttpServletResponse resp) } Object pc = RESTUtils.getObjectFromJSONObject(jsonobj, className, ec); // boolean restAccessOk = restAccessCheck(pc, req, jsonobj); - boolean restAccessOk = false; // TEMPORARILY disable ALL access to POST/PUT until we really test things TODO -/* - System.out.println(jsonobj); - System.out.println("+++++"); - - Method restAccess = null; - boolean restAccessOk = true; - try { - restAccess = pc.getClass().getMethod("restAccess", new Class[] { HttpServletRequest.class }); - } catch (NoSuchMethodException nsm) { - //nothing to do - } - - if (restAccess != null) { - try { - restAccess.invoke(pc, req); - } catch (Exception ex) { - restAccessOk = false; - //this is the expected result when we are blocked (user not allowed) System.out.println("got Exception trying to - invoke restAccess: " + ex.toString()); - } - } - */ + boolean restAccessOk = false; if (restAccessOk) { Object obj = pm.makePersistent(pc); JSONObject jsonobj2 = convertToJson(req, obj, ec); @@ -661,14 +563,7 @@ protected void doDelete(HttpServletRequest req, HttpServletResponse resp) pm.currentTransaction().commit(); q.closeAll(); } else { - // we disable any delete for now, until permission testing complete TODO throw new NucleusUserException("DELETE access denied"); -/* - // Delete the object with the supplied id pm.currentTransaction().begin(); - Object obj = pm.getObjectById(id); - pm.deletePersistent(obj); - pm.currentTransaction().commit(); - */ } } catch (NucleusObjectNotFoundException ex) { try { @@ -892,33 +787,13 @@ JSONArray convertToJson(HttpServletRequest req, Collection coll, ExecutionContex for (Object o : coll) { if (o instanceof Collection) { jarr.put(convertToJson(req, (Collection)o, ec)); - } else { // TODO can it *only* be an JSONObject-worthy object at this point? + } else { jarr.put(convertToJson(req, o, ec)); } } return jarr; } -/* - //jo can be either JSONObject or JSONArray Object scrubJson(HttpServletRequest req, Object jo) throws JSONException { - System.out.println("scrubJson"); - if (jo instanceof JSONArray) { - JSONArray newArray = new JSONArray(); - JSONArray ja = (JSONArray)jo; - System.out.println("- JSON Array " + ja); - for (int i = 0 ; i < ja.length() ; i++) { - newArray.put(scrubJson(req, ja.getJSONObject(i))); - } - return newArray; - - } else { - JSONObject jobj = (JSONObject)jo; - System.out.println("- JSON Object " + jobj); - System.out.println("- scrubJson reporting class=" + jobj.get("class").toString()); - return jobj; - } - } - */ void tryCompress(HttpServletRequest req, HttpServletResponse resp, Object jo, boolean useComp) throws IOException, JSONException { // System.out.println("??? TRY COMPRESS ??"); diff --git a/src/main/java/org/ecocean/servlet/ServletUtilities.java b/src/main/java/org/ecocean/servlet/ServletUtilities.java index 398cf21512..a57fb3fe25 100644 --- a/src/main/java/org/ecocean/servlet/ServletUtilities.java +++ b/src/main/java/org/ecocean/servlet/ServletUtilities.java @@ -538,8 +538,6 @@ else if (request.isUserInRole("orgAdmin") && return true; } // allow WDP edit stenella frontalis cit sci encounters - // TODO make a mmore resonable way for researchers to ID and edit cit sci - // submissions if (!isOwner && "wdp".equals(request.getUserPrincipal().getName())) { List users = enc.getSubmitters(); boolean researcherSubmitted = false; @@ -703,39 +701,6 @@ public static String cleanFileName(String myString) { return myString.replaceAll("[^a-zA-Z0-9\\.\\-]", "_"); } - /* - * public static String cleanFileName(String aTagFragment) { - * final StringBuffer result = new StringBuffer(); - * - * final StringCharacterIterator iterator = new - * StringCharacterIterator(aTagFragment); - * char character = iterator.current(); - * while (character != CharacterIterator.DONE) { - * if (character == '<') { - * result.append("_"); - * } else if (character == '>') { - * result.append("_"); - * } else if (character == '\"') { - * result.append("_"); - * } else if (character == '\'') { - * result.append("_"); - * } else if (character == '\\') { - * result.append("_"); - * } else if (character == '&') { - * result.append("_"); - * } else if (character == ' ') { - * result.append("_"); - * } else if (character == '#') { - * result.append("_"); - * } else { - * //the char is not a special one - * //add it to the result as is result.append(character); - * } - * character = iterator.next(); - * } - * return result.toString(); - * } - */ public static String getEncounterUrl(String encID, HttpServletRequest request) { return (CommonConfiguration.getServerURL(request) + "/encounters/encounter.jsp?number=" + encID); @@ -899,20 +864,6 @@ public static String dataDir(String context, String rootWebappPath, String subdi return dataDir(context, rootWebappPath) + File.separator + subdir; } - /* - * //like above, but only need request passed public static String - * dataDir(HttpServletRequest request) { - * String context = "context0"; - * context = ServletUtilities.getContext(request); - * //String rootWebappPath = request.getServletContext().getRealPath("/"); // - * only in 3.0?? - * //String rootWebappPath = - * request.getSession(true).getServlet().getServletContext().getRealPath("/"); - * ServletContext s = request.getServletContext(); - * String rootWebappPath = "xxxxxx"; - * return dataDir(context, rootWebappPath); - * } - */ private static String loadOverrideText(String shepherdDataDir, String fileName, String langCode) { // System.out.println("Starting loadOverrideProps"); diff --git a/src/main/java/org/ecocean/servlet/SiteSearch.java b/src/main/java/org/ecocean/servlet/SiteSearch.java index c44a950a86..4f0b2fe65d 100644 --- a/src/main/java/org/ecocean/servlet/SiteSearch.java +++ b/src/main/java/org/ecocean/servlet/SiteSearch.java @@ -70,9 +70,6 @@ public class SiteSearch extends HttpServlet { hm.put("value", ind.getIndividualID()); hm.put("type", "individual"); - // - // TODO: Read species from db. See SimpleIndividual - // String gs = ind.getGenusSpeciesDeep(); if (gs != null) { hm.put("species", gs); @@ -105,9 +102,7 @@ public class SiteSearch extends HttpServlet { } String regex = ".*" + term.toLowerCase() + ".*"; - // // Query on Individuals - // Shepherd myShepherd = new Shepherd(context); myShepherd.setAction("SiteSearch.class"); myShepherd.beginDBTransaction(); @@ -122,9 +117,6 @@ public class SiteSearch extends HttpServlet { hm.put("value", ind.getIndividualID()); hm.put("type", "individual"); - // - // TODO: Read species from db. See SimpleIndividual - // String gs = ind.getGenusSpeciesDeep(); if (gs != null) { hm.put("species", gs); @@ -149,34 +141,6 @@ public class SiteSearch extends HttpServlet { myShepherd.rollbackDBTransaction(); myShepherd.closeDBTransaction(); } - /* - // - // Query on Users - // - filter = "this.fullName.toLowerCase().matches('" - + regex - + "') || this.username.toLowerCase().matches('" - + regex + "')"; - - query = myShepherd.getPM().newQuery(User.class); - query.setFilter(filter); - - @SuppressWarnings("unchecked") List users = (List) query.execute(); - - for (User user : users) { - HashMap hm = new HashMap(); - if (StringUtils.isBlank(user.getFullName())) { - hm.put("label", user.getUsername()); - } else { - hm.put("label", user.getFullName() + " (" + user.getUsername() + ")"); - } - hm.put("value", user.getUsername()); - hm.put("type", "user"); - list.add(hm); - } - - query.closeAll(); - */ // query locationIDs boolean moreLocationIDs = true; @@ -198,10 +162,7 @@ public class SiteSearch extends HttpServlet { } } // end query locationIDs - - // // return our results - // out.println(new Gson().toJson(list)); } } diff --git a/src/main/java/org/ecocean/servlet/SubmitSpotsAndTransformImage.java b/src/main/java/org/ecocean/servlet/SubmitSpotsAndTransformImage.java index 6a981a5a3e..7c5eff6bc4 100644 --- a/src/main/java/org/ecocean/servlet/SubmitSpotsAndTransformImage.java +++ b/src/main/java/org/ecocean/servlet/SubmitSpotsAndTransformImage.java @@ -187,9 +187,9 @@ note however, that there is the slim(??) chance someone does the *exact* same tr if (spotMAisNew) spotMA.setMinimalMetadata((int)Math.round(ma.getWidth() * sizeMult), (int)Math.round(ma.getHeight() * sizeMult), "image/jpeg"); -//////TODO how do we make this generic, for sided-spots (whalesharks dorsal) vs fluke vs dorsal etc... +// how do we make this generic, for sided-spots (whalesharks dorsal) vs fluke vs dorsal etc... JSONObject params = new JSONObject(); -// what *is* the deal with sidedness here? did we flip that in js ... i forget! TODO +// what *is* the deal with sidedness here? did we flip that in js ... i forget! String typePrefix = "org.ecocean.flukeEdge"; if (isDorsalFin) typePrefix = "org.ecocean.dorsalEdge"; if (refSpots.size() > 0) { @@ -243,7 +243,7 @@ note however, that there is the slim(??) chance someone does the *exact* same tr System.out.println( "ERROR: SubmitSpotsAndTranform failed to generate a spot MediaAsset!"); } - /////m.put("name", name); TODO return url to MA!! + /////m.put("name", name); return url to MA!! Gson gson = new Gson(); out.println(gson.toJson(m)); diff --git a/src/main/java/org/ecocean/servlet/TranslateQuery.java b/src/main/java/org/ecocean/servlet/TranslateQuery.java index 0304f1573c..9fa1f5c58c 100644 --- a/src/main/java/org/ecocean/servlet/TranslateQuery.java +++ b/src/main/java/org/ecocean/servlet/TranslateQuery.java @@ -30,7 +30,7 @@ * required argument. * @requestParameter query a mongo-query-syntax JSON object defining the search on 'class'. * @requestParameter rangeMin the start index of the results. E.g. rangeMin=10 returns search results starting with the 10th entry. Default 0. Note - * that sorting options are required (TODO) for this to be as useful as we'd like, as results are currently returned in whatever order JDOQL needs. + * that sorting options are required for this to be as useful as we'd like, as results are currently returned in whatever order JDOQL needs. * @requestParameter range the end index of the results, similarly to rangeMin. Defaults to 100 because the server is slow on anything longer, and * it's hard to imagine a UI call that would need so many objects. * @returns a 2-item JSONObject: {assets: , queryMetadata: } diff --git a/src/main/java/org/ecocean/servlet/UserConsolidate.java b/src/main/java/org/ecocean/servlet/UserConsolidate.java index 88273414d1..954300ec28 100644 --- a/src/main/java/org/ecocean/servlet/UserConsolidate.java +++ b/src/main/java/org/ecocean/servlet/UserConsolidate.java @@ -239,7 +239,6 @@ public static void consolidateCollaborations(Shepherd myShepherd, User userToRet currentCollaboration.getUsername2()); System.out.println("currentCollaboration after swap is: " + currentCollaboration.toString()); - // TODO I can't tell if this persists yet... } // now we know for sure that userName1 of the collaboration is our userToBeConsolidated.getUsername()... if (Util.stringExists(userToRetain.getUsername())) { @@ -364,13 +363,9 @@ public static void consolidateRoles(Shepherd myShepherd, User userToRetain, public static void consolidateEncounterSubmitterIds(Shepherd myShepherd, User userToRetain, User userToBeConsolidated) { // System.out.println("dedupe consolidating encounter submitter IDs in encounters containing user: " + userToBeConsolidated.toString() + " - // into user: " + userToRetain.toString()); //TODO comment out + // into user: " + userToRetain.toString()); if (Util.stringExists(userToBeConsolidated.getUsername()) && - Util.stringExists(userToRetain.getUsername())) { // can't look it up if - // userToBeConsolidated doesn't have - // username and can't change it to - // something if userToRetain doesn't - // have username + Util.stringExists(userToRetain.getUsername())) { // can't look it up if userToBeConsolidated doesn't have username and can't change it to something if have username String filter = "SELECT FROM org.ecocean.Encounter WHERE this.submitterID=='" + userToBeConsolidated.getUsername() + "' "; System.out.println("dedupe query is: " + filter); @@ -450,10 +445,7 @@ public static void consolidateEncounterInformOthers(Shepherd myShepherd, User us } public static int consolidateUsersAndNameless(Shepherd myShepherd, User useMe, - List dupes) { // TODO this is not up-to-date with consolidateUser. - // Use that as a model when the time comes. Lots of - // wonky db commit weirdness, so be careful out - // there -MF + List dupes) { PersistenceManager persistenceManager = myShepherd.getPM(); dupes.remove(useMe); @@ -477,14 +469,6 @@ public static int consolidateUsersAndNameless(Shepherd myShepherd, User useMe, currentDupe); } } - // TODO assign usernameless encounters to public maybe using the below, and maybe not - // List usernameLessEncounters= getEncountersForUsersThatDoNotHaveUsernameButHaveSameEmailAddress(myShepherd,currentDupe); - // for(int j=0;j submitterOccurrences = getOccurrencesForUser(persistenceManager, currentDupe); @@ -653,15 +637,12 @@ public static List getSimilarUsers(User user, PersistenceManager persisten public static void consolidateUsernameless(Shepherd myShepherd, Encounter enc, User useMe, User currentUser) { - // TODO flesh this out when you have a "Public" user // System.out.println("dedupe assigning usernameless encounters with useMe's username for encounter: " + enc.getCatalogNumber()); List subs = enc.getSubmitters(); if (subs.contains(currentUser) || subs.size() == 0) { // System.out.println("dedupe here’s what you’re removing: " + currentUser.getUsername()); // System.out.println("dedupe here’s what you’re adding: " + useMe.getUsername()); - // subs.remove(currentUser); //TODO comment back in - // subs.add(useMe); //TODO comment back in } enc.setSubmitters(subs); myShepherd.commitDBTransaction(); @@ -970,10 +951,7 @@ public static int getNumberEncountersUsingSubmitterId(User user, return size; // if it's indeterminable, it's false } else { String filter = "SELECT FROM org.ecocean.Encounter where this.submitterID==\"" + - user.getUsername() + "\""; // don't check using email address - // because you are using this in an - // effort to deduplicate accounts with - // matching email addresses. + user.getUsername() + "\""; // don't check using email address because you are using this in an effort to deduplicate accounts with matching email addresses. List encs = new ArrayList(); Query query = persistenceManager.newQuery(filter); Collection c = (Collection)(query.execute()); @@ -1020,8 +998,7 @@ public static List getAllUsersWithEmailAddressWithOptAdditionalFilter(Stri "SELECT FROM org.ecocean.User where this.emailAddress.toLowerCase()==emailVal PARAMETERS String emailVal"; } Query query = persistenceManager.newQuery(filter); - Collection c = (Collection)(query.execute(emailAddress.toLowerCase())); // note for posterity: trying this query with ?1 variables or - // named variables was not successful. + Collection c = (Collection)(query.execute(emailAddress.toLowerCase())); // note for posterity: trying this query with ?1 variables or named variables was not successful. if (c != null) { returnUsers = new ArrayList(c); } diff --git a/src/main/java/org/ecocean/servlet/export/ExportExcelIndividualReport.java b/src/main/java/org/ecocean/servlet/export/ExportExcelIndividualReport.java index 07561746b4..65b835341c 100644 --- a/src/main/java/org/ecocean/servlet/export/ExportExcelIndividualReport.java +++ b/src/main/java/org/ecocean/servlet/export/ExportExcelIndividualReport.java @@ -35,12 +35,6 @@ public void doPost(HttpServletRequest request, HttpServletResponse response) context = ServletUtilities.getContext(request); Shepherd myShepherd = new Shepherd(context); - // String query = request.getParameter("query"); - // String[] headers = request.getParameterValues("headers"); - // String[] columns = request.getParameterValues("columns"); - // Collection c = (Collection) myShepherd.getPM().newQuery(query).execute(); - // Vector v = new Vector(c); - // Class cls = v.get(0).getClass(); String filename = request.getParameter("filename"); if (filename == null) { Calendar cal = Calendar.getInstance(); @@ -52,8 +46,6 @@ public void doPost(HttpServletRequest request, HttpServletResponse response) File excelFile = new File("/tmp/" + filename); FileOutputStream exfos = new FileOutputStream(excelFile); OutputStreamWriter exout = new OutputStreamWriter(exfos); - // WritableCellFormat floatFormat = new WritableCellFormat(NumberFormats.FLOAT); - // WritableCellFormat integerFormat = new WritableCellFormat(NumberFormats.INTEGER); WritableWorkbook workbook = Workbook.createWorkbook(excelFile); WritableSheet sheet = workbook.createSheet(sheetname, 0); int sheetRow = 0; @@ -94,13 +86,6 @@ public void doPost(HttpServletRequest request, HttpServletResponse response) if (enc.getMonth() > 0) encCal.set(Calendar.MONTH, enc.getMonth() - 1); if (enc.getDay() > 0) encCal.set(Calendar.DAY_OF_MONTH, enc.getDay()); } -/* oops... snuck in from lewa-master maybe? FIXME later and clean this up! - Double ageFirstSighted = indiv.getAgeAtFirstSighting(); - String ageFirstSightedString = ""; - if (ageFirstSighted!=null) { - ageFirstSightedString = String.valueOf(ageFirstSighted); - } - */ Vector
- " onClick="$('#ia-match-filter-location .item input').prop('checked', true); iaMatchFilterLocationCountUpdate();" /> " @@ -6981,16 +6969,6 @@ $(".search-collapse-header").click(function(){
-
<%=encprops.getProperty("chooseAlgorithm")%>
<% diff --git a/src/main/webapp/encounters/encounterCR.jsp b/src/main/webapp/encounters/encounterCR.jsp index df762588b6..6858b4034e 100755 --- a/src/main/webapp/encounters/encounterCR.jsp +++ b/src/main/webapp/encounters/encounterCR.jsp @@ -227,7 +227,7 @@ margin-bottom: 8px !important; controlEl: document.getElementById('cr-info') }); - //sometimes .toWork() doesnt fire via .init() above. wtf? TODO fix! + //sometimes .toWork() doesnt fire via .init() above. wtf? window.setTimeout(function() { CRtool.toWork(); }, 1100); }); diff --git a/src/main/webapp/encounters/encounterCropTool.jsp b/src/main/webapp/encounters/encounterCropTool.jsp index 0cc1a9cdde..6f06c96f51 100755 --- a/src/main/webapp/encounters/encounterCropTool.jsp +++ b/src/main/webapp/encounters/encounterCropTool.jsp @@ -24,10 +24,6 @@ if (ma == null) throw new Exception("unknown MediaAsset id=" + imageID); Encounter enc = Encounter.findByMediaAsset(ma, myShepherd); if (enc == null) throw new Exception("could not find Encounter for MediaAsset id=" + imageID); - -//TODO we might(?) want to get the _mid sized image at some point?? - - //allow passing of dorsal-ness by way of param: boolean passedDorsal = (request.getParameter("isDorsalFin") != null); boolean isDorsalFin = false; @@ -205,7 +201,6 @@ function spotsSave() { var sp = itool.spotsVisible(); console.log('sp = %o', sp); if (sp.length < 1) return; -//TODO verify we really have all we need (like when we updateSaveButton()) $('#imageTools-buttons').hide(); $('#imageTools-message').html('saving spot data...'); diff --git a/src/main/webapp/encounters/encounterMediaGallery.jsp b/src/main/webapp/encounters/encounterMediaGallery.jsp index a2fb1d75ec..04c3d76f9f 100755 --- a/src/main/webapp/encounters/encounterMediaGallery.jsp +++ b/src/main/webapp/encounters/encounterMediaGallery.jsp @@ -202,7 +202,7 @@ function forceLink(el) { //end caption render JSP side - // SKIPPING NON-TRIVIAL ANNOTATIONS FOR NOW! TODO + // SKIPPING NON-TRIVIAL ANNOTATIONS FOR NOW! //if (!ann.isTrivial()) continue; ///or not? @@ -253,8 +253,7 @@ function forceLink(el) { if ((ann.getFeatures() == null) || (ann.getFeatures().size() < 1)) continue; - //TODO here we skip unity feature annots. BETTER would be to look at detectionStatus and feature type etc! - // also: prob should check *what* is detected. :) somewhere.... + // here we skip unity feature annots. also: prob should check *what* is detected. if (ann.getFeatures().get(0).isUnity()) continue; //assume only 1 feature !! System.out.println("\n\n==== got detected frame! " + ma + " -> " + ann.getFeatures().get(0) + " => " + ann.getFeatures().get(0).getParametersAsString()); j.put("extractFPS", ma.getParameters().optDouble("extractFPS",0)); @@ -962,7 +961,6 @@ console.info(' ===========> %o %o', el, enh); if (!opt.init) opt.init = []; //maybe created if logged in? opt.init.push( - //function(el, enh) { enhancerDisplayAnnots(el, enh); }, //TODO fix for scaled/watermark image function(el, enh) { enhancerCaption(el, enh); } ); @@ -1070,7 +1068,6 @@ function featureSortOrder(feat) { function enhancerDisplayFeature(el, opt, focusAnnId, feat, zdelta, mediaAssetId) { if (!feat.type) return; //unity, skip if (!feat.parameters) return; //wtf??? - //TODO other than boundingBox var scale = el.data('enhancerScale') || 1; console.log('FEAT!!!!!!!!!!!!!!! scale=%o feat=%o', scale, feat); let widthScale = el; //.width;// / el.naturalWidth; @@ -1133,7 +1130,6 @@ console.log('FEAT!!!!!!!!!!!!!!! scale=%o feat=%o', scale, feat); } function checkImageEnhancerResize() { -//TODO update enhancerScale when this happens! var needUpdate = false; $('.image-enhancer-wrapper').each(function(i,el) { var jel = $(el); @@ -1336,8 +1332,6 @@ function refreshKeywordsForMediaAsset(mid, data) { } } - //TODO do we need to FIXME this for when a single MediaAsset appears multiple times??? (gallery style) - console.log("in refreshKeywordsForMediaAsset, looking for #asset-id-"+mid); $('#asset-id-'+mid).each(function(i,el) { $(el).find('.image-enhancer-keyword-wrapper-hover').empty(); @@ -1700,8 +1694,7 @@ function _parseDetection(task) { rtn.msg = 'Detection task found, but no results. Possibly still processing?'; } else { for (var i = 0 ; i < task.results.length ; i++) { - if (!task.results[i].status) continue; //kinda cheap hack.. should probably investigate this TODO - //TODO actually check out what most recent has to say here.... + if (!task.results[i].status) continue; //kinda cheap hack rtn.state = 'complete'; rtn.msg = 'most recent result status _action=' + task.results[i].status._action; break; diff --git a/src/main/webapp/encounters/encounterSpotTool.jsp b/src/main/webapp/encounters/encounterSpotTool.jsp index d1a6ad2a65..ac373b7f46 100755 --- a/src/main/webapp/encounters/encounterSpotTool.jsp +++ b/src/main/webapp/encounters/encounterSpotTool.jsp @@ -373,7 +373,7 @@ function nextAvailableSpotType(old) { function spotTypeAvailable(t) { - if (t == 'spot') return true; //TODO any limit? + if (t == 'spot') return true; for (var i = 0 ; i < itool.spots.length ; i++) { if (itool.spots[i].type == t) return false; } @@ -482,7 +482,6 @@ function spotsSave() { var sp = itool.spotsVisible(); console.log('sp = %o', sp); if (sp.length < 1) return; -//TODO verify we really have all we need (like when we updateSaveButton()) $('#imageTools-spot-type-picker').hide(); $('#imageTools-buttons').hide(); diff --git a/src/main/webapp/encounters/exportSearchResults.jsp b/src/main/webapp/encounters/exportSearchResults.jsp index 8fbac75ef7..f909f1a12d 100755 --- a/src/main/webapp/encounters/exportSearchResults.jsp +++ b/src/main/webapp/encounters/exportSearchResults.jsp @@ -40,7 +40,6 @@ EncounterQueryResult queryResult = EncounterQueryProcessor.processQuery(myShepherd, request, order); rEncounters = queryResult.getResult(); blocked = Encounter.blocked(rEncounters, request); - //TODO styles to follow can go in _encounter-pages.less if they don't conflict with ones already in there %> diff --git a/src/main/webapp/encounters/mappedSearchResults.jsp b/src/main/webapp/encounters/mappedSearchResults.jsp index c345ea8c51..63397c65ff 100755 --- a/src/main/webapp/encounters/mappedSearchResults.jsp +++ b/src/main/webapp/encounters/mappedSearchResults.jsp @@ -71,7 +71,6 @@ List allSpeciesColors=CommonConfiguration.getIndexedPropertyValues("genusSpeciesColor",context); int numSpeciesColors=allSpeciesColors.size(); - //TODO styles to follow can go in _encounter-pages.less if they don't conflict with ones already in there %> diff --git a/src/main/webapp/encounters/searchResults.jsp b/src/main/webapp/encounters/searchResults.jsp index 5ed0fb116a..19cbacdecd 100755 --- a/src/main/webapp/encounters/searchResults.jsp +++ b/src/main/webapp/encounters/searchResults.jsp @@ -859,7 +859,7 @@ function _colFileName(o) { var outStrings = []; for (id in o.get('annotations')) { var ann = o.get('annotations')[id]; - //note: assuming 0th feature "may be bad" ? TODO + //note: assuming 0th feature "may be bad" if (ann.features && ann.features.length && ann.features[0].mediaAsset && ann.features[0].mediaAsset.filename) { outStrings.push(ann.features[0].mediaAsset.filename); } diff --git a/src/main/webapp/encounters/searchResultsAnalysis.jsp b/src/main/webapp/encounters/searchResultsAnalysis.jsp index fc2b26a209..62389064dd 100755 --- a/src/main/webapp/encounters/searchResultsAnalysis.jsp +++ b/src/main/webapp/encounters/searchResultsAnalysis.jsp @@ -9,7 +9,6 @@ Properties encprops = new Properties(); //encprops.load(getClass().getResourceAsStream("/bundles/" + langCode + "/searchResultsAnalysis.properties")); encprops=ShepherdProperties.getProperties("searchResultsAnalysis.properties", langCode, context); -//TODO styles to follow can go in _encounter-pages.less if they don't conflict with ones already in there %> diff --git a/src/main/webapp/encounters/thumbnailSearchResults.jsp b/src/main/webapp/encounters/thumbnailSearchResults.jsp index 15c769c56c..8d0ca6df44 100755 --- a/src/main/webapp/encounters/thumbnailSearchResults.jsp +++ b/src/main/webapp/encounters/thumbnailSearchResults.jsp @@ -186,7 +186,6 @@
<% -//TODO styles above can go in _encounter-pages.less if they don't conflict with ones already in there String rq = ""; if (request.getQueryString() != null) { rq = request.getQueryString(); diff --git a/src/main/webapp/header.jsp b/src/main/webapp/header.jsp index 0f1dac52a1..1e8ac3b1cf 100755 --- a/src/main/webapp/header.jsp +++ b/src/main/webapp/header.jsp @@ -185,7 +185,7 @@ if(request.getUserPrincipal()!=null){ - + diff --git a/src/main/webapp/iaResults.jsp b/src/main/webapp/iaResults.jsp index a716e018d4..3808f03356 100755 --- a/src/main/webapp/iaResults.jsp +++ b/src/main/webapp/iaResults.jsp @@ -129,7 +129,7 @@ String gaveUpWaitingMsg = "Gave up trying to obtain results. Refresh page to kee -//TODO security for this stuff, obvs? +// security could be better for this stuff //quick hack to set id & approve String taskId = request.getParameter("taskId"); @@ -139,7 +139,7 @@ String taskId = request.getParameter("taskId"); %> - + @@ -231,7 +231,7 @@ h4.intro.accordion .rotate-chevron.down { String individualScoreSelected = (individualScores) ? " selected btn-selected" : ""; String annotationScoreSelected = (!individualScores) ? " selected btn-selected" : ""; //String currentUrl = javax.servlet.http.HttpUtils.getRequestURL(request).toString(); - String currentUrl = request.getRequestURL().toString() + "?" + request.getQueryString(); // silly how complicated this is---TODO: ServletUtilities convenience func? + String currentUrl = request.getRequestURL().toString() + "?" + request.getQueryString(); System.out.println("Current URL = "+currentUrl); // linkUrl removes scoreType (which may or may not be present) then adds the opposite of the current scoreType String linkUrl = currentUrl; @@ -261,7 +261,7 @@ h4.intro.accordion .rotate-chevron.down { - +
@@ -1065,7 +1065,7 @@ function displayAnnotDetails(taskId, num, illustrationUrl, acmIdPassed) { } } acmId=acmIdPassed; - if (mainAnnId) $('#task-' + taskId + ' .annot-summary-' + acmId).data('annid', mainAnnId); //TODO what if this fails? + if (mainAnnId) $('#task-' + taskId + ' .annot-summary-' + acmId).data('annid', mainAnnId); if (mainAsset) { //console.info('mainAsset -> %o', mainAsset); //console.info('illustrationUrl '+illustrationUrl); @@ -1325,7 +1325,6 @@ console.info('qdata[%s] = %o', taskId, qdata); // Illustration if (illustrationUrl) { var selector = '#task-' + taskId + ' .annot-summary-' + acmId; - // TODO: generify var iaBase = wildbookGlobals.iaStatus.map.iaURL; illustrationUrl = iaBase+illustrationUrl let resultIndex = $(selector).closest(".has-data-index").data("index"); @@ -1366,7 +1365,7 @@ console.info('qdata[%s] = %o', taskId, qdata); imgInfo += '
Alternate references:
- - - -
@@ -1398,14 +1361,6 @@ if(CommonConfiguration.showProperty("showLifestage",context)){