Skip to content

Commit

Permalink
Merge pull request #817 from WildMeOrg/808_background_deepindex
Browse files Browse the repository at this point in the history
opensearchIndexDeep() fix on MarkedIndividuals
  • Loading branch information
TanyaStere42 authored Oct 26, 2024
2 parents 27e0b42 + 9e3566b commit 63f1938
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/main/java/org/ecocean/Encounter.java
Original file line number Diff line number Diff line change
Expand Up @@ -2391,7 +2391,7 @@ public void setTissueSamples(List<TissueSample> samps) {
public Set<String> getTissueSampleIDs() {
Set<String> ids = new HashSet<String>();

for (TissueSample ts : tissueSamples) {
if (tissueSamples != null) for (TissueSample ts : tissueSamples) {
ids.add(ts.getSampleID());
}
return ids;
Expand Down
52 changes: 46 additions & 6 deletions src/main/java/org/ecocean/MarkedIndividual.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import java.util.concurrent.Executors;
import java.util.concurrent.ExecutorService;

import javax.jdo.Query;
import javax.servlet.http.HttpServletRequest;
import org.apache.commons.lang3.builder.ToStringBuilder;
Expand Down Expand Up @@ -44,7 +47,7 @@ public class MarkedIndividual extends Base implements java.io.Serializable {
private static HashMap<Integer, String> NAMES_KEY_CACHE = new HashMap<Integer, String>();

private String alternateid;
private String legacyIndividualID;
private String legacyIndividualID;

// additional comments added by researchers
private String comments = "None";
Expand Down Expand Up @@ -1832,7 +1835,6 @@ public List<String> getAllEmailsToUpdate() {
// process encounters
for (int i = 0; i < numEncounters; i++) {
Encounter enc = (Encounter)encounters.get(i);

List<User> allUsers = new ArrayList<User>();
if (enc.getSubmitters() != null) allUsers.addAll(enc.getSubmitters());
if (enc.getPhotographers() != null) allUsers.addAll(enc.getPhotographers());
Expand Down Expand Up @@ -2593,11 +2595,49 @@ public void mergeAndThrowawayIndividual(MarkedIndividual other, String username,

public void opensearchIndexDeep()
throws IOException {
if (this.encounters != null)
for (Encounter enc : this.encounters) {
enc.opensearchIndex();
}
this.opensearchIndex();

final String indivId = this.getId();
ExecutorService executor = Executors.newFixedThreadPool(4);
Runnable rn = new Runnable() {
public void run() {
Shepherd bgShepherd = new Shepherd("context0");
bgShepherd.setAction("MarkedIndividual.opensearchIndexDeep");
bgShepherd.beginDBTransaction();
try {
MarkedIndividual indiv = bgShepherd.getMarkedIndividual(indivId);
if ((indiv == null) || (indiv.getEncounters() == null)) {
bgShepherd.rollbackAndClose();
executor.shutdown();
return;
}
int total = indiv.getNumEncounters();
int ct = 0;
for (Encounter enc : indiv.getEncounters()) {
ct++;
System.out.println("opensearchIndexDeep() background indexing " +
enc.getId() + " via " + indivId + " [" + ct + "/" + total + "]");
try {
enc.opensearchIndex();
} catch (Exception ex) {
System.out.println("opensearchIndexDeep() background indexing " +
enc.getId() + " FAILED: " + ex.toString());
ex.printStackTrace();
}
}
} finally {
bgShepherd.rollbackAndClose();
}
System.out.println("opensearchIndexDeep() backgrounding MarkedIndividual " +
indivId + " finished.");
executor.shutdown();
}
};
System.out.println("opensearchIndexDeep() begin backgrounding " + this.getNumEncounters() +
" encs for " + this);
executor.execute(rn);
System.out.println("opensearchIndexDeep() [foreground] finished for MarkedIndividual " +
indivId);
}

public String toString() {
Expand Down
1 change: 1 addition & 0 deletions src/main/java/org/ecocean/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -1130,6 +1130,7 @@ public static long getVersionFromModified(final String modified) {
}

public static String getISO8601Date(final String date) {
if (date == null) return null;
String iso8601 = date.replace(" ", "T");

if (iso8601.length() == 10) iso8601 += "T00:00:00";
Expand Down

0 comments on commit 63f1938

Please sign in to comment.