Blame view

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

4b3a296c   Nathanael Jourdane   Implement getServ...
19
import java.util.ArrayList;
fa934e09   Nathanael Jourdane   Add the epntap fa...
20
import java.util.List;
fa934e09   Nathanael Jourdane   Add the epntap fa...
21

1375d734   Nathanael Jourdane   Create package ep...
22
23
24
25
import eu.omp.irap.vespa.epntapclient.epntap.EpnTapInterface;
import eu.omp.irap.vespa.epntapclient.epntap.service.Queries;
import eu.omp.irap.vespa.epntapclient.epntap.service.ServiceCore;
import eu.omp.irap.vespa.epntapclient.epntap.service.ServiceCtrl;
cfbb6d07   Nathanael Jourdane   Implement most of...
26
27
import eu.omp.irap.vespa.epntapclient.granule.Granule;
import eu.omp.irap.vespa.epntapclient.granule.GranuleCtrl;
cfbb6d07   Nathanael Jourdane   Implement most of...
28
29
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;
1f971475   Nathanael Jourdane   Granule parsing: ...
32
import eu.omp.irap.vespa.votable.utils.Debug;
9144ee77   Nathanael Jourdane   Implement Service...
33
import eu.omp.irap.vespa.votable.utils.StringJoiner;
1375d734   Nathanael Jourdane   Create package ep...
34
35
import eu.omp.irap.vespa.votable.votable.VOTableCtrl;
import eu.omp.irap.vespa.votable.votable.VOTableException;
cfbb6d07   Nathanael Jourdane   Implement most of...
36
import eu.omp.irap.vespa.votable.votabledata.VOTableData;
fa934e09   Nathanael Jourdane   Add the epntap fa...
37
38
39
40

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

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

fa934e09   Nathanael Jourdane   Add the epntap fa...
45
	@Override
45fb4583   Nathanael Jourdane   Sort methods and ...
46
47
	public String getEPNCoreTableName(String ivoid) throws VOTableException {
		return (String) ServiceCtrl.getParameter(ivoid, "table_name");
fa934e09   Nathanael Jourdane   Add the epntap fa...
48
49
	}

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

fa934e09   Nathanael Jourdane   Add the epntap fa...
52
	@Override
e669c5d3   Nathanael Jourdane   Improve Javadoc.
53
	public VOTABLE getEPNService(String ivoid) throws VOTableException {
35daa117   Nathanael Jourdane   Improve JUnits te...
54
55
		String query = String.format(Queries.SELECT_ALL_TAP_SERVICES_WHERE_IVOID, ivoid);
		return ServiceCtrl.getVoTable(query);
fa934e09   Nathanael Jourdane   Add the epntap fa...
56
57
	}

fa934e09   Nathanael Jourdane   Add the epntap fa...
58
	@Override
cfbb6d07   Nathanael Jourdane   Implement most of...
59
	public VOTABLE getEPNService(String ivoid, List<String> attributes)
e669c5d3   Nathanael Jourdane   Improve Javadoc.
60
			throws VOTableException {
35daa117   Nathanael Jourdane   Improve JUnits te...
61
62
63
		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...
64
65
	}

45fb4583   Nathanael Jourdane   Sort methods and ...
66
	// *** Service ***
fa934e09   Nathanael Jourdane   Add the epntap fa...
67

cfbb6d07   Nathanael Jourdane   Implement most of...
68
	@Override
e669c5d3   Nathanael Jourdane   Improve Javadoc.
69
	public VOTABLE getEPNServices() throws VOTableException {
35daa117   Nathanael Jourdane   Improve JUnits te...
70
71
72
		String query = String.format(Queries.SELECT_ALL_TAP_SERVICES_WHERE_CORE,
				ServiceCore.EPNCORE);
		return ServiceCtrl.getVoTable(query);
fa934e09   Nathanael Jourdane   Add the epntap fa...
73
74
	}

fa934e09   Nathanael Jourdane   Add the epntap fa...
75
	@Override
e669c5d3   Nathanael Jourdane   Improve Javadoc.
76
	public VOTABLE getEPNServices(List<String> attributes) throws VOTableException {
35daa117   Nathanael Jourdane   Improve JUnits te...
77
78
79
		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...
80
81
	}

45fb4583   Nathanael Jourdane   Sort methods and ...
82
83
	// *** Services ***

fa934e09   Nathanael Jourdane   Add the epntap fa...
84
	@Override
35daa117   Nathanael Jourdane   Improve JUnits te...
85
	public VOTABLE getEPNServices(List<String> keywords, List<String> attributes)
