Blame view

src/main/java/eu/omp/irap/vespa/epntapclient/EpnTapConnection.java 5.63 KB
fa934e09   Nathanael Jourdane   Add the epntap fa...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
/*
 * 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.
 *
 * 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;
fa934e09   Nathanael Jourdane   Add the epntap fa...
18

cfbb6d07   Nathanael Jourdane   Implement most of...
19
import java.text.ParseException;
4b3a296c   Nathanael Jourdane   Implement getServ...
20
import java.util.ArrayList;
fa934e09   Nathanael Jourdane   Add the epntap fa...
21
import java.util.List;
fa934e09   Nathanael Jourdane   Add the epntap fa...
22

cfbb6d07   Nathanael Jourdane   Implement most of...
23
24
25
import eu.omp.irap.vespa.epntapclient.granule.Granule;
import eu.omp.irap.vespa.epntapclient.granule.GranuleCtrl;
import eu.omp.irap.vespa.epntapclient.service.Queries;
cfbb6d07   Nathanael Jourdane   Implement most of...
26
27
28
29
import eu.omp.irap.vespa.epntapclient.service.ServiceCore;
import eu.omp.irap.vespa.epntapclient.service.ServiceCtrl;
import eu.omp.irap.vespa.epntapclient.voresource.VOResourceCtrl;
import eu.omp.irap.vespa.epntapclient.voresource.VOResourceException;
fa934e09   Nathanael Jourdane   Add the epntap fa...
30
import eu.omp.irap.vespa.epntapclient.voresource.model.Resource;
cfbb6d07   Nathanael Jourdane   Implement most of...
31
import eu.omp.irap.vespa.epntapclient.votable.model.VOTABLE;
99642cfe   Nathanael Jourdane   Improve unit test...
32
import eu.omp.irap.vespa.votable.controller.VOTableController;
e669c5d3   Nathanael Jourdane   Improve Javadoc.
33
import eu.omp.irap.vespa.votable.controller.VOTableException;
6b128e20   Nathanael Jourdane   Add lasts Javadoc...
34
import eu.omp.irap.vespa.votable.controller.VOTableException.CantParseVOTableException;
1f971475   Nathanael Jourdane   Granule parsing: ...
35
import eu.omp.irap.vespa.votable.utils.Debug;
9144ee77   Nathanael Jourdane   Implement Service...
36
import eu.omp.irap.vespa.votable.utils.StringJoiner;
cfbb6d07   Nathanael Jourdane   Implement most of...
37
import eu.omp.irap.vespa.votable.votabledata.VOTableData;
fa934e09   Nathanael Jourdane   Add the epntap fa...
38
39
40
41

/**
 * @author N. Jourdane
 */
