Skip to content

Commit

Permalink
Updates to support Airborne, Facility, Telescope
Browse files Browse the repository at this point in the history
Resolves #35
  • Loading branch information
jordanpadams committed Oct 19, 2024
1 parent ac20cbd commit edc9629
Show file tree
Hide file tree
Showing 6 changed files with 509 additions and 340 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@
<dependency>
<groupId>org.apache.solr</groupId>
<artifactId>solr-solrj</artifactId>
<version>9.6.1</version>
<version>9.7.0</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
Expand Down
40 changes: 39 additions & 1 deletion src/main/java/gov/nasa/pds/dsview/registry/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@

package gov.nasa.pds.dsview.registry;

import java.util.Map;
import java.util.LinkedHashMap;
import java.util.Map;
/**
* Class that holds constants used in ds-view.
*
Expand Down Expand Up @@ -328,4 +328,42 @@ public class Constants {
observationalPds4ToSearch.put("TYPE", "data_class");
observationalPds4ToSearch.put("FILE(S)", "file_name");
}

public static final Map<String, String> telescopePds4ToRegistry =
new LinkedHashMap<String, String>();
static {
telescopePds4ToRegistry.put("IDENTIFIER", "identifier");
telescopePds4ToRegistry.put("NAME", "title");
telescopePds4ToRegistry.put("DESCRIPTION", "description");
telescopePds4ToRegistry.put("FACILITY", "facility_ref");
telescopePds4ToRegistry.put("APERTURE", "telescope_aperture");
telescopePds4ToRegistry.put("LONGITUDE", "telescope_longitude");
telescopePds4ToRegistry.put("LATITUDE", "telescope_latitude");
telescopePds4ToRegistry.put("ALTITUDE", "telescope_altitude");
telescopePds4ToRegistry.put("COORIDINATE SOURCE", "telescope_coordinate_source");
telescopePds4ToRegistry.put("INVESTIGATION(S)", "investigation_ref");
telescopePds4ToRegistry.put("INSTRUMENT(S)", "instrument_ref");
}

public static final Map<String, String> facilityPds4ToRegistry =
new LinkedHashMap<String, String>();
static {
facilityPds4ToRegistry.put("IDENTIFIER", "identifier");
facilityPds4ToRegistry.put("NAME", "title");
facilityPds4ToRegistry.put("TYPE", "facility_type");
facilityPds4ToRegistry.put("DESCRIPTION", "description");
facilityPds4ToRegistry.put("ADDRESS", "facility_address");
facilityPds4ToRegistry.put("COUNTRY", "facility_country");
facilityPds4ToRegistry.put("INVESTIGATION(S)", "investigation_ref");
facilityPds4ToRegistry.put("TELESCOPE(S)", "telescope_ref");
}

public static final Map<String, String> airbornePds4ToRegistry =
new LinkedHashMap<String, String>();
static {
airbornePds4ToRegistry.put("IDENTIFIER", "identifier");
airbornePds4ToRegistry.put("NAME", "title");
airbornePds4ToRegistry.put("TYPE", "airborne_type");
airbornePds4ToRegistry.put("DESCRIPTION", "description");
}
}
66 changes: 36 additions & 30 deletions src/main/java/gov/nasa/pds/dsview/registry/PDS3Search.java
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ public SolrDocument getInst(String instId, String instHostId) throws SolrServerE
org.apache.solr.client.solrj.SolrRequest.METHOD.GET);

SolrDocumentList solrResults = response.getResults();
log.info("numFound = " + solrResults.getNumFound());
log.fine("numFound = " + solrResults.getNumFound());

Iterator<SolrDocument> itr = solrResults.iterator();
SolrDocument doc = null;
Expand Down Expand Up @@ -341,7 +341,7 @@ public SolrDocument getTarget(String identifier) throws SolrServerException, IOE
params.set("wt", "xml");
params.set("fq", "facet_type:\"1,target\"");

log.info("params = " + params.toString());
log.info("params = " + params.toString());
QueryResponse response = solr.query(params,
org.apache.solr.client.solrj.SolrRequest.METHOD.GET);

Expand Down Expand Up @@ -446,34 +446,40 @@ public String getDoi(String identifier) throws IOException, JSONException {
log.info("getDOI(" + identifier + ")");
URL url = new URL(DOI_SERVER_URL + "?ids=" + URLEncoder.encode(identifier, "UTF-8"));

HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("GET");
conn.setConnectTimeout(5000);
conn.setReadTimeout(5000);

int responseCode = conn.getResponseCode();
if (responseCode == 200) {
BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String line;
StringBuffer response = new StringBuffer();
while ((line = br.readLine()) != null) {
response.append(line);
}
br.close();

JSONArray jsonArray = new JSONArray(response.toString());
log.info("DOI Service response = " + jsonArray.toString(2));
if (jsonArray.length() == 0) {
return null;
} else if (jsonArray.length() == 1) {
JSONObject jsonResponse = jsonArray.getJSONObject(0);
String doi = jsonResponse.getString("doi");
return "<a href=\"https://doi.org/" + doi + "\">" + doi + "</a>";
} else {
return "Multiple DOIs found. Use <a href=\"/tools/doi/#/search/" + identifier + "\">DOI Search</a> to select the most appropriate.";
}
} else {
return null;
HttpURLConnection conn = null;
try {
conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("GET");
conn.setConnectTimeout(5000);
conn.setReadTimeout(5000);

int responseCode = conn.getResponseCode();
if (responseCode == 200) {
BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String line;
StringBuffer response = new StringBuffer();
while ((line = br.readLine()) != null) {
response.append(line);
}
br.close();

JSONArray jsonArray = new JSONArray(response.toString());
log.info("DOI Service response = " + jsonArray.toString(2));
if (jsonArray.length() == 0) {
return null;
} else if (jsonArray.length() == 1) {
JSONObject jsonResponse = jsonArray.getJSONObject(0);
String doi = jsonResponse.getString("doi");
return "<a href=\"https://doi.org/" + doi + "\">" + doi + "</a>";
} else {
return "Multiple DOIs found. Use <a href=\"/tools/doi/#/search/" + identifier
+ "\">DOI Search</a> to select the most appropriate.";
}
} else {
return null;
}
} finally {
conn.disconnect();
}
}

Expand Down
7 changes: 6 additions & 1 deletion src/main/java/gov/nasa/pds/dsview/registry/PDS4Search.java
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,9 @@ private String getValue(Map.Entry<String, Object> entry) {

public JSONArray getDoiResponse(URL url) throws IOException, JSONException {
log.fine("getDoiResponse(" + url + ")");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
HttpURLConnection conn = null;
try {
conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("GET");
conn.setConnectTimeout(5000);
conn.setReadTimeout(5000);
Expand All @@ -371,6 +373,9 @@ public JSONArray getDoiResponse(URL url) throws IOException, JSONException {
log.warning("getDoiResponse's responseCode != 200");
return null;
}
} finally {
conn.disconnect();
}

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,21 +57,16 @@ public void doIt(HttpServletRequest req, HttpServletResponse res)
String queryString = constructKeywordQuery(req);
System.out.println("queryString = " + queryString);

/*
res.setContentType("text/html");
PrintWriter out = res.getWriter();
out.println("<html>");
out.println("<head>");
out.println("<title>Testing RegistryQueryServlet!</title>");
out.println("</head>");
out.println("<body>");
out.println("<h1>Testing RegistryQueyrServlet!</h1>");
out.println("parameter names = " + req.getParameterMap().toString() + "<br>");
//out.println("parameter values = " + req.getParameterValues().toString() + "<br>");
//out.println("registryUrl = " + req.getParameterValues("registryUrl")[0]);
out.println("</body>");
out.println("</html>");
*/
/*
* res.setContentType("text/html"); PrintWriter out = res.getWriter();
* out.println("<html>"); out.println("<head>");
* out.println("<title>Testing RegistryQueryServlet!</title>"); out.println("</head>");
* out.println("<body>"); out.println("<h1>Testing RegistryQueyrServlet!</h1>");
* out.println("parameter names = " + req.getParameterMap().toString() + "<br>");
* //out.println("parameter values = " + req.getParameterValues().toString() + "<br>");
* //out.println("registryUrl = " + req.getParameterValues("registryUrl")[0]);
* out.println("</body>"); out.println("</html>");
*/
req.getSession().setAttribute("queryString", queryString);
getServletConfig().getServletContext().getRequestDispatcher
("/pds/results.jsp").forward(req,res);
Expand Down
Loading

0 comments on commit edc9629

Please sign in to comment.