diff --git a/src/main/java/eu/omp/irap/vespa/epntapclient/utils/Queries.java b/src/main/java/eu/omp/irap/vespa/epntapclient/utils/Queries.java index 5f4286f..d8d8075 100644 --- a/src/main/java/eu/omp/irap/vespa/epntapclient/utils/Queries.java +++ b/src/main/java/eu/omp/irap/vespa/epntapclient/utils/Queries.java @@ -16,6 +16,8 @@ package eu.omp.irap.vespa.epntapclient.utils; +import java.util.ArrayList; +import java.util.List; import java.util.Map; import java.util.StringJoiner; @@ -48,15 +50,22 @@ public final class Queries { * @return The literal string of the query. */ public static String getQuery(String tableName, Map params, int nbRow) { - StringJoiner join = new StringJoiner(" AND "); + StringJoiner addJoin = new StringJoiner(" AND "); for (Map.Entry param : params.entrySet()) { - if (param.getValue().getClass() == String.class) { - join.add(param.getKey() + " LIKE '" + param.getValue() + "'"); + Class paramClass = param.getValue().getClass(); + if (paramClass == ArrayList.class) { + StringJoiner orJoin = new StringJoiner(" OR "); + List possibleValues = ((List) param.getValue()); + for (String possibleValue : possibleValues) + orJoin.add(param.getKey() + " LIKE '" + possibleValue + "'"); + addJoin.add("(" + orJoin.toString() + ")"); + } else if (paramClass == String.class) { + addJoin.add(param.getKey() + " LIKE '" + param.getValue() + "'"); } else { - join.add(param.getKey() + " = " + param.getValue().toString()); + addJoin.add(param.getKey() + " = " + param.getValue().toString()); } } - String where = "".equals(join.toString()) ? "" : " WHERE " + join.toString(); + String where = "".equals(addJoin.toString()) ? "" : " WHERE " + addJoin.toString(); return "SELECT TOP " + nbRow + " target_name, target_class FROM " + tableName + where; } diff --git a/src/main/java/eu/omp/irap/vespa/epntapclient/view/ParamField.java b/src/main/java/eu/omp/irap/vespa/epntapclient/view/ParamField.java index c21cebc..b4217a7 100644 --- a/src/main/java/eu/omp/irap/vespa/epntapclient/view/ParamField.java +++ b/src/main/java/eu/omp/irap/vespa/epntapclient/view/ParamField.java @@ -8,6 +8,9 @@ import java.beans.PropertyChangeEvent; import java.text.DateFormat; import java.text.ParseException; import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; import java.util.Locale; import java.util.Objects; @@ -225,7 +228,7 @@ public abstract class ParamField extends JPanel { DataProductTypeField(RequestView requestView, String paramName) { super(requestView, paramName); - comboBox = new JComboBox(getItems()); + comboBox = new JComboBox(getItems().keySet().toArray()); comboBox.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { @@ -235,14 +238,29 @@ public abstract class ParamField extends JPanel { this.add(comboBox); } - private String[] getItems() { - return new String[] { "All", "Image", "Spectrum", "Dynamic spectrum", "Spectral cube", - "Profile", "Volume", "Movie", "Cube" }; + private HashMap getItems() { + HashMap items = new HashMap(); + items.put("All", "all"); + items.put("Image", "im"); + items.put("Spectrum", "sp"); + items.put("Dynamic spectrum", "ds"); + items.put("Spectral cube", "sc"); + items.put("Profile", "pr"); + items.put("Volume", "vo"); + items.put("Movie", "mo"); + items.put("Cube", "cu"); + items.put("Time series", "ts"); + items.put("Catalog", "ca"); + items.put("Spatial vector", "sv"); + return items; } private void onUpdate() { - String value = comboBox.getSelectedItem().toString().replace(" ", "-").toLowerCase(); - requestView.updateParam(paramName, "All".equals(value) ? null : value); + String key = comboBox.getSelectedItem().toString(); + List item = new ArrayList(); + item.add(key.replace(" ", "-").toLowerCase()); + item.add(getItems().get(key)); + requestView.updateParam(paramName, "All".equals(key) ? null : item); } } diff --git a/src/main/java/eu/omp/irap/vespa/epntapclient/view/RequestView.java b/src/main/java/eu/omp/irap/vespa/epntapclient/view/RequestView.java index 28eaf6f..c0fa898 100644 --- a/src/main/java/eu/omp/irap/vespa/epntapclient/view/RequestView.java +++ b/src/main/java/eu/omp/irap/vespa/epntapclient/view/RequestView.java @@ -103,7 +103,6 @@ public class RequestView extends JPanel implements ActionListener { paramFields.add(new DateRangeField(this, "time_")); paramFields.add(new FloatRangeField(this, "spectral_range_")); paramFields.add(new DataProductTypeField(this, "dataproduct_type")); - JPanel paramPanel = new JPanel(); paramPanel.setLayout(new BoxLayout(paramPanel, BoxLayout.Y_AXIS)); paramPanel.setBorder(BorderFactory.createTitledBorder("Query parameters")); -- libgit2 0.21.2