Commit 5672c106cdce912469658c1555b2a1c43bcefba2
1 parent
6a2d3842
Exists in
master
Fix Sonar issues.
Showing
15 changed files
with
74 additions
and
116 deletions
Show diff stats
src/main/java/eu/omp/irap/vespa/epntapclient/EpnTapConnection.java
... | ... | @@ -96,7 +96,6 @@ public class EpnTapConnection implements EpnTapInterface { |
96 | 96 | @Override |
97 | 97 | public VOTABLE getEPNServices(List<String> keywords, List<String> attributes) |
98 | 98 | throws CantGetVOTableException { |
99 | - // TODO: move this code to a new class in ServiceCtrl() | |
100 | 99 | attributes.add("res_subject"); |
101 | 100 | String select = StringJoiner.join(attributes); |
102 | 101 | List<String> whereList = new ArrayList<>(); | ... | ... |
src/main/java/eu/omp/irap/vespa/epntapclient/EpnTapController.java
... | ... | @@ -53,7 +53,6 @@ public class EpnTapController { |
53 | 53 | String query = String.format(Queries.SELECT_ALL_TAP_SERVICES_WHERE_CORE, |
54 | 54 | ServiceCore.EPNCORE); |
55 | 55 | servicesCtrl = new VOTableController(Consts.DEFAULT_REGISTRY_URL, query); |
56 | - requestCtrl = new RequestCtrl(this); | |
57 | 56 | } |
58 | 57 | |
59 | 58 | /** |
... | ... | @@ -94,6 +93,10 @@ public class EpnTapController { |
94 | 93 | voTablePath = resultsCtrl.getVOTablePath(); |
95 | 94 | } |
96 | 95 | |
96 | + public String getVOTablePath() { | |
97 | + return voTablePath; | |
98 | + } | |
99 | + | |
97 | 100 | /** |
98 | 101 | * @return The controller of the VOTable which displays the result of the query. |
99 | 102 | */ | ... | ... |
src/main/java/eu/omp/irap/vespa/epntapclient/EpnTapMainApp.java
... | ... | @@ -23,8 +23,8 @@ import javax.swing.SwingUtilities; |
23 | 23 | |
24 | 24 | import com.google.gson.Gson; |
25 | 25 | |
26 | -import eu.omp.irap.vespa.epntapclient.gui.mainPanel.MainPanelCtrl; | |
27 | -import eu.omp.irap.vespa.epntapclient.gui.mainPanel.MainPanelView; | |
26 | +import eu.omp.irap.vespa.epntapclient.gui.mainpanel.MainPanelCtrl; | |
27 | +import eu.omp.irap.vespa.epntapclient.gui.mainpanel.MainPanelView; | |
28 | 28 | |
29 | 29 | /** |
30 | 30 | * Simple class to have a main function to launch the EPNTap client. | ... | ... |
src/main/java/eu/omp/irap/vespa/epntapclient/Query.java
... | ... | @@ -28,15 +28,15 @@ public enum Query { |
28 | 28 | // TBC |
29 | 29 | // @format |
30 | 30 | |
31 | - private String query; | |
31 | + private String literalQuery; | |
32 | 32 | |
33 | 33 | |
34 | - Query(String query) { | |
35 | - this.query = query; | |
34 | + Query(String literalQuery) { | |
35 | + this.literalQuery = literalQuery; | |
36 | 36 | } |
37 | 37 | |
38 | 38 | @Override |
39 | 39 | public String toString() { |
40 | - return query; | |
40 | + return literalQuery; | |
41 | 41 | } |
42 | 42 | } | ... | ... |
src/main/java/eu/omp/irap/vespa/epntapclient/RequestCtrl.java
... | ... | @@ -20,7 +20,6 @@ import java.util.ArrayList; |
20 | 20 | import java.util.HashMap; |
21 | 21 | import java.util.List; |
22 | 22 | import java.util.Map; |
23 | -import java.util.logging.Logger; | |
24 | 23 | |
25 | 24 | import com.google.gson.JsonArray; |
26 | 25 | import com.google.gson.JsonObject; |
... | ... | @@ -34,23 +33,15 @@ import eu.omp.irap.vespa.votable.utils.StringJoiner; |
34 | 33 | */ |
35 | 34 | public class RequestCtrl { |
36 | 35 | |
37 | - /** The logger for the class RequestCtrl. */ | |
38 | - private static final Logger logger = Logger.getLogger(RequestCtrl.class.getName()); | |
39 | - | |
40 | 36 | /** The URL of the resolver used for the `target name` field. */ |
41 | 37 | private static final String RESOLVER_URL = "http://voparis-registry.obspm.fr/ssodnet/1/autocomplete"; |
42 | 38 | |
43 | 39 | /** The parameters fields for the request. */ |
44 | 40 | protected Map<String, Object> paramValues = new HashMap<>(); |
45 | 41 | |
46 | - private EpnTapController epnTapCtrl; | |
47 | - | |
48 | 42 | |
49 | 43 | public RequestCtrl() { |
50 | - } | |
51 | - | |
52 | - public RequestCtrl(EpnTapController epnTapCtrl) { | |
53 | - this.epnTapCtrl = epnTapCtrl; | |
44 | + /* Subclasses initializes their own attributes, we don't want to initialize them twice. */ | |
54 | 45 | } |
55 | 46 | |
56 | 47 | /** |
... | ... | @@ -59,9 +50,9 @@ public class RequestCtrl { |
59 | 50 | * @param params A map of parameters, for the `WHERE` keywords. |
60 | 51 | * @return The literal string of the query. |
61 | 52 | */ |
62 | - public static String getQuery(String tableName, Map<String, Object> params, int nbRow) { | |
53 | + public String getQuery(String tableName, int nbRow) { | |
63 | 54 | StringJoiner addJoin = new StringJoiner(" AND "); |
64 | - for (Map.Entry<String, Object> param : params.entrySet()) { | |
55 | + for (Map.Entry<String, Object> param : paramValues.entrySet()) { | |
65 | 56 | if (param.getValue() instanceof ArrayList) { |
66 | 57 | StringJoiner orJoin = new StringJoiner(" OR "); |
67 | 58 | @SuppressWarnings("unchecked") |
... | ... | @@ -77,6 +68,7 @@ public class RequestCtrl { |
77 | 68 | } |
78 | 69 | } |
79 | 70 | String where = addJoin.isEmpty() ? "" : " WHERE " + addJoin; |
71 | + | |
80 | 72 | return "SELECT TOP " + nbRow + " target_name, target_class FROM " + tableName + where; |
81 | 73 | } |
82 | 74 | ... | ... |
src/main/java/eu/omp/irap/vespa/epntapclient/gui/mainPanel/GUIDim.java renamed to src/main/java/eu/omp/irap/vespa/epntapclient/gui/mainpanel/GUIDim.java
src/main/java/eu/omp/irap/vespa/epntapclient/gui/mainPanel/MainPanelCtrl.java renamed to src/main/java/eu/omp/irap/vespa/epntapclient/gui/mainpanel/MainPanelCtrl.java
src/main/java/eu/omp/irap/vespa/epntapclient/gui/mainPanel/MainPanelView.java renamed to src/main/java/eu/omp/irap/vespa/epntapclient/gui/mainpanel/MainPanelView.java
src/main/java/eu/omp/irap/vespa/epntapclient/gui/requestpanel/RequestPanelCtrl.java
... | ... | @@ -19,7 +19,7 @@ package eu.omp.irap.vespa.epntapclient.gui.requestpanel; |
19 | 19 | import java.util.logging.Logger; |
20 | 20 | |
21 | 21 | import eu.omp.irap.vespa.epntapclient.RequestCtrl; |
22 | -import eu.omp.irap.vespa.epntapclient.gui.mainPanel.MainPanelCtrl; | |
22 | +import eu.omp.irap.vespa.epntapclient.gui.mainpanel.MainPanelCtrl; | |
23 | 23 | import eu.omp.irap.vespa.epntapclient.service.Queries; |
24 | 24 | |
25 | 25 | /** |
... | ... | @@ -54,11 +54,6 @@ public class RequestPanelCtrl extends RequestCtrl implements RequestPanelListene |
54 | 54 | return view; |
55 | 55 | } |
56 | 56 | |
57 | - /* | |
58 | - * @see | |
59 | - * eu.omp.irap.vespa.epntapclient.gui.requestpanel.RequestPanelListener#onSendButtonClicked(java | |
60 | - * .lang.String) | |
61 | - */ | |
62 | 57 | @Override |
63 | 58 | public void onSendButtonClicked(String query) { |
64 | 59 | mainPanelCtrl.sendQuery(query); |
... | ... | @@ -73,18 +68,6 @@ public class RequestPanelCtrl extends RequestCtrl implements RequestPanelListene |
73 | 68 | view.updateQueryArea(query); |
74 | 69 | } |
75 | 70 | |
76 | - /** | |
77 | - * Update the query area with a working ADQL query, based on the parameters list. | |
78 | - */ | |
79 | - // private void updateQueryArea() { | |
80 | - // mainPanelCtrl.updateQueryArea(); | |
81 | - // } | |
82 | - | |
83 | - /* | |
84 | - * @see | |
85 | - * eu.omp.irap.vespa.epntapclient.gui.requestpanel.RequestPanelListener#onParameterRemoved(java. | |
86 | - * lang.String) | |
87 | - */ | |
88 | 71 | @Override |
89 | 72 | public void onParameterRemoved(String paramName) { |
90 | 73 | removeParameter(paramName); |
... | ... | @@ -92,11 +75,6 @@ public class RequestPanelCtrl extends RequestCtrl implements RequestPanelListene |
92 | 75 | logger.info("removed " + paramName); |
93 | 76 | } |
94 | 77 | |
95 | - /* | |
96 | - * @see | |
97 | - * eu.omp.irap.vespa.epntapclient.gui.requestpanel.RequestPanelListener#onParameterChanged(java. | |
98 | - * lang.String, java.lang.Object) | |
99 | - */ | |
100 | 78 | @Override |
101 | 79 | public void onParameterChanged(String paramName, Object paramValue) { |
102 | 80 | updateParameter(paramName, paramValue); | ... | ... |
src/main/java/eu/omp/irap/vespa/epntapclient/gui/requestpanel/paramfield/TargetNameField.java
... | ... | @@ -17,7 +17,6 @@ |
17 | 17 | package eu.omp.irap.vespa.epntapclient.gui.requestpanel.paramfield; |
18 | 18 | |
19 | 19 | import java.awt.Dimension; |
20 | -import java.io.File; | |
21 | 20 | import java.util.logging.Level; |
22 | 21 | |
23 | 22 | import javax.swing.JComboBox; |
... | ... | @@ -54,6 +53,39 @@ public class TargetNameField extends ParamField implements TextFieldListener { |
54 | 53 | */ |
55 | 54 | String lastContent; |
56 | 55 | |
56 | + /** | |
57 | + * This method is called each time the field is modified. A Runnable is used it is impossible to | |
58 | + * modify the comboBox from a DocumentEvent. | |
59 | + */ | |
60 | + Runnable updateComboBox = new Runnable() { | |
61 | + | |
62 | + @Override | |
63 | + public void run() { | |
64 | + String content = field.getText(); | |
65 | + if (!content.equals(lastContent)) { | |
66 | + if (content.length() >= 2) { | |
67 | + lastContent = content; | |
68 | + comboBox.removeAllItems(); | |
69 | + try { | |
70 | + for (String s : RequestCtrl.getTargetNames(content)) { | |
71 | + comboBox.addItem(s); | |
72 | + } | |
73 | + } catch (CantSendQueryException e) { | |
74 | + ParamField.logger.log(Level.WARNING, | |
75 | + "Can't get table names for the resolver", e); | |
76 | + } | |
77 | + comboBox.getEditor().setItem(content); | |
78 | + comboBox.showPopup(); | |
79 | + } | |
80 | + if (content.isEmpty()) { | |
81 | + requestPanelListener.onParameterRemoved(paramName); | |
82 | + } else { | |
83 | + requestPanelListener.onParameterChanged(paramName, content); | |
84 | + } | |
85 | + } | |
86 | + } | |
87 | + }; | |
88 | + | |
57 | 89 | |
58 | 90 | /** |
59 | 91 | * Method constructor |
... | ... | @@ -74,26 +106,16 @@ public class TargetNameField extends ParamField implements TextFieldListener { |
74 | 106 | } |
75 | 107 | |
76 | 108 | public TargetNameField(String paraName) { |
109 | + // @noformat | |
77 | 110 | this(new RequestPanelListener() { |
78 | - | |
79 | - public void onServiceSelected(int selectedService) { | |
80 | - } | |
81 | - | |
82 | 111 | @Override |
83 | - public void onSendButtonClicked(String query) { | |
84 | - } | |
85 | - | |
112 | + public void onSendButtonClicked(String query) {/** no SendButtonClicked event, we just want the field */} | |
86 | 113 | @Override |
87 | - public void onParameterRemoved(String paramName) { | |
88 | - } | |
89 | - | |
114 | + public void onParameterRemoved(String paramName) {/** no ParameterRemoved event, we just want the field */} | |
90 | 115 | @Override |
91 | - public void onParameterChanged(String paramName, Object paramValue) { | |
92 | - } | |
93 | - | |
94 | - public void onDownloadButtonClicked(File outputFile) { | |
95 | - } | |
116 | + public void onParameterChanged(String paramName, Object paramValue) {/** no ParameterChanged event, we just want the field */} | |
96 | 117 | }, paraName); |
118 | + // @format | |
97 | 119 | } |
98 | 120 | |
99 | 121 | /** |
... | ... | @@ -104,37 +126,4 @@ public class TargetNameField extends ParamField implements TextFieldListener { |
104 | 126 | SwingUtilities.invokeLater(updateComboBox); |
105 | 127 | } |
106 | 128 | |
107 | - | |
108 | - /** | |
109 | - * This method is called each time the field is modified. A Runnable is used it is impossible to | |
110 | - * modify the comboBox from a DocumentEvent. | |
111 | - */ | |
112 | - Runnable updateComboBox = new Runnable() { | |
113 | - | |
114 | - @Override | |
115 | - public void run() { | |
116 | - String content = field.getText(); | |
117 | - if (!content.equals(lastContent)) { | |
118 | - if (content.length() >= 2) { | |
119 | - lastContent = content; | |
120 | - comboBox.removeAllItems(); | |
121 | - try { | |
122 | - for (String s : RequestCtrl.getTargetNames(content)) { | |
123 | - comboBox.addItem(s); | |
124 | - } | |
125 | - } catch (CantSendQueryException e) { | |
126 | - ParamField.logger.log(Level.WARNING, | |
127 | - "Can't get table names for the resolver", e); | |
128 | - } | |
129 | - comboBox.getEditor().setItem(content); | |
130 | - comboBox.showPopup(); | |
131 | - } | |
132 | - if (content.isEmpty()) { | |
133 | - requestPanelListener.onParameterRemoved(paramName); | |
134 | - } else { | |
135 | - requestPanelListener.onParameterChanged(paramName, content); | |
136 | - } | |
137 | - } | |
138 | - } | |
139 | - }; | |
140 | 129 | } |
141 | 130 | \ No newline at end of file | ... | ... |
src/main/java/eu/omp/irap/vespa/epntapclient/gui/resultpanel/ResultPanelCtrl.java
... | ... | @@ -23,7 +23,7 @@ import java.nio.file.Paths; |
23 | 23 | import java.util.logging.Level; |
24 | 24 | import java.util.logging.Logger; |
25 | 25 | |
26 | -import eu.omp.irap.vespa.epntapclient.gui.mainPanel.MainPanelCtrl; | |
26 | +import eu.omp.irap.vespa.epntapclient.gui.mainpanel.MainPanelCtrl; | |
27 | 27 | import eu.omp.irap.vespa.votable.controller.VOTableController; |
28 | 28 | |
29 | 29 | /** |
... | ... | @@ -44,11 +44,6 @@ public class ResultPanelCtrl extends VOTableController implements ResultPanelLis |
44 | 44 | view = new ResultPanelView(this); |
45 | 45 | } |
46 | 46 | |
47 | - /* | |
48 | - * @see | |
49 | - * eu.omp.irap.vespa.epntapclient.gui.resultpanel.ResultPanelListener#onDownloadButtonClicked( | |
50 | - * java.io.File) | |
51 | - */ | |
52 | 47 | @Override |
53 | 48 | public void onDownloadButtonClicked(File file) { |
54 | 49 | try { | ... | ... |
src/main/java/eu/omp/irap/vespa/epntapclient/gui/servicespanel/ServicesPanelCtrl.java
... | ... | @@ -18,7 +18,7 @@ package eu.omp.irap.vespa.epntapclient.gui.servicespanel; |
18 | 18 | |
19 | 19 | import java.util.logging.Logger; |
20 | 20 | |
21 | -import eu.omp.irap.vespa.epntapclient.gui.mainPanel.MainPanelCtrl; | |
21 | +import eu.omp.irap.vespa.epntapclient.gui.mainpanel.MainPanelCtrl; | |
22 | 22 | import eu.omp.irap.vespa.epntapclient.service.Queries; |
23 | 23 | import eu.omp.irap.vespa.epntapclient.service.ServiceCore; |
24 | 24 | import eu.omp.irap.vespa.votable.Consts; | ... | ... |
src/main/java/eu/omp/irap/vespa/epntapclient/service/Queries.java
... | ... | @@ -28,8 +28,8 @@ import eu.omp.irap.vespa.votable.utils.StringJoiner; |
28 | 28 | * @author N. Jourdane |
29 | 29 | */ |
30 | 30 | public final class Queries { |
31 | - | |
32 | - public static String RETURN_PARAMETERS = "target_name, target_class"; | |
31 | + | |
32 | + public static final String RETURN_PARAMETERS = "target_name, target_class"; | |
33 | 33 | |
34 | 34 | private static final String SELECT = "SELECT DISTINCT short_name, res_title, " |
35 | 35 | + "table_name, schema_name, ivoid, access_url "; |
... | ... | @@ -115,7 +115,7 @@ public final class Queries { |
115 | 115 | } |
116 | 116 | } |
117 | 117 | String where = addJoin.isEmpty() ? "" : " WHERE " + addJoin; |
118 | - | |
118 | + | |
119 | 119 | return "SELECT TOP " + nbRow + " " |
120 | 120 | + RETURN_PARAMETERS |
121 | 121 | + " " | ... | ... |
src/main/java/eu/omp/irap/vespa/epntapclient/service/ServiceCtrl.java
... | ... | @@ -20,7 +20,6 @@ import java.text.SimpleDateFormat; |
20 | 20 | import java.util.ArrayList; |
21 | 21 | import java.util.List; |
22 | 22 | import java.util.Map; |
23 | -import java.util.logging.Logger; | |
24 | 23 | |
25 | 24 | import javax.xml.datatype.XMLGregorianCalendar; |
26 | 25 | |
... | ... | @@ -42,13 +41,13 @@ import eu.omp.irap.vespa.votable.votabledata.VOTableDataParser; |
42 | 41 | */ |
43 | 42 | public class ServiceCtrl { |
44 | 43 | |
45 | - /** The logger for the class ServiceCtrl. */ | |
46 | - private static final Logger logger = Logger.getLogger(ServiceCtrl.class.getName()); | |
47 | - | |
48 | 44 | public static final String DATE_FORMAT = "yyyy/MM/dd HH:mm:ss"; |
49 | 45 | |
50 | 46 | |
51 | - public final static Service getService(Resource resource) { | |
47 | + private ServiceCtrl() { | |
48 | + } | |
49 | + | |
50 | + public static final Service getService(Resource resource) { | |
52 | 51 | Service service = new Service(resource.getIdentifier()); |
53 | 52 | service.setTitle(resource.getTitle()); |
54 | 53 | service.setShortName(resource.getShortName()); |
... | ... | @@ -70,8 +69,8 @@ public class ServiceCtrl { |
70 | 69 | |
71 | 70 | service.setContentLevel(contentLevels.toString()); |
72 | 71 | service.setReferenceURL(resource.getContent().getReferenceURL()); |
73 | - service.setCreated(ServiceCtrl.XMLDateToString(resource.getCreated())); | |
74 | - service.setUpdated(ServiceCtrl.XMLDateToString(resource.getUpdated())); | |
72 | + service.setCreated(ServiceCtrl.xmlDateToString(resource.getCreated())); | |
73 | + service.setUpdated(ServiceCtrl.xmlDateToString(resource.getUpdated())); | |
75 | 74 | return service; |
76 | 75 | } |
77 | 76 | |
... | ... | @@ -130,7 +129,7 @@ public class ServiceCtrl { |
130 | 129 | return getVoTableData(query).getCell(0, 0); |
131 | 130 | } |
132 | 131 | |
133 | - private static String XMLDateToString(XMLGregorianCalendar date) { | |
132 | + private static String xmlDateToString(XMLGregorianCalendar date) { | |
134 | 133 | SimpleDateFormat sdf = new SimpleDateFormat(ServiceCtrl.DATE_FORMAT); |
135 | 134 | return sdf.format(date.toGregorianCalendar().getTime()); |
136 | 135 | } | ... | ... |
src/main/java/eu/omp/irap/vespa/epntapclient/voresource/VOResourceCtrl.java
... | ... | @@ -67,11 +67,14 @@ public class VOResourceCtrl { |
67 | 67 | private static final String NAMESPACE_TR = "http://www.ivoa.net/xml/VODataService/v1.1"; |
68 | 68 | |
69 | 69 | |
70 | + private VOResourceCtrl() { | |
71 | + } | |
72 | + | |
70 | 73 | public static List<String> getVOResources(ServiceCore type) throws VOResourceException { |
71 | 74 | List<String> ivoidResources; |
72 | 75 | Map<String, String> parameters = new HashMap(); |
73 | 76 | |
74 | - parameters.put("keywords", "datamodel:\"EpnCore\""); | |
77 | + parameters.put("keywords", "datamodel:\"" + type.toString() + "\""); | |
75 | 78 | parameters.put("max", String.valueOf(MAX_VORESOURCES)); |
76 | 79 | String query = Network.buildQuery(GET_JSONRESOURCES_URL, parameters); |
77 | 80 | try { |
... | ... | @@ -88,7 +91,8 @@ public class VOResourceCtrl { |
88 | 91 | List<String> ivoidResources; |
89 | 92 | Map<String, String> parameters = new HashMap(); |
90 | 93 | String subjects = StringJoiner.join(keywords); |
91 | - parameters.put("keywords", "datamodel:\"EpnCore\" subjects:\"" + subjects + "\""); | |
94 | + parameters.put("keywords", | |
95 | + "datamodel:\"" + type.toString() + "\" subjects:\"" + subjects + "\""); | |
92 | 96 | parameters.put("max", String.valueOf(MAX_VORESOURCES)); |
93 | 97 | |
94 | 98 | String query = Network.buildQuery(GET_JSONRESOURCES_URL, parameters); |
... | ... | @@ -130,7 +134,6 @@ public class VOResourceCtrl { |
130 | 134 | Unmarshaller unmarshaller = jc.createUnmarshaller(); |
131 | 135 | voResource = unmarshaller.unmarshal(source, Resource.class).getValue(); |
132 | 136 | |
133 | - // erreur sur : o = unmarshaller.unmarshal(f); | |
134 | 137 | } catch (JAXBException e) { |
135 | 138 | throw new VOResourceIsNotValidException(voResourcePath, e); |
136 | 139 | } | ... | ... |