Skip to content

Commit aae82a2

Browse files
authored
Merge pull request #1000 from WildMeOrg/910_individuals_opensearch_indexing
MarkedIndividual indexing via OpenSearch
2 parents 4c6aff1 + 925e233 commit aae82a2

File tree

8 files changed

+330
-11
lines changed

8 files changed

+330
-11
lines changed

src/main/java/org/ecocean/Annotation.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ public long setVersion() {
134134

135135
public JSONObject opensearchMapping() {
136136
JSONObject map = super.opensearchMapping();
137-
JSONObject keywordType = new org.json.JSONObject("{\"type\": \"keyword\"}");
137+
JSONObject keywordType = new JSONObject("{\"type\": \"keyword\"}");
138138

139139
/*
140140
JSONObject keywordNormalType = new org.json.JSONObject(
@@ -1373,7 +1373,7 @@ public static Base createFromApi(JSONObject payload, List<File> files, Shepherd
13731373
public static Object validateFieldValue(String fieldName, JSONObject data)
13741374
throws ApiException {
13751375
if (data == null) throw new ApiException("empty payload");
1376-
org.json.JSONObject error = new org.json.JSONObject();
1376+
JSONObject error = new JSONObject();
13771377
error.put("fieldName", fieldName);
13781378
String exMessage = "invalid value for " + fieldName;
13791379
Object returnValue = null;

src/main/java/org/ecocean/Encounter.java

+45
Original file line numberDiff line numberDiff line change
@@ -4311,6 +4311,51 @@ public void opensearchDocumentSerializer(JsonGenerator jgen, Shepherd myShepherd
43114311
}
43124312
}
43134313

4314+
public void opensearchIndexDeep()
4315+
throws IOException {
4316+
this.opensearchIndex();
4317+
4318+
final String encId = this.getId();
4319+
ExecutorService executor = Executors.newFixedThreadPool(4);
4320+
Runnable rn = new Runnable() {
4321+
public void run() {
4322+
Shepherd bgShepherd = new Shepherd("context0");
4323+
bgShepherd.setAction("Encounter.opensearchIndexDeep_" + encId);
4324+
bgShepherd.beginDBTransaction();
4325+
try {
4326+
Encounter enc = bgShepherd.getEncounter(encId);
4327+
if ((enc == null) || !enc.hasMarkedIndividual()) {
4328+
// bgShepherd.rollbackAndClose();
4329+
executor.shutdown();
4330+
return;
4331+
}
4332+
MarkedIndividual indiv = enc.getIndividual();
4333+
System.out.println("opensearchIndexDeep() background indexing indiv " +
4334+
indiv.getId() + " via enc " + encId);
4335+
try {
4336+
indiv.opensearchIndex();
4337+
} catch (Exception ex) {
4338+
System.out.println("opensearchIndexDeep() background indexing " +
4339+
indiv.getId() + " FAILED: " + ex.toString());
4340+
ex.printStackTrace();
4341+
}
4342+
} catch (Exception e) {
4343+
System.out.println("opensearchIndexDeep() backgrounding Encounter " + encId +
4344+
" hit an exception.");
4345+
e.printStackTrace();
4346+
} finally {
4347+
bgShepherd.rollbackAndClose();
4348+
}
4349+
System.out.println("opensearchIndexDeep() backgrounding Encounter " + encId +
4350+
" finished.");
4351+
executor.shutdown();
4352+
}
4353+
};
4354+
System.out.println("opensearchIndexDeep() begin backgrounding indiv for " + this);
4355+
executor.execute(rn);
4356+
System.out.println("opensearchIndexDeep() [foreground] finished for Encounter " + encId);
4357+
}
4358+
43144359
// given a doc from opensearch, can user access it?
43154360
public static boolean opensearchAccess(org.json.JSONObject doc, User user,
43164361
Shepherd myShepherd) {

0 commit comments

Comments
 (0)