1
|
|
2
|
|
3
|
|
4
|
|
5
|
|
6
|
package fr.ias.sitools.vo.tap;
|
7
|
|
8
|
import fr.ias.sitools.vo.representation.VOTableRepresentation;
|
9
|
import fr.cnes.sitools.dataset.DataSetApplication;
|
10
|
import fr.cnes.sitools.plugins.resources.model.ResourceModel;
|
11
|
import java.util.Map;
|
12
|
import java.util.logging.Level;
|
13
|
import org.restlet.Context;
|
14
|
import org.restlet.Request;
|
15
|
|
16
|
|
17
|
|
18
|
|
19
|
|
20
|
public class TableAccessProtocolLibrary {
|
21
|
|
22
|
public enum langSupported {
|
23
|
|
24
|
ADQL
|
25
|
};
|
26
|
|
27
|
public enum formatResultsSupported {
|
28
|
|
29
|
VOTABLE
|
30
|
};
|
31
|
|
32
|
|
33
|
public static final String FORMAT = "FORMAT";
|
34
|
public static final String QUERY = "QUERY";
|
35
|
public static final String LANG = "LANG";
|
36
|
public static final String PHASE = "PHASE";
|
37
|
public static final String REQUEST = "REQUEST";
|
38
|
|
39
|
public static final String SELECT = "SELECT";
|
40
|
public static final String FROM = "FROM";
|
41
|
public static final String WHERE = "WHERE";
|
42
|
public static final String SELECT_ALL = "*";
|
43
|
public static final String BLANCK = " ";
|
44
|
|
45
|
private transient DataSetApplication datasetApp;
|
46
|
private transient ResourceModel resourceModel;
|
47
|
private transient Request request;
|
48
|
private transient Context context;
|
49
|
|
50
|
|
51
|
|
52
|
|
53
|
public static final String DICTIONARY = "PARAM_Dictionary";
|
54
|
|
55
|
|
56
|
|
57
|
|
58
|
public static final String DESCRIPTION = "Description";
|
59
|
|
60
|
|
61
|
|
62
|
public static final String INSTRUMENT = "Instrument";
|
63
|
|
64
|
|
65
|
|
66
|
public static final String SERVICE_NAME = "Service Name";
|
67
|
|
68
|
|
69
|
|
70
|
public static final String MAX_RECORDS = "Max records";
|
71
|
|
72
|
public TableAccessProtocolLibrary(final DataSetApplication datasetApp, final ResourceModel resourceModel, final Request request, final Context context) {
|
73
|
this.datasetApp = datasetApp;
|
74
|
this.resourceModel = resourceModel;
|
75
|
this.request = request;
|
76
|
this.context = context;
|
77
|
}
|
78
|
|
79
|
|
80
|
|
81
|
|
82
|
|
83
|
|
84
|
private Map fillDataModel() {
|
85
|
|
86
|
Map dataModel = null;
|
87
|
Map<String, Object> map = this.request.getAttributes();
|
88
|
|
89
|
|
90
|
|
91
|
|
92
|
|
93
|
|
94
|
String tapRequestType = this.request.getAttributes().get("tapRequestType").toString();
|
95
|
|
96
|
final DataModelInterface inputParameters = new TableAccessProtocolInputParameters(datasetApp, request, this.context, this.resourceModel);
|
97
|
if (tapRequestType.equalsIgnoreCase("sync")) {
|
98
|
this.context.getLogger().log(Level.INFO, "JE SUIS DANS LE SYNC !!!");
|
99
|
|
100
|
if (inputParameters.getDataModel().containsKey("infos")) {
|
101
|
dataModel = inputParameters.getDataModel();
|
102
|
} else {
|
103
|
final TableAccessProtocolDataModelInterface response = new TableAccessProtocolResponse((TableAccessProtocolInputParameters) inputParameters, resourceModel);
|
104
|
dataModel = response.getDataModel();
|
105
|
}
|
106
|
} else if (tapRequestType.equalsIgnoreCase("async")) {
|
107
|
this.context.getLogger().log(Level.INFO, "JE SUIS DANS LE ASYNC !!!");
|
108
|
TableAccessProtocolAsynchronousResponse asyncTask = new TableAccessProtocolAsynchronousResponse((TableAccessProtocolInputParameters) inputParameters);
|
109
|
asyncTask.run();
|
110
|
this.context.getLogger().log(Level.INFO, "Apres le run de la tache async !!!");
|
111
|
|
112
|
} else {
|
113
|
this.context.getLogger().log(Level.INFO, "JE SUIS DANS NI SYNC NI ASYNC !!!");
|
114
|
}
|
115
|
|
116
|
return dataModel;
|
117
|
}
|
118
|
|
119
|
|
120
|
|
121
|
|
122
|
|
123
|
|
124
|
public final VOTableRepresentation getResponse() {
|
125
|
final Map dataModel = fillDataModel();
|
126
|
return new VOTableRepresentation(dataModel, "votable.ftl");
|
127
|
}
|
128
|
|
129
|
}
|