Blame view

src/main/java/eu/omp/irap/vespa/epntapclient/EpnTapController.java 4.86 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;
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;
e2264856   Nathanael Jourdane   Delete votable pa...
25
import eu.omp.irap.vespa.votable.controller.VOTableController;
285505be   Nathanael Jourdane   Remove complex co...
26
27
import eu.omp.irap.vespa.votable.controller.VOTableException;
import eu.omp.irap.vespa.votable.utils.StringJoiner;
1353e182   Nathanael Jourdane   Add minimal eleme...
28
29

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

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

285505be   Nathanael Jourdane   Remove complex co...
39
40
41
42
43
44
45
46
47
	/** 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 ...
48
49
50
51
52
53
	/**
	 * 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 ...
54

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

eda63a5c   Nathanael Jourdane   Add Javadoc.
65
	/**
285505be   Nathanael Jourdane   Remove complex co...
66
	 * @return The request controller.
eda63a5c   Nathanael Jourdane   Add Javadoc.
67
	 */
285505be   Nathanael Jourdane   Remove complex co...
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
	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...
84
85
	}

30e4599b   Nathanael Jourdane   Add Javadoc
86
87
88
	/**
	 * @return the path of the XML VOTable file.
	 */
5672c106   Nathanael Jourdane   Fix Sonar issues.
89
90
91
92
	public String getVOTablePath() {
		return voTablePath;
	}

1353e182   Nathanael Jourdane   Add minimal eleme...
93
	/**
285505be   Nathanael Jourdane   Remove complex co...
94
	 * Get the services from the XML path or the targetURL / query.
02448921   Nathanael Jourdane   Improve service p...
95
96
	 *
	 * @throws VOTableException Can not read the services.
1353e182   Nathanael Jourdane   Add minimal eleme...
97
	 */
02448921   Nathanael Jourdane   Improve service p...
98
	public void readServices() throws VOTableException {
285505be   Nathanael Jourdane   Remove complex co...
99
100
		// Here getServicesCtrl() is used instead of class field servicesCtrl to get the
		// subclass field, since subclasses overrides getServicesCtrl().
02448921   Nathanael Jourdane   Improve service p...
101
		getServicesCtrl().readTable();
1353e182   Nathanael Jourdane   Add minimal eleme...
102
103
	}

02448921   Nathanael Jourdane   Improve service p...
104
105
106
107
108
109
110
111
112
113
	/**
	 * ...
	 *
	 * @param tableNames
	 * @param servicesUrls
	 * @throws VOTableException Can not update the VOTable.
	 * @throws EpnTapException The lists are empty.
	 */
	public void sendQuery(List<String> tableNames, List<String> servicesUrls)
			throws VOTableException, EpnTapException {
285505be   Nathanael Jourdane   Remove complex co...
114
115
116
		// Here getRequestCtrl() and getResultsCtrl() are used instead of class fields requestCtrl
		// and resultCtrl to get the subclass field, since subclasses overrides getRequestCtrl() and
		// getResultsCtrl().
02448921   Nathanael Jourdane   Improve service p...
117
118
119
120
121
122
123
124
125
126
		LOGGER.info("Sending query(ies) on " + StringJoiner.join(servicesUrls));
		if (tableNames.isEmpty()) {
			throw new EpnTapException("There is no service to query.");
		} else if (tableNames.size() != servicesUrls.size()) {
			throw new EpnTapException(
					"list of tableNames and list of servicesUrls are not the same size.");
		}
		for (int i = 0; i < tableNames.size(); i++) {
			String query = getRequestCtrl().getQuery(tableNames.get(i));
			getResultsCtrl().updateVOTable(servicesUrls.get(i), query);
285505be   Nathanael Jourdane   Remove complex co...
127
128
		}

18446806   Jean-Michel Glorian   add custom EPN TA...
129
130
	}

30e4599b   Nathanael Jourdane   Add Javadoc
131
	/**
285505be   Nathanael Jourdane   Remove complex co...
132
133
134
135
136
	 * 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
137
	 */
285505be   Nathanael Jourdane   Remove complex co...
138
139
140
141
	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...
142
	}
5af53be7   Nathanael Jourdane   Make the applicat...
143

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