-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
extract the search controller for the search endpoints
- Loading branch information
1 parent
ab15ec6
commit e7ff86a
Showing
3 changed files
with
60 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,4 +42,8 @@ build/ | |
# System files | ||
.DS_Store | ||
|
||
node_modules/ | ||
|
||
src/frontend/.next/ | ||
|
||
/src/frontend/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
src/main/java/org/semantics/apigateway/controller/SearchController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package org.semantics.apigateway.controller; | ||
|
||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.responses.ApiResponse; | ||
import io.swagger.v3.oas.annotations.responses.ApiResponses; | ||
import org.apache.http.HttpStatus; | ||
import org.apache.lucene.queryparser.classic.ParseException; | ||
import org.semantics.apigateway.service.search.SearchService; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
import java.io.IOException; | ||
import java.util.concurrent.CompletableFuture; | ||
|
||
|
||
@RestController | ||
@RequestMapping("/") | ||
public class SearchController { | ||
private final SearchService searchService; | ||
|
||
@Autowired | ||
public SearchController(SearchService searchService) { | ||
this.searchService = searchService; | ||
} | ||
|
||
|
||
@Operation(summary = "Search all of the content in a catalogue.", description = "The returned data should include a description of the type of data that is being returned. For example the returned content could be SKOS Concepts or OWL Classes.", tags={ "Search" }) | ||
@ApiResponses(value = { | ||
@ApiResponse(responseCode = "200", description = ""), | ||
|
||
@ApiResponse(responseCode = "404", description = "") }) | ||
@CrossOrigin | ||
@GetMapping("/search") | ||
public CompletableFuture<ResponseEntity<?>> performDynFederatedSearch(@RequestParam String query, | ||
@RequestParam(required = false) String database, | ||
@RequestParam(required = false) String format, | ||
@RequestParam(required = false) String targetDbSchema) throws IOException, ParseException { | ||
return searchService.performSearch(query, database, format, targetDbSchema) | ||
.<ResponseEntity<?>>thenApply(ResponseEntity::ok) | ||
.exceptionally(e -> { | ||
if (e.getCause() instanceof IllegalArgumentException) { | ||
return ResponseEntity | ||
.status(HttpStatus.SC_BAD_REQUEST) | ||
.body("Error: " + e.getCause().getMessage()); | ||
} | ||
return ResponseEntity | ||
.status(HttpStatus.SC_INTERNAL_SERVER_ERROR) | ||
.body("Error: An internal server error occurred"); | ||
}); | ||
} | ||
} |