2021-11-09 22:59:27 +01:00
|
|
|
package eu.openaire.urls_controller.controllers;
|
|
|
|
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.LoggerFactory;
|
2022-01-30 21:14:52 +01:00
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
2022-02-07 12:57:09 +01:00
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
2021-11-09 22:59:27 +01:00
|
|
|
import org.springframework.http.HttpStatus;
|
|
|
|
import org.springframework.http.ResponseEntity;
|
2022-01-30 21:14:52 +01:00
|
|
|
import org.springframework.jdbc.core.JdbcTemplate;
|
2021-11-09 22:59:27 +01:00
|
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
2022-01-30 21:14:52 +01:00
|
|
|
/**
|
|
|
|
* This controller will test the connectivity with the database and return statistics!
|
|
|
|
*/
|
2021-11-09 22:59:27 +01:00
|
|
|
@RestController
|
|
|
|
@RequestMapping("/impala")
|
|
|
|
public class ImpalaController {
|
|
|
|
private static final Logger logger = LoggerFactory.getLogger(ImpalaController.class);
|
|
|
|
|
2022-01-30 21:14:52 +01:00
|
|
|
@Autowired
|
|
|
|
private JdbcTemplate jdbcTemplate;
|
2021-11-09 22:59:27 +01:00
|
|
|
|
2022-02-07 12:57:09 +01:00
|
|
|
@Value("${services.pdfaggregation.controller.db.databaseName}")
|
|
|
|
private String databaseName;
|
|
|
|
|
2021-11-09 22:59:27 +01:00
|
|
|
@GetMapping("get10PublicationIdsTest")
|
|
|
|
public ResponseEntity<?> get10PublicationIdsTest() {
|
|
|
|
|
2022-02-07 12:57:09 +01:00
|
|
|
String query = "SELECT id FROM " + databaseName + ".publication LIMIT 10;";
|
2021-11-09 22:59:27 +01:00
|
|
|
|
2022-01-30 21:14:52 +01:00
|
|
|
try {
|
|
|
|
List<String> publications = jdbcTemplate.queryForList(query, String.class);
|
2021-11-09 22:59:27 +01:00
|
|
|
|
2022-01-30 21:14:52 +01:00
|
|
|
return new ResponseEntity<>(publications.toString(), HttpStatus.OK);
|
2021-11-09 22:59:27 +01:00
|
|
|
} catch (Exception e) {
|
|
|
|
String errorMsg = "Problem when executing \"getAssignmentsQuery\": " + query;
|
2021-11-30 18:59:46 +01:00
|
|
|
logger.error(errorMsg, e);
|
2021-11-09 22:59:27 +01:00
|
|
|
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(errorMsg);
|
|
|
|
}
|
|
|
|
}
|
2022-02-07 12:57:09 +01:00
|
|
|
|
2021-11-09 22:59:27 +01:00
|
|
|
}
|