Skip to content

Commit

Permalink
Enable batch update of nahima
Browse files Browse the repository at this point in the history
  • Loading branch information
GenieTim committed Feb 6, 2024
1 parent e0714ea commit c7e82ac
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 6 deletions.
26 changes: 21 additions & 5 deletions src/main/java/edu/harvard/mcz/imagecapture/data/NahimaManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -481,12 +481,27 @@ protected JSONObject findSimilarMatch(JSONArray foundObjects, String objectType,
if (key.startsWith("_")) {
continue;
}
// TODO: compare more than just Strings
if (selectionHelper.get(key) instanceof JSONObject && selectionHelper.getJSONObject(key).has("en-US")) {
requiredMatches += 1;

if (testObj.has(key) && Objects.equals(testObj.getJSONObject(key).getString("en-US"), selectionHelper.getJSONObject(key).getString("en-US"))) {
matches += 1;
}
}
// TODO: compare more than just Strings, Integers and
if (selectionHelper.get(key) instanceof String && !((String) selectionHelper.get(key)).contains("DataShot")) {
requiredMatches += 1;

if (selectionHelper.get(key).equals(testObj.has(key) ? testObj.get(key) : null)) {
matches += 1;
}
}
if (selectionHelper.get(key).equals(testObj.has(key) ? testObj.get(key) : null)) {
matches += 1;
if (selectionHelper.get(key) instanceof Integer) {
requiredMatches += 1;

if (testObj.has(key) && testObj.getInt(key) == selectionHelper.getInt(key)) {
matches += 1;
}
}
}
if (matches >= requiredMatches && requiredMatches > 0) {
Expand Down Expand Up @@ -553,7 +568,7 @@ public JSONObject resolveOrCreate(String name, String objectType, String mask, J
// create
JSONObject toCreate = wrapForCreation(inner, objectType, mask, omitPool);
JSONObject createdResponse = this.createObjectInNahima(toCreate, objectType);
Thread.sleep(250); // this is a heuristic number and is here to improve reliability, as Nahima does not usually claim creation immediately.
Thread.sleep(50); // this is a heuristic number and is here to improve reliability, as Nahima does not usually claim creation immediately.
if (createdResponse.has("_uuid")) {
try {
results = this.findObjectByUuid(createdResponse.getString("_uuid"));
Expand Down Expand Up @@ -932,7 +947,8 @@ public JSONObject resolveLocation(Specimen specimen) throws IOException, Interru
return this.resolveOrCreateInteractive(searchString, "gazetteer", "gazetteer__all_fields", new JSONObject(new HashMap<>() {{
put("ortsname", wrapInLan(specimen.getPrimaryDivison()));
put("_id_parent", parentId == null ? JSONObject.NULL : parentId); // Might throw NullPointerException. If we find the location, it is never called, therefore, we only have a problem if neither location nor country are found
put("isocode3166_2", specimen.getPrimaryDivisonISO());
// put("isocode3166_2", specimen.getPrimaryDivisonISO());
put("isocode3166_alpha_2", specimen.getPrimaryDivisonISO());
}}));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,19 +131,22 @@ public void start() {
try {
existingExport = manager.findObjectByGlobalObjectId(specimen.getNahimaId());
} catch (IOException | InterruptedException e) {
log.warn("NoExport: skip specimen exception");
throw new SkipSpecimenException();
}
specimenJson = serializer.serialize2JSON(specimen, existingExport);
} else {
specimenJson = serializer.serialize2JSON(specimen);
}
} catch (SkipSpecimenException e) {
log.debug("NoExport: skip specimen exception");
continue;
}

if (specimenJson == null) {
// might want to add some checks
// to make sure this only happens when the SkipSpecimenException is thrown
log.debug("NoExport: Specimen json null, cannot upload stuff");
continue;
}

Expand Down Expand Up @@ -266,13 +269,16 @@ public void start() {
specimen.setDateLastNahimaUpdated(new Date());
if (specimen.getSpecimenId() != null && specimen.getSpecimenId() > 0) {
try {
log.debug("No specimen id, will not update the database");
sls.attachDirty(specimen);
} catch (SaveFailedException e) {
lastError = e;
log.error("Failed to store Nahima export status", e);
this.status = STATUS_DATASHOT_FAILED;
return;
}
} else {
log.debug("No specimen id, will not update the database");
}
notifyProgressChanged();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ private JComboBox getFieldSelectionJComboBox() {

private void doApplyChange() {
String fieldName = ((UpdateableField) this.getFieldSelectionJComboBox().getSelectedItem()).getDatabaseDescription();
String conditionQuery = "WHERE " + fieldName + " LIKE :fromValue AND (s.nahimaExported = FALSE OR s.nahimaExported IS NULL)";
String conditionQuery = "WHERE " + fieldName + " LIKE :fromValue"; // AND (s.nahimaExported = FALSE OR s.nahimaExported IS NULL)

Session session;
try {
Expand Down

0 comments on commit c7e82ac

Please sign in to comment.