58950524   Nathanael Jourdane   #2 Rename EpnTapF...
42
public class EpnTapConnection implements EpnTapInterface {
fa934e09   Nathanael Jourdane   Add the epntap fa...
43

cfbb6d07   Nathanael Jourdane   Implement most of...
44
45
	// *** Resource ***

fa934e09   Nathanael Jourdane   Add the epntap fa...
46
	@Override
cfbb6d07   Nathanael Jourdane   Implement most of...
47
48
	public Resource getEPNVOresource(String ivoid) throws VOResourceException {
		return VOResourceCtrl.getVOresource(ivoid);
fa934e09   Nathanael Jourdane   Add the epntap fa...
49
50
	}

cfbb6d07   Nathanael Jourdane   Implement most of...
51
52
	// *** Resources ***

fa934e09   Nathanael Jourdane   Add the epntap fa...
53
	@Override
cfbb6d07   Nathanael Jourdane   Implement most of...
54
	public List<Resource> getEPNVOResources() throws VOResourceException {
e669c5d3   Nathanael Jourdane   Improve Javadoc.
55
		List<String> ivoids = VOResourceCtrl.getIvoidResources(ServiceCore.EPNCORE);
35daa117   Nathanael Jourdane   Improve JUnits te...
56
		return VOResourceCtrl.getVOResources(ivoids);
fa934e09   Nathanael Jourdane   Add the epntap fa...
57
58
	}

fa934e09   Nathanael Jourdane   Add the epntap fa...
59
	@Override
35daa117   Nathanael Jourdane   Improve JUnits te...
60
	public List<Resource> getEPNVOResources(List<String> keywords)
cfbb6d07   Nathanael Jourdane   Implement most of...
61
			throws VOResourceException {
35daa117   Nathanael Jourdane   Improve JUnits te...
62
63
		List<String> ivoids = VOResourceCtrl.getVOResources(ServiceCore.EPNCORE, keywords);
		return VOResourceCtrl.getVOResources(ivoids);
fa934e09   Nathanael Jourdane   Add the epntap fa...
64
65
	}

cfbb6d07   Nathanael Jourdane   Implement most of...
66
	// *** Service ***
fa934e09   Nathanael Jourdane   Add the epntap fa...
67

fa934e09   Nathanael Jourdane   Add the epntap fa...
68
	@Override
e669c5d3   Nathanael Jourdane   Improve Javadoc.
69
	public VOTABLE getEPNService(String ivoid) throws VOTableException {
35daa117   Nathanael Jourdane   Improve JUnits te...
70
71
		String query = String.format(Queries.SELECT_ALL_TAP_SERVICES_WHERE_IVOID, ivoid);
		return ServiceCtrl.getVoTable(query);
fa934e09   Nathanael Jourdane   Add the epntap fa...
72
73
	}

fa934e09   Nathanael Jourdane   Add the epntap fa...
74
	@Override
cfbb6d07   Nathanael Jourdane   Implement most of...
75
	public VOTABLE getEPNService(String ivoid, List<String> attributes)
e669c5d3   Nathanael Jourdane   Improve Javadoc.
76
			throws VOTableException {
35daa117   Nathanael Jourdane   Improve JUnits te...
77
78
79
		String select = StringJoiner.join(attributes);
		String query = String.format(Queries.SELECT_TAP_SERVICES_WHERE_IVOID, select, ivoid);
		return ServiceCtrl.getVoTable(query);
fa934e09   Nathanael Jourdane   Add the epntap fa...
80
81
	}

cfbb6d07   Nathanael Jourdane   Implement most of...
82
	// *** Services ***
fa934e09   Nathanael Jourdane   Add the epntap fa...
83

cfbb6d07   Nathanael Jourdane   Implement most of...
84
	@Override
e669c5d3   Nathanael Jourdane   Improve Javadoc.
85
	public VOTABLE getEPNServices() throws VOTableException {
35daa117   Nathanael Jourdane   Improve JUnits te...
86
87
88
		String query = String.format(Queries.SELECT_ALL_TAP_SERVICES_WHERE_CORE,
				ServiceCore.EPNCORE);
		return ServiceCtrl.getVoTable(query);
fa934e09   Nathanael Jourdane   Add the epntap fa...
89
90
	}

fa934e09   Nathanael Jourdane   Add the epntap fa...
91
	@Override
e669c5d3   Nathanael Jourdane   Improve Javadoc.
92
	public VOTABLE getEPNServices(List<String> attributes) throws VOTableException {
35daa117   Nathanael Jourdane   Improve JUnits te...
93
94
95
		String select = StringJoiner.join(attributes);
		String query = String.format(Queries.SELECT_TAP_SERVICES, select);
		return ServiceCtrl.getVoTable(query);
fa934e09   Nathanael Jourdane   Add the epntap fa...
96
97
	}

fa934e09   Nathanael Jourdane   Add the epntap fa...
98
	@Override
35daa117   Nathanael Jourdane   Improve JUnits te...
99
	public VOTABLE getEPNServices(List<String> keywords, List<String> attributes)
e669c5d3   Nathanael Jourdane   Improve Javadoc.
100
			throws VOTableException {
35daa117   Nathanael Jourdane   Improve JUnits te...
101
102
103
104
105
		attributes.add("res_subject");
		String select = StringJoiner.join(attributes);
		List<String> whereList = new ArrayList<>();
		for (String keyword : keywords) {
			whereList.add("res_subject = '" + keyword + "'");
8ae5b6c8   Nathanael Jourdane   Implement getServ...
106
		}
35daa117   Nathanael Jourdane   Improve JUnits te...
107
108
		String where = StringJoiner.join(whereList, " OR ");
		String query = String.format(Queries.SELECT_TAP_SERVICES_WHERE_SUBJECT, select, where);
35daa117   Nathanael Jourdane   Improve JUnits te...
109
		return ServiceCtrl.getVoTable(query);
fa934e09   Nathanael Jourdane   Add the epntap fa...
110
111
	}

cfbb6d07   Nathanael Jourdane   Implement most of...
112
	// *** Getters ***
fa934e09   Nathanael Jourdane   Add the epntap fa...
113

cfbb6d07   Nathanael Jourdane   Implement most of...
114
	@Override
e669c5d3   Nathanael Jourdane   Improve Javadoc.
115
	public String getEPNCoreTableName(String ivoid) throws VOTableException {
35daa117   Nathanael Jourdane   Improve JUnits te...
116
		return (String) ServiceCtrl.getParameter(ivoid, "table_name");
fa934e09   Nathanael Jourdane   Add the epntap fa...
117
118
	}

fa934e09   Nathanael Jourdane   Add the epntap fa...
119
	@Override
e669c5d3   Nathanael Jourdane   Improve Javadoc.
120
	public String getTAPURL(String ivoid) throws VOTableException {
35daa117   Nathanael Jourdane   Improve JUnits te...
121
		return (String) ServiceCtrl.getParameter(ivoid, "access_url");
fa934e09   Nathanael Jourdane   Add the epntap fa...
122
123
	}

cfbb6d07   Nathanael Jourdane   Implement most of...
124
125
	// *** Queries ***

fa934e09   Nathanael Jourdane   Add the epntap fa...
126
	@Override
cfbb6d07   Nathanael Jourdane   Implement most of...
127
	public List<Granule> sendADQLQuery(String tapURL, String adqlQuery)
e669c5d3   Nathanael Jourdane   Improve Javadoc.
128
			throws VOTableException {
99642cfe   Nathanael Jourdane   Improve unit test...
129
130
131
132
		VOTableController voTableCtrl = new VOTableController(tapURL, adqlQuery);
		voTableCtrl.readTable();
		VOTableData data = voTableCtrl.getVOTableData();

cfbb6d07   Nathanael Jourdane   Implement most of...
133
134
135
		List<Granule> granules;
		try {
			GranuleCtrl gc = new GranuleCtrl(data);
30e4599b   Nathanael Jourdane   Add Javadoc
136
			granules = gc.getGranules();
cfbb6d07   Nathanael Jourdane   Implement most of...
137
		} catch (ParseException e) {
6b128e20   Nathanael Jourdane   Add lasts Javadoc...
138
			throw new CantParseVOTableException("Parsing error on a granule.", e);
cfbb6d07   Nathanael Jourdane   Implement most of...
139
140
141
		}
		return granules;
	}
fa934e09   Nathanael Jourdane   Add the epntap fa...
142

cfbb6d07   Nathanael Jourdane   Implement most of...
143
	@Override
125adfc1   Nathanael Jourdane   Use enumerated qu...
144
	public List<Granule> sendQuery(String tapURL, String schemaName, Query enumeratedQuery)
e669c5d3   Nathanael Jourdane   Improve Javadoc.
145
			throws VOTableException {
125adfc1   Nathanael Jourdane   Use enumerated qu...
146
147
148
149
		String query = String.format(enumeratedQuery.toString(), schemaName);
		VOTableController voTableCtrl = new VOTableController(tapURL, query);
		voTableCtrl.readTable();
		VOTableData data = voTableCtrl.getVOTableData();
1f971475   Nathanael Jourdane   Granule parsing: ...
150
		Debug.writeObject("data", data);
125adfc1   Nathanael Jourdane   Use enumerated qu...
151
152
153
154

		List<Granule> granules;
		try {
			GranuleCtrl gc = new GranuleCtrl(data);
30e4599b   Nathanael Jourdane   Add Javadoc
155
			granules = gc.getGranules();
125adfc1   Nathanael Jourdane   Use enumerated qu...
156
		} catch (ParseException e) {
6b128e20   Nathanael Jourdane   Add lasts Javadoc...
157
			throw new CantParseVOTableException("Parsing error on a granule.", e);
125adfc1   Nathanael Jourdane   Use enumerated qu...
158
159
		}
		return granules;
fa934e09   Nathanael Jourdane   Add the epntap fa...
160
161
162
	}

}