Revision 58157
Added by Katerina Iatropoulou about 4 years ago
SearchApiService.java | ||
---|---|---|
22 | 22 |
import javax.ws.rs.core.StreamingOutput; |
23 | 23 |
import java.io.IOException; |
24 | 24 |
import java.io.OutputStream; |
25 |
import java.util.ArrayList; |
|
26 |
import java.util.Arrays; |
|
25 | 27 |
import java.util.List; |
26 | 28 |
import java.util.Locale; |
27 | 29 |
|
... | ... | |
46 | 48 |
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) |
47 | 49 |
@Timed(value = "http.server.request.duration", extraTags = {"referer", "portal", "uri", "/rest/v2/api/resources"}, longTask = false) |
48 | 50 |
public Response fetchResources(@QueryParam("query") String query, |
49 |
@DefaultValue("0") @QueryParam("page") final int offset,
|
|
50 |
@DefaultValue("10") @QueryParam("size") final int limit,
|
|
51 |
@QueryParam("refine") @DefaultValue("false") final boolean refine,
|
|
52 |
@QueryParam("fields") final List<String> refineFields,
|
|
53 |
@QueryParam("sf") final List<String> specialFacets,
|
|
54 |
@QueryParam("fq") final List<String> fieldQueries,
|
|
55 |
@QueryParam("format") final String format,
|
|
56 |
@QueryParam("type") final String type,
|
|
57 |
@Context final HttpServletRequest request) {
|
|
51 |
@DefaultValue("0") @QueryParam("page") final int offset, |
|
52 |
@DefaultValue("10") @QueryParam("size") final int limit, |
|
53 |
@QueryParam("refine") @DefaultValue("false") final boolean refine, |
|
54 |
@QueryParam("fields") final List<String> refineFields, |
|
55 |
@QueryParam("sf") final List<String> specialFacets, |
|
56 |
@QueryParam("fq") final List<String> fieldQueries, |
|
57 |
@QueryParam("format") final String format, |
|
58 |
@QueryParam("type") final String type, |
|
59 |
@Context final HttpServletRequest request) { |
|
58 | 60 |
|
59 | 61 |
return getResponseByEntity(query, extractEntity(type), offset, limit, format, request, refine, refineFields, specialFacets, fieldQueries); |
60 | 62 |
} |
61 | 63 |
|
62 | 64 |
@GET |
65 |
@Path("/api/resources2") |
|
66 |
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) |
|
67 |
@Timed(value = "http.server.request.duration", extraTags = {"referer", "portal", "uri", "/rest/v2/api/resources2"}, longTask = false) |
|
68 |
public Response fetchResources(@QueryParam("query") String query, |
|
69 |
@DefaultValue("0") @QueryParam("page") final int offset, |
|
70 |
@DefaultValue("10") @QueryParam("size") final int limit, |
|
71 |
@QueryParam("refine") @DefaultValue("false") final boolean refine, |
|
72 |
@QueryParam("fields") final List<String> refineFields, |
|
73 |
@QueryParam("sf") final List<String> specialFacets, |
|
74 |
@QueryParam("fq") final List<String> fieldQueries, |
|
75 |
@QueryParam("format") final String format, |
|
76 |
@QueryParam("type") final List<String> types, |
|
77 |
@Context final HttpServletRequest request) { |
|
78 |
|
|
79 |
return getResponseByEntityTypes(query, types, offset, limit, format, request, refine, refineFields, specialFacets, fieldQueries); |
|
80 |
} |
|
81 |
|
|
82 |
private RequestResponseHandler.Entity identifyBasicEntityType(final List<String> types) { |
|
83 |
for(String type: types) { |
|
84 |
if (type.equals(RequestResponseHandler.Entity.PUBLICATION.getPlural()) || type.equals(RequestResponseHandler.Entity.DATASET.getPlural()) || |
|
85 |
type.equals(RequestResponseHandler.Entity.SOFTWARE.getPlural()) || type.equals(RequestResponseHandler.Entity.OTHER.getPlural())) { |
|
86 |
return RequestResponseHandler.Entity.RESULT; |
|
87 |
|
|
88 |
} else if (type.equals(RequestResponseHandler.Entity.PROJECT.getPlural())) { |
|
89 |
return RequestResponseHandler.Entity.PROJECT; |
|
90 |
|
|
91 |
} else if (type.equals(RequestResponseHandler.Entity.DATASOURCE.getPlural())) { |
|
92 |
return RequestResponseHandler.Entity.DATASOURCE; |
|
93 |
|
|
94 |
} else if (type.equals(RequestResponseHandler.Entity.ORGANIZATION.getPlural())) { |
|
95 |
return RequestResponseHandler.Entity.ORGANIZATION; |
|
96 |
} |
|
97 |
} |
|
98 |
return RequestResponseHandler.Entity.NONE; |
|
99 |
} |
|
100 |
|
|
101 |
@GET |
|
63 | 102 |
@Path("/api/results") |
64 | 103 |
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) |
65 | 104 |
@Timed(value = "http.server.request.duration", extraTags = {"referer", "portal", "uri", "/rest/v2/api/results"}, longTask = false) |
66 | 105 |
public Response fetchResults(@QueryParam("q") final String keywords, |
67 |
@QueryParam("doi") final String doi, |
|
68 |
@QueryParam("sortBy") final String sortBy, |
|
69 |
@DefaultValue("0") @QueryParam("page") final int offset, |
|
70 |
@DefaultValue("10") @QueryParam("size") final int limit, |
|
71 |
@QueryParam("refine") @DefaultValue("false") final boolean refine, |
|
72 |
@QueryParam("fields") final List<String> refineFields, |
|
73 |
@QueryParam("sf") final List<String> specialFacets, |
|
74 |
@QueryParam("fq") final List<String> fieldQueries, |
|
75 |
@QueryParam("format") final String format, |
|
76 |
@Context final HttpServletRequest request) { |
|
106 |
@QueryParam("doi") final String doi, |
|
107 |
@QueryParam("sortBy") final String sortBy, |
|
108 |
@DefaultValue("0") @QueryParam("page") final int offset, |
|
109 |
@DefaultValue("10") @QueryParam("size") final int limit, |
|
110 |
@QueryParam("refine") @DefaultValue("false") final boolean refine, |
|
111 |
@QueryParam("fields") final List<String> refineFields, |
|
112 |
@QueryParam("sf") final List<String> specialFacets, |
|
113 |
@QueryParam("fq") final List<String> fieldQueries, |
|
114 |
@QueryParam("format") final String format, |
|
115 |
@QueryParam("type") final List<String> types, |
|
116 |
@Context final HttpServletRequest request) { |
|
77 | 117 |
|
78 | 118 |
logger.debug("Publications request received"); |
79 |
//TODO do not allow q and keywords both - SWITCH back if needed |
|
80 |
//String simpleQuery = buildSimpleSearchQuery(RequestResponseHandler.Entity.PUBLICATION, keywords) ; |
|
81 |
String simpleQuery = buildSearchRequest(RequestResponseHandler.Entity.RESULT, keywords, doi,sortBy, fieldQueries); |
|
119 |
|
|
120 |
String simpleQuery = buildSearchRequest(types, keywords, doi,sortBy, fieldQueries); |
|
82 | 121 |
return getResponseByEntity(simpleQuery, RequestResponseHandler.Entity.RESULT, offset, limit, format, request, refine, refineFields, specialFacets, fieldQueries); |
83 | 122 |
|
84 | 123 |
} |
85 | 124 |
|
86 |
|
|
87 | 125 |
@GET |
88 | 126 |
@Path("/api/results/count") |
89 | 127 |
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) |
90 | 128 |
@Timed(value = "http.server.request.duration", extraTags = {"referer", "portal", "uri", "/rest/v2/api/results/count"}, longTask = false) |
91 | 129 |
public Response fetchResultsCount(@QueryParam("q") String query, |
92 |
@QueryParam("format") final String format, |
|
93 |
@QueryParam("fq") final List<String> fieldQueries, |
|
94 |
@Context final HttpServletRequest request) { |
|
95 |
String fullQuery = buildSearchRequest(RequestResponseHandler.Entity.RESULT, query, fieldQueries); |
|
130 |
@QueryParam("format") final String format, |
|
131 |
@QueryParam("fq") final List<String> fieldQueries, |
|
132 |
@QueryParam("types") final List<String> types, |
|
133 |
@Context final HttpServletRequest request) { |
|
134 |
String fullQuery = buildSearchRequest(types, query, fieldQueries); |
|
96 | 135 |
return getCount(request, fullQuery, format, fieldQueries); |
97 | 136 |
} |
98 | 137 |
|
99 | 138 |
|
139 |
/* |
|
100 | 140 |
@GET |
101 | 141 |
@Path("/api/results/{resultid}") |
102 | 142 |
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) |
103 | 143 |
@Timed(value = "http.server.request.duration", extraTags = {"referer", "portal", "uri", "/rest/v2/api/results/{resultid}"}, longTask = false) |
104 | 144 |
public Response fetchResultsById(@PathParam("resultid") String resultid, |
105 |
@QueryParam("format") final String format,
|
|
106 |
@QueryParam("fq") final List<String> fieldQueries,
|
|
107 |
@Context final HttpServletRequest request) {
|
|
145 |
@QueryParam("format") final String format, |
|
146 |
@QueryParam("fq") final List<String> fieldQueries, |
|
147 |
@Context final HttpServletRequest request) { |
|
108 | 148 |
return getResponseByEntityId(request, RequestResponseHandler.Entity.RESULT, resultid, format, fieldQueries); |
109 |
} |
|
149 |
}*/
|
|
110 | 150 |
|
111 | 151 |
@GET |
112 | 152 |
@Path("/api/publications") |
... | ... | |
205 | 245 |
@Path("/api/software") |
206 | 246 |
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) |
207 | 247 |
@Timed(value = "http.server.request.duration", extraTags = {"referer", "portal", "uri", "/rest/v2/api/software"}, longTask = false) |
208 |
public Response fetchSoftware(@QueryParam("q") String keywords,
|
|
248 |
public Response fetchSoftware(@QueryParam("ru") String keywords,
|
|
209 | 249 |
@QueryParam("doi") final String doi, |
210 | 250 |
@QueryParam("sortBy") final String sortBy, |
211 | 251 |
@DefaultValue("0") @QueryParam("page") int offset, |
... | ... | |
249 | 289 |
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) |
250 | 290 |
@Timed(value = "http.server.request.duration", extraTags = {"referer", "portal", "uri", "/rest/v2/api/other"}, longTask = false) |
251 | 291 |
public Response fetchOther(@QueryParam("q") String keywords, |
252 |
@QueryParam("doi") final String doi,
|
|
253 |
@QueryParam("sortBy") final String sortBy,
|
|
254 |
@DefaultValue("0") @QueryParam("page") int offset,
|
|
255 |
@DefaultValue("10") @QueryParam("size") int limit,
|
|
256 |
@QueryParam("refine") @DefaultValue("false") boolean refine,
|
|
257 |
@QueryParam("fields") final List<String> refineFields,
|
|
258 |
@QueryParam("sf") final List<String> specialFacets,
|
|
259 |
@QueryParam("fq") final List<String> fieldQueries,
|
|
260 |
@QueryParam("format") final String format,
|
|
261 |
@Context HttpServletRequest request) {
|
|
292 |
@QueryParam("doi") final String doi, |
|
293 |
@QueryParam("sortBy") final String sortBy, |
|
294 |
@DefaultValue("0") @QueryParam("page") int offset, |
|
295 |
@DefaultValue("10") @QueryParam("size") int limit, |
|
296 |
@QueryParam("refine") @DefaultValue("false") boolean refine, |
|
297 |
@QueryParam("fields") final List<String> refineFields, |
|
298 |
@QueryParam("sf") final List<String> specialFacets, |
|
299 |
@QueryParam("fq") final List<String> fieldQueries, |
|
300 |
@QueryParam("format") final String format, |
|
301 |
@Context HttpServletRequest request) { |
|
262 | 302 |
|
263 | 303 |
String simpleQuery = buildSearchRequest(RequestResponseHandler.Entity.OTHER, keywords, doi, sortBy, fieldQueries); |
264 | 304 |
return getResponseByEntity(simpleQuery, RequestResponseHandler.Entity.OTHER, offset, limit, format, request, refine, refineFields, specialFacets, fieldQueries); |
... | ... | |
269 | 309 |
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) |
270 | 310 |
@Timed(value = "http.server.request.duration", extraTags = {"referer", "portal", "uri", "/rest/v2/api/other"}, longTask = false) |
271 | 311 |
public Response fetchOtherCount(@QueryParam("q") String query, |
272 |
@QueryParam("format") final String format,
|
|
273 |
@QueryParam("fq") final List<String> fieldQueries,
|
|
274 |
@Context final HttpServletRequest request) {
|
|
312 |
@QueryParam("format") final String format, |
|
313 |
@QueryParam("fq") final List<String> fieldQueries, |
|
314 |
@Context final HttpServletRequest request) { |
|
275 | 315 |
String fullQuery = buildSearchRequest(RequestResponseHandler.Entity.OTHER, query, fieldQueries); |
276 | 316 |
return getCount(request, fullQuery, format, fieldQueries); |
277 | 317 |
} |
... | ... | |
281 | 321 |
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) |
282 | 322 |
@Timed(value = "http.server.request.duration", extraTags = {"referer", "portal", "uri", "/rest/v2/api/other/{otherid}"}, longTask = false) |
283 | 323 |
public Response fetchOther(@PathParam("otherid") String datasetid, |
284 |
@QueryParam("format") final String format,
|
|
285 |
@QueryParam("fq") final List<String> fieldQueries,
|
|
286 |
@Context final HttpServletRequest request) {
|
|
324 |
@QueryParam("format") final String format, |
|
325 |
@QueryParam("fq") final List<String> fieldQueries, |
|
326 |
@Context final HttpServletRequest request) { |
|
287 | 327 |
return getResponseByEntityId(request, RequestResponseHandler.Entity.OTHER, datasetid, format, fieldQueries); |
288 | 328 |
} |
289 | 329 |
@GET |
... | ... | |
360 | 400 |
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) |
361 | 401 |
@Timed(value = "http.server.request.duration", extraTags = {"referer", "portal", "uri", "/rest/v2/api/projects/{projectId}/datasets"}, longTask = false) |
362 | 402 |
public Response fetchProjectDatasets(@PathParam("projectId") String projectId, |
363 |
@DefaultValue("0") @QueryParam("page") int offset,
|
|
364 |
@DefaultValue("10") @QueryParam("size") int limit,
|
|
365 |
@QueryParam("format") final String format,
|
|
366 |
@QueryParam("fq") final List<String> fieldQueries,
|
|
367 |
@Context HttpServletRequest request) {
|
|
403 |
@DefaultValue("0") @QueryParam("page") int offset, |
|
404 |
@DefaultValue("10") @QueryParam("size") int limit, |
|
405 |
@QueryParam("format") final String format, |
|
406 |
@QueryParam("fq") final List<String> fieldQueries, |
|
407 |
@Context HttpServletRequest request) { |
|
368 | 408 |
|
369 | 409 |
String fullQuery = builtEntity2EntityRelationQuery(RequestResponseHandler.Entity.DATASET, "relprojectid", projectId, fieldQueries); |
370 | 410 |
return getResponseByEntity(fullQuery, RequestResponseHandler.Entity.DATASET, offset, limit, format, request, false, null, null, fieldQueries); |
... | ... | |
421 | 461 |
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) |
422 | 462 |
@Timed(value = "http.server.request.duration", extraTags = {"referer", "portal", "uri", "/rest/v2/api/projects/{projectId}/other/count"}, longTask = false) |
423 | 463 |
public Response fetchProjectOtherCount(@PathParam("projectId") String projectId, |
424 |
@DefaultValue("0") @QueryParam("page") int offset,
|
|
425 |
@DefaultValue("10") @QueryParam("size") int limit,
|
|
426 |
@QueryParam("format") final String format,
|
|
427 |
@QueryParam("fq") final List<String> fieldQueries,
|
|
428 |
@Context HttpServletRequest request) {
|
|
464 |
@DefaultValue("0") @QueryParam("page") int offset, |
|
465 |
@DefaultValue("10") @QueryParam("size") int limit, |
|
466 |
@QueryParam("format") final String format, |
|
467 |
@QueryParam("fq") final List<String> fieldQueries, |
|
468 |
@Context HttpServletRequest request) { |
|
429 | 469 |
String fullQuery = builtEntity2EntityRelationQuery(RequestResponseHandler.Entity.OTHER, "relprojectid", projectId, fieldQueries); |
430 | 470 |
return getCount(request, fullQuery, format, fieldQueries); |
431 | 471 |
} |
... | ... | |
435 | 475 |
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) |
436 | 476 |
@Timed(value = "http.server.request.duration", extraTags = {"referer", "portal", "uri", "/rest/v2/api/projects/{projectId}/other"}, longTask = false) |
437 | 477 |
public Response fetchProjectOther(@PathParam("projectId") String projectId, |
438 |
@DefaultValue("0") @QueryParam("page") int offset,
|
|
439 |
@DefaultValue("10") @QueryParam("size") int limit,
|
|
440 |
@QueryParam("format") final String format,
|
|
441 |
@QueryParam("fq") final List<String> fieldQueries,
|
|
442 |
@Context HttpServletRequest request) {
|
|
478 |
@DefaultValue("0") @QueryParam("page") int offset, |
|
479 |
@DefaultValue("10") @QueryParam("size") int limit, |
|
480 |
@QueryParam("format") final String format, |
|
481 |
@QueryParam("fq") final List<String> fieldQueries, |
|
482 |
@Context HttpServletRequest request) { |
|
443 | 483 |
|
444 | 484 |
String fullQuery = builtEntity2EntityRelationQuery(RequestResponseHandler.Entity.OTHER, "relprojectid", projectId, fieldQueries); |
445 | 485 |
return getResponseByEntity(fullQuery, RequestResponseHandler.Entity.OTHER, offset, limit, format, request, false, null, null, fieldQueries); |
... | ... | |
562 | 602 |
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) |
563 | 603 |
@Timed(value = "http.server.request.duration", extraTags = {"referer", "portal", "uri", "/rest/v2/api/organizations/{organizationid}/publications"}, longTask = false) |
564 | 604 |
public Response fetchOrganizationPublications(@PathParam("organizationid") String organizationid, |
565 |
@DefaultValue("0") @QueryParam("page") int offset, |
|
566 |
@DefaultValue("10") @QueryParam("size") int limit, |
|
567 |
@QueryParam("format") final String format, |
|
568 |
@QueryParam("fq") final List<String> fieldQueries, |
|
569 |
@Context HttpServletRequest request) { |
|
605 |
@DefaultValue("0") @QueryParam("page") int offset,
|
|
606 |
@DefaultValue("10") @QueryParam("size") int limit,
|
|
607 |
@QueryParam("format") final String format,
|
|
608 |
@QueryParam("fq") final List<String> fieldQueries,
|
|
609 |
@Context HttpServletRequest request) {
|
|
570 | 610 |
String fullQuery = builtEntity2EntityRelationQuery(RequestResponseHandler.Entity.PUBLICATION, "relorganizationid", organizationid, fieldQueries); |
571 | 611 |
return getResponseByEntity(fullQuery, RequestResponseHandler.Entity.PUBLICATION, offset, limit, format, request, false, null, null, fieldQueries); |
572 | 612 |
} |
... | ... | |
576 | 616 |
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) |
577 | 617 |
@Timed(value = "http.server.request.duration", extraTags = {"referer", "portal", "uri", "/rest/v2/api/organizations/{organizationid}/publications/count"}, longTask = false) |
578 | 618 |
public Response fetchOrganizationPublicationsCount(@PathParam("organizationid") String organizationid, |
579 |
@DefaultValue("0") @QueryParam("page") int offset, |
|
580 |
@DefaultValue("10") @QueryParam("size") int limit, |
|
581 |
@QueryParam("format") final String format, |
|
582 |
@QueryParam("fq") final List<String> fieldQueries, |
|
583 |
@Context HttpServletRequest request) { |
|
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) {
|
|
584 | 624 |
String fullQuery = builtEntity2EntityRelationQuery(RequestResponseHandler.Entity.PUBLICATION, "relorganizationid", organizationid, fieldQueries); |
585 | 625 |
return getCount(request, fullQuery, format, fieldQueries); |
586 | 626 |
} |
... | ... | |
590 | 630 |
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) |
591 | 631 |
@Timed(value = "http.server.request.duration", extraTags = {"referer", "portal", "uri", "/rest/v2/api/organizations/{organizationid}/datasets"}, longTask = false) |
592 | 632 |
public Response fetchOrganizationDatsets(@PathParam("organizationid") String organizationid, |
593 |
@DefaultValue("0") @QueryParam("page") int offset,
|
|
594 |
@DefaultValue("10") @QueryParam("size") int limit,
|
|
595 |
@QueryParam("format") final String format,
|
|
596 |
@QueryParam("fq") final List<String> fieldQueries,
|
|
597 |
@Context HttpServletRequest request) {
|
|
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) { |
|
598 | 638 |
String fullQuery = builtEntity2EntityRelationQuery(RequestResponseHandler.Entity.DATASET, "relorganizationid", organizationid, fieldQueries); |
599 | 639 |
return getResponseByEntity(fullQuery, RequestResponseHandler.Entity.DATASET, offset, limit, format, request, false, null, null,fieldQueries); |
600 | 640 |
} |
... | ... | |
604 | 644 |
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) |
605 | 645 |
@Timed(value = "http.server.request.duration", extraTags = {"referer", "portal", "uri", "/rest/v2/api/organizations/{organizationid}/datasets/count"}, longTask = false) |
606 | 646 |
public Response fetchOrganizationDatsetsCount(@PathParam("organizationid") String organizationid, |
607 |
@DefaultValue("0") @QueryParam("page") int offset, |
|
608 |
@DefaultValue("10") @QueryParam("size") int limit, |
|
609 |
@QueryParam("format") final String format, |
|
610 |
@QueryParam("fq") final List<String> fieldQueries, |
|
611 |
@Context HttpServletRequest request) { |
|
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) {
|
|
612 | 652 |
String fullQuery = builtEntity2EntityRelationQuery(RequestResponseHandler.Entity.DATASET, "relorganizationid", organizationid, fieldQueries); |
613 | 653 |
return getCount(request, fullQuery, format, fieldQueries); |
614 | 654 |
} |
... | ... | |
618 | 658 |
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) |
619 | 659 |
@Timed(value = "http.server.request.duration", extraTags = {"referer", "portal", "uri", "/rest/v2/api/organizations/{organizationid}/projects"}, longTask = false) |
620 | 660 |
public Response fetchOrganizationProjects(@PathParam("organizationid") String organizationid, |
621 |
@DefaultValue("0") @QueryParam("page") int offset,
|
|
622 |
@DefaultValue("10") @QueryParam("size") int limit,
|
|
623 |
@QueryParam("format") final String format,
|
|
624 |
@QueryParam("fq") final List<String> fieldQueries,
|
|
625 |
@Context HttpServletRequest request) {
|
|
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) { |
|
626 | 666 |
String fullQuery = builtEntity2EntityRelationQuery(RequestResponseHandler.Entity.PROJECT, "relorganizationid", organizationid, fieldQueries); |
627 | 667 |
return getResponseByEntity(fullQuery, RequestResponseHandler.Entity.PROJECT, offset, limit, format, request, false, null, null, fieldQueries); |
628 | 668 |
} |
... | ... | |
639 | 679 |
return getCount(request, fullQuery,format, fieldQueries); |
640 | 680 |
} |
641 | 681 |
|
642 |
/* |
|
682 |
/*
|
|
643 | 683 |
|
644 |
@GET |
|
645 |
@Path("/api/people") |
|
646 |
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) |
|
647 |
public Response fetchPeople(@QueryParam("q") String keywords, |
|
648 |
@DefaultValue("0") @QueryParam("page") final int offset, |
|
649 |
@DefaultValue("10") @QueryParam("size") final int limit, |
|
650 |
@QueryParam("refine") @DefaultValue("false") final boolean refine, |
|
651 |
@QueryParam("fields") final List<String> refineFields, |
|
652 |
@QueryParam("fq") final List<String> fieldQueries, |
|
653 |
@QueryParam("format") final String format, |
|
654 |
@Context final HttpServletRequest request) { |
|
684 |
@GET
|
|
685 |
@Path("/api/people")
|
|
686 |
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
|
|
687 |
public Response fetchPeople(@QueryParam("q") String keywords,
|
|
688 |
@DefaultValue("0") @QueryParam("page") final int offset,
|
|
689 |
@DefaultValue("10") @QueryParam("size") final int limit,
|
|
690 |
@QueryParam("refine") @DefaultValue("false") final boolean refine,
|
|
691 |
@QueryParam("fields") final List<String> refineFields,
|
|
692 |
@QueryParam("fq") final List<String> fieldQueries,
|
|
693 |
@QueryParam("format") final String format,
|
|
694 |
@Context final HttpServletRequest request) {
|
|
655 | 695 |
|
656 |
String simpleQuery = buildSearchRequest(RequestResponseHandler.Entity.PERSON, keywords, fieldQueries); |
|
657 |
return getResponseByEntity(simpleQuery, RequestResponseHandler.Entity.PERSON, offset, limit, format, request, refine, refineFields, fieldQueries); |
|
658 |
} |
|
696 |
String simpleQuery = buildSearchRequest(RequestResponseHandler.Entity.PERSON, keywords, fieldQueries);
|
|
697 |
return getResponseByEntity(simpleQuery, RequestResponseHandler.Entity.PERSON, offset, limit, format, request, refine, refineFields, fieldQueries);
|
|
698 |
}
|
|
659 | 699 |
|
660 | 700 |
|
661 |
@GET |
|
662 |
@Path("/api/people/count") |
|
663 |
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) |
|
664 |
public Response fetchPeopleCount(@QueryParam("q") String query, |
|
665 |
@QueryParam("format") final String format, |
|
666 |
@QueryParam("fq") final List<String> fieldQueries, |
|
667 |
@Context final HttpServletRequest request) { |
|
668 |
String fullQuery = buildSearchRequest(RequestResponseHandler.Entity.PERSON, query, fieldQueries); |
|
669 |
return getCount(request, fullQuery, format, fieldQueries); |
|
670 |
} |
|
701 |
@GET
|
|
702 |
@Path("/api/people/count")
|
|
703 |
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
|
|
704 |
public Response fetchPeopleCount(@QueryParam("q") String query,
|
|
705 |
@QueryParam("format") final String format,
|
|
706 |
@QueryParam("fq") final List<String> fieldQueries,
|
|
707 |
@Context final HttpServletRequest request) {
|
|
708 |
String fullQuery = buildSearchRequest(RequestResponseHandler.Entity.PERSON, query, fieldQueries);
|
|
709 |
return getCount(request, fullQuery, format, fieldQueries);
|
|
710 |
}
|
|
671 | 711 |
|
672 |
@GET |
|
673 |
@Path("/api/people/{personid}") |
|
674 |
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) |
|
675 |
public Response fetchPeople(@PathParam("personid") String personid, |
|
676 |
@QueryParam("format") final String format, |
|
677 |
@QueryParam("fq") final List<String> fieldQueries, |
|
678 |
@Context final HttpServletRequest request) { |
|
679 |
return getResponseByEntityId(request, RequestResponseHandler.Entity.PERSON, personid, format, fieldQueries); |
|
680 |
} |
|
712 |
@GET
|
|
713 |
@Path("/api/people/{personid}")
|
|
714 |
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
|
|
715 |
public Response fetchPeople(@PathParam("personid") String personid,
|
|
716 |
@QueryParam("format") final String format,
|
|
717 |
@QueryParam("fq") final List<String> fieldQueries,
|
|
718 |
@Context final HttpServletRequest request) {
|
|
719 |
return getResponseByEntityId(request, RequestResponseHandler.Entity.PERSON, personid, format, fieldQueries);
|
|
720 |
}
|
|
681 | 721 |
|
682 | 722 |
|
683 |
@GET |
|
684 |
@Path("/api/people/{personid}/publications") |
|
685 |
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) |
|
686 |
public Response fetchPeoplePublications(@PathParam("personid") String personid, |
|
723 |
@GET |
|
724 |
@Path("/api/people/{personid}/publications") |
|
725 |
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) |
|
726 |
public Response fetchPeoplePublications(@PathParam("personid") String personid, |
|
727 |
@DefaultValue("0") @QueryParam("page") final int offset, |
|
728 |
@DefaultValue("10") @QueryParam("size") final int limit, |
|
729 |
@QueryParam("format") final String format, |
|
730 |
@QueryParam("fq") final List<String> fieldQueries, |
|
731 |
@Context final HttpServletRequest request) { |
|
732 |
String fullQuery = builtEntity2EntityRelationQuery(RequestResponseHandler.Entity.PUBLICATION, "relpersonid", personid, fieldQueries); |
|
733 |
return getResponseByEntity(fullQuery, RequestResponseHandler.Entity.PUBLICATION, offset, limit, format, request, false, null, fieldQueries); |
|
734 |
} |
|
735 |
|
|
736 |
@GET |
|
737 |
@Path("/api/people/{personid}/publications/count") |
|
738 |
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) |
|
739 |
public Response fetchPeoplePublicationsCount(@PathParam("personid") String personid, |
|
740 |
@QueryParam("format") final String format, |
|
741 |
@QueryParam("fq") final List<String> fieldQueries, |
|
742 |
@Context final HttpServletRequest request) { |
|
743 |
String fullQuery = builtEntity2EntityRelationQuery(RequestResponseHandler.Entity.PUBLICATION, "relpersonid", personid, fieldQueries); |
|
744 |
return getCount(request, fullQuery, format, fieldQueries); |
|
745 |
} |
|
746 |
|
|
747 |
|
|
748 |
@GET |
|
749 |
@Path("/api/people/{personid}/datasets") |
|
750 |
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) |
|
751 |
public Response fetchPeopleDatasets(@PathParam("personid") String personid, |
|
687 | 752 |
@DefaultValue("0") @QueryParam("page") final int offset, |
688 | 753 |
@DefaultValue("10") @QueryParam("size") final int limit, |
689 | 754 |
@QueryParam("format") final String format, |
690 | 755 |
@QueryParam("fq") final List<String> fieldQueries, |
691 | 756 |
@Context final HttpServletRequest request) { |
692 |
String fullQuery = builtEntity2EntityRelationQuery(RequestResponseHandler.Entity.PUBLICATION, "relpersonid", personid, fieldQueries);
|
|
693 |
return getResponseByEntity(fullQuery, RequestResponseHandler.Entity.PUBLICATION, offset, limit, format, request, false, null, fieldQueries);
|
|
694 |
} |
|
757 |
String fullQuery = builtEntity2EntityRelationQuery(RequestResponseHandler.Entity.DATASET, "relpersonid", personid, fieldQueries);
|
|
758 |
return getResponseByEntity(fullQuery, RequestResponseHandler.Entity.DATASET, offset, limit, format, request, false, null, fieldQueries);
|
|
759 |
}
|
|
695 | 760 |
|
696 |
@GET |
|
697 |
@Path("/api/people/{personid}/publications/count")
|
|
698 |
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) |
|
699 |
public Response fetchPeoplePublicationsCount(@PathParam("personid") String personid,
|
|
761 |
@GET
|
|
762 |
@Path("/api/people/{personid}/datasets/count")
|
|
763 |
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
|
|
764 |
public Response fetchPeopleDatasetsCount(@PathParam("personid") String personid,
|
|
700 | 765 |
@QueryParam("format") final String format, |
701 | 766 |
@QueryParam("fq") final List<String> fieldQueries, |
702 | 767 |
@Context final HttpServletRequest request) { |
703 |
String fullQuery = builtEntity2EntityRelationQuery(RequestResponseHandler.Entity.PUBLICATION, "relpersonid", personid, fieldQueries); |
|
704 |
return getCount(request, fullQuery, format, fieldQueries); |
|
705 |
} |
|
706 |
|
|
707 |
|
|
768 |
String fullQuery = builtEntity2EntityRelationQuery(RequestResponseHandler.Entity.DATASET, "relpersonid", personid, fieldQueries); |
|
769 |
return getCount(request, fullQuery, format, fieldQueries); |
|
770 |
} |
|
771 |
*/ |
|
708 | 772 |
@GET |
709 |
@Path("/api/people/{personid}/datasets") |
|
710 |
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) |
|
711 |
public Response fetchPeopleDatasets(@PathParam("personid") String personid, |
|
712 |
@DefaultValue("0") @QueryParam("page") final int offset, |
|
713 |
@DefaultValue("10") @QueryParam("size") final int limit, |
|
714 |
@QueryParam("format") final String format, |
|
715 |
@QueryParam("fq") final List<String> fieldQueries, |
|
716 |
@Context final HttpServletRequest request) { |
|
717 |
String fullQuery = builtEntity2EntityRelationQuery(RequestResponseHandler.Entity.DATASET, "relpersonid", personid, fieldQueries); |
|
718 |
return getResponseByEntity(fullQuery, RequestResponseHandler.Entity.DATASET, offset, limit, format, request, false, null, fieldQueries); |
|
719 |
} |
|
720 |
|
|
721 |
@GET |
|
722 |
@Path("/api/people/{personid}/datasets/count") |
|
723 |
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) |
|
724 |
public Response fetchPeopleDatasetsCount(@PathParam("personid") String personid, |
|
725 |
@QueryParam("format") final String format, |
|
726 |
@QueryParam("fq") final List<String> fieldQueries, |
|
727 |
@Context final HttpServletRequest request) { |
|
728 |
String fullQuery = builtEntity2EntityRelationQuery(RequestResponseHandler.Entity.DATASET, "relpersonid", personid, fieldQueries); |
|
729 |
return getCount(request, fullQuery, format, fieldQueries); |
|
730 |
} |
|
731 |
*/ |
|
732 |
@GET |
|
733 | 773 |
@Path("/api/reports") |
734 | 774 |
@Produces(MediaType.TEXT_PLAIN) |
735 | 775 |
@Timed(value = "http.server.request.duration", extraTags = {"referer", "portal", "uri", "/rest/v2/api/reports"}, longTask = false) |
736 |
public Response fetchReport(@QueryParam("q") String keywords,
|
|
776 |
public Response fetchReport(@QueryParam("query") String query,
|
|
737 | 777 |
@QueryParam("refine") @DefaultValue("false") boolean refine, |
738 | 778 |
@QueryParam("fields") final List<String> refineFields, |
739 | 779 |
@QueryParam("fq") final List<String> fieldQueries, |
740 |
@QueryParam("type") final String type,
|
|
780 |
@QueryParam("type") final List<String> types,
|
|
741 | 781 |
@QueryParam("format") final String format, |
742 | 782 |
@Context final HttpServletResponse response) { |
743 | 783 |
|
784 |
long startTime = System.nanoTime(); |
|
744 | 785 |
logger.debug("Reports request received"); |
745 | 786 |
|
746 |
if (type == null || type.isEmpty()) { |
|
747 |
return Response.status(Response.Status.BAD_REQUEST).entity(APIResponseFormatter. |
|
748 |
compose500Message(MediaType.APPLICATION_JSON, "Fail to fetch report.", "The 'type' parameter is missing.")).build(); |
|
749 |
} |
|
750 |
|
|
751 |
long startTime = System.nanoTime(); |
|
752 |
final RequestResponseHandler.Entity entity = extractEntity(type); |
|
753 |
final Transformer transformer = extractTransformer(format, entity); |
|
754 | 787 |
final boolean special = isSpecialFormat(format); |
755 | 788 |
String responseType = extractResponseFormat(format); |
756 | 789 |
|
757 |
final String fullQuery = buildSearchRequest(entity, keywords, fieldQueries); |
|
758 |
logger.debug("fullquery " + fullQuery); |
|
790 |
if(checkTypes(types)) { |
|
791 |
return Response.status(Response.Status.FORBIDDEN). |
|
792 |
entity(APIResponseFormatter.compose400Message(responseType, "The type parameter is missing or is invalid.")).type(responseType).build(); |
|
793 |
} |
|
794 |
|
|
795 |
RequestResponseHandler.Entity basicEntity = identifyBasicEntityType(types); |
|
796 |
if (basicEntity.equals(RequestResponseHandler.Entity.NONE)) { |
|
797 |
return Response.status(Response.Status.FORBIDDEN). |
|
798 |
entity(APIResponseFormatter.compose400Message(responseType, "The type parameter is missing or is invalid.")).type(responseType).build(); |
|
799 |
} |
|
800 |
|
|
801 |
Transformer transformer = extractTransformer(format, basicEntity); |
|
802 |
|
|
803 |
StringBuilder queryBuilder = new StringBuilder(); |
|
804 |
if (basicEntity.equals(RequestResponseHandler.Entity.RESULT)) { |
|
805 |
enhanceFieldQueryWithResultType(types, fieldQueries); |
|
806 |
|
|
807 |
} else { |
|
808 |
enhanceFieldQueryWithEntityType(basicEntity, fieldQueries); |
|
809 |
} |
|
810 |
|
|
811 |
final String fullquery; |
|
812 |
if (query==null || query.isEmpty()) { |
|
813 |
fullquery = "*"; |
|
814 |
} else { |
|
815 |
fullquery = query; |
|
816 |
} |
|
817 |
|
|
818 |
logger.debug("fullquery " + query); |
|
759 | 819 |
logger.debug("fieldQueries " + fieldQueries); |
760 | 820 |
|
761 | 821 |
try { |
762 |
SearchResult sr = ((SearchServiceImpl)searchService).newSearch(fullQuery, Locale.getDefault().toString(), refineFields, null, fieldQueries,0, 0, format, transformer,null,false);
|
|
822 |
SearchResult sr = ((SearchServiceImpl)searchService).newSearch(fullquery, Locale.getDefault().toString(), refineFields, null, fieldQueries,0, 0, format, transformer,null,false);
|
|
763 | 823 |
logger.debug("Total number of results " + sr.getTotal()); |
764 | 824 |
|
765 | 825 |
|
... | ... | |
773 | 833 |
public void write(OutputStream os) throws IOException, WebApplicationException |
774 | 834 |
{ |
775 | 835 |
if (hasTitle(format) && !format.equals("html")) { |
776 |
os.write(CSVResponseFormat.appendTitle(entity, special).getBytes());
|
|
836 |
os.write(CSVResponseFormat.appendTitle(basicEntity, special).getBytes());
|
|
777 | 837 |
} |
778 | 838 |
try { |
779 |
((SearchServiceImpl)searchService).cursorSearch(fullQuery, refineFields, null, fieldQueries, format, transformer, os);
|
|
839 |
((SearchServiceImpl)searchService).cursorSearch(fullquery, refineFields, null, fieldQueries, format, transformer, os);
|
|
780 | 840 |
|
781 | 841 |
} catch (SearchServiceException sse) { |
782 | 842 |
os.write(("Fail to return report. " + sse.getMessage()).getBytes()); |
783 | 843 |
logger.warn("Fail to return report. ", sse); |
784 | 844 |
} |
785 |
|
|
845 |
|
|
786 | 846 |
//os.close(); |
787 | 847 |
} |
788 | 848 |
|
... | ... | |
847 | 907 |
return queryBuilder.toString(); |
848 | 908 |
}*/ |
849 | 909 |
|
850 |
private String cleanKeywords(String keywords) { |
|
910 |
private static String cleanKeywords(String keywords) {
|
|
851 | 911 |
if (keywords != null) { |
852 | 912 |
return keywords.replaceAll("[\\\\/:*?<>|()]", ""); |
853 | 913 |
} |
... | ... | |
872 | 932 |
return queryBuilder.toString(); |
873 | 933 |
} |
874 | 934 |
|
935 |
public static String buildSearchRequest(List<String> types, String keywords, String doi, String sortBy, List<String> fieldQueries) { |
|
936 |
|
|
937 |
List<RequestResponseHandler.Entity> entities = extractEntities(types); |
|
938 |
//all results are of oaftype result |
|
939 |
enhanceFieldQueryWithResultType(types, fieldQueries); |
|
940 |
|
|
941 |
StringBuilder queryBuilder = new StringBuilder(); |
|
942 |
if (doi != null && !doi.trim().isEmpty()) { |
|
943 |
if (!queryBuilder.toString().isEmpty()) { |
|
944 |
queryBuilder.append(" and "); |
|
945 |
} |
|
946 |
queryBuilder.append("(pidclassid exact \"doi\" and pid exact " + doi + ")"); |
|
947 |
} |
|
948 |
|
|
949 |
builtQueryKeywords(queryBuilder, keywords); |
|
950 |
enhanceWithSortParameter(queryBuilder, sortBy); |
|
951 |
|
|
952 |
return queryBuilder.toString(); |
|
953 |
} |
|
954 |
|
|
875 | 955 |
private String buildSearchRequest(RequestResponseHandler.Entity entity, String keywords, List<String> fieldQueries) { |
876 | 956 |
enhanceFieldQueryWithEntityType(entity, fieldQueries); |
877 | 957 |
|
... | ... | |
881 | 961 |
return queryBuilder.toString(); |
882 | 962 |
} |
883 | 963 |
|
884 |
private void enhanceFieldQueryWithEntityType(RequestResponseHandler.Entity entity, List<String> fieldQueries) { |
|
964 |
private String buildSearchRequest(List<String> types, String keywords, List<String> fieldQueries) { |
|
965 |
|
|
966 |
List<RequestResponseHandler.Entity> entities = extractEntities(types); |
|
967 |
enhanceFieldQueryWithEntityType(RequestResponseHandler.Entity.RESULT, fieldQueries); |
|
968 |
|
|
969 |
StringBuilder queryBuilder = new StringBuilder(); |
|
970 |
builtQueryKeywords(queryBuilder, keywords); |
|
971 |
|
|
972 |
return queryBuilder.toString(); |
|
973 |
} |
|
974 |
|
|
975 |
private static void enhanceFieldQueryWithEntityType(RequestResponseHandler.Entity entity, List<String> fieldQueries) { |
|
885 | 976 |
for (String fieldQuery: entity.getFieldQueries()) { |
886 | 977 |
logger.debug("adding " + fieldQuery); |
887 | 978 |
fieldQueries.add(fieldQuery); |
888 | 979 |
} |
889 | 980 |
} |
890 | 981 |
|
891 |
private void builtQueryKeywords(StringBuilder queryBuilder, String keywords) { |
|
982 |
private static void enhanceFieldQueryWithResultType(final List<String> types, List<String> fieldQueries) { |
|
983 |
|
|
984 |
fieldQueries.add(RequestResponseHandler.Entity.RESULT.getSimpleQuery()); |
|
985 |
List<RequestResponseHandler.Entity> entities = extractEntities(types); |
|
986 |
|
|
987 |
if (types!= null && !types.isEmpty()) { |
|
988 |
StringBuilder queryBuilder = new StringBuilder(); |
|
989 |
for(RequestResponseHandler.Entity entity: entities) { |
|
990 |
CQLQueryBuilder.appendSimpleTerm(queryBuilder, CQLQueryBuilder.Operator.OR, entity.getSimpleQuery()); |
|
991 |
} |
|
992 |
fieldQueries.add(queryBuilder.toString()); |
|
993 |
} |
|
994 |
} |
|
995 |
|
|
996 |
|
|
997 |
|
|
998 |
private static void builtQueryKeywords(StringBuilder queryBuilder, String keywords) { |
|
892 | 999 |
if (keywords != null && !keywords.trim().isEmpty()) { |
893 | 1000 |
CQLQueryBuilder.appendKeywords(queryBuilder, cleanKeywords(keywords)); |
894 | 1001 |
} |
... | ... | |
964 | 1071 |
} |
965 | 1072 |
} |
966 | 1073 |
|
967 |
private void enhanceWithSortParameter(StringBuilder queryBuilder, String sortBy) { |
|
1074 |
private static void enhanceWithSortParameter(StringBuilder queryBuilder, String sortBy) {
|
|
968 | 1075 |
if (sortBy != null) { |
969 | 1076 |
String[] sortParams = sortBy.split(","); |
970 | 1077 |
|
... | ... | |
1012 | 1119 |
|
1013 | 1120 |
private Response getResponseByEntityId(HttpServletRequest request, RequestResponseHandler.Entity entity, String entityId, String format, List<String> fieldQueries) { |
1014 | 1121 |
String responseType = extractResponseFormat(format); |
1015 |
|
|
1122 |
|
|
1016 | 1123 |
try { |
1017 | 1124 |
StringBuilder queryBuilder = new StringBuilder(); |
1018 | 1125 |
builtEntityIdQuery(queryBuilder, entity, entityId, fieldQueries); |
... | ... | |
1029 | 1136 |
if (searchResult.getSearchResults() == null || searchResult.getSearchResults().isEmpty() || |
1030 | 1137 |
searchResult.getSearchResults().size() == 0 || searchResult.getSearchResults().get(0) == null) { |
1031 | 1138 |
return Response.status(Response.Status.NOT_FOUND).entity(APIResponseFormatter.compose404Message(responseType, "404 - " + entity +" with id " |
1032 |
+ entityId + " not found.")).type(responseType).build();
|
|
1139 |
+ entityId + " not found.")).type(responseType).build(); |
|
1033 | 1140 |
} |
1034 | 1141 |
|
1035 | 1142 |
return Response.status(Response.Status.OK).entity(APIResponseFormatter.createEntityResponse(request, entity, searchResult.getSearchResults().get(0).toString(), responseType)).type(responseType).build(); |
... | ... | |
1066 | 1173 |
} |
1067 | 1174 |
} |
1068 | 1175 |
|
1069 |
private RequestResponseHandler.Entity extractEntity(String type) { |
|
1176 |
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) { |
|
1177 |
long startTime = System.nanoTime(); |
|
1070 | 1178 |
|
1179 |
boolean special = isSpecialFormat(format); |
|
1180 |
boolean hasTitle = hasTitle(format); |
|
1181 |
String responseType = extractResponseFormat(format); |
|
1182 |
|
|
1183 |
if(checkTypes(types)) { |
|
1184 |
return Response.status(Response.Status.FORBIDDEN). |
|
1185 |
entity(APIResponseFormatter.compose400Message(responseType, "The type parameter is missing or is invalid.")).type(responseType).build(); |
|
1186 |
} |
|
1187 |
|
|
1188 |
RequestResponseHandler.Entity basicEntity = identifyBasicEntityType(types); |
|
1189 |
if (basicEntity.equals(RequestResponseHandler.Entity.NONE)) { |
|
1190 |
return Response.status(Response.Status.FORBIDDEN). |
|
1191 |
entity(APIResponseFormatter.compose400Message(responseType, "The type parameter is missing or is invalid.")).type(responseType).build(); |
|
1192 |
} |
|
1193 |
Transformer transformer = extractTransformer(format, basicEntity); |
|
1194 |
|
|
1195 |
//List<RequestResponseHandler.Entity> entities = extractEntities(types); |
|
1196 |
StringBuilder queryBuilder = new StringBuilder(); |
|
1197 |
if (basicEntity.equals(RequestResponseHandler.Entity.RESULT)) { |
|
1198 |
enhanceFieldQueryWithResultType(types, fieldQueries); |
|
1199 |
} else { |
|
1200 |
enhanceFieldQueryWithEntityType(basicEntity, fieldQueries); |
|
1201 |
} |
|
1202 |
|
|
1203 |
try { |
|
1204 |
if (fullQuery==null || fullQuery.isEmpty()) { |
|
1205 |
fullQuery = "*"; |
|
1206 |
} |
|
1207 |
|
|
1208 |
SearchResult solrResults = ((SearchServiceImpl)searchService).newSearch(fullQuery, Locale.getDefault().toString(), refineFields, specialFacets, fieldQueries, offset, limit, responseType, transformer, null, false); |
|
1209 |
long estimatedTime = System.nanoTime() - startTime; |
|
1210 |
logger.debug("Publications search time " + estimatedTime/1000000 + " milliseconds"); |
|
1211 |
return Response.status(Response.Status.OK).entity(APIResponseFormatter.createEntitiesResponse(request, basicEntity, fullQuery, fieldQueries, solrResults, refine, responseType, special, hasTitle)).type(responseType).build(); |
|
1212 |
|
|
1213 |
} catch (SearchServiceException sse) { |
|
1214 |
logger.error("Fail to get " + basicEntity.getPlural() , sse); |
|
1215 |
return Response.status(Response.Status.INTERNAL_SERVER_ERROR). |
|
1216 |
entity(APIResponseFormatter.compose500Message(responseType, "Fail to fetch " + basicEntity.getPlural(), sse.getMessage())).type(responseType).build(); |
|
1217 |
} |
|
1218 |
} |
|
1219 |
|
|
1220 |
private void enhanceQueryWithEntities(StringBuilder queryBuilder, List<String> types) { |
|
1221 |
|
|
1222 |
} |
|
1223 |
|
|
1224 |
|
|
1225 |
private static List<RequestResponseHandler.Entity> extractEntities(final List<String> types) { |
|
1226 |
List<RequestResponseHandler.Entity> entities = null; |
|
1227 |
if (types!= null || types.isEmpty()) { |
|
1228 |
logger.debug("types " + types); |
|
1229 |
entities = new ArrayList<>(); |
|
1230 |
for (String type: types) { |
|
1231 |
if (!entities.contains(type)) { |
|
1232 |
logger.debug("extracting for type " + type); |
|
1233 |
entities.add(extractEntity(type)); |
|
1234 |
} |
|
1235 |
} |
|
1236 |
} |
|
1237 |
return entities; |
|
1238 |
} |
|
1239 |
|
|
1240 |
private static RequestResponseHandler.Entity extractEntity(String type) { |
|
1241 |
|
|
1071 | 1242 |
if (type == null) { |
1072 | 1243 |
return RequestResponseHandler.Entity.NONE; |
1073 | 1244 |
} |
... | ... | |
1116 | 1287 |
@Timed(value = "http.requests.portal.publicationDuplicates", longTask = false) |
1117 | 1288 |
//TODO remove |
1118 | 1289 |
public Response fetchDeletedByInferencePublicationsById(@PathParam("publicationid") String publicationid, |
1119 |
@QueryParam("format") final String format, |
|
1120 |
@QueryParam("size") final int limit, |
|
1121 |
@QueryParam("fq") final List<String> fieldQueries, |
|
1122 |
@Context final HttpServletRequest request) { |
|
1290 |
@QueryParam("format") final String format,
|
|
1291 |
@QueryParam("size") final int limit,
|
|
1292 |
@QueryParam("fq") final List<String> fieldQueries,
|
|
1293 |
@Context final HttpServletRequest request) {
|
|
1123 | 1294 |
|
1124 | 1295 |
return getDeletedByInferenceResponseByPid(request, RequestResponseHandler.Entity.PUBLICATION, publicationid, format, limit, fieldQueries); |
1125 | 1296 |
} |
... | ... | |
1129 | 1300 |
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) |
1130 | 1301 |
@Timed(value = "http.requests.portal.publicationDuplicates", longTask = false) |
1131 | 1302 |
public Response fetchDeletedByInferenceEntitiesById(@PathParam("resultPid") String resultPid, |
1132 |
@QueryParam("format") final String format,
|
|
1133 |
@QueryParam("size") final int limit,
|
|
1134 |
@QueryParam("fq") final List<String> fieldQueries,
|
|
1135 |
@Context final HttpServletRequest request) {
|
|
1303 |
@QueryParam("format") final String format, |
|
1304 |
@QueryParam("size") final int limit, |
|
1305 |
@QueryParam("fq") final List<String> fieldQueries, |
|
1306 |
@Context final HttpServletRequest request) { |
|
1136 | 1307 |
|
1137 | 1308 |
return getDeletedByInferenceResponseByPid(request, RequestResponseHandler.Entity.NONE, resultPid, format, limit, fieldQueries); |
1138 | 1309 |
} |
... | ... | |
1143 | 1314 |
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) |
1144 | 1315 |
@Timed(value = "http.requests.portal.organizationDuplicates", longTask = false) |
1145 | 1316 |
public Response fetchDeletedByInferenceOrganizationById(@PathParam("organizationPid") String organizationPid, |
1146 |
@QueryParam("format") final String format, |
|
1147 |
@QueryParam("size") final int limit, |
|
1148 |
@QueryParam("fq") final List<String> fieldQueries, |
|
1149 |
@Context final HttpServletRequest request) { |
|
1317 |
@QueryParam("format") final String format,
|
|
1318 |
@QueryParam("size") final int limit,
|
|
1319 |
@QueryParam("fq") final List<String> fieldQueries,
|
|
1320 |
@Context final HttpServletRequest request) {
|
|
1150 | 1321 |
|
1151 | 1322 |
return getDeletedByInferenceResponseByPid(request, RequestResponseHandler.Entity.ORGANIZATION, organizationPid, format, limit, fieldQueries); |
1152 | 1323 |
} |
... | ... | |
1184 | 1355 |
} |
1185 | 1356 |
} |
1186 | 1357 |
|
1358 |
public boolean checkTypes(List<String> types) { |
|
1359 |
for (RequestResponseHandler.Entity entity: RequestResponseHandler.Entity.values()){ |
|
1360 |
if (!types.contains(entity.getPlural())) { |
|
1361 |
return false; |
|
1362 |
} |
|
1363 |
} |
|
1364 |
|
|
1365 |
return true; |
|
1366 |
} |
|
1187 | 1367 |
/* |
1188 | 1368 |
public static void main(String[] args) { |
1189 | 1369 |
String json = " {\"result\":{\"xmlns:oaf\":\"http://namespace.openaire.eu/oaf\",\"xmlns:xsi\":\"http://www.w3.o" + |
Also available in: Unified diff
Enhanced portal API with general method to return resources based on their type. For oaftype result we can query with multiple resulttypeids that are seperated with OR operator