e669c5d3   Nathanael Jourdane   Improve Javadoc.
86
			throws VOTableException {
35daa117   Nathanael Jourdane   Improve JUnits te...
87
88
89
90
91
		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...
92
		}
35daa117   Nathanael Jourdane   Improve JUnits te...
93
94
		String where = StringJoiner.join(whereList, " OR ");
		String query = String.format(Queries.SELECT_TAP_SERVICES_WHERE_SUBJECT, select, where);
35daa117   Nathanael Jourdane   Improve JUnits te...
95
		return ServiceCtrl.getVoTable(query);
fa934e09   Nathanael Jourdane   Add the epntap fa...
96
97
	}

45fb4583   Nathanael Jourdane   Sort methods and ...
98
99
100
101
102
103
104
105
106
107
108
	@Override
	public Resource getEPNVOresource(String ivoid) throws VOResourceException {
		return VOResourceCtrl.getVOresource(ivoid);
	}

	@Override
	public List<Resource> getEPNVOResources() throws VOResourceException {
		List<String> ivoids = VOResourceCtrl.getIvoidResources(ServiceCore.EPNCORE);
		return VOResourceCtrl.getVOResources(ivoids);
	}

cfbb6d07   Nathanael Jourdane   Implement most of...
109
	// *** Getters ***
fa934e09   Nathanael Jourdane   Add the epntap fa...
110

cfbb6d07   Nathanael Jourdane   Implement most of...
111
	@Override
45fb4583   Nathanael Jourdane   Sort methods and ...
112
113
114
115
	public List<Resource> getEPNVOResources(List<String> keywords)
			throws VOResourceException {
		List<String> ivoids = VOResourceCtrl.getVOResources(ServiceCore.EPNCORE, keywords);
		return VOResourceCtrl.getVOResources(ivoids);
fa934e09   Nathanael Jourdane   Add the epntap fa...
116
117
	}

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

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

fa934e09   Nathanael Jourdane   Add the epntap fa...
125
	@Override
fd1d4872   Nathanael Jourdane   Immplement unit t...
126
	public List<Granule> sendADQLQuery(String tapURL, String adqlQuery) throws VOTableException {
1375d734   Nathanael Jourdane   Create package ep...
127
		VOTableCtrl voTableCtrl = new VOTableCtrl();
56349bde   Nathanael Jourdane   Add ResultsPanelC...
128
		voTableCtrl.acquireVOTable(tapURL, adqlQuery);
99642cfe   Nathanael Jourdane   Improve unit test...
129
130
		VOTableData data = voTableCtrl.getVOTableData();

cfbb6d07   Nathanael Jourdane   Implement most of...
131
		List<Granule> granules;
fd1d4872   Nathanael Jourdane   Immplement unit t...
132
133
		GranuleCtrl gc = new GranuleCtrl(data);
		granules = gc.getGranules();
cfbb6d07   Nathanael Jourdane   Implement most of...
134
135
		return granules;
	}
fa934e09   Nathanael Jourdane   Add the epntap fa...
136

cfbb6d07   Nathanael Jourdane   Implement most of...
137
	@Override
125adfc1   Nathanael Jourdane   Use enumerated qu...
138
	public List<Granule> sendQuery(String tapURL, String schemaName, Query enumeratedQuery)
e669c5d3   Nathanael Jourdane   Improve Javadoc.
139
			throws VOTableException {
125adfc1   Nathanael Jourdane   Use enumerated qu...
140
		String query = String.format(enumeratedQuery.toString(), schemaName);
1375d734   Nathanael Jourdane   Create package ep...
141
		VOTableCtrl voTableCtrl = new VOTableCtrl();
56349bde   Nathanael Jourdane   Add ResultsPanelC...
142
		voTableCtrl.acquireVOTable(tapURL, query);
125adfc1   Nathanael Jourdane   Use enumerated qu...
143
		VOTableData data = voTableCtrl.getVOTableData();
1f971475   Nathanael Jourdane   Granule parsing: ...
144
		Debug.writeObject("data", data);
125adfc1   Nathanael Jourdane   Use enumerated qu...
145
146

		List<Granule> granules;
fd1d4872   Nathanael Jourdane   Immplement unit t...
147
148
		GranuleCtrl gc = new GranuleCtrl(data);
		granules = gc.getGranules();
125adfc1   Nathanael Jourdane   Use enumerated qu...
149
		return granules;
fa934e09   Nathanael Jourdane   Add the epntap fa...
150
151
152
	}

}