Skip to content

Commit

Permalink
Merge pull request #1000 from WildMeOrg/910_individuals_opensearch_in…
Browse files Browse the repository at this point in the history
…dexing

MarkedIndividual indexing via OpenSearch
  • Loading branch information
naknomum authored Feb 3, 2025
2 parents 4c6aff1 + 925e233 commit aae82a2
Show file tree
Hide file tree
Showing 8 changed files with 330 additions and 11 deletions.
4 changes: 2 additions & 2 deletions src/main/java/org/ecocean/Annotation.java
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public long setVersion() {

public JSONObject opensearchMapping() {
JSONObject map = super.opensearchMapping();
JSONObject keywordType = new org.json.JSONObject("{\"type\": \"keyword\"}");
JSONObject keywordType = new JSONObject("{\"type\": \"keyword\"}");

/*
JSONObject keywordNormalType = new org.json.JSONObject(
Expand Down Expand Up @@ -1373,7 +1373,7 @@ public static Base createFromApi(JSONObject payload, List<File> files, Shepherd
public static Object validateFieldValue(String fieldName, JSONObject data)
throws ApiException {
if (data == null) throw new ApiException("empty payload");
org.json.JSONObject error = new org.json.JSONObject();
JSONObject error = new JSONObject();
error.put("fieldName", fieldName);
String exMessage = "invalid value for " + fieldName;
Object returnValue = null;
Expand Down
45 changes: 45 additions & 0 deletions src/main/java/org/ecocean/Encounter.java
Original file line number Diff line number Diff line change
Expand Up @@ -4311,6 +4311,51 @@ public void opensearchDocumentSerializer(JsonGenerator jgen, Shepherd myShepherd
}
}

public void opensearchIndexDeep()
throws IOException {
this.opensearchIndex();

final String encId = this.getId();
ExecutorService executor = Executors.newFixedThreadPool(4);
Runnable rn = new Runnable() {
public void run() {
Shepherd bgShepherd = new Shepherd("context0");
bgShepherd.setAction("Encounter.opensearchIndexDeep_" + encId);
bgShepherd.beginDBTransaction();
try {
Encounter enc = bgShepherd.getEncounter(encId);
if ((enc == null) || !enc.hasMarkedIndividual()) {
// bgShepherd.rollbackAndClose();
executor.shutdown();
return;
}
MarkedIndividual indiv = enc.getIndividual();
System.out.println("opensearchIndexDeep() background indexing indiv " +
indiv.getId() + " via enc " + encId);
try {
indiv.opensearchIndex();
} catch (Exception ex) {
System.out.println("opensearchIndexDeep() background indexing " +
indiv.getId() + " FAILED: " + ex.toString());
ex.printStackTrace();
}
} catch (Exception e) {
System.out.println("opensearchIndexDeep() backgrounding Encounter " + encId +
" hit an exception.");
e.printStackTrace();
} finally {
bgShepherd.rollbackAndClose();
}
System.out.println("opensearchIndexDeep() backgrounding Encounter " + encId +
" finished.");
executor.shutdown();
}
};
System.out.println("opensearchIndexDeep() begin backgrounding indiv for " + this);
executor.execute(rn);
System.out.println("opensearchIndexDeep() [foreground] finished for Encounter " + encId);
}

// given a doc from opensearch, can user access it?
public static boolean opensearchAccess(org.json.JSONObject doc, User user,
Shepherd myShepherd) {
Expand Down
Loading

0 comments on commit aae82a2

Please sign in to comment.