Commit 05b140ed5a9dbf4ba71d2b34433f8f2b0e4db0e7

Authored by Nathanael Jourdane
1 parent 3507bdd6
Exists in master

TargetNameField JComboBox is filled with actual name suggestions.

src/main/java/eu/omp/irap/vespa/epntapclient/view/ParamField.java
@@ -25,11 +25,20 @@ import javax.swing.text.JTextComponent; @@ -25,11 +25,20 @@ import javax.swing.text.JTextComponent;
25 import org.apache.logging.log4j.LogManager; 25 import org.apache.logging.log4j.LogManager;
26 import org.apache.logging.log4j.Logger; 26 import org.apache.logging.log4j.Logger;
27 27
  28 +import com.google.gson.JsonArray;
  29 +import com.google.gson.JsonObject;
  30 +import com.google.gson.JsonParser;
  31 +
  32 +import eu.omp.irap.vespa.epntapclient.votable.controller.VOTableConnection;
  33 +import eu.omp.irap.vespa.epntapclient.votable.controller.VOTableException.BadRequestException;
  34 +import eu.omp.irap.vespa.epntapclient.votable.controller.VOTableException.HTTPRequestException;
  35 +
28 public abstract class ParamField extends JPanel { 36 public abstract class ParamField extends JPanel {
29 37
30 /** The logger for this class. */ 38 /** The logger for this class. */
31 private static final Logger logger = LogManager.getLogger(ParamField.class); 39 private static final Logger logger = LogManager.getLogger(ParamField.class);
32 40
  41 + private static final String RESOLVER_URL = "http://voparis-registry.obspm.fr/ssodnet/1/autocomplete";
33 private static final String DATE_FORMAT = "dd/MM/yyyy"; 42 private static final String DATE_FORMAT = "dd/MM/yyyy";
34 private static final String DATE_REGEX = "(^(((0[1-9]|1[0-9]|2[0-8])[\\/](0[1-9]|1[012]))|((29|30|31)[\\/](0[13578]|1[02]))|((29|30)[\\/](0[4,6,9]|11)))[\\/](19|[2-9][0-9])\\d\\d$)|(^29[\\/]02[\\/](19|[2-9][0-9])(00|04|08|12|16|20|24|28|32|36|40|44|48|52|56|60|64|68|72|76|80|84|88|92|96)$)"; 43 private static final String DATE_REGEX = "(^(((0[1-9]|1[0-9]|2[0-8])[\\/](0[1-9]|1[012]))|((29|30|31)[\\/](0[13578]|1[02]))|((29|30)[\\/](0[4,6,9]|11)))[\\/](19|[2-9][0-9])\\d\\d$)|(^29[\\/]02[\\/](19|[2-9][0-9])(00|04|08|12|16|20|24|28|32|36|40|44|48|52|56|60|64|68|72|76|80|84|88|92|96)$)";
35 44
@@ -176,7 +185,21 @@ public abstract class ParamField extends JPanel { @@ -176,7 +185,21 @@ public abstract class ParamField extends JPanel {
176 } 185 }
177 186
178 private String[] getTargetNames(String begining) { 187 private String[] getTargetNames(String begining) {
179 - String[] targetNames = { begining + "Bird", begining + "Cat", begining + "Dog" }; 188 + StringBuilder resolverResult = null;
  189 + try {
  190 + resolverResult = VOTableConnection.sendGet(RESOLVER_URL, "q=\"" + begining + "\"");
  191 + } catch (HTTPRequestException | BadRequestException e) {
  192 + logger.fatal("Can not send sersolver query: ", e);
  193 + }
  194 + JsonObject root = new JsonParser().parse(resolverResult.toString()).getAsJsonObject();
  195 + int count = Integer.parseInt(root.get("count").toString());
  196 + String[] targetNames = new String[count];
  197 + JsonArray hits = root.getAsJsonArray("hits");
  198 + for (int i = 0; i < count; i++) {
  199 + JsonObject elmt = hits.get(i).getAsJsonObject();
  200 + targetNames[i] = elmt.get("name").toString().replace("\"", "");
  201 + // TODO: Display "[name] ([type])" on the JComboBox, but only "[name]" on the query.
  202 + }
180 return targetNames; 203 return targetNames;
181 } 204 }
182 205