Skip to content

Commit

Permalink
Merge pull request #27 from ts4nfdi/refacotor/generlize-federation-ca…
Browse files Browse the repository at this point in the history
…lls-service

Refacotor: generlize federation calls service
  • Loading branch information
syphax-bouazzouni committed Aug 21, 2024
2 parents 7ca8c75 + 33934f3 commit dcb9908
Show file tree
Hide file tree
Showing 28 changed files with 550 additions and 484 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ jobs:
distribution: 'temurin'
java-version: '11'

- name: Run tests
run: mvn test

- name: Build with Maven
run: mvn clean package

Expand Down
23 changes: 23 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Tests Ci

on:
pull_request:

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'

- name: Build with Maven
run: mvn clean install

- name: Run tests
run: mvn test
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,8 @@ build/
# System files
.DS_Store

node_modules/

src/frontend/.next/

/src/frontend/
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,31 @@
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

import java.util.concurrent.Executor;

@SpringBootApplication
@EnableConfigurationProperties
@EnableAsync
public class FederatedSearchApplication {

public static void main(String[] args) {

SpringApplication.run(FederatedSearchApplication.class, args);
}

@Bean
public Executor taskExecutor() {
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
executor.setCorePoolSize(10);
executor.setMaxPoolSize(10);
executor.setQueueCapacity(500);
executor.setThreadNamePrefix("Async-");
executor.initialize();
return executor;
}
}
89 changes: 0 additions & 89 deletions src/main/java/org/semantics/apigateway/config/Mapping.java

This file was deleted.

29 changes: 0 additions & 29 deletions src/main/java/org/semantics/apigateway/config/MappingConfig.java

This file was deleted.

16 changes: 0 additions & 16 deletions src/main/java/org/semantics/apigateway/config/Search.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import org.apache.http.HttpStatus;
import org.apache.jena.rdf.model.ResourceFactory;
import org.semantics.apigateway.service.search.DynSearchService;
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.*;
Expand All @@ -21,11 +22,11 @@
@RequestMapping("/")
public class GatewayController {

private final DynSearchService dynSearchService;
private final SearchService searchService;

@Autowired
public GatewayController(DynSearchService dynSearchService) {
this.dynSearchService = dynSearchService;
public GatewayController(SearchService searchService) {
this.searchService = searchService;
}

@CrossOrigin
Expand All @@ -35,36 +36,11 @@ public void home(HttpServletRequest request, HttpServletResponse response) throw
}


@CrossOrigin
@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 = "")})
@GetMapping("/search")
public CompletableFuture<ResponseEntity<?>> performDynFederatedSearch(@RequestParam String query,
@RequestParam(required = false) String database,
@RequestParam(required = false) String format,
@RequestParam(required = false) String targetDbSchema) {
return dynSearchService.performDynFederatedSearch(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");
});
}

@CrossOrigin
@Operation(summary = "", description = "", tags = {"OLS"})
@GetMapping("/ols/api/select")
public CompletableFuture<ResponseEntity<?>>
performDynFederatedSearchInOLSTargetDBSchema(@RequestParam Map<String, String> allParams) {
performDynFederatedSearchInOLSTargetDBSchema(@RequestParam Map<String, String> allParams) throws IOException, ParseException {

String query;
if (allParams.containsKey("q") || allParams.containsKey("query")) {
Expand All @@ -77,7 +53,7 @@ public CompletableFuture<ResponseEntity<?>> performDynFederatedSearch(@RequestPa
query = "*";
}

return dynSearchService.performDynFederatedSearch(query + "*", allParams.get("database"), allParams.get("format"), "ols")
return searchService.performSearch(query + "*", allParams.get("database"), allParams.get("format"), "ols")
.<ResponseEntity<?>>thenApply(ResponseEntity::ok)
.exceptionally(e -> {
if (e.getCause() instanceof IllegalArgumentException) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package org.semantics.apigateway.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
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.model.Database;
import org.semantics.apigateway.model.ResponseFormat;
import org.semantics.apigateway.model.TargetDbSchema;
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(
@Parameter(description = "The text to search", example = "plant")
@RequestParam String query,
@Parameter(description = "Source to run search against")
@RequestParam(required = false) Database database,
@RequestParam(required = false) ResponseFormat format,
@Parameter(description = "Transform the response result to a specific schema")
@RequestParam(required = false) TargetDbSchema targetDbSchema) {


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");
});
}
}
7 changes: 7 additions & 0 deletions src/main/java/org/semantics/apigateway/model/Database.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package org.semantics.apigateway.model;

public enum Database {
ontoportal,
ols,
skosmos;
}
Loading

0 comments on commit dcb9908

Please sign in to comment.