Blame view

src/main/java/eu/omp/irap/vespa/epntapclient/EpnTapController.java 4.25 KB
1353e182   Nathanael Jourdane   Add minimal eleme...
1
2
3
4
5
/*
 * This file is a part of EpnTAPClient.
 * This program aims to provide EPN-TAP support for software clients, like CASSIS spectrum analyzer.
 * See draft specifications: https://voparis-confluence.obspm.fr/pages/viewpage.action?pageId=559861
 * Copyright (C) 2016 Institut de Recherche en Astrophysique et Planétologie.
1e543ea0   Nathanael Jourdane   Code clean-up
6
 *
1353e182   Nathanael Jourdane   Add minimal eleme...
7
8
9
10
11
12
13
14
15
16
 * This program is free software: you can
 * redistribute it and/or modify it under the terms of the GNU General Public License as published
 * by the Free Software Foundation, either version 3 of the License, or (at your option) any later
 * version. This program is distributed in the hope that it will be useful, but WITHOUT ANY
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
 * PURPOSE. See the GNU General Public License for more details. You should have received a copy of
 * the GNU General Public License along with this program. If not, see
 * <http://www.gnu.org/licenses/>.
 */

5e72363b   Nathanael Jourdane   Change project ar...
17
package eu.omp.irap.vespa.epntapclient;
1353e182   Nathanael Jourdane   Add minimal eleme...
18

5af53be7   Nathanael Jourdane   Make the applicat...
19
20
import java.util.HashMap;
import java.util.Map;
eae7b5f9   Nathanael Jourdane   bugfix #1
21
import java.util.logging.Level;
5d3c344e   Nathanael Jourdane   Use Java logging ...
22
import java.util.logging.Logger;
7706bfa4   Nathanael Jourdane   Use log4j as logg...
23

4bcbd19f   Nathanael Jourdane   Fix imports
24
import eu.omp.irap.vespa.epntapclient.service.Queries;
cfbb6d07   Nathanael Jourdane   Implement most of...
25
import eu.omp.irap.vespa.epntapclient.service.ServiceCore;
e2264856   Nathanael Jourdane   Delete votable pa...
26
import eu.omp.irap.vespa.votable.Consts;
cfbb6d07   Nathanael Jourdane   Implement most of...
27
import eu.omp.irap.vespa.votable.controller.CantGetVOTableException;
e2264856   Nathanael Jourdane   Delete votable pa...
28
import eu.omp.irap.vespa.votable.controller.VOTableController;
1353e182   Nathanael Jourdane   Add minimal eleme...
29
30

/**
a227a22d   Nathanael Jourdane   Add comments.
31
 * The main controller which manage views and controllers.
1e543ea0   Nathanael Jourdane   Code clean-up
32
 *
1353e182   Nathanael Jourdane   Add minimal eleme...
33
34
 * @author N. Jourdane
 */
