1
|
package eu.dnetlib.data.search.web.api;
|
2
|
|
3
|
import eu.dnetlib.api.data.SearchServiceException;
|
4
|
import eu.dnetlib.data.search.app.SearchServiceImpl;
|
5
|
import eu.dnetlib.data.search.transform.Transformer;
|
6
|
import eu.dnetlib.data.search.transform.config.SearchRegistry;
|
7
|
import eu.dnetlib.data.search.utils.cql.CQLQueryBuilder;
|
8
|
import eu.dnetlib.data.search.web.utils.RequestResponseHandler;
|
9
|
import eu.dnetlib.domain.data.SearchResult;
|
10
|
import org.apache.log4j.Logger;
|
11
|
import org.springframework.beans.factory.annotation.Autowired;
|
12
|
import org.springframework.stereotype.Component;
|
13
|
|
14
|
import javax.servlet.http.HttpServletRequest;
|
15
|
import javax.servlet.http.HttpServletResponse;
|
16
|
import javax.ws.rs.*;
|
17
|
import javax.ws.rs.core.Context;
|
18
|
import javax.ws.rs.core.MediaType;
|
19
|
import javax.ws.rs.core.Response;
|
20
|
import javax.ws.rs.core.StreamingOutput;
|
21
|
import java.io.IOException;
|
22
|
import java.io.OutputStream;
|
23
|
import java.util.List;
|
24
|
import java.util.Locale;
|
25
|
|
26
|
/**
|
27
|
* Created by kiatrop on 2/6/2016.
|
28
|
*/
|
29
|
|
30
|
@Component
|
31
|
@Path("/v2")
|
32
|
public class SearchApiService {
|
33
|
|
34
|
private static final Logger logger = Logger.getLogger(SearchApiService.class);
|
35
|
|
36
|
@Autowired
|
37
|
private SearchServiceImpl searchService = null;
|
38
|
|
39
|
@Autowired
|
40
|
private SearchRegistry searchRegistry = null;
|
41
|
|
42
|
@GET
|
43
|
@Path("/api/resources")
|
44
|
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
|
45
|
public Response fetchResources(@QueryParam("query") String query,
|
46
|
@DefaultValue("0") @QueryParam("page") final int offset,
|
47
|
@DefaultValue("10") @QueryParam("size") final int limit,
|
48
|
@QueryParam("refine") @DefaultValue("false") final boolean refine,
|
49
|
@QueryParam("fields") final List<String> fields,
|
50
|
@QueryParam("fq") final List<String> fieldQueries,
|
51
|
@QueryParam("format") final String format,
|
52
|
@QueryParam("type") final String type,
|
53
|
@Context final HttpServletRequest request) {
|
54
|
|
55
|
return getResponseByEntity(query, extractEntity(type), offset, limit, format, request, refine, fields, fieldQueries);
|
56
|
}
|
57
|
|
58
|
@GET
|
59
|
@Path("/api/publications")
|
60
|
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
|
61
|
public Response fetchPublications(@QueryParam("q") final String keywords,
|
62
|
@QueryParam("doi") final String doi,
|
63
|
@QueryParam("sortBy") final String sortBy,
|
64
|
@DefaultValue("0") @QueryParam("page") final int offset,
|
65
|
@DefaultValue("10") @QueryParam("size") final int limit,
|
66
|
@QueryParam("refine") @DefaultValue("false") final boolean refine,
|
67
|
@QueryParam("fields") final List<String> fields,
|
68
|
@QueryParam("fq") final List<String> fieldQueries,
|
69
|
@QueryParam("format") final String format,
|
70
|
@Context final HttpServletRequest request) {
|
71
|
|
72
|
logger.debug("Publications request received");
|
73
|
//TODO do not allow q and keywords both - SWITCH back if needed
|
74
|
//String simpleQuery = buildSimpleSearchQuery(RequestResponseHandler.Entity.PUBLICATION, keywords) ;
|
75
|
String simpleQuery = buildSearchRequest(RequestResponseHandler.Entity.PUBLICATION, keywords, doi,sortBy, fieldQueries);
|
76
|
return getResponseByEntity(simpleQuery, RequestResponseHandler.Entity.PUBLICATION, offset, limit, format, request, refine, fields, fieldQueries);
|
77
|
|
78
|
}
|
79
|
|
80
|
|
81
|
@GET
|
82
|
@Path("/api/publications/count")
|
83
|
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
|
84
|
public Response fetchPublicationsCount(@QueryParam("q") String query,
|
85
|
@QueryParam("format") final String format,
|
86
|
@QueryParam("fq") final List<String> fieldQueries,
|
87
|
@Context final HttpServletRequest request) {
|
88
|
String fullQuery = buildSearchRequest(RequestResponseHandler.Entity.PUBLICATION, query, fieldQueries);
|
89
|
return getCount(request, fullQuery, format, fieldQueries);
|
90
|
}
|
91
|
|
92
|
|
93
|
@GET
|
94
|
@Path("/api/publications/{publicationid}")
|
95
|
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
|
96
|
public Response fetchPublicationsById(@PathParam("publicationid") String publicationid,
|
97
|
@QueryParam("format") final String format,
|
98
|
@QueryParam("fq") final List<String> fieldQueries,
|
99
|
@Context final HttpServletRequest request) {
|
100
|
return getResponseByEntityId(request, RequestResponseHandler.Entity.PUBLICATION, publicationid, format, fieldQueries);
|
101
|
}
|
102
|
|
103
|
|
104
|
@GET
|
105
|
@Path("/api/datasets")
|
106
|
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
|
107
|
public Response fetchDatasets(@QueryParam("q") String keywords,
|
108
|
@QueryParam("doi") final String doi,
|
109
|
@QueryParam("sortBy") final String sortBy,
|
110
|
@DefaultValue("0") @QueryParam("page") int offset,
|
111
|
@DefaultValue("10") @QueryParam("size") int limit,
|
112
|
@QueryParam("refine") @DefaultValue("false") boolean refine,
|
113
|
@QueryParam("fields") final List<String> fields,
|
114
|
@QueryParam("fq") final List<String> fieldQueries,
|
115
|
@QueryParam("format") final String format,
|
116
|
@Context HttpServletRequest request) {
|
117
|
|
118
|
String simpleQuery = buildSearchRequest(RequestResponseHandler.Entity.DATASET, keywords, doi, sortBy, fieldQueries);
|
119
|
return getResponseByEntity(simpleQuery, RequestResponseHandler.Entity.DATASET, offset, limit, format, request, refine, fields, fieldQueries);
|
120
|
}
|
121
|
|
122
|
@GET
|
123
|
@Path("/api/datasets/count")
|
124
|
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
|
125
|
public Response fetchDatesetsCount(@QueryParam("q") String query,
|
126
|
@QueryParam("format") final String format,
|
127
|
@QueryParam("fq") final List<String> fieldQueries,
|
128
|
@Context final HttpServletRequest request) {
|
129
|
String fullQuery = buildSearchRequest(RequestResponseHandler.Entity.DATASET, query, fieldQueries);
|
130
|
return getCount(request, fullQuery, format, fieldQueries);
|
131
|
}
|
132
|
|
133
|
|
134
|
@GET
|
135
|
@Path("/api/datasets/{datasetid}")
|
136
|
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
|
137
|
public Response fetchDatasets(@PathParam("datasetid") String datasetid,
|
138
|
@QueryParam("format") final String format,
|
139
|
@QueryParam("fq") final List<String> fieldQueries,
|
140
|
@Context final HttpServletRequest request) {
|
141
|
return getResponseByEntityId(request, RequestResponseHandler.Entity.DATASET, datasetid, format, fieldQueries);
|
142
|
}
|
143
|
|
144
|
@GET
|
145
|
@Path("/api/software")
|
146
|
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
|
147
|
public Response fetchSoftware(@QueryParam("q") String keywords,
|
148
|
@QueryParam("doi") final String doi,
|
149
|
@QueryParam("sortBy") final String sortBy,
|
150
|
@DefaultValue("0") @QueryParam("page") int offset,
|
151
|
@DefaultValue("10") @QueryParam("size") int limit,
|
152
|
@QueryParam("refine") @DefaultValue("false") boolean refine,
|
153
|
@QueryParam("fields") final List<String> fields,
|
154
|
@QueryParam("fq") final List<String> fieldQueries,
|
155
|
@QueryParam("format") final String format,
|
156
|
@Context HttpServletRequest request) {
|
157
|
|
158
|
String simpleQuery = buildSearchRequest(RequestResponseHandler.Entity.SOFTWARE, keywords, doi, sortBy, fieldQueries);
|
159
|
return getResponseByEntity(simpleQuery, RequestResponseHandler.Entity.SOFTWARE, offset, limit, format, request, refine, fields, fieldQueries);
|
160
|
}
|
161
|
|
162
|
@GET
|
163
|
@Path("/api/software/count")
|
164
|
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
|
165
|
public Response fetchSoftwareCount(@QueryParam("q") String query,
|
166
|
@QueryParam("format") final String format,
|
167
|
@QueryParam("fq") final List<String> fieldQueries,
|
168
|
@Context final HttpServletRequest request) {
|
169
|
String fullQuery = buildSearchRequest(RequestResponseHandler.Entity.SOFTWARE, query, fieldQueries);
|
170
|
return getCount(request, fullQuery, format, fieldQueries);
|
171
|
}
|
172
|
|
173
|
@GET
|
174
|
@Path("/api/software/{softwareid}")
|
175
|
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
|
176
|
public Response fetchSoftware(@PathParam("softwareid") String datasetid,
|
177
|
@QueryParam("format") final String format,
|
178
|
@QueryParam("fq") final List<String> fieldQueries,
|
179
|
@Context final HttpServletRequest request) {
|
180
|
return getResponseByEntityId(request, RequestResponseHandler.Entity.SOFTWARE, datasetid, format, fieldQueries);
|
181
|
}
|
182
|
|
183
|
@GET
|
184
|
@Path("/api/other")
|
185
|
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
|
186
|
public Response fetchOther(@QueryParam("q") String keywords,
|
187
|
@QueryParam("doi") final String doi,
|
188
|
@QueryParam("sortBy") final String sortBy,
|
189
|
@DefaultValue("0") @QueryParam("page") int offset,
|
190
|
@DefaultValue("10") @QueryParam("size") int limit,
|
191
|
@QueryParam("refine") @DefaultValue("false") boolean refine,
|
192
|
@QueryParam("fields") final List<String> fields,
|
193
|
@QueryParam("fq") final List<String> fieldQueries,
|
194
|
@QueryParam("format") final String format,
|
195
|
@Context HttpServletRequest request) {
|
196
|
|
197
|
String simpleQuery = buildSearchRequest(RequestResponseHandler.Entity.OTHER, keywords, doi, sortBy, fieldQueries);
|
198
|
return getResponseByEntity(simpleQuery, RequestResponseHandler.Entity.OTHER, offset, limit, format, request, refine, fields, fieldQueries);
|
199
|
}
|
200
|
|
201
|
@GET
|
202
|
@Path("/api/other/count")
|
203
|
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
|
204
|
public Response fetchOtherCount(@QueryParam("q") String query,
|
205
|
@QueryParam("format") final String format,
|
206
|
@QueryParam("fq") final List<String> fieldQueries,
|
207
|
@Context final HttpServletRequest request) {
|
208
|
String fullQuery = buildSearchRequest(RequestResponseHandler.Entity.OTHER, query, fieldQueries);
|
209
|
return getCount(request, fullQuery, format, fieldQueries);
|
210
|
}
|
211
|
|
212
|
@GET
|
213
|
@Path("/api/other/{otherid}")
|
214
|
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
|
215
|
public Response fetchOther(@PathParam("otherid") String datasetid,
|
216
|
@QueryParam("format") final String format,
|
217
|
@QueryParam("fq") final List<String> fieldQueries,
|
218
|
@Context final HttpServletRequest request) {
|
219
|
return getResponseByEntityId(request, RequestResponseHandler.Entity.OTHER, datasetid, format, fieldQueries);
|
220
|
}
|
221
|
@GET
|
222
|
@Path("/api/projects")
|
223
|
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
|
224
|
public Response fetchProjects(@QueryParam("q") String keywords,
|
225
|
@DefaultValue("0") @QueryParam("page") int offset,
|
226
|
@DefaultValue("10") @QueryParam("size") int limit,
|
227
|
@QueryParam("refine") @DefaultValue("false") boolean refine,
|
228
|
@QueryParam("fields") final List<String> fields,
|
229
|
@QueryParam("fq") final List<String> fieldQueries,
|
230
|
@QueryParam("format") final String format,
|
231
|
@Context HttpServletRequest request) {
|
232
|
|
233
|
String simpleQuery = buildSearchRequest(RequestResponseHandler.Entity.PROJECT, keywords, fieldQueries);
|
234
|
return getResponseByEntity(simpleQuery, RequestResponseHandler.Entity.PROJECT, offset, limit, format, request, refine, fields, fieldQueries);
|
235
|
}
|
236
|
|
237
|
|
238
|
@GET
|
239
|
@Path("/api/projects/count")
|
240
|
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
|
241
|
public Response fetchProjectsCount(@QueryParam("q") String query,
|
242
|
@QueryParam("format") final String format,
|
243
|
@QueryParam("fq") final List<String> fieldQueries,
|
244
|
@Context final HttpServletRequest request) {
|
245
|
String fullQuery = buildSearchRequest(RequestResponseHandler.Entity.PROJECT, query, fieldQueries);
|
246
|
return getCount(request, fullQuery, format, fieldQueries);
|
247
|
}
|
248
|
|
249
|
@GET
|
250
|
@Path("/api/projects/{projectid}")
|
251
|
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
|
252
|
public Response fetchProjects(@PathParam("projectid") String projectid,
|
253
|
@QueryParam("format") final String format,
|
254
|
@QueryParam("fq") final List<String> fieldQueries,
|
255
|
@Context final HttpServletRequest request) {
|
256
|
return getResponseByEntityId(request, RequestResponseHandler.Entity.PROJECT, projectid, format, fieldQueries);
|
257
|
}
|
258
|
|
259
|
@GET
|
260
|
@Path("/api/projects/{projectId}/publications")
|
261
|
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
|
262
|
public Response fetchProjectPublications(@PathParam("projectId") String projectId,
|
263
|
@DefaultValue("0") @QueryParam("page") int offset,
|
264
|
@DefaultValue("10") @QueryParam("size") int limit,
|
265
|
@QueryParam("format") final String format,
|
266
|
@QueryParam("fq") final List<String> fieldQueries,
|
267
|
@Context HttpServletRequest request) {
|
268
|
|
269
|
String fullQuery = builtEntity2EntityRelationQuery(RequestResponseHandler.Entity.PUBLICATION, "relprojectid", projectId, fieldQueries);
|
270
|
return getResponseByEntity(fullQuery, RequestResponseHandler.Entity.PUBLICATION, offset, limit, format, request, false, null, fieldQueries);
|
271
|
}
|
272
|
|
273
|
@GET
|
274
|
@Path("/api/projects/{projectId}/publications/count")
|
275
|
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
|
276
|
public Response fetchProjectPublicationsCount(@PathParam("projectId") String projectId,
|
277
|
@QueryParam("format") final String format,
|
278
|
@QueryParam("fq") final List<String> fieldQueries,
|
279
|
@Context final HttpServletRequest request) {
|
280
|
String fullQuery = builtEntity2EntityRelationQuery(RequestResponseHandler.Entity.PUBLICATION, "relprojectid", projectId, fieldQueries);
|
281
|
return getCount(request, fullQuery, format, fieldQueries);
|
282
|
}
|
283
|
|
284
|
@GET
|
285
|
@Path("/api/projects/{projectId}/datasets")
|
286
|
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
|
287
|
public Response fetchProjectDatasets(@PathParam("projectId") String projectId,
|
288
|
@DefaultValue("0") @QueryParam("page") int offset,
|
289
|
@DefaultValue("10") @QueryParam("size") int limit,
|
290
|
@QueryParam("format") final String format,
|
291
|
@QueryParam("fq") final List<String> fieldQueries,
|
292
|
@Context HttpServletRequest request) {
|
293
|
|
294
|
String fullQuery = builtEntity2EntityRelationQuery(RequestResponseHandler.Entity.DATASET, "relprojectid", projectId, fieldQueries);
|
295
|
return getResponseByEntity(fullQuery, RequestResponseHandler.Entity.DATASET, offset, limit, format, request, false, null, fieldQueries);
|
296
|
}
|
297
|
|
298
|
|
299
|
@GET
|
300
|
@Path("/api/projects/{projectId}/datasets/count")
|
301
|
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
|
302
|
public Response fetchProjectDatasetsCount(@PathParam("projectId") String projectId,
|
303
|
@DefaultValue("0") @QueryParam("page") int offset,
|
304
|
@DefaultValue("10") @QueryParam("size") int limit,
|
305
|
@QueryParam("format") final String format,
|
306
|
@QueryParam("fq") final List<String> fieldQueries,
|
307
|
@Context HttpServletRequest request) {
|
308
|
String fullQuery = builtEntity2EntityRelationQuery(RequestResponseHandler.Entity.DATASET, "relprojectid", projectId, fieldQueries);
|
309
|
return getCount(request, fullQuery, format, fieldQueries);
|
310
|
}
|
311
|
|
312
|
|
313
|
|
314
|
@GET
|
315
|
@Path("/api/projects/{projectId}/software/count")
|
316
|
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
|
317
|
public Response fetchProjectSoftwareCount(@PathParam("projectId") String projectId,
|
318
|
@DefaultValue("0") @QueryParam("page") int offset,
|
319
|
@DefaultValue("10") @QueryParam("size") int limit,
|
320
|
@QueryParam("format") final String format,
|
321
|
@QueryParam("fq") final List<String> fieldQueries,
|
322
|
@Context HttpServletRequest request) {
|
323
|
String fullQuery = builtEntity2EntityRelationQuery(RequestResponseHandler.Entity.SOFTWARE, "relprojectid", projectId, fieldQueries);
|
324
|
return getCount(request, fullQuery, format, fieldQueries);
|
325
|
}
|
326
|
|
327
|
@GET
|
328
|
@Path("/api/projects/{projectId}/software")
|
329
|
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
|
330
|
public Response fetchProjectSoftware(@PathParam("projectId") String projectId,
|
331
|
@DefaultValue("0") @QueryParam("page") int offset,
|
332
|
@DefaultValue("10") @QueryParam("size") int limit,
|
333
|
@QueryParam("format") final String format,
|
334
|
@QueryParam("fq") final List<String> fieldQueries,
|
335
|
@Context HttpServletRequest request) {
|
336
|
|
337
|
String fullQuery = builtEntity2EntityRelationQuery(RequestResponseHandler.Entity.SOFTWARE, "relprojectid", projectId, fieldQueries);
|
338
|
return getResponseByEntity(fullQuery, RequestResponseHandler.Entity.SOFTWARE, offset, limit, format, request, false, null, fieldQueries);
|
339
|
}
|
340
|
|
341
|
@GET
|
342
|
@Path("/api/projects/{projectId}/other/count")
|
343
|
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
|
344
|
public Response fetchProjectOtherCount(@PathParam("projectId") String projectId,
|
345
|
@DefaultValue("0") @QueryParam("page") int offset,
|
346
|
@DefaultValue("10") @QueryParam("size") int limit,
|
347
|
@QueryParam("format") final String format,
|
348
|
@QueryParam("fq") final List<String> fieldQueries,
|
349
|
@Context HttpServletRequest request) {
|
350
|
String fullQuery = builtEntity2EntityRelationQuery(RequestResponseHandler.Entity.OTHER, "relprojectid", projectId, fieldQueries);
|
351
|
return getCount(request, fullQuery, format, fieldQueries);
|
352
|
}
|
353
|
|
354
|
@GET
|
355
|
@Path("/api/projects/{projectId}/other")
|
356
|
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
|
357
|
public Response fetchProjectOther(@PathParam("projectId") String projectId,
|
358
|
@DefaultValue("0") @QueryParam("page") int offset,
|
359
|
@DefaultValue("10") @QueryParam("size") int limit,
|
360
|
@QueryParam("format") final String format,
|
361
|
@QueryParam("fq") final List<String> fieldQueries,
|
362
|
@Context HttpServletRequest request) {
|
363
|
|
364
|
String fullQuery = builtEntity2EntityRelationQuery(RequestResponseHandler.Entity.OTHER, "relprojectid", projectId, fieldQueries);
|
365
|
return getResponseByEntity(fullQuery, RequestResponseHandler.Entity.OTHER, offset, limit, format, request, false, null, fieldQueries);
|
366
|
}
|
367
|
|
368
|
@GET
|
369
|
@Path("/api/datasources")
|
370
|
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
|
371
|
public Response fetchDatasources(@QueryParam("q") String keywords,
|
372
|
@DefaultValue("0") @QueryParam("page") final int offset,
|
373
|
@DefaultValue("10") @QueryParam("size") final int limit,
|
374
|
@QueryParam("refine") @DefaultValue("false") final boolean refine,
|
375
|
@QueryParam("fields") final List<String> fields,
|
376
|
@QueryParam("fq") final List<String> fieldQueries,
|
377
|
@QueryParam("format") final String format,
|
378
|
@Context final HttpServletRequest request) {
|
379
|
|
380
|
String simpleQuery = buildSearchRequest(RequestResponseHandler.Entity.DATASOURCE, keywords, fieldQueries);
|
381
|
return getResponseByEntity(simpleQuery, RequestResponseHandler.Entity.DATASOURCE, offset, limit, format, request, refine, fields, fieldQueries);
|
382
|
}
|
383
|
|
384
|
@GET
|
385
|
@Path("/api/datasources/count")
|
386
|
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
|
387
|
public Response fetchDatasourcesCount(@QueryParam("q") String query,
|
388
|
@QueryParam("format") final String format,
|
389
|
@QueryParam("fq") final List<String> fieldQueries,
|
390
|
@Context final HttpServletRequest request) {
|
391
|
String fullQuery = buildSearchRequest(RequestResponseHandler.Entity.DATASOURCE, query, fieldQueries);
|
392
|
return getCount(request, fullQuery, format, fieldQueries);
|
393
|
}
|
394
|
|
395
|
@GET
|
396
|
@Path("/api/datasources/{datasourceid}")
|
397
|
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
|
398
|
public Response fetchDatasources(@PathParam("datasourceid") String datasourceid,
|
399
|
@QueryParam("format") final String format,
|
400
|
@QueryParam("fq") final List<String> fieldQueries,
|
401
|
@Context final HttpServletRequest request) {
|
402
|
return getResponseByEntityId(request, RequestResponseHandler.Entity.DATASOURCE, datasourceid, format, fieldQueries);
|
403
|
}
|
404
|
|
405
|
|
406
|
@GET
|
407
|
@Path("/api/organizations")
|
408
|
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
|
409
|
public Response fetchOrganisations(@QueryParam("q") String keywords,
|
410
|
@DefaultValue("0") @QueryParam("page") final int offset,
|
411
|
@DefaultValue("10") @QueryParam("size") final int limit,
|
412
|
@QueryParam("refine") @DefaultValue("false") final boolean refine,
|
413
|
@QueryParam("fields") final List<String> fields,
|
414
|
@QueryParam("fq") final List<String> fieldQueries,
|
415
|
@QueryParam("format") final String format,
|
416
|
@Context final HttpServletRequest request) {
|
417
|
|
418
|
String simpleQuery = buildSearchRequest(RequestResponseHandler.Entity.ORGANIZATION, keywords, fieldQueries);
|
419
|
return getResponseByEntity(simpleQuery, RequestResponseHandler.Entity.ORGANIZATION, offset, limit, format, request, refine, fields, fieldQueries);
|
420
|
}
|
421
|
|
422
|
|
423
|
@GET
|
424
|
@Path("/api/organizations/count")
|
425
|
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
|
426
|
public Response fetchOrganizationsCount(@QueryParam("q") String query,
|
427
|
@QueryParam("format") final String format,
|
428
|
@QueryParam("fq") final List<String> fieldQueries,
|
429
|
@Context final HttpServletRequest request) {
|
430
|
String fullQuery = buildSearchRequest(RequestResponseHandler.Entity.ORGANIZATION, query, fieldQueries);
|
431
|
return getCount(request, fullQuery, format, fieldQueries);
|
432
|
}
|
433
|
|
434
|
@GET
|
435
|
@Path("/api/organizations/{organizationid}")
|
436
|
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
|
437
|
public Response fetchOrganizations(@PathParam("organizationid") String organizationid,
|
438
|
@QueryParam("format") final String format,
|
439
|
@QueryParam("fq") final List<String> fieldQueries,
|
440
|
@Context final HttpServletRequest request) {
|
441
|
return getResponseByEntityId(request, RequestResponseHandler.Entity.ORGANIZATION, organizationid, format, fieldQueries);
|
442
|
}
|
443
|
|
444
|
|
445
|
@GET
|
446
|
@Path("/api/organizations/{organizationid}/datasources")
|
447
|
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
|
448
|
public Response fetchOrganizationDatasources(@PathParam("organizationid") String organizationid,
|
449
|
@DefaultValue("0") @QueryParam("page") int offset,
|
450
|
@DefaultValue("10") @QueryParam("size") int limit,
|
451
|
@QueryParam("format") final String format,
|
452
|
@QueryParam("fq") final List<String> fieldQueries,
|
453
|
@Context HttpServletRequest request) {
|
454
|
String fullQuery = builtEntity2EntityRelationQuery(RequestResponseHandler.Entity.DATASOURCE, "relorganizationid", organizationid, fieldQueries);
|
455
|
return getResponseByEntity(fullQuery, RequestResponseHandler.Entity.DATASOURCE, offset, limit, format, request, false, null, fieldQueries);
|
456
|
}
|
457
|
|
458
|
@GET
|
459
|
@Path("/api/organizations/{organizationid}/datasources/count")
|
460
|
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
|
461
|
public Response fetchOrganizationDatasources(@PathParam("organizationid") String organizationid,
|
462
|
@QueryParam("format") final String format,
|
463
|
@QueryParam("fq") final List<String> fieldQueries,
|
464
|
@Context final HttpServletRequest request) {
|
465
|
String fullQuery = builtEntity2EntityRelationQuery(RequestResponseHandler.Entity.DATASOURCE, "relorganizationid", organizationid, fieldQueries);
|
466
|
return getCount(request, fullQuery, format, fieldQueries);
|
467
|
}
|
468
|
|
469
|
|
470
|
@GET
|
471
|
@Path("/api/organizations/{organizationid}/publications")
|
472
|
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
|
473
|
public Response fetchOrganizationPublications(@PathParam("organizationid") String organizationid,
|
474
|
@DefaultValue("0") @QueryParam("page") int offset,
|
475
|
@DefaultValue("10") @QueryParam("size") int limit,
|
476
|
@QueryParam("format") final String format,
|
477
|
@QueryParam("fq") final List<String> fieldQueries,
|
478
|
@Context HttpServletRequest request) {
|
479
|
String fullQuery = builtEntity2EntityRelationQuery(RequestResponseHandler.Entity.PUBLICATION, "relorganizationid", organizationid, fieldQueries);
|
480
|
return getResponseByEntity(fullQuery, RequestResponseHandler.Entity.PUBLICATION, offset, limit, format, request, false, null, fieldQueries);
|
481
|
}
|
482
|
|
483
|
@GET
|
484
|
@Path("/api/organizations/{organizationid}/publications/count")
|
485
|
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
|
486
|
public Response fetchOrganizationPublicationsCount(@PathParam("organizationid") String organizationid,
|
487
|
@DefaultValue("0") @QueryParam("page") int offset,
|
488
|
@DefaultValue("10") @QueryParam("size") int limit,
|
489
|
@QueryParam("format") final String format,
|
490
|
@QueryParam("fq") final List<String> fieldQueries,
|
491
|
@Context HttpServletRequest request) {
|
492
|
String fullQuery = builtEntity2EntityRelationQuery(RequestResponseHandler.Entity.PUBLICATION, "relorganizationid", organizationid, fieldQueries);
|
493
|
return getCount(request, fullQuery, format, fieldQueries);
|
494
|
}
|
495
|
|
496
|
@GET
|
497
|
@Path("/api/organizations/{organizationid}/datasets")
|
498
|
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
|
499
|
public Response fetchOrganizationDatsets(@PathParam("organizationid") String organizationid,
|
500
|
@DefaultValue("0") @QueryParam("page") int offset,
|
501
|
@DefaultValue("10") @QueryParam("size") int limit,
|
502
|
@QueryParam("format") final String format,
|
503
|
@QueryParam("fq") final List<String> fieldQueries,
|
504
|
@Context HttpServletRequest request) {
|
505
|
String fullQuery = builtEntity2EntityRelationQuery(RequestResponseHandler.Entity.DATASET, "relorganizationid", organizationid, fieldQueries);
|
506
|
return getResponseByEntity(fullQuery, RequestResponseHandler.Entity.DATASET, offset, limit, format, request, false, null, fieldQueries);
|
507
|
}
|
508
|
|
509
|
@GET
|
510
|
@Path("/api/organizations/{organizationid}/datasets/count")
|
511
|
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
|
512
|
public Response fetchOrganizationDatsetsCount(@PathParam("organizationid") String organizationid,
|
513
|
@DefaultValue("0") @QueryParam("page") int offset,
|
514
|
@DefaultValue("10") @QueryParam("size") int limit,
|
515
|
@QueryParam("format") final String format,
|
516
|
@QueryParam("fq") final List<String> fieldQueries,
|
517
|
@Context HttpServletRequest request) {
|
518
|
String fullQuery = builtEntity2EntityRelationQuery(RequestResponseHandler.Entity.DATASET, "relorganizationid", organizationid, fieldQueries);
|
519
|
return getCount(request, fullQuery, format, fieldQueries);
|
520
|
}
|
521
|
|
522
|
@GET
|
523
|
@Path("/api/organizations/{organizationid}/projects")
|
524
|
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
|
525
|
public Response fetchOrganizationProjects(@PathParam("organizationid") String organizationid,
|
526
|
@DefaultValue("0") @QueryParam("page") int offset,
|
527
|
@DefaultValue("10") @QueryParam("size") int limit,
|
528
|
@QueryParam("format") final String format,
|
529
|
@QueryParam("fq") final List<String> fieldQueries,
|
530
|
@Context HttpServletRequest request) {
|
531
|
String fullQuery = builtEntity2EntityRelationQuery(RequestResponseHandler.Entity.PROJECT, "relorganizationid", organizationid, fieldQueries);
|
532
|
return getResponseByEntity(fullQuery, RequestResponseHandler.Entity.PROJECT, offset, limit, format, request, false, null, fieldQueries);
|
533
|
}
|
534
|
|
535
|
@GET
|
536
|
@Path("/api/organizations/{organizationid}/projects/count")
|
537
|
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
|
538
|
public Response fetchOrganizationProjectsCount(@PathParam("organizationid") String organizationid,
|
539
|
@QueryParam("format") final String format,
|
540
|
@QueryParam("fq") final List<String> fieldQueries,
|
541
|
@Context final HttpServletRequest request) {
|
542
|
String fullQuery = builtEntity2EntityRelationQuery(RequestResponseHandler.Entity.PROJECT, "relorganizationid", organizationid, fieldQueries);
|
543
|
return getCount(request, fullQuery,format, fieldQueries);
|
544
|
}
|
545
|
|
546
|
|
547
|
|
548
|
@GET
|
549
|
@Path("/api/people")
|
550
|
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
|
551
|
public Response fetchPeople(@QueryParam("q") String keywords,
|
552
|
@DefaultValue("0") @QueryParam("page") final int offset,
|
553
|
@DefaultValue("10") @QueryParam("size") final int limit,
|
554
|
@QueryParam("refine") @DefaultValue("false") final boolean refine,
|
555
|
@QueryParam("fields") final List<String> fields,
|
556
|
@QueryParam("fq") final List<String> fieldQueries,
|
557
|
@QueryParam("format") final String format,
|
558
|
@Context final HttpServletRequest request) {
|
559
|
|
560
|
String simpleQuery = buildSearchRequest(RequestResponseHandler.Entity.PERSON, keywords, fieldQueries);
|
561
|
return getResponseByEntity(simpleQuery, RequestResponseHandler.Entity.PERSON, offset, limit, format, request, refine, fields, fieldQueries);
|
562
|
}
|
563
|
|
564
|
|
565
|
@GET
|
566
|
@Path("/api/people/count")
|
567
|
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
|
568
|
public Response fetchPeopleCount(@QueryParam("q") String query,
|
569
|
@QueryParam("format") final String format,
|
570
|
@QueryParam("fq") final List<String> fieldQueries,
|
571
|
@Context final HttpServletRequest request) {
|
572
|
String fullQuery = buildSearchRequest(RequestResponseHandler.Entity.PERSON, query, fieldQueries);
|
573
|
return getCount(request, fullQuery, format, fieldQueries);
|
574
|
}
|
575
|
|
576
|
@GET
|
577
|
@Path("/api/people/{personid}")
|
578
|
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
|
579
|
public Response fetchPeople(@PathParam("personid") String personid,
|
580
|
@QueryParam("format") final String format,
|
581
|
@QueryParam("fq") final List<String> fieldQueries,
|
582
|
@Context final HttpServletRequest request) {
|
583
|
return getResponseByEntityId(request, RequestResponseHandler.Entity.PERSON, personid, format, fieldQueries);
|
584
|
}
|
585
|
|
586
|
|
587
|
@GET
|
588
|
@Path("/api/people/{personid}/publications")
|
589
|
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
|
590
|
public Response fetchPeoplePublications(@PathParam("personid") String personid,
|
591
|
@DefaultValue("0") @QueryParam("page") final int offset,
|
592
|
@DefaultValue("10") @QueryParam("size") final int limit,
|
593
|
@QueryParam("format") final String format,
|
594
|
@QueryParam("fq") final List<String> fieldQueries,
|
595
|
@Context final HttpServletRequest request) {
|
596
|
String fullQuery = builtEntity2EntityRelationQuery(RequestResponseHandler.Entity.PUBLICATION, "relpersonid", personid, fieldQueries);
|
597
|
return getResponseByEntity(fullQuery, RequestResponseHandler.Entity.PUBLICATION, offset, limit, format, request, false, null, fieldQueries);
|
598
|
}
|
599
|
|
600
|
@GET
|
601
|
@Path("/api/people/{personid}/publications/count")
|
602
|
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
|
603
|
public Response fetchPeoplePublicationsCount(@PathParam("personid") String personid,
|
604
|
@QueryParam("format") final String format,
|
605
|
@QueryParam("fq") final List<String> fieldQueries,
|
606
|
@Context final HttpServletRequest request) {
|
607
|
String fullQuery = builtEntity2EntityRelationQuery(RequestResponseHandler.Entity.PUBLICATION, "relpersonid", personid, fieldQueries);
|
608
|
return getCount(request, fullQuery, format, fieldQueries);
|
609
|
}
|
610
|
|
611
|
|
612
|
@GET
|
613
|
@Path("/api/people/{personid}/datasets")
|
614
|
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
|
615
|
public Response fetchPeopleDatasets(@PathParam("personid") String personid,
|
616
|
@DefaultValue("0") @QueryParam("page") final int offset,
|
617
|
@DefaultValue("10") @QueryParam("size") final int limit,
|
618
|
@QueryParam("format") final String format,
|
619
|
@QueryParam("fq") final List<String> fieldQueries,
|
620
|
@Context final HttpServletRequest request) {
|
621
|
String fullQuery = builtEntity2EntityRelationQuery(RequestResponseHandler.Entity.DATASET, "relpersonid", personid, fieldQueries);
|
622
|
return getResponseByEntity(fullQuery, RequestResponseHandler.Entity.DATASET, offset, limit, format, request, false, null, fieldQueries);
|
623
|
}
|
624
|
|
625
|
@GET
|
626
|
@Path("/api/people/{personid}/datasets/count")
|
627
|
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
|
628
|
public Response fetchPeopleDatasetsCount(@PathParam("personid") String personid,
|
629
|
@QueryParam("format") final String format,
|
630
|
@QueryParam("fq") final List<String> fieldQueries,
|
631
|
@Context final HttpServletRequest request) {
|
632
|
String fullQuery = builtEntity2EntityRelationQuery(RequestResponseHandler.Entity.DATASET, "relpersonid", personid, fieldQueries);
|
633
|
return getCount(request, fullQuery, format, fieldQueries);
|
634
|
}
|
635
|
|
636
|
@GET
|
637
|
@Path("/api/reports")
|
638
|
@Produces(MediaType.TEXT_PLAIN)
|
639
|
public Response fetchReport(@QueryParam("q") String keywords,
|
640
|
@QueryParam("refine") @DefaultValue("false") boolean refine,
|
641
|
@QueryParam("fields") final List<String> fields,
|
642
|
@QueryParam("fq") final List<String> fieldQueries,
|
643
|
@QueryParam("type") final String type,
|
644
|
@QueryParam("format") final String format,
|
645
|
@Context final HttpServletResponse response) {
|
646
|
|
647
|
logger.debug("Reports request received");
|
648
|
|
649
|
if (type == null || type.isEmpty()) {
|
650
|
return Response.status(Response.Status.BAD_REQUEST).entity(APIResponseFormatter.
|
651
|
compose500Message(MediaType.APPLICATION_JSON, "Fail to fetch report.", "The 'type' parameter is missing.")).build();
|
652
|
}
|
653
|
|
654
|
long startTime = System.nanoTime();
|
655
|
final RequestResponseHandler.Entity entity = extractEntity(type);
|
656
|
final Transformer transformer = extractTransformer(format, extractEntity(type));
|
657
|
final boolean special = isSpecialFormat(format);
|
658
|
String responseType = extractResponseFormat(format);
|
659
|
|
660
|
final String fullQuery = buildSearchRequest(entity, keywords, fieldQueries);
|
661
|
|
662
|
try {
|
663
|
SearchResult sr = searchService.newSearch(fullQuery, Locale.getDefault().toString(), fields, fieldQueries,0, 0, format, transformer,null,false);
|
664
|
logger.debug("Total number of results " + sr.getTotal());
|
665
|
|
666
|
if (sr.getTotal() > 10000) {
|
667
|
return Response.status(Response.Status.BAD_REQUEST).entity(APIResponseFormatter.
|
668
|
compose500Message(MediaType.APPLICATION_JSON, "Fail to fetch report.", "You have exceeded the number of allowed returned results")).build();
|
669
|
}
|
670
|
|
671
|
} catch (SearchServiceException sse) {
|
672
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(APIResponseFormatter.
|
673
|
compose500Message(MediaType.APPLICATION_JSON, "Fail to fetch report.", sse.getMessage())).build();
|
674
|
}
|
675
|
|
676
|
StreamingOutput stream = new StreamingOutput() {
|
677
|
@Override
|
678
|
public void write(OutputStream os) throws IOException, WebApplicationException
|
679
|
{
|
680
|
if (hasTitle(format) && !format.equals("html")) {
|
681
|
os.write(CSVResponseFormat.appendTitle(entity, special).getBytes());
|
682
|
}
|
683
|
try {
|
684
|
searchService.cursorSearch(fullQuery, fields, fieldQueries, format, transformer, os);
|
685
|
|
686
|
} catch (SearchServiceException sse) {
|
687
|
os.write(("Fail to return report. " + sse.getMessage()).getBytes());
|
688
|
logger.warn("Fail to return report. ", sse);
|
689
|
}
|
690
|
|
691
|
//os.close();
|
692
|
}
|
693
|
|
694
|
};
|
695
|
|
696
|
long estimatedTime = System.nanoTime() - startTime;
|
697
|
logger.debug("Reports search time " + estimatedTime/1000000 + " milliseconds");
|
698
|
return Response.ok().entity(stream).type(responseType).build();
|
699
|
}
|
700
|
|
701
|
private String extractResponseFormat(String format) {
|
702
|
if (format != null && !format.isEmpty()) {
|
703
|
if (format.equalsIgnoreCase("json")) {
|
704
|
return MediaType.APPLICATION_JSON;
|
705
|
|
706
|
} else if (format.contains("csv")) {
|
707
|
return new MediaType("text", "csv").toString();
|
708
|
|
709
|
} else if (format.equalsIgnoreCase("tsv")) {
|
710
|
return new MediaType("text", "tsv").toString();
|
711
|
|
712
|
} else if (format.equalsIgnoreCase("html")) {
|
713
|
return MediaType.TEXT_HTML;
|
714
|
}
|
715
|
}
|
716
|
|
717
|
return MediaType.APPLICATION_XML;
|
718
|
}
|
719
|
|
720
|
private boolean isSpecialFormat(String format) {
|
721
|
if (format != null && format.toLowerCase().contains("special")) {
|
722
|
return true;
|
723
|
}
|
724
|
return false;
|
725
|
}
|
726
|
|
727
|
private boolean hasTitle(String format) {
|
728
|
if (format != null && format.toLowerCase().contains("notitle")) {
|
729
|
return false;
|
730
|
}
|
731
|
return true;
|
732
|
}
|
733
|
|
734
|
//TODO differentiate for html + add special controls for format support
|
735
|
private Transformer extractTransformer(String format, RequestResponseHandler.Entity entity) {
|
736
|
if (searchRegistry == null) { return null;}
|
737
|
|
738
|
if (format != null && (format.toLowerCase().contains("csv") || format.equalsIgnoreCase("html"))) {
|
739
|
logger.debug("Extracting transformer...." + format + "_" + entity);
|
740
|
return searchRegistry.getTransformer(format.replaceAll("-notitle","") + "_" + entity, Locale.getDefault());
|
741
|
|
742
|
}
|
743
|
|
744
|
return null;
|
745
|
}
|
746
|
|
747
|
//TODO old way of creating query see if needed.
|
748
|
/*private String buildSimpleSearchQuery(RequestResponseHandler.Entity entity, String keywords) {
|
749
|
StringBuilder queryBuilder = new StringBuilder();
|
750
|
enhanceQueryWithEntityType(queryBuilder, entity);
|
751
|
builtQueryKeywords(queryBuilder, cleanKeywords(keywords));
|
752
|
return queryBuilder.toString();
|
753
|
}*/
|
754
|
|
755
|
private String cleanKeywords(String keywords) {
|
756
|
if (keywords != null) {
|
757
|
return keywords.replaceAll("[\\\\/:*?<>|()]", "");
|
758
|
}
|
759
|
return keywords;
|
760
|
}
|
761
|
|
762
|
private String cleanId(String entityId) {
|
763
|
return entityId.replaceAll("\"", "");
|
764
|
}
|
765
|
|
766
|
private String buildSearchRequest(RequestResponseHandler.Entity entity, String keywords, String doi, String sortBy, List<String> fieldQueries) {
|
767
|
enhanceFieldQueryWithEntityType(entity, fieldQueries);
|
768
|
|
769
|
StringBuilder queryBuilder = new StringBuilder();
|
770
|
if (doi != null && !doi.trim().isEmpty()) {
|
771
|
queryBuilder.append("(pidclassid exact \"doi\" and pid exact " + doi + ")");
|
772
|
}
|
773
|
|
774
|
builtQueryKeywords(queryBuilder, keywords);
|
775
|
enhanceWithSortParameter(queryBuilder, sortBy);
|
776
|
|
777
|
return queryBuilder.toString();
|
778
|
}
|
779
|
|
780
|
private String buildSearchRequest(RequestResponseHandler.Entity entity, String keywords, List<String> fieldQueries) {
|
781
|
enhanceFieldQueryWithEntityType(entity, fieldQueries);
|
782
|
|
783
|
StringBuilder queryBuilder = new StringBuilder();
|
784
|
builtQueryKeywords(queryBuilder, keywords);
|
785
|
|
786
|
return queryBuilder.toString();
|
787
|
}
|
788
|
|
789
|
private void enhanceFieldQueryWithEntityType(RequestResponseHandler.Entity entity, List<String> fieldQueries) {
|
790
|
for (String fieldQuery: entity.getFieldQueries()) {
|
791
|
logger.debug("adding " + fieldQuery);
|
792
|
fieldQueries.add(fieldQuery);
|
793
|
}
|
794
|
}
|
795
|
|
796
|
private void builtQueryKeywords(StringBuilder queryBuilder, String keywords) {
|
797
|
if (keywords != null && !keywords.trim().isEmpty()) {
|
798
|
CQLQueryBuilder.appendKeywords(queryBuilder, cleanKeywords(keywords));
|
799
|
}
|
800
|
|
801
|
if (queryBuilder.toString().isEmpty()) {
|
802
|
queryBuilder.append("(*)");
|
803
|
}
|
804
|
}
|
805
|
|
806
|
private void builtEntityIdQuery(StringBuilder queryBuilder, RequestResponseHandler.Entity entity, String entityId, List<String> fieldQueries){
|
807
|
enhanceFieldQueryWithEntityType(entity, fieldQueries);
|
808
|
enhanceQueryWithEntityId(queryBuilder, entity, cleanId(entityId));
|
809
|
}
|
810
|
|
811
|
private String builtEntity2EntityRelationQuery(RequestResponseHandler.Entity entity, String relationfield, String entityId, List<String> fieldQueries){
|
812
|
StringBuilder queryBuilder = new StringBuilder();
|
813
|
//enhanceQueryWithEntityType(queryBuilder, entity);
|
814
|
enhanceFieldQueryWithEntityType(entity, fieldQueries);
|
815
|
enhanceQueryWithRelationId(queryBuilder, relationfield, cleanId(entityId));
|
816
|
return queryBuilder.toString();
|
817
|
}
|
818
|
|
819
|
private void enhanceQueryWithRelationId(StringBuilder queryBuilder, String relationfield, String entityId) {
|
820
|
if (!queryBuilder.toString().isEmpty()) {
|
821
|
CQLQueryBuilder.appendFieldTerm(queryBuilder, CQLQueryBuilder.Operator.AND, " " + relationfield + " ", CQLQueryBuilder.Operator.EXACT, entityId);
|
822
|
|
823
|
} else {
|
824
|
CQLQueryBuilder.appendFieldTerm(queryBuilder, CQLQueryBuilder.Operator.NONE, relationfield + " ", CQLQueryBuilder.Operator.EXACT, entityId);
|
825
|
}
|
826
|
}
|
827
|
|
828
|
private void enhanceQueryWithEntityId(StringBuilder queryBuilder, RequestResponseHandler.Entity entity, String entityId) {
|
829
|
if (queryBuilder.toString().isEmpty()) {
|
830
|
CQLQueryBuilder.appendFieldTerm(queryBuilder, CQLQueryBuilder.Operator.NONE, "objidentifier", CQLQueryBuilder.Operator.EXACT, entityId);
|
831
|
} else {
|
832
|
CQLQueryBuilder.appendFieldTerm(queryBuilder, CQLQueryBuilder.Operator.AND, "objidentifier", CQLQueryBuilder.Operator.EXACT, entityId);
|
833
|
}
|
834
|
|
835
|
if (entity == RequestResponseHandler.Entity.PUBLICATION || entity == RequestResponseHandler.Entity.DATASET) {
|
836
|
CQLQueryBuilder.appendFieldTerm(queryBuilder, CQLQueryBuilder.Operator.OR, "resultdupid", CQLQueryBuilder.Operator.EXACT, entityId);
|
837
|
}
|
838
|
|
839
|
}
|
840
|
|
841
|
private void enhanceWithSortParameter(StringBuilder queryBuilder, String sortBy) {
|
842
|
if (sortBy != null) {
|
843
|
String[] sortParams = sortBy.split(",");
|
844
|
|
845
|
if (sortParams.length != 2) {
|
846
|
throw new IllegalArgumentException("Invalid sort paremeter. 'sortBy' parameter format is <fieldName>[,asc|,desc].");
|
847
|
}
|
848
|
|
849
|
String sortByField = sortParams[0];
|
850
|
String order = sortParams[1];
|
851
|
|
852
|
if (!sortByField.equals("resultdateofacceptance")){
|
853
|
throw new IllegalArgumentException("'" + sortByField + "' is not a sortable field.");
|
854
|
}
|
855
|
|
856
|
if (!checkOrder(order)) {
|
857
|
throw new IllegalArgumentException("'" + order + "' is not a valid ordering. Please use one of {ascending, descending}");
|
858
|
}
|
859
|
|
860
|
addSortParameter(sortByField, order, queryBuilder);
|
861
|
}
|
862
|
}
|
863
|
|
864
|
private static boolean checkOrder(String order) {
|
865
|
if (order.matches("ascending|descending")) {
|
866
|
return true;
|
867
|
}
|
868
|
return false;
|
869
|
}
|
870
|
|
871
|
private static void addSortParameter(String indexField, String order, StringBuilder queryBuilder) {
|
872
|
queryBuilder.append(" sortBy " + indexField + "/sort." + order);
|
873
|
}
|
874
|
|
875
|
private Response getCount(HttpServletRequest request, String query, String format, List<String> fieldQueries) {
|
876
|
String responseFormat = extractResponseFormat(format);
|
877
|
|
878
|
try {
|
879
|
SearchResult searchResult = searchService.newSearch(query, Locale.getDefault().toString(), null, fieldQueries, 0, 0, responseFormat, null, null, false);
|
880
|
return Response.status(Response.Status.OK).entity(APIResponseFormatter.createCountMeta(request, query, searchResult.getTotal(), responseFormat)).type(responseFormat).build();
|
881
|
|
882
|
} catch (SearchServiceException sse) {
|
883
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(APIResponseFormatter.compose500Message(responseFormat, "Fail to fetch count for query " + query + ".", sse.getMessage())).build();
|
884
|
}
|
885
|
}
|
886
|
|
887
|
private Response getResponseByEntityId(HttpServletRequest request, RequestResponseHandler.Entity entity, String entityId, String format, List<String> fieldQueries) {
|
888
|
String responseType = extractResponseFormat(format);
|
889
|
|
890
|
try {
|
891
|
StringBuilder queryBuilder = new StringBuilder();
|
892
|
builtEntityIdQuery(queryBuilder, entity, entityId, fieldQueries);
|
893
|
String fullQuery = queryBuilder.toString();
|
894
|
|
895
|
if(fullQuery == null || fullQuery.isEmpty()) {
|
896
|
return Response.status(Response.Status.BAD_REQUEST).
|
897
|
entity(APIResponseFormatter.compose400Message(format, "The 'query' parameter is required")).
|
898
|
type(responseType).build();
|
899
|
}
|
900
|
|
901
|
SearchResult searchResult = searchService.newSearch(fullQuery, Locale.getDefault().toString(), null, fieldQueries, 0, 1, responseType, null, null, false);
|
902
|
|
903
|
if (searchResult.getSearchResults() == null || searchResult.getSearchResults().isEmpty() ||
|
904
|
searchResult.getSearchResults().size() == 0 || searchResult.getSearchResults().get(0) == null) {
|
905
|
return Response.status(Response.Status.NOT_FOUND).entity(APIResponseFormatter.compose404Message(responseType, "404 - " + entity +" with id "
|
906
|
+ entityId + " not found.")).type(responseType).build();
|
907
|
}
|
908
|
|
909
|
return Response.status(Response.Status.OK).entity(APIResponseFormatter.createEntityResponse(request, entity, searchResult.getSearchResults().get(0).toString(), responseType)).type(responseType).build();
|
910
|
|
911
|
} catch (SearchServiceException sse) {
|
912
|
logger.error("Fail to fetch "+ entity + " with id " + entityId, sse);
|
913
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(APIResponseFormatter.compose500Message(responseType, "Fail to fetch " + entity + " with id " + entityId, sse.getMessage())).build();
|
914
|
}
|
915
|
}
|
916
|
|
917
|
private Response getResponseByEntity(String fullQuery, RequestResponseHandler.Entity entity, int offset, int limit, String format, HttpServletRequest request, boolean refine, List<String> refineFields, List<String> fieldQueries) {
|
918
|
long startTime = System.nanoTime();
|
919
|
Transformer transformer = extractTransformer(format, entity);
|
920
|
boolean special = isSpecialFormat(format);
|
921
|
boolean hasTitle = hasTitle(format);
|
922
|
String responseType = extractResponseFormat(format);
|
923
|
|
924
|
if(fullQuery == null || fullQuery.isEmpty()) {
|
925
|
return Response.status(Response.Status.BAD_REQUEST).
|
926
|
entity(APIResponseFormatter.compose400Message(responseType, "The 'query' parameter is required")).
|
927
|
type(responseType).build();
|
928
|
}
|
929
|
|
930
|
try {
|
931
|
SearchResult solrResults = searchService.newSearch(fullQuery, Locale.getDefault().toString(), refineFields, fieldQueries, offset, limit, responseType, transformer, null, false);
|
932
|
long estimatedTime = System.nanoTime() - startTime;
|
933
|
logger.debug("Publications search time " + estimatedTime/1000000 + " milliseconds");
|
934
|
return Response.status(Response.Status.OK).entity(APIResponseFormatter.createEntitiesResponse(request, entity, fullQuery, fieldQueries, solrResults, refine, responseType, special, hasTitle)).type(responseType).build();
|
935
|
|
936
|
} catch (SearchServiceException sse) {
|
937
|
logger.error("Fail to get " + entity.getPlural() , sse);
|
938
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).
|
939
|
entity(APIResponseFormatter.compose500Message(responseType, "Fail to fetch " + entity.getPlural(), sse.getMessage())).type(responseType).build();
|
940
|
}
|
941
|
}
|
942
|
|
943
|
private RequestResponseHandler.Entity extractEntity(String type) {
|
944
|
|
945
|
if (type == null) {
|
946
|
return RequestResponseHandler.Entity.NONE;
|
947
|
}
|
948
|
|
949
|
if (type.equalsIgnoreCase(RequestResponseHandler.Entity.PUBLICATION.getPlural())) {
|
950
|
return RequestResponseHandler.Entity.PUBLICATION;
|
951
|
|
952
|
} else if (type.equalsIgnoreCase(RequestResponseHandler.Entity.DATASET.getPlural())) {
|
953
|
return RequestResponseHandler.Entity.DATASET;
|
954
|
|
955
|
} else if (type.equalsIgnoreCase(RequestResponseHandler.Entity.SOFTWARE.getPlural())) {
|
956
|
return RequestResponseHandler.Entity.SOFTWARE;
|
957
|
|
958
|
} else if (type.equalsIgnoreCase(RequestResponseHandler.Entity.OTHER.getPlural())) {
|
959
|
return RequestResponseHandler.Entity.OTHER;
|
960
|
|
961
|
} else if (type.equalsIgnoreCase(RequestResponseHandler.Entity.PROJECT.getPlural())) {
|
962
|
return RequestResponseHandler.Entity.PROJECT;
|
963
|
|
964
|
} else if (type.equalsIgnoreCase(RequestResponseHandler.Entity.DATASOURCE.getPlural())) {
|
965
|
return RequestResponseHandler.Entity.DATASOURCE;
|
966
|
|
967
|
} else if (type.equalsIgnoreCase(RequestResponseHandler.Entity.PERSON.getPlural())) {
|
968
|
return RequestResponseHandler.Entity.PERSON;
|
969
|
|
970
|
} else if (type.equalsIgnoreCase(RequestResponseHandler.Entity.ORGANIZATION.getPlural())) {
|
971
|
return RequestResponseHandler.Entity.ORGANIZATION;
|
972
|
}
|
973
|
|
974
|
return RequestResponseHandler.Entity.NONE;
|
975
|
}
|
976
|
|
977
|
|
978
|
/*
|
979
|
public static void main(String[] args) {
|
980
|
String json = " {\"result\":{\"xmlns:oaf\":\"http://namespace.openaire.eu/oaf\",\"xmlns:xsi\":\"http://www.w3.o" +
|
981
|
"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" +
|
982
|
"lue\":1},\"counter_authorship_inferred\":{\"value\":1}},\"dri:objIdentifier\":\"dedup_wf_001::0f5604702b32f59d9789573113279e69\"},\"metadata\":{\"oaf:entity\":{\"oaf:result\":{\"datainfo\":{\"provenanceaction\":{\"schemename\"" +
|
983
|
":\"dnet:provenanceActions\",\"classname\":\"sysimport:dedup\",\"schemeid\":\"dnet:provenanceActions\",\"classid\":\"sysimport:dedup\"},\"trust\":0.9,\"inferenceprovenance\":\"dedup-similarity-result\",\"deletedbyinference\":fal" +
|
984
|
"se,\"inferred\":true},\"rels\":{\"rel\":{\"to\":{\"content\":\"dedup_wf_001::884d8c367553a8de98ec90ece1b1be4a\",\"scheme\":\"dnet:person_result_relations\",\"class\":\"hasAuthor\",\"type\":\"person\"},\"provenanceaction\":\"sysimpor" +
|
985
|
"t:crosswalk:repository\",\"trust\":0.9,\"inferenceprovenance\":\"\",\"ranking\":1,\"inferred\":true,\"fullname\":\"Krafft, Alexander\"}},\"subject\":[{\"content\":\"Clinic for Obstetrics\",\"schemename\":\"dnet:result_subject\",\"c" +
|
986
|
"lassname\":\"keyword\",\"schemeid\":\"dnet:result_subject\",\"classid\":\"keyword\"},{\"content\":\"610 Medicine & health\",\"schemename\":\"dnet:result_subject\",\"classname\":\"keyword\",\"schemeid\":\"dnet:result_subject\",\"class" +
|
987
|
"id\":\"keyword\"},{\"content\":\"News\",\"schemename\":\"dnet:result_subject\",\"classname\":\"keyword\",\"schemeid\":\"dnet:result_subject\",\"classid\":\"keyword\"}],\"collectedfrom\":[{\"id\":\"opendoar____::0efe32849d230d7f53049d" +
|
988
|
"dc4a4b0c60\",\"name\":\"Zurich Open Repository and Archive\"},{\"id\":\"opendoar____::8b6dd7db9af49e67306feb59a8bdc52c\",\"name\":\"Europe PubMed Central\"}],\"children\":{\"result\":[{\"title\":{\"content\":\"Iron supplementat" +
|
989
|
"ion in pregnancy\",\"schemename\":\"dnet:dataCite_title\",\"classname\":\"main title\",\"schemeid\":\"dnet:dataCite_title\",\"classid\":\"main title\"},\"resulttype\":{\"schemename\":\"dnet:result_typologies\",\"classname\":\"publi" +
|
990
|
"cation\",\"schemeid\":\"dnet:result_typologies\",\"classid\":\"publication\"},\"dateofacceptance\":\"1981-09-01\",\"objidentifier\":\"od_______908::f27f9e68f0b9f510ebf572ba295344e1\"},{\"title\":{\"content\":\"Iron supplementat" +
|
991
|
"ion in pregnancy\",\"schemename\":\"dnet:dataCite_title\",\"classname\":\"main title\",\"schemeid\":\"dnet:dataCite_title\",\"classid\":\"main title\"},\"resulttype\":{\"schemename\":\"dnet:result_typologies\",\"classname\":\"publi" +
|
992
|
"cation\",\"schemeid\":\"dnet:result_typologies\",\"classid\":\"publication\"},\"dateofacceptance\":\"2013-01-01\",\"publisher\":\"BMJ Publishing Group\",\"objidentifier\":\"od_______885::0f5604702b32f59d9789573113279e69\"}],\"i" +
|
993
|
"nstance\":[{\"webresource\":{\"url\":\"http://europepmc.org/articles/PMC2306130\"},\"id\":\"opendoar____::8b6dd7db9af49e67306feb59a8bdc52c\",\"licence\":{\"schemename\":\"dnet:access_modes\",\"classname\":\"Open Access\",\"sche" +
|
994
|
"meid\":\"dnet:access_modes\",\"classid\":\"OPEN\"},\"hostedby\":{\"id\":\"opendoar____::8b6dd7db9af49e67306feb59a8bdc52c\",\"name\":\"Europe PubMed Central\"},\"instancetype\":{\"schemename\":\"dnet:publication_resource\",\"class" +
|
995
|
"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" +
|
996
|
"49ddc4a4b0c60\",\"licence\":{\"schemename\":\"dnet:access_modes\",\"classname\":\"Open Access\",\"schemeid\":\"dnet:access_modes\",\"classid\":\"OPEN\"},\"hostedby\":{\"id\":\"opendoar____::0efe32849d230d7f53049ddc4a4b0c60\",\"name" +
|
997
|
"\":\"Zurich Open Repository and Archive\"},\"instancetype\":{\"schemename\":\"dnet:publication_resource\",\"classname\":\"Article\",\"schemeid\":\"dnet:publication_resource\",\"classid\":\"0001\"}}]},\"pid\":[{\"content\":\"10.5167" +
|
998
|
"/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\"," +
|
999
|
"\"classid\":\"pmc\"},{\"content\":\"10.1136/bmj.f4399\",\"schemename\":\"dnet:pid_types\",\"classname\":\"doi\",\"schemeid\":\"dnet:pid_types\",\"classid\":\"doi\"}],\"resourcetype\":{\"schemename\":\"\",\"classname\":\"\",\"schemeid\":\"\",\"c" +
|
1000
|
"lassid\":\"\"},\"format\":\"\",\"dateofacceptance\":\"2013-01-01\",\"embargoenddate\":\"\",\"version\":\"\",\"size\":\"\",\"publisher\":\"BMJ Publishing Group\",\"country\":{\"schemename\":\"\",\"classname\":\"\",\"schemeid\":\"\",\"classid\":\"\"},\"" +
|
1001
|
"metadataversionnumber\":\"\",\"title\":{\"content\":\"Iron supplementation in pregnancy\",\"schemename\":\"dnet:dataCite_title\",\"classname\":\"main title\",\"schemeid\":\"dnet:dataCite_title\",\"classid\":\"main title\"},\"result" +
|
1002
|
"type\":{\"schemename\":\"dnet:result_typologies\",\"classname\":\"publication\",\"schemeid\":\"dnet:result_typologies\",\"classid\":\"publication\"},\"source\":\"Krafft, Alexander (2013). Iron supplementation in pregnancy. Br" +
|
1003
|
"itish Medical Journal, 347:f4399.\",\"contributor\":\"\",\"description\":\"\",\"originalId\":[\"oai:europepmc.org:1052305\",\"oai:www.zora.uzh.ch:87059\"],\"lastmetadataupdate\":\"\",\"relevantdate\":{\"schemename\":\"\",\"classnam" +
|
1004
|
"e\":\"\",\"schemeid\":\"\",\"classid\":\"\"},\"device\":\"\",\"bestlicense\":{\"schemename\":\"dnet:access_modes\",\"classname\":\"Open Access\",\"schemeid\":\"dnet:access_modes\",\"classid\":\"OPEN\"},\"language\":{\"schemename\":\"dnet:langu" +
|
1005
|
"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" +
|
1006
|
"d\"}},\"xmlns:dri\":\"http://www.driver-repository.eu/namespace/dri\"}}";
|
1007
|
|
1008
|
String s = "{\"result\":{\"xmlns:oaf\":\"http://namespace.openaire.eu/oaf\",\"xmlns:xsi\":\"http://www.w3.org/2001" +
|
1009
|
"/XMLSchema-instance\",\"header\":{\"dri:dateOfCollection\":\"2014-04-10T13:35:33Z\",\"dri:dateOfTransformation\":\"\",\"counters\":{\"counter_dedup\":{\"value\":2},\"counter_authorship\":{\"value\":1},\"counter_authorship_infer" +
|
1010
|
"red\":{\"value\":1}},\"dri:objIdentifier\":\"dedup_wf_001::4d934888dee33a62dece6fa36192c710\"},\"metadata\":{\"oaf:entity\":{\"oaf:result\":{\"datainfo\":{\"provenanceaction\":{\"schemename\":\"dnet:provenanceActions\",\"classn" +
|
1011
|
"ame\":\"sysimport:dedup\",\"schemeid\":\"dnet:provenanceActions\",\"classid\":\"sysimport:dedup\"},\"trust\":0.9,\"inferenceprovenance\":\"dedup-similarity-result\",\"deletedbyinference\":false,\"inferred\":true},\"rels\":{\"rel\"" +
|
1012
|
":{\"to\":{\"content\":\"od______1232::d4f9cea02c7762da24cd71ea0b9791de\",\"scheme\":\"dnet:person_result_relations\",\"class\":\"hasAuthor\",\"type\":\"person\"},\"provenanceaction\":\"sysimport:crosswalk:repository\",\"trust\":0" +
|
1013
|
".9,\"inferenceprovenance\":\"\",\"ranking\":1,\"inferred\":true,\"fullname\":\"Anonymous\"}},\"subject\":{\"content\":\"Señoríos-Legislación\",\"schemename\":\"dnet:result_subject\",\"classname\":\"keyword\",\"schemeid\":\"dnet:result" +
|
1014
|
"_subject\",\"classid\":\"keyword\"},\"collectedfrom\":[{\"id\":\"opendoar____::e53a0a2978c28872a4505bdb51db06dc\",\"name\":\"Biblioteca Virtual del Patrimonio Bibliográfico (Virtual Library of Bibliographical Heritage)\"" +
|
1015
|
"},{\"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" +
|
1016
|
" 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" +
|
1017
|
"emename\":\"dnet:result_typologies\",\"classname\":\"publication\",\"schemeid\":\"dnet:result_typologies\",\"classid\":\"publication\"},\"dateofacceptance\":\"1820-01-01\",\"objidentifier\":\"od______2719::bc2326a31763719dc5ebd" +
|
1018
|
"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\"," +
|
1019
|
"\"classname\":\"main title\",\"schemeid\":\"dnet:dataCite_title\",\"classid\":\"main title\"},\"resulttype\":{\"schemename\":\"dnet:result_typologies\",\"classname\":\"publication\",\"schemeid\":\"dnet:result_typologies\",\"classid\"" +
|
1020
|
":\"publication\"},\"dateofacceptance\":\"1820-01-01\",\"objidentifier\":\"od______1232::4d934888dee33a62dece6fa36192c710\"}],\"instance\":[{\"webresource\":[{\"url\":\"http://bvpb.mcu.es/es/consulta/registro.cmd?id=403864\"" +
|
1021
|
"},{\"url\":\"http://bvpb.mcu.es/es/catalogo_imagenes/grupo.cmd?path=2755\"}],\"id\":\"opendoar____::e53a0a2978c28872a4505bdb51db06dc\",\"licence\":{\"schemename\":\"dnet:access_modes\",\"classname\":\"Open Access\",\"schemei" +
|
1022
|
"d\":\"dnet:access_modes\",\"classid\":\"OPEN\"},\"hostedby\":{\"id\":\"opendoar____::e53a0a2978c28872a4505bdb51db06dc\",\"name\":\"Biblioteca Virtual del Patrimonio Bibliográfico (Virtual Library of Bibliographical Herita" +
|
1023
|
"ge)\"},\"instancetype\":{\"schemename\":\"dnet:publication_resource\",\"classname\":\"Book\",\"schemeid\":\"dnet:publication_resource\",\"classid\":\"0002\"}},{\"webresource\":{\"url\":\"http://bibliotecavirtual.aragon.es/bva/i18" +
|
1024
|
"n/consulta/registro.cmd?id=2878\"},\"id\":\"opendoar____::7aee26c309def8c5a2a076eb250b8f36\",\"licence\":{\"schemename\":\"dnet:access_modes\",\"classname\":\"Open Access\",\"schemeid\":\"dnet:access_modes\",\"classid\":\"OPEN\"" +
|
1025
|
"},\"hostedby\":{\"id\":\"opendoar____::7aee26c309def8c5a2a076eb250b8f36\",\"name\":\"Biblioteca Virtual de Aragón\"},\"instancetype\":{\"schemename\":\"dnet:publication_resource\",\"classname\":\"Book\",\"schemeid\":\"dnet:publi" +
|
1026
|
"cation_resource\",\"classid\":\"0002\"}}]},\"pid\":{\"schemename\":\"\",\"classname\":\"\",\"schemeid\":\"\",\"classid\":\"\"},\"resourcetype\":{\"schemename\":\"\",\"classname\":\"\",\"schemeid\":\"\",\"classid\":\"\"},\"format\":\"\",\"dateofaccepta" +
|
1027
|
"nce\":\"1820-01-01\",\"embargoenddate\":\"\",\"version\":\"\",\"size\":\"\",\"country\":{\"schemename\":\"\",\"classname\":\"\",\"schemeid\":\"\",\"classid\":\"\"},\"publisher\":\"\",\"metadataversionnumber\":\"\",\"title\":{\"content\":\"Discurso sob" +
|
1028
|
"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" +
|
1029
|
"ite_title\",\"classid\":\"main title\"},\"resulttype\":{\"schemename\":\"dnet:result_typologies\",\"classname\":\"publication\",\"schemeid\":\"dnet:result_typologies\",\"classid\":\"publication\"},\"source\":\"\",\"contributor\":\"Impr" +
|
1030
|
"enta de Heras, imp.\",\"description\":\"\",\"originalId\":[\"oai:bvpb.mcu.es:403864\",\"oai:bibliotecavirtual.aragon.es:2878\"],\"lastmetadataupdate\":\"\",\"relevantdate\":{\"schemename\":\"\",\"classname\":\"\",\"schemeid\":\"\",\"cl" +
|
1031
|
"assid\":\"\"},\"device\":\"\",\"bestlicense\":{\"schemename\":\"dnet:access_modes\",\"classname\":\"Open Access\",\"schemeid\":\"dnet:access_modes\",\"classid\":\"OPEN\"},\"language\":{\"schemename\":\"dnet:languages\",\"classname\":\"Span" +
|
1032
|
"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" +
|
1033
|
"ttp://www.driver-repository.eu/namespace/dri\"}}\n";
|
1034
|
|
1035
|
JSONObject finalOject = new JSONObject();
|
1036
|
finalOject.put("dri:objIdentifier", new JSONObject(json).getJSONObject("result").getJSONObject("header").getString("dri:objIdentifier"));
|
1037
|
finalOject.put("content", new JSONObject(new JSONObject(json).getJSONObject("result").getJSONObject("metadata").getJSONObject("oaf:entity").getJSONObject("oaf:result"),
|
1038
|
new String[]{"title", "description", "language", "bestlicense", "pid", "rels"}));
|
1039
|
|
1040
|
System.out.println(finalOject);
|
1041
|
|
1042
|
JSONObject jsonObject = new JSONObject(s).getJSONObject("result").getJSONObject("metadata").getJSONObject("oaf:entity").getJSONObject("oaf:result");
|
1043
|
System.out.println("title --> " + jsonObject.getJSONObject("title").getString("content"));
|
1044
|
System.out.println("pid --> " + jsonObject.getJSONArray("pid"));
|
1045
|
|
1046
|
JSONObject newJsonObject1 = new JSONObject(jsonObject, new String[]{"title", "description", "language", "bestlicense", "pid", "rels"});
|
1047
|
|
1048
|
}
|
1049
|
*/
|
1050
|
/*
|
1051
|
|
1052
|
public static void main(String[] args) throws IOException, CQLParseException {
|
1053
|
CqlTranslator translator = new CqlTranslatorImpl();
|
1054
|
System.out.println(translator.toLucene("relfundinglevel0_id = ec__________::EC::FP7"));
|
1055
|
}
|
1056
|
*/
|
1057
|
|
1058
|
}
|