1
|
package eu.dnetlib.data.search.web.api;
|
2
|
|
3
|
import eu.dnetlib.api.data.SearchService;
|
4
|
import eu.dnetlib.api.data.SearchServiceException;
|
5
|
import eu.dnetlib.data.search.app.SearchServiceImpl;
|
6
|
import eu.dnetlib.data.search.transform.Transformer;
|
7
|
import eu.dnetlib.data.search.transform.config.SearchRegistry;
|
8
|
import eu.dnetlib.data.search.utils.cql.CQLQueryBuilder;
|
9
|
import eu.dnetlib.data.search.web.utils.RequestResponseHandler;
|
10
|
import eu.dnetlib.domain.data.SearchResult;
|
11
|
import io.micrometer.core.annotation.Timed;
|
12
|
import org.apache.log4j.Logger;
|
13
|
import org.springframework.beans.factory.annotation.Autowired;
|
14
|
import org.springframework.http.HttpStatus;
|
15
|
import org.springframework.stereotype.Component;
|
16
|
|
17
|
import javax.servlet.http.HttpServletRequest;
|
18
|
import javax.servlet.http.HttpServletResponse;
|
19
|
import javax.ws.rs.*;
|
20
|
import javax.ws.rs.core.Context;
|
21
|
import javax.ws.rs.core.MediaType;
|
22
|
import javax.ws.rs.core.Response;
|
23
|
import javax.ws.rs.core.StreamingOutput;
|
24
|
import java.io.IOException;
|
25
|
import java.io.OutputStream;
|
26
|
import java.util.ArrayList;
|
27
|
import java.util.Arrays;
|
28
|
import java.util.List;
|
29
|
import java.util.Locale;
|
30
|
|
31
|
/**
|
32
|
* Created by kiatrop on 2/6/2016.
|
33
|
*/
|
34
|
|
35
|
@Component
|
36
|
@Path("/v2")
|
37
|
public class SearchApiService {
|
38
|
|
39
|
private static final Logger logger = Logger.getLogger(SearchApiService.class);
|
40
|
|
41
|
@Autowired
|
42
|
private SearchService searchService = null;
|
43
|
|
44
|
@Autowired
|
45
|
private SearchRegistry searchRegistry = null;
|
46
|
|
47
|
@GET
|
48
|
@Path("/api/resources")
|
49
|
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
|
50
|
@Timed(value = "http.server.request.duration", extraTags = {"referer", "portal", "uri", "/rest/v2/api/resources"}, longTask = false)
|
51
|
public Response fetchResources(@QueryParam("query") String query,
|
52
|
@DefaultValue("0") @QueryParam("page") final int offset,
|
53
|
@DefaultValue("10") @QueryParam("size") final int limit,
|
54
|
@QueryParam("refine") @DefaultValue("false") final boolean refine,
|
55
|
@QueryParam("fields") final List<String> refineFields,
|
56
|
@QueryParam("sf") final List<String> specialFacets,
|
57
|
@QueryParam("fq") final List<String> fieldQueries,
|
58
|
@QueryParam("format") final String format,
|
59
|
@QueryParam("type") final String type,
|
60
|
@Context final HttpServletRequest request) {
|
61
|
|
62
|
return getResponseByEntity(query, extractEntity(type), offset, limit, format, request, refine, refineFields, specialFacets, fieldQueries);
|
63
|
}
|
64
|
|
65
|
@GET
|
66
|
@Path("/api/resources2")
|
67
|
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
|
68
|
@Timed(value = "http.server.request.duration", extraTags = {"referer", "portal", "uri", "/rest/v2/api/resources2"}, longTask = false)
|
69
|
public Response fetchResources(@QueryParam("query") final String query,
|
70
|
@QueryParam("pid") final String pid,
|
71
|
@QueryParam("pidtype") final String pidType,
|
72
|
@DefaultValue("0") @QueryParam("page") final int offset,
|
73
|
@DefaultValue("10") @QueryParam("size") final int limit,
|
74
|
@QueryParam("refine") @DefaultValue("false") final boolean refine,
|
75
|
@QueryParam("fields") final List<String> refineFields,
|
76
|
@QueryParam("sf") final List<String> specialFacets,
|
77
|
@QueryParam("fq") final List<String> fieldQueries,
|
78
|
@QueryParam("format") final String format,
|
79
|
@QueryParam("type") final List<String> types,
|
80
|
@Context final HttpServletRequest request) {
|
81
|
|
82
|
return getResponseByEntityTypes(query, pid, pidType, types, offset, limit, format, request, refine, refineFields, specialFacets, fieldQueries);
|
83
|
}
|
84
|
|
85
|
|
86
|
@GET
|
87
|
@Path("/api/results")
|
88
|
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
|
89
|
@Timed(value = "http.server.request.duration", extraTags = {"referer", "portal", "uri", "/rest/v2/api/results"}, longTask = false)
|
90
|
public Response fetchResults(@QueryParam("q") final String keywords,
|
91
|
@QueryParam("doi") final String doi,
|
92
|
@QueryParam("sortBy") final String sortBy,
|
93
|
@DefaultValue("0") @QueryParam("page") final int offset,
|
94
|
@DefaultValue("10") @QueryParam("size") final int limit,
|
95
|
@QueryParam("refine") @DefaultValue("false") final boolean refine,
|
96
|
@QueryParam("fields") final List<String> refineFields,
|
97
|
@QueryParam("sf") final List<String> specialFacets,
|
98
|
@QueryParam("fq") final List<String> fieldQueries,
|
99
|
@QueryParam("format") final String format,
|
100
|
@QueryParam("type") final List<String> types,
|
101
|
@Context final HttpServletRequest request) {
|
102
|
|
103
|
String simpleQuery = buildSearchRequest(types, keywords, doi,sortBy, fieldQueries);
|
104
|
return getResponseByEntity(simpleQuery, RequestResponseHandler.Entity.RESULT, offset, limit, format, request, refine, refineFields, specialFacets, fieldQueries);
|
105
|
|
106
|
}
|
107
|
|
108
|
@GET
|
109
|
@Path("/api/results/{resultsid}")
|
110
|
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
|
111
|
@Timed(value = "http.server.request.duration", extraTags = {"referer", "portal", "uri", "/rest/v2/api/results/{resultsid}"}, longTask = false)
|
112
|
public Response fetchResultsById(@PathParam("resultsid") String resultsid,
|
113
|
@QueryParam("format") final String format,
|
114
|
@QueryParam("fq") final List<String> fieldQueries,
|
115
|
@Context final HttpServletRequest request) {
|
116
|
|
117
|
return getResponseByEntityId(request, RequestResponseHandler.Entity.RESULT, resultsid, format, fieldQueries);
|
118
|
}
|
119
|
|
120
|
@GET
|
121
|
@Path("/api/results/count")
|
122
|
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
|
123
|
@Timed(value = "http.server.request.duration", extraTags = {"referer", "portal", "uri", "/rest/v2/api/results/count"}, longTask = false)
|
124
|
public Response fetchResultsCount(@QueryParam("q") String query,
|
125
|
@QueryParam("format") final String format,
|
126
|
@QueryParam("fq") final List<String> fieldQueries,
|
127
|
@QueryParam("types") final List<String> types,
|
128
|
@Context final HttpServletRequest request) {
|
129
|
String fullQuery = buildSearchRequest(types, query, fieldQueries);
|
130
|
return getCount(request, fullQuery, format, fieldQueries);
|
131
|
}
|
132
|
|
133
|
|
134
|
@GET
|
135
|
@Path("/api/publications")
|
136
|
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
|
137
|
@Timed(value = "http.server.request.duration", extraTags = {"referer", "portal", "uri", "/rest/v2/api/publications"}, longTask = false)
|
138
|
public Response fetchPublications(@QueryParam("q") final String keywords,
|
139
|
@QueryParam("doi") final String doi,
|
140
|
@QueryParam("sortBy") final String sortBy,
|
141
|
@DefaultValue("0") @QueryParam("page") final int offset,
|
142
|
@DefaultValue("10") @QueryParam("size") final int limit,
|
143
|
@QueryParam("refine") @DefaultValue("false") final boolean refine,
|
144
|
@QueryParam("fields") final List<String> refineFields,
|
145
|
@QueryParam("sf") final List<String> specialFacets,
|
146
|
@QueryParam("fq") final List<String> fieldQueries,
|
147
|
@QueryParam("format") final String format,
|
148
|
@Context final HttpServletRequest request) {
|
149
|
|
150
|
logger.debug("Publications request received");
|
151
|
//TODO do not allow q and keywords both - SWITCH back if needed
|
152
|
//String simpleQuery = buildSimpleSearchQuery(RequestResponseHandler.Entity.PUBLICATION, keywords) ;
|
153
|
String simpleQuery = buildSearchRequest(RequestResponseHandler.Entity.PUBLICATION, keywords, doi,sortBy, fieldQueries);
|
154
|
return getResponseByEntity(simpleQuery, RequestResponseHandler.Entity.PUBLICATION, offset, limit, format, request, refine, refineFields, specialFacets, fieldQueries);
|
155
|
}
|
156
|
|
157
|
|
158
|
@GET
|
159
|
@Path("/api/publications/count")
|
160
|
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
|
161
|
@Timed(value = "http.server.request.duration", extraTags = {"referer", "portal", "uri", "/rest/v2/api/publications/count"}, longTask = false)
|
162
|
public Response fetchPublicationsCount(@QueryParam("q") String query,
|
163
|
@QueryParam("format") final String format,
|
164
|
@QueryParam("fq") final List<String> fieldQueries,
|
165
|
@Context final HttpServletRequest request) {
|
166
|
String fullQuery = buildSearchRequest(RequestResponseHandler.Entity.PUBLICATION, query, fieldQueries);
|
167
|
return getCount(request, fullQuery, format, fieldQueries);
|
168
|
}
|
169
|
|
170
|
|
171
|
@GET
|
172
|
@Path("/api/publications/{publicationid}")
|
173
|
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
|
174
|
@Timed(value = "http.server.request.duration", extraTags = {"referer", "portal", "uri", "/rest/v2/api/publications/{publicationid}"}, longTask = false)
|
175
|
public Response fetchPublicationsById(@PathParam("publicationid") String publicationid,
|
176
|
@QueryParam("format") final String format,
|
177
|
@QueryParam("fq") final List<String> fieldQueries,
|
178
|
@Context final HttpServletRequest request) {
|
179
|
return getResponseByEntityId(request, RequestResponseHandler.Entity.PUBLICATION, publicationid, format, fieldQueries);
|
180
|
}
|
181
|
|
182
|
|
183
|
@GET
|
184
|
@Path("/api/datasets")
|
185
|
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
|
186
|
@Timed(value = "http.server.request.duration", extraTags = {"referer", "portal", "uri", "/rest/v2/api/datasets"}, longTask = false)
|
187
|
public Response fetchDatasets(@QueryParam("q") String keywords,
|
188
|
@QueryParam("doi") final String doi,
|
189
|
@QueryParam("sortBy") final String sortBy,
|
190
|
@DefaultValue("0") @QueryParam("page") int offset,
|
191
|
@DefaultValue("10") @QueryParam("size") int limit,
|
192
|
@QueryParam("refine") @DefaultValue("false") boolean refine,
|
193
|
@QueryParam("fields") final List<String> refineFields,
|
194
|
@QueryParam("sf") final List<String> specialFacets,
|
195
|
@QueryParam("fq") final List<String> fieldQueries,
|
196
|
@QueryParam("format") final String format,
|
197
|
@Context HttpServletRequest request) {
|
198
|
|
199
|
String simpleQuery = buildSearchRequest(RequestResponseHandler.Entity.DATASET, keywords, doi, sortBy, fieldQueries);
|
200
|
return getResponseByEntity(simpleQuery, RequestResponseHandler.Entity.DATASET, offset, limit, format, request, refine, refineFields, specialFacets, fieldQueries);
|
201
|
}
|
202
|
|
203
|
@GET
|
204
|
@Path("/api/datasets/count")
|
205
|
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
|
206
|
@Timed(value = "http.server.request.duration", extraTags = {"referer", "portal", "uri", "/rest/v2/api/datasets/count"}, longTask = false)
|
207
|
public Response fetchDatesetsCount(@QueryParam("q") String query,
|
208
|
@QueryParam("format") final String format,
|
209
|
@QueryParam("fq") final List<String> fieldQueries,
|
210
|
@Context final HttpServletRequest request) {
|
211
|
String fullQuery = buildSearchRequest(RequestResponseHandler.Entity.DATASET, query, fieldQueries);
|
212
|
return getCount(request, fullQuery, format, fieldQueries);
|
213
|
}
|
214
|
|
215
|
|
216
|
@GET
|
217
|
@Path("/api/datasets/{datasetid}")
|
218
|
@Timed(value = "http.server.request.duration", extraTags = {"referer", "portal", "uri", "/rest/v2/api/datasets/{datasetid}"}, longTask = false)
|
219
|
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
|
220
|
public Response fetchDatasets(@PathParam("datasetid") String datasetid,
|
221
|
@QueryParam("format") final String format,
|
222
|
@QueryParam("fq") final List<String> fieldQueries,
|
223
|
@Context final HttpServletRequest request) {
|
224
|
return getResponseByEntityId(request, RequestResponseHandler.Entity.DATASET, datasetid, format, fieldQueries);
|
225
|
}
|
226
|
|
227
|
@GET
|
228
|
@Path("/api/software")
|
229
|
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
|
230
|
@Timed(value = "http.server.request.duration", extraTags = {"referer", "portal", "uri", "/rest/v2/api/software"}, longTask = false)
|
231
|
public Response fetchSoftware(@QueryParam("ru") String keywords,
|
232
|
@QueryParam("doi") final String doi,
|
233
|
@QueryParam("sortBy") final String sortBy,
|
234
|
@DefaultValue("0") @QueryParam("page") int offset,
|
235
|
@DefaultValue("10") @QueryParam("size") int limit,
|
236
|
@QueryParam("refine") @DefaultValue("false") boolean refine,
|
237
|
@QueryParam("fields") final List<String> refineFields,
|
238
|
@QueryParam("sf") final List<String> specialFacets,
|
239
|
@QueryParam("fq") final List<String> fieldQueries,
|
240
|
@QueryParam("format") final String format,
|
241
|
@Context HttpServletRequest request) {
|
242
|
|
243
|
String simpleQuery = buildSearchRequest(RequestResponseHandler.Entity.SOFTWARE, keywords, doi, sortBy, fieldQueries);
|
244
|
return getResponseByEntity(simpleQuery, RequestResponseHandler.Entity.SOFTWARE, offset, limit, format, request, refine, refineFields, specialFacets, fieldQueries);
|
245
|
}
|
246
|
|
247
|
@GET
|
248
|
@Path("/api/software/count")
|
249
|
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
|
250
|
@Timed(value = "http.server.request.duration", extraTags = {"referer", "portal", "uri", "/rest/v2/api/software/count"}, longTask = false)
|
251
|
public Response fetchSoftwareCount(@QueryParam("q") String query,
|
252
|
@QueryParam("format") final String format,
|
253
|
@QueryParam("fq") final List<String> fieldQueries,
|
254
|
@Context final HttpServletRequest request) {
|
255
|
String fullQuery = buildSearchRequest(RequestResponseHandler.Entity.SOFTWARE, query, fieldQueries);
|
256
|
return getCount(request, fullQuery, format, fieldQueries);
|
257
|
}
|
258
|
|
259
|
@GET
|
260
|
@Path("/api/software/{softwareid}")
|
261
|
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
|
262
|
@Timed(value = "http.server.request.duration", extraTags = {"referer", "portal", "uri", "/rest/v2/api/software/{softwareid}"}, longTask = false)
|
263
|
public Response fetchSoftware(@PathParam("softwareid") String datasetid,
|
264
|
@QueryParam("format") final String format,
|
265
|
@QueryParam("fq") final List<String> fieldQueries,
|
266
|
@Context final HttpServletRequest request) {
|
267
|
return getResponseByEntityId(request, RequestResponseHandler.Entity.SOFTWARE, datasetid, format, fieldQueries);
|
268
|
}
|
269
|
|
270
|
@GET
|
271
|
@Path("/api/other")
|
272
|
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
|
273
|
@Timed(value = "http.server.request.duration", extraTags = {"referer", "portal", "uri", "/rest/v2/api/other"}, longTask = false)
|
274
|
public Response fetchOther(@QueryParam("q") String keywords,
|
275
|
@QueryParam("doi") final String doi,
|
276
|
@QueryParam("sortBy") final String sortBy,
|
277
|
@DefaultValue("0") @QueryParam("page") int offset,
|
278
|
@DefaultValue("10") @QueryParam("size") int limit,
|
279
|
@QueryParam("refine") @DefaultValue("false") boolean refine,
|
280
|
@QueryParam("fields") final List<String> refineFields,
|
281
|
@QueryParam("sf") final List<String> specialFacets,
|
282
|
@QueryParam("fq") final List<String> fieldQueries,
|
283
|
@QueryParam("format") final String format,
|
284
|
@Context HttpServletRequest request) {
|
285
|
|
286
|
String simpleQuery = buildSearchRequest(RequestResponseHandler.Entity.OTHER, keywords, doi, sortBy, fieldQueries);
|
287
|
return getResponseByEntity(simpleQuery, RequestResponseHandler.Entity.OTHER, offset, limit, format, request, refine, refineFields, specialFacets, fieldQueries);
|
288
|
}
|
289
|
|
290
|
@GET
|
291
|
@Path("/api/other/count")
|
292
|
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
|
293
|
@Timed(value = "http.server.request.duration", extraTags = {"referer", "portal", "uri", "/rest/v2/api/other"}, longTask = false)
|
294
|
public Response fetchOtherCount(@QueryParam("q") String query,
|
295
|
@QueryParam("format") final String format,
|
296
|
@QueryParam("fq") final List<String> fieldQueries,
|
297
|
@Context final HttpServletRequest request) {
|
298
|
String fullQuery = buildSearchRequest(RequestResponseHandler.Entity.OTHER, query, fieldQueries);
|
299
|
return getCount(request, fullQuery, format, fieldQueries);
|
300
|
}
|
301
|
|
302
|
@GET
|
303
|
@Path("/api/other/{otherid}")
|
304
|
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
|
305
|
@Timed(value = "http.server.request.duration", extraTags = {"referer", "portal", "uri", "/rest/v2/api/other/{otherid}"}, longTask = false)
|
306
|
public Response fetchOther(@PathParam("otherid") String datasetid,
|
307
|
@QueryParam("format") final String format,
|
308
|
@QueryParam("fq") final List<String> fieldQueries,
|
309
|
@Context final HttpServletRequest request) {
|
310
|
return getResponseByEntityId(request, RequestResponseHandler.Entity.OTHER, datasetid, format, fieldQueries);
|
311
|
}
|
312
|
@GET
|
313
|
@Path("/api/projects")
|
314
|
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
|
315
|
@Timed(value = "http.server.request.duration", extraTags = {"referer", "portal", "uri", "/rest/v2/api/projects"}, longTask = false)
|
316
|
public Response fetchProjects(@QueryParam("q") String keywords,
|
317
|
@DefaultValue("0") @QueryParam("page") int offset,
|
318
|
@DefaultValue("10") @QueryParam("size") int limit,
|
319
|
@QueryParam("refine") @DefaultValue("false") boolean refine,
|
320
|
@QueryParam("fields") final List<String> refineFields,
|
321
|
@QueryParam("sf") final List<String> specialFacets,
|
322
|
@QueryParam("fq") final List<String> fieldQueries,
|
323
|
@QueryParam("format") final String format,
|
324
|
@Context HttpServletRequest request) {
|
325
|
|
326
|
String simpleQuery = buildSearchRequest(RequestResponseHandler.Entity.PROJECT, keywords, fieldQueries);
|
327
|
return getResponseByEntity(simpleQuery, RequestResponseHandler.Entity.PROJECT, offset, limit, format, request, refine, refineFields, specialFacets, fieldQueries);
|
328
|
}
|
329
|
|
330
|
|
331
|
@GET
|
332
|
@Path("/api/projects/count")
|
333
|
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
|
334
|
@Timed(value = "http.server.request.duration", extraTags = {"referer", "portal", "uri", "/rest/v2/api/projects/count"}, longTask = false)
|
335
|
public Response fetchProjectsCount(@QueryParam("q") String query,
|
336
|
@QueryParam("format") final String format,
|
337
|
@QueryParam("fq") final List<String> fieldQueries,
|
338
|
@Context final HttpServletRequest request) {
|
339
|
String fullQuery = buildSearchRequest(RequestResponseHandler.Entity.PROJECT, query, fieldQueries);
|
340
|
return getCount(request, fullQuery, format, fieldQueries);
|
341
|
}
|
342
|
|
343
|
@GET
|
344
|
@Path("/api/projects/{projectid}")
|
345
|
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
|
346
|
@Timed(value = "http.server.request.duration", extraTags = {"referer", "portal", "uri", "/rest/v2/api/projects/{projectid}"}, longTask = false)
|
347
|
public Response fetchProjects(@PathParam("projectid") String projectid,
|
348
|
@QueryParam("format") final String format,
|
349
|
@QueryParam("fq") final List<String> fieldQueries,
|
350
|
@Context final HttpServletRequest request) {
|
351
|
return getResponseByEntityId(request, RequestResponseHandler.Entity.PROJECT, projectid, format, fieldQueries);
|
352
|
}
|
353
|
|
354
|
@GET
|
355
|
@Path("/api/projects/{projectId}/publications")
|
356
|
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
|
357
|
@Timed(value = "http.server.request.duration", extraTags = {"referer", "portal", "uri", "/rest/v2/api/projects/{projectid}/publications"}, longTask = false)
|
358
|
public Response fetchProjectPublications(@PathParam("projectId") String projectId,
|
359
|
@DefaultValue("0") @QueryParam("page") int offset,
|
360
|
@DefaultValue("10") @QueryParam("size") int limit,
|
361
|
@QueryParam("format") final String format,
|
362
|
@QueryParam("fq") final List<String> fieldQueries,
|
363
|
@Context HttpServletRequest request) {
|
364
|
|
365
|
String fullQuery = builtEntity2EntityRelationQuery(RequestResponseHandler.Entity.PUBLICATION, "relprojectid", projectId, fieldQueries);
|
366
|
return getResponseByEntity(fullQuery, RequestResponseHandler.Entity.PUBLICATION, offset, limit, format, request, false, null, null,fieldQueries);
|
367
|
}
|
368
|
|
369
|
@GET
|
370
|
@Path("/api/projects/{projectId}/publications/count")
|
371
|
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
|
372
|
@Timed(value = "http.server.request.duration", extraTags = {"referer", "portal", "uri", "/rest/v2/api/projects/{projectid}/publications/count"}, longTask = false)
|
373
|
public Response fetchProjectPublicationsCount(@PathParam("projectId") String projectId,
|
374
|
@QueryParam("format") final String format,
|
375
|
@QueryParam("fq") final List<String> fieldQueries,
|
376
|
@Context final HttpServletRequest request) {
|
377
|
String fullQuery = builtEntity2EntityRelationQuery(RequestResponseHandler.Entity.PUBLICATION, "relprojectid", projectId, fieldQueries);
|
378
|
return getCount(request, fullQuery, format, fieldQueries);
|
379
|
}
|
380
|
|
381
|
@GET
|
382
|
@Path("/api/projects/{projectId}/datasets")
|
383
|
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
|
384
|
@Timed(value = "http.server.request.duration", extraTags = {"referer", "portal", "uri", "/rest/v2/api/projects/{projectId}/datasets"}, longTask = false)
|
385
|
public Response fetchProjectDatasets(@PathParam("projectId") String projectId,
|
386
|
@DefaultValue("0") @QueryParam("page") int offset,
|
387
|
@DefaultValue("10") @QueryParam("size") int limit,
|
388
|
@QueryParam("format") final String format,
|
389
|
@QueryParam("fq") final List<String> fieldQueries,
|
390
|
@Context HttpServletRequest request) {
|
391
|
|
392
|
String fullQuery = builtEntity2EntityRelationQuery(RequestResponseHandler.Entity.DATASET, "relprojectid", projectId, fieldQueries);
|
393
|
return getResponseByEntity(fullQuery, RequestResponseHandler.Entity.DATASET, offset, limit, format, request, false, null, null, fieldQueries);
|
394
|
}
|
395
|
|
396
|
|
397
|
@GET
|
398
|
@Path("/api/projects/{projectId}/datasets/count")
|
399
|
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
|
400
|
@Timed(value = "http.server.request.duration", extraTags = {"referer", "portal", "uri", "/rest/v2/api/projects/{projectId}/datasets/count"}, longTask = false)
|
401
|
public Response fetchProjectDatasetsCount(@PathParam("projectId") String projectId,
|
402
|
@DefaultValue("0") @QueryParam("page") int offset,
|
403
|
@DefaultValue("10") @QueryParam("size") int limit,
|
404
|
@QueryParam("format") final String format,
|
405
|
@QueryParam("fq") final List<String> fieldQueries,
|
406
|
@Context HttpServletRequest request) {
|
407
|
String fullQuery = builtEntity2EntityRelationQuery(RequestResponseHandler.Entity.DATASET, "relprojectid", projectId, fieldQueries);
|
408
|
return getCount(request, fullQuery, format, fieldQueries);
|
409
|
}
|
410
|
|
411
|
|
412
|
|
413
|
@GET
|
414
|
@Path("/api/projects/{projectId}/software/count")
|
415
|
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
|
416
|
@Timed(value = "http.server.request.duration", extraTags = {"referer", "portal", "uri", "/rest/v2/api/projects/{projectId}/software/count"}, longTask = false)
|
417
|
public Response fetchProjectSoftwareCount(@PathParam("projectId") String projectId,
|
418
|
@DefaultValue("0") @QueryParam("page") int offset,
|
419
|
@DefaultValue("10") @QueryParam("size") int limit,
|
420
|
@QueryParam("format") final String format,
|
421
|
@QueryParam("fq") final List<String> fieldQueries,
|
422
|
@Context HttpServletRequest request) {
|
423
|
String fullQuery = builtEntity2EntityRelationQuery(RequestResponseHandler.Entity.SOFTWARE, "relprojectid", projectId, fieldQueries);
|
424
|
return getCount(request, fullQuery, format, fieldQueries);
|
425
|
}
|
426
|
|
427
|
@GET
|
428
|
@Path("/api/projects/{projectId}/software")
|
429
|
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
|
430
|
@Timed(value = "http.server.request.duration", extraTags = {"referer", "portal", "uri", "/rest/v2/api/projects/{projectId}/software"}, longTask = false)
|
431
|
public Response fetchProjectSoftware(@PathParam("projectId") String projectId,
|
432
|
@DefaultValue("0") @QueryParam("page") int offset,
|
433
|
@DefaultValue("10") @QueryParam("size") int limit,
|
434
|
@QueryParam("format") final String format,
|
435
|
@QueryParam("fq") final List<String> fieldQueries,
|
436
|
@Context HttpServletRequest request) {
|
437
|
|
438
|
String fullQuery = builtEntity2EntityRelationQuery(RequestResponseHandler.Entity.SOFTWARE, "relprojectid", projectId, fieldQueries);
|
439
|
return getResponseByEntity(fullQuery, RequestResponseHandler.Entity.SOFTWARE, offset, limit, format, request, false, null, null,fieldQueries);
|
440
|
}
|
441
|
|
442
|
@GET
|
443
|
@Path("/api/projects/{projectId}/other/count")
|
444
|
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
|
445
|
@Timed(value = "http.server.request.duration", extraTags = {"referer", "portal", "uri", "/rest/v2/api/projects/{projectId}/other/count"}, longTask = false)
|
446
|
public Response fetchProjectOtherCount(@PathParam("projectId") String projectId,
|
447
|
@DefaultValue("0") @QueryParam("page") int offset,
|
448
|
@DefaultValue("10") @QueryParam("size") int limit,
|
449
|
@QueryParam("format") final String format,
|
450
|
@QueryParam("fq") final List<String> fieldQueries,
|
451
|
@Context HttpServletRequest request) {
|
452
|
String fullQuery = builtEntity2EntityRelationQuery(RequestResponseHandler.Entity.OTHER, "relprojectid", projectId, fieldQueries);
|
453
|
return getCount(request, fullQuery, format, fieldQueries);
|
454
|
}
|
455
|
|
456
|
|
457
|
@GET
|
458
|
@Path("/api/projects/{projectId}/other")
|
459
|
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
|
460
|
@Timed(value = "http.server.request.duration", extraTags = {"referer", "portal", "uri", "/rest/v2/api/projects/{projectId}/other"}, longTask = false)
|
461
|
public Response fetchProjectOther(@PathParam("projectId") String projectId,
|
462
|
@DefaultValue("0") @QueryParam("page") int offset,
|
463
|
@DefaultValue("10") @QueryParam("size") int limit,
|
464
|
@QueryParam("format") final String format,
|
465
|
@QueryParam("fq") final List<String> fieldQueries,
|
466
|
@Context HttpServletRequest request) {
|
467
|
|
468
|
String fullQuery = builtEntity2EntityRelationQuery(RequestResponseHandler.Entity.OTHER, "relprojectid", projectId, fieldQueries);
|
469
|
return getResponseByEntity(fullQuery, RequestResponseHandler.Entity.OTHER, offset, limit, format, request, false, null, null, fieldQueries);
|
470
|
}
|
471
|
|
472
|
@GET
|
473
|
@Path("/api/projects/{projectId}/results")
|
474
|
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
|
475
|
@Timed(value = "http.server.request.duration", extraTags = {"referer", "portal", "uri", "/rest/v2/api/projects/{projectId}/results"}, longTask = false)
|
476
|
public Response fetchProjectResults(@PathParam("projectId") String projectId,
|
477
|
@DefaultValue("0") @QueryParam("page") int offset,
|
478
|
@DefaultValue("10") @QueryParam("size") int limit,
|
479
|
@QueryParam("format") final String format,
|
480
|
@QueryParam("fq") final List<String> fieldQueries,
|
481
|
@Context HttpServletRequest request) {
|
482
|
|
483
|
String fullQuery = builtEntity2EntityRelationQuery(RequestResponseHandler.Entity.RESULT, "relprojectid", projectId, fieldQueries);
|
484
|
return getResponseByEntity(fullQuery, RequestResponseHandler.Entity.RESULT, offset, limit, format, request, false, null, null, fieldQueries);
|
485
|
}
|
486
|
|
487
|
@GET
|
488
|
@Path("/api/projects/{projectId}/results/count")
|
489
|
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
|
490
|
@Timed(value = "http.server.request.duration", extraTags = {"referer", "portal", "uri", "/rest/v2/api/projects/{projectId}/results/count"}, longTask = false)
|
491
|
public Response fetchProjectResultsCount(@PathParam("projectId") String projectId,
|
492
|
@DefaultValue("0") @QueryParam("page") int offset,
|
493
|
@DefaultValue("10") @QueryParam("size") int limit,
|
494
|
@QueryParam("format") final String format,
|
495
|
@QueryParam("fq") final List<String> fieldQueries,
|
496
|
@Context HttpServletRequest request) {
|
497
|
String fullQuery = builtEntity2EntityRelationQuery(RequestResponseHandler.Entity.RESULT, "relprojectid", projectId, fieldQueries);
|
498
|
return getCount(request, fullQuery, format, fieldQueries);
|
499
|
}
|
500
|
|
501
|
|
502
|
@GET
|
503
|
@Path("/api/datasources")
|
504
|
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
|
505
|
@Timed(value = "http.server.request.duration", extraTags = {"referer", "portal", "uri", "/rest/v2/api/datasources"}, longTask = false)
|
506
|
public Response fetchDatasources(@QueryParam("q") String keywords,
|
507
|
@DefaultValue("0") @QueryParam("page") final int offset,
|
508
|
@DefaultValue("10") @QueryParam("size") final int limit,
|
509
|
@QueryParam("refine") @DefaultValue("false") final boolean refine,
|
510
|
@QueryParam("fields") final List<String> refineFields,
|
511
|
@QueryParam("fq") final List<String> fieldQueries,
|
512
|
@QueryParam("sf") final List<String> specialFacets,
|
513
|
@QueryParam("format") final String format,
|
514
|
@Context final HttpServletRequest request) {
|
515
|
|
516
|
String simpleQuery = buildSearchRequest(RequestResponseHandler.Entity.DATASOURCE, keywords, fieldQueries);
|
517
|
return getResponseByEntity(simpleQuery, RequestResponseHandler.Entity.DATASOURCE, offset, limit, format, request, refine, refineFields, specialFacets, fieldQueries);
|
518
|
}
|
519
|
|
520
|
@GET
|
521
|
@Path("/api/datasources/count")
|
522
|
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
|
523
|
@Timed(value = "http.server.request.duration", extraTags = {"referer", "portal", "uri", "/rest/v2/api/datasources/count"}, longTask = false)
|
524
|
public Response fetchDatasourcesCount(@QueryParam("q") String query,
|
525
|
@QueryParam("format") final String format,
|
526
|
@QueryParam("fq") final List<String> fieldQueries,
|
527
|
@Context final HttpServletRequest request) {
|
528
|
String fullQuery = buildSearchRequest(RequestResponseHandler.Entity.DATASOURCE, query, fieldQueries);
|
529
|
return getCount(request, fullQuery, format, fieldQueries);
|
530
|
}
|
531
|
|
532
|
@GET
|
533
|
@Path("/api/datasources/{datasourceid}")
|
534
|
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
|
535
|
@Timed(value = "http.server.request.duration", extraTags = {"referer", "portal", "uri", "/rest/v2/api/datasources/{datasourceid}"}, longTask = false)
|
536
|
public Response fetchDatasources(@PathParam("datasourceid") String datasourceid,
|
537
|
@QueryParam("format") final String format,
|
538
|
@QueryParam("fq") final List<String> fieldQueries,
|
539
|
@Context final HttpServletRequest request) {
|
540
|
return getResponseByEntityId(request, RequestResponseHandler.Entity.DATASOURCE, datasourceid, format, fieldQueries);
|
541
|
}
|
542
|
|
543
|
|
544
|
@GET
|
545
|
@Path("/api/organizations")
|
546
|
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
|
547
|
@Timed(value = "http.server.request.duration", extraTags = {"referer", "portal", "uri", "/rest/v2/api/organizations"}, longTask = false)
|
548
|
public Response fetchOrganisations(@QueryParam("q") String keywords,
|
549
|
@DefaultValue("0") @QueryParam("page") final int offset,
|
550
|
@DefaultValue("10") @QueryParam("size") final int limit,
|
551
|
@QueryParam("refine") @DefaultValue("false") final boolean refine,
|
552
|
@QueryParam("fields") final List<String> refineFields,
|
553
|
@QueryParam("sf") final List<String> specialFacets,
|
554
|
@QueryParam("fq") final List<String> fieldQueries,
|
555
|
@QueryParam("format") final String format,
|
556
|
@Context final HttpServletRequest request) {
|
557
|
|
558
|
String simpleQuery = buildSearchRequest(RequestResponseHandler.Entity.ORGANIZATION, keywords, fieldQueries);
|
559
|
return getResponseByEntity(simpleQuery, RequestResponseHandler.Entity.ORGANIZATION, offset, limit, format, request, refine, refineFields, specialFacets, fieldQueries);
|
560
|
}
|
561
|
|
562
|
|
563
|
@GET
|
564
|
@Path("/api/organizations/count")
|
565
|
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
|
566
|
@Timed(value = "http.server.request.duration", extraTags = {"referer", "portal", "uri", "/rest/v2/api/organizations/count"}, longTask = false)
|
567
|
public Response fetchOrganizationsCount(@QueryParam("q") String query,
|
568
|
@QueryParam("format") final String format,
|
569
|
@QueryParam("fq") final List<String> fieldQueries,
|
570
|
@Context final HttpServletRequest request) {
|
571
|
String fullQuery = buildSearchRequest(RequestResponseHandler.Entity.ORGANIZATION, query, fieldQueries);
|
572
|
return getCount(request, fullQuery, format, fieldQueries);
|
573
|
}
|
574
|
|
575
|
@GET
|
576
|
@Path("/api/organizations/{organizationid}")
|
577
|
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
|
578
|
@Timed(value = "http.server.request.duration", extraTags = {"referer", "portal", "uri", "/rest/v2/api/organizations/{organizationid}"}, longTask = false)
|
579
|
public Response fetchOrganizations(@PathParam("organizationid") String organizationid,
|
580
|
@QueryParam("format") final String format,
|
581
|
@QueryParam("fq") final List<String> fieldQueries,
|
582
|
@Context final HttpServletRequest request) {
|
583
|
return getResponseByEntityId(request, RequestResponseHandler.Entity.ORGANIZATION, organizationid, format, fieldQueries);
|
584
|
}
|
585
|
|
586
|
|
587
|
@GET
|
588
|
@Path("/api/organizations/{organizationid}/datasources")
|
589
|
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
|
590
|
@Timed(value = "http.server.request.duration", extraTags = {"referer", "portal", "uri", "/rest/v2/api/organizations/{organizationid}/datasources"}, longTask = false)
|
591
|
public Response fetchOrganizationDatasources(@PathParam("organizationid") String organizationid,
|
592
|
@DefaultValue("0") @QueryParam("page") int offset,
|
593
|
@DefaultValue("10") @QueryParam("size") int limit,
|
594
|
@QueryParam("format") final String format,
|
595
|
@QueryParam("fq") final List<String> fieldQueries,
|
596
|
@Context HttpServletRequest request) {
|
597
|
String fullQuery = builtEntity2EntityRelationQuery(RequestResponseHandler.Entity.DATASOURCE, "relorganizationid", organizationid, fieldQueries);
|
598
|
return getResponseByEntity(fullQuery, RequestResponseHandler.Entity.DATASOURCE, offset, limit, format, request, false, null, null, fieldQueries);
|
599
|
}
|
600
|
|
601
|
@GET
|
602
|
@Path("/api/organizations/{organizationid}/datasources/count")
|
603
|
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
|
604
|
@Timed(value = "http.server.request.duration", extraTags = {"referer", "portal", "uri", "/rest/v2/api/organizations/{organizationid}/datasources/count"}, longTask = false)
|
605
|
public Response fetchOrganizationDatasources(@PathParam("organizationid") String organizationid,
|
606
|
@QueryParam("format") final String format,
|
607
|
@QueryParam("fq") final List<String> fieldQueries,
|
608
|
@Context final HttpServletRequest request) {
|
609
|
String fullQuery = builtEntity2EntityRelationQuery(RequestResponseHandler.Entity.DATASOURCE, "relorganizationid", organizationid, fieldQueries);
|
610
|
return getCount(request, fullQuery, format, fieldQueries);
|
611
|
}
|
612
|
|
613
|
|
614
|
@GET
|
615
|
@Path("/api/organizations/{organizationid}/publications")
|
616
|
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
|
617
|
@Timed(value = "http.server.request.duration", extraTags = {"referer", "portal", "uri", "/rest/v2/api/organizations/{organizationid}/publications"}, longTask = false)
|
618
|
public Response fetchOrganizationPublications(@PathParam("organizationid") String organizationid,
|
619
|
@DefaultValue("0") @QueryParam("page") int offset,
|
620
|
@DefaultValue("10") @QueryParam("size") int limit,
|
621
|
@QueryParam("format") final String format,
|
622
|
@QueryParam("fq") final List<String> fieldQueries,
|
623
|
@Context HttpServletRequest request) {
|
624
|
String fullQuery = builtEntity2EntityRelationQuery(RequestResponseHandler.Entity.PUBLICATION, "relorganizationid", organizationid, fieldQueries);
|
625
|
return getResponseByEntity(fullQuery, RequestResponseHandler.Entity.PUBLICATION, offset, limit, format, request, false, null, null, fieldQueries);
|
626
|
}
|
627
|
|
628
|
@GET
|
629
|
@Path("/api/organizations/{organizationid}/publications/count")
|
630
|
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
|
631
|
@Timed(value = "http.server.request.duration", extraTags = {"referer", "portal", "uri", "/rest/v2/api/organizations/{organizationid}/publications/count"}, longTask = false)
|
632
|
public Response fetchOrganizationPublicationsCount(@PathParam("organizationid") String organizationid,
|
633
|
@DefaultValue("0") @QueryParam("page") int offset,
|
634
|
@DefaultValue("10") @QueryParam("size") int limit,
|
635
|
@QueryParam("format") final String format,
|
636
|
@QueryParam("fq") final List<String> fieldQueries,
|
637
|
@Context HttpServletRequest request) {
|
638
|
String fullQuery = builtEntity2EntityRelationQuery(RequestResponseHandler.Entity.PUBLICATION, "relorganizationid", organizationid, fieldQueries);
|
639
|
return getCount(request, fullQuery, format, fieldQueries);
|
640
|
}
|
641
|
|
642
|
@GET
|
643
|
@Path("/api/organizations/{organizationid}/datasets")
|
644
|
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
|
645
|
@Timed(value = "http.server.request.duration", extraTags = {"referer", "portal", "uri", "/rest/v2/api/organizations/{organizationid}/datasets"}, longTask = false)
|
646
|
public Response fetchOrganizationDatasets(@PathParam("organizationid") String organizationid,
|
647
|
@DefaultValue("0") @QueryParam("page") int offset,
|
648
|
@DefaultValue("10") @QueryParam("size") int limit,
|
649
|
@QueryParam("format") final String format,
|
650
|
@QueryParam("fq") final List<String> fieldQueries,
|
651
|
@Context HttpServletRequest request) {
|
652
|
String fullQuery = builtEntity2EntityRelationQuery(RequestResponseHandler.Entity.DATASET, "relorganizationid", organizationid, fieldQueries);
|
653
|
return getResponseByEntity(fullQuery, RequestResponseHandler.Entity.DATASET, offset, limit, format, request, false, null, null,fieldQueries);
|
654
|
}
|
655
|
|
656
|
@GET
|
657
|
@Path("/api/organizations/{organizationid}/datasets/count")
|
658
|
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
|
659
|
@Timed(value = "http.server.request.duration", extraTags = {"referer", "portal", "uri", "/rest/v2/api/organizations/{organizationid}/datasets/count"}, longTask = false)
|
660
|
public Response fetchOrganizationDatasetsCount(@PathParam("organizationid") String organizationid,
|
661
|
@DefaultValue("0") @QueryParam("page") int offset,
|
662
|
@DefaultValue("10") @QueryParam("size") int limit,
|
663
|
@QueryParam("format") final String format,
|
664
|
@QueryParam("fq") final List<String> fieldQueries,
|
665
|
@Context HttpServletRequest request) {
|
666
|
String fullQuery = builtEntity2EntityRelationQuery(RequestResponseHandler.Entity.DATASET, "relorganizationid", organizationid, fieldQueries);
|
667
|
return getCount(request, fullQuery, format, fieldQueries);
|
668
|
}
|
669
|
|
670
|
@GET
|
671
|
@Path("/api/organizations/{organizationid}/software")
|
672
|
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
|
673
|
@Timed(value = "http.server.request.duration", extraTags = {"referer", "portal", "uri", "/rest/v2/api/organizations/{organizationid}/software"}, longTask = false)
|
674
|
public Response fetchOrganizationSoftware(@PathParam("organizationid") String organizationid,
|
675
|
@DefaultValue("0") @QueryParam("page") int offset,
|
676
|
@DefaultValue("10") @QueryParam("size") int limit,
|
677
|
@QueryParam("format") final String format,
|
678
|
@QueryParam("fq") final List<String> fieldQueries,
|
679
|
@Context HttpServletRequest request) {
|
680
|
String fullQuery = builtEntity2EntityRelationQuery(RequestResponseHandler.Entity.SOFTWARE, "relorganizationid", organizationid, fieldQueries);
|
681
|
return getResponseByEntity(fullQuery, RequestResponseHandler.Entity.SOFTWARE, offset, limit, format, request, false, null, null,fieldQueries);
|
682
|
}
|
683
|
|
684
|
@GET
|
685
|
@Path("/api/organizations/{organizationid}/software/count")
|
686
|
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
|
687
|
@Timed(value = "http.server.request.duration", extraTags = {"referer", "portal", "uri", "/rest/v2/api/organizations/{organizationid}/software/count"}, longTask = false)
|
688
|
public Response fetchOrganizationSoftwareCount(@PathParam("organizationid") String organizationid,
|
689
|
@DefaultValue("0") @QueryParam("page") int offset,
|
690
|
@DefaultValue("10") @QueryParam("size") int limit,
|
691
|
@QueryParam("format") final String format,
|
692
|
@QueryParam("fq") final List<String> fieldQueries,
|
693
|
@Context HttpServletRequest request) {
|
694
|
String fullQuery = builtEntity2EntityRelationQuery(RequestResponseHandler.Entity.SOFTWARE, "relorganizationid", organizationid, fieldQueries);
|
695
|
return getCount(request, fullQuery, format, fieldQueries);
|
696
|
}
|
697
|
|
698
|
@GET
|
699
|
@Path("/api/organizations/{organizationid}/other")
|
700
|
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
|
701
|
@Timed(value = "http.server.request.duration", extraTags = {"referer", "portal", "uri", "/rest/v2/api/organizations/{organizationid}/other"}, longTask = false)
|
702
|
public Response fetchOrganizationOther(@PathParam("organizationid") String organizationid,
|
703
|
@DefaultValue("0") @QueryParam("page") int offset,
|
704
|
@DefaultValue("10") @QueryParam("size") int limit,
|
705
|
@QueryParam("format") final String format,
|
706
|
@QueryParam("fq") final List<String> fieldQueries,
|
707
|
@Context HttpServletRequest request) {
|
708
|
String fullQuery = builtEntity2EntityRelationQuery(RequestResponseHandler.Entity.OTHER, "relorganizationid", organizationid, fieldQueries);
|
709
|
return getResponseByEntity(fullQuery, RequestResponseHandler.Entity.OTHER, offset, limit, format, request, false, null, null,fieldQueries);
|
710
|
}
|
711
|
|
712
|
@GET
|
713
|
@Path("/api/organizations/{organizationid}/other/count")
|
714
|
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
|
715
|
@Timed(value = "http.server.request.duration", extraTags = {"referer", "portal", "uri", "/rest/v2/api/organizations/{organizationid}/other/count"}, longTask = false)
|
716
|
public Response fetchOrganizationOtherCount(@PathParam("organizationid") String organizationid,
|
717
|
@DefaultValue("0") @QueryParam("page") int offset,
|
718
|
@DefaultValue("10") @QueryParam("size") int limit,
|
719
|
@QueryParam("format") final String format,
|
720
|
@QueryParam("fq") final List<String> fieldQueries,
|
721
|
@Context HttpServletRequest request) {
|
722
|
String fullQuery = builtEntity2EntityRelationQuery(RequestResponseHandler.Entity.OTHER, "relorganizationid", organizationid, fieldQueries);
|
723
|
return getCount(request, fullQuery, format, fieldQueries);
|
724
|
}
|
725
|
|
726
|
@GET
|
727
|
@Path("/api/organizations/{organizationid}/results")
|
728
|
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
|
729
|
@Timed(value = "http.server.request.duration", extraTags = {"referer", "portal", "uri", "/rest/v2/api/organizations/{organizationid}/results"}, longTask = false)
|
730
|
public Response fetchOrganizationResults(@PathParam("organizationid") String organizationid,
|
731
|
@DefaultValue("0") @QueryParam("page") int offset,
|
732
|
@DefaultValue("10") @QueryParam("size") int limit,
|
733
|
@QueryParam("format") final String format,
|
734
|
@QueryParam("fq") final List<String> fieldQueries,
|
735
|
@Context HttpServletRequest request) {
|
736
|
String fullQuery = builtEntity2EntityRelationQuery(RequestResponseHandler.Entity.RESULT, "relorganizationid", organizationid, fieldQueries);
|
737
|
return getResponseByEntity(fullQuery, RequestResponseHandler.Entity.RESULT, offset, limit, format, request, false, null, null,fieldQueries);
|
738
|
}
|
739
|
|
740
|
@GET
|
741
|
@Path("/api/organizations/{organizationid}/results/count")
|
742
|
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
|
743
|
@Timed(value = "http.server.request.duration", extraTags = {"referer", "portal", "uri", "/rest/v2/api/organizations/{organizationid}/other/count"}, longTask = false)
|
744
|
public Response fetchOrganizationResultsCount(@PathParam("organizationid") String organizationid,
|
745
|
@DefaultValue("0") @QueryParam("page") int offset,
|
746
|
@DefaultValue("10") @QueryParam("size") int limit,
|
747
|
@QueryParam("format") final String format,
|
748
|
@QueryParam("fq") final List<String> fieldQueries,
|
749
|
@Context HttpServletRequest request) {
|
750
|
String fullQuery = builtEntity2EntityRelationQuery(RequestResponseHandler.Entity.RESULT, "relorganizationid", organizationid, fieldQueries);
|
751
|
return getCount(request, fullQuery, format, fieldQueries);
|
752
|
}
|
753
|
|
754
|
@GET
|
755
|
@Path("/api/organizations/{organizationid}/projects")
|
756
|
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
|
757
|
@Timed(value = "http.server.request.duration", extraTags = {"referer", "portal", "uri", "/rest/v2/api/organizations/{organizationid}/projects"}, longTask = false)
|
758
|
public Response fetchOrganizationProjects(@PathParam("organizationid") String organizationid,
|
759
|
@DefaultValue("0") @QueryParam("page") int offset,
|
760
|
@DefaultValue("10") @QueryParam("size") int limit,
|
761
|
@QueryParam("format") final String format,
|
762
|
@QueryParam("fq") final List<String> fieldQueries,
|
763
|
@Context HttpServletRequest request) {
|
764
|
String fullQuery = builtEntity2EntityRelationQuery(RequestResponseHandler.Entity.PROJECT, "relorganizationid", organizationid, fieldQueries);
|
765
|
return getResponseByEntity(fullQuery, RequestResponseHandler.Entity.PROJECT, offset, limit, format, request, false, null, null, fieldQueries);
|
766
|
}
|
767
|
|
768
|
@GET
|
769
|
@Path("/api/organizations/{organizationid}/projects/count")
|
770
|
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
|
771
|
@Timed(value = "http.server.request.duration", extraTags = {"referer", "portal", "uri", "/rest/v2/api/organizations/{organizationid}/projects/count"}, longTask = false)
|
772
|
public Response fetchOrganizationProjectsCount(@PathParam("organizationid") String organizationid,
|
773
|
@QueryParam("format") final String format,
|
774
|
@QueryParam("fq") final List<String> fieldQueries,
|
775
|
@Context final HttpServletRequest request) {
|
776
|
String fullQuery = builtEntity2EntityRelationQuery(RequestResponseHandler.Entity.PROJECT, "relorganizationid", organizationid, fieldQueries);
|
777
|
return getCount(request, fullQuery,format, fieldQueries);
|
778
|
}
|
779
|
|
780
|
/*
|
781
|
|
782
|
@GET
|
783
|
@Path("/api/people")
|
784
|
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
|
785
|
public Response fetchPeople(@QueryParam("q") String keywords,
|
786
|
@DefaultValue("0") @QueryParam("page") final int offset,
|
787
|
@DefaultValue("10") @QueryParam("size") final int limit,
|
788
|
@QueryParam("refine") @DefaultValue("false") final boolean refine,
|
789
|
@QueryParam("fields") final List<String> refineFields,
|
790
|
@QueryParam("fq") final List<String> fieldQueries,
|
791
|
@QueryParam("format") final String format,
|
792
|
@Context final HttpServletRequest request) {
|
793
|
|
794
|
String simpleQuery = buildSearchRequest(RequestResponseHandler.Entity.PERSON, keywords, fieldQueries);
|
795
|
return getResponseByEntity(simpleQuery, RequestResponseHandler.Entity.PERSON, offset, limit, format, request, refine, refineFields, fieldQueries);
|
796
|
}
|
797
|
|
798
|
|
799
|
@GET
|
800
|
@Path("/api/people/count")
|
801
|
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
|
802
|
public Response fetchPeopleCount(@QueryParam("q") String query,
|
803
|
@QueryParam("format") final String format,
|
804
|
@QueryParam("fq") final List<String> fieldQueries,
|
805
|
@Context final HttpServletRequest request) {
|
806
|
String fullQuery = buildSearchRequest(RequestResponseHandler.Entity.PERSON, query, fieldQueries);
|
807
|
return getCount(request, fullQuery, format, fieldQueries);
|
808
|
}
|
809
|
|
810
|
@GET
|
811
|
@Path("/api/people/{personid}")
|
812
|
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
|
813
|
public Response fetchPeople(@PathParam("personid") String personid,
|
814
|
@QueryParam("format") final String format,
|
815
|
@QueryParam("fq") final List<String> fieldQueries,
|
816
|
@Context final HttpServletRequest request) {
|
817
|
return getResponseByEntityId(request, RequestResponseHandler.Entity.PERSON, personid, format, fieldQueries);
|
818
|
}
|
819
|
|
820
|
|
821
|
@GET
|
822
|
@Path("/api/people/{personid}/publications")
|
823
|
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
|
824
|
public Response fetchPeoplePublications(@PathParam("personid") String personid,
|
825
|
@DefaultValue("0") @QueryParam("page") final int offset,
|
826
|
@DefaultValue("10") @QueryParam("size") final int limit,
|
827
|
@QueryParam("format") final String format,
|
828
|
@QueryParam("fq") final List<String> fieldQueries,
|
829
|
@Context final HttpServletRequest request) {
|
830
|
String fullQuery = builtEntity2EntityRelationQuery(RequestResponseHandler.Entity.PUBLICATION, "relpersonid", personid, fieldQueries);
|
831
|
return getResponseByEntity(fullQuery, RequestResponseHandler.Entity.PUBLICATION, offset, limit, format, request, false, null, fieldQueries);
|
832
|
}
|
833
|
|
834
|
@GET
|
835
|
@Path("/api/people/{personid}/publications/count")
|
836
|
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
|
837
|
public Response fetchPeoplePublicationsCount(@PathParam("personid") String personid,
|
838
|
@QueryParam("format") final String format,
|
839
|
@QueryParam("fq") final List<String> fieldQueries,
|
840
|
@Context final HttpServletRequest request) {
|
841
|
String fullQuery = builtEntity2EntityRelationQuery(RequestResponseHandler.Entity.PUBLICATION, "relpersonid", personid, fieldQueries);
|
842
|
return getCount(request, fullQuery, format, fieldQueries);
|
843
|
}
|
844
|
|
845
|
|
846
|
@GET
|
847
|
@Path("/api/people/{personid}/datasets")
|
848
|
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
|
849
|
public Response fetchPeopleDatasets(@PathParam("personid") String personid,
|
850
|
@DefaultValue("0") @QueryParam("page") final int offset,
|
851
|
@DefaultValue("10") @QueryParam("size") final int limit,
|
852
|
@QueryParam("format") final String format,
|
853
|
@QueryParam("fq") final List<String> fieldQueries,
|
854
|
@Context final HttpServletRequest request) {
|
855
|
String fullQuery = builtEntity2EntityRelationQuery(RequestResponseHandler.Entity.DATASET, "relpersonid", personid, fieldQueries);
|
856
|
return getResponseByEntity(fullQuery, RequestResponseHandler.Entity.DATASET, offset, limit, format, request, false, null, fieldQueries);
|
857
|
}
|
858
|
|
859
|
@GET
|
860
|
@Path("/api/people/{personid}/datasets/count")
|
861
|
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
|
862
|
public Response fetchPeopleDatasetsCount(@PathParam("personid") String personid,
|
863
|
@QueryParam("format") final String format,
|
864
|
@QueryParam("fq") final List<String> fieldQueries,
|
865
|
@Context final HttpServletRequest request) {
|
866
|
String fullQuery = builtEntity2EntityRelationQuery(RequestResponseHandler.Entity.DATASET, "relpersonid", personid, fieldQueries);
|
867
|
return getCount(request, fullQuery, format, fieldQueries);
|
868
|
}
|
869
|
*/
|
870
|
@GET
|
871
|
@Path("/api/reports")
|
872
|
@Produces(MediaType.TEXT_PLAIN)
|
873
|
@Timed(value = "http.server.request.duration", extraTags = {"referer", "portal", "uri", "/rest/v2/api/reports"}, longTask = false)
|
874
|
public Response fetchReport(@QueryParam("query") String query,
|
875
|
@QueryParam("refine") @DefaultValue("false") boolean refine,
|
876
|
@QueryParam("fields") final List<String> refineFields,
|
877
|
@QueryParam("fq") final List<String> fieldQueries,
|
878
|
@QueryParam("type") final List<String> types,
|
879
|
@QueryParam("format") final String format,
|
880
|
@Context final HttpServletResponse response) {
|
881
|
|
882
|
long startTime = System.nanoTime();
|
883
|
logger.debug("Reports request received");
|
884
|
|
885
|
final boolean special = isSpecialFormat(format);
|
886
|
String responseType = extractResponseFormat(format);
|
887
|
|
888
|
if(checkTypes(types)) {
|
889
|
return Response.status(Response.Status.BAD_REQUEST).
|
890
|
entity(APIResponseFormatter.compose400Message(responseType, "The type parameter is missing or is invalid.")).type(responseType).build();
|
891
|
}
|
892
|
|
893
|
RequestResponseHandler.Entity basicEntity = identifyBasicEntityType(types);
|
894
|
if (basicEntity.equals(RequestResponseHandler.Entity.NONE)) {
|
895
|
return Response.status(Response.Status.BAD_REQUEST).
|
896
|
entity(APIResponseFormatter.compose400Message(responseType, "The type parameter is missing or is invalid.")).type(responseType).build();
|
897
|
}
|
898
|
|
899
|
Transformer transformer = extractTransformer(format, basicEntity);
|
900
|
|
901
|
StringBuilder queryBuilder = new StringBuilder();
|
902
|
if (basicEntity.equals(RequestResponseHandler.Entity.RESULT)) {
|
903
|
enhanceFieldQueryWithResultType(types, fieldQueries);
|
904
|
|
905
|
} else {
|
906
|
enhanceFieldQueryWithEntityType(basicEntity, fieldQueries);
|
907
|
}
|
908
|
|
909
|
final String fullquery;
|
910
|
if (query==null || query.isEmpty()) {
|
911
|
fullquery = "*";
|
912
|
} else {
|
913
|
fullquery = query;
|
914
|
}
|
915
|
|
916
|
logger.debug("fullquery " + query);
|
917
|
logger.debug("fieldQueries " + fieldQueries);
|
918
|
|
919
|
try {
|
920
|
SearchResult sr = ((SearchServiceImpl)searchService).newSearch(fullquery, Locale.getDefault().toString(), refineFields, null, fieldQueries,0, 0, format, transformer,null,false);
|
921
|
logger.debug("Total number of results " + sr.getTotal());
|
922
|
|
923
|
|
924
|
} catch (SearchServiceException sse) {
|
925
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(APIResponseFormatter.
|
926
|
compose500Message(MediaType.APPLICATION_JSON, "Fail to fetch report.", sse.getMessage())).build();
|
927
|
}
|
928
|
|
929
|
StreamingOutput stream = new StreamingOutput() {
|
930
|
@Override
|
931
|
public void write(OutputStream os) throws IOException, WebApplicationException
|
932
|
{
|
933
|
if (hasTitle(format) && !format.equals("html")) {
|
934
|
os.write(CSVResponseFormat.appendTitle(basicEntity, special).getBytes());
|
935
|
}
|
936
|
try {
|
937
|
((SearchServiceImpl)searchService).cursorSearch(fullquery, refineFields, null, fieldQueries, format, transformer, os);
|
938
|
|
939
|
} catch (SearchServiceException sse) {
|
940
|
os.write(("Fail to return report. " + sse.getMessage()).getBytes());
|
941
|
logger.warn("Fail to return report. ", sse);
|
942
|
}
|
943
|
|
944
|
//os.close();
|
945
|
}
|
946
|
|
947
|
};
|
948
|
|
949
|
long estimatedTime = System.nanoTime() - startTime;
|
950
|
logger.debug("Reports search time " + estimatedTime/1000000 + " milliseconds");
|
951
|
return Response.ok().entity(stream).type(responseType).build();
|
952
|
}
|
953
|
|
954
|
private String extractResponseFormat(String format) {
|
955
|
if (format != null && !format.isEmpty()) {
|
956
|
if (format.equalsIgnoreCase("json")) {
|
957
|
return MediaType.APPLICATION_JSON;
|
958
|
|
959
|
} else if (format.contains("csv")) {
|
960
|
return new MediaType("text", "csv").toString();
|
961
|
|
962
|
} else if (format.equalsIgnoreCase("tsv")) {
|
963
|
return new MediaType("text", "tsv").toString();
|
964
|
|
965
|
} else if (format.equalsIgnoreCase("html")) {
|
966
|
return MediaType.TEXT_HTML;
|
967
|
}
|
968
|
}
|
969
|
|
970
|
return MediaType.APPLICATION_XML;
|
971
|
}
|
972
|
|
973
|
private boolean isSpecialFormat(String format) {
|
974
|
if (format != null && format.toLowerCase().contains("special")) {
|
975
|
return true;
|
976
|
}
|
977
|
return false;
|
978
|
}
|
979
|
|
980
|
private boolean hasTitle(String format) {
|
981
|
if (format != null && format.toLowerCase().contains("notitle")) {
|
982
|
return false;
|
983
|
}
|
984
|
return true;
|
985
|
}
|
986
|
|
987
|
//TODO differentiate for html + add special controls for format support
|
988
|
private Transformer extractTransformer(String format, RequestResponseHandler.Entity entity) {
|
989
|
if (searchRegistry == null) { return null;}
|
990
|
|
991
|
if (format != null && (format.toLowerCase().contains("csv") || format.equalsIgnoreCase("html"))) {
|
992
|
logger.debug("Extracting transformer...." + format + "_" + entity);
|
993
|
return searchRegistry.getTransformer(format.replaceAll("-notitle","") + "_" + entity, Locale.getDefault());
|
994
|
|
995
|
}
|
996
|
|
997
|
return null;
|
998
|
}
|
999
|
|
1000
|
//TODO old way of creating query see if needed.
|
1001
|
/*private String buildSimpleSearchQuery(RequestResponseHandler.Entity entity, String keywords) {
|
1002
|
StringBuilder queryBuilder = new StringBuilder();
|
1003
|
enhanceQueryWithEntityType(queryBuilder, entity);
|
1004
|
builtQueryKeywords(queryBuilder, cleanKeywords(keywords));
|
1005
|
return queryBuilder.toString();
|
1006
|
}*/
|
1007
|
|
1008
|
private static String cleanKeywords(String keywords) {
|
1009
|
if (keywords != null) {
|
1010
|
return keywords.replaceAll("[\\\\/:*?<>|()]", "");
|
1011
|
}
|
1012
|
return keywords;
|
1013
|
}
|
1014
|
|
1015
|
private String cleanId(String entityId) {
|
1016
|
return entityId.replaceAll("\"", "");
|
1017
|
}
|
1018
|
|
1019
|
private String buildSearchRequest(RequestResponseHandler.Entity entity, String keywords, String doi, String sortBy, List<String> fieldQueries) {
|
1020
|
enhanceFieldQueryWithEntityType(entity, fieldQueries);
|
1021
|
|
1022
|
StringBuilder queryBuilder = new StringBuilder();
|
1023
|
if (doi != null && !doi.trim().isEmpty()) {
|
1024
|
queryBuilder.append("(pidclassid exact \"doi\" and pid exact " + doi + ")");
|
1025
|
}
|
1026
|
|
1027
|
builtQueryKeywords(queryBuilder, keywords);
|
1028
|
enhanceWithSortParameter(queryBuilder, sortBy);
|
1029
|
|
1030
|
return queryBuilder.toString();
|
1031
|
}
|
1032
|
|
1033
|
public static String buildSearchRequest(List<String> types, String keywords, String doi, String sortBy, List<String> fieldQueries) {
|
1034
|
|
1035
|
List<RequestResponseHandler.Entity> entities = extractEntities(types);
|
1036
|
//all results are of oaftype result
|
1037
|
enhanceFieldQueryWithResultType(types, fieldQueries);
|
1038
|
|
1039
|
StringBuilder queryBuilder = new StringBuilder();
|
1040
|
if (doi != null && !doi.trim().isEmpty()) {
|
1041
|
if (!queryBuilder.toString().isEmpty()) {
|
1042
|
queryBuilder.append(" and ");
|
1043
|
}
|
1044
|
queryBuilder.append("(pidclassid exact \"doi\" and pid exact " + doi + ")");
|
1045
|
}
|
1046
|
|
1047
|
builtQueryKeywords(queryBuilder, keywords);
|
1048
|
enhanceWithSortParameter(queryBuilder, sortBy);
|
1049
|
|
1050
|
return queryBuilder.toString();
|
1051
|
}
|
1052
|
|
1053
|
private String buildSearchRequest(RequestResponseHandler.Entity entity, String keywords, List<String> fieldQueries) {
|
1054
|
enhanceFieldQueryWithEntityType(entity, fieldQueries);
|
1055
|
|
1056
|
StringBuilder queryBuilder = new StringBuilder();
|
1057
|
builtQueryKeywords(queryBuilder, keywords);
|
1058
|
|
1059
|
return queryBuilder.toString();
|
1060
|
}
|
1061
|
|
1062
|
private String buildSearchRequest(List<String> types, String keywords, List<String> fieldQueries) {
|
1063
|
|
1064
|
List<RequestResponseHandler.Entity> entities = extractEntities(types);
|
1065
|
enhanceFieldQueryWithEntityType(RequestResponseHandler.Entity.RESULT, fieldQueries);
|
1066
|
|
1067
|
StringBuilder queryBuilder = new StringBuilder();
|
1068
|
builtQueryKeywords(queryBuilder, keywords);
|
1069
|
|
1070
|
return queryBuilder.toString();
|
1071
|
}
|
1072
|
|
1073
|
private static void enhanceFieldQueryWithEntityType(RequestResponseHandler.Entity entity, List<String> fieldQueries) {
|
1074
|
for (String fieldQuery: entity.getFieldQueries()) {
|
1075
|
logger.debug("adding " + fieldQuery);
|
1076
|
fieldQueries.add(fieldQuery);
|
1077
|
}
|
1078
|
}
|
1079
|
|
1080
|
private static void enhanceFieldQueryWithResultType(final List<String> types, List<String> fieldQueries) {
|
1081
|
|
1082
|
fieldQueries.add(RequestResponseHandler.Entity.RESULT.getSimpleQuery());
|
1083
|
List<RequestResponseHandler.Entity> entities = extractEntities(types);
|
1084
|
|
1085
|
if (types!= null && !types.isEmpty()) {
|
1086
|
StringBuilder queryBuilder = new StringBuilder();
|
1087
|
for(RequestResponseHandler.Entity entity: entities) {
|
1088
|
CQLQueryBuilder.appendSimpleTerm(queryBuilder, CQLQueryBuilder.Operator.OR, entity.getSimpleQuery());
|
1089
|
}
|
1090
|
fieldQueries.add(queryBuilder.toString());
|
1091
|
}
|
1092
|
}
|
1093
|
|
1094
|
|
1095
|
|
1096
|
private static void builtQueryKeywords(StringBuilder queryBuilder, String keywords) {
|
1097
|
if (keywords != null && !keywords.trim().isEmpty()) {
|
1098
|
CQLQueryBuilder.appendKeywords(queryBuilder, cleanKeywords(keywords));
|
1099
|
}
|
1100
|
|
1101
|
if (queryBuilder.toString().isEmpty()) {
|
1102
|
queryBuilder.append("(*)");
|
1103
|
}
|
1104
|
}
|
1105
|
|
1106
|
private void builtEntityIdQuery(StringBuilder queryBuilder, RequestResponseHandler.Entity entity, String entityId, List<String> fieldQueries){
|
1107
|
enhanceFieldQueryWithEntityType(entity, fieldQueries);
|
1108
|
enhanceQueryWithEntityId(queryBuilder, entity, cleanId(entityId));
|
1109
|
}
|
1110
|
|
1111
|
/* Queries with pids are only valid with deleted by inference marked as true */
|
1112
|
private void resultPidQuery(StringBuilder queryBuilder, RequestResponseHandler.Entity entity, String resultPid, List<String> fieldQueries){
|
1113
|
builtDeletedByInferenceQuery(queryBuilder);
|
1114
|
|
1115
|
if (entity != RequestResponseHandler.Entity.NONE && entity != RequestResponseHandler.Entity.ORGANIZATION) {
|
1116
|
throw new IllegalArgumentException("Entity " + entity.toString() + " is not supported.");
|
1117
|
}
|
1118
|
enhanceQueryWithPid(queryBuilder, entity, cleanId(resultPid));
|
1119
|
}
|
1120
|
|
1121
|
private void builtDeletedByInferenceQuery(StringBuilder queryBuilder) {
|
1122
|
CQLQueryBuilder.appendFieldTerm(queryBuilder, CQLQueryBuilder.Operator.NONE, "deletedByInference", CQLQueryBuilder.Operator.EQUAL, "true");
|
1123
|
}
|
1124
|
|
1125
|
private String builtEntity2EntityRelationQuery(RequestResponseHandler.Entity entity, String relationfield, String entityId, List<String> fieldQueries){
|
1126
|
StringBuilder queryBuilder = new StringBuilder();
|
1127
|
//enhanceQueryWithEntityType(queryBuilder, entity);
|
1128
|
enhanceFieldQueryWithEntityType(entity, fieldQueries);
|
1129
|
enhanceQueryWithRelationId(queryBuilder, relationfield, cleanId(entityId));
|
1130
|
return queryBuilder.toString();
|
1131
|
}
|
1132
|
|
1133
|
private void enhanceQueryWithRelationId(StringBuilder queryBuilder, String relationfield, String entityId) {
|
1134
|
if (!queryBuilder.toString().isEmpty()) {
|
1135
|
CQLQueryBuilder.appendFieldTerm(queryBuilder, CQLQueryBuilder.Operator.AND, " " + relationfield + " ", CQLQueryBuilder.Operator.EXACT, entityId);
|
1136
|
|
1137
|
} else {
|
1138
|
CQLQueryBuilder.appendFieldTerm(queryBuilder, CQLQueryBuilder.Operator.NONE, relationfield + " ", CQLQueryBuilder.Operator.EXACT, entityId);
|
1139
|
}
|
1140
|
}
|
1141
|
|
1142
|
private void enhanceQueryWithEntityId(StringBuilder queryBuilder, RequestResponseHandler.Entity entity, String entityId) {
|
1143
|
if (queryBuilder.toString().isEmpty()) {
|
1144
|
CQLQueryBuilder.appendFieldTerm(queryBuilder, CQLQueryBuilder.Operator.NONE, "objidentifier", CQLQueryBuilder.Operator.EXACT, entityId);
|
1145
|
} else {
|
1146
|
CQLQueryBuilder.appendFieldTerm(queryBuilder, CQLQueryBuilder.Operator.AND, "objidentifier", CQLQueryBuilder.Operator.EXACT, entityId);
|
1147
|
}
|
1148
|
|
1149
|
if (entity == RequestResponseHandler.Entity.PUBLICATION || entity == RequestResponseHandler.Entity.DATASET
|
1150
|
|| entity == RequestResponseHandler.Entity.SOFTWARE || entity == RequestResponseHandler.Entity.OTHER ||
|
1151
|
entity == RequestResponseHandler.Entity.RESULT) {
|
1152
|
CQLQueryBuilder.appendFieldTerm(queryBuilder, CQLQueryBuilder.Operator.OR, "resultdupid", CQLQueryBuilder.Operator.EXACT, entityId);
|
1153
|
|
1154
|
} else if (entity == RequestResponseHandler.Entity.ORGANIZATION) {
|
1155
|
CQLQueryBuilder.appendFieldTerm(queryBuilder, CQLQueryBuilder.Operator.OR, "organizationdupid", CQLQueryBuilder.Operator.EXACT, entityId);
|
1156
|
}
|
1157
|
}
|
1158
|
|
1159
|
|
1160
|
|
1161
|
private void enhanceQueryWithPid(StringBuilder queryBuilder, RequestResponseHandler.Entity entity, String entityId) {
|
1162
|
if (entity == RequestResponseHandler.Entity.NONE) {
|
1163
|
CQLQueryBuilder.appendFieldTerm(queryBuilder, CQLQueryBuilder.Operator.AND, "resultdupid", CQLQueryBuilder.Operator.EXACT, entityId);
|
1164
|
|
1165
|
} else if (entity == RequestResponseHandler.Entity.ORGANIZATION) {
|
1166
|
CQLQueryBuilder.appendFieldTerm(queryBuilder, CQLQueryBuilder.Operator.AND, "organizationdupid", CQLQueryBuilder.Operator.EXACT, entityId);
|
1167
|
|
1168
|
} else {
|
1169
|
throw new IllegalArgumentException("The entity " + entity.toString() + " is not supported.");
|
1170
|
}
|
1171
|
}
|
1172
|
|
1173
|
private static void enhanceWithSortParameter(StringBuilder queryBuilder, String sortBy) {
|
1174
|
if (sortBy != null) {
|
1175
|
String[] sortParams = sortBy.split(",");
|
1176
|
|
1177
|
if (sortParams.length != 2) {
|
1178
|
throw new IllegalArgumentException("Invalid sort paremeter. 'sortBy' parameter format is <fieldName>[,asc|,desc].");
|
1179
|
}
|
1180
|
|
1181
|
String sortByField = sortParams[0];
|
1182
|
String order = sortParams[1];
|
1183
|
|
1184
|
if (!sortByField.equals("resultdateofacceptance")){
|
1185
|
throw new IllegalArgumentException("'" + sortByField + "' is not a sortable field.");
|
1186
|
}
|
1187
|
|
1188
|
if (!checkOrder(order)) {
|
1189
|
throw new IllegalArgumentException("'" + order + "' is not a valid ordering. Please use one of {ascending, descending}");
|
1190
|
}
|
1191
|
|
1192
|
addSortParameter(sortByField, order, queryBuilder);
|
1193
|
}
|
1194
|
}
|
1195
|
|
1196
|
private static boolean checkOrder(String order) {
|
1197
|
if (order.matches("ascending|descending")) {
|
1198
|
return true;
|
1199
|
}
|
1200
|
return false;
|
1201
|
}
|
1202
|
|
1203
|
private static void addSortParameter(String indexField, String order, StringBuilder queryBuilder) {
|
1204
|
queryBuilder.append(" sortBy " + indexField + "/sort." + order);
|
1205
|
}
|
1206
|
|
1207
|
private Response getCount(HttpServletRequest request, String query, String format, List<String> fieldQueries) {
|
1208
|
String responseFormat = extractResponseFormat(format);
|
1209
|
|
1210
|
try {
|
1211
|
SearchResult searchResult = ((SearchServiceImpl)searchService).newSearch(query, Locale.getDefault().toString(), null, null, fieldQueries, 0, 0, responseFormat, null, null, false);
|
1212
|
return Response.status(Response.Status.OK).entity(APIResponseFormatter.createCountMeta(request, query, searchResult.getTotal(), responseFormat)).type(responseFormat).build();
|
1213
|
|
1214
|
} catch (SearchServiceException sse) {
|
1215
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(APIResponseFormatter.compose500Message(responseFormat, "Fail to fetch count for query " + query + ".", sse.getMessage())).build();
|
1216
|
}
|
1217
|
}
|
1218
|
|
1219
|
private Response getResponseByEntityId(HttpServletRequest request, RequestResponseHandler.Entity entity, String entityId, String format, List<String> fieldQueries) {
|
1220
|
String responseType = extractResponseFormat(format);
|
1221
|
|
1222
|
try {
|
1223
|
StringBuilder queryBuilder = new StringBuilder();
|
1224
|
builtEntityIdQuery(queryBuilder, entity, entityId, fieldQueries);
|
1225
|
String fullQuery = queryBuilder.toString();
|
1226
|
|
1227
|
if(fullQuery == null || fullQuery.isEmpty()) {
|
1228
|
return Response.status(Response.Status.BAD_REQUEST).
|
1229
|
entity(APIResponseFormatter.compose400Message(format, "The 'query' parameter is required")).
|
1230
|
type(responseType).build();
|
1231
|
}
|
1232
|
|
1233
|
SearchResult searchResult = ((SearchServiceImpl)searchService).newSearch(fullQuery, Locale.getDefault().toString(), null, null, fieldQueries, 0, 1, responseType, null, null, false);
|
1234
|
|
1235
|
if (searchResult.getSearchResults() == null || searchResult.getSearchResults().isEmpty() ||
|
1236
|
searchResult.getSearchResults().size() == 0 || searchResult.getSearchResults().get(0) == null) {
|
1237
|
return Response.status(Response.Status.NOT_FOUND).entity(APIResponseFormatter.compose404Message(responseType, "404 - " + entity +" with id "
|
1238
|
+ entityId + " not found.")).type(responseType).build();
|
1239
|
}
|
1240
|
|
1241
|
return Response.status(Response.Status.OK).entity(APIResponseFormatter.createEntityResponse(request, entity, searchResult.getSearchResults().get(0).toString(), responseType)).type(responseType).build();
|
1242
|
|
1243
|
} catch (SearchServiceException sse) {
|
1244
|
logger.error("Fail to fetch "+ entity + " with id " + entityId, sse);
|
1245
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(APIResponseFormatter.compose500Message(responseType, "Fail to fetch " + entity + " with id " + entityId, sse.getMessage())).build();
|
1246
|
}
|
1247
|
}
|
1248
|
|
1249
|
private Response getResponseByEntity(String fullQuery, RequestResponseHandler.Entity entity, int offset, int limit, String format, HttpServletRequest request, boolean refine, List<String> refineFields, List<String> specialFacets, List<String> fieldQueries) {
|
1250
|
long startTime = System.nanoTime();
|
1251
|
Transformer transformer = extractTransformer(format, entity);
|
1252
|
boolean special = isSpecialFormat(format);
|
1253
|
boolean hasTitle = hasTitle(format);
|
1254
|
String responseType = extractResponseFormat(format);
|
1255
|
|
1256
|
if(fullQuery == null || fullQuery.isEmpty()) {
|
1257
|
return Response.status(Response.Status.BAD_REQUEST).
|
1258
|
entity(APIResponseFormatter.compose400Message(responseType, "The 'query' parameter is required")).
|
1259
|
type(responseType).build();
|
1260
|
}
|
1261
|
|
1262
|
try {
|
1263
|
SearchResult solrResults = ((SearchServiceImpl)searchService).newSearch(fullQuery, Locale.getDefault().toString(), refineFields, specialFacets, fieldQueries, offset, limit, responseType, transformer, null, false);
|
1264
|
long estimatedTime = System.nanoTime() - startTime;
|
1265
|
logger.debug("Publications search time " + estimatedTime/1000000 + " milliseconds");
|
1266
|
return Response.status(Response.Status.OK).entity(APIResponseFormatter.createEntitiesResponse(request, entity, fullQuery, fieldQueries, solrResults, refine, responseType, special, hasTitle)).type(responseType).build();
|
1267
|
|
1268
|
} catch (SearchServiceException sse) {
|
1269
|
logger.error("Fail to get " + entity.getPlural() , sse);
|
1270
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).
|
1271
|
entity(APIResponseFormatter.compose500Message(responseType, "Fail to fetch " + entity.getPlural(), sse.getMessage())).type(responseType).build();
|
1272
|
}
|
1273
|
}
|
1274
|
|
1275
|
private Response getResponseByEntityTypes(String fullQuery, List<String> types, int offset, int limit, String format, HttpServletRequest request, boolean refine, List<String> refineFields, List<String> specialFacets, List<String> fieldQueries) {
|
1276
|
long startTime = System.nanoTime();
|
1277
|
|
1278
|
boolean special = isSpecialFormat(format);
|
1279
|
boolean hasTitle = hasTitle(format);
|
1280
|
String responseType = extractResponseFormat(format);
|
1281
|
|
1282
|
if(checkTypes(types)) {
|
1283
|
return Response.status(Response.Status.FORBIDDEN).
|
1284
|
entity(APIResponseFormatter.compose400Message(responseType, "The type parameter is missing or is invalid.")).type(responseType).build();
|
1285
|
}
|
1286
|
|
1287
|
RequestResponseHandler.Entity basicEntity = identifyBasicEntityType(types);
|
1288
|
if (basicEntity.equals(RequestResponseHandler.Entity.NONE)) {
|
1289
|
return Response.status(Response.Status.FORBIDDEN).
|
1290
|
entity(APIResponseFormatter.compose400Message(responseType, "The type parameter is missing or is invalid.")).type(responseType).build();
|
1291
|
}
|
1292
|
Transformer transformer = extractTransformer(format, basicEntity);
|
1293
|
|
1294
|
//List<RequestResponseHandler.Entity> entities = extractEntities(types);
|
1295
|
StringBuilder queryBuilder = new StringBuilder();
|
1296
|
if (basicEntity.equals(RequestResponseHandler.Entity.RESULT)) {
|
1297
|
enhanceFieldQueryWithResultType(types, fieldQueries);
|
1298
|
} else {
|
1299
|
enhanceFieldQueryWithEntityType(basicEntity, fieldQueries);
|
1300
|
}
|
1301
|
|
1302
|
try {
|
1303
|
if (fullQuery==null || fullQuery.isEmpty()) {
|
1304
|
fullQuery = "*";
|
1305
|
}
|
1306
|
|
1307
|
SearchResult solrResults = ((SearchServiceImpl)searchService).newSearch(fullQuery, Locale.getDefault().toString(), refineFields, specialFacets, fieldQueries, offset, limit, responseType, transformer, null, false);
|
1308
|
long estimatedTime = System.nanoTime() - startTime;
|
1309
|
logger.debug("Publications search time " + estimatedTime/1000000 + " milliseconds");
|
1310
|
return Response.status(Response.Status.OK).entity(APIResponseFormatter.createEntitiesResponse(request, basicEntity, fullQuery, fieldQueries, solrResults, refine, responseType, special, hasTitle)).type(responseType).build();
|
1311
|
|
1312
|
} catch (SearchServiceException sse) {
|
1313
|
logger.error("Fail to get " + basicEntity.getPlural() , sse);
|
1314
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).
|
1315
|
entity(APIResponseFormatter.compose500Message(responseType, "Fail to fetch " + basicEntity.getPlural(), sse.getMessage())).type(responseType).build();
|
1316
|
}
|
1317
|
}
|
1318
|
|
1319
|
private Response getResponseByEntityTypes(String fullQuery, String pid, String pidType, List<String> types, int offset, int limit, String format, HttpServletRequest request, boolean refine, List<String> refineFields, List<String> specialFacets, List<String> fieldQueries) {
|
1320
|
long startTime = System.nanoTime();
|
1321
|
|
1322
|
boolean special = isSpecialFormat(format);
|
1323
|
boolean hasTitle = hasTitle(format);
|
1324
|
String responseType = extractResponseFormat(format);
|
1325
|
|
1326
|
if(checkTypes(types)) {
|
1327
|
return Response.status(Response.Status.FORBIDDEN).
|
1328
|
entity(APIResponseFormatter.compose400Message(responseType, "The type parameter is missing or is invalid.")).type(responseType).build();
|
1329
|
}
|
1330
|
|
1331
|
RequestResponseHandler.Entity basicEntity = identifyBasicEntityType(types);
|
1332
|
if (basicEntity.equals(RequestResponseHandler.Entity.NONE)) {
|
1333
|
return Response.status(Response.Status.FORBIDDEN).
|
1334
|
entity(APIResponseFormatter.compose400Message(responseType, "The type parameter is missing or is invalid.")).type(responseType).build();
|
1335
|
}
|
1336
|
Transformer transformer = extractTransformer(format, basicEntity);
|
1337
|
|
1338
|
//List<RequestResponseHandler.Entity> entities = extractEntities(types);
|
1339
|
|
1340
|
if (basicEntity.equals(RequestResponseHandler.Entity.RESULT)) {
|
1341
|
enhanceFieldQueryWithResultType(types, fieldQueries);
|
1342
|
} else {
|
1343
|
enhanceFieldQueryWithEntityType(basicEntity, fieldQueries);
|
1344
|
}
|
1345
|
|
1346
|
StringBuilder queryBuilder = new StringBuilder();
|
1347
|
logger.debug("pid " +pid);
|
1348
|
logger.debug("pidtype" +pidType);
|
1349
|
|
1350
|
if (pid != null && !pid.isEmpty()) {
|
1351
|
if ((pidType != null) && !pidType.isEmpty()) {
|
1352
|
enhanceQueryWithPersistentIdentifier(queryBuilder, pid, pidType);
|
1353
|
} else {
|
1354
|
return Response.status(Response.Status.BAD_REQUEST).
|
1355
|
entity(APIResponseFormatter.compose400Message(responseType, "The pid type is missing.")).type(responseType).build();
|
1356
|
}
|
1357
|
}
|
1358
|
try {
|
1359
|
logger.debug("Query builder " + queryBuilder.toString());
|
1360
|
logger.debug("Query " + fullQuery);
|
1361
|
|
1362
|
if (!queryBuilder.toString().isEmpty()){
|
1363
|
if (fullQuery != null && !fullQuery.isEmpty()) {
|
1364
|
queryBuilder.append(" ").append(CQLQueryBuilder.Operator.AND).append(" ").append(fullQuery);
|
1365
|
}
|
1366
|
} else {
|
1367
|
if (fullQuery != null && !fullQuery.isEmpty()) {
|
1368
|
queryBuilder.append(fullQuery);
|
1369
|
} else {
|
1370
|
queryBuilder.append("*");
|
1371
|
}
|
1372
|
}
|
1373
|
|
1374
|
SearchResult solrResults = ((SearchServiceImpl)searchService).newSearch(queryBuilder.toString(), Locale.getDefault().toString(), refineFields, specialFacets, fieldQueries, offset, limit, responseType, transformer, null, false);
|
1375
|
long estimatedTime = System.nanoTime() - startTime;
|
1376
|
logger.debug("Publications search time " + estimatedTime/1000000 + " milliseconds");
|
1377
|
return Response.status(Response.Status.OK).entity(APIResponseFormatter.createEntitiesResponse(request, basicEntity, queryBuilder.toString(), fieldQueries, solrResults, refine, responseType, special, hasTitle)).type(responseType).build();
|
1378
|
|
1379
|
} catch (SearchServiceException sse) {
|
1380
|
logger.error("Fail to get " + basicEntity.getPlural() , sse);
|
1381
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).
|
1382
|
entity(APIResponseFormatter.compose500Message(responseType, "Fail to fetch " + basicEntity.getPlural(), sse.getMessage())).type(responseType).build();
|
1383
|
}
|
1384
|
}
|
1385
|
|
1386
|
private void enhanceQueryWithPersistentIdentifier(StringBuilder queryBuilder, String pid, String pidType) {
|
1387
|
queryBuilder.append("(pidclassid exact "+ pidType + " and pid exact \"" + pid + "\")");
|
1388
|
}
|
1389
|
|
1390
|
private void enhanceQueryWithEntities(StringBuilder queryBuilder, List<String> types) {
|
1391
|
|
1392
|
}
|
1393
|
|
1394
|
|
1395
|
private static List<RequestResponseHandler.Entity> extractEntities(final List<String> types) {
|
1396
|
List<RequestResponseHandler.Entity> entities = null;
|
1397
|
if (types!= null || types.isEmpty()) {
|
1398
|
logger.debug("types " + types);
|
1399
|
entities = new ArrayList<>();
|
1400
|
for (String type: types) {
|
1401
|
if (!entities.contains(type)) {
|
1402
|
logger.debug("extracting for type " + type);
|
1403
|
entities.add(extractEntity(type));
|
1404
|
}
|
1405
|
}
|
1406
|
}
|
1407
|
return entities;
|
1408
|
}
|
1409
|
|
1410
|
private static RequestResponseHandler.Entity extractEntity(String type) {
|
1411
|
|
1412
|
if (type == null) {
|
1413
|
return RequestResponseHandler.Entity.NONE;
|
1414
|
}
|
1415
|
|
1416
|
if (type.equalsIgnoreCase(RequestResponseHandler.Entity.RESULT.getPlural())) {
|
1417
|
return RequestResponseHandler.Entity.RESULT;
|
1418
|
|
1419
|
} else if (type.equalsIgnoreCase(RequestResponseHandler.Entity.PUBLICATION.getPlural())) {
|
1420
|
return RequestResponseHandler.Entity.PUBLICATION;
|
1421
|
|
1422
|
} else if (type.equalsIgnoreCase(RequestResponseHandler.Entity.DATASET.getPlural())) {
|
1423
|
return RequestResponseHandler.Entity.DATASET;
|
1424
|
|
1425
|
} else if (type.equalsIgnoreCase(RequestResponseHandler.Entity.SOFTWARE.getPlural())) {
|
1426
|
return RequestResponseHandler.Entity.SOFTWARE;
|
1427
|
|
1428
|
} else if (type.equalsIgnoreCase(RequestResponseHandler.Entity.OTHER.getPlural())) {
|
1429
|
return RequestResponseHandler.Entity.OTHER;
|
1430
|
|
1431
|
} else if (type.equalsIgnoreCase(RequestResponseHandler.Entity.PROJECT.getPlural())) {
|
1432
|
return RequestResponseHandler.Entity.PROJECT;
|
1433
|
|
1434
|
} else if (type.equalsIgnoreCase(RequestResponseHandler.Entity.DATASOURCE.getPlural())) {
|
1435
|
return RequestResponseHandler.Entity.DATASOURCE;
|
1436
|
|
1437
|
/*} else if (type.equalsIgnoreCase(RequestResponseHandler.Entity.PERSON.getPlural())) {
|
1438
|
return RequestResponseHandler.Entity.PERSON;
|
1439
|
*/
|
1440
|
|
1441
|
} else if (type.equalsIgnoreCase(RequestResponseHandler.Entity.ORGANIZATION.getPlural())) {
|
1442
|
return RequestResponseHandler.Entity.ORGANIZATION;
|
1443
|
}
|
1444
|
|
1445
|
return RequestResponseHandler.Entity.NONE;
|
1446
|
}
|
1447
|
|
1448
|
|
1449
|
//This follows the newSearchWithoutFieldQueries comment. I wish to remove it!!! This was only made
|
1450
|
// (quick and dirty - only the getResponseByEntity version with newSearchWithoutFieldQueries is used
|
1451
|
// after a last time request for the portal to show all the publications and the deletedbyinference ones.
|
1452
|
// I did not want to pass a parameter since I do not know if we are going to keep it. This is for a tech meeting showcase.
|
1453
|
// If we want to keep this I need to redesign.
|
1454
|
@GET
|
1455
|
@Path("/api/deletedByInferencePublications/{publicationid}")
|
1456
|
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
|
1457
|
@Timed(value = "http.requests.portal.publicationDuplicates", longTask = false)
|
1458
|
//TODO remove
|
1459
|
public Response fetchDeletedByInferencePublicationsById(@PathParam("publicationid") String publicationid,
|
1460
|
@QueryParam("format") final String format,
|
1461
|
@QueryParam("size") final int limit,
|
1462
|
@QueryParam("fq") final List<String> fieldQueries,
|
1463
|
@Context final HttpServletRequest request) {
|
1464
|
|
1465
|
return getDeletedByInferenceResponseByPid(request, RequestResponseHandler.Entity.PUBLICATION, publicationid, format, limit, fieldQueries);
|
1466
|
}
|
1467
|
|
1468
|
@GET
|
1469
|
@Path("/api/deletedByInferenceResults/{resultPid}")
|
1470
|
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
|
1471
|
@Timed(value = "http.requests.portal.publicationDuplicates", longTask = false)
|
1472
|
public Response fetchDeletedByInferenceEntitiesById(@PathParam("resultPid") String resultPid,
|
1473
|
@QueryParam("format") final String format,
|
1474
|
@QueryParam("size") final int limit,
|
1475
|
@QueryParam("fq") final List<String> fieldQueries,
|
1476
|
@Context final HttpServletRequest request) {
|
1477
|
|
1478
|
return getDeletedByInferenceResponseByPid(request, RequestResponseHandler.Entity.NONE, resultPid, format, limit, fieldQueries);
|
1479
|
}
|
1480
|
|
1481
|
|
1482
|
@GET
|
1483
|
@Path("/api/deletedByInferenceOrganizations/{organizationPid}")
|
1484
|
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
|
1485
|
@Timed(value = "http.requests.portal.organizationDuplicates", longTask = false)
|
1486
|
public Response fetchDeletedByInferenceOrganizationById(@PathParam("organizationPid") String organizationPid,
|
1487
|
@QueryParam("format") final String format,
|
1488
|
@QueryParam("size") final int limit,
|
1489
|
@QueryParam("fq") final List<String> fieldQueries,
|
1490
|
@Context final HttpServletRequest request) {
|
1491
|
|
1492
|
return getDeletedByInferenceResponseByPid(request, RequestResponseHandler.Entity.ORGANIZATION, organizationPid, format, limit, fieldQueries);
|
1493
|
}
|
1494
|
|
1495
|
|
1496
|
//Please see comment above. I wish to remove it.
|
1497
|
private Response getDeletedByInferenceResponseByPid(HttpServletRequest request, RequestResponseHandler.Entity entity, String resultPid, String format, int limit, List<String> fieldQueries) {
|
1498
|
String responseType = extractResponseFormat(format);
|
1499
|
|
1500
|
try {
|
1501
|
StringBuilder queryBuilder = new StringBuilder();
|
1502
|
resultPidQuery(queryBuilder, entity, resultPid, fieldQueries);
|
1503
|
String fullQuery = queryBuilder.toString();
|
1504
|
|
1505
|
if(fullQuery == null || fullQuery.isEmpty()) {
|
1506
|
return Response.status(Response.Status.BAD_REQUEST).
|
1507
|
entity(APIResponseFormatter.compose400Message(format, "The 'query' parameter is required")).
|
1508
|
type(responseType).build();
|
1509
|
}
|
1510
|
|
1511
|
SearchResult searchResults = ((SearchServiceImpl)searchService).newSearchWithoutFieldQueries(fullQuery, Locale.getDefault().toString(), null, null, fieldQueries, 0, limit, responseType, null, null, false);
|
1512
|
|
1513
|
if (searchResults.getSearchResults() == null || searchResults.getSearchResults().isEmpty() ||
|
1514
|
searchResults.getSearchResults().size() == 0 || searchResults.getSearchResults().get(0) == null) {
|
1515
|
return Response.status(Response.Status.NOT_FOUND).entity(APIResponseFormatter.compose404Message(responseType, "404 - " + entity +" with id "
|
1516
|
+ resultPid + " not found.")).type(responseType).build();
|
1517
|
}
|
1518
|
|
1519
|
|
1520
|
return Response.status(Response.Status.OK).entity(APIResponseFormatter.createEntitiesResponse(request, entity, fullQuery, null, searchResults, false, responseType, false, false)).type(responseType).build();
|
1521
|
|
1522
|
} catch (SearchServiceException sse) {
|
1523
|
logger.error("Fail to fetch "+ entity + " with id " + resultPid, sse);
|
1524
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(APIResponseFormatter.compose500Message(responseType, "Fail to fetch " + entity + " with id " + resultPid, sse.getMessage())).build();
|
1525
|
}
|
1526
|
}
|
1527
|
|
1528
|
public boolean checkTypes(List<String> types) {
|
1529
|
for (RequestResponseHandler.Entity entity: RequestResponseHandler.Entity.values()){
|
1530
|
if (!types.contains(entity.getPlural())) {
|
1531
|
return false;
|
1532
|
}
|
1533
|
}
|
1534
|
|
1535
|
return true;
|
1536
|
}
|
1537
|
|
1538
|
private RequestResponseHandler.Entity identifyBasicEntityType(final List<String> types) {
|
1539
|
if (types != null && !types.isEmpty() && types.get(0) != null && !types.get(0).isEmpty()) {
|
1540
|
String type = types.get(0);
|
1541
|
|
1542
|
if (type.equals(RequestResponseHandler.Entity.RESULT.getPlural())) {
|
1543
|
return RequestResponseHandler.Entity.RESULT;
|
1544
|
|
1545
|
} else if (type.equals(RequestResponseHandler.Entity.PUBLICATION.getPlural()) || type.equals(RequestResponseHandler.Entity.DATASET.getPlural()) ||
|
1546
|
type.equals(RequestResponseHandler.Entity.SOFTWARE.getPlural()) || type.equals(RequestResponseHandler.Entity.OTHER.getPlural())) {
|
1547
|
return RequestResponseHandler.Entity.RESULT;
|
1548
|
|
1549
|
} else if (type.equals(RequestResponseHandler.Entity.PROJECT.getPlural())) {
|
1550
|
return RequestResponseHandler.Entity.PROJECT;
|
1551
|
|
1552
|
} else if (type.equals(RequestResponseHandler.Entity.DATASOURCE.getPlural())) {
|
1553
|
return RequestResponseHandler.Entity.DATASOURCE;
|
1554
|
|
1555
|
} else if (type.equals(RequestResponseHandler.Entity.ORGANIZATION.getPlural())) {
|
1556
|
return RequestResponseHandler.Entity.ORGANIZATION;
|
1557
|
}
|
1558
|
}
|
1559
|
return RequestResponseHandler.Entity.NONE;
|
1560
|
}
|
1561
|
|
1562
|
/*
|
1563
|
public static void main(String[] args) {
|
1564
|
String json = " {\"result\":{\"xmlns:oaf\":\"http://namespace.openaire.eu/oaf\",\"xmlns:xsi\":\"http://www.w3.o" +
|
1565
|
"rg/2001/XMLSchema-instance\",\"header\":{\"dri:dateOfCollection\":\"2016-05-20T03:34:07Z\",\"dri:dateOfTransformation\":\"\",\"counters\":{\"counter_dedup\":{\"value\":2},\"counter_doi\":{\"value\":2},\"counter_authorship\":{\"va" +
|
1566
|
"lue\":1},\"counter_authorship_inferred\":{\"value\":1}},\"dri:objIdentifier\":\"dedup_wf_001::0f5604702b32f59d9789573113279e69\"},\"metadata\":{\"oaf:entity\":{\"oaf:result\":{\"datainfo\":{\"provenanceaction\":{\"schemename\"" +
|
1567
|
":\"dnet:provenanceActions\",\"classname\":\"sysimport:dedup\",\"schemeid\":\"dnet:provenanceActions\",\"classid\":\"sysimport:dedup\"},\"trust\":0.9,\"inferenceprovenance\":\"dedup-similarity-result\",\"deletedbyinference\":fal" +
|
1568
|
"se,\"inferred\":true},\"rels\":{\"rel\":{\"to\":{\"content\":\"dedup_wf_001::884d8c367553a8de98ec90ece1b1be4a\",\"scheme\":\"dnet:person_result_relations\",\"class\":\"hasAuthor\",\"type\":\"person\"},\"provenanceaction\":\"sysimpor" +
|
1569
|
"t:crosswalk:repository\",\"trust\":0.9,\"inferenceprovenance\":\"\",\"ranking\":1,\"inferred\":true,\"fullname\":\"Krafft, Alexander\"}},\"subject\":[{\"content\":\"Clinic for Obstetrics\",\"schemename\":\"dnet:result_subject\",\"c" +
|
1570
|
"lassname\":\"keyword\",\"schemeid\":\"dnet:result_subject\",\"classid\":\"keyword\"},{\"content\":\"610 Medicine & health\",\"schemename\":\"dnet:result_subject\",\"classname\":\"keyword\",\"schemeid\":\"dnet:result_subject\",\"class" +
|
1571
|
"id\":\"keyword\"},{\"content\":\"News\",\"schemename\":\"dnet:result_subject\",\"classname\":\"keyword\",\"schemeid\":\"dnet:result_subject\",\"classid\":\"keyword\"}],\"collectedfrom\":[{\"id\":\"opendoar____::0efe32849d230d7f53049d" +
|
1572
|
"dc4a4b0c60\",\"name\":\"Zurich Open Repository and Archive\"},{\"id\":\"opendoar____::8b6dd7db9af49e67306feb59a8bdc52c\",\"name\":\"Europe PubMed Central\"}],\"children\":{\"result\":[{\"title\":{\"content\":\"Iron supplementat" +
|
1573
|
"ion in pregnancy\",\"schemename\":\"dnet:dataCite_title\",\"classname\":\"main title\",\"schemeid\":\"dnet:dataCite_title\",\"classid\":\"main title\"},\"resulttype\":{\"schemename\":\"dnet:result_typologies\",\"classname\":\"publi" +
|
1574
|
"cation\",\"schemeid\":\"dnet:result_typologies\",\"classid\":\"publication\"},\"dateofacceptance\":\"1981-09-01\",\"objidentifier\":\"od_______908::f27f9e68f0b9f510ebf572ba295344e1\"},{\"title\":{\"content\":\"Iron supplementat" +
|
1575
|
"ion in pregnancy\",\"schemename\":\"dnet:dataCite_title\",\"classname\":\"main title\",\"schemeid\":\"dnet:dataCite_title\",\"classid\":\"main title\"},\"resulttype\":{\"schemename\":\"dnet:result_typologies\",\"classname\":\"publi" +
|
1576
|
"cation\",\"schemeid\":\"dnet:result_typologies\",\"classid\":\"publication\"},\"dateofacceptance\":\"2013-01-01\",\"publisher\":\"BMJ Publishing Group\",\"objidentifier\":\"od_______885::0f5604702b32f59d9789573113279e69\"}],\"i" +
|
1577
|
"nstance\":[{\"webresource\":{\"url\":\"http://europepmc.org/articles/PMC2306130\"},\"id\":\"opendoar____::8b6dd7db9af49e67306feb59a8bdc52c\",\"licence\":{\"schemename\":\"dnet:access_modes\",\"classname\":\"Open Access\",\"sche" +
|
1578
|
"meid\":\"dnet:access_modes\",\"classid\":\"OPEN\"},\"hostedby\":{\"id\":\"opendoar____::8b6dd7db9af49e67306feb59a8bdc52c\",\"name\":\"Europe PubMed Central\"},\"instancetype\":{\"schemename\":\"dnet:publication_resource\",\"class" +
|
1579
|
"name\":\"Article\",\"schemeid\":\"dnet:publication_resource\",\"classid\":\"0001\"}},{\"webresource\":{\"url\":\"http://www.zora.uzh.ch/87059/1/30_13_Krafft_2013bmj_f4399_full.pdf\"},\"id\":\"opendoar____::0efe32849d230d7f530" +
|
1580
|
"49ddc4a4b0c60\",\"licence\":{\"schemename\":\"dnet:access_modes\",\"classname\":\"Open Access\",\"schemeid\":\"dnet:access_modes\",\"classid\":\"OPEN\"},\"hostedby\":{\"id\":\"opendoar____::0efe32849d230d7f53049ddc4a4b0c60\",\"name" +
|
1581
|
"\":\"Zurich Open Repository and Archive\"},\"instancetype\":{\"schemename\":\"dnet:publication_resource\",\"classname\":\"Article\",\"schemeid\":\"dnet:publication_resource\",\"classid\":\"0001\"}}]},\"pid\":[{\"content\":\"10.5167" +
|
1582
|
"/uzh-87059\",\"schemename\":\"dnet:pid_types\",\"classname\":\"doi\",\"schemeid\":\"dnet:pid_types\",\"classid\":\"doi\"},{\"content\":\"PMC2306130\",\"schemename\":\"dnet:pid_types\",\"classname\":\"pmc\",\"schemeid\":\"dnet:pid_types\"," +
|
1583
|
"\"classid\":\"pmc\"},{\"content\":\"10.1136/bmj.f4399\",\"schemename\":\"dnet:pid_types\",\"classname\":\"doi\",\"schemeid\":\"dnet:pid_types\",\"classid\":\"doi\"}],\"resourcetype\":{\"schemename\":\"\",\"classname\":\"\",\"schemeid\":\"\",\"c" +
|
1584
|
"lassid\":\"\"},\"format\":\"\",\"dateofacceptance\":\"2013-01-01\",\"embargoenddate\":\"\",\"version\":\"\",\"size\":\"\",\"publisher\":\"BMJ Publishing Group\",\"country\":{\"schemename\":\"\",\"classname\":\"\",\"schemeid\":\"\",\"classid\":\"\"},\"" +
|
1585
|
"metadataversionnumber\":\"\",\"title\":{\"content\":\"Iron supplementation in pregnancy\",\"schemename\":\"dnet:dataCite_title\",\"classname\":\"main title\",\"schemeid\":\"dnet:dataCite_title\",\"classid\":\"main title\"},\"result" +
|
1586
|
"type\":{\"schemename\":\"dnet:result_typologies\",\"classname\":\"publication\",\"schemeid\":\"dnet:result_typologies\",\"classid\":\"publication\"},\"source\":\"Krafft, Alexander (2013). Iron supplementation in pregnancy. Br" +
|
1587
|
"itish Medical Journal, 347:f4399.\",\"contributor\":\"\",\"description\":\"\",\"originalId\":[\"oai:europepmc.org:1052305\",\"oai:www.zora.uzh.ch:87059\"],\"lastmetadataupdate\":\"\",\"relevantdate\":{\"schemename\":\"\",\"classnam" +
|
1588
|
"e\":\"\",\"schemeid\":\"\",\"classid\":\"\"},\"device\":\"\",\"bestlicense\":{\"schemename\":\"dnet:access_modes\",\"classname\":\"Open Access\",\"schemeid\":\"dnet:access_modes\",\"classid\":\"OPEN\"},\"language\":{\"schemename\":\"dnet:langu" +
|
1589
|
"ages\",\"classname\":\"English\",\"schemeid\":\"dnet:languages\",\"classid\":\"eng\"},\"storagedate\":\"\",\"fulltext\":\"\"},\"xsi:schemaLocation\":\"http://namespace.openaire.eu/oaf https://www.openaire.eu/schema/0.2/oaf-0.2.xs" +
|
1590
|
"d\"}},\"xmlns:dri\":\"http://www.driver-repository.eu/namespace/dri\"}}";
|
1591
|
|
1592
|
String s = "{\"result\":{\"xmlns:oaf\":\"http://namespace.openaire.eu/oaf\",\"xmlns:xsi\":\"http://www.w3.org/2001" +
|
1593
|
"/XMLSchema-instance\",\"header\":{\"dri:dateOfCollection\":\"2014-04-10T13:35:33Z\",\"dri:dateOfTransformation\":\"\",\"counters\":{\"counter_dedup\":{\"value\":2},\"counter_authorship\":{\"value\":1},\"counter_authorship_infer" +
|
1594
|
"red\":{\"value\":1}},\"dri:objIdentifier\":\"dedup_wf_001::4d934888dee33a62dece6fa36192c710\"},\"metadata\":{\"oaf:entity\":{\"oaf:result\":{\"datainfo\":{\"provenanceaction\":{\"schemename\":\"dnet:provenanceActions\",\"classn" +
|
1595
|
"ame\":\"sysimport:dedup\",\"schemeid\":\"dnet:provenanceActions\",\"classid\":\"sysimport:dedup\"},\"trust\":0.9,\"inferenceprovenance\":\"dedup-similarity-result\",\"deletedbyinference\":false,\"inferred\":true},\"rels\":{\"rel\"" +
|
1596
|
":{\"to\":{\"content\":\"od______1232::d4f9cea02c7762da24cd71ea0b9791de\",\"scheme\":\"dnet:person_result_relations\",\"class\":\"hasAuthor\",\"type\":\"person\"},\"provenanceaction\":\"sysimport:crosswalk:repository\",\"trust\":0" +
|
1597
|
".9,\"inferenceprovenance\":\"\",\"ranking\":1,\"inferred\":true,\"fullname\":\"Anonymous\"}},\"subject\":{\"content\":\"Señoríos-Legislación\",\"schemename\":\"dnet:result_subject\",\"classname\":\"keyword\",\"schemeid\":\"dnet:result" +
|
1598
|
"_subject\",\"classid\":\"keyword\"},\"collectedfrom\":[{\"id\":\"opendoar____::e53a0a2978c28872a4505bdb51db06dc\",\"name\":\"Biblioteca Virtual del Patrimonio Bibliográfico (Virtual Library of Bibliographical Heritage)\"" +
|
1599
|
"},{\"id\":\"opendoar____::7aee26c309def8c5a2a076eb250b8f36\",\"name\":\"Biblioteca Virtual de Aragón\"}],\"children\":{\"result\":[{\"title\":{\"content\":\"Discurso sobre los señoríos : necesidad y justicia del decreto de" +
|
1600
|
" Cortes de 6 de Agosto de 1811 y ventaja que debe causar a la Nación\",\"schemename\":\"dnet:dataCite_title\",\"classname\":\"main title\",\"schemeid\":\"dnet:dataCite_title\",\"classid\":\"main title\"},\"resulttype\":{\"sch" +
|
1601
|
"emename\":\"dnet:result_typologies\",\"classname\":\"publication\",\"schemeid\":\"dnet:result_typologies\",\"classid\":\"publication\"},\"dateofacceptance\":\"1820-01-01\",\"objidentifier\":\"od______2719::bc2326a31763719dc5ebd" +
|
1602
|
"38f16a25404\"},{\"title\":{\"content\":\"Discurso sobre los señoríos : necesidad y justicia del decreto de Cortes de 6 de Agosto de 1811 y ventaja que debe causar a la Nación\",\"schemename\":\"dnet:dataCite_title\"," +
|
1603
|
"\"classname\":\"main title\",\"schemeid\":\"dnet:dataCite_title\",\"classid\":\"main title\"},\"resulttype\":{\"schemename\":\"dnet:result_typologies\",\"classname\":\"publication\",\"schemeid\":\"dnet:result_typologies\",\"classid\"" +
|
1604
|
":\"publication\"},\"dateofacceptance\":\"1820-01-01\",\"objidentifier\":\"od______1232::4d934888dee33a62dece6fa36192c710\"}],\"instance\":[{\"webresource\":[{\"url\":\"http://bvpb.mcu.es/es/consulta/registro.cmd?id=403864\"" +
|
1605
|
"},{\"url\":\"http://bvpb.mcu.es/es/catalogo_imagenes/grupo.cmd?path=2755\"}],\"id\":\"opendoar____::e53a0a2978c28872a4505bdb51db06dc\",\"licence\":{\"schemename\":\"dnet:access_modes\",\"classname\":\"Open Access\",\"schemei" +
|
1606
|
"d\":\"dnet:access_modes\",\"classid\":\"OPEN\"},\"hostedby\":{\"id\":\"opendoar____::e53a0a2978c28872a4505bdb51db06dc\",\"name\":\"Biblioteca Virtual del Patrimonio Bibliográfico (Virtual Library of Bibliographical Herita" +
|
1607
|
"ge)\"},\"instancetype\":{\"schemename\":\"dnet:publication_resource\",\"classname\":\"Book\",\"schemeid\":\"dnet:publication_resource\",\"classid\":\"0002\"}},{\"webresource\":{\"url\":\"http://bibliotecavirtual.aragon.es/bva/i18" +
|
1608
|
"n/consulta/registro.cmd?id=2878\"},\"id\":\"opendoar____::7aee26c309def8c5a2a076eb250b8f36\",\"licence\":{\"schemename\":\"dnet:access_modes\",\"classname\":\"Open Access\",\"schemeid\":\"dnet:access_modes\",\"classid\":\"OPEN\"" +
|
1609
|
"},\"hostedby\":{\"id\":\"opendoar____::7aee26c309def8c5a2a076eb250b8f36\",\"name\":\"Biblioteca Virtual de Aragón\"},\"instancetype\":{\"schemename\":\"dnet:publication_resource\",\"classname\":\"Book\",\"schemeid\":\"dnet:publi" +
|
1610
|
"cation_resource\",\"classid\":\"0002\"}}]},\"pid\":{\"schemename\":\"\",\"classname\":\"\",\"schemeid\":\"\",\"classid\":\"\"},\"resourcetype\":{\"schemename\":\"\",\"classname\":\"\",\"schemeid\":\"\",\"classid\":\"\"},\"format\":\"\",\"dateofaccepta" +
|
1611
|
"nce\":\"1820-01-01\",\"embargoenddate\":\"\",\"version\":\"\",\"size\":\"\",\"country\":{\"schemename\":\"\",\"classname\":\"\",\"schemeid\":\"\",\"classid\":\"\"},\"publisher\":\"\",\"metadataversionnumber\":\"\",\"title\":{\"content\":\"Discurso sob" +
|
1612
|
"re los señoríos : necesidad y justicia del decreto de Cortes de 6 de Agosto de 1811 y ventaja que debe causar a la Nación\",\"schemename\":\"dnet:dataCite_title\",\"classname\":\"main title\",\"schemeid\":\"dnet:dataC" +
|
1613
|
"ite_title\",\"classid\":\"main title\"},\"resulttype\":{\"schemename\":\"dnet:result_typologies\",\"classname\":\"publication\",\"schemeid\":\"dnet:result_typologies\",\"classid\":\"publication\"},\"source\":\"\",\"contributor\":\"Impr" +
|
1614
|
"enta de Heras, imp.\",\"description\":\"\",\"originalId\":[\"oai:bvpb.mcu.es:403864\",\"oai:bibliotecavirtual.aragon.es:2878\"],\"lastmetadataupdate\":\"\",\"relevantdate\":{\"schemename\":\"\",\"classname\":\"\",\"schemeid\":\"\",\"cl" +
|
1615
|
"assid\":\"\"},\"device\":\"\",\"bestlicense\":{\"schemename\":\"dnet:access_modes\",\"classname\":\"Open Access\",\"schemeid\":\"dnet:access_modes\",\"classid\":\"OPEN\"},\"language\":{\"schemename\":\"dnet:languages\",\"classname\":\"Span" +
|
1616
|
"ish\",\"schemeid\":\"dnet:languages\",\"classid\":\"esl/spa\"},\"storagedate\":\"\",\"fulltext\":\"\"},\"xsi:schemaLocation\":\"http://namespace.openaire.eu/oaf https://www.openaire.eu/schema/0.2/oaf-0.2.xsd\"}},\"xmlns:dri\":\"h" +
|
1617
|
"ttp://www.driver-repository.eu/namespace/dri\"}}\n";
|
1618
|
|
1619
|
JSONObject finalOject = new JSONObject();
|
1620
|
finalOject.put("dri:objIdentifier", new JSONObject(json).getJSONObject("result").getJSONObject("header").getString("dri:objIdentifier"));
|
1621
|
finalOject.put("content", new JSONObject(new JSONObject(json).getJSONObject("result").getJSONObject("metadata").getJSONObject("oaf:entity").getJSONObject("oaf:result"),
|
1622
|
new String[]{"title", "description", "language", "bestlicense", "pid", "rels"}));
|
1623
|
|
1624
|
System.out.println(finalOject);
|
1625
|
|
1626
|
JSONObject jsonObject = new JSONObject(s).getJSONObject("result").getJSONObject("metadata").getJSONObject("oaf:entity").getJSONObject("oaf:result");
|
1627
|
System.out.println("title --> " + jsonObject.getJSONObject("title").getString("content"));
|
1628
|
System.out.println("pid --> " + jsonObject.getJSONArray("pid"));
|
1629
|
|
1630
|
JSONObject newJsonObject1 = new JSONObject(jsonObject, new String[]{"title", "description", "language", "bestlicense", "pid", "rels"});
|
1631
|
|
1632
|
}
|
1633
|
*/
|
1634
|
/*
|
1635
|
|
1636
|
public static void main(String[] args) throws IOException, CQLParseException {
|
1637
|
CqlTranslator translator = new CqlTranslatorImpl();
|
1638
|
System.out.println(translator.toLucene("relfundinglevel0_id = ec__________::EC::FP7"));
|
1639
|
}
|
1640
|
*/
|
1641
|
|
1642
|
}
|