2022-02-02 14:23:28 +01:00
|
|
|
package eu.dnetlib.scholix.api.controller;
|
2022-02-14 09:16:37 +01:00
|
|
|
import eu.dnetlib.scholix.api.ScholixException;
|
|
|
|
import eu.dnetlib.scholix.api.index.ScholixIndexManager;
|
2022-02-02 14:23:28 +01:00
|
|
|
import eu.dnetlib.scholix.api.model.v2.LinkProviderType;
|
|
|
|
import io.swagger.annotations.Api;
|
|
|
|
import io.swagger.v3.oas.annotations.Operation;
|
|
|
|
import io.swagger.v3.oas.annotations.Parameter;
|
|
|
|
import io.swagger.v3.oas.annotations.enums.ParameterIn;
|
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.RequestParam;
|
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
2022-02-14 09:16:37 +01:00
|
|
|
import java.util.ArrayList;
|
2022-02-02 14:23:28 +01:00
|
|
|
import java.util.List;
|
2022-02-14 09:16:37 +01:00
|
|
|
import java.util.stream.Collectors;
|
2022-02-02 14:23:28 +01:00
|
|
|
|
|
|
|
@RestController
|
|
|
|
@RequestMapping("/v2/LinkPublisher")
|
|
|
|
@Api(tags = {
|
|
|
|
"LinkPublisher : Operation related to the Link Publisher"
|
|
|
|
})
|
|
|
|
public class LinkPublisherV2 {
|
|
|
|
|
2022-02-14 09:16:37 +01:00
|
|
|
@Autowired
|
|
|
|
ScholixIndexManager manager;
|
|
|
|
|
2022-02-02 14:23:28 +01:00
|
|
|
@Operation(
|
|
|
|
summary = "Get All Publishers that provide source object",
|
|
|
|
description = "Return a List of all Publishers that provide source objects in Scholix " +
|
|
|
|
"links and the total number of links where the source object comes from this publisher")
|
|
|
|
@GetMapping("/inSource")
|
|
|
|
public List<LinkProviderType> getInSource(
|
|
|
|
@Parameter(in = ParameterIn.QUERY, description = "Filter the link publisher name") @RequestParam(required = false) String name
|
2022-02-14 09:16:37 +01:00
|
|
|
) throws ScholixException {
|
|
|
|
List<Pair<String, Long>> result = manager.totalLinksPublisher(ScholixIndexManager.RelationPrefix.source,name);
|
|
|
|
|
|
|
|
if (result==null)
|
|
|
|
return new ArrayList<>();
|
|
|
|
|
|
|
|
return result.stream().map(s -> new LinkProviderType().name(s.getLeft()).totalRelationships(s.getValue().intValue())).collect(Collectors.toList());
|
2022-02-02 14:23:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Operation(
|
|
|
|
summary = "Get All Publishers that provide target object",
|
|
|
|
description = "Return a List of all Publishers that provide source objects in Scholix " +
|
|
|
|
"links and the total number of links where the target object comes from this publisher")
|
|
|
|
@GetMapping("/inTarget")
|
|
|
|
public List<LinkProviderType> getInTarget(
|
|
|
|
@Parameter(in = ParameterIn.QUERY, description = "Filter the link publisher name") @RequestParam(required = false) String name
|
2022-02-14 09:16:37 +01:00
|
|
|
) throws ScholixException {
|
|
|
|
List<Pair<String, Long>> result = manager.totalLinksPublisher(ScholixIndexManager.RelationPrefix.target,name);
|
|
|
|
|
|
|
|
if (result==null)
|
|
|
|
return new ArrayList<>();
|
|
|
|
|
|
|
|
return result.stream().map(s -> new LinkProviderType().name(s.getLeft()).totalRelationships(s.getValue().intValue())).collect(Collectors.toList());
|
2022-02-02 14:23:28 +01:00
|
|
|
}
|
|
|
|
}
|