6dd0d332   Nathanael Jourdane   The controller do...
35
public class EpnTapController {
aa2a59ba   Nathanael Jourdane   [coding style] 2 ...
36

5d3c344e   Nathanael Jourdane   Use Java logging ...
37
	/** The logger for the class EpnTapController. */
6dd0d332   Nathanael Jourdane   The controller do...
38
	private static final Logger logger = Logger.getLogger(EpnTapController.class.getName());
1353e182   Nathanael Jourdane   Add minimal eleme...
39

4cc84b63   Nathanael Jourdane   Add the possibili...
40
	/** The controller of the VOTable displaying the list of services. */
6dd0d332   Nathanael Jourdane   The controller do...
41
	protected VOTableController servicesCtrl;
6415d908   Nathanael Jourdane   Get all tap servi...
42

cfbb6d07   Nathanael Jourdane   Implement most of...
43
	/** The controller of the VOTable displaying the result. */
6dd0d332   Nathanael Jourdane   The controller do...
44
	protected VOTableController resultsCtrl;
ccd40d6d   Nathanael Jourdane   Add download button
45

1353e182   Nathanael Jourdane   Add minimal eleme...
46
	/**
5af53be7   Nathanael Jourdane   Make the applicat...
47
48
	 * The parameters fields for the request.
	 */
6dd0d332   Nathanael Jourdane   The controller do...
49
	protected Map<String, Object> paramValues = new HashMap<>();
5af53be7   Nathanael Jourdane   Make the applicat...
50

aa2a59ba   Nathanael Jourdane   [coding style] 2 ...
51

5af53be7   Nathanael Jourdane   Make the applicat...
52
	/**
a227a22d   Nathanael Jourdane   Add comments.
53
	 * Method constructor, which initialize servicesController, resultsController and mainView.
1353e182   Nathanael Jourdane   Add minimal eleme...
54
55
	 */
	public EpnTapController() {
eae7b5f9   Nathanael Jourdane   bugfix #1
56
57
		String query = String.format(Queries.SELECT_ALL_TAP_SERVICES_WHERE_CORE,
				ServiceCore.EPNCORE);
cfbb6d07   Nathanael Jourdane   Implement most of...
58
		servicesCtrl = new VOTableController(Consts.DEFAULT_REGISTRY_URL, query);
eae7b5f9   Nathanael Jourdane   bugfix #1
59
60
	}

eda63a5c   Nathanael Jourdane   Add Javadoc.
61
62
63
	/**
	 * Get the services from the XML path or the targetURL / query.
	 */
eae7b5f9   Nathanael Jourdane   bugfix #1
64
65
66
67
	public void readServices() {
		try {
			servicesCtrl.readTable();
		} catch (CantGetVOTableException e) {
9b0dade9   Nathanael Jourdane   Improve error dis...
68
			displayError("Can not get services.", e);
eae7b5f9   Nathanael Jourdane   bugfix #1
69
70
71
		}
	}

eda63a5c   Nathanael Jourdane   Add Javadoc.
72
73
74
75
76
77
78
	/**
	 * display an error with the logger.
	 *
	 * @param message A small error message.
	 * @param e The error.
	 */
	@SuppressWarnings("static-method")
9b0dade9   Nathanael Jourdane   Improve error dis...
79
80
	public void displayError(String message, Exception e) {
		logger.log(Level.SEVERE, message, e);
1353e182   Nathanael Jourdane   Add minimal eleme...
81
82
	}

eda63a5c   Nathanael Jourdane   Add Javadoc.
83
84
85
86
87
88
89
90
91
	/**
	 * Send the query to the specified service.
	 *
	 * @param query An ADQL query to send.
	 * @param tableServiceURL the URL of the service.
	 * @return The Path of the VOTable containing the result, downloaded in the system temporary
	 *         path.
	 * @throws CantGetVOTableException Can not get the VOTable.
	 */
6dd0d332   Nathanael Jourdane   The controller do...
92
	public String sendQuery(String query, String tableServiceURL)
cfbb6d07   Nathanael Jourdane   Implement most of...
93
94
			throws CantGetVOTableException {
		resultsCtrl = new VOTableController(tableServiceURL, query);
6dd0d332   Nathanael Jourdane   The controller do...
95
96
		resultsCtrl.readTable();
		return resultsCtrl.getVOTablePath();
1353e182   Nathanael Jourdane   Add minimal eleme...
97
98
99
	}

	/**
a227a22d   Nathanael Jourdane   Add comments.
100
	 * @return The controller of the VOTable which displays the result of the query.
1353e182   Nathanael Jourdane   Add minimal eleme...
101
102
	 */
	public VOTableController getResultsController() {
6dd0d332   Nathanael Jourdane   The controller do...
103
		return resultsCtrl;
1353e182   Nathanael Jourdane   Add minimal eleme...
104
105
106
	}

	/**
a227a22d   Nathanael Jourdane   Add comments.
107
	 * @return The controller of the VOTable which displays the list of services.
1353e182   Nathanael Jourdane   Add minimal eleme...
108
109
	 */
	public VOTableController getServicesController() {
6dd0d332   Nathanael Jourdane   The controller do...
110
		return servicesCtrl;
18446806   Jean-Michel Glorian   add custom EPN TA...
111
112
	}

eda63a5c   Nathanael Jourdane   Add Javadoc.
113
114
115
116
117
118
	/**
	 * Update a specified parameter
	 *
	 * @param paramName The name of the parameter.
	 * @param paramValue The new value of the parameter
	 */
6dd0d332   Nathanael Jourdane   The controller do...
119
	public void updateParameter(String paramName, Object paramValue) {
0f1bce56   Nathanael Jourdane   Use a listerner i...
120
		paramValues.put(paramName, paramValue);
0f1bce56   Nathanael Jourdane   Use a listerner i...
121
	}
5af53be7   Nathanael Jourdane   Make the applicat...
122

eda63a5c   Nathanael Jourdane   Add Javadoc.
123
124
125
126
127
	/**
	 * Remove a specified parameter.
	 *
	 * @param paramName the name of the parameter.
	 */
6dd0d332   Nathanael Jourdane   The controller do...
128
	public void removeParameter(String paramName) {
0f1bce56   Nathanael Jourdane   Use a listerner i...
129
		paramValues.remove(paramName);
6dd0d332   Nathanael Jourdane   The controller do...
130
131
	}

eda63a5c   Nathanael Jourdane   Add Javadoc.
132
133
134
135
136
	/**
	 * Get the values of all the parameters.
	 *
	 * @return A map containing all the values, as couples <key, value>.
	 */
6dd0d332   Nathanael Jourdane   The controller do...
137
138
	public Map<String, Object> getParamValues() {
		return paramValues;
5af53be7   Nathanael Jourdane   Make the applicat...
139
	}
1353e182   Nathanael Jourdane   Add minimal eleme...
140
}