Blame view

src/main/java/eu/omp/irap/vespa/epntapclient/EpnTapController.java 3.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
	/**
285505be   Nathanael Jourdane   Remove complex co...
56
	 * @return The request controller.
eda63a5c   Nathanael Jourdane   Add Javadoc.
57
	 */
285505be   Nathanael Jourdane   Remove complex co...
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
	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...
74
75
	}

30e4599b   Nathanael Jourdane   Add Javadoc
76
77
78
	/**
	 * @return the path of the XML VOTable file.
	 */
5672c106   Nathanael Jourdane   Fix Sonar issues.
79
80
81
82
	public String getVOTablePath() {
		return voTablePath;
	}

1353e182   Nathanael Jourdane   Add minimal eleme...
83
	/**
285505be   Nathanael Jourdane   Remove complex co...
84
	 * Get the services from the XML path or the targetURL / query.
02448921   Nathanael Jourdane   Improve service p...
85
86
	 *
	 * @throws VOTableException Can not read the services.
1353e182   Nathanael Jourdane   Add minimal eleme...
87
	 */
02448921   Nathanael Jourdane   Improve service p...
88
	public void readServices() throws VOTableException {
285505be   Nathanael Jourdane   Remove complex co...
89
90
		// Here getServicesCtrl() is used instead of class field servicesCtrl to get the
		// subclass field, since subclasses overrides getServicesCtrl().
8b66e087   Nathanael Jourdane   Make readTable() ...
91
92
93
		String query = String.format(Queries.SELECT_ALL_TAP_SERVICES_WHERE_CORE,
				ServiceCore.EPNCORE);
		getServicesCtrl().newVOTable(Consts.DEFAULT_REGISTRY_URL, query);
1353e182   Nathanael Jourdane   Add minimal eleme...
94
95
	}

02448921   Nathanael Jourdane   Improve service p...
96
97
98
	/**
	 * ...
	 *
987f00a7   Nathanael Jourdane   Use ServicesList ...
99
	 * @param services The services to send the queries.
02448921   Nathanael Jourdane   Improve service p...
100
	 * @throws VOTableException Can not update the VOTable.
02448921   Nathanael Jourdane   Improve service p...
101
	 */
987f00a7   Nathanael Jourdane   Use ServicesList ...
102
	public void sendQueries(ServicesList services) throws VOTableException {
285505be   Nathanael Jourdane   Remove complex co...
103
104
105
		// Here getRequestCtrl() and getResultsCtrl() are used instead of class fields requestCtrl
		// and resultCtrl to get the subclass field, since subclasses overrides getRequestCtrl() and
		// getResultsCtrl().
987f00a7   Nathanael Jourdane   Use ServicesList ...
106
		List<String> servicesUrls = services.getTargetUrls();
02448921   Nathanael Jourdane   Improve service p...
107
		LOGGER.info("Sending query(ies) on " + StringJoiner.join(servicesUrls));
987f00a7   Nathanael Jourdane   Use ServicesList ...
108
109
		for (int i = 0; i < servicesUrls.size(); i++) {
			String query = getRequestCtrl().getQuery(services.getTableNames().get(i));
8b66e087   Nathanael Jourdane   Make readTable() ...
110
			getResultsCtrl().appendVOTable(servicesUrls.get(i), query);
285505be   Nathanael Jourdane   Remove complex co...
111
112
		}

18446806   Jean-Michel Glorian   add custom EPN TA...
113
	}
1353e182   Nathanael Jourdane   Add minimal eleme...
114
}