Commit e7647bba77ce69dba625ec22f610c3fecb6dc270
1 parent
737f769f
Exists in
master
change query to get an entry based on one of several dataProductType (ie. 'spectrum' or 'sp').
Showing
3 changed files
with
38 additions
and
12 deletions
Show diff stats
src/main/java/eu/omp/irap/vespa/epntapclient/utils/Queries.java
@@ -16,6 +16,8 @@ | @@ -16,6 +16,8 @@ | ||
16 | 16 | ||
17 | package eu.omp.irap.vespa.epntapclient.utils; | 17 | package eu.omp.irap.vespa.epntapclient.utils; |
18 | 18 | ||
19 | +import java.util.ArrayList; | ||
20 | +import java.util.List; | ||
19 | import java.util.Map; | 21 | import java.util.Map; |
20 | import java.util.StringJoiner; | 22 | import java.util.StringJoiner; |
21 | 23 | ||
@@ -48,15 +50,22 @@ public final class Queries { | @@ -48,15 +50,22 @@ public final class Queries { | ||
48 | * @return The literal string of the query. | 50 | * @return The literal string of the query. |
49 | */ | 51 | */ |
50 | public static String getQuery(String tableName, Map<String, Object> params, int nbRow) { | 52 | public static String getQuery(String tableName, Map<String, Object> params, int nbRow) { |
51 | - StringJoiner join = new StringJoiner(" AND "); | 53 | + StringJoiner addJoin = new StringJoiner(" AND "); |
52 | for (Map.Entry<String, Object> param : params.entrySet()) { | 54 | for (Map.Entry<String, Object> param : params.entrySet()) { |
53 | - if (param.getValue().getClass() == String.class) { | ||
54 | - join.add(param.getKey() + " LIKE '" + param.getValue() + "'"); | 55 | + Class paramClass = param.getValue().getClass(); |
56 | + if (paramClass == ArrayList.class) { | ||
57 | + StringJoiner orJoin = new StringJoiner(" OR "); | ||
58 | + List<String> possibleValues = ((List<String>) param.getValue()); | ||
59 | + for (String possibleValue : possibleValues) | ||
60 | + orJoin.add(param.getKey() + " LIKE '" + possibleValue + "'"); | ||
61 | + addJoin.add("(" + orJoin.toString() + ")"); | ||
62 | + } else if (paramClass == String.class) { | ||
63 | + addJoin.add(param.getKey() + " LIKE '" + param.getValue() + "'"); | ||
55 | } else { | 64 | } else { |
56 | - join.add(param.getKey() + " = " + param.getValue().toString()); | 65 | + addJoin.add(param.getKey() + " = " + param.getValue().toString()); |
57 | } | 66 | } |
58 | } | 67 | } |
59 | - String where = "".equals(join.toString()) ? "" : " WHERE " + join.toString(); | 68 | + String where = "".equals(addJoin.toString()) ? "" : " WHERE " + addJoin.toString(); |
60 | return "SELECT TOP " + nbRow + " target_name, target_class FROM " + tableName + where; | 69 | return "SELECT TOP " + nbRow + " target_name, target_class FROM " + tableName + where; |
61 | } | 70 | } |
62 | 71 |
src/main/java/eu/omp/irap/vespa/epntapclient/view/ParamField.java
@@ -8,6 +8,9 @@ import java.beans.PropertyChangeEvent; | @@ -8,6 +8,9 @@ import java.beans.PropertyChangeEvent; | ||
8 | import java.text.DateFormat; | 8 | import java.text.DateFormat; |
9 | import java.text.ParseException; | 9 | import java.text.ParseException; |
10 | import java.text.SimpleDateFormat; | 10 | import java.text.SimpleDateFormat; |
11 | +import java.util.ArrayList; | ||
12 | +import java.util.HashMap; | ||
13 | +import java.util.List; | ||
11 | import java.util.Locale; | 14 | import java.util.Locale; |
12 | import java.util.Objects; | 15 | import java.util.Objects; |
13 | 16 | ||
@@ -225,7 +228,7 @@ public abstract class ParamField extends JPanel { | @@ -225,7 +228,7 @@ public abstract class ParamField extends JPanel { | ||
225 | 228 | ||
226 | DataProductTypeField(RequestView requestView, String paramName) { | 229 | DataProductTypeField(RequestView requestView, String paramName) { |
227 | super(requestView, paramName); | 230 | super(requestView, paramName); |
228 | - comboBox = new JComboBox(getItems()); | 231 | + comboBox = new JComboBox(getItems().keySet().toArray()); |
229 | comboBox.addActionListener(new ActionListener() { | 232 | comboBox.addActionListener(new ActionListener() { |
230 | @Override | 233 | @Override |
231 | public void actionPerformed(ActionEvent e) { | 234 | public void actionPerformed(ActionEvent e) { |
@@ -235,14 +238,29 @@ public abstract class ParamField extends JPanel { | @@ -235,14 +238,29 @@ public abstract class ParamField extends JPanel { | ||
235 | this.add(comboBox); | 238 | this.add(comboBox); |
236 | } | 239 | } |
237 | 240 | ||
238 | - private String[] getItems() { | ||
239 | - return new String[] { "All", "Image", "Spectrum", "Dynamic spectrum", "Spectral cube", | ||
240 | - "Profile", "Volume", "Movie", "Cube" }; | 241 | + private HashMap<String, String> getItems() { |
242 | + HashMap items = new HashMap<String, String>(); | ||
243 | + items.put("All", "all"); | ||
244 | + items.put("Image", "im"); | ||
245 | + items.put("Spectrum", "sp"); | ||
246 | + items.put("Dynamic spectrum", "ds"); | ||
247 | + items.put("Spectral cube", "sc"); | ||
248 | + items.put("Profile", "pr"); | ||
249 | + items.put("Volume", "vo"); | ||
250 | + items.put("Movie", "mo"); | ||
251 | + items.put("Cube", "cu"); | ||
252 | + items.put("Time series", "ts"); | ||
253 | + items.put("Catalog", "ca"); | ||
254 | + items.put("Spatial vector", "sv"); | ||
255 | + return items; | ||
241 | } | 256 | } |
242 | 257 | ||
243 | private void onUpdate() { | 258 | private void onUpdate() { |
244 | - String value = comboBox.getSelectedItem().toString().replace(" ", "-").toLowerCase(); | ||
245 | - requestView.updateParam(paramName, "All".equals(value) ? null : value); | 259 | + String key = comboBox.getSelectedItem().toString(); |
260 | + List<String> item = new ArrayList(); | ||
261 | + item.add(key.replace(" ", "-").toLowerCase()); | ||
262 | + item.add(getItems().get(key)); | ||
263 | + requestView.updateParam(paramName, "All".equals(key) ? null : item); | ||
246 | } | 264 | } |
247 | } | 265 | } |
248 | 266 |
src/main/java/eu/omp/irap/vespa/epntapclient/view/RequestView.java
@@ -103,7 +103,6 @@ public class RequestView extends JPanel implements ActionListener { | @@ -103,7 +103,6 @@ public class RequestView extends JPanel implements ActionListener { | ||
103 | paramFields.add(new DateRangeField(this, "time_")); | 103 | paramFields.add(new DateRangeField(this, "time_")); |
104 | paramFields.add(new FloatRangeField(this, "spectral_range_")); | 104 | paramFields.add(new FloatRangeField(this, "spectral_range_")); |
105 | paramFields.add(new DataProductTypeField(this, "dataproduct_type")); | 105 | paramFields.add(new DataProductTypeField(this, "dataproduct_type")); |
106 | - | ||
107 | JPanel paramPanel = new JPanel(); | 106 | JPanel paramPanel = new JPanel(); |
108 | paramPanel.setLayout(new BoxLayout(paramPanel, BoxLayout.Y_AXIS)); | 107 | paramPanel.setLayout(new BoxLayout(paramPanel, BoxLayout.Y_AXIS)); |
109 | paramPanel.setBorder(BorderFactory.createTitledBorder("Query parameters")); | 108 | paramPanel.setBorder(BorderFactory.createTitledBorder("Query parameters")); |