Skip to content

Commit

Permalink
Merge commit 'ae7cf1f13d1527b5d031c9162a80bc44497b00ba' into snails
Browse files Browse the repository at this point in the history
  • Loading branch information
holmbergius committed Jan 17, 2025
2 parents 1014cc1 + ae7cf1f commit c5e79d0
Show file tree
Hide file tree
Showing 12 changed files with 1,624 additions and 1,568 deletions.
232 changes: 126 additions & 106 deletions frontend/package-lock.json

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions frontend/src/FrontDesk.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ import {
sessionCountdownTime,
} from "./constants/sessionWarning";
import useGetSiteSettings from "./models/useGetSiteSettings";
import useDocumentTitle from "./hooks/useDocumentTitle";

export default function FrontDesk() {
useDocumentTitle();
const [isLoggedIn, setIsLoggedIn] = useState(false);
const [collaborationTitle, setCollaborationTitle] = useState();
const [collaborationData, setCollaborationData] = useState([]);
Expand Down
26 changes: 26 additions & 0 deletions frontend/src/hooks/useDocumentTitle.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,36 @@ import useGetSiteSettings from "../models/useGetSiteSettings";

export default function useDocumentTitle() {
const { data: siteSettings } = useGetSiteSettings();

document.title = siteSettings?.siteName || "wildbook";
useEffect(() => {
if (!siteSettings) return;
let iconURL = siteSettings?.siteFavicon;
let link = document.querySelector("link[rel*='icon']");
const metaDescription = document.querySelector("meta[name='description']");
const metaKeywords = document.querySelector("meta[name='keywords']");
const metaAuthor = document.querySelector("meta[name='author']");

if (!metaDescription) {
const meta = document.createElement("meta");
meta.name = "description";
meta.content = siteSettings?.siteDescription;
document.getElementsByTagName("head")[0].appendChild(meta);
}

if (!metaKeywords) {
const meta = document.createElement("meta");
meta.name = "keywords";
meta.content = siteSettings?.siteKeywords;
document.getElementsByTagName("head")[0].appendChild(meta);
}

if (!metaAuthor) {
const meta = document.createElement("meta");
meta.name = "author";
meta.content = siteSettings?.siteAuthor;
document.getElementsByTagName("head")[0].appendChild(meta);
}

if (link) {
link.href = iconURL;
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.ecocean</groupId>
<artifactId>wildbook</artifactId>
<version>10.5.2</version>
<version>10.5.3</version>
<packaging>war</packaging>

<properties>
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/org/ecocean/Base.java
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,12 @@ public JSONObject opensearchMapping() {

public void opensearchIndex()
throws IOException {
long startT = System.currentTimeMillis();
OpenSearch opensearch = new OpenSearch();

opensearch.index(this.opensearchIndexName(), this);
long endT = System.currentTimeMillis();
System.out.println("opensearchIndex(): " + (endT - startT) + "ms indexing " + this);
}

// this will index "related" objects as needed
Expand Down
31 changes: 0 additions & 31 deletions src/main/java/org/ecocean/Encounter.java
Original file line number Diff line number Diff line change
Expand Up @@ -4705,35 +4705,4 @@ public void sendCreationEmails(Shepherd myShepherd, String langCode) {
}
}

public void opensearchIndexDeep()
throws IOException {
final String encId = this.getId();
final Encounter origEnc = this;
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) {
// we use origEnc if we can (especially necessary on initial creation of Encounter)
if (origEnc != null) origEnc.opensearchIndex();
bgShepherd.rollbackAndClose();
executor.shutdown();
return;
}
enc.opensearchIndex();
} catch (Exception e) {
e.printStackTrace();
} finally {
bgShepherd.rollbackAndClose();
}
executor.shutdown();
}
};

executor.execute(rn);
}
}
2,642 changes: 1,337 additions & 1,305 deletions src/main/java/org/ecocean/EncounterQueryProcessor.java

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/main/java/org/ecocean/Occurrence.java
Original file line number Diff line number Diff line change
Expand Up @@ -1370,7 +1370,7 @@ public void run() {
try {
Occurrence occur = bgShepherd.getOccurrence(occurId);
if ((occur == null) || (occur.getEncounters() == null)) {
bgShepherd.rollbackAndClose();
// rollbackAndClose handled by finally
executor.shutdown();
return;
}
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/org/ecocean/api/SiteSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ protected void doGet(HttpServletRequest request, HttpServletResponse response)
// note: there is a CommonConfiguration property: htmlShortcutIcon=images/favicon.ico?v=2
settings.put("siteFavicon", "/images/favicon.ico");
settings.put("siteName", CommonConfiguration.getHTMLTitle(context));
settings.put("siteDescription", CommonConfiguration.getHTMLDescription(context));
settings.put("siteKeywords", CommonConfiguration.getHTMLKeywords(context));
settings.put("siteAuthor", CommonConfiguration.getHTMLAuthor(context));
settings.put("locationData", LocationID.getLocationIDStructure());

settings.put("mapCenterLat", CommonConfiguration.getCenterLat(context));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public void doPost(HttpServletRequest request, HttpServletResponse response)
}
if (!locked) {
myShepherd.commitDBTransaction();
if (enc2remove != null) enc2remove.opensearchIndexDeep();
//if (enc2remove != null) enc2remove.opensearchIndexDeep();
out.println(ServletUtilities.getHeader(request));
response.setStatus(HttpServletResponse.SC_OK);
out.println("<strong>Success:</strong> Encounter #" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public void doPost(HttpServletRequest request, HttpServletResponse response)
if (!locked) {
myShepherd.commitDBTransaction();
// out.println(ServletUtilities.getHeader(request));
if (enc2remove != null) enc2remove.opensearchIndexDeep();
//if (enc2remove != null) enc2remove.opensearchIndexDeep();
out.println("<strong>Success:</strong> Encounter " +
request.getParameter("number") +
" was successfully removed from occurrence " + old_name + ".");
Expand Down
245 changes: 123 additions & 122 deletions src/main/java/org/ecocean/servlet/SubmitSpotsAndImage.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,132 +50,133 @@ public void doPost(HttpServletRequest request, HttpServletResponse response)
myShepherd.setAction("SubmitSpotsAndImage.class");

myShepherd.beginDBTransaction();
JSONObject json = ServletUtilities.jsonFromHttpServletRequest(request);
int maId = json.optInt("mediaAssetId", -1);
if (maId < 0) {
myShepherd.rollbackDBTransaction();
myShepherd.closeDBTransaction();
throw new IOException("invalid mediaAssetId");
}
String encId = json.optString("encId", null);
if (encId == null) {
myShepherd.rollbackDBTransaction();
myShepherd.closeDBTransaction();
throw new IOException("invalid encId");
}
Encounter enc = myShepherd.getEncounter(encId);
if (enc == null) {
myShepherd.rollbackDBTransaction();
myShepherd.closeDBTransaction();
throw new IOException("invalid encId");
}
boolean rightSide = json.optBoolean("rightSide", false);
ArrayList<SuperSpot> spots = parseSpots(json.optJSONArray("spots"));
if (spots == null) {
myShepherd.rollbackDBTransaction();
myShepherd.closeDBTransaction();
throw new IOException("invalid spots");
}
ArrayList<SuperSpot> refSpots = parseSpots(json.optJSONArray("refSpots"));
if (refSpots == null) {
myShepherd.rollbackDBTransaction();
myShepherd.closeDBTransaction();
throw new IOException("invalid refSpots");
}
AssetStore store = AssetStore.getDefault(myShepherd);
// this should put it in the same old (pre-MediaAsset) location to maintain url pattern

// setup data dir
String rootWebappPath = getServletContext().getRealPath("/");
File webappsDir = new File(rootWebappPath).getParentFile();
File shepherdDataDir = new File(webappsDir,
CommonConfiguration.getDataDirectoryName(context));
// if(!shepherdDataDir.exists()){shepherdDataDir.mkdirs();}
// File encountersDir=new File(shepherdDataDir.getAbsolutePath()+"/encounters");
// if(!encountersDir.exists()){encountersDir.mkdirs();}
String thisEncDirString = Encounter.dir(shepherdDataDir, encId);
File thisEncounterDir = new File(thisEncDirString);
if (!thisEncounterDir.exists()) {
thisEncounterDir.mkdirs();
System.out.println("I am making the encDir: " + thisEncDirString);
}
// now persist
JSONObject params = store.createParameters(new File("encounters/" +
Encounter.subdir(encId) + "/extract" + (rightSide ? "Right" : "") + encId + ".jpg"));
System.out.println("====> params = " + params);
MediaAsset crMa = store.create(params);
crMa.copyInBase64(json.optString("imageData", null));
crMa.addLabel("_spot" + (rightSide ? "Right" : "")); // we are sticking with "legacy" '_spot' for left
// crMa.setParentId(maId);
crMa.addDerivationMethod("spotTool", json.optJSONObject("imageToolValues"));
// ma.updateMinimalMetadata();

try{
JSONObject json = ServletUtilities.jsonFromHttpServletRequest(request);
int maId = json.optInt("mediaAssetId", -1);
if (maId < 0) {
throw new IOException("invalid mediaAssetId");
}
String encId = json.optString("encId", null);
if (encId == null) {
throw new IOException("invalid encId");
}
Encounter enc = myShepherd.getEncounter(encId);
if (enc == null) {
throw new IOException("invalid encId");
}
boolean rightSide = json.optBoolean("rightSide", false);
ArrayList<SuperSpot> spots = parseSpots(json.optJSONArray("spots"));
if (spots == null) {
throw new IOException("invalid spots");
}
ArrayList<SuperSpot> refSpots = parseSpots(json.optJSONArray("refSpots"));
if (refSpots == null) {
throw new IOException("invalid refSpots");
}
AssetStore store = AssetStore.getDefault(myShepherd);
// this should put it in the same old (pre-MediaAsset) location to maintain url pattern

// setup data dir
String rootWebappPath = getServletContext().getRealPath("/");
File webappsDir = new File(rootWebappPath).getParentFile();
File shepherdDataDir = new File(webappsDir,
CommonConfiguration.getDataDirectoryName(context));
// if(!shepherdDataDir.exists()){shepherdDataDir.mkdirs();}
// File encountersDir=new File(shepherdDataDir.getAbsolutePath()+"/encounters");
// if(!encountersDir.exists()){encountersDir.mkdirs();}
String thisEncDirString = Encounter.dir(shepherdDataDir, encId);
File thisEncounterDir = new File(thisEncDirString);
if (!thisEncounterDir.exists()) {
thisEncounterDir.mkdirs();
System.out.println("I am making the encDir: " + thisEncDirString);
}
// now persist
JSONObject params = store.createParameters(new File("encounters/" +
Encounter.subdir(encId) + "/extract" + (rightSide ? "Right" : "") + encId + ".jpg"));
System.out.println("====> params = " + params);
MediaAsset crMa = store.create(params);
crMa.copyInBase64(json.optString("imageData", null));
crMa.addLabel("_spot" + (rightSide ? "Right" : "")); // we are sticking with "legacy" '_spot' for left
// crMa.setParentId(maId);
crMa.addDerivationMethod("spotTool", json.optJSONObject("imageToolValues"));
// ma.updateMinimalMetadata();

Keyword crKeyword = myShepherd.getOrCreateKeyword("CR Image");
String crParentId = request.getParameter("dataCollectionEventID");
// crMa.addDerivationMethod("crParentId", crParentId);
// crMa.addLabel("CR");
crMa.addKeyword(crKeyword);
crMa.updateMinimalMetadata();
crMa.setDetectionStatus("complete");
System.out.println(" + updated made media asset");
MediaAssetFactory.save(crMa, myShepherd);
System.out.println(" + saved media asset " + crMa.toString());
myShepherd.updateDBTransaction();
System.out.println(" + updated transaction, about to make children");
crMa.updateStandardChildren(myShepherd);
crMa.updateMetadata();
System.out.println(" + updated children for asset " + crMa.toString() +
"; hasFamily = " + crMa.hasFamily(myShepherd));
String speciesString = enc.getTaxonomyString();
Annotation ann = new Annotation(speciesString, crMa);
ann.setMatchAgainst(true);
String iaClass = "whalesharkCR"; // should we change this?
ann.setIAClass(iaClass);
if (rightSide) { ann.setViewpoint("right"); } else { ann.setViewpoint("left"); }
enc.addAnnotation(ann);
System.out.println(" + made annotation " + ann.toString());

Keyword crKeyword = myShepherd.getOrCreateKeyword("CR Image");
String crParentId = request.getParameter("dataCollectionEventID");
// crMa.addDerivationMethod("crParentId", crParentId);
// crMa.addLabel("CR");
crMa.addKeyword(crKeyword);
crMa.updateMinimalMetadata();
crMa.setDetectionStatus("complete");
System.out.println(" + updated made media asset");
MediaAssetFactory.save(crMa, myShepherd);
System.out.println(" + saved media asset " + crMa.toString());
myShepherd.updateDBTransaction();
System.out.println(" + updated transaction, about to make children");
crMa.updateStandardChildren(myShepherd);
crMa.updateMetadata();
System.out.println(" + updated children for asset " + crMa.toString() +
"; hasFamily = " + crMa.hasFamily(myShepherd));
String speciesString = enc.getTaxonomyString();
Annotation ann = new Annotation(speciesString, crMa);
ann.setMatchAgainst(true);
String iaClass = "whalesharkCR"; // should we change this?
ann.setIAClass(iaClass);
if (rightSide) { ann.setViewpoint("right"); } else { ann.setViewpoint("left"); }
enc.addAnnotation(ann);
System.out.println(" + made annotation " + ann.toString());
myShepherd.getPM().makePersistent(ann);
System.out.println(" + saved annotation");

// we need to intake mediaassets so they get acmIds and are matchable
ArrayList<MediaAsset> maList = new ArrayList<MediaAsset>();
maList.add(crMa);
ArrayList<Annotation> annList = new ArrayList<Annotation>();
annList.add(ann);
try {
System.out.println(" + sending asset to IA");
IBEISIA.sendMediaAssetsNew(maList, context);
myShepherd.updateDBTransaction();
System.out.println(" + asset sent, sending annot");
IBEISIA.sendAnnotationsNew(annList, context, myShepherd);
myShepherd.updateDBTransaction();
System.out.println(" + annot sent.");
} catch (Exception e) {
e.printStackTrace();
System.out.println("hit above exception while trying to send CR ma & annot to IA");
myShepherd.getPM().makePersistent(ann);
System.out.println(" + saved annotation");

// we need to intake mediaassets so they get acmIds and are matchable
ArrayList<MediaAsset> maList = new ArrayList<MediaAsset>();
maList.add(crMa);
ArrayList<Annotation> annList = new ArrayList<Annotation>();
annList.add(ann);
try {
System.out.println(" + sending asset to IA");
IBEISIA.sendMediaAssetsNew(maList, context);
myShepherd.updateDBTransaction();
System.out.println(" + asset sent, sending annot");
IBEISIA.sendAnnotationsNew(annList, context, myShepherd);
myShepherd.updateDBTransaction();
System.out.println(" + annot sent.");
} catch (Exception e) {
e.printStackTrace();
System.out.println("hit above exception while trying to send CR ma & annot to IA");
}
System.out.println(" + done processing new CR annot");
if (rightSide) {
enc.setRightSpots(spots);
enc.setRightReferenceSpots(refSpots);
} else {
enc.setSpots(spots);
enc.setLeftReferenceSpots(refSpots);
}
// reset the entry in the GridManager graph
GridManager gm = GridManagerFactory.getGridManager();
gm.addMatchGraphEntry(encId, new EncounterLite(enc));

myShepherd.commitDBTransaction();
myShepherd.closeDBTransaction();

JSONObject rtn = new JSONObject("{\"success\": true}");
rtn.put("spotAssetId", crMa.getId());
rtn.put("spotAssetUrl", crMa.webURL());
response.setContentType("text/plain");
PrintWriter out = response.getWriter();
out.println(rtn.toString());
out.close();
}
System.out.println(" + done processing new CR annot");
if (rightSide) {
enc.setRightSpots(spots);
enc.setRightReferenceSpots(refSpots);
} else {
enc.setSpots(spots);
enc.setLeftReferenceSpots(refSpots);
catch(Exception e) {
e.printStackTrace();
}
finally {
myShepherd.rollbackAndClose();
}
// reset the entry in the GridManager graph
GridManager gm = GridManagerFactory.getGridManager();
gm.addMatchGraphEntry(encId, new EncounterLite(enc));

myShepherd.commitDBTransaction();
myShepherd.closeDBTransaction();

JSONObject rtn = new JSONObject("{\"success\": true}");
rtn.put("spotAssetId", crMa.getId());
rtn.put("spotAssetUrl", crMa.webURL());
response.setContentType("text/plain");
PrintWriter out = response.getWriter();
out.println(rtn.toString());
out.close();
}

private ArrayList<SuperSpot> parseSpots(JSONArray arr) {
Expand Down

0 comments on commit c5e79d0

Please sign in to comment.