Skip to content

Commit

Permalink
[#779] catch bad lat/lon; catch index exceptions; startNum on opensea…
Browse files Browse the repository at this point in the history
…rchSync
  • Loading branch information
naknomum committed Dec 12, 2024
1 parent 4f74818 commit 0b40acf
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
11 changes: 9 additions & 2 deletions src/main/java/org/ecocean/Encounter.java
Original file line number Diff line number Diff line change
Expand Up @@ -4119,7 +4119,8 @@ public void opensearchDocumentSerializer(JsonGenerator jgen)

Double dlat = this.getDecimalLatitudeAsDouble();
Double dlon = this.getDecimalLongitudeAsDouble();
if ((dlat == null) || (dlon == null)) {
if ((dlat == null) || !Util.isValidDecimalLatitude(dlat) || (dlon == null) ||
!Util.isValidDecimalLongitude(dlon)) {
jgen.writeNullField("locationGeoPoint");
} else {
jgen.writeObjectFieldStart("locationGeoPoint");
Expand Down Expand Up @@ -4300,7 +4301,13 @@ public static int[] opensearchSyncIndex(Shepherd myShepherd, int stopAfter)
int ct = 0;
for (String id : needIndexing) {
Encounter enc = myShepherd.getEncounter(id);
if (enc != null) os.index(indexName, enc);
try {
if (enc != null) os.index(indexName, enc);
} catch (Exception ex) {
System.out.println("Encounter.opensearchSyncIndex(): index failed " + enc + " => " +
ex.toString());
ex.printStackTrace();
}
if (ct % 500 == 0)
System.out.println("Encounter.opensearchSyncIndex needIndexing: " + ct + "/" +
rtn[0]);
Expand Down
24 changes: 22 additions & 2 deletions src/main/webapp/appadmin/opensearchSync.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ org.ecocean.*

<%
System.out.println("opensearchSync.jsp begun...");
long timer = System.currentTimeMillis();
Util.mark("opensearchSync begin");
boolean resetIndex = Util.requestParameterSet(request.getParameter("resetIndex"));
Expand All @@ -23,6 +25,14 @@ if ("".equals(fstr)) {
if (forceNum == 0) forceNum = 999999;
String sstr = request.getParameter("startNum");
int startNum = -1;
if (sstr != null) {
try {
startNum = Integer.parseInt(sstr);
} catch (Exception ex) {}
}
Shepherd myShepherd = new Shepherd(request);
OpenSearch os = new OpenSearch();
Expand All @@ -45,10 +55,19 @@ if (forceNum > 0) {
while (itr.hasNext()) {
Encounter enc = (Encounter)itr.next();
if (!Util.stringExists(enc.getId())) continue;
ct++;
if (startNum > 0) {
if (ct < startNum) continue;
if (ct == startNum) System.out.println("opensearchSync.jsp: starting at " + startNum);
}
//System.out.println(enc.getId() + ": " + enc.getVersion());
enc.opensearchIndex();
try {
enc.opensearchIndex();
} catch (Exception ex) {
System.out.println("opensearchSync.jsp: exception failure on " + enc);
ex.printStackTrace();
}
if (ct % 100 == 0) System.out.println("opensearchSync.jsp: count " + ct);
ct++;
if (ct > forceNum) break;
}
Expand All @@ -62,5 +81,6 @@ myShepherd.rollbackAndClose();
os.deleteAllPits();
System.out.println("opensearchSync.jsp finished");
Util.mark("opensearchSync ended", timer);
%>

0 comments on commit 0b40acf

Please sign in to comment.