Skip to content

Commit

Permalink
handle removeTrivial stuff, some bugfixes
Browse files Browse the repository at this point in the history
  • Loading branch information
naknomum committed Jan 14, 2025
1 parent 2c6a0b0 commit 7a533c2
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 10 deletions.
45 changes: 37 additions & 8 deletions src/main/java/org/ecocean/Annotation.java
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,8 @@ public boolean isTrivial() {
for (Feature ft : getFeatures()) {
if (ft.isUnity()) return true;
}
// prevents zero-values from return true on final test
if ((getWidth() == 0) || (getHeight() == 0)) return false;
return (!needsTransform() && (getWidth() == (int)ma.getWidth()) &&
(getHeight() == (int)ma.getHeight()));
}
Expand Down Expand Up @@ -1245,12 +1247,12 @@ public static Base createFromApi(JSONObject payload, List<File> files, Shepherd
fparams.put("viewpoint", viewpoint); // not sure when/how this is used, but seems here historically
fparams.put("_manualAnnotationViaApiV3", System.currentTimeMillis());
Feature ft = new Feature("org.ecocean.boundingBox", fparams);

ma.addFeature(ft);
ma.setDetectionStatus("complete");

Annotation ann = new Annotation(null, ft, iaClass);
ann.setViewpoint(viewpoint);
ma.addFeature(ft);
ma.setDetectionStatus("complete");
myShepherd.getPM().makePersistent(ft);
myShepherd.getPM().makePersistent(ann);
/*
if (enc != null) {
String context = myShepherd.getContext();
Expand All @@ -1259,29 +1261,36 @@ public static Base createFromApi(JSONObject payload, List<File> files, Shepherd
}
}
*/
// NOTE: manualAnnotation.jsp once allowed featureId to be passed; that functionality is not handled here
//
// we replace trivial if applicable; otherwise this logic determines if we should
// clone the encounter (based off historic logic in manualAnnotation.jsp)
if (enc != null) {
boolean cloneEncounter = false;
// we would expect at least a trivial annotation, so if annots>=2, we know we need to clone
if ((annots.size() > 1) && (iaClass != null)) {
System.out.println("DEBUG Annotation.createFromApi(): cloneEncounter [0]");
cloneEncounter = true;

// also don't clone if this is a part
// if the one annot isn't trivial, then we have to clone the encounter as well
} else if ((annots.size() == 1) && !annots.get(0).isTrivial() && (iaClass != null) &&
(iaClass.indexOf("+") == -1)) {
System.out.println("DEBUG Annotation.createFromApi(): cloneEncounter [1]");
cloneEncounter = true;
// exception case - if there is only one annotation and it is a part
Annotation annot1 = annots.get(0);
if ((annot1.getIAClass() != null) && (annot1.getIAClass().indexOf("+") != -1)) {
System.out.println("DEBUG Annotation.createFromApi(): cloneEncounter [2]");
cloneEncounter = false;
}
// exception case - if there is only one annotation and it is a part
} else if ((annots.size() == 1) && !annots.get(0).isTrivial() && (iaClass != null) &&
(iaClass.indexOf("+") > -1)) {
System.out.println("DEBUG Annotation.createFromApi(): cloneEncounter [3]");
Annotation annot1 = annots.get(0);
if ((annot1.getIAClass() != null) && (annot1.getIAClass().indexOf("+") != -1)) {
System.out.println("DEBUG Annotation.createFromApi(): cloneEncounter [4]");
cloneEncounter = true;
}
}
Expand All @@ -1303,6 +1312,8 @@ public static Base createFromApi(JSONObject payload, List<File> files, Shepherd
occ.addEncounter(enc);
myShepherd.getPM().makePersistent(occ);
}
System.out.println("Annotation.createFromApi(): " + ann + " added to clone " +
clone + " in " + occ);
myShepherd.updateDBTransaction();
} catch (Exception ex) {
throw new ApiException("cloning encounter " + enc.getId() + " failed: " +
Expand All @@ -1312,6 +1323,26 @@ public static Base createFromApi(JSONObject payload, List<File> files, Shepherd
enc.addAnnotation(ann);
enc.addComments("<p data-annot-id=\"" + ann.getId() +
"\"><i>new Annotation</i> manually added by " + user.getDisplayName() + "</p>");
System.out.println("Annotation.createFromApi(): " + ann + " added to " + enc);
}
}
// NOTE: manualAnnotation.jsp allowed 'removeTrivial' (boolean) to be set via url, but was default true
Annotation foundTrivial = null; // note this will only remove (at most) ONE (but "should never" have > 1 anyway)
for (Annotation a : ma.getAnnotations()) {
if (a.isTrivial()) foundTrivial = a;
}
if (foundTrivial == null) {
System.out.println(
"Annotation.createFromApi(): no trivial annotation found to remove from " + ma);
} else {
foundTrivial.detachFromMediaAsset();
if (enc == null) {
System.out.println("Annotation.createFromApi(): removeTrivial detached " +
foundTrivial + " (and Feature) from " + ma);
} else {
enc.removeAnnotation(foundTrivial);
System.out.println("Annotation.createFromApi(): removeTrivial detached " +
foundTrivial + " (and Feature) from " + ma + " and " + enc);
}
}
return ann;
Expand Down Expand Up @@ -1351,10 +1382,8 @@ public static Object validateFieldValue(String fieldName, JSONObject data)
returnValue = data.optDouble(fieldName, 9999.9);
double dval = (double)returnValue;
if (dval == 9999.9) {
error.put("code", ApiException.ERROR_RETURN_CODE_REQUIRED);
throw new ApiException(exMessage, error);
}
if ((dval < -6.28318) || (dval > 6.28318)) {
returnValue = 0.0d; // theta (passed-in) is optional, but results in 0.0
} else if ((dval < -6.28318) || (dval > 6.28318)) {
error.put("code", ApiException.ERROR_RETURN_CODE_INVALID);
error.put("value", dval);
throw new ApiException("invalid theta value in radians", error);
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/org/ecocean/api/BaseObject.java
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,7 @@ protected JSONObject processPost(HttpServletRequest request, String[] args, JSON
myShepherd.commitDBTransaction();
}
// not sure what this is for, but servlet/EncounterForm did it so guessing its important
if (encounterForIA != null)
org.ecocean.ShepherdPMF.getPMF(context).getDataStoreCache().evictAll();
org.ecocean.ShepherdPMF.getPMF(context).getDataStoreCache().evictAll();
} else {
myShepherd.rollbackDBTransaction();
}
Expand Down

0 comments on commit 7a533c2

Please sign in to comment.