Blame view

src/main/java/eu/omp/irap/vespa/epntapclient/EpnTapConnection.java 5.77 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
23
import java.util.logging.Logger;

cfbb6d07   Nathanael Jourdane   Implement most of...
24
25
26
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...
27
28
29
30
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...
31
import eu.omp.irap.vespa.epntapclient.voresource.model.Resource;
cfbb6d07   Nathanael Jourdane   Implement most of...
32
import eu.omp.irap.vespa.epntapclient.votable.model.VOTABLE;
cfbb6d07   Nathanael Jourdane   Implement most of...
33
import eu.omp.irap.vespa.votable.controller.CantGetVOTableException;
99642cfe   Nathanael Jourdane   Improve unit test...
34
import eu.omp.irap.vespa.votable.controller.VOTableController;
9144ee77   Nathanael Jourdane   Implement Service...
35
import eu.omp.irap.vespa.votable.utils.StringJoiner;
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
43

	/** The logger for the class EpnTapFacade. */
58950524   Nathanael Jourdane   #2 Rename EpnTapF...
44
	private static final Logger logger = Logger.getLogger(EpnTapConnection.class.getName());
fa934e09   Nathanael Jourdane   Add the epntap fa...
45
46


cfbb6d07   Nathanael Jourdane   Implement most of...
47
48
	// *** Resource ***

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

cfbb6d07   Nathanael Jourdane   Implement most of...
54
55
	// *** Resources ***

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

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

cfbb6d07   Nathanael Jourdane   Implement most of...
69
	// *** Service ***
fa934e09   Nathanael Jourdane   Add the epntap fa...
70

fa934e09   Nathanael Jourdane   Add the epntap fa...
71
	@Override
cfbb6d07   Nathanael Jourdane   Implement most of...
72
	public VOTABLE getEPNService(String ivoid) throws CantGetVOTableException {
35daa117   Nathanael Jourdane   Improve JUnits te...
73
74
		String query = String.format(Queries.SELECT_ALL_TAP_SERVICES_WHERE_IVOID, ivoid);
		return ServiceCtrl.getVoTable(query);
fa934e09   Nathanael Jourdane   Add the epntap fa...
75
76
	}

fa934e09   Nathanael Jourdane   Add the epntap fa...
77
	@Override
cfbb6d07   Nathanael Jourdane   Implement most of...
78
79
	public VOTABLE getEPNService(String ivoid, List<String> attributes)
			throws CantGetVOTableException {
35daa117   Nathanael Jourdane   Improve JUnits te...
80
81
82
		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...
83
84
	}

cfbb6d07   Nathanael Jourdane   Implement most of...
85
	// *** Services ***
fa934e09   Nathanael Jourdane   Add the epntap fa...
86

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

fa934e09   Nathanael Jourdane   Add the epntap fa...
94
	@Override
35daa117   Nathanael Jourdane   Improve JUnits te...
95
96
97
98
	public VOTABLE getEPNServices(List<String> attributes) throws CantGetVOTableException {
		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...
99
100
	}

fa934e09   Nathanael Jourdane   Add the epntap fa...
101
	@Override
35daa117   Nathanael Jourdane   Improve JUnits te...
102
103
104
105
106
107
108
	public VOTABLE getEPNServices(List<String> keywords, List<String> attributes)
			throws CantGetVOTableException {
		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...
109
		}
35daa117   Nathanael Jourdane   Improve JUnits te...
110
111
112
113
		String where = StringJoiner.join(whereList, " OR ");
		String query = String.format(Queries.SELECT_TAP_SERVICES_WHERE_SUBJECT, select, where);
		// TODO: move this code to a new class in ServiceCtrl()
		return ServiceCtrl.getVoTable(query);
fa934e09   Nathanael Jourdane   Add the epntap fa...
114
115
	}

cfbb6d07   Nathanael Jourdane   Implement most of...
116
	// *** Getters ***
fa934e09   Nathanael Jourdane   Add the epntap fa...
117

cfbb6d07   Nathanael Jourdane   Implement most of...
118
	@Override
35daa117   Nathanael Jourdane   Improve JUnits te...
119
120
	public String getEPNCoreTableName(String ivoid) throws CantGetVOTableException {
		return (String) ServiceCtrl.getParameter(ivoid, "table_name");
fa934e09   Nathanael Jourdane   Add the epntap fa...
121
122
	}

fa934e09   Nathanael Jourdane   Add the epntap fa...
123
	@Override
35daa117   Nathanael Jourdane   Improve JUnits te...
124
125
	public String getTAPURL(String ivoid) throws CantGetVOTableException {
		return (String) ServiceCtrl.getParameter(ivoid, "access_url");
fa934e09   Nathanael Jourdane   Add the epntap fa...
126
127
	}

cfbb6d07   Nathanael Jourdane   Implement most of...
128
129
	// *** Queries ***

fa934e09   Nathanael Jourdane   Add the epntap fa...
130
	@Override
cfbb6d07   Nathanael Jourdane   Implement most of...
131
132
	public List<Granule> sendADQLQuery(String tapURL, String adqlQuery)
			throws CantGetVOTableException {
99642cfe   Nathanael Jourdane   Improve unit test...
133
134
135
136
		VOTableController voTableCtrl = new VOTableController(tapURL, adqlQuery);
		voTableCtrl.readTable();
		VOTableData data = voTableCtrl.getVOTableData();

cfbb6d07   Nathanael Jourdane   Implement most of...
137
138
139
140
141
142
143
144
145
		List<Granule> granules;
		try {
			GranuleCtrl gc = new GranuleCtrl(data);
			granules = gc.getGranulesFromVOTable();
		} catch (ParseException e) {
			throw new CantGetVOTableException("Parsing error on a granule.", e);
		}
		return granules;
	}
fa934e09   Nathanael Jourdane   Add the epntap fa...
146

cfbb6d07   Nathanael Jourdane   Implement most of...
147
	@Override
125adfc1   Nathanael Jourdane   Use enumerated qu...
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
	public List<Granule> sendQuery(String tapURL, String schemaName, Query enumeratedQuery)
			throws CantGetVOTableException {
		String query = String.format(enumeratedQuery.toString(), schemaName);
		VOTableController voTableCtrl = new VOTableController(tapURL, query);
		voTableCtrl.readTable();
		VOTableData data = voTableCtrl.getVOTableData();

		List<Granule> granules;
		try {
			GranuleCtrl gc = new GranuleCtrl(data);
			granules = gc.getGranulesFromVOTable();
		} catch (ParseException e) {
			throw new CantGetVOTableException("Parsing error on a granule.", e);
		}
		return granules;
fa934e09   Nathanael Jourdane   Add the epntap fa...
163
164
165
	}

}