Blame view

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

285505be   Nathanael Jourdane   Remove complex co...
19
import java.util.List;
eae7b5f9   Nathanael Jourdane   bugfix #1
20
import java.util.logging.Level;
5d3c344e   Nathanael Jourdane   Use Java logging ...
21
import java.util.logging.Logger;
7706bfa4   Nathanael Jourdane   Use log4j as logg...
22

4bcbd19f   Nathanael Jourdane   Fix imports
23
import eu.omp.irap.vespa.epntapclient.service.Queries;
cfbb6d07   Nathanael Jourdane   Implement most of...
24
import eu.omp.irap.vespa.epntapclient.service.ServiceCore;
e2264856   Nathanael Jourdane   Delete votable pa...
25
import eu.omp.irap.vespa.votable.Consts;
e2264856   Nathanael Jourdane   Delete votable pa...
26
import eu.omp.irap.vespa.votable.controller.VOTableController;
285505be   Nathanael Jourdane   Remove complex co...
27
28
import eu.omp.irap.vespa.votable.controller.VOTableException;
import eu.omp.irap.vespa.votable.utils.StringJoiner;
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
 */
285505be   Nathanael Jourdane   Remove complex co...
35
public abstract class EpnTapController {
aa2a59ba   Nathanael Jourdane   [coding style] 2 ...
36

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

285505be   Nathanael Jourdane   Remove complex co...
40
41
42
43
44
45
46
47
48
	/** The request controller, to manage requests. */
	private RequestCtrl requestCtrl;

	/** The controller of the VOTable displaying the result. */
	private VOTableController resultsCtrl;

	/** The controller of the VOTable displaying the list of services. */
	private VOTableController servicesCtrl;

45fb4583   Nathanael Jourdane   Sort methods and ...
49
50
51
52
53
54
	/**
	 * The path of the VOTable to parse. Will be affected to a temporary folder if not assigned
	 * through the controller.
	 */
	private String voTablePath;

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

5af53be7   Nathanael Jourdane   Make the applicat...
56
	/**
a227a22d   Nathanael Jourdane   Add comments.
57
	 * Method constructor, which initialize servicesController, resultsController and mainView.
1353e182   Nathanael Jourdane   Add minimal eleme...
58
59
	 */
	public EpnTapController() {
285505be   Nathanael Jourdane   Remove complex co...
60
		// TODO: Should not init controllers, because the default ctrl is called by subclasses.
eae7b5f9   Nathanael Jourdane   bugfix #1
61
62
		String query = String.format(Queries.SELECT_ALL_TAP_SERVICES_WHERE_CORE,
				ServiceCore.EPNCORE);
cfbb6d07   Nathanael Jourdane   Implement most of...
63
		servicesCtrl = new VOTableController(Consts.DEFAULT_REGISTRY_URL, query);
eae7b5f9   Nathanael Jourdane   bugfix #1
64
65
	}

eda63a5c   Nathanael Jourdane   Add Javadoc.
66
	/**
285505be   Nathanael Jourdane   Remove complex co...
67
	 * Display an error with the logger.
eda63a5c   Nathanael Jourdane   Add Javadoc.
68
69
70
71
	 *
	 * @param message A small error message.
	 * @param e The error.
	 */
285505be   Nathanael Jourdane   Remove complex co...
72
	@SuppressWarnings("static-method") // Because the method is overrided by a subclass.
9b0dade9   Nathanael Jourdane   Improve error dis...
73
	public void displayError(String message, Exception e) {
fd93317f   Nathanael Jourdane   Solve Sonar/Eclip...
74
		LOGGER.log(Level.SEVERE, message, e);
1353e182   Nathanael Jourdane   Add minimal eleme...
75
76
	}

eda63a5c   Nathanael Jourdane   Add Javadoc.
77
	/**
285505be   Nathanael Jourdane   Remove complex co...
78
	 * @return The request controller.
eda63a5c   Nathanael Jourdane   Add Javadoc.
79
	 */
285505be   Nathanael Jourdane   Remove complex co...
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
	public RequestCtrl getRequestCtrl() {
		return requestCtrl;
	}

	/**
	 * @return The controller of the VOTable which displays the result of the query.
	 */
	public VOTableController getResultsCtrl() {
		return resultsCtrl;
	}

	/**
	 * @return The controller of the VOTable which displays the list of services.
	 */
	public VOTableController getServicesCtrl() {
		return servicesCtrl;
1353e182   Nathanael Jourdane   Add minimal eleme...
96
97
	}

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

1353e182   Nathanael Jourdane   Add minimal eleme...
105
	/**
285505be   Nathanael Jourdane   Remove complex co...
106
	 * Get the services from the XML path or the targetURL / query.
1353e182   Nathanael Jourdane   Add minimal eleme...
107
	 */
285505be   Nathanael Jourdane   Remove complex co...
108
109
110
111
112
113
114
115
	public void readServices() {
		// Here getServicesCtrl() is used instead of class field servicesCtrl to get the
		// subclass field, since subclasses overrides getServicesCtrl().
		try {
			getServicesCtrl().readTable();
		} catch (VOTableException e) {
			displayError("Can not get services.", e);
		}
1353e182   Nathanael Jourdane   Add minimal eleme...
116
117
	}

285505be   Nathanael Jourdane   Remove complex co...
118
119
120
121
122
123
124
125
126
127
128
129
130
131
	public void sendQuery(List<String> tableNames, List<String> servicesUrls) {
		// Here getRequestCtrl() and getResultsCtrl() are used instead of class fields requestCtrl
		// and resultCtrl to get the subclass field, since subclasses overrides getRequestCtrl() and
		// getResultsCtrl().
		try {
			LOGGER.info("Sending queries on " + StringJoiner.join(servicesUrls));
			for (int i = 0; i < tableNames.size(); i++) {
				String query = getRequestCtrl().getQuery(tableNames.get(i));
				getResultsCtrl().updateVOTable(servicesUrls.get(i), query);
			}
		} catch (VOTableException e) {
			displayError("Can not update the VOTable.", e);
		}

18446806   Jean-Michel Glorian   add custom EPN TA...
132
133
	}

30e4599b   Nathanael Jourdane   Add Javadoc
134
	/**
285505be   Nathanael Jourdane   Remove complex co...
135
136
137
138
139
	 * Send the query to the specified service, download the result and update the voTable path.
	 *
	 * @param query An ADQL query to send.
	 * @param tableServiceURL the URL of the service.
	 * @throws VOTableException Can not get the VOTable.
30e4599b   Nathanael Jourdane   Add Javadoc
140
	 */
285505be   Nathanael Jourdane   Remove complex co...
141
142
143
144
	public void sendQuery(String query, String tableServiceURL) throws VOTableException {
		resultsCtrl = new VOTableController(tableServiceURL, query);
		resultsCtrl.readTable();
		voTablePath = resultsCtrl.getVOTablePath();
0f1bce56   Nathanael Jourdane   Use a listerner i...
145
	}
5af53be7   Nathanael Jourdane   Make the applicat...
146

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