Revision 55639
Added by Katerina Iatropoulou almost 5 years ago
SearchApiService.java | ||
---|---|---|
181 | 181 |
} |
182 | 182 |
|
183 | 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 |
|
184 | 222 |
@Path("/api/projects") |
185 | 223 |
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) |
186 | 224 |
public Response fetchProjects(@QueryParam("q") String keywords, |
... | ... | |
301 | 339 |
} |
302 | 340 |
|
303 | 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 |
|
304 | 369 |
@Path("/api/datasources") |
305 | 370 |
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) |
306 | 371 |
public Response fetchDatasources(@QueryParam("q") String keywords, |
... | ... | |
478 | 543 |
return getCount(request, fullQuery,format, fieldQueries); |
479 | 544 |
} |
480 | 545 |
|
546 |
/* |
|
481 | 547 |
|
482 |
|
|
483 | 548 |
@GET |
484 | 549 |
@Path("/api/people") |
485 | 550 |
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) |
... | ... | |
567 | 632 |
String fullQuery = builtEntity2EntityRelationQuery(RequestResponseHandler.Entity.DATASET, "relpersonid", personid, fieldQueries); |
568 | 633 |
return getCount(request, fullQuery, format, fieldQueries); |
569 | 634 |
} |
570 |
|
|
635 |
*/ |
|
571 | 636 |
@GET |
572 |
@Path("/reports") |
|
637 |
@Path("/api/reports")
|
|
573 | 638 |
@Produces(MediaType.TEXT_PLAIN) |
574 |
public Response fetchReport(@QueryParam("query") String query,
|
|
639 |
public Response fetchReport(@QueryParam("q") String keywords,
|
|
575 | 640 |
@QueryParam("refine") @DefaultValue("false") boolean refine, |
576 | 641 |
@QueryParam("fields") final List<String> fields, |
577 | 642 |
@QueryParam("fq") final List<String> fieldQueries, |
... | ... | |
592 | 657 |
final boolean special = isSpecialFormat(format); |
593 | 658 |
String responseType = extractResponseFormat(format); |
594 | 659 |
|
595 |
final String fullQuery = buildSearchRequest(entity,"", fieldQueries); |
|
660 |
final String fullQuery = buildSearchRequest(entity, keywords, fieldQueries); |
|
661 |
logger.debug("fullquery " + fullQuery); |
|
662 |
logger.debug("fieldQueries " + fieldQueries); |
|
596 | 663 |
|
597 | 664 |
try { |
598 | 665 |
SearchResult sr = searchService.newSearch(fullQuery, Locale.getDefault().toString(), fields, fieldQueries,0, 0, format, transformer,null,false); |
... | ... | |
890 | 957 |
} else if (type.equalsIgnoreCase(RequestResponseHandler.Entity.SOFTWARE.getPlural())) { |
891 | 958 |
return RequestResponseHandler.Entity.SOFTWARE; |
892 | 959 |
|
960 |
} else if (type.equalsIgnoreCase(RequestResponseHandler.Entity.OTHER.getPlural())) { |
|
961 |
return RequestResponseHandler.Entity.OTHER; |
|
962 |
|
|
893 | 963 |
} else if (type.equalsIgnoreCase(RequestResponseHandler.Entity.PROJECT.getPlural())) { |
894 | 964 |
return RequestResponseHandler.Entity.PROJECT; |
895 | 965 |
|
... | ... | |
907 | 977 |
} |
908 | 978 |
|
909 | 979 |
|
980 |
//This follows the newSearchWithoutFieldQueries comment. I wish to remove it!!! This was only made |
|
981 |
// (quick and dirty - only the getResponseByEntity version with newSearchWithoutFieldQueries is used |
|
982 |
// after a last time request for the portal to show all the publications and the deletedbyinference ones. |
|
983 |
// I did not want to pass a parameter since I do not know if we are going to keep it. This is for a tech meeting showcase. |
|
984 |
// If we want to keep this I need to redesign. |
|
985 |
@GET |
|
986 |
@Path("/api/deletedByInferencePublications/{publicationid}") |
|
987 |
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) |
|
988 |
public Response fetchDeletedByInferencePublicationsById(@PathParam("publicationid") String publicationid, |
|
989 |
@QueryParam("format") final String format, |
|
990 |
@QueryParam("fq") final List<String> fieldQueries, |
|
991 |
@Context final HttpServletRequest request) { |
|
992 |
return getDeletedByInferenceResponseByEntityId(request, RequestResponseHandler.Entity.PUBLICATION, publicationid, format, fieldQueries); |
|
993 |
} |
|
994 |
|
|
995 |
//Please see comment above. I wish to remove it. |
|
996 |
private Response getDeletedByInferenceResponseByEntityId(HttpServletRequest request, RequestResponseHandler.Entity entity, String entityId, String format, List<String> fieldQueries) { |
|
997 |
String responseType = extractResponseFormat(format); |
|
998 |
|
|
999 |
try { |
|
1000 |
StringBuilder queryBuilder = new StringBuilder(); |
|
1001 |
builtEntityIdQuery(queryBuilder, entity, entityId, fieldQueries); |
|
1002 |
String fullQuery = queryBuilder.toString(); |
|
1003 |
|
|
1004 |
if(fullQuery == null || fullQuery.isEmpty()) { |
|
1005 |
return Response.status(Response.Status.BAD_REQUEST). |
|
1006 |
entity(APIResponseFormatter.compose400Message(format, "The 'query' parameter is required")). |
|
1007 |
type(responseType).build(); |
|
1008 |
} |
|
1009 |
|
|
1010 |
SearchResult searchResult = searchService.newSearchWithoutFieldQueries(fullQuery, Locale.getDefault().toString(), null, fieldQueries, 0, 1, responseType, null, null, false); |
|
1011 |
|
|
1012 |
if (searchResult.getSearchResults() == null || searchResult.getSearchResults().isEmpty() || |
|
1013 |
searchResult.getSearchResults().size() == 0 || searchResult.getSearchResults().get(0) == null) { |
|
1014 |
return Response.status(Response.Status.NOT_FOUND).entity(APIResponseFormatter.compose404Message(responseType, "404 - " + entity +" with id " |
|
1015 |
+ entityId + " not found.")).type(responseType).build(); |
|
1016 |
} |
|
1017 |
|
|
1018 |
return Response.status(Response.Status.OK).entity(APIResponseFormatter.createEntityResponse(request, entity, searchResult.getSearchResults().get(0).toString(), responseType)).type(responseType).build(); |
|
1019 |
|
|
1020 |
} catch (SearchServiceException sse) { |
|
1021 |
logger.error("Fail to fetch "+ entity + " with id " + entityId, sse); |
|
1022 |
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(APIResponseFormatter.compose500Message(responseType, "Fail to fetch " + entity + " with id " + entityId, sse.getMessage())).build(); |
|
1023 |
} |
|
1024 |
} |
|
1025 |
|
|
910 | 1026 |
/* |
911 | 1027 |
public static void main(String[] args) { |
912 | 1028 |
String json = " {\"result\":{\"xmlns:oaf\":\"http://namespace.openaire.eu/oaf\",\"xmlns:xsi\":\"http://www.w3.o" + |
Also available in: Unified diff
Latest for solr7 + deletedByInferencePublications method added #4216