Commit 70b98e7e9c1cf9bb3a3bbb6568c9f4032c3615fd

Authored by Nathanael Jourdane
1 parent bd930b1f
Exists in master

Add listeners.

src/main/java/eu/omp/irap/vespa/epntapclient/RequestCtrl.java 0 → 100644
... ... @@ -0,0 +1,116 @@
  1 +/*
  2 + * This file is a part of EpnTAPClient.
  3 + * This program aims to provide EPN-TAP support for software clients, like CASSIS spectrum analyzer.
  4 + * See draft specifications: https://voparis-confluence.obspm.fr/pages/viewpage.action?pageId=559861
  5 + * Copyright (C) 2016 Institut de Recherche en Astrophysique et Planétologie.
  6 + *
  7 + * This program is free software: you can
  8 + * redistribute it and/or modify it under the terms of the GNU General Public License as published
  9 + * by the Free Software Foundation, either version 3 of the License, or (at your option) any later
  10 + * version. This program is distributed in the hope that it will be useful, but WITHOUT ANY
  11 + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  12 + * PURPOSE. See the GNU General Public License for more details. You should have received a copy of
  13 + * the GNU General Public License along with this program. If not, see
  14 + * <http://www.gnu.org/licenses/>.
  15 + */
  16 +
  17 +package eu.omp.irap.vespa.epntapclient;
  18 +
  19 +import java.util.ArrayList;
  20 +import java.util.HashMap;
  21 +import java.util.List;
  22 +import java.util.Map;
  23 +import java.util.logging.Logger;
  24 +
  25 +import com.google.gson.JsonArray;
  26 +import com.google.gson.JsonObject;
  27 +
  28 +import eu.omp.irap.vespa.votable.utils.CantSendQueryException;
  29 +import eu.omp.irap.vespa.votable.utils.Network;
  30 +import eu.omp.irap.vespa.votable.utils.StringJoiner;
  31 +
  32 +/**
  33 + * @author N. Jourdane
  34 + */
  35 +public class RequestCtrl {
  36 +
  37 + /** The logger for the class RequestCtrl. */
  38 + private static final Logger logger = Logger.getLogger(RequestCtrl.class.getName());
  39 +
  40 + /** The URL of the resolver used for the `target name` field. */
  41 + private static final String RESOLVER_URL = "http://voparis-registry.obspm.fr/ssodnet/1/autocomplete";
  42 +
  43 + /**
  44 + * The parameters fields for the request.
  45 + */
  46 + protected Map<String, Object> paramValues = new HashMap<>();
  47 +
  48 +
  49 + public RequestCtrl() {
  50 +
  51 + }
  52 +
  53 + /**
  54 + * @param nbRow The maximum number of rows returned.
  55 + * @param tableName The name of the target table for the query.
  56 + * @param params A map of parameters, for the `WHERE` keywords.
  57 + * @return The literal string of the query.
  58 + */
  59 + public static String getQuery(String tableName, Map<String, Object> params, int nbRow) {
  60 + StringJoiner addJoin = new StringJoiner(" AND ");
  61 + for (Map.Entry<String, Object> param : params.entrySet()) {
  62 + if (param.getValue() instanceof ArrayList) {
  63 + StringJoiner orJoin = new StringJoiner(" OR ");
  64 + @SuppressWarnings("unchecked")
  65 + List<String> possibleValues = (List<String>) param.getValue();
  66 + for (String possibleValue : possibleValues) {
  67 + orJoin.add(param.getKey() + " LIKE '" + possibleValue + "'");
  68 + }
  69 + addJoin.add("(" + orJoin + ")");
  70 + } else if (param.getValue() instanceof String) {
  71 + addJoin.add(param.getKey() + " LIKE '" + param.getValue() + "'");
  72 + } else {
  73 + addJoin.add(param.getKey() + " = " + param.getValue().toString());
  74 + }
  75 + }
  76 + String where = addJoin.isEmpty() ? "" : " WHERE " + addJoin;
  77 + return "SELECT TOP " + nbRow + " target_name, target_class FROM " + tableName + where;
  78 + }
  79 +
  80 + /**
  81 + * The method used to get target names propositions by asking to the resolver.
  82 + *
  83 + * @param begining The beginning of the target_name.
  84 + * @return An array of Strings corresponding to the target names got.
  85 + * @throws CantSendQueryException
  86 + * @throws CantGetXMLException If the resolver do not work.
  87 + */
  88 + public static String[] getTargetNames(String begining) throws CantSendQueryException {
  89 + Map<String, String> params = new HashMap<>();
  90 + params.put("q", "\"" + begining + "\"");
  91 +
  92 + String query = Network.buildQuery(RESOLVER_URL, params);
  93 + JsonObject root = Network.readJson(query);
  94 + int count = Integer.parseInt(root.get("count").toString());
  95 + String[] targetNames = new String[count];
  96 + JsonArray hits = root.getAsJsonArray("hits");
  97 + for (int i = 0; i < count; i++) {
  98 + JsonObject elmt = hits.get(i).getAsJsonObject();
  99 + targetNames[i] = elmt.get("name").toString().replace("\"", "");
  100 + }
  101 + return targetNames;
  102 + }
  103 +
  104 + public void updateParameter(String paramName, Object paramValue) {
  105 + paramValues.put(paramName, paramValue);
  106 + }
  107 +
  108 + public void removeParameter(String paramName) {
  109 + paramValues.remove(paramName);
  110 + }
  111 +
  112 + public Map<String, Object> getParamValues() {
  113 + return paramValues;
  114 + }
  115 +
  116 +}
