Blame view

src/main/java/eu/omp/irap/vespa/epntapclient/EpnTapController.java 3.84 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

eae7b5f9   Nathanael Jourdane   bugfix #1
19
import java.util.logging.Level;
5d3c344e   Nathanael Jourdane   Use Java logging ...
20
import java.util.logging.Logger;
7706bfa4   Nathanael Jourdane   Use log4j as logg...
21

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

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

5d3c344e   Nathanael Jourdane   Use Java logging ...
35
	/** The logger for the class EpnTapController. */
fd93317f   Nathanael Jourdane   Solve Sonar/Eclip...
36
	private static final Logger LOGGER = Logger.getLogger(EpnTapController.class.getName());
1353e182   Nathanael Jourdane   Add minimal eleme...
37

4cc84b63   Nathanael Jourdane   Add the possibili...
38
	/** The controller of the VOTable displaying the list of services. */
0d36b4b0   Nathanael Jourdane   Use RequestPanelC...
39
	private VOTableController servicesCtrl;
6415d908   Nathanael Jourdane   Get all tap servi...
40

cfbb6d07   Nathanael Jourdane   Implement most of...
41
	/** The controller of the VOTable displaying the result. */
0d36b4b0   Nathanael Jourdane   Use RequestPanelC...
42
	private VOTableController resultsCtrl;
ccd40d6d   Nathanael Jourdane   Add download button
43

30e4599b   Nathanael Jourdane   Add Javadoc
44
	/** The request controller, to manage requests. */
0d36b4b0   Nathanael Jourdane   Use RequestPanelC...
45
46
	private RequestCtrl requestCtrl;

30e4599b   Nathanael Jourdane   Add Javadoc
47
48
49
50
	/**
	 * The path of the VOTable to parse. Will be affected to a temporary folder if not assigned
	 * through the controller.
	 */
0d36b4b0   Nathanael Jourdane   Use RequestPanelC...
51
	private String voTablePath;
5af53be7   Nathanael Jourdane   Make the applicat...
52

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

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

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

eda63a5c   Nathanael Jourdane   Add Javadoc.
74
75
76
77
78
79
80
	/**
	 * 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...
81
	public void displayError(String message, Exception e) {
fd93317f   Nathanael Jourdane   Solve Sonar/Eclip...
82
		LOGGER.log(Level.SEVERE, message, e);
1353e182   Nathanael Jourdane   Add minimal eleme...
83
84
	}

eda63a5c   Nathanael Jourdane   Add Javadoc.
85
	/**
30e4599b   Nathanael Jourdane   Add Javadoc
86
	 * Send the query to the specified service, download the result and update the voTable path.
eda63a5c   Nathanael Jourdane   Add Javadoc.
87
88
89
	 *
	 * @param query An ADQL query to send.
	 * @param tableServiceURL the URL of the service.
e669c5d3   Nathanael Jourdane   Improve Javadoc.
90
	 * @throws VOTableException Can not get the VOTable.
eda63a5c   Nathanael Jourdane   Add Javadoc.
91
	 */
0d36b4b0   Nathanael Jourdane   Use RequestPanelC...
92
	public void sendQuery(String query, String tableServiceURL)
e669c5d3   Nathanael Jourdane   Improve Javadoc.
93
			throws VOTableException {
cfbb6d07   Nathanael Jourdane   Implement most of...
94
		resultsCtrl = new VOTableController(tableServiceURL, query);
6dd0d332   Nathanael Jourdane   The controller do...
95
		resultsCtrl.readTable();
0d36b4b0   Nathanael Jourdane   Use RequestPanelC...
96
		voTablePath = resultsCtrl.getVOTablePath();
1353e182   Nathanael Jourdane   Add minimal eleme...
97
98
	}

30e4599b   Nathanael Jourdane   Add Javadoc
99
100
101
	/**
	 * @return the path of the XML VOTable file.
	 */
5672c106   Nathanael Jourdane   Fix Sonar issues.
102
103
104
105
	public String getVOTablePath() {
		return voTablePath;
	}

1353e182   Nathanael Jourdane   Add minimal eleme...
106
	/**
a227a22d   Nathanael Jourdane   Add comments.
107
	 * @return The controller of the VOTable which displays the result of the query.
1353e182   Nathanael Jourdane   Add minimal eleme...
108
109
	 */
	public VOTableController getResultsController() {
6dd0d332   Nathanael Jourdane   The controller do...
110
		return resultsCtrl;
1353e182   Nathanael Jourdane   Add minimal eleme...
111
112
113
	}

	/**
a227a22d   Nathanael Jourdane   Add comments.
114
	 * @return The controller of the VOTable which displays the list of services.
1353e182   Nathanael Jourdane   Add minimal eleme...
115
116
	 */
	public VOTableController getServicesController() {
6dd0d332   Nathanael Jourdane   The controller do...
117
		return servicesCtrl;
18446806   Jean-Michel Glorian   add custom EPN TA...
118
119
	}

30e4599b   Nathanael Jourdane   Add Javadoc
120
121
122
	/**
	 * @return The request controller.
	 */
6f25e39e   Nathanael Jourdane   Use ServicePanelC...
123
	public RequestCtrl getRequestCtrl() {
0d36b4b0   Nathanael Jourdane   Use RequestPanelC...
124
		return requestCtrl;
0f1bce56   Nathanael Jourdane   Use a listerner i...
125
	}
5af53be7   Nathanael Jourdane   Make the applicat...
126

1353e182   Nathanael Jourdane   Add minimal eleme...
127
}