Skip to content

Commit bdc9371

Browse files
Merge pull request #1341 from WildMeOrg/dont_orphan_asset_on_annotation_patch
remove annotation does not remove image
2 parents 59d0f5d + afc7e61 commit bdc9371

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/main/java/org/ecocean/api/patch/EncounterPatchValidator.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,8 +233,21 @@ public static JSONObject applyPatch(Encounter enc, JSONObject patch, User user,
233233
if (ann == null)
234234
throw new ApiException("no such annotation id=" + value.toString(),
235235
ApiException.ERROR_RETURN_CODE_INVALID);
236+
MediaAsset ma = ann.getMediaAsset();
236237
ann.detachFromTasks(myShepherd);
237238
enc.removeAnnotation(ann);
239+
ann.detachFromMediaAsset();
240+
// "most likely" this encounter is now detached from the asset, but we want them still connected
241+
// TODO parts might be connecting these, but how do we determine if we still need to add the trivial?
242+
if (ma != null) {
243+
// note this kind of replicates ann.revertToTrivial() but that searches out the enc, which we already have
244+
System.out.println(
245+
"[INFO] applyPatch() removed annotation, reconnecting with trivial annotation to "
246+
+ enc);
247+
Annotation triv = new Annotation(enc.getTaxonomyString(), ma);
248+
enc.addAnnotation(triv);
249+
myShepherd.getPM().makePersistent(triv);
250+
}
238251
myShepherd.getPM().deletePersistent(ann);
239252
value = ann;
240253
} else if (path.equals("occurrenceId")) {

0 commit comments

Comments
 (0)