diff --git a/src/main/java/org/ecocean/identity/IBEISIA.java b/src/main/java/org/ecocean/identity/IBEISIA.java index bd3f7e7884..04c79968d1 100644 --- a/src/main/java/org/ecocean/identity/IBEISIA.java +++ b/src/main/java/org/ecocean/identity/IBEISIA.java @@ -2049,15 +2049,61 @@ public static JSONObject processCallback(String taskID, JSONObject resp, String } } if (needIdentifying.size() > 0) { - Task task = IA.intakeAnnotations(myShepherd2, needIdentifying, parentTask, false); - // Here is a place we check downstream. IA.intakeAnnotations() will check the anns vs the identification classes in IA.properties, - // and return null if nobody was valid. - if (task != null) { - rtn.put("identificationTaskId", task.getId()); - if (parentTask != null) parentTask.addChild(task); - myShepherd2.storeNewTask(task); - } - } else { + + //split the results into encounters + HashMap> needIdentifyingMap = new HashMap>(); + for(Annotation annot:needIdentifying) { + Encounter enc=annot.findEncounter(myShepherd2); + if(enc!=null) { + if(needIdentifyingMap.containsKey(enc.getCatalogNumber())) { + ArrayList annots = needIdentifyingMap.get(enc.getCatalogNumber()); + annots.add(annot); + needIdentifyingMap.put(enc.getCatalogNumber(), annots); + } + else { + ArrayList annots = new ArrayList(); + annots.add(annot); + needIdentifyingMap.put(enc.getCatalogNumber(), annots); + } + } + } + + //check number of encounters + System.out.println("ZZZZ Sending "+needIdentifyingMap.keySet().size() +" encounters to ID."); + + //send to ID by Encounter + for(String encUUID:needIdentifyingMap.keySet()) { + + System.out.println("ZZZZ Sending enc "+encUUID+" to ID."); + + ArrayList annots = needIdentifyingMap.get(encUUID); + + JSONObject j = new JSONObject(); + JSONObject taskParameters = j.optJSONObject("taskParameters"); + if (taskParameters == null) taskParameters = new JSONObject(); + JSONObject tp = new JSONObject(); + JSONObject mf = new JSONObject(); + taskParameters.put("matchingSetFilter", mf); + + Task subParentTask = new Task(); + subParentTask.setParameters(taskParameters); + myShepherd.storeNewTask(subParentTask); + myShepherd.updateDBTransaction(); + + Task task = IA.intakeAnnotations(myShepherd2, annots, subParentTask, false); + // Here is a place we check downstream. IA.intakeAnnotations() will check the anns vs the identification classes in IA.properties, + // and return null if nobody was valid. + if (task != null) { + rtn.put("identificationTaskId", task.getId()); + if (subParentTask != null) subParentTask.addChild(task); + myShepherd2.storeNewTask(task); + } + + } + + + } + else { System.out.println( "[INFO]: No annotations were suitable for identification. Check resulting identification class(es)."); myShepherd2.rollbackDBTransaction();