2022-02-02 14:23:28 +01:00
|
|
|
package eu.dnetlib.scholix.api.controller;
|
|
|
|
|
2022-08-22 13:36:36 +02:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.stream.Collectors;
|
2022-02-28 14:26:55 +01:00
|
|
|
|
2022-02-14 09:16:37 +01:00
|
|
|
import org.apache.commons.lang3.tuple.Pair;
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
2022-02-02 14:23:28 +01:00
|
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
2022-08-22 13:36:36 +02:00
|
|
|
import eu.dnetlib.common.controller.AbstractDnetController;
|
|
|
|
import eu.dnetlib.dhp.schema.sx.api.model.v1.LinkPublisher;
|
|
|
|
import eu.dnetlib.scholix.api.ScholixException;
|
|
|
|
import eu.dnetlib.scholix.api.index.ScholixIndexManager;
|
|
|
|
import io.micrometer.core.annotation.Timed;
|
|
|
|
import io.swagger.v3.oas.annotations.Operation;
|
|
|
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
2022-02-02 14:23:28 +01:00
|
|
|
|
|
|
|
@RestController
|
|
|
|
@RequestMapping("/v1")
|
2022-08-22 13:36:36 +02:00
|
|
|
@Tag(name = "Datasources")
|
|
|
|
public class DatasourceV1 extends AbstractDnetController {
|
2022-02-14 09:16:37 +01:00
|
|
|
|
2022-08-22 13:36:36 +02:00
|
|
|
@Autowired
|
|
|
|
private ScholixIndexManager manager;
|
2022-02-14 09:16:37 +01:00
|
|
|
|
2022-08-22 13:36:36 +02:00
|
|
|
@Timed(value = "scholix.v1.datasources", description = "Time taken to return all datasources on Version 1.0 of Scholix")
|
|
|
|
@Operation(summary = "Get all Datasources", description = "returns a list of all datasources")
|
|
|
|
@GetMapping("/listDatasources")
|
|
|
|
public List<LinkPublisher> getDatasources() throws ScholixException {
|
2022-02-14 09:16:37 +01:00
|
|
|
|
2022-08-22 13:36:36 +02:00
|
|
|
final List<Pair<String, Long>> result = manager.totalLinksByProvider(null);
|
2022-02-14 09:16:37 +01:00
|
|
|
|
2022-08-22 13:36:36 +02:00
|
|
|
if (result == null) { return new ArrayList<>(); }
|
2022-02-14 09:16:37 +01:00
|
|
|
|
2022-08-22 13:36:36 +02:00
|
|
|
return result.stream().map(p -> new LinkPublisher().name(p.getKey()).totalRelationships(p.getValue().intValue())).collect(Collectors.toList());
|
2022-02-14 09:16:37 +01:00
|
|
|
|
2022-08-22 13:36:36 +02:00
|
|
|
}
|
2022-02-02 14:23:28 +01:00
|
|
|
}
|