... ...
src/main/java/eu/omp/irap/vespa/epntapclient/gui/requestpanel/RequestPanelListener.java 0 → 100644
... ... @@ -0,0 +1,46 @@
  1 +/*
  2 + * This file is a part of EpnTAPClient.
  3 + * This program aims to provide EPN-TAP support for software clients, like CASSIS spectrum analyzer.
  4 + * See draft specifications: https://voparis-confluence.obspm.fr/pages/viewpage.action?pageId=559861
  5 + * Copyright (C) 2016 Institut de Recherche en Astrophysique et Planétologie.
  6 + *
  7 + * This program is free software: you can
  8 + * redistribute it and/or modify it under the terms of the GNU General Public License as published
  9 + * by the Free Software Foundation, either version 3 of the License, or (at your option) any later
  10 + * version. This program is distributed in the hope that it will be useful, but WITHOUT ANY
  11 + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  12 + * PURPOSE. See the GNU General Public License for more details. You should have received a copy of
  13 + * the GNU General Public License along with this program. If not, see
  14 + * <http://www.gnu.org/licenses/>.
  15 + */
  16 +
  17 +package eu.omp.irap.vespa.epntapclient.gui.requestpanel;
  18 +
  19 +/**
  20 + * @author N. Jourdane
  21 + */
  22 +public interface RequestPanelListener {
  23 +
  24 + /**
  25 + * ...
  26 + *
  27 + * @param text
  28 + */
  29 + void onSendButtonClicked(String text);
  30 +
  31 + /**
  32 + * ...
  33 + *
  34 + * @param paramName
  35 + */
  36 + void onParameterRemoved(String paramName);
  37 +
  38 + /**
  39 + * ...
  40 + *
  41 + * @param paramName
  42 + * @param query
  43 + */
  44 + void onParameterChanged(String paramName, Object paramValue);
  45 +
  46 +}
... ...
src/main/java/eu/omp/irap/vespa/epntapclient/gui/resultpanel/ResultPanelListener.java 0 → 100644
... ... @@ -0,0 +1,27 @@
  1 +/*
  2 + * This file is a part of EpnTAPClient.
  3 + * This program aims to provide EPN-TAP support for software clients, like CASSIS spectrum analyzer.
  4 + * See draft specifications: https://voparis-confluence.obspm.fr/pages/viewpage.action?pageId=559861
  5 + * Copyright (C) 2016 Institut de Recherche en Astrophysique et Planétologie.
  6 + *
  7 + * This program is free software: you can
  8 + * redistribute it and/or modify it under the terms of the GNU General Public License as published
  9 + * by the Free Software Foundation, either version 3 of the License, or (at your option) any later
  10 + * version. This program is distributed in the hope that it will be useful, but WITHOUT ANY
  11 + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  12 + * PURPOSE. See the GNU General Public License for more details. You should have received a copy of
  13 + * the GNU General Public License along with this program. If not, see
  14 + * <http://www.gnu.org/licenses/>.
  15 + */
  16 +
  17 +package eu.omp.irap.vespa.epntapclient.gui.resultpanel;
  18 +
  19 +import java.io.File;
  20 +
  21 +/**
  22 + * @author N. Jourdane
  23 + */
  24 +public interface ResultPanelListener {
  25 +
  26 + public void onDownloadButtonClicked(File file);
  27 +}
... ...
src/main/java/eu/omp/irap/vespa/epntapclient/gui/servicespanel/ServicesPanelListener.java 0 → 100644
... ... @@ -0,0 +1,25 @@
  1 +/*
  2 + * This file is a part of EpnTAPClient.
  3 + * This program aims to provide EPN-TAP support for software clients, like CASSIS spectrum analyzer.
  4 + * See draft specifications: https://voparis-confluence.obspm.fr/pages/viewpage.action?pageId=559861
  5 + * Copyright (C) 2016 Institut de Recherche en Astrophysique et Planétologie.
  6 + *
  7 + * This program is free software: you can
  8 + * redistribute it and/or modify it under the terms of the GNU General Public License as published
  9 + * by the Free Software Foundation, either version 3 of the License, or (at your option) any later
  10 + * version. This program is distributed in the hope that it will be useful, but WITHOUT ANY
  11 + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  12 + * PURPOSE. See the GNU General Public License for more details. You should have received a copy of
  13 + * the GNU General Public License along with this program. If not, see
  14 + * <http://www.gnu.org/licenses/>.
  15 + */
  16 +
  17 +package eu.omp.irap.vespa.epntapclient.gui.servicespanel;
  18 +
  19 +/**
  20 + * @author N. Jourdane
  21 + */
  22 +public interface ServicesPanelListener {
  23 +
  24 + public void onServiceSelected(int selectedServiceRow);
  25 +}